Browse files

radical chat clean up, see forum for details

  • Loading branch information...
1 parent 60ecca3 commit 516121bd0d001433eba0d1bb54220bc64b0a9d74 skodak committed Feb 3, 2005
View
6 mod/chat/chatd.php
@@ -531,7 +531,7 @@ function promote_final($sessionid, $groupid, $customdata) {
$this->dismiss_half($sessionid, false);
$this->write_data($this->conn_sets[$sessionid][CHAT_CONNECTION_CHANNEL], $CHAT_HTMLHEAD_JS);
$this->trace('Connection accepted: '.$this->conn_sets[$sessionid][CHAT_CONNECTION_CHANNEL].', SID: '.$sessionid.' UID: '.$chatuser->userid.' GID: '.intval($groupid), E_USER_WARNING);
-
+/*
// Finally, broadcast the "entered the chat" message
$msg = &New stdClass;
@@ -544,7 +544,7 @@ function promote_final($sessionid, $groupid, $customdata) {
insert_record('chat_messages', $msg);
$this->message_broadcast($msg, $this->sets_info[$sessionid]['user']);
-
+*/
return true;
}
@@ -973,7 +973,7 @@ function cli_switch($switch, $param = NULL) {
if($changed > 0) {
// Let's see what it has to say
- $data = socket_read($handle, 512);
+ $data = socket_read($handle, 2048); // should be more to prevent empty pages and repeated messages!!
if(empty($data)) {
continue;
}
View
5 mod/chat/db/mysql.php
@@ -53,6 +53,11 @@ function chat_upgrade($oldversion) {
modify_database('','ALTER TABLE prefix_chat_users ADD INDEX `groupid` (`groupid`);');
}
+ if ($oldversion < 2005020300) {
+ table_column('chat_users', '', 'course');
+ table_column('chat_users', '', 'lang', 'varchar', '10', '', '');
+ }
+
return true;
}
View
2 mod/chat/db/mysql.sql
@@ -52,6 +52,8 @@ CREATE TABLE `prefix_chat_users` (
`lastping` int(10) unsigned NOT NULL default '0',
`lastmessageping` int(10) unsigned NOT NULL default '0',
`sid` varchar(32) NOT NULL default '',
+ `course` int(10) NOT NULL default '0',
+ `lang` varchar(10) NOT NULL default '',
PRIMARY KEY (`id`),
KEY `userid` (`userid`),
KEY `lastping` (`lastping`),
View
4 mod/chat/db/oci8po.sql
@@ -93,7 +93,9 @@ CREATE TABLE prefix_chat_users (
firstping number(10) default '0' not null,
lastping number(10) default '0' not null,
lastmessageping number(10) default '0' not null,
- sid varchar2(32) default '' not null
+ sid varchar2(32) default '' not null,
+ course number(10) default '0' not null,
+ lang varchar2(10) default '' not null
);
create index userid on prefix_chat_users(userid);
View
6 mod/chat/db/postgres7.php
@@ -42,9 +42,13 @@ function chat_upgrade($oldversion) {
modify_database('','CREATE INDEX prefix_chat_users_lastping_idx ON prefix_chat_users (lastping);');
}
+ if ($oldversion < 2005020300) {
+ table_column('chat_users', '', 'course');
+ table_column('chat_users', '', 'lang', 'varchar', '10', '', '');
+ }
+
return true;
}
?>
-
View
2 mod/chat/db/postgres7.sql
@@ -56,6 +56,8 @@ CREATE TABLE prefix_chat_users (
lastping integer NOT NULL default '0',
lastmessageping integer NOT NULL default '0',
sid varchar(32) NOT NULL default '',
+ course integer NOT NULL default '0',
+ lang varchar(10) NOT NULL default '',
PRIMARY KEY (id)
);
View
38 mod/chat/drawboard.php
@@ -1,38 +0,0 @@
-<?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();
-}
-?>
View
33 mod/chat/gui_header/chatinput.php
@@ -1,33 +0,0 @@
-<?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"];
-}
-?>
View
74 mod/chat/gui_header/chatmsg.php
@@ -1,74 +0,0 @@
-<?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 = getremoteaddr();
- 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"];
-}
-?>
View
23 mod/chat/gui_header/index.php
@@ -1,23 +0,0 @@
-<?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>
View
92 mod/chat/gui_header_js/chatinput.php
@@ -1,64 +1,50 @@
-<?php
+<?php // $Id$
-require("../../../config.php");
-require("../lib.php");
+ $nomoodlecookie = true; // Session not needed!
-require_variable($chat_sid);
-optional_variable($groupid);
-optional_variable($chat_pretext, '');
+ require('../../../config.php');
+ require('../lib.php');
-if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
- echo "Not logged in!";
- die;
-}
+ $chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
-if (!$chat = get_record("chat", "id", $chatuser->chatid)) {
- error("No chat found");
-}
-require_login($chat->course);
+ if (!$chatuser = get_record('chat_users', 'sid', $chat_sid)) {
+ error('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>
-
-<?php include("$CFG->javascript"); ?>
-
-<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>
+ chat_force_language($chatuser->lang);
-<body bgcolor="<?php echo $THEME->body ?>"
- OnLoad="document.f.chat_message.focus();document.f.chat_message.select();">
+ ob_start();
+ ?>
+ <script type="text/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>
+ <?php
-<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; ?>" />
-<?php helpbutton("chatting", get_string("helpchatting", "chat"), "chat", true, false); ?>
-</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="groupid" value="<?php echo $groupid ?>" />
- <input type="hidden" name="chat_version" value="header_js" />
- <input type="hidden" name="chat_message" />
-</form>
+ $meta = ob_get_clean();
+ print_header('', '', '', 'f.chat_message', $meta, false);
+?>
+ <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 helpbutton('chatting', get_string('helpchatting', 'chat'), 'chat', true, false); ?>
+ </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_message" />
+ </form>
</body>
-
-</html>
+</html>
View
62 mod/chat/gui_header_js/index.php
@@ -1,73 +1,75 @@
-<?php
+<?php // $Id$
require_once('../../../config.php');
require_once('../lib.php');
- require_variable($id);
- optional_variable($groupid, -1);
+ $id = required_param('id', PARAM_INT);
+ $groupid = optional_param('groupid', 0, PARAM_INT); //only for teachers
- if (!$chat = get_record("chat", "id", $id)) {
- error("Could not find that chat room!");
+ 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 (!$course = get_record('course', 'id', $chat->course)) {
+ error('Could not find the course this belongs to!');
}
- if (!$cm = get_coursemodule_from_instance("chat", $chat->id, $course->id)) {
- error("Course Module ID was incorrect");
+ if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
+ error('Course Module ID was incorrect');
}
-
+
require_login($course->id);
-
+
if (isguest()) {
- error("Guest does not have access to chat rooms");
+ error('Guest does not have access to chat rooms');
+ }
+
+ if (!$cm->visible and !isteacher($course->id)) {
+ print_header();
+ notice(get_string("activityiscurrentlyhidden"));
}
/// Check to see if groups are being used here
- if ($groupmode = groupmode($course, $cm)) { // Groups are being used
- if ($currentgroup = get_and_set_current_group($course, $groupmode, $groupid)) {
- if (!$group = get_record('groups', 'id', $currentgroup)) {
- error("That group (id $currentgroup) doesn't exist!");
+ if ($groupmode = groupmode($course, $cm)) { // Groups are being used
+ if ($groupid = get_and_set_current_group($course, $groupmode, $groupid)) {
+ if (!$group = get_record('groups', 'id', $groupid)) {
+ error("That group (id $groupid) doesn't exist!");
}
$groupname = ': '.$group->name;
} else {
$groupname = ': '.get_string('allparticipants');
}
} else {
- $currentgroup = false;
+ $groupid = 0;
$groupname = '';
}
- if (!$chat_sid = chat_login_user($chat->id, "header_js", $currentgroup)) {
- error("Could not log in to chat room!!");
+ if (!$chat_sid = chat_login_user($chat->id, 'header_js', $groupid, $course)) {
+ error('Could not log in to chat room!!');
}
- if ($currentgroup !== false) {
- $params = "chat_enter=true&chat_sid=$chat_sid&amp;groupid=$currentgroup";
- } else {
- $params = "chat_enter=true&chat_sid=$chat_sid";
- }
+ $params = "chat_sid=$chat_sid";
- $strchat = get_string("modulename", "chat");
-
+ $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>
+ <meta http-equiv="content-type" content="text/html; charset=<?php echo get_string('thischarset'); ?>" />
<title>
<?php echo "$strchat: $course->shortname: $chat->name$groupname" ?>
</title>
</head>
<frameset cols="*,200" border="5" framespacing="no" frameborder="yes" marginwidth="2" marginheight="1">
- <frameset rows="0,0,*,40" border="0" framespacing="no" frameborder="no" marginwidth="2" marginheight="1">
+ <frameset rows="0,0,*,50" 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?<?php echo $params ?>" scrolling="no" marginwidth="0" marginheight="0">
+ <frame src="jsupdate.php?<?php echo $params ?>" name="jsupdate" scrolling="no" marginwidth="0" marginheight="0">
<frame src="chatmsg.php" name="msg" scrolling="auto" marginwidth="2" marginheight="1">
<frame src="chatinput.php?<?php echo $params ?>" name="input" scrolling="no" marginwidth="2" marginheight="1">
</frameset>
- <frame src="../users.php?<?php echo $params ?>" name="users" scrolling="auto" marginwidth="5" marginheight="5">
+ <frame src="users.php?<?php echo $params ?>" name="users" scrolling="auto" marginwidth="5" marginheight="5">
</frameset>
<noframes>
Sorry, this version of Moodle Chat needs a browser that handles frames.
View
65 mod/chat/gui_header_js/insert.php
@@ -0,0 +1,65 @@
+<?php // $Id$
+
+ include('../../../config.php');
+ include('../lib.php');
+
+ $chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
+ $chat_message = required_param('chat_message', PARAM_RAW);
+
+ if (!$chatuser = get_record('chat_users', 'sid', $chat_sid)) {
+ error('Not logged in!');
+ }
+
+ if (!$chat = get_record('chat', 'id', $chatuser->chatid)) {
+ error('No chat found');
+ }
+
+ if (!$course = get_record('course', 'id', $chat->course)) {
+ error('Could not find the course this belongs to!');
+ }
+
+ require_login($course->id);
+
+ if (isguest()) {
+ error('Guest does not have access to chat rooms');
+ }
+
+ session_write_close();
+
+/// Delete old users now
+
+ chat_delete_old_users();
+
+/// Clean up the message
+
+ $chat_message = addslashes(clean_text(stripslashes($chat_message), FORMAT_MOODLE)); // Strip bad tags
+
+/// Add the message to the database
+
+ if (!empty($chat_message)) {
+
+ $message->chatid = $chatuser->chatid;
+ $message->userid = $chatuser->userid;
+ $message->groupid = $chatuser->groupid;
+ $message->message = $chat_message;
+ $message->timestamp = time();
+
+ if (!insert_record('chat_messages', $message)) {
+ error('Could not insert a chat message!');
+ }
+
+ $chatuser->lastmessageping = time() - 2;
+ update_record('chat_users', $chatuser);
+
+ if ($cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
+ add_to_log($course->id, 'chat', 'talk', "view.php?id=$cm->id", $chat->id, $cm->id);
+ }
+ }
+
+ if ($chatuser->version == 'header_js') {
+ /// force msg referesh ASAP
+ echo '<script type="text/javascript">parent.jsupdate.location.href = parent.jsupdate.document.anchors[0].href;</script>';
+ }
+
+ //redirect('empty.php');
+?>
View
156 mod/chat/gui_header_js/jsupdate.php
@@ -1,73 +1,107 @@
-<?php
+<?php // $Id$
-require("../../../config.php");
-require("../lib.php");
+ $nomoodlecookie = true; // Session not needed!
-$groupid = empty($_GET['groupid']) ? 0 : $_GET['groupid'];
-$groupselect = $groupid ? " AND (groupid='$groupid' OR groupid='0') " : "";
+ require('../../../config.php');
+ require('../lib.php');
-if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
- echo "Not logged in!";
- die;
-}
+ $chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
+ $chat_lasttime = optional_param('chat_lasttime', 0, PARAM_INT);
-if (!$chat = get_record("chat", "id", $chatuser->chatid)) {
- error("No chat found");
-}
+ if (!$chatuser = get_record('chat_users', 'sid', $chat_sid)) {
+ error('Not logged in!');
+ }
-require_login($chat->course);
+ chat_force_language($chatuser->lang);
-if ($message = chat_get_latest_message($chatuser->chatid, $groupid)) {
- $chat_newlasttime = $message->timestamp;
-} else {
- $chat_newlasttime = 0;
-}
+ // force deleting of timed out users if there is a silence in room or just entering
+ if ((time() - $chat_lasttime) > $CFG->chat_old_ping) {
+ // must be done before chat_get_latest_message!!!
+ chat_delete_old_users();
+ }
-if (empty($chat_lasttime)) {
- $chat_lasttime = 0;
-}
+ if ($message = chat_get_latest_message($chatuser->chatid, $chatuser->groupid)) {
+ $chat_newlasttime = $message->timestamp;
+ } else {
+ $chat_newlasttime = 0;
+ }
+ if ($chat_lasttime == 0) { //display some previous messages
+ $chat_lasttime = time() - $CFG->chat_old_ping; //TO DO - any better value??
+ }
-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: $CFG->chat_refresh_room; url=jsupdate.php?chat_sid=$chat_sid&chat_lasttime=$chat_newlasttime&groupid=$groupid");
+ $refreshurl = "jsupdate.php?chat_sid=$chat_sid&chat_lasttime=$chat_newlasttime"; // no &amp; in url, does not work in header!
+ $timenow = time();
+
+ $groupselect = $chatuser->groupid ? " AND (groupid='".$chatuser->groupid."' OR groupid='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: $CFG->chat_refresh_room; url=$refreshurl");
?>
- <!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
- $beep = false;
-
- if ($chat_lasttime) {
- if ($messages = get_records_select("chat_messages",
- "chatid = '$chatuser->chatid' AND timestamp > '$chat_lasttime' $groupselect",
- "timestamp ASC")) {
- foreach ($messages as $message) {
- $formatmessage = chat_format_message($message, $chat->course);
- if ($formatmessage->beep) {
- $beep = $formatmessage->beep;
- }
- echo "parent.msg.document.write('".addslashes($formatmessage->html)."\\n');";
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=<?php echo get_string('thischarset'); ?>" />
+ <script type="text/javascript">
+ <!--
+ <?php
+ $beep = false;
+ $refreshusers = false;
+ $us = array ();
+ if (($chat_lasttime != $chat_newlasttime)
+ and $messages = get_records_select("chat_messages",
+ "chatid = '$chatuser->chatid' AND timestamp > '$chat_lasttime' $groupselect",
+ "timestamp ASC")) {
+
+ if (!$currentuser = get_record('user', 'id', $chatuser->userid)) {
+ error('User does not exist!');
+ }
+ $currentuser->description = '';
+
+ foreach ($messages as $message) {
+ $formatmessage = chat_format_message($message, $chatuser->course, $currentuser);
+ if ($formatmessage->beep) {
+ $beep = true;
+ }
+ if ($formatmessage->refreshusers) {
+ $refreshusers = true;
+ }
+ $us[$message->userid] = $timenow - $message->timestamp;
+ echo "parent.msg.document.write('".addslashes($formatmessage->html)."\\n');\n";
}
- }
- }
-
- $chatuser->lastping = time();
- update_record("chat_users", $chatuser);
- ?>
- parent.msg.scroll(1,5000000);
- // -->
- </script>
- </head>
- <body>
- <?php if ($beep) { ?>
- <embed src="../beep.wav" autostart="true" hidden="true" />
- <?php } ?>
- </body>
- </html>
+ }
+
+ $chatuser->lastping = time();
+ update_record('chat_users', $chatuser);
+
+ if ($refreshusers) {
+ echo "parent.users.location.href = parent.users.document.anchors[0].href;\n";
+ } else {
+ foreach($us as $uid=>$lastping) {
+ $min = (int) ($lastping/60);
+ $sec = $lastping - ($min*60);
+ $min = $min < 10 ? '0'.$min : $min;
+ $sec = $sec < 10 ? '0'.$sec : $sec;
+ $idle = $min.':'.$sec;
+ echo "parent.users.document.getElementById('uidle{$uid}').innerHTML = '$idle';";
+ }
+ }
+ ?>
+ parent.msg.scroll(1,5000000);
+ // -->
+ </script>
+ </head>
+ <body>
+ <?php
+ if ($beep) {
+ echo '<embed src="../beep.wav" autostart="true" hidden="true" name="beep" />';
+ }
+ ?>
+ <a href="<? echo $refreshurl ?>" name="refreshlink">Refresh link</a>
+ </body>
+</html>
View
116 mod/chat/gui_header_js/users.php
@@ -0,0 +1,116 @@
+<?php // $Id$
+
+ $nomoodlecookie = true; // Session not needed!
+
+ include('../../../config.php');
+ include('../lib.php');
+
+ $chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
+ $beep = optional_param('beep', 0, PARAM_INT); // beep target
+
+ if (!$chatuser = get_record('chat_users', 'sid', $chat_sid)) {
+ error('Not logged in!');
+ }
+
+ chat_force_language($chatuser->lang);
+
+ $courseid = $chatuser->course;
+
+ if ($beep) {
+ $message->chatid = $chatuser->chatid;
+ $message->userid = $chatuser->userid;
+ $message->groupid = $chatuser->groupid;
+ $message->message = "beep $beep";
+ $message->system = 0;
+ $message->timestamp = time();
+
+ if (!insert_record('chat_messages', $message)) {
+ error('Could not insert a chat message!');
+ }
+
+ $chatuser->lastmessageping = time(); // A beep is a ping ;-)
+ }
+
+ $chatuser->lastping = time();
+ update_record('chat_users', $chatuser);
+
+ $refreshurl = "users.php?chat_sid=$chat_sid";
+
+ /// Get list of users
+
+ if (!$chatusers = chat_get_users($chatuser->chatid, $chatuser->groupid)) {
+ error(get_string('errornousers', 'chat'));
+ }
+
+ ob_start();
+ ?>
+ <script type="text/javascript">
+ <!--
+ var timer = null
+ var f = 1; //seconds
+ var uidles = new Array(<?php echo count($chatusers) ?>);
+ <?php
+ $i = 0;
+ foreach ($chatusers as $chatuser) {
+ echo "uidles[$i] = 'uidle{$chatuser->id}';\n";
+ $i++;
+ }
+ ?>
+
+ function stop() {
+ clearTimeout(timer)
+ }
+
+ function start() {
+ timer = setTimeout("update()", f*1000);
+ }
+
+ function update() {
+ for(i=0; i<uidles.length; i++) {
+ el = document.getElementById(uidles[i]);
+ parts = el.innerHTML.split(":");
+ time = f + (parseInt(parts[0], 10)*60) + parseInt(parts[1], 10);
+ min = Math.floor(time/60);
+ sec = time % 60;
+ el.innerHTML = ((min < 10) ? "0" : "") + min + ":" + ((sec < 10) ? "0" : "") + sec;
+ }
+ timer = setTimeout("update()", f*1000);
+ }
+ // -->
+ </script>
+ <?php
+
+
+ /// Print headers
+ $meta = ob_get_clean();
+ print_header('', '', '', '', $meta, false, '', '', false, 'onload="start()" onunload="stop()"');
+
+
+ /// Print user panel body
+ $timenow = time();
+ $stridle = get_string('idle', 'chat');
+ $strbeep = get_string('beep', 'chat');
+
+
+ echo '<div style="display: none"><a href="'.$refreshurl.'" name="refreshlink">Refresh link</a></div>';
+ echo '<table width="100%">';
+ foreach ($chatusers as $chatuser) {
+ $lastping = $timenow - $chatuser->lastmessageping;
+ $min = (int) ($lastping/60);
+ $sec = $lastping - ($min*60);
+ $min = $min < 10 ? '0'.$min : $min;
+ $sec = $sec < 10 ? '0'.$sec : $sec;
+ $idle = $min.':'.$sec;
+ echo '<tr><td width="35">';
+ echo "<a target=\"_new\" onClick=\"return openpopup('$CFG->wwwroot/user/view.php?id=$chatuser->id&amp;course=$courseid','user$chatuser->id','');\" href=\"$CFG->wwwroot/user/view.php?id=$chatuser->id&amp;course=$courseid\">";
+ print_user_picture($chatuser->id, 0, $chatuser->picture, false, false, false);
+ echo '</a></td><td valign="center">';
+ echo '<p><font size="1">';
+ echo fullname($chatuser).'<br />';
+ echo "<span class=\"dimmed_text\">$stridle <span name=\"uidles\" id=\"uidle{$chatuser->id}\">$idle</span></span>";
+ echo " <a href=\"users.php?chat_sid=$chat_sid&amp;beep=$chatuser->id\">$strbeep</a>";
+ echo '</font></p>';
+ echo '<td></tr>';
+ }
+ echo '</table></body></html>';
+?>
View
177 mod/chat/gui_java/MainFrameGui.java
@@ -1,177 +0,0 @@
-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;
- }
-}
View
68 mod/chat/gui_java/TextDialog.java
@@ -1,68 +0,0 @@
-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();
- }
-}
View
90 mod/chat/gui_java/arsc.java
@@ -1,90 +0,0 @@
-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);
- }
- }
- }
-}
View
35 mod/chat/gui_push_js/chatinput.php
@@ -1,35 +0,0 @@
-<?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;
-}
-?>
View
98 mod/chat/gui_push_js/chatmsg.php
@@ -1,98 +0,0 @@
-<?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 = getremoteaddr();
- 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"];
-}
-?>
View
24 mod/chat/gui_push_js/index.php
@@ -1,24 +0,0 @@
-<?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>
View
47 mod/chat/gui_sockets/chatinput.php
@@ -1,31 +1,31 @@
-<?php
+<?php // $Id$
-require("../../../config.php");
-require("../lib.php");
+ $nomoodlecookie = true; // Session not needed!
-require_variable($chat_sid);
-optional_variable($groupid);
+ require('../../../config.php');
+ require('../lib.php');
-if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
- echo "Not logged in!";
- die;
-}
+ $chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
+ $groupid = optional_param('groupid', 0, PARAM_INT);
-if (!$chat = get_record("chat", "id", $chatuser->chatid)) {
- error("No chat found");
-}
+ if (!$chatuser = get_record('chat_users', 'sid', $chat_sid)) {
+ error('Not logged in!');
+ }
-require_login($chat->course);
-optional_variable($chat_pretext, '');
+ chat_force_language($chatuser->lang);
?>
-<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
+<meta http-equiv="content-type" content="text/html; charset=<?php echo get_string('thischarset'); ?>" />
<title>Message Input</title>
-<?php include("$CFG->javascript"); ?>
+<?php
+ $focus = '';
+ include("$CFG->javascript");
+?>
<script type="text/javascript">
<!--
@@ -44,9 +44,9 @@ function empty_field_and_submit() {
function prepareusers() {
var frm = window.parent.frames;
for(i = 0; i < frm.length; ++i) {
- if(frm(i).name == "users") {
- window.userFrame = frm(i);
- window.userHREF = frm(i).location.href;
+ if(frm[i]).name == "users") {
+ window.userFrame = frm[i];
+ window.userHREF = frm[i].location.href;
window.setTimeout("reloadusers();", <?php echo $CFG->chat_refresh_userlist; ?> * 1000);
}
}
@@ -63,17 +63,13 @@ function reloadusers() {
<body bgcolor="<?php echo $THEME->body ?>" onload="document.getElementById('inputform').chat_message.focus();document.getElementById('inputform').chat_message.select(); prepareusers();">
-<!--
-<form action="<?php echo "http://$CFG->chat_serverhost:$CFG->chat_serverport"; ?>" method="GET" target="empty" name="f" onsubmit="return empty_field_and_submit()">
--->
-<form action="../insert.php" method="get" target="empty" id="inputform" onsubmit="return empty_field_and_submit();">
-&gt;&gt; <input type="text" name="chat_message" size="60" value="<?php echo $chat_pretext; ?>" />
+<form action="<?php echo "http://$CFG->chat_serverhost:$CFG->chat_serverport/"; ?>" method="get" target="empty" id="inputform" onsubmit="return empty_field_and_submit();">
+&gt;&gt; <input type="text" name="chat_message" size="60" value="" />
<?php helpbutton("chatting", get_string("helpchatting", "chat"), "chat", true, false); ?>
</form>
<form action="<?php echo "http://$CFG->chat_serverhost:$CFG->chat_serverport/"; ?>" method="get" target="empty" id="sendform">
<input type="hidden" name="win" value="message" />
- <input type="hidden" name="chat_version" value="sockets" />
<input type="hidden" name="chat_message" value="" />
<input type="hidden" name="chat_msgidnr" value="0" />
<input type="hidden" name="chat_sid" value="<?php echo $chat_sid ?>" />
@@ -82,4 +78,3 @@ function reloadusers() {
</body>
</html>
-
View
40 mod/chat/gui_sockets/index.php
@@ -1,9 +1,10 @@
-<?php
+<?php // $Id$
+
require_once('../../../config.php');
require_once('../lib.php');
- require_variable($id);
- optional_variable($groupid, -1);
+ $id = required_param('id', PARAM_INT);
+ $groupid = optional_param('groupid', 0, PARAM_INT); //only for teachers
if (!$chat = get_record('chat', 'id', $id)) {
error('Could not find that chat room!');
@@ -23,31 +24,35 @@
error('Guest does not have access to chat rooms');
}
+ if (!$cm->visible and !isteacher($course->id)) {
+ print_header();
+ notice(get_string("activityiscurrentlyhidden"));
+ }
+
/// Check to see if groups are being used here
- if ($groupmode = groupmode($course, $cm)) { // Groups are being used
- if ($currentgroup = get_and_set_current_group($course, $groupmode, $groupid)) {
- if (!$group = get_record('groups', 'id', $currentgroup)) {
- error("That group (id $currentgroup) doesn't exist!");
+ if ($groupmode = groupmode($course, $cm)) { // Groups are being used
+ if ($groupid = get_and_set_current_group($course, $groupmode, $groupid)) {
+ if (!$group = get_record('groups', 'id', $groupid)) {
+ error("That group (id $groupid) doesn't exist!");
}
$groupname = ': '.$group->name;
} else {
$groupname = ': '.get_string('allparticipants');
}
} else {
- $currentgroup = false;
+ $groupid = 0;
$groupname = '';
}
- if (!$chat_sid = chat_login_user($chat->id, 'sockets', $currentgroup)) {
- error("Could not log in to chat room!!");
- }
+ chat_delete_old_users();
- if ($currentgroup !== false) {
- $params = "chat_enter=true&amp;chat_sid=$chat_sid&amp;groupid=$currentgroup";
- } else {
- $params = "chat_enter=true&amp;chat_sid=$chat_sid&amp;groupid=0";
+ if (!$chat_sid = chat_login_user($chat->id, 'sockets', $groupid, $course)) {
+ error('Could not log in to chat room!!');
}
+
+ $params = "chat_sid=$chat_sid&amp;groupid=$groupid";
+
$strchat = get_string("modulename", "chat");
@@ -61,15 +66,12 @@
</title>
</head>
<frameset cols="*,200" border="5" framespacing="no" frameborder="yes" marginwidth="2" marginheight="1">
- <frameset rows="0,*,40" border="0" framespacing="no" frameborder="no" marginwidth="2" marginheight="1">
+ <frameset rows="0,*,50" border="0" framespacing="no" frameborder="no" marginwidth="2" marginheight="1">
<frame src="empty.php" name="empty" scrolling="auto" noresize marginwidth="2" marginheight="0">
<frame src="<?php echo "http://$CFG->chat_serverhost:$CFG->chat_serverport?win=chat&amp;$params"; ?>" name="msg" scrolling="auto" noresize marginwidth="2" marginheight="0">
<frame src="chatinput.php?<?php echo $params ?>" name="input" scrolling="no" marginwidth="2" marginheight="1">
</frameset>
<frame src="<?php echo "http://$CFG->chat_serverhost:$CFG->chat_serverport?win=users&amp;$params"; ?>" name="users" scrolling="auto" marginwidth="5" marginheight="5">
- <!--
- <frame src="../users.php?<?php echo $params ?>" name="users" scrolling="auto" marginwidth="5" marginheight="5">
- -->
</frameset>
<noframes>
Sorry, this version of Moodle Chat needs a browser that handles frames.
View
122 mod/chat/gui_text/index.php
@@ -1,122 +0,0 @@
-<?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 = getremoteaddr();
- mysql_query("UPDATE arsc_users SET lastping = '$arsc_ping', ip = '$arsc_ip' WHERE user = '$arsc_user'");
- ?>
- </body>
- </html>
- <?php
- }
-}
-else
-{
- echo $arsc_htmlhead_out;
-}
-?>
View
52 mod/chat/index.php
@@ -1,55 +1,55 @@
<?php // $Id$
- require_once("../../config.php");
- require_once("lib.php");
+ require_once('../../config.php');
+ require_once('lib.php');
- require_variable($id); // course
+ $id = required_param('id', PARAM_INT); // course
- if (! $course = get_record("course", "id", $id)) {
- error("Course ID is incorrect");
+ if (! $course = get_record('course', 'id', $id)) {
+ error('Course ID is incorrect');
}
require_course_login($course);
- add_to_log($course->id, "chat", "view all", "index.php?id=$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");
+ $strchats = get_string('modulenameplural', 'chat');
+ $strchat = get_string('modulename', 'chat');
/// Print the header
- print_header_simple($strchats, "", $strchats, "", "", true, "", navmenu($course));
+ print_header_simple($strchats, '', $strchats, '', '', true, '', navmenu($course));
/// Get all the appropriate data
- if (! $chats = get_all_instances_in_course("chat", $course)) {
- notice("There are no chats", "../../course/view.php?id=$course->id");
- die;
+ if (! $chats = get_all_instances_in_course('chat', $course)) {
+ 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");
+ $timenow = time();
+ $strname = get_string('name');
+ $strweek = get_string('week');
+ $strtopic = get_string('topic');
- if ($course->format == "weeks") {
+ if ($course->format == 'weeks') {
$table->head = array ($strweek, $strname);
- $table->align = array ("center", "left");
- } else if ($course->format == "topics") {
+ $table->align = array ('center', 'left');
+ } else if ($course->format == 'topics') {
$table->head = array ($strtopic, $strname);
- $table->align = array ("center", "left", "left", "left");
+ $table->align = array ('center', 'left', 'left', 'left');
} else {
$table->head = array ($strname);
- $table->align = array ("left", "left", "left");
+ $table->align = array ('left', 'left', 'left');
}
- $currentsection = "";
+ $currentsection = '';
foreach ($chats as $chat) {
if (!$chat->visible) {
//Show dimmed if the mod is hidden
@@ -58,24 +58,24 @@
//Show normal if the mod is visible
$link = "<a href=\"view.php?id=$chat->coursemodule\">$chat->name</a>";
}
- $printsection = "";
+ $printsection = '';
if ($chat->section !== $currentsection) {
if ($chat->section) {
$printsection = $chat->section;
}
- if ($currentsection !== "") {
+ if ($currentsection !== '') {
$table->data[] = 'hr';
}
$currentsection = $chat->section;
}
- if ($course->format == "weeks" or $course->format == "topics") {
+ if ($course->format == 'weeks' or $course->format == 'topics') {
$table->data[] = array ($printsection, $link);
} else {
$table->data[] = array ($link);
}
}
- echo "<br />";
+ echo '<br />';
print_table($table);
View
69 mod/chat/insert.php
@@ -1,69 +0,0 @@
-<?php
-
- include("../../config.php");
- include("lib.php");
-
- require_variable($chat_sid);
- require_variable($chat_version);
- require_variable($chat_message);
- optional_variable($groupid);
-
- if (!$chatuser = get_record("chat_users", "sid", $chat_sid)) {
- echo "Not logged in!";
- die;
- }
-
- if (!$chat = get_record("chat", "id", $chatuser->chatid)) {
- error("No chat found");
- }
-
- require_login($chat->course);
-
- if ($groupid) {
- if (!isteacheredit($chat->course) and !ismember($groupid)) {
- error("You can't chat here!");
- }
- }
-
-/// Clean up the message
-
- $chat_message = addslashes(clean_text(stripslashes($chat_message), FORMAT_MOODLE)); // Strip bad tags
-
-/// Add the message to the database
-
- if (!empty($chat_message)) {
-
- $message->chatid = $chatuser->chatid;
- $message->userid = $chatuser->userid;
- $message->groupid = $groupid;
- $message->message = $chat_message;
- $message->timestamp = time();
-
- if (!insert_record("chat_messages", $message)) {
- error("Could not insert a chat message!");
- }
-
- $chatuser->lastmessageping = time() - 2;
- update_record("chat_users", $chatuser);
-
- if ($cm = get_coursemodule_from_instance("chat", $chat->id, $chat->course)) {
- add_to_log($chat->course, "chat", "talk", "view.php?id=$cm->id", $chat->id, $cm->id);
- }
- }
-
-/// Go back to the other page
-
- if ($chat_version == "header" OR $chat_version == "box") {
- redirect("../gui_$chat_version/chatinput.php?chat_sid=$chat_sid&amp;groupid=$groupid");
-
- } else if ($chat_version == 'sockets') {
- //redirect('./gui_sockets/chatinput.php?chat_sid='.$chat_sid.'&amp;groupid='.$groupid);
-
- } else if ($chat_version == "text") {
- redirect("../gui_$chat_version/index.php?chat_sid=$chat_sid&chat_lastid=$chat_lastid&amp;groupid=$groupid");
-
- } else {
- redirect("empty.php");
- }
-
-?>
View
273 mod/chat/lib.php
@@ -27,8 +27,6 @@
set_config("chat_servermax", 100);
}
-define("CHAT_DRAWBOARD", false); // Look into this later
-
global $THEME;
// The HTML head for the message window to start with (<!-- nix --> is used to get some browsers starting with output
@@ -293,6 +291,20 @@ function chat_refresh_events($courseid = 0) {
return true;
}
+function chat_force_language($lang) {
+/// This function prepares moodle to operate in given language
+/// usable when $nomoodlecookie = true;
+/// BEWARE: there must be no $course, $USER or $SESSION
+ if(!empty($CFG->courselang)) {
+ uset($CFG->courselang);
+ }
+ if(!empty($CFG->locale)) {
+ uset($CFG->locale);
+ }
+ $CFG->lang = clean_filename($lang);
+ moodle_setlocale();
+}
+
//////////////////////////////////////////////////////////////////////
/// Functions that require some SQL
@@ -343,20 +355,50 @@ function chat_get_latest_message($chatid, $groupid=0) {
//////////////////////////////////////////////////////////////////////
+// login if not already logged in
-function chat_login_user($chatid, $version="header_js", $groupid=0) {
+function chat_login_user($chatid, $version, $groupid, $course) {
global $USER;
- $chatuser->chatid = $chatid;
- $chatuser->userid = $USER->id;
- $chatuser->groupid = $groupid;
- $chatuser->version = $version;
- $chatuser->ip = $USER->lastIP;
- $chatuser->lastping = $chatuser->firstping = $chatuser->lastmessageping = time();
- $chatuser->sid = random_string(32);
+ if ($chatuser = get_record_select('chat_users', "chatid='$chatid' AND userid='$USER->id' AND groupid='$groupid' LIMIT 1")) {
+ $chatuser->version = $version;
+ $chatuser->ip = $USER->lastIP;
+ $chatuser->lastping = time();