]> git.mjollnir.org Git - moodle.git/commitdiff
Message windows now popup from any page
authormoodler <moodler>
Thu, 30 Dec 2004 12:54:22 +0000 (12:54 +0000)
committermoodler <moodler>
Thu, 30 Dec 2004 12:54:22 +0000 (12:54 +0000)
lib/moodlelib.php
lib/weblib.php
message/lib.php

index 9c2b498a4ee943ef34a085984a636281ccfbd66f..db31c1a79a5b9b93b9f0d76d52593c539abf4630 100644 (file)
@@ -4628,5 +4628,35 @@ if(!function_exists('html_entity_decode')) {
     }
 }
 
+/**
+ * If new messages are waiting for the current user, then return 
+ * Javascript code to create a popup window
+ *
+ * @return string Javascript code
+ */
+function message_popup_window() {
+    global $USER;
+
+    $popuplimit = 30;     // Minimum seconds between popups
+
+    if (!defined('MESSAGE_WINDOW')) {
+        if (isset($USER->id)) {
+            if (!isset($USER->message_lastpopup)) {
+                $USER->message_lastpopup = 0;
+            }
+            if ((time() - $USER->message_lastpopup) > $popuplimit) {  /// It's been long enough
+                if (get_user_preferences('message_showmessagewindow', 1) == 1) {
+                    if (count_records_select('message', 'useridto = \''.$USER->id.'\' AND timecreated > \''.$USER->message_lastpopup.'\'')) {
+                        $USER->message_lastpopup = time();
+                        return '<script language="JavaScript" type="text/javascript">'."\n openpopup('/message/index.php', 'message', 'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500', 0);\n</script>";
+                    }
+                }
+            }
+        }
+    }
+
+    return '';
+}
+
 // vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140:
 ?>
index f281860986f3a18ad4024e13eaf20d04e4cf4c25..0aa34c343a95eb9c024dea3d98477f446817d6da 100644 (file)
@@ -1617,6 +1617,8 @@ function print_header ($title='', $heading='', $navigation='', $focus='', $meta=
     $title = strip_tags($title);
 
     include ($CFG->dirroot .'/theme/'. $CFG->theme .'/header.html');
+
+    echo message_popup_window();
 }
 
 /**
index 78613f498c94a17bad61a29ee4bc7a706784fe69..44547c64fa4ad748f196a527a6280c0853bf52cc 100644 (file)
@@ -3,6 +3,7 @@
 
 
 define ('MESSAGE_SHORTLENGTH', 300);
+define ('MESSAGE_WINDOW', true);
 
 
 function message_print_contacts() {