Translated using Weblate (Estonian)
[phpmyadmin.git] / tbl_change.php
blob20804d89bb6cc608fd7ed1b96101bcfc1f0999ea
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\InsertEdit;
12 use PhpMyAdmin\Relation;
13 use PhpMyAdmin\Response;
14 use PhpMyAdmin\Util;
15 use PhpMyAdmin\Url;
17 /**
18 * Gets the variables sent or posted to this script and displays the header
20 require_once 'libraries/common.inc.php';
22 PageSettings::showGroup('Edit');
24 /**
25 * Ensures db and table are valid, else moves to the "parent" script
27 require_once 'libraries/db_table_exists.inc.php';
29 $insertEdit = new InsertEdit($GLOBALS['dbi']);
31 /**
32 * Determine whether Insert or Edit and set global variables
34 list(
35 $insert_mode, $where_clause, $where_clause_array, $where_clauses,
36 $result, $rows, $found_unique_key, $after_insert
37 ) = $insertEdit->determineInsertOrEdit(
38 isset($where_clause) ? $where_clause : null,
39 $db,
40 $table
42 // Increase number of rows if unsaved rows are more
43 if (!empty($unsaved_values) && count($rows) < count($unsaved_values)) {
44 $rows = array_fill(0, count($unsaved_values), false);
47 /**
48 * Defines the url to return to in case of error in a sql statement
49 * (at this point, $GLOBALS['goto'] will be set but could be empty)
51 if (empty($GLOBALS['goto'])) {
52 if (strlen($table) > 0) {
53 // avoid a problem (see bug #2202709)
54 $GLOBALS['goto'] = 'tbl_sql.php';
55 } else {
56 $GLOBALS['goto'] = 'db_sql.php';
61 $_url_params = $insertEdit->getUrlParameters($db, $table);
62 $err_url = $GLOBALS['goto'] . Url::getCommon($_url_params);
63 unset($_url_params);
65 $comments_map = $insertEdit->getCommentsMap($db, $table);
67 /**
68 * START REGULAR OUTPUT
71 /**
72 * Load JavaScript files
74 $response = Response::getInstance();
75 $header = $response->getHeader();
76 $scripts = $header->getScripts();
77 $scripts->addFile('sql.js');
78 $scripts->addFile('tbl_change.js');
79 $scripts->addFile('vendor/jquery/additional-methods.js');
80 $scripts->addFile('gis_data_editor.js');
82 /**
83 * Displays the query submitted and its result
85 * $disp_message come from tbl_replace.php
87 if (! empty($disp_message)) {
88 $response->addHTML(Util::getMessage($disp_message, null));
91 $table_columns = $insertEdit->getTableColumns($db, $table);
93 // retrieve keys into foreign fields, if any
94 $relation = new Relation();
95 $foreigners = $relation->getForeigners($db, $table);
97 // Retrieve form parameters for insert/edit form
98 $_form_params = $insertEdit->getFormParametersForInsertForm(
99 $db,
100 $table,
101 $where_clauses,
102 $where_clause_array,
103 $err_url
107 * Displays the form
109 // autocomplete feature of IE kills the "onchange" event handler and it
110 // must be replaced by the "onpropertychange" one in this case
111 $chg_evt_handler = 'onchange';
112 // Had to put the URI because when hosted on an https server,
113 // some browsers send wrongly this form to the http server.
115 $html_output = '';
116 // Set if we passed the first timestamp field
117 $timestamp_seen = false;
118 $columns_cnt = count($table_columns);
120 $tabindex = 0;
121 $tabindex_for_function = +3000;
122 $tabindex_for_null = +6000;
123 $tabindex_for_value = 0;
124 $o_rows = 0;
125 $biggest_max_file_size = 0;
127 $url_params['db'] = $db;
128 $url_params['table'] = $table;
129 $url_params = $insertEdit->urlParamsInEditMode(
130 $url_params,
131 $where_clause_array,
132 $where_clause
135 $has_blob_field = false;
136 foreach ($table_columns as $column) {
137 if ($insertEdit->isColumn(
138 $column,
139 ['blob', 'tinyblob', 'mediumblob', 'longblob']
140 )) {
141 $has_blob_field = true;
142 break;
146 //Insert/Edit form
147 //If table has blob fields we have to disable ajax.
148 $html_output .= $insertEdit->getHtmlForInsertEditFormHeader($has_blob_field, $is_upload);
150 $html_output .= Url::getHiddenInputs($_form_params);
152 $titles['Browse'] = Util::getIcon('b_browse', __('Browse foreign values'));
154 // user can toggle the display of Function column and column types
155 // (currently does not work for multi-edits)
156 if (! $cfg['ShowFunctionFields'] || ! $cfg['ShowFieldTypesInDataEditView']) {
157 $html_output .= __('Show');
160 if (! $cfg['ShowFunctionFields']) {
161 $html_output .= $insertEdit->showTypeOrFunction('function', $url_params, false);
164 if (! $cfg['ShowFieldTypesInDataEditView']) {
165 $html_output .= $insertEdit->showTypeOrFunction('type', $url_params, false);
168 $GLOBALS['plugin_scripts'] = [];
169 foreach ($rows as $row_id => $current_row) {
170 if (empty($current_row)) {
171 $current_row = [];
174 $jsvkey = $row_id;
175 $vkey = '[multi_edit][' . $jsvkey . ']';
177 $current_result = (isset($result) && is_array($result) && isset($result[$row_id])
178 ? $result[$row_id]
179 : $result);
180 $repopulate = [];
181 $checked = true;
182 if (isset($unsaved_values[$row_id])) {
183 $repopulate = $unsaved_values[$row_id];
184 $checked = false;
186 if ($insert_mode && $row_id > 0) {
187 $html_output .= $insertEdit->getHtmlForIgnoreOption($row_id, $checked);
190 $html_output .= $insertEdit->getHtmlForInsertEditRow(
191 $url_params,
192 $table_columns,
193 $comments_map,
194 $timestamp_seen,
195 $current_result,
196 $chg_evt_handler,
197 $jsvkey,
198 $vkey,
199 $insert_mode,
200 $current_row,
201 $o_rows,
202 $tabindex,
203 $columns_cnt,
204 $is_upload,
205 $tabindex_for_function,
206 $foreigners,
207 $tabindex_for_null,
208 $tabindex_for_value,
209 $table,
210 $db,
211 $row_id,
212 $titles,
213 $biggest_max_file_size,
214 $text_dir,
215 $repopulate,
216 $where_clause_array
218 } // end foreach on multi-edit
219 $scripts->addFiles($GLOBALS['plugin_scripts']);
220 unset($unsaved_values, $checked, $repopulate, $GLOBALS['plugin_scripts']);
222 if (! isset($after_insert)) {
223 $after_insert = 'back';
226 //action panel
227 $html_output .= $insertEdit->getActionsPanel(
228 $where_clause,
229 $after_insert,
230 $tabindex,
231 $tabindex_for_value,
232 $found_unique_key
235 if ($biggest_max_file_size > 0) {
236 $html_output .= ' '
237 . Util::generateHiddenMaxFileSize(
238 $biggest_max_file_size
239 ) . "\n";
241 $html_output .= '</form>';
243 $html_output .= $insertEdit->getHtmlForGisEditor();
244 // end Insert/Edit form
246 if ($insert_mode) {
247 //Continue insertion form
248 $html_output .= $insertEdit->getContinueInsertionForm(
249 $table,
250 $db,
251 $where_clause_array,
252 $err_url
256 $response->addHTML($html_output);