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 Configurable Reports
|
|
|
20 |
* @package blocks
|
|
|
21 |
* @author: Juan leyva <http://www.twitter.com/jleyvadelgado>
|
|
|
22 |
* @date: 2009
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
if (!defined('MOODLE_INTERNAL')) {
|
|
|
26 |
// It must be included from a Moodle page.
|
|
|
27 |
die('Direct access to this script is forbidden.');
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
require_once($CFG->libdir.'/formslib.php');
|
|
|
31 |
|
|
|
32 |
class reportcolumn_form extends moodleform {
|
|
|
33 |
public function definition() {
|
|
|
34 |
global $DB, $USER, $CFG;
|
|
|
35 |
|
|
|
36 |
$mform =& $this->_form;
|
|
|
37 |
$mform->addElement('header', 'crformheader', get_string('reportcolumn', 'block_configurable_reports'), '');
|
|
|
38 |
|
|
|
39 |
$reportid = optional_param('reportid', 0, PARAM_INT);
|
|
|
40 |
if ($actualrid = $this->_customdata['pluginclass']->get_current_report($this->_customdata['report'])) {
|
|
|
41 |
$reportid = $actualrid;
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
$reports = $this->_customdata['pluginclass']->get_user_reports();
|
|
|
45 |
$reportoptions = array(0 => get_string('choose'));
|
|
|
46 |
|
|
|
47 |
if ($reports) {
|
|
|
48 |
foreach ($reports as $r) {
|
|
|
49 |
$reportoptions[$r->id] = format_string($r->name);
|
|
|
50 |
}
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
$furl = "$CFG->wwwroot/blocks/configurable_reports/editplugin.php?id=".$this->_customdata['report']->id."&comp=columns&pname=reportcolumn";
|
|
|
54 |
$options = array('onchange' => 'location.href="'.$furl.'&reportid="+document.getElementById("id_reportid").value');
|
|
|
55 |
if ($actualrid) {
|
|
|
56 |
$options['disabled'] = 'disabled';
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
$mform->addElement('select', 'reportid', get_string('report', 'block_configurable_reports'), $reportoptions, $options);
|
|
|
60 |
$mform->setDefault('reportid', $reportid);
|
|
|
61 |
|
|
|
62 |
$columnsoptions = $this->_customdata['pluginclass']->get_report_columns($reportid);
|
|
|
63 |
$mform->addElement('select', 'column', get_string('column', 'block_configurable_reports'), $columnsoptions);
|
|
|
64 |
|
|
|
65 |
$this->_customdata['compclass']->add_form_elements($mform, $this);
|
|
|
66 |
|
|
|
67 |
// Buttons.
|
|
|
68 |
$this->add_action_buttons(true, get_string('add'));
|
|
|
69 |
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
public function validation($data, $files) {
|
|
|
73 |
$errors = parent::validation($data, $files);
|
|
|
74 |
|
|
|
75 |
$errors = $this->_customdata['compclass']->validate_form_elements($data, $errors);
|
|
|
76 |
|
|
|
77 |
if (!$data['reportid']) {
|
|
|
78 |
$errors['reportid'] = get_string('missingcolumn', 'block_configurable_reports');
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
if (!isset($data['column'])) {
|
|
|
82 |
$errors['column'] = get_string('missingcolumn', 'block_configurable_reports');
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
return $errors;
|
|
|
86 |
}
|
|
|
87 |
}
|