fixed inactivity timeout failure
[openemr.git] / interface / main / myadmin / tbl_alter.php
blob9f193f18a1d849271fa4e99e00f72a14b2308554
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('./header.inc.php');
13 // Check parameters
14 PMA_checkParameters(array('db', 'table'));
16 /**
17 * Defines the url to return to in case of error in a sql statement
19 $err_url = 'tbl_properties_structure.php?' . PMA_generate_common_url($db, $table);
22 /**
23 * Modifications have been submitted -> updates the table
25 $abort = false;
26 if (isset($submit)) {
27 $field_cnt = count($field_orig);
28 for ($i = 0; $i < $field_cnt; $i++) {
29 // to "&quot;" in tbl_properties.php
30 $field_orig[$i] = urldecode($field_orig[$i]);
31 if (strcmp(str_replace('"', '&quot;', $field_orig[$i]), $field_name[$i]) == 0) {
32 $field_name[$i] = $field_orig[$i];
34 $field_default_orig[$i] = urldecode($field_default_orig[$i]);
35 if (strcmp(str_replace('"', '&quot;', $field_default_orig[$i]), $field_default[$i]) == 0) {
36 $field_default[$i] = $field_default_orig[$i];
38 $field_length_orig[$i] = urldecode($field_length_orig[$i]);
39 if (strcmp(str_replace('"', '&quot;', $field_length_orig[$i]), $field_length[$i]) == 0) {
40 $field_length[$i] = $field_length_orig[$i];
42 if (!isset($query)) {
43 $query = '';
44 } else {
45 $query .= ', CHANGE ';
47 $query .= PMA_backquote($field_orig[$i]) . ' ' . PMA_backquote($field_name[$i]) . ' ' . $field_type[$i];
48 // Some field types shouldn't have lengths
49 if ($field_length[$i] != ''
50 && !preg_match('@^(DATE|DATETIME|TIME|TINYBLOB|TINYTEXT|BLOB|TEXT|MEDIUMBLOB|MEDIUMTEXT|LONGBLOB|LONGTEXT)$@i', $field_type[$i])) {
51 $query .= '(' . $field_length[$i] . ')';
53 if ($field_attribute[$i] != '') {
54 $query .= ' ' . $field_attribute[$i];
55 } else if (PMA_MYSQL_INT_VERSION >= 40100 && $field_charset[$i] != '') {
56 $query .= ' CHARACTER SET ' . $field_charset[$i];
58 if ($field_default[$i] != '') {
59 if (strtoupper($field_default[$i]) == 'NULL') {
60 $query .= ' DEFAULT NULL';
61 } else {
62 $query .= ' DEFAULT \'' . PMA_sqlAddslashes($field_default[$i]) . '\'';
65 if ($field_null[$i] != '') {
66 $query .= ' ' . $field_null[$i];
68 if ($field_extra[$i] != '') {
69 $query .= ' ' . $field_extra[$i];
71 } // end for
73 // To allow replication, we first select the db to use and then run queries
74 // on this db.
75 $sql_query = 'USE ' . PMA_backquote($db);
76 $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', '', '', $err_url);
77 // Optimization fix - 2 May 2001 - Robbat2
78 $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' CHANGE ' . $query;
79 $error_create = false;
80 $result = PMA_mysql_query($sql_query) or $error_create = true;
82 if ($error_create == false) {
83 $message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenAltered;
84 $btnDrop = 'Fake';
86 // garvin: If comments were sent, enable relation stuff
87 require_once('./libraries/relation.lib.php');
88 require_once('./libraries/transformations.lib.php');
90 $cfgRelation = PMA_getRelationsParam();
92 // garvin: Update comment table, if a comment was set.
93 if (isset($field_comments) && is_array($field_comments) && $cfgRelation['commwork']) {
94 foreach($field_comments AS $fieldindex => $fieldcomment) {
95 PMA_setComment($db, $table, $field_name[$fieldindex], $fieldcomment, $field_orig[$fieldindex]);
99 // garvin: Rename relations&display fields, if altered.
100 if (($cfgRelation['displaywork'] || $cfgRelation['relwork']) && isset($field_orig) && is_array($field_orig)) {
101 foreach($field_orig AS $fieldindex => $fieldcontent) {
102 if ($field_name[$fieldindex] != $fieldcontent) {
103 if ($cfgRelation['displaywork']) {
104 $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_info'])
105 . ' SET display_field = \'' . PMA_sqlAddslashes($field_name[$fieldindex]) . '\''
106 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
107 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
108 . ' AND display_field = \'' . PMA_sqlAddslashes($fieldcontent) . '\'';
109 $tb_rs = PMA_query_as_cu($table_query);
110 unset($table_query);
111 unset($tb_rs);
114 if ($cfgRelation['relwork']) {
115 $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation'])
116 . ' SET master_field = \'' . PMA_sqlAddslashes($field_name[$fieldindex]) . '\''
117 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
118 . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\''
119 . ' AND master_field = \'' . PMA_sqlAddslashes($fieldcontent) . '\'';
120 $tb_rs = PMA_query_as_cu($table_query);
121 unset($table_query);
122 unset($tb_rs);
124 $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation'])
125 . ' SET foreign_field = \'' . PMA_sqlAddslashes($field_name[$fieldindex]) . '\''
126 . ' WHERE foreign_db = \'' . PMA_sqlAddslashes($db) . '\''
127 . ' AND foreign_table = \'' . PMA_sqlAddslashes($table) . '\''
128 . ' AND foreign_field = \'' . PMA_sqlAddslashes($fieldcontent) . '\'';
129 $tb_rs = PMA_query_as_cu($table_query);
130 unset($table_query);
131 unset($tb_rs);
132 } // end if relwork
133 } // end if fieldname has changed
134 } // end while check fieldnames
135 } // end if relations/display has to be changed
137 // garvin: Update comment table for mime types [MIME]
138 if (isset($field_mimetype) && is_array($field_mimetype) && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME']) {
139 foreach($field_mimetype AS $fieldindex => $mimetype) {
140 PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]);
144 $active_page = 'tbl_properties_structure.php';
145 require('./tbl_properties_structure.php');
146 } else {
147 PMA_mysqlDie('', '', '', $err_url, FALSE);
148 // garvin: An error happened while inserting/updating a table definition.
149 // to prevent total loss of that data, we embed the form once again.
150 // The variable $regenerate will be used to restore data in tbl_properties.inc.php
151 if (isset($orig_field)) {
152 $field = $orig_field;
155 $regenerate = true;
160 * No modifications yet required -> displays the table fields
162 if ($abort == FALSE) {
163 if (!isset($selected)) {
164 PMA_checkParameters(array('field'));
165 $selected[] = $field;
166 $selected_cnt = 1;
167 } else { // from a multiple submit
168 $selected_cnt = count($selected);
171 // TODO: optimize in case of multiple fields to modify
172 for ($i = 0; $i < $selected_cnt; $i++) {
173 if (!empty($submit_mult)) {
174 $field = PMA_sqlAddslashes(urldecode($selected[$i]), TRUE);
175 } else {
176 $field = PMA_sqlAddslashes($selected[$i], TRUE);
178 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db) . " LIKE '$field'";
179 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
180 $fields_meta[] = PMA_mysql_fetch_array($result);
181 mysql_free_result($result);
184 $num_fields = count($fields_meta);
185 $action = 'tbl_alter.php';
186 require('./tbl_properties.inc.php');
191 * Displays the footer
193 require_once('./footer.inc.php');