3 require('../config.php');
9 redirect($CFG->wwwroot
);
12 if (empty($CFG->messaging
)) {
13 error("Messaging is disabled on this site");
16 if (has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTEM
))) {
19 /// Don't use print_header, for more speed
20 $stylesheetshtml = '';
21 foreach ($CFG->stylesheets
as $stylesheet) {
22 $stylesheetshtml .= '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'" />';
26 if ( get_string('thisdirection') == 'rtl' ) {
27 $direction = ' dir="rtl"';
29 $direction = ' dir="ltr"';
32 @header
('Content-Type: text/html; charset=utf-8');
33 echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
34 echo "<html $direction xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n";
35 echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />';
36 echo $stylesheetshtml;
37 include($CFG->javascript
);
40 $userid = required_param('id', PARAM_INT
);
41 $message = optional_param('message', '', PARAM_CLEANHTML
);
42 $format = optional_param('format', FORMAT_MOODLE
, PARAM_INT
);
44 /// Check the user we are talking to is valid
45 if (! $user = get_record('user', 'id', $userid)) {
46 error("User ID was incorrect");
49 /// Check that the user is not blocking us!!
50 if ($contact = get_record('message_contacts', 'userid', $user->id
, 'contactid', $USER->id
)) {
51 if ($contact->blocked
and !has_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM
))) {
52 print_heading(get_string('userisblockingyou', 'message'));
56 $userpreferences = get_user_preferences(NULL, NULL, $user->id
);
58 if (!empty($userpreferences['message_blocknoncontacts'])) { // User is blocking non-contacts
59 if (empty($contact)) { // We are not a contact!
60 print_heading(get_string('userisblockingyounoncontact', 'message'));
66 if ($message!='' and confirm_sesskey()) { /// Current user has just sent a message
68 /// Save it to the database...
69 $messageid = message_post_message($USER, $user, addslashes($message), $format, 'direct');
71 /// Format the message as HTML
73 $options->para
= false;
74 $options->newlines
= true;
75 $message = format_text($message, $format, $options);
77 $time = userdate(time(), get_string('strftimedatetimeshort'));
78 $message = '<div class="message me"><span class="author">'.fullname($USER).'</span> '.
79 '<span class="time">['.$time.']</span>: '.
80 '<span class="content">'.$message.'</span></div>';
81 $message = addslashes_js($message); // So Javascript can write it
83 /// Then write it to our own message screen immediately
84 echo "\n<script type=\"text/javascript\">\n<!--\n";
85 echo 'parent.messages.document.write(\''.$message."\\n');\n";
86 echo 'parent.messages.scroll(1,5000000);';
87 echo "\n-->\n</script>\n\n";
89 add_to_log(SITEID
, 'message', 'write', 'history.php?user1='.$user->id
.'&user2='.$USER->id
.'#m'.$messageid, $user->id
);
92 echo '<title> </title></head>';
95 echo '<body class="message course-1" id="message-send">';
97 echo '<form id="editing" method="post" action="send.php">';
99 echo '<input type="hidden" name="id" value="'.$user->id
.'" />';
100 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey
.'" />';
102 $usehtmleditor = (can_use_html_editor() && get_user_preferences('message_usehtmleditor', 0));
103 if ($usehtmleditor) {
104 echo '<table><tr><td class="fixeditor" align="center">';
105 print_textarea($usehtmleditor, 9, 200, 0, 0, 'message', '');
106 echo '</td></tr></table>';
107 echo '<input type="submit" value="'.get_string('sendmessage', 'message').'" />';
108 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');
109 echo '<input type="hidden" name="format" value="'.FORMAT_HTML
.'" />';
111 print_textarea(false, 5, 34, 0, 0, 'message', '');
112 echo '<input type="hidden" name="format" value="'.FORMAT_MOODLE
.'" />';
113 echo '<br /><input type="submit" value="'.get_string('sendmessage', 'message').'" />';
117 if (!empty($CFG->messagewasjustemailed
)) {
118 notify(get_string('mailsent', 'message'), 'notifysuccess');
120 echo '<div class="noframesjslink"><a target="_parent" href="discussion.php?id='.$userid.'&noframesjs=1">'.get_string('noframesjs', 'message').'</a></div>';
123 echo "\n<script type=\"text/javascript\">\n<!--\n"; /// Focus on the textarea
124 echo 'document.getElementById("edit-message").focus();'."\n";
125 echo "\n-->\n</script>\n\n";
127 echo '</body></html>';