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 if ( get_string('thisdirection') == 'rtl' ) {
24 $direction = ' dir="rtl"';
26 $direction = ' dir="ltr"';
29 @header
('Content-Type: text/html; charset=utf-8');
30 echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
31 echo "<html $direction xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n";
32 echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />';
33 echo $stylesheetshtml;
36 $userid = required_param('id', PARAM_INT
);
37 $message = optional_param('message', '', PARAM_CLEANHTML
);
38 $format = optional_param('format', FORMAT_MOODLE
, PARAM_INT
);
40 /// Check the user we are talking to is valid
41 if (! $user = get_record('user', 'id', $userid)) {
42 error("User ID was incorrect");
45 /// Check that the user is not blocking us!!
46 if ($contact = get_record('message_contacts', 'userid', $user->id
, 'contactid', $USER->id
)) {
47 if ($contact->blocked
and !has_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM
, SITEID
))) {
48 print_heading(get_string('userisblockingyou', 'message'));
52 $userpreferences = get_user_preferences(NULL, NULL, $user->id
);
54 if (!empty($userpreferences['message_blocknoncontacts'])) { // User is blocking non-contacts
55 if (empty($contact)) { // We are not a contact!
56 print_heading(get_string('userisblockingyounoncontact', 'message'));
62 if ($message!='' and confirm_sesskey()) { /// Current user has just sent a message
64 /// Save it to the database...
65 $messageid = message_post_message($USER, $user, addslashes($message), $format, 'direct');
67 /// Format the message as HTML
69 $options->para
= false;
70 $options->newlines
= true;
71 $message = format_text($message, $format, $options);
73 $time = userdate(time(), get_string('strftimedaytime'));
74 $message = '<div class="message me"><span class="author">'.fullname($USER).'</span> '.
75 '<span class="time">['.$time.']</span>: '.
76 '<span class="content">'.$message.'</span></div>';
77 $message = addslashes_js($message); // So Javascript can write it
79 /// Then write it to our own message screen immediately
80 echo "\n<script type=\"text/javascript\">\n<!--\n";
81 echo 'parent.messages.document.write(\''.$message."\\n');\n";
82 echo 'parent.messages.scroll(1,5000000);';
83 echo "\n-->\n</script>\n\n";
85 add_to_log(SITEID
, 'message', 'write', 'history.php?user1='.$user->id
.'&user2='.$USER->id
.'#m'.$messageid, $user->id
);
88 echo '<title></title></head>';
91 echo '<body class="message course-1" id="message-send">';
93 echo '<form id="editing" method="post" action="send.php">';
94 echo '<input type="hidden" name="id" value="'.$user->id
.'" />';
95 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey
.'" />';
97 $usehtmleditor = (can_use_html_editor() && get_user_preferences('message_usehtmleditor', 0));
99 echo '<table align="center"><tr><td align="center">';
100 print_textarea($usehtmleditor, 8, 34, 0, 0, 'message', '');
101 echo '</td></tr></table>';
102 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');
103 echo '<input type="hidden" name="format" value="'.FORMAT_HTML
.'" />';
105 print_textarea(false, 5, 34, 0, 0, 'message', '');
106 echo '<input type="hidden" name="format" value="'.FORMAT_MOODLE
.'" />';
108 echo '<br /><input type="submit" value="'.get_string('sendmessage', 'message').'" />';
110 echo '<div class="noframesjslink"><a target="_parent" href="discussion.php?id='.$userid.'&noframesjs=1">'.get_string('noframesjs', 'message').'</a></div>';
113 echo "\n<script type=\"text/javascript\">\n<!--\n"; /// Focus on the textarea
114 echo 'document.getElementById("edit-message").focus();'."\n";
115 echo "\n-->\n</script>\n\n";
117 echo '</body></html>';