3 require('../config.php');
9 redirect($CFG->wwwroot
);
12 if (empty($CFG->messaging
)) {
13 error("Messaging is disabled on this site");
17 $userid = required_param('id', PARAM_INT
);
18 $noframesjs = optional_param('noframesjs', 0, PARAM_BOOL
);
20 /// Check the user we are talking to is valid
21 if (! $user = get_record('user', 'id', $userid)) {
22 error("User ID was incorrect");
25 /// Check if frame&jsless mode selected
26 if (!get_user_preferences('message_noframesjs', 0) and !$noframesjs) {
28 /// Print frameset to contain all the various panes
29 @header
('Content-Type: text/html; charset=utf-8');
32 <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
35 <meta http
-equiv
="content-type" content
="text/html; charset=utf-8" />
36 <title
><?php
echo get_string('discussion', 'message').': '.fullname($user) ?
></title
>
38 <frameset rows
="110,*,0,220">
40 echo '<a href="discussion.php?id='.$userid.'&noframesjs=1">'.get_string('noframesjs', 'message').'<a/>';
43 <frame src
="user.php?id=<?php p($user->id)?>&frame=user" name
="user"
44 scrolling
="no" marginwidth
="0" marginheight
="0" frameborder
="0" />
45 <frame src
="messages.php" name
="messages"
46 scrolling
="yes" marginwidth
="10" marginheight
="10" frameborder
="0" />
47 <frame src
="refresh.php?id=<?php p($user->id)?>&name=<?php echo urlencode(fullname($user)) ?>" name
="refresh"
48 scrolling
="no" marginwidth
="0" marginheight
="0" frameborder
="0" />
49 <frame src
="send.php?id=<?php p($user->id)?>" name
="send"
50 scrolling
="no" marginwidth
="2" marginheight
="2" frameborder
="0" />
58 /// user wants simple frame&js-less mode
60 $start = optional_param('start', time(), PARAM_INT
);
61 $message = optional_param('message', '', PARAM_CLEAN
);
62 $format = optional_param('format', FORMAT_MOODLE
, PARAM_INT
);
63 $refresh = optional_param('refresh', '', PARAM_RAW
);
64 $last = optional_param('last', 0, PARAM_INT
);
65 $newonly = optional_param('newonly', 0, PARAM_BOOL
);
67 $addcontact = optional_param('addcontact', 0, PARAM_INT
); // adding a contact
68 $removecontact = optional_param('removecontact', 0, PARAM_INT
); // removing a contact
69 $blockcontact = optional_param('blockcontact', 0, PARAM_INT
); // blocking a contact
70 $unblockcontact = optional_param('unblockcontact', 0, PARAM_INT
); // unblocking a contact
72 if ($addcontact and confirm_sesskey()) {
73 add_to_log(SITEID
, 'message', 'add contact',
74 'discussion.php?user1='.$addcontact.'&user2='.$USER->id
, $addcontact);
75 message_add_contact($addcontact);
77 if ($removecontact and confirm_sesskey()) {
78 add_to_log(SITEID
, 'message', 'remove contact',
79 'discussion.php?user1='.$removecontact.'&user2='.$USER->id
, $removecontact);
80 message_remove_contact($removecontact);
82 if ($blockcontact and confirm_sesskey()) {
83 add_to_log(SITEID
, 'message', 'block contact',
84 'discussion.php?user1='.$blockcontact.'&user2='.$USER->id
, $blockcontact);
85 message_block_contact($blockcontact);
87 if ($unblockcontact and confirm_sesskey()) {
88 add_to_log(SITEID
, 'message', 'unblock contact',
89 'history.php?user1='.$unblockcontact.'&user2='.$USER->id
, $unblockcontact);
90 message_unblock_contact($unblockcontact);
93 /// Check that the user is not blocking us!!
94 if ($contact = get_record('message_contacts', 'userid', $user->id
, 'contactid', $USER->id
)) {
95 if ($contact->blocked
and !has_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM
, SITEID
))) {
96 print_heading(get_string('userisblockingyou', 'message'));
100 if (get_user_preferences('message_blocknoncontacts', 0, $user->id
)) { // User is blocking non-contacts
101 if (empty($contact)) { // We are not a contact!
102 print_heading(get_string('userisblockingyounoncontact', 'message'));
107 $refreshedmessage = '';
109 if (!empty($refresh) and data_submitted()) {
110 $refreshedmessage = $message;
112 } else if (empty($refresh) and data_submitted() and confirm_sesskey()) {
114 message_post_message($USER, $user, $message, $format, 'direct');
116 redirect('discussion.php?id='.$userid.'&start='.$start.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last);
120 $userfullname = fullname($user);
121 $mefullname = fullname($USER);
123 print_header(get_string('discussion', 'message').': '.fullname($user), '', '', 'edit-message');
124 echo '<div class="message-discussion-noframes">';
125 echo '<div id="userinfo">';
126 echo print_user_picture($user->id
, SITEID
, $user->picture
, 48, true, true, 'userwindow');
127 echo '<div class="name"><h1>'.$userfullname.'</h1></div>';
128 echo '<div class="commands"><ul>';
129 if ($contact = get_record('message_contacts', 'userid', $USER->id
, 'contactid', $user->id
)) {
130 if ($contact->blocked
) {
132 message_contact_link($user->id
, 'add', false, 'discussion.php?id='.$user->id
.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true);
134 message_contact_link($user->id
, 'unblock', false, 'discussion.php?id='.$user->id
.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true);
138 message_contact_link($user->id
, 'remove', false, 'discussion.php?id='.$user->id
.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true);
140 message_contact_link($user->id
, 'block', false, 'discussion.php?id='.$user->id
.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true);
145 message_contact_link($user->id
, 'add', false, 'discussion.php?id='.$user->id
.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true);
147 message_contact_link($user->id
, 'block', false, 'discussion.php?id='.$user->id
.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true);
151 message_history_link($user->id
, 0, false, '', '', 'both');
155 echo '</div>'; // class="userinfo"
157 echo '<div id="send">';
158 echo '<form id="editing" method="post" action="discussion.php">';
160 $usehtmleditor = (can_use_html_editor() && get_user_preferences('message_usehtmleditor', 0));
161 echo '<h1><label for="edit-message">'.get_string('sendmessage', 'message').'</label></h1>';
163 if ($usehtmleditor) {
164 print_textarea(true, 8, 34, 100, 100, 'message', $refreshedmessage);
165 use_html_editor('message', 'formatblock subscript superscript copy cut paste clean undo redo justifyleft justifycenter justifyright justifyfull lefttoright righttoleft insertorderedlist insertunorderedlist outdent indent inserthorizontalrule createanchor nolink inserttable');
166 echo '<input type="hidden" name="format" value="'.FORMAT_HTML
.'" />';
168 print_textarea(false, 8, 50, 0, 0, 'message', $refreshedmessage);
169 echo '<input type="hidden" name="format" value="'.FORMAT_MOODLE
.'" />';
172 echo '<input type="hidden" name="id" value="'.$user->id
.'" />';
173 echo '<input type="hidden" name="start" value="'.$start.'" />';
174 echo '<input type="hidden" name="noframesjs" value="'.$noframesjs.'" />';
175 echo '<input type="hidden" name="last" value="'.time().'" />';
176 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey
.'" />';
177 echo '<input type="submit" value="'.get_string('sendmessage', 'message').'" /> ';
178 echo '<input type="submit" name="refresh" value="'.get_string('refresh').'" />';
179 echo '<input type="checkbox" name="newonly" id="newonly" '.($newonly?
'checked="checked" ':'').'/><label for="newonly">'.get_string('newonlymsg', 'message').'</label>';
184 echo '<div id="messages">';
185 echo '<h1>'.get_string('messages', 'message').'</h1>';
187 $allmessages = array();
189 $options = new object();
190 $options->para
= false;
191 $options->newlines
= true;
194 $lastsql = " AND timecreated > $last";
199 if ($messages = get_records_select('message_read', "(useridto = '$USER->id' AND useridfrom = '$userid' AND timeread > '$start' $lastsql) OR (useridto = '$userid' AND useridfrom = '$USER->id' AND timeread > '$start' $lastsql)")) {
200 foreach ($messages as $message) {
201 $time = userdate($message->timecreated
, get_string('strftimedaytime'));
203 if ($message->useridfrom
== $USER->id
) {
204 $fullname = $mefullname;
206 $fullname = $userfullname;
209 $printmessage = format_text($message->message
, $message->format
, $options, 0);
210 $printmessage = '<div class="message other"><span class="author">'.$fullname.'</span> '.
211 '<span class="time">['.$time.']</span>: '.
212 '<span class="content">'.$printmessage.'</span></div>';
214 $sortkey = $message->timecreated
."$i"; // we need string bacause we would run out of int range
215 while (array_key_exists($sortkey, $allmessages)) {
217 $sortkey = $message->timecreated
."$i";
219 $allmessages[$sortkey] = $printmessage;
223 if ($messages = get_records_select('message', "useridto = '$userid' AND useridfrom = '$USER->id' $lastsql")) {
224 foreach ($messages as $message) {
225 $time = userdate($message->timecreated
, get_string('strftimedaytime'));
227 $printmessage = format_text($message->message
, $message->format
, $options, 0);
228 $printmessage = '<div class="message other"><span class="author">'.$mefullname.'</span> '.
229 '<span class="time">['.$time.']</span>: '.
230 '<span class="content">'.$printmessage.'</span></div>';
232 $sortkey = $message->timecreated
."$i"; // we need string bacause we would run out of int range
233 while (array_key_exists($sortkey, $allmessages)) {
235 $sortkey = $message->timecreated
."$i";
237 $allmessages[$sortkey] = $printmessage;
241 if ($messages = get_records_select('message', "useridto = '$USER->id' AND useridfrom = '$userid' $lastsql")) {
242 foreach ($messages as $message) {
243 $time = userdate($message->timecreated
, get_string('strftimedaytime'));
245 $printmessage = format_text($message->message
, $message->format
, $options, 0);
246 $printmessage = '<div class="message other"><span class="author">'.$userfullname.'</span> '.
247 '<span class="time">['.$time.']</span>: '.
248 '<span class="content">'.$printmessage.'</span></div>';
250 $sortkey = $message->timecreated
."$i"; // we need string bacause we would run out of int range
251 while (array_key_exists($sortkey, $allmessages)) {
253 $sortkey = $message->timecreated
."$i";
255 $allmessages[$sortkey] = $printmessage;
257 /// Move the entry to the other table
259 $messageid = $message->id
;
261 $message->timeread
= time();
262 $message = addslashes_object($message);
263 if (insert_record('message_read', $message)) {
264 delete_records('message', 'id', $messageid);
266 if ($message->timecreated
< $start) {
267 $start = $message->timecreated
; // move start back so that we see all current history
273 krsort($allmessages);
275 if (empty($allmessages)) {
276 echo get_string('nomessagesfound', 'message');
278 echo '<ul class="messagelist">';
279 foreach ($allmessages as $message) {
285 if ($playbeep and get_user_preferences('message_beepnewmessage', 0)) {
286 echo '<embed src="bell.wav" autostart="true" hidden="true" name="bell" />';
292 print_footer('none');