cache table information
[phpmyadmin.git] / tbl_change.php
blob5e5467380a861cf266519fef5a442a6f3520de38
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 */
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';
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 /**
28 * @todo this one is badly named, it's really a WHERE condition
29 * and exists even for tables not having a primary key or unique key
31 if (isset($_REQUEST['primary_key'])) {
32 $primary_key = $_REQUEST['primary_key'];
34 if (isset($_SESSION['edit_next'])) {
35 $primary_key = $_SESSION['edit_next'];
36 unset($_SESSION['edit_next']);
37 $after_insert = 'edit_next';
39 if (isset($_REQUEST['sql_query'])) {
40 $sql_query = $_REQUEST['sql_query'];
42 if (isset($_REQUEST['ShowFunctionFields'])) {
43 $cfg['ShowFunctionFields'] = $_REQUEST['ShowFunctionFields'];
46 /**
47 * load relation data, foreign keys
49 require_once './libraries/relation.lib.php';
51 /**
52 * file listing
54 require_once './libraries/file_listing.php';
57 /**
58 * Defines the url to return to in case of error in a sql statement
59 * (at this point, $GLOBALS['goto'] will be set but could be empty)
61 if (empty($GLOBALS['goto'])) {
62 $GLOBALS['goto'] = 'db_sql.php';
64 /**
65 * @todo check if we could replace by "db_|tbl_" - please clarify!?
67 $_url_params = array(
68 'db' => $db,
69 'sql_query' => $sql_query
72 if (preg_match('@^tbl_@', $GLOBALS['goto'])) {
73 $_url_params['table'] = $table;
76 $err_url = $GLOBALS['goto'] . PMA_generate_common_url($_url_params);
77 unset($_url_params);
80 /**
81 * Sets parameters for links
82 * where is this variable used?
83 * replace by PMA_generate_common_url($url_params);
85 $url_query = PMA_generate_common_url($url_params, 'html', '');
87 /**
88 * get table information
89 * @todo should be done by a Table object
91 require_once './libraries/tbl_info.inc.php';
93 /**
94 * Get comments for table fileds/columns
96 $comments_map = array();
98 if ($GLOBALS['cfg']['ShowPropertyComments']) {
99 $comments_map = PMA_getComments($db, $table);
103 * START REGULAR OUTPUT
107 * used in ./libraries/header.inc.php to load JavaScript library file
109 $GLOBALS['js_include'][] = 'tbl_change.js';
112 * HTTP and HTML headers
114 require_once './libraries/header.inc.php';
117 * Displays the query submitted and its result
119 * @todo where does $disp_message and $disp_query come from???
121 if (! empty($disp_message)) {
122 if (! isset($disp_query)) {
123 $disp_query = null;
125 PMA_showMessage($disp_message, $disp_query);
129 * Displays top menu links
131 require_once './libraries/tbl_links.inc.php';
135 * Get the analysis of SHOW CREATE TABLE for this table
136 * @todo should be handled by class Table
138 $show_create_table = PMA_DBI_fetch_value(
139 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
140 0, 1);
141 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
142 unset($show_create_table);
145 * Get the list of the fields of the current table
147 PMA_DBI_select_db($db);
148 $table_fields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ';',
149 null, null, null, PMA_DBI_QUERY_STORE);
150 $rows = array();
151 if (isset($primary_key)) {
152 // when in edit mode load all selected rows from table
153 $insert_mode = false;
154 if (is_array($primary_key)) {
155 $primary_key_array = $primary_key;
156 } else {
157 $primary_key_array = array(0 => $primary_key);
160 $result = array();
161 $found_unique_key = false;
162 foreach ($primary_key_array as $key_id => $primary_key) {
163 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';';
164 $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE);
165 $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]);
166 $primary_keys[$key_id] = str_replace('\\', '\\\\', $primary_key);
168 // No row returned
169 if (! $rows[$key_id]) {
170 unset($rows[$key_id], $primary_key_array[$key_id]);
171 PMA_showMessage($strEmptyResultSet, $local_query);
172 echo "\n";
173 require_once './libraries/footer.inc.php';
174 } else { // end if (no record returned)
175 $meta = PMA_DBI_get_fields_meta($result[$key_id]);
176 if ($tmp = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true)) {
177 $found_unique_key = true;
179 unset($tmp);
182 } else {
183 // no primary key given, just load first row - but what happens if tbale is empty?
184 $insert_mode = true;
185 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
186 $rows = array_fill(0, $cfg['InsertRows'], false);
189 // <markus@noga.de>
190 // retrieve keys into foreign fields, if any
191 $foreigners = PMA_getForeigners($db, $table);
195 * Displays the form
197 // loic1: autocomplete feature of IE kills the "onchange" event handler and it
198 // must be replaced by the "onpropertychange" one in this case
199 $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5)
200 ? 'onpropertychange'
201 : 'onchange';
202 // Had to put the URI because when hosted on an https server,
203 // some browsers send wrongly this form to the http server.
205 if ($cfg['CtrlArrowsMoving']) {
207 <!-- Set on key handler for moving using by Ctrl+arrows -->
208 <script src="./js/keyhandler.js" type="text/javascript"></script>
209 <script type="text/javascript">
210 //<![CDATA[
211 var switch_movement = 0;
212 document.onkeydown = onKeyDownArrowsHandler;
213 //]]>
214 </script>
215 <?php
218 $_form_params = array(
219 'db' => $db,
220 'table' => $table,
221 'goto' => $GLOBALS['goto'],
222 'err_url' => $err_url,
223 'sql_query' => $sql_query,
225 if (isset($primary_keys)) {
226 foreach ($primary_key_array as $key_id => $primary_key) {
227 $_form_params['primary_key[' . $key_id . ']'] = trim($primary_key);
232 <!-- Insert/Edit form -->
233 <form method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?>>
234 <?php
235 echo PMA_generate_common_hidden_inputs($_form_params);
237 $titles['Browse'] = PMA_getIcon('b_browse.png', $strBrowseForeignValues);
239 // Set if we passed the first timestamp field
240 $timestamp_seen = 0;
241 $fields_cnt = count($table_fields);
243 $tabindex = 0;
244 $tabindex_for_function = +1000;
245 $tabindex_for_null = +2000;
246 $tabindex_for_value = 0;
247 $o_rows = 0;
248 $biggest_max_file_size = 0;
250 // user can toggle the display of Function column
251 // (currently does not work for multi-edits)
252 $url_params['db'] = $db;
253 $url_params['table'] = $table;
254 if (isset($primary_key)) {
255 $url_params['primary_key'] = trim($primary_key);
257 if (! empty($sql_query)) {
258 $url_params['sql_query'] = $sql_query;
261 if (! $cfg['ShowFunctionFields']) {
262 $this_url_params = array_merge($url_params,
263 array('ShowFunctionFields' => 1));
264 echo $strShow . ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . $strFunction . '</a>' . "\n";
267 foreach ($rows as $row_id => $vrow) {
268 if ($vrow === false) {
269 unset($vrow);
272 $jsvkey = $row_id;
273 $browse_foreigners_uri = '&amp;pk=' . $row_id;
274 $vkey = '[multi_edit][' . $jsvkey . ']';
276 $vresult = (isset($result) && is_array($result) && isset($result[$row_id]) ? $result[$row_id] : $result);
277 if ($insert_mode && $row_id > 0) {
278 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $row_id . '" id="insert_ignore_check_' . $row_id . '" />';
279 echo '<label for="insert_ignore_check_' . $row_id . '">' . $strIgnore . '</label><br />' . "\n";
282 <table>
283 <thead>
284 <tr>
285 <th><?php echo $strField; ?></th>
286 <th><?php echo $strType; ?></th>
287 <?php
288 if ($cfg['ShowFunctionFields']) {
289 $this_url_params = array_merge($url_params,
290 array('ShowFunctionFields' => 0));
291 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . $strHide . '">' . $strFunction . '</a></th>' . "\n";
294 <th><?php echo $strNull; ?></th>
295 <th><?php echo $strValue; ?></th>
296 </tr>
297 </thead>
298 <tfoot>
299 <tr>
300 <th colspan="5" align="right" class="tblFooters">
301 <input type="submit" value="<?php echo $strGo; ?>" />
302 </th>
303 </tr>
304 </tfoot>
305 <tbody>
306 <?php
307 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
308 $m_rows = $o_rows + 1;
310 $odd_row = true;
311 for ($i = 0; $i < $fields_cnt; $i++) {
312 if (! isset($table_fields[$i]['processed'])) {
313 $table_fields[$i]['Field_html'] = htmlspecialchars($table_fields[$i]['Field']);
314 $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']);
315 $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']);
317 // d a t e t i m e
319 // loic1: current date should not be set as default if the field is NULL
320 // for the current row
321 // lem9: but do not put here the current datetime if there is a default
322 // value (the real default value will be set in the
323 // Default value logic below)
325 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
326 // $field['Default'] is not set if it contains NULL:
327 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime)
328 // but, look what we get if we switch to iso: (Default is NULL)
329 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime)
330 // so I force a NULL into it (I don't think it's possible
331 // to have an empty default value for DATETIME)
332 // then, the "if" after this one will work
333 if ($table_fields[$i]['Type'] == 'datetime'
334 && ! isset($table_fields[$i]['Default'])
335 && isset($table_fields[$i]['Null'])
336 && $table_fields[$i]['Null'] == 'YES') {
337 $table_fields[$i]['Default'] = null;
340 $table_fields[$i]['len'] =
341 preg_match('@float|double@', $table_fields[$i]['Type']) ? 100 : -1;
344 if (isset($comments_map[$table_fields[$i]['Field']])) {
345 $table_fields[$i]['Field_title'] = '<span style="border-bottom: 1px dashed black;" title="'
346 . htmlspecialchars($comments_map[$table_fields[$i]['Field']]) . '">'
347 . $table_fields[$i]['Field_html'] . '</span>';
348 } else {
349 $table_fields[$i]['Field_title'] = $table_fields[$i]['Field_html'];
352 // The type column
353 $table_fields[$i]['is_binary'] = stristr($table_fields[$i]['Type'], 'binary');
354 $table_fields[$i]['is_blob'] = stristr($table_fields[$i]['Type'], 'blob');
355 $table_fields[$i]['is_char'] = stristr($table_fields[$i]['Type'], 'char');
356 $table_fields[$i]['first_timestamp'] = false;
357 switch ($table_fields[$i]['True_Type']) {
358 case 'set':
359 $table_fields[$i]['pma_type'] = 'set';
360 $table_fields[$i]['wrap'] = '';
361 break;
362 case 'enum':
363 $table_fields[$i]['pma_type'] = 'enum';
364 $table_fields[$i]['wrap'] = '';
365 break;
366 case 'timestamp':
367 if (!$timestamp_seen) { // can only occur once per table
368 $timestamp_seen = 1;
369 $table_fields[$i]['first_timestamp'] = true;
371 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
372 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
373 break;
375 default:
376 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
377 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
378 break;
381 $field = $table_fields[$i];
382 $type_and_length = PMA_extract_type_length($field['Type']);
384 if (-1 === $field['len']) {
385 $field['len'] = PMA_DBI_field_len($vresult, $i);
388 $unnullify_trigger = $chg_evt_handler . "=\"return unNullify('"
389 . PMA_escapeJsString($field['Field_html']) . "', '"
390 . PMA_escapeJsString($jsvkey) . "')\"";
391 $field_name_appendix = $vkey . '[' . $field['Field_html'] . ']';
392 $field_name_appendix_md5 = $field['Field_md5'] . $vkey . '[]';
395 if ($field['Type'] == 'datetime'
396 && ! isset($field['Default'])
397 && ! is_null($field['Default'])
398 && ($insert_mode || ! isset($vrow[$field['Field']]))) {
399 // INSERT case or
400 // UPDATE case with an NULL value
401 $vrow[$field['Field']] = date('Y-m-d H:i:s', time());
404 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
405 <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($field['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center"><?php echo $field['Field_title']; ?></td>
406 <td align="center"<?php echo $field['wrap']; ?>>
407 <?php echo $field['pma_type']; ?>
408 </td>
410 <?php
412 // Prepares the field value
413 $real_null_value = FALSE;
414 if (isset($vrow)) {
415 if (! isset($vrow[$field['Field']])
416 || is_null($vrow[$field['Field']])) {
417 $real_null_value = TRUE;
418 $vrow[$field['Field']] = '';
419 $special_chars = '';
420 $data = $vrow[$field['Field']];
421 } elseif ($field['True_Type'] == 'bit') {
422 $special_chars = PMA_printable_bit_value($vrow[$field], $type_and_length['length']);
423 } else {
424 // loic1: special binary "characters"
425 if ($field['is_binary'] || $field['is_blob']) {
426 $vrow[$field['Field']] = str_replace("\x00", '\0', $vrow[$field['Field']]);
427 $vrow[$field['Field']] = str_replace("\x08", '\b', $vrow[$field['Field']]);
428 $vrow[$field['Field']] = str_replace("\x0a", '\n', $vrow[$field['Field']]);
429 $vrow[$field['Field']] = str_replace("\x0d", '\r', $vrow[$field['Field']]);
430 $vrow[$field['Field']] = str_replace("\x1a", '\Z', $vrow[$field['Field']]);
431 } // end if
432 $special_chars = htmlspecialchars($vrow[$field['Field']]);
433 $data = $vrow[$field['Field']];
434 } // end if... else...
435 // loic1: if a timestamp field value is not included in an update
436 // statement MySQL auto-update it to the current timestamp
437 // lem9: however, things have changed since MySQL 4.1, so
438 // it's better to set a fields_prev in this situation
439 $backup_field = '<input type="hidden" name="fields_prev'
440 . $field_name_appendix . '" value="'
441 . htmlspecialchars($vrow[$field['Field']]) . '" />';
442 } else {
443 // loic1: display default values
444 if (!isset($field['Default'])) {
445 $field['Default'] = '';
446 $real_null_value = TRUE;
447 $data = '';
448 } else {
449 $data = $field['Default'];
451 if ($field['True_Type'] == 'bit') {
452 $special_chars = PMA_printable_bit_value($field['Default'], $type_and_length['length']);
453 } else {
454 $special_chars = htmlspecialchars($field['Default']);
456 $backup_field = '';
459 $idindex = ($o_rows * $fields_cnt) + $i + 1;
460 $tabindex = (($idindex - 1) * 3) + 1;
462 // The function column
463 // -------------------
464 // Change by Bernard M. Piller <bernard@bmpsystems.com>
465 // We don't want binary data to be destroyed
466 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
467 // stored or retrieved" so it does not mean that the contents is
468 // binary
469 if ($cfg['ShowFunctionFields']) {
470 if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload)
471 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
472 echo ' <td align="center">' . $strBinary . '</td>' . "\n";
473 } elseif (strstr($field['True_Type'], 'enum') || strstr($field['True_Type'], 'set')) {
474 echo ' <td align="center">--</td>' . "\n";
475 } else {
477 <td>
478 <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">
479 <option></option>
480 <?php
481 $selected = '';
483 // garvin: Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
484 // or something similar. Then directly look up the entry in the RestrictFunctions array,
485 // which will then reveal the available dropdown options
486 if (isset($cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])])
487 && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])]])) {
488 $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])];
489 $dropdown = $cfg['RestrictFunctions'][$current_func_type];
490 $default_function = $cfg['DefaultFunctions'][$current_func_type];
491 } else {
492 $dropdown = array();
493 $default_function = '';
496 $dropdown_built = array();
497 $op_spacing_needed = FALSE;
499 // what function defined as default?
500 // for the first timestamp we don't set the default function
501 // if there is a default value for the timestamp
502 // (not including CURRENT_TIMESTAMP)
503 // and the column does not have the
504 // ON UPDATE DEFAULT TIMESTAMP attribute.
506 if ($field['True_Type'] == 'timestamp'
507 && empty($field['Default'])
508 && ! isset($analyzed_sql[0]['create_table_fields'][$field['Field']]['on_update_current_timestamp'])) {
509 $default_function = $cfg['DefaultFunctions']['first_timestamp'];
512 if ($field['Key'] == 'PRI'
513 && ($field['Type'] == 'char(36)' || $field['Type'] == 'varchar(36)')) {
514 $default_function = $cfg['DefaultFunctions']['pk_char36'];
517 // garvin: loop on the dropdown array and print all available options for that field.
518 foreach ($dropdown as $each_dropdown){
519 echo '<option';
520 if ($default_function === $each_dropdown) {
521 echo ' selected="selected"';
523 echo '>' . $each_dropdown . '</option>' . "\n";
524 $dropdown_built[$each_dropdown] = 'TRUE';
525 $op_spacing_needed = TRUE;
528 // garvin: For compatibility's sake, do not let out all other functions. Instead
529 // print a separator (blank) and then show ALL functions which weren't shown
530 // yet.
531 $cnt_functions = count($cfg['Functions']);
532 for ($j = 0; $j < $cnt_functions; $j++) {
533 if (!isset($dropdown_built[$cfg['Functions'][$j]]) || $dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
534 // Is current function defined as default?
535 $selected = ($field['first_timestamp'] && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
536 || (!$field['first_timestamp'] && $cfg['Functions'][$j] == $default_function)
537 ? ' selected="selected"'
538 : '';
539 if ($op_spacing_needed == TRUE) {
540 echo ' ';
541 echo '<option value="">--------</option>' . "\n";
542 $op_spacing_needed = FALSE;
545 echo ' ';
546 echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
548 } // end for
549 unset($selected);
551 </select>
552 </td>
553 <?php
555 } // end if ($cfg['ShowFunctionFields'])
558 // The null column
559 // ---------------
560 echo ' <td>' . "\n";
561 if ($field['Null'] == 'YES') {
562 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
563 if ($real_null_value && !$field['first_timestamp']) {
564 echo ' value="on"';
566 echo ' />' . "\n";
568 if (!(($cfg['ProtectBinary'] && $field['is_blob']) || ($cfg['ProtectBinary'] == 'all' && $field['is_binary']))) {
570 echo ' <input type="checkbox" tabindex="' . ($tabindex + $tabindex_for_null) . '"'
571 . ' name="fields_null' . $field_name_appendix . '"';
572 if ($real_null_value && !$field['first_timestamp']) {
573 echo ' checked="checked"';
575 echo ' id="field_' . ($idindex) . '_2"';
576 $onclick = ' onclick="if (this.checked) {nullify(';
577 if (strstr($field['True_Type'], 'enum')) {
578 if (strlen($field['Type']) > 20) {
579 $onclick .= '1, ';
580 } else {
581 $onclick .= '2, ';
583 } elseif (strstr($field['True_Type'], 'set')) {
584 $onclick .= '3, ';
585 } elseif ($foreigners && isset($foreigners[$field['Field']])) {
586 $onclick .= '4, ';
587 } else {
588 $onclick .= '5, ';
590 $onclick .= '\'' . PMA_escapeJsString($field['Field_html']) . '\', \'' . $field['Field_md5'] . '\', \'' . PMA_escapeJsString($vkey) . '\'); this.checked = true}; return true" />' . "\n";
591 echo $onclick;
592 } else {
593 echo ' <input type="hidden" name="fields_null' . $field_name_appendix . '"';
594 if ($real_null_value && !$field['first_timestamp']) {
595 echo ' value="on"';
597 echo ' />' . "\n";
600 echo ' </td>' . "\n";
602 // The value column (depends on type)
603 // ----------------
604 // See bug #1667887 for the reason why we don't use the maxlength
605 // HTML attribute
607 $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', '');
608 echo ' <td>' . "\n";
609 if ($foreignData['foreign_link'] == true) {
610 echo $backup_field . "\n";
612 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
613 value="foreign" />
614 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
615 value="" id="field_<?php echo ($idindex); ?>_3A" />
616 <input type="text" name="field_<?php echo $field_name_appendix_md5; ?>"
617 class="textfield" <?php echo $unnullify_trigger; ?>
618 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
619 id="field_<?php echo ($idindex); ?>_3"
620 value="<?php echo htmlspecialchars($data); ?>" />
621 <script type="text/javascript">
622 //<![CDATA[
623 document.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes,resizable=yes\'); return false"');
624 document.write(' href="browse_foreigners.php?');
625 document.write('<?php echo PMA_generate_common_url($db, $table); ?>');
626 document.writeln('&amp;field=<?php echo PMA_escapeJsString(urlencode($field['Field']) . $browse_foreigners_uri); ?>">');
627 document.writeln('<?php echo str_replace("'", "\'", $titles['Browse']); ?></a>');
628 //]]>
629 </script>
630 <?php
631 } elseif (is_array($foreignData['disp_row'])) {
632 echo $backup_field . "\n";
634 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
635 value="foreign" />
636 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
637 value="" id="field_<?php echo $idindex; ?>_3A" />
638 <select name="field_<?php echo $field_name_appendix_md5; ?>"
639 <?php echo $unnullify_trigger; ?>
640 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
641 id="field_<?php echo ($idindex); ?>_3">
642 <?php echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?>
643 </select>
644 <?php
645 // still needed? :
646 unset($foreignData['disp_row']);
647 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
649 &nbsp;</td>
650 </tr>
651 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
652 <td colspan="5" align="right">
653 <?php echo $backup_field . "\n"; ?>
654 <textarea name="fields<?php echo $field_name_appendix; ?>"
655 rows="<?php echo ($cfg['TextareaRows']*2); ?>"
656 cols="<?php echo ($cfg['TextareaCols']*2); ?>"
657 dir="<?php echo $text_dir; ?>"
658 id="field_<?php echo ($idindex); ?>_3"
659 <?php echo $unnullify_trigger; ?>
660 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
661 ><?php echo $special_chars; ?></textarea>
662 <?php
663 } elseif (strstr($field['pma_type'], 'text')) {
664 echo $backup_field . "\n";
666 <textarea name="fields<?php echo $field_name_appendix; ?>"
667 rows="<?php echo $cfg['TextareaRows']; ?>"
668 cols="<?php echo $cfg['TextareaCols']; ?>"
669 dir="<?php echo $text_dir; ?>"
670 id="field_<?php echo ($idindex); ?>_3"
671 <?php echo $unnullify_trigger; ?>
672 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
673 ><?php echo $special_chars; ?></textarea>
674 <?php
675 echo "\n";
676 if (strlen($special_chars) > 32000) {
677 echo " </td>\n";
678 echo ' <td>' . $strTextAreaLength;
680 } elseif ($field['pma_type'] == 'enum') {
681 if (! isset($table_fields[$i]['values'])) {
682 $table_fields[$i]['values'] = array();
683 foreach (PMA_getEnumSetOptions($field['Type']) as $val) {
684 // Removes automatic MySQL escape format
685 $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
686 $table_fields[$i]['values'][] = array(
687 'plain' => $val,
688 'html' => htmlspecialchars($val),
692 $field_enum_values = $table_fields[$i]['values'];
694 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="enum" />
695 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
696 <?php
697 echo "\n" . ' ' . $backup_field . "\n";
699 // show dropdown or radio depend on length
700 if (strlen($field['Type']) > 20) {
702 <select name="field_<?php echo $field_name_appendix_md5; ?>"
703 <?php echo $unnullify_trigger; ?>
704 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
705 id="field_<?php echo ($idindex); ?>_3">
706 <option value="">&nbsp;</option>
707 <?php
708 echo "\n";
710 foreach ($field_enum_values as $enum_value) {
711 echo ' ';
712 echo '<option value="' . $enum_value['html'] . '"';
713 if ($data == $enum_value['plain']
714 || ($data == ''
715 && (! isset($primary_key) || $field['Null'] != 'YES')
716 && isset($field['Default'])
717 && $enum_value['plain'] == $field['Default'])) {
718 echo ' selected="selected"';
720 echo '>' . $enum_value['html'] . '</option>' . "\n";
721 } // end for
724 </select>
725 <?php
726 } else {
727 $j = 0;
728 foreach ($field_enum_values as $enum_value) {
729 echo ' ';
730 echo '<input type="radio" name="field_' . $field_name_appendix_md5 . '"';
731 echo ' value="' . $enum_value['html'] . '"';
732 echo ' id="field_' . ($idindex) . '_3_' . $j . '"';
733 echo ' onclick="';
734 echo "if (typeof(document.forms['insertForm'].elements['fields_null"
735 . $field_name_appendix . "']) != 'undefined') {document.forms['insertForm'].elements['fields_null"
736 . $field_name_appendix . "'].checked = false}";
737 echo '"';
738 if ($data == $enum_value['plain']
739 || ($data == ''
740 && (! isset($primary_key) || $field['Null'] != 'YES')
741 && isset($field['Default'])
742 && $enum_value['plain'] == $field['Default'])) {
743 echo ' checked="checked"';
745 echo 'tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
746 echo '<label for="field_' . $idindex . '_3_' . $j . '">'
747 . $enum_value['html'] . '</label>' . "\n";
748 $j++;
749 } // end for
750 } // end else
751 } elseif ($field['pma_type'] == 'set') {
752 if (! isset($table_fields[$i]['values'])) {
753 $table_fields[$i]['values'] = array();
754 foreach (PMA_getEnumSetOptions($field['Type']) as $val) {
755 $table_fields[$i]['values'][] = array(
756 'plain' => $val,
757 'html' => htmlspecialchars($val),
760 $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
762 $field_set_values = $table_fields[$i]['values'];
763 $select_size = $table_fields[$i]['select_size'];
765 $vset = array_flip(explode(',', $data));
766 echo $backup_field . "\n";
768 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="set" />
769 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
770 <select name="field_<?php echo $field_name_appendix_md5; ?>"
771 size="<?php echo $select_size; ?>"
772 multiple="multiple" <?php echo $unnullify_trigger; ?>
773 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
774 id="field_<?php echo ($idindex); ?>_3">
775 <?php
776 foreach ($field_set_values as $field_set_value) {
777 echo ' ';
778 echo '<option value="' . $field_set_value['html'] . '"';
779 if (isset($vset[$field_set_value['plain']])) {
780 echo ' selected="selected"';
782 echo '>' . $field_set_value['html'] . '</option>' . "\n";
783 } // end for
785 </select>
786 <?php
788 // Change by Bernard M. Piller <bernard@bmpsystems.com>
789 // We don't want binary data destroyed
790 elseif ($field['is_binary'] || $field['is_blob']) {
791 if (($cfg['ProtectBinary'] && $field['is_blob'])
792 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
793 echo "\n";
794 echo $strBinaryDoNotEdit;
795 if (isset($data)) {
796 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
797 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
798 unset($data_size);
800 echo "\n";
802 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="protected" />
803 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
804 <?php
805 } elseif ($field['is_blob']) {
806 echo "\n";
807 echo $backup_field . "\n";
809 <textarea name="fields<?php echo $field_name_appendix; ?>"
810 rows="<?php echo $cfg['TextareaRows']; ?>"
811 cols="<?php echo $cfg['TextareaCols']; ?>"
812 dir="<?php echo $text_dir; ?>"
813 id="field_<?php echo ($idindex); ?>_3"
814 <?php echo $unnullify_trigger; ?>
815 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
816 ><?php echo $special_chars; ?></textarea>
817 <?php
819 } else {
820 // field size should be at least 4 and max 40
821 $fieldsize = min(max($field['len'], 4), 40);
822 echo "\n";
823 echo $backup_field . "\n";
825 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
826 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
827 class="textfield" <?php echo $unnullify_trigger; ?>
828 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
829 id="field_<?php echo ($idindex); ?>_3" />
830 <?php
831 } // end if...elseif...else
833 // Upload choice (only for BLOBs because the binary
834 // attribute does not imply binary contents)
835 // (displayed whatever value the ProtectBinary has)
837 if ($is_upload && $field['is_blob']) {
838 echo '<br />';
839 echo '<input type="file" name="fields_upload_' . $field['Field_html'] . $vkey . '" class="textfield" id="field_' . $idindex . '_3" size="10" />&nbsp;';
841 // find maximum upload size, based on field type
843 * @todo with functions this is not so easy, as you can basically
844 * process any data with function like MD5
846 $max_field_sizes = array(
847 'tinyblob' => '256',
848 'blob' => '65536',
849 'mediumblob' => '16777216',
850 'longblob' => '4294967296'); // yeah, really
852 $this_field_max_size = $max_upload_size; // from PHP max
853 if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
854 $this_field_max_size = $max_field_sizes[$field['pma_type']];
856 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
857 // do not generate here the MAX_FILE_SIZE, because we should
858 // put only one in the form to accommodate the biggest field
859 if ($this_field_max_size > $biggest_max_file_size) {
860 $biggest_max_file_size = $this_field_max_size;
864 if (!empty($cfg['UploadDir'])) {
865 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
866 if ($files === FALSE) {
867 echo ' <font color="red">' . $strError . '</font><br />' . "\n";
868 echo ' ' . $strWebServerUploadDirectoryError . "\n";
869 } elseif (!empty($files)) {
870 echo "<br />\n";
871 echo ' <i>' . $strOr . '</i>' . ' ' . $strWebServerUploadDirectory . ':<br />' . "\n";
872 echo ' <select size="1" name="fields_uploadlocal_' . $field['Field_html'] . $vkey . '">' . "\n";
873 echo ' <option value="" selected="selected"></option>' . "\n";
874 echo $files;
875 echo ' </select>' . "\n";
877 } // end if (web-server upload directory)
878 } // end elseif (binary or blob)
879 else {
880 // field size should be at least 4 and max 40
881 $fieldsize = min(max($field['len'], 4), 40);
882 echo $backup_field . "\n";
883 if ($field['is_char'] && ($cfg['CharEditing'] == 'textarea' || strpos($data, "\n") !== FALSE)) {
884 echo "\n";
886 <textarea name="fields<?php echo $field_name_appendix; ?>"
887 rows="<?php echo $cfg['CharTextareaRows']; ?>"
888 cols="<?php echo $cfg['CharTextareaCols']; ?>"
889 dir="<?php echo $text_dir; ?>"
890 id="field_<?php echo ($idindex); ?>_3"
891 <?php echo $unnullify_trigger; ?>
892 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
893 ><?php echo $special_chars; ?></textarea>
894 <?php
895 } else {
897 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
898 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
899 class="textfield" <?php echo $unnullify_trigger; ?>
900 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
901 id="field_<?php echo ($idindex); ?>_3" />
902 <?php
903 if ($field['Extra'] == 'auto_increment') {
905 <input type="hidden" name="auto_increment<?php echo $field_name_appendix; ?>" value="1" />
906 <?php
907 } // end if
908 if (substr($field['pma_type'], 0, 9) == 'timestamp') {
910 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="timestamp" />
911 <?php
913 if ($field['True_Type'] == 'bit') {
915 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="bit" />
916 <?php
918 if ($field['pma_type'] == 'date' || $field['pma_type'] == 'datetime' || substr($field['pma_type'], 0, 9) == 'timestamp') {
920 <script type="text/javascript">
921 //<![CDATA[
922 document.write('<a title="<?php echo $strCalendar;?>"');
923 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); ?>\')">');
924 document.write('<img class="calendar"');
925 document.write(' src="<?php echo $pmaThemeImage; ?>b_calendar.png"');
926 document.write(' alt="<?php echo $strCalendar; ?>"/></a>');
927 //]]>
928 </script>
929 <?php
934 </td>
935 </tr>
936 <?php
937 $odd_row = !$odd_row;
938 } // end for
939 $o_rows++;
940 echo ' </tbody></table><br />';
941 } // end foreach on multi-edit
943 <br />
945 <fieldset>
946 <table border="0" cellpadding="5" cellspacing="0">
947 <tr>
948 <td valign="middle" nowrap="nowrap">
949 <select name="submit_type" tabindex="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
950 <?php
951 if (isset($primary_key)) {
953 <option value="<?php echo $strSave; ?>"><?php echo $strSave; ?></option>
954 <?php
957 <option value="<?php echo $strInsertAsNewRow; ?>"><?php echo $strInsertAsNewRow; ?></option>
958 </select>
959 <?php
960 echo "\n";
962 if (!isset($after_insert)) {
963 $after_insert = 'back';
966 </td>
967 <td valign="middle">
968 &nbsp;&nbsp;&nbsp;<b><?php echo $strAndThen; ?></b>&nbsp;&nbsp;&nbsp;
969 </td>
970 <td valign="middle" nowrap="nowrap">
971 <select name="after_insert">
972 <option value="back" <?php echo ($after_insert == 'back' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertBack; ?></option>
973 <option value="new_insert" <?php echo ($after_insert == 'new_insert' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertNewInsert; ?></option>
974 <?php
975 if (isset($primary_key)) {
977 <option value="same_insert" <?php echo ($after_insert == 'same_insert' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertSame; ?></option>
978 <?php
979 // If we have just numeric primary key, we can also edit next
980 // in 2.8.2, we were looking for `field_name` = numeric_value
981 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $primary_key)) {
982 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
983 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $primary_key)) {
985 <option value="edit_next" <?php echo ($after_insert == 'edit_next' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertNext; ?></option>
986 <?php
990 </select>
991 </td>
992 </tr>
994 <tr>
995 <td>
996 <?php echo PMA_showHint($strUseTabKey); ?>
997 </td>
998 <td colspan="3" align="right" valign="middle">
999 <input type="submit" value="<?php echo $strGo; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 6); ?>" id="buttonYes" />
1000 <input type="reset" value="<?php echo $strReset; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 7); ?>" />
1001 </td>
1002 </tr>
1003 </table>
1004 </fieldset>
1005 <?php if ($biggest_max_file_size > 0) {
1006 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
1007 } ?>
1008 </form>
1009 <?php
1010 if ($insert_mode) {
1012 <!-- Restart insertion form -->
1013 <form method="post" action="tbl_replace.php" name="restartForm" >
1014 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
1015 <input type="hidden" name="goto" value="<?php echo htmlspecialchars($GLOBALS['goto']); ?>" />
1016 <input type="hidden" name="err_url" value="<?php echo htmlspecialchars($err_url); ?>" />
1017 <input type="hidden" name="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
1018 <?php
1019 if (isset($primary_keys)) {
1020 foreach ($primary_key_array as $key_id => $primary_key) {
1021 echo '<input type="hidden" name="primary_key[' . $key_id . ']" value="' . htmlspecialchars(trim($primary_key)) . '" />'. "\n";
1024 $tmp = '<select name="insert_rows" id="insert_rows" onchange="this.form.submit();" >' . "\n";
1025 $option_values = array(1,2,5,10,15,20,30,40);
1026 foreach ($option_values as $value) {
1027 $tmp .= '<option value="' . $value . '"';
1028 if ($value == $cfg['InsertRows']) {
1029 $tmp .= ' selected="selected"';
1031 $tmp .= '>' . $value . '</option>' . "\n";
1033 $tmp .= '</select>' . "\n";
1034 echo "\n" . sprintf($strRestartInsertion, $tmp);
1035 unset($tmp);
1036 echo '<noscript><input type="submit" value="' . $strGo . '" /></noscript>' . "\n";
1037 echo '</form>' . "\n";
1041 * Displays the footer
1043 require_once './libraries/footer.inc.php';