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