moodle/message/history.php

90 lines
3.3 KiB
PHP
Raw Normal View History

<?php // $Id$
2005-01-01 04:23:09 +00:00
// For listing message histories between any two users
require('../config.php');
2005-01-01 04:23:09 +00:00
require('lib.php');
require_login();
2005-03-17 20:39:30 +00:00
if (isguest()) {
redirect($CFG->wwwroot);
}
if (empty($CFG->messaging)) {
print_error("Messaging is disabled on this site");
}
/// Script parameters
2005-01-01 04:23:09 +00:00
$userid1 = required_param('user1', PARAM_INT);
2008-06-05 13:26:40 +00:00
if (! $user1 = $DB->get_record("user", array("id"=>$userid1))) { // Check it's correct
print_error("User ID 1 was incorrect");
2005-01-01 04:23:09 +00:00
}
if (has_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM))) { // Able to see any discussion
2005-01-01 04:23:09 +00:00
$userid2 = optional_param('user2', $USER->id, PARAM_INT);
2008-06-05 13:26:40 +00:00
if (! $user2 = $DB->get_record("user", array("id"=>$userid2))) { // Check
print_error("User ID 2 was incorrect");
2005-01-01 04:23:09 +00:00
}
} else {
$userid2 = $USER->id; // Can only see messages involving yourself
$user2 = $USER;
}
$search = optional_param('search', '', PARAM_CLEAN);
2005-01-28 17:40:04 +00:00
add_to_log(SITEID, 'message', 'history', 'history.php?user1='.$userid1.'&amp;user2='.$userid2, $userid1);
2005-01-01 04:23:09 +00:00
2005-01-28 17:40:04 +00:00
/// Our two users are defined - let's set up the page
2005-01-01 04:23:09 +00:00
print_header(get_string('messagehistory', 'message'), '', '', '', '<base target="_blank" />');
2005-01-01 04:23:09 +00:00
/// Print out a heading including the users we are looking at
print_simple_box_start('center');
echo '<table align="center" cellpadding="10"><tr>';
echo '<td align="center">';
echo print_user_picture($user1, SITEID, $user1->picture, 100, true, true, 'userwindow').'<br />';
2005-01-01 04:23:09 +00:00
echo fullname($user1);
echo '</td>';
echo '<td align="center">';
echo '<img src="'.$CFG->wwwroot.'/pix/t/left.gif" alt="'.get_string('from').'" />';
echo '<img src="'.$CFG->wwwroot.'/pix/t/right.gif" alt="'.get_string('to').'" />';
2005-01-01 04:23:09 +00:00
echo '</td>';
echo '<td align="center">';
echo print_user_picture($user2, SITEID, $user2->picture, 100, true, true, 'userwindow').'<br />';
2005-01-01 04:23:09 +00:00
echo fullname($user2);
echo '</td>';
echo '</tr></table>';
print_simple_box_end();
/// Get all the messages and print them
if ($messages = message_get_history($user1, $user2)) {
$current->mday = '';
2005-01-01 04:23:09 +00:00
$current->month = '';
$current->year = '';
$messagedate = get_string('strftimetime');
$blockdate = get_string('strftimedaydate');
foreach ($messages as $message) {
$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'];
2005-01-01 11:47:18 +00:00
echo '<a name="'.$date['year'].$date['mon'].$date['mday'].'"></a>';
2005-01-01 04:23:09 +00:00
print_heading(userdate($message->timecreated, $blockdate), 'center', 4);
}
if ($message->useridfrom == $user1->id) {
echo message_format_message($message, $user1, $messagedate, $search, 'other');
2005-01-01 04:23:09 +00:00
} else {
echo message_format_message($message, $user2, $messagedate, $search, 'me');
2005-01-01 04:23:09 +00:00
}
}
} else {
print_heading(get_string('nomessagesfound', 'message'));
}
print_footer('none');
2005-01-01 04:23:09 +00:00
?>