Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / mod / chat / gui_header_js / users.php
blob9cd107c5afc7cb9c48156c772fc772f5459d3451
1 <?php // $Id$
3 $nomoodlecookie = true; // Session not needed!
5 include('../../../config.php');
6 include('../lib.php');
8 $chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
9 $beep = optional_param('beep', 0, PARAM_INT); // beep target
11 if (!$chatuser = get_record('chat_users', 'sid', $chat_sid)) {
12 error('Not logged in!');
15 //Get the minimal course
16 if (!$course = get_record('course','id',$chatuser->course,'','','','','id,theme,lang')) {
17 error('incorrect course id');
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!');
24 $USER->description = '';
26 //Setup course, lang and theme
27 course_setup($course);
29 $courseid = $chatuser->course;
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();
39 if (!insert_record('chat_messages', $message)) {
40 error('Could not insert a chat message!');
43 $chatuser->lastmessageping = time(); // A beep is a ping ;-)
46 $chatuser->lastping = time();
47 set_field('chat_users', 'lastping', $chatuser->lastping, 'id', $chatuser->id );
49 $refreshurl = "users.php?chat_sid=$chat_sid";
51 /// Get list of users
53 if (!$chatusers = chat_get_users($chatuser->chatid, $chatuser->groupid)) {
54 error(get_string('errornousers', 'chat'));
57 ob_start();
59 <script type="text/javascript">
60 //<![CDATA[
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++;
72 function stop() {
73 clearTimeout(timer)
76 function start() {
77 timer = setTimeout("update()", f*1000);
80 function update() {
81 for(i=0; i<uidles.length; i++) {
82 el = document.getElementById(uidles[i]);
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;
91 timer = setTimeout("update()", f*1000);
93 //]]>
94 </script>
95 <?php
98 /// Print headers
99 $meta = ob_get_clean();
102 // Use ob to support Keep-Alive
103 ob_start();
104 print_header('', '', '', '', $meta, false, '', '', false, 'onload="start()" onunload="stop()"');
107 /// Print user panel body
108 $timenow = time();
109 $stridle = get_string('idle', 'chat');
110 $strbeep = get_string('beep', 'chat');
113 echo '<div style="display: none"><a href="'.$refreshurl.'" name="refreshLink">Refresh link</a></div>';
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">';
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\">";
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>';
131 echo '</td></tr>';
133 // added 2 </div>s, xhtml strict complaints
134 echo '</table></div></div></body></html>';
137 // Support HTTP Keep-Alive by printing Content-Length
139 // If the user pane is refreshing often, using keepalives
140 // is lighter on the server and faster for most clients.
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.
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();
154 exit; // no further output