| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: jsupdate.php,v 1.32.2.5 2008/10/14 08:38:26 dongsheng Exp $ 2 3 $nomoodlecookie = true; // Session not needed! 4 5 require('../../../config.php'); 6 require ('../lib.php'); 7 8 $chat_sid = required_param('chat_sid', PARAM_ALPHANUM); 9 $chat_lasttime = optional_param('chat_lasttime', 0, PARAM_INT); 10 $chat_lastrow = optional_param('chat_lastrow', 1, PARAM_INT); 11 12 if (!$chatuser = get_record('chat_users', 'sid', $chat_sid)) { 13 error('Not logged in!'); 14 } 15 16 //Get the minimal course 17 if (!$course = get_record('course','id',$chatuser->course,'','','','','id,theme,lang')) { 18 error('incorrect course id'); 19 } 20 21 //Get the user theme and enough info to be used in chat_format_message() which passes it along to 22 if (!$USER = get_record('user','id',$chatuser->userid)) { // no optimisation here, it would break again in future! 23 error('User does not exist!'); 24 } 25 $USER->description = ''; 26 27 //Setup course, lang and theme 28 course_setup($course); 29 30 // force deleting of timed out users if there is a silence in room or just entering 31 if ((time() - $chat_lasttime) > $CFG->chat_old_ping) { 32 // must be done before chat_get_latest_message!!! 33 chat_delete_old_users(); 34 } 35 36 if ($message = chat_get_latest_message($chatuser->chatid, $chatuser->groupid)) { 37 $chat_newlasttime = $message->timestamp; 38 } else { 39 $chat_newlasttime = 0; 40 } 41 42 if ($chat_lasttime == 0) { //display some previous messages 43 $chat_lasttime = time() - $CFG->chat_old_ping; //TO DO - any better value?? 44 } 45 46 $timenow = time(); 47 48 $groupselect = $chatuser->groupid ? " AND (groupid='".$chatuser->groupid."' OR groupid='0') " : ""; 49 50 $messages = get_records_select("chat_messages", 51 "chatid = '$chatuser->chatid' AND timestamp > '$chat_lasttime' $groupselect", 52 "timestamp ASC"); 53 54 if ($messages) { 55 $num = count($messages); 56 } else { 57 $num = 0; 58 } 59 60 $chat_newrow = ($chat_lastrow + $num) % 2; 61 62 // no & in url, does not work in header! 63 $refreshurl = "{$CFG->wwwroot}/mod/chat/gui_header_js/jsupdate.php?chat_sid=$chat_sid&chat_lasttime=$chat_newlasttime&chat_lastrow=$chat_newrow"; 64 $refreshurlamp = "{$CFG->wwwroot}/mod/chat/gui_header_js/jsupdate.php?chat_sid=$chat_sid&chat_lasttime=$chat_newlasttime&chat_lastrow=$chat_newrow"; 65 66 header('Expires: Sun, 28 Dec 1997 09:32:45 GMT'); 67 header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); 68 header('Cache-Control: no-cache, must-revalidate'); 69 header('Pragma: no-cache'); 70 header('Content-Type: text/html; charset=utf-8'); 71 header("Refresh: $CFG->chat_refresh_room; url=$refreshurl"); 72 73 /// required stylesheets 74 $stylesheetshtml = ''; 75 foreach ($CFG->stylesheets as $stylesheet) { 76 $stylesheetshtml .= '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'" />'; 77 } 78 79 // use ob to be able to send Content-Length headers 80 // needed for Keep-Alive to work 81 ob_start(); 82 83 ?> 84 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 85 <html> 86 <head> 87 <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 88 <script type="text/javascript"> 89 //<![CDATA[ 90 function safari_refresh() { 91 self.location.href= '<?php echo $refreshurl;?>'; 92 } 93 var issafari = false; 94 if(window.devicePixelRatio){ 95 issafari = true; 96 setTimeout('safari_refresh()', <?php echo $CFG->chat_refresh_room*1000;?>); 97 } 98 if (parent.msg && parent.msg.document.getElementById("msgStarted") == null) { 99 parent.msg.document.close(); 100 parent.msg.document.open("text/html","replace"); 101 parent.msg.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"); 102 parent.msg.document.write("<html><head>"); 103 parent.msg.document.write("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />"); 104 parent.msg.document.write("<base target=\"_blank\" />"); 105 parent.msg.document.write("<?php echo addslashes_js($stylesheetshtml) ?>"); 106 parent.msg.document.write("<\/head><body class=\"mod-chat-gui_header_js course-<?php echo $chatuser->course ?>\" id=\"mod-chat-gui_header_js-jsupdate\"><div style=\"display: none\" id=\"msgStarted\"> <\/div>"); 107 } 108 <?php 109 $beep = false; 110 $refreshusers = false; 111 $us = array (); 112 if (($chat_lasttime != $chat_newlasttime) and $messages) { 113 114 foreach ($messages as $message) { 115 $chat_lastrow = ($chat_lastrow + 1) % 2; 116 $formatmessage = chat_format_message($message, $chatuser->course, $USER, $chat_lastrow); 117 if ($formatmessage->beep) { 118 $beep = true; 119 } 120 if ($formatmessage->refreshusers) { 121 $refreshusers = true; 122 } 123 $us[$message->userid] = $timenow - $message->timestamp; 124 echo "if(parent.msg)"; 125 echo "parent.msg.document.write('".addslashes_js($formatmessage->html)."\\n');\n"; 126 } 127 } 128 129 $chatuser->lastping = time(); 130 set_field('chat_users', 'lastping', $chatuser->lastping, 'id', $chatuser->id ); 131 132 if ($refreshusers) { 133 ?> 134 var link = parent.users.document.getElementById('refreshLink'); 135 if (link != null) { 136 parent.users.location.href = link.href; 137 } 138 <?php 139 } else { 140 foreach($us as $uid=>$lastping) { 141 $min = (int) ($lastping/60); 142 $sec = $lastping - ($min*60); 143 $min = $min < 10 ? '0'.$min : $min; 144 $sec = $sec < 10 ? '0'.$sec : $sec; 145 $idle = $min.':'.$sec; 146 echo "if (parent.users && parent.users.document.getElementById('uidle{$uid}') != null) {". 147 "parent.users.document.getElementById('uidle{$uid}').innerHTML = '$idle';}\n"; 148 } 149 } 150 ?> 151 if(parent.input){ 152 var autoscroll = parent.input.document.getElementById('auto'); 153 if(parent.msg && autoscroll && autoscroll.checked){ 154 parent.msg.scroll(1,5000000); 155 } 156 } 157 //]]> 158 </script> 159 </head> 160 <body> 161 <?php 162 if ($beep) { 163 echo '<embed src="../beep.wav" autostart="true" hidden="true" name="beep" />'; 164 } 165 ?> 166 <a href="<?php echo $refreshurlamp ?>" name="refreshLink">Refresh link</a> 167 </body> 168 </html> 169 <?php 170 171 // support HTTP Keep-Alive 172 header("Content-Length: " . ob_get_length() ); 173 ob_end_flush(); 174 exit; 175 176 177 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |