Accessibility: 'weekscss' course format, replaced <table>, <td> with DIVs, inline...
[moodle.git] / admin / replace.php
CommitLineData
04337d75 1<?php /// $Id$
2 /// Search and replace strings throughout all texts in the whole database
3
4require('../config.php');
5
6$search = optional_param('search', '');
7$replace = optional_param('replace', '');
8
9require_login();
10
11if (!isadmin()) {
12 error("Admins only");
13}
14
15###################################################################
16print_header('Search and replace throughout the whole database', 'Replace text within the whole database');
17
18
19if (!$search or !$replace or !confirm_sesskey()) { /// Print a form
20
21 print_simple_box_start('center');
22 echo '<div align="center">';
23 echo '<form action="replace.php">';
24 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'">';
25 echo 'Search whole database for: <input type="text" name="search"><br />';
26 echo 'Replace with this string: <input type="text" name="replace"><br /></br />';
27 echo '<input type="submit" value="Yes, do it now"><br />';
28 echo '</form>';
29 echo '</div>';
30 print_simple_box_end();
31 die;
32}
33
34
35if (!$tables = $db->Metatables() ) { // No tables yet at all.
36 error("no tables");
37}
38
39print_simple_box_start('center');
40foreach ($tables as $table) {
41 if (in_array($table, array($CFG->prefix.'config'))) { // Don't process these
42 continue;
43 }
44 if ($columns = $db->MetaColumns($table, false)) {
45 foreach ($columns as $column => $data) {
46 if (in_array($data->type, array('text','mediumtext','longtext','varchar'))) { // Text stuff only
47 $db->debug = true;
48 execute_sql("UPDATE {$CFG->prefix}$table SET $column = REPLACE($column, '$search', '$replace');");
49 $db->debug = false;
50 }
51 }
52 }
53}
54print_simple_box_end();
55
56print_continue('index.php');
57
58?>