1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Configurable Reports
|
|
|
19 |
* A Moodle block for creating customizable reports
|
|
|
20 |
* @package blocks
|
|
|
21 |
* @author: Juan leyva <http://www.twitter.com/jleyvadelgado>
|
|
|
22 |
* @date: 2009
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
require_once("../../../../../config.php");
|
|
|
26 |
require_once($CFG->dirroot."/blocks/configurable_reports/locallib.php");
|
|
|
27 |
|
|
|
28 |
require_login();
|
|
|
29 |
|
|
|
30 |
error_reporting(0);
|
|
|
31 |
ini_set('display_erros', false);
|
|
|
32 |
|
|
|
33 |
$id = required_param('id', PARAM_ALPHANUM);
|
|
|
34 |
$reportid = required_param('reportid', PARAM_INT);
|
|
|
35 |
|
|
|
36 |
if (!$report = $DB->get_record('block_configurable_reports', array('id' => $reportid))) {
|
|
|
37 |
print_error('reportdoesnotexists');
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
$courseid = $report->courseid;
|
|
|
41 |
|
|
|
42 |
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
|
|
|
43 |
print_error('No such course id');
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
// Force user login in course (SITE or Course).
|
|
|
47 |
if ($course->id == SITEID) {
|
|
|
48 |
require_login();
|
|
|
49 |
$context = context_system::instance();
|
|
|
50 |
} else {
|
|
|
51 |
require_login($course->id);
|
|
|
52 |
$context = context_course::instance($course->id);
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
require_once($CFG->dirroot.'/blocks/configurable_reports/report.class.php');
|
|
|
56 |
require_once($CFG->dirroot.'/blocks/configurable_reports/reports/'.$report->type.'/report.class.php');
|
|
|
57 |
|
|
|
58 |
$reportclassname = 'report_'.$report->type;
|
|
|
59 |
$reportclass = new $reportclassname($report);
|
|
|
60 |
|
|
|
61 |
if (!$reportclass->check_permissions($USER->id, $context)) {
|
|
|
62 |
print_error("No permissions");
|
|
|
63 |
} else {
|
|
|
64 |
|
|
|
65 |
$components = cr_unserialize($report->components);
|
|
|
66 |
$graphs = $components['plot']['elements'];
|
|
|
67 |
|
|
|
68 |
if (!empty($graphs)) {
|
|
|
69 |
$series = array();
|
|
|
70 |
foreach ($graphs as $g) {
|
|
|
71 |
require_once($CFG->dirroot.'/blocks/configurable_reports/components/plot/'.$g['pluginname'].'/plugin.class.php');
|
|
|
72 |
if ($g['id'] == $id) {
|
|
|
73 |
$classname = 'plugin_'.$g['pluginname'];
|
|
|
74 |
$class = new $classname($report);
|
|
|
75 |
$series = $class->get_series($g['formdata']);
|
|
|
76 |
break;
|
|
|
77 |
}
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
if ($g['id'] == $id) {
|
|
|
81 |
|
|
|
82 |
$min = optional_param('min', 0, PARAM_INT);
|
|
|
83 |
$max = optional_param('max', 0, PARAM_INT);
|
|
|
84 |
$abcise = optional_param('abcise', -1, PARAM_INT);
|
|
|
85 |
|
|
|
86 |
$abciselabel = array();
|
|
|
87 |
if ($abcise != -1) {
|
|
|
88 |
$abciselabel = $series[$abcise]['serie'];
|
|
|
89 |
unset($series[$abcise]);
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
// Standard inclusions.
|
|
|
93 |
include($CFG->dirroot."/blocks/configurable_reports/lib/pChart/pData.class");
|
|
|
94 |
include($CFG->dirroot."/blocks/configurable_reports/lib/pChart/pChart.class");
|
|
|
95 |
|
|
|
96 |
// Dataset definition.
|
|
|
97 |
$dataset = new pData;
|
|
|
98 |
$lastid = 0;
|
|
|
99 |
foreach ($series as $key => $val) {
|
|
|
100 |
$dataset->AddPoint($val['serie'], "Serie$key");
|
|
|
101 |
$dataset->AddAllSeries("Serie$key");
|
|
|
102 |
$lastid = $key;
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
if (!empty($abciselabel)) {
|
|
|
106 |
$nk = $lastid + 1;
|
|
|
107 |
$dataset->AddPoint($abciselabel, "Serie$nk");
|
|
|
108 |
$dataset->SetAbsciseLabelSerie("Serie$nk");
|
|
|
109 |
} else {
|
|
|
110 |
$dataset->SetAbsciseLabelSerie();
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
foreach ($series as $key => $val) {
|
|
|
114 |
$value = $val['name'];
|
|
|
115 |
$ishebrew = preg_match("/[\xE0-\xFA]/", iconv("UTF-8", "ISO-8859-8", $value));
|
|
|
116 |
$fixedvalue = ($ishebrew == 1) ? $reportclass->utf8_strrev($value) : $value;
|
|
|
117 |
$dataset->SetSerieName($fixedvalue, "Serie$key");
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
// Initialise the graph.
|
|
|
121 |
$test = new pChart(700, 230);
|
|
|
122 |
$test->setFixedScale($min, $max);
|
|
|
123 |
|
|
|
124 |
$test->setFontProperties($CFG->dirroot."/blocks/configurable_reports/lib/Fonts/tahoma.ttf", 8);
|
|
|
125 |
$test->setGraphArea(70, 30, 680, 200);
|
|
|
126 |
$test->drawFilledRoundedRectangle(7, 7, 693, 223, 5, 240, 240, 240);
|
|
|
127 |
$test->drawRoundedRectangle(5, 5, 695, 225, 5, 230, 230, 230);
|
|
|
128 |
$test->drawGraphArea(255, 255, 255, true);
|
|
|
129 |
$test->drawScale($dataset->GetData(), $dataset->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, true, 0, 2);
|
|
|
130 |
|
|
|
131 |
$test->drawGrid(4, true, 230, 230, 230, 50);
|
|
|
132 |
|
|
|
133 |
// Draw the 0 line.
|
|
|
134 |
$test->setFontProperties($CFG->dirroot."/blocks/configurable_reports/lib/Fonts/tahoma.ttf", 10);
|
|
|
135 |
$test->drawTreshold(0, 143, 55, 72, true, true);
|
|
|
136 |
|
|
|
137 |
// Draw the line graph.
|
|
|
138 |
$test->drawLineGraph($dataset->GetData(), $dataset->GetDataDescription());
|
|
|
139 |
$test->drawPlotGraph($dataset->GetData(), $dataset->GetDataDescription(), 3, 2, 255, 255, 255);
|
|
|
140 |
|
|
|
141 |
// Finish the graph.
|
|
|
142 |
$test->setFontProperties($CFG->dirroot."/blocks/configurable_reports/lib/Fonts/tahoma.ttf", 8);
|
|
|
143 |
$test->drawLegend(75, 35, $dataset->GetDataDescription(), 255, 255, 255);
|
|
|
144 |
ob_clean(); // Hack to clear output and send only IMAGE data to browser.
|
|
|
145 |
$test->Stroke();
|
|
|
146 |
}
|
|
|
147 |
}
|
|
|
148 |
}
|