Translated using Weblate (Japanese)
[phpmyadmin.git] / tbl_change.php
blob0cd26130606827349d150dc2e4576d19602e9c5e
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('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');
91 /**
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(
109 $db,
110 $table,
111 $where_clauses,
112 $where_clause_array,
113 $err_url
117 * Displays the form
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.
125 $html_output = '';
126 // Set if we passed the first timestamp field
127 $timestamp_seen = false;
128 $columns_cnt = count($table_columns);
130 $tabindex = 0;
131 $tabindex_for_function = +3000;
132 $tabindex_for_null = +6000;
133 $tabindex_for_value = 0;
134 $o_rows = 0;
135 $biggest_max_file_size = 0;
137 $url_params['db'] = $db;
138 $url_params['table'] = $table;
139 $url_params = $insertEdit->urlParamsInEditMode(
140 $url_params,
141 $where_clause_array
144 $has_blob_field = false;
145 foreach ($table_columns as $column) {
146 if ($insertEdit->isColumn(
147 $column,
149 'blob',
150 'tinyblob',
151 'mediumblob',
152 'longblob',
154 )) {
155 $has_blob_field = true;
156 break;
160 //Insert/Edit form
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)) {
185 $current_row = [];
188 $jsvkey = $row_id;
189 $vkey = '[multi_edit][' . $jsvkey . ']';
191 $current_result = (isset($result) && is_array($result) && isset($result[$row_id])
192 ? $result[$row_id]
193 : $result);
194 $repopulate = [];
195 $checked = true;
196 if (isset($unsaved_values[$row_id])) {
197 $repopulate = $unsaved_values[$row_id];
198 $checked = false;
200 if ($insert_mode && $row_id > 0) {
201 $html_output .= $insertEdit->getHtmlForIgnoreOption($row_id, $checked);
204 $html_output .= $insertEdit->getHtmlForInsertEditRow(
205 $url_params,
206 $table_columns,
207 $comments_map,
208 $timestamp_seen,
209 $current_result,
210 $chg_evt_handler,
211 $jsvkey,
212 $vkey,
213 $insert_mode,
214 $current_row,
215 $o_rows,
216 $tabindex,
217 $columns_cnt,
218 $is_upload,
219 $tabindex_for_function,
220 $foreigners,
221 $tabindex_for_null,
222 $tabindex_for_value,
223 $table,
224 $db,
225 $row_id,
226 $titles,
227 $biggest_max_file_size,
228 $text_dir,
229 $repopulate,
230 $where_clause_array
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';
240 //action panel
241 $html_output .= $insertEdit->getActionsPanel(
242 $where_clause,
243 $after_insert,
244 $tabindex,
245 $tabindex_for_value,
246 $found_unique_key
249 if ($biggest_max_file_size > 0) {
250 $html_output .= ' '
251 . Util::generateHiddenMaxFileSize(
252 $biggest_max_file_size
253 ) . "\n";
255 $html_output .= '</form>';
257 $html_output .= $insertEdit->getHtmlForGisEditor();
258 // end Insert/Edit form
260 if ($insert_mode) {
261 //Continue insertion form
262 $html_output .= $insertEdit->getContinueInsertionForm(
263 $table,
264 $db,
265 $where_clause_array,
266 $err_url
270 $response->addHTML($html_output);