2002-07-27 08:31:09 +00:00
|
|
|
<?PHP // $Id$
|
2002-08-11 15:41:54 +00:00
|
|
|
// Produces a graph of log accesses
|
2002-07-27 08:31:09 +00:00
|
|
|
|
|
|
|
require("../config.php");
|
|
|
|
require("lib.php");
|
|
|
|
require("$CFG->libdir/graphlib.php");
|
|
|
|
|
|
|
|
require_variable($id); // Course ID
|
|
|
|
require_variable($type); // Graph Type
|
|
|
|
optional_variable($user); // Student ID
|
2002-08-08 17:29:22 +00:00
|
|
|
optional_variable($date); // A time of a day (in GMT)
|
2002-07-27 08:31:09 +00:00
|
|
|
|
|
|
|
if (! $course = get_record("course", "id", $id)) {
|
|
|
|
error("Course is misconfigured");
|
|
|
|
}
|
|
|
|
|
|
|
|
require_login($course->id);
|
|
|
|
|
|
|
|
if (!isteacher($course->id)) {
|
2002-07-27 09:44:01 +00:00
|
|
|
if (! ($type == "usercourse.png" and $user == $USER->id) ) {
|
2002-07-27 08:31:09 +00:00
|
|
|
error("Sorry, you aren't allowed to see this.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($user) {
|
|
|
|
if (! $user = get_record("user", "id", $user)) {
|
|
|
|
error("Can not find that user");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$timenow = time();
|
|
|
|
|
|
|
|
switch ($type) {
|
2002-07-27 09:44:01 +00:00
|
|
|
case "usercourse.png":
|
2002-07-27 08:31:09 +00:00
|
|
|
|
2002-08-01 15:48:27 +00:00
|
|
|
$COURSE_MAX_LOG_DISPLAY = $COURSE_MAX_LOG_DISPLAY * 3600 * 24; // seconds
|
|
|
|
if ($timenow - $course->startdate > $COURSE_MAX_LOG_DISPLAY) {
|
|
|
|
$course->startdate = $timenow - $COURSE_MAX_LOG_DISPLAY;
|
|
|
|
}
|
2002-09-02 15:53:19 +00:00
|
|
|
$timestart = $coursestart = usergetmidnight($course->startdate);
|
|
|
|
|
2002-07-27 08:31:09 +00:00
|
|
|
$i = 0;
|
|
|
|
while ($timestart < $timenow) {
|
2002-09-02 15:53:19 +00:00
|
|
|
$timefinish = $timestart + 86400;
|
2002-11-19 14:27:57 +00:00
|
|
|
$days[$i] = userdate($timestart, "%a %d %b");
|
2002-09-02 15:53:19 +00:00
|
|
|
$logs[$i] = 0;
|
2002-07-27 08:31:09 +00:00
|
|
|
$i++;
|
|
|
|
$timestart = $timefinish;
|
|
|
|
}
|
|
|
|
|
2002-09-02 15:53:19 +00:00
|
|
|
if ($rawlogs = get_records_sql("SELECT floor((`time` - $coursestart)/86400) as day,
|
|
|
|
count(*) as num FROM log
|
|
|
|
WHERE user = '$user->id'
|
|
|
|
AND course = '$course->id'
|
|
|
|
AND `time` > '$coursestart'
|
|
|
|
GROUP BY day ")) {
|
|
|
|
foreach ($rawlogs as $rawlog) {
|
|
|
|
$logs[$rawlog->day] = $rawlog->num;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-27 08:31:09 +00:00
|
|
|
$maxlogs = max($logs);
|
|
|
|
|
|
|
|
|
2002-07-27 09:44:01 +00:00
|
|
|
$graph = new graph(750, 400);
|
2002-11-21 14:57:10 +00:00
|
|
|
|
|
|
|
$a->coursename = $course->shortname;
|
|
|
|
$a->username = "$user->firstname $user->lastname";
|
|
|
|
$graph->parameter['title'] = get_string("hitsoncourse", "", $a);
|
2002-07-27 08:31:09 +00:00
|
|
|
|
|
|
|
$graph->x_data = $days;
|
|
|
|
|
|
|
|
$graph->y_data['logs'] = $logs;
|
2002-09-02 16:35:41 +00:00
|
|
|
$graph->y_format['logs'] = array('colour' => 'blue','line' => 'line');
|
2002-11-21 14:57:10 +00:00
|
|
|
$graph->y_label_left = get_string("hits");
|
2002-07-27 09:44:01 +00:00
|
|
|
$graph->label_size = "6";
|
2002-07-27 08:31:09 +00:00
|
|
|
|
|
|
|
$graph->y_order = array('logs');
|
|
|
|
|
|
|
|
|
|
|
|
$graph->parameter['shadow'] = 'none';
|
|
|
|
|
2002-11-21 14:57:10 +00:00
|
|
|
error_reporting(5);
|
2002-07-27 08:31:09 +00:00
|
|
|
$graph->draw_stack();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2002-07-27 09:44:01 +00:00
|
|
|
case "userday.png":
|
|
|
|
|
2002-07-27 13:33:50 +00:00
|
|
|
if ($date) {
|
2002-09-02 16:35:41 +00:00
|
|
|
$daystart = usergetmidnight($date);
|
2002-07-27 13:33:50 +00:00
|
|
|
} else {
|
2002-09-02 16:35:41 +00:00
|
|
|
$daystart = usergetmidnight(time());
|
2002-07-27 13:33:50 +00:00
|
|
|
}
|
2002-09-02 16:35:41 +00:00
|
|
|
$dayfinish = $daystart + 86400;
|
|
|
|
|
|
|
|
for ($i=0; $i<=23; $i++) {
|
|
|
|
$logs[$i] = 0;
|
|
|
|
$hour = $daystart + $i * 3600;
|
|
|
|
$hh = (int)userdate($hour, "%I");
|
|
|
|
$hours[$i] = userdate($hour, "$hh %p");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($rawlogs = get_records_sql("SELECT floor((`time` - $daystart)/3600) as hour,
|
|
|
|
count(*) as num FROM log
|
|
|
|
WHERE user = '$user->id'
|
|
|
|
AND course = '$course->id'
|
|
|
|
AND `time` > '$daystart'
|
|
|
|
GROUP BY hour ")) {
|
|
|
|
foreach ($rawlogs as $rawlog) {
|
|
|
|
$logs[$rawlog->hour] = $rawlog->num;
|
2002-07-27 13:33:50 +00:00
|
|
|
}
|
2002-07-27 09:44:01 +00:00
|
|
|
}
|
|
|
|
|
2002-07-27 13:33:50 +00:00
|
|
|
$maxlogs = max($logs);
|
|
|
|
|
|
|
|
$graph = new graph(750, 400);
|
2002-11-21 14:57:10 +00:00
|
|
|
|
|
|
|
$a->coursename = $course->shortname;
|
|
|
|
$a->username = "$user->firstname $user->lastname";
|
|
|
|
$graph->parameter['title'] = get_string("hitsoncoursetoday", "", $a);
|
2002-07-27 13:33:50 +00:00
|
|
|
|
|
|
|
$graph->x_data = $hours;
|
|
|
|
|
|
|
|
$graph->y_data['logs'] = $logs;
|
|
|
|
$graph->y_format['logs'] = array('colour' => 'blue','bar' => 'fill','legend' =>'actual','bar_size' => 0.9);
|
2002-11-21 14:57:10 +00:00
|
|
|
$graph->y_label_left = get_string("hits");
|
2002-07-27 13:33:50 +00:00
|
|
|
$graph->label_size = "6";
|
|
|
|
|
|
|
|
$graph->y_order = array('logs');
|
|
|
|
|
|
|
|
|
|
|
|
$graph->parameter['shadow'] = 'none';
|
|
|
|
|
2002-11-21 14:57:10 +00:00
|
|
|
error_reporting(5);
|
2002-07-27 13:33:50 +00:00
|
|
|
$graph->draw_stack();
|
2002-07-27 09:44:01 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2002-07-27 08:31:09 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|