2005-04-14 09:28:07 +00:00
|
|
|
<?php // $Id$
|
2006-12-25 22:34:05 +00:00
|
|
|
|
2007-11-21 07:53:42 +00:00
|
|
|
require('../config.php');
|
|
|
|
require('lib.php');
|
2005-04-14 09:28:07 +00:00
|
|
|
|
2007-11-21 07:53:42 +00:00
|
|
|
require_login();
|
2005-04-14 09:28:07 +00:00
|
|
|
|
2007-11-21 07:53:42 +00:00
|
|
|
if (isguest()) {
|
|
|
|
redirect($CFG->wwwroot);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($CFG->messaging)) {
|
2008-06-13 06:55:25 +00:00
|
|
|
print_error('disabled', 'message');
|
2007-11-21 07:53:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTEM))) {
|
2005-04-14 09:28:07 +00:00
|
|
|
|
2008-06-11 08:43:14 +00:00
|
|
|
// if ($USER->
|
2005-04-14 09:28:07 +00:00
|
|
|
|
|
|
|
/// Don't use print_header, for more speed
|
|
|
|
$stylesheetshtml = '';
|
|
|
|
foreach ($CFG->stylesheets as $stylesheet) {
|
|
|
|
$stylesheetshtml .= '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'" />';
|
|
|
|
}
|
|
|
|
|
2005-11-05 10:50:35 +00:00
|
|
|
/// Select direction
|
|
|
|
if ( get_string('thisdirection') == 'rtl' ) {
|
|
|
|
$direction = ' dir="rtl"';
|
|
|
|
} else {
|
|
|
|
$direction = ' dir="ltr"';
|
|
|
|
}
|
|
|
|
|
2006-11-11 17:23:20 +00:00
|
|
|
@header('Content-Type: text/html; charset=utf-8');
|
2006-12-18 09:04:33 +00:00
|
|
|
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
|
|
|
|
echo "<html $direction xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n";
|
2006-11-11 17:23:20 +00:00
|
|
|
echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />';
|
2005-04-14 09:28:07 +00:00
|
|
|
echo $stylesheetshtml;
|
2008-06-11 08:43:14 +00:00
|
|
|
|
2008-05-01 05:18:14 +00:00
|
|
|
include($CFG->javascript);
|
2005-04-14 09:28:07 +00:00
|
|
|
|
2008-06-11 08:43:14 +00:00
|
|
|
require_once($CFG->libdir .'/editor/htmlEditor.class.php');
|
|
|
|
$htmlEditorObject = new htmlEditor();
|
|
|
|
echo $htmlEditorObject->configure();
|
|
|
|
|
|
|
|
echo '<title> </title></head>';
|
|
|
|
|
2005-04-14 09:28:07 +00:00
|
|
|
/// Script parameters
|
|
|
|
$userid = required_param('id', PARAM_INT);
|
|
|
|
$message = optional_param('message', '', PARAM_CLEANHTML);
|
|
|
|
$format = optional_param('format', FORMAT_MOODLE, PARAM_INT);
|
|
|
|
|
|
|
|
/// Check the user we are talking to is valid
|
2008-06-05 13:26:40 +00:00
|
|
|
if (! $user = $DB->get_record('user', array('id'=>$userid))) {
|
2008-06-13 06:55:25 +00:00
|
|
|
print_error('invaliduserid');
|
2005-04-14 09:28:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Check that the user is not blocking us!!
|
2008-06-05 13:26:40 +00:00
|
|
|
if ($contact = $DB->get_record('message_contacts', array('userid'=>$user->id, 'contactid'=>$USER->id))) {
|
2008-05-02 04:37:02 +00:00
|
|
|
if ($contact->blocked and !has_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM))) {
|
2005-04-14 09:28:07 +00:00
|
|
|
print_heading(get_string('userisblockingyou', 'message'));
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
2007-08-06 15:11:06 +00:00
|
|
|
$userpreferences = get_user_preferences(NULL, NULL, $user->id);
|
|
|
|
|
|
|
|
if (!empty($userpreferences['message_blocknoncontacts'])) { // User is blocking non-contacts
|
2005-04-23 06:26:10 +00:00
|
|
|
if (empty($contact)) { // We are not a contact!
|
|
|
|
print_heading(get_string('userisblockingyounoncontact', 'message'));
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
2005-04-14 09:28:07 +00:00
|
|
|
|
2008-06-11 08:43:14 +00:00
|
|
|
echo '<body class="message course-1" id="message-send">';
|
2007-08-06 15:11:06 +00:00
|
|
|
|
2006-12-25 22:34:05 +00:00
|
|
|
if ($message!='' and confirm_sesskey()) { /// Current user has just sent a message
|
2005-04-14 09:28:07 +00:00
|
|
|
|
|
|
|
/// Save it to the database...
|
2008-06-09 16:53:30 +00:00
|
|
|
$messageid = message_post_message($USER, $user, $message, $format, 'direct');
|
2005-04-14 09:28:07 +00:00
|
|
|
|
|
|
|
/// Format the message as HTML
|
|
|
|
$options = NULL;
|
|
|
|
$options->para = false;
|
|
|
|
$options->newlines = true;
|
2007-01-01 13:26:20 +00:00
|
|
|
$message = format_text($message, $format, $options);
|
2005-04-14 09:28:07 +00:00
|
|
|
|
2008-05-08 03:49:51 +00:00
|
|
|
$time = userdate(time(), get_string('strftimedatetimeshort'));
|
2005-05-04 08:22:46 +00:00
|
|
|
$message = '<div class="message me"><span class="author">'.fullname($USER).'</span> '.
|
2005-04-14 09:28:07 +00:00
|
|
|
'<span class="time">['.$time.']</span>: '.
|
|
|
|
'<span class="content">'.$message.'</span></div>';
|
2007-01-01 13:26:20 +00:00
|
|
|
$message = addslashes_js($message); // So Javascript can write it
|
2005-04-14 09:28:07 +00:00
|
|
|
|
|
|
|
/// Then write it to our own message screen immediately
|
|
|
|
echo "\n<script type=\"text/javascript\">\n<!--\n";
|
|
|
|
echo 'parent.messages.document.write(\''.$message."\\n');\n";
|
|
|
|
echo 'parent.messages.scroll(1,5000000);';
|
|
|
|
echo "\n-->\n</script>\n\n";
|
|
|
|
|
|
|
|
add_to_log(SITEID, 'message', 'write', 'history.php?user1='.$user->id.'&user2='.$USER->id.'#m'.$messageid, $user->id);
|
|
|
|
}
|
|
|
|
|
2007-01-04 21:32:36 +00:00
|
|
|
echo '<form id="editing" method="post" action="send.php">';
|
2008-06-11 08:43:14 +00:00
|
|
|
echo '<div class="message-form">';
|
2005-04-14 09:28:07 +00:00
|
|
|
echo '<input type="hidden" name="id" value="'.$user->id.'" />';
|
|
|
|
echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
|
|
|
|
|
|
|
|
$usehtmleditor = (can_use_html_editor() && get_user_preferences('message_usehtmleditor', 0));
|
|
|
|
if ($usehtmleditor) {
|
2008-06-11 08:43:14 +00:00
|
|
|
echo '<div class="message-send-box">';
|
|
|
|
print_textarea($usehtmleditor, 5, 34, 0, 0, 'message', '', 0, false, '', 'form-textarea-simple');
|
|
|
|
echo '</div>';
|
|
|
|
echo '<input class="message-send-button" type="submit" value="'.get_string('sendmessage', 'message').'" />';
|
|
|
|
//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');
|
2005-04-14 09:28:07 +00:00
|
|
|
echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
|
|
|
|
} else {
|
|
|
|
print_textarea(false, 5, 34, 0, 0, 'message', '');
|
|
|
|
echo '<input type="hidden" name="format" value="'.FORMAT_MOODLE.'" />';
|
2008-06-11 08:43:14 +00:00
|
|
|
echo '<br /><input class="message-send-button" type="submit" value="'.get_string('sendmessage', 'message').'" />';
|
2005-04-14 09:28:07 +00:00
|
|
|
}
|
2007-08-27 03:22:16 +00:00
|
|
|
echo '</div>';
|
2005-04-14 09:28:07 +00:00
|
|
|
echo '</form>';
|
2007-08-27 03:22:16 +00:00
|
|
|
if (!empty($CFG->messagewasjustemailed)) {
|
|
|
|
notify(get_string('mailsent', 'message'), 'notifysuccess');
|
|
|
|
}
|
2006-12-25 22:34:05 +00:00
|
|
|
echo '<div class="noframesjslink"><a target="_parent" href="discussion.php?id='.$userid.'&noframesjs=1">'.get_string('noframesjs', 'message').'</a></div>';
|
|
|
|
|
2008-06-18 09:17:09 +00:00
|
|
|
echo "<script type=\"text/javascript\">".
|
|
|
|
"\n//<![CDATA[".
|
|
|
|
"\ndocument.getElementById(\"edit-message\").focus();".
|
|
|
|
"\n//]]>".
|
|
|
|
"\n</script>";
|
2005-04-23 16:43:49 +00:00
|
|
|
|
2005-04-14 09:28:07 +00:00
|
|
|
echo '</body></html>';
|
2007-11-21 07:53:42 +00:00
|
|
|
}
|
2005-04-14 09:28:07 +00:00
|
|
|
?>
|