From 1515a89e2dddf556d349c1085d22781766c532d2 Mon Sep 17 00:00:00 2001 From: moodler Date: Mon, 7 Jul 2003 06:44:16 +0000 Subject: [PATCH] Very early version of new chat module, made by Martin using ARSC as an inspiration. Works OK already on most newish browsers .. see mod/chat/README.txt for details. --- lang/en/chat.php | 15 + mod/chat/README.txt | 29 ++ mod/chat/db/mysql.php | 17 ++ mod/chat/db/mysql.sql | 55 ++++ mod/chat/drawboard.php | 38 +++ mod/chat/empty.php | 9 + mod/chat/gui_header/chatinput.php | 33 +++ mod/chat/gui_header/chatmsg.php | 74 +++++ mod/chat/gui_header/index.php | 23 ++ mod/chat/gui_header_js/chatinput.php | 48 ++++ mod/chat/gui_header_js/chatmsg.php | 2 + mod/chat/gui_header_js/index.php | 43 +++ mod/chat/gui_header_js/jsupdate.php | 58 ++++ mod/chat/gui_java/MainFrameGui.java | 177 ++++++++++++ mod/chat/gui_java/TextDialog.java | 68 +++++ mod/chat/gui_java/arsc.java | 90 ++++++ mod/chat/gui_push_js/chatinput.php | 35 +++ mod/chat/gui_push_js/chatmsg.php | 98 +++++++ mod/chat/gui_push_js/index.php | 24 ++ mod/chat/gui_sockets/arscd.php | 264 ++++++++++++++++++ mod/chat/gui_sockets/chatinput.php | 36 +++ mod/chat/gui_sockets/index.php | 26 ++ mod/chat/gui_text/index.php | 122 +++++++++ mod/chat/icon.gif | Bin 0 -> 99 bytes mod/chat/index.php | 74 +++++ mod/chat/insert.php | 43 +++ mod/chat/lib.php | 396 +++++++++++++++++++++++++++ mod/chat/mod.html | 60 ++++ mod/chat/users.php | 64 +++++ mod/chat/version.php | 11 + mod/chat/view.php | 92 +++++++ 31 files changed, 2124 insertions(+) create mode 100644 lang/en/chat.php create mode 100644 mod/chat/README.txt create mode 100644 mod/chat/db/mysql.php create mode 100644 mod/chat/db/mysql.sql create mode 100644 mod/chat/drawboard.php create mode 100644 mod/chat/empty.php create mode 100644 mod/chat/gui_header/chatinput.php create mode 100644 mod/chat/gui_header/chatmsg.php create mode 100644 mod/chat/gui_header/index.php create mode 100644 mod/chat/gui_header_js/chatinput.php create mode 100644 mod/chat/gui_header_js/chatmsg.php create mode 100644 mod/chat/gui_header_js/index.php create mode 100644 mod/chat/gui_header_js/jsupdate.php create mode 100644 mod/chat/gui_java/MainFrameGui.java create mode 100644 mod/chat/gui_java/TextDialog.java create mode 100644 mod/chat/gui_java/arsc.java create mode 100644 mod/chat/gui_push_js/chatinput.php create mode 100644 mod/chat/gui_push_js/chatmsg.php create mode 100644 mod/chat/gui_push_js/index.php create mode 100644 mod/chat/gui_sockets/arscd.php create mode 100644 mod/chat/gui_sockets/chatinput.php create mode 100644 mod/chat/gui_sockets/index.php create mode 100644 mod/chat/gui_text/index.php create mode 100755 mod/chat/icon.gif create mode 100644 mod/chat/index.php create mode 100644 mod/chat/insert.php create mode 100644 mod/chat/lib.php create mode 100644 mod/chat/mod.html create mode 100644 mod/chat/users.php create mode 100644 mod/chat/version.php create mode 100644 mod/chat/view.php diff --git a/lang/en/chat.php b/lang/en/chat.php new file mode 100644 index 0000000000..4c1d85f63b --- /dev/null +++ b/lang/en/chat.php @@ -0,0 +1,15 @@ + diff --git a/mod/chat/README.txt b/mod/chat/README.txt new file mode 100644 index 0000000000..c613422c6e --- /dev/null +++ b/mod/chat/README.txt @@ -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 index 0000000000..fe9b6d3265 --- /dev/null +++ b/mod/chat/db/mysql.php @@ -0,0 +1,17 @@ + + diff --git a/mod/chat/db/mysql.sql b/mod/chat/db/mysql.sql new file mode 100644 index 0000000000..1dd573b90b --- /dev/null +++ b/mod/chat/db/mysql.sql @@ -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 index 0000000000..5edb4e9e31 --- /dev/null +++ b/mod/chat/drawboard.php @@ -0,0 +1,38 @@ + + + + + + Abacho - Drawboard + + + + " HEIGHT=""> + "> + + + + + + + Unfortunatelly, your browser doesn't support Java applets. You have to use another one. + + + + \ No newline at end of file diff --git a/mod/chat/empty.php b/mod/chat/empty.php new file mode 100644 index 0000000000..c06c35e0d5 --- /dev/null +++ b/mod/chat/empty.php @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/mod/chat/gui_header/chatinput.php b/mod/chat/gui_header/chatinput.php new file mode 100644 index 0000000000..24f6c3ea1c --- /dev/null +++ b/mod/chat/gui_header/chatinput.php @@ -0,0 +1,33 @@ += 0) + { + echo $arsc_parameters["htmlhead_msginput"]; + ?> +
+ + + " value=""> + "> +
+ + + diff --git a/mod/chat/gui_header/chatmsg.php b/mod/chat/gui_header/chatmsg.php new file mode 100644 index 0000000000..635188df5a --- /dev/null +++ b/mod/chat/gui_header/chatmsg.php @@ -0,0 +1,74 @@ +".$arsc_message."", $arsc_room, 0); + ?> + + + '$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'"); + ?> + + + + diff --git a/mod/chat/gui_header/index.php b/mod/chat/gui_header/index.php new file mode 100644 index 0000000000..ffaf827078 --- /dev/null +++ b/mod/chat/gui_header/index.php @@ -0,0 +1,23 @@ + + + + + + ARSC - ARSC Really Simple Chat + + + + + + + + + + + + Sorry, this version of ARSC needs a browser that understands framesets. We have a Lynx friendly version too. + + diff --git a/mod/chat/gui_header_js/chatinput.php b/mod/chat/gui_header_js/chatinput.php new file mode 100644 index 0000000000..6f8d19d9f3 --- /dev/null +++ b/mod/chat/gui_header_js/chatinput.php @@ -0,0 +1,48 @@ + + + + + +Message Input + + + + + + +
+>> +
+ +
+ + + +
+ + + + diff --git a/mod/chat/gui_header_js/chatmsg.php b/mod/chat/gui_header_js/chatmsg.php new file mode 100644 index 0000000000..678b075cfe --- /dev/null +++ b/mod/chat/gui_header_js/chatmsg.php @@ -0,0 +1,2 @@ + + diff --git a/mod/chat/gui_header_js/index.php b/mod/chat/gui_header_js/index.php new file mode 100644 index 0000000000..169f5a4207 --- /dev/null +++ b/mod/chat/gui_header_js/index.php @@ -0,0 +1,43 @@ +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"); + + +?> + + + + + <?php echo "$strchat: $course->shortname: $chat->name" ?> + + + + + + + + + + + + + Sorry, this version of ARSC needs a browser that understands framesets. We have a Lynx friendly version too. + + diff --git a/mod/chat/gui_header_js/jsupdate.php b/mod/chat/gui_header_js/jsupdate.php new file mode 100644 index 0000000000..90de60e970 --- /dev/null +++ b/mod/chat/gui_header_js/jsupdate.php @@ -0,0 +1,58 @@ +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); + +?> + + + + + + + + diff --git a/mod/chat/gui_java/MainFrameGui.java b/mod/chat/gui_java/MainFrameGui.java new file mode 100644 index 0000000000..53c292b2e0 --- /dev/null +++ b/mod/chat/gui_java/MainFrameGui.java @@ -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 index 0000000000..52e3a12021 --- /dev/null +++ b/mod/chat/gui_java/TextDialog.java @@ -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 index 0000000000..b45a6b4bc1 --- /dev/null +++ b/mod/chat/gui_java/arsc.java @@ -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 index 0000000000..ac790d5ba9 --- /dev/null +++ b/mod/chat/gui_push_js/chatinput.php @@ -0,0 +1,35 @@ += 0) + { + echo $arsc_parameters["htmlhead_msginput_js"]; + ?> +
+ " value=""> +
+
+ + + +
+ + + diff --git a/mod/chat/gui_push_js/chatmsg.php b/mod/chat/gui_push_js/chatmsg.php new file mode 100644 index 0000000000..e16e337d9c --- /dev/null +++ b/mod/chat/gui_push_js/chatmsg.php @@ -0,0 +1,98 @@ + "") + { + $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"), "".$arsc_lang["youwerekicked"]."", $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 index 0000000000..656d18cdf8 --- /dev/null +++ b/mod/chat/gui_push_js/index.php @@ -0,0 +1,24 @@ + + + + + + ARSC - ARSC Really Simple Chat + + + + + + + + + + + + + Sorry, ARSC needs a browser that understands framesets. We have a Lynx friendly version too. + + diff --git a/mod/chat/gui_sockets/arscd.php b/mod/chat/gui_sockets/arscd.php new file mode 100644 index 0000000000..25ac0fd8fb --- /dev/null +++ b/mod/chat/gui_sockets/arscd.php @@ -0,0 +1,264 @@ +#!/usr/local/php-cgi/current/bin/php -q +.\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"), "".$arsc_lang["youwerekicked"]."", $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 index 0000000000..354486fac6 --- /dev/null +++ b/mod/chat/gui_sockets/chatinput.php @@ -0,0 +1,36 @@ += 0) + { + echo $arsc_parameters["htmlhead_msginput_js"]; + ?> +
+ " value=""> +
+
+ + + +
+ + + \ 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 index 0000000000..aae09dc209 --- /dev/null +++ b/mod/chat/gui_sockets/index.php @@ -0,0 +1,26 @@ + + + + + + <?php echo $arsc_parameters["title"]; ?> + + + + + + + + /?arsc_sid=" NAME="msg" scrolling="auto" noresize marginwidth="2" marginheight="0"> + + + + + + + Sorry, this version of ARSC needs a browser that understands framesets. But we have a lynx-friendly version too. + + diff --git a/mod/chat/gui_text/index.php b/mod/chat/gui_text/index.php new file mode 100644 index 0000000000..85e38341e5 --- /dev/null +++ b/mod/chat/gui_text/index.php @@ -0,0 +1,122 @@ + + + + + ".$arsc_message."", $arsc_room, 0); ?> + + + + + + + + <?php echo $arsc_parameters["title"]; ?> + + + +
+ + + + + " value=""> + "> +     +
+ @"; + } + if ($arsc_a["user"] == $arsc_my["user"]) + { + echo "".$arsc_opstring.$arsc_a["user"]."\n"; + } + else + { + echo "".$arsc_opstring.$arsc_a["user"]."\n"; + } + } + echo "
"; + $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'"); + ?> + + + diff --git a/mod/chat/icon.gif b/mod/chat/icon.gif new file mode 100755 index 0000000000000000000000000000000000000000..ad43629a6013d47b816422485ad5c078a88dfcfc GIT binary patch literal 99 zcmZ?wbhEHb6krfwn8?8J|Ns9JCr&Vc8Hzty7#SFt8FYYLpsWA`1Cz;|)|JPY_!nnv zJY*@uvFCGp=Cl%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 = "id\">$course->shortname ->"; + } + + 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 = "coursemodule\">$chat->name"; + + if ($course->format == "weeks" or $course->format == "topics") { + $table->data[] = array ($chat->section, $link); + } else { + $table->data[] = array ($link); + } + } + + echo "
"; + + 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 index 0000000000..00827c9f2a --- /dev/null +++ b/mod/chat/insert.php @@ -0,0 +1,43 @@ +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 index 0000000000..69cf7ba737 --- /dev/null +++ b/mod/chat/lib.php @@ -0,0 +1,396 @@ + is used to get some browsers starting with output +$CHAT_HTMLHEAD = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"; + +// The HTML head for the message window to start with (with js scrolling) +$CHAT_HTMLHEAD_JS = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"; + +// The HTML code for standard empty pages (e.g. if a user was kicked out) +$CHAT_HTMLHEAD_OUT = "You are out!body\">"; + +// The HTML head for the message input page +$CHAT_HTMLHEAD_MSGINPUT = "Message Inputbody\">"; + +// The HTML code for the message input page, with JavaScript +$CHAT_HTMLHEAD_MSGINPUT_JS = "Message Input\n\nbody\" 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"; + } + ?> + + + > + + + + + + + + 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 = "
$picture"; + $output .= "$strtime $message"; + $output .= "
"; + 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 = "
$picture"; + $output .= "$strtime $user->firstname: $message"; + $output .= "
"; + + return addslashes($output); + +} + + +?> diff --git a/mod/chat/mod.html b/mod/chat/mod.html new file mode 100644 index 0000000000..44782ae7b3 --- /dev/null +++ b/mod/chat/mod.html @@ -0,0 +1,60 @@ +name)) { + $form->name = ""; + } + if (!isset($form->intro)) { + $form->intro = ""; + } + if (!isset($form->messages)) { + $form->messages = 1000; + } +?> +
action="mod.php"> + + + + + + + + + + + + + + +

:

+ +

:

+ + "; + helpbutton("questions", get_string("helpquestions"), "moodle", true, true); + echo "
"; + emoticonhelpbutton("form", "intro"); + echo "
"; + ?> +
+
+ +

:

+
+ messages, "", "", ""); + ?> +
+
+ + + + + + + +"> +"> +
+
diff --git a/mod/chat/users.php b/mod/chat/users.php new file mode 100644 index 0000000000..f635e5d2e3 --- /dev/null +++ b/mod/chat/users.php @@ -0,0 +1,64 @@ +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 ""; +foreach ($chatusers as $chatuser) { + echo ""; +} +echo "
"; + print_user_picture($chatuser->id, 0, $chatuser->picture, false, false, false); + echo ""; + echo "

$chatuser->firstname $chatuser->lastname

"; + echo "
"; + +?> diff --git a/mod/chat/version.php b/mod/chat/version.php new file mode 100644 index 0000000000..7582545cf2 --- /dev/null +++ b/mod/chat/version.php @@ -0,0 +1,11 @@ +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 index 0000000000..2d161ef5ff --- /dev/null +++ b/mod/chat/view.php @@ -0,0 +1,92 @@ +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 = "id\">$course->shortname ->"; + } + + $strchats = get_string("modulenameplural", "chat"); + $strchat = get_string("modulename", "chat"); + $strenterchat = get_string("enterchat", "chat"); + + print_header("$course->shortname: $chat->name", "$course->fullname", + "$navigation id>$strchats -> $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 "

"; + notify("(Note: This chat module is an early alpha version)"); + echo "

"; + + 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 "



"; + + +/// Finish the page + print_footer($course); + +?> -- 2.39.5