maybe fixed double posts, fixed javascript errors, solved problems with reloading
This commit is contained in:
@@ -7,24 +7,22 @@
|
||||
|
||||
$chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
|
||||
|
||||
|
||||
if (!$chatuser = get_record('chat_users', 'sid', $chat_sid)) {
|
||||
error('Not logged in!');
|
||||
}
|
||||
|
||||
chat_force_language($chatuser->lang);
|
||||
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
scroll_active = true;
|
||||
function empty_field_and_submit() {
|
||||
document.fdummy.chat_message.value=document.f.chat_message.value;
|
||||
document.fdummy.submit();
|
||||
document.f.chat_message.value='';
|
||||
document.f.chat_message.focus();
|
||||
document.sendForm.chat_message.value = document.inputForm.chat_message.value;
|
||||
document.inputForm.chat_message.value = '';
|
||||
document.sendForm.submit();
|
||||
document.inputForm.chat_message.focus();
|
||||
return false;
|
||||
}
|
||||
// -->
|
||||
@@ -32,19 +30,18 @@
|
||||
<?php
|
||||
|
||||
$meta = ob_get_clean();
|
||||
print_header('', '', '', 'f.chat_message', $meta, false);
|
||||
print_header('', '', '', 'inputForm.chat_message', $meta, false);
|
||||
|
||||
?>
|
||||
<form action="insert.php" method="GET" target="empty" name="f"
|
||||
<form action="../empty.php" method="GET" target="empty" name="inputForm"
|
||||
OnSubmit="return empty_field_and_submit()">
|
||||
>><input type="text" name="chat_message" size="60" value="" />
|
||||
<?php helpbutton('chatting', get_string('helpchatting', 'chat'), 'chat', true, false); ?>
|
||||
</form>
|
||||
|
||||
<form action="insert.php" method="GET" target="empty" name="fdummy"
|
||||
OnSubmit="return empty_field_and_submit()">
|
||||
<form action="insert.php" method="GET" target="empty" name="sendForm">
|
||||
<input type="hidden" name="chat_sid" value="<?php echo $chat_sid ?>" />
|
||||
<input type="hidden" name="chat_message" />
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
$groupname = '';
|
||||
}
|
||||
|
||||
if (!$chat_sid = chat_login_user($chat->id, 'header_js', $groupid, $course)) {
|
||||
if (!$chat_sid = chat_login_user($chat->id, 'header_js', $groupid, $course, true)) {
|
||||
error('Could not log in to chat room!!');
|
||||
}
|
||||
|
||||
|
||||
@@ -61,5 +61,5 @@
|
||||
echo '<script type="text/javascript">parent.jsupdate.location.href = parent.jsupdate.document.anchors[0].href;</script>';
|
||||
}
|
||||
|
||||
//redirect('empty.php');
|
||||
redirect('../empty.php');
|
||||
?>
|
||||
|
||||
@@ -80,7 +80,8 @@
|
||||
update_record('chat_users', $chatuser);
|
||||
|
||||
if ($refreshusers) {
|
||||
echo "parent.users.location.href = parent.users.document.anchors[0].href;\n";
|
||||
echo "if (parent.users.document.anchors[0] != null) {" .
|
||||
"parent.users.location.href = parent.users.document.anchors[0].href;}\n";
|
||||
} else {
|
||||
foreach($us as $uid=>$lastping) {
|
||||
$min = (int) ($lastping/60);
|
||||
@@ -88,7 +89,8 @@
|
||||
$min = $min < 10 ? '0'.$min : $min;
|
||||
$sec = $sec < 10 ? '0'.$sec : $sec;
|
||||
$idle = $min.':'.$sec;
|
||||
echo "parent.users.document.getElementById('uidle{$uid}').innerHTML = '$idle';";
|
||||
echo "if (parent.users.document.getElementById('uidle{$uid}') != null) {".
|
||||
"parent.users.document.getElementById('uidle{$uid}').innerHTML = '$idle';}\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -102,6 +104,6 @@
|
||||
echo '<embed src="../beep.wav" autostart="true" hidden="true" name="beep" />';
|
||||
}
|
||||
?>
|
||||
<a href="<? echo $refreshurl ?>" name="refreshlink">Refresh link</a>
|
||||
<a href="<? echo $refreshurl ?>" name="refreshLink">Refresh link</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -68,11 +68,13 @@
|
||||
function update() {
|
||||
for(i=0; i<uidles.length; i++) {
|
||||
el = document.getElementById(uidles[i]);
|
||||
parts = el.innerHTML.split(":");
|
||||
time = f + (parseInt(parts[0], 10)*60) + parseInt(parts[1], 10);
|
||||
min = Math.floor(time/60);
|
||||
sec = time % 60;
|
||||
el.innerHTML = ((min < 10) ? "0" : "") + min + ":" + ((sec < 10) ? "0" : "") + sec;
|
||||
if (el != null) {
|
||||
parts = el.innerHTML.split(":");
|
||||
time = f + (parseInt(parts[0], 10)*60) + parseInt(parts[1], 10);
|
||||
min = Math.floor(time/60);
|
||||
sec = time % 60;
|
||||
el.innerHTML = ((min < 10) ? "0" : "") + min + ":" + ((sec < 10) ? "0" : "") + sec;
|
||||
}
|
||||
}
|
||||
timer = setTimeout("update()", f*1000);
|
||||
}
|
||||
@@ -92,7 +94,7 @@
|
||||
$strbeep = get_string('beep', 'chat');
|
||||
|
||||
|
||||
echo '<div style="display: none"><a href="'.$refreshurl.'" name="refreshlink">Refresh link</a></div>';
|
||||
echo '<div style="display: none"><a href="'.$refreshurl.'" name="refreshLink">Refresh link</a></div>';
|
||||
echo '<table width="100%">';
|
||||
foreach ($chatusers as $chatuser) {
|
||||
$lastping = $timenow - $chatuser->lastmessageping;
|
||||
|
||||
+5
-7
@@ -357,10 +357,9 @@ function chat_get_latest_message($chatid, $groupid=0) {
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// login if not already logged in
|
||||
|
||||
function chat_login_user($chatid, $version, $groupid, $course) {
|
||||
function chat_login_user($chatid, $version, $groupid, $course, $sendentermsg=false) {
|
||||
global $USER;
|
||||
|
||||
if ($chatuser = get_record_select('chat_users', "chatid='$chatid' AND userid='$USER->id' AND groupid='$groupid' LIMIT 1")) {
|
||||
if ($chatuser = get_record_select('chat_users', "chatid='$chatid' AND userid='$USER->id' AND groupid='$groupid'")) {
|
||||
$chatuser->version = $version;
|
||||
$chatuser->ip = $USER->lastIP;
|
||||
$chatuser->lastping = time();
|
||||
@@ -373,7 +372,6 @@ function chat_login_user($chatid, $version, $groupid, $course) {
|
||||
if (!update_record('chat_users', $chatuser)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} else {
|
||||
$chatuser->chatid = $chatid;
|
||||
$chatuser->userid = $USER->id;
|
||||
@@ -382,14 +380,14 @@ function chat_login_user($chatid, $version, $groupid, $course) {
|
||||
$chatuser->ip = $USER->lastIP;
|
||||
$chatuser->lastping = $chatuser->firstping = $chatuser->lastmessageping = time();
|
||||
$chatuser->sid = random_string(32);
|
||||
$chatuser->course = $course->id; //caching only, but needed for current_language() to work properly!
|
||||
$chatuser->lang = current_language();
|
||||
$chatuser->course = $course->id; //caching - needed for current_language too
|
||||
$chatuser->lang = current_language(); //caching - to resource intensive to find out later
|
||||
|
||||
if (!insert_record('chat_users', $chatuser)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($version == 'header_js') {
|
||||
if ($sendentermsg) {
|
||||
$message->chatid = $chatuser->chatid;
|
||||
$message->userid = $chatuser->userid;
|
||||
$message->groupid = $groupid;
|
||||
|
||||
Reference in New Issue
Block a user