Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
require_once('../../config.php');
26
 
27
require_once($CFG->dirroot.'/blocks/configurable_reports/locallib.php');
28
require_once($CFG->dirroot.'/blocks/configurable_reports/report.class.php');
29
require_once($CFG->dirroot.'/blocks/configurable_reports/component.class.php');
30
require_once($CFG->dirroot.'/blocks/configurable_reports/plugin.class.php');
31
 
32
$id = required_param('id', PARAM_INT);
33
$comp = required_param('comp', PARAM_ALPHA);
34
$courseid = optional_param('courseid', null, PARAM_INT);
35
 
36
if (!$report = $DB->get_record('block_configurable_reports', ['id' => $id])) {
37
    print_error('reportdoesnotexists');
38
}
39
 
40
// Ignore report's courseid, If we are running this report on a specific courseid
41
// (For permission checks).
42
if (empty($courseid)) {
43
    $courseid = $report->courseid;
44
}
45
 
46
if (!$course = $DB->get_record("course", ['id' => $courseid])) {
47
    print_error("No such course id");
48
}
49
 
50
// Force user login in course (SITE or Course).
51
if ($course->id == SITEID) {
52
    require_login();
53
    $context = \context_system::instance();
54
} else {
55
    require_login($course->id);
56
    $context = \context_course::instance($course->id);
57
}
58
 
59
$PAGE->set_url('/blocks/configurable_reports/editreport.php', ['id' => $id, 'comp' => $comp]);
60
$PAGE->set_context($context);
61
$PAGE->set_pagelayout('incourse');
62
 
63
$PAGE->requires->js('/blocks/configurable_reports/js/configurable_reports.js');
64
 
65
$hasreportscap = has_capability('block/configurable_reports:managereports', $context);
66
if (!$hasreportscap && !has_capability('block/configurable_reports:manageownreports', $context)) {
67
    print_error('badpermissions');
68
}
69
 
70
 
71
if (!$hasreportscap && $report->ownerid != $USER->id) {
72
    print_error('badpermissions');
73
}
74
 
75
require_once($CFG->dirroot.'/blocks/configurable_reports/reports/'.$report->type.'/report.class.php');
76
 
77
$reportclassname = 'report_'.$report->type;
78
$reportclass = new $reportclassname($report->id);
79
 
80
if (!in_array($comp, $reportclass->components)) {
81
    print_error('badcomponent');
82
}
83
 
84
$elements = cr_unserialize($report->components);
85
$elements = isset($elements[$comp]['elements']) ? $elements[$comp]['elements'] : [];
86
 
87
require_once($CFG->dirroot.'/blocks/configurable_reports/components/'.$comp.'/component.class.php');
88
$componentclassname = 'component_'.$comp;
89
$compclass = new $componentclassname($report->id);
90
 
91
if ($compclass->form) {
92
    require_once($CFG->dirroot.'/blocks/configurable_reports/components/'.$comp.'/form.php');
93
    $classname = $comp.'_form';
94
    $editform = new $classname('editcomp.php?id='.$id.'&comp='.$comp, compact('compclass', 'comp', 'id', 'report', 'reportclass', 'elements'));
95
 
96
    if ($editform->is_cancelled()) {
97
        redirect($CFG->wwwroot.'/blocks/configurable_reports/editcomp.php?id='.$id.'&amp;comp='.$comp);
98
    } else if ($data = $editform->get_data()) {
99
        $compclass->form_process_data($editform);
100
        cr_add_to_log($courseid, 'configurable_reports', 'edit', '', $report->name);
101
    }
102
 
103
    $compclass->form_set_data($editform);
104
}
105
 
106
if ($compclass->plugins) {
107
    $currentplugins = array();
108
    if ($elements) {
109
        foreach ($elements as $e) {
110
            $currentplugins[] = $e['pluginname'];
111
        }
112
    }
113
    $plugins = get_list_of_plugins('blocks/configurable_reports/components/'.$comp);
114
    $optionsplugins = array();
115
    foreach ($plugins as $p) {
116
        require_once($CFG->dirroot.'/blocks/configurable_reports/components/'.$comp.'/'.$p.'/plugin.class.php');
117
        $pluginclassname = 'plugin_'.$p;
118
        $pluginclass = new $pluginclassname($report);
119
        if (in_array($report->type, $pluginclass->reporttypes)) {
120
            if ($pluginclass->unique && in_array($p, $currentplugins)) {
121
                continue;
122
            }
123
            $optionsplugins[$p] = get_string($p, 'block_configurable_reports');
124
        }
125
    }
126
    asort($optionsplugins);
127
}
128
 
129
$managereporturl = new \moodle_url('/blocks/configurable_reports/managereport.php', ['courseid' => $courseid]);
130
$PAGE->navbar->add(get_string('managereports', 'block_configurable_reports'), $managereporturl);
131
 
132
$PAGE->navbar->add($report->name);
133
 
134
$title = format_string($report->name);
135
$PAGE->set_title($title);
136
$PAGE->set_heading($title);
137
$PAGE->set_cacheable(true);
138
 
139
echo $OUTPUT->header();
140
 
141
$currenttab = $comp;
142
require('tabs.php');
143
 
144
if ($elements) {
145
    $table = new \stdclass;
146
    $table->head = [get_string('idnumber'), get_string('name'), get_string('summary'), get_string('edit')];
147
    $i = 0;
148
 
149
    foreach ($elements as $e) {
150
 
151
        if (empty($e)) {
152
            continue;
153
        }
154
 
155
        require_once($CFG->dirroot.'/blocks/configurable_reports/components/'.$comp.'/'.$e['pluginname'].'/plugin.class.php');
156
        $pluginclassname = 'plugin_'.$e['pluginname'];
157
        $pluginclass = new $pluginclassname($report);
158
 
159
        $editcell = '';
160
 
161
        if ($pluginclass->form) {
162
            $editcell .= '<a href="editplugin.php?id='.$id.'&comp='.$comp.'&pname='.$e['pluginname'].'&cid='.$e['id'].'">'.
163
                         $OUTPUT->pix_icon('t/edit', get_string('edit')).
164
                         '</a>';
165
        }
166
 
167
        $editcell .= '<a href="editplugin.php?id='.$id.'&comp='.$comp.'&pname='.$e['pluginname'].
168
                     '&cid='.$e['id'].'&delete=1&amp;sesskey='.sesskey().'">'.
169
                     $OUTPUT->pix_icon('t/delete', get_string('delete')).
170
                     '</a>';
171
 
172
        if ($compclass->ordering && $i != 0 && count($elements) > 1) {
173
            $editcell .= '<a href="editplugin.php?id='.$id.'&comp='.$comp.'&pname='.$e['pluginname'].'&cid='.$e['id'].
174
                         '&moveup=1&amp;sesskey='.sesskey().'">'.
175
                         $OUTPUT->pix_icon('t/up', get_string('moveup')).
176
                         '</a>';
177
        }
178
        if ($compclass->ordering && $i != count($elements) - 1) {
179
            $editcell .= '<a href="editplugin.php?id='.$id.'&comp='.$comp.'&pname='.$e['pluginname'].'&cid='.$e['id'].
180
                         '&movedown=1&amp;sesskey='.sesskey().'">'.
181
                         $OUTPUT->pix_icon('t/down', get_string('movedown')).
182
                         '</a>';
183
        }
184
 
185
        $table->data[] = ['c'.($i + 1), $e['pluginfullname'], $e['summary'], $editcell];
186
        $i++;
187
    }
188
    cr_print_table($table);
189
} else {
190
    if ($compclass->plugins) {
191
        echo $OUTPUT->heading(get_string('no'.$comp.'yet', 'block_configurable_reports'));
192
    }
193
}
194
 
195
if ($compclass->plugins) {
196
    echo '<div class="boxaligncenter">';
197
    echo '<p class="centerpara">';
198
    print_string('add');
199
    echo ': &nbsp;';
200
 
201
    $attributes = ['id' => 'menuplugin'];
202
 
203
    echo \html_writer::select($optionsplugins, 'plugin', '', ['' => get_string('choose')], $attributes);
204
    $OUTPUT->add_action_handler(new component_action('change', 'menuplugin', ['url' => "editplugin.php?id=".$id."&comp=".$comp."&pname="]), 'menuplugin');
205
    echo '</p>';
206
    echo '</div>';
207
}
208
 
209
if ($compclass->form) {
210
    $editform->display();
211
}
212
 
213
if ($compclass->help) {
214
    echo '<div class="boxaligncenter">';
215
    echo '<p class="centerpara">';
216
    echo $OUTPUT->help_icon('comp_'.$comp, 'block_configurable_reports', get_string('comp_'.$comp, 'block_configurable_reports'));
217
    echo '</p>';
218
    echo '</div>';
219
}
220
 
221
echo $OUTPUT->footer();