MDL-12296:
[moodle-linuxchix.git] / message / send.php
blobc8d085a5331b464f3f9179489c868729c2598dcb
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 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.'" />';
25 /// Select direction
26 if ( get_string('thisdirection') == 'rtl' ) {
27 $direction = ' dir="rtl"';
28 } else {
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;
38 /// Script parameters
39 $userid = required_param('id', PARAM_INT);
40 $message = optional_param('message', '', PARAM_CLEANHTML);
41 $format = optional_param('format', FORMAT_MOODLE, PARAM_INT);
43 /// Check the user we are talking to is valid
44 if (! $user = get_record('user', 'id', $userid)) {
45 error("User ID was incorrect");
48 /// Check that the user is not blocking us!!
49 if ($contact = get_record('message_contacts', 'userid', $user->id, 'contactid', $USER->id)) {
50 if ($contact->blocked and !has_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
51 print_heading(get_string('userisblockingyou', 'message'));
52 exit;
55 $userpreferences = get_user_preferences(NULL, NULL, $user->id);
57 if (!empty($userpreferences['message_blocknoncontacts'])) { // User is blocking non-contacts
58 if (empty($contact)) { // We are not a contact!
59 print_heading(get_string('userisblockingyounoncontact', 'message'));
60 exit;
65 if ($message!='' and confirm_sesskey()) { /// Current user has just sent a message
67 /// Save it to the database...
68 $messageid = message_post_message($USER, $user, addslashes($message), $format, 'direct');
70 /// Format the message as HTML
71 $options = NULL;
72 $options->para = false;
73 $options->newlines = true;
74 $message = format_text($message, $format, $options);
76 $time = userdate(time(), get_string('strftimedaytime'));
77 $message = '<div class="message me"><span class="author">'.fullname($USER).'</span> '.
78 '<span class="time">['.$time.']</span>: '.
79 '<span class="content">'.$message.'</span></div>';
80 $message = addslashes_js($message); // So Javascript can write it
82 /// Then write it to our own message screen immediately
83 echo "\n<script type=\"text/javascript\">\n<!--\n";
84 echo 'parent.messages.document.write(\''.$message."\\n');\n";
85 echo 'parent.messages.scroll(1,5000000);';
86 echo "\n-->\n</script>\n\n";
88 add_to_log(SITEID, 'message', 'write', 'history.php?user1='.$user->id.'&amp;user2='.$USER->id.'#m'.$messageid, $user->id);
91 echo '<title> </title></head>';
94 echo '<body class="message course-1" id="message-send">';
95 echo '<center>';
96 echo '<form id="editing" method="post" action="send.php">';
97 echo '<div>';
98 echo '<input type="hidden" name="id" value="'.$user->id.'" />';
99 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
101 $usehtmleditor = (can_use_html_editor() && get_user_preferences('message_usehtmleditor', 0));
102 if ($usehtmleditor) {
103 echo '<table><tr><td class="fixeditor" align="center">';
104 print_textarea($usehtmleditor, 9, 200, 0, 0, 'message', '');
105 echo '</td></tr></table>';
106 echo '<input type="submit" value="'.get_string('sendmessage', 'message').'" />';
107 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');
108 echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
109 } else {
110 print_textarea(false, 5, 34, 0, 0, 'message', '');
111 echo '<input type="hidden" name="format" value="'.FORMAT_MOODLE.'" />';
112 echo '<br /><input type="submit" value="'.get_string('sendmessage', 'message').'" />';
114 echo '</div>';
115 echo '</form>';
116 if (!empty($CFG->messagewasjustemailed)) {
117 notify(get_string('mailsent', 'message'), 'notifysuccess');
119 echo '<div class="noframesjslink"><a target="_parent" href="discussion.php?id='.$userid.'&amp;noframesjs=1">'.get_string('noframesjs', 'message').'</a></div>';
120 echo '</center>';
122 echo "\n<script type=\"text/javascript\">\n<!--\n"; /// Focus on the textarea
123 echo 'document.getElementById("edit-message").focus();'."\n";
124 echo "\n-->\n</script>\n\n";
126 echo '</body></html>';