Merge branch 'MAINT_3_3_5'
[phpmyadmin/crack.git] / tbl_change.php
blob704cdc13a91f8fba34793f43d423ae6cc28accc1
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 * load relation data, foreign keys
50 require_once './libraries/relation.lib.php';
52 /**
53 * file listing
55 require_once './libraries/file_listing.php';
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)) {
64 // avoid a problem (see bug #2202709)
65 $GLOBALS['goto'] = 'tbl_sql.php';
66 } else {
67 $GLOBALS['goto'] = 'db_sql.php';
70 /**
71 * @todo check if we could replace by "db_|tbl_" - please clarify!?
73 $_url_params = array(
74 'db' => $db,
75 'sql_query' => $sql_query
78 if (preg_match('@^tbl_@', $GLOBALS['goto'])) {
79 $_url_params['table'] = $table;
82 $err_url = $GLOBALS['goto'] . PMA_generate_common_url($_url_params);
83 unset($_url_params);
86 /**
87 * Sets parameters for links
88 * where is this variable used?
89 * replace by PMA_generate_common_url($url_params);
91 $url_query = PMA_generate_common_url($url_params, 'html', '');
93 /**
94 * get table information
95 * @todo should be done by a Table object
97 require_once './libraries/tbl_info.inc.php';
99 /**
100 * Get comments for table fileds/columns
102 $comments_map = array();
104 if ($GLOBALS['cfg']['ShowPropertyComments']) {
105 $comments_map = PMA_getComments($db, $table);
109 * START REGULAR OUTPUT
113 * used in ./libraries/header.inc.php to load JavaScript library file
115 $GLOBALS['js_include'][] = 'tbl_change.js';
116 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
117 $GLOBALS['js_include'][] = 'jquery/timepicker.js';
119 * HTTP and HTML headers
121 require_once './libraries/header.inc.php';
124 * Displays the query submitted and its result
126 * @todo where does $disp_message and $disp_query come from???
128 if (! empty($disp_message)) {
129 if (! isset($disp_query)) {
130 $disp_query = null;
132 PMA_showMessage($disp_message, $disp_query);
136 * Displays top menu links
138 require_once './libraries/tbl_links.inc.php';
142 * Get the analysis of SHOW CREATE TABLE for this table
143 * @todo should be handled by class Table
145 $show_create_table = PMA_DBI_fetch_value(
146 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
147 0, 1);
148 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
149 unset($show_create_table);
152 * Get the list of the fields of the current table
154 PMA_DBI_select_db($db);
155 $table_fields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ';',
156 null, null, null, PMA_DBI_QUERY_STORE);
157 $rows = array();
158 if (isset($where_clause)) {
159 // when in edit mode load all selected rows from table
160 $insert_mode = false;
161 if (is_array($where_clause)) {
162 $where_clause_array = $where_clause;
163 } else {
164 $where_clause_array = array(0 => $where_clause);
167 $result = array();
168 $found_unique_key = false;
169 $where_clauses = array();
171 foreach ($where_clause_array as $key_id => $where_clause) {
172 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $where_clause . ';';
173 $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE);
174 $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]);
175 $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause);
177 // No row returned
178 if (! $rows[$key_id]) {
179 unset($rows[$key_id], $where_clause_array[$key_id]);
180 PMA_showMessage(__('MySQL returned an empty result set (i.e. zero rows).'), $local_query);
181 echo "\n";
182 require_once './libraries/footer.inc.php';
183 } else { // end if (no row returned)
184 $meta = PMA_DBI_get_fields_meta($result[$key_id]);
185 list($unique_condition, $tmp_clause_is_unique) = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true);
186 if (! empty($unique_condition)) {
187 $found_unique_key = true;
189 unset($unique_condition, $tmp_clause_is_unique);
192 } else {
193 // no primary key given, just load first row - but what happens if table is empty?
194 $insert_mode = true;
195 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
196 $rows = array_fill(0, $cfg['InsertRows'], false);
199 // retrieve keys into foreign fields, if any
200 $foreigners = PMA_getForeigners($db, $table);
204 * Displays the form
206 // autocomplete feature of IE kills the "onchange" event handler and it
207 // must be replaced by the "onpropertychange" one in this case
208 $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5 && PMA_USR_BROWSER_VER < 7)
209 ? 'onpropertychange'
210 : 'onchange';
211 // Had to put the URI because when hosted on an https server,
212 // some browsers send wrongly this form to the http server.
214 if ($cfg['CtrlArrowsMoving']) {
216 <!-- Set on key handler for moving using by Ctrl+arrows -->
217 <script src="./js/keyhandler.js" type="text/javascript"></script>
218 <script type="text/javascript">
219 //<![CDATA[
220 var switch_movement = 0;
221 document.onkeydown = onKeyDownArrowsHandler;
222 //]]>
223 </script>
224 <?php
227 $_form_params = array(
228 'db' => $db,
229 'table' => $table,
230 'goto' => $GLOBALS['goto'],
231 'err_url' => $err_url,
232 'sql_query' => $sql_query,
234 if (isset($where_clauses)) {
235 foreach ($where_clause_array as $key_id => $where_clause) {
236 $_form_params['where_clause[' . $key_id . ']'] = trim($where_clause);
239 if (isset($clause_is_unique)) {
240 $_form_params['clause_is_unique'] = $clause_is_unique;
245 <!-- Insert/Edit form -->
246 <form method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?>>
247 <?php
248 echo PMA_generate_common_hidden_inputs($_form_params);
250 $titles['Browse'] = PMA_getIcon('b_browse.png', __('Browse foreign values'));
252 // Set if we passed the first timestamp field
253 $timestamp_seen = 0;
254 $fields_cnt = count($table_fields);
256 $tabindex = 0;
257 $tabindex_for_function = +3000;
258 $tabindex_for_null = +6000;
259 $tabindex_for_value = 0;
260 $o_rows = 0;
261 $biggest_max_file_size = 0;
263 // user can toggle the display of Function column
264 // (currently does not work for multi-edits)
265 $url_params['db'] = $db;
266 $url_params['table'] = $table;
267 if (isset($where_clause)) {
268 $url_params['where_clause'] = trim($where_clause);
270 if (! empty($sql_query)) {
271 $url_params['sql_query'] = $sql_query;
274 if (! $cfg['ShowFunctionFields'] || ! $cfg['ShowFieldTypesInDataEditView']) {
275 echo __('Show');
277 if (! $cfg['ShowFunctionFields']) {
278 $this_url_params = array_merge($url_params,
279 array('ShowFunctionFields' => 1, 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'], 'goto' => 'sql.php'));
280 echo ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . __('Function') . '</a>' . "\n";
282 if (! $cfg['ShowFieldTypesInDataEditView']) {
283 $this_other_url_params = array_merge($url_params,
284 array('ShowFieldTypesInDataEditView' => 1, 'ShowFunctionFields' => $cfg['ShowFunctionFields'], 'goto' => 'sql.php'));
285 echo ' : <a href="tbl_change.php' . PMA_generate_common_url($this_other_url_params) . '">' . __('Type') . '</a>' . "\n";
288 foreach ($rows as $row_id => $vrow) {
289 if ($vrow === false) {
290 unset($vrow);
293 $jsvkey = $row_id;
294 $browse_foreigners_uri = '&amp;pk=' . $row_id;
295 $vkey = '[multi_edit][' . $jsvkey . ']';
297 $vresult = (isset($result) && is_array($result) && isset($result[$row_id]) ? $result[$row_id] : $result);
298 if ($insert_mode && $row_id > 0) {
299 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $row_id . '" id="insert_ignore_check_' . $row_id . '" />';
300 echo '<label for="insert_ignore_check_' . $row_id . '">' . __('Ignore') . '</label><br />' . "\n";
303 <table>
304 <thead>
305 <tr>
306 <th><?php echo __('Column'); ?></th>
308 <?php
309 if ($cfg['ShowFieldTypesInDataEditView']) {
310 $this_url_params = array_merge($url_params,
311 array('ShowFieldTypesInDataEditView' => 0, 'ShowFunctionFields' => $cfg['ShowFunctionFields'], 'goto' => 'sql.php'));
312 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . __('Hide') . '">' . __('Type') . '</a></th>' . "\n";
315 if ($cfg['ShowFunctionFields']) {
316 $this_url_params = array_merge($url_params,
317 array('ShowFunctionFields' => 0, 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'], 'goto' => 'sql.php'));
318 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . __('Hide') . '">' . __('Function') . '</a></th>' . "\n";
321 <th><?php echo __('Null'); ?></th>
322 <th><?php echo __('Value'); ?></th>
323 </tr>
324 </thead>
325 <tfoot>
326 <tr>
327 <th colspan="5" align="right" class="tblFooters">
328 <input type="submit" value="<?php echo __('Go'); ?>" />
329 </th>
330 </tr>
331 </tfoot>
332 <tbody>
333 <?php
334 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
335 $m_rows = $o_rows + 1;
337 $odd_row = true;
338 for ($i = 0; $i < $fields_cnt; $i++) {
339 if (! isset($table_fields[$i]['processed'])) {
340 $table_fields[$i]['Field_html'] = htmlspecialchars($table_fields[$i]['Field']);
341 $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']);
342 // True_Type contains only the type (stops at first bracket)
343 $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']);
345 // d a t e t i m e
347 // Current date should not be set as default if the field is NULL
348 // for the current row, but do not put here the current datetime
349 // if there is a default value (the real default value will be set
350 // in the Default value logic below)
352 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
353 // $field['Default'] is not set if it contains NULL:
354 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime)
355 // but, look what we get if we switch to iso: (Default is NULL)
356 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime)
357 // so I force a NULL into it (I don't think it's possible
358 // to have an empty default value for DATETIME)
359 // then, the "if" after this one will work
360 if ($table_fields[$i]['Type'] == 'datetime'
361 && ! isset($table_fields[$i]['Default'])
362 && isset($table_fields[$i]['Null'])
363 && $table_fields[$i]['Null'] == 'YES') {
364 $table_fields[$i]['Default'] = null;
367 $table_fields[$i]['len'] =
368 preg_match('@float|double@', $table_fields[$i]['Type']) ? 100 : -1;
371 if (isset($comments_map[$table_fields[$i]['Field']])) {
372 $table_fields[$i]['Field_title'] = '<span style="border-bottom: 1px dashed black;" title="'
373 . htmlspecialchars($comments_map[$table_fields[$i]['Field']]) . '">'
374 . $table_fields[$i]['Field_html'] . '</span>';
375 } else {
376 $table_fields[$i]['Field_title'] = $table_fields[$i]['Field_html'];
379 // The type column
380 $table_fields[$i]['is_binary'] = stristr($table_fields[$i]['Type'], 'binary');
381 $table_fields[$i]['is_blob'] = stristr($table_fields[$i]['Type'], 'blob');
382 $table_fields[$i]['is_char'] = stristr($table_fields[$i]['Type'], 'char');
383 $table_fields[$i]['first_timestamp'] = false;
384 switch ($table_fields[$i]['True_Type']) {
385 case 'set':
386 $table_fields[$i]['pma_type'] = 'set';
387 $table_fields[$i]['wrap'] = '';
388 break;
389 case 'enum':
390 $table_fields[$i]['pma_type'] = 'enum';
391 $table_fields[$i]['wrap'] = '';
392 break;
393 case 'timestamp':
394 if (!$timestamp_seen) { // can only occur once per table
395 $timestamp_seen = 1;
396 $table_fields[$i]['first_timestamp'] = true;
398 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
399 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
400 break;
402 default:
403 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
404 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
405 break;
408 $field = $table_fields[$i];
409 $extracted_fieldspec = PMA_extractFieldSpec($field['Type']);
411 if (-1 === $field['len']) {
412 $field['len'] = PMA_DBI_field_len($vresult, $i);
414 //Call validation when the form submited...
415 $unnullify_trigger = $chg_evt_handler . "=\"return Validator('". PMA_escapeJsString($field['Field_md5']) . "', '"
416 . PMA_escapeJsString($jsvkey) . "','".$field['pma_type']."')\"";
418 // Use an MD5 as an array index to avoid having special characters in the name atttibute (see bug #1746964 )
419 $field_name_appendix = $vkey . '[' . $field['Field_md5'] . ']';
420 $field_name_appendix_md5 = $field['Field_md5'] . $vkey . '[]';
423 if ($field['Type'] == 'datetime'
424 && ! isset($field['Default'])
425 && ! is_null($field['Default'])
426 && ($insert_mode || ! isset($vrow[$field['Field']]))) {
427 // INSERT case or
428 // UPDATE case with an NULL value
429 $vrow[$field['Field']] = date('Y-m-d H:i:s', time());
432 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
433 <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($field['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center">
434 <?php echo $field['Field_title']; ?>
435 <input type="hidden" name="fields_name<?php echo $field_name_appendix; ?>" value="<?php echo $field['Field_html']; ?>"/>
436 </td>
437 <?php if ($cfg['ShowFieldTypesInDataEditView']) { ?>
438 <td align="center"<?php echo $field['wrap']; ?>>
439 <?php echo $field['pma_type']; ?>
440 </td>
442 <?php } //End if
444 // Prepares the field value
445 $real_null_value = FALSE;
446 $special_chars_encoded = '';
447 if (isset($vrow)) {
448 // (we are editing)
449 if (is_null($vrow[$field['Field']])) {
450 $real_null_value = TRUE;
451 $vrow[$field['Field']] = '';
452 $special_chars = '';
453 $data = $vrow[$field['Field']];
454 } elseif ($field['True_Type'] == 'bit') {
455 $special_chars = PMA_printable_bit_value($vrow[$field['Field']], $extracted_fieldspec['spec_in_brackets']);
456 } else {
457 // special binary "characters"
458 if ($field['is_binary'] || ($field['is_blob'] && ! $cfg['ProtectBinary'])) {
459 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
460 $vrow[$field['Field']] = bin2hex($vrow[$field['Field']]);
461 $field['display_binary_as_hex'] = true;
462 } else {
463 $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]);
465 } // end if
466 $special_chars = htmlspecialchars($vrow[$field['Field']]);
468 //We need to duplicate the first \n or otherwise we will lose the first newline entered in a VARCHAR or TEXT column
469 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
471 $data = $vrow[$field['Field']];
472 } // end if... else...
473 // If a timestamp field value is not included in an update
474 // statement MySQL auto-update it to the current timestamp;
475 // however, things have changed since MySQL 4.1, so
476 // it's better to set a fields_prev in this situation
477 $backup_field = '<input type="hidden" name="fields_prev'
478 . $field_name_appendix . '" value="'
479 . htmlspecialchars($vrow[$field['Field']]) . '" />';
480 } else {
481 // (we are inserting)
482 // display default values
483 if (!isset($field['Default'])) {
484 $field['Default'] = '';
485 $real_null_value = TRUE;
486 $data = '';
487 } else {
488 $data = $field['Default'];
490 if ($field['True_Type'] == 'bit') {
491 $special_chars = PMA_convert_bit_default_value($field['Default']);
492 } else {
493 $special_chars = htmlspecialchars($field['Default']);
495 $backup_field = '';
496 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
497 // this will select the UNHEX function while inserting
498 if (($field['is_binary'] || ($field['is_blob'] && ! $cfg['ProtectBinary'])) && $_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
499 $field['display_binary_as_hex'] = true;
503 $idindex = ($o_rows * $fields_cnt) + $i + 1;
504 $tabindex = (($idindex - 1) * 3) + 1;
506 // The function column
507 // -------------------
508 // We don't want binary data to be destroyed
509 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
510 // stored or retrieved" so it does not mean that the contents is
511 // binary
512 if ($cfg['ShowFunctionFields']) {
513 if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload)
514 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
515 echo ' <td align="center">' . __('Binary') . '</td>' . "\n";
516 } elseif (strstr($field['True_Type'], 'enum') || strstr($field['True_Type'], 'set')) {
517 echo ' <td align="center">--</td>' . "\n";
518 } else {
520 <td>
521 <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">
522 <option></option>
523 <?php
524 $selected = '';
526 // Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
527 // or something similar. Then directly look up the entry in the RestrictFunctions array,
528 // which will then reveal the available dropdown options
529 if (isset($cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])])
530 && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])]])) {
531 $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])];
532 $dropdown = $cfg['RestrictFunctions'][$current_func_type];
533 $default_function = $cfg['DefaultFunctions'][$current_func_type];
534 } else {
535 $dropdown = array();
536 $default_function = '';
539 $dropdown_built = array();
540 $op_spacing_needed = FALSE;
542 // what function defined as default?
543 // for the first timestamp we don't set the default function
544 // if there is a default value for the timestamp
545 // (not including CURRENT_TIMESTAMP)
546 // and the column does not have the
547 // ON UPDATE DEFAULT TIMESTAMP attribute.
549 if ($field['True_Type'] == 'timestamp'
550 && empty($field['Default'])
551 && ! isset($analyzed_sql[0]['create_table_fields'][$field['Field']]['on_update_current_timestamp'])) {
552 $default_function = $cfg['DefaultFunctions']['first_timestamp'];
555 // For primary keys of type char(36) or varchar(36) UUID if the default function
556 // Only applies to insert mode, as it would silently trash data on updates.
557 if ($insert_mode
558 && $field['Key'] == 'PRI'
559 && ($field['Type'] == 'char(36)' || $field['Type'] == 'varchar(36)')
561 $default_function = $cfg['DefaultFunctions']['pk_char36'];
564 // this is set only when appropriate and is always true
565 if (isset($field['display_binary_as_hex'])) {
566 $default_function = 'UNHEX';
569 // loop on the dropdown array and print all available options for that field.
570 foreach ($dropdown as $each_dropdown){
571 echo '<option';
572 if ($default_function === $each_dropdown) {
573 echo ' selected="selected"';
575 echo '>' . $each_dropdown . '</option>' . "\n";
576 $dropdown_built[$each_dropdown] = 'TRUE';
577 $op_spacing_needed = TRUE;
580 // For compatibility's sake, do not let out all other functions. Instead
581 // print a separator (blank) and then show ALL functions which weren't shown
582 // yet.
583 $cnt_functions = count($cfg['Functions']);
584 for ($j = 0; $j < $cnt_functions; $j++) {
585 if (!isset($dropdown_built[$cfg['Functions'][$j]]) || $dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
586 // Is current function defined as default?
587 $selected = ($field['first_timestamp'] && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
588 || (!$field['first_timestamp'] && $cfg['Functions'][$j] == $default_function)
589 ? ' selected="selected"'
590 : '';
591 if ($op_spacing_needed == TRUE) {
592 echo ' ';
593 echo '<option value="">--------</option>' . "\n";
594 $op_spacing_needed = FALSE;
597 echo ' ';
598 echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
600 } // end for
601 unset($selected);
603 </select>
604 </td>
605 <?php
607 } // end if ($cfg['ShowFunctionFields'])
610 // The null column
611 // ---------------
612 $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', '');
613 echo ' <td>' . "\n";
614 if ($field['Null'] == 'YES') {
615 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
616 if ($real_null_value && !$field['first_timestamp']) {
617 echo ' value="on"';
619 echo ' />' . "\n";
621 echo ' <input type="checkbox" tabindex="' . ($tabindex + $tabindex_for_null) . '"'
622 . ' name="fields_null' . $field_name_appendix . '"';
623 if ($real_null_value && !$field['first_timestamp']) {
624 echo ' checked="checked"';
626 echo ' id="field_' . ($idindex) . '_2"';
627 $onclick = ' onclick="if (this.checked) {nullify(';
628 if (strstr($field['True_Type'], 'enum')) {
629 if (strlen($field['Type']) > 20) {
630 $onclick .= '1, ';
631 } else {
632 $onclick .= '2, ';
634 } elseif (strstr($field['True_Type'], 'set')) {
635 $onclick .= '3, ';
636 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == false) {
637 // foreign key in a drop-down
638 $onclick .= '4, ';
639 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == true) {
640 // foreign key with a browsing icon
641 $onclick .= '6, ';
642 } else {
643 $onclick .= '5, ';
645 $onclick .= '\'' . PMA_escapeJsString($field['Field_html']) . '\', \'' . $field['Field_md5'] . '\', \'' . PMA_escapeJsString($vkey) . '\'); this.checked = true}; return true" />' . "\n";
646 echo $onclick;
648 echo ' </td>' . "\n";
650 // The value column (depends on type)
651 // ----------------
652 // See bug #1667887 for the reason why we don't use the maxlength
653 // HTML attribute
655 echo ' <td>' . "\n";
656 if ($foreignData['foreign_link'] == true) {
657 echo $backup_field . "\n";
659 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
660 value="foreign" />
661 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
662 value="" id="field_<?php echo ($idindex); ?>_3A" />
663 <input type="text" name="field_<?php echo $field_name_appendix_md5; ?>"
664 class="textfield" <?php echo $unnullify_trigger; ?>
665 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
666 id="field_<?php echo ($idindex); ?>_3"
667 value="<?php echo htmlspecialchars($data); ?>" />
668 <script type="text/javascript">
669 //<![CDATA[
670 document.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes,resizable=yes\'); return false"');
671 document.write(' href="browse_foreigners.php?');
672 document.write('<?php echo PMA_generate_common_url($db, $table); ?>');
673 document.writeln('&amp;field=<?php echo PMA_escapeJsString(urlencode($field['Field']) . $browse_foreigners_uri); ?>">');
674 document.writeln('<?php echo str_replace("'", "\'", $titles['Browse']); ?></a>');
675 //]]>
676 </script>
677 <?php
678 } elseif (is_array($foreignData['disp_row'])) {
679 echo $backup_field . "\n";
681 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
682 value="foreign" />
683 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
684 value="" id="field_<?php echo $idindex; ?>_3A" />
685 <select name="field_<?php echo $field_name_appendix_md5; ?>"
686 <?php echo $unnullify_trigger; ?>
687 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
688 id="field_<?php echo ($idindex); ?>_3">
689 <?php echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?>
690 </select>
691 <?php
692 // still needed? :
693 unset($foreignData['disp_row']);
694 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
696 &nbsp;</td>
697 </tr>
698 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
699 <td colspan="5" align="right">
700 <?php echo $backup_field . "\n"; ?>
701 <textarea name="fields<?php echo $field_name_appendix; ?>"
702 rows="<?php echo ($cfg['TextareaRows']*2); ?>"
703 cols="<?php echo ($cfg['TextareaCols']*2); ?>"
704 dir="<?php echo $text_dir; ?>"
705 id="field_<?php echo ($idindex); ?>_3"
706 <?php echo $unnullify_trigger; ?>
707 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
708 ><?php echo $special_chars_encoded; ?></textarea>
709 <?php
710 } elseif (strstr($field['pma_type'], 'text')) {
711 echo $backup_field . "\n";
713 <textarea name="fields<?php echo $field_name_appendix; ?>"
714 rows="<?php echo $cfg['TextareaRows']; ?>"
715 cols="<?php echo $cfg['TextareaCols']; ?>"
716 dir="<?php echo $text_dir; ?>"
717 id="field_<?php echo ($idindex); ?>_3"
718 <?php echo $unnullify_trigger; ?>
719 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
720 ><?php echo $special_chars_encoded; ?></textarea>
721 <?php
722 echo "\n";
723 if (strlen($special_chars) > 32000) {
724 echo " </td>\n";
725 echo ' <td>' . __(' Because of its length,<br /> this column might not be editable ');
727 } elseif ($field['pma_type'] == 'enum') {
728 if (! isset($table_fields[$i]['values'])) {
729 $table_fields[$i]['values'] = array();
730 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
731 // Removes automatic MySQL escape format
732 $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
733 $table_fields[$i]['values'][] = array(
734 'plain' => $val,
735 'html' => htmlspecialchars($val),
739 $field_enum_values = $table_fields[$i]['values'];
741 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="enum" />
742 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
743 <?php
744 echo "\n" . ' ' . $backup_field . "\n";
746 // show dropdown or radio depend on length
747 if (strlen($field['Type']) > 20) {
749 <select name="field_<?php echo $field_name_appendix_md5; ?>"
750 <?php echo $unnullify_trigger; ?>
751 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
752 id="field_<?php echo ($idindex); ?>_3">
753 <option value="">&nbsp;</option>
754 <?php
755 echo "\n";
757 foreach ($field_enum_values as $enum_value) {
758 echo ' ';
759 echo '<option value="' . $enum_value['html'] . '"';
760 if ($data == $enum_value['plain']
761 || ($data == ''
762 && (! isset($where_clause) || $field['Null'] != 'YES')
763 && isset($field['Default'])
764 && $enum_value['plain'] == $field['Default'])) {
765 echo ' selected="selected"';
767 echo '>' . $enum_value['html'] . '</option>' . "\n";
768 } // end for
771 </select>
772 <?php
773 } else {
774 $j = 0;
775 foreach ($field_enum_values as $enum_value) {
776 echo ' ';
777 echo '<input type="radio" name="field_' . $field_name_appendix_md5 . '"';
778 echo ' value="' . $enum_value['html'] . '"';
779 echo ' id="field_' . ($idindex) . '_3_' . $j . '"';
780 echo $unnullify_trigger;
781 if ($data == $enum_value['plain']
782 || ($data == ''
783 && (! isset($where_clause) || $field['Null'] != 'YES')
784 && isset($field['Default'])
785 && $enum_value['plain'] == $field['Default'])) {
786 echo ' checked="checked"';
788 echo ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
789 echo '<label for="field_' . $idindex . '_3_' . $j . '">'
790 . $enum_value['html'] . '</label>' . "\n";
791 $j++;
792 } // end for
793 } // end else
794 } elseif ($field['pma_type'] == 'set') {
795 if (! isset($table_fields[$i]['values'])) {
796 $table_fields[$i]['values'] = array();
797 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
798 $table_fields[$i]['values'][] = array(
799 'plain' => $val,
800 'html' => htmlspecialchars($val),
803 $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
805 $field_set_values = $table_fields[$i]['values'];
806 $select_size = $table_fields[$i]['select_size'];
808 $vset = array_flip(explode(',', $data));
809 echo $backup_field . "\n";
811 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="set" />
812 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
813 <select name="field_<?php echo $field_name_appendix_md5; ?>"
814 size="<?php echo $select_size; ?>"
815 multiple="multiple" <?php echo $unnullify_trigger; ?>
816 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
817 id="field_<?php echo ($idindex); ?>_3">
818 <?php
819 foreach ($field_set_values as $field_set_value) {
820 echo ' ';
821 echo '<option value="' . $field_set_value['html'] . '"';
822 if (isset($vset[$field_set_value['plain']])) {
823 echo ' selected="selected"';
825 echo '>' . $field_set_value['html'] . '</option>' . "\n";
826 } // end for
828 </select>
829 <?php
831 // We don't want binary data destroyed
832 elseif ($field['is_binary'] || $field['is_blob']) {
833 if (($cfg['ProtectBinary'] && $field['is_blob'])
834 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
835 echo "\n";
836 // for blobstreaming
837 if (PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type) && PMA_BS_IsPBMSReference($data, $db))
839 echo '<input type="hidden" name="remove_blob_ref_' . $field['Field_md5'] . $vkey . '" value="' . $data . '" />';
840 echo '<input type="checkbox" name="remove_blob_repo_' . $field['Field_md5'] . $vkey . '" /> ' . __('Remove BLOB Repository Reference') . "<br />";
841 echo PMA_BS_CreateReferenceLink($data, $db);
842 echo "<br />";
844 else
846 echo __('Binary - do not edit');
847 if (isset($data)) {
848 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
849 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
850 unset($data_size);
852 echo "\n";
853 } // end if (PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type) && PMA_BS_IsPBMSReference($data, $db))
855 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="protected" />
856 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
857 <?php
858 } elseif ($field['is_blob']) {
859 echo "\n";
860 echo $backup_field . "\n";
862 <textarea name="fields<?php echo $field_name_appendix; ?>"
863 rows="<?php echo $cfg['TextareaRows']; ?>"
864 cols="<?php echo $cfg['TextareaCols']; ?>"
865 dir="<?php echo $text_dir; ?>"
866 id="field_<?php echo ($idindex); ?>_3"
867 <?php echo $unnullify_trigger; ?>
868 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
869 ><?php echo $special_chars_encoded; ?></textarea>
870 <?php
872 } else {
873 // field size should be at least 4 and max 40
874 $fieldsize = min(max($field['len'], 4), 40);
875 echo "\n";
876 echo $backup_field . "\n";
878 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
879 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
880 class="textfield" <?php echo $unnullify_trigger; ?>
881 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
882 id="field_<?php echo ($idindex); ?>_3" />
883 <?php
884 } // end if...elseif...else
886 // Upload choice (only for BLOBs because the binary
887 // attribute does not imply binary contents)
888 // (displayed whatever value the ProtectBinary has)
890 if ($is_upload && $field['is_blob']) {
891 // check if field type is of longblob and if the table is PBMS enabled.
892 if (($field['pma_type'] == "longblob") && PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type)) {
893 echo '<br />';
894 echo '<input type="checkbox" name="upload_blob_repo_' . $field['Field_md5'] . $vkey . '" /> ' . __('Upload to BLOB repository');
897 echo '<br />';
898 echo '<input type="file" name="fields_upload_' . $field['Field_md5'] . $vkey . '" class="textfield" id="field_' . $idindex . '_3" size="10" ' . $unnullify_trigger . '/>&nbsp;';
900 // find maximum upload size, based on field type
902 * @todo with functions this is not so easy, as you can basically
903 * process any data with function like MD5
905 $max_field_sizes = array(
906 'tinyblob' => '256',
907 'blob' => '65536',
908 'mediumblob' => '16777216',
909 'longblob' => '4294967296'); // yeah, really
911 $this_field_max_size = $max_upload_size; // from PHP max
912 if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
913 $this_field_max_size = $max_field_sizes[$field['pma_type']];
915 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
916 // do not generate here the MAX_FILE_SIZE, because we should
917 // put only one in the form to accommodate the biggest field
918 if ($this_field_max_size > $biggest_max_file_size) {
919 $biggest_max_file_size = $this_field_max_size;
923 if (!empty($cfg['UploadDir'])) {
924 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
925 if ($files === FALSE) {
926 echo ' <font color="red">' . __('Error') . '</font><br />' . "\n";
927 echo ' ' . __('The directory you set for upload work cannot be reached') . "\n";
928 } elseif (!empty($files)) {
929 echo "<br />\n";
930 echo ' <i>' . __('Or') . '</i>' . ' ' . __('web server upload directory') . ':<br />' . "\n";
931 echo ' <select size="1" name="fields_uploadlocal_' . $field['Field_md5'] . $vkey . '">' . "\n";
932 echo ' <option value="" selected="selected"></option>' . "\n";
933 echo $files;
934 echo ' </select>' . "\n";
936 } // end if (web-server upload directory)
937 } // end elseif (binary or blob)
938 else {
939 // field size should be at least 4 and max 40
940 $fieldsize = min(max($field['len'], 4), 40);
941 echo $backup_field . "\n";
942 if ($field['is_char'] && ($cfg['CharEditing'] == 'textarea' || strpos($data, "\n") !== FALSE)) {
943 echo "\n";
945 <textarea name="fields<?php echo $field_name_appendix; ?>"
946 rows="<?php echo $cfg['CharTextareaRows']; ?>"
947 cols="<?php echo $cfg['CharTextareaCols']; ?>"
948 dir="<?php echo $text_dir; ?>"
949 id="field_<?php echo ($idindex); ?>_3"
950 <?php echo $unnullify_trigger; ?>
951 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
952 ><?php echo $special_chars_encoded; ?></textarea>
953 <?php
954 } else {
956 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
957 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
958 class="textfield" <?php echo $unnullify_trigger; ?>
959 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
960 id="field_<?php echo ($idindex); ?>_3" />
961 <?php
962 if ($field['Extra'] == 'auto_increment') {
964 <input type="hidden" name="auto_increment<?php echo $field_name_appendix; ?>" value="1" />
965 <?php
966 } // end if
967 if (substr($field['pma_type'], 0, 9) == 'timestamp') {
969 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="timestamp" />
970 <?php
972 if (substr($field['pma_type'], 0, 8) == 'datetime') {
974 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="datetime" />
975 <?php
977 if ($field['True_Type'] == 'bit') {
979 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="bit" />
980 <?php
982 if ($field['pma_type'] == 'date' || $field['pma_type'] == 'datetime' || substr($field['pma_type'], 0, 9) == 'timestamp') {
983 // the _3 suffix points to the date field
984 // the _2 suffix points to the corresponding NULL checkbox
985 // in dateFormat, 'yy' means the year with 4 digits
987 <script type="text/javascript">
988 //<![CDATA[
989 $(function() {
990 $('#field_<?php echo ($idindex); ?>_3').datepicker({
991 duration: '',
992 time24h: true,
993 stepMinutes: 1,
994 stepHours: 1,
995 <?php echo ($field['pma_type'] == 'date' ? "showTime: false,":"showTime: true,"); ?>
996 dateFormat: 'yy-mm-dd',
997 altTimeField: '',
998 constrainInput: false
1001 //]]>
1002 </script>
1003 <?php
1008 </td>
1009 </tr>
1010 <?php
1011 $odd_row = !$odd_row;
1012 } // end for
1013 $o_rows++;
1014 echo ' </tbody></table><br />';
1015 } // end foreach on multi-edit
1017 <br />
1019 <fieldset>
1020 <table border="0" cellpadding="5" cellspacing="0">
1021 <tr>
1022 <td valign="middle" nowrap="nowrap">
1023 <select name="submit_type" tabindex="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
1024 <?php
1025 if (isset($where_clause)) {
1027 <option value="save"><?php echo __('Save'); ?></option>
1028 <?php
1031 <option value="insert"><?php echo __('Insert as new row'); ?></option>
1032 <option value="insertignore"><?php echo __('Insert as new row and ignore errors'); ?></option>
1033 <option value="showinsert"><?php echo __('Show insert query'); ?></option>
1034 </select>
1035 <?php
1036 echo "\n";
1038 if (!isset($after_insert)) {
1039 $after_insert = 'back';
1042 </td>
1043 <td valign="middle">
1044 &nbsp;&nbsp;&nbsp;<strong><?php echo __('and then'); ?></strong>&nbsp;&nbsp;&nbsp;
1045 </td>
1046 <td valign="middle" nowrap="nowrap">
1047 <select name="after_insert">
1048 <option value="back" <?php echo ($after_insert == 'back' ? 'selected="selected"' : ''); ?>><?php echo __('Go back to previous page'); ?></option>
1049 <option value="new_insert" <?php echo ($after_insert == 'new_insert' ? 'selected="selected"' : ''); ?>><?php echo __('Insert another new row'); ?></option>
1050 <?php
1051 if (isset($where_clause)) {
1053 <option value="same_insert" <?php echo ($after_insert == 'same_insert' ? 'selected="selected"' : ''); ?>><?php echo __('Go back to this page'); ?></option>
1054 <?php
1055 // If we have just numeric primary key, we can also edit next
1056 // in 2.8.2, we were looking for `field_name` = numeric_value
1057 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $where_clause)) {
1058 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1059 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $where_clause)) {
1061 <option value="edit_next" <?php echo ($after_insert == 'edit_next' ? 'selected="selected"' : ''); ?>><?php echo __('Edit next row'); ?></option>
1062 <?php
1066 </select>
1067 </td>
1068 </tr>
1070 <tr>
1071 <td>
1072 <?php echo PMA_showHint(__('Use TAB key to move from value to value, or CTRL+arrows to move anywhere')); ?>
1073 </td>
1074 <td colspan="3" align="right" valign="middle">
1075 <input type="submit" value="<?php echo __('Go'); ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 6); ?>" id="buttonYes" />
1076 <input type="reset" value="<?php echo __('Reset'); ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 7); ?>" />
1077 </td>
1078 </tr>
1079 </table>
1080 </fieldset>
1081 <?php if ($biggest_max_file_size > 0) {
1082 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
1083 } ?>
1084 </form>
1085 <?php
1086 if ($insert_mode) {
1088 <!-- Restart insertion form -->
1089 <form method="post" action="tbl_replace.php" name="restartForm" >
1090 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
1091 <input type="hidden" name="goto" value="<?php echo htmlspecialchars($GLOBALS['goto']); ?>" />
1092 <input type="hidden" name="err_url" value="<?php echo htmlspecialchars($err_url); ?>" />
1093 <input type="hidden" name="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
1094 <?php
1095 if (isset($where_clauses)) {
1096 foreach ($where_clause_array as $key_id => $where_clause) {
1097 echo '<input type="hidden" name="where_clause[' . $key_id . ']" value="' . htmlspecialchars(trim($where_clause)) . '" />'. "\n";
1100 $tmp = '<select name="insert_rows" id="insert_rows" onchange="this.form.submit();" >' . "\n";
1101 $option_values = array(1,2,5,10,15,20,30,40);
1102 foreach ($option_values as $value) {
1103 $tmp .= '<option value="' . $value . '"';
1104 if ($value == $cfg['InsertRows']) {
1105 $tmp .= ' selected="selected"';
1107 $tmp .= '>' . $value . '</option>' . "\n";
1109 $tmp .= '</select>' . "\n";
1110 echo "\n" . sprintf(__('Restart insertion with %s rows'), $tmp);
1111 unset($tmp);
1112 echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>' . "\n";
1113 echo '</form>' . "\n";
1117 * Displays the footer
1119 require_once './libraries/footer.inc.php';