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\DatabaseInterface
;
12 use PhpMyAdmin\InsertEdit
;
13 use PhpMyAdmin\Relation
;
14 use PhpMyAdmin\Response
;
18 if (! defined('ROOT_PATH')) {
19 define('ROOT_PATH', __DIR__
. DIRECTORY_SEPARATOR
);
22 global $cfg, $containerBuilder, $db, $table, $text_dir;
24 require_once ROOT_PATH
. 'libraries/common.inc.php';
26 /** @var Response $response */
27 $response = $containerBuilder->get(Response
::class);
29 /** @var DatabaseInterface $dbi */
30 $dbi = $containerBuilder->get(DatabaseInterface
::class);
32 PageSettings
::showGroup('Edit');
35 * Ensures db and table are valid, else moves to the "parent" script
37 require_once ROOT_PATH
. 'libraries/db_table_exists.inc.php';
39 /** @var InsertEdit $insertEdit */
40 $insertEdit = $containerBuilder->get('insert_edit');
43 * Determine whether Insert or Edit and set global variables
46 $insert_mode, $where_clause, $where_clause_array, $where_clauses,
47 $result, $rows, $found_unique_key, $after_insert
48 ) = $insertEdit->determineInsertOrEdit(
49 isset($where_clause) ?
$where_clause : null,
53 // Increase number of rows if unsaved rows are more
54 if (! empty($unsaved_values) && count($rows) < count($unsaved_values)) {
55 $rows = array_fill(0, count($unsaved_values), false);
59 * Defines the url to return to in case of error in a sql statement
60 * (at this point, $GLOBALS['goto'] will be set but could be empty)
62 if (empty($GLOBALS['goto'])) {
63 if (strlen($table) > 0) {
64 // avoid a problem (see bug #2202709)
65 $GLOBALS['goto'] = 'tbl_sql.php';
67 $GLOBALS['goto'] = 'db_sql.php';
72 $_url_params = $insertEdit->getUrlParameters($db, $table);
73 $err_url = $GLOBALS['goto'] . Url
::getCommon($_url_params);
76 $comments_map = $insertEdit->getCommentsMap($db, $table);
79 * START REGULAR OUTPUT
82 $header = $response->getHeader();
83 $scripts = $header->getScripts();
84 $scripts->addFile('makegrid.js');
85 $scripts->addFile('vendor/stickyfill.min.js');
86 $scripts->addFile('sql.js');
87 $scripts->addFile('table/change.js');
88 $scripts->addFile('vendor/jquery/additional-methods.js');
89 $scripts->addFile('gis_data_editor.js');
92 * Displays the query submitted and its result
94 * $disp_message come from tbl_replace.php
96 if (! empty($disp_message)) {
97 $response->addHTML(Util
::getMessage($disp_message, null));
100 $table_columns = $insertEdit->getTableColumns($db, $table);
102 // retrieve keys into foreign fields, if any
103 /** @var Relation $relation */
104 $relation = $containerBuilder->get('relation');
105 $foreigners = $relation->getForeigners($db, $table);
107 // Retrieve form parameters for insert/edit form
108 $_form_params = $insertEdit->getFormParametersForInsertForm(
119 // autocomplete feature of IE kills the "onchange" event handler and it
120 // must be replaced by the "onpropertychange" one in this case
121 $chg_evt_handler = 'onchange';
122 // Had to put the URI because when hosted on an https server,
123 // some browsers send wrongly this form to the http server.
126 // Set if we passed the first timestamp field
127 $timestamp_seen = false;
128 $columns_cnt = count($table_columns);
131 $tabindex_for_function = +
3000;
132 $tabindex_for_null = +
6000;
133 $tabindex_for_value = 0;
135 $biggest_max_file_size = 0;
137 $url_params['db'] = $db;
138 $url_params['table'] = $table;
139 $url_params = $insertEdit->urlParamsInEditMode(
144 $has_blob_field = false;
145 foreach ($table_columns as $column) {
146 if ($insertEdit->isColumn(
155 $has_blob_field = true;
161 //If table has blob fields we have to disable ajax.
162 $html_output .= $insertEdit->getHtmlForInsertEditFormHeader($has_blob_field, $is_upload);
164 $html_output .= Url
::getHiddenInputs($_form_params);
166 $titles['Browse'] = Util
::getIcon('b_browse', __('Browse foreign values'));
168 // user can toggle the display of Function column and column types
169 // (currently does not work for multi-edits)
170 if (! $cfg['ShowFunctionFields'] ||
! $cfg['ShowFieldTypesInDataEditView']) {
171 $html_output .= __('Show');
174 if (! $cfg['ShowFunctionFields']) {
175 $html_output .= $insertEdit->showTypeOrFunction('function', $url_params, false);
178 if (! $cfg['ShowFieldTypesInDataEditView']) {
179 $html_output .= $insertEdit->showTypeOrFunction('type', $url_params, false);
182 $GLOBALS['plugin_scripts'] = [];
183 foreach ($rows as $row_id => $current_row) {
184 if (empty($current_row)) {
189 $vkey = '[multi_edit][' . $jsvkey . ']';
191 $current_result = (isset($result) && is_array($result) && isset($result[$row_id])
196 if (isset($unsaved_values[$row_id])) {
197 $repopulate = $unsaved_values[$row_id];
200 if ($insert_mode && $row_id > 0) {
201 $html_output .= $insertEdit->getHtmlForIgnoreOption($row_id, $checked);
204 $html_output .= $insertEdit->getHtmlForInsertEditRow(
219 $tabindex_for_function,
227 $biggest_max_file_size,
232 } // end foreach on multi-edit
233 $scripts->addFiles($GLOBALS['plugin_scripts']);
234 unset($unsaved_values, $checked, $repopulate, $GLOBALS['plugin_scripts']);
236 if (! isset($after_insert)) {
237 $after_insert = 'back';
241 $html_output .= $insertEdit->getActionsPanel(
249 if ($biggest_max_file_size > 0) {
251 . Util
::generateHiddenMaxFileSize(
252 $biggest_max_file_size
255 $html_output .= '</form>';
257 $html_output .= $insertEdit->getHtmlForGisEditor();
258 // end Insert/Edit form
261 //Continue insertion form
262 $html_output .= $insertEdit->getContinueInsertionForm(
270 $response->addHTML($html_output);