return ((float)$usec+(float)$sec);
}
-function format_user_list(&$data, $course) {
+function format_user_list($data, $course) {
global $CFG, $DB;
$users = array();
foreach($data as $v){
$user['name'] = fullname($v);
$user['url'] = $CFG->wwwroot.'/user/view.php?id='.$v->id.'&course='.$course->id;
$user['picture'] = print_user_picture($v->id, 0, $v->picture, false, true, false);
+ $user['id'] = $v->id;
$users[] = $user;
}
return $users;
<link rel="stylesheet" type="text/css" href="<?php echo $CFG->httpswwwroot;?>/lib/yui/layout/assets/skins/sam/layout.css" />
<link rel="stylesheet" type="text/css" href="<?php echo $CFG->httpswwwroot;?>/lib/yui/button/assets/skins/sam/button.css" />
<?php
-print_js_config(array('sid'=>$chat_sid,'timer'=>5000, 'chat_lasttime'=>0,'chat_lastrow'=>null, 'header_title'=>$strchat), 'chat_cfg');
+print_js_config(array('userid'=>$USER->id, 'sid'=>$chat_sid,'timer'=>5000, 'chat_lasttime'=>0,'chat_lastrow'=>null,'header_title'=>$strchat,'chatroom_name'=>$str_title), 'chat_cfg');
print_js_config(array('send'=>$str_send, 'sending'=>$str_sending), 'chat_lang');
?>
<script type="text/javascript" src="<?php echo $CFG->httpswwwroot;?>/lib/yui/yahoo-dom-event/yahoo-dom-event.js"></script>
<ul id="msg_list">
<ul>
</div>
+<div id="notify">
+</div>
</body>
</html>
include('../lib.php');
$chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
-$chat_message = required_param('chat_message', PARAM_RAW);
+$chat_message = optional_param('chat_message', '', PARAM_RAW);
+$beep_id = optional_param('beep', '', PARAM_RAW);
if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
echo 'invalid sid';
chat_delete_old_users();
$chat_message = clean_text($chat_message, FORMAT_MOODLE);
-//TODO: Before insert the chat message into database, we should push the
-//message into a global object (which can hold 100 messages), when user request
-//the lastest messages, we compare the oldest messsage's timestamp $a to user's
-//timestamp $b, if $a<$b, directly return messages in global object, otherwise,
-//fetch the message from database.
+if (!empty($beep_id)) {
+ $chat_message = 'beep '.$beep_id;
+}
if (!empty($chat_message)) {
$message = new object();
add_to_log($course->id, 'chat', 'talk', "view.php?id=$cm->id", $chat->id, $cm->id);
}
-?>
ob_start();
-$beep = false;
$sendlist = false;
if ($messages && ($chat_lasttime != $chat_newlasttime)) {
foreach ($messages as $n => &$message) {
+ $tmp = new stdclass;
// when somebody enter room, user list will be updated
if($message->system == 1){
$sendlist = true;
}
$users = format_user_list($users, $course);
}
- $html = chat_format_message($message, $chatuser->course, $USER, $chat_lastrow);
- if ($html->beep) {
- $beep = true;
+ if ($html = chat_format_message($message, $chatuser->course, $USER, $chat_lastrow)) {
+ if ($html->beep) {
+ $tmp->type = 'beep';
+ }
+ $tmp->msg = $html->html;
+ $message = $tmp;
+ } else {
+ unset($message);
}
- $message = $html->html;
}
}
$response['users'] = $users;
}
-if ($beep) {
- $response['beep'] = true;
-}
-
$response['lasttime'] = $chat_newlasttime;
$response['lastrow'] = $chat_newrow;
if($messages){