| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: discussion.php,v 1.15.2.5 2008/07/05 14:53:32 skodak Exp $ 2 3 require ('../config.php'); 4 require ('lib.php'); 5 6 require_login(); 7 8 if (isguest()) { 9 redirect($CFG->wwwroot); 10 } 11 12 if (empty($CFG->messaging)) { 13 error("Messaging is disabled on this site"); 14 } 15 16 /// Script parameters 17 $userid = required_param('id', PARAM_INT); 18 $noframesjs = optional_param('noframesjs', 0, PARAM_BOOL); 19 20 /// Check the user we are talking to is valid 21 if (! $user = get_record('user', 'id', $userid)) { 22 error("User ID was incorrect"); 23 } 24 25 if ($user->deleted) { 26 print_header(); 27 print_heading(get_string('userdeleted')); 28 print_footer(); 29 die; 30 } 31 32 /// Check if frame&jsless mode selected 33 if (!get_user_preferences('message_noframesjs', 0) and !$noframesjs) { 34 35 /// Print frameset to contain all the various panes 36 @header('Content-Type: text/html; charset=utf-8'); 37 38 ?> 39 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> 40 <html> 41 <head> 42 <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 43 <title><?php echo get_string('discussion', 'message').': '.fullname($user) ?></title> 44 </head> 45 <frameset rows="110,*,0,220"> 46 <noframes><body><?php 47 echo '<a href="discussion.php?id='.$userid.'&noframesjs=1">'.get_string('noframesjs', 'message').'</a>'; 48 ?></body></noframes> 49 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" /> 56 57 <frame src="send.php?id=<?php p($user->id)?>" name="send" 58 scrolling="no" marginwidth="2" marginheight="2" frameborder="0" /> 59 </frameset> 60 </html> 61 62 <?php 63 die; 64 } 65 66 /// user wants simple frame&js-less mode 67 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); 74 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 79 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); 84 } 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); 89 } 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); 94 } 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); 99 } 100 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')); 105 exit; 106 } 107 } 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')); 111 exit; 112 } 113 } 114 115 $refreshedmessage = ''; 116 117 if (!empty($refresh) and data_submitted()) { 118 $refreshedmessage = $message; 119 120 } else if (empty($refresh) and data_submitted() and confirm_sesskey()) { 121 if ($message!='') { 122 message_post_message($USER, $user, $message, $format, 'direct'); 123 } 124 redirect('discussion.php?id='.$userid.'&start='.$start.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last); 125 } 126 127 128 $userfullname = fullname($user); 129 $mefullname = fullname($USER); 130 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) { 139 echo '<li>'; 140 message_contact_link($user->id, 'add', false, 'discussion.php?id='.$user->id.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true); 141 echo '</li><li>'; 142 message_contact_link($user->id, 'unblock', false, 'discussion.php?id='.$user->id.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true); 143 echo '</li>'; 144 } else { 145 echo '<li>'; 146 message_contact_link($user->id, 'remove', false, 'discussion.php?id='.$user->id.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true); 147 echo '</li><li>'; 148 message_contact_link($user->id, 'block', false, 'discussion.php?id='.$user->id.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true); 149 echo '</li>'; 150 } 151 } else { 152 echo '<li>'; 153 message_contact_link($user->id, 'add', false, 'discussion.php?id='.$user->id.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true); 154 echo '</li><li>'; 155 message_contact_link($user->id, 'block', false, 'discussion.php?id='.$user->id.'&noframesjs='.$noframesjs.'&newonly='.$newonly.'&last='.$last, true); 156 echo '</li>'; 157 } 158 echo '<li>'; 159 message_history_link($user->id, 0, false, '', '', 'both'); 160 echo '</li>'; 161 echo '</ul>'; 162 echo '</div>'; 163 echo '</div>'; // class="userinfo" 164 165 echo '<div id="send">'; 166 echo '<form id="editing" method="post" action="discussion.php">'; 167 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>'; 170 echo '<div>'; 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.'" />'; 175 } else { 176 print_textarea(false, 8, 50, 0, 0, 'message', $refreshedmessage); 177 echo '<input type="hidden" name="format" value="'.FORMAT_MOODLE.'" />'; 178 } 179 echo '</div><div>'; 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>'; 188 echo '</div>'; 189 echo '</form>'; 190 echo '</div>'; 191 192 echo '<div id="messages">'; 193 echo '<h1>'.get_string('messages', 'message').'</h1>'; 194 195 $allmessages = array(); 196 $playbeep = false; 197 $options = new object(); 198 $options->para = false; 199 $options->newlines = true; 200 201 if ($newonly) { 202 $lastsql = " AND timecreated > $last"; 203 } else { 204 $lastsql = ""; 205 } 206 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')); 210 211 if ($message->useridfrom == $USER->id) { 212 $fullname = $mefullname; 213 } else { 214 $fullname = $userfullname; 215 } 216 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>'; 221 $i=0; 222 $sortkey = $message->timecreated."$i"; // we need string bacause we would run out of int range 223 while (array_key_exists($sortkey, $allmessages)) { 224 $i++; 225 $sortkey = $message->timecreated."$i"; 226 } 227 $allmessages[$sortkey] = $printmessage; 228 } 229 } 230 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')); 234 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>'; 239 $i=0; 240 $sortkey = $message->timecreated."$i"; // we need string bacause we would run out of int range 241 while (array_key_exists($sortkey, $allmessages)) { 242 $i++; 243 $sortkey = $message->timecreated."$i"; 244 } 245 $allmessages[$sortkey] = $printmessage; 246 } 247 } 248 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')); 252 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>'; 257 $i=0; 258 $sortkey = $message->timecreated."$i"; // we need string bacause we would run out of int range 259 while (array_key_exists($sortkey, $allmessages)) { 260 $i++; 261 $sortkey = $message->timecreated."$i"; 262 } 263 $allmessages[$sortkey] = $printmessage; 264 265 /// Move the entry to the other table 266 267 $messageid = $message->id; 268 unset($message->id); 269 $message->timeread = time(); 270 $message = addslashes_object($message); 271 if (insert_record('message_read', $message)) { 272 delete_records('message', 'id', $messageid); 273 } 274 if ($message->timecreated < $start) { 275 $start = $message->timecreated; // move start back so that we see all current history 276 } 277 } 278 $playbeep = true; 279 } 280 281 krsort($allmessages); 282 283 if (empty($allmessages)) { 284 echo get_string('nomessagesfound', 'message'); 285 } else { 286 echo '<ul class="messagelist">'; 287 foreach ($allmessages as $message) { 288 echo '<li>'; 289 echo $message; 290 echo '</li>'; 291 } 292 echo '</ul>'; 293 if ($playbeep and get_user_preferences('message_beepnewmessage', 0)) { 294 echo '<embed src="bell.wav" autostart="true" hidden="true" name="bell" />'; 295 } 296 } 297 298 echo '</div></div>'; 299 300 print_footer('none'); 301 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |