forked from jleyva/moodle-block_configurablereports
-
Notifications
You must be signed in to change notification settings - Fork 0
/
editcomp.php
210 lines (164 loc) · 8.09 KB
/
editcomp.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** Configurable Reports
* A Moodle block for creating Configurable Reports
* @package blocks
* @author: Juan leyva <http://www.twitter.com/jleyvadelgado>
* @date: 2009
*/
require_once("../../config.php");
require_once($CFG->dirroot."/blocks/configurable_reports/locallib.php");
require_once($CFG->dirroot.'/blocks/configurable_reports/report.class.php');
require_once($CFG->dirroot.'/blocks/configurable_reports/component.class.php');
require_once($CFG->dirroot.'/blocks/configurable_reports/plugin.class.php');
$id = required_param('id', PARAM_INT);
$comp = required_param('comp', PARAM_ALPHA);
$courseid = optional_param('courseid', null, PARAM_INT);
if(! $report = $DB->get_record('block_configurable_reports',array('id' => $id)))
print_error('reportdoesnotexists');
// Ignore report's courseid, If we are running this report on a specific courseid
// (For permission checks)
if (empty($courseid))
$courseid = $report->courseid;
if (! $course = $DB->get_record("course",array( "id" => $courseid)) ) {
print_error("No such course id");
}
// Force user login in course (SITE or Course)
if ($course->id == SITEID){
require_login();
$context = context_system::instance();
} else {
require_login($course->id);
$context = context_course::instance($course->id);
}
$PAGE->set_url('/blocks/configurable_reports/editreport.php', array('id'=>$id,'comp'=>$comp));
$PAGE->set_context($context);
$PAGE->set_pagelayout('incourse');
$PAGE->requires->js('/blocks/configurable_reports/js/codemirror/lib/codemirror.js');
$PAGE->requires->css('/blocks/configurable_reports/js/codemirror/lib/codemirror.css');
$PAGE->requires->js('/blocks/configurable_reports/js/configurable_reports.js');
if(! has_capability('block/configurable_reports:managereports', $context) && ! has_capability('block/configurable_reports:manageownreports', $context))
print_error('badpermissions');
if(! has_capability('block/configurable_reports:managereports', $context) && $report->ownerid != $USER->id)
print_error('badpermissions');
require_once($CFG->dirroot.'/blocks/configurable_reports/reports/'.$report->type.'/report.class.php');
$reportclassname = 'report_'.$report->type;
$reportclass = new $reportclassname($report->id);
if(!in_array($comp,$reportclass->components))
print_error('badcomponent');
$elements = cr_unserialize($report->components);
$elements = isset($elements[$comp]['elements'])? $elements[$comp]['elements'] : array();
require_once($CFG->dirroot.'/blocks/configurable_reports/components/'.$comp.'/component.class.php');
$componentclassname = 'component_'.$comp;
$compclass = new $componentclassname($report->id);
if($compclass->form){
require_once($CFG->dirroot.'/blocks/configurable_reports/components/'.$comp.'/form.php');
$classname = $comp.'_form';
$editform = new $classname('editcomp.php?id='.$id.'&comp='.$comp,compact('compclass','comp','id','report','reportclass','elements'));
if($editform->is_cancelled()){
redirect($CFG->wwwroot.'/blocks/configurable_reports/editcomp.php?id='.$id.'&comp='.$comp);
}
else if ($data = $editform->get_data()) {
$compclass->form_process_data($editform);
cr_add_to_log($courseid, 'configurable_reports', 'edit', '', $report->name);
}
$compclass->form_set_data($editform);
}
if($compclass->plugins){
$currentplugins = array();
if($elements){
foreach($elements as $e){
$currentplugins[] = $e['pluginname'];
}
}
$plugins = get_list_of_plugins('blocks/configurable_reports/components/'.$comp);
$optionsplugins = array();
foreach($plugins as $p){
require_once($CFG->dirroot.'/blocks/configurable_reports/components/'.$comp.'/'.$p.'/plugin.class.php');
$pluginclassname = 'plugin_'.$p;
$pluginclass = new $pluginclassname($report);
if(in_array($report->type,$pluginclass->reporttypes)){
if($pluginclass->unique && in_array($p,$currentplugins))
continue;
$optionsplugins[$p] = get_string($p,'block_configurable_reports');
}
}
asort($optionsplugins);
}
//$courseurl = new moodle_url($CFG->wwwroot.'/course/view.php',array('id'=>$report->courseid));
//$PAGE->navbar->add($COURSE->shortname, $courseurl);
$managereporturl = new moodle_url($CFG->wwwroot.'/blocks/configurable_reports/managereport.php',array('courseid'=>$courseid));
$PAGE->navbar->add(get_string('managereports','block_configurable_reports'), $managereporturl);
$PAGE->navbar->add($report->name);
$title = format_string($report->name);//.' '.get_string($comp,'block_configurable_reports');
$PAGE->set_title($title);
$PAGE->set_heading($title);
$PAGE->set_cacheable(true);
echo $OUTPUT->header();
$currenttab = $comp;
include('tabs.php');
if($elements){
$table = new stdclass;
$table->head = array(get_string('idnumber'),get_string('name'),get_string('summary'),get_string('edit'));
$i = 0;
foreach($elements as $e){
if (empty($e)) {
continue;
}
require_once($CFG->dirroot.'/blocks/configurable_reports/components/'.$comp.'/'.$e['pluginname'].'/plugin.class.php');
$pluginclassname = 'plugin_'.$e['pluginname'];
$pluginclass = new $pluginclassname($report);
$editcell = '';
if($pluginclass->form){
$editcell .= '<a href="editplugin.php?id='.$id.'&comp='.$comp.'&pname='.$e['pluginname'].'&cid='.$e['id'].'"><img src="'.$OUTPUT->pix_url('/t/edit').'" class="iconsmall"></a>';
}
$editcell .= '<a href="editplugin.php?id='.$id.'&comp='.$comp.'&pname='.$e['pluginname'].'&cid='.$e['id'].'&delete=1&sesskey='.sesskey().'"><img src="'.$OUTPUT->pix_url('/t/delete').'" class="iconsmall"></a>';
if($compclass->ordering && $i != 0 && count($elements) > 1)
$editcell .= '<a href="editplugin.php?id='.$id.'&comp='.$comp.'&pname='.$e['pluginname'].'&cid='.$e['id'].'&moveup=1&sesskey='.sesskey().'"><img src="'.$OUTPUT->pix_url('/t/up').'" class="iconsmall"></a>';
if($compclass->ordering && $i != count($elements) -1)
$editcell .= '<a href="editplugin.php?id='.$id.'&comp='.$comp.'&pname='.$e['pluginname'].'&cid='.$e['id'].'&movedown=1&sesskey='.sesskey().'"><img src="'.$OUTPUT->pix_url('/t/down').'" class="iconsmall"></a>';
$table->data[] = array('c'.($i+1),$e['pluginfullname'],$e['summary'],$editcell);
$i++;
}
cr_print_table($table);
} else {
if($compclass->plugins)
echo $OUTPUT->heading(get_string('no'.$comp.'yet','block_configurable_reports'));
}
if($compclass->plugins) {
echo '<div class="boxaligncenter">';
echo '<p class="centerpara">';
print_string('add');
echo ': ';
//choose_from_menu($optionsplugins,'plugin','',get_string('choose'),"location.href = 'editplugin.php?id=".$id."&comp=".$comp."&pname='+document.getElementById('menuplugin').value");
$attributes = array('id'=>'menuplugin');
echo html_writer::select($optionsplugins,'plugin','', array(''=>get_string('choose')), $attributes);
$OUTPUT->add_action_handler(new component_action('change', 'menuplugin',array('url'=>"editplugin.php?id=".$id."&comp=".$comp."&pname=")),'menuplugin');
echo '</p>';
echo '</div>';
}
if($compclass->form){
$editform->display();
}
if($compclass->help){
echo '<div class="boxaligncenter">';
echo '<p class="centerpara">';
echo $OUTPUT->help_icon('comp_'.$comp,'block_configurable_reports',get_string('comp_'.$comp,'block_configurable_reports'));
//helpbutton('comp_'.$comp, get_string('componenthelp','block_configurable_reports'),'block_configurable_reports', true, true);
echo '</p>';
echo '</div>';
}
echo $OUTPUT->footer();