Skip to content

Commit

Permalink
Merge pull request #88 from catalyst/add-export
Browse files Browse the repository at this point in the history
Add export
  • Loading branch information
brendanheywood authored Jul 8, 2024
2 parents a8757b5 + 5e6627f commit 62121a6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
11 changes: 10 additions & 1 deletion classes/table/csp_report.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ private function format_uri($uri, $label = '', $size = 40) {
}
$label = str_replace($CFG->wwwroot, '', $label);
$label = ltrim($label, '/');
$label = shorten_text($label, $size, true);

// Only shorten text when not exporting.
if (!$this->is_downloading()) {
$label = shorten_text($label, $size, true);
}
$label = s($label);

return \html_writer::link($uri, $label);
Expand Down Expand Up @@ -287,6 +291,11 @@ protected function col_courses($record) {
* @return string HTML link.
*/
protected function col_action($record) {
// Output no action if exporting.
if ($this->is_downloading()) {
return '';
}

global $OUTPUT;

// Find whether we are drilling down.
Expand Down
39 changes: 25 additions & 14 deletions csp_report.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
$removedirective = optional_param('removedirective', false, PARAM_TEXT);
$removedomain = optional_param('removedomain', false, PARAM_TEXT);
$removerecordwithid = optional_param('removerecordwithid', false, PARAM_TEXT);
$download = optional_param('download', '', PARAM_ALPHA);

admin_externalpage_setup('local_csp_report', '', null, '', array('pagelayout' => 'report'));

Expand All @@ -58,6 +59,14 @@
redirect($PAGE->url);
}

$PAGE->set_url('/local/csp/csp_report.php', [
'blockeddomain' => $viewblockeddomain,
'blockeddirective' => $viewdirective ?? '',
'removedirective' => $removedirective,
'removedomain' => $removedomain,
'removerecordwithid' => $removerecordwithid,
]);

$resetallcspstatistics = optional_param('resetallcspstatistics', 0, PARAM_INT);
if ($resetallcspstatistics == 1 && confirm_sesskey()) {
$DB->delete_records('local_csp');
Expand All @@ -69,18 +78,8 @@
$PAGE->set_heading($title);
$PAGE->set_pagelayout('admin');

global $OUTPUT, $DB;

echo $OUTPUT->header();
echo $OUTPUT->heading($title);

$action = new \confirm_action(get_string('areyousuretodeleteallrecords', 'local_csp'));
$urlresetallcspstatistics = new moodle_url($PAGE->url, array(
'resetallcspstatistics' => 1,
'sesskey' => sesskey(),
));
echo $OUTPUT->single_button($urlresetallcspstatistics,
get_string('resetallcspstatistics', 'local_csp'), 'post', array('actions' => array($action)));
$table = new \local_csp\table\csp_report('cspreportstable');
$table->is_downloading($download, 'csp_report', 'csp_report');

$blockeduri = get_string('blockeduri', 'local_csp');
$blockeddomain = get_string('blockeddomain', 'local_csp');
Expand All @@ -93,7 +92,6 @@
$timeupdated = get_string('timeupdated', 'local_csp');
$action = get_string('action', 'local_csp');

$table = new \local_csp\table\csp_report('cspreportstable');
$table->define_baseurl($PAGE->url);
$table->sortable(true, 'failcounter', SORT_DESC);
$table->set_attribute('class', 'generaltable generalbox table-sm');
Expand Down Expand Up @@ -159,8 +157,21 @@
$where = '1 = 1';
$params = array();
}
$table->set_sql($fields, $from, $where, $params);

if (!$table->is_downloading()) {
echo $OUTPUT->header();
echo $OUTPUT->heading($title);

$action = new \confirm_action(get_string('areyousuretodeleteallrecords', 'local_csp'));
$urlresetallcspstatistics = new moodle_url($PAGE->url, array(
'resetallcspstatistics' => 1,
'sesskey' => sesskey(),
));
echo $OUTPUT->single_button($urlresetallcspstatistics,
get_string('resetallcspstatistics', 'local_csp'), 'post', array('actions' => array($action)));
}

$table->set_sql($fields, $from, $where, $params);
$table->out(30, true);

echo $OUTPUT->footer();

0 comments on commit 62121a6

Please sign in to comment.