Adding composer lock for 5.0.0-rc1
[phpmyadmin.git] / tbl_change.php
blob35bff5c8abed5b7ca64d5f425d6481c7a58ab699
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Displays form for editing and inserting new table rows
6 * @package PhpMyAdmin
7 */
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;
15 use PhpMyAdmin\Url;
16 use PhpMyAdmin\Util;
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');
34 /**
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');
42 /**
43 * Determine whether Insert or Edit and set global variables
45 list(
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,
50 $db,
51 $table
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);
58 /**
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';
66 } else {
67 $GLOBALS['goto'] = 'db_sql.php';
72 $_url_params = $insertEdit->getUrlParameters($db, $table);
73 $err_url = $GLOBALS['goto'] . Url::getCommon($_url_params);
74 unset($_url_params);
76 $comments_map = $insertEdit->getCommentsMap($db, $table);
78 /**
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');
89 /**
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(
107 $db,
108 $table,
109 $where_clauses,
110 $where_clause_array,
111 $err_url
115 * Displays the form
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.
123 $html_output = '';
124 // Set if we passed the first timestamp field
125 $timestamp_seen = false;
126 $columns_cnt = count($table_columns);
128 $tabindex = 0;
129 $tabindex_for_function = +3000;
130 $tabindex_for_null = +6000;
131 $tabindex_for_value = 0;
132 $o_rows = 0;
133 $biggest_max_file_size = 0;
135 $url_params['db'] = $db;
136 $url_params['table'] = $table;
137 $url_params = $insertEdit->urlParamsInEditMode(
138 $url_params,
139 $where_clause_array,
140 $where_clause
143 $has_blob_field = false;
144 foreach ($table_columns as $column) {
145 if ($insertEdit->isColumn(
146 $column,
148 'blob',
149 'tinyblob',
150 'mediumblob',
151 'longblob',
153 )) {
154 $has_blob_field = true;
155 break;
159 //Insert/Edit form
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)) {
184 $current_row = [];
187 $jsvkey = $row_id;
188 $vkey = '[multi_edit][' . $jsvkey . ']';
190 $current_result = (isset($result) && is_array($result) && isset($result[$row_id])
191 ? $result[$row_id]
192 : $result);
193 $repopulate = [];
194 $checked = true;
195 if (isset($unsaved_values[$row_id])) {
196 $repopulate = $unsaved_values[$row_id];
197 $checked = false;
199 if ($insert_mode && $row_id > 0) {
200 $html_output .= $insertEdit->getHtmlForIgnoreOption($row_id, $checked);
203 $html_output .= $insertEdit->getHtmlForInsertEditRow(
204 $url_params,
205 $table_columns,
206 $comments_map,
207 $timestamp_seen,
208 $current_result,
209 $chg_evt_handler,
210 $jsvkey,
211 $vkey,
212 $insert_mode,
213 $current_row,
214 $o_rows,
215 $tabindex,
216 $columns_cnt,
217 $is_upload,
218 $tabindex_for_function,
219 $foreigners,
220 $tabindex_for_null,
221 $tabindex_for_value,
222 $table,
223 $db,
224 $row_id,
225 $titles,
226 $biggest_max_file_size,
227 $text_dir,
228 $repopulate,
229 $where_clause_array
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';
239 //action panel
240 $html_output .= $insertEdit->getActionsPanel(
241 $where_clause,
242 $after_insert,
243 $tabindex,
244 $tabindex_for_value,
245 $found_unique_key
248 if ($biggest_max_file_size > 0) {
249 $html_output .= ' '
250 . Util::generateHiddenMaxFileSize(
251 $biggest_max_file_size
252 ) . "\n";
254 $html_output .= '</form>';
256 $html_output .= $insertEdit->getHtmlForGisEditor();
257 // end Insert/Edit form
259 if ($insert_mode) {
260 //Continue insertion form
261 $html_output .= $insertEdit->getContinueInsertionForm(
262 $table,
263 $db,
264 $where_clause_array,
265 $err_url
269 $response->addHTML($html_output);