-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_replace.php
71 lines (62 loc) · 2.94 KB
/
file_replace.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Advanced search and replace strings throughout all texts in the whole database
*
* @package tool_advancedreplace
* @copyright 2024 Catalyst IT Australia Pty Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('NO_OUTPUT_BUFFERING', true); // Progress bar is used here.
use tool_advancedreplace\helper;
require_once(__DIR__ . '/../../../config.php');
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);
$draftid = optional_param('draftid', '', PARAM_TEXT);
$url = new moodle_url('/admin/tool/advancedreplace/file_replace.php');
$PAGE->set_url($url);
admin_externalpage_setup('tool_advancedreplace_search');
$redirect = new moodle_url('/admin/tool/advancedreplace/files.php');
$customdata = [
'userid' => $USER->id,
];
$form = new \tool_advancedreplace\form\replace($url->out(false), $customdata);
echo $OUTPUT->header();
if ($form->is_cancelled()) {
redirect($redirect);
} else if (!(get_config('tool_advancedreplace', 'allowuireplace'))) {
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 ($data = $form->get_data()) {
$returnurl = new moodle_url('/admin/tool/advancedreplace/file_replace.php');
$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('replacecheckfiles', 'tool_advancedreplace'), $deletebutton, $returnurl);
} 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'));
$form->display();
}
echo $OUTPUT->footer();