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" />
50 <frame src
="send.php?id=<?php p($user->id)?>" name
="send"
51 scrolling
="no" marginwidth
="2" marginheight
="2" frameborder
="0" />
59 /// user wants simple frame&js-less mode
61 $start = optional_param('start', time(), PARAM_INT
);
62 $message = optional_param('message', '', PARAM_CLEAN
);
63 $format = optional_param('format', FORMAT_MOODLE
, PARAM_INT
);
64 $refresh = optional_param('refresh', '', PARAM_RAW
);
65 $last = optional_param('last', 0, PARAM_INT
);
66 $newonly = optional_param('newonly', 0, PARAM_BOOL
);
68 $addcontact = optional_param('addcontact', 0, PARAM_INT
); // adding a contact
69 $removecontact = optional_param('removecontact', 0, PARAM_INT
); // removing a contact
70 $blockcontact = optional_param('blockcontact', 0, PARAM_INT
); // blocking a contact
71 $unblockcontact = optional_param('unblockcontact', 0, PARAM_INT
); // unblocking a contact
73 if ($addcontact and confirm_sesskey()) {
74 add_to_log(SITEID
, 'message', 'add contact',
75 'discussion.php?user1='.$addcontact.'&user2='.$USER->id
, $addcontact);
76 message_add_contact($addcontact);
78 if ($removecontact and confirm_sesskey()) {
79 add_to_log(SITEID
, 'message', 'remove contact',
80 'discussion.php?user1='.$removecontact.'&user2='.$USER->id
, $removecontact);
81 message_remove_contact($removecontact);
83 if ($blockcontact and confirm_sesskey()) {
84 add_to_log(SITEID
, 'message', 'block contact',
85 'discussion.php?user1='.$blockcontact.'&user2='.$USER->id
, $blockcontact);
86 message_block_contact($blockcontact);
88 if ($unblockcontact and confirm_sesskey()) {
89 add_to_log(SITEID
, 'message', 'unblock contact',
90 'history.php?user1='.$unblockcontact.'&user2='.$USER->id
, $unblockcontact);
91 message_unblock_contact($unblockcontact);
94 /// Check that the user is not blocking us!!
95 if ($contact = get_record('message_contacts', 'userid', $user->id
, 'contactid', $USER->id
)) {
96 if ($contact->blocked
and !has_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM
))) {
97 print_heading(get_string('userisblockingyou', 'message'));
101 if (get_user_preferences('message_blocknoncontacts', 0, $user->id
)) { // User is blocking non-contacts
102 if (empty($contact)) { // We are not a contact!
103 print_heading(get_string('userisblockingyounoncontact', 'message'));
108 $refreshedmessage = '';
110 if (!empty($refresh) and data_submitted()) {
111 $refreshedmessage = $message;
113 } else if (empty($refresh) and data_submitted() and confirm_sesskey()) {
115 message_post_message($USER, $user, $message, $format, 'direct');
117 redirect('discussion.php?id='.$userid.'&start='.$start.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last);
121 $userfullname = fullname($user);
122 $mefullname = fullname($USER);
124 print_header(get_string('discussion', 'message').': '.fullname($user), '', '', 'edit-message');
125 echo '<div class="message-discussion-noframes">';
126 echo '<div id="userinfo">';
127 echo print_user_picture($user, SITEID
, $user->picture
, 48, true, true, 'userwindow');
128 echo '<div class="name"><h1>'.$userfullname.'</h1></div>';
129 echo '<div class="commands"><ul>';
130 if ($contact = get_record('message_contacts', 'userid', $USER->id
, 'contactid', $user->id
)) {
131 if ($contact->blocked
) {
133 message_contact_link($user->id
, 'add', false, 'discussion.php?id='.$user->id
.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true);
135 message_contact_link($user->id
, 'unblock', false, 'discussion.php?id='.$user->id
.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true);
139 message_contact_link($user->id
, 'remove', false, 'discussion.php?id='.$user->id
.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true);
141 message_contact_link($user->id
, 'block', false, 'discussion.php?id='.$user->id
.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true);
146 message_contact_link($user->id
, 'add', false, 'discussion.php?id='.$user->id
.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true);
148 message_contact_link($user->id
, 'block', false, 'discussion.php?id='.$user->id
.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true);
152 message_history_link($user->id
, 0, false, '', '', 'both');
156 echo '</div>'; // class="userinfo"
158 echo '<div id="send">';
159 echo '<form id="editing" method="post" action="discussion.php">';
161 $usehtmleditor = (can_use_html_editor() && get_user_preferences('message_usehtmleditor', 0));
162 echo '<h1><label for="edit-message">'.get_string('sendmessage', 'message').'</label></h1>';
164 if ($usehtmleditor) {
165 print_textarea(true, 8, 34, 100, 100, 'message', $refreshedmessage);
166 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');
167 echo '<input type="hidden" name="format" value="'.FORMAT_HTML
.'" />';
169 print_textarea(false, 8, 50, 0, 0, 'message', $refreshedmessage);
170 echo '<input type="hidden" name="format" value="'.FORMAT_MOODLE
.'" />';
173 echo '<input type="hidden" name="id" value="'.$user->id
.'" />';
174 echo '<input type="hidden" name="start" value="'.$start.'" />';
175 echo '<input type="hidden" name="noframesjs" value="'.$noframesjs.'" />';
176 echo '<input type="hidden" name="last" value="'.time().'" />';
177 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey
.'" />';
178 echo '<input type="submit" value="'.get_string('sendmessage', 'message').'" /> ';
179 echo '<input type="submit" name="refresh" value="'.get_string('refresh').'" />';
180 echo '<input type="checkbox" name="newonly" id="newonly" '.($newonly?
'checked="checked" ':'').'/><label for="newonly">'.get_string('newonlymsg', 'message').'</label>';
185 echo '<div id="messages">';
186 echo '<h1>'.get_string('messages', 'message').'</h1>';
188 $allmessages = array();
190 $options = new object();
191 $options->para
= false;
192 $options->newlines
= true;
195 $lastsql = " AND timecreated > $last";
200 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)")) {
201 foreach ($messages as $message) {
202 $time = userdate($message->timecreated
, get_string('strftimedatetimeshort'));
204 if ($message->useridfrom
== $USER->id
) {
205 $fullname = $mefullname;
207 $fullname = $userfullname;
210 $printmessage = format_text($message->message
, $message->format
, $options, 0);
211 $printmessage = '<div class="message other"><span class="author">'.$fullname.'</span> '.
212 '<span class="time">['.$time.']</span>: '.
213 '<span class="content">'.$printmessage.'</span></div>';
215 $sortkey = $message->timecreated
."$i"; // we need string bacause we would run out of int range
216 while (array_key_exists($sortkey, $allmessages)) {
218 $sortkey = $message->timecreated
."$i";
220 $allmessages[$sortkey] = $printmessage;
224 if ($messages = get_records_select('message', "useridto = '$userid' AND useridfrom = '$USER->id' $lastsql")) {
225 foreach ($messages as $message) {
226 $time = userdate($message->timecreated
, get_string('strftimedatetimeshort'));
228 $printmessage = format_text($message->message
, $message->format
, $options, 0);
229 $printmessage = '<div class="message other"><span class="author">'.$mefullname.'</span> '.
230 '<span class="time">['.$time.']</span>: '.
231 '<span class="content">'.$printmessage.'</span></div>';
233 $sortkey = $message->timecreated
."$i"; // we need string bacause we would run out of int range
234 while (array_key_exists($sortkey, $allmessages)) {
236 $sortkey = $message->timecreated
."$i";
238 $allmessages[$sortkey] = $printmessage;
242 if ($messages = get_records_select('message', "useridto = '$USER->id' AND useridfrom = '$userid' $lastsql")) {
243 foreach ($messages as $message) {
244 $time = userdate($message->timecreated
, get_string('strftimedatetimeshort'));
246 $printmessage = format_text($message->message
, $message->format
, $options, 0);
247 $printmessage = '<div class="message other"><span class="author">'.$userfullname.'</span> '.
248 '<span class="time">['.$time.']</span>: '.
249 '<span class="content">'.$printmessage.'</span></div>';
251 $sortkey = $message->timecreated
."$i"; // we need string bacause we would run out of int range
252 while (array_key_exists($sortkey, $allmessages)) {
254 $sortkey = $message->timecreated
."$i";
256 $allmessages[$sortkey] = $printmessage;
258 /// Move the entry to the other table
260 $messageid = $message->id
;
262 $message->timeread
= time();
263 $message = addslashes_object($message);
264 if (insert_record('message_read', $message)) {
265 delete_records('message', 'id', $messageid);
267 if ($message->timecreated
< $start) {
268 $start = $message->timecreated
; // move start back so that we see all current history
274 krsort($allmessages);
276 if (empty($allmessages)) {
277 echo get_string('nomessagesfound', 'message');
279 echo '<ul class="messagelist">';
280 foreach ($allmessages as $message) {
286 if ($playbeep and get_user_preferences('message_beepnewmessage', 0)) {
287 echo '<embed src="bell.wav" autostart="true" hidden="true" name="bell" />';
293 print_footer('none');