Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,19 @@ function block_configurable_reports_security_checks() {
return [new block_configurable_reports\check\sql_execution()];
}

function block_configurable_reports_pluginfile($course, $birecord, $context, $filearea, $args, $forcedownload, $sendfileoptions) {
global $CFG;

if ($filearea !== 'export') {
send_file_not_found();
}

$exporttype = $args[0];

if (!in_array($exporttype, ['csv','json', 'ods', 'xls'])) {
send_file_not_found();
}

$filename = $CFG->dirroot . '/blocks/configurable_reports/' . $filearea . '/' . $exporttype . '/pix.gif';
send_file($filename, $exporttype . ".gif", null , 0, false, false, '', false, array("immutable"=>1, "cacheability"=>"public"));
}
10 changes: 7 additions & 3 deletions managereport.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,13 @@
if (!empty($export)) {
foreach ($export as $e) {
if ($e) {
$download .= '<a href="viewreport.php?id='.$r->id.'&amp;download=1&amp;format='.$e.'">'.
'<img src="'.$CFG->wwwroot.'/blocks/configurable_reports/export/'.$e.'/pix.gif" alt="'.$e.'">'.
'&nbsp;'.(strtoupper($e)).'</a>&nbsp;&nbsp;';
$cid = $context->id;
$imageurl = moodle_url::make_pluginfile_url($cid, 'block_configurable_reports', 'export', null, '/', $e);
$image = html_writer::img($imageurl, $e, array('alt' => $e));
$params = ['id' => $r->id, 'download' => 1, 'format' => $e];
$downloadurl = new moodle_url('/blocks/configurable_reports/viewreport.php', $params);
$download .= html_writer::link($downloadurl, $image . '&nbsp;' . (strtoupper($e)));
$download .= '&nbsp;&nbsp;';
}
}
}
Expand Down
18 changes: 13 additions & 5 deletions report.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,23 +216,23 @@ public function print_graphs($return = false) {
public function print_export_options($return = false) {
global $CFG;

$wwwpath = $CFG->wwwroot;
$params = [];
$request = array_merge($_POST, $_GET);
if ($request) {
$id = clean_param($request['id'], PARAM_INT);
$wwwpath = 'viewreport.php?id='.$id;
$params['id'] = $id;
unset($request['id']);
foreach ($request as $key => $val) {
$key = clean_param($key, PARAM_CLEANHTML);
if (is_array($val)) {
foreach ($val as $k => $v) {
$k = clean_param($k, PARAM_CLEANHTML);
$v = clean_param($v, PARAM_CLEANHTML);
$wwwpath .= "&amp;{$key}[$k]=".$v;
$params[$key[$k]] = $v;
}
} else {
$val = clean_param($val, PARAM_CLEANHTML);
$wwwpath .= "&amp;$key=".$val;
$params[$key] = $val;
}
}
}
Expand All @@ -244,7 +244,15 @@ public function print_export_options($return = false) {
$output .= get_string('downloadreport', 'block_configurable_reports').': ';
foreach ($export as $e) {
if ($e) {
$output .= '<a href="'.$wwwpath.'&amp;download=1&amp;format='.$e.'"><img src="'.$CFG->wwwroot.'/blocks/configurable_reports/export/'.$e.'/pix.gif" alt="'.$e.'">&nbsp;'.(strtoupper($e)).'</a>&nbsp;';
$context = \context_system::instance();
$cid = $context->id;
$imageurl = moodle_url::make_pluginfile_url($cid, 'block_configurable_reports', 'export', null, '/', $e);
$image = html_writer::img($imageurl, $e, array('alt' => $e));
$params['download'] = 1;
$params['format'] = $e;
$downloadurl = new moodle_url('/blocks/configurable_reports/viewreport.php', $params);
$output .= html_writer::link($downloadurl, $image . '&nbsp;' . (strtoupper($e)));
$output .= '&nbsp;';
}
}
$output .= '</div>';
Expand Down