bug #1253252 [display] Cannot NULL a column with relation defined
[phpmyadmin/crack.git] / tbl_change.php
blobc5140e78d66279dd1e214bb1aa29fccabe1dab72
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 if (strlen($table)) {
63 // avoid a problem (see bug #2202709)
64 $GLOBALS['goto'] = 'tbl_sql.php';
65 } else {
66 $GLOBALS['goto'] = 'db_sql.php';
69 /**
70 * @todo check if we could replace by "db_|tbl_" - please clarify!?
72 $_url_params = array(
73 'db' => $db,
74 'sql_query' => $sql_query
77 if (preg_match('@^tbl_@', $GLOBALS['goto'])) {
78 $_url_params['table'] = $table;
81 $err_url = $GLOBALS['goto'] . PMA_generate_common_url($_url_params);
82 unset($_url_params);
85 /**
86 * Sets parameters for links
87 * where is this variable used?
88 * replace by PMA_generate_common_url($url_params);
90 $url_query = PMA_generate_common_url($url_params, 'html', '');
92 /**
93 * get table information
94 * @todo should be done by a Table object
96 require_once './libraries/tbl_info.inc.php';
98 /**
99 * Get comments for table fileds/columns
101 $comments_map = array();
103 if ($GLOBALS['cfg']['ShowPropertyComments']) {
104 $comments_map = PMA_getComments($db, $table);
108 * START REGULAR OUTPUT
112 * used in ./libraries/header.inc.php to load JavaScript library file
114 $GLOBALS['js_include'][] = 'tbl_change.js';
117 * HTTP and HTML headers
119 require_once './libraries/header.inc.php';
122 * Displays the query submitted and its result
124 * @todo where does $disp_message and $disp_query come from???
126 if (! empty($disp_message)) {
127 if (! isset($disp_query)) {
128 $disp_query = null;
130 PMA_showMessage($disp_message, $disp_query);
134 * Displays top menu links
136 require_once './libraries/tbl_links.inc.php';
140 * Get the analysis of SHOW CREATE TABLE for this table
141 * @todo should be handled by class Table
143 $show_create_table = PMA_DBI_fetch_value(
144 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
145 0, 1);
146 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
147 unset($show_create_table);
150 * Get the list of the fields of the current table
152 PMA_DBI_select_db($db);
153 $table_fields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ';',
154 null, null, null, PMA_DBI_QUERY_STORE);
155 $rows = array();
156 if (isset($primary_key)) {
157 // when in edit mode load all selected rows from table
158 $insert_mode = false;
159 if (is_array($primary_key)) {
160 $primary_key_array = $primary_key;
161 } else {
162 $primary_key_array = array(0 => $primary_key);
165 $result = array();
166 $found_unique_key = false;
167 foreach ($primary_key_array as $key_id => $primary_key) {
168 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';';
169 $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE);
170 $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]);
171 $primary_keys[$key_id] = str_replace('\\', '\\\\', $primary_key);
173 // No row returned
174 if (! $rows[$key_id]) {
175 unset($rows[$key_id], $primary_key_array[$key_id]);
176 PMA_showMessage($strEmptyResultSet, $local_query);
177 echo "\n";
178 require_once './libraries/footer.inc.php';
179 } else { // end if (no record returned)
180 $meta = PMA_DBI_get_fields_meta($result[$key_id]);
181 if ($tmp = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true)) {
182 $found_unique_key = true;
184 unset($tmp);
187 } else {
188 // no primary key given, just load first row - but what happens if tbale is empty?
189 $insert_mode = true;
190 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
191 $rows = array_fill(0, $cfg['InsertRows'], false);
194 // <markus@noga.de>
195 // retrieve keys into foreign fields, if any
196 $foreigners = PMA_getForeigners($db, $table);
200 * Displays the form
202 // loic1: autocomplete feature of IE kills the "onchange" event handler and it
203 // must be replaced by the "onpropertychange" one in this case
204 $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5 && PMA_USR_BROWSER_VER < 7)
205 ? 'onpropertychange'
206 : 'onchange';
207 // Had to put the URI because when hosted on an https server,
208 // some browsers send wrongly this form to the http server.
210 if ($cfg['CtrlArrowsMoving']) {
212 <!-- Set on key handler for moving using by Ctrl+arrows -->
213 <script src="./js/keyhandler.js" type="text/javascript"></script>
214 <script type="text/javascript">
215 //<![CDATA[
216 var switch_movement = 0;
217 document.onkeydown = onKeyDownArrowsHandler;
218 //]]>
219 </script>
220 <?php
223 $_form_params = array(
224 'db' => $db,
225 'table' => $table,
226 'goto' => $GLOBALS['goto'],
227 'err_url' => $err_url,
228 'sql_query' => $sql_query,
230 if (isset($primary_keys)) {
231 foreach ($primary_key_array as $key_id => $primary_key) {
232 $_form_params['primary_key[' . $key_id . ']'] = trim($primary_key);
237 <!-- Insert/Edit form -->
238 <form method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?>>
239 <?php
240 echo PMA_generate_common_hidden_inputs($_form_params);
242 $titles['Browse'] = PMA_getIcon('b_browse.png', $strBrowseForeignValues);
244 // Set if we passed the first timestamp field
245 $timestamp_seen = 0;
246 $fields_cnt = count($table_fields);
248 $tabindex = 0;
249 $tabindex_for_function = +3000;
250 $tabindex_for_null = +6000;
251 $tabindex_for_value = 0;
252 $o_rows = 0;
253 $biggest_max_file_size = 0;
255 // user can toggle the display of Function column
256 // (currently does not work for multi-edits)
257 $url_params['db'] = $db;
258 $url_params['table'] = $table;
259 if (isset($primary_key)) {
260 $url_params['primary_key'] = trim($primary_key);
262 if (! empty($sql_query)) {
263 $url_params['sql_query'] = $sql_query;
266 if (! $cfg['ShowFunctionFields']) {
267 $this_url_params = array_merge($url_params,
268 array('ShowFunctionFields' => 1));
269 echo $strShow . ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . $strFunction . '</a>' . "\n";
272 foreach ($rows as $row_id => $vrow) {
273 if ($vrow === false) {
274 unset($vrow);
277 $jsvkey = $row_id;
278 $browse_foreigners_uri = '&amp;pk=' . $row_id;
279 $vkey = '[multi_edit][' . $jsvkey . ']';
281 $vresult = (isset($result) && is_array($result) && isset($result[$row_id]) ? $result[$row_id] : $result);
282 if ($insert_mode && $row_id > 0) {
283 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $row_id . '" id="insert_ignore_check_' . $row_id . '" />';
284 echo '<label for="insert_ignore_check_' . $row_id . '">' . $strIgnore . '</label><br />' . "\n";
287 <table>
288 <thead>
289 <tr>
290 <th><?php echo $strField; ?></th>
291 <th><?php echo $strType; ?></th>
292 <?php
293 if ($cfg['ShowFunctionFields']) {
294 $this_url_params = array_merge($url_params,
295 array('ShowFunctionFields' => 0));
296 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . $strHide . '">' . $strFunction . '</a></th>' . "\n";
299 <th><?php echo $strNull; ?></th>
300 <th><?php echo $strValue; ?></th>
301 </tr>
302 </thead>
303 <tfoot>
304 <tr>
305 <th colspan="5" align="right" class="tblFooters">
306 <input type="submit" value="<?php echo $strGo; ?>" />
307 </th>
308 </tr>
309 </tfoot>
310 <tbody>
311 <?php
312 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
313 $m_rows = $o_rows + 1;
315 $odd_row = true;
316 for ($i = 0; $i < $fields_cnt; $i++) {
317 if (! isset($table_fields[$i]['processed'])) {
318 $table_fields[$i]['Field_html'] = htmlspecialchars($table_fields[$i]['Field']);
319 $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']);
320 // True_Type contains only the type (stops at first bracket)
321 $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']);
323 // d a t e t i m e
325 // loic1: current date should not be set as default if the field is NULL
326 // for the current row
327 // lem9: but do not put here the current datetime if there is a default
328 // value (the real default value will be set in the
329 // Default value logic below)
331 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
332 // $field['Default'] is not set if it contains NULL:
333 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime)
334 // but, look what we get if we switch to iso: (Default is NULL)
335 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime)
336 // so I force a NULL into it (I don't think it's possible
337 // to have an empty default value for DATETIME)
338 // then, the "if" after this one will work
339 if ($table_fields[$i]['Type'] == 'datetime'
340 && ! isset($table_fields[$i]['Default'])
341 && isset($table_fields[$i]['Null'])
342 && $table_fields[$i]['Null'] == 'YES') {
343 $table_fields[$i]['Default'] = null;
346 $table_fields[$i]['len'] =
347 preg_match('@float|double@', $table_fields[$i]['Type']) ? 100 : -1;
350 if (isset($comments_map[$table_fields[$i]['Field']])) {
351 $table_fields[$i]['Field_title'] = '<span style="border-bottom: 1px dashed black;" title="'
352 . htmlspecialchars($comments_map[$table_fields[$i]['Field']]) . '">'
353 . $table_fields[$i]['Field_html'] . '</span>';
354 } else {
355 $table_fields[$i]['Field_title'] = $table_fields[$i]['Field_html'];
358 // The type column
359 $table_fields[$i]['is_binary'] = stristr($table_fields[$i]['Type'], 'binary');
360 $table_fields[$i]['is_blob'] = stristr($table_fields[$i]['Type'], 'blob');
361 $table_fields[$i]['is_char'] = stristr($table_fields[$i]['Type'], 'char');
362 $table_fields[$i]['first_timestamp'] = false;
363 switch ($table_fields[$i]['True_Type']) {
364 case 'set':
365 $table_fields[$i]['pma_type'] = 'set';
366 $table_fields[$i]['wrap'] = '';
367 break;
368 case 'enum':
369 $table_fields[$i]['pma_type'] = 'enum';
370 $table_fields[$i]['wrap'] = '';
371 break;
372 case 'timestamp':
373 if (!$timestamp_seen) { // can only occur once per table
374 $timestamp_seen = 1;
375 $table_fields[$i]['first_timestamp'] = true;
377 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
378 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
379 break;
381 default:
382 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
383 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
384 break;
387 $field = $table_fields[$i];
388 $extracted_fieldspec = PMA_extractFieldSpec($field['Type']);
390 if (-1 === $field['len']) {
391 $field['len'] = PMA_DBI_field_len($vresult, $i);
394 $unnullify_trigger = $chg_evt_handler . "=\"return unNullify('"
395 . PMA_escapeJsString($field['Field_html']) . "', '"
396 . PMA_escapeJsString($jsvkey) . "')\"";
397 $field_name_appendix = $vkey . '[' . $field['Field_html'] . ']';
398 $field_name_appendix_md5 = $field['Field_md5'] . $vkey . '[]';
401 if ($field['Type'] == 'datetime'
402 && ! isset($field['Default'])
403 && ! is_null($field['Default'])
404 && ($insert_mode || ! isset($vrow[$field['Field']]))) {
405 // INSERT case or
406 // UPDATE case with an NULL value
407 $vrow[$field['Field']] = date('Y-m-d H:i:s', time());
410 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
411 <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($field['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center"><?php echo $field['Field_title']; ?></td>
412 <td align="center"<?php echo $field['wrap']; ?>>
413 <?php echo $field['pma_type']; ?>
414 </td>
416 <?php
418 // Prepares the field value
419 $real_null_value = FALSE;
420 if (isset($vrow)) {
421 // On a BLOB that can have a NULL value, the is_null() returns
422 // true if it has no content but for me this is different than
423 // having been set explicitely to NULL so I put an exception here
424 if (! $field['is_blob'] && is_null($vrow[$field['Field']])) {
425 $real_null_value = TRUE;
426 $vrow[$field['Field']] = '';
427 $special_chars = '';
428 $data = $vrow[$field['Field']];
429 } elseif ($field['True_Type'] == 'bit') {
430 $special_chars = PMA_printable_bit_value($vrow[$field], $extracted_fieldspec['spec_in_brackets']);
431 } else {
432 // loic1: special binary "characters"
433 if ($field['is_binary'] || $field['is_blob']) {
434 $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]);
435 } // end if
436 $special_chars = htmlspecialchars($vrow[$field['Field']]);
438 //We need to duplicate the first \n or otherwise we will lose the first newline entered in a VARCHAR or TEXT column
439 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
441 $data = $vrow[$field['Field']];
442 } // end if... else...
443 // loic1: if a timestamp field value is not included in an update
444 // statement MySQL auto-update it to the current timestamp
445 // lem9: however, things have changed since MySQL 4.1, so
446 // it's better to set a fields_prev in this situation
447 $backup_field = '<input type="hidden" name="fields_prev'
448 . $field_name_appendix . '" value="'
449 . htmlspecialchars($vrow[$field['Field']]) . '" />';
450 } else {
451 // loic1: display default values
452 if (!isset($field['Default'])) {
453 $field['Default'] = '';
454 $real_null_value = TRUE;
455 $data = '';
456 } else {
457 $data = $field['Default'];
459 if ($field['True_Type'] == 'bit') {
460 $special_chars = PMA_printable_bit_value($field['Default'], $extracted_fieldspec['spec_in_brackets']);
461 } else {
462 $special_chars = htmlspecialchars($field['Default']);
464 $backup_field = '';
467 $idindex = ($o_rows * $fields_cnt) + $i + 1;
468 $tabindex = (($idindex - 1) * 3) + 1;
470 // The function column
471 // -------------------
472 // Change by Bernard M. Piller <bernard@bmpsystems.com>
473 // We don't want binary data to be destroyed
474 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
475 // stored or retrieved" so it does not mean that the contents is
476 // binary
477 if ($cfg['ShowFunctionFields']) {
478 if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload)
479 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
480 echo ' <td align="center">' . $strBinary . '</td>' . "\n";
481 } elseif (strstr($field['True_Type'], 'enum') || strstr($field['True_Type'], 'set')) {
482 echo ' <td align="center">--</td>' . "\n";
483 } else {
485 <td>
486 <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">
487 <option></option>
488 <?php
489 $selected = '';
491 // garvin: Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
492 // or something similar. Then directly look up the entry in the RestrictFunctions array,
493 // which will then reveal the available dropdown options
494 if (isset($cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])])
495 && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])]])) {
496 $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])];
497 $dropdown = $cfg['RestrictFunctions'][$current_func_type];
498 $default_function = $cfg['DefaultFunctions'][$current_func_type];
499 } else {
500 $dropdown = array();
501 $default_function = '';
504 $dropdown_built = array();
505 $op_spacing_needed = FALSE;
507 // what function defined as default?
508 // for the first timestamp we don't set the default function
509 // if there is a default value for the timestamp
510 // (not including CURRENT_TIMESTAMP)
511 // and the column does not have the
512 // ON UPDATE DEFAULT TIMESTAMP attribute.
514 if ($field['True_Type'] == 'timestamp'
515 && empty($field['Default'])
516 && ! isset($analyzed_sql[0]['create_table_fields'][$field['Field']]['on_update_current_timestamp'])) {
517 $default_function = $cfg['DefaultFunctions']['first_timestamp'];
520 if ($field['Key'] == 'PRI'
521 && ($field['Type'] == 'char(36)' || $field['Type'] == 'varchar(36)')) {
522 $default_function = $cfg['DefaultFunctions']['pk_char36'];
525 // garvin: loop on the dropdown array and print all available options for that field.
526 foreach ($dropdown as $each_dropdown){
527 echo '<option';
528 if ($default_function === $each_dropdown) {
529 echo ' selected="selected"';
531 echo '>' . $each_dropdown . '</option>' . "\n";
532 $dropdown_built[$each_dropdown] = 'TRUE';
533 $op_spacing_needed = TRUE;
536 // garvin: For compatibility's sake, do not let out all other functions. Instead
537 // print a separator (blank) and then show ALL functions which weren't shown
538 // yet.
539 $cnt_functions = count($cfg['Functions']);
540 for ($j = 0; $j < $cnt_functions; $j++) {
541 if (!isset($dropdown_built[$cfg['Functions'][$j]]) || $dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
542 // Is current function defined as default?
543 $selected = ($field['first_timestamp'] && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
544 || (!$field['first_timestamp'] && $cfg['Functions'][$j] == $default_function)
545 ? ' selected="selected"'
546 : '';
547 if ($op_spacing_needed == TRUE) {
548 echo ' ';
549 echo '<option value="">--------</option>' . "\n";
550 $op_spacing_needed = FALSE;
553 echo ' ';
554 echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
556 } // end for
557 unset($selected);
559 </select>
560 </td>
561 <?php
563 } // end if ($cfg['ShowFunctionFields'])
566 // The null column
567 // ---------------
568 $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', '');
569 echo ' <td>' . "\n";
570 if ($field['Null'] == 'YES') {
571 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
572 if ($real_null_value && !$field['first_timestamp']) {
573 echo ' value="on"';
575 echo ' />' . "\n";
577 if (!(($cfg['ProtectBinary'] && $field['is_blob']) || ($cfg['ProtectBinary'] == 'all' && $field['is_binary']))) {
579 echo ' <input type="checkbox" tabindex="' . ($tabindex + $tabindex_for_null) . '"'
580 . ' name="fields_null' . $field_name_appendix . '"';
581 if ($real_null_value && !$field['first_timestamp']) {
582 echo ' checked="checked"';
584 echo ' id="field_' . ($idindex) . '_2"';
585 $onclick = ' onclick="if (this.checked) {nullify(';
586 if (strstr($field['True_Type'], 'enum')) {
587 if (strlen($field['Type']) > 20) {
588 $onclick .= '1, ';
589 } else {
590 $onclick .= '2, ';
592 } elseif (strstr($field['True_Type'], 'set')) {
593 $onclick .= '3, ';
594 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == false) {
595 // foreign key in a drop-down
596 $onclick .= '4, ';
597 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == true) {
598 // foreign key with a browsing icon
599 $onclick .= '6, ';
600 } else {
601 $onclick .= '5, ';
603 $onclick .= '\'' . PMA_escapeJsString($field['Field_html']) . '\', \'' . $field['Field_md5'] . '\', \'' . PMA_escapeJsString($vkey) . '\'); this.checked = true}; return true" />' . "\n";
604 echo $onclick;
605 } else {
606 echo ' <input type="hidden" name="fields_null' . $field_name_appendix . '"';
607 if ($real_null_value && !$field['first_timestamp']) {
608 echo ' value="on"';
610 echo ' />' . "\n";
613 echo ' </td>' . "\n";
615 // The value column (depends on type)
616 // ----------------
617 // See bug #1667887 for the reason why we don't use the maxlength
618 // HTML attribute
620 echo ' <td>' . "\n";
621 if ($foreignData['foreign_link'] == true) {
622 echo $backup_field . "\n";
624 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
625 value="foreign" />
626 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
627 value="" id="field_<?php echo ($idindex); ?>_3A" />
628 <input type="text" name="field_<?php echo $field_name_appendix_md5; ?>"
629 class="textfield" <?php echo $unnullify_trigger; ?>
630 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
631 id="field_<?php echo ($idindex); ?>_3"
632 value="<?php echo htmlspecialchars($data); ?>" />
633 <script type="text/javascript">
634 //<![CDATA[
635 document.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes,resizable=yes\'); return false"');
636 document.write(' href="browse_foreigners.php?');
637 document.write('<?php echo PMA_generate_common_url($db, $table); ?>');
638 document.writeln('&amp;field=<?php echo PMA_escapeJsString(urlencode($field['Field']) . $browse_foreigners_uri); ?>">');
639 document.writeln('<?php echo str_replace("'", "\'", $titles['Browse']); ?></a>');
640 //]]>
641 </script>
642 <?php
643 } elseif (is_array($foreignData['disp_row'])) {
644 echo $backup_field . "\n";
646 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
647 value="foreign" />
648 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
649 value="" id="field_<?php echo $idindex; ?>_3A" />
650 <select name="field_<?php echo $field_name_appendix_md5; ?>"
651 <?php echo $unnullify_trigger; ?>
652 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
653 id="field_<?php echo ($idindex); ?>_3">
654 <?php echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?>
655 </select>
656 <?php
657 // still needed? :
658 unset($foreignData['disp_row']);
659 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
661 &nbsp;</td>
662 </tr>
663 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
664 <td colspan="5" align="right">
665 <?php echo $backup_field . "\n"; ?>
666 <textarea name="fields<?php echo $field_name_appendix; ?>"
667 rows="<?php echo ($cfg['TextareaRows']*2); ?>"
668 cols="<?php echo ($cfg['TextareaCols']*2); ?>"
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_encoded; ?></textarea>
674 <?php
675 } elseif (strstr($field['pma_type'], 'text')) {
676 echo $backup_field . "\n";
678 <textarea name="fields<?php echo $field_name_appendix; ?>"
679 rows="<?php echo $cfg['TextareaRows']; ?>"
680 cols="<?php echo $cfg['TextareaCols']; ?>"
681 dir="<?php echo $text_dir; ?>"
682 id="field_<?php echo ($idindex); ?>_3"
683 <?php echo $unnullify_trigger; ?>
684 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
685 ><?php echo $special_chars_encoded; ?></textarea>
686 <?php
687 echo "\n";
688 if (strlen($special_chars) > 32000) {
689 echo " </td>\n";
690 echo ' <td>' . $strTextAreaLength;
692 } elseif ($field['pma_type'] == 'enum') {
693 if (! isset($table_fields[$i]['values'])) {
694 $table_fields[$i]['values'] = array();
695 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
696 // Removes automatic MySQL escape format
697 $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
698 $table_fields[$i]['values'][] = array(
699 'plain' => $val,
700 'html' => htmlspecialchars($val),
704 $field_enum_values = $table_fields[$i]['values'];
706 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="enum" />
707 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
708 <?php
709 echo "\n" . ' ' . $backup_field . "\n";
711 // show dropdown or radio depend on length
712 if (strlen($field['Type']) > 20) {
714 <select name="field_<?php echo $field_name_appendix_md5; ?>"
715 <?php echo $unnullify_trigger; ?>
716 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
717 id="field_<?php echo ($idindex); ?>_3">
718 <option value="">&nbsp;</option>
719 <?php
720 echo "\n";
722 foreach ($field_enum_values as $enum_value) {
723 echo ' ';
724 echo '<option value="' . $enum_value['html'] . '"';
725 if ($data == $enum_value['plain']
726 || ($data == ''
727 && (! isset($primary_key) || $field['Null'] != 'YES')
728 && isset($field['Default'])
729 && $enum_value['plain'] == $field['Default'])) {
730 echo ' selected="selected"';
732 echo '>' . $enum_value['html'] . '</option>' . "\n";
733 } // end for
736 </select>
737 <?php
738 } else {
739 $j = 0;
740 foreach ($field_enum_values as $enum_value) {
741 echo ' ';
742 echo '<input type="radio" name="field_' . $field_name_appendix_md5 . '"';
743 echo ' value="' . $enum_value['html'] . '"';
744 echo ' id="field_' . ($idindex) . '_3_' . $j . '"';
745 echo ' onclick="';
746 echo "if (typeof(document.forms['insertForm'].elements['fields_null"
747 . $field_name_appendix . "']) != 'undefined') {document.forms['insertForm'].elements['fields_null"
748 . $field_name_appendix . "'].checked = false}";
749 echo '"';
750 if ($data == $enum_value['plain']
751 || ($data == ''
752 && (! isset($primary_key) || $field['Null'] != 'YES')
753 && isset($field['Default'])
754 && $enum_value['plain'] == $field['Default'])) {
755 echo ' checked="checked"';
757 echo ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
758 echo '<label for="field_' . $idindex . '_3_' . $j . '">'
759 . $enum_value['html'] . '</label>' . "\n";
760 $j++;
761 } // end for
762 } // end else
763 } elseif ($field['pma_type'] == 'set') {
764 if (! isset($table_fields[$i]['values'])) {
765 $table_fields[$i]['values'] = array();
766 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
767 $table_fields[$i]['values'][] = array(
768 'plain' => $val,
769 'html' => htmlspecialchars($val),
772 $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
774 $field_set_values = $table_fields[$i]['values'];
775 $select_size = $table_fields[$i]['select_size'];
777 $vset = array_flip(explode(',', $data));
778 echo $backup_field . "\n";
780 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="set" />
781 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
782 <select name="field_<?php echo $field_name_appendix_md5; ?>"
783 size="<?php echo $select_size; ?>"
784 multiple="multiple" <?php echo $unnullify_trigger; ?>
785 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
786 id="field_<?php echo ($idindex); ?>_3">
787 <?php
788 foreach ($field_set_values as $field_set_value) {
789 echo ' ';
790 echo '<option value="' . $field_set_value['html'] . '"';
791 if (isset($vset[$field_set_value['plain']])) {
792 echo ' selected="selected"';
794 echo '>' . $field_set_value['html'] . '</option>' . "\n";
795 } // end for
797 </select>
798 <?php
800 // Change by Bernard M. Piller <bernard@bmpsystems.com>
801 // We don't want binary data destroyed
802 elseif ($field['is_binary'] || $field['is_blob']) {
803 if (($cfg['ProtectBinary'] && $field['is_blob'])
804 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
805 echo "\n";
806 // rajk - for blobstreaming
807 $bs_reference_exists = FALSE;
809 if (isset ($tbl_type) && strlen ($tbl_type) > 0)
811 // load PMA_Config
812 $PMA_Config = $_SESSION['PMA_Config'];
814 if (!empty($PMA_Config))
816 $requiredTblType = $PMA_Config->get('PBXT_NAME');
818 if ($requiredTblType == strtolower ($tbl_type))
820 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
822 // check if blobstreaming plugins exist
823 if ($pluginsExist)
825 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
827 if (!empty($bs_tables) && strlen($db) > 0)
829 $bs_tables = $bs_tables[$db];
831 if (isset($bs_tables))
833 $allBSTablesExist = TRUE;
835 foreach ($bs_tables as $table_key=>$bs_tbl)
836 if (!$bs_tables[$table_key]['Exists'])
838 $allBSTablesExist = FALSE;
839 break;
842 if ($allBSTablesExist)
843 $bs_reference_exists = PMA_BS_ReferenceExists($data, $db);
844 } // end if (isset($bs_tables))
845 } // end if (!empty($bs_tables) && strlen($db) > 0)
846 } // end if ($pluginsExist)
847 } // end if ($requiredTblType == strtolower ($tbl_type))
848 } // end if (!empty($PMA_Config))
849 } // end if (isset ($tbl_type) && strlen ($tbl_type) > 0)
851 if ($bs_reference_exists)
853 echo '<input type="hidden" name="remove_blob_ref_' . $field['Field_html'] . $vkey . '" value="' . $data . '" />';
854 echo '<input type="checkbox" name="remove_blob_repo_' . $field['Field_html'] . $vkey . '" /> ' . $strBLOBRepositoryRemove . "<br />";
855 echo PMA_BS_CreateReferenceLink($data, $db);
856 echo "<br />";
858 else
860 echo $strBinaryDoNotEdit;
861 if (isset($data)) {
862 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
863 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
864 unset($data_size);
866 echo "\n";
867 } // end if ($bs_reference_exists)
869 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="protected" />
870 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
871 <?php
872 } elseif ($field['is_blob']) {
873 echo "\n";
874 echo $backup_field . "\n";
876 <textarea name="fields<?php echo $field_name_appendix; ?>"
877 rows="<?php echo $cfg['TextareaRows']; ?>"
878 cols="<?php echo $cfg['TextareaCols']; ?>"
879 dir="<?php echo $text_dir; ?>"
880 id="field_<?php echo ($idindex); ?>_3"
881 <?php echo $unnullify_trigger; ?>
882 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
883 ><?php echo $special_chars_encoded; ?></textarea>
884 <?php
886 } else {
887 // field size should be at least 4 and max 40
888 $fieldsize = min(max($field['len'], 4), 40);
889 echo "\n";
890 echo $backup_field . "\n";
892 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
893 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
894 class="textfield" <?php echo $unnullify_trigger; ?>
895 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
896 id="field_<?php echo ($idindex); ?>_3" />
897 <?php
898 } // end if...elseif...else
900 // Upload choice (only for BLOBs because the binary
901 // attribute does not imply binary contents)
902 // (displayed whatever value the ProtectBinary has)
904 if ($is_upload && $field['is_blob']) {
905 // added by rajk
906 // check if field type is of longblob
907 if ($field['pma_type'] == "longblob")
909 if (isset ($tbl_type) && strlen ($tbl_type) > 0)
911 // load PMA Config
912 $PMA_Config = $_SESSION['PMA_Config'];
914 // is PMA_Config's data loaded? continue only if it is
915 if (!empty($PMA_Config))
917 $requiredTblType = $PMA_Config->get('PBXT_NAME');
919 if ($requiredTblType == strtolower ($tbl_type))
921 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
923 // check if blobstreaming plugins exist
924 if ($pluginsExist)
926 $curlExists = $PMA_Config->get('CURL_EXISTS');
928 // check if CURL exists
929 if ($curlExists)
931 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
933 // check for BLOBStreamable databases and if current database name is provided
934 if (!empty($bs_tables) && strlen($db) > 0)
936 $bs_tables = $bs_tables[$db];
938 // check if reference to BLOBStreaming tables exists
939 if (isset($bs_tables))
941 $allBSTablesExist = TRUE;
943 foreach ($bs_tables as $table_key=>$bs_tbl)
944 if (!$bs_tables[$table_key]['Exists'])
946 $allBSTablesExist = FALSE;
947 break;
950 // check if necessary BLOBStreaming tables exist
951 if ($allBSTablesExist)
953 echo '<br />';
954 echo '<input type="checkbox" name="upload_blob_repo_' . $field['Field_html'] . $vkey . '" /> ' . $strBLOBRepositoryUpload;
955 } // end if ($allBSTablesExist)
956 } // end if (isset($bs_tables)
957 } // end if (!empty($bs_tables) && strlen ($db) > 0)
958 } // end if ($curlExists)
959 } // end if ($pluginsExist)
960 } // end if ($requiredTblType == strtolower ($tbl_type))
961 } // end if (!empty($PMA_Config))
962 } // end if (isset ($tbl_type) && strlen ($tbl_type) > 0)
965 echo '<br />';
966 echo '<input type="file" name="fields_upload_' . $field['Field_html'] . $vkey . '" class="textfield" id="field_' . $idindex . '_3" size="10" />&nbsp;';
968 // find maximum upload size, based on field type
970 * @todo with functions this is not so easy, as you can basically
971 * process any data with function like MD5
973 $max_field_sizes = array(
974 'tinyblob' => '256',
975 'blob' => '65536',
976 'mediumblob' => '16777216',
977 'longblob' => '4294967296'); // yeah, really
979 $this_field_max_size = $max_upload_size; // from PHP max
980 if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
981 $this_field_max_size = $max_field_sizes[$field['pma_type']];
983 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
984 // do not generate here the MAX_FILE_SIZE, because we should
985 // put only one in the form to accommodate the biggest field
986 if ($this_field_max_size > $biggest_max_file_size) {
987 $biggest_max_file_size = $this_field_max_size;
991 if (!empty($cfg['UploadDir'])) {
992 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
993 if ($files === FALSE) {
994 echo ' <font color="red">' . $strError . '</font><br />' . "\n";
995 echo ' ' . $strWebServerUploadDirectoryError . "\n";
996 } elseif (!empty($files)) {
997 echo "<br />\n";
998 echo ' <i>' . $strOr . '</i>' . ' ' . $strWebServerUploadDirectory . ':<br />' . "\n";
999 echo ' <select size="1" name="fields_uploadlocal_' . $field['Field_html'] . $vkey . '">' . "\n";
1000 echo ' <option value="" selected="selected"></option>' . "\n";
1001 echo $files;
1002 echo ' </select>' . "\n";
1004 } // end if (web-server upload directory)
1005 } // end elseif (binary or blob)
1006 else {
1007 // field size should be at least 4 and max 40
1008 $fieldsize = min(max($field['len'], 4), 40);
1009 echo $backup_field . "\n";
1010 if ($field['is_char'] && ($cfg['CharEditing'] == 'textarea' || strpos($data, "\n") !== FALSE)) {
1011 echo "\n";
1013 <textarea name="fields<?php echo $field_name_appendix; ?>"
1014 rows="<?php echo $cfg['CharTextareaRows']; ?>"
1015 cols="<?php echo $cfg['CharTextareaCols']; ?>"
1016 dir="<?php echo $text_dir; ?>"
1017 id="field_<?php echo ($idindex); ?>_3"
1018 <?php echo $unnullify_trigger; ?>
1019 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
1020 ><?php echo $special_chars_encoded; ?></textarea>
1021 <?php
1022 } else {
1024 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
1025 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
1026 class="textfield" <?php echo $unnullify_trigger; ?>
1027 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
1028 id="field_<?php echo ($idindex); ?>_3" />
1029 <?php
1030 if ($field['Extra'] == 'auto_increment') {
1032 <input type="hidden" name="auto_increment<?php echo $field_name_appendix; ?>" value="1" />
1033 <?php
1034 } // end if
1035 if (substr($field['pma_type'], 0, 9) == 'timestamp') {
1037 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="timestamp" />
1038 <?php
1040 if ($field['True_Type'] == 'bit') {
1042 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="bit" />
1043 <?php
1045 if ($field['pma_type'] == 'date' || $field['pma_type'] == 'datetime' || substr($field['pma_type'], 0, 9) == 'timestamp') {
1047 <script type="text/javascript">
1048 //<![CDATA[
1049 document.write('<a title="<?php echo $strCalendar;?>"');
1050 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); ?>\')">');
1051 document.write('<img class="calendar"');
1052 document.write(' src="<?php echo $pmaThemeImage; ?>b_calendar.png"');
1053 document.write(' alt="<?php echo $strCalendar; ?>"/></a>');
1054 //]]>
1055 </script>
1056 <?php
1061 </td>
1062 </tr>
1063 <?php
1064 $odd_row = !$odd_row;
1065 } // end for
1066 $o_rows++;
1067 echo ' </tbody></table><br />';
1068 } // end foreach on multi-edit
1070 <br />
1072 <fieldset>
1073 <table border="0" cellpadding="5" cellspacing="0">
1074 <tr>
1075 <td valign="middle" nowrap="nowrap">
1076 <select name="submit_type" tabindex="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
1077 <?php
1078 if (isset($primary_key)) {
1080 <option value="<?php echo $strSave; ?>"><?php echo $strSave; ?></option>
1081 <?php
1084 <option value="<?php echo $strInsertAsNewRow; ?>"><?php echo $strInsertAsNewRow; ?></option>
1085 </select>
1086 <?php
1087 echo "\n";
1089 if (!isset($after_insert)) {
1090 $after_insert = 'back';
1093 </td>
1094 <td valign="middle">
1095 &nbsp;&nbsp;&nbsp;<strong><?php echo $strAndThen; ?></strong>&nbsp;&nbsp;&nbsp;
1096 </td>
1097 <td valign="middle" nowrap="nowrap">
1098 <select name="after_insert">
1099 <option value="back" <?php echo ($after_insert == 'back' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertBack; ?></option>
1100 <option value="new_insert" <?php echo ($after_insert == 'new_insert' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertNewInsert; ?></option>
1101 <?php
1102 if (isset($primary_key)) {
1104 <option value="same_insert" <?php echo ($after_insert == 'same_insert' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertSame; ?></option>
1105 <?php
1106 // If we have just numeric primary key, we can also edit next
1107 // in 2.8.2, we were looking for `field_name` = numeric_value
1108 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $primary_key)) {
1109 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1110 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $primary_key)) {
1112 <option value="edit_next" <?php echo ($after_insert == 'edit_next' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertNext; ?></option>
1113 <?php
1117 </select>
1118 </td>
1119 </tr>
1121 <tr>
1122 <td>
1123 <?php echo PMA_showHint($strUseTabKey); ?>
1124 </td>
1125 <td colspan="3" align="right" valign="middle">
1126 <input type="submit" value="<?php echo $strGo; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 6); ?>" id="buttonYes" />
1127 <input type="reset" value="<?php echo $strReset; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 7); ?>" />
1128 </td>
1129 </tr>
1130 </table>
1131 </fieldset>
1132 <?php if ($biggest_max_file_size > 0) {
1133 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
1134 } ?>
1135 </form>
1136 <?php
1137 if ($insert_mode) {
1139 <!-- Restart insertion form -->
1140 <form method="post" action="tbl_replace.php" name="restartForm" >
1141 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
1142 <input type="hidden" name="goto" value="<?php echo htmlspecialchars($GLOBALS['goto']); ?>" />
1143 <input type="hidden" name="err_url" value="<?php echo htmlspecialchars($err_url); ?>" />
1144 <input type="hidden" name="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
1145 <?php
1146 if (isset($primary_keys)) {
1147 foreach ($primary_key_array as $key_id => $primary_key) {
1148 echo '<input type="hidden" name="primary_key[' . $key_id . ']" value="' . htmlspecialchars(trim($primary_key)) . '" />'. "\n";
1151 $tmp = '<select name="insert_rows" id="insert_rows" onchange="this.form.submit();" >' . "\n";
1152 $option_values = array(1,2,5,10,15,20,30,40);
1153 foreach ($option_values as $value) {
1154 $tmp .= '<option value="' . $value . '"';
1155 if ($value == $cfg['InsertRows']) {
1156 $tmp .= ' selected="selected"';
1158 $tmp .= '>' . $value . '</option>' . "\n";
1160 $tmp .= '</select>' . "\n";
1161 echo "\n" . sprintf($strRestartInsertion, $tmp);
1162 unset($tmp);
1163 echo '<noscript><input type="submit" value="' . $strGo . '" /></noscript>' . "\n";
1164 echo '</form>' . "\n";
1168 * Displays the footer
1170 require_once './libraries/footer.inc.php';