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 |
require_once($CFG->dirroot."/blocks/configurable_reports/locallib.php");
|
|
|
27 |
require_once('import_form.php');
|
|
|
28 |
|
|
|
29 |
$courseid = optional_param('courseid', SITEID, PARAM_INT);
|
|
|
30 |
$importurl = optional_param('importurl', '', PARAM_RAW);
|
|
|
31 |
|
|
|
32 |
if (! $course = $DB->get_record("course", array('id' => $courseid)) ) {
|
|
|
33 |
print_error("No such course id");
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
// Force user login in course (SITE or Course).
|
|
|
37 |
if ($course->id == SITEID) {
|
|
|
38 |
require_login();
|
|
|
39 |
$context = \context_system::instance();
|
|
|
40 |
} else {
|
|
|
41 |
require_login($course->id);
|
|
|
42 |
$context = \context_course::instance($course->id);
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
if (!has_capability('block/configurable_reports:managereports', $context) &&
|
|
|
46 |
!has_capability('block/configurable_reports:manageownreports', $context)) {
|
|
|
47 |
print_error('badpermissions');
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
$PAGE->set_url('/blocks/configurable_reports/managereport.php', array('courseid' => $course->id));
|
|
|
51 |
$PAGE->set_context($context);
|
|
|
52 |
$PAGE->set_pagelayout('incourse');
|
|
|
53 |
|
|
|
54 |
if ($importurl) {
|
|
|
55 |
$c = new \curl();
|
|
|
56 |
if ($data = $c->get($importurl)) {
|
|
|
57 |
$data = json_decode($data);
|
|
|
58 |
$xml = base64_decode($data->content);
|
|
|
59 |
} else {
|
|
|
60 |
print_error('errorimporting');
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
if (cr_import_xml($xml, $course)) {
|
|
|
64 |
redirect("$CFG->wwwroot/blocks/configurable_reports/managereport.php?courseid={$course->id}",
|
|
|
65 |
get_string('reportcreated', 'block_configurable_reports'));
|
|
|
66 |
} else {
|
|
|
67 |
print_error('errorimporting');
|
|
|
68 |
}
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
$mform = new \import_form(null, $course->id);
|
|
|
72 |
|
|
|
73 |
if ($data = $mform->get_data()) {
|
|
|
74 |
if ($xml = $mform->get_file_content('userfile')) {
|
|
|
75 |
if (cr_import_xml($xml, $course)) {
|
|
|
76 |
redirect("$CFG->wwwroot/blocks/configurable_reports/managereport.php?courseid={$course->id}",
|
|
|
77 |
get_string('reportcreated', 'block_configurable_reports'));
|
|
|
78 |
} else {
|
|
|
79 |
print_error('errorimporting');
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
$reports = cr_get_my_reports($course->id, $USER->id);
|
|
|
85 |
|
|
|
86 |
$title = get_string('reports', 'block_configurable_reports');
|
|
|
87 |
|
|
|
88 |
$PAGE->navbar->add(get_string('managereports', 'block_configurable_reports'));
|
|
|
89 |
|
|
|
90 |
$PAGE->set_title($title);
|
|
|
91 |
$PAGE->set_heading($title);
|
|
|
92 |
$PAGE->set_cacheable(true);
|
|
|
93 |
$jsmodule = [
|
|
|
94 |
'name' => 'block_configurable_reports',
|
|
|
95 |
'fullpath' => '/blocks/configurable_reports/js/configurable_reports.js',
|
|
|
96 |
'requires' => ['io']
|
|
|
97 |
];
|
|
|
98 |
$PAGE->requires->js_init_call('M.block_configurable_reports.loadReportCategories', null, false, $jsmodule);
|
|
|
99 |
|
|
|
100 |
echo $OUTPUT->header();
|
|
|
101 |
|
|
|
102 |
if ($reports) {
|
|
|
103 |
$table = new \stdclass;
|
|
|
104 |
$table->width = "100%";
|
|
|
105 |
$table->head = [
|
|
|
106 |
get_string('name'),
|
|
|
107 |
get_string('reportsmanage', 'admin').' '.get_string('course'),
|
|
|
108 |
get_string('type', 'block_configurable_reports'),
|
|
|
109 |
get_string('username'),
|
|
|
110 |
get_string('edit'),
|
|
|
111 |
get_string('download', 'block_configurable_reports'),
|
|
|
112 |
];
|
|
|
113 |
$table->align = ['left', 'left', 'left', 'left', 'center', 'center'];
|
|
|
114 |
$table->size = ['30%', '10%', '10%', '10%', '20%', '20%'];
|
|
|
115 |
$stredit = get_string('edit');
|
|
|
116 |
$strdelete = get_string('delete');
|
|
|
117 |
$strhide = get_string('hide');
|
|
|
118 |
$strshow = get_string('show');
|
|
|
119 |
$strcopy = get_string('duplicate');
|
|
|
120 |
$strexport = get_string('exportreport', 'block_configurable_reports');
|
|
|
121 |
|
|
|
122 |
foreach ($reports as $r) {
|
|
|
123 |
if ($r->courseid == 1) {
|
|
|
124 |
$coursename = '<a href="'.$CFG->wwwroot.'">'.get_string('site').'</a>';
|
|
|
125 |
} else if (!$coursename = $DB->get_field('course', 'fullname', ['id' => $r->courseid])) {
|
|
|
126 |
$coursename = get_string('deleted');
|
|
|
127 |
} else {
|
|
|
128 |
$coursename = format_string($coursename);
|
|
|
129 |
$coursename = '<a href="'.$CFG->wwwroot.'/blocks/configurable_reports/managereport.php?courseid='.$r->courseid.'">'.$coursename.'</a>';
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
if ($owneruser = $DB->get_record('user', array('id' => $r->ownerid))) {
|
|
|
133 |
$owner = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$r->ownerid.'">'.fullname($owneruser).'</a>';
|
|
|
134 |
} else {
|
|
|
135 |
$owner = get_string('deleted');
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
$editcell = '';
|
|
|
139 |
$editcell .= '<a title="'.$stredit.'" href="editreport.php?id='.$r->id.'">'.
|
|
|
140 |
$OUTPUT->pix_icon('t/edit', $stredit).
|
|
|
141 |
'</a> ';
|
|
|
142 |
$editcell .= '<a title="'.$strdelete.'" href="editreport.php?id='.$r->id.'&delete=1&sesskey='.$USER->sesskey.'">'.
|
|
|
143 |
$OUTPUT->pix_icon('t/delete', $strdelete).
|
|
|
144 |
'</a> ';
|
|
|
145 |
|
|
|
146 |
if (!empty($r->visible)) {
|
|
|
147 |
$editcell .= '<a title="'.$strhide.'" href="editreport.php?id='.$r->id.'&hide=1&sesskey='.$USER->sesskey.'">'.
|
|
|
148 |
$OUTPUT->pix_icon('t/hide', $strhide).
|
|
|
149 |
'</a> ';
|
|
|
150 |
} else {
|
|
|
151 |
$editcell .= '<a title="'.$strshow.'" href="editreport.php?id='.$r->id.'&show=1&sesskey='.$USER->sesskey.'">'.
|
|
|
152 |
$OUTPUT->pix_icon('t/show', $strshow).
|
|
|
153 |
'</a> ';
|
|
|
154 |
}
|
|
|
155 |
$editcell .= '<a title="'.$strcopy.'" href="editreport.php?id='.$r->id.'&duplicate=1&sesskey='.$USER->sesskey.'">'.
|
|
|
156 |
$OUTPUT->pix_icon('t/copy', $strcopy).
|
|
|
157 |
'</a> ';
|
|
|
158 |
$editcell .= '<a title="'.$strexport.'" href="export.php?id='.$r->id.'&sesskey='.$USER->sesskey.'">'.
|
|
|
159 |
$OUTPUT->pix_icon('t/backup', $strexport).
|
|
|
160 |
'</a> ';
|
|
|
161 |
|
|
|
162 |
$download = '';
|
|
|
163 |
$export = explode(',', $r->export);
|
|
|
164 |
if (!empty($export)) {
|
|
|
165 |
foreach ($export as $e) {
|
|
|
166 |
if ($e) {
|
|
|
167 |
$download .= '<a href="viewreport.php?id='.$r->id.'&download=1&format='.$e.'">'.
|
|
|
168 |
'<img src="'.$CFG->wwwroot.'/blocks/configurable_reports/export/'.$e.'/pix.gif" alt="'.$e.'">'.
|
|
|
169 |
' '.(strtoupper($e)).'</a> ';
|
|
|
170 |
}
|
|
|
171 |
}
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
$table->data[] = [
|
|
|
175 |
'<a href="viewreport.php?id='.$r->id.'">'.format_string($r->name).'</a>',
|
|
|
176 |
$coursename,
|
|
|
177 |
get_string('report_'.$r->type, 'block_configurable_reports'),
|
|
|
178 |
$owner,
|
|
|
179 |
$editcell,
|
|
|
180 |
$download
|
|
|
181 |
];
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
$table->id = 'reportslist';
|
|
|
185 |
cr_add_jsordering("#reportslist", $PAGE);
|
|
|
186 |
cr_print_table($table);
|
|
|
187 |
} else {
|
|
|
188 |
echo $OUTPUT->heading(get_string('noreportsavailable', 'block_configurable_reports'));
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
$addreporturl = $CFG->wwwroot.'/blocks/configurable_reports/editreport.php?courseid='.$course->id;
|
|
|
192 |
echo $OUTPUT->heading('<div class="addbutton">
|
|
|
193 |
<a href="'.$addreporturl.'" class="btn btn-secondary">'.
|
|
|
194 |
get_string('addreport', 'block_configurable_reports').
|
|
|
195 |
'</a> </div>');
|
|
|
196 |
|
|
|
197 |
// Repository report import.
|
|
|
198 |
if ($userandrepo = get_config('block_configurable_reports', 'crrepository')) {
|
|
|
199 |
echo html_writer::start_tag('div', array('class' => 'mform'));
|
|
|
200 |
echo html_writer::start_tag('fieldset');
|
|
|
201 |
echo html_writer::tag('legend', get_string('importfromrepository', 'block_configurable_reports'));
|
|
|
202 |
|
|
|
203 |
echo $OUTPUT->help_icon('repository', 'block_configurable_reports') . " ";
|
|
|
204 |
|
|
|
205 |
$reportcategories = array('' => '...');
|
|
|
206 |
echo get_string('categories', 'block_configurable_reports');
|
|
|
207 |
|
|
|
208 |
$attrs = [
|
|
|
209 |
'onchange' => 'M.block_configurable_reports.onchange_crreportcategories(this,"'.sesskey().'")',
|
|
|
210 |
'id' => 'id_crreportcategories'
|
|
|
211 |
];
|
|
|
212 |
echo html_writer::select($reportcategories, 'crreportcategories', '', null, $attrs);
|
|
|
213 |
echo get_string('report', 'block_configurable_reports');
|
|
|
214 |
|
|
|
215 |
$attrs = [
|
|
|
216 |
'onchange' => 'M.block_configurable_reports.onchange_crreportnames(this,"'.sesskey().'")',
|
|
|
217 |
'id' => 'id_crreportnames'
|
|
|
218 |
];
|
|
|
219 |
echo html_writer::select([], 'crreportnames', '', [], $attrs);
|
|
|
220 |
|
|
|
221 |
echo html_writer::end_tag('fieldset');
|
|
|
222 |
echo html_writer::end_tag('div');
|
|
|
223 |
}
|
|
|
224 |
|
|
|
225 |
$mform->display();
|
|
|
226 |
|
|
|
227 |
echo $OUTPUT->footer();
|