is*() methods now return boolean values;
[phpmyadmin.git] / tbl_change.php
blob79acba7839b749a434891ce19925d03e625830f9
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';
23 /**
24 * Sets global variables.
25 * Here it's better to use a if, instead of the '?' operator
26 * to avoid setting a variable to '' when it's not present in $_REQUEST
28 /**
29 * @todo this one is badly named, it's really a WHERE condition
30 * and exists even for tables not having a primary key or unique key
32 if (isset($_REQUEST['primary_key'])) {
33 $primary_key = $_REQUEST['primary_key'];
35 if (isset($_SESSION['edit_next'])) {
36 $primary_key = $_SESSION['edit_next'];
37 unset($_SESSION['edit_next']);
38 $after_insert = 'edit_next';
40 if (isset($_REQUEST['sql_query'])) {
41 $sql_query = $_REQUEST['sql_query'];
43 if (isset($_REQUEST['ShowFunctionFields'])) {
44 $cfg['ShowFunctionFields'] = $_REQUEST['ShowFunctionFields'];
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';
118 * HTTP and HTML headers
120 require_once './libraries/header.inc.php';
123 * Displays the query submitted and its result
125 * @todo where does $disp_message and $disp_query come from???
127 if (! empty($disp_message)) {
128 if (! isset($disp_query)) {
129 $disp_query = null;
131 PMA_showMessage($disp_message, $disp_query);
135 * Displays top menu links
137 require_once './libraries/tbl_links.inc.php';
141 * Get the analysis of SHOW CREATE TABLE for this table
142 * @todo should be handled by class Table
144 $show_create_table = PMA_DBI_fetch_value(
145 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
146 0, 1);
147 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
148 unset($show_create_table);
151 * Get the list of the fields of the current table
153 PMA_DBI_select_db($db);
154 $table_fields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ';',
155 null, null, null, PMA_DBI_QUERY_STORE);
156 $rows = array();
157 if (isset($primary_key)) {
158 // when in edit mode load all selected rows from table
159 $insert_mode = false;
160 if (is_array($primary_key)) {
161 $primary_key_array = $primary_key;
162 } else {
163 $primary_key_array = array(0 => $primary_key);
166 $result = array();
167 $found_unique_key = false;
168 foreach ($primary_key_array as $key_id => $primary_key) {
169 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';';
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 $primary_keys[$key_id] = str_replace('\\', '\\\\', $primary_key);
174 // No row returned
175 if (! $rows[$key_id]) {
176 unset($rows[$key_id], $primary_key_array[$key_id]);
177 PMA_showMessage($strEmptyResultSet, $local_query);
178 echo "\n";
179 require_once './libraries/footer.inc.php';
180 } else { // end if (no record returned)
181 $meta = PMA_DBI_get_fields_meta($result[$key_id]);
182 if ($tmp = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true)) {
183 $found_unique_key = true;
185 unset($tmp);
188 } else {
189 // no primary key given, just load first row - but what happens if tbale is empty?
190 $insert_mode = true;
191 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
192 $rows = array_fill(0, $cfg['InsertRows'], false);
195 // <markus@noga.de>
196 // retrieve keys into foreign fields, if any
197 $foreigners = PMA_getForeigners($db, $table);
201 * Displays the form
203 // loic1: autocomplete feature of IE kills the "onchange" event handler and it
204 // must be replaced by the "onpropertychange" one in this case
205 $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5 && PMA_USR_BROWSER_VER < 7)
206 ? 'onpropertychange'
207 : 'onchange';
208 // Had to put the URI because when hosted on an https server,
209 // some browsers send wrongly this form to the http server.
211 if ($cfg['CtrlArrowsMoving']) {
213 <!-- Set on key handler for moving using by Ctrl+arrows -->
214 <script src="./js/keyhandler.js" type="text/javascript"></script>
215 <script type="text/javascript">
216 //<![CDATA[
217 var switch_movement = 0;
218 document.onkeydown = onKeyDownArrowsHandler;
219 //]]>
220 </script>
221 <?php
224 $_form_params = array(
225 'db' => $db,
226 'table' => $table,
227 'goto' => $GLOBALS['goto'],
228 'err_url' => $err_url,
229 'sql_query' => $sql_query,
231 if (isset($primary_keys)) {
232 foreach ($primary_key_array as $key_id => $primary_key) {
233 $_form_params['primary_key[' . $key_id . ']'] = trim($primary_key);
238 <!-- Insert/Edit form -->
239 <form method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?>>
240 <?php
241 echo PMA_generate_common_hidden_inputs($_form_params);
243 $titles['Browse'] = PMA_getIcon('b_browse.png', $strBrowseForeignValues);
245 // Set if we passed the first timestamp field
246 $timestamp_seen = 0;
247 $fields_cnt = count($table_fields);
249 $tabindex = 0;
250 $tabindex_for_function = +3000;
251 $tabindex_for_null = +6000;
252 $tabindex_for_value = 0;
253 $o_rows = 0;
254 $biggest_max_file_size = 0;
256 // user can toggle the display of Function column
257 // (currently does not work for multi-edits)
258 $url_params['db'] = $db;
259 $url_params['table'] = $table;
260 if (isset($primary_key)) {
261 $url_params['primary_key'] = trim($primary_key);
263 if (! empty($sql_query)) {
264 $url_params['sql_query'] = $sql_query;
267 if (! $cfg['ShowFunctionFields']) {
268 $this_url_params = array_merge($url_params,
269 array('ShowFunctionFields' => 1));
270 echo $strShow . ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . $strFunction . '</a>' . "\n";
273 foreach ($rows as $row_id => $vrow) {
274 if ($vrow === false) {
275 unset($vrow);
278 $jsvkey = $row_id;
279 $browse_foreigners_uri = '&amp;pk=' . $row_id;
280 $vkey = '[multi_edit][' . $jsvkey . ']';
282 $vresult = (isset($result) && is_array($result) && isset($result[$row_id]) ? $result[$row_id] : $result);
283 if ($insert_mode && $row_id > 0) {
284 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $row_id . '" id="insert_ignore_check_' . $row_id . '" />';
285 echo '<label for="insert_ignore_check_' . $row_id . '">' . $strIgnore . '</label><br />' . "\n";
288 <table>
289 <thead>
290 <tr>
291 <th><?php echo $strField; ?></th>
292 <th><?php echo $strType; ?></th>
293 <?php
294 if ($cfg['ShowFunctionFields']) {
295 $this_url_params = array_merge($url_params,
296 array('ShowFunctionFields' => 0));
297 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . $strHide . '">' . $strFunction . '</a></th>' . "\n";
300 <th><?php echo $strNull; ?></th>
301 <th><?php echo $strValue; ?></th>
302 </tr>
303 </thead>
304 <tfoot>
305 <tr>
306 <th colspan="5" align="right" class="tblFooters">
307 <input type="submit" value="<?php echo $strGo; ?>" />
308 </th>
309 </tr>
310 </tfoot>
311 <tbody>
312 <?php
313 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
314 $m_rows = $o_rows + 1;
316 $odd_row = true;
317 for ($i = 0; $i < $fields_cnt; $i++) {
318 if (! isset($table_fields[$i]['processed'])) {
319 $table_fields[$i]['Field_html'] = htmlspecialchars($table_fields[$i]['Field']);
320 $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']);
321 // True_Type contains only the type (stops at first bracket)
322 $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']);
324 // d a t e t i m e
326 // loic1: current date should not be set as default if the field is NULL
327 // for the current row
328 // lem9: but do not put here the current datetime if there is a default
329 // value (the real default value will be set in the
330 // Default value logic below)
332 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
333 // $field['Default'] is not set if it contains NULL:
334 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime)
335 // but, look what we get if we switch to iso: (Default is NULL)
336 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime)
337 // so I force a NULL into it (I don't think it's possible
338 // to have an empty default value for DATETIME)
339 // then, the "if" after this one will work
340 if ($table_fields[$i]['Type'] == 'datetime'
341 && ! isset($table_fields[$i]['Default'])
342 && isset($table_fields[$i]['Null'])
343 && $table_fields[$i]['Null'] == 'YES') {
344 $table_fields[$i]['Default'] = null;
347 $table_fields[$i]['len'] =
348 preg_match('@float|double@', $table_fields[$i]['Type']) ? 100 : -1;
351 if (isset($comments_map[$table_fields[$i]['Field']])) {
352 $table_fields[$i]['Field_title'] = '<span style="border-bottom: 1px dashed black;" title="'
353 . htmlspecialchars($comments_map[$table_fields[$i]['Field']]) . '">'
354 . $table_fields[$i]['Field_html'] . '</span>';
355 } else {
356 $table_fields[$i]['Field_title'] = $table_fields[$i]['Field_html'];
359 // The type column
360 $table_fields[$i]['is_binary'] = stristr($table_fields[$i]['Type'], 'binary');
361 $table_fields[$i]['is_blob'] = stristr($table_fields[$i]['Type'], 'blob');
362 $table_fields[$i]['is_char'] = stristr($table_fields[$i]['Type'], 'char');
363 $table_fields[$i]['first_timestamp'] = false;
364 switch ($table_fields[$i]['True_Type']) {
365 case 'set':
366 $table_fields[$i]['pma_type'] = 'set';
367 $table_fields[$i]['wrap'] = '';
368 break;
369 case 'enum':
370 $table_fields[$i]['pma_type'] = 'enum';
371 $table_fields[$i]['wrap'] = '';
372 break;
373 case 'timestamp':
374 if (!$timestamp_seen) { // can only occur once per table
375 $timestamp_seen = 1;
376 $table_fields[$i]['first_timestamp'] = true;
378 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
379 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
380 break;
382 default:
383 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
384 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
385 break;
388 $field = $table_fields[$i];
389 $extracted_fieldspec = PMA_extractFieldSpec($field['Type']);
391 if (-1 === $field['len']) {
392 $field['len'] = PMA_DBI_field_len($vresult, $i);
395 $unnullify_trigger = $chg_evt_handler . "=\"return unNullify('"
396 . PMA_escapeJsString($field['Field_html']) . "', '"
397 . PMA_escapeJsString($jsvkey) . "')\"";
398 $field_name_appendix = $vkey . '[' . $field['Field_html'] . ']';
399 $field_name_appendix_md5 = $field['Field_md5'] . $vkey . '[]';
402 if ($field['Type'] == 'datetime'
403 && ! isset($field['Default'])
404 && ! is_null($field['Default'])
405 && ($insert_mode || ! isset($vrow[$field['Field']]))) {
406 // INSERT case or
407 // UPDATE case with an NULL value
408 $vrow[$field['Field']] = date('Y-m-d H:i:s', time());
411 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
412 <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($field['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center"><?php echo $field['Field_title']; ?></td>
413 <td align="center"<?php echo $field['wrap']; ?>>
414 <?php echo $field['pma_type']; ?>
415 </td>
417 <?php
419 // Prepares the field value
420 $real_null_value = FALSE;
421 if (isset($vrow)) {
422 // On a BLOB that can have a NULL value, the is_null() returns
423 // true if it has no content but for me this is different than
424 // having been set explicitely to NULL so I put an exception here
425 if (! $field['is_blob'] && is_null($vrow[$field['Field']])) {
426 $real_null_value = TRUE;
427 $vrow[$field['Field']] = '';
428 $special_chars = '';
429 $data = $vrow[$field['Field']];
430 } elseif ($field['True_Type'] == 'bit') {
431 $special_chars = PMA_printable_bit_value($vrow[$field], $extracted_fieldspec['spec_in_brackets']);
432 } else {
433 // loic1: special binary "characters"
434 if ($field['is_binary'] || $field['is_blob']) {
435 $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]);
436 } // end if
437 $special_chars = htmlspecialchars($vrow[$field['Field']]);
439 //We need to duplicate the first \n or otherwise we will lose the first newline entered in a VARCHAR or TEXT column
440 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
442 $data = $vrow[$field['Field']];
443 } // end if... else...
444 // loic1: if a timestamp field value is not included in an update
445 // statement MySQL auto-update it to the current timestamp
446 // lem9: however, things have changed since MySQL 4.1, so
447 // it's better to set a fields_prev in this situation
448 $backup_field = '<input type="hidden" name="fields_prev'
449 . $field_name_appendix . '" value="'
450 . htmlspecialchars($vrow[$field['Field']]) . '" />';
451 } else {
452 // loic1: display default values
453 if (!isset($field['Default'])) {
454 $field['Default'] = '';
455 $real_null_value = TRUE;
456 $data = '';
457 } else {
458 $data = $field['Default'];
460 if ($field['True_Type'] == 'bit') {
461 $special_chars = PMA_printable_bit_value($field['Default'], $extracted_fieldspec['spec_in_brackets']);
462 } else {
463 $special_chars = htmlspecialchars($field['Default']);
465 $backup_field = '';
468 $idindex = ($o_rows * $fields_cnt) + $i + 1;
469 $tabindex = (($idindex - 1) * 3) + 1;
471 // The function column
472 // -------------------
473 // Change by Bernard M. Piller <bernard@bmpsystems.com>
474 // We don't want binary data to be destroyed
475 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
476 // stored or retrieved" so it does not mean that the contents is
477 // binary
478 if ($cfg['ShowFunctionFields']) {
479 if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload)
480 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
481 echo ' <td align="center">' . $strBinary . '</td>' . "\n";
482 } elseif (strstr($field['True_Type'], 'enum') || strstr($field['True_Type'], 'set')) {
483 echo ' <td align="center">--</td>' . "\n";
484 } else {
486 <td>
487 <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">
488 <option></option>
489 <?php
490 $selected = '';
492 // garvin: Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
493 // or something similar. Then directly look up the entry in the RestrictFunctions array,
494 // which will then reveal the available dropdown options
495 if (isset($cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])])
496 && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])]])) {
497 $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])];
498 $dropdown = $cfg['RestrictFunctions'][$current_func_type];
499 $default_function = $cfg['DefaultFunctions'][$current_func_type];
500 } else {
501 $dropdown = array();
502 $default_function = '';
505 $dropdown_built = array();
506 $op_spacing_needed = FALSE;
508 // what function defined as default?
509 // for the first timestamp we don't set the default function
510 // if there is a default value for the timestamp
511 // (not including CURRENT_TIMESTAMP)
512 // and the column does not have the
513 // ON UPDATE DEFAULT TIMESTAMP attribute.
515 if ($field['True_Type'] == 'timestamp'
516 && empty($field['Default'])
517 && ! isset($analyzed_sql[0]['create_table_fields'][$field['Field']]['on_update_current_timestamp'])) {
518 $default_function = $cfg['DefaultFunctions']['first_timestamp'];
521 if ($field['Key'] == 'PRI'
522 && ($field['Type'] == 'char(36)' || $field['Type'] == 'varchar(36)')) {
523 $default_function = $cfg['DefaultFunctions']['pk_char36'];
526 // garvin: loop on the dropdown array and print all available options for that field.
527 foreach ($dropdown as $each_dropdown){
528 echo '<option';
529 if ($default_function === $each_dropdown) {
530 echo ' selected="selected"';
532 echo '>' . $each_dropdown . '</option>' . "\n";
533 $dropdown_built[$each_dropdown] = 'TRUE';
534 $op_spacing_needed = TRUE;
537 // garvin: For compatibility's sake, do not let out all other functions. Instead
538 // print a separator (blank) and then show ALL functions which weren't shown
539 // yet.
540 $cnt_functions = count($cfg['Functions']);
541 for ($j = 0; $j < $cnt_functions; $j++) {
542 if (!isset($dropdown_built[$cfg['Functions'][$j]]) || $dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
543 // Is current function defined as default?
544 $selected = ($field['first_timestamp'] && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
545 || (!$field['first_timestamp'] && $cfg['Functions'][$j] == $default_function)
546 ? ' selected="selected"'
547 : '';
548 if ($op_spacing_needed == TRUE) {
549 echo ' ';
550 echo '<option value="">--------</option>' . "\n";
551 $op_spacing_needed = FALSE;
554 echo ' ';
555 echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
557 } // end for
558 unset($selected);
560 </select>
561 </td>
562 <?php
564 } // end if ($cfg['ShowFunctionFields'])
567 // The null column
568 // ---------------
569 $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', '');
570 echo ' <td>' . "\n";
571 if ($field['Null'] == 'YES') {
572 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
573 if ($real_null_value && !$field['first_timestamp']) {
574 echo ' value="on"';
576 echo ' />' . "\n";
578 if (!(($cfg['ProtectBinary'] && $field['is_blob']) || ($cfg['ProtectBinary'] == 'all' && $field['is_binary']))) {
580 echo ' <input type="checkbox" tabindex="' . ($tabindex + $tabindex_for_null) . '"'
581 . ' name="fields_null' . $field_name_appendix . '"';
582 if ($real_null_value && !$field['first_timestamp']) {
583 echo ' checked="checked"';
585 echo ' id="field_' . ($idindex) . '_2"';
586 $onclick = ' onclick="if (this.checked) {nullify(';
587 if (strstr($field['True_Type'], 'enum')) {
588 if (strlen($field['Type']) > 20) {
589 $onclick .= '1, ';
590 } else {
591 $onclick .= '2, ';
593 } elseif (strstr($field['True_Type'], 'set')) {
594 $onclick .= '3, ';
595 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == false) {
596 // foreign key in a drop-down
597 $onclick .= '4, ';
598 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == true) {
599 // foreign key with a browsing icon
600 $onclick .= '6, ';
601 } else {
602 $onclick .= '5, ';
604 $onclick .= '\'' . PMA_escapeJsString($field['Field_html']) . '\', \'' . $field['Field_md5'] . '\', \'' . PMA_escapeJsString($vkey) . '\'); this.checked = true}; return true" />' . "\n";
605 echo $onclick;
606 } else {
607 echo ' <input type="hidden" name="fields_null' . $field_name_appendix . '"';
608 if ($real_null_value && !$field['first_timestamp']) {
609 echo ' value="on"';
611 echo ' />' . "\n";
614 echo ' </td>' . "\n";
616 // The value column (depends on type)
617 // ----------------
618 // See bug #1667887 for the reason why we don't use the maxlength
619 // HTML attribute
621 echo ' <td>' . "\n";
622 if ($foreignData['foreign_link'] == true) {
623 echo $backup_field . "\n";
625 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
626 value="foreign" />
627 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
628 value="" id="field_<?php echo ($idindex); ?>_3A" />
629 <input type="text" name="field_<?php echo $field_name_appendix_md5; ?>"
630 class="textfield" <?php echo $unnullify_trigger; ?>
631 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
632 id="field_<?php echo ($idindex); ?>_3"
633 value="<?php echo htmlspecialchars($data); ?>" />
634 <script type="text/javascript">
635 //<![CDATA[
636 document.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes,resizable=yes\'); return false"');
637 document.write(' href="browse_foreigners.php?');
638 document.write('<?php echo PMA_generate_common_url($db, $table); ?>');
639 document.writeln('&amp;field=<?php echo PMA_escapeJsString(urlencode($field['Field']) . $browse_foreigners_uri); ?>">');
640 document.writeln('<?php echo str_replace("'", "\'", $titles['Browse']); ?></a>');
641 //]]>
642 </script>
643 <?php
644 } elseif (is_array($foreignData['disp_row'])) {
645 echo $backup_field . "\n";
647 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
648 value="foreign" />
649 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
650 value="" id="field_<?php echo $idindex; ?>_3A" />
651 <select name="field_<?php echo $field_name_appendix_md5; ?>"
652 <?php echo $unnullify_trigger; ?>
653 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
654 id="field_<?php echo ($idindex); ?>_3">
655 <?php echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?>
656 </select>
657 <?php
658 // still needed? :
659 unset($foreignData['disp_row']);
660 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
662 &nbsp;</td>
663 </tr>
664 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
665 <td colspan="5" align="right">
666 <?php echo $backup_field . "\n"; ?>
667 <textarea name="fields<?php echo $field_name_appendix; ?>"
668 rows="<?php echo ($cfg['TextareaRows']*2); ?>"
669 cols="<?php echo ($cfg['TextareaCols']*2); ?>"
670 dir="<?php echo $text_dir; ?>"
671 id="field_<?php echo ($idindex); ?>_3"
672 <?php echo $unnullify_trigger; ?>
673 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
674 ><?php echo $special_chars_encoded; ?></textarea>
675 <?php
676 } elseif (strstr($field['pma_type'], 'text')) {
677 echo $backup_field . "\n";
679 <textarea name="fields<?php echo $field_name_appendix; ?>"
680 rows="<?php echo $cfg['TextareaRows']; ?>"
681 cols="<?php echo $cfg['TextareaCols']; ?>"
682 dir="<?php echo $text_dir; ?>"
683 id="field_<?php echo ($idindex); ?>_3"
684 <?php echo $unnullify_trigger; ?>
685 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
686 ><?php echo $special_chars_encoded; ?></textarea>
687 <?php
688 echo "\n";
689 if (strlen($special_chars) > 32000) {
690 echo " </td>\n";
691 echo ' <td>' . $strTextAreaLength;
693 } elseif ($field['pma_type'] == 'enum') {
694 if (! isset($table_fields[$i]['values'])) {
695 $table_fields[$i]['values'] = array();
696 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
697 // Removes automatic MySQL escape format
698 $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
699 $table_fields[$i]['values'][] = array(
700 'plain' => $val,
701 'html' => htmlspecialchars($val),
705 $field_enum_values = $table_fields[$i]['values'];
707 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="enum" />
708 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
709 <?php
710 echo "\n" . ' ' . $backup_field . "\n";
712 // show dropdown or radio depend on length
713 if (strlen($field['Type']) > 20) {
715 <select name="field_<?php echo $field_name_appendix_md5; ?>"
716 <?php echo $unnullify_trigger; ?>
717 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
718 id="field_<?php echo ($idindex); ?>_3">
719 <option value="">&nbsp;</option>
720 <?php
721 echo "\n";
723 foreach ($field_enum_values as $enum_value) {
724 echo ' ';
725 echo '<option value="' . $enum_value['html'] . '"';
726 if ($data == $enum_value['plain']
727 || ($data == ''
728 && (! isset($primary_key) || $field['Null'] != 'YES')
729 && isset($field['Default'])
730 && $enum_value['plain'] == $field['Default'])) {
731 echo ' selected="selected"';
733 echo '>' . $enum_value['html'] . '</option>' . "\n";
734 } // end for
737 </select>
738 <?php
739 } else {
740 $j = 0;
741 foreach ($field_enum_values as $enum_value) {
742 echo ' ';
743 echo '<input type="radio" name="field_' . $field_name_appendix_md5 . '"';
744 echo ' value="' . $enum_value['html'] . '"';
745 echo ' id="field_' . ($idindex) . '_3_' . $j . '"';
746 echo ' onclick="';
747 echo "if (typeof(document.forms['insertForm'].elements['fields_null"
748 . $field_name_appendix . "']) != 'undefined') {document.forms['insertForm'].elements['fields_null"
749 . $field_name_appendix . "'].checked = false}";
750 echo '"';
751 if ($data == $enum_value['plain']
752 || ($data == ''
753 && (! isset($primary_key) || $field['Null'] != 'YES')
754 && isset($field['Default'])
755 && $enum_value['plain'] == $field['Default'])) {
756 echo ' checked="checked"';
758 echo ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
759 echo '<label for="field_' . $idindex . '_3_' . $j . '">'
760 . $enum_value['html'] . '</label>' . "\n";
761 $j++;
762 } // end for
763 } // end else
764 } elseif ($field['pma_type'] == 'set') {
765 if (! isset($table_fields[$i]['values'])) {
766 $table_fields[$i]['values'] = array();
767 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
768 $table_fields[$i]['values'][] = array(
769 'plain' => $val,
770 'html' => htmlspecialchars($val),
773 $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
775 $field_set_values = $table_fields[$i]['values'];
776 $select_size = $table_fields[$i]['select_size'];
778 $vset = array_flip(explode(',', $data));
779 echo $backup_field . "\n";
781 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="set" />
782 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
783 <select name="field_<?php echo $field_name_appendix_md5; ?>"
784 size="<?php echo $select_size; ?>"
785 multiple="multiple" <?php echo $unnullify_trigger; ?>
786 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
787 id="field_<?php echo ($idindex); ?>_3">
788 <?php
789 foreach ($field_set_values as $field_set_value) {
790 echo ' ';
791 echo '<option value="' . $field_set_value['html'] . '"';
792 if (isset($vset[$field_set_value['plain']])) {
793 echo ' selected="selected"';
795 echo '>' . $field_set_value['html'] . '</option>' . "\n";
796 } // end for
798 </select>
799 <?php
801 // Change by Bernard M. Piller <bernard@bmpsystems.com>
802 // We don't want binary data destroyed
803 elseif ($field['is_binary'] || $field['is_blob']) {
804 if (($cfg['ProtectBinary'] && $field['is_blob'])
805 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
806 echo "\n";
807 // rajk - for blobstreaming
808 $bs_reference_exists = FALSE;
810 if (isset ($tbl_type) && strlen ($tbl_type) > 0)
812 // load PMA_Config
813 $PMA_Config = $_SESSION['PMA_Config'];
815 if (!empty($PMA_Config))
817 $requiredTblType = $PMA_Config->get('PBXT_NAME');
819 if ($requiredTblType == strtolower ($tbl_type))
821 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
823 // check if blobstreaming plugins exist
824 if ($pluginsExist)
826 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
828 if (!empty($bs_tables) && strlen($db) > 0)
830 $bs_tables = $bs_tables[$db];
832 if (isset($bs_tables))
834 $allBSTablesExist = TRUE;
836 foreach ($bs_tables as $table_key=>$bs_tbl)
837 if (!$bs_tables[$table_key]['Exists'])
839 $allBSTablesExist = FALSE;
840 break;
843 if ($allBSTablesExist)
844 $bs_reference_exists = PMA_BS_ReferenceExists($data, $db);
845 } // end if (isset($bs_tables))
846 } // end if (!empty($bs_tables) && strlen($db) > 0)
847 } // end if ($pluginsExist)
848 } // end if ($requiredTblType == strtolower ($tbl_type))
849 } // end if (!empty($PMA_Config))
850 } // end if (isset ($tbl_type) && strlen ($tbl_type) > 0)
852 if ($bs_reference_exists)
854 echo '<input type="hidden" name="remove_blob_ref_' . $field['Field_html'] . $vkey . '" value="' . $data . '" />';
855 echo '<input type="checkbox" name="remove_blob_repo_' . $field['Field_html'] . $vkey . '" /> ' . $strBLOBRepositoryRemove . "<br />";
856 echo PMA_BS_CreateReferenceLink($data, $db);
857 echo "<br />";
859 else
861 echo $strBinaryDoNotEdit;
862 if (isset($data)) {
863 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
864 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
865 unset($data_size);
867 echo "\n";
868 } // end if ($bs_reference_exists)
870 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="protected" />
871 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
872 <?php
873 } elseif ($field['is_blob']) {
874 echo "\n";
875 echo $backup_field . "\n";
877 <textarea name="fields<?php echo $field_name_appendix; ?>"
878 rows="<?php echo $cfg['TextareaRows']; ?>"
879 cols="<?php echo $cfg['TextareaCols']; ?>"
880 dir="<?php echo $text_dir; ?>"
881 id="field_<?php echo ($idindex); ?>_3"
882 <?php echo $unnullify_trigger; ?>
883 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
884 ><?php echo $special_chars_encoded; ?></textarea>
885 <?php
887 } else {
888 // field size should be at least 4 and max 40
889 $fieldsize = min(max($field['len'], 4), 40);
890 echo "\n";
891 echo $backup_field . "\n";
893 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
894 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
895 class="textfield" <?php echo $unnullify_trigger; ?>
896 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
897 id="field_<?php echo ($idindex); ?>_3" />
898 <?php
899 } // end if...elseif...else
901 // Upload choice (only for BLOBs because the binary
902 // attribute does not imply binary contents)
903 // (displayed whatever value the ProtectBinary has)
905 if ($is_upload && $field['is_blob']) {
906 // added by rajk
907 // check if field type is of longblob
908 if ($field['pma_type'] == "longblob")
910 if (isset ($tbl_type) && strlen ($tbl_type) > 0)
912 // load PMA Config
913 $PMA_Config = $_SESSION['PMA_Config'];
915 // is PMA_Config's data loaded? continue only if it is
916 if (!empty($PMA_Config))
918 $requiredTblType = $PMA_Config->get('PBXT_NAME');
920 if ($requiredTblType == strtolower ($tbl_type))
922 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
924 // check if blobstreaming plugins exist
925 if ($pluginsExist)
927 $curlExists = $PMA_Config->get('CURL_EXISTS');
929 // check if CURL exists
930 if ($curlExists)
932 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
934 // check for BLOBStreamable databases and if current database name is provided
935 if (!empty($bs_tables) && strlen($db) > 0)
937 $bs_tables = $bs_tables[$db];
939 // check if reference to BLOBStreaming tables exists
940 if (isset($bs_tables))
942 $allBSTablesExist = TRUE;
944 foreach ($bs_tables as $table_key=>$bs_tbl)
945 if (!$bs_tables[$table_key]['Exists'])
947 $allBSTablesExist = FALSE;
948 break;
951 // check if necessary BLOBStreaming tables exist
952 if ($allBSTablesExist)
954 echo '<br />';
955 echo '<input type="checkbox" name="upload_blob_repo_' . $field['Field_html'] . $vkey . '" /> ' . $strBLOBRepositoryUpload;
956 } // end if ($allBSTablesExist)
957 } // end if (isset($bs_tables)
958 } // end if (!empty($bs_tables) && strlen ($db) > 0)
959 } // end if ($curlExists)
960 } // end if ($pluginsExist)
961 } // end if ($requiredTblType == strtolower ($tbl_type))
962 } // end if (!empty($PMA_Config))
963 } // end if (isset ($tbl_type) && strlen ($tbl_type) > 0)
966 echo '<br />';
967 echo '<input type="file" name="fields_upload_' . $field['Field_html'] . $vkey . '" class="textfield" id="field_' . $idindex . '_3" size="10" />&nbsp;';
969 // find maximum upload size, based on field type
971 * @todo with functions this is not so easy, as you can basically
972 * process any data with function like MD5
974 $max_field_sizes = array(
975 'tinyblob' => '256',
976 'blob' => '65536',
977 'mediumblob' => '16777216',
978 'longblob' => '4294967296'); // yeah, really
980 $this_field_max_size = $max_upload_size; // from PHP max
981 if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
982 $this_field_max_size = $max_field_sizes[$field['pma_type']];
984 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
985 // do not generate here the MAX_FILE_SIZE, because we should
986 // put only one in the form to accommodate the biggest field
987 if ($this_field_max_size > $biggest_max_file_size) {
988 $biggest_max_file_size = $this_field_max_size;
992 if (!empty($cfg['UploadDir'])) {
993 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
994 if ($files === FALSE) {
995 echo ' <font color="red">' . $strError . '</font><br />' . "\n";
996 echo ' ' . $strWebServerUploadDirectoryError . "\n";
997 } elseif (!empty($files)) {
998 echo "<br />\n";
999 echo ' <i>' . $strOr . '</i>' . ' ' . $strWebServerUploadDirectory . ':<br />' . "\n";
1000 echo ' <select size="1" name="fields_uploadlocal_' . $field['Field_html'] . $vkey . '">' . "\n";
1001 echo ' <option value="" selected="selected"></option>' . "\n";
1002 echo $files;
1003 echo ' </select>' . "\n";
1005 } // end if (web-server upload directory)
1006 } // end elseif (binary or blob)
1007 else {
1008 // field size should be at least 4 and max 40
1009 $fieldsize = min(max($field['len'], 4), 40);
1010 echo $backup_field . "\n";
1011 if ($field['is_char'] && ($cfg['CharEditing'] == 'textarea' || strpos($data, "\n") !== FALSE)) {
1012 echo "\n";
1014 <textarea name="fields<?php echo $field_name_appendix; ?>"
1015 rows="<?php echo $cfg['CharTextareaRows']; ?>"
1016 cols="<?php echo $cfg['CharTextareaCols']; ?>"
1017 dir="<?php echo $text_dir; ?>"
1018 id="field_<?php echo ($idindex); ?>_3"
1019 <?php echo $unnullify_trigger; ?>
1020 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
1021 ><?php echo $special_chars_encoded; ?></textarea>
1022 <?php
1023 } else {
1025 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
1026 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
1027 class="textfield" <?php echo $unnullify_trigger; ?>
1028 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
1029 id="field_<?php echo ($idindex); ?>_3" />
1030 <?php
1031 if ($field['Extra'] == 'auto_increment') {
1033 <input type="hidden" name="auto_increment<?php echo $field_name_appendix; ?>" value="1" />
1034 <?php
1035 } // end if
1036 if (substr($field['pma_type'], 0, 9) == 'timestamp') {
1038 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="timestamp" />
1039 <?php
1041 if ($field['True_Type'] == 'bit') {
1043 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="bit" />
1044 <?php
1046 if ($field['pma_type'] == 'date' || $field['pma_type'] == 'datetime' || substr($field['pma_type'], 0, 9) == 'timestamp') {
1048 <script type="text/javascript">
1049 //<![CDATA[
1050 document.write('<a title="<?php echo $strCalendar;?>"');
1051 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); ?>\')">');
1052 document.write('<img class="calendar"');
1053 document.write(' src="<?php echo $pmaThemeImage; ?>b_calendar.png"');
1054 document.write(' alt="<?php echo $strCalendar; ?>"/></a>');
1055 //]]>
1056 </script>
1057 <?php
1062 </td>
1063 </tr>
1064 <?php
1065 $odd_row = !$odd_row;
1066 } // end for
1067 $o_rows++;
1068 echo ' </tbody></table><br />';
1069 } // end foreach on multi-edit
1071 <br />
1073 <fieldset>
1074 <table border="0" cellpadding="5" cellspacing="0">
1075 <tr>
1076 <td valign="middle" nowrap="nowrap">
1077 <select name="submit_type" tabindex="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
1078 <?php
1079 if (isset($primary_key)) {
1081 <option value="<?php echo $strSave; ?>"><?php echo $strSave; ?></option>
1082 <?php
1085 <option value="<?php echo $strInsertAsNewRow; ?>"><?php echo $strInsertAsNewRow; ?></option>
1086 </select>
1087 <?php
1088 echo "\n";
1090 if (!isset($after_insert)) {
1091 $after_insert = 'back';
1094 </td>
1095 <td valign="middle">
1096 &nbsp;&nbsp;&nbsp;<strong><?php echo $strAndThen; ?></strong>&nbsp;&nbsp;&nbsp;
1097 </td>
1098 <td valign="middle" nowrap="nowrap">
1099 <select name="after_insert">
1100 <option value="back" <?php echo ($after_insert == 'back' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertBack; ?></option>
1101 <option value="new_insert" <?php echo ($after_insert == 'new_insert' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertNewInsert; ?></option>
1102 <?php
1103 if (isset($primary_key)) {
1105 <option value="same_insert" <?php echo ($after_insert == 'same_insert' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertSame; ?></option>
1106 <?php
1107 // If we have just numeric primary key, we can also edit next
1108 // in 2.8.2, we were looking for `field_name` = numeric_value
1109 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $primary_key)) {
1110 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1111 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $primary_key)) {
1113 <option value="edit_next" <?php echo ($after_insert == 'edit_next' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertNext; ?></option>
1114 <?php
1118 </select>
1119 </td>
1120 </tr>
1122 <tr>
1123 <td>
1124 <?php echo PMA_showHint($strUseTabKey); ?>
1125 </td>
1126 <td colspan="3" align="right" valign="middle">
1127 <input type="submit" value="<?php echo $strGo; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 6); ?>" id="buttonYes" />
1128 <input type="reset" value="<?php echo $strReset; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 7); ?>" />
1129 </td>
1130 </tr>
1131 </table>
1132 </fieldset>
1133 <?php if ($biggest_max_file_size > 0) {
1134 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
1135 } ?>
1136 </form>
1137 <?php
1138 if ($insert_mode) {
1140 <!-- Restart insertion form -->
1141 <form method="post" action="tbl_replace.php" name="restartForm" >
1142 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
1143 <input type="hidden" name="goto" value="<?php echo htmlspecialchars($GLOBALS['goto']); ?>" />
1144 <input type="hidden" name="err_url" value="<?php echo htmlspecialchars($err_url); ?>" />
1145 <input type="hidden" name="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
1146 <?php
1147 if (isset($primary_keys)) {
1148 foreach ($primary_key_array as $key_id => $primary_key) {
1149 echo '<input type="hidden" name="primary_key[' . $key_id . ']" value="' . htmlspecialchars(trim($primary_key)) . '" />'. "\n";
1152 $tmp = '<select name="insert_rows" id="insert_rows" onchange="this.form.submit();" >' . "\n";
1153 $option_values = array(1,2,5,10,15,20,30,40);
1154 foreach ($option_values as $value) {
1155 $tmp .= '<option value="' . $value . '"';
1156 if ($value == $cfg['InsertRows']) {
1157 $tmp .= ' selected="selected"';
1159 $tmp .= '>' . $value . '</option>' . "\n";
1161 $tmp .= '</select>' . "\n";
1162 echo "\n" . sprintf($strRestartInsertion, $tmp);
1163 unset($tmp);
1164 echo '<noscript><input type="submit" value="' . $strGo . '" /></noscript>' . "\n";
1165 echo '</form>' . "\n";
1169 * Displays the footer
1171 require_once './libraries/footer.inc.php';