3 require('../config.php');
9 redirect($CFG->wwwroot
);
12 if (empty($CFG->messaging
)) {
13 error("Messaging is disabled on this site");
16 /// Don't use print_header, for more speed
17 $stylesheetshtml = '';
18 foreach ($CFG->stylesheets
as $stylesheet) {
19 $stylesheetshtml .= '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'" />';
23 echo $stylesheetshtml;
26 $userid = required_param('id', PARAM_INT
);
27 $message = optional_param('message', '', PARAM_CLEANHTML
);
28 $format = optional_param('format', FORMAT_MOODLE
, PARAM_INT
);
30 /// Check the user we are talking to is valid
31 if (! $user = get_record('user', 'id', $userid)) {
32 error("User ID was incorrect");
35 /// Check that the user is not blocking us!!
36 if ($contact = get_record('message_contacts', 'userid', $user->id
, 'contactid', $USER->id
)) {
37 if ($contact->blocked
and !isadmin()) {
38 print_heading(get_string('userisblockingyou', 'message'));
42 if (get_user_preferences('message_blocknoncontacts', 0, $user->id
)) { // User is blocking non-contacts
43 if (empty($contact)) { // We are not a contact!
44 print_heading(get_string('userisblockingyounoncontact', 'message'));
49 if ($message and confirm_sesskey()) { /// Current user has just sent a message
51 /// Save it to the database...
52 $messageid = message_post_message($USER, $user, addslashes($message), $format, 'direct');
54 /// Format the message as HTML
56 $options->para
= false;
57 $options->newlines
= true;
58 $message = format_text($message, $format, $options, 0);
60 $message = str_replace("\r", ' ', $message);
61 $message = str_replace("\n", ' ', $message);
62 $time = userdate(time(), get_string('strftimedaytime'));
63 $message = '<div class="message me"><span class="author">'.fullname($USER).'</span> '.
64 '<span class="time">['.$time.']</span>: '.
65 '<span class="content">'.$message.'</span></div>';
66 $message = addslashes($message); // So Javascript can write it
67 $message = str_replace('</', '<\/', $message); // XHTML compliance
69 /// Then write it to our own message screen immediately
70 echo "\n<script type=\"text/javascript\">\n<!--\n";
71 echo 'parent.messages.document.write(\''.$message."\\n');\n";
72 echo 'parent.messages.scroll(1,5000000);';
73 echo "\n-->\n</script>\n\n";
75 $date = usergetdate($message->timecreated
);
76 $datestring = $date['year'].$date['mon'].$date['mday'];
78 add_to_log(SITEID
, 'message', 'write', 'history.php?user1='.$user->id
.'&user2='.$USER->id
.'#m'.$messageid, $user->id
);
84 echo '<body class="message course-1" id="message-send">';
86 echo '<form name="editing" method="post" action="send.php">';
87 echo '<input type="hidden" name="id" value="'.$user->id
.'" />';
88 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey
.'" />';
90 $usehtmleditor = (can_use_html_editor() && get_user_preferences('message_usehtmleditor', 0));
92 echo '<table align="center"><tr><td align="center">';
93 print_textarea($usehtmleditor, 8, 34, 0, 0, 'message', '');
94 echo '</td></tr></table>';
95 use_html_editor('message', 'formatblock subscript superscript copy cut paste clean undo redo justifyleft justifycenter justifyright justifyfull lefttoright righttoleft insertorderedlist insertunorderedlist outdent indent forecolor hilitecolor inserthorizontalrule createanchor nolink inserttable');
96 echo '<input type="hidden" name="format" value="'.FORMAT_HTML
.'" />';
98 print_textarea(false, 5, 34, 0, 0, 'message', '');
99 echo '<input type="hidden" name="format" value="'.FORMAT_MOODLE
.'" />';
101 echo '<br /><input type="submit" value="'.get_string('sendmessage', 'message').'" />';
105 echo "\n<script type=\"text/javascript\">\n<!--\n"; /// Focus on the textarea
106 echo 'document.getElementById("edit-message").focus();'."\n";
107 echo "\n-->\n</script>\n\n";
109 echo '</body></html>';