Translation update done using Pootle.
[phpmyadmin-themes.git] / tbl_change.php
blob263e4ab3626175841b5beaf2fe296d651344e949
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 * @version $Id$
9 * @package phpMyAdmin
12 /**
13 * Gets the variables sent or posted to this script and displays the header
15 require_once './libraries/common.inc.php';
17 /**
18 * Ensures db and table are valid, else moves to the "parent" script
20 require_once './libraries/db_table_exists.lib.php';
22 /**
23 * Sets global variables.
24 * Here it's better to use a if, instead of the '?' operator
25 * to avoid setting a variable to '' when it's not present in $_REQUEST
27 if (isset($_REQUEST['where_clause'])) {
28 $where_clause = $_REQUEST['where_clause'];
30 if (isset($_REQUEST['clause_is_unique'])) {
31 $clause_is_unique = $_REQUEST['clause_is_unique'];
33 if (isset($_SESSION['edit_next'])) {
34 $where_clause = $_SESSION['edit_next'];
35 unset($_SESSION['edit_next']);
36 $after_insert = 'edit_next';
38 if (isset($_REQUEST['sql_query'])) {
39 $sql_query = $_REQUEST['sql_query'];
41 if (isset($_REQUEST['ShowFunctionFields'])) {
42 $cfg['ShowFunctionFields'] = $_REQUEST['ShowFunctionFields'];
45 /**
46 * load relation data, foreign keys
48 require_once './libraries/relation.lib.php';
50 /**
51 * file listing
53 require_once './libraries/file_listing.php';
56 /**
57 * Defines the url to return to in case of error in a sql statement
58 * (at this point, $GLOBALS['goto'] will be set but could be empty)
60 if (empty($GLOBALS['goto'])) {
61 if (strlen($table)) {
62 // avoid a problem (see bug #2202709)
63 $GLOBALS['goto'] = 'tbl_sql.php';
64 } else {
65 $GLOBALS['goto'] = 'db_sql.php';
68 /**
69 * @todo check if we could replace by "db_|tbl_" - please clarify!?
71 $_url_params = array(
72 'db' => $db,
73 'sql_query' => $sql_query
76 if (preg_match('@^tbl_@', $GLOBALS['goto'])) {
77 $_url_params['table'] = $table;
80 $err_url = $GLOBALS['goto'] . PMA_generate_common_url($_url_params);
81 unset($_url_params);
84 /**
85 * Sets parameters for links
86 * where is this variable used?
87 * replace by PMA_generate_common_url($url_params);
89 $url_query = PMA_generate_common_url($url_params, 'html', '');
91 /**
92 * get table information
93 * @todo should be done by a Table object
95 require_once './libraries/tbl_info.inc.php';
97 /**
98 * Get comments for table fileds/columns
100 $comments_map = array();
102 if ($GLOBALS['cfg']['ShowPropertyComments']) {
103 $comments_map = PMA_getComments($db, $table);
107 * START REGULAR OUTPUT
111 * used in ./libraries/header.inc.php to load JavaScript library file
113 $GLOBALS['js_include'][] = 'tbl_change.js';
116 * HTTP and HTML headers
118 require_once './libraries/header.inc.php';
121 * Displays the query submitted and its result
123 * @todo where does $disp_message and $disp_query come from???
125 if (! empty($disp_message)) {
126 if (! isset($disp_query)) {
127 $disp_query = null;
129 PMA_showMessage($disp_message, $disp_query);
133 * Displays top menu links
135 require_once './libraries/tbl_links.inc.php';
139 * Get the analysis of SHOW CREATE TABLE for this table
140 * @todo should be handled by class Table
142 $show_create_table = PMA_DBI_fetch_value(
143 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
144 0, 1);
145 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
146 unset($show_create_table);
149 * Get the list of the fields of the current table
151 PMA_DBI_select_db($db);
152 $table_fields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ';',
153 null, null, null, PMA_DBI_QUERY_STORE);
154 $rows = array();
155 if (isset($where_clause)) {
156 // when in edit mode load all selected rows from table
157 $insert_mode = false;
158 if (is_array($where_clause)) {
159 $where_clause_array = $where_clause;
160 } else {
161 $where_clause_array = array(0 => $where_clause);
164 $result = array();
165 $found_unique_key = false;
166 $where_clauses = array();
168 foreach ($where_clause_array as $key_id => $where_clause) {
169 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $where_clause . ';';
170 $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE);
171 $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]);
172 $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause);
174 // No row returned
175 if (! $rows[$key_id]) {
176 unset($rows[$key_id], $where_clause_array[$key_id]);
177 PMA_showMessage($strEmptyResultSet, $local_query);
178 echo "\n";
179 require_once './libraries/footer.inc.php';
180 } else { // end if (no row returned)
181 $meta = PMA_DBI_get_fields_meta($result[$key_id]);
182 list($unique_condition, $tmp_clause_is_unique) = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true);
183 if (! empty($unique_condition)) {
184 $found_unique_key = true;
186 unset($unique_condition, $tmp_clause_is_unique);
189 } else {
190 // no primary key given, just load first row - but what happens if table is empty?
191 $insert_mode = true;
192 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
193 $rows = array_fill(0, $cfg['InsertRows'], false);
196 // <markus@noga.de>
197 // retrieve keys into foreign fields, if any
198 $foreigners = PMA_getForeigners($db, $table);
202 * Displays the form
204 // autocomplete feature of IE kills the "onchange" event handler and it
205 // must be replaced by the "onpropertychange" one in this case
206 $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5 && PMA_USR_BROWSER_VER < 7)
207 ? 'onpropertychange'
208 : 'onchange';
209 // Had to put the URI because when hosted on an https server,
210 // some browsers send wrongly this form to the http server.
212 if ($cfg['CtrlArrowsMoving']) {
214 <!-- Set on key handler for moving using by Ctrl+arrows -->
215 <script src="./js/keyhandler.js" type="text/javascript"></script>
216 <script type="text/javascript">
217 //<![CDATA[
218 var switch_movement = 0;
219 document.onkeydown = onKeyDownArrowsHandler;
220 //]]>
221 </script>
222 <?php
225 $_form_params = array(
226 'db' => $db,
227 'table' => $table,
228 'goto' => $GLOBALS['goto'],
229 'err_url' => $err_url,
230 'sql_query' => $sql_query,
232 if (isset($where_clauses)) {
233 foreach ($where_clause_array as $key_id => $where_clause) {
234 $_form_params['where_clause[' . $key_id . ']'] = trim($where_clause);
237 if (isset($clause_is_unique)) {
238 $_form_params['clause_is_unique'] = $clause_is_unique;
242 <!-- Insert/Edit form -->
243 <form method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?>>
244 <?php
245 echo PMA_generate_common_hidden_inputs($_form_params);
247 $titles['Browse'] = PMA_getIcon('b_browse.png', $strBrowseForeignValues);
249 // Set if we passed the first timestamp field
250 $timestamp_seen = 0;
251 $fields_cnt = count($table_fields);
253 $tabindex = 0;
254 $tabindex_for_function = +3000;
255 $tabindex_for_null = +6000;
256 $tabindex_for_value = 0;
257 $o_rows = 0;
258 $biggest_max_file_size = 0;
260 // user can toggle the display of Function column
261 // (currently does not work for multi-edits)
262 $url_params['db'] = $db;
263 $url_params['table'] = $table;
264 if (isset($where_clause)) {
265 $url_params['where_clause'] = trim($where_clause);
267 if (! empty($sql_query)) {
268 $url_params['sql_query'] = $sql_query;
271 if (! $cfg['ShowFunctionFields']) {
272 $this_url_params = array_merge($url_params,
273 array('ShowFunctionFields' => 1, 'goto' => 'sql.php'));
274 echo $strShow . ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . $strFunction . '</a>' . "\n";
277 foreach ($rows as $row_id => $vrow) {
278 if ($vrow === false) {
279 unset($vrow);
282 $jsvkey = $row_id;
283 $browse_foreigners_uri = '&amp;pk=' . $row_id;
284 $vkey = '[multi_edit][' . $jsvkey . ']';
286 $vresult = (isset($result) && is_array($result) && isset($result[$row_id]) ? $result[$row_id] : $result);
287 if ($insert_mode && $row_id > 0) {
288 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $row_id . '" id="insert_ignore_check_' . $row_id . '" />';
289 echo '<label for="insert_ignore_check_' . $row_id . '">' . $strIgnore . '</label><br />' . "\n";
292 <table>
293 <thead>
294 <tr>
295 <th><?php echo $strField; ?></th>
296 <th><?php echo $strType; ?></th>
297 <?php
298 if ($cfg['ShowFunctionFields']) {
299 $this_url_params = array_merge($url_params,
300 array('ShowFunctionFields' => 0, 'goto' => 'sql.php'));
301 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . $strHide . '">' . $strFunction . '</a></th>' . "\n";
304 <th><?php echo $strNull; ?></th>
305 <th><?php echo $strValue; ?></th>
306 </tr>
307 </thead>
308 <tfoot>
309 <tr>
310 <th colspan="5" align="right" class="tblFooters">
311 <input type="submit" value="<?php echo $strGo; ?>" />
312 </th>
313 </tr>
314 </tfoot>
315 <tbody>
316 <?php
317 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
318 $m_rows = $o_rows + 1;
320 $odd_row = true;
321 for ($i = 0; $i < $fields_cnt; $i++) {
322 if (! isset($table_fields[$i]['processed'])) {
323 $table_fields[$i]['Field_html'] = htmlspecialchars($table_fields[$i]['Field']);
324 $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']);
325 // True_Type contains only the type (stops at first bracket)
326 $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']);
328 // d a t e t i m e
330 // Current date should not be set as default if the field is NULL
331 // for the current row, but do not put here the current datetime
332 // if there is a default value (the real default value will be set
333 // in the Default value logic below)
335 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
336 // $field['Default'] is not set if it contains NULL:
337 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime)
338 // but, look what we get if we switch to iso: (Default is NULL)
339 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime)
340 // so I force a NULL into it (I don't think it's possible
341 // to have an empty default value for DATETIME)
342 // then, the "if" after this one will work
343 if ($table_fields[$i]['Type'] == 'datetime'
344 && ! isset($table_fields[$i]['Default'])
345 && isset($table_fields[$i]['Null'])
346 && $table_fields[$i]['Null'] == 'YES') {
347 $table_fields[$i]['Default'] = null;
350 $table_fields[$i]['len'] =
351 preg_match('@float|double@', $table_fields[$i]['Type']) ? 100 : -1;
354 if (isset($comments_map[$table_fields[$i]['Field']])) {
355 $table_fields[$i]['Field_title'] = '<span style="border-bottom: 1px dashed black;" title="'
356 . htmlspecialchars($comments_map[$table_fields[$i]['Field']]) . '">'
357 . $table_fields[$i]['Field_html'] . '</span>';
358 } else {
359 $table_fields[$i]['Field_title'] = $table_fields[$i]['Field_html'];
362 // The type column
363 $table_fields[$i]['is_binary'] = stristr($table_fields[$i]['Type'], 'binary');
364 $table_fields[$i]['is_blob'] = stristr($table_fields[$i]['Type'], 'blob');
365 $table_fields[$i]['is_char'] = stristr($table_fields[$i]['Type'], 'char');
366 $table_fields[$i]['first_timestamp'] = false;
367 switch ($table_fields[$i]['True_Type']) {
368 case 'set':
369 $table_fields[$i]['pma_type'] = 'set';
370 $table_fields[$i]['wrap'] = '';
371 break;
372 case 'enum':
373 $table_fields[$i]['pma_type'] = 'enum';
374 $table_fields[$i]['wrap'] = '';
375 break;
376 case 'timestamp':
377 if (!$timestamp_seen) { // can only occur once per table
378 $timestamp_seen = 1;
379 $table_fields[$i]['first_timestamp'] = true;
381 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
382 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
383 break;
385 default:
386 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
387 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
388 break;
391 $field = $table_fields[$i];
392 $extracted_fieldspec = PMA_extractFieldSpec($field['Type']);
394 if (-1 === $field['len']) {
395 $field['len'] = PMA_DBI_field_len($vresult, $i);
398 $unnullify_trigger = $chg_evt_handler . "=\"return unNullify('"
399 . PMA_escapeJsString($field['Field_md5']) . "', '"
400 . PMA_escapeJsString($jsvkey) . "')\"";
402 // Use an MD5 as an array index to avoid having special characters in the name atttibute (see bug #1746964 )
403 $field_name_appendix = $vkey . '[' . $field['Field_md5'] . ']';
404 $field_name_appendix_md5 = $field['Field_md5'] . $vkey . '[]';
407 if ($field['Type'] == 'datetime'
408 && ! isset($field['Default'])
409 && ! is_null($field['Default'])
410 && ($insert_mode || ! isset($vrow[$field['Field']]))) {
411 // INSERT case or
412 // UPDATE case with an NULL value
413 $vrow[$field['Field']] = date('Y-m-d H:i:s', time());
416 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
417 <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($field['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center">
418 <?php echo $field['Field_title']; ?>
419 <input type="hidden" name="fields_name<?php echo $field_name_appendix; ?>" value="<?php echo $field['Field_html']; ?>"/>
420 </td>
421 <td align="center"<?php echo $field['wrap']; ?>>
422 <?php echo $field['pma_type']; ?>
423 </td>
425 <?php
427 // Prepares the field value
428 $real_null_value = FALSE;
429 $special_chars_encoded = '';
430 if (isset($vrow)) {
431 // (we are editing)
432 if (is_null($vrow[$field['Field']])) {
433 $real_null_value = TRUE;
434 $vrow[$field['Field']] = '';
435 $special_chars = '';
436 $data = $vrow[$field['Field']];
437 } elseif ($field['True_Type'] == 'bit') {
438 $special_chars = PMA_printable_bit_value($vrow[$field['Field']], $extracted_fieldspec['spec_in_brackets']);
439 } else {
440 // special binary "characters"
441 if ($field['is_binary'] || $field['is_blob']) {
442 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields'] && !$cfg['ProtectBinary']) {
443 $vrow[$field['Field']] = bin2hex($vrow[$field['Field']]);
444 $field['display_binary_as_hex'] = true;
445 } else {
446 $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]);
448 } // end if
449 $special_chars = htmlspecialchars($vrow[$field['Field']]);
451 //We need to duplicate the first \n or otherwise we will lose the first newline entered in a VARCHAR or TEXT column
452 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
454 $data = $vrow[$field['Field']];
455 } // end if... else...
456 // If a timestamp field value is not included in an update
457 // statement MySQL auto-update it to the current timestamp;
458 // however, things have changed since MySQL 4.1, so
459 // it's better to set a fields_prev in this situation
460 $backup_field = '<input type="hidden" name="fields_prev'
461 . $field_name_appendix . '" value="'
462 . htmlspecialchars($vrow[$field['Field']]) . '" />';
463 } else {
464 // (we are inserting)
465 // display default values
466 if (!isset($field['Default'])) {
467 $field['Default'] = '';
468 $real_null_value = TRUE;
469 $data = '';
470 } else {
471 $data = $field['Default'];
473 if ($field['True_Type'] == 'bit') {
474 $special_chars = PMA_convert_bit_default_value($field['Default']);
475 } else {
476 $special_chars = htmlspecialchars($field['Default']);
478 $backup_field = '';
479 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
480 // this will select the UNHEX function while inserting
481 if (($field['is_binary'] || $field['is_blob']) && $_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields'] && ! $cfg['ProtectBinary']) {
482 $field['display_binary_as_hex'] = true;
486 $idindex = ($o_rows * $fields_cnt) + $i + 1;
487 $tabindex = (($idindex - 1) * 3) + 1;
489 // The function column
490 // -------------------
491 // Change by Bernard M. Piller <bernard@bmpsystems.com>
492 // We don't want binary data to be destroyed
493 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
494 // stored or retrieved" so it does not mean that the contents is
495 // binary
496 if ($cfg['ShowFunctionFields']) {
497 if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload)
498 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
499 echo ' <td align="center">' . $strBinary . '</td>' . "\n";
500 } elseif (strstr($field['True_Type'], 'enum') || strstr($field['True_Type'], 'set')) {
501 echo ' <td align="center">--</td>' . "\n";
502 } else {
504 <td>
505 <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">
506 <option></option>
507 <?php
508 $selected = '';
510 // Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
511 // or something similar. Then directly look up the entry in the RestrictFunctions array,
512 // which will then reveal the available dropdown options
513 if (isset($cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])])
514 && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])]])) {
515 $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])];
516 $dropdown = $cfg['RestrictFunctions'][$current_func_type];
517 $default_function = $cfg['DefaultFunctions'][$current_func_type];
518 } else {
519 $dropdown = array();
520 $default_function = '';
523 $dropdown_built = array();
524 $op_spacing_needed = FALSE;
526 // what function defined as default?
527 // for the first timestamp we don't set the default function
528 // if there is a default value for the timestamp
529 // (not including CURRENT_TIMESTAMP)
530 // and the column does not have the
531 // ON UPDATE DEFAULT TIMESTAMP attribute.
533 if ($field['True_Type'] == 'timestamp'
534 && empty($field['Default'])
535 && ! isset($analyzed_sql[0]['create_table_fields'][$field['Field']]['on_update_current_timestamp'])) {
536 $default_function = $cfg['DefaultFunctions']['first_timestamp'];
539 // For primary keys of type char(36) or varchar(36) UUID if the default function
540 // Only applies to insert mode, as it would silently trash data on updates.
541 if ($insert_mode
542 && $field['Key'] == 'PRI'
543 && ($field['Type'] == 'char(36)' || $field['Type'] == 'varchar(36)')
545 $default_function = $cfg['DefaultFunctions']['pk_char36'];
548 // this is set only when appropriate and is always true
549 if (isset($field['display_binary_as_hex'])) {
550 $default_function = 'UNHEX';
553 // loop on the dropdown array and print all available options for that field.
554 foreach ($dropdown as $each_dropdown){
555 echo '<option';
556 if ($default_function === $each_dropdown) {
557 echo ' selected="selected"';
559 echo '>' . $each_dropdown . '</option>' . "\n";
560 $dropdown_built[$each_dropdown] = 'TRUE';
561 $op_spacing_needed = TRUE;
564 // For compatibility's sake, do not let out all other functions. Instead
565 // print a separator (blank) and then show ALL functions which weren't shown
566 // yet.
567 $cnt_functions = count($cfg['Functions']);
568 for ($j = 0; $j < $cnt_functions; $j++) {
569 if (!isset($dropdown_built[$cfg['Functions'][$j]]) || $dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
570 // Is current function defined as default?
571 $selected = ($field['first_timestamp'] && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
572 || (!$field['first_timestamp'] && $cfg['Functions'][$j] == $default_function)
573 ? ' selected="selected"'
574 : '';
575 if ($op_spacing_needed == TRUE) {
576 echo ' ';
577 echo '<option value="">--------</option>' . "\n";
578 $op_spacing_needed = FALSE;
581 echo ' ';
582 echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
584 } // end for
585 unset($selected);
587 </select>
588 </td>
589 <?php
591 } // end if ($cfg['ShowFunctionFields'])
594 // The null column
595 // ---------------
596 $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', '');
597 echo ' <td>' . "\n";
598 if ($field['Null'] == 'YES') {
599 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
600 if ($real_null_value && !$field['first_timestamp']) {
601 echo ' value="on"';
603 echo ' />' . "\n";
605 echo ' <input type="checkbox" tabindex="' . ($tabindex + $tabindex_for_null) . '"'
606 . ' name="fields_null' . $field_name_appendix . '"';
607 if ($real_null_value && !$field['first_timestamp']) {
608 echo ' checked="checked"';
610 echo ' id="field_' . ($idindex) . '_2"';
611 $onclick = ' onclick="if (this.checked) {nullify(';
612 if (strstr($field['True_Type'], 'enum')) {
613 if (strlen($field['Type']) > 20) {
614 $onclick .= '1, ';
615 } else {
616 $onclick .= '2, ';
618 } elseif (strstr($field['True_Type'], 'set')) {
619 $onclick .= '3, ';
620 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == false) {
621 // foreign key in a drop-down
622 $onclick .= '4, ';
623 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == true) {
624 // foreign key with a browsing icon
625 $onclick .= '6, ';
626 } else {
627 $onclick .= '5, ';
629 $onclick .= '\'' . PMA_escapeJsString($field['Field_html']) . '\', \'' . $field['Field_md5'] . '\', \'' . PMA_escapeJsString($vkey) . '\'); this.checked = true}; return true" />' . "\n";
630 echo $onclick;
632 echo ' </td>' . "\n";
634 // The value column (depends on type)
635 // ----------------
636 // See bug #1667887 for the reason why we don't use the maxlength
637 // HTML attribute
639 echo ' <td>' . "\n";
640 if ($foreignData['foreign_link'] == true) {
641 echo $backup_field . "\n";
643 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
644 value="foreign" />
645 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
646 value="" id="field_<?php echo ($idindex); ?>_3A" />
647 <input type="text" name="field_<?php echo $field_name_appendix_md5; ?>"
648 class="textfield" <?php echo $unnullify_trigger; ?>
649 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
650 id="field_<?php echo ($idindex); ?>_3"
651 value="<?php echo htmlspecialchars($data); ?>" />
652 <script type="text/javascript">
653 //<![CDATA[
654 document.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes,resizable=yes\'); return false"');
655 document.write(' href="browse_foreigners.php?');
656 document.write('<?php echo PMA_generate_common_url($db, $table); ?>');
657 document.writeln('&amp;field=<?php echo PMA_escapeJsString(urlencode($field['Field']) . $browse_foreigners_uri); ?>">');
658 document.writeln('<?php echo str_replace("'", "\'", $titles['Browse']); ?></a>');
659 //]]>
660 </script>
661 <?php
662 } elseif (is_array($foreignData['disp_row'])) {
663 echo $backup_field . "\n";
665 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
666 value="foreign" />
667 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
668 value="" id="field_<?php echo $idindex; ?>_3A" />
669 <select name="field_<?php echo $field_name_appendix_md5; ?>"
670 <?php echo $unnullify_trigger; ?>
671 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
672 id="field_<?php echo ($idindex); ?>_3">
673 <?php echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?>
674 </select>
675 <?php
676 // still needed? :
677 unset($foreignData['disp_row']);
678 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
680 &nbsp;</td>
681 </tr>
682 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
683 <td colspan="5" align="right">
684 <?php echo $backup_field . "\n"; ?>
685 <textarea name="fields<?php echo $field_name_appendix; ?>"
686 rows="<?php echo ($cfg['TextareaRows']*2); ?>"
687 cols="<?php echo ($cfg['TextareaCols']*2); ?>"
688 dir="<?php echo $text_dir; ?>"
689 id="field_<?php echo ($idindex); ?>_3"
690 <?php echo $unnullify_trigger; ?>
691 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
692 ><?php echo $special_chars_encoded; ?></textarea>
693 <?php
694 } elseif (strstr($field['pma_type'], 'text')) {
695 echo $backup_field . "\n";
697 <textarea name="fields<?php echo $field_name_appendix; ?>"
698 rows="<?php echo $cfg['TextareaRows']; ?>"
699 cols="<?php echo $cfg['TextareaCols']; ?>"
700 dir="<?php echo $text_dir; ?>"
701 id="field_<?php echo ($idindex); ?>_3"
702 <?php echo $unnullify_trigger; ?>
703 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
704 ><?php echo $special_chars_encoded; ?></textarea>
705 <?php
706 echo "\n";
707 if (strlen($special_chars) > 32000) {
708 echo " </td>\n";
709 echo ' <td>' . $strTextAreaLength;
711 } elseif ($field['pma_type'] == 'enum') {
712 if (! isset($table_fields[$i]['values'])) {
713 $table_fields[$i]['values'] = array();
714 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
715 // Removes automatic MySQL escape format
716 $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
717 $table_fields[$i]['values'][] = array(
718 'plain' => $val,
719 'html' => htmlspecialchars($val),
723 $field_enum_values = $table_fields[$i]['values'];
725 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="enum" />
726 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
727 <?php
728 echo "\n" . ' ' . $backup_field . "\n";
730 // show dropdown or radio depend on length
731 if (strlen($field['Type']) > 20) {
733 <select name="field_<?php echo $field_name_appendix_md5; ?>"
734 <?php echo $unnullify_trigger; ?>
735 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
736 id="field_<?php echo ($idindex); ?>_3">
737 <option value="">&nbsp;</option>
738 <?php
739 echo "\n";
741 foreach ($field_enum_values as $enum_value) {
742 echo ' ';
743 echo '<option value="' . $enum_value['html'] . '"';
744 if ($data == $enum_value['plain']
745 || ($data == ''
746 && (! isset($where_clause) || $field['Null'] != 'YES')
747 && isset($field['Default'])
748 && $enum_value['plain'] == $field['Default'])) {
749 echo ' selected="selected"';
751 echo '>' . $enum_value['html'] . '</option>' . "\n";
752 } // end for
755 </select>
756 <?php
757 } else {
758 $j = 0;
759 foreach ($field_enum_values as $enum_value) {
760 echo ' ';
761 echo '<input type="radio" name="field_' . $field_name_appendix_md5 . '"';
762 echo ' value="' . $enum_value['html'] . '"';
763 echo ' id="field_' . ($idindex) . '_3_' . $j . '"';
764 echo $unnullify_trigger;
765 if ($data == $enum_value['plain']
766 || ($data == ''
767 && (! isset($where_clause) || $field['Null'] != 'YES')
768 && isset($field['Default'])
769 && $enum_value['plain'] == $field['Default'])) {
770 echo ' checked="checked"';
772 echo ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
773 echo '<label for="field_' . $idindex . '_3_' . $j . '">'
774 . $enum_value['html'] . '</label>' . "\n";
775 $j++;
776 } // end for
777 } // end else
778 } elseif ($field['pma_type'] == 'set') {
779 if (! isset($table_fields[$i]['values'])) {
780 $table_fields[$i]['values'] = array();
781 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
782 $table_fields[$i]['values'][] = array(
783 'plain' => $val,
784 'html' => htmlspecialchars($val),
787 $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
789 $field_set_values = $table_fields[$i]['values'];
790 $select_size = $table_fields[$i]['select_size'];
792 $vset = array_flip(explode(',', $data));
793 echo $backup_field . "\n";
795 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="set" />
796 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
797 <select name="field_<?php echo $field_name_appendix_md5; ?>"
798 size="<?php echo $select_size; ?>"
799 multiple="multiple" <?php echo $unnullify_trigger; ?>
800 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
801 id="field_<?php echo ($idindex); ?>_3">
802 <?php
803 foreach ($field_set_values as $field_set_value) {
804 echo ' ';
805 echo '<option value="' . $field_set_value['html'] . '"';
806 if (isset($vset[$field_set_value['plain']])) {
807 echo ' selected="selected"';
809 echo '>' . $field_set_value['html'] . '</option>' . "\n";
810 } // end for
812 </select>
813 <?php
815 // Change by Bernard M. Piller <bernard@bmpsystems.com>
816 // We don't want binary data destroyed
817 elseif ($field['is_binary'] || $field['is_blob']) {
818 if (($cfg['ProtectBinary'] && $field['is_blob'])
819 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
820 echo "\n";
821 // rajk - for blobstreaming
822 $bs_reference_exists = FALSE;
824 if (isset ($tbl_type) && strlen ($tbl_type) > 0)
826 // load PMA_Config
827 $PMA_Config = $GLOBALS['PMA_Config'];
829 if (!empty($PMA_Config))
831 $requiredTblType = $PMA_Config->get('PBXT_NAME');
833 if ($requiredTblType == strtolower ($tbl_type))
835 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
837 // check if blobstreaming plugins exist
838 if ($pluginsExist)
840 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
842 if (!empty($bs_tables) && strlen($db) > 0)
844 $bs_tables = $bs_tables[$db];
846 if (isset($bs_tables))
848 $allBSTablesExist = TRUE;
850 foreach ($bs_tables as $table_key=>$bs_tbl)
851 if (!$bs_tables[$table_key]['Exists'])
853 $allBSTablesExist = FALSE;
854 break;
857 if ($allBSTablesExist)
858 $bs_reference_exists = PMA_BS_ReferenceExists($data, $db);
859 } // end if (isset($bs_tables))
860 } // end if (!empty($bs_tables) && strlen($db) > 0)
861 } // end if ($pluginsExist)
862 } // end if ($requiredTblType == strtolower ($tbl_type))
863 } // end if (!empty($PMA_Config))
864 } // end if (isset ($tbl_type) && strlen ($tbl_type) > 0)
866 if ($bs_reference_exists)
868 echo '<input type="hidden" name="remove_blob_ref_' . $field['Field_md5'] . $vkey . '" value="' . $data . '" />';
869 echo '<input type="checkbox" name="remove_blob_repo_' . $field['Field_md5'] . $vkey . '" /> ' . $strBLOBRepositoryRemove . "<br />";
870 echo PMA_BS_CreateReferenceLink($data, $db);
871 echo "<br />";
873 else
875 echo $strBinaryDoNotEdit;
876 if (isset($data)) {
877 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
878 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
879 unset($data_size);
881 echo "\n";
882 } // end if ($bs_reference_exists)
884 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="protected" />
885 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
886 <?php
887 } elseif ($field['is_blob']) {
888 echo "\n";
889 echo $backup_field . "\n";
891 <textarea name="fields<?php echo $field_name_appendix; ?>"
892 rows="<?php echo $cfg['TextareaRows']; ?>"
893 cols="<?php echo $cfg['TextareaCols']; ?>"
894 dir="<?php echo $text_dir; ?>"
895 id="field_<?php echo ($idindex); ?>_3"
896 <?php echo $unnullify_trigger; ?>
897 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
898 ><?php echo $special_chars_encoded; ?></textarea>
899 <?php
901 } else {
902 // field size should be at least 4 and max 40
903 $fieldsize = min(max($field['len'], 4), 40);
904 echo "\n";
905 echo $backup_field . "\n";
907 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
908 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
909 class="textfield" <?php echo $unnullify_trigger; ?>
910 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
911 id="field_<?php echo ($idindex); ?>_3" />
912 <?php
913 } // end if...elseif...else
915 // Upload choice (only for BLOBs because the binary
916 // attribute does not imply binary contents)
917 // (displayed whatever value the ProtectBinary has)
919 if ($is_upload && $field['is_blob']) {
920 // added by rajk
921 // check if field type is of longblob
922 if ($field['pma_type'] == "longblob")
924 if (isset ($tbl_type) && strlen ($tbl_type) > 0)
926 // load PMA Config
927 $PMA_Config = $GLOBALS['PMA_Config'];
929 // is PMA_Config's data loaded? continue only if it is
930 if (!empty($PMA_Config))
932 $requiredTblType = $PMA_Config->get('PBXT_NAME');
934 if ($requiredTblType == strtolower ($tbl_type))
936 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
938 // check if blobstreaming plugins exist
939 if ($pluginsExist)
941 $curlExists = $PMA_Config->get('CURL_EXISTS');
943 // check if CURL exists
944 if ($curlExists)
946 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
948 // check for BLOBStreamable databases and if current database name is provided
949 if (!empty($bs_tables) && strlen($db) > 0)
951 $bs_tables = $bs_tables[$db];
953 // check if reference to BLOBStreaming tables exists
954 if (isset($bs_tables))
956 $allBSTablesExist = TRUE;
958 foreach ($bs_tables as $table_key=>$bs_tbl)
959 if (!$bs_tables[$table_key]['Exists'])
961 $allBSTablesExist = FALSE;
962 break;
965 // check if necessary BLOBStreaming tables exist
966 if ($allBSTablesExist)
968 echo '<br />';
969 echo '<input type="checkbox" name="upload_blob_repo_' . $field['Field_md5'] . $vkey . '" /> ' . $strBLOBRepositoryUpload;
970 } // end if ($allBSTablesExist)
971 } // end if (isset($bs_tables)
972 } // end if (!empty($bs_tables) && strlen ($db) > 0)
973 } // end if ($curlExists)
974 } // end if ($pluginsExist)
975 } // end if ($requiredTblType == strtolower ($tbl_type))
976 } // end if (!empty($PMA_Config))
977 } // end if (isset ($tbl_type) && strlen ($tbl_type) > 0)
980 echo '<br />';
981 echo '<input type="file" name="fields_upload_' . $field['Field_md5'] . $vkey . '" class="textfield" id="field_' . $idindex . '_3" size="10" ' . $unnullify_trigger . '/>&nbsp;';
983 // find maximum upload size, based on field type
985 * @todo with functions this is not so easy, as you can basically
986 * process any data with function like MD5
988 $max_field_sizes = array(
989 'tinyblob' => '256',
990 'blob' => '65536',
991 'mediumblob' => '16777216',
992 'longblob' => '4294967296'); // yeah, really
994 $this_field_max_size = $max_upload_size; // from PHP max
995 if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
996 $this_field_max_size = $max_field_sizes[$field['pma_type']];
998 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
999 // do not generate here the MAX_FILE_SIZE, because we should
1000 // put only one in the form to accommodate the biggest field
1001 if ($this_field_max_size > $biggest_max_file_size) {
1002 $biggest_max_file_size = $this_field_max_size;
1006 if (!empty($cfg['UploadDir'])) {
1007 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
1008 if ($files === FALSE) {
1009 echo ' <font color="red">' . $strError . '</font><br />' . "\n";
1010 echo ' ' . $strWebServerUploadDirectoryError . "\n";
1011 } elseif (!empty($files)) {
1012 echo "<br />\n";
1013 echo ' <i>' . $strOr . '</i>' . ' ' . $strWebServerUploadDirectory . ':<br />' . "\n";
1014 echo ' <select size="1" name="fields_uploadlocal_' . $field['Field_md5'] . $vkey . '">' . "\n";
1015 echo ' <option value="" selected="selected"></option>' . "\n";
1016 echo $files;
1017 echo ' </select>' . "\n";
1019 } // end if (web-server upload directory)
1020 } // end elseif (binary or blob)
1021 else {
1022 // field size should be at least 4 and max 40
1023 $fieldsize = min(max($field['len'], 4), 40);
1024 echo $backup_field . "\n";
1025 if ($field['is_char'] && ($cfg['CharEditing'] == 'textarea' || strpos($data, "\n") !== FALSE)) {
1026 echo "\n";
1028 <textarea name="fields<?php echo $field_name_appendix; ?>"
1029 rows="<?php echo $cfg['CharTextareaRows']; ?>"
1030 cols="<?php echo $cfg['CharTextareaCols']; ?>"
1031 dir="<?php echo $text_dir; ?>"
1032 id="field_<?php echo ($idindex); ?>_3"
1033 <?php echo $unnullify_trigger; ?>
1034 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
1035 ><?php echo $special_chars_encoded; ?></textarea>
1036 <?php
1037 } else {
1039 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
1040 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
1041 class="textfield" <?php echo $unnullify_trigger; ?>
1042 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
1043 id="field_<?php echo ($idindex); ?>_3" />
1044 <?php
1045 if ($field['Extra'] == 'auto_increment') {
1047 <input type="hidden" name="auto_increment<?php echo $field_name_appendix; ?>" value="1" />
1048 <?php
1049 } // end if
1050 if (substr($field['pma_type'], 0, 9) == 'timestamp') {
1052 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="timestamp" />
1053 <?php
1055 if ($field['True_Type'] == 'bit') {
1057 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="bit" />
1058 <?php
1060 if ($field['pma_type'] == 'date' || $field['pma_type'] == 'datetime' || substr($field['pma_type'], 0, 9) == 'timestamp') {
1061 // the _3 suffix points to the date field
1062 // the _2 suffix points to the corresponding NULL checkbox
1064 <script type="text/javascript">
1065 //<![CDATA[
1066 document.write('<a title="<?php echo $strCalendar;?>"');
1067 document.write(' href="javascript:openCalendar(\'<?php echo PMA_generate_common_url();?>\', \'insertForm\', \'field_<?php echo ($idindex); ?>_3\', \'<?php echo (substr($field['pma_type'], 0, 9) == 'timestamp') ? 'datetime' : substr($field['pma_type'], 0, 9); ?>\', \'field_<?php echo ($idindex); ?>_2\')">');
1068 document.write('<img class="calendar"');
1069 document.write(' src="<?php echo $pmaThemeImage; ?>b_calendar.png"');
1070 document.write(' alt="<?php echo $strCalendar; ?>"/></a>');
1071 //]]>
1072 </script>
1073 <?php
1078 </td>
1079 </tr>
1080 <?php
1081 $odd_row = !$odd_row;
1082 } // end for
1083 $o_rows++;
1084 echo ' </tbody></table><br />';
1085 } // end foreach on multi-edit
1087 <br />
1089 <fieldset>
1090 <table border="0" cellpadding="5" cellspacing="0">
1091 <tr>
1092 <td valign="middle" nowrap="nowrap">
1093 <select name="submit_type" tabindex="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
1094 <?php
1095 if (isset($where_clause)) {
1097 <option value="save"><?php echo $strSave; ?></option>
1098 <?php
1101 <option value="insert"><?php echo $strInsertAsNewRow; ?></option>
1102 <option value="insertignore"><?php echo $strInsertIgnoreAsNewRow; ?></option>
1103 <option value="showinsert"><?php echo $strShowInsert; ?></option>
1104 </select>
1105 <?php
1106 echo "\n";
1108 if (!isset($after_insert)) {
1109 $after_insert = 'back';
1112 </td>
1113 <td valign="middle">
1114 &nbsp;&nbsp;&nbsp;<strong><?php echo $strAndThen; ?></strong>&nbsp;&nbsp;&nbsp;
1115 </td>
1116 <td valign="middle" nowrap="nowrap">
1117 <select name="after_insert">
1118 <option value="back" <?php echo ($after_insert == 'back' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertBack; ?></option>
1119 <option value="new_insert" <?php echo ($after_insert == 'new_insert' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertNewInsert; ?></option>
1120 <?php
1121 if (isset($where_clause)) {
1123 <option value="same_insert" <?php echo ($after_insert == 'same_insert' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertSame; ?></option>
1124 <?php
1125 // If we have just numeric primary key, we can also edit next
1126 // in 2.8.2, we were looking for `field_name` = numeric_value
1127 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $where_clause)) {
1128 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1129 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $where_clause)) {
1131 <option value="edit_next" <?php echo ($after_insert == 'edit_next' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertNext; ?></option>
1132 <?php
1136 </select>
1137 </td>
1138 </tr>
1140 <tr>
1141 <td>
1142 <?php echo PMA_showHint($strUseTabKey); ?>
1143 </td>
1144 <td colspan="3" align="right" valign="middle">
1145 <input type="submit" value="<?php echo $strGo; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 6); ?>" id="buttonYes" />
1146 <input type="reset" value="<?php echo $strReset; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 7); ?>" />
1147 </td>
1148 </tr>
1149 </table>
1150 </fieldset>
1151 <?php if ($biggest_max_file_size > 0) {
1152 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
1153 } ?>
1154 </form>
1155 <?php
1156 if ($insert_mode) {
1158 <!-- Restart insertion form -->
1159 <form method="post" action="tbl_replace.php" name="restartForm" >
1160 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
1161 <input type="hidden" name="goto" value="<?php echo htmlspecialchars($GLOBALS['goto']); ?>" />
1162 <input type="hidden" name="err_url" value="<?php echo htmlspecialchars($err_url); ?>" />
1163 <input type="hidden" name="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
1164 <?php
1165 if (isset($where_clauses)) {
1166 foreach ($where_clause_array as $key_id => $where_clause) {
1167 echo '<input type="hidden" name="where_clause[' . $key_id . ']" value="' . htmlspecialchars(trim($where_clause)) . '" />'. "\n";
1170 $tmp = '<select name="insert_rows" id="insert_rows" onchange="this.form.submit();" >' . "\n";
1171 $option_values = array(1,2,5,10,15,20,30,40);
1172 foreach ($option_values as $value) {
1173 $tmp .= '<option value="' . $value . '"';
1174 if ($value == $cfg['InsertRows']) {
1175 $tmp .= ' selected="selected"';
1177 $tmp .= '>' . $value . '</option>' . "\n";
1179 $tmp .= '</select>' . "\n";
1180 echo "\n" . sprintf($strRestartInsertion, $tmp);
1181 unset($tmp);
1182 echo '<noscript><input type="submit" value="' . $strGo . '" /></noscript>' . "\n";
1183 echo '</form>' . "\n";
1187 * Displays the footer
1189 require_once './libraries/footer.inc.php';