chat_refresh_room)) { set_config("chat_refresh_room", 5); } if (!isset($CFG->chat_refresh_userlist)) { set_config("chat_refresh_userlist", 10); } if (!isset($CFG->chat_old_ping)) { set_config("chat_old_ping", 30); } define("CHAT_DRAWBOARD", false); // Look into this later // The HTML head for the message window to start with ( 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 = "wwwroot/mod/chat/view.php?c=$chat->id\">$chat->name
";
}
$current = $chatuser->chatid;
}
$fullname = fullname($chatuser);
echo " - $fullname
";
}
echo "
";
return true;
}
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;
chat_update_chat_times();
chat_delete_old_users();
/// Delete old messages
if ($chats = get_records("chat")) {
foreach ($chats as $chat) {
if ($chat->keepdays) {
$timeold = time() - ($chat->keepdays * 24 * 3600);
delete_records_select("chat_messages", "chatid = '$chat->id' AND timestamp < '$timeold'");
}
}
}
return true;
}
function chat_get_participants($chatid) {
//Returns the users with data in one chat
//(users with records in chat_messages, students)
global $CFG;
//Get students
$students = get_records_sql("SELECT DISTINCT u.*
FROM {$CFG->prefix}user u,
{$CFG->prefix}chat_messages c
WHERE c.chatid = '$chatid' and
u.id = c.userid");
//Return students array (it contains an array of unique users)
return ($students);
}
//////////////////////////////////////////////////////////////////////
/// 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, c.lastmessageping
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) {
/// Efficient way to extract just the latest message
/// Uses ADOdb directly instead of get_record_sql()
/// because the LIMIT command causes problems with
/// the developer debugging in there.
global $db, $CFG;
if (!$rs = $db->Execute("SELECT *
FROM {$CFG->prefix}chat_messages
WHERE chatid = '$chatid'
ORDER BY timestamp DESC LIMIT 1")) {
return false;
}
if ($rs->RecordCount() == 1) {
return (object)$rs->fields;
} else {
return false; // Found no records
}
}
//////////////////////////////////////////////////////////////////////
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 = $chatuser->firstping = $chatuser->lastmessageping = time();
$chatuser->sid = random_string(32);
if (!insert_record("chat_users", $chatuser)) {
return false;
}
return $chatuser->sid;
}
function chat_delete_old_users() {
// Delete the old and in the way
global $CFG;
$timeold = time() - $CFG->chat_old_ping;
if ($oldusers = get_records_select("chat_users", "lastping < '$timeold'") ) {
delete_records_select("chat_users", "lastping < '$timeold'");
foreach ($oldusers as $olduser) {
$message->chatid = $olduser->chatid;
$message->userid = $olduser->userid;
$message->message = "exit";
$message->system = 1;
$message->timestamp = time();
if (!insert_record("chat_messages", $message)) {
error("Could not insert a chat message!");
}
}
}
}
function chat_update_chat_times($chatid=0) {
/// Updates chat records so that the next chat time is correct
$timenow = time();
if ($chatid) {
if (!$chats[] = get_record_select("chat", "id = '$chatid' AND chattime <= '$timenow' AND schedule > '0'")) {
return;
}
} else {
if (!$chats = get_records_select("chat", "chattime <= '$timenow' AND schedule > '0'")) {
return;
}
}
foreach ($chats as $chat) {
switch ($chat->schedule) {
case 1: // Single event - turn off schedule and disable
$chat->chattime = 0;
$chat->schedule = 0;
break;
case 2: // Repeat daily
$chat->chattime += 24 * 3600;
break;
case 3: // Repeat weekly
$chat->chattime += 7 * 24 * 3600;
break;
}
update_record("chat", $chat);
}
}
function chat_browser_detect($HTTP_USER_AGENT) {
if(eregi("(opera) ([0-9]{1,2}.[0-9]{1,3}){0,1}", $HTTP_USER_AGENT, $match)
|| 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";
}
?>
$picture | "; $output->html .= "$output->text"; $output->html .= " |
$picture | "; $output->html .= "$outinfo"; if ($outmain) { $output->html .= ": $outmain"; } $output->html .= " |