| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: users.php,v 1.13.2.3 2008/06/18 03:13:40 dongsheng Exp $ 2 3 $nomoodlecookie = true; // Session not needed! 4 5 include('../../../config.php'); 6 include ('../lib.php'); 7 8 $chat_sid = required_param('chat_sid', PARAM_ALPHANUM); 9 $beep = optional_param('beep', 0, PARAM_INT); // beep target 10 11 if (!$chatuser = get_record('chat_users', 'sid', $chat_sid)) { 12 error('Not logged in!'); 13 } 14 15 //Get the minimal course 16 if (!$course = get_record('course','id',$chatuser->course,'','','','','id,theme,lang')) { 17 error('incorrect course id'); 18 } 19 20 //Get the user theme and enough info to be used in chat_format_message() which passes it along to 21 if (!$USER = get_record('user','id',$chatuser->userid)) { // no optimisation here, it would break again in future! 22 error('User does not exist!'); 23 } 24 $USER->description = ''; 25 26 //Setup course, lang and theme 27 course_setup($course); 28 29 $courseid = $chatuser->course; 30 31 if (!$cm = get_coursemodule_from_instance('chat', $chatuser->chatid, $courseid)) { 32 error('Course Module ID was incorrect'); 33 } 34 35 if ($beep) { 36 $message->chatid = $chatuser->chatid; 37 $message->userid = $chatuser->userid; 38 $message->groupid = $chatuser->groupid; 39 $message->message = "beep $beep"; 40 $message->system = 0; 41 $message->timestamp = time(); 42 43 if (!insert_record('chat_messages', $message)) { 44 error('Could not insert a chat message!'); 45 } 46 47 $chatuser->lastmessageping = time(); // A beep is a ping ;-) 48 } 49 50 $chatuser->lastping = time(); 51 set_field('chat_users', 'lastping', $chatuser->lastping, 'id', $chatuser->id ); 52 53 $refreshurl = "users.php?chat_sid=$chat_sid"; 54 55 /// Get list of users 56 57 if (!$chatusers = chat_get_users($chatuser->chatid, $chatuser->groupid, $cm->groupingid)) { 58 print_error('errornousers', 'chat'); 59 } 60 61 ob_start(); 62 ?> 63 <script type="text/javascript"> 64 //<![CDATA[ 65 var timer = null 66 var f = 1; //seconds 67 var uidles = new Array(<?php echo count($chatusers) ?>); 68 <?php 69 $i = 0; 70 foreach ($chatusers as $chatuser) { 71 echo "uidles[$i] = 'uidle{$chatuser->id}';\n"; 72 $i++; 73 } 74 ?> 75 76 function stop() { 77 clearTimeout(timer) 78 } 79 80 function start() { 81 timer = setTimeout("update()", f*1000); 82 } 83 84 function update() { 85 for(i=0; i<uidles.length; i++) { 86 el = document.getElementById(uidles[i]); 87 if (el != null) { 88 parts = el.innerHTML.split(":"); 89 time = f + (parseInt(parts[0], 10)*60) + parseInt(parts[1], 10); 90 min = Math.floor(time/60); 91 sec = time % 60; 92 el.innerHTML = ((min < 10) ? "0" : "") + min + ":" + ((sec < 10) ? "0" : "") + sec; 93 } 94 } 95 timer = setTimeout("update()", f*1000); 96 } 97 //]]> 98 </script> 99 <?php 100 101 102 /// Print headers 103 $meta = ob_get_clean(); 104 105 106 // Use ob to support Keep-Alive 107 ob_start(); 108 print_header('', '', '', '', $meta, false, '', '', false, 'onload="start()" onunload="stop()"'); 109 110 111 /// Print user panel body 112 $timenow = time(); 113 $stridle = get_string('idle', 'chat'); 114 $strbeep = get_string('beep', 'chat'); 115 116 117 echo '<div style="display: none"><a href="'.$refreshurl.'" id="refreshLink">Refresh link</a></div>'; 118 echo '<table width="100%">'; 119 foreach ($chatusers as $chatuser) { 120 $lastping = $timenow - $chatuser->lastmessageping; 121 $min = (int) ($lastping/60); 122 $sec = $lastping - ($min*60); 123 $min = $min < 10 ? '0'.$min : $min; 124 $sec = $sec < 10 ? '0'.$sec : $sec; 125 $idle = $min.':'.$sec; 126 echo '<tr><td width="35">'; 127 echo "<a target=\"_blank\" onClick=\"return openpopup('/user/view.php?id=$chatuser->id&course=$courseid','user$chatuser->id','');\" href=\"$CFG->wwwroot/user/view.php?id=$chatuser->id&course=$courseid\">"; 128 print_user_picture($chatuser->id, 0, $chatuser->picture, false, false, false); 129 echo '</a></td><td valign="center">'; 130 echo '<p><font size="1">'; 131 echo fullname($chatuser).'<br />'; 132 echo "<span class=\"dimmed_text\">$stridle <span name=\"uidles\" id=\"uidle{$chatuser->id}\">$idle</span></span>"; 133 echo " <a href=\"users.php?chat_sid=$chat_sid&beep=$chatuser->id\">$strbeep</a>"; 134 echo '</font></p>'; 135 echo '</td></tr>'; 136 } 137 // added 2 </div>s, xhtml strict complaints 138 echo '</table>'; 139 print_footer('empty'); 140 141 // 142 // Support HTTP Keep-Alive by printing Content-Length 143 // 144 // If the user pane is refreshing often, using keepalives 145 // is lighter on the server and faster for most clients. 146 // 147 // Apache is normally configured to have a 15s timeout on 148 // keepalives, so let's observe that. Unfortunately, we cannot 149 // autodetect the keepalive timeout. 150 // 151 // Using keepalives when the refresh is longer than the timeout 152 // wastes server resources keeping an apache child around on a 153 // connection that will timeout. So we don't. 154 if ($CFG->chat_refresh_userlist < 15) { 155 header("Content-Length: " . ob_get_length() ); 156 ob_end_flush(); 157 } 158 159 exit; // no further output 160 161 162 ?>
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 |