MDL-11071 Added disabledif logic to groupings/groups common dialogue
[moodle-pu.git] / message / send.php
blob522a5901a49bb20bdce9b3924aae41ed7fe07055
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 $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'));
57 exit;
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
68 $options = NULL;
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.'&amp;user2='.$USER->id.'#m'.$messageid, $user->id);
88 echo '<title> </title></head>';
91 echo '<body class="message course-1" id="message-send">';
92 echo '<center>';
93 echo '<form id="editing" method="post" action="send.php">';
94 echo '<div>';
95 echo '<input type="hidden" name="id" value="'.$user->id.'" />';
96 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
98 $usehtmleditor = (can_use_html_editor() && get_user_preferences('message_usehtmleditor', 0));
99 if ($usehtmleditor) {
100 echo '<table align="center"><tr><td align="center">';
101 print_textarea($usehtmleditor, 7, 34, 0, 0, 'message', '');
102 echo '</td></tr></table>';
103 echo '<input type="submit" value="'.get_string('sendmessage', 'message').'" />';
104 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');
105 echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
106 } else {
107 print_textarea(false, 5, 34, 0, 0, 'message', '');
108 echo '<input type="hidden" name="format" value="'.FORMAT_MOODLE.'" />';
109 echo '<br /><input type="submit" value="'.get_string('sendmessage', 'message').'" />';
111 echo '</div>';
112 echo '</form>';
113 if (!empty($CFG->messagewasjustemailed)) {
114 notify(get_string('mailsent', 'message'), 'notifysuccess');
116 echo '<div class="noframesjslink"><a target="_parent" href="discussion.php?id='.$userid.'&amp;noframesjs=1">'.get_string('noframesjs', 'message').'</a></div>';
117 echo '</center>';
119 echo "\n<script type=\"text/javascript\">\n<!--\n"; /// Focus on the textarea
120 echo 'document.getElementById("edit-message").focus();'."\n";
121 echo "\n-->\n</script>\n\n";
123 echo '</body></html>';