]> git.mjollnir.org Git - moodle.git/commitdiff
Some minor improvements
authormoodler <moodler>
Mon, 7 Jul 2003 09:45:08 +0000 (09:45 +0000)
committermoodler <moodler>
Mon, 7 Jul 2003 09:45:08 +0000 (09:45 +0000)
mod/chat/gui_header_js/chatinput.php
mod/chat/gui_header_js/index.php
mod/chat/gui_header_js/jsupdate.php
mod/chat/insert.php
mod/chat/lib.php
mod/chat/users.php

index 6f8d19d9f379ca764dab67a2cef5f6fedd7c3176..3d8ff858c4efcb0ae4c01a3cacefc382da4fbadd 100644 (file)
@@ -3,10 +3,19 @@
 require("../../../config.php");
 require("../lib.php");
 
+require_variable($chat_sid);
+
 if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
     echo "Not logged in!";
+    die;
+}
+
+if (!$chat = get_record("chat", "id", $chatuser->chatid)) {
+    error("No chat found");
 }
 
+require_login($chat->course);
+
 ?>
  
 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">
index 169f5a4207f58d471e44143440f18cbbf6c9cdf6..1e01d66c0dee131f0ba1be1d17a1e9c974362428 100644 (file)
@@ -13,6 +13,8 @@ if (!$course = get_record("course", "id", $chat->course)) {
     error("Could not find the course this belongs to!");
 }
 
+require_login($course->id);
+
 if (!$chat_sid = chat_login_user($chat->id, "header_js")) {
     error("Could not log in to chat room!!");
 }
index 90de60e9705995cce57d39c7d19fd571f76df202..ef76ee8ca59eb0a3c8eeb8d8503916eeb9f0cea2 100644 (file)
@@ -5,8 +5,16 @@ require("../lib.php");
 
 if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
     echo "Not logged in!";
+    die;
 }
 
+if (!$chat = get_record("chat", "id", $chatuser->chatid)) {
+    error("No chat found");
+}
+
+require_login($chat->course);
+
+
 if ($message = chat_get_latest_message($chatuser->chatid)) {
     $chat_newlasttime = $message->timestamp;
 } else {
index 00827c9f2a7b5ee3c33130e0211e66a61978c94b..780006f6e93c96cb8decefbd627056a4ebe78a7e 100644 (file)
@@ -1,43 +1,59 @@
 <?php
 
-include("../../config.php");
-include("lib.php");
+    include("../../config.php");
+    include("lib.php");
 
-require_variable($chat_sid);
-require_variable($chat_version);
-require_variable($chat_message);
+    require_variable($chat_sid);
+    require_variable($chat_version);
+    require_variable($chat_message);
 
-if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
-    echo "Not logged in!";
-    die;
-}
+    if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
+        echo "Not logged in!";
+        die;
+    }
+    
+    if (!$chat = get_record("chat", "id", $chatuser->chatid)) {
+        error("No chat found");
+    }
+    
+    require_login($chat->course);
+    
 
 /// Delete old messages here
 
-/// Clean up the message
 
-$chat_message = clean_text($chat_message, FORMAT_MOODLE);  // Strip bad tags
 
-if (!empty($chat_message)) {
+/// Clean up the message
 
-    $message->chatid = $chatuser->chatid;
-    $message->userid = $chatuser->userid;
-    $message->message = $chat_message;
-    $message->timestamp = time();
-    if (!insert_record("chat_messages", $message)) {
-        error("Could not insert a chat message!");
-    }
-}
+    $chat_message = clean_text($chat_message, FORMAT_MOODLE);  // Strip bad tags
 
-if ($chat_version == "header" OR $chat_version == "box") {
-    redirect("../gui_$chat_version/chatinput.php?chat_sid=$chat_sid");
+/// Add the message to the database
 
-} else if ($chat_version == "text") {
-    redirect("../gui_$chat_version/index.php?chat_sid=$chat_sid&chat_lastid=$chat_lastid");
+    if (!empty($chat_message)) {
+    
+        $message->chatid = $chatuser->chatid;
+        $message->userid = $chatuser->userid;
+        $message->message = $chat_message;
+        $message->timestamp = time();
+     
+        if (!insert_record("chat_messages", $message)) {
+            error("Could not insert a chat message!");
+        }
 
-} else {
-    redirect("empty.php");
-}
+        $chatuser->lastmessageping = time();
+        update_record("chat_users", $chatuser);
+    }
+    
+/// Go back to the other page
+
+    if ($chat_version == "header" OR $chat_version == "box") {
+        redirect("../gui_$chat_version/chatinput.php?chat_sid=$chat_sid");
+    
+    } else if ($chat_version == "text") {
+        redirect("../gui_$chat_version/index.php?chat_sid=$chat_sid&chat_lastid=$chat_lastid");
+    
+    } else {
+        redirect("empty.php");
+    }
 
 ?>
index 69cf7ba73737d4669e3f8277b05cc7eb2ed7fdaa..7e6b1e4bd5533b634ea915bbe9640694f6c90045 100644 (file)
@@ -130,7 +130,7 @@ function chat_get_users($chatid) {
 
     global $CFG;
    
-    return get_records_sql("SELECT u.id, u.firstname, u.lastname, u.picture 
+    return get_records_sql("SELECT u.id, u.firstname, u.lastname, u.picture, c.lastmessageping
                               FROM {$CFG->prefix}chat_users c,
                                    {$CFG->prefix}user u
                              WHERE c.chatid = '$chatid'
@@ -158,7 +158,7 @@ function chat_login_user($chatid, $version="header_js") {
     $chatuser->userid   = $USER->id;
     $chatuser->version  = $version;
     $chatuser->ip       = $USER->lastIP;
-    $chatuser->lastping = time();
+    $chatuser->lastping = $chatuser->firstping = $chatuser->lastmessageping = time();
     $chatuser->sid      = random_string(32);
 
     if (!insert_record("chat_users", $chatuser)) {
index f635e5d2e3982a70078bfdb992870eeb68d2813e..d68bb77aa1e0b01621211a9c9de41e26f584b1d4 100644 (file)
@@ -10,6 +10,13 @@ if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
     die;
 }
 
+if (!$chat = get_record("chat", "id", $chatuser->chatid)) {
+    error("No chat found");
+}
+
+require_login($chat->course);
+
+
 if (!$chat = get_record("chat", "id", $chatuser->chatid)) {
     error("Could not find chat! id = $chatuser->chatid");
 }
@@ -51,12 +58,28 @@ header("Refresh: ".CHAT_REFRESH_USERLIST."; URL=users.php?chat_sid=".$chat_sid);
 
 print_header();
 
+$timenow = time();
+
+$stridle   = get_string("idle", "chat");
+$str->day   = get_string("day");
+$str->days  = get_string("days");
+$str->hour  = get_string("hour");
+$str->hours = get_string("hours");
+$str->min   = get_string("min");
+$str->mins  = get_string("mins");
+$str->sec   = get_string("sec");
+$str->secs  = get_string("secs");
+
 echo "<table width=\"100%\">";
 foreach ($chatusers as $chatuser) {
+    $lastping = $timenow - $chatuser->lastmessageping;
     echo "<tr><td width=35>";
     print_user_picture($chatuser->id, 0, $chatuser->picture, false, false, false);
     echo "</td><td valign=center>";
-    echo "<p><font size=1>$chatuser->firstname $chatuser->lastname</font></p>";
+    echo "<p><font size=1>";
+    echo "$chatuser->firstname $chatuser->lastname<br />";
+    echo "<font color=\"#888888\">$stridle: ".format_time($lastping, $str)."</font>";
+    echo "</font></p>";
     echo "<td></tr>";
 }
 echo "</table>";