2 // Produces a graph of log accesses
4 require_once("../../../config.php");
5 require_once("../../lib.php");
6 require_once("$CFG->libdir/graphlib.php");
8 $id = required_param('id', PARAM_INT
); // Course ID
9 $type = required_param('type', PARAM_FILE
); // Graph Type
10 $user = optional_param('user', 0, PARAM_INT
); // Student ID
11 $date = optional_param('date', 0, PARAM_INT
); // A time of a day (in GMT)
13 if (! $course = get_record("course", "id", $id)) {
14 error("Course is misconfigured");
17 require_login($course->id
);
18 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
20 if (! (has_capability('moodle/site:viewreports', $context)
21 or ($course->showreports
and $USER->id
== $user)) ) {
22 error("Sorry, you aren't allowed to see this.");
26 if (! $user = get_record("user", "id", $user)) {
27 error("Can not find that user");
36 case "usercourse.png":
40 if ($course->id
== $site->id
) {
43 $courseselect = $course->id
;
46 $maxseconds = COURSE_MAX_LOG_DISPLAY
* 3600 * 24; // seconds
47 //$maxseconds = 60 * 3600 * 24; // seconds
48 if ($timenow - $course->startdate
> $maxseconds) {
49 $course->startdate
= $timenow - $maxseconds;
52 if (!empty($CFG->loglifetime
)) {
53 $maxseconds = $CFG->loglifetime
* 3600 * 24; // seconds
54 if ($timenow - $course->startdate
> $maxseconds) {
55 $course->startdate
= $timenow - $maxseconds;
59 $timestart = $coursestart = usergetmidnight($course->startdate
);
61 if ((($timenow - $timestart)/86400.0) > 40) {
68 while ($timestart < $timenow) {
69 $timefinish = $timestart +
86400;
71 if ($i %
$reducedays) {
74 $days[$i] = userdate($timestart, "%a %d %b");
77 $days[$i] = userdate($timestart, "%a %d %b");
81 $timestart = $timefinish;
84 if ($rawlogs = get_logs_usercourse($user->id
, $courseselect, $coursestart)) {
85 foreach ($rawlogs as $rawlog) {
86 $logs[$rawlog->day
] = $rawlog->num
;
90 $graph = new graph(750, 400);
92 $a->coursename
= $course->shortname
;
93 $a->username
= fullname($user, true);
94 $graph->parameter
['title'] = get_string("hitsoncourse", "", $a);
96 $graph->x_data
= $days;
98 $graph->y_data
['logs'] = $logs;
99 $graph->y_order
= array('logs');
101 if (!empty($CFG->preferlinegraphs
)) {
102 $graph->y_format
['logs'] = array('colour' => 'blue','line' => 'line');
104 $graph->y_format
['logs'] = array('colour' => 'blue','bar' => 'fill','bar_size' => 0.6);
105 $graph->parameter
['bar_spacing'] = 0;
109 $graph->parameter
['y_label_left'] = get_string("hits");
110 $graph->parameter
['label_size'] = "12";
111 $graph->parameter
['x_axis_angle'] = 90;
112 $graph->parameter
['x_label_angle'] = 0;
113 $graph->parameter
['tick_length'] = 0;
116 $graph->parameter
['shadow'] = 'none';
118 error_reporting(5); // ignore most warnings such as font problems etc
119 $graph->draw_stack();
127 if ($course->id
== $site->id
) {
130 $courseselect = $course->id
;
134 $daystart = usergetmidnight($date);
136 $daystart = usergetmidnight(time());
138 $dayfinish = $daystart +
86400;
140 for ($i=0; $i<=23; $i++
) {
142 $hour = $daystart +
$i * 3600;
146 if ($rawlogs = get_logs_userday($user->id
, $courseselect, $daystart)) {
147 foreach ($rawlogs as $rawlog) {
148 $logs[$rawlog->hour
] = $rawlog->num
;
152 $graph = new graph(750, 400);
154 $a->coursename
= $course->shortname
;
155 $a->username
= fullname($user, true);
156 $graph->parameter
['title'] = get_string("hitsoncoursetoday", "", $a);
158 $graph->x_data
= $hours;
160 $graph->y_data
['logs'] = $logs;
161 $graph->y_order
= array('logs');
163 if (!empty($CFG->preferlinegraphs
)) {
164 $graph->y_format
['logs'] = array('colour' => 'blue','line' => 'line');
166 $graph->y_format
['logs'] = array('colour' => 'blue','bar' => 'fill','bar_size' => 0.9);
169 $graph->parameter
['y_label_left'] = get_string("hits");
170 $graph->parameter
['label_size'] = "12";
171 $graph->parameter
['x_axis_angle'] = 0;
172 $graph->parameter
['x_label_angle'] = 0;
174 $graph->parameter
['shadow'] = 'none';
176 error_reporting(5); // ignore most warnings such as font problems etc
177 $graph->draw_stack();