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('sql.js');
85 $scripts->addFile('table/change.js');
86 $scripts->addFile('vendor/jquery/additional-methods.js');
87 $scripts->addFile('gis_data_editor.js');
90 * Displays the query submitted and its result
92 * $disp_message come from tbl_replace.php
94 if (! empty($disp_message)) {
95 $response->addHTML(Util
::getMessage($disp_message, null));
98 $table_columns = $insertEdit->getTableColumns($db, $table);
100 // retrieve keys into foreign fields, if any
101 /** @var Relation $relation */
102 $relation = $containerBuilder->get('relation');
103 $foreigners = $relation->getForeigners($db, $table);
105 // Retrieve form parameters for insert/edit form
106 $_form_params = $insertEdit->getFormParametersForInsertForm(
117 // autocomplete feature of IE kills the "onchange" event handler and it
118 // must be replaced by the "onpropertychange" one in this case
119 $chg_evt_handler = 'onchange';
120 // Had to put the URI because when hosted on an https server,
121 // some browsers send wrongly this form to the http server.
124 // Set if we passed the first timestamp field
125 $timestamp_seen = false;
126 $columns_cnt = count($table_columns);
129 $tabindex_for_function = +
3000;
130 $tabindex_for_null = +
6000;
131 $tabindex_for_value = 0;
133 $biggest_max_file_size = 0;
135 $url_params['db'] = $db;
136 $url_params['table'] = $table;
137 $url_params = $insertEdit->urlParamsInEditMode(
143 $has_blob_field = false;
144 foreach ($table_columns as $column) {
145 if ($insertEdit->isColumn(
154 $has_blob_field = true;
160 //If table has blob fields we have to disable ajax.
161 $html_output .= $insertEdit->getHtmlForInsertEditFormHeader($has_blob_field, $is_upload);
163 $html_output .= Url
::getHiddenInputs($_form_params);
165 $titles['Browse'] = Util
::getIcon('b_browse', __('Browse foreign values'));
167 // user can toggle the display of Function column and column types
168 // (currently does not work for multi-edits)
169 if (! $cfg['ShowFunctionFields'] ||
! $cfg['ShowFieldTypesInDataEditView']) {
170 $html_output .= __('Show');
173 if (! $cfg['ShowFunctionFields']) {
174 $html_output .= $insertEdit->showTypeOrFunction('function', $url_params, false);
177 if (! $cfg['ShowFieldTypesInDataEditView']) {
178 $html_output .= $insertEdit->showTypeOrFunction('type', $url_params, false);
181 $GLOBALS['plugin_scripts'] = [];
182 foreach ($rows as $row_id => $current_row) {
183 if (empty($current_row)) {
188 $vkey = '[multi_edit][' . $jsvkey . ']';
190 $current_result = (isset($result) && is_array($result) && isset($result[$row_id])
195 if (isset($unsaved_values[$row_id])) {
196 $repopulate = $unsaved_values[$row_id];
199 if ($insert_mode && $row_id > 0) {
200 $html_output .= $insertEdit->getHtmlForIgnoreOption($row_id, $checked);
203 $html_output .= $insertEdit->getHtmlForInsertEditRow(
218 $tabindex_for_function,
226 $biggest_max_file_size,
231 } // end foreach on multi-edit
232 $scripts->addFiles($GLOBALS['plugin_scripts']);
233 unset($unsaved_values, $checked, $repopulate, $GLOBALS['plugin_scripts']);
235 if (! isset($after_insert)) {
236 $after_insert = 'back';
240 $html_output .= $insertEdit->getActionsPanel(
248 if ($biggest_max_file_size > 0) {
250 . Util
::generateHiddenMaxFileSize(
251 $biggest_max_file_size
254 $html_output .= '</form>';
256 $html_output .= $insertEdit->getHtmlForGisEditor();
257 // end Insert/Edit form
260 //Continue insertion form
261 $html_output .= $insertEdit->getContinueInsertionForm(
269 $response->addHTML($html_output);