Translated using Weblate (Ukrainian)
[phpmyadmin.git] / tbl_change.php
blob478b12f1bba5a84247896ba1f164fe6624748fd2
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 use PMA\libraries\config\PageSettings;
9 use PMA\libraries\Response;
10 use PMA\libraries\Util;
11 use PMA\libraries\URL;
13 /**
14 * Gets the variables sent or posted to this script and displays the header
16 require_once 'libraries/common.inc.php';
17 require_once 'libraries/config/user_preferences.forms.php';
18 require_once 'libraries/config/page_settings.forms.php';
20 PageSettings::showGroup('Edit');
22 /**
23 * Ensures db and table are valid, else moves to the "parent" script
25 require_once 'libraries/db_table_exists.inc.php';
27 /**
28 * functions implementation for this script
30 require_once 'libraries/insert_edit.lib.php';
31 require_once 'libraries/transformations.lib.php';
33 /**
34 * Determine whether Insert or Edit and set global variables
36 list(
37 $insert_mode, $where_clause, $where_clause_array, $where_clauses,
38 $result, $rows, $found_unique_key, $after_insert
39 ) = PMA_determineInsertOrEdit(
40 isset($where_clause) ? $where_clause : null, $db, $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);
46 /**
47 * file listing
49 require_once 'libraries/file_listing.lib.php';
51 /**
52 * Defines the url to return to in case of error in a sql statement
53 * (at this point, $GLOBALS['goto'] will be set but could be empty)
55 if (empty($GLOBALS['goto'])) {
56 if (strlen($table) > 0) {
57 // avoid a problem (see bug #2202709)
58 $GLOBALS['goto'] = 'tbl_sql.php';
59 } else {
60 $GLOBALS['goto'] = 'db_sql.php';
65 $_url_params = PMA_getUrlParameters($db, $table);
66 $err_url = $GLOBALS['goto'] . URL::getCommon($_url_params);
67 unset($_url_params);
69 $comments_map = PMA_getCommentsMap($db, $table);
71 /**
72 * START REGULAR OUTPUT
75 /**
76 * Load JavaScript files
78 $response = Response::getInstance();
79 $header = $response->getHeader();
80 $scripts = $header->getScripts();
81 $scripts->addFile('sql.js');
82 $scripts->addFile('tbl_change.js');
83 $scripts->addFile('jquery/jquery-ui-timepicker-addon.js');
84 $scripts->addFile('jquery/jquery.validate.js');
85 $scripts->addFile('jquery/additional-methods.js');
86 $scripts->addFile('gis_data_editor.js');
88 /**
89 * Displays the query submitted and its result
91 * $disp_message come from tbl_replace.php
93 if (! empty($disp_message)) {
94 $response->addHTML(Util::getMessage($disp_message, null));
97 $table_columns = PMA_getTableColumns($db, $table);
99 // retrieve keys into foreign fields, if any
100 $foreigners = PMA_getForeigners($db, $table);
102 // Retrieve form parameters for insert/edit form
103 $_form_params = PMA_getFormParametersForInsertForm(
104 $db, $table, $where_clauses, $where_clause_array, $err_url
108 * Displays the form
110 // autocomplete feature of IE kills the "onchange" event handler and it
111 // must be replaced by the "onpropertychange" one in this case
112 $chg_evt_handler = 'onchange';
113 // Had to put the URI because when hosted on an https server,
114 // some browsers send wrongly this form to the http server.
116 $html_output = '';
117 // Set if we passed the first timestamp field
118 $timestamp_seen = false;
119 $columns_cnt = count($table_columns);
121 $tabindex = 0;
122 $tabindex_for_function = +3000;
123 $tabindex_for_null = +6000;
124 $tabindex_for_value = 0;
125 $o_rows = 0;
126 $biggest_max_file_size = 0;
128 $url_params['db'] = $db;
129 $url_params['table'] = $table;
130 $url_params = PMA_urlParamsInEditMode(
131 $url_params, $where_clause_array, $where_clause
134 $has_blob_field = false;
135 foreach ($table_columns as $column) {
136 if (PMA_isColumn(
137 $column,
138 array('blob', 'tinyblob', 'mediumblob', 'longblob')
139 )) {
140 $has_blob_field = true;
141 break;
145 //Insert/Edit form
146 //If table has blob fields we have to disable ajax.
147 $html_output .= PMA_getHtmlForInsertEditFormHeader($has_blob_field, $is_upload);
149 $html_output .= URL::getHiddenInputs($_form_params);
151 $titles['Browse'] = Util::getIcon('b_browse.png', __('Browse foreign values'));
153 // user can toggle the display of Function column and column types
154 // (currently does not work for multi-edits)
155 if (! $cfg['ShowFunctionFields'] || ! $cfg['ShowFieldTypesInDataEditView']) {
156 $html_output .= __('Show');
159 if (! $cfg['ShowFunctionFields']) {
160 $html_output .= PMA_showTypeOrFunction('function', $url_params, false);
163 if (! $cfg['ShowFieldTypesInDataEditView']) {
164 $html_output .= PMA_showTypeOrFunction('type', $url_params, false);
167 $GLOBALS['plugin_scripts'] = array();
168 foreach ($rows as $row_id => $current_row) {
169 if (empty($current_row)) {
170 $current_row = array();
173 $jsvkey = $row_id;
174 $vkey = '[multi_edit][' . $jsvkey . ']';
176 $current_result = (isset($result) && is_array($result) && isset($result[$row_id])
177 ? $result[$row_id]
178 : $result);
179 $repopulate = array();
180 $checked = true;
181 if (isset($unsaved_values[$row_id])) {
182 $repopulate = $unsaved_values[$row_id];
183 $checked = false;
185 if ($insert_mode && $row_id > 0) {
186 $html_output .= PMA_getHtmlForIgnoreOption($row_id, $checked);
189 $html_output .= PMA_getHtmlForInsertEditRow(
190 $url_params, $table_columns, $comments_map, $timestamp_seen,
191 $current_result, $chg_evt_handler, $jsvkey, $vkey, $insert_mode,
192 $current_row, $o_rows, $tabindex, $columns_cnt,
193 $is_upload, $tabindex_for_function, $foreigners, $tabindex_for_null,
194 $tabindex_for_value, $table, $db, $row_id, $titles,
195 $biggest_max_file_size, $text_dir, $repopulate, $where_clause_array
197 } // end foreach on multi-edit
198 $scripts->addFiles($GLOBALS['plugin_scripts']);
199 unset($unsaved_values, $checked, $repopulate, $GLOBALS['plugin_scripts']);
201 if (! isset($after_insert)) {
202 $after_insert = 'back';
205 //action panel
206 $html_output .= PMA_getActionsPanel(
207 $where_clause, $after_insert, $tabindex,
208 $tabindex_for_value, $found_unique_key
211 if ($biggest_max_file_size > 0) {
212 $html_output .= ' '
213 . Util::generateHiddenMaxFileSize(
214 $biggest_max_file_size
215 ) . "\n";
217 $html_output .= '</form>';
219 $html_output .= PMA_getHtmlForGisEditor();
220 // end Insert/Edit form
222 if ($insert_mode) {
223 //Continue insertion form
224 $html_output .= PMA_getContinueInsertionForm(
225 $table, $db, $where_clause_array, $err_url
229 $response->addHTML($html_output);