2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Displays form for editing and inserting new table rows
8 declare(strict_types
=1);
10 use PhpMyAdmin\Config\PageSettings
;
11 use PhpMyAdmin\InsertEdit
;
12 use PhpMyAdmin\Relation
;
13 use PhpMyAdmin\Response
;
18 * Gets the variables sent or posted to this script and displays the header
20 require_once 'libraries/common.inc.php';
22 PageSettings
::showGroup('Edit');
25 * Ensures db and table are valid, else moves to the "parent" script
27 require_once 'libraries/db_table_exists.inc.php';
29 $insertEdit = new InsertEdit($GLOBALS['dbi']);
32 * Determine whether Insert or Edit and set global variables
35 $insert_mode, $where_clause, $where_clause_array, $where_clauses,
36 $result, $rows, $found_unique_key, $after_insert
37 ) = $insertEdit->determineInsertOrEdit(
38 isset($where_clause) ?
$where_clause : null,
42 // Increase number of rows if unsaved rows are more
43 if (!empty($unsaved_values) && count($rows) < count($unsaved_values)) {
44 $rows = array_fill(0, count($unsaved_values), false);
48 * Defines the url to return to in case of error in a sql statement
49 * (at this point, $GLOBALS['goto'] will be set but could be empty)
51 if (empty($GLOBALS['goto'])) {
52 if (strlen($table) > 0) {
53 // avoid a problem (see bug #2202709)
54 $GLOBALS['goto'] = 'tbl_sql.php';
56 $GLOBALS['goto'] = 'db_sql.php';
61 $_url_params = $insertEdit->getUrlParameters($db, $table);
62 $err_url = $GLOBALS['goto'] . Url
::getCommon($_url_params);
65 $comments_map = $insertEdit->getCommentsMap($db, $table);
68 * START REGULAR OUTPUT
72 * Load JavaScript files
74 $response = Response
::getInstance();
75 $header = $response->getHeader();
76 $scripts = $header->getScripts();
77 $scripts->addFile('sql.js');
78 $scripts->addFile('tbl_change.js');
79 $scripts->addFile('vendor/jquery/additional-methods.js');
80 $scripts->addFile('gis_data_editor.js');
83 * Displays the query submitted and its result
85 * $disp_message come from tbl_replace.php
87 if (! empty($disp_message)) {
88 $response->addHTML(Util
::getMessage($disp_message, null));
91 $table_columns = $insertEdit->getTableColumns($db, $table);
93 // retrieve keys into foreign fields, if any
94 $relation = new Relation($GLOBALS['dbi']);
95 $foreigners = $relation->getForeigners($db, $table);
97 // Retrieve form parameters for insert/edit form
98 $_form_params = $insertEdit->getFormParametersForInsertForm(
109 // autocomplete feature of IE kills the "onchange" event handler and it
110 // must be replaced by the "onpropertychange" one in this case
111 $chg_evt_handler = 'onchange';
112 // Had to put the URI because when hosted on an https server,
113 // some browsers send wrongly this form to the http server.
116 // Set if we passed the first timestamp field
117 $timestamp_seen = false;
118 $columns_cnt = count($table_columns);
121 $tabindex_for_function = +
3000;
122 $tabindex_for_null = +
6000;
123 $tabindex_for_value = 0;
125 $biggest_max_file_size = 0;
127 $url_params['db'] = $db;
128 $url_params['table'] = $table;
129 $url_params = $insertEdit->urlParamsInEditMode(
135 $has_blob_field = false;
136 foreach ($table_columns as $column) {
137 if ($insertEdit->isColumn(
139 ['blob', 'tinyblob', 'mediumblob', 'longblob']
141 $has_blob_field = true;
147 //If table has blob fields we have to disable ajax.
148 $html_output .= $insertEdit->getHtmlForInsertEditFormHeader($has_blob_field, $is_upload);
150 $html_output .= Url
::getHiddenInputs($_form_params);
152 $titles['Browse'] = Util
::getIcon('b_browse', __('Browse foreign values'));
154 // user can toggle the display of Function column and column types
155 // (currently does not work for multi-edits)
156 if (! $cfg['ShowFunctionFields'] ||
! $cfg['ShowFieldTypesInDataEditView']) {
157 $html_output .= __('Show');
160 if (! $cfg['ShowFunctionFields']) {
161 $html_output .= $insertEdit->showTypeOrFunction('function', $url_params, false);
164 if (! $cfg['ShowFieldTypesInDataEditView']) {
165 $html_output .= $insertEdit->showTypeOrFunction('type', $url_params, false);
168 $GLOBALS['plugin_scripts'] = [];
169 foreach ($rows as $row_id => $current_row) {
170 if (empty($current_row)) {
175 $vkey = '[multi_edit][' . $jsvkey . ']';
177 $current_result = (isset($result) && is_array($result) && isset($result[$row_id])
182 if (isset($unsaved_values[$row_id])) {
183 $repopulate = $unsaved_values[$row_id];
186 if ($insert_mode && $row_id > 0) {
187 $html_output .= $insertEdit->getHtmlForIgnoreOption($row_id, $checked);
190 $html_output .= $insertEdit->getHtmlForInsertEditRow(
205 $tabindex_for_function,
213 $biggest_max_file_size,
218 } // end foreach on multi-edit
219 $scripts->addFiles($GLOBALS['plugin_scripts']);
220 unset($unsaved_values, $checked, $repopulate, $GLOBALS['plugin_scripts']);
222 if (! isset($after_insert)) {
223 $after_insert = 'back';
227 $html_output .= $insertEdit->getActionsPanel(
235 if ($biggest_max_file_size > 0) {
237 . Util
::generateHiddenMaxFileSize(
238 $biggest_max_file_size
241 $html_output .= '</form>';
243 $html_output .= $insertEdit->getHtmlForGisEditor();
244 // end Insert/Edit form
247 //Continue insertion form
248 $html_output .= $insertEdit->getContinueInsertionForm(
256 $response->addHTML($html_output);