2006-03-09 09:45:57 +00:00
|
|
|
<?php // $Id$
|
|
|
|
// Produces a graph of log accesses
|
|
|
|
|
2006-04-05 03:17:20 +00:00
|
|
|
require_once("../../../config.php");
|
|
|
|
require_once("../../lib.php");
|
2006-03-09 09:45:57 +00:00
|
|
|
require_once("$CFG->libdir/graphlib.php");
|
|
|
|
|
2006-04-20 22:36:22 +00:00
|
|
|
$id = required_param('id', PARAM_INT); // Course ID
|
|
|
|
$type = required_param('type', PARAM_FILE); // Graph Type
|
|
|
|
$user = optional_param('user', 0, PARAM_INT); // Student ID
|
|
|
|
$date = optional_param('date', 0, PARAM_INT); // A time of a day (in GMT)
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2008-05-31 14:35:58 +00:00
|
|
|
if (! $course = $DB->get_record("course", array("id"=>$id))) {
|
2008-05-13 06:15:20 +00:00
|
|
|
print_error('invalidcourseid');
|
2006-03-09 09:45:57 +00:00
|
|
|
}
|
|
|
|
|
2008-11-29 14:22:10 +00:00
|
|
|
require_login($course);
|
2006-08-25 08:51:50 +00:00
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2008-11-29 14:22:10 +00:00
|
|
|
if ($course->showreports and $USER->id == $user and !isguestuser()) {
|
|
|
|
// no cap required to view own graph
|
|
|
|
} else {
|
|
|
|
require_capability('coursereport/log:view', $context);
|
2006-03-09 09:45:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($user) {
|
2008-05-31 14:35:58 +00:00
|
|
|
if (! $user = $DB->get_record("user", array("id"=>$user))) {
|
2008-05-13 06:15:20 +00:00
|
|
|
print_error("nousers");
|
2006-03-09 09:45:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$logs = array();
|
|
|
|
|
|
|
|
$timenow = time();
|
|
|
|
|
|
|
|
switch ($type) {
|
|
|
|
case "usercourse.png":
|
|
|
|
|
|
|
|
$site = get_site();
|
|
|
|
|
|
|
|
if ($course->id == $site->id) {
|
|
|
|
$courseselect = 0;
|
|
|
|
} else {
|
|
|
|
$courseselect = $course->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
$maxseconds = COURSE_MAX_LOG_DISPLAY * 3600 * 24; // seconds
|
|
|
|
//$maxseconds = 60 * 3600 * 24; // seconds
|
|
|
|
if ($timenow - $course->startdate > $maxseconds) {
|
|
|
|
$course->startdate = $timenow - $maxseconds;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($CFG->loglifetime)) {
|
|
|
|
$maxseconds = $CFG->loglifetime * 3600 * 24; // seconds
|
|
|
|
if ($timenow - $course->startdate > $maxseconds) {
|
|
|
|
$course->startdate = $timenow - $maxseconds;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$timestart = $coursestart = usergetmidnight($course->startdate);
|
|
|
|
|
|
|
|
if ((($timenow - $timestart)/86400.0) > 40) {
|
|
|
|
$reducedays = 7;
|
|
|
|
} else {
|
|
|
|
$reducedays = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
while ($timestart < $timenow) {
|
|
|
|
$timefinish = $timestart + 86400;
|
|
|
|
if ($reducedays) {
|
|
|
|
if ($i % $reducedays) {
|
|
|
|
$days[$i] = "";
|
|
|
|
} else {
|
|
|
|
$days[$i] = userdate($timestart, "%a %d %b");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$days[$i] = userdate($timestart, "%a %d %b");
|
|
|
|
}
|
|
|
|
$logs[$i] = 0;
|
|
|
|
$i++;
|
|
|
|
$timestart = $timefinish;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($rawlogs = get_logs_usercourse($user->id, $courseselect, $coursestart)) {
|
|
|
|
foreach ($rawlogs as $rawlog) {
|
|
|
|
$logs[$rawlog->day] = $rawlog->num;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$graph = new graph(750, 400);
|
|
|
|
|
|
|
|
$a->coursename = $course->shortname;
|
|
|
|
$a->username = fullname($user, true);
|
|
|
|
$graph->parameter['title'] = get_string("hitsoncourse", "", $a);
|
|
|
|
|
|
|
|
$graph->x_data = $days;
|
|
|
|
|
|
|
|
$graph->y_data['logs'] = $logs;
|
|
|
|
$graph->y_order = array('logs');
|
|
|
|
|
|
|
|
if (!empty($CFG->preferlinegraphs)) {
|
|
|
|
$graph->y_format['logs'] = array('colour' => 'blue','line' => 'line');
|
|
|
|
} else {
|
|
|
|
$graph->y_format['logs'] = array('colour' => 'blue','bar' => 'fill','bar_size' => 0.6);
|
|
|
|
$graph->parameter['bar_spacing'] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$graph->parameter['y_label_left'] = get_string("hits");
|
|
|
|
$graph->parameter['label_size'] = "12";
|
|
|
|
$graph->parameter['x_axis_angle'] = 90;
|
|
|
|
$graph->parameter['x_label_angle'] = 0;
|
|
|
|
$graph->parameter['tick_length'] = 0;
|
|
|
|
|
|
|
|
|
|
|
|
$graph->parameter['shadow'] = 'none';
|
|
|
|
|
|
|
|
error_reporting(5); // ignore most warnings such as font problems etc
|
|
|
|
$graph->draw_stack();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "userday.png":
|
|
|
|
|
|
|
|
$site = get_site();
|
|
|
|
|
|
|
|
if ($course->id == $site->id) {
|
|
|
|
$courseselect = 0;
|
|
|
|
} else {
|
|
|
|
$courseselect = $course->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($date) {
|
|
|
|
$daystart = usergetmidnight($date);
|
|
|
|
} else {
|
|
|
|
$daystart = usergetmidnight(time());
|
|
|
|
}
|
|
|
|
$dayfinish = $daystart + 86400;
|
|
|
|
|
|
|
|
for ($i=0; $i<=23; $i++) {
|
|
|
|
$logs[$i] = 0;
|
|
|
|
$hour = $daystart + $i * 3600;
|
|
|
|
$hours[$i] = $i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($rawlogs = get_logs_userday($user->id, $courseselect, $daystart)) {
|
|
|
|
foreach ($rawlogs as $rawlog) {
|
|
|
|
$logs[$rawlog->hour] = $rawlog->num;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$graph = new graph(750, 400);
|
|
|
|
|
|
|
|
$a->coursename = $course->shortname;
|
|
|
|
$a->username = fullname($user, true);
|
|
|
|
$graph->parameter['title'] = get_string("hitsoncoursetoday", "", $a);
|
|
|
|
|
|
|
|
$graph->x_data = $hours;
|
|
|
|
|
|
|
|
$graph->y_data['logs'] = $logs;
|
|
|
|
$graph->y_order = array('logs');
|
|
|
|
|
|
|
|
if (!empty($CFG->preferlinegraphs)) {
|
|
|
|
$graph->y_format['logs'] = array('colour' => 'blue','line' => 'line');
|
|
|
|
} else {
|
|
|
|
$graph->y_format['logs'] = array('colour' => 'blue','bar' => 'fill','bar_size' => 0.9);
|
|
|
|
}
|
|
|
|
|
|
|
|
$graph->parameter['y_label_left'] = get_string("hits");
|
|
|
|
$graph->parameter['label_size'] = "12";
|
|
|
|
$graph->parameter['x_axis_angle'] = 0;
|
|
|
|
$graph->parameter['x_label_angle'] = 0;
|
|
|
|
|
|
|
|
$graph->parameter['shadow'] = 'none';
|
|
|
|
|
|
|
|
error_reporting(5); // ignore most warnings such as font problems etc
|
|
|
|
$graph->draw_stack();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|