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\Di\Container
;
13 use PhpMyAdmin\InsertEdit
;
14 use PhpMyAdmin\Relation
;
15 use PhpMyAdmin\Response
;
19 if (! defined('ROOT_PATH')) {
20 define('ROOT_PATH', __DIR__
. DIRECTORY_SEPARATOR
);
23 global $cfg, $db, $table, $text_dir;
25 require_once ROOT_PATH
. 'libraries/common.inc.php';
27 $container = Container
::getDefaultContainer();
28 $container->set(Response
::class, Response
::getInstance());
30 /** @var Response $response */
31 $response = $container->get(Response
::class);
33 /** @var DatabaseInterface $dbi */
34 $dbi = $container->get(DatabaseInterface
::class);
36 PageSettings
::showGroup('Edit');
39 * Ensures db and table are valid, else moves to the "parent" script
41 require_once ROOT_PATH
. 'libraries/db_table_exists.inc.php';
43 $insertEdit = new InsertEdit($dbi);
46 * Determine whether Insert or Edit and set global variables
49 $insert_mode, $where_clause, $where_clause_array, $where_clauses,
50 $result, $rows, $found_unique_key, $after_insert
51 ) = $insertEdit->determineInsertOrEdit(
52 isset($where_clause) ?
$where_clause : null,
56 // Increase number of rows if unsaved rows are more
57 if (! empty($unsaved_values) && count($rows) < count($unsaved_values)) {
58 $rows = array_fill(0, count($unsaved_values), false);
62 * Defines the url to return to in case of error in a sql statement
63 * (at this point, $GLOBALS['goto'] will be set but could be empty)
65 if (empty($GLOBALS['goto'])) {
66 if (strlen($table) > 0) {
67 // avoid a problem (see bug #2202709)
68 $GLOBALS['goto'] = 'tbl_sql.php';
70 $GLOBALS['goto'] = 'db_sql.php';
75 $_url_params = $insertEdit->getUrlParameters($db, $table);
76 $err_url = $GLOBALS['goto'] . Url
::getCommon($_url_params);
79 $comments_map = $insertEdit->getCommentsMap($db, $table);
82 * START REGULAR OUTPUT
85 $header = $response->getHeader();
86 $scripts = $header->getScripts();
87 $scripts->addFile('sql.js');
88 $scripts->addFile('tbl_change.js');
89 $scripts->addFile('vendor/jquery/additional-methods.js');
90 $scripts->addFile('gis_data_editor.js');
93 * Displays the query submitted and its result
95 * $disp_message come from tbl_replace.php
97 if (! empty($disp_message)) {
98 $response->addHTML(Util
::getMessage($disp_message, null));
101 $table_columns = $insertEdit->getTableColumns($db, $table);
103 // retrieve keys into foreign fields, if any
104 /** @var Relation $relation */
105 $relation = $containerBuilder->get('relation');
106 $foreigners = $relation->getForeigners($db, $table);
108 // Retrieve form parameters for insert/edit form
109 $_form_params = $insertEdit->getFormParametersForInsertForm(
120 // autocomplete feature of IE kills the "onchange" event handler and it
121 // must be replaced by the "onpropertychange" one in this case
122 $chg_evt_handler = 'onchange';
123 // Had to put the URI because when hosted on an https server,
124 // some browsers send wrongly this form to the http server.
127 // Set if we passed the first timestamp field
128 $timestamp_seen = false;
129 $columns_cnt = count($table_columns);
132 $tabindex_for_function = +
3000;
133 $tabindex_for_null = +
6000;
134 $tabindex_for_value = 0;
136 $biggest_max_file_size = 0;
138 $url_params['db'] = $db;
139 $url_params['table'] = $table;
140 $url_params = $insertEdit->urlParamsInEditMode(
146 $has_blob_field = false;
147 foreach ($table_columns as $column) {
148 if ($insertEdit->isColumn(
157 $has_blob_field = true;
163 //If table has blob fields we have to disable ajax.
164 $html_output .= $insertEdit->getHtmlForInsertEditFormHeader($has_blob_field, $is_upload);
166 $html_output .= Url
::getHiddenInputs($_form_params);
168 $titles['Browse'] = Util
::getIcon('b_browse', __('Browse foreign values'));
170 // user can toggle the display of Function column and column types
171 // (currently does not work for multi-edits)
172 if (! $cfg['ShowFunctionFields'] ||
! $cfg['ShowFieldTypesInDataEditView']) {
173 $html_output .= __('Show');
176 if (! $cfg['ShowFunctionFields']) {
177 $html_output .= $insertEdit->showTypeOrFunction('function', $url_params, false);
180 if (! $cfg['ShowFieldTypesInDataEditView']) {
181 $html_output .= $insertEdit->showTypeOrFunction('type', $url_params, false);
184 $GLOBALS['plugin_scripts'] = [];
185 foreach ($rows as $row_id => $current_row) {
186 if (empty($current_row)) {
191 $vkey = '[multi_edit][' . $jsvkey . ']';
193 $current_result = (isset($result) && is_array($result) && isset($result[$row_id])
198 if (isset($unsaved_values[$row_id])) {
199 $repopulate = $unsaved_values[$row_id];
202 if ($insert_mode && $row_id > 0) {
203 $html_output .= $insertEdit->getHtmlForIgnoreOption($row_id, $checked);
206 $html_output .= $insertEdit->getHtmlForInsertEditRow(
221 $tabindex_for_function,
229 $biggest_max_file_size,
234 } // end foreach on multi-edit
235 $scripts->addFiles($GLOBALS['plugin_scripts']);
236 unset($unsaved_values, $checked, $repopulate, $GLOBALS['plugin_scripts']);
238 if (! isset($after_insert)) {
239 $after_insert = 'back';
243 $html_output .= $insertEdit->getActionsPanel(
251 if ($biggest_max_file_size > 0) {
253 . Util
::generateHiddenMaxFileSize(
254 $biggest_max_file_size
257 $html_output .= '</form>';
259 $html_output .= $insertEdit->getHtmlForGisEditor();
260 // end Insert/Edit form
263 //Continue insertion form
264 $html_output .= $insertEdit->getContinueInsertionForm(
272 $response->addHTML($html_output);