diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 9c2b498a4ee94..db31c1a79a5b9 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -4628,5 +4628,35 @@ function html_entity_decode($string) { } } +/** + * 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 '"; + } + } + } + } + } + + return ''; +} + // vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140: ?> diff --git a/lib/weblib.php b/lib/weblib.php index f281860986f3a..0aa34c343a95e 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -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(); } /** diff --git a/message/lib.php b/message/lib.php index 78613f498c94a..44547c64fa4ad 100644 --- a/message/lib.php +++ b/message/lib.php @@ -3,6 +3,7 @@ define ('MESSAGE_SHORTLENGTH', 300); +define ('MESSAGE_WINDOW', true); function message_print_contacts() {