]> git.mjollnir.org Git - moodle.git/commitdiff
maybe fixed double posts, fixed javascript errors, solved problems with reloading
authorskodak <skodak>
Mon, 7 Feb 2005 20:33:44 +0000 (20:33 +0000)
committerskodak <skodak>
Mon, 7 Feb 2005 20:33:44 +0000 (20:33 +0000)
mod/chat/gui_header_js/chatinput.php
mod/chat/gui_header_js/index.php
mod/chat/gui_header_js/insert.php
mod/chat/gui_header_js/jsupdate.php
mod/chat/gui_header_js/users.php
mod/chat/lib.php

index e7477b7fe6b8d33f7f469ac879729d3a88fa734e..c4d9471263447f5a9591e0042e4b37cd4f2ce222 100644 (file)
@@ -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;
     }
     // -->
     <?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()">
         &gt;&gt;<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>
\ No newline at end of file
+</html>
index 008f53e3ea61a96ed91f18af64454c2df947a142..e3bec8cab887f0cd40f2d0e09be02069fe6c7d41 100644 (file)
@@ -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!!');
     }
 
index 7b197164fff4ac283f264b03a2a3eb38d0fccf60..5321fc02b29656c4d35eb1c8451959f1ab511a53 100644 (file)
@@ -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');
 ?>
index 57da1a5ece3e0cde4ab0b3dbf82fefb6f5bbeb6d..7ac6981c0ff64fd28e08a4adb391f541e256699f 100644 (file)
@@ -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";
             }
         }
         ?>
                 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>
index 5b909be362849e505e7c647c03b49a4cfb44b3ed..1aa5f2770c691dfbe1915b0a87423296882ca83e 100644 (file)
     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;
index 7a4c6c2e8dc6a8a3632d88785076da81de0088d5..5100b70070a751ac60f8654a726f454f2585ba9c 100644 (file)
@@ -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;