Use $this->error for only error report
[moodle-linuxchix.git] / message / send.php
blob989925d13b54a5a47f2b1d3903848d7ee90c7b8b
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 /// 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.'" />';
22 /// Select direction
23 if ( get_string('thisdirection') == 'rtl' ) {
24 $direction = ' dir="rtl"';
25 } else {
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;
35 /// Script parameters
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'));
49 exit;
52 if (get_user_preferences('message_blocknoncontacts', 0, $user->id)) { // User is blocking non-contacts
53 if (empty($contact)) { // We are not a contact!
54 print_heading(get_string('userisblockingyounoncontact', 'message'));
55 exit;
59 if ($message!='' and confirm_sesskey()) { /// Current user has just sent a message
61 /// Save it to the database...
62 $messageid = message_post_message($USER, $user, addslashes($message), $format, 'direct');
64 /// Format the message as HTML
65 $options = NULL;
66 $options->para = false;
67 $options->newlines = true;
68 $message = format_text($message, $format, $options);
70 $time = userdate(time(), get_string('strftimedaytime'));
71 $message = '<div class="message me"><span class="author">'.fullname($USER).'</span> '.
72 '<span class="time">['.$time.']</span>: '.
73 '<span class="content">'.$message.'</span></div>';
74 $message = addslashes_js($message); // So Javascript can write it
76 /// Then write it to our own message screen immediately
77 echo "\n<script type=\"text/javascript\">\n<!--\n";
78 echo 'parent.messages.document.write(\''.$message."\\n');\n";
79 echo 'parent.messages.scroll(1,5000000);';
80 echo "\n-->\n</script>\n\n";
82 add_to_log(SITEID, 'message', 'write', 'history.php?user1='.$user->id.'&amp;user2='.$USER->id.'#m'.$messageid, $user->id);
85 echo '<title></title></head>';
88 echo '<body class="message course-1" id="message-send">';
89 echo '<center>';
90 echo '<form id="editing" method="post" action="send.php">';
91 echo '<input type="hidden" name="id" value="'.$user->id.'" />';
92 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
94 $usehtmleditor = (can_use_html_editor() && get_user_preferences('message_usehtmleditor', 0));
95 if ($usehtmleditor) {
96 echo '<table align="center"><tr><td align="center">';
97 print_textarea($usehtmleditor, 8, 34, 0, 0, 'message', '');
98 echo '</td></tr></table>';
99 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');
100 echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
101 } else {
102 print_textarea(false, 5, 34, 0, 0, 'message', '');
103 echo '<input type="hidden" name="format" value="'.FORMAT_MOODLE.'" />';
105 echo '<br /><input type="submit" value="'.get_string('sendmessage', 'message').'" />';
106 echo '</form>';
107 echo '<div class="noframesjslink"><a target="_parent" href="discussion.php?id='.$userid.'&amp;noframesjs=1">'.get_string('noframesjs', 'message').'</a></div>';
108 echo '</center>';
110 echo "\n<script type=\"text/javascript\">\n<!--\n"; /// Focus on the textarea
111 echo 'document.getElementById("edit-message").focus();'."\n";
112 echo "\n-->\n</script>\n\n";
114 echo '</body></html>';