]> git.mjollnir.org Git - moodle.git/commitdiff
New feature - chat scheduling. Can now set a time for the next chat,
authormoodler <moodler>
Fri, 25 Jul 2003 06:47:06 +0000 (06:47 +0000)
committermoodler <moodler>
Fri, 25 Jul 2003 06:47:06 +0000 (06:47 +0000)
as well as rotating weekly or daily period.

Also some small fixes.

lang/en/chat.php
mod/chat/db/mysql.php
mod/chat/db/mysql.sql
mod/chat/gui_header_js/index.php
mod/chat/lib.php
mod/chat/mod.html
mod/chat/version.php
mod/chat/view.php

index 47ce645a5acb482e55cfd88fbaf21ad8d17c5504..39222eb7f6cbe024570d99b785fd1b10914b71c0 100644 (file)
@@ -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";
 
 ?>
index 79e9f94f6262878c11dc14c4af30e0e10d9dd948..57c0ca7f304af53694f17067a6ad7ba427118bc0 100644 (file)
@@ -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;
 }
 
index 44ee87b4cefd0101f12da7b2a95bef20ea47c0e1..dde169848b00d9d32d15385f9e3704f95e22c33a 100644 (file)
@@ -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';
index 1e01d66c0dee131f0ba1be1d17a1e9c974362428..f19e37b4be9e7b2ad57b128aa9112775e33e70e9 100644 (file)
@@ -30,8 +30,8 @@ $strchat = get_string("modulename", "chat");
    <?php echo "$strchat: $course->shortname: $chat->name" ?>
   </title>
  </head>
- <frameset cols="*,200" border="4" framespacing="no" frameborder="yes" marginwidth="2" marginheight="1">
-  <frameset rows="1,1,*,40" border="0" framespacing="no" frameborder="no" marginwidth="2" marginheight="1">
+ <frameset cols="*,200" border="5" framespacing="no" frameborder="yes" marginwidth="2" marginheight="1">
+  <frameset rows="0,0,*,40" border="0" framespacing="no" frameborder="no" marginwidth="2" marginheight="1">
    <frame src="../empty.php" NAME="empty" scrolling="no" marginwidth="0" marginheight="0">
    <frame src="jsupdate.php?chat_sid=<?php echo $chat_sid; ?>&chat_enter=true" scrolling="no" marginwidth="0" marginheight="0">
    <frame src="chatmsg.php" NAME="msg" scrolling="auto" marginwidth="2" marginheight="1">
index ec7397a9afd69ac4fab91d88bcac332dd1f57810..a0c80f4213f5263f9f2b4f1b88b92d24e2c8429a 100644 (file)
@@ -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)
index a225e1051fee949e64a5cc57cbfe8b1628577352..947ae65c56b1c3211183a2ad157f5aaf75b1899c 100644 (file)
         <textarea name="intro" rows=4 cols=50 wrap="virtual"><?php p($form->intro) ?></textarea>
     </td>
 </tr>
+<tr valign=top>
+    <td align=right><p><b><?php print_string("chattime", "chat") ?>:</b></td>
+    <td><?php
+           print_date_selector("chatday", "chatmonth", "chatyear", $form->chattime);
+           echo "&nbsp;-&nbsp;";
+           print_time_selector("chathour", "chatminute", $form->chattime);
+    ?></td>
+</tr>
+<tr valign=top>
+    <td align=right><p><b><?php print_string("repeattimes", "chat") ?>:</b></td>
+    <td><?php
+       unset($options);
+       $options[0]  = get_string("donotusechattime", "chat");
+       $options[1]  = get_string("repeatnone", "chat");
+       $options[2]  = get_string("repeatdaily", "chat");
+       $options[3]  = get_string("repeatweekly", "chat");
+       choose_from_menu ($options, "schedule", $form->schedule, "", "", "");
+    ?></td>
+</tr>
 <tr valign=top>
        <td align=right><p><b><?php print_string("savemessages", "chat")?>:</b></p>
        <td>
index 0e3ad435c45f2ad7930fbf1359a3495b8bbb970b..32d0580099cb13473481fcdc1a228af37414c62e 100644 (file)
@@ -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)?
 
 ?>
index 2e7c006952f421a512ebe06ab69e656a72896e11..b55c1257836826decf0ba75a6fcbb117f559f8d8 100644 (file)
         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 <A HREF=index.php?id=$course->id>$strchats</A> -> $chat->name", 
                           "chat$course->id$chat->id", "$strenterchat", 500, 700, $strchat);
     print_simple_box_end();
 
-    echo "<br />";
-    print_simple_box( text_to_html($chat->intro) , "center");
-    echo "<br />";
+
+    if ($chat->chattime and $chat->schedule) {  // A chat is scheduled
+        echo "<p align=center>$strnextsession: ".userdate($chat->chattime)."</p>";
+    } else {
+        echo "<br />";
+    }
+
+    if ($chat->intro) {
+        print_simple_box( text_to_html($chat->intro) , "center");
+        echo "<br />";
+    }
+
+    chat_delete_old_users();
 
     if ($chatusers = chat_get_users($chat->id)) {
         $timenow = time();