From: moodler Date: Mon, 7 Jul 2003 09:45:08 +0000 (+0000) Subject: Some minor improvements X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=f7e648da70d4f1c1fdf452c75993a50e54716124;p=moodle.git Some minor improvements --- diff --git a/mod/chat/gui_header_js/chatinput.php b/mod/chat/gui_header_js/chatinput.php index 6f8d19d9f3..3d8ff858c4 100644 --- a/mod/chat/gui_header_js/chatinput.php +++ b/mod/chat/gui_header_js/chatinput.php @@ -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); + ?> diff --git a/mod/chat/gui_header_js/index.php b/mod/chat/gui_header_js/index.php index 169f5a4207..1e01d66c0d 100644 --- a/mod/chat/gui_header_js/index.php +++ b/mod/chat/gui_header_js/index.php @@ -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!!"); } diff --git a/mod/chat/gui_header_js/jsupdate.php b/mod/chat/gui_header_js/jsupdate.php index 90de60e970..ef76ee8ca5 100644 --- a/mod/chat/gui_header_js/jsupdate.php +++ b/mod/chat/gui_header_js/jsupdate.php @@ -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 { diff --git a/mod/chat/insert.php b/mod/chat/insert.php index 00827c9f2a..780006f6e9 100644 --- a/mod/chat/insert.php +++ b/mod/chat/insert.php @@ -1,43 +1,59 @@ 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"); + } ?> diff --git a/mod/chat/lib.php b/mod/chat/lib.php index 69cf7ba737..7e6b1e4bd5 100644 --- a/mod/chat/lib.php +++ b/mod/chat/lib.php @@ -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)) { diff --git a/mod/chat/users.php b/mod/chat/users.php index f635e5d2e3..d68bb77aa1 100644 --- a/mod/chat/users.php +++ b/mod/chat/users.php @@ -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 ""; foreach ($chatusers as $chatuser) { + $lastping = $timenow - $chatuser->lastmessageping; echo ""; } echo "
"; print_user_picture($chatuser->id, 0, $chatuser->picture, false, false, false); echo ""; - echo "

$chatuser->firstname $chatuser->lastname

"; + echo "

"; + echo "$chatuser->firstname $chatuser->lastname
"; + echo "$stridle: ".format_time($lastping, $str).""; + echo "

"; echo "
";