mod-choice MDL-19805 Added PAGE->set_url calls and removed deprecated functions
[moodle.git] / mod / chat / gui_header_js / users.php
CommitLineData
516121bd 1<?php // $Id$
2
6800d78e 3 define('NO_MOODLE_COOKIES', true); // session not used here
516121bd 4
d3bf6f92 5 require('../../../config.php');
6 require('../lib.php');
516121bd 7
8 $chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
9 $beep = optional_param('beep', 0, PARAM_INT); // beep target
10
d3bf6f92 11 if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
2f52a088 12 print_error('notlogged', 'chat');
516121bd 13 }
14
9152fc99 15 //Get the minimal course
c13a5e71 16 if (!$course = $DB->get_record('course', array('id'=>$chatuser->course))) {
2f52a088 17 print_error('invalidcourseid');
aa5c32fd 18 }
aa5c32fd 19
9152fc99 20 //Get the user theme and enough info to be used in chat_format_message() which passes it along to
d3bf6f92 21 if (!$USER = $DB->get_record('user', array('id'=>$chatuser->userid))) { // no optimisation here, it would break again in future!
2f52a088 22 print_error('invaliduser');
9152fc99 23 }
889f591c 24
25 $PAGE->set_generaltype('embedded');
26
9152fc99 27 $USER->description = '';
aa5c32fd 28
9152fc99 29 //Setup course, lang and theme
c13a5e71 30 $PAGE->set_course($course);
516121bd 31
32 $courseid = $chatuser->course;
33
a12e11c1 34 if (!$cm = get_coursemodule_from_instance('chat', $chatuser->chatid, $courseid)) {
2f52a088 35 print_error('invalidcoursemodule');
a12e11c1 36 }
37
516121bd 38 if ($beep) {
39 $message->chatid = $chatuser->chatid;
40 $message->userid = $chatuser->userid;
41 $message->groupid = $chatuser->groupid;
42 $message->message = "beep $beep";
43 $message->system = 0;
44 $message->timestamp = time();
45
7826abc7 46 $DB->insert_record('chat_messages', $message);
47 $DB->insert_record('chat_messages_current', $message);
516121bd 48
49 $chatuser->lastmessageping = time(); // A beep is a ping ;-)
50 }
51
52 $chatuser->lastping = time();
d3bf6f92 53 $DB->set_field('chat_users', 'lastping', $chatuser->lastping, array('id'=>$chatuser->id));
516121bd 54
55 $refreshurl = "users.php?chat_sid=$chat_sid";
56
57 /// Get list of users
58
a12e11c1 59 if (!$chatusers = chat_get_users($chatuser->chatid, $chatuser->groupid, $cm->groupingid)) {
5a2a5331 60 print_error('errornousers', 'chat');
516121bd 61 }
62
8ab94a36 63 $uidles = Array();
64 $i = 0;
65 foreach ($chatusers as $chatuser) {
66 $uidles[$i] = 'uidle{$chatuser->id}';
67 $i++;
516121bd 68 }
8ab94a36 69 $PAGE->requires->data_for_js('uidles', $uidles)->in_head();
70 $PAGE->requires->js('mod/chat/gui_header_js/chat_gui_header.js')->in_head();
296b589e 71 $PAGE->requires->js_function_call('start')->on_dom_ready();
889f591c 72 ob_start();
296b589e 73 echo $OUTPUT->header();
516121bd 74
75 /// Print user panel body
76 $timenow = time();
77 $stridle = get_string('idle', 'chat');
78 $strbeep = get_string('beep', 'chat');
79
80
5537bb04 81 echo '<div style="display: none"><a href="'.$refreshurl.'" id="refreshLink">Refresh link</a></div>';
516121bd 82 echo '<table width="100%">';
83 foreach ($chatusers as $chatuser) {
84 $lastping = $timenow - $chatuser->lastmessageping;
85 $min = (int) ($lastping/60);
86 $sec = $lastping - ($min*60);
87 $min = $min < 10 ? '0'.$min : $min;
88 $sec = $sec < 10 ? '0'.$sec : $sec;
89 $idle = $min.':'.$sec;
90 echo '<tr><td width="35">';
3b9f38bc 91 echo "<a target=\"_blank\" onClick=\"return openpopup('/user/view.php?id=$chatuser->id&amp;course=$courseid','user$chatuser->id','');\" href=\"$CFG->wwwroot/user/view.php?id=$chatuser->id&amp;course=$courseid\">";
889f591c 92 echo $OUTPUT->user_picture(moodle_user_picture::make($chatuser, $courseid));
516121bd 93 echo '</a></td><td valign="center">';
94 echo '<p><font size="1">';
95 echo fullname($chatuser).'<br />';
96 echo "<span class=\"dimmed_text\">$stridle <span name=\"uidles\" id=\"uidle{$chatuser->id}\">$idle</span></span>";
97 echo " <a href=\"users.php?chat_sid=$chat_sid&amp;beep=$chatuser->id\">$strbeep</a>";
98 echo '</font></p>';
d3cc8d56 99 echo '</td></tr>';
516121bd 100 }
d3cc8d56 101 // added 2 </div>s, xhtml strict complaints
d795bfdb 102 echo '</table>';
d8772689 103 echo $OUTPUT->footer();
6169ea25 104
c5e817f0 105 //
106 // Support HTTP Keep-Alive by printing Content-Length
107 //
5537bb04 108 // If the user pane is refreshing often, using keepalives
109 // is lighter on the server and faster for most clients.
c5e817f0 110 //
5537bb04 111 // Apache is normally configured to have a 15s timeout on
c5e817f0 112 // keepalives, so let's observe that. Unfortunately, we cannot
5537bb04 113 // autodetect the keepalive timeout.
c5e817f0 114 //
115 // Using keepalives when the refresh is longer than the timeout
5537bb04 116 // wastes server resources keeping an apache child around on a
117 // connection that will timeout. So we don't.
118 if ($CFG->chat_refresh_userlist < 15) {
c5e817f0 119 header("Content-Length: " . ob_get_length() );
5537bb04 120 ob_end_flush();
c5e817f0 121 }
122
6169ea25 123 exit; // no further output
124
125
516121bd 126?>