Translation update done using Pootle.
[phpmyadmin/crack.git] / tbl_change.php
blobd77ae864db87f0f660a29180027ad6a8973e56e4
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 * Sets global variables.
23 * Here it's better to use a if, instead of the '?' operator
24 * to avoid setting a variable to '' when it's not present in $_REQUEST
26 if (isset($_REQUEST['where_clause'])) {
27 $where_clause = $_REQUEST['where_clause'];
29 if (isset($_REQUEST['clause_is_unique'])) {
30 $clause_is_unique = $_REQUEST['clause_is_unique'];
32 if (isset($_SESSION['edit_next'])) {
33 $where_clause = $_SESSION['edit_next'];
34 unset($_SESSION['edit_next']);
35 $after_insert = 'edit_next';
37 if (isset($_REQUEST['sql_query'])) {
38 $sql_query = $_REQUEST['sql_query'];
40 if (isset($_REQUEST['ShowFunctionFields'])) {
41 $cfg['ShowFunctionFields'] = $_REQUEST['ShowFunctionFields'];
43 if (isset($_REQUEST['ShowFieldTypesInDataEditView'])) {
44 $cfg['ShowFieldTypesInDataEditView'] = $_REQUEST['ShowFieldTypesInDataEditView'];
47 /**
48 * file listing
50 require_once './libraries/file_listing.php';
53 /**
54 * Defines the url to return to in case of error in a sql statement
55 * (at this point, $GLOBALS['goto'] will be set but could be empty)
57 if (empty($GLOBALS['goto'])) {
58 if (strlen($table)) {
59 // avoid a problem (see bug #2202709)
60 $GLOBALS['goto'] = 'tbl_sql.php';
61 } else {
62 $GLOBALS['goto'] = 'db_sql.php';
65 /**
66 * @todo check if we could replace by "db_|tbl_" - please clarify!?
68 $_url_params = array(
69 'db' => $db,
70 'sql_query' => $sql_query
73 if (preg_match('@^tbl_@', $GLOBALS['goto'])) {
74 $_url_params['table'] = $table;
77 $err_url = $GLOBALS['goto'] . PMA_generate_common_url($_url_params);
78 unset($_url_params);
81 /**
82 * Sets parameters for links
83 * where is this variable used?
84 * replace by PMA_generate_common_url($url_params);
86 $url_query = PMA_generate_common_url($url_params, 'html', '');
88 /**
89 * get table information
90 * @todo should be done by a Table object
92 require_once './libraries/tbl_info.inc.php';
94 /**
95 * Get comments for table fileds/columns
97 $comments_map = array();
99 if ($GLOBALS['cfg']['ShowPropertyComments']) {
100 $comments_map = PMA_getComments($db, $table);
104 * START REGULAR OUTPUT
108 * used in ./libraries/header.inc.php to load JavaScript library file
110 $GLOBALS['js_include'][] = 'functions.js';
111 $GLOBALS['js_include'][] = 'tbl_change.js';
112 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
113 $GLOBALS['js_include'][] = 'jquery/timepicker.js';
115 * HTTP and HTML headers
117 require_once './libraries/header.inc.php';
120 * Displays the query submitted and its result
122 * @todo where does $disp_message and $disp_query come from???
124 if (! empty($disp_message)) {
125 if (! isset($disp_query)) {
126 $disp_query = null;
128 PMA_showMessage($disp_message, $disp_query);
132 * Displays top menu links
134 require_once './libraries/tbl_links.inc.php';
138 * Get the analysis of SHOW CREATE TABLE for this table
139 * @todo should be handled by class Table
141 $show_create_table = PMA_DBI_fetch_value(
142 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
143 0, 1);
144 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
145 unset($show_create_table);
148 * Get the list of the fields of the current table
150 PMA_DBI_select_db($db);
151 $table_fields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ';',
152 null, null, null, PMA_DBI_QUERY_STORE);
153 $rows = array();
154 if (isset($where_clause)) {
155 // when in edit mode load all selected rows from table
156 $insert_mode = false;
157 if (is_array($where_clause)) {
158 $where_clause_array = $where_clause;
159 } else {
160 $where_clause_array = array(0 => $where_clause);
163 $result = array();
164 $found_unique_key = false;
165 $where_clauses = array();
167 foreach ($where_clause_array as $key_id => $where_clause) {
168 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $where_clause . ';';
169 $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE);
170 $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]);
171 $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause);
173 // No row returned
174 if (! $rows[$key_id]) {
175 unset($rows[$key_id], $where_clause_array[$key_id]);
176 PMA_showMessage(__('MySQL returned an empty result set (i.e. zero rows).'), $local_query);
177 echo "\n";
178 require './libraries/footer.inc.php';
179 } else { // end if (no row returned)
180 $meta = PMA_DBI_get_fields_meta($result[$key_id]);
181 list($unique_condition, $tmp_clause_is_unique) = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true);
182 if (! empty($unique_condition)) {
183 $found_unique_key = true;
185 unset($unique_condition, $tmp_clause_is_unique);
188 } else {
189 // no primary key given, just load first row - but what happens if table is empty?
190 $insert_mode = true;
191 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
192 $rows = array_fill(0, $cfg['InsertRows'], false);
195 // retrieve keys into foreign fields, if any
196 $foreigners = PMA_getForeigners($db, $table);
200 * Displays the form
202 // autocomplete feature of IE kills the "onchange" event handler and it
203 // must be replaced by the "onpropertychange" one in this case
204 $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5 && PMA_USR_BROWSER_VER < 7)
205 ? 'onpropertychange'
206 : 'onchange';
207 // Had to put the URI because when hosted on an https server,
208 // some browsers send wrongly this form to the http server.
211 <!-- Set on key handler for moving using by Ctrl+arrows -->
212 <script src="./js/keyhandler.js" type="text/javascript"></script>
213 <script type="text/javascript">
214 //<![CDATA[
215 var switch_movement = 0;
216 document.onkeydown = onKeyDownArrowsHandler;
217 //]]>
218 </script>
219 <?php
221 $_form_params = array(
222 'db' => $db,
223 'table' => $table,
224 'goto' => $GLOBALS['goto'],
225 'err_url' => $err_url,
226 'sql_query' => $sql_query,
228 if (isset($where_clauses)) {
229 foreach ($where_clause_array as $key_id => $where_clause) {
230 $_form_params['where_clause[' . $key_id . ']'] = trim($where_clause);
233 if (isset($clause_is_unique)) {
234 $_form_params['clause_is_unique'] = $clause_is_unique;
239 <!-- Insert/Edit form -->
240 <form id="insertForm" method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?>>
241 <?php
242 echo PMA_generate_common_hidden_inputs($_form_params);
244 $titles['Browse'] = PMA_getIcon('b_browse.png', __('Browse foreign values'));
246 // Set if we passed the first timestamp field
247 $timestamp_seen = 0;
248 $fields_cnt = count($table_fields);
250 $tabindex = 0;
251 $tabindex_for_function = +3000;
252 $tabindex_for_null = +6000;
253 $tabindex_for_value = 0;
254 $o_rows = 0;
255 $biggest_max_file_size = 0;
257 // user can toggle the display of Function column
258 // (currently does not work for multi-edits)
259 $url_params['db'] = $db;
260 $url_params['table'] = $table;
261 if (isset($where_clause)) {
262 $url_params['where_clause'] = trim($where_clause);
264 if (! empty($sql_query)) {
265 $url_params['sql_query'] = $sql_query;
268 if (! $cfg['ShowFunctionFields'] || ! $cfg['ShowFieldTypesInDataEditView']) {
269 echo __('Show');
271 if (! $cfg['ShowFunctionFields']) {
272 $this_url_params = array_merge($url_params,
273 array('ShowFunctionFields' => 1, 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'], 'goto' => 'sql.php'));
274 echo ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . __('Function') . '</a>' . "\n";
276 if (! $cfg['ShowFieldTypesInDataEditView']) {
277 $this_other_url_params = array_merge($url_params,
278 array('ShowFieldTypesInDataEditView' => 1, 'ShowFunctionFields' => $cfg['ShowFunctionFields'], 'goto' => 'sql.php'));
279 echo ' : <a href="tbl_change.php' . PMA_generate_common_url($this_other_url_params) . '">' . __('Type') . '</a>' . "\n";
282 foreach ($rows as $row_id => $vrow) {
283 if ($vrow === false) {
284 unset($vrow);
287 $jsvkey = $row_id;
288 $rownumber_param = '&amp;rownumber=' . $row_id;
289 $vkey = '[multi_edit][' . $jsvkey . ']';
291 $vresult = (isset($result) && is_array($result) && isset($result[$row_id]) ? $result[$row_id] : $result);
292 if ($insert_mode && $row_id > 0) {
293 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $row_id . '" id="insert_ignore_' . $row_id . '" />';
294 echo '<label for="insert_ignore_' . $row_id . '">' . __('Ignore') . '</label><br />' . "\n";
297 <table class="insertRowTable">
298 <thead>
299 <tr>
300 <th><?php echo __('Column'); ?></th>
302 <?php
303 if ($cfg['ShowFieldTypesInDataEditView']) {
304 $this_url_params = array_merge($url_params,
305 array('ShowFieldTypesInDataEditView' => 0, 'ShowFunctionFields' => $cfg['ShowFunctionFields'], 'goto' => 'sql.php'));
306 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . __('Hide') . '">' . __('Type') . '</a></th>' . "\n";
309 if ($cfg['ShowFunctionFields']) {
310 $this_url_params = array_merge($url_params,
311 array('ShowFunctionFields' => 0, 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'], 'goto' => 'sql.php'));
312 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . __('Hide') . '">' . __('Function') . '</a></th>' . "\n";
315 <th><?php echo __('Null'); ?></th>
316 <th><?php echo __('Value'); ?></th>
317 </tr>
318 </thead>
319 <tfoot>
320 <tr>
321 <th colspan="5" align="right" class="tblFooters">
322 <input type="submit" value="<?php echo __('Go'); ?>" />
323 </th>
324 </tr>
325 </tfoot>
326 <tbody>
327 <?php
328 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
329 $m_rows = $o_rows + 1;
331 $odd_row = true;
332 for ($i = 0; $i < $fields_cnt; $i++) {
333 if (! isset($table_fields[$i]['processed'])) {
334 $table_fields[$i]['Field_html'] = htmlspecialchars($table_fields[$i]['Field']);
335 $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']);
336 // True_Type contains only the type (stops at first bracket)
337 $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']);
339 // d a t e t i m e
341 // Current date should not be set as default if the field is NULL
342 // for the current row, but do not put here the current datetime
343 // if there is a default value (the real default value will be set
344 // in the Default value logic below)
346 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
347 // $field['Default'] is not set if it contains NULL:
348 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime)
349 // but, look what we get if we switch to iso: (Default is NULL)
350 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime)
351 // so I force a NULL into it (I don't think it's possible
352 // to have an empty default value for DATETIME)
353 // then, the "if" after this one will work
354 if ($table_fields[$i]['Type'] == 'datetime'
355 && ! isset($table_fields[$i]['Default'])
356 && isset($table_fields[$i]['Null'])
357 && $table_fields[$i]['Null'] == 'YES') {
358 $table_fields[$i]['Default'] = null;
361 $table_fields[$i]['len'] =
362 preg_match('@float|double@', $table_fields[$i]['Type']) ? 100 : -1;
365 if (isset($comments_map[$table_fields[$i]['Field']])) {
366 $table_fields[$i]['Field_title'] = '<span style="border-bottom: 1px dashed black;" title="'
367 . htmlspecialchars($comments_map[$table_fields[$i]['Field']]) . '">'
368 . $table_fields[$i]['Field_html'] . '</span>';
369 } else {
370 $table_fields[$i]['Field_title'] = $table_fields[$i]['Field_html'];
373 // The type column.
374 // Fix for bug #3152931 'ENUM and SET cannot have "Binary" option'
375 // If check to ensure types such as "enum('one','two','binary',..)" or
376 // "enum('one','two','varbinary',..)" are not categorized as binary.
377 if (stripos($table_fields[$i]['Type'], 'binary') === 0
378 || stripos($table_fields[$i]['Type'], 'varbinary') === 0) {
379 $table_fields[$i]['is_binary'] = stristr($table_fields[$i]['Type'], 'binary');
380 } else {
381 $table_fields[$i]['is_binary'] = false;
384 // If check to ensure types such as "enum('one','two','blob',..)" or
385 // "enum('one','two','tinyblob',..)" etc. are not categorized as blob.
386 if (stripos($table_fields[$i]['Type'], 'blob') === 0
387 || stripos($table_fields[$i]['Type'], 'tinyblob') === 0
388 || stripos($table_fields[$i]['Type'], 'mediumblob') === 0
389 || stripos($table_fields[$i]['Type'], 'longblob') === 0) {
390 $table_fields[$i]['is_blob'] = stristr($table_fields[$i]['Type'], 'blob');
391 } else {
392 $table_fields[$i]['is_blob'] = false;
395 // If check to ensure types such as "enum('one','two','char',..)" or
396 // "enum('one','two','varchar',..)" are not categorized as char.
397 if (stripos($table_fields[$i]['Type'], 'char') === 0
398 || stripos($table_fields[$i]['Type'], 'varchar') === 0) {
399 $table_fields[$i]['is_char'] = stristr($table_fields[$i]['Type'], 'char');
400 } else {
401 $table_fields[$i]['is_char'] = false;
404 $table_fields[$i]['first_timestamp'] = false;
405 switch ($table_fields[$i]['True_Type']) {
406 case 'set':
407 $table_fields[$i]['pma_type'] = 'set';
408 $table_fields[$i]['wrap'] = '';
409 break;
410 case 'enum':
411 $table_fields[$i]['pma_type'] = 'enum';
412 $table_fields[$i]['wrap'] = '';
413 break;
414 case 'timestamp':
415 if (!$timestamp_seen) { // can only occur once per table
416 $timestamp_seen = 1;
417 $table_fields[$i]['first_timestamp'] = true;
419 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
420 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
421 break;
423 default:
424 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
425 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
426 break;
429 $field = $table_fields[$i];
430 $extracted_fieldspec = PMA_extractFieldSpec($field['Type']);
432 if (-1 === $field['len']) {
433 $field['len'] = PMA_DBI_field_len($vresult, $i);
435 //Call validation when the form submited...
436 $unnullify_trigger = $chg_evt_handler . "=\"return verificationsAfterFieldChange('". PMA_escapeJsString($field['Field_md5']) . "', '"
437 . PMA_escapeJsString($jsvkey) . "','".$field['pma_type']."')\"";
439 // Use an MD5 as an array index to avoid having special characters in the name atttibute (see bug #1746964 )
440 $field_name_appendix = $vkey . '[' . $field['Field_md5'] . ']';
442 if ($field['Type'] == 'datetime'
443 && ! isset($field['Default'])
444 && ! is_null($field['Default'])
445 && ($insert_mode || ! isset($vrow[$field['Field']]))) {
446 // INSERT case or
447 // UPDATE case with an NULL value
448 $vrow[$field['Field']] = date('Y-m-d H:i:s', time());
451 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
452 <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($field['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center">
453 <?php echo $field['Field_title']; ?>
454 <input type="hidden" name="fields_name<?php echo $field_name_appendix; ?>" value="<?php echo $field['Field_html']; ?>"/>
455 </td>
456 <?php if ($cfg['ShowFieldTypesInDataEditView']) { ?>
457 <td align="center"<?php echo $field['wrap']; ?>><span class="column_type"><?php echo $field['pma_type']; ?></span>
458 </td>
460 <?php } //End if
462 // Prepares the field value
463 $real_null_value = FALSE;
464 $special_chars_encoded = '';
465 if (isset($vrow)) {
466 // (we are editing)
467 if (is_null($vrow[$field['Field']])) {
468 $real_null_value = TRUE;
469 $vrow[$field['Field']] = '';
470 $special_chars = '';
471 $data = $vrow[$field['Field']];
472 } elseif ($field['True_Type'] == 'bit') {
473 $special_chars = PMA_printable_bit_value($vrow[$field['Field']], $extracted_fieldspec['spec_in_brackets']);
474 } else {
475 // special binary "characters"
476 if ($field['is_binary'] || ($field['is_blob'] && ! $cfg['ProtectBinary'])) {
477 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
478 $vrow[$field['Field']] = bin2hex($vrow[$field['Field']]);
479 $field['display_binary_as_hex'] = true;
480 } else {
481 $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]);
483 } // end if
484 $special_chars = htmlspecialchars($vrow[$field['Field']]);
486 //We need to duplicate the first \n or otherwise we will lose the first newline entered in a VARCHAR or TEXT column
487 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
489 $data = $vrow[$field['Field']];
490 } // end if... else...
491 // If a timestamp field value is not included in an update
492 // statement MySQL auto-update it to the current timestamp;
493 // however, things have changed since MySQL 4.1, so
494 // it's better to set a fields_prev in this situation
495 $backup_field = '<input type="hidden" name="fields_prev'
496 . $field_name_appendix . '" value="'
497 . htmlspecialchars($vrow[$field['Field']]) . '" />';
498 } else {
499 // (we are inserting)
500 // display default values
501 if (!isset($field['Default'])) {
502 $field['Default'] = '';
503 $real_null_value = TRUE;
504 $data = '';
505 } else {
506 $data = $field['Default'];
508 if ($field['True_Type'] == 'bit') {
509 $special_chars = PMA_convert_bit_default_value($field['Default']);
510 } else {
511 $special_chars = htmlspecialchars($field['Default']);
513 $backup_field = '';
514 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
515 // this will select the UNHEX function while inserting
516 if (($field['is_binary'] || ($field['is_blob'] && ! $cfg['ProtectBinary'])) && $_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
517 $field['display_binary_as_hex'] = true;
521 $idindex = ($o_rows * $fields_cnt) + $i + 1;
522 $tabindex = $idindex;
524 // The function column
525 // -------------------
526 // We don't want binary data to be destroyed
527 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
528 // stored or retrieved" so it does not mean that the contents is
529 // binary
530 if ($cfg['ShowFunctionFields']) {
531 if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload)
532 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
533 echo ' <td align="center">' . __('Binary') . '</td>' . "\n";
534 } elseif (strstr($field['True_Type'], 'enum') || strstr($field['True_Type'], 'set') || 'geometry' == $field['pma_type']) {
535 echo ' <td align="center">--</td>' . "\n";
536 } else {
538 <td>
539 <select name="funcs<?php echo $field_name_appendix; ?>" <?php echo $unnullify_trigger; ?> tabindex="<?php echo ($tabindex + $tabindex_for_function); ?>" id="field_<?php echo $idindex; ?>_1">
540 <option></option>
541 <?php
542 $selected = '';
544 // Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
545 // or something similar. Then directly look up the entry in the RestrictFunctions array,
546 // which will then reveal the available dropdown options
547 if (isset($cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])])
548 && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])]])) {
549 $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])];
550 $dropdown = $cfg['RestrictFunctions'][$current_func_type];
551 $default_function = $cfg['DefaultFunctions'][$current_func_type];
552 } else {
553 $dropdown = array();
554 $default_function = '';
557 $dropdown_built = array();
558 $op_spacing_needed = FALSE;
560 // what function defined as default?
561 // for the first timestamp we don't set the default function
562 // if there is a default value for the timestamp
563 // (not including CURRENT_TIMESTAMP)
564 // and the column does not have the
565 // ON UPDATE DEFAULT TIMESTAMP attribute.
567 if ($field['True_Type'] == 'timestamp'
568 && empty($field['Default'])
569 && empty($data)
570 && ! isset($analyzed_sql[0]['create_table_fields'][$field['Field']]['on_update_current_timestamp'])) {
571 $default_function = $cfg['DefaultFunctions']['first_timestamp'];
574 // For primary keys of type char(36) or varchar(36) UUID if the default function
575 // Only applies to insert mode, as it would silently trash data on updates.
576 if ($insert_mode
577 && $field['Key'] == 'PRI'
578 && ($field['Type'] == 'char(36)' || $field['Type'] == 'varchar(36)')
580 $default_function = $cfg['DefaultFunctions']['pk_char36'];
583 // this is set only when appropriate and is always true
584 if (isset($field['display_binary_as_hex'])) {
585 $default_function = 'UNHEX';
588 // loop on the dropdown array and print all available options for that field.
589 foreach ($dropdown as $each_dropdown){
590 echo '<option';
591 if ($default_function === $each_dropdown) {
592 echo ' selected="selected"';
594 echo '>' . $each_dropdown . '</option>' . "\n";
595 $dropdown_built[$each_dropdown] = 'TRUE';
596 $op_spacing_needed = TRUE;
599 // For compatibility's sake, do not let out all other functions. Instead
600 // print a separator (blank) and then show ALL functions which weren't shown
601 // yet.
602 $cnt_functions = count($cfg['Functions']);
603 for ($j = 0; $j < $cnt_functions; $j++) {
604 if (!isset($dropdown_built[$cfg['Functions'][$j]]) || $dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
605 // Is current function defined as default?
606 $selected = ($field['first_timestamp'] && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
607 || (!$field['first_timestamp'] && $cfg['Functions'][$j] == $default_function)
608 ? ' selected="selected"'
609 : '';
610 if ($op_spacing_needed == TRUE) {
611 echo ' ';
612 echo '<option value="">--------</option>' . "\n";
613 $op_spacing_needed = FALSE;
616 echo ' ';
617 echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
619 } // end for
620 unset($selected);
622 </select>
623 </td>
624 <?php
626 } // end if ($cfg['ShowFunctionFields'])
629 // The null column
630 // ---------------
631 $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', '');
632 echo ' <td>' . "\n";
633 if ($field['Null'] == 'YES') {
634 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
635 if ($real_null_value && !$field['first_timestamp']) {
636 echo ' value="on"';
638 echo ' />' . "\n";
640 echo ' <input type="checkbox" class="checkbox_null" tabindex="' . ($tabindex + $tabindex_for_null) . '"'
641 . ' name="fields_null' . $field_name_appendix . '"';
642 if ($real_null_value && !$field['first_timestamp']) {
643 echo ' checked="checked"';
645 echo ' id="field_' . ($idindex) . '_2" />';
647 // nullify_code is needed by the js nullify() function
648 if (strstr($field['True_Type'], 'enum')) {
649 if (strlen($field['Type']) > 20) {
650 $nullify_code = '1';
651 } else {
652 $nullify_code = '2';
654 } elseif (strstr($field['True_Type'], 'set')) {
655 $nullify_code = '3';
656 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == false) {
657 // foreign key in a drop-down
658 $nullify_code = '4';
659 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == true) {
660 // foreign key with a browsing icon
661 $nullify_code = '6';
662 } else {
663 $nullify_code = '5';
665 // to be able to generate calls to nullify() in jQuery
666 echo '<input type="hidden" class="nullify_code" name="nullify_code' . $field_name_appendix . '" value="' . $nullify_code . '" />';
667 echo '<input type="hidden" class="hashed_field" name="hashed_field' . $field_name_appendix . '" value="' . $field['Field_md5'] . '" />';
668 echo '<input type="hidden" class="multi_edit" name="multi_edit' . $field_name_appendix . '" value="' . PMA_escapeJsString($vkey) . '" />';
670 echo ' </td>' . "\n";
672 // The value column (depends on type)
673 // ----------------
674 // See bug #1667887 for the reason why we don't use the maxlength
675 // HTML attribute
677 echo ' <td>' . "\n";
678 if ($foreignData['foreign_link'] == true) {
679 echo $backup_field . "\n";
681 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
682 value="foreign" />
683 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
684 class="textfield" <?php echo $unnullify_trigger; ?>
685 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
686 id="field_<?php echo ($idindex); ?>_3"
687 value="<?php echo htmlspecialchars($data); ?>" />
688 <a class="hide foreign_values_anchor" target="_blank" onclick="window.open(this.href, 'foreigners', 'width=640,height=240,scrollbars=yes,resizable=yes'); return false;" href="browse_foreigners.php?<?php echo PMA_generate_common_url($db, $table); ?>&amp;field=<?php echo PMA_escapeJsString(urlencode($field['Field']) . $rownumber_param); ?>"><?php echo str_replace("'", "\'", $titles['Browse']); ?></a>
689 <?php
690 } elseif (is_array($foreignData['disp_row'])) {
691 echo $backup_field . "\n";
693 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
694 value="foreign" />
695 <select name="fields<?php echo $field_name_appendix; ?>"
696 <?php echo $unnullify_trigger; ?>
697 class="textfield"
698 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
699 id="field_<?php echo ($idindex); ?>_3">
700 <?php echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?>
701 </select>
702 <?php
703 // still needed? :
704 unset($foreignData['disp_row']);
705 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
707 &nbsp;</td>
708 </tr>
709 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
710 <td colspan="5" align="right">
711 <?php echo $backup_field . "\n"; ?>
712 <textarea name="fields<?php echo $field_name_appendix; ?>"
713 rows="<?php echo ($cfg['TextareaRows']*2); ?>"
714 cols="<?php echo ($cfg['TextareaCols']*2); ?>"
715 dir="<?php echo $text_dir; ?>"
716 id="field_<?php echo ($idindex); ?>_3"
717 <?php echo $unnullify_trigger; ?>
718 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
719 ><?php echo $special_chars_encoded; ?></textarea>
720 <?php
721 } elseif (strstr($field['pma_type'], 'text')) {
722 echo $backup_field . "\n";
724 <textarea name="fields<?php echo $field_name_appendix; ?>"
725 rows="<?php echo $cfg['TextareaRows']; ?>"
726 cols="<?php echo $cfg['TextareaCols']; ?>"
727 dir="<?php echo $text_dir; ?>"
728 id="field_<?php echo ($idindex); ?>_3"
729 <?php echo $unnullify_trigger; ?>
730 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
731 ><?php echo $special_chars_encoded; ?></textarea>
732 <?php
733 echo "\n";
734 if (strlen($special_chars) > 32000) {
735 echo " </td>\n";
736 echo ' <td>' . __(' Because of its length,<br /> this column might not be editable ');
738 } elseif ($field['pma_type'] == 'enum') {
739 if (! isset($table_fields[$i]['values'])) {
740 $table_fields[$i]['values'] = array();
741 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
742 // Removes automatic MySQL escape format
743 $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
744 $table_fields[$i]['values'][] = array(
745 'plain' => $val,
746 'html' => htmlspecialchars($val),
750 $field_enum_values = $table_fields[$i]['values'];
752 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="enum" />
753 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
754 <?php
755 echo "\n" . ' ' . $backup_field . "\n";
757 // show dropdown or radio depend on length
758 if (strlen($field['Type']) > 20) {
760 <select name="fields<?php echo $field_name_appendix; ?>"
761 <?php echo $unnullify_trigger; ?>
762 class="textfield"
763 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
764 id="field_<?php echo ($idindex); ?>_3">
765 <option value="">&nbsp;</option>
766 <?php
767 echo "\n";
769 foreach ($field_enum_values as $enum_value) {
770 echo ' ';
771 echo '<option value="' . $enum_value['html'] . '"';
772 if ($data == $enum_value['plain']
773 || ($data == ''
774 && (! isset($where_clause) || $field['Null'] != 'YES')
775 && isset($field['Default'])
776 && $enum_value['plain'] == $field['Default'])) {
777 echo ' selected="selected"';
779 echo '>' . $enum_value['html'] . '</option>' . "\n";
780 } // end for
783 </select>
784 <?php
785 } else {
786 $j = 0;
787 foreach ($field_enum_values as $enum_value) {
788 echo ' ';
789 echo '<input type="radio" name="fields' . $field_name_appendix . '"';
790 echo ' class="textfield"';
791 echo ' value="' . $enum_value['html'] . '"';
792 echo ' id="field_' . ($idindex) . '_3_' . $j . '"';
793 echo $unnullify_trigger;
794 if ($data == $enum_value['plain']
795 || ($data == ''
796 && (! isset($where_clause) || $field['Null'] != 'YES')
797 && isset($field['Default'])
798 && $enum_value['plain'] == $field['Default'])) {
799 echo ' checked="checked"';
801 echo ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
802 echo '<label for="field_' . $idindex . '_3_' . $j . '">'
803 . $enum_value['html'] . '</label>' . "\n";
804 $j++;
805 } // end for
806 } // end else
807 } elseif ($field['pma_type'] == 'set') {
808 if (! isset($table_fields[$i]['values'])) {
809 $table_fields[$i]['values'] = array();
810 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
811 $table_fields[$i]['values'][] = array(
812 'plain' => $val,
813 'html' => htmlspecialchars($val),
816 $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
818 $field_set_values = $table_fields[$i]['values'];
819 $select_size = $table_fields[$i]['select_size'];
821 $vset = array_flip(explode(',', $data));
822 echo $backup_field . "\n";
824 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="set" />
825 <select name="fields<?php echo $field_name_appendix . '[]'; ?>"
826 class="textfield"
827 size="<?php echo $select_size; ?>"
828 multiple="multiple" <?php echo $unnullify_trigger; ?>
829 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
830 id="field_<?php echo ($idindex); ?>_3">
831 <?php
832 foreach ($field_set_values as $field_set_value) {
833 echo ' ';
834 echo '<option value="' . $field_set_value['html'] . '"';
835 if (isset($vset[$field_set_value['plain']])) {
836 echo ' selected="selected"';
838 echo '>' . $field_set_value['html'] . '</option>' . "\n";
839 } // end for
841 </select>
842 <?php
844 // We don't want binary data destroyed
845 elseif ($field['is_binary'] || $field['is_blob']) {
846 if (($cfg['ProtectBinary'] && $field['is_blob'])
847 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
848 echo "\n";
849 // for blobstreaming
850 if (PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type) && PMA_BS_IsPBMSReference($data, $db))
852 echo '<input type="hidden" name="remove_blob_ref_' . $field['Field_md5'] . $vkey . '" value="' . $data . '" />';
853 echo '<input type="checkbox" name="remove_blob_repo_' . $field['Field_md5'] . $vkey . '" /> ' . __('Remove BLOB Repository Reference') . "<br />";
854 echo PMA_BS_CreateReferenceLink($data, $db);
855 echo "<br />";
857 else
859 echo __('Binary - do not edit');
860 if (isset($data)) {
861 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
862 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
863 unset($data_size);
865 echo "\n";
866 } // end if (PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type) && PMA_BS_IsPBMSReference($data, $db))
868 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="protected" />
869 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
870 <?php
871 } elseif ($field['is_blob']) {
872 echo "\n";
873 echo $backup_field . "\n";
875 <textarea name="fields<?php echo $field_name_appendix; ?>"
876 rows="<?php echo $cfg['TextareaRows']; ?>"
877 cols="<?php echo $cfg['TextareaCols']; ?>"
878 dir="<?php echo $text_dir; ?>"
879 id="field_<?php echo ($idindex); ?>_3"
880 <?php echo $unnullify_trigger; ?>
881 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
882 ><?php echo $special_chars_encoded; ?></textarea>
883 <?php
885 } else {
886 // field size should be at least 4 and max 40
887 $fieldsize = min(max($field['len'], 4), 40);
888 echo "\n";
889 echo $backup_field . "\n";
891 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
892 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
893 class="textfield" <?php echo $unnullify_trigger; ?>
894 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
895 id="field_<?php echo ($idindex); ?>_3" />
896 <?php
897 } // end if...elseif...else
899 // Upload choice (only for BLOBs because the binary
900 // attribute does not imply binary contents)
901 // (displayed whatever value the ProtectBinary has)
903 if ($is_upload && $field['is_blob']) {
904 // check if field type is of longblob and if the table is PBMS enabled.
905 if (($field['pma_type'] == "longblob") && PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type)) {
906 echo '<br />';
907 echo '<input type="checkbox" name="upload_blob_repo' . $vkey . '[' . $field['Field_md5'] . ']" /> ' . __('Upload to BLOB repository');
910 echo '<br />';
911 echo '<input type="file" name="fields_upload' . $vkey . '[' . $field['Field_md5'] . ']" class="textfield" id="field_' . $idindex . '_3" size="10" ' . $unnullify_trigger . '/>&nbsp;';
913 // find maximum upload size, based on field type
915 * @todo with functions this is not so easy, as you can basically
916 * process any data with function like MD5
918 $max_field_sizes = array(
919 'tinyblob' => '256',
920 'blob' => '65536',
921 'mediumblob' => '16777216',
922 'longblob' => '4294967296'); // yeah, really
924 $this_field_max_size = $max_upload_size; // from PHP max
925 if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
926 $this_field_max_size = $max_field_sizes[$field['pma_type']];
928 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
929 // do not generate here the MAX_FILE_SIZE, because we should
930 // put only one in the form to accommodate the biggest field
931 if ($this_field_max_size > $biggest_max_file_size) {
932 $biggest_max_file_size = $this_field_max_size;
936 if (!empty($cfg['UploadDir'])) {
937 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
938 if ($files === FALSE) {
939 echo ' <font color="red">' . __('Error') . '</font><br />' . "\n";
940 echo ' ' . __('The directory you set for upload work cannot be reached') . "\n";
941 } elseif (!empty($files)) {
942 echo "<br />\n";
943 echo ' <i>' . __('Or') . '</i>' . ' ' . __('web server upload directory') . ':<br />' . "\n";
944 echo ' <select size="1" name="fields_uploadlocal' . $vkey . '[' . $field['Field_md5'] . ']">' . "\n";
945 echo ' <option value="" selected="selected"></option>' . "\n";
946 echo $files;
947 echo ' </select>' . "\n";
949 } // end if (web-server upload directory)
950 } // end elseif (binary or blob)
952 elseif ('geometry' == $field['pma_type']) {
953 // ignore this column to avoid changing it
955 else {
956 // field size should be at least 4 and max 40
957 $fieldsize = min(max($field['len'], 4), 40);
958 echo $backup_field . "\n";
959 if ($field['is_char'] && ($cfg['CharEditing'] == 'textarea' || strpos($data, "\n") !== FALSE)) {
960 echo "\n";
962 <textarea name="fields<?php echo $field_name_appendix; ?>"
963 rows="<?php echo $cfg['CharTextareaRows']; ?>"
964 cols="<?php echo $cfg['CharTextareaCols']; ?>"
965 dir="<?php echo $text_dir; ?>"
966 id="field_<?php echo ($idindex); ?>_3"
967 <?php echo $unnullify_trigger; ?>
968 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
969 ><?php echo $special_chars_encoded; ?></textarea>
970 <?php
971 } else {
972 $the_class = 'textfield';
973 if ($field['pma_type'] == 'date') {
974 $the_class .= ' datefield';
975 } elseif ($field['pma_type'] == 'datetime' || substr($field['pma_type'], 0, 9) == 'timestamp') {
976 $the_class .= ' datetimefield';
979 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
980 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
981 class="<?php echo $the_class; ?>" <?php echo $unnullify_trigger; ?>
982 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
983 id="field_<?php echo ($idindex); ?>_3" />
984 <?php
985 if ($field['Extra'] == 'auto_increment') {
987 <input type="hidden" name="auto_increment<?php echo $field_name_appendix; ?>" value="1" />
988 <?php
989 } // end if
990 if (substr($field['pma_type'], 0, 9) == 'timestamp') {
992 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="timestamp" />
993 <?php
995 if (substr($field['pma_type'], 0, 8) == 'datetime') {
997 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="datetime" />
998 <?php
1000 if ($field['True_Type'] == 'bit') {
1002 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="bit" />
1003 <?php
1005 if ($field['pma_type'] == 'date' || $field['pma_type'] == 'datetime' || substr($field['pma_type'], 0, 9) == 'timestamp') {
1006 // the _3 suffix points to the date field
1007 // the _2 suffix points to the corresponding NULL checkbox
1008 // in dateFormat, 'yy' means the year with 4 digits
1013 </td>
1014 </tr>
1015 <?php
1016 $odd_row = !$odd_row;
1017 } // end for
1018 $o_rows++;
1019 echo ' </tbody></table><br />';
1020 } // end foreach on multi-edit
1022 <br />
1024 <fieldset id="actions_panel">
1025 <table border="0" cellpadding="5" cellspacing="0">
1026 <tr>
1027 <td valign="middle" nowrap="nowrap">
1028 <select name="submit_type" class="control_at_footer" tabindex="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
1029 <?php
1030 if (isset($where_clause)) {
1032 <option value="save"><?php echo __('Save'); ?></option>
1033 <?php
1036 <option value="insert"><?php echo __('Insert as new row'); ?></option>
1037 <option value="insertignore"><?php echo __('Insert as new row and ignore errors'); ?></option>
1038 <option value="showinsert"><?php echo __('Show insert query'); ?></option>
1039 </select>
1040 <?php
1041 echo "\n";
1043 if (!isset($after_insert)) {
1044 $after_insert = 'back';
1047 </td>
1048 <td valign="middle">
1049 &nbsp;&nbsp;&nbsp;<strong><?php echo __('and then'); ?></strong>&nbsp;&nbsp;&nbsp;
1050 </td>
1051 <td valign="middle" nowrap="nowrap">
1052 <select name="after_insert">
1053 <option value="back" <?php echo ($after_insert == 'back' ? 'selected="selected"' : ''); ?>><?php echo __('Go back to previous page'); ?></option>
1054 <option value="new_insert" <?php echo ($after_insert == 'new_insert' ? 'selected="selected"' : ''); ?>><?php echo __('Insert another new row'); ?></option>
1055 <?php
1056 if (isset($where_clause)) {
1058 <option value="same_insert" <?php echo ($after_insert == 'same_insert' ? 'selected="selected"' : ''); ?>><?php echo __('Go back to this page'); ?></option>
1059 <?php
1060 // If we have just numeric primary key, we can also edit next
1061 // in 2.8.2, we were looking for `field_name` = numeric_value
1062 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $where_clause)) {
1063 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1064 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $where_clause)) {
1066 <option value="edit_next" <?php echo ($after_insert == 'edit_next' ? 'selected="selected"' : ''); ?>><?php echo __('Edit next row'); ?></option>
1067 <?php
1071 </select>
1072 </td>
1073 </tr>
1075 <tr>
1076 <td>
1077 <?php echo PMA_showHint(__('Use TAB key to move from value to value, or CTRL+arrows to move anywhere')); ?>
1078 </td>
1079 <td colspan="3" align="right" valign="middle">
1080 <input type="submit" class="control_at_footer" value="<?php echo __('Go'); ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 6); ?>" id="buttonYes" />
1081 <input type="reset" class="control_at_footer" value="<?php echo __('Reset'); ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 7); ?>" />
1082 </td>
1083 </tr>
1084 </table>
1085 </fieldset>
1086 <?php if ($biggest_max_file_size > 0) {
1087 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
1088 } ?>
1089 </form>
1090 <?php
1091 if ($insert_mode) {
1093 <!-- Continue insertion form -->
1094 <form id="continueForm" method="post" action="tbl_replace.php" name="continueForm" >
1095 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
1096 <input type="hidden" name="goto" value="<?php echo htmlspecialchars($GLOBALS['goto']); ?>" />
1097 <input type="hidden" name="err_url" value="<?php echo htmlspecialchars($err_url); ?>" />
1098 <input type="hidden" name="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
1099 <?php
1100 if (isset($where_clauses)) {
1101 foreach ($where_clause_array as $key_id => $where_clause) {
1102 echo '<input type="hidden" name="where_clause[' . $key_id . ']" value="' . htmlspecialchars(trim($where_clause)) . '" />'. "\n";
1105 $tmp = '<select name="insert_rows" id="insert_rows">' . "\n";
1106 $option_values = array(1,2,5,10,15,20,30,40);
1107 foreach ($option_values as $value) {
1108 $tmp .= '<option value="' . $value . '"';
1109 if ($value == $cfg['InsertRows']) {
1110 $tmp .= ' selected="selected"';
1112 $tmp .= '>' . $value . '</option>' . "\n";
1114 $tmp .= '</select>' . "\n";
1115 echo "\n" . sprintf(__('Continue insertion with %s rows'), $tmp);
1116 unset($tmp);
1117 echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>' . "\n";
1118 echo '</form>' . "\n";
1122 * Displays the footer
1124 require './libraries/footer.inc.php';