MDL-33943 tool_replace: Hardcoded strings replaced with lang strings
[moodle.git] / admin / tool / replace / index.php
CommitLineData
20207b82 1<?php
fab6f7b7
PS
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Search and replace strings throughout all texts in the whole database
19 *
20 * @package tool
21 * @subpackage replace
22 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
04337d75 25
cbad562e
PS
26define('NO_OUTPUT_BUFFERING', true);
27
fab6f7b7 28require_once('../../../config.php');
c9a49cea 29require_once($CFG->dirroot.'/course/lib.php');
30require_once($CFG->libdir.'/adminlib.php');
1ae083e4 31
fab6f7b7 32admin_externalpage_setup('toolreplace');
04337d75 33
a2eaae61 34$search = optional_param('search', '', PARAM_RAW);
35$replace = optional_param('replace', '', PARAM_RAW);
c3b5e829 36$sure = optional_param('sure', 0, PARAM_BOOL);
04337d75 37
04337d75 38###################################################################
61ef8f9f 39echo $OUTPUT->header();
04337d75 40
4387f138 41echo $OUTPUT->heading(get_string('pageheader', 'tool_replace'));
04337d75 42
c3b5e829
PS
43if ($DB->get_dbfamily() !== 'mysql' and $DB->get_dbfamily() !== 'postgres') {
44 //TODO: add $DB->text_replace() to DML drivers
4387f138 45 echo $OUTPUT->notification(get_string('notimplemented', 'tool_replace'));
c3b5e829
PS
46 echo $OUTPUT->footer();
47 die;
48}
c9a49cea 49
c3b5e829 50if (!data_submitted() or !$search or !$replace or !confirm_sesskey() or !$sure) { /// Print a form
4387f138 51 echo $OUTPUT->notification(get_string('notsupported', 'tool_replace'));
04337d75 52
8fbce1c8 53 echo $OUTPUT->box_start();
85db96c5 54 echo '<div class="mdl-align">';
fab6f7b7 55 echo '<form action="index.php" method="post"><div>';
d4a1fcaf 56 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
4387f138
RT
57 echo '<div><label for="search">'.get_string('searchwholedb', 'tool_replace').
58 ' </label><input id="search" type="text" name="search" size="40" /> ('.
59 get_string('searchwholedbhelp', 'tool_replace').')</div>';
60 echo '<div><label for="replace">'.get_string('replacewith', 'tool_replace').
61 ' </label><input type="text" id="replace" name="replace" size="40" /> ('.
62 get_string('replacewithhelp', 'tool_replace').')</div>';
63 echo '<div><label for="sure">'.get_string('disclaimer', 'tool_replace').' </label><input type="checkbox" id="sure" name="sure" value="1" /></div>';
c3b5e829
PS
64 echo '<div class="buttons"><input type="submit" class="singlebutton" value="Yes, do it now" /></div>';
65 echo '</div></form>';
04337d75 66 echo '</div>';
8fbce1c8 67 echo $OUTPUT->box_end();
73d6f52f 68 echo $OUTPUT->footer();
04337d75 69 die;
70}
71
8fbce1c8 72echo $OUTPUT->box_start();
c3b5e829 73db_replace($search, $replace);
8fbce1c8 74echo $OUTPUT->box_end();
04337d75 75
c9a49cea 76/// Rebuild course cache which might be incorrect now
4387f138 77echo $OUTPUT->notification(get_string('notifyrebuilding', 'tool_replace'), 'notifysuccess');
c9a49cea 78rebuild_course_cache();
4387f138 79echo $OUTPUT->notification(get_string('notifyfinished', 'tool_replace'), 'notifysuccess');
c9a49cea 80
fab6f7b7 81echo $OUTPUT->continue_button(new moodle_url('/admin/index.php'));
04337d75 82
73d6f52f 83echo $OUTPUT->footer();
c9a49cea 84
20207b82 85