Initial import.
[openemr.git] / interface / main / myadmin / tbl_rename.php
blob070df4fe0486b546933086590c4b65f3b26b5fc6
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
6 /**
7 * Gets some core libraries
8 */
9 require_once('./libraries/grab_globals.lib.php');
10 $js_to_run = 'functions.js';
11 require_once('./libraries/common.lib.php');
13 PMA_checkParameters(array('db','table'));
15 /**
16 * Defines the url to return to in case of error in a sql statement
18 $err_url = 'tbl_properties.php?' . PMA_generate_common_url($db, $table);
21 /**
22 * A new name has been submitted -> do the work
24 if (isset($new_name) && trim($new_name) != '' && strpos($new_name,'.') === FALSE) {
25 $old_name = $table;
26 $table = $new_name;
28 // Ensure the target is valid
29 if (count($dblist) > 0 && PMA_isInto($db, $dblist) == -1) {
30 exit();
33 require_once('./header.inc.php');
34 PMA_mysql_select_db($db);
35 $sql_query = 'ALTER TABLE ' . PMA_backquote($old_name) . ' RENAME ' . PMA_backquote($new_name);
36 $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', '', '', $err_url);
37 $message = sprintf($strRenameTableOK, htmlspecialchars($old_name), htmlspecialchars($table));
38 $reload = 1;
40 // garvin: Move old entries from comments to new table
41 require_once('./libraries/relation.lib.php');
42 $cfgRelation = PMA_getRelationsParam();
43 if ($cfgRelation['commwork']) {
44 $remove_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_info'])
45 . ' SET table_name = \'' . PMA_sqlAddslashes($table) . '\''
46 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
47 . ' AND table_name = \'' . PMA_sqlAddslashes($old_name) . '\'';
48 $rmv_rs = PMA_query_as_cu($remove_query);
49 unset($rmv_query);
52 if ($cfgRelation['displaywork']) {
53 $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_info'])
54 . ' SET table_name = \'' . PMA_sqlAddslashes($table) . '\''
55 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
56 . ' AND table_name = \'' . PMA_sqlAddslashes($old_name) . '\'';
57 $tb_rs = PMA_query_as_cu($table_query);
58 unset($table_query);
59 unset($tb_rs);
62 if ($cfgRelation['relwork']) {
63 $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation'])
64 . ' SET foreign_table = \'' . PMA_sqlAddslashes($table) . '\''
65 . ' WHERE foreign_db = \'' . PMA_sqlAddslashes($db) . '\''
66 . ' AND foreign_table = \'' . PMA_sqlAddslashes($old_name) . '\'';
67 $tb_rs = PMA_query_as_cu($table_query);
68 unset($table_query);
69 unset($tb_rs);
71 $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation'])
72 . ' SET master_table = \'' . PMA_sqlAddslashes($table) . '\''
73 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
74 . ' AND master_table = \'' . PMA_sqlAddslashes($old_name) . '\'';
75 $tb_rs = PMA_query_as_cu($table_query);
76 unset($table_query);
77 unset($tb_rs);
80 if ($cfgRelation['pdfwork']) {
81 $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_coords'])
82 . ' SET table_name = \'' . PMA_sqlAddslashes($table) . '\''
83 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
84 . ' AND table_name = \'' . PMA_sqlAddslashes($old_name) . '\'';
85 $tb_rs = PMA_query_as_cu($table_query);
86 unset($table_query);
87 unset($tb_rs);
93 /**
94 * No new name for the table!
96 else {
97 require_once('./header.inc.php');
98 if (strpos($new_name,'.') === FALSE) {
99 PMA_mysqlDie($strTableEmpty, '', '', $err_url);
100 } else {
101 PMA_mysqlDie($strError . ': ' . $new_name, '', '', $err_url);
107 * Back to the calling script
109 require('./tbl_properties_operations.php');