📄 tbl_change.php
字号:
<?php/* vim: set expandtab sw=4 ts=4 sts=4: *//** * Displays form for editing and inserting new table rows * * register_globals_save (mark this file save for disabling register globals) * * @version $Id: tbl_change.php 12164 2009-01-01 21:44:37Z lem9 $ *//** * Gets the variables sent or posted to this script and displays the header */require_once './libraries/common.inc.php';/** * Ensures db and table are valid, else moves to the "parent" script */require_once './libraries/db_table_exists.lib.php';/** * Sets global variables. * Here it's better to use a if, instead of the '?' operator * to avoid setting a variable to '' when it's not present in $_REQUEST *//** * @todo this one is badly named, it's really a WHERE condition * and exists even for tables not having a primary key or unique key */if (isset($_REQUEST['primary_key'])) { $primary_key = $_REQUEST['primary_key'];}if (isset($_SESSION['edit_next'])) { $primary_key = $_SESSION['edit_next']; unset($_SESSION['edit_next']); $after_insert = 'edit_next';}if (isset($_REQUEST['sql_query'])) { $sql_query = $_REQUEST['sql_query'];}if (isset($_REQUEST['ShowFunctionFields'])) { $cfg['ShowFunctionFields'] = $_REQUEST['ShowFunctionFields'];}/** * load relation data, foreign keys */require_once './libraries/relation.lib.php';/** * file listing */require_once './libraries/file_listing.php';/** * Defines the url to return to in case of error in a sql statement * (at this point, $GLOBALS['goto'] will be set but could be empty) */if (empty($GLOBALS['goto'])) { if (strlen($table)) { // avoid a problem (see bug #2202709) $GLOBALS['goto'] = 'tbl_sql.php'; } else { $GLOBALS['goto'] = 'db_sql.php'; }}/** * @todo check if we could replace by "db_|tbl_" - please clarify!? */$_url_params = array( 'db' => $db, 'sql_query' => $sql_query);if (preg_match('@^tbl_@', $GLOBALS['goto'])) { $_url_params['table'] = $table;}$err_url = $GLOBALS['goto'] . PMA_generate_common_url($_url_params);unset($_url_params);/** * Sets parameters for links * where is this variable used? * replace by PMA_generate_common_url($url_params); */$url_query = PMA_generate_common_url($url_params, 'html', '');/** * get table information * @todo should be done by a Table object */require_once './libraries/tbl_info.inc.php';/** * Get comments for table fileds/columns */$comments_map = array();if ($GLOBALS['cfg']['ShowPropertyComments']) { $comments_map = PMA_getComments($db, $table);}/** * START REGULAR OUTPUT *//** * used in ./libraries/header.inc.php to load JavaScript library file */$GLOBALS['js_include'][] = 'tbl_change.js';/** * HTTP and HTML headers */require_once './libraries/header.inc.php';/** * Displays the query submitted and its result * * @todo where does $disp_message and $disp_query come from??? */if (! empty($disp_message)) { if (! isset($disp_query)) { $disp_query = null; } PMA_showMessage($disp_message, $disp_query);}/** * Displays top menu links */require_once './libraries/tbl_links.inc.php';/** * Get the analysis of SHOW CREATE TABLE for this table * @todo should be handled by class Table */$show_create_table = PMA_DBI_fetch_value( 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table), 0, 1);$analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));unset($show_create_table);/** * Get the list of the fields of the current table */PMA_DBI_select_db($db);$table_fields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, null, null, PMA_DBI_QUERY_STORE);$rows = array();if (isset($primary_key)) { // when in edit mode load all selected rows from table $insert_mode = false; if (is_array($primary_key)) { $primary_key_array = $primary_key; } else { $primary_key_array = array(0 => $primary_key); } $result = array(); $found_unique_key = false; foreach ($primary_key_array as $key_id => $primary_key) { $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';'; $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE); $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]); $primary_keys[$key_id] = str_replace('\\', '\\\\', $primary_key); // No row returned if (! $rows[$key_id]) { unset($rows[$key_id], $primary_key_array[$key_id]); PMA_showMessage($strEmptyResultSet, $local_query); echo "\n"; require_once './libraries/footer.inc.php'; } else { // end if (no record returned) $meta = PMA_DBI_get_fields_meta($result[$key_id]); if ($tmp = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true)) { $found_unique_key = true; } unset($tmp); } }} else { // no primary key given, just load first row - but what happens if tbale is empty? $insert_mode = true; $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE); $rows = array_fill(0, $cfg['InsertRows'], false);}// <markus@noga.de>// retrieve keys into foreign fields, if any$foreigners = PMA_getForeigners($db, $table);/** * Displays the form */// loic1: autocomplete feature of IE kills the "onchange" event handler and it// must be replaced by the "onpropertychange" one in this case$chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5 && PMA_USR_BROWSER_VER < 7) ? 'onpropertychange' : 'onchange';// Had to put the URI because when hosted on an https server,// some browsers send wrongly this form to the http server.if ($cfg['CtrlArrowsMoving']) { ?><!-- Set on key handler for moving using by Ctrl+arrows --><script src="./js/keyhandler.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[var switch_movement = 0;document.onkeydown = onKeyDownArrowsHandler;//]]></script> <?php}$_form_params = array( 'db' => $db, 'table' => $table, 'goto' => $GLOBALS['goto'], 'err_url' => $err_url, 'sql_query' => $sql_query,);if (isset($primary_keys)) { foreach ($primary_key_array as $key_id => $primary_key) { $_form_params['primary_key[' . $key_id . ']'] = trim($primary_key); }}?><!-- Insert/Edit form --><form method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?>><?phpecho PMA_generate_common_hidden_inputs($_form_params);$titles['Browse'] = PMA_getIcon('b_browse.png', $strBrowseForeignValues);// Set if we passed the first timestamp field$timestamp_seen = 0;$fields_cnt = count($table_fields);$tabindex = 0;$tabindex_for_function = +3000;$tabindex_for_null = +6000;$tabindex_for_value = 0;$o_rows = 0;$biggest_max_file_size = 0;// user can toggle the display of Function column// (currently does not work for multi-edits)$url_params['db'] = $db;$url_params['table'] = $table;if (isset($primary_key)) { $url_params['primary_key'] = trim($primary_key);}if (! empty($sql_query)) { $url_params['sql_query'] = $sql_query;}if (! $cfg['ShowFunctionFields']) { $this_url_params = array_merge($url_params, array('ShowFunctionFields' => 1)); echo $strShow . ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . $strFunction . '</a>' . "\n";}foreach ($rows as $row_id => $vrow) { if ($vrow === false) { unset($vrow); } $jsvkey = $row_id; $browse_foreigners_uri = '&pk=' . $row_id; $vkey = '[multi_edit][' . $jsvkey . ']'; $vresult = (isset($result) && is_array($result) && isset($result[$row_id]) ? $result[$row_id] : $result); if ($insert_mode && $row_id > 0) { echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $row_id . '" id="insert_ignore_check_' . $row_id . '" />'; echo '<label for="insert_ignore_check_' . $row_id . '">' . $strIgnore . '</label><br />' . "\n"; }?> <table> <thead> <tr> <th><?php echo $strField; ?></th> <th><?php echo $strType; ?></th><?php if ($cfg['ShowFunctionFields']) { $this_url_params = array_merge($url_params,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -