acknowledgments update
[openemr.git] / phpmyadmin / tbl_operations.php
blobf487ea97f0ff65dc4c928eb5f9bb9bc8524cd477
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package PhpMyAdmin
6 */
8 /**
11 require_once 'libraries/common.inc.php';
13 /**
14 * functions implementation for this script
16 require_once 'libraries/operations.lib.php';
18 $pma_table = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
19 $response = PMA_Response::getInstance();
21 /**
22 * Runs common work
24 require 'libraries/tbl_common.inc.php';
25 $url_query .= '&amp;goto=tbl_operations.php&amp;back=tbl_operations.php';
26 $url_params['goto'] = $url_params['back'] = 'tbl_operations.php';
28 /**
29 * Gets relation settings
31 $cfgRelation = PMA_getRelationsParam();
33 /**
34 * Gets available MySQL charsets and storage engines
36 require_once 'libraries/mysql_charsets.lib.php';
37 require_once 'libraries/StorageEngine.class.php';
39 /**
40 * Class for partition management
42 require_once 'libraries/Partition.class.php';
44 // reselect current db (needed in some cases probably due to
45 // the calling of relation.lib.php)
46 PMA_DBI_select_db($GLOBALS['db']);
48 /**
49 * Gets tables informations
51 require 'libraries/tbl_info.inc.php';
53 // define some variables here, for improved syntax in the conditionals
54 $is_myisam_or_aria = $is_isam = $is_innodb = $is_berkeleydb = $is_aria = $is_pbxt = false;
55 // set initial value of these variables, based on the current table engine
56 list($is_myisam_or_aria, $is_innodb, $is_isam,
57 $is_berkeleydb, $is_aria, $is_pbxt
58 ) = PMA_setGlobalVariablesForEngine($tbl_storage_engine);
60 if ($is_aria) {
61 // the value for transactional can be implicit
62 // (no create option found, in this case it means 1)
63 // or explicit (option found with a value of 0 or 1)
64 // ($transactional may have been set by libraries/tbl_info.inc.php,
65 // from the $create_options)
66 $transactional = (isset($transactional) && $transactional == '0')
67 ? '0'
68 : '1';
69 $page_checksum = (isset($page_checksum)) ? $page_checksum : '';
72 $reread_info = false;
73 $table_alters = array();
75 /**
76 * If the table has to be moved to some other database
78 if (isset($_REQUEST['submit_move']) || isset($_REQUEST['submit_copy'])) {
79 $_message = '';
80 include_once 'tbl_move_copy.php';
82 /**
83 * If the table has to be maintained
85 if (isset($_REQUEST['table_maintenance'])) {
86 include_once 'sql.php';
87 unset($result);
89 /**
90 * Updates table comment, type and options if required
92 if (isset($_REQUEST['submitoptions'])) {
93 $_message = '';
94 $warning_messages = array();
96 if (isset($_REQUEST['new_name'])) {
97 if ($pma_table->rename($_REQUEST['new_name'])) {
98 $_message .= $pma_table->getLastMessage();
99 $result = true;
100 $GLOBALS['table'] = $pma_table->getName();
101 $reread_info = true;
102 $reload = true;
103 } else {
104 $_message .= $pma_table->getLastError();
105 $result = false;
109 if (! empty($_REQUEST['new_tbl_storage_engine'])
110 && strtolower($_REQUEST['new_tbl_storage_engine'])
111 !== strtolower($tbl_storage_engine)
113 $new_tbl_storage_engine = $_REQUEST['new_tbl_storage_engine'];
114 // reset the globals for the new engine
115 list($is_myisam_or_aria, $is_innodb, $is_isam,
116 $is_berkeleydb, $is_aria, $is_pbxt
117 ) = PMA_setGlobalVariablesForEngine($new_tbl_storage_engine);
119 if ($is_aria) {
120 $transactional = (isset($transactional) && $transactional == '0')
121 ? '0'
122 : '1';
123 $page_checksum = (isset($page_checksum)) ? $page_checksum : '';
125 } else {
126 $new_tbl_storage_engine = '';
129 $table_alters = PMA_getTableAltersArray(
130 $is_myisam_or_aria, $is_isam, $pack_keys,
131 (empty($checksum) ? '0' : '1'),
132 $is_aria,
133 ((isset($page_checksum)) ? $page_checksum : ''),
134 (empty($delay_key_write) ? '0' : '1'),
135 $is_innodb, $is_pbxt, $row_format,
136 $new_tbl_storage_engine,
137 ((isset($transactional) && $transactional == '0') ? '0' : '1'),
138 $tbl_collation
141 if (count($table_alters) > 0) {
142 $sql_query = 'ALTER TABLE '
143 . PMA_Util::backquote($GLOBALS['table']);
144 $sql_query .= "\r\n" . implode("\r\n", $table_alters);
145 $sql_query .= ';';
146 $result .= PMA_DBI_query($sql_query) ? true : false;
147 $reread_info = true;
148 unset($table_alters);
149 $warning_messages = PMA_getWarningMessagesArray();
153 * Reordering the table has been requested by the user
155 if (isset($_REQUEST['submitorderby']) && ! empty($_REQUEST['order_field'])) {
156 list($sql_query, $result) = PMA_getQueryAndResultForReorderingTable();
157 } // end if
160 * A partition operation has been requested by the user
162 if (isset($_REQUEST['submit_partition'])
163 && ! empty($_REQUEST['partition_operation'])
165 list($sql_query, $result) = PMA_getQueryAndResultForPartition();
166 } // end if
168 if ($reread_info) {
169 // to avoid showing the old value (for example the AUTO_INCREMENT) after
170 // a change, clear the cache
171 PMA_Table::$cache = array();
172 $page_checksum = $checksum = $delay_key_write = 0;
173 include 'libraries/tbl_info.inc.php';
175 unset($reread_info);
177 if (isset($result) && empty($message_to_show)) {
178 // set to success by default, because result set could be empty
179 // (for example, a table rename)
180 $_type = 'success';
181 if (empty($_message)) {
182 $_message = $result
183 ? PMA_Message::success(
184 __('Your SQL query has been executed successfully')
186 : PMA_Message::error(__('Error'));
187 // $result should exist, regardless of $_message
188 $_type = $result ? 'success' : 'error';
190 if (isset($GLOBALS['ajax_request'])
191 && $GLOBALS['ajax_request'] == true
193 $response = PMA_Response::getInstance();
194 $response->isSuccess($_message->isSuccess());
195 $response->addJSON('message', $_message);
196 $response->addJSON(
197 'sql_query', PMA_Util::getMessage(null, $sql_query)
199 exit;
202 if (! empty($warning_messages)) {
203 $_message = new PMA_Message;
204 $_message->addMessages($warning_messages);
205 $_message->isError(true);
206 if ($GLOBALS['ajax_request'] == true) {
207 $response = PMA_Response::getInstance();
208 $response->isSuccess(false);
209 $response->addJSON('message', $_message);
210 exit;
212 unset($warning_messages);
215 $response->addHTML(
216 PMA_Util::getMessage($_message, $sql_query, $_type)
218 unset($_message, $_type);
221 $url_params['goto']
222 = $url_params['back']
223 = 'tbl_operations.php';
226 * Get columns names
228 $columns = PMA_DBI_get_columns($GLOBALS['db'], $GLOBALS['table']);
231 * Displays the page
234 * Order the table
236 $response->addHTML(PMA_getHtmlForOrderTheTable($columns));
239 * Move table
241 $response->addHTML(PMA_getHtmlForMoveTable());
243 if (strstr($show_comment, '; InnoDB free') === false) {
244 if (strstr($show_comment, 'InnoDB free') === false) {
245 // only user entered comment
246 $comment = $show_comment;
247 } else {
248 // here we have just InnoDB generated part
249 $comment = '';
251 } else {
252 // remove InnoDB comment from end, just the minimal part (*? is non greedy)
253 $comment = preg_replace('@; InnoDB free:.*?$@', '', $show_comment);
256 // PACK_KEYS: MyISAM or ISAM
257 // DELAY_KEY_WRITE, CHECKSUM, : MyISAM only
258 // AUTO_INCREMENT: MyISAM and InnoDB since 5.0.3, PBXT
260 // Here should be version check for InnoDB, however it is supported
261 // in >5.0.4, >4.1.12 and >4.0.11, so I decided not to
262 // check for version
264 $response->addHTML(
265 PMA_getTableOptionDiv(
266 $comment, $tbl_collation, $tbl_storage_engine,
267 $is_myisam_or_aria, $is_isam, $pack_keys,
268 $auto_increment,
269 (empty($delay_key_write) ? '0' : '1'),
270 ((isset($transactional) && $transactional == '0') ? '0' : '1'),
271 ((isset($page_checksum)) ? $page_checksum : ''),
272 $is_innodb, $is_pbxt, $is_aria, (empty($checksum) ? '0' : '1')
277 * Copy table
279 $response->addHTML(PMA_getHtmlForCopytable());
281 $response->addHTML('<br class="clearfloat"/>');
284 * Table maintenance
286 $response->addHTML(
287 PMA_getHtmlForTableMaintenance(
288 $is_myisam_or_aria,
289 $is_innodb,
290 $is_berkeleydb,
291 $url_params
295 if (! (isset($db_is_information_schema) && $db_is_information_schema)) {
296 $truncate_table_url_params = array();
297 $drop_table_url_params = array();
299 if (! $tbl_is_view
300 && ! (isset($db_is_information_schema) && $db_is_information_schema)
302 $this_sql_query = 'TRUNCATE TABLE '
303 . PMA_Util::backquote($GLOBALS['table']);
304 $truncate_table_url_params = array_merge(
305 $url_params,
306 array(
307 'sql_query' => $this_sql_query,
308 'goto' => 'tbl_structure.php',
309 'reload' => '1',
310 'message_to_show' => sprintf(
311 __('Table %s has been emptied'),
312 htmlspecialchars($table)
317 if (! (isset($db_is_information_schema) && $db_is_information_schema)) {
318 $this_sql_query = 'DROP TABLE '
319 . PMA_Util::backquote($GLOBALS['table']);
320 $drop_table_url_params = array_merge(
321 $url_params,
322 array(
323 'sql_query' => $this_sql_query,
324 'goto' => 'db_operations.php',
325 'reload' => '1',
326 'purge' => '1',
327 'message_to_show' => sprintf(
328 ($tbl_is_view
329 ? __('View %s has been dropped')
330 : __('Table %s has been dropped')
332 htmlspecialchars($table)
334 // table name is needed to avoid running
335 // PMA_relationsCleanupDatabase() on the whole db later
336 'table' => $GLOBALS['table'],
340 $response->addHTML(
341 PMA_getHtmlForDeleteDataOrTable(
342 $truncate_table_url_params,
343 $drop_table_url_params
347 $response->addHTML('<br class="clearfloat">');
349 if (PMA_Partition::havePartitioning()) {
350 $partition_names = PMA_Partition::getPartitionNames($db, $table);
351 // show the Partition maintenance section only if we detect a partition
352 if (! is_null($partition_names[0])) {
353 $response->addHTML(
354 PMA_getHtmlForPartitionMaintenance($partition_names, $url_params)
356 } // end if
357 } // end if
358 unset($partition_names);
360 // Referential integrity check
361 // The Referential integrity check was intended for the non-InnoDB
362 // tables for which the relations are defined in pmadb
363 // so I assume that if the current table is InnoDB, I don't display
364 // this choice (InnoDB maintains integrity by itself)
366 if ($cfgRelation['relwork'] && ! $is_innodb) {
367 PMA_DBI_select_db($GLOBALS['db']);
368 $foreign = PMA_getForeigners($GLOBALS['db'], $GLOBALS['table']);
370 if ($foreign) {
371 $response->addHTML(
372 PMA_getHtmlForReferentialIntegrityCheck($foreign, $url_params)
374 } // end if ($foreign)
376 } // end if (!empty($cfg['Server']['relation']))