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 |
if (!defined('MOODLE_INTERNAL')) {
|
|
|
18 |
// It must be included from a Moodle page.
|
|
|
19 |
die('Direct access to this script is forbidden.');
|
|
|
20 |
}
|
|
|
21 |
|
|
|
22 |
require_once($CFG->libdir.'/formslib.php');
|
|
|
23 |
|
|
|
24 |
class bar_form extends moodleform {
|
|
|
25 |
public function definition() {
|
|
|
26 |
global $DB, $USER, $CFG;
|
|
|
27 |
|
|
|
28 |
$mform =& $this->_form;
|
|
|
29 |
$options = array();
|
|
|
30 |
$report = $this->_customdata['report'];
|
|
|
31 |
|
|
|
32 |
if ($report->type != 'sql') {
|
|
|
33 |
$components = cr_unserialize($this->_customdata['report']->components);
|
|
|
34 |
|
|
|
35 |
if (!is_array($components) || empty($components['columns']['elements'])) {
|
|
|
36 |
print_error('nocolumns');
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
$columns = $components['columns']['elements'];
|
|
|
40 |
$i = 0;
|
|
|
41 |
foreach ($columns as $c) {
|
|
|
42 |
if (!empty($c['summary'])) {
|
|
|
43 |
$key = "$i," . $c['summary'];
|
|
|
44 |
$options[$key] = str_replace('_', ' ', $c['summary']);
|
|
|
45 |
$i++;
|
|
|
46 |
}
|
|
|
47 |
}
|
|
|
48 |
} else {
|
|
|
49 |
require_once($CFG->dirroot.'/blocks/configurable_reports/report.class.php');
|
|
|
50 |
require_once($CFG->dirroot.'/blocks/configurable_reports/reports/'.$report->type.'/report.class.php');
|
|
|
51 |
|
|
|
52 |
$reportclassname = 'report_'.$report->type;
|
|
|
53 |
$reportclass = new $reportclassname($report);
|
|
|
54 |
|
|
|
55 |
$components = cr_unserialize($report->components);
|
|
|
56 |
$config = (isset($components['customsql']['config'])) ? $components['customsql']['config'] : new \stdclass;
|
|
|
57 |
|
|
|
58 |
if (isset($config->querysql)) {
|
|
|
59 |
$sql = $config->querysql;
|
|
|
60 |
$sql = $reportclass->prepare_sql($sql);
|
|
|
61 |
if ($rs = $reportclass->execute_query($sql)) {
|
|
|
62 |
foreach ($rs as $row) {
|
|
|
63 |
$i = 0;
|
|
|
64 |
foreach ($row as $colname => $value) {
|
|
|
65 |
$key = "$i,$colname";
|
|
|
66 |
$options[$key] = str_replace('_', ' ', $colname);
|
|
|
67 |
$i++;
|
|
|
68 |
}
|
|
|
69 |
break;
|
|
|
70 |
}
|
|
|
71 |
$rs->close();
|
|
|
72 |
}
|
|
|
73 |
}
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
$mform->addElement('header', 'crformheader', get_string('head_data', 'block_configurable_reports'), '');
|
|
|
77 |
|
|
|
78 |
$mform->addElement('select', 'label_field', get_string('label_field', 'block_configurable_reports'), $options);
|
|
|
79 |
$mform->addHelpButton('label_field', 'label_field', 'block_configurable_reports');
|
|
|
80 |
$valuefieldsstr = get_string('value_fields', 'block_configurable_reports');
|
|
|
81 |
$valueselect = $mform->addElement('select', 'value_fields', $valuefieldsstr, $options);
|
|
|
82 |
$valueselect->setMultiple(true);
|
|
|
83 |
$mform->addHelpButton('value_fields', 'value_fields', 'block_configurable_reports');
|
|
|
84 |
|
|
|
85 |
$this->add_formatting_elements($mform);
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
public function add_formatting_elements($mform) {
|
|
|
89 |
$mform->addElement('header', 'size', get_string('head_size', 'block_configurable_reports'));
|
|
|
90 |
|
|
|
91 |
$mform->addElement('text', 'width', get_string('width', 'block_configurable_reports'));
|
|
|
92 |
$mform->setDefault('width', 900);
|
|
|
93 |
$mform->setType("width", PARAM_INT);
|
|
|
94 |
$mform->addElement('text', 'height', get_string('height', 'block_configurable_reports'));
|
|
|
95 |
$mform->setDefault('height', 500);
|
|
|
96 |
$mform->setType("height", PARAM_INT);
|
|
|
97 |
|
|
|
98 |
/* Shouldn't use these without a way to automatically
|
|
|
99 |
* calculate colors for the text and bars that contrast
|
|
|
100 |
* with the chosen background.
|
|
|
101 |
*
|
|
|
102 |
$mform->addElement(
|
|
|
103 |
'header',
|
|
|
104 |
'color',
|
|
|
105 |
get_string('head_color', 'block_configurable_reports')
|
|
|
106 |
);
|
|
|
107 |
$mform->addElement(
|
|
|
108 |
'text',
|
|
|
109 |
'color_r',
|
|
|
110 |
"R",
|
|
|
111 |
"size = 5"
|
|
|
112 |
);
|
|
|
113 |
$mform->setDefault("color_r",170);
|
|
|
114 |
$mform->addElement(
|
|
|
115 |
'text',
|
|
|
116 |
'color_g',
|
|
|
117 |
"G",
|
|
|
118 |
"size = 5"
|
|
|
119 |
);
|
|
|
120 |
$mform->setDefault("color_g",183);
|
|
|
121 |
$mform->addElement(
|
|
|
122 |
'text',
|
|
|
123 |
'color_b',
|
|
|
124 |
"B",
|
|
|
125 |
"size = 5"
|
|
|
126 |
);
|
|
|
127 |
$mform->setDefault("color_b",87);
|
|
|
128 |
*/
|
|
|
129 |
|
|
|
130 |
// Buttons.
|
|
|
131 |
$this->add_action_buttons(true, get_string('add'));
|
|
|
132 |
}
|
|
|
133 |
}
|