diff --git a/classes/form/replace.php b/classes/form/replace.php index 0faebad..141e53f 100644 --- a/classes/form/replace.php +++ b/classes/form/replace.php @@ -55,11 +55,6 @@ public function definition(): void { $mform->setType('origin', PARAM_TEXT); $mform->setConstant('origin', 'web'); - $mform->addElement('text', 'name', get_string('field_name', 'tool_advancedreplace'), $fullwidth); - $mform->setType('name', PARAM_RAW); - $mform->setDefault('name', ''); - $mform->addElement('static', 'name_help', '', get_string("field_name_help", "tool_advancedreplace")); - // File upload. $mform->addElement('filepicker', 'csvfile', get_string('selectfile', 'tool_advancedreplace'), null, ['accepted_types' => ['.csv']]); diff --git a/db_replace.php b/db_replace.php index 8bf0a0d..0456d8f 100644 --- a/db_replace.php +++ b/db_replace.php @@ -29,6 +29,11 @@ require_once($CFG->libdir . '/adminlib.php'); require_once($CFG->dirroot . '/lib/csvlib.class.php'); +global $CFG; +$replace = optional_param('delete', 0, PARAM_INT); +$confirm = optional_param('confirm', '', PARAM_BOOL); +$csvpostcontent = optional_param('csvpostcontent', '', PARAM_TEXT); + $url = new moodle_url('/admin/tool/advancedreplace/db_replace.php'); $PAGE->set_url($url); @@ -43,9 +48,18 @@ echo $OUTPUT->header(); if ($form->is_cancelled()) { redirect($redirect); -} else if ($csvcontent = $form->get_file_content('csvfile')) { - helper::handle_replace_csv($csvcontent); -} else { +} else if (!(get_config('tool_advancedreplace', 'allowuireplace'))) { + echo $OUTPUT->heading(get_string('replacepageheader', 'tool_advancedreplace')); + echo html_writer::div(get_string('replace_warning', 'tool_advancedreplace'), 'alert alert-warning'); +} else if ($csvcontent = ($form->get_file_content('csvfile') ?? $csvpostcontent)) { + $returnurl = new moodle_url('/admin/tool/advancedreplace/db_replace.php'); + $optionsyes = array('replace' => $replace, 'confirm' => 1, 'sesskey' => sesskey(), 'csvpostcontent' => $csvcontent); + $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); +}else { // Display form. echo $OUTPUT->heading(get_string('replacepageheader', 'tool_advancedreplace')); $form->display(); diff --git a/lang/en/tool_advancedreplace.php b/lang/en/tool_advancedreplace.php index 8fc7e5a..a909823 100644 --- a/lang/en/tool_advancedreplace.php +++ b/lang/en/tool_advancedreplace.php @@ -92,6 +92,8 @@ $string['replacepageheader'] = 'Replace text stored in the DB'; $string['replacepagename'] = 'Replace strings in the Database'; $string['replace'] = 'Replace'; +$string['replacecheck'] = 'Are you sure you want to replace strings in the Database using the uploaded csv file?'; +$string['replace_warning'] = 'Replace via UI not enabled, to enable please set allowuireplace to true in config.php'; $string['strftimedatetimemonthshort'] = '%d %b %Y, %I:%M %p'; $string['searchdeleted'] = 'The selected search was deleted.'; $string['searchpagename'] = 'Search in the Database';