require_once('../../../config.php');
require_once('../lib.php');
require_once('common.php');
-$time_start = microtime_float();
$id = required_param('id', PARAM_INT);
$groupid = optional_param('groupid', 0, PARAM_INT); //only for teachers
if (!$chat = $DB->get_record('chat', array('id'=>$id))) {
require_login($course->id, false, $cm);
require_capability('mod/chat:chat',$context);
-if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id))) {
+if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id)))
+{
print_header();
notice(get_string("activityiscurrentlyhidden"));
}
$groupname = '';
}
-$strchat = get_string('modulename', 'chat'); // must be before current_language() in chat_login_user() to force course language!!!
-$str_send = get_string('send', 'chat');
-$str_sending = get_string('sending', 'chat');
-$str_title = format_string($course->shortname) . ": ".format_string($chat->name,true).$groupname;
+// login chat room
if (!$chat_sid = chat_login_user($chat->id, 'ajax', $groupid, $course)) {
print_error('cantlogin', 'chat');
}
+
+// language string
+$str_chat = get_string('modulename', 'chat'); // must be before current_language() in chat_login_user() to force course language!!!
+$str_send = get_string('send', 'chat');
+$str_sending = get_string('sending', 'chat');
+$str_title = format_string($course->shortname) . ": ".format_string($chat->name,true).$groupname;
+$str_inputarea = get_string('inputarea', 'chat');
+$str_userlist = get_string('userlist', 'chat');
?>
<html>
<head>
<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('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');
+print_js_config(array('userid'=>$USER->id, 'sid'=>$chat_sid,'timer'=>5000, 'chat_lasttime'=>0,'chat_lastrow'=>null,'header_title'=>$str_chat,'chatroom_name'=>$str_title), 'chat_cfg');
+print_js_config(array('send'=>$str_send, 'sending'=>$str_sending, 'inputarea'=>$str_inputarea, 'userlist'=>$str_userlist), 'chat_lang');
?>
<script type="text/javascript" src="<?php echo $CFG->httpswwwroot;?>/lib/yui/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="<?php echo $CFG->httpswwwroot;?>/lib/yui/element/element-beta-min.js"></script>
<script type="text/javascript" src="<?php echo $CFG->httpswwwroot;?>/lib/yui/button/button-min.js"></script>
<script type="text/javascript" src="<?php echo $CFG->httpswwwroot;?>/lib/yui/selector/selector-beta-min.js"></script>
<script type="text/javascript" src="script.js"></script>
+<style type="text/css">
+#listing a{text-decoration:none;color:gray}
+#listing a:hover{text-decoration:underline;color:white;background:blue}
+#listing{padding: .5em}
+</style>
</head>
<body class=" yui-skin-sam">
<div id="chat_header">
+// record msg IDs
+var msgs = [];
+var interval = null;
+var scrollable = true;
+
(function() {
var Dom = YAHOO.util.Dom, Event = YAHOO.util.Event;
// window.onload
var layout = new YAHOO.widget.Layout({
units: [
{ position: 'top', height: 60, body: 'chat_header', header: chat_cfg.header_title, gutter: '5px', collapse: true, resize: false },
- { position: 'right', header: 'User List', width: 300, resize: true, gutter: '5px', footer: null, collapse: true, scroll: true, body: 'chat_user_list', animate: false },
- { position: 'bottom', header: 'Input Area', height: 60, resize: true, body: 'chat_input', gutter: '5px', collapse: false },
+ { position: 'right', header: chat_lang.userlist, width: 180, resize: true, gutter: '5px', footer: null, collapse: true, scroll: true, body: 'chat_user_list', animate: false },
+ { position: 'bottom', header: chat_lang.inputarea, height: 60, resize: true, body: 'chat_input', gutter: '5px', collapse: false, resize: false },
//{ position: 'left', header: 'Options', width: 200, resize: true, body: 'chat_options', gutter: '5px', collapse: true, close: true, collapseSize: 50, scroll: true, animate: false },
{ position: 'center', body: 'chat_panel', gutter: '5px', scroll: true }
]
});
Event.on('chat_panel', 'mouseout', function(ev) {
Event.stopEvent(ev);
- scrollable = false;
+ scrollable = true;
});
var key_send = new YAHOO.util.KeyListener(document, { keys:13 }, {fn:send_msg, correctScope:true });
key_send.enable();
}, chat_cfg.timer);
});
})();
+
+function in_array(f, t){
+ var a = false;
+ for( var i = 0; i<t.length; i++){
+ if(f==t[i]){
+ a=true;
+ break;
+ }
+ }
+ return a;
+}
+
+function talkto(name) {
+ var msg = document.getElementById('input_msgbox');
+ msg.value = "To "+name+": ";
+ msg.focus();
+}
function send_msg() {
var msg = document.getElementById('input_msgbox').value;
var el_send = document.getElementById('btn_send');
var url = 'post.php?chat_sid='+chat_cfg.sid;
var a = YAHOO.util.Connect.asyncRequest('POST', url, send_cb, "beep="+id);
}
-
-// record msg IDs
-var msgs = [];
-var interval = null;
-var scrollable = true;
-
function update_users(users) {
if(!users){
return;
}
var list = document.getElementById('listing');
+ list.innerHTML = '';
var html = '';
for(var i in users){
var el = document.createElement('li');
html += '<table><tr><td>' + users[i].picture + '</td><td>'
- html += users[i].name+'<br/><a href="###" onclick="send_beep('+users[i].id+')"> Beep </a>';
+ html += '<a target="_blank" href="'+users[i].url+'">'+ users[i].name+'<br/>';
+ html += '<a href="###" onclick="talkto(\''+users[i].name+'\')">Talk</a> ';
+ html += '<a href="###" onclick="send_beep('+users[i].id+')">Beep</a>';
html += '</td></tr></table>';
el.innerHTML = html;
- console.info(el.innerHTML);
list.appendChild(el);
}
}
-
function update_info() {
if(!chat_cfg.req_count){
chat_cfg.req_count = 1;
} else {
chat_cfg.req_count++;
}
- console.info(chat_cfg.req_count);
+ console.info('Update count: '+chat_cfg.req_count);
var url = "update.php?chat_sid="+chat_cfg.sid+"&chat_lasttime="+chat_cfg.chat_lasttime;
if(chat_cfg.chat_lastrow != null){
url += "&chat_lastrow="+chat_cfg.chat_lastrow;
function append_msg(msg) {
var list = document.getElementById('msg_list');
var el = document.createElement('li');
- console.info(msg);
+ console.info('New message:'+msg);
el.innerHTML = msg.msg;
if(msg.type && msg.type == 'beep'){
document.getElementById('notify').innerHTML = '<embed src="../beep.wav" autostart="true" hidden="true" name="beep" />';
if(!in_array(key, msgs)){
msgs.push(key);
append_msg(data['msgs'][key]);
- console.log(data['msgs'][key]);
}
}
// update users
update_users(data['users']);
// scroll to the bottom of the message list
- document.getElementById('chat_panel').parentNode.scrollTop+=500;
+ if(scrollable){
+ document.getElementById('chat_panel').parentNode.scrollTop+=500;
+ }
}
}
var init_cb = {
return;
}
if (data.users) {
- console.info(data);
update_users(data.users);
}
}
}
-function in_array(f, t){
- var a = false;
- for( var i = 0; i<t.length; i++){
- if(f==t[i]){
- a=true;
- break;
- }
- }
- return a;
-}
-
// debug code
if(!console){
var console = {
global $USER, $DB;
if (($version != 'sockets') and $chatuser = $DB->get_record('chat_users', array('chatid'=>$chatid, 'userid'=>$USER->id, 'groupid'=>$groupid))) {
+ // this will update logged user information
$chatuser->version = $version;
$chatuser->ip = $USER->lastip;
$chatuser->lastping = time();
}
}
- if (($chatuser->course != $course->id)
- or ($chatuser->userid != $USER->id)) {
+ if (($chatuser->course != $course->id) or ($chatuser->userid != $USER->id)) {
return false;
}
if (!$DB->update_record('chat_users', $chatuser)) {
$message->system = 1;
$message->timestamp = time();
- if (!$DB->insert_record('chat_messages', $message) || !$DB->insert_record('chat_messages_current', $message)) {
+ if (!$DB->insert_record('chat_messages', $message) || !$DB->insert_record('chat_messages_current', $message))
+ {
print_error('cantinsert', 'chat');
}
}
$outmain = '*** <b>'.$sender->firstname.' '.substr($text, 4).'</b>';
break;
}
+ } elseif (substr($text, 0, 2) == 'To') {
+ $pattern = '#To[[:space:]](.*):(.*)#';
+ preg_match($pattern, trim($text), $matches);
+ $special = true;
+ $outinfo = $message->strtime;
+ $outmain = $sender->firstname.' '.get_string('saidto', 'chat').' <i>'.$matches[1].'</i>: '.$matches[2];
}
if(!$special) {