2004-09-12 15:06:29 +00:00
|
|
|
<?php // $Id$
|
2003-07-21 03:16:19 +00:00
|
|
|
|
|
|
|
/// This page prints reports and info about chats
|
|
|
|
|
2005-02-03 20:39:27 +00:00
|
|
|
require_once('../../config.php');
|
|
|
|
require_once('lib.php');
|
|
|
|
|
|
|
|
$id = required_param('id', PARAM_INT);
|
|
|
|
$start = optional_param('start', 0, PARAM_INT); // Start of period
|
|
|
|
$end = optional_param('end', 0, PARAM_INT); // End of period
|
|
|
|
$deletesession = optional_param('deletesession', 0, PARAM_BOOL);
|
|
|
|
$confirmdelete = optional_param('confirmdelete', 0, PARAM_BOOL);
|
|
|
|
|
2006-08-08 22:09:55 +00:00
|
|
|
if (! $cm = get_coursemodule_from_id('chat', $id)) {
|
2008-06-06 08:46:48 +00:00
|
|
|
print_error('invalidcoursemodule');
|
2004-02-24 06:35:57 +00:00
|
|
|
}
|
2008-06-08 15:49:36 +00:00
|
|
|
if (! $chat = $DB->get_record('chat', array('id'=>$cm->instance))) {
|
2008-06-06 08:46:48 +00:00
|
|
|
print_error('invalidcoursemodule');
|
2003-07-21 03:16:19 +00:00
|
|
|
}
|
2008-06-08 15:49:36 +00:00
|
|
|
if (! $course = $DB->get_record('course', array('id'=>$chat->course))) {
|
2008-06-06 08:46:48 +00:00
|
|
|
print_error('coursemisconf');
|
2003-07-21 03:16:19 +00:00
|
|
|
}
|
|
|
|
|
2006-08-09 13:45:49 +00:00
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
2005-02-16 10:40:48 +00:00
|
|
|
require_login($course->id, false, $cm);
|
2003-07-21 03:16:19 +00:00
|
|
|
|
2008-06-18 01:45:01 +00:00
|
|
|
require_capability('mod/chat:readlog', $context);
|
2003-07-21 03:16:19 +00:00
|
|
|
|
2005-02-03 20:39:27 +00:00
|
|
|
add_to_log($course->id, 'chat', 'report', "report.php?id=$cm->id", $chat->id, $cm->id);
|
2003-07-21 03:16:19 +00:00
|
|
|
|
2005-02-03 20:39:27 +00:00
|
|
|
$strchats = get_string('modulenameplural', 'chat');
|
|
|
|
$strchat = get_string('modulename', 'chat');
|
|
|
|
$strchatreport = get_string('chatreport', 'chat');
|
|
|
|
$strseesession = get_string('seesession', 'chat');
|
|
|
|
$strdeletesession = get_string('deletesession', 'chat');
|
2004-01-16 13:14:42 +00:00
|
|
|
|
2007-07-05 04:55:24 +00:00
|
|
|
$navlinks = array();
|
2008-06-18 01:45:01 +00:00
|
|
|
|
2004-10-19 10:34:02 +00:00
|
|
|
/// Print a session if one has been specified
|
2003-07-21 04:08:32 +00:00
|
|
|
|
2004-01-16 13:14:42 +00:00
|
|
|
if ($start and $end and !$confirmdelete) { // Show a full transcript
|
2007-10-12 15:55:49 +00:00
|
|
|
$navigation = build_navigation($strchatreport, $cm);
|
2007-04-16 20:59:17 +00:00
|
|
|
print_header_simple(format_string($chat->name).": $strchatreport", '', $navigation,
|
2005-02-03 20:39:27 +00:00
|
|
|
'', '', true, '', navmenu($course, $cm));
|
|
|
|
|
|
|
|
/// Check to see if groups are being used here
|
2007-08-27 02:28:35 +00:00
|
|
|
$groupmode = groups_get_activity_groupmode($cm);
|
|
|
|
$currentgroup = groups_get_activity_group($cm, true);
|
|
|
|
groups_print_activity_menu($cm, "report.php?id=$cm->id");
|
|
|
|
|
2008-06-08 15:49:36 +00:00
|
|
|
$params = array('currentgroup'=>$currentgroup, 'chatid'=>$chat->id, 'start'=>$start, 'end'=>$end);
|
2005-02-03 20:39:27 +00:00
|
|
|
|
2008-08-27 02:21:11 +00:00
|
|
|
// If the user is allocated to a group, only show messages from people
|
|
|
|
// in the same group, or no group
|
2007-07-05 04:40:48 +00:00
|
|
|
if ($currentgroup) {
|
2008-08-27 02:21:11 +00:00
|
|
|
$groupselect = " AND (groupid = :currentgroup OR groupid = 0)";
|
2004-02-24 07:21:52 +00:00
|
|
|
} else {
|
|
|
|
$groupselect = "";
|
|
|
|
}
|
|
|
|
|
2006-08-14 05:55:40 +00:00
|
|
|
if ($deletesession and has_capability('mod/chat:deletelog', $context)) {
|
2005-02-03 20:39:27 +00:00
|
|
|
notice_yesno(get_string('deletesessionsure', 'chat'),
|
2009-01-02 10:51:26 +00:00
|
|
|
"report.php?id=$cm->id&deletesession=1&confirmdelete=1&start=$start&end=$end&sesskey=".sesskey(),
|
2004-02-24 06:35:57 +00:00
|
|
|
"report.php?id=$cm->id");
|
2004-01-16 13:14:42 +00:00
|
|
|
}
|
|
|
|
|
2008-06-18 01:45:01 +00:00
|
|
|
if (!$messages = $DB->get_records_select('chat_messages', "chatid = :chatid AND timestamp >= :start AND timestamp <= :end $groupselect", $params, "timestamp ASC")) {
|
2009-08-06 08:21:01 +00:00
|
|
|
echo $OUTPUT->heading(get_string('nomessages', 'chat'));
|
2003-07-21 04:08:32 +00:00
|
|
|
|
|
|
|
} else {
|
2007-01-09 04:50:07 +00:00
|
|
|
echo '<p class="boxaligncenter">'.userdate($start).' --> '. userdate($end).'</p>';
|
2003-07-21 04:08:32 +00:00
|
|
|
|
2005-02-03 20:39:27 +00:00
|
|
|
print_simple_box_start('center');
|
2003-07-21 04:08:32 +00:00
|
|
|
foreach ($messages as $message) { // We are walking FORWARDS through messages
|
2005-02-03 20:39:27 +00:00
|
|
|
$formatmessage = chat_format_message($message, $course->id, $USER);
|
2006-04-18 07:14:21 +00:00
|
|
|
if (isset($formatmessage->html)) {
|
|
|
|
echo $formatmessage->html;
|
|
|
|
}
|
2003-07-21 04:08:32 +00:00
|
|
|
}
|
2008-08-18 10:16:56 +00:00
|
|
|
if (has_capability('mod/chat:exportsession', $context)
|
|
|
|
|| (array_key_exists($USER->id, $sessionusers)
|
|
|
|
&& has_capability('mod/chat:exportparticipatedsession', $context))) {
|
|
|
|
require_once($CFG->libdir . '/portfoliolib.php');
|
2008-09-11 13:42:58 +00:00
|
|
|
$buttonoptions = array(
|
2008-08-18 10:16:56 +00:00
|
|
|
'id' => $cm->id,
|
|
|
|
'start' => $start,
|
|
|
|
'end' => $end,
|
|
|
|
);
|
2008-09-11 13:42:58 +00:00
|
|
|
$button = new portfolio_add_button();
|
|
|
|
$button->set_callback_options('chat_portfolio_caller', $buttonoptions, '/mod/chat/lib.php');
|
|
|
|
$button->render();
|
2008-08-18 10:16:56 +00:00
|
|
|
}
|
2006-10-31 21:07:00 +00:00
|
|
|
print_simple_box_end();
|
2003-07-21 04:08:32 +00:00
|
|
|
}
|
|
|
|
|
2006-08-14 05:55:40 +00:00
|
|
|
if (!$deletesession or !has_capability('mod/chat:deletelog', $context)) {
|
2004-02-24 06:35:57 +00:00
|
|
|
print_continue("report.php?id=$cm->id");
|
2004-01-16 13:14:42 +00:00
|
|
|
}
|
|
|
|
|
2003-07-21 04:08:32 +00:00
|
|
|
print_footer($course);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Print the Sessions display
|
2007-10-12 15:55:49 +00:00
|
|
|
$navigation = build_navigation($strchatreport, $cm);
|
2007-04-16 20:59:17 +00:00
|
|
|
print_header_simple(format_string($chat->name).": $strchatreport", '', $navigation,
|
2005-02-03 20:39:27 +00:00
|
|
|
'', '', true, '', navmenu($course, $cm));
|
2003-07-21 03:16:19 +00:00
|
|
|
|
2009-08-06 08:21:01 +00:00
|
|
|
echo $OUTPUT->heading(format_string($chat->name).': '.get_string('sessions', 'chat'));
|
2004-02-24 07:00:13 +00:00
|
|
|
|
2003-07-21 03:16:19 +00:00
|
|
|
|
2004-02-24 06:35:57 +00:00
|
|
|
/// Check to see if groups are being used here
|
2007-08-27 02:28:35 +00:00
|
|
|
if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used
|
|
|
|
$currentgroup = groups_get_activity_group($cm, true);
|
|
|
|
groups_print_activity_menu($cm, "report.php?id=$cm->id");
|
2004-02-24 06:35:57 +00:00
|
|
|
} else {
|
|
|
|
$currentgroup = false;
|
|
|
|
}
|
|
|
|
|
2008-06-08 15:49:36 +00:00
|
|
|
$params = array('currentgroup'=>$currentgroup, 'chatid'=>$chat->id, 'start'=>$start, 'end'=>$end);
|
|
|
|
|
2008-08-27 02:21:11 +00:00
|
|
|
// If the user is allocated to a group, only show discussions with people in
|
|
|
|
// the same group, or no group
|
2004-11-23 02:05:47 +00:00
|
|
|
if (!empty($currentgroup)) {
|
2008-08-27 02:21:11 +00:00
|
|
|
$groupselect = " AND (groupid = :currentgroup OR groupid = 0)";
|
2004-02-24 06:35:57 +00:00
|
|
|
} else {
|
|
|
|
$groupselect = "";
|
|
|
|
}
|
2003-07-21 03:16:19 +00:00
|
|
|
|
2004-01-16 13:14:42 +00:00
|
|
|
/// Delete a session if one has been specified
|
|
|
|
|
2006-08-14 05:55:40 +00:00
|
|
|
if ($deletesession and has_capability('mod/chat:deletelog', $context) and $confirmdelete and $start and $end and confirm_sesskey()) {
|
2008-06-08 15:49:36 +00:00
|
|
|
$DB->delete_records_select('chat_messages', "chatid = :chatid AND timestamp >= :start AND
|
|
|
|
timestamp <= :end $groupselect", $params);
|
2005-02-03 20:39:27 +00:00
|
|
|
$strdeleted = get_string('deleted');
|
|
|
|
notify("$strdeleted: ".userdate($start).' --> '. userdate($end));
|
2004-01-16 13:14:42 +00:00
|
|
|
unset($deletesession);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Get the messages
|
|
|
|
|
|
|
|
if (empty($messages)) { /// May have already got them above
|
2008-06-08 15:49:36 +00:00
|
|
|
if (!$messages = $DB->get_records_select('chat_messages', "chatid = :chatid $groupselect", $params, "timestamp DESC")) {
|
2009-08-06 08:21:01 +00:00
|
|
|
echo $OUTPUT->heading(get_string('nomessages', 'chat'));
|
2004-01-16 13:14:42 +00:00
|
|
|
print_footer($course);
|
|
|
|
exit;
|
|
|
|
}
|
2003-07-21 03:16:19 +00:00
|
|
|
}
|
|
|
|
|
2004-01-16 13:14:42 +00:00
|
|
|
/// Show all the sessions
|
2003-07-21 04:08:32 +00:00
|
|
|
|
|
|
|
$sessiongap = 5 * 60; // 5 minutes silence means a new session
|
2003-07-21 03:37:53 +00:00
|
|
|
$sessionend = 0;
|
|
|
|
$sessionstart = 0;
|
2003-07-21 03:16:19 +00:00
|
|
|
$sessionusers = array();
|
2003-07-21 03:37:53 +00:00
|
|
|
$lasttime = 0;
|
2003-07-21 03:16:19 +00:00
|
|
|
|
2004-12-08 13:47:06 +00:00
|
|
|
$messagesleft = count($messages);
|
|
|
|
|
2003-07-21 04:08:32 +00:00
|
|
|
foreach ($messages as $message) { // We are walking BACKWARDS through the messages
|
2004-12-08 13:47:06 +00:00
|
|
|
|
|
|
|
$messagesleft --; // Countdown
|
|
|
|
|
2003-07-21 03:37:53 +00:00
|
|
|
if (!$lasttime) {
|
|
|
|
$lasttime = $message->timestamp;
|
2003-07-21 03:16:19 +00:00
|
|
|
}
|
2003-07-21 03:37:53 +00:00
|
|
|
if (!$sessionend) {
|
|
|
|
$sessionend = $message->timestamp;
|
2003-07-21 03:16:19 +00:00
|
|
|
}
|
2004-12-08 13:47:06 +00:00
|
|
|
if ((($lasttime - $message->timestamp) < $sessiongap) and $messagesleft) { // Same session
|
2003-07-21 04:08:32 +00:00
|
|
|
if ($message->userid and !$message->system) { // Remember user and count messages
|
|
|
|
if (empty($sessionusers[$message->userid])) {
|
|
|
|
$sessionusers[$message->userid] = 1;
|
|
|
|
} else {
|
|
|
|
$sessionusers[$message->userid] ++;
|
|
|
|
}
|
2003-07-21 03:37:53 +00:00
|
|
|
}
|
2005-02-03 20:39:27 +00:00
|
|
|
} else {
|
2003-07-21 03:37:53 +00:00
|
|
|
$sessionstart = $lasttime;
|
2003-07-21 03:16:19 +00:00
|
|
|
|
2003-07-21 03:37:53 +00:00
|
|
|
if ($sessionend - $sessionstart > 60 and count($sessionusers) > 1) {
|
2003-07-21 03:16:19 +00:00
|
|
|
|
2005-02-03 20:39:27 +00:00
|
|
|
echo '<p align="center">'.userdate($sessionstart).' --> '. userdate($sessionend).'</p>';
|
2003-07-21 03:16:19 +00:00
|
|
|
|
2005-02-03 20:39:27 +00:00
|
|
|
print_simple_box_start('center');
|
2003-07-21 03:16:19 +00:00
|
|
|
|
2003-07-21 04:08:32 +00:00
|
|
|
arsort($sessionusers);
|
|
|
|
foreach ($sessionusers as $sessionuser => $usermessagecount) {
|
2008-06-08 15:49:36 +00:00
|
|
|
if ($user = $DB->get_record('user', array('id'=>$sessionuser))) {
|
2008-02-13 17:03:25 +00:00
|
|
|
print_user_picture($user, $course->id, $user->picture);
|
2006-08-14 05:55:40 +00:00
|
|
|
echo ' '.fullname($user, true); // XXX TODO use capability instead of true
|
2003-07-21 05:31:23 +00:00
|
|
|
echo " ($usermessagecount)<br />";
|
2003-07-21 03:37:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-03 20:39:27 +00:00
|
|
|
echo '<p align="right">';
|
|
|
|
echo "<a href=\"report.php?id=$cm->id&start=$sessionstart&end=$sessionend\">$strseesession</a>";
|
2008-08-18 10:16:56 +00:00
|
|
|
if (has_capability('mod/chat:exportsession', $context)
|
|
|
|
|| (array_key_exists($USER->id, $sessionusers)
|
|
|
|
&& has_capability('mod/chat:exportparticipatedsession', $context))) {
|
|
|
|
require_once($CFG->libdir . '/portfoliolib.php');
|
2008-09-11 13:42:58 +00:00
|
|
|
$buttonoptions = array(
|
2008-08-18 10:16:56 +00:00
|
|
|
'id' => $cm->id,
|
|
|
|
'start' => $sessionstart,
|
|
|
|
'end' => $sessionend,
|
|
|
|
);
|
2008-09-11 13:42:58 +00:00
|
|
|
$button = new portfolio_add_button();
|
|
|
|
$button->set_callback_options('chat_portfolio_caller', $buttonoptions, '/mod/chat/lib.php');
|
|
|
|
$button->render(PORTFOLIO_ADD_TEXT_LINK);
|
2008-08-18 10:16:56 +00:00
|
|
|
}
|
2006-08-14 05:55:40 +00:00
|
|
|
if (has_capability('mod/chat:deletelog', $context)) {
|
2005-02-03 20:39:27 +00:00
|
|
|
echo "<br /><a href=\"report.php?id=$cm->id&start=$sessionstart&end=$sessionend&deletesession=1\">$strdeletesession</a>";
|
2004-01-16 13:14:42 +00:00
|
|
|
}
|
2005-02-03 20:39:27 +00:00
|
|
|
echo '</p>';
|
2003-07-21 03:37:53 +00:00
|
|
|
print_simple_box_end();
|
|
|
|
}
|
2003-07-21 03:16:19 +00:00
|
|
|
|
2003-07-21 03:37:53 +00:00
|
|
|
$sessionend = $message->timestamp;
|
2003-07-21 03:16:19 +00:00
|
|
|
$sessionusers = array();
|
2003-07-21 04:08:32 +00:00
|
|
|
$sessionusers[$message->userid] = 1;
|
2003-07-21 03:16:19 +00:00
|
|
|
}
|
2003-07-21 03:37:53 +00:00
|
|
|
$lasttime = $message->timestamp;
|
2003-07-21 03:16:19 +00:00
|
|
|
}
|
|
|
|
|
2008-08-18 10:16:56 +00:00
|
|
|
if (has_capability('mod/chat:exportsession', $context)) {
|
|
|
|
require_once($CFG->libdir . '/portfoliolib.php');
|
2008-09-11 13:42:58 +00:00
|
|
|
$button = new portfolio_add_button();
|
|
|
|
$button->set_callback_options('chat_portfolio_caller', array('id' => $cm->id), '/mod/chat/lib.php');
|
|
|
|
$button->render(null, get_string('addalltoportfolio', 'portfolio'));
|
2008-08-18 10:16:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-21 03:16:19 +00:00
|
|
|
/// Finish the page
|
|
|
|
print_footer($course);
|
|
|
|
|
|
|
|
?>
|