]> git.mjollnir.org Git - moodle.git/commitdiff
Very early version of new chat module, made by Martin using ARSC as
authormoodler <moodler>
Mon, 7 Jul 2003 06:44:16 +0000 (06:44 +0000)
committermoodler <moodler>
Mon, 7 Jul 2003 06:44:16 +0000 (06:44 +0000)
an inspiration.

Works OK already on most newish browsers .. see mod/chat/README.txt for details.

31 files changed:
lang/en/chat.php [new file with mode: 0644]
mod/chat/README.txt [new file with mode: 0644]
mod/chat/db/mysql.php [new file with mode: 0644]
mod/chat/db/mysql.sql [new file with mode: 0644]
mod/chat/drawboard.php [new file with mode: 0644]
mod/chat/empty.php [new file with mode: 0644]
mod/chat/gui_header/chatinput.php [new file with mode: 0644]
mod/chat/gui_header/chatmsg.php [new file with mode: 0644]
mod/chat/gui_header/index.php [new file with mode: 0644]
mod/chat/gui_header_js/chatinput.php [new file with mode: 0644]
mod/chat/gui_header_js/chatmsg.php [new file with mode: 0644]
mod/chat/gui_header_js/index.php [new file with mode: 0644]
mod/chat/gui_header_js/jsupdate.php [new file with mode: 0644]
mod/chat/gui_java/MainFrameGui.java [new file with mode: 0644]
mod/chat/gui_java/TextDialog.java [new file with mode: 0644]
mod/chat/gui_java/arsc.java [new file with mode: 0644]
mod/chat/gui_push_js/chatinput.php [new file with mode: 0644]
mod/chat/gui_push_js/chatmsg.php [new file with mode: 0644]
mod/chat/gui_push_js/index.php [new file with mode: 0644]
mod/chat/gui_sockets/arscd.php [new file with mode: 0644]
mod/chat/gui_sockets/chatinput.php [new file with mode: 0644]
mod/chat/gui_sockets/index.php [new file with mode: 0644]
mod/chat/gui_text/index.php [new file with mode: 0644]
mod/chat/icon.gif [new file with mode: 0755]
mod/chat/index.php [new file with mode: 0644]
mod/chat/insert.php [new file with mode: 0644]
mod/chat/lib.php [new file with mode: 0644]
mod/chat/mod.html [new file with mode: 0644]
mod/chat/users.php [new file with mode: 0644]
mod/chat/version.php [new file with mode: 0644]
mod/chat/view.php [new file with mode: 0644]

diff --git a/lang/en/chat.php b/lang/en/chat.php
new file mode 100644 (file)
index 0000000..4c1d85f
--- /dev/null
@@ -0,0 +1,15 @@
+<?PHP // $Id$
+
+#------------------------------------------------------------
+$string['modulename'] = "Chat";
+$string['modulenameplural'] = "Chats";
+#------------------------------------------------------------
+
+$string['chatintro'] = "Introduction text";
+$string['chatname'] = "Name of this chat room";
+$string['enterchat'] = "Click here to enter the chat";
+$string['messageenter'] = "\$a has just entered this chat";
+$string['savemessages'] = "Number of messages to save";
+$string['strftimemessage'] = "%%H:%%M";
+
+?>
diff --git a/mod/chat/README.txt b/mod/chat/README.txt
new file mode 100644 (file)
index 0000000..c613422
--- /dev/null
@@ -0,0 +1,29 @@
+Official Chat Module for Moodle
+------------------------------
+
+Version 0.1  (for Moodle 1.1)
+
+This module is still very new and very incomplete compared
+to the version that will be shipping with Moodle 1.1
+
+It's based in part on ARSC but I ended up rewriting so much 
+of it there's hardly a line of code in use that has not
+been changed, so perhaps it's *inspired* by ARSC.
+
+It's fairly useful already and should work with most newer browers.
+
+Note it supports user images, smilies and even HTML already.
+
+Things to do yet:
+
+  - fix up the other chat front-end version (currently only using 
+    header_js)
+
+  - make the socket server work
+
+  - more useful shortcuts in the user interface
+
+  - postgresql support (db schema)
+
+
+Martin, 7 July 2003
diff --git a/mod/chat/db/mysql.php b/mod/chat/db/mysql.php
new file mode 100644 (file)
index 0000000..fe9b6d3
--- /dev/null
@@ -0,0 +1,17 @@
+<?PHP // $Id$
+
+function chat_upgrade($oldversion) {
+// This function does anything necessary to upgrade
+// older versions to match current functionality
+
+    global $CFG;
+
+    if ($oldversion < 2002080500) {
+    }
+
+    return true;
+}
+
+
+?>
+
diff --git a/mod/chat/db/mysql.sql b/mod/chat/db/mysql.sql
new file mode 100644 (file)
index 0000000..1dd573b
--- /dev/null
@@ -0,0 +1,55 @@
+#
+# Table structure for table `chat`
+#
+
+CREATE TABLE `prefix_chat` (
+  `id` int(10) unsigned NOT NULL auto_increment,
+  `course` int(10) unsigned NOT NULL default '0',
+  `name` varchar(255) NOT NULL default '',
+  `intro` text NOT NULL,
+  `messages` int(11) NOT NULL default '1000',
+  `timemodified` int(10) unsigned NOT NULL default '0',
+  PRIMARY KEY  (`id`)
+) TYPE=MyISAM COMMENT='Each of these is a chat room';
+# --------------------------------------------------------
+
+#
+# Table structure for table `chat_messages`
+#
+
+CREATE TABLE `prefix_chat_messages` (
+  `id` int(10) unsigned NOT NULL auto_increment,
+  `chatid` int(10) NOT NULL default '0',
+  `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',
+  PRIMARY KEY  (`id`),
+  KEY `timemodifiedchat` (`timestamp`,`chatid`)
+) TYPE=MyISAM COMMENT='Stores all the actual chat messages';
+# --------------------------------------------------------
+
+#
+# Table structure for table `chat_users`
+#
+
+CREATE TABLE `prefix_chat_users` (
+  `id` int(10) unsigned NOT NULL auto_increment,
+  `chatid` int(11) NOT NULL default '0',
+  `userid` int(11) NOT NULL default '0',
+  `version` varchar(16) NOT NULL default '',
+  `ip` varchar(15) NOT NULL default '',
+  `firstping` int(10) unsigned NOT NULL default '0',
+  `lastping` int(10) unsigned NOT NULL default '0',
+  `lastmessageping` int(10) unsigned NOT NULL default '0',
+  `sid` varchar(32) NOT NULL default '',
+  PRIMARY KEY  (`id`),
+  KEY `userid` (`userid`),
+  KEY `lastping` (`lastping`)
+) TYPE=MyISAM COMMENT='Keeps track of which users are in which chat rooms';
+
+
+INSERT INTO prefix_log_display VALUES ('chat', 'view', 'chat', 'name');
+INSERT INTO prefix_log_display VALUES ('chat', 'add', 'chat', 'name');
+INSERT INTO prefix_log_display VALUES ('chat', 'update', 'chat', 'name');
+
diff --git a/mod/chat/drawboard.php b/mod/chat/drawboard.php
new file mode 100644 (file)
index 0000000..5edb4e9
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+
+include("../config.inc.php");
+include("../functions.inc.php");
+
+$arsc_result = mysql_query("SELECT COUNT(*) AS anzahl FROM arsc_users WHERE sid = '$arsc_sid'");
+$arsc_a = mysql_fetch_array($arsc_result);
+if ($arsc_a["anzahl"] == 1)
+{
+ ?>
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
+ <html>
+  <head>
+   <title>
+    Abacho - Drawboard
+   </title>
+  </head>
+  <body bgcolor="#000000" topmargin="0" leftmargin="0" marginleft="0" margintop="0">
+   <APPLET CODE="drawboard/Main.class" WIDTH="<?php echo $arsc_parameters["drawboard_width"]; ?>" HEIGHT="<?php echo $arsc_parameters["drawboard_height"]; ?>">
+    <param name="port" value="<?php echo $arsc_parameters["drawboard_port"]; ?>">
+    <param name="bgcolor" value="FFFFFF">
+    <PARAM NAME="menubgcolor" VALUE="FAE6A6">
+    <PARAM NAME="emptythumbnailcolor" VALUE="FDF0C6">
+    <PARAM NAME="countercolor" VALUE="000000">
+    <param name="pencolor" value="0000FF">
+    <PARAM NAME="skindef" VALUE="abacho/abacho.def">
+    Unfortunatelly, your browser doesn't support Java applets. You have to use another one.
+   </APPLET>
+  </body>
+ </html>
+ <?php
+}
+else
+{
+ header("Location: ../shared/empty.php");
+ die();
+}
+?>
\ No newline at end of file
diff --git a/mod/chat/empty.php b/mod/chat/empty.php
new file mode 100644 (file)
index 0000000..c06c35e
--- /dev/null
@@ -0,0 +1,9 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
+<html>
+ <head>
+  <title>
+  </title>
+ </head>
+ <body bgcolor="#FFFFFF">
+ </body>
+</html>
diff --git a/mod/chat/gui_header/chatinput.php b/mod/chat/gui_header/chatinput.php
new file mode 100644 (file)
index 0000000..24f6c3e
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+
+include("../config.inc.php");
+include("../functions.inc.php");
+
+if ($arsc_my = arsc_getdatafromsid($arsc_sid))
+{
+ include("../shared/language/".$arsc_my["language"].".inc.php");
+ if ($arsc_my["level"] >= 0)
+ {
+  echo $arsc_parameters["htmlhead_msginput"];
+  ?>
+    <form action="../shared/chatins.php" METHOD="POST" name="f">
+     <input type="hidden" name="arsc_sid" value="<?php echo $arsc_sid; ?>">
+     <input type="hidden" name="arsc_chatversion" value="header">
+     <input type="text" name="arsc_message" size="50" maxlength="<?php echo $arsc_parameters["input_maxsize"]; ?>" value="<?php echo $arsc_pretext; ?>">
+     <input type="submit" value="<?php echo $arsc_lang["sendmessage"]; ?>">
+    </form>
+   </body>
+  </html>
+  <?php
+ }
+ else
+ {
+  echo $arsc_parameters["htmlhead_out"];
+ }
+}
+else
+{
+ echo $arsc_parameters["htmlhead_out"];
+}
+?>
diff --git a/mod/chat/gui_header/chatmsg.php b/mod/chat/gui_header/chatmsg.php
new file mode 100644 (file)
index 0000000..635188d
--- /dev/null
@@ -0,0 +1,74 @@
+<?php
+
+include("../config.inc.php");
+include("../functions.inc.php");
+include("../filter.inc.php");
+
+if ($arsc_my = arsc_getdatafromsid($arsc_sid))
+{
+ include("../shared/language/".$arsc_my["language"].".inc.php");
+ $arsc_user = $arsc_my["user"];
+ $arsc_room = $arsc_my["room"];
+ if ($arsc_lastid == "")
+ {
+  $arsc_result = mysql_query("SELECT * from arsc_room_$arsc_room ORDER BY timeid DESC");
+  $arsc_b = mysql_fetch_array($arsc_result);
+  $arsc_lastid = $arsc_b["timeid"];
+ }
+ if ($arsc_my["level"] < 0)
+ {
+  switch($arsc_my["level"])
+  {
+   case "-1": $arsc_message = $arsc_lang["youwerekicked"];
+              mysql_query("DELETE from arsc_users WHERE sid = '$arsc_sid'");
+              break;
+  }
+  header("Expires: Sun, 28 Dec 1997 09:32:45 GMT");
+  header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
+  header("Cache-Control: no-cache, must-revalidate");
+  header("Pragma: no-cache");
+  header("Content-Type: text/html");
+  echo $arsc_parameters["htmlhead"];
+  echo arsc_filter_posting("System", date("H:i:s"), "<font size=\"4\"><b>".$arsc_message."</b></font>", $arsc_room, 0);
+  ?>
+   </body>
+  </html>
+  <?php
+ }
+ else
+ {
+  header("Expires: Sun, 28 Dec 1997 09:32:45 GMT");
+  header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
+  header("Cache-Control: no-cache, must-revalidate");
+  header("Pragma: no-cache");
+  header("Content-Type: text/html");
+  header("Refresh: 4; URL=chatmsg.php?arsc_sid=".$arsc_sid."&arsc_lastid=".$arsc_lastid."&dummy=".time()."#end");
+  echo $arsc_parameters["htmlhead"];
+  
+  set_magic_quotes_runtime(0);
+  $arsc_sendtime = date("H:i:s");
+  $arsc_timeid = arsc_microtime();
+  $arsc_message = "/msg ".$arsc_my["user"]." ".$arsc_lang["welcome"];
+  echo arsc_filter_posting("System", $arsc_sendtime, $arsc_message, $arsc_room, 0);
+  $arsc_result = mysql_query("SELECT * FROM arsc_room_$arsc_room WHERE timeid > '$arsc_lastid' ORDER BY timeid ASC");
+  while ($arsc_a = mysql_fetch_array($arsc_result))
+  {
+   echo arsc_filter_posting($arsc_a["user"], $arsc_a["sendtime"], $arsc_a["message"], $arsc_room, $arsc_a["flag_ripped"])."\n";
+  }
+  $arsc_ping = time();
+  $arsc_ip = getenv("REMOTE_ADDR");
+  mysql_query("UPDATE arsc_users SET lastping = '$arsc_ping', ip = '$arsc_ip' WHERE user = '$arsc_user'");
+  ?>
+    <a name="end"></a>
+   </body>
+  </html>
+  <?php
+ }
+}
+else
+{
+ echo $arsc_parameters["htmlhead_out"];
+}
+?>
diff --git a/mod/chat/gui_header/index.php b/mod/chat/gui_header/index.php
new file mode 100644 (file)
index 0000000..ffaf827
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+include("../config.inc.php");
+include("../functions.inc.php");
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
+<html>
+ <head>
+  <title>
+   ARSC - ARSC Really Simple Chat
+  </title>
+ </head>
+ <frameset cols="193,*,120" border="0" framespacing="no" frameborder="0" marginwidth="2" marginheight="1">
+  <frame src="../shared/roomlist.php?arsc_sid=<?php echo $arsc_sid; ?>" name="roomlist" scrolling="auto" noresize marginwidth="0" marginheight="0">
+  <frameset rows="*,40" border="1" framespacing="no" frameborder="0" marginwidth="2" marginheight="1">
+   <frame src="chatmsg.php?arsc_sid=<?php echo $arsc_sid; ?>#end" NAME="msg" scrolling="auto" noresize marginwidth="2" marginheight="1">
+   <frame src="chatinput.php?arsc_sid=<?php echo $arsc_sid; ?>" name="input"  scrolling="no" noresize marginwidth="2" marginheight="1">
+  </frameset>
+  <frame src="../shared/userlist.php?arsc_sid=<?php echo $arsc_sid; ?>&arsc_enter=true" name="users" scrolling="auto" noresize marginwidth="5" marginheight="5">
+ </frameset>
+ <noframes>
+  Sorry, this version of ARSC needs a browser that understands framesets. We have a Lynx friendly version too.
+ </noframes>
+</html>
diff --git a/mod/chat/gui_header_js/chatinput.php b/mod/chat/gui_header_js/chatinput.php
new file mode 100644 (file)
index 0000000..6f8d19d
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+
+require("../../../config.php");
+require("../lib.php");
+
+if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
+    echo "Not logged in!";
+}
+
+?>
+<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">
+<html>
+<head>
+<title>Message Input</title>
+<script language="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();
+    return false;
+}
+// -->
+</script>
+</head>
+
+<body bgcolor="<?php echo $THEME->body ?>" 
+      OnLoad="document.f.chat_message.focus();document.f.chat_message.select();">
+
+
+<form action="../insert.php" method="GET" target="empty" name="f" 
+      OnSubmit="return empty_field_and_submit()">
+&gt;&gt;<input type="text" name="chat_message" size="60" value="<?php echo $chat_pretext; ?>">
+</form>
+
+<form action="../insert.php" method="GET" target="empty" name="fdummy" 
+      OnSubmit="return empty_field_and_submit()">
+    <input type="hidden" name="chat_sid" value="<?php echo $chat_sid; ?>">
+    <input type="hidden" name="chat_version" value="header_js">
+    <input type="hidden" name="chat_message">
+</form>
+
+</body>
+
+</html>
diff --git a/mod/chat/gui_header_js/chatmsg.php b/mod/chat/gui_header_js/chatmsg.php
new file mode 100644 (file)
index 0000000..678b075
--- /dev/null
@@ -0,0 +1,2 @@
+<html>
+<body>
diff --git a/mod/chat/gui_header_js/index.php b/mod/chat/gui_header_js/index.php
new file mode 100644 (file)
index 0000000..169f5a4
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+
+require_once('../../../config.php');
+require_once('../lib.php');
+
+require_variable($id);
+
+if (!$chat = get_record("chat", "id", $id)) {
+    error("Could not find that chat room!");
+}
+
+if (!$course = get_record("course", "id", $chat->course)) {
+    error("Could not find the course this belongs to!");
+}
+
+if (!$chat_sid = chat_login_user($chat->id, "header_js")) {
+    error("Could not log in to chat room!!");
+}
+
+$strchat = get_string("modulename", "chat");
+
+
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
+<html>
+ <head>
+  <title>
+   <?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">
+   <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">
+   <frame src="chatinput.php?chat_sid=<?php echo $chat_sid; ?>" name="input" scrolling="no" marginwidth="2" marginheight="1">
+  </frameset>
+  <frame src="../users.php?chat_sid=<?php echo $chat_sid; ?>&chat_enter=true" name="users" scrolling="auto" marginwidth="5" marginheight="5">
+ </frameset>
+ <noframes>
+  Sorry, this version of ARSC needs a browser that understands framesets. We have a Lynx friendly version too.
+ </noframes>
+</html>
diff --git a/mod/chat/gui_header_js/jsupdate.php b/mod/chat/gui_header_js/jsupdate.php
new file mode 100644 (file)
index 0000000..90de60e
--- /dev/null
@@ -0,0 +1,58 @@
+<?php
+
+require("../../../config.php");
+require("../lib.php");
+
+if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
+    echo "Not logged in!";
+}
+
+if ($message = chat_get_latest_message($chatuser->chatid)) {
+    $chat_newlasttime = $message->timestamp;
+} else {
+    $chat_newlasttime = 0;
+}
+
+if (empty($chat_lasttime)) {
+    $chat_lasttime = 0;
+}
+
+
+header("Expires: Sun, 28 Dec 1997 09:32:45 GMT");
+header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
+header("Cache-Control: no-cache, must-revalidate");
+header("Pragma: no-cache");
+header("Content-Type: text/html");
+header("Refresh: 4; URL=jsupdate.php?chat_sid=".$chat_sid."&chat_lasttime=".$chat_newlasttime);
+
+?>
+  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
+  <html>
+   <head>
+    <script language="Javascript">
+    <!--
+<?php
+     if ($chat_lasttime) {
+         if ($messages = get_records_select("chat_messages", 
+                                            "chatid = '$chatuser->chatid' AND timestamp > '$chat_lasttime'", 
+                                            "timestamp ASC")) {
+             foreach ($messages as $message) {
+                 $formatmessage = chat_format_message($message->userid, $message->chatid, 
+                                                      $message->timestamp, $message->message, $message->system);
+?>
+                 parent.msg.document.write('<?php echo $formatmessage ?>\n');
+<?php
+             }
+         }
+     }
+
+     $chatuser->lastping = time();
+     update_record("chat_users", $chatuser);
+     ?>
+     parent.msg.scroll(1,5000000);
+    // -->
+    </script>
+   </head>
+   <body bgcolor="<?php echo $THEME->body ?>">
+   </body>
+  </html>
diff --git a/mod/chat/gui_java/MainFrameGui.java b/mod/chat/gui_java/MainFrameGui.java
new file mode 100644 (file)
index 0000000..53c292b
--- /dev/null
@@ -0,0 +1,177 @@
+import java.awt.*;
+import java.awt.event.*;
+
+public class MainFrameGui
+extends Frame
+{
+ public static TextArea messages;
+ public static TextField eingabe;
+ public static List userliste;
+ public static Checkbox cb;
+ public static Button hilfebutton;
+ public static GridBagConstraints makegbc;
+ public static TextDialog hilfedialog;
+ public static MenuBar menu;
+ public MainFrameGui()
+ {
+  super ("ARSC Really Simple Chat");
+  setBackground(Color.lightGray);
+  addWindowListener(new WindowClosingAdapter(true));
+  
+  //Menü
+  MenuBar menu = new MenuBar();
+   Menu menuConnection = new Menu("Connection");
+    menuConnection.add("Connect to server");
+    menuConnection.add("Disconnect from server");
+    menuConnection.add("Quit");
+   Menu menuConfiguration = new Menu("Configuration");
+   Menu menuHelp = new Menu("Help");
+    MenuItem mi = new MenuItem("Show commands");
+    mi.addActionListener(new hilfebuttonListener());
+    menuHelp.add(mi);
+    menuHelp.add("About...");
+   menu.add(menuConnection);
+   menu.add(menuConfiguration);
+   menu.add(menuHelp);
+  
+  setMenuBar(menu);
+  
+  //Layout setzen und Komponenten hinzufügen
+  GridBagLayout gbl = new GridBagLayout();
+  GridBagConstraints gbc;
+  setLayout(gbl);
+  
+  //TextArea hinzufügen
+  messages = new TextArea("", 20, 20, TextArea.SCROLLBARS_VERTICAL_ONLY);
+  gbc = makegbc(0, 0, 2, 2);
+  gbc.weightx = 100;
+  gbc.weighty = 100;
+  gbc.fill = GridBagConstraints.BOTH;
+  gbl.setConstraints(messages, gbc);
+  add(messages);
+  
+  //Userliste
+  userliste = new List();
+  userliste.add("pgod");
+  userliste.add("HanSolo");
+  userliste.add("dArUdE");
+  gbc = makegbc(2, 0, 2, 2);
+  gbc.fill = GridBagConstraints.BOTH;
+  gbl.setConstraints(userliste, gbc);
+  userliste.addActionListener(new userlisteListener());
+  add(userliste);
+  
+  //Eingabefeld
+  eingabe = new TextField();
+  gbc = makegbc(0, 2, 1, 1);
+  gbc.weightx = 100;
+  gbc.fill = GridBagConstraints.HORIZONTAL;
+  gbc.anchor = GridBagConstraints.SOUTH;
+  gbl.setConstraints(eingabe, gbc);
+  eingabe.addActionListener(new eingabeListener());
+  add(eingabe);
+
+  //Checkbox
+  cb = new Checkbox("Scrolling");
+  cb.setState(true);
+  gbc = makegbc(1, 2, 1, 1);
+  gbc.fill = GridBagConstraints.NONE;
+  gbc.anchor = GridBagConstraints.SOUTH;
+  gbl.setConstraints(cb, gbc);
+  add(cb);
+  
+  //Hilfebutton
+  hilfebutton = new Button("Help");
+  gbc = makegbc(2, 2, 1, 1);
+  gbc.fill = GridBagConstraints.NONE;
+  gbc.anchor = GridBagConstraints.WEST;
+  gbl.setConstraints(hilfebutton, gbc);
+  hilfebutton.addActionListener(new hilfebuttonListener());
+  add(hilfebutton);
+  //Gib ihm
+  pack();
+  hilfedialog = new TextDialog(this, "Hilfe", "Hilfe\nLala\nLulu...", "Schliessen", false, 200, 400);
+ }
+ //Die Listener
+ public class eingabeListener
+ implements ActionListener
+ {
+  public void actionPerformed(ActionEvent event)
+  {
+   System.out.println("Event erhalten");
+   TextField source = (TextField)event.getSource();
+   messages.append("\n" + source.getText());
+   source.selectAll();
+  }
+ }
+
+ public class userlisteListener
+ implements ActionListener
+ {
+  public void actionPerformed(ActionEvent event)
+  {
+   System.out.println("userliste Event erhalten");
+   List source = (List)event.getSource();
+   eingabe.setText("/msg " + source.getSelectedItem() + " ");
+   eingabe.setCaretPosition(99);
+   eingabe.requestFocus();
+  }
+ }
+
+ public class hilfebuttonListener
+ implements ActionListener
+ {
+  public void actionPerformed(ActionEvent event)
+  {
+   System.out.println("hilfebutton Event erhalten");
+   if(getToolkit().getScreenSize().width - (getBounds().x + getBounds().width) >= hilfedialog.getSize().width)
+   {
+    hilfedialog.setLocation(getBounds().x + getBounds().width, getBounds().y);
+   }
+   else
+   {
+    hilfedialog.setLocation(getToolkit().getScreenSize().width - hilfedialog.getSize().width, getBounds().y);
+   }
+   hilfedialog.setVisible(true);
+  }
+ }
+
+ public class WindowClosingAdapter
+ extends WindowAdapter
+ {
+  private boolean exitSystem;
+  
+  public WindowClosingAdapter(boolean exitSystem)
+  {
+   this.exitSystem = exitSystem;
+  }
+  
+  public WindowClosingAdapter()
+  {
+   this(true);
+  }
+  
+  public void windowClosing(WindowEvent event)
+  {
+   event.getWindow().setVisible(false);
+   event.getWindow().dispose();
+   if (exitSystem)
+   {
+    System.exit(0);
+   }
+  }
+ }
+ public static GridBagConstraints makegbc(int x, int y, int width, int height)
+ {
+  GridBagConstraints gbc = new GridBagConstraints();
+  gbc.gridx = x;
+  gbc.gridy = y;
+  gbc.gridwidth = width;
+  gbc.gridheight = height;
+  gbc.insets = new Insets(1, 1, 1, 1);
+  return gbc;
+ }
+}
diff --git a/mod/chat/gui_java/TextDialog.java b/mod/chat/gui_java/TextDialog.java
new file mode 100644 (file)
index 0000000..52e3a12
--- /dev/null
@@ -0,0 +1,68 @@
+import java.awt.*;
+import java.awt.event.*;
+
+public class TextDialog
+extends Dialog
+implements ActionListener
+{
+ public TextDialog(Frame owner, String title, String textAreaText, String buttonText, boolean modal, int sizeX, int sizeY)
+ {
+  super(owner, title, modal);
+  setBackground(Color.lightGray);
+  setLocation(getToolkit().getScreenSize().width - sizeY, 0);
+  
+  //Layout setzen und Komponenten hinzufügen
+  GridBagLayout gbl = new GridBagLayout();
+  GridBagConstraints gbc;
+  setLayout(gbl);
+  
+  //TextArea hinzufügen
+  TextArea text = new TextArea(textAreaText, 1, 1, TextArea.SCROLLBARS_VERTICAL_ONLY);
+  gbc = MainFrameGui.makegbc(0, 0, 1, 1);
+  gbc.weightx = 100;
+  gbc.weighty = 100;
+  gbc.fill = GridBagConstraints.BOTH;
+  gbl.setConstraints(text, gbc);
+  add(text);
+  
+  //Button
+  Button button = new Button(buttonText);
+  gbc = MainFrameGui.makegbc(0, 1, 1, 1);
+  gbc.fill = GridBagConstraints.NONE;
+  gbc.anchor = GridBagConstraints.SOUTH;
+  gbl.setConstraints(button, gbc);
+  button.addActionListener(this);
+  add(button);
+
+  pack();
+  setSize(sizeX, sizeY);
+ }
+ public void actionPerformed(ActionEvent event)
+ {
+  int i = getSize().height;
+  int j = i / 20;
+  int oldWidth = getSize().width;
+  int oldHeight = getSize().height;
+  
+  System.out.println(i + " - " + j);
+  
+  while(i > -1)
+  {
+   //System.out.println(i);
+   setSize(getSize().width, i);
+   try
+   {
+    Thread.sleep(5);
+   }
+   catch (InterruptedException e)
+   {
+    //nix
+   }
+   i = i - j;
+  }
+  setVisible(false);
+  setSize(oldWidth, oldHeight);
+  dispose();
+ }
+}
diff --git a/mod/chat/gui_java/arsc.java b/mod/chat/gui_java/arsc.java
new file mode 100644 (file)
index 0000000..b45a6b4
--- /dev/null
@@ -0,0 +1,90 @@
+import java.awt.*;
+import java.awt.event.*;
+import java.net.*;
+import java.io.*;
+import java.sql.*;
+import java.util.*;
+
+public class arsc
+{
+ static String DBUrl = "jdbc:mysql://194.231.30.146/arscdev?user=user&password=password";
+ static String arsc_sid = "dhndewbz2798z23dzdewßdew";
+
+ public static void main(String[] args)
+ {
+  MainFrameGui gui = new MainFrameGui();
+  gui.setSize(480,300);
+  gui.setVisible(true);
+  
+  try
+  {
+   try
+   {
+    Class.forName("org.gjt.mm.mysql.Driver").newInstance();
+   }
+   catch (Exception e)
+   {
+    System.err.println(e.toString());
+   }
+   
+   Connection conn = null;
+   Statement stmt = null;
+   PreparedStatement pStmt = null;
+  
+   conn = DriverManager.getConnection(DBUrl);
+   stmt = conn.createStatement();
+   stmt.executeUpdate("INSERT INTO arsc_users (id, user, lastping, ip, room, language, version, level, sid, lastmessageping) VALUES ('', 'javapgod', '', '', 'lounge', 'german', 'sockets', '1', 'abcdefg', '') ");
+  }
+  catch (SQLException sqlEx) { System.err.println(sqlEx.toString()); }
+
+  try
+  {
+   Thread.sleep(5000);
+  }
+  catch (InterruptedException e)
+  {
+   //nix
+  }
+
+  try
+  {
+   Socket sock = new Socket("194.231.30.146", 12345);
+   BufferedReader in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
+   OutputStream out = sock.getOutputStream();
+   String line = "arsc_sid=abcdefg HTTP";
+   out.write(line.getBytes());
+   out.write('\r');
+   out.write('\n');
+   String blubb = new String();
+   while ((blubb = in.readLine()) != null)
+   {
+    gui.messages.append(blubb);
+   }
+   in.close();
+   out.close();
+   sock.close();
+  }
+  catch (IOException e)
+  {
+   System.err.println(e.toString());
+   //System.exit;
+  }
+  
+  while (true)
+  {
+   try
+   {
+    Thread.sleep(500);
+   }
+   catch (InterruptedException e)
+   {
+    //nix
+   }
+   //gui.messages.append("blah...\n");
+   if (gui.cb.getState() == true)
+   {
+    gui.messages.setCaretPosition(99999999);
+   }
+  }
+ }
+}
diff --git a/mod/chat/gui_push_js/chatinput.php b/mod/chat/gui_push_js/chatinput.php
new file mode 100644 (file)
index 0000000..ac790d5
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+
+include("../config.inc.php");
+include("../functions.inc.php");
+
+if ($arsc_my = arsc_getdatafromsid($arsc_sid))
+{
+ include("../shared/language/".$arsc_my["language"].".inc.php");
+ if ($arsc_my["level"] >= 0)
+ {
+  echo $arsc_parameters["htmlhead_msginput_js"];
+  ?>
+    <form action="../shared/chatins.php" method="GET" target="empty" name="f" OnSubmit="return empty_field_and_submit()">
+     <input type="text" name="arsc_message" size="50" maxlength="<?php echo $arsc_parameters["input_maxsize"]; ?>" value="<?php echo $arsc_pretext; ?>">
+    </form>
+    <form action="../shared/chatins.php" method="GET" target="empty" name="fdummy" OnSubmit="return empty_field_and_submit()">
+     <input type="hidden" name="arsc_sid" value="<?php echo $arsc_sid; ?>">
+     <input type="hidden" name="arsc_chatversion" value="header_js">
+     <input type="hidden" name="arsc_message">
+    </form>
+   </body>
+  </html>
+  <?php
+ }
+ else
+ {
+  echo $arsc_htmlhead_out;
+ }
+}
+else
+{
+ echo $arsc_htmlhead_out;
+}
+?>
diff --git a/mod/chat/gui_push_js/chatmsg.php b/mod/chat/gui_push_js/chatmsg.php
new file mode 100644 (file)
index 0000000..e16e337
--- /dev/null
@@ -0,0 +1,98 @@
+<?php
+
+function arsc_shutdown()
+{
+ GLOBAL $arsc_sid,
+        $arsc_my;
+ if ($arsc_my["user"] <> "")
+ {
+  $arsc_user = $arsc_my["user"];
+  $arsc_room = $arsc_my["room"];
+  $arsc_nice_room = arsc_nice_room($arsc_room);
+  $arsc_timeid = arsc_microtime();
+  $arsc_sendtime = date("H:i:s");
+  mysql_query("DELETE from arsc_users WHERE sid = '$arsc_sid'");
+  mysql_query("INSERT into arsc_room_$arsc_room (message, user, sendtime, timeid) VALUES ('arsc_user_quit~~$arsc_user~~$arsc_nice_room', 'System', '$arsc_sendtime', '$arsc_timeid')");
+ }
+}
+
+register_shutdown_function("arsc_shutdown");
+
+include("../config.inc.php");
+include("../functions.inc.php");
+include("../filter.inc.php");
+
+if ($arsc_my = arsc_getdatafromsid($arsc_sid))
+{
+ include("../shared/language/".$arsc_my["language"].".inc.php");
+
+ $arsc_room = $arsc_my["room"];
+ if ($arsc_lastid == "")
+ {
+  $arsc_result = mysql_query("SELECT * from arsc_room_$arsc_room ORDER BY timeid DESC");
+  $arsc_b = mysql_fetch_array($arsc_result);
+  $arsc_lastid = $arsc_b["timeid"];
+ }
+ echo $arsc_parameters["htmlhead_js"];
+ set_magic_quotes_runtime(0);
+ set_time_limit(0);
+ $arsc_sendtime = date("H:i:s");
+ $arsc_timeid = arsc_microtime();
+ $arsc_message = "/msg ".$arsc_my["user"]." ".$arsc_lang["welcome"];
+ echo arsc_filter_posting("System", $arsc_sendtime, $arsc_message, $arsc_room, 0);
+ $i = 0;
+ while(!connection_aborted())
+ {
+  $arsc_my = arsc_getdatafromsid($arsc_sid);
+  $arsc_room = $arsc_my["room"];
+  if(!$arsc_result = mysql_query("SELECT * from arsc_room_$arsc_room ORDER BY timeid DESC"))
+  {
+   arsc_shutdown();
+   die();
+  }
+  $arsc_b = mysql_fetch_array($arsc_result);
+  if ($arsc_lastid == "")
+  {
+   $arsc_lastid = $arsc_b["timeid"];
+  }
+  $arsc_lastid_save = $arsc_b["timeid"];
+  if ($arsc_my["level"] < 0)
+  {
+   switch($arsc_my["level"])
+   {
+    case "-1": echo arsc_filter_posting("System", date("H:i:s"), "<font size=\"4\"><b>".$arsc_lang["youwerekicked"]."</b></font>", $arsc_room, 0);
+               mysql_query("DELETE from arsc_users WHERE sid = '$arsc_sid'");
+               break;
+   }
+   break;
+  }
+  
+  $i++;
+  $arsc_result = mysql_query("SELECT * from arsc_room_$arsc_room WHERE timeid > '$arsc_lastid' ORDER BY timeid ASC, id ASC");
+  while ($arsc_a = mysql_fetch_array($arsc_result))
+  {
+   $arsc_posting = arsc_filter_posting($arsc_a["user"], $arsc_a["sendtime"], $arsc_a["message"], $arsc_room, $arsc_a["flag_ripped"]);
+   echo "$arsc_posting";
+  }
+  $arsc_lastid = $arsc_lastid_save;
+  $arsc_ping = time();
+  $arsc_ip = getenv("REMOTE_ADDR");
+  mysql_query("UPDATE arsc_users SET lastping = '$arsc_ping', ip = '$arsc_ip' WHERE sid = '$arsc_sid'");
+  echo " ";
+  flush();
+  usleep($arsc_parameters["socketserver_refresh"]);
+  flush();
+  flush();
+  flush();
+  flush();
+  flush();
+  // just to be sure :)
+ }
+}
+else
+{
+ echo $arsc_parameters["htmlhead_out"];
+}
+?>
diff --git a/mod/chat/gui_push_js/index.php b/mod/chat/gui_push_js/index.php
new file mode 100644 (file)
index 0000000..656d18c
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+include("../config.inc.php");
+include("../functions.inc.php");
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
+<html>
+ <head>
+  <title>
+   ARSC - ARSC Really Simple Chat
+  </title>
+ </head>
+ <frameset cols="193,*,120" border="0" framespacing="no" frameborder="0" marginwidth="2" marginheight="1">
+  <frame src="../shared/roomlist.php?arsc_sid=<?php echo $arsc_sid; ?>" name="roomlist" scrolling="auto" noresize marginwidth="0" marginheight="0">
+  <frameset rows="1,*,40" border="1" framespacing="no" frameborder="0" marginwidth="2" marginheight="1">
+   <frame src="../shared/empty.php" NAME="empty" scrolling="no" noresize marginwidth="0" marginheight="0">
+   <frame src="chatmsg.php?arsc_sid=<?php echo $arsc_sid; ?>" NAME="msg" scrolling="auto" noresize marginwidth="2" marginheight="1">
+   <frame src="chatinput.php?arsc_sid=<?php echo $arsc_sid; ?>" name="input"  scrolling="no" noresize marginwidth="2" marginheight="1">
+  </frameset>
+  <frame src="../shared/userlist.php?arsc_sid=<?php echo $arsc_sid; ?>&arsc_enter=true" name="users" scrolling="auto" noresize marginwidth="5" marginheight="5">
+ </frameset>
+ <noframes>
+  Sorry, ARSC needs a browser that understands framesets. We have a Lynx friendly version too.
+ </noframes>
+</html>
diff --git a/mod/chat/gui_sockets/arscd.php b/mod/chat/gui_sockets/arscd.php
new file mode 100644 (file)
index 0000000..25ac0fd
--- /dev/null
@@ -0,0 +1,264 @@
+#!/usr/local/php-cgi/current/bin/php -q
+<?php
+set_time_limit (0);
+set_magic_quotes_runtime(0);
+
+include("../config.inc.php");
+include("../functions.inc.php");
+include("../filter.inc.php");
+
+
+// Checking parameters
+
+if ($argv[1] == "--help" OR $argv[1] == "-h" OR $argv[1] == "/?")
+{
+ echo "Starts the ARSC socket server on port {$arsc_parameters["socketserver_port"]}.";
+ echo "\n\n";
+ echo "Usage: arscd.php [-v|-l|--help]\n\n";
+ echo "Example:\n";
+ echo "  arscd.php -l=/var/log/arsc\n\n";
+ echo "Options:\n";
+ echo "  -v           Verbose mode, print every message every user receives to STDOUT\n";
+ echo "  -l=DIR       Write message logfiles for every room into DIR (creates file for every room)\n";
+ echo "  -h, --help   Show this help\n";
+ echo "\n";
+ echo "For bug reporting, please visit:";
+ echo "<URL:http://manuel.kiessling.net/projects/software/arsc/bugs/>.\n";
+ die();
+}
+$arsc_logdir = false;
+if (ereg("-l=", $argv[1]))
+{
+ if (is_dir(str_replace("-l=", "", $argv[1])))
+ {
+  $arsc_logdir = str_replace("-l=", "", $argv[1]);
+  echo "Logging into '".$arsc_logdir."'\n";
+ }
+ else
+ {
+  die ("Cannot log into '".str_replace("-l=", "", $argv[1])."'. Aborting.\n");
+ }
+}
+
+
+// Creating socket
+
+if(false === ($arsc_listen_socket = socket_create_listen((string)$arsc_parameters["socketserver_port"], $arsc_parameters["socketserver_maximumusers"])))
+ die("Couldn't create listening socket on port {$arsc_parameters["socketserver_port"]}.\n");
+if(false === socket_setopt($arsc_listen_socket, SOL_SOCKET, SO_REUSEADDR, 1))
+ die("Couldn't set socket option\n");
+
+socket_set_nonblock($arsc_listen_socket);
+
+$arsc_connected_clients = 0;
+$arsc_connections = array();
+$arsc_connection_info = array();
+$arsc_sid = array();
+
+echo date("[Y-m-d H:i:s]")." {SOCK} Started ARSC server listening on port ".$arsc_parameters["socketserver_port"].".\n";
+
+while(1) // Handling connections in a neverending loop
+{
+ $arsc_socket_set = array_merge($arsc_listen_socket, $arsc_connections);
+ if(socket_select($arsc_socket_set, $a = NULL, $b = NULL, 0, 0))
+ {
+  foreach($arsc_connections as $arsc_connection)
+  {
+   if(!($arsc_connection == $arsc_listen_socket))
+   {
+    foreach($arsc_connection_info as $arsc_num => $arsc_info)
+    {
+     if($arsc_connection == $arsc_info['handle'])
+     {
+      if ($arsc_sid[$arsc_num] == "")
+      {
+       $arsc_read_socket = array($arsc_connection);
+       $arsc_socket_changed = socket_select($arsc_read_socket, $write = NULL, $except = NULL, 0, 0);
+       if ($arsc_socket_changed > 0)
+       {
+        $received_data = socket_read($arsc_connection, 100);
+        ereg("arsc_sid=(.*) HTTP", $received_data, $a);
+        $arsc_sid[$arsc_num] = $a[1];
+        if ($arsc_sid[$arsc_num] <> "")
+        {
+         $arsc_my = arsc_getdatafromsid($arsc_sid[$arsc_num]);
+         echo date("[Y-m-d H:i:s]")." {ARSC} #$arsc_num | Connection is an ARSC client (SID $arsc_sid[$arsc_num], nickname {$arsc_my["user"]}, room {$arsc_my["room"]})\n";
+         arsc_socket_write($arsc_connection, $arsc_parameters["htmlhead_js"]);
+         $arsc_sendtime = date("H:i:s");
+         $arsc_timeid = arsc_microtime();
+         @include("../shared/language/".$arsc_my["language"].".inc.php");
+         $arsc_message = "/msg ".$arsc_my["user"]." ".$arsc_lang["welcome"];
+         $arsc_message = arsc_filter_posting("System", $arsc_sendtime, $arsc_message, $arsc_my["room"], 0);
+         arsc_socket_write($arsc_connection, $arsc_message);
+        }
+        else
+        {
+         $arsc_sid[$arsc_num] = "-1";
+         echo date("[Y-m-d H:i:s]")." {SOCK} #$arsc_num | Connection is invalid\n";
+         $arsc_text = "You don't seem to be a valid ARSC client. Connection closed.";
+         arsc_socket_write($arsc_connection, $arsc_text);
+         unset($arsc_connections[$arsc_num]);
+         unset($arsc_connection_info[$arsc_num]);
+         flush();
+        }
+       }
+      }
+      else
+      {
+       $arsc_newmessages = arsc_getmessages($arsc_sid[$arsc_num]);
+       if ($arsc_newmessages <> "")
+       {
+        if (!arsc_socket_write($arsc_connection, $arsc_newmessages))
+        {
+         $arsc_user = $arsc_my["user"];
+         $arsc_room = $arsc_my["room"];
+         $arsc_nice_room = arsc_nice_room($arsc_room);
+         $arsc_timeid = arsc_microtime();
+         $arsc_sendtime = date("H:i:s");
+         mysql_query("DELETE from arsc_users WHERE sid = '{$arsc_sid[$arsc_num]}'");
+         mysql_query("INSERT into arsc_room_$arsc_room (message, user, sendtime, timeid) VALUES ('arsc_user_quit~~$arsc_user~~$arsc_nice_room', 'System', '$arsc_sendtime', '$arsc_timeid')");
+         echo date("[Y-m-d H:i:s]")." {SOCK} #$arsc_num | Client #$arsc_num {$arsc_connection_info[$arsc_num]['address']}:{$arsc_connection_info[$arsc_num]['port']} disconnected\n";
+         echo date("[Y-m-d H:i:s]")." {ARSC} #$arsc_num | Cannot reach user (SID $arsc_sid[$arsc_num], nickname {$arsc_my["user"]}, room {$arsc_my["room"]})\n";
+         unset($arsc_connections[$arsc_num]);
+         unset($arsc_connection_info[$arsc_num]);
+         flush();
+        }
+       }
+       else
+       {
+        $arsc_user = $arsc_my["user"];
+        $arsc_room = $arsc_my["room"];
+        $arsc_nice_room = arsc_nice_room($arsc_room);
+        $arsc_timeid = arsc_microtime();
+        $arsc_sendtime = date("H:i:s");
+        mysql_query("DELETE from arsc_users WHERE sid = '{$arsc_sid[$arsc_num]}'");
+        mysql_query("INSERT into arsc_room_$arsc_room (message, user, sendtime, timeid) VALUES ('arsc_user_quit~~$arsc_user~~$arsc_nice_room', 'System', '$arsc_sendtime', '$arsc_timeid')");
+        echo date("[Y-m-d H:i:s]")." {ARSC} #$arsc_num | User no longer known to ARSC (SID was $arsc_sid[$arsc_num])\n";
+        echo date("[Y-m-d H:i:s]")." {SOCK} #$arsc_num | Client {$arsc_connection_info[$arsc_num]['address']}:{$arsc_connection_info[$arsc_num]['port']} disconnected\n";
+        unset($arsc_connections[$arsc_num]);
+        unset($arsc_connection_info[$arsc_num]);
+        flush();
+       }
+      }
+     }
+    }
+   }
+  } 
+  // A new client connected
+  if($arsc_connection_info[$arsc_connected_clients]['handle'] = @socket_accept($arsc_listen_socket))
+  {
+   $arsc_connections[] = $arsc_connection_info[$arsc_connected_clients]['handle'];
+   socket_getpeername($arsc_connection_info[$arsc_connected_clients]['handle'], &$arsc_connection_info[$arsc_connected_clients]['address'], &$arsc_connection_info[$arsc_connected_clients]['port']);
+   echo date("[Y-m-d H:i:s]")." {SOCK} #$arsc_connected_clients | Connection from {$arsc_connection_info[$arsc_connected_clients]['address']} on port {$arsc_connection_info[$arsc_connected_clients]['port']}\n";
+   flush();
+   $arsc_connected_clients++;
+  }
+ }
+ usleep($arsc_parameters["socketserver_refresh"]); 
+}
+
+
+// Message handling
+
+function arsc_getmessages($arsc_sid)
+{
+ GLOBAL $arsc_my,
+        $arsc_parameters,
+        $arsc_lang,
+        $argv,
+        $arsc_logdir,
+        $arsc_lastlogmessage,
+        $arsc_num;
+ $arsc_sid = str_replace("/", "", $arsc_sid);
+ if (($arsc_my = arsc_getdatafromsid($arsc_sid)) <> FALSE)
+ {
+  $arsc_room = $arsc_my["room"];
+  if ($arsc_my["level"] < 0)
+  {
+   include("../shared/language/".$arsc_my["language"].".inc.php");
+   switch($arsc_my["level"])
+   {
+    case "-1": mysql_query("DELETE from arsc_users WHERE sid = '$arsc_sid'");
+               return arsc_filter_posting("System", date("H:i:s"), "<font size=\"4\"><b>".$arsc_lang["youwerekicked"]."</b></font>", $arsc_room, 0);
+               
+   }
+  }
+  else
+  {
+   $arsc_posting = " \n ";
+   include("../shared/language/".$arsc_my["language"].".inc.php");
+   $arsc_result = mysql_query("SELECT lastmessageping from arsc_users WHERE sid = '$arsc_sid'");
+   $arsc_b = mysql_fetch_array($arsc_result);
+   if ($arsc_b["lastmessageping"] == "0")
+   {
+    $arsc_lastmessageping = arsc_microtime();
+    mysql_query("UPDATE arsc_users SET lastmessageping = '$arsc_lastmessageping' WHERE sid = '$arsc_sid'");
+   }
+   else
+   {
+    $arsc_lastmessageping = $arsc_b["lastmessageping"];
+    $arsc_result = mysql_query("SELECT message, user, flag_ripped, sendtime, timeid from arsc_room_$arsc_room WHERE timeid > '$arsc_lastmessageping' ORDER BY timeid ASC, id ASC");
+    while ($arsc_a = mysql_fetch_array($arsc_result))
+    {
+     $arsc_posting .= arsc_filter_posting($arsc_a["user"], $arsc_a["sendtime"], $arsc_a["message"], $arsc_room, $arsc_a["flag_ripped"]);
+     $arsc_lastmessageping = $arsc_a["timeid"];
+     if ($argv[1] == "-v")
+     {
+      echo date("[Y-m-d H:i:s]")." {MESG} #$arsc_num | Room: $arsc_room | User: {$arsc_a["user"]} | Sendtime: {$arsc_a["sendtime"]} | Message: {$arsc_a["message"]}\n";
+     }
+     elseif($arsc_logdir)
+     {
+      $arsc_logmessage = "[".date("Y-m-d")."] [{$arsc_a["sendtime"]}] {$arsc_a["user"]}: {$arsc_a["message"]}\n";
+      if ($arsc_lastlogmessage != $arsc_logmessage)
+      {
+       $arsc_lastlogmessage = $arsc_logmessage;
+       $arsc_logresource = "fp_".$arsc_room;
+       if(is_resource($$arsc_logresource))
+       {
+        fputs($$arsc_logresource, $arsc_logmessage);
+       }
+       else
+       {
+        if ($$arsc_logresource = fopen($arsc_logdir."/".$arsc_room.".log", "a"))
+        {
+         fputs($$arsc_logresource, $arsc_logmessage);
+        }
+        else
+        {
+         echo "Error: cannot open logfile '".$arsc_logdir."/".$arsc_room.".log', disable logging.\n";
+         $arsc_logdir = false;
+        }
+       }
+      }
+     }
+    }
+    $arsc_ping = time();
+    mysql_query("UPDATE arsc_users SET lastping = '$arsc_ping', lastmessageping = '$arsc_lastmessageping' WHERE sid = '$arsc_sid'");
+   }
+   return $arsc_posting;
+  }
+ }
+}
+
+
+// Helpers
+function arsc_socket_write(&$connection, $text)
+{
+ $return = false;
+ $check_socket = array($connection);
+ $socket_changed = socket_select($read = NULL, $check_socket, $except = NULL, 0, 0);
+ if ($socket_changed > 0)
+ {
+  $return = true;
+  @socket_write($connection, $text, strlen($text));
+ }
+ else
+ {
+  echo date("[Y-m-d H:i:s]")." {SOCK} Socket not ready for write, closing connection.\n";
+ }
+ return $return;
+}
+
+?>
\ No newline at end of file
diff --git a/mod/chat/gui_sockets/chatinput.php b/mod/chat/gui_sockets/chatinput.php
new file mode 100644 (file)
index 0000000..354486f
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+
+include("../config.inc.php");
+include("../functions.inc.php");
+include("../filter.inc.php");
+
+if ($arsc_my = arsc_getdatafromsid($arsc_sid))
+{
+ include("../shared/language/".$arsc_my["language"].".inc.php");
+ if ($arsc_my["level"] >= 0)
+ {
+  echo $arsc_parameters["htmlhead_msginput_js"];
+  ?>
+    <form action="../shared/chatins.php" method="GET" target="empty" name="f" OnSubmit="return empty_field_and_submit()">
+     <input type="text" name="arsc_message" size="50" maxlength="<?php echo $arsc_parameters["input_maxsize"]; ?>" value="<?php echo $arsc_pretext; ?>">
+    </form>
+    <form action="../shared/chatins.php" method="GET" target="empty" name="fdummy" OnSubmit="return empty_field_and_submit()">
+     <input type="hidden" name="arsc_sid" value="<?php echo $arsc_sid; ?>">
+     <input type="hidden" name="arsc_chatversion" value="sockets">
+     <input type="hidden" name="arsc_message">
+    </form>
+   </body>
+  </html>
+  <?php
+ }
+ else
+ {
+  echo $arsc_htmlhead_out;
+ }
+}
+else
+{
+ echo $arsc_htmlhead_out;
+}
+?>
\ No newline at end of file
diff --git a/mod/chat/gui_sockets/index.php b/mod/chat/gui_sockets/index.php
new file mode 100644 (file)
index 0000000..aae09dc
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+include("../config.inc.php");
+include("../functions.inc.php");
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
+<html>
+ <head>
+  <title>
+   <?php echo $arsc_parameters["title"]; ?>
+  </title>
+ </head>
+ <frameset cols="193,*" border="0" framespacing="no" frameborder="0" marginwidth="2" marginheight="1">
+  <frame src="../shared/roomlist.php?arsc_sid=<?php echo $arsc_sid; ?>" name="roomlist" scrolling="auto" noresize marginwidth="0" marginheight="0">
+  <frameset cols="*,120" border="0" framespacing="no" frameborder="0" marginwidth="2" marginheight="1">
+   <frameset rows="1,*,40" border="1" framespacing="no" frameborder="0" marginwidth="2" marginheight="1">
+    <frame src="../shared/empty.php" NAME="empty" scrolling="no" noresize marginwidth="0" marginheight="0">
+    <frame src="http://<?php echo $arsc_parameters["socketserver_adress"].":".$arsc_parameters["socketserver_port"]; ?>/?arsc_sid=<?php echo $arsc_sid; ?>" NAME="msg" scrolling="auto" noresize marginwidth="2" marginheight="0">
+    <frame src="chatinput.php?arsc_sid=<?php echo $arsc_sid; ?>" name="input" scrolling="no" noresize marginwidth="2" marginheight="1">
+   </frameset>
+   <frame src="../shared/userlist.php?arsc_sid=<?php echo $arsc_sid; ?>&arsc_enter=true" name="users" scrolling="auto" noresize marginwidth="2" marginheight="2">
+  </frameset>
+ </frameset>
+ <noframes>
+  Sorry, this version of ARSC needs a browser that understands framesets. But we have a lynx-friendly version too.
+ </noframes>
+</html>
diff --git a/mod/chat/gui_text/index.php b/mod/chat/gui_text/index.php
new file mode 100644 (file)
index 0000000..85e3834
--- /dev/null
@@ -0,0 +1,122 @@
+<?php
+
+include("../config.inc.php");
+include("../functions.inc.php");
+include("../filter.inc.php");
+
+if ($arsc_my = arsc_getdatafromsid($arsc_sid))
+{
+ include("../shared/language/".$arsc_my["language"].".inc.php");
+ $arsc_user = $arsc_my["user"];
+ $arsc_room = $arsc_my["room"];
+ if ($arsc_lastid == "")
+ {
+  $arsc_result = mysql_query("SELECT * from arsc_room_$arsc_room ORDER BY timeid DESC");
+  $arsc_b = mysql_fetch_array($arsc_result);
+  $arsc_lastid = $arsc_b["timeid"];
+ }
+ if ($arsc_my["level"] < 0)
+ {
+  switch($arsc_my["level"])
+  {
+   case "-1": $arsc_message = $arsc_lang["youwerekicked"];
+              mysql_query("DELETE from arsc_users WHERE sid = '$arsc_sid'");
+              break;
+  }
+  header("Expires: Sun, 28 Dec 1997 09:32:45 GMT");
+  header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
+  header("Cache-Control: no-cache, must-revalidate");
+  header("Pragma: no-cache");
+  header("Content-Type: text/html");
+  ?>
+  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
+  <html>
+   <body>
+    <?php echo arsc_filter_posting("System", date("H:i:s"), "<font size=4><b>".$arsc_message."</b></font>", $arsc_room, 0); ?>
+   </body>
+  </html>
+  <?php
+ }
+ else
+ {
+  if ($arsc_enter == "true")
+  {
+   $arsc_sendtime = date("H:i:s");
+   $arsc_timeid = arsc_microtime();
+   $arsc_message = "arsc_user_enter~~".$arsc_my["user"]."~~".arsc_nice_room($arsc_room);
+   mysql_query("INSERT into arsc_room_$arsc_room (message, user, sendtime, timeid) VALUES ('$arsc_message', 'System', '$arsc_sendtime', '$arsc_timeid')");
+  }
+  header("Expires: Sun, 28 Dec 1997 09:32:45 GMT");
+  header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
+  header("Cache-Control: no-cache, must-revalidate");
+  header("Pragma: no-cache");
+  header("Content-Type: text/html");
+  ?>
+  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
+  <html>
+   <head>
+    <title>
+     <?php echo $arsc_parameters["title"]; ?>
+    </title>
+   </head>
+   <body>
+    <form action="../shared/chatins.php" METHOD="POST">
+     <a href="index.php?arsc_sid=<?php echo $arsc_sid; ?>&arsc_lastid=<?php echo $arsc_lastid; ?>"><?php echo $arsc_lang["refreshmessages"]; ?></a>
+     <input type="hidden" name="arsc_sid" value="<?php echo $arsc_sid; ?>">
+     <input type="hidden" name="arsc_lastid" value="<?php echo $arsc_lastid; ?>">
+     <input type="hidden" name="arsc_chatversion" value="text">
+     <input type="text" name="arsc_message" size="30" maxlength="<?php echo $arsc_parameters["input_maxsize"]; ?>" value="<?php echo $arsc_pretext; ?>">
+     <input type="submit" value="<?php echo $arsc_lang["sendmessage"]; ?>">
+     &nbsp;&nbsp;&nbsp;<a href="../logout.php?arsc_sid=<?php echo $arsc_sid; ?>"><?php echo $arsc_lang["leave"]; ?></a>
+    </form>
+    <?php
+     set_magic_quotes_runtime(0);
+     echo $arsc_lang["usersinroom"]." ".arsc_nice_room($arsc_room).": ";
+     $arsc_result = mysql_query("SELECT user, level from arsc_users WHERE room = '$arsc_room' ORDER BY level DESC, user ASC");
+     while ($arsc_a = mysql_fetch_array($arsc_result))
+     {
+      $arsc_opstring = "";
+      if ($arsc_a["level"] == 1)
+      {
+       $arsc_opstring = "@";
+      }
+      if ($arsc_a["level"] == 2)
+      {
+       $arsc_opstring = "<b>@</b>";
+      }
+      if ($arsc_a["user"] == $arsc_my["user"])
+      {
+       echo "<i>".$arsc_opstring.$arsc_a["user"]."</i>\n";
+      }
+      else
+      {
+       echo "<a href=\"../version_".$arsc_my["version"]."/index.php?arsc_sid=".$arsc_my["sid"]."&arsc_lastid=".$arsc_lastid."&arsc_pretext=".urlencode("/msg ".$arsc_a["user"]." ")."\">".$arsc_opstring.$arsc_a["user"]."</a>\n";
+      }
+     }
+     echo "<br>";
+     $arsc_result = mysql_query("SELECT * from arsc_room_$arsc_room WHERE timeid > '$arsc_lastid' ORDER BY timeid DESC");
+     while ($arsc_a = mysql_fetch_array($arsc_result))
+     {
+      echo arsc_filter_posting($arsc_a["user"], $arsc_a["sendtime"], $arsc_a["message"], $arsc_room, $arsc_a["flag_ripped"])."\n";
+     }
+     $arsc_sendtime = date("H:i:s");
+     $arsc_timeid = arsc_microtime();
+     $arsc_message = "/msg ".$arsc_my["user"]." ".$arsc_lang["welcome"];
+     echo arsc_filter_posting("System", $arsc_sendtime, $arsc_message, $arsc_room, 0);
+     $arsc_ping = time();
+     $arsc_ip = getenv("REMOTE_ADDR");
+     mysql_query("UPDATE arsc_users SET lastping = '$arsc_ping', ip = '$arsc_ip' WHERE user = '$arsc_user'");
+    ?>
+   </body>
+  </html>
+  <?php
+ }
+}
+else
+{
+ echo $arsc_htmlhead_out;
+}
+?>
diff --git a/mod/chat/icon.gif b/mod/chat/icon.gif
new file mode 100755 (executable)
index 0000000..ad43629
Binary files /dev/null and b/mod/chat/icon.gif differ
diff --git a/mod/chat/index.php b/mod/chat/index.php
new file mode 100644 (file)
index 0000000..2d9e0bd
--- /dev/null
@@ -0,0 +1,74 @@
+<?PHP // $Id$
+
+    require_once("../../config.php");
+    require_once("lib.php");
+
+    require_variable($id);   // course
+
+    if (! $course = get_record("course", "id", $id)) {
+        error("Course ID is incorrect");
+    }
+
+    require_login($course->id);
+
+    add_to_log($course->id, "chat", "view all", "index.php?id=$course->id", "");
+
+
+/// Get all required strings
+
+    $strchats = get_string("modulenameplural", "chat");
+    $strchat  = get_string("modulename", "chat");
+
+
+/// Print the header
+
+    if ($course->category) {
+        $navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
+    }
+
+    print_header("$course->shortname: $strchats", "$course->fullname", "$navigation $strchats");
+
+/// Get all the appropriate data
+
+    if (! $chats = get_all_instances_in_course("chat", $course->id, "cw.section ASC")) {
+        notice("There are no chats", "../../course/view.php?id=$course->id");
+        die;
+    }
+
+/// Print the list of instances (your module will probably extend this)
+
+    $timenow = time();
+    $strname  = get_string("name");
+    $strweek  = get_string("week");
+    $strtopic  = get_string("topic");
+
+    if ($course->format == "weeks") {
+        $table->head  = array ($strweek, $strname);
+        $table->align = array ("CENTER", "LEFT");
+    } else if ($course->format == "topics") {
+        $table->head  = array ($strtopic, $strname);
+        $table->align = array ("CENTER", "LEFT", "LEFT", "LEFT");
+    } else {
+        $table->head  = array ($strname);
+        $table->align = array ("LEFT", "LEFT", "LEFT");
+    }
+
+    foreach ($chats as $chat) {
+        $link = "<A HREF=\"view.php?id=$chat->coursemodule\">$chat->name</A>";
+
+        if ($course->format == "weeks" or $course->format == "topics") {
+            $table->data[] = array ($chat->section, $link);
+        } else {
+            $table->data[] = array ($link);
+        }
+    }
+
+    echo "<br />";
+
+    print_table($table);
+
+/// Finish the page
+
+    print_footer($course);
+
+?>
diff --git a/mod/chat/insert.php b/mod/chat/insert.php
new file mode 100644 (file)
index 0000000..00827c9
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+
+include("../../config.php");
+include("lib.php");
+
+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;
+}
+
+/// Delete old messages here
+
+/// Clean up the message
+
+$chat_message = clean_text($chat_message, FORMAT_MOODLE);  // Strip bad tags
+
+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!");
+    }
+}
+
+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
new file mode 100644 (file)
index 0000000..69cf7ba
--- /dev/null
@@ -0,0 +1,396 @@
+<?PHP  // $Id$
+
+/// Library of functions and constants for module chat
+
+
+define("CHAT_REFRESH_ROOM", 10);
+define("CHAT_REFRESH_USERLIST", 10);
+define("CHAT_OLD_PING", 30);
+
+define("CHAT_DRAWBOARD", false);  // Look into this later
+
+
+// The HTML head for the message window to start with (<!-- nix --> is used to get some browsers starting with output
+$CHAT_HTMLHEAD = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\"><html><head></head>\n<body bgcolor=\"#FFFFFF\">\n\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n";
+
+// The HTML head for the message window to start with (with js scrolling)
+$CHAT_HTMLHEAD_JS = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\"><html><head><script language=\"JavaScript\">\n<!--\nfunction move()\n{\nif (scroll_active) window.scroll(1,400000);\nwindow.setTimeout(\"move()\",100);\n}\nscroll_active = true;\nmove();\n//-->\n</script>\n</head>\n<body bgcolor=\"#FFFFFF\" onBlur=\"scroll_active = true\" onFocus=\"scroll_active = false\">\n\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n";
+
+// The HTML code for standard empty pages (e.g. if a user was kicked out)
+$CHAT_HTMLHEAD_OUT = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\"><html><head><title>You are out!</title></head><body bgcolor=\"$THEME->body\"></body></html>";
+
+// The HTML head for the message input page
+$CHAT_HTMLHEAD_MSGINPUT = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\"><html><head><title>Message Input</title></head><body bgcolor=\"$THEME->body\">";
+
+// The HTML code for the message input page, with JavaScript
+$CHAT_HTMLHEAD_MSGINPUT_JS = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\"><html><head><title>Message Input</title>\n<script language=\"Javascript\">\n<!--\nscroll_active = true;\nfunction empty_field_and_submit()\n{\ndocument.fdummy.arsc_message.value=document.f.arsc_message.value;\ndocument.fdummy.submit();\ndocument.f.arsc_message.focus();\ndocument.f.arsc_message.select();\nreturn false;\n}\n// -->\n</script>\n</head><body bgcolor=\"$THEME->body\" OnLoad=\"document.f.arsc_message.focus();document.f.arsc_message.select();\">";
+
+
+function chat_add_instance($chat) {
+/// Given an object containing all the necessary data, 
+/// (defined by the form in mod.html) this function 
+/// will create a new instance and return the id number 
+/// of the new instance.
+
+    $chat->timemodified = time();
+
+    # May have to add extra stuff in here #
+    
+    return insert_record("chat", $chat);
+}
+
+
+function chat_update_instance($chat) {
+/// Given an object containing all the necessary data, 
+/// (defined by the form in mod.html) this function 
+/// will update an existing instance with new data.
+
+    $chat->timemodified = time();
+    $chat->id = $chat->instance;
+
+    # May have to add extra stuff in here #
+
+    return update_record("chat", $chat);
+}
+
+
+function chat_delete_instance($id) {
+/// Given an ID of an instance of this module, 
+/// this function will permanently delete the instance 
+/// and any data that depends on it.  
+
+    if (! $chat = get_record("chat", "id", "$id")) {
+        return false;
+    }
+
+    $result = true;
+
+    # Delete any dependent records here #
+
+    if (! delete_records("chat", "id", "$chat->id")) {
+        $result = false;
+    }
+
+    return $result;
+}
+
+function chat_user_outline($course, $user, $mod, $chat) {
+/// Return a small object with summary information about what a 
+/// user has done with a given particular instance of this module
+/// Used for user activity reports.
+/// $return->time = the time they did it
+/// $return->info = a short text description
+
+    return $return;
+}
+
+function chat_user_complete($course, $user, $mod, $chat) {
+/// Print a detailed representation of what a  user has done with 
+/// a given particular instance of this module, for user activity reports.
+
+    return true;
+}
+
+function chat_print_recent_activity(&$logs, $isteacher=false) {
+/// Given a list of logs, assumed to be those since the last login 
+/// this function prints a short list of changes related to this module
+/// If isteacher is true then perhaps additional information is printed.
+/// This function is called from course/lib.php: print_recent_activity()
+
+    global $CFG, $COURSE_TEACHER_COLOR;
+
+    return $content;  // True if anything was printed, otherwise false
+}
+
+function chat_cron () {
+/// Function to be run periodically according to the moodle cron
+/// This function searches for things that need to be done, such 
+/// as sending out mail, toggling flags etc ... 
+
+    global $CFG;
+
+    return true;
+}
+
+function chat_grades($chatid) {
+/// Must return an array of grades for a given instance of this module, 
+/// indexed by user.  It also returns a maximum allowed grade.
+
+    $return->grades = NULL;
+    $return->maxgrade = NULL;
+
+    return $return;
+}
+
+
+//////////////////////////////////////////////////////////////////////
+/// Functions that require some SQL
+
+function chat_get_users($chatid) {
+
+    global $CFG;
+   
+    return get_records_sql("SELECT u.id, u.firstname, u.lastname, u.picture 
+                              FROM {$CFG->prefix}chat_users c,
+                                   {$CFG->prefix}user u
+                             WHERE c.chatid = '$chatid'
+                               AND u.id = c.userid
+                             GROUP BY u.id
+                             ORDER BY c.firstping ASC");
+}
+
+function chat_get_latest_message($chatid) {
+
+    global $CFG;
+
+    return get_record_sql("SELECT * 
+                             FROM {$CFG->prefix}chat_messages 
+                            WHERE chatid = '$chatid' 
+                         ORDER BY timestamp DESC");
+}
+
+//////////////////////////////////////////////////////////////////////
+
+function chat_login_user($chatid, $version="header_js") {
+    global $USER;
+
+    $chatuser->chatid   = $chatid;
+    $chatuser->userid   = $USER->id;
+    $chatuser->version  = $version;
+    $chatuser->ip       = $USER->lastIP;
+    $chatuser->lastping = time();
+    $chatuser->sid      = random_string(32);
+
+    if (!insert_record("chat_users", $chatuser)) {
+        return false;
+    }
+
+    return $chatuser->sid;
+}
+
+
+
+function chat_browser_detect($HTTP_USER_AGENT) {
+
+ if(eregi("(opera) ([0-9]{1,2}.[0-9]{1,3}){0,1}", $HTTP_USER_AGENT, $match)
+ || eregi("(opera/)([0-9]{1,2}.[0-9]{1,3}){0,1}", $HTTP_USER_AGENT, $match))
+ {
+  $BName = "Opera"; $BVersion=$match[2];
+ }
+ elseif( eregi("(konqueror)/([0-9]{1,2}.[0-9]{1,3})", $HTTP_USER_AGENT, $match) )
+ {
+  $BName = "Konqueror"; $BVersion=$match[2];
+ }
+ elseif( eregi("(lynx)/([0-9]{1,2}.[0-9]{1,2}.[0-9]{1,2})", $HTTP_USER_AGENT, $match) )
+ {
+  $BName = "Lynx"; $BVersion=$match[2];
+ }
+ elseif( eregi("(links) \(([0-9]{1,2}.[0-9]{1,3})", $HTTP_USER_AGENT, $match) )
+ {
+  $BName = "Links"; $BVersion=$match[2];
+ }
+ elseif( eregi("(msie) ([0-9]{1,2}.[0-9]{1,3})", $HTTP_USER_AGENT, $match) )
+ {
+  $BName = "MSIE"; $BVersion=$match[2];
+ }
+ elseif( eregi("(netscape6)/(6.[0-9]{1,3})", $HTTP_USER_AGENT, $match) )
+ {
+  $BName = "Netscape"; $BVersion=$match[2];
+ }
+ elseif( eregi("mozilla/5", $HTTP_USER_AGENT) )
+ {
+  $BName = "Netscape"; $BVersion="Unknown";
+ }
+ elseif( eregi("(mozilla)/([0-9]{1,2}.[0-9]{1,3})", $HTTP_USER_AGENT, $match) )
+ {
+  $BName = "Netscape"; $BVersion=$match[2];
+ }
+ elseif( eregi("w3m", $HTTP_USER_AGENT) )
+ {
+  $BName = "w3m"; $BVersion="Unknown";
+ }
+ else
+ {
+  $BName = "Unknown"; $BVersion="Unknown";
+ }
+
+ if(eregi("linux", $HTTP_USER_AGENT))
+ {
+  $BPlatform = "Linux";
+ }
+ elseif( eregi("win32", $HTTP_USER_AGENT) )
+ {
+  $BPlatform = "Windows";
+ }
+ elseif( (eregi("(win)([0-9]{2})", $HTTP_USER_AGENT, $match) )
+ ||      (eregi("(windows) ([0-9]{2})", $HTTP_USER_AGENT, $match) ))
+ {
+  $BPlatform = "Windows $match[2]";
+ }
+ elseif( eregi("(winnt)([0-9]{1,2}.[0-9]{1,2}){0,1}", $HTTP_USER_AGENT, $match) )
+ {
+  $BPlatform = "Windows NT $match[2]";
+ }
+ elseif( eregi("(windows nt)( ){0,1}([0-9]{1,2}.[0-9]{1,2}){0,1}", $HTTP_USER_AGENT, $match) )
+ {
+  $BPlatform = "Windows NT $match[3]";
+ }
+ elseif( eregi("mac", $HTTP_USER_AGENT) )
+ {
+  $BPlatform = "Macintosh";
+ }
+ elseif( eregi("(sunos) ([0-9]{1,2}.[0-9]{1,2}){0,1}", $HTTP_USER_AGENT, $match) )
+ {
+  $BPlatform = "SunOS $match[2]";
+ }
+ elseif( eregi("(beos) r([0-9]{1,2}.[0-9]{1,2}){0,1}", $HTTP_USER_AGENT, $match) )
+ {
+  $BPlatform = "BeOS $match[2]";
+ }
+ elseif( eregi("freebsd", $HTTP_USER_AGENT) )
+ {
+  $BPlatform = "FreeBSD";
+ }
+ elseif( eregi("openbsd", $HTTP_USER_AGENT) )
+ {
+  $BPlatform = "OpenBSD";
+ }
+ elseif( eregi("irix", $HTTP_USER_AGENT) )
+ {
+  $BPlatform = "IRIX";
+ }
+ elseif( eregi("os/2", $HTTP_USER_AGENT) )
+ {
+  $BPlatform = "OS/2";
+ }
+ elseif( eregi("plan9", $HTTP_USER_AGENT) )
+ {
+  $BPlatform = "Plan9";
+ }
+ elseif( eregi("unix", $HTTP_USER_AGENT)
+ ||      eregi("hp-ux", $HTTP_USER_AGENT) )
+ {
+  $BPlatform = "Unix";
+ }
+ elseif( eregi("osf", $HTTP_USER_AGENT) )
+ {
+  $BPlatform = "OSF";
+ }
+ else
+ {
+  $BPlatform = "Unknown";
+ }
+ $return["name"] = $BName;
+ $return["version"] = $BVersion;
+ $return["platform"] = $BPlatform;
+ return $return;
+}
+
+function chat_display_version($version, $browser)
+{
+ GLOBAL $CFG;
+
+ $checked = "";
+ if (($version == "sockets") OR ($version == "push_js"))
+ {
+  $checked = "checked";
+ }
+ if (($version == "sockets" OR $version == "push_js")
+     AND
+     ($browser["name"] == "Lynx"
+      OR
+      $browser["name"] == "Links"
+      OR
+      $browser["name"] == "w3m"
+      OR
+      $browser["name"] == "Konqueror"
+      OR
+      ($browser["name"] == "Netscape" AND substr($browser["version"], 0, 1) == "2")))
+ {
+  $checked = "";
+ }
+ if (($version == "text")
+     AND
+     ($browser["name"] == "Lynx"
+      OR
+      $browser["name"] == "Links"
+      OR
+      $browser["name"] == "w3m"))
+ {
+  $checked = "checked";
+ }
+ if (($version == "header")
+     AND
+     ($browser["name"] == "Konqueror"))
+ {
+  $checked = "checked";
+ }
+ if (($version == "header_js")
+     AND
+     ($browser["name"] == "Netscape" AND substr($browser["version"], 0, 1) == "2"))
+ {
+  $checked = "checked";
+ }
+  ?>
+  <tr>
+   <td valign="top">
+    <input type="radio" name="chat_chatversion" value="<?php echo $version; ?>"<?php echo $checked; ?>>
+   </td>
+   <td valign="top" align="left">
+    <font face="Arial" size="2">
+     <?php echo $chat_lang["gui_".$version]; ?>
+    </font>
+   </td>
+  </tr>
+  <?php
+
+}
+
+
+function chat_format_message($userid, $chatid, $timestamp, $message, $system=false) {
+/// Given a message and some information, this function formats it appropriately
+/// for displaying on the web, and returns the formatted string.
+
+    global $CFG, $USER;
+
+    if (!$user = get_record("user", "id", $userid)) {
+        return "Error finding user id = $userid";
+    }
+
+    $picture = print_user_picture($user->id, 0, $user->picture, false, true, false);
+
+    $strtime = userdate($timestamp, get_string("strftimemessage", "chat"));
+
+    if ($system) {                     /// It's a system message
+        $message = get_string("message$message", "chat", "$user->firstname $user->lastname");
+        $message = addslashes($message);
+        $output  = "<table><tr><td valign=top>$picture</td><td>";
+        $output .= "<font size=2 color=\"#AAAAAA\">$strtime $message</font>";
+        $output .= "</td></tr></table>";
+        return $output;
+    }
+
+    if (substr($message, 0, 1) == "/") {  /// It's a user command
+
+        if (substr($message, 0, 4) == "/me ") {
+            $output = $chat_parameters["template_me"];
+            $output = str_replace("{user}", $userid, $output);
+            $output = str_replace("{message}", $message, $output);
+            $output = str_replace("{sendtime}", substr($timestamp, 0, 5), $output);
+            $output = str_replace("/me ", "", $output);
+        }
+    }
+
+    replace_smilies($message);
+
+    $output  = "<table><tr><td valign=top>$picture</td><td>";
+    $output .= "<font size=2><font color=\"#888888\">$strtime $user->firstname</font>: $message</font>";
+    $output .= "</td></tr></table>";
+
+    return addslashes($output);
+
+}
+
+
+?>
diff --git a/mod/chat/mod.html b/mod/chat/mod.html
new file mode 100644 (file)
index 0000000..44782ae
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+    if (!isset($form->name)) {
+        $form->name = "";
+    }
+    if (!isset($form->intro)) {
+        $form->intro = "";
+    }
+    if (!isset($form->messages)) {
+        $form->messages = 1000;
+    }
+?>
+<form name="form" method="post" <?php echo $onsubmit ?> action="mod.php">
+<table cellpadding=5>
+<tr>
+<tr valign=top>
+    <td align=right><p><b><?php print_string("chatname", "chat")?>:</b></p></td>
+    <td>
+        <input type="text" name="name" size=30 value="<?php p($form->name) ?>">
+    </td>
+</tr>
+<tr valign=top>
+    <td align=right><p><b><?php print_string("chatintro", "chat")?>:</b></p>
+    <font size="1">
+     <?php
+        helpbutton("writing", get_string("helpwriting"), "moodle", true, true);
+        echo "<br />";
+        helpbutton("questions", get_string("helpquestions"), "moodle", true, true);
+        echo "<br />";
+        emoticonhelpbutton("form", "intro");
+        echo " <br />";
+      ?>
+    </font>
+    </td>
+    <td>
+        <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("savemessages", "chat")?>:</b></p>
+       <td>
+    <?php 
+       $options = array(5000, 1000, 500, 100);
+       choose_from_menu ($options, "messages", $form->messages, "", "", "");
+    ?>
+    </td>
+</tr>
+
+</table>
+<center>
+<input type="hidden" name=course     value="<? p($form->course) ?>">
+<input type="hidden" name=coursemodule  value="<? p($form->coursemodule) ?>">
+<input type="hidden" name=section       value="<? p($form->section) ?>">
+<input type="hidden" name=module     value="<? p($form->module) ?>">
+<input type="hidden" name=modulename value="<? p($form->modulename) ?>">
+<input type="hidden" name=instance   value="<? p($form->instance) ?>">
+<input type="hidden" name=mode       value="<? p($form->mode) ?>">
+<input type="submit" value="<? print_string("savechanges") ?>">
+<input type="submit" name=cancel value="<? print_string("cancel") ?>">
+</center>
+</form>
diff --git a/mod/chat/users.php b/mod/chat/users.php
new file mode 100644 (file)
index 0000000..f635e5d
--- /dev/null
@@ -0,0 +1,64 @@
+<?php
+
+include("../../config.php");
+include("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("Could not find chat! id = $chatuser->chatid");
+}
+
+if (isset($chat_enter)) {
+    $message->chatid = $chatuser->chatid;
+    $message->userid = $chatuser->userid;
+    $message->message = "enter";
+    $message->system = 1;
+    $message->timestamp = time();
+    if (!insert_record("chat_messages", $message)) {
+        error("Could not insert a chat message!");
+    }
+}
+
+/// Delete users who are using text version and are old
+
+$timeold = time() - CHAT_OLD_PING;
+
+delete_records_select("chat_users", "lastping < '$timeold'");
+
+/// Get list of users
+
+if (!$chatusers = chat_get_users($chatuser->chatid)) {
+    error("Could not find any users!");
+}
+
+
+/// Print headers
+
+header("Expires: Wed, 4 Oct 1978 09:32:45 GMT");
+header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
+header("Cache-Control: no-cache, must-revalidate");
+header("Pragma: no-cache");
+header("Content-Type: text/html");
+header("Refresh: ".CHAT_REFRESH_USERLIST."; URL=users.php?chat_sid=".$chat_sid);
+
+print_header();
+
+echo "<table width=\"100%\">";
+foreach ($chatusers as $chatuser) {
+    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 "<td></tr>";
+}
+echo "</table>";
+
+?>
diff --git a/mod/chat/version.php b/mod/chat/version.php
new file mode 100644 (file)
index 0000000..7582545
--- /dev/null
@@ -0,0 +1,11 @@
+<?PHP // $Id$
+
+/////////////////////////////////////////////////////////////////////////////////
+///  Code fragment to define the version of chat
+///  This fragment is called by moodle_needs_upgrading() and /admin/index.php
+/////////////////////////////////////////////////////////////////////////////////
+
+$module->version  = 2003070600;   // 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
new file mode 100644 (file)
index 0000000..2d161ef
--- /dev/null
@@ -0,0 +1,92 @@
+<?PHP  // $Id$
+
+/// This page prints a particular instance of chat
+
+    require_once("../../config.php");
+    require_once("lib.php");
+
+    optional_variable($id);    // Course Module ID, or
+    optional_variable($c);     // chat ID
+
+    if ($id) {
+        if (! $cm = get_record("course_modules", "id", $id)) {
+            error("Course Module ID was incorrect");
+        }
+    
+        if (! $course = get_record("course", "id", $cm->course)) {
+            error("Course is misconfigured");
+        }
+    
+        if (! $chat = get_record("chat", "id", $cm->instance)) {
+            error("Course module is incorrect");
+        }
+
+    } else {
+        if (! $chat = get_record("chat", "id", $c)) {
+            error("Course module is incorrect");
+        }
+        if (! $course = get_record("course", "id", $chat->course)) {
+            error("Course is misconfigured");
+        }
+        if (! $cm = get_coursemodule_from_instance("chat", $chat->id, $course->id)) {
+            error("Course Module ID was incorrect");
+        }
+    }
+
+    require_login($course->id);
+
+    add_to_log($course->id, "chat", "view", "view.php?id=$cm->id", "$chat->id");
+
+/// Print the page header
+
+    if ($course->category) {
+        $navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
+    }
+
+    $strchats = get_string("modulenameplural", "chat");
+    $strchat  = get_string("modulename", "chat");
+    $strenterchat  = get_string("enterchat", "chat");
+
+    print_header("$course->shortname: $chat->name", "$course->fullname",
+                 "$navigation <A HREF=index.php?id=$course->id>$strchats</A> -> $chat->name", 
+                  "", "", true, update_module_button($cm->id, $course->id, $strchat), 
+                  navmenu($course, $cm));
+
+/// Print the main part of the page
+
+   // Do the browser-detection etc later on.
+    $chatversion = "header_js";
+
+   // $browser = chat_browser_detect($HTTP_USER_AGENT);
+
+   // print_object($browser);
+
+   //if ($CFG->chatsocketserver == true) {
+   //    chat_display_version("sockets", $browser);
+   //} else {
+   //    chat_display_version("push_js", $browser);
+   // }
+   // chat_display_version("header_js", $browser);
+   // chat_display_version("header", $browser);
+   // chat_display_version("box", $browser);
+   // chat_display_version("text", $browser);
+
+    echo "<br /><br />";
+    notify("(Note: This chat module is an early alpha version)");
+    echo "<br /><br />";
+
+    print_simple_box_start("center");
+
+
+    link_to_popup_window ("/mod/chat/gui_$chatversion/index.php?id=$chat->id", 
+                          "chat$chat->id", "$strenterchat", 500, 700, $strchat);
+
+    print_simple_box_end();
+
+    echo "<br /><br /><br /><br />";
+
+
+/// Finish the page
+    print_footer($course);
+
+?>