1c61c8d6 |
1 | <?php // $Id$ |
1515a89e |
2 | |
3 | /// Library of functions and constants for module chat |
4 | |
c4d588cc |
5 | require_once($CFG->libdir.'/pagelib.php'); |
6 | |
b5012f3e |
7 | if (!isset($CFG->chat_refresh_room)) { |
8 | set_config("chat_refresh_room", 5); |
b5de723d |
9 | } |
b5012f3e |
10 | if (!isset($CFG->chat_refresh_userlist)) { |
11 | set_config("chat_refresh_userlist", 10); |
b5de723d |
12 | } |
b5012f3e |
13 | if (!isset($CFG->chat_old_ping)) { |
34308732 |
14 | set_config("chat_old_ping", 35); |
b5de723d |
15 | } |
d434b9ae |
16 | if (!isset($CFG->chat_method)) { |
17 | set_config("chat_method", "header_js"); |
b5de723d |
18 | } |
930413b1 |
19 | if (!isset($CFG->chat_normal_updatemode)) { |
20 | set_config("chat_normal_updatemode", 'jsupdate'); |
21 | } |
d434b9ae |
22 | if (!isset($CFG->chat_serverhost)) { |
23 | set_config("chat_serverhost", $_SERVER['HTTP_HOST']); |
b5de723d |
24 | } |
d434b9ae |
25 | if (!isset($CFG->chat_serverip)) { |
e2a1a0fa |
26 | set_config("chat_serverip", '127.0.0.1'); |
b5de723d |
27 | } |
d434b9ae |
28 | if (!isset($CFG->chat_serverport)) { |
29 | set_config("chat_serverport", 9111); |
b5de723d |
30 | } |
d434b9ae |
31 | if (!isset($CFG->chat_servermax)) { |
32 | set_config("chat_servermax", 100); |
b5de723d |
33 | } |
1515a89e |
34 | |
1515a89e |
35 | // The HTML head for the message window to start with (<!-- nix --> is used to get some browsers starting with output |
36 | $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"; |
37 | |
38 | // The HTML head for the message window to start with (with js scrolling) |
39 | $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"; |
40 | |
41 | // The HTML code for standard empty pages (e.g. if a user was kicked out) |
89f688b6 |
42 | $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=\"#FFFFFF\"></body></html>"; |
1515a89e |
43 | |
44 | // The HTML head for the message input page |
89f688b6 |
45 | $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=\"#FFFFFF\">"; |
1515a89e |
46 | |
47 | // The HTML code for the message input page, with JavaScript |
89f688b6 |
48 | $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=\"#FFFFFF\" OnLoad=\"document.f.arsc_message.focus();document.f.arsc_message.select();\">"; |
1515a89e |
49 | |
fbabbd23 |
50 | // Dummy data that gets output to the browser as needed, in order to make it show output |
51 | $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 |
52 | |
53 | function chat_add_instance($chat) { |
b5de723d |
54 | /// Given an object containing all the necessary data, |
55 | /// (defined by the form in mod.html) this function |
56 | /// will create a new instance and return the id number |
1515a89e |
57 | /// of the new instance. |
58 | |
59 | $chat->timemodified = time(); |
60 | |
b5de723d |
61 | $chat->chattime = make_timestamp($chat->chatyear, $chat->chatmonth, $chat->chatday, |
fcd3a1ee |
62 | $chat->chathour, $chat->chatminute); |
b5de723d |
63 | |
8496c4af |
64 | if ($returnid = insert_record("chat", $chat)) { |
65 | |
66 | $event = NULL; |
67 | $event->name = $chat->name; |
68 | $event->description = $chat->intro; |
69 | $event->courseid = $chat->course; |
70 | $event->groupid = 0; |
71 | $event->userid = 0; |
72 | $event->modulename = 'chat'; |
73 | $event->instance = $returnid; |
74 | $event->eventtype = $chat->schedule; |
75 | $event->timestart = $chat->chattime; |
76 | $event->timeduration = 0; |
77 | |
78 | add_event($event); |
79 | } |
80 | |
81 | return $returnid; |
1515a89e |
82 | } |
83 | |
84 | |
85 | function chat_update_instance($chat) { |
b5de723d |
86 | /// Given an object containing all the necessary data, |
87 | /// (defined by the form in mod.html) this function |
1515a89e |
88 | /// will update an existing instance with new data. |
89 | |
90 | $chat->timemodified = time(); |
91 | $chat->id = $chat->instance; |
92 | |
b5de723d |
93 | $chat->chattime = make_timestamp($chat->chatyear, $chat->chatmonth, $chat->chatday, |
fcd3a1ee |
94 | $chat->chathour, $chat->chatminute); |
1515a89e |
95 | |
8496c4af |
96 | if ($returnid = update_record("chat", $chat)) { |
97 | |
98 | $event = NULL; |
99 | |
100 | if ($event->id = get_field('event', 'id', 'modulename', 'chat', 'instance', $chat->id)) { |
101 | |
102 | $event->name = $chat->name; |
103 | $event->description = $chat->intro; |
104 | $event->timestart = $chat->chattime; |
105 | |
106 | update_event($event); |
107 | } |
108 | } |
109 | |
110 | return $returnid; |
1515a89e |
111 | } |
112 | |
113 | |
114 | function chat_delete_instance($id) { |
b5de723d |
115 | /// Given an ID of an instance of this module, |
116 | /// this function will permanently delete the instance |
117 | /// and any data that depends on it. |
1515a89e |
118 | |
a71efae3 |
119 | if (! $chat = get_record('chat', 'id', $id)) { |
1515a89e |
120 | return false; |
121 | } |
122 | |
123 | $result = true; |
124 | |
125 | # Delete any dependent records here # |
126 | |
a71efae3 |
127 | if (! delete_records('chat', 'id', $chat->id)) { |
128 | $result = false; |
129 | } |
130 | if (! delete_records('chat_messages', 'chatid', $chat->id)) { |
131 | $result = false; |
132 | } |
133 | if (! delete_records('chat_users', 'chatid', $chat->id)) { |
1515a89e |
134 | $result = false; |
135 | } |
136 | |
880d8675 |
137 | $pagetypes = page_import_types('mod/chat/'); |
138 | foreach($pagetypes as $pagetype) { |
139 | if(!delete_records('block_instance', 'pageid', $chat->id, 'pagetype', $pagetype)) { |
140 | $result = false; |
141 | } |
142 | } |
143 | |
36eb856f |
144 | if (! delete_records('event', 'modulename', 'chat', 'instance', $chat->id)) { |
145 | $result = false; |
146 | } |
147 | |
1515a89e |
148 | return $result; |
149 | } |
150 | |
151 | function chat_user_outline($course, $user, $mod, $chat) { |
b5de723d |
152 | /// Return a small object with summary information about what a |
1515a89e |
153 | /// user has done with a given particular instance of this module |
154 | /// Used for user activity reports. |
155 | /// $return->time = the time they did it |
156 | /// $return->info = a short text description |
157 | |
5c05d23b |
158 | $return = NULL; |
1515a89e |
159 | return $return; |
160 | } |
161 | |
162 | function chat_user_complete($course, $user, $mod, $chat) { |
b5de723d |
163 | /// Print a detailed representation of what a user has done with |
1515a89e |
164 | /// a given particular instance of this module, for user activity reports. |
165 | |
166 | return true; |
167 | } |
168 | |
b7602a11 |
169 | function chat_print_recent_activity($course, $isteacher, $timestart) { |
170 | /// Given a course and a date, prints a summary of all chat rooms |
171 | /// that currently have people in them. |
1515a89e |
172 | /// This function is called from course/lib.php: print_recent_activity() |
173 | |
b7602a11 |
174 | global $CFG; |
175 | |
c5a05b95 |
176 | $timeold = time() - $CFG->chat_old_ping; |
177 | |
8f7dc7f1 |
178 | $lastpingsearch = ($CFG->chat_method == 'sockets') ? '': 'AND cu.lastping > \''.$timeold.'\''; |
0469cccf |
179 | |
132911c8 |
180 | if (!$chatusers = get_records_sql("SELECT u.id, cu.chatid, u.firstname, u.lastname |
b7602a11 |
181 | FROM {$CFG->prefix}chat_users as cu, |
cea57965 |
182 | {$CFG->prefix}chat as ch, |
b7602a11 |
183 | {$CFG->prefix}user as u |
b5de723d |
184 | WHERE cu.userid = u.id |
0469cccf |
185 | AND cu.chatid = ch.id $lastpingsearch |
cea57965 |
186 | AND ch.course = '$course->id' |
b7602a11 |
187 | ORDER BY cu.chatid ASC") ) { |
188 | return false; |
189 | } |
1515a89e |
190 | |
3120f6f2 |
191 | $isteacher = isteacher($course->id); |
b7602a11 |
192 | |
3120f6f2 |
193 | $outputstarted = false; |
b7602a11 |
194 | $current = 0; |
195 | foreach ($chatusers as $chatuser) { |
196 | if ($current != $chatuser->chatid) { |
197 | if ($current) { |
8f7dc7f1 |
198 | echo '</ul></div>'; // room |
199 | $current = 0; |
b7602a11 |
200 | } |
8f7dc7f1 |
201 | if ($chat = get_record('chat', 'id', $chatuser->chatid)) { |
3120f6f2 |
202 | if (!($isteacher or instance_is_visible('chat', $chat))) { // Chat hidden to students |
203 | continue; |
204 | } |
205 | if (!$outputstarted) { |
8f7dc7f1 |
206 | print_headline(get_string('currentchats', 'chat').':'); |
3120f6f2 |
207 | $outputstarted = true; |
208 | } |
200371e9 |
209 | echo '<div class="room"><p class="head"><a href="'.$CFG->wwwroot.'/mod/chat/view.php?c='.$chat->id.'">'.format_string($chat->name,true).'</a></p><ul>'; |
b7602a11 |
210 | } |
211 | $current = $chatuser->chatid; |
212 | } |
8f7dc7f1 |
213 | $fullname = fullname($chatuser, $isteacher); |
214 | echo '<li class="info name">'.$fullname.'</li>'; |
215 | } |
216 | |
217 | if ($current) { |
218 | echo '</ul></div>'; // room |
b7602a11 |
219 | } |
220 | |
221 | return true; |
1515a89e |
222 | } |
223 | |
8f7dc7f1 |
224 | |
1515a89e |
225 | function chat_cron () { |
226 | /// Function to be run periodically according to the moodle cron |
b5de723d |
227 | /// This function searches for things that need to be done, such |
228 | /// as sending out mail, toggling flags etc ... |
1515a89e |
229 | |
230 | global $CFG; |
231 | |
fcd3a1ee |
232 | chat_update_chat_times(); |
233 | |
7d792369 |
234 | chat_delete_old_users(); |
235 | |
22a4491a |
236 | /// Delete old messages |
237 | if ($chats = get_records("chat")) { |
238 | foreach ($chats as $chat) { |
239 | if ($chat->keepdays) { |
240 | $timeold = time() - ($chat->keepdays * 24 * 3600); |
241 | delete_records_select("chat_messages", "chatid = '$chat->id' AND timestamp < '$timeold'"); |
242 | } |
243 | } |
244 | } |
245 | |
1515a89e |
246 | return true; |
247 | } |
248 | |
84a2fdd7 |
249 | function chat_get_participants($chatid, $groupid=0) { |
05855091 |
250 | //Returns the users with data in one chat |
251 | //(users with records in chat_messages, students) |
252 | |
253 | global $CFG; |
254 | |
84a2fdd7 |
255 | if ($groupid) { |
256 | $groupselect = " AND (c.groupid='$groupid' OR c.groupid='0')"; |
257 | } else { |
258 | $groupselect = ""; |
259 | } |
260 | |
05855091 |
261 | //Get students |
95e72c12 |
262 | $students = get_records_sql("SELECT DISTINCT u.id, u.id |
05855091 |
263 | FROM {$CFG->prefix}user u, |
264 | {$CFG->prefix}chat_messages c |
84a2fdd7 |
265 | WHERE c.chatid = '$chatid' $groupselect |
266 | AND u.id = c.userid"); |
1515a89e |
267 | |
05855091 |
268 | //Return students array (it contains an array of unique users) |
269 | return ($students); |
270 | } |
1515a89e |
271 | |
8496c4af |
272 | function chat_refresh_events($courseid = 0) { |
273 | // This standard function will check all instances of this module |
274 | // and make sure there are up-to-date events created for each of them. |
275 | // If courseid = 0, then every chat event in the site is checked, else |
276 | // only chat events belonging to the course specified are checked. |
277 | // This function is used, in its new format, by restore_refresh_events() |
278 | |
279 | if ($courseid) { |
280 | if (! $chats = get_records("chat", "course", $courseid)) { |
281 | return true; |
282 | } |
283 | } else { |
284 | if (! $chats = get_records("chat")) { |
285 | return true; |
286 | } |
287 | } |
dcd338ff |
288 | $moduleid = get_field('modules', 'id', 'name', 'chat'); |
8496c4af |
289 | |
290 | foreach ($chats as $chat) { |
291 | $event = NULL; |
292 | $event->name = addslashes($chat->name); |
293 | $event->description = addslashes($chat->intro); |
294 | $event->timestart = $chat->chattime; |
295 | |
296 | if ($event->id = get_field('event', 'id', 'modulename', 'chat', 'instance', $chat->id)) { |
297 | update_event($event); |
298 | |
299 | } else { |
300 | $event->courseid = $chat->course; |
301 | $event->groupid = 0; |
302 | $event->userid = 0; |
303 | $event->modulename = 'chat'; |
304 | $event->instance = $chat->id; |
305 | $event->eventtype = $chat->schedule; |
306 | $event->timeduration = 0; |
dcd338ff |
307 | $event->visible = get_field('course_modules', 'visible', 'module', $moduleid, 'instance', $chat->id); |
b5de723d |
308 | |
8496c4af |
309 | add_event($event); |
310 | } |
311 | } |
312 | return true; |
313 | } |
314 | |
516121bd |
315 | function chat_force_language($lang) { |
316 | /// This function prepares moodle to operate in given language |
317 | /// usable when $nomoodlecookie = true; |
318 | /// BEWARE: there must be no $course, $USER or $SESSION |
a776c371 |
319 | global $CFG; |
320 | |
516121bd |
321 | if(!empty($CFG->courselang)) { |
a776c371 |
322 | unset($CFG->courselang); |
516121bd |
323 | } |
324 | if(!empty($CFG->locale)) { |
a776c371 |
325 | unset($CFG->locale); |
516121bd |
326 | } |
e7fbd0b3 |
327 | $CFG->lang = $lang; |
516121bd |
328 | moodle_setlocale(); |
329 | } |
330 | |
1515a89e |
331 | ////////////////////////////////////////////////////////////////////// |
332 | /// Functions that require some SQL |
333 | |
84a2fdd7 |
334 | function chat_get_users($chatid, $groupid=0) { |
1515a89e |
335 | |
336 | global $CFG; |
84a2fdd7 |
337 | |
338 | if ($groupid) { |
339 | $groupselect = " AND (c.groupid='$groupid' OR c.groupid='0')"; |
340 | } else { |
341 | $groupselect = ""; |
342 | } |
b5de723d |
343 | |
426c0437 |
344 | return get_records_sql("SELECT DISTINCT u.id, u.firstname, u.lastname, u.picture, c.lastmessageping, c.firstping |
1515a89e |
345 | FROM {$CFG->prefix}chat_users c, |
346 | {$CFG->prefix}user u |
347 | WHERE c.chatid = '$chatid' |
84a2fdd7 |
348 | AND u.id = c.userid $groupselect |
1515a89e |
349 | ORDER BY c.firstping ASC"); |
350 | } |
351 | |
84a2fdd7 |
352 | function chat_get_latest_message($chatid, $groupid=0) { |
5a8625e4 |
353 | /// Efficient way to extract just the latest message |
354 | /// Uses ADOdb directly instead of get_record_sql() |
b5de723d |
355 | /// because the LIMIT command causes problems with |
5a8625e4 |
356 | /// the developer debugging in there. |
1515a89e |
357 | |
5a8625e4 |
358 | global $db, $CFG; |
1515a89e |
359 | |
84a2fdd7 |
360 | if ($groupid) { |
361 | $groupselect = " AND (groupid='$groupid' OR groupid='0')"; |
362 | } else { |
363 | $groupselect = ""; |
364 | } |
365 | |
5a8625e4 |
366 | if (!$rs = $db->Execute("SELECT * |
b5de723d |
367 | FROM {$CFG->prefix}chat_messages |
84a2fdd7 |
368 | WHERE chatid = '$chatid' $groupselect |
5a8625e4 |
369 | ORDER BY timestamp DESC LIMIT 1")) { |
370 | return false; |
371 | } |
372 | if ($rs->RecordCount() == 1) { |
373 | return (object)$rs->fields; |
374 | } else { |
375 | return false; // Found no records |
376 | } |
1515a89e |
377 | } |
378 | |
5a8625e4 |
379 | |
1515a89e |
380 | ////////////////////////////////////////////////////////////////////// |
516121bd |
381 | // login if not already logged in |
1515a89e |
382 | |
a32c7772 |
383 | function chat_login_user($chatid, $version, $groupid, $course) { |
1515a89e |
384 | global $USER; |
e7fbd0b3 |
385 | if (($version != 'sockets') and $chatuser = get_record_select('chat_users', "chatid='$chatid' AND userid='$USER->id' AND groupid='$groupid'")) { |
516121bd |
386 | $chatuser->version = $version; |
0eda0a46 |
387 | $chatuser->ip = $USER->lastIP; |
516121bd |
388 | $chatuser->lastping = time(); |
389 | $chatuser->lang = current_language(); |
1515a89e |
390 | |
d13ef2fb |
391 | // Sometimes $USER->lastIP is not setup properly |
392 | // during login. Update with current value if possible |
f83edcb1 |
393 | // or provide a dummy value for the db |
d13ef2fb |
394 | if (empty($chatuser->ip)) { |
395 | $chatuser->ip = getremoteaddr(); |
396 | if (empty($chatuser->ip)) { |
f83edcb1 |
397 | $chatuser->ip = ''; |
d13ef2fb |
398 | } |
399 | } |
400 | |
516121bd |
401 | if (($chatuser->course != $course->id) |
402 | or ($chatuser->userid != $USER->id)) { |
403 | return false; |
404 | } |
405 | if (!update_record('chat_users', $chatuser)) { |
406 | return false; |
407 | } |
516121bd |
408 | } else { |
409 | $chatuser->chatid = $chatid; |
410 | $chatuser->userid = $USER->id; |
411 | $chatuser->groupid = $groupid; |
412 | $chatuser->version = $version; |
7b5aa1b7 |
413 | $chatuser->ip = $USER->lastIP; |
516121bd |
414 | $chatuser->lastping = $chatuser->firstping = $chatuser->lastmessageping = time(); |
415 | $chatuser->sid = random_string(32); |
3dfd307f |
416 | $chatuser->course = $course->id; //caching - needed for current_language too |
417 | $chatuser->lang = current_language(); //caching - to resource intensive to find out later |
516121bd |
418 | |
419 | if (!insert_record('chat_users', $chatuser)) { |
420 | return false; |
421 | } |
422 | |
a32c7772 |
423 | if ($version == 'sockets') { |
424 | // do not send 'enter' message, chatd will do it |
425 | } else { |
2ac0d13b |
426 | $message->chatid = $chatuser->chatid; |
427 | $message->userid = $chatuser->userid; |
428 | $message->groupid = $groupid; |
429 | $message->message = 'enter'; |
430 | $message->system = 1; |
431 | $message->timestamp = time(); |
432 | |
433 | if (!insert_record('chat_messages', $message)) { |
434 | error('Could not insert a chat message!'); |
435 | } |
516121bd |
436 | } |
1515a89e |
437 | } |
438 | |
439 | return $chatuser->sid; |
440 | } |
441 | |
7d792369 |
442 | function chat_delete_old_users() { |
443 | // Delete the old and in the way |
444 | |
b5012f3e |
445 | global $CFG; |
446 | |
e7fbd0b3 |
447 | $timeold = time() - $CFG->chat_old_ping; |
a32c7772 |
448 | |
c7756c73 |
449 | $query = "lastping < '$timeold'"; |
7d792369 |
450 | |
516121bd |
451 | if ($oldusers = get_records_select('chat_users', $query) ) { |
452 | delete_records_select('chat_users', $query); |
7d792369 |
453 | foreach ($oldusers as $olduser) { |
516121bd |
454 | $message->chatid = $olduser->chatid; |
455 | $message->userid = $olduser->userid; |
456 | $message->groupid = $olduser->groupid; |
457 | $message->message = 'exit'; |
458 | $message->system = 1; |
7d792369 |
459 | $message->timestamp = time(); |
b5de723d |
460 | |
516121bd |
461 | if (!insert_record('chat_messages', $message)) { |
462 | error('Could not insert a chat message!'); |
7d792369 |
463 | } |
464 | } |
465 | } |
466 | } |
1515a89e |
467 | |
22a4491a |
468 | |
fcd3a1ee |
469 | function chat_update_chat_times($chatid=0) { |
470 | /// Updates chat records so that the next chat time is correct |
471 | |
472 | $timenow = time(); |
473 | if ($chatid) { |
474 | if (!$chats[] = get_record_select("chat", "id = '$chatid' AND chattime <= '$timenow' AND schedule > '0'")) { |
475 | return; |
476 | } |
477 | } else { |
478 | if (!$chats = get_records_select("chat", "chattime <= '$timenow' AND schedule > '0'")) { |
479 | return; |
480 | } |
481 | } |
482 | |
483 | foreach ($chats as $chat) { |
7626969c |
484 | unset($chat->name); |
485 | unset($chat->intro); |
fcd3a1ee |
486 | switch ($chat->schedule) { |
487 | case 1: // Single event - turn off schedule and disable |
488 | $chat->chattime = 0; |
489 | $chat->schedule = 0; |
490 | break; |
491 | case 2: // Repeat daily |
492 | $chat->chattime += 24 * 3600; |
493 | break; |
494 | case 3: // Repeat weekly |
495 | $chat->chattime += 7 * 24 * 3600; |
496 | break; |
497 | } |
498 | update_record("chat", $chat); |
8496c4af |
499 | |
500 | $event = NULL; // Update calendar too |
501 | if ($event->id = get_field('event', 'id', 'modulename', 'chat', 'instance', $chat->id)) { |
502 | $event->timestart = $chat->chattime; |
503 | update_event($event); |
504 | } |
fcd3a1ee |
505 | } |
506 | } |
507 | |
508 | |
aa5c32fd |
509 | function chat_format_message_manually($message, $courseid, $sender, $currentuser, $chat_lastrow=NULL) { |
72989350 |
510 | global $CFG, $USER; |
1515a89e |
511 | |
b5de723d |
512 | $output = New stdClass; |
516121bd |
513 | $output->beep = false; // by default |
514 | $output->refreshusers = false; // by default |
7d792369 |
515 | |
72989350 |
516 | // Use get_user_timezone() to find the correct timezone for displaying this message: |
517 | // It's either the current user's timezone or else decided by some Moodle config setting |
970f144e |
518 | // First, "reset" $USER->timezone (which could have been set by a previous call to here) |
519 | // because otherwise the value for the previous $currentuser will take precedence over $CFG->timezone |
520 | $USER->timezone = 99; |
72989350 |
521 | $tz = get_user_timezone($currentuser->timezone); |
b5de723d |
522 | |
72989350 |
523 | // Before formatting the message time string, set $USER->timezone to the above. |
524 | // This will allow dst_offset_on (called by userdate) to work correctly, otherwise the |
525 | // message times appear off because DST is not taken into account when it should be. |
526 | $USER->timezone = $tz; |
b5de723d |
527 | $message->strtime = userdate($message->timestamp, get_string('strftimemessage', 'chat'), $tz); |
528 | |
529 | $message->picture = print_user_picture($sender->id, 0, $sender->picture, false, true, false); |
582de679 |
530 | if ($courseid) { |
839f2456 |
531 | $message->picture = "<a target=\"_new\" href=\"$CFG->wwwroot/user/view.php?id=$sender->id&course=$courseid\">$message->picture</a>"; |
582de679 |
532 | } |
1515a89e |
533 | |
aa5c32fd |
534 | //Calculate the row class |
535 | if ($chat_lastrow !== NULL) { |
536 | $rowclass = ' class="r'.$chat_lastrow.'" '; |
537 | } else { |
538 | $rowclass = ''; |
539 | } |
540 | |
b5de723d |
541 | // Start processing the message |
1515a89e |
542 | |
b5de723d |
543 | if(!empty($message->system)) { |
544 | // System event |
545 | $output->text = $message->strtime.': '.get_string('message'.$message->message, 'chat', fullname($sender)); |
aa5c32fd |
546 | $output->html = '<table class="chat-event"><tr'.$rowclass.'><td class="picture">'.$message->picture.'</td><td class="text">'; |
547 | $output->html .= '<span class="event">'.$output->text.'</span></td></tr></table>'; |
7d792369 |
548 | |
516121bd |
549 | if($message->message == 'exit' or $message->message == 'enter') { |
550 | $output->refreshusers = true; //force user panel refresh ASAP |
551 | } |
1515a89e |
552 | return $output; |
553 | } |
554 | |
82a524ef |
555 | // It's not a system event |
b5de723d |
556 | |
557 | $text = $message->message; |
82a524ef |
558 | |
559 | /// Parse the text to clean and filter it |
560 | |
561 | $options->para = false; |
562 | $text = format_text($text, FORMAT_MOODLE, $options, $courseid); |
b5de723d |
563 | // And now check for special cases |
b5de723d |
564 | if (substr($text, 0, 5) == 'beep ') { |
0eda0a46 |
565 | /// It's a beep! |
7d792369 |
566 | $beepwho = trim(substr($text, 5)); |
9f85bed4 |
567 | |
b5de723d |
568 | if ($beepwho == 'all') { // everyone |
569 | $outinfo = $message->strtime.': '.get_string('messagebeepseveryone', 'chat', fullname($sender)); |
570 | $outmain = ''; |
571 | $output->beep = true; // (eventually this should be set to |
7d792369 |
572 | // to a filename uploaded by the user) |
573 | |
82a524ef |
574 | } else if ($beepwho == $currentuser->id) { // current user |
b5de723d |
575 | $outinfo = $message->strtime.': '.get_string('messagebeepsyou', 'chat', fullname($sender)); |
576 | $outmain = ''; |
7d792369 |
577 | $output->beep = true; |
0eda0a46 |
578 | |
579 | } else { //something is not caught? |
7d792369 |
580 | return false; |
581 | } |
b5de723d |
582 | } else if (substr($text, 0, 1) == ':') { /// It's an MOO emote |
583 | $outinfo = $message->strtime; |
584 | $outmain = $sender->firstname.' '.substr($text, 1); |
7d792369 |
585 | |
b5de723d |
586 | } else if (substr($text, 0, 1) == '/') { /// It's a user command |
1515a89e |
587 | |
7d792369 |
588 | if (substr($text, 0, 4) == "/me ") { |
b5de723d |
589 | $outinfo = $message->strtime; |
590 | $outmain = $sender->firstname.' '.substr($text, 4); |
9f85bed4 |
591 | } else { |
b5de723d |
592 | $outinfo = $message->strtime; |
7d792369 |
593 | $outmain = $text; |
1515a89e |
594 | } |
9f85bed4 |
595 | |
596 | } else { /// It's a normal message |
b5de723d |
597 | $outinfo = $message->strtime.' '.$sender->firstname; |
7d792369 |
598 | $outmain = $text; |
1515a89e |
599 | } |
0eda0a46 |
600 | |
9f85bed4 |
601 | /// Format the message as a small table |
1515a89e |
602 | |
b5de723d |
603 | $output->text = strip_tags($outinfo.': '.$outmain); |
7d792369 |
604 | |
5379d249 |
605 | $output->html = "<table class=\"chat-message\"><tr$rowclass><td class=\"picture\" valign=\"top\">$message->picture</td><td class=\"text\">"; |
aa5c32fd |
606 | $output->html .= "<span class=\"title\">$outinfo</span>"; |
7d792369 |
607 | if ($outmain) { |
608 | $output->html .= ": $outmain"; |
609 | } |
aa5c32fd |
610 | $output->html .= "</td></tr></table>"; |
7d792369 |
611 | return $output; |
b5de723d |
612 | } |
613 | |
aa5c32fd |
614 | function chat_format_message($message, $courseid, $currentuser, $chat_lastrow=NULL) { |
b5de723d |
615 | /// Given a message object full of information, this function |
616 | /// formats it appropriately into text and html, then |
617 | /// returns the formatted data. |
618 | |
78c98892 |
619 | static $users; // Cache user lookups |
620 | |
621 | if (isset($users[$message->userid])) { |
622 | $user = $users[$message->userid]; |
623 | } else if ($user = get_record('user', 'id', $message->userid, '','','','','id,picture,firstname,lastname')) { |
624 | $users[$message->userid] = $user; |
625 | } else { |
626 | return NULL; |
b5de723d |
627 | } |
aa5c32fd |
628 | return chat_format_message_manually($message, $courseid, $user, $currentuser, $chat_lastrow); |
1515a89e |
629 | } |
630 | |
38be9b31 |
631 | if (!function_exists('ob_get_clean')) { |
632 | /// Compatibility function for PHP < 4.3.0 |
633 | function ob_get_clean() { |
634 | $cont = ob_get_contents(); |
635 | if ($cont !== false) { |
636 | ob_end_clean(); |
637 | return $cont; |
638 | } else { |
639 | return $cont; |
640 | } |
641 | } |
642 | } |
643 | |
f3221af9 |
644 | function chat_get_view_actions() { |
645 | return array('view','view all','report'); |
646 | } |
647 | |
648 | function chat_get_post_actions() { |
649 | return array('talk'); |
650 | } |
651 | |
9ca0187e |
652 | function chat_print_overview($courses, &$htmlarray) { |
653 | global $USER, $CFG; |
654 | |
655 | if (empty($courses) || !is_array($courses) || count($courses) == 0) { |
656 | return array(); |
657 | } |
658 | |
659 | if (!$chats = get_all_instances_in_courses('chat',$courses)) { |
660 | return; |
661 | } |
662 | |
663 | $strchat = get_string('modulename', 'chat'); |
664 | $strnextsession = get_string('nextsession', 'chat'); |
9ca0187e |
665 | |
666 | foreach ($chats as $chat) { |
9ca0187e |
667 | if ($chat->chattime and $chat->schedule) { // A chat is scheduled |
a2a37336 |
668 | $str = '<div class="chat overview"><div class="name">'. |
669 | $strchat.': <a '.($chat->visible?'':' class="dimmed"'). |
670 | ' href="'.$CFG->wwwroot.'/mod/chat/view.php?id='.$chat->coursemodule.'">'. |
671 | $chat->name.'</a></div>'; |
672 | $str .= '<div class="info">'.$strnextsession.': '.userdate($chat->chattime).'</div></div>'; |
673 | |
674 | if (empty($htmlarray[$chat->course]['chat'])) { |
675 | $htmlarray[$chat->course]['chat'] = $str; |
676 | } else { |
677 | $htmlarray[$chat->course]['chat'] .= $str; |
678 | } |
9ca0187e |
679 | } |
9ca0187e |
680 | } |
681 | } |
682 | |
1515a89e |
683 | ?> |