|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 define('NO_MOODLE_COOKIES', true); // session not used here 00004 00005 require_once('../../../config.php'); 00006 require_once($CFG->dirroot.'/mod/chat/lib.php'); 00007 00008 $chat_sid = required_param('chat_sid', PARAM_ALPHANUM); 00009 $beep = optional_param('beep', 0, PARAM_INT); // beep target 00010 00011 $PAGE->set_url('/mod/chat/gui_header_js/users.php', array('chat_sid'=>$chat_sid)); 00012 00013 if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) { 00014 print_error('notlogged', 'chat'); 00015 } 00016 00017 //Get the minimal course 00018 if (!$course = $DB->get_record('course', array('id'=>$chatuser->course))) { 00019 print_error('invalidcourseid'); 00020 } 00021 00022 //Get the user theme and enough info to be used in chat_format_message() which passes it along to 00023 if (!$USER = $DB->get_record('user', array('id'=>$chatuser->userid))) { // no optimisation here, it would break again in future! 00024 print_error('invaliduser'); 00025 } 00026 00027 $PAGE->set_pagelayout('embedded'); 00028 00029 $USER->description = ''; 00030 00031 //Setup course, lang and theme 00032 $PAGE->set_course($course); 00033 00034 $courseid = $chatuser->course; 00035 00036 if (!$cm = get_coursemodule_from_instance('chat', $chatuser->chatid, $courseid)) { 00037 print_error('invalidcoursemodule'); 00038 } 00039 00040 if ($beep) { 00041 $message->chatid = $chatuser->chatid; 00042 $message->userid = $chatuser->userid; 00043 $message->groupid = $chatuser->groupid; 00044 $message->message = "beep $beep"; 00045 $message->system = 0; 00046 $message->timestamp = time(); 00047 00048 $DB->insert_record('chat_messages', $message); 00049 $DB->insert_record('chat_messages_current', $message); 00050 00051 $chatuser->lastmessageping = time(); // A beep is a ping ;-) 00052 } 00053 00054 $chatuser->lastping = time(); 00055 $DB->set_field('chat_users', 'lastping', $chatuser->lastping, array('id'=>$chatuser->id)); 00056 00057 $refreshurl = "users.php?chat_sid=$chat_sid"; 00058 00060 00061 if (!$chatusers = chat_get_users($chatuser->chatid, $chatuser->groupid, $cm->groupingid)) { 00062 print_error('errornousers', 'chat'); 00063 } 00064 00065 $uidles = Array(); 00066 foreach ($chatusers as $chatuser) { 00067 $uidles[] = $chatuser->id; 00068 } 00069 00070 $module = array( 00071 'name' => 'mod_chat_header', 00072 'fullpath' => '/mod/chat/gui_header_js/module.js', 00073 'requires' => array('node') 00074 ); 00075 $PAGE->requires->js_init_call('M.mod_chat_header.init_users', array($uidles), false, $module); 00076 00078 $timenow = time(); 00079 $stridle = get_string('idle', 'chat'); 00080 $strbeep = get_string('beep', 'chat'); 00081 00082 $table = new html_table(); 00083 $table->width = '100%'; 00084 $table->data = array(); 00085 foreach ($chatusers as $chatuser) { 00086 $lastping = $timenow - $chatuser->lastmessageping; 00087 $min = (int) ($lastping/60); 00088 $sec = $lastping - ($min*60); 00089 $min = $min < 10 ? '0'.$min : $min; 00090 $sec = $sec < 10 ? '0'.$sec : $sec; 00091 $idle = $min.':'.$sec; 00092 00093 00094 $row = array(); 00095 $row[0] = $OUTPUT->user_picture($chatuser, array('courseid'=>$courseid, 'popup'=>true)); 00096 $row[1] = html_writer::start_tag('p'); 00097 $row[1] .= html_writer::start_tag('font', array('size'=>'1')); 00098 $row[1] .= fullname($chatuser).'<br />'; 00099 $row[1] .= html_writer::tag('span', $stridle . html_writer::tag('span', $idle, array('name'=>'uidles', 'id'=>'uidle'.$chatuser->id)), array('class'=>'dimmed_text')).' '; 00100 $row[1] .= html_writer::tag('a', $strbeep, array('href'=>new moodle_url('/mod/chat/gui_header_js/users.php', array('chat_sid'=>$chat_sid, 'beep'=>$chatuser->id)))); 00101 $row[1] .= html_writer::end_tag('font'); 00102 $row[1] .= html_writer::end_tag('p'); 00103 $table->data[] = $row; 00104 } 00105 00106 ob_start(); 00107 echo $OUTPUT->header(); 00108 echo html_writer::tag('div', html_writer::tag('a', 'Refresh link', array('href'=>$refreshurl, 'id'=>'refreshLink')), array('style'=>'display:none')); //TODO: localize 00109 echo html_writer::table($table); 00110 echo $OUTPUT->footer(); 00111 00112 // 00113 // Support HTTP Keep-Alive by printing Content-Length 00114 // 00115 // If the user pane is refreshing often, using keepalives 00116 // is lighter on the server and faster for most clients. 00117 // 00118 // Apache is normally configured to have a 15s timeout on 00119 // keepalives, so let's observe that. Unfortunately, we cannot 00120 // autodetect the keepalive timeout. 00121 // 00122 // Using keepalives when the refresh is longer than the timeout 00123 // wastes server resources keeping an apache child around on a 00124 // connection that will timeout. So we don't. 00125 if ($CFG->chat_refresh_userlist < 15) { 00126 header("Content-Length: " . ob_get_length() ); 00127 ob_end_flush(); 00128 } 00129 00130 exit; // no further output 00131