adding some strings
[moodle-linuxchix.git] / course / report / log / graph.php
blobb2dd3117e4478caa14434dcbd696408d279fe49d
1 <?php // $Id$
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.");
25 if ($user) {
26 if (! $user = get_record("user", "id", $user)) {
27 error("Can not find that user");
31 $logs = array();
33 $timenow = time();
35 switch ($type) {
36 case "usercourse.png":
38 $site = get_site();
40 if ($course->id == $site->id) {
41 $courseselect = 0;
42 } else {
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) {
62 $reducedays = 7;
63 } else {
64 $reducedays = 0;
67 $i = 0;
68 while ($timestart < $timenow) {
69 $timefinish = $timestart + 86400;
70 if ($reducedays) {
71 if ($i % $reducedays) {
72 $days[$i] = "";
73 } else {
74 $days[$i] = userdate($timestart, "%a %d %b");
76 } else {
77 $days[$i] = userdate($timestart, "%a %d %b");
79 $logs[$i] = 0;
80 $i++;
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');
103 } else {
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();
121 break;
123 case "userday.png":
125 $site = get_site();
127 if ($course->id == $site->id) {
128 $courseselect = 0;
129 } else {
130 $courseselect = $course->id;
133 if ($date) {
134 $daystart = usergetmidnight($date);
135 } else {
136 $daystart = usergetmidnight(time());
138 $dayfinish = $daystart + 86400;
140 for ($i=0; $i<=23; $i++) {
141 $logs[$i] = 0;
142 $hour = $daystart + $i * 3600;
143 $hours[$i] = $i;
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');
165 } else {
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();
179 break;
181 default:
182 break;