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");
27 print_heading(get_string('userdeleted'));
32 /// Check if frame&jsless mode selected
33 if (!get_user_preferences('message_noframesjs', 0) and !$noframesjs) {
35 /// Print frameset to contain all the various panes
36 @header
('Content-Type: text/html; charset=utf-8');
39 <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
42 <meta http
-equiv
="content-type" content
="text/html; charset=utf-8" />
43 <title
><?php
echo get_string('discussion', 'message').': '.fullname($user) ?
></title
>
45 <frameset rows
="110,*,0,220">
47 echo '<a href="discussion.php?id='.$userid.'&noframesjs=1">'.get_string('noframesjs', 'message').'</a>';
50 <frame src
="user.php?id=<?php p($user->id)?>&frame=user" name
="user"
51 scrolling
="no" marginwidth
="0" marginheight
="0" frameborder
="0" />
52 <frame src
="messages.php" name
="messages"
53 scrolling
="yes" marginwidth
="10" marginheight
="10" frameborder
="0" />
54 <frame src
="refresh.php?id=<?php p($user->id)?>&name=<?php echo urlencode(fullname($user)) ?>" name
="refresh"
55 scrolling
="no" marginwidth
="0" marginheight
="0" frameborder
="0" />
57 <frame src
="send.php?id=<?php p($user->id)?>" name
="send"
58 scrolling
="no" marginwidth
="2" marginheight
="2" frameborder
="0" />
66 /// user wants simple frame&js-less mode
68 $start = optional_param('start', time(), PARAM_INT
);
69 $message = optional_param('message', '', PARAM_CLEAN
);
70 $format = optional_param('format', FORMAT_MOODLE
, PARAM_INT
);
71 $refresh = optional_param('refresh', '', PARAM_RAW
);
72 $last = optional_param('last', 0, PARAM_INT
);
73 $newonly = optional_param('newonly', 0, PARAM_BOOL
);
75 $addcontact = optional_param('addcontact', 0, PARAM_INT
); // adding a contact
76 $removecontact = optional_param('removecontact', 0, PARAM_INT
); // removing a contact
77 $blockcontact = optional_param('blockcontact', 0, PARAM_INT
); // blocking a contact
78 $unblockcontact = optional_param('unblockcontact', 0, PARAM_INT
); // unblocking a contact
80 if ($addcontact and confirm_sesskey()) {
81 add_to_log(SITEID
, 'message', 'add contact',
82 'discussion.php?user1='.$addcontact.'&user2='.$USER->id
, $addcontact);
83 message_add_contact($addcontact);
85 if ($removecontact and confirm_sesskey()) {
86 add_to_log(SITEID
, 'message', 'remove contact',
87 'discussion.php?user1='.$removecontact.'&user2='.$USER->id
, $removecontact);
88 message_remove_contact($removecontact);
90 if ($blockcontact and confirm_sesskey()) {
91 add_to_log(SITEID
, 'message', 'block contact',
92 'discussion.php?user1='.$blockcontact.'&user2='.$USER->id
, $blockcontact);
93 message_block_contact($blockcontact);
95 if ($unblockcontact and confirm_sesskey()) {
96 add_to_log(SITEID
, 'message', 'unblock contact',
97 'history.php?user1='.$unblockcontact.'&user2='.$USER->id
, $unblockcontact);
98 message_unblock_contact($unblockcontact);
101 /// Check that the user is not blocking us!!
102 if ($contact = get_record('message_contacts', 'userid', $user->id
, 'contactid', $USER->id
)) {
103 if ($contact->blocked
and !has_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM
))) {
104 print_heading(get_string('userisblockingyou', 'message'));
108 if (get_user_preferences('message_blocknoncontacts', 0, $user->id
)) { // User is blocking non-contacts
109 if (empty($contact)) { // We are not a contact!
110 print_heading(get_string('userisblockingyounoncontact', 'message'));
115 $refreshedmessage = '';
117 if (!empty($refresh) and data_submitted()) {
118 $refreshedmessage = $message;
120 } else if (empty($refresh) and data_submitted() and confirm_sesskey()) {
122 message_post_message($USER, $user, $message, $format, 'direct');
124 redirect('discussion.php?id='.$userid.'&start='.$start.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last);
128 $userfullname = fullname($user);
129 $mefullname = fullname($USER);
131 print_header(get_string('discussion', 'message').': '.fullname($user), '', '', 'edit-message');
132 echo '<div class="message-discussion-noframes">';
133 echo '<div id="userinfo">';
134 echo print_user_picture($user, SITEID
, $user->picture
, 48, true, true, 'userwindow');
135 echo '<div class="name"><h1>'.$userfullname.'</h1></div>';
136 echo '<div class="commands"><ul>';
137 if ($contact = get_record('message_contacts', 'userid', $USER->id
, 'contactid', $user->id
)) {
138 if ($contact->blocked
) {
140 message_contact_link($user->id
, 'add', false, 'discussion.php?id='.$user->id
.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true);
142 message_contact_link($user->id
, 'unblock', false, 'discussion.php?id='.$user->id
.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true);
146 message_contact_link($user->id
, 'remove', 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);
153 message_contact_link($user->id
, 'add', false, 'discussion.php?id='.$user->id
.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true);
155 message_contact_link($user->id
, 'block', false, 'discussion.php?id='.$user->id
.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true);
159 message_history_link($user->id
, 0, false, '', '', 'both');
163 echo '</div>'; // class="userinfo"
165 echo '<div id="send">';
166 echo '<form id="editing" method="post" action="discussion.php">';
168 $usehtmleditor = (can_use_html_editor() && get_user_preferences('message_usehtmleditor', 0));
169 echo '<h1><label for="edit-message">'.get_string('sendmessage', 'message').'</label></h1>';
171 if ($usehtmleditor) {
172 print_textarea(true, 8, 34, 100, 100, 'message', $refreshedmessage);
173 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');
174 echo '<input type="hidden" name="format" value="'.FORMAT_HTML
.'" />';
176 print_textarea(false, 8, 50, 0, 0, 'message', $refreshedmessage);
177 echo '<input type="hidden" name="format" value="'.FORMAT_MOODLE
.'" />';
180 echo '<input type="hidden" name="id" value="'.$user->id
.'" />';
181 echo '<input type="hidden" name="start" value="'.$start.'" />';
182 echo '<input type="hidden" name="noframesjs" value="'.$noframesjs.'" />';
183 echo '<input type="hidden" name="last" value="'.time().'" />';
184 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey
.'" />';
185 echo '<input type="submit" value="'.get_string('sendmessage', 'message').'" /> ';
186 echo '<input type="submit" name="refresh" value="'.get_string('refresh').'" />';
187 echo '<input type="checkbox" name="newonly" id="newonly" '.($newonly?
'checked="checked" ':'').'/><label for="newonly">'.get_string('newonlymsg', 'message').'</label>';
192 echo '<div id="messages">';
193 echo '<h1>'.get_string('messages', 'message').'</h1>';
195 $allmessages = array();
197 $options = new object();
198 $options->para
= false;
199 $options->newlines
= true;
202 $lastsql = " AND timecreated > $last";
207 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)")) {
208 foreach ($messages as $message) {
209 $time = userdate($message->timecreated
, get_string('strftimedatetimeshort'));
211 if ($message->useridfrom
== $USER->id
) {
212 $fullname = $mefullname;
214 $fullname = $userfullname;
217 $printmessage = format_text($message->message
, $message->format
, $options, 0);
218 $printmessage = '<div class="message other"><span class="author">'.$fullname.'</span> '.
219 '<span class="time">['.$time.']</span>: '.
220 '<span class="content">'.$printmessage.'</span></div>';
222 $sortkey = $message->timecreated
."$i"; // we need string bacause we would run out of int range
223 while (array_key_exists($sortkey, $allmessages)) {
225 $sortkey = $message->timecreated
."$i";
227 $allmessages[$sortkey] = $printmessage;
231 if ($messages = get_records_select('message', "useridto = '$userid' AND useridfrom = '$USER->id' $lastsql")) {
232 foreach ($messages as $message) {
233 $time = userdate($message->timecreated
, get_string('strftimedatetimeshort'));
235 $printmessage = format_text($message->message
, $message->format
, $options, 0);
236 $printmessage = '<div class="message other"><span class="author">'.$mefullname.'</span> '.
237 '<span class="time">['.$time.']</span>: '.
238 '<span class="content">'.$printmessage.'</span></div>';
240 $sortkey = $message->timecreated
."$i"; // we need string bacause we would run out of int range
241 while (array_key_exists($sortkey, $allmessages)) {
243 $sortkey = $message->timecreated
."$i";
245 $allmessages[$sortkey] = $printmessage;
249 if ($messages = get_records_select('message', "useridto = '$USER->id' AND useridfrom = '$userid' $lastsql")) {
250 foreach ($messages as $message) {
251 $time = userdate($message->timecreated
, get_string('strftimedatetimeshort'));
253 $printmessage = format_text($message->message
, $message->format
, $options, 0);
254 $printmessage = '<div class="message other"><span class="author">'.$userfullname.'</span> '.
255 '<span class="time">['.$time.']</span>: '.
256 '<span class="content">'.$printmessage.'</span></div>';
258 $sortkey = $message->timecreated
."$i"; // we need string bacause we would run out of int range
259 while (array_key_exists($sortkey, $allmessages)) {
261 $sortkey = $message->timecreated
."$i";
263 $allmessages[$sortkey] = $printmessage;
265 /// Move the entry to the other table
267 $messageid = $message->id
;
269 $message->timeread
= time();
270 $message = addslashes_object($message);
271 if (insert_record('message_read', $message)) {
272 delete_records('message', 'id', $messageid);
274 if ($message->timecreated
< $start) {
275 $start = $message->timecreated
; // move start back so that we see all current history
281 krsort($allmessages);
283 if (empty($allmessages)) {
284 echo get_string('nomessagesfound', 'message');
286 echo '<ul class="messagelist">';
287 foreach ($allmessages as $message) {
293 if ($playbeep and get_user_preferences('message_beepnewmessage', 0)) {
294 echo '<embed src="bell.wav" autostart="true" hidden="true" name="bell" />';
300 print_footer('none');