Improve create-release script to handle QA branches higher than QA_4_8.
[phpmyadmin.git] / tbl_change.php
blob9db9765239e97a437abb976cdfdbc16eebbc09d9
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\Di\Container;
13 use PhpMyAdmin\InsertEdit;
14 use PhpMyAdmin\Relation;
15 use PhpMyAdmin\Response;
16 use PhpMyAdmin\Util;
17 use PhpMyAdmin\Url;
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');
38 /**
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);
45 /**
46 * Determine whether Insert or Edit and set global variables
48 list(
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,
53 $db,
54 $table
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);
61 /**
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';
69 } else {
70 $GLOBALS['goto'] = 'db_sql.php';
75 $_url_params = $insertEdit->getUrlParameters($db, $table);
76 $err_url = $GLOBALS['goto'] . Url::getCommon($_url_params);
77 unset($_url_params);
79 $comments_map = $insertEdit->getCommentsMap($db, $table);
81 /**
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');
92 /**
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(
110 $db,
111 $table,
112 $where_clauses,
113 $where_clause_array,
114 $err_url
118 * Displays the form
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.
126 $html_output = '';
127 // Set if we passed the first timestamp field
128 $timestamp_seen = false;
129 $columns_cnt = count($table_columns);
131 $tabindex = 0;
132 $tabindex_for_function = +3000;
133 $tabindex_for_null = +6000;
134 $tabindex_for_value = 0;
135 $o_rows = 0;
136 $biggest_max_file_size = 0;
138 $url_params['db'] = $db;
139 $url_params['table'] = $table;
140 $url_params = $insertEdit->urlParamsInEditMode(
141 $url_params,
142 $where_clause_array,
143 $where_clause
146 $has_blob_field = false;
147 foreach ($table_columns as $column) {
148 if ($insertEdit->isColumn(
149 $column,
151 'blob',
152 'tinyblob',
153 'mediumblob',
154 'longblob',
156 )) {
157 $has_blob_field = true;
158 break;
162 //Insert/Edit form
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)) {
187 $current_row = [];
190 $jsvkey = $row_id;
191 $vkey = '[multi_edit][' . $jsvkey . ']';
193 $current_result = (isset($result) && is_array($result) && isset($result[$row_id])
194 ? $result[$row_id]
195 : $result);
196 $repopulate = [];
197 $checked = true;
198 if (isset($unsaved_values[$row_id])) {
199 $repopulate = $unsaved_values[$row_id];
200 $checked = false;
202 if ($insert_mode && $row_id > 0) {
203 $html_output .= $insertEdit->getHtmlForIgnoreOption($row_id, $checked);
206 $html_output .= $insertEdit->getHtmlForInsertEditRow(
207 $url_params,
208 $table_columns,
209 $comments_map,
210 $timestamp_seen,
211 $current_result,
212 $chg_evt_handler,
213 $jsvkey,
214 $vkey,
215 $insert_mode,
216 $current_row,
217 $o_rows,
218 $tabindex,
219 $columns_cnt,
220 $is_upload,
221 $tabindex_for_function,
222 $foreigners,
223 $tabindex_for_null,
224 $tabindex_for_value,
225 $table,
226 $db,
227 $row_id,
228 $titles,
229 $biggest_max_file_size,
230 $text_dir,
231 $repopulate,
232 $where_clause_array
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';
242 //action panel
243 $html_output .= $insertEdit->getActionsPanel(
244 $where_clause,
245 $after_insert,
246 $tabindex,
247 $tabindex_for_value,
248 $found_unique_key
251 if ($biggest_max_file_size > 0) {
252 $html_output .= ' '
253 . Util::generateHiddenMaxFileSize(
254 $biggest_max_file_size
255 ) . "\n";
257 $html_output .= '</form>';
259 $html_output .= $insertEdit->getHtmlForGisEditor();
260 // end Insert/Edit form
262 if ($insert_mode) {
263 //Continue insertion form
264 $html_output .= $insertEdit->getContinueInsertionForm(
265 $table,
266 $db,
267 $where_clause_array,
268 $err_url
272 $response->addHTML($html_output);