Skip to content

Commit

Permalink
Issue #95: Improve handling of replace form data
Browse files Browse the repository at this point in the history
  • Loading branch information
petersistrom committed Dec 9, 2024
1 parent 6c32c80 commit c72dd87
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions file_replace.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
global $CFG;
$replace = optional_param('delete', 0, PARAM_INT);
$confirm = optional_param('confirm', '', PARAM_BOOL);
$csvpostcontent = optional_param('csvpostcontent', '', PARAM_TEXT);
$draftid = optional_param('draftid', '', PARAM_TEXT);

$url = new moodle_url('/admin/tool/advancedreplace/file_replace.php');
$PAGE->set_url($url);
Expand All @@ -52,14 +52,16 @@
echo $OUTPUT->heading(get_string('replacefilespageheader', 'tool_advancedreplace'));
echo html_writer::div(get_string('replace_warning', 'tool_advancedreplace',
'$CFG->forced_plugin_settings[\'tool_advancedreplace\'][\'allowuireplace\'] = 1;'), 'alert alert-warning');
} else if ($csvcontent = ($form->get_file_content('csvfile') ?? $csvpostcontent)) {
} else if ($data = $form->get_data()) {
$returnurl = new moodle_url('/admin/tool/advancedreplace/file_replace.php');
$optionsyes = array('replace' => $replace, 'confirm' => 1, 'sesskey' => sesskey(), 'csvpostcontent' => $csvcontent);
$optionsyes = array('replace' => $replace, 'confirm' => 1, 'sesskey' => sesskey(), 'draftid' => $data->csvfile);
$deleteurl = new moodle_url($url, $optionsyes);
$deletebutton = new single_button($deleteurl, get_string('replace', 'tool_advancedreplace'), 'post');
echo $OUTPUT->confirm(get_string('replacecheck', 'tool_advancedreplace'), $deletebutton, $returnurl);
} else if ($confirm && isset($csvpostcontent)) {
helper::handle_replace_csv($csvpostcontent, 'files');
} else if ($confirm && !empty($draftid)) {
require_sesskey();
$contents = helper::get_replace_csv_content($draftid);
helper::handle_replace_csv($contents, 'files');
} else {
// Display form.
echo $OUTPUT->heading(get_string('replacefilespageheader', 'tool_advancedreplace'));
Expand Down

0 comments on commit c72dd87

Please sign in to comment.