/** * Print the message history between two users * * @param object $user1 the current user * @param object $user2 the other user * @param string $search search terms to highlight * @param int $messagelimit maximum number of messages to return * @param string $messagehistorylink the html for the message history link or false * @param bool $viewingnewmessages are we currently viewing new messages? */ function message_print_message_history($user1, $user2 ,$search = '', $messagelimit = 0, $messagehistorylink = false, $viewingnewmessages = false, $showactionlinks = true) { global $OUTPUT, $PAGE; $PAGE->requires->yui_module( array('moodle-core_message-toolbox'), 'M.core_message.toolbox.deletemsg.init', array(array()) ); echo $OUTPUT->box_start('center', 'message_user_pictures'); echo $OUTPUT->box_start('user'); echo $OUTPUT->box_start('generalbox', 'user1'); echo $OUTPUT->user_picture($user1, array('size' => 100, 'courseid' => SITEID)); echo html_writer::tag('div', fullname($user1), array('class' => 'heading')); echo $OUTPUT->box_end(); echo $OUTPUT->box_end(); $imgattr = array('src' => $OUTPUT->pix_url('i/twoway'), 'alt' => '', 'width' => 16, 'height' => 16); echo $OUTPUT->box(html_writer::empty_tag('img', $imgattr), 'between'); echo $OUTPUT->box_start('user'); echo $OUTPUT->box_start('generalbox', 'user2'); // Show user picture with link is real user else without link. if (core_user::is_real_user($user2->id)) { echo $OUTPUT->user_picture($user2, array('size' => 100, 'courseid' => SITEID)); } else { echo $OUTPUT->user_picture($user2, array('size' => 100, 'courseid' => SITEID, 'link' => false)); } echo html_writer::tag('div', fullname($user2), array('class' => 'heading')); if ($showactionlinks && isset($user2->iscontact) && isset($user2->isblocked)) { $script = null; $text = true; $icon = false; $strcontact = message_get_contact_add_remove_link($user2->iscontact, $user2->isblocked, $user2, $script, $text, $icon); $strblock = message_get_contact_block_link($user2->iscontact, $user2->isblocked, $user2, $script, $text, $icon); $useractionlinks = $strcontact.' | '.$strblock; echo html_writer::tag('div', $useractionlinks, array('class' => 'useractionlinks')); } echo $OUTPUT->box_end(); echo $OUTPUT->box_end(); echo $OUTPUT->box_end(); if (!empty($messagehistorylink)) { echo $messagehistorylink; } /// Get all the messages and print them if ($messages = message_get_history($user1, $user2, $messagelimit, $viewingnewmessages)) { $tablecontents = ''; $current = new stdClass(); $current->mday = ''; $current->month = ''; $current->year = ''; $messagedate = get_string('strftimetime'); $blockdate = get_string('strftimedaydate'); $messagenumber = 0; foreach ($messages as $message) { $messagenumber++; if ($message->notification) { $notificationclass = ' notification'; } else { $notificationclass = null; } $date = usergetdate($message->timecreated); if ($current->mday != $date['mday'] | $current->month != $date['month'] | $current->year != $date['year']) { $current->mday = $date['mday']; $current->month = $date['month']; $current->year = $date['year']; $datestring = html_writer::empty_tag('a', array('name' => $date['year'].$date['mon'].$date['mday'])); $tablecontents .= html_writer::tag('div', $datestring, array('class' => 'mdl-align heading')); $tablecontents .= $OUTPUT->heading(userdate($message->timecreated, $blockdate), 4, 'mdl-align'); } if ($message->useridfrom == $user1->id) { $formatted_message = message_format_message($message, $messagedate, $search, 'me'); $side = 'left'; } else { $formatted_message = message_format_message($message, $messagedate, $search, 'other'); $side = 'right'; } // Check if it is a read message or not. if (isset($message->timeread)) { $type = 'message_read'; } else { $type = 'message'; } if (message_can_delete_message($message, $user1->id)) { $usergroup = optional_param('usergroup', MESSAGE_VIEW_UNREAD_MESSAGES, PARAM_ALPHANUMEXT); $viewing = optional_param('viewing', $usergroup, PARAM_ALPHANUMEXT); $deleteurl = new moodle_url('/message/index.php', array('user1' => $user1->id, 'user2' => $user2->id, 'viewing' => $viewing, 'deletemessageid' => $message->id, 'deletemessagetype' => $type, 'sesskey' => sesskey())); $deleteicon = $OUTPUT->action_icon($deleteurl, new pix_icon('t/delete', get_string('delete'))); $deleteicon = html_writer::tag('div', $deleteicon, array('class' => 'deleteicon accesshide')); $formatted_message .= $deleteicon; } $tablecontents .= html_writer::tag('div', $formatted_message, array('class' => "mdl-left messagecontent $side $notificationclass", 'id' => 'message_' . $messagenumber)); } echo html_writer::nonempty_tag('div', $tablecontents, array('class' => 'mdl-left messagehistory')); } else { echo html_writer::nonempty_tag('div', '('.get_string('nomessagesfound', 'message').')', array('class' => 'mdl-align messagehistory')); } }
/** * Deletes a message * * @param int $messageid the message id * @param int $userid the user id of who we want to delete the message for * @param bool $read if is a message read (default to true) * @return external_description * @throws moodle_exception * @since 3.1 */ public static function delete_message($messageid, $userid, $read = true) { global $CFG, $DB; // Check if private messaging between users is allowed. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } // Warnings array, it can be empty at the end but is mandatory. $warnings = array(); // Validate params. $params = array('messageid' => $messageid, 'userid' => $userid, 'read' => $read); $params = self::validate_parameters(self::delete_message_parameters(), $params); // Validate context. $context = context_system::instance(); self::validate_context($context); $messagestable = $params['read'] ? 'message_read' : 'message'; $message = $DB->get_record($messagestable, array('id' => $params['messageid']), '*', MUST_EXIST); $user = core_user::get_user($params['userid'], '*', MUST_EXIST); core_user::require_active_user($user); $status = false; if (message_can_delete_message($message, $user->id)) { $status = message_delete_message($message, $user->id); } else { throw new moodle_exception('You do not have permission to delete this message'); } $results = array('status' => $status, 'warnings' => $warnings); return $results; }
redirect($CFG->wwwroot . '/message/index.php?viewing=contacts&id='.$addcontact); } if ($removecontact and confirm_sesskey()) { message_remove_contact($removecontact); } if ($blockcontact and confirm_sesskey()) { message_block_contact($blockcontact); } if ($unblockcontact and confirm_sesskey()) { message_unblock_contact($unblockcontact); } if ($deletemessageid and confirm_sesskey()) { // Check that the message actually exists. if ($message = $DB->get_record($deletemessagetype, array('id' => $deletemessageid))) { // Check that we are allowed to delete this message. if (message_can_delete_message($message, $user1->id)) { if (!$deletemessageconfirm) { $confirmurl = new moodle_url('/message/index.php', array('user1' => $user1->id, 'user2' => $user2->id, 'viewing' => $viewing, 'deletemessageid' => $message->id, 'deletemessagetype' => $deletemessagetype, 'deletemessageconfirm' => 1, 'sesskey' => sesskey())); $confirmbutton = new single_button($confirmurl, get_string('delete'), 'post'); $strdeletemessage = get_string('deletemessage', 'message'); $PAGE->set_title($strdeletemessage); echo $OUTPUT->header(); echo $OUTPUT->heading($strdeletemessage); echo $OUTPUT->confirm(get_string('deletemessageconfirmation', 'message'), $confirmbutton, $url); echo $OUTPUT->footer(); exit(); } message_delete_message($message, $user1->id); }