示例#1
0
    $user = get_record('usr', 'id', $id);
    if (!$user) {
        throw new UserNotFoundException(get_string('cantmessageuser', 'group'));
    } else {
        if ($user->deleted != 0) {
            throw new AccessDeniedException(get_string('cantmessageuserdeleted', 'group'));
        } else {
            if (!can_send_message($USER->to_stdclass(), $id)) {
                throw new AccessDeniedException(get_string('cantmessageuser', 'group'));
            }
        }
    }
    $users[] = $id;
}
if (!is_null($oldreplytoid)) {
    $message = get_message_thread($oldreplytoid);
    if (null === $message) {
        throw new AccessDeniedException(get_string('cantviewmessage', 'group'));
    }
    if ($message[0]->usr != $USER->id) {
        throw new AccessDeniedException(get_string('cantviewmessage', 'group'));
    }
    $subject = $message[0]->subject;
    $prefix = trim(get_string('replysubjectprefix', 'module.multirecipientnotification'));
    if (strpos($subject, $prefix) !== 0) {
        $subject = $prefix . ' ' . $subject;
    }
}
if (!is_null($replytoid)) {
    // Let us validate what we are going to reply first. The message should exist,
    // addressed to us and originated from the user we are replying to.
/**
 * Get the thread of message up to this point, given the id of
 * the message being replied to.
 */
function get_message_thread($replyto)
{
    $message = get_record('notification_internal_activity', 'id', $replyto);
    if (empty($message->parent)) {
        return array($message);
    }
    return array_merge(get_message_thread($message->parent), array($message));
}
示例#3
0
require dirname(dirname(__FILE__)) . '/init.php';
require_once 'pieforms/pieform.php';
require_once 'searchlib.php';
safe_require('search', 'internal');
$id = param_integer('id');
$replytoid = param_integer('replyto', null);
$messages = null;
if (!is_null($replytoid)) {
    // Let us validate what we are going to reply first. The message should exist,
    // addressed to us and originated from user we are replying to.
    $message = get_record('notification_internal_activity', 'id', $replytoid, 'usr', $USER->get('id'), 'from', $id);
    if (!$message) {
        throw new AccessDeniedException(get_string('cantviewmessage', 'group'));
    }
    // OK, now it safe to fetch the whole thread.
    $messages = get_message_thread($replytoid);
}
$user = get_record('usr', 'id', $id);
if (!$user) {
    throw new UserNotFoundException(get_string('cantmessageuser', 'group'));
} else {
    if ($user->deleted != 0) {
        throw new AccessDeniedException(get_string('cantmessageuserdeleted', 'group'));
    } else {
        if (!can_send_message($USER->to_stdclass(), $id)) {
            throw new AccessDeniedException(get_string('cantmessageuser', 'group'));
        }
    }
}
define('TITLE', get_string('sendmessageto', 'group', display_name($user)));
$returnto = param_alpha('returnto', 'myfriends');