Translated using Weblate (Japanese)
[phpmyadmin.git] / tbl_change.php
blobb5de613b2c13a11a31acb12c5e2adc3c67c5e20d
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Displays form for editing and inserting new table rows
6 * register_globals_save (mark this file save for disabling register globals)
8 * @package PhpMyAdmin
9 */
11 /**
12 * Gets the variables sent or posted to this script and displays the header
14 require_once 'libraries/common.inc.php';
16 /**
17 * Ensures db and table are valid, else moves to the "parent" script
19 require_once 'libraries/db_table_exists.lib.php';
21 /**
22 * functions implementation for this script
24 require_once 'libraries/insert_edit.lib.php';
26 /**
27 * Determine whether Insert or Edit and set global variables
29 list(
30 $insert_mode, $where_clause, $where_clause_array, $where_clauses,
31 $result, $rows, $found_unique_key, $after_insert
32 ) = PMA_determineInsertOrEdit($where_clause, $db, $table);
34 /**
35 * file listing
37 require_once 'libraries/file_listing.lib.php';
39 /**
40 * Defines the url to return to in case of error in a sql statement
41 * (at this point, $GLOBALS['goto'] will be set but could be empty)
43 if (empty($GLOBALS['goto'])) {
44 if (strlen($table)) {
45 // avoid a problem (see bug #2202709)
46 $GLOBALS['goto'] = 'tbl_sql.php';
47 } else {
48 $GLOBALS['goto'] = 'db_sql.php';
53 $_url_params = PMA_getUrlParameters($db, $table);
54 $err_url = $GLOBALS['goto'] . PMA_URL_getCommon($_url_params);
55 unset($_url_params);
57 $comments_map = PMA_getCommentsMap($db, $table);
59 /**
60 * START REGULAR OUTPUT
63 /**
64 * Load JavaScript files
66 $response = PMA_Response::getInstance();
67 $header = $response->getHeader();
68 $scripts = $header->getScripts();
69 $scripts->addFile('functions.js');
70 $scripts->addFile('tbl_change.js');
71 $scripts->addFile('jquery/jquery-ui-timepicker-addon.js');
72 $scripts->addFile('gis_data_editor.js');
74 /**
75 * Displays the query submitted and its result
77 * $disp_message come from tbl_replace.php
79 if (! empty($disp_message)) {
80 $response->addHTML(PMA_Util::getMessage($disp_message, null));
84 $table_columns = PMA_getTableColumns($db, $table);
86 // retrieve keys into foreign fields, if any
87 $foreigners = PMA_getForeigners($db, $table);
89 // Retrieve form parameters for insert/edit form
90 $_form_params = PMA_getFormParametersForInsertForm(
91 $db, $table, $where_clauses, $where_clause_array, $err_url
94 /**
95 * Displays the form
97 // autocomplete feature of IE kills the "onchange" event handler and it
98 // must be replaced by the "onpropertychange" one in this case
99 $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE'
100 && PMA_USR_BROWSER_VER >= 5
101 && PMA_USR_BROWSER_VER < 7
103 ? 'onpropertychange'
104 : 'onchange';
105 // Had to put the URI because when hosted on an https server,
106 // some browsers send wrongly this form to the http server.
108 $html_output = '';
109 // Set if we passed the first timestamp field
110 $timestamp_seen = false;
111 $columns_cnt = count($table_columns);
113 $tabindex = 0;
114 $tabindex_for_function = +3000;
115 $tabindex_for_null = +6000;
116 $tabindex_for_value = 0;
117 $o_rows = 0;
118 $biggest_max_file_size = 0;
120 $url_params['db'] = $db;
121 $url_params['table'] = $table;
122 $url_params = PMA_urlParamsInEditMode(
123 $url_params, $where_clause_array, $where_clause
126 //Insert/Edit form
127 //If table has blob fields we have to disable ajax.
128 $has_blob_field = false;
129 foreach ($table_columns as $column) {
130 if (PMA_isColumnBlob($column)) {
131 $has_blob_field = true;
132 break;
135 $html_output .='<form id="insertForm" ';
136 if ($has_blob_field && $is_upload) {
137 $html_output .='class="disableAjax" ';
139 $html_output .='method="post" action="tbl_replace.php" name="insertForm" ';
140 if ($is_upload) {
141 $html_output .= ' enctype="multipart/form-data"';
143 $html_output .= '>';
144 $html_output .= PMA_URL_getHiddenInputs($_form_params);
146 $titles['Browse'] = PMA_Util::getIcon('b_browse.png', __('Browse foreign values'));
148 // user can toggle the display of Function column and column types
149 // (currently does not work for multi-edits)
150 if (! $cfg['ShowFunctionFields'] || ! $cfg['ShowFieldTypesInDataEditView']) {
151 $html_output .= __('Show');
154 if (! $cfg['ShowFunctionFields']) {
155 $html_output .= PMA_showFunctionFieldsInEditMode($url_params, false);
158 if (! $cfg['ShowFieldTypesInDataEditView']) {
159 $html_output .= PMA_showColumnTypesInDataEditView($url_params, false);
162 foreach ($rows as $row_id => $current_row) {
163 if ($current_row === false) {
164 unset($current_row);
167 $jsvkey = $row_id;
168 $rownumber_param = '&amp;rownumber=' . $row_id;
169 $vkey = '[multi_edit][' . $jsvkey . ']';
171 $current_result = (isset($result) && is_array($result) && isset($result[$row_id])
172 ? $result[$row_id]
173 : $result);
174 if ($insert_mode && $row_id > 0) {
175 $html_output .= '<input type="checkbox" checked="checked"'
176 . ' name="insert_ignore_' . $row_id . '"'
177 . ' id="insert_ignore_' . $row_id . '" />'
178 .'<label for="insert_ignore_' . $row_id . '">'
179 . __('Ignore')
180 . '</label><br />' . "\n";
183 $html_output .= PMA_getHeadAndFootOfInsertRowTable($url_params)
184 . '<tbody>';
186 // Sets a multiplier used for input-field counts
187 // (as zero cannot be used, advance the counter plus one)
188 $m_rows = $o_rows + 1;
189 //store the default value for CharEditing
190 $default_char_editing = $cfg['CharEditing'];
192 $odd_row = true;
193 for ($i = 0; $i < $columns_cnt; $i++) {
194 if (! isset($table_columns[$i]['processed'])) {
195 $column = $table_columns[$i];
196 $column = PMA_analyzeTableColumnsArray(
197 $column, $comments_map, $timestamp_seen
201 $extracted_columnspec
202 = PMA_Util::extractColumnSpec($column['Type']);
204 if (-1 === $column['len']) {
205 $column['len'] = $GLOBALS['dbi']->fieldLen($current_result, $i);
206 // length is unknown for geometry fields,
207 // make enough space to edit very simple WKTs
208 if (-1 === $column['len']) {
209 $column['len'] = 30;
212 //Call validation when the form submited...
213 $unnullify_trigger = $chg_evt_handler
214 . "=\"return verificationsAfterFieldChange('"
215 . PMA_escapeJsString($column['Field_md5']) . "', '"
216 . PMA_escapeJsString($jsvkey) . "','".$column['pma_type'] . "')\"";
218 // Use an MD5 as an array index to avoid having special characters
219 // in the name atttibute (see bug #1746964 )
220 $column_name_appendix = $vkey . '[' . $column['Field_md5'] . ']';
222 if ($column['Type'] == 'datetime'
223 && ! isset($column['Default'])
224 && ! is_null($column['Default'])
225 && ($insert_mode || ! isset($current_row[$column['Field']]))
227 // INSERT case or
228 // UPDATE case with an NULL value
229 $current_row[$column['Field']] = date('Y-m-d H:i:s', time());
232 $html_output .= '<tr class="noclick ' . ($odd_row ? 'odd' : 'even' ) . '">'
233 . '<td ' . ($cfg['LongtextDoubleTextarea'] && strstr($column['True_Type'], 'longtext') ? 'rowspan="2"' : '') . 'class="center">'
234 . $column['Field_title']
235 . '<input type="hidden" name="fields_name' . $column_name_appendix . '" value="' . $column['Field_html'] . '"/>'
236 . '</td>';
237 if ($cfg['ShowFieldTypesInDataEditView']) {
238 $html_output .= '<td class="center' . $column['wrap'] . '">'
239 . '<span class="column_type">' . $column['pma_type'] . '</span>'
240 . '</td>';
241 } //End if
243 // Get a list of GIS data types.
244 $gis_data_types = PMA_Util::getGISDatatypes();
246 // Prepares the field value
247 $real_null_value = false;
248 $special_chars_encoded = '';
249 if (isset($current_row)) {
250 // (we are editing)
251 list(
252 $real_null_value, $special_chars_encoded, $special_chars,
253 $data, $backup_field
255 = PMA_getSpecialCharsAndBackupFieldForExistingRow(
256 $current_row, $column, $extracted_columnspec,
257 $real_null_value, $gis_data_types, $column_name_appendix
259 } else {
260 // (we are inserting)
261 // display default values
262 list($real_null_value, $data, $special_chars, $backup_field, $special_chars_encoded)
263 = PMA_getSpecialCharsAndBackupFieldForInsertingMode($column, $real_null_value);
266 $idindex = ($o_rows * $columns_cnt) + $i + 1;
267 $tabindex = $idindex;
269 // Get a list of data types that are not yet supported.
270 $no_support_types = PMA_Util::unsupportedDatatypes();
272 // The function column
273 // -------------------
274 if ($cfg['ShowFunctionFields']) {
275 $html_output .= PMA_getFunctionColumn(
276 $column, $is_upload, $column_name_appendix,
277 $unnullify_trigger, $no_support_types, $tabindex_for_function,
278 $tabindex, $idindex, $insert_mode
282 // The null column
283 // ---------------
284 $foreignData = PMA_getForeignData(
285 $foreigners, $column['Field'], false, '', ''
287 $html_output .= PMA_getNullColumn(
288 $column, $column_name_appendix, $real_null_value,
289 $tabindex, $tabindex_for_null, $idindex, $vkey, $foreigners,
290 $foreignData
293 // The value column (depends on type)
294 // ----------------
295 // See bug #1667887 for the reason why we don't use the maxlength
296 // HTML attribute
297 $html_output .= ' <td>' . "\n";
298 // Will be used by js/tbl_change.js to set the default value
299 // for the "Continue insertion" feature
300 $html_output .= '<span class="default_value hide">'
301 . $special_chars . '</span>';
303 $html_output .= PMA_getValueColumn(
304 $column, $backup_field, $column_name_appendix, $unnullify_trigger,
305 $tabindex, $tabindex_for_value, $idindex, $data, $special_chars,
306 $foreignData, $odd_row, array($table, $db), $rownumber_param, $titles,
307 $text_dir, $special_chars_encoded, $vkey, $is_upload,
308 $biggest_max_file_size, $default_char_editing,
309 $no_support_types, $gis_data_types, $extracted_columnspec
312 $html_output .= '</td>'
313 . '</tr>';
315 $odd_row = !$odd_row;
316 } // end for
317 $o_rows++;
318 $html_output .= ' </tbody>'
319 . '</table><br />';
320 } // end foreach on multi-edit
322 $html_output .='<div id="gis_editor"></div>'
323 . '<div id="popup_background"></div>'
324 . '<br />';
326 if (! isset($after_insert)) {
327 $after_insert = 'back';
330 //action panel
331 $html_output .= PMA_getActionsPanel(
332 $where_clause, $after_insert, $tabindex,
333 $tabindex_for_value, $found_unique_key
336 if ($biggest_max_file_size > 0) {
337 $html_output .= ' '
338 . PMA_Util::generateHiddenMaxFileSize(
339 $biggest_max_file_size
340 ) . "\n";
342 $html_output .= '</form>';
343 // end Insert/Edit form
345 if ($insert_mode) {
346 //Continue insertion form
347 $html_output .= PMA_getContinueInsertionForm(
348 $table, $db, $where_clause_array, $err_url
351 $response->addHTML($html_output);