1c61c8d6 |
1 | <?php // $Id$ |
1515a89e |
2 | |
3 | /// Library of functions and constants for module chat |
4 | |
b5012f3e |
5 | if (!isset($CFG->chat_refresh_room)) { |
6 | set_config("chat_refresh_room", 5); |
b5de723d |
7 | } |
b5012f3e |
8 | if (!isset($CFG->chat_refresh_userlist)) { |
9 | set_config("chat_refresh_userlist", 10); |
b5de723d |
10 | } |
b5012f3e |
11 | if (!isset($CFG->chat_old_ping)) { |
34308732 |
12 | set_config("chat_old_ping", 35); |
b5de723d |
13 | } |
d434b9ae |
14 | if (!isset($CFG->chat_method)) { |
15 | set_config("chat_method", "header_js"); |
b5de723d |
16 | } |
d434b9ae |
17 | if (!isset($CFG->chat_serverhost)) { |
18 | set_config("chat_serverhost", $_SERVER['HTTP_HOST']); |
b5de723d |
19 | } |
d434b9ae |
20 | if (!isset($CFG->chat_serverip)) { |
21 | set_config("chat_serverip", $_SERVER['SERVER_ADDR']); |
b5de723d |
22 | } |
d434b9ae |
23 | if (!isset($CFG->chat_serverport)) { |
24 | set_config("chat_serverport", 9111); |
b5de723d |
25 | } |
d434b9ae |
26 | if (!isset($CFG->chat_servermax)) { |
27 | set_config("chat_servermax", 100); |
b5de723d |
28 | } |
1515a89e |
29 | |
30 | define("CHAT_DRAWBOARD", false); // Look into this later |
31 | |
ff458eb5 |
32 | global $THEME; |
1515a89e |
33 | |
34 | // The HTML head for the message window to start with (<!-- nix --> is used to get some browsers starting with output |
35 | $CHAT_HTMLHEAD = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\"><html><head></head>\n<body bgcolor=\"#FFFFFF\">\n\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n"; |
36 | |
37 | // The HTML head for the message window to start with (with js scrolling) |
38 | $CHAT_HTMLHEAD_JS = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\"><html><head><script language=\"JavaScript\">\n<!--\nfunction move()\n{\nif (scroll_active) window.scroll(1,400000);\nwindow.setTimeout(\"move()\",100);\n}\nscroll_active = true;\nmove();\n//-->\n</script>\n</head>\n<body bgcolor=\"#FFFFFF\" onBlur=\"scroll_active = true\" onFocus=\"scroll_active = false\">\n\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n"; |
39 | |
40 | // The HTML code for standard empty pages (e.g. if a user was kicked out) |
41 | $CHAT_HTMLHEAD_OUT = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\"><html><head><title>You are out!</title></head><body bgcolor=\"$THEME->body\"></body></html>"; |
42 | |
43 | // The HTML head for the message input page |
44 | $CHAT_HTMLHEAD_MSGINPUT = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\"><html><head><title>Message Input</title></head><body bgcolor=\"$THEME->body\">"; |
45 | |
46 | // The HTML code for the message input page, with JavaScript |
47 | $CHAT_HTMLHEAD_MSGINPUT_JS = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\"><html><head><title>Message Input</title>\n<script language=\"Javascript\">\n<!--\nscroll_active = true;\nfunction empty_field_and_submit()\n{\ndocument.fdummy.arsc_message.value=document.f.arsc_message.value;\ndocument.fdummy.submit();\ndocument.f.arsc_message.focus();\ndocument.f.arsc_message.select();\nreturn false;\n}\n// -->\n</script>\n</head><body bgcolor=\"$THEME->body\" OnLoad=\"document.f.arsc_message.focus();document.f.arsc_message.select();\">"; |
48 | |
fbabbd23 |
49 | // Dummy data that gets output to the browser as needed, in order to make it show output |
50 | $CHAT_DUMMY_DATA = "<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n"; |
1515a89e |
51 | |
52 | function chat_add_instance($chat) { |
b5de723d |
53 | /// Given an object containing all the necessary data, |
54 | /// (defined by the form in mod.html) this function |
55 | /// will create a new instance and return the id number |
1515a89e |
56 | /// of the new instance. |
57 | |
58 | $chat->timemodified = time(); |
59 | |
b5de723d |
60 | $chat->chattime = make_timestamp($chat->chatyear, $chat->chatmonth, $chat->chatday, |
fcd3a1ee |
61 | $chat->chathour, $chat->chatminute); |
b5de723d |
62 | |
8496c4af |
63 | if ($returnid = insert_record("chat", $chat)) { |
64 | |
65 | $event = NULL; |
66 | $event->name = $chat->name; |
67 | $event->description = $chat->intro; |
68 | $event->courseid = $chat->course; |
69 | $event->groupid = 0; |
70 | $event->userid = 0; |
71 | $event->modulename = 'chat'; |
72 | $event->instance = $returnid; |
73 | $event->eventtype = $chat->schedule; |
74 | $event->timestart = $chat->chattime; |
75 | $event->timeduration = 0; |
76 | |
77 | add_event($event); |
78 | } |
79 | |
80 | return $returnid; |
1515a89e |
81 | } |
82 | |
83 | |
84 | function chat_update_instance($chat) { |
b5de723d |
85 | /// Given an object containing all the necessary data, |
86 | /// (defined by the form in mod.html) this function |
1515a89e |
87 | /// will update an existing instance with new data. |
88 | |
89 | $chat->timemodified = time(); |
90 | $chat->id = $chat->instance; |
91 | |
b5de723d |
92 | $chat->chattime = make_timestamp($chat->chatyear, $chat->chatmonth, $chat->chatday, |
fcd3a1ee |
93 | $chat->chathour, $chat->chatminute); |
1515a89e |
94 | |
8496c4af |
95 | if ($returnid = update_record("chat", $chat)) { |
96 | |
97 | $event = NULL; |
98 | |
99 | if ($event->id = get_field('event', 'id', 'modulename', 'chat', 'instance', $chat->id)) { |
100 | |
101 | $event->name = $chat->name; |
102 | $event->description = $chat->intro; |
103 | $event->timestart = $chat->chattime; |
104 | |
105 | update_event($event); |
106 | } |
107 | } |
108 | |
109 | return $returnid; |
1515a89e |
110 | } |
111 | |
112 | |
113 | function chat_delete_instance($id) { |
b5de723d |
114 | /// Given an ID of an instance of this module, |
115 | /// this function will permanently delete the instance |
116 | /// and any data that depends on it. |
1515a89e |
117 | |
118 | if (! $chat = get_record("chat", "id", "$id")) { |
119 | return false; |
120 | } |
121 | |
122 | $result = true; |
123 | |
124 | # Delete any dependent records here # |
125 | |
126 | if (! delete_records("chat", "id", "$chat->id")) { |
127 | $result = false; |
128 | } |
129 | |
36eb856f |
130 | if (! delete_records('event', 'modulename', 'chat', 'instance', $chat->id)) { |
131 | $result = false; |
132 | } |
133 | |
1515a89e |
134 | return $result; |
135 | } |
136 | |
137 | function chat_user_outline($course, $user, $mod, $chat) { |
b5de723d |
138 | /// Return a small object with summary information about what a |
1515a89e |
139 | /// user has done with a given particular instance of this module |
140 | /// Used for user activity reports. |
141 | /// $return->time = the time they did it |
142 | /// $return->info = a short text description |
143 | |
5c05d23b |
144 | $return = NULL; |
1515a89e |
145 | return $return; |
146 | } |
147 | |
148 | function chat_user_complete($course, $user, $mod, $chat) { |
b5de723d |
149 | /// Print a detailed representation of what a user has done with |
1515a89e |
150 | /// a given particular instance of this module, for user activity reports. |
151 | |
152 | return true; |
153 | } |
154 | |
b7602a11 |
155 | function chat_print_recent_activity($course, $isteacher, $timestart) { |
156 | /// Given a course and a date, prints a summary of all chat rooms |
157 | /// that currently have people in them. |
1515a89e |
158 | /// This function is called from course/lib.php: print_recent_activity() |
159 | |
b7602a11 |
160 | global $CFG; |
161 | |
c5a05b95 |
162 | $timeold = time() - $CFG->chat_old_ping; |
163 | |
0469cccf |
164 | $lastpingsearch = ($CFG->chat_method == 'sockets') ? "": "AND cu.lastping > '$timeold'"; |
165 | |
132911c8 |
166 | if (!$chatusers = get_records_sql("SELECT u.id, cu.chatid, u.firstname, u.lastname |
b7602a11 |
167 | FROM {$CFG->prefix}chat_users as cu, |
cea57965 |
168 | {$CFG->prefix}chat as ch, |
b7602a11 |
169 | {$CFG->prefix}user as u |
b5de723d |
170 | WHERE cu.userid = u.id |
0469cccf |
171 | AND cu.chatid = ch.id $lastpingsearch |
cea57965 |
172 | AND ch.course = '$course->id' |
b7602a11 |
173 | ORDER BY cu.chatid ASC") ) { |
174 | return false; |
175 | } |
1515a89e |
176 | |
3120f6f2 |
177 | $isteacher = isteacher($course->id); |
b7602a11 |
178 | |
3120f6f2 |
179 | $outputstarted = false; |
b7602a11 |
180 | $current = 0; |
181 | foreach ($chatusers as $chatuser) { |
182 | if ($current != $chatuser->chatid) { |
183 | if ($current) { |
184 | echo "</p>"; |
185 | } |
186 | if ($chat = get_record("chat", "id", $chatuser->chatid)) { |
3120f6f2 |
187 | if (!($isteacher or instance_is_visible('chat', $chat))) { // Chat hidden to students |
188 | continue; |
189 | } |
190 | if (!$outputstarted) { |
191 | print_headline(get_string("currentchats", "chat").":"); |
192 | $outputstarted = true; |
193 | } |
1c61c8d6 |
194 | echo "<p><font size=\"1\"><a href=\"$CFG->wwwroot/mod/chat/view.php?c=$chat->id\">$chat->name</a></font><br />"; |
b7602a11 |
195 | } |
196 | $current = $chatuser->chatid; |
197 | } |
8f6ca087 |
198 | $fullname = fullname($chatuser); |
1c61c8d6 |
199 | echo " <font size=\"1\">- $fullname</font><br />"; |
b7602a11 |
200 | } |
48548144 |
201 | echo "<br />"; |
b7602a11 |
202 | |
203 | return true; |
1515a89e |
204 | } |
205 | |
206 | function chat_cron () { |
207 | /// Function to be run periodically according to the moodle cron |
b5de723d |
208 | /// This function searches for things that need to be done, such |
209 | /// as sending out mail, toggling flags etc ... |
1515a89e |
210 | |
211 | global $CFG; |
212 | |
fcd3a1ee |
213 | chat_update_chat_times(); |
214 | |
7d792369 |
215 | chat_delete_old_users(); |
216 | |
22a4491a |
217 | /// Delete old messages |
218 | if ($chats = get_records("chat")) { |
219 | foreach ($chats as $chat) { |
220 | if ($chat->keepdays) { |
221 | $timeold = time() - ($chat->keepdays * 24 * 3600); |
222 | delete_records_select("chat_messages", "chatid = '$chat->id' AND timestamp < '$timeold'"); |
223 | } |
224 | } |
225 | } |
226 | |
1515a89e |
227 | return true; |
228 | } |
229 | |
84a2fdd7 |
230 | function chat_get_participants($chatid, $groupid=0) { |
05855091 |
231 | //Returns the users with data in one chat |
232 | //(users with records in chat_messages, students) |
233 | |
234 | global $CFG; |
235 | |
84a2fdd7 |
236 | if ($groupid) { |
237 | $groupselect = " AND (c.groupid='$groupid' OR c.groupid='0')"; |
238 | } else { |
239 | $groupselect = ""; |
240 | } |
241 | |
05855091 |
242 | //Get students |
243 | $students = get_records_sql("SELECT DISTINCT u.* |
244 | FROM {$CFG->prefix}user u, |
245 | {$CFG->prefix}chat_messages c |
84a2fdd7 |
246 | WHERE c.chatid = '$chatid' $groupselect |
247 | AND u.id = c.userid"); |
1515a89e |
248 | |
05855091 |
249 | //Return students array (it contains an array of unique users) |
250 | return ($students); |
251 | } |
1515a89e |
252 | |
8496c4af |
253 | function chat_refresh_events($courseid = 0) { |
254 | // This standard function will check all instances of this module |
255 | // and make sure there are up-to-date events created for each of them. |
256 | // If courseid = 0, then every chat event in the site is checked, else |
257 | // only chat events belonging to the course specified are checked. |
258 | // This function is used, in its new format, by restore_refresh_events() |
259 | |
260 | if ($courseid) { |
261 | if (! $chats = get_records("chat", "course", $courseid)) { |
262 | return true; |
263 | } |
264 | } else { |
265 | if (! $chats = get_records("chat")) { |
266 | return true; |
267 | } |
268 | } |
dcd338ff |
269 | $moduleid = get_field('modules', 'id', 'name', 'chat'); |
8496c4af |
270 | |
271 | foreach ($chats as $chat) { |
272 | $event = NULL; |
273 | $event->name = addslashes($chat->name); |
274 | $event->description = addslashes($chat->intro); |
275 | $event->timestart = $chat->chattime; |
276 | |
277 | if ($event->id = get_field('event', 'id', 'modulename', 'chat', 'instance', $chat->id)) { |
278 | update_event($event); |
279 | |
280 | } else { |
281 | $event->courseid = $chat->course; |
282 | $event->groupid = 0; |
283 | $event->userid = 0; |
284 | $event->modulename = 'chat'; |
285 | $event->instance = $chat->id; |
286 | $event->eventtype = $chat->schedule; |
287 | $event->timeduration = 0; |
dcd338ff |
288 | $event->visible = get_field('course_modules', 'visible', 'module', $moduleid, 'instance', $chat->id); |
b5de723d |
289 | |
8496c4af |
290 | add_event($event); |
291 | } |
292 | } |
293 | return true; |
294 | } |
295 | |
1515a89e |
296 | ////////////////////////////////////////////////////////////////////// |
297 | /// Functions that require some SQL |
298 | |
84a2fdd7 |
299 | function chat_get_users($chatid, $groupid=0) { |
1515a89e |
300 | |
301 | global $CFG; |
84a2fdd7 |
302 | |
303 | if ($groupid) { |
304 | $groupselect = " AND (c.groupid='$groupid' OR c.groupid='0')"; |
305 | } else { |
306 | $groupselect = ""; |
307 | } |
b5de723d |
308 | |
426c0437 |
309 | return get_records_sql("SELECT DISTINCT u.id, u.firstname, u.lastname, u.picture, c.lastmessageping, c.firstping |
1515a89e |
310 | FROM {$CFG->prefix}chat_users c, |
311 | {$CFG->prefix}user u |
312 | WHERE c.chatid = '$chatid' |
84a2fdd7 |
313 | AND u.id = c.userid $groupselect |
1515a89e |
314 | ORDER BY c.firstping ASC"); |
315 | } |
316 | |
84a2fdd7 |
317 | function chat_get_latest_message($chatid, $groupid=0) { |
5a8625e4 |
318 | /// Efficient way to extract just the latest message |
319 | /// Uses ADOdb directly instead of get_record_sql() |
b5de723d |
320 | /// because the LIMIT command causes problems with |
5a8625e4 |
321 | /// the developer debugging in there. |
1515a89e |
322 | |
5a8625e4 |
323 | global $db, $CFG; |
1515a89e |
324 | |
84a2fdd7 |
325 | if ($groupid) { |
326 | $groupselect = " AND (groupid='$groupid' OR groupid='0')"; |
327 | } else { |
328 | $groupselect = ""; |
329 | } |
330 | |
5a8625e4 |
331 | if (!$rs = $db->Execute("SELECT * |
b5de723d |
332 | FROM {$CFG->prefix}chat_messages |
84a2fdd7 |
333 | WHERE chatid = '$chatid' $groupselect |
5a8625e4 |
334 | ORDER BY timestamp DESC LIMIT 1")) { |
335 | return false; |
336 | } |
337 | if ($rs->RecordCount() == 1) { |
338 | return (object)$rs->fields; |
339 | } else { |
340 | return false; // Found no records |
341 | } |
1515a89e |
342 | } |
343 | |
5a8625e4 |
344 | |
1515a89e |
345 | ////////////////////////////////////////////////////////////////////// |
346 | |
fdff1f63 |
347 | function chat_login_user($chatid, $version="header_js", $groupid=0) { |
1515a89e |
348 | global $USER; |
349 | |
350 | $chatuser->chatid = $chatid; |
351 | $chatuser->userid = $USER->id; |
fdff1f63 |
352 | $chatuser->groupid = $groupid; |
1515a89e |
353 | $chatuser->version = $version; |
354 | $chatuser->ip = $USER->lastIP; |
f7e648da |
355 | $chatuser->lastping = $chatuser->firstping = $chatuser->lastmessageping = time(); |
1515a89e |
356 | $chatuser->sid = random_string(32); |
357 | |
358 | if (!insert_record("chat_users", $chatuser)) { |
359 | return false; |
360 | } |
361 | |
362 | return $chatuser->sid; |
363 | } |
364 | |
7d792369 |
365 | function chat_delete_old_users() { |
366 | // Delete the old and in the way |
367 | |
b5012f3e |
368 | global $CFG; |
369 | |
370 | $timeold = time() - $CFG->chat_old_ping; |
c7756c73 |
371 | $query = "lastping < '$timeold'"; |
7d792369 |
372 | |
96a391a5 |
373 | if ($oldusers = get_records_select("chat_users", $query) ) { |
374 | delete_records_select("chat_users", $query); |
7d792369 |
375 | foreach ($oldusers as $olduser) { |
376 | $message->chatid = $olduser->chatid; |
377 | $message->userid = $olduser->userid; |
84a2fdd7 |
378 | $message->groupid = $olduser->groupid; |
7d792369 |
379 | $message->message = "exit"; |
380 | $message->system = 1; |
381 | $message->timestamp = time(); |
b5de723d |
382 | |
7d792369 |
383 | if (!insert_record("chat_messages", $message)) { |
384 | error("Could not insert a chat message!"); |
385 | } |
386 | } |
387 | } |
388 | } |
1515a89e |
389 | |
22a4491a |
390 | |
fcd3a1ee |
391 | function chat_update_chat_times($chatid=0) { |
392 | /// Updates chat records so that the next chat time is correct |
393 | |
394 | $timenow = time(); |
395 | if ($chatid) { |
396 | if (!$chats[] = get_record_select("chat", "id = '$chatid' AND chattime <= '$timenow' AND schedule > '0'")) { |
397 | return; |
398 | } |
399 | } else { |
400 | if (!$chats = get_records_select("chat", "chattime <= '$timenow' AND schedule > '0'")) { |
401 | return; |
402 | } |
403 | } |
404 | |
405 | foreach ($chats as $chat) { |
7626969c |
406 | unset($chat->name); |
407 | unset($chat->intro); |
fcd3a1ee |
408 | switch ($chat->schedule) { |
409 | case 1: // Single event - turn off schedule and disable |
410 | $chat->chattime = 0; |
411 | $chat->schedule = 0; |
412 | break; |
413 | case 2: // Repeat daily |
414 | $chat->chattime += 24 * 3600; |
415 | break; |
416 | case 3: // Repeat weekly |
417 | $chat->chattime += 7 * 24 * 3600; |
418 | break; |
419 | } |
420 | update_record("chat", $chat); |
8496c4af |
421 | |
422 | $event = NULL; // Update calendar too |
423 | if ($event->id = get_field('event', 'id', 'modulename', 'chat', 'instance', $chat->id)) { |
424 | $event->timestart = $chat->chattime; |
425 | update_event($event); |
426 | } |
fcd3a1ee |
427 | } |
428 | } |
429 | |
430 | |
1515a89e |
431 | function chat_browser_detect($HTTP_USER_AGENT) { |
432 | |
433 | if(eregi("(opera) ([0-9]{1,2}.[0-9]{1,3}){0,1}", $HTTP_USER_AGENT, $match) |
434 | || eregi("(opera/)([0-9]{1,2}.[0-9]{1,3}){0,1}", $HTTP_USER_AGENT, $match)) |
435 | { |
436 | $BName = "Opera"; $BVersion=$match[2]; |
437 | } |
438 | elseif( eregi("(konqueror)/([0-9]{1,2}.[0-9]{1,3})", $HTTP_USER_AGENT, $match) ) |
439 | { |
440 | $BName = "Konqueror"; $BVersion=$match[2]; |
441 | } |
442 | elseif( eregi("(lynx)/([0-9]{1,2}.[0-9]{1,2}.[0-9]{1,2})", $HTTP_USER_AGENT, $match) ) |
443 | { |
444 | $BName = "Lynx"; $BVersion=$match[2]; |
445 | } |
446 | elseif( eregi("(links) \(([0-9]{1,2}.[0-9]{1,3})", $HTTP_USER_AGENT, $match) ) |
447 | { |
448 | $BName = "Links"; $BVersion=$match[2]; |
449 | } |
450 | elseif( eregi("(msie) ([0-9]{1,2}.[0-9]{1,3})", $HTTP_USER_AGENT, $match) ) |
451 | { |
452 | $BName = "MSIE"; $BVersion=$match[2]; |
453 | } |
454 | elseif( eregi("(netscape6)/(6.[0-9]{1,3})", $HTTP_USER_AGENT, $match) ) |
455 | { |
456 | $BName = "Netscape"; $BVersion=$match[2]; |
457 | } |
458 | elseif( eregi("mozilla/5", $HTTP_USER_AGENT) ) |
459 | { |
460 | $BName = "Netscape"; $BVersion="Unknown"; |
461 | } |
462 | elseif( eregi("(mozilla)/([0-9]{1,2}.[0-9]{1,3})", $HTTP_USER_AGENT, $match) ) |
463 | { |
464 | $BName = "Netscape"; $BVersion=$match[2]; |
465 | } |
466 | elseif( eregi("w3m", $HTTP_USER_AGENT) ) |
467 | { |
468 | $BName = "w3m"; $BVersion="Unknown"; |
469 | } |
470 | else |
471 | { |
472 | $BName = "Unknown"; $BVersion="Unknown"; |
473 | } |
474 | |
475 | if(eregi("linux", $HTTP_USER_AGENT)) |
476 | { |
477 | $BPlatform = "Linux"; |
478 | } |
479 | elseif( eregi("win32", $HTTP_USER_AGENT) ) |
480 | { |
481 | $BPlatform = "Windows"; |
482 | } |
483 | elseif( (eregi("(win)([0-9]{2})", $HTTP_USER_AGENT, $match) ) |
484 | || (eregi("(windows) ([0-9]{2})", $HTTP_USER_AGENT, $match) )) |
485 | { |
486 | $BPlatform = "Windows $match[2]"; |
487 | } |
488 | elseif( eregi("(winnt)([0-9]{1,2}.[0-9]{1,2}){0,1}", $HTTP_USER_AGENT, $match) ) |
489 | { |
490 | $BPlatform = "Windows NT $match[2]"; |
491 | } |
492 | elseif( eregi("(windows nt)( ){0,1}([0-9]{1,2}.[0-9]{1,2}){0,1}", $HTTP_USER_AGENT, $match) ) |
493 | { |
494 | $BPlatform = "Windows NT $match[3]"; |
495 | } |
496 | elseif( eregi("mac", $HTTP_USER_AGENT) ) |
497 | { |
498 | $BPlatform = "Macintosh"; |
499 | } |
500 | elseif( eregi("(sunos) ([0-9]{1,2}.[0-9]{1,2}){0,1}", $HTTP_USER_AGENT, $match) ) |
501 | { |
502 | $BPlatform = "SunOS $match[2]"; |
503 | } |
504 | elseif( eregi("(beos) r([0-9]{1,2}.[0-9]{1,2}){0,1}", $HTTP_USER_AGENT, $match) ) |
505 | { |
506 | $BPlatform = "BeOS $match[2]"; |
507 | } |
508 | elseif( eregi("freebsd", $HTTP_USER_AGENT) ) |
509 | { |
510 | $BPlatform = "FreeBSD"; |
511 | } |
512 | elseif( eregi("openbsd", $HTTP_USER_AGENT) ) |
513 | { |
514 | $BPlatform = "OpenBSD"; |
515 | } |
516 | elseif( eregi("irix", $HTTP_USER_AGENT) ) |
517 | { |
518 | $BPlatform = "IRIX"; |
519 | } |
520 | elseif( eregi("os/2", $HTTP_USER_AGENT) ) |
521 | { |
522 | $BPlatform = "OS/2"; |
523 | } |
524 | elseif( eregi("plan9", $HTTP_USER_AGENT) ) |
525 | { |
526 | $BPlatform = "Plan9"; |
527 | } |
528 | elseif( eregi("unix", $HTTP_USER_AGENT) |
529 | || eregi("hp-ux", $HTTP_USER_AGENT) ) |
530 | { |
531 | $BPlatform = "Unix"; |
532 | } |
533 | elseif( eregi("osf", $HTTP_USER_AGENT) ) |
534 | { |
535 | $BPlatform = "OSF"; |
536 | } |
537 | else |
538 | { |
539 | $BPlatform = "Unknown"; |
540 | } |
b5de723d |
541 | |
1515a89e |
542 | $return["name"] = $BName; |
543 | $return["version"] = $BVersion; |
544 | $return["platform"] = $BPlatform; |
545 | return $return; |
546 | } |
547 | |
548 | function chat_display_version($version, $browser) |
549 | { |
550 | GLOBAL $CFG; |
551 | |
552 | $checked = ""; |
553 | if (($version == "sockets") OR ($version == "push_js")) |
554 | { |
555 | $checked = "checked"; |
556 | } |
557 | if (($version == "sockets" OR $version == "push_js") |
558 | AND |
559 | ($browser["name"] == "Lynx" |
560 | OR |
561 | $browser["name"] == "Links" |
562 | OR |
563 | $browser["name"] == "w3m" |
564 | OR |
565 | $browser["name"] == "Konqueror" |
566 | OR |
567 | ($browser["name"] == "Netscape" AND substr($browser["version"], 0, 1) == "2"))) |
568 | { |
569 | $checked = ""; |
570 | } |
571 | if (($version == "text") |
572 | AND |
573 | ($browser["name"] == "Lynx" |
574 | OR |
575 | $browser["name"] == "Links" |
576 | OR |
577 | $browser["name"] == "w3m")) |
578 | { |
579 | $checked = "checked"; |
580 | } |
581 | if (($version == "header") |
582 | AND |
583 | ($browser["name"] == "Konqueror")) |
584 | { |
585 | $checked = "checked"; |
586 | } |
587 | if (($version == "header_js") |
588 | AND |
589 | ($browser["name"] == "Netscape" AND substr($browser["version"], 0, 1) == "2")) |
590 | { |
591 | $checked = "checked"; |
592 | } |
593 | ?> |
594 | <tr> |
595 | <td valign="top"> |
b4510d53 |
596 | <input type="radio" name="chat_chatversion" value="<?php echo $version; ?>"<?php echo $checked; ?> /> |
1515a89e |
597 | </td> |
598 | <td valign="top" align="left"> |
599 | <font face="Arial" size="2"> |
600 | <?php echo $chat_lang["gui_".$version]; ?> |
601 | </font> |
602 | </td> |
603 | </tr> |
604 | <?php |
605 | |
606 | } |
607 | |
82a524ef |
608 | function chat_language_override($language) { |
609 | // Override the highest-ranking language variable from current_language() |
610 | // And save it so we can restore it again afterwards |
611 | global $CFG; |
1515a89e |
612 | |
82a524ef |
613 | $oldlang = empty($CFG->courselang) ? NULL : $CFG->courselang; |
614 | $CFG->courselang = $language; |
615 | |
616 | return $oldlang; |
617 | } |
618 | |
619 | function chat_language_restore($language = NULL) { |
620 | // Restore the highest-ranking language variable from current_language() |
621 | global $CFG; |
622 | |
623 | if(!empty($language)) { |
624 | $CFG->courselang = $language; |
625 | } |
626 | } |
627 | |
628 | function chat_format_message_manually($message, $courseid, $sender, $currentuser, $language = NULL) { |
b5de723d |
629 | global $CFG; |
1515a89e |
630 | |
b5de723d |
631 | $output = New stdClass; |
632 | $output->beep = false; // by default |
7d792369 |
633 | |
b5de723d |
634 | if(empty($language)) { |
635 | $language = current_language(); |
1515a89e |
636 | } |
637 | |
82a524ef |
638 | $oldcfglang = chat_language_override($language); |
b5de723d |
639 | |
640 | // Get some additional info now that the language has been correctly set |
641 | |
642 | // But before that :-) let's override get_user_timezone() for this call... messy stuff... |
82a524ef |
643 | $tz = ($currentuser->timezone == 99) ? $CFG->timezone : $currentuser->timezone; |
b5de723d |
644 | $message->strtime = userdate($message->timestamp, get_string('strftimemessage', 'chat'), $tz); |
645 | |
646 | $message->picture = print_user_picture($sender->id, 0, $sender->picture, false, true, false); |
582de679 |
647 | if ($courseid) { |
839f2456 |
648 | $message->picture = "<a target=\"_new\" href=\"$CFG->wwwroot/user/view.php?id=$sender->id&course=$courseid\">$message->picture</a>"; |
582de679 |
649 | } |
1515a89e |
650 | |
b5de723d |
651 | // Start processing the message |
1515a89e |
652 | |
b5de723d |
653 | if(!empty($message->system)) { |
654 | // System event |
655 | $output->text = $message->strtime.': '.get_string('message'.$message->message, 'chat', fullname($sender)); |
656 | $output->html = '<table><tr><td style="vertical-align: top;">'.$message->picture.'</td><td>'; |
2defdcd7 |
657 | $output->html .= '<font size="2" color="#ccaaaa">'.$output->text.'</font></td></tr></table>'; |
7d792369 |
658 | |
b5de723d |
659 | // Don't forget to reset the language before returning!!! |
660 | if(!empty($oldcfglang)) { |
661 | $CFG->courselang = $oldcfglang; |
662 | } |
1515a89e |
663 | return $output; |
664 | } |
665 | |
82a524ef |
666 | // It's not a system event |
b5de723d |
667 | |
668 | $text = $message->message; |
82a524ef |
669 | |
670 | /// Parse the text to clean and filter it |
671 | |
672 | $options->para = false; |
673 | $text = format_text($text, FORMAT_MOODLE, $options, $courseid); |
7d792369 |
674 | |
b5de723d |
675 | // And now check for special cases |
676 | |
677 | if (substr($text, 0, 5) == 'beep ') { |
678 | /// It's a beep! |
7d792369 |
679 | $beepwho = trim(substr($text, 5)); |
9f85bed4 |
680 | |
b5de723d |
681 | if ($beepwho == 'all') { // everyone |
682 | $outinfo = $message->strtime.': '.get_string('messagebeepseveryone', 'chat', fullname($sender)); |
683 | $outmain = ''; |
684 | $output->beep = true; // (eventually this should be set to |
7d792369 |
685 | // to a filename uploaded by the user) |
686 | |
82a524ef |
687 | } else if ($beepwho == $currentuser->id) { // current user |
b5de723d |
688 | $outinfo = $message->strtime.': '.get_string('messagebeepsyou', 'chat', fullname($sender)); |
689 | $outmain = ''; |
7d792369 |
690 | $output->beep = true; |
691 | |
692 | } else { |
693 | return false; |
694 | } |
b5de723d |
695 | } else if (substr($text, 0, 1) == ':') { /// It's an MOO emote |
696 | $outinfo = $message->strtime; |
697 | $outmain = $sender->firstname.' '.substr($text, 1); |
7d792369 |
698 | |
b5de723d |
699 | } else if (substr($text, 0, 1) == '/') { /// It's a user command |
1515a89e |
700 | |
7d792369 |
701 | if (substr($text, 0, 4) == "/me ") { |
b5de723d |
702 | $outinfo = $message->strtime; |
703 | $outmain = $sender->firstname.' '.substr($text, 4); |
9f85bed4 |
704 | } else { |
b5de723d |
705 | $outinfo = $message->strtime; |
7d792369 |
706 | $outmain = $text; |
1515a89e |
707 | } |
9f85bed4 |
708 | |
709 | } else { /// It's a normal message |
b5de723d |
710 | $outinfo = $message->strtime.' '.$sender->firstname; |
7d792369 |
711 | $outmain = $text; |
1515a89e |
712 | } |
713 | |
9f85bed4 |
714 | /// Format the message as a small table |
1515a89e |
715 | |
b5de723d |
716 | $output->text = strip_tags($outinfo.': '.$outmain); |
7d792369 |
717 | |
1c61c8d6 |
718 | $output->html = "<table><tr><td valign=\"top\">$message->picture</td><td><font size=\"2\">"; |
7d792369 |
719 | $output->html .= "<font color=\"#888888\">$outinfo</font>"; |
720 | if ($outmain) { |
721 | $output->html .= ": $outmain"; |
722 | } |
723 | $output->html .= "</font></td></tr></table>"; |
1515a89e |
724 | |
b5de723d |
725 | // Don't forget to reset the language before returning!!! |
82a524ef |
726 | chat_language_restore($oldcfglang); |
b5de723d |
727 | |
7d792369 |
728 | return $output; |
b5de723d |
729 | } |
730 | |
731 | function chat_format_message($message, $courseid=0) { |
732 | /// Given a message object full of information, this function |
733 | /// formats it appropriately into text and html, then |
734 | /// returns the formatted data. |
735 | |
736 | global $CFG, $USER; |
737 | |
738 | if (!$user = get_record("user", "id", $message->userid)) { |
739 | return "Error finding user id = $message->userid"; |
740 | } |
741 | |
82a524ef |
742 | return chat_format_message_manually($message, $courseid, $user, $USER); |
1515a89e |
743 | |
744 | } |
745 | |
1515a89e |
746 | ?> |