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 |
$colors = $class->get_color_palette($g['formdata']);
|
|
|
77 |
break;
|
|
|
78 |
}
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
if ($g['id'] == $id) {
|
|
|
82 |
|
|
|
83 |
// Standard inclusions.
|
|
|
84 |
include($CFG->dirroot."/blocks/configurable_reports/lib/pChart/pData.class");
|
|
|
85 |
include($CFG->dirroot."/blocks/configurable_reports/lib/pChart/pChart.class");
|
|
|
86 |
|
|
|
87 |
// Dataset definition.
|
|
|
88 |
$dataset = new pData;
|
|
|
89 |
|
|
|
90 |
$dataset->AddPoint($series[1], "Serie1");
|
|
|
91 |
// Invert/Reverse Hebrew labels so it can be rendered using PHP imagettftext().
|
|
|
92 |
foreach ($series[0] as $key => $value) {
|
|
|
93 |
$invertedlabels[$key] = strip_tags((preg_match("/[\xE0-\xFA]/", iconv("UTF-8", "ISO-8859-8", $value))) ? $reportclass->utf8_strrev($value) : $value);
|
|
|
94 |
}
|
|
|
95 |
$dataset->AddPoint($invertedlabels /* $series[0] */, "Serie2");
|
|
|
96 |
$dataset->AddAllSeries();
|
|
|
97 |
$dataset->SetAbsciseLabelSerie("Serie2");
|
|
|
98 |
|
|
|
99 |
// Initialise the graph.
|
|
|
100 |
$test = new pChart(450, 200 + (count($series[0]) * 10));
|
|
|
101 |
$test->drawFilledRoundedRectangle(7, 7, 293, 193, 5, 240, 240, 240);
|
|
|
102 |
$test->drawRoundedRectangle(5, 5, 295, 195, 5, 230, 230, 230);
|
|
|
103 |
$test->createColorGradientPalette(195, 204, 56, 223, 110, 41, 5);
|
|
|
104 |
|
|
|
105 |
// Custom colors.
|
|
|
106 |
if ($colors) {
|
|
|
107 |
foreach ($colors as $index => $color) {
|
|
|
108 |
if (!empty($color)) {
|
|
|
109 |
$test->Palette[$index] = array("R" => $color[0], "G" => $color[1], "B" => $color[2]);
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
// Draw the pie chart.
|
|
|
115 |
$test->setFontProperties($CFG->dirroot."/blocks/configurable_reports/lib/Fonts/tahoma.ttf", 8);
|
|
|
116 |
$test->AntialiasQuality = 0;
|
|
|
117 |
$test->drawPieGraph($dataset->GetData(), $dataset->GetDataDescription(), 150, 90, 110, PIE_PERCENTAGE, true, 50, 20, 5);
|
|
|
118 |
$test->drawPieLegend(300, 15, $dataset->GetData(), $dataset->GetDataDescription(), 250, 250, 250);
|
|
|
119 |
|
|
|
120 |
ob_clean(); // Hack to clear output and send only IMAGE data to browser.
|
|
|
121 |
$test->Stroke();
|
|
|
122 |
}
|
|
|
123 |
}
|
|
|
124 |
}
|