wwwroot);
}
if (empty($CFG->messaging)) {
print_error('disabled', 'message');
}
if (has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTEM))) {
// if ($USER->
/// Don't use print_header, for more speed
$stylesheetshtml = '';
foreach ($CFG->stylesheets as $stylesheet) {
$stylesheetshtml .= '';
}
/// Select direction
if ( get_string('thisdirection') == 'rtl' ) {
$direction = ' dir="rtl"';
} else {
$direction = ' dir="ltr"';
}
@header('Content-Type: text/html; charset=utf-8');
echo ''."\n";
echo "\n
\n";
echo '';
echo $stylesheetshtml;
include($CFG->javascript);
require_once($CFG->libdir .'/editor/htmlEditor.class.php');
$htmlEditorObject = new htmlEditor();
echo $htmlEditorObject->configure();
echo '';
/// 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
if (! $user = $DB->get_record('user', array('id'=>$userid))) {
print_error('invaliduserid');
}
/// Check that the user is not blocking us!!
if ($contact = $DB->get_record('message_contacts', array('userid'=>$user->id, 'contactid'=>$USER->id))) {
if ($contact->blocked and !has_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM))) {
print_heading(get_string('userisblockingyou', 'message'));
exit;
}
}
$userpreferences = get_user_preferences(NULL, NULL, $user->id);
if (!empty($userpreferences['message_blocknoncontacts'])) { // User is blocking non-contacts
if (empty($contact)) { // We are not a contact!
print_heading(get_string('userisblockingyounoncontact', 'message'));
exit;
}
}
echo '';
if ($message!='' and confirm_sesskey()) { /// Current user has just sent a message
/// Save it to the database...
$messageid = message_post_message($USER, $user, $message, $format, 'direct');
/// Format the message as HTML
$options = NULL;
$options->para = false;
$options->newlines = true;
$message = format_text($message, $format, $options);
$time = userdate(time(), get_string('strftimedatetimeshort'));
$message = '
';
$message = addslashes_js($message); // So Javascript can write it
/// Then write it to our own message screen immediately
echo "\n\n\n";
add_to_log(SITEID, 'message', 'write', 'history.php?user1='.$user->id.'&user2='.$USER->id.'#m'.$messageid, $user->id);
}
echo '';
if (!empty($CFG->messagewasjustemailed)) {
notify(get_string('mailsent', 'message'), 'notifysuccess');
}
echo '