MDL-10392 completed: the finalgrade value wasn't assigned to the grade_grades object...
[moodle-pu.git] / message / discussion.php
blobd64a36f170264837305a65e3a0404128fe6ebc59
1 <?php // $Id$
3 require('../config.php');
4 require('lib.php');
6 require_login();
8 if (isguest()) {
9 redirect($CFG->wwwroot);
12 if (empty($CFG->messaging)) {
13 error("Messaging is disabled on this site");
16 /// Script parameters
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">
33 <html>
34 <head>
35 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
36 <title><?php echo get_string('discussion', 'message').': '.fullname($user) ?></title>
37 </head>
38 <frameset rows="110,*,0,200">
39 <noframes><body><?php
40 echo '<a href="discussion.php?id='.$userid.'&amp;noframesjs=1">'.get_string('noframesjs', 'message').'<a/>';
41 ?></body></noframes>
43 <frame src="user.php?id=<?php p($user->id)?>&amp;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)?>&amp;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" />
51 </frameset>
52 </html>
54 <?php
55 die;
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.'&amp;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.'&amp;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.'&amp;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.'&amp;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'));
97 exit;
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'));
103 exit;
107 $refreshedmessage = '';
109 if (!empty($refresh) and data_submitted()) {
110 $refreshedmessage = $message;
112 } else if (empty($refresh) and data_submitted() and confirm_sesskey()) {
113 if ($message!='') {
114 message_post_message($USER, $user, $message, $format, 'direct');
116 redirect('discussion.php?id='.$userid.'&amp;start='.$start.'&amp;noframesjs='.$noframesjs.'&amp;newonly='.$newonly.'&amp;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) {
131 echo '<li>';
132 message_contact_link($user->id, 'add', false, 'discussion.php?id='.$user->id.'&amp;noframesjs='.$noframesjs.'&amp;newonly='.$newonly.'&amp;last='.$last, true);
133 echo '</li><li>';
134 message_contact_link($user->id, 'unblock', false, 'discussion.php?id='.$user->id.'&amp;noframesjs='.$noframesjs.'&amp;newonly='.$newonly.'&amp;last='.$last, true);
135 echo '</li>';
136 } else {
137 echo '<li>';
138 message_contact_link($user->id, 'remove', false, 'discussion.php?id='.$user->id.'&amp;noframesjs='.$noframesjs.'&amp;newonly='.$newonly.'&amp;last='.$last, true);
139 echo '</li><li>';
140 message_contact_link($user->id, 'block', false, 'discussion.php?id='.$user->id.'&amp;noframesjs='.$noframesjs.'&amp;newonly='.$newonly.'&amp;last='.$last, true);
141 echo '</li>';
143 } else {
144 echo '<li>';
145 message_contact_link($user->id, 'add', false, 'discussion.php?id='.$user->id.'&amp;noframesjs='.$noframesjs.'&amp;newonly='.$newonly.'&amp;last='.$last, true);
146 echo '</li><li>';
147 message_contact_link($user->id, 'block', false, 'discussion.php?id='.$user->id.'&amp;noframesjs='.$noframesjs.'&amp;newonly='.$newonly.'&amp;last='.$last, true);
148 echo '</li>';
150 echo '<li>';
151 message_history_link($user->id, 0, false, '', '', 'both');
152 echo '</li>';
153 echo '</ul>';
154 echo '</div>';
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>';
162 echo '<div>';
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.'" />';
167 } else {
168 print_textarea(false, 8, 50, 0, 0, 'message', $refreshedmessage);
169 echo '<input type="hidden" name="format" value="'.FORMAT_MOODLE.'" />';
171 echo '</div><div>';
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').'" />&nbsp;';
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>';
180 echo '</div>';
181 echo '</form>';
182 echo '</div>';
184 echo '<div id="messages">';
185 echo '<h1>'.get_string('messages', 'message').'</h1>';
187 $allmessages = array();
188 $playbeep = false;
189 $options = new object();
190 $options->para = false;
191 $options->newlines = true;
193 if ($newonly) {
194 $lastsql = " AND timecreated > $last";
195 } else {
196 $lastsql = "";
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;
205 } else {
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>';
213 $i=0;
214 $sortkey = $message->timecreated."$i"; // we need string bacause we would run out of int range
215 while (array_key_exists($sortkey, $allmessages)) {
216 $i++;
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>';
231 $i=0;
232 $sortkey = $message->timecreated."$i"; // we need string bacause we would run out of int range
233 while (array_key_exists($sortkey, $allmessages)) {
234 $i++;
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>';
249 $i=0;
250 $sortkey = $message->timecreated."$i"; // we need string bacause we would run out of int range
251 while (array_key_exists($sortkey, $allmessages)) {
252 $i++;
253 $sortkey = $message->timecreated."$i";
255 $allmessages[$sortkey] = $printmessage;
257 /// Move the entry to the other table
259 $messageid = $message->id;
260 unset($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
270 $playbeep = true;
273 krsort($allmessages);
275 if (empty($allmessages)) {
276 echo get_string('nomessagesfound', 'message');
277 } else {
278 echo '<ul class="messagelist">';
279 foreach ($allmessages as $message) {
280 echo '<li>';
281 echo $message;
282 echo '</li>';
284 echo '</ul>';
285 if ($playbeep and get_user_preferences('message_beepnewmessage', 0)) {
286 echo '<embed src="bell.wav" autostart="true" hidden="true" name="bell" />';
290 echo '</div></div>';
292 print_footer('none');