From fcd3a1ee425d9f5c87fe7f74b13d4a97c5a97a2c Mon Sep 17 00:00:00 2001 From: moodler Date: Fri, 25 Jul 2003 06:47:06 +0000 Subject: [PATCH] New feature - chat scheduling. Can now set a time for the next chat, as well as rotating weekly or daily period. Also some small fixes. --- lang/en/chat.php | 13 +++++++--- mod/chat/db/mysql.php | 5 ++++ mod/chat/db/mysql.sql | 4 ++- mod/chat/gui_header_js/index.php | 4 +-- mod/chat/lib.php | 42 +++++++++++++++++++++++++++++--- mod/chat/mod.html | 19 +++++++++++++++ mod/chat/version.php | 2 +- mod/chat/view.php | 21 +++++++++++++--- 8 files changed, 97 insertions(+), 13 deletions(-) diff --git a/lang/en/chat.php b/lang/en/chat.php index 47ce645a5a..39222eb7f6 100644 --- a/lang/en/chat.php +++ b/lang/en/chat.php @@ -9,9 +9,11 @@ $string['beep'] = "beep"; $string['chatintro'] = "Introduction text"; $string['chatname'] = "Name of this chat room"; $string['chatreport'] = "Chat sessions"; +$string['chattime'] = "Next chat time"; $string['currentchats'] = "Active chat sessions"; $string['currentusers'] = "Current users"; -$string['enterchat'] = "Click here to enter the chat"; +$string['donotusechattime'] = "Don't publish any chat times"; +$string['enterchat'] = "Click here to enter the chat now"; $string['errornousers'] = "Could not find any users!"; $string['idle'] = "Idle"; $string['messagebeepseveryone'] = "\$a beeps everyone!"; @@ -19,12 +21,17 @@ $string['messagebeepsyou'] = "\$a has just beeped you!"; $string['messageenter'] = "\$a has just entered this chat"; $string['messageexit'] = "\$a has left this chat"; $string['neverdeletemessages'] = "Never delete messages"; +$string['nextsession'] = "Next scheduled session"; $string['nomessages'] = "No messages yet"; -$string['savemessages'] = "Save messages"; +$string['repeatnone'] = "No repeats - publish the specified time only"; +$string['repeatdaily'] = "At the same time every day"; +$string['repeattimes'] = "Repeat sessions"; +$string['repeatweekly'] = "At the same time every week"; +$string['savemessages'] = "Save past sessions"; $string['sessions'] = "Chat sessions"; $string['seesession'] = "See this session"; $string['strftimemessage'] = "%%H:%%M"; -$string['studentseereports'] = "Everyone can see past sessions"; +$string['studentseereports'] = "Everyone can view past sessions"; $string['viewreport'] = "View past chat sessions"; ?> diff --git a/mod/chat/db/mysql.php b/mod/chat/db/mysql.php index 79e9f94f62..57c0ca7f30 100644 --- a/mod/chat/db/mysql.php +++ b/mod/chat/db/mysql.php @@ -18,6 +18,11 @@ function chat_upgrade($oldversion) { table_column("chat", "", "studentlogs", "integer", "4", "unsigned", "0", "not null", "keepdays"); } + if ($oldversion < 2003072500) { + table_column("chat", "", "chattime", "integer", "10", "unsigned", "0", "not null", "studentlogs"); + table_column("chat", "", "schedule", "integer", "4", "", "0", "not null", "studentlogs"); + } + return true; } diff --git a/mod/chat/db/mysql.sql b/mod/chat/db/mysql.sql index 44ee87b4ce..dde169848b 100644 --- a/mod/chat/db/mysql.sql +++ b/mod/chat/db/mysql.sql @@ -9,6 +9,8 @@ CREATE TABLE `prefix_chat` ( `intro` text NOT NULL, `keepdays` int(11) NOT NULL default '0', `studentlogs` int(4) NOT NULL default '0', + `chattime` int(10) unsigned NOT NULL default '0', + `schedule` int(4) NOT NULL default '0', `timemodified` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`id`) ) TYPE=MyISAM COMMENT='Each of these is a chat room'; @@ -24,7 +26,7 @@ CREATE TABLE `prefix_chat_messages` ( `userid` int(10) NOT NULL default '0', `system` int(1) unsigned NOT NULL default '0', `message` text NOT NULL, - `timestamp` int(10) NOT NULL default '0', + `timestamp` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`id`), KEY `timemodifiedchat` (`timestamp`,`chatid`) ) TYPE=MyISAM COMMENT='Stores all the actual chat messages'; diff --git a/mod/chat/gui_header_js/index.php b/mod/chat/gui_header_js/index.php index 1e01d66c0d..f19e37b4be 100644 --- a/mod/chat/gui_header_js/index.php +++ b/mod/chat/gui_header_js/index.php @@ -30,8 +30,8 @@ $strchat = get_string("modulename", "chat"); shortname: $chat->name" ?> - - + + diff --git a/mod/chat/lib.php b/mod/chat/lib.php index ec7397a9af..a0c80f4213 100644 --- a/mod/chat/lib.php +++ b/mod/chat/lib.php @@ -34,7 +34,8 @@ function chat_add_instance($chat) { $chat->timemodified = time(); - # May have to add extra stuff in here # + $chat->chattime = make_timestamp($chat->chatyear, $chat->chatmonth, $chat->chatday, + $chat->chathour, $chat->chatminute); return insert_record("chat", $chat); } @@ -48,7 +49,8 @@ function chat_update_instance($chat) { $chat->timemodified = time(); $chat->id = $chat->instance; - # May have to add extra stuff in here # + $chat->chattime = make_timestamp($chat->chatyear, $chat->chatmonth, $chat->chatday, + $chat->chathour, $chat->chatminute); return update_record("chat", $chat); } @@ -136,6 +138,8 @@ function chat_cron () { global $CFG; + chat_update_chat_times(); + chat_delete_old_users(); /// Delete old messages @@ -185,7 +189,7 @@ function chat_get_latest_message($chatid) { return get_record_sql("SELECT * FROM {$CFG->prefix}chat_messages WHERE chatid = '$chatid' - ORDER BY timestamp DESC"); + ORDER BY timestamp DESC LIMIT 1"); } ////////////////////////////////////////////////////////////////////// @@ -229,6 +233,38 @@ function chat_delete_old_users() { } +function chat_update_chat_times($chatid=0) { +/// Updates chat records so that the next chat time is correct + + $timenow = time(); + if ($chatid) { + if (!$chats[] = get_record_select("chat", "id = '$chatid' AND chattime <= '$timenow' AND schedule > '0'")) { + return; + } + } else { + if (!$chats = get_records_select("chat", "chattime <= '$timenow' AND schedule > '0'")) { + return; + } + } + + foreach ($chats as $chat) { + switch ($chat->schedule) { + case 1: // Single event - turn off schedule and disable + $chat->chattime = 0; + $chat->schedule = 0; + break; + case 2: // Repeat daily + $chat->chattime += 24 * 3600; + break; + case 3: // Repeat weekly + $chat->chattime += 7 * 24 * 3600; + break; + } + update_record("chat", $chat); + } +} + + function chat_browser_detect($HTTP_USER_AGENT) { if(eregi("(opera) ([0-9]{1,2}.[0-9]{1,3}){0,1}", $HTTP_USER_AGENT, $match) diff --git a/mod/chat/mod.html b/mod/chat/mod.html index a225e1051f..947ae65c56 100644 --- a/mod/chat/mod.html +++ b/mod/chat/mod.html @@ -38,6 +38,25 @@ + +

: + chattime); + echo " - "; + print_time_selector("chathour", "chatminute", $form->chattime); + ?> + + +

: + schedule, "", "", ""); + ?> +

:

diff --git a/mod/chat/version.php b/mod/chat/version.php index 0e3ad435c4..32d0580099 100644 --- a/mod/chat/version.php +++ b/mod/chat/version.php @@ -5,7 +5,7 @@ /// This fragment is called by moodle_needs_upgrading() and /admin/index.php ///////////////////////////////////////////////////////////////////////////////// -$module->version = 2003072102; // The (date) version of this module +$module->version = 2003072500; // The (date) version of this module $module->cron = 300; // How often should cron check this module (seconds)? ?> diff --git a/mod/chat/view.php b/mod/chat/view.php index 2e7c006952..b55c125783 100644 --- a/mod/chat/view.php +++ b/mod/chat/view.php @@ -16,12 +16,16 @@ if (! $course = get_record("course", "id", $cm->course)) { error("Course is misconfigured"); } + + chat_update_chat_times($cm->instance); if (! $chat = get_record("chat", "id", $cm->instance)) { error("Course module is incorrect"); } } else { + chat_update_chat_times($c); + if (! $chat = get_record("chat", "id", $c)) { error("Course module is incorrect"); } @@ -48,6 +52,7 @@ $strenterchat = get_string("enterchat", "chat"); $stridle = get_string("idle", "chat"); $strcurrentusers = get_string("currentusers", "chat"); + $strnextsession = get_string("nextsession", "chat"); print_header("$course->shortname: $chat->name", "$course->fullname", "$navigation id>$strchats -> $chat->name", @@ -86,9 +91,19 @@ "chat$course->id$chat->id", "$strenterchat", 500, 700, $strchat); print_simple_box_end(); - echo "
"; - print_simple_box( text_to_html($chat->intro) , "center"); - echo "
"; + + if ($chat->chattime and $chat->schedule) { // A chat is scheduled + echo "

$strnextsession: ".userdate($chat->chattime)."

"; + } else { + echo "
"; + } + + if ($chat->intro) { + print_simple_box( text_to_html($chat->intro) , "center"); + echo "
"; + } + + chat_delete_old_users(); if ($chatusers = chat_get_users($chat->id)) { $timenow = time(); -- 2.39.5