MDL-8323 finished full conversion to proper $COURSE global - no more $CFG->coursethem...
[moodle.git] / mod / chat / gui_header_js / users.php
CommitLineData
516121bd 1<?php // $Id$
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
9152fc99 15 //Get the minimal course
16 if (!$course = get_record('course','id',$chatuser->course,'','','','','id,theme,lang')) {
17 error('incorrect course id');
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
21 if (!$USER = get_record('user','id',$chatuser->userid,'','','','','id, lang, theme, username, timezone')) {
22 error('User does not exist!');
23 }
24 $USER->description = '';
aa5c32fd 25
9152fc99 26 //Setup course, lang and theme
27 course_setup($course);
516121bd 28
29 $courseid = $chatuser->course;
30
31 if ($beep) {
32 $message->chatid = $chatuser->chatid;
33 $message->userid = $chatuser->userid;
34 $message->groupid = $chatuser->groupid;
35 $message->message = "beep $beep";
36 $message->system = 0;
37 $message->timestamp = time();
38
39 if (!insert_record('chat_messages', $message)) {
40 error('Could not insert a chat message!');
41 }
42
43 $chatuser->lastmessageping = time(); // A beep is a ping ;-)
44 }
45
46 $chatuser->lastping = time();
46c85976 47 set_field('chat_users', 'lastping', $chatuser->lastping, 'id', $chatuser->id );
516121bd 48
49 $refreshurl = "users.php?chat_sid=$chat_sid";
50
51 /// Get list of users
52
53 if (!$chatusers = chat_get_users($chatuser->chatid, $chatuser->groupid)) {
54 error(get_string('errornousers', 'chat'));
55 }
56
57 ob_start();
58 ?>
f4ba7e1a 59 <script type="text/javascript">
0cdf34fb 60 //<![CDATA[
516121bd 61 var timer = null
62 var f = 1; //seconds
63 var uidles = new Array(<?php echo count($chatusers) ?>);
64 <?php
65 $i = 0;
66 foreach ($chatusers as $chatuser) {
67 echo "uidles[$i] = 'uidle{$chatuser->id}';\n";
68 $i++;
69 }
70 ?>
71
72 function stop() {
73 clearTimeout(timer)
74 }
75
76 function start() {
77 timer = setTimeout("update()", f*1000);
78 }
79
80 function update() {
81 for(i=0; i<uidles.length; i++) {
82 el = document.getElementById(uidles[i]);
3dfd307f 83 if (el != null) {
84 parts = el.innerHTML.split(":");
85 time = f + (parseInt(parts[0], 10)*60) + parseInt(parts[1], 10);
86 min = Math.floor(time/60);
87 sec = time % 60;
88 el.innerHTML = ((min < 10) ? "0" : "") + min + ":" + ((sec < 10) ? "0" : "") + sec;
89 }
516121bd 90 }
91 timer = setTimeout("update()", f*1000);
92 }
0cdf34fb 93 //]]>
516121bd 94 </script>
95 <?php
96
97
98 /// Print headers
99 $meta = ob_get_clean();
6169ea25 100
101
102 // Use ob to support Keep-Alive
103 ob_start();
516121bd 104 print_header('', '', '', '', $meta, false, '', '', false, 'onload="start()" onunload="stop()"');
105
106
107 /// Print user panel body
108 $timenow = time();
109 $stridle = get_string('idle', 'chat');
110 $strbeep = get_string('beep', 'chat');
111
112
3dfd307f 113 echo '<div style="display: none"><a href="'.$refreshurl.'" name="refreshLink">Refresh link</a></div>';
516121bd 114 echo '<table width="100%">';
115 foreach ($chatusers as $chatuser) {
116 $lastping = $timenow - $chatuser->lastmessageping;
117 $min = (int) ($lastping/60);
118 $sec = $lastping - ($min*60);
119 $min = $min < 10 ? '0'.$min : $min;
120 $sec = $sec < 10 ? '0'.$sec : $sec;
121 $idle = $min.':'.$sec;
122 echo '<tr><td width="35">';
3b9f38bc 123 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\">";
516121bd 124 print_user_picture($chatuser->id, 0, $chatuser->picture, false, false, false);
125 echo '</a></td><td valign="center">';
126 echo '<p><font size="1">';
127 echo fullname($chatuser).'<br />';
128 echo "<span class=\"dimmed_text\">$stridle <span name=\"uidles\" id=\"uidle{$chatuser->id}\">$idle</span></span>";
129 echo " <a href=\"users.php?chat_sid=$chat_sid&amp;beep=$chatuser->id\">$strbeep</a>";
130 echo '</font></p>';
d3cc8d56 131 echo '</td></tr>';
516121bd 132 }
d3cc8d56 133 // added 2 </div>s, xhtml strict complaints
134 echo '</table></div></div></body></html>';
6169ea25 135
c5e817f0 136 //
137 // Support HTTP Keep-Alive by printing Content-Length
138 //
139 // If the user pane is refreshing often, using keepalives
140 // is lighter on the server and faster for most clients.
141 //
142 // Apache is normally configured to have a 15s timeout on
143 // keepalives, so let's observe that. Unfortunately, we cannot
144 // autodetect the keepalive timeout.
145 //
146 // Using keepalives when the refresh is longer than the timeout
147 // wastes server resources keeping an apache child around on a
148 // connection that will timeout. So we don't.
149 if ($CFG->chat_refresh_userlist < 15) {
150 header("Content-Length: " . ob_get_length() );
151 ob_end_flush();
152 }
153
6169ea25 154 exit; // no further output
155
156
516121bd 157?>