2009-09-25 05:24:13 +00:00
|
|
|
<?php
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Produces a graph of log accesses
|
|
|
|
*
|
2011-11-03 08:30:26 +01:00
|
|
|
* @package report
|
|
|
|
* @subpackage log
|
|
|
|
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
2009-09-25 05:24:13 +00:00
|
|
|
*/
|
|
|
|
|
2011-11-03 08:30:26 +01:00
|
|
|
require("../../config.php");
|
|
|
|
require_once("$CFG->dirroot/course/lib.php");
|
2009-09-25 05:24:13 +00:00
|
|
|
require_once("$CFG->libdir/graphlib.php");
|
|
|
|
|
|
|
|
$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)
|
|
|
|
|
2011-11-03 08:30:26 +01:00
|
|
|
$url = new moodle_url('/report/log/graph.php', array('id'=>$id,'type'=>$type));
|
2009-09-25 05:24:13 +00:00
|
|
|
if ($user !== 0) {
|
|
|
|
$url->param('user', $user);
|
|
|
|
}
|
|
|
|
if ($date !== 0) {
|
|
|
|
$url->param('date', $date);
|
|
|
|
}
|
|
|
|
$PAGE->set_url($url);
|
|
|
|
|
|
|
|
if (! $course = $DB->get_record("course", array("id"=>$id))) {
|
|
|
|
print_error('invalidcourseid');
|
|
|
|
}
|
|
|
|
|
|
|
|
require_login($course);
|
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
|
|
|
|
|
|
|
if (!$course->showreports or $USER->id != $user) {
|
2011-11-03 08:30:26 +01:00
|
|
|
require_capability('report/log:view', $context);
|
2009-09-25 05:24:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($user) {
|
|
|
|
if (! $user = $DB->get_record("user", array("id"=>$user))) {
|
|
|
|
print_error("nousers");
|
2006-03-09 09:45:57 +00:00
|
|
|
}
|
2009-09-25 05:24:13 +00:00
|
|
|
}
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
$logs = array();
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
$timenow = time();
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
switch ($type) {
|
|
|
|
case "usercourse.png":
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
$site = get_site();
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
if ($course->id == $site->id) {
|
|
|
|
$courseselect = 0;
|
|
|
|
} else {
|
|
|
|
$courseselect = $course->id;
|
|
|
|
}
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
$maxseconds = COURSE_MAX_LOG_DISPLAY * 3600 * 24; // seconds
|
|
|
|
//$maxseconds = 60 * 3600 * 24; // seconds
|
|
|
|
if ($timenow - $course->startdate > $maxseconds) {
|
|
|
|
$course->startdate = $timenow - $maxseconds;
|
|
|
|
}
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
if (!empty($CFG->loglifetime)) {
|
|
|
|
$maxseconds = $CFG->loglifetime * 3600 * 24; // seconds
|
2006-03-09 09:45:57 +00:00
|
|
|
if ($timenow - $course->startdate > $maxseconds) {
|
|
|
|
$course->startdate = $timenow - $maxseconds;
|
|
|
|
}
|
2009-09-25 05:24:13 +00:00
|
|
|
}
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
$timestart = $coursestart = usergetmidnight($course->startdate);
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
if ((($timenow - $timestart)/86400.0) > 40) {
|
|
|
|
$reducedays = 7;
|
|
|
|
} else {
|
|
|
|
$reducedays = 0;
|
|
|
|
}
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2011-07-19 15:03:58 +02:00
|
|
|
$days = array();
|
2009-09-25 05:24:13 +00:00
|
|
|
$i = 0;
|
|
|
|
while ($timestart < $timenow) {
|
|
|
|
$timefinish = $timestart + 86400;
|
|
|
|
if ($reducedays) {
|
|
|
|
if ($i % $reducedays) {
|
|
|
|
$days[$i] = "";
|
2006-03-09 09:45:57 +00:00
|
|
|
} else {
|
|
|
|
$days[$i] = userdate($timestart, "%a %d %b");
|
|
|
|
}
|
2009-09-25 05:24:13 +00:00
|
|
|
} else {
|
|
|
|
$days[$i] = userdate($timestart, "%a %d %b");
|
2006-03-09 09:45:57 +00:00
|
|
|
}
|
2009-09-25 05:24:13 +00:00
|
|
|
$logs[$i] = 0;
|
|
|
|
$i++;
|
|
|
|
$timestart = $timefinish;
|
|
|
|
}
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
if ($rawlogs = get_logs_usercourse($user->id, $courseselect, $coursestart)) {
|
|
|
|
foreach ($rawlogs as $rawlog) {
|
|
|
|
$logs[$rawlog->day] = $rawlog->num;
|
2006-03-09 09:45:57 +00:00
|
|
|
}
|
2009-09-25 05:24:13 +00:00
|
|
|
}
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
$graph = new graph(750, 400);
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2011-09-07 11:46:28 +12:00
|
|
|
$a->coursename = format_string($course->shortname, true, array('context' => $context));
|
2009-09-25 05:24:13 +00:00
|
|
|
$a->username = fullname($user, true);
|
|
|
|
$graph->parameter['title'] = get_string("hitsoncourse", "", $a);
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
$graph->x_data = $days;
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
$graph->y_data['logs'] = $logs;
|
|
|
|
$graph->y_order = array('logs');
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
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;
|
|
|
|
}
|
2006-03-09 09:45:57 +00:00
|
|
|
|
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
$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;
|
2006-03-09 09:45:57 +00:00
|
|
|
|
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
$graph->parameter['shadow'] = 'none';
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
error_reporting(5); // ignore most warnings such as font problems etc
|
|
|
|
$graph->draw_stack();
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
break;
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
case "userday.png":
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
$site = get_site();
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
if ($course->id == $site->id) {
|
|
|
|
$courseselect = 0;
|
|
|
|
} else {
|
|
|
|
$courseselect = $course->id;
|
|
|
|
}
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
if ($date) {
|
|
|
|
$daystart = usergetmidnight($date);
|
|
|
|
} else {
|
|
|
|
$daystart = usergetmidnight(time());
|
|
|
|
}
|
|
|
|
$dayfinish = $daystart + 86400;
|
|
|
|
|
2011-07-19 15:03:58 +02:00
|
|
|
$hours = array();
|
2009-09-25 05:24:13 +00:00
|
|
|
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;
|
2006-03-09 09:45:57 +00:00
|
|
|
}
|
2009-09-25 05:24:13 +00:00
|
|
|
}
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
$graph = new graph(750, 400);
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2011-09-07 11:46:28 +12:00
|
|
|
$a->coursename = format_string($course->shortname, true, array('context' => $context));
|
2009-09-25 05:24:13 +00:00
|
|
|
$a->username = fullname($user, true);
|
|
|
|
$graph->parameter['title'] = get_string("hitsoncoursetoday", "", $a);
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
$graph->x_data = $hours;
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
$graph->y_data['logs'] = $logs;
|
|
|
|
$graph->y_order = array('logs');
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
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);
|
|
|
|
}
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
$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;
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
$graph->parameter['shadow'] = 'none';
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
error_reporting(5); // ignore most warnings such as font problems etc
|
|
|
|
$graph->draw_stack();
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
break;
|
2006-03-09 09:45:57 +00:00
|
|
|
|
2009-09-25 05:24:13 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2006-03-09 09:45:57 +00:00
|
|
|
|