2.11.11-dev
[phpmyadmin/dkf.git] / tbl_change.php
blobd802e2ad3d88faf8a1d263ae6bf300f3c60489c8
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 */
8 /**
9 * Gets the variables sent or posted to this script and displays the header
11 require_once './libraries/common.inc.php';
13 /**
14 * Sets global variables.
15 * Here it's better to use a if, instead of the '?' operator
16 * to avoid setting a variable to '' when it's not present in $_REQUEST
18 /**
19 * @todo this one is badly named, it's really a WHERE condition
20 * and exists even for tables not having a primary key or unique key
22 if (isset($_REQUEST['primary_key'])) {
23 $primary_key = $_REQUEST['primary_key'];
25 if (isset($_SESSION['edit_next'])) {
26 $primary_key = $_SESSION['edit_next'];
27 unset($_SESSION['edit_next']);
28 $after_insert = 'edit_next';
30 if (isset($_REQUEST['sql_query'])) {
31 $sql_query = $_REQUEST['sql_query'];
33 if (isset($_REQUEST['ShowFunctionFields'])) {
34 $cfg['ShowFunctionFields'] = $_REQUEST['ShowFunctionFields'];
38 $js_to_run = 'tbl_change.js';
39 require_once './libraries/header.inc.php';
40 require_once './libraries/relation.lib.php'; // foreign keys
41 require_once './libraries/file_listing.php'; // file listing
44 /**
45 * Displays the query submitted and its result
47 if (! empty($disp_message)) {
48 if (! isset($disp_query)) {
49 $disp_query = null;
51 PMA_showMessage($disp_message, $disp_query);
55 /**
56 * Defines the url to return to in case of error in a sql statement
57 * (at this point, $goto might be set but empty)
59 if (empty($goto)) {
60 $goto = 'db_sql.php';
62 /**
63 * @todo check if we could replace by "db_|tbl_"
65 if (!preg_match('@^(db|tbl)_@', $goto)) {
66 $err_url = $goto . "?" . PMA_generate_common_url($db) . "&amp;sql_query=" . urlencode($sql_query);
67 } else {
68 $err_url = $goto . '?'
69 . PMA_generate_common_url($db)
70 . ((preg_match('@^(tbl_)@', $goto)) ? '&amp;table=' . urlencode($table) : '');
74 /**
75 * Ensures db and table are valid, else moves to the "parent" script
77 require_once './libraries/db_table_exists.lib.php';
80 /**
81 * Sets parameters for links
83 $url_query = PMA_generate_common_url($db, $table)
84 . '&amp;goto=tbl_sql.php';
86 require_once './libraries/tbl_info.inc.php';
88 /* Get comments */
90 $comments_map = array();
92 if ($GLOBALS['cfg']['ShowPropertyComments']) {
93 require_once './libraries/relation.lib.php';
94 require_once './libraries/transformations.lib.php';
96 $cfgRelation = PMA_getRelationsParam();
98 if ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) {
99 $comments_map = PMA_getComments($db, $table);
104 * Displays top menu links
106 require_once './libraries/tbl_links.inc.php';
110 * Get the analysis of SHOW CREATE TABLE for this table
112 $show_create_table = PMA_DBI_fetch_value(
113 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
114 0, 1);
115 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
116 unset($show_create_table);
119 * Get the list of the fields of the current table
121 PMA_DBI_select_db($db);
122 $table_def = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
123 if (isset($primary_key)) {
124 if (is_array($primary_key)) {
125 $primary_key_array = $primary_key;
126 } else {
127 $primary_key_array = array(0 => $primary_key);
130 $row = array();
131 $result = array();
132 $found_unique_key = false;
133 foreach ($primary_key_array as $rowcount => $primary_key) {
134 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';';
135 $result[$rowcount] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE);
136 $row[$rowcount] = PMA_DBI_fetch_assoc($result[$rowcount]);
137 $primary_keys[$rowcount] = str_replace('\\', '\\\\', $primary_key);
139 // No row returned
140 if (!$row[$rowcount]) {
141 unset($row[$rowcount], $primary_key_array[$rowcount]);
142 PMA_showMessage($strEmptyResultSet, $local_query);
143 echo "\n";
144 require_once './libraries/footer.inc.php';
145 } else { // end if (no record returned)
146 $meta = PMA_DBI_get_fields_meta($result[$rowcount]);
147 if ($tmp = PMA_getUniqueCondition($result[$rowcount], count($meta), $meta, $row[$rowcount], true)) {
148 $found_unique_key = true;
150 unset($tmp);
153 } else {
154 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
155 unset($row);
158 // <markus@noga.de>
159 // retrieve keys into foreign fields, if any
160 $cfgRelation = PMA_getRelationsParam();
161 $foreigners = ($cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : FALSE);
165 * Displays the form
167 // loic1: autocomplete feature of IE kills the "onchange" event handler and it
168 // must be replaced by the "onpropertychange" one in this case
169 $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5)
170 ? 'onpropertychange'
171 : 'onchange';
172 // Had to put the URI because when hosted on an https server,
173 // some browsers send wrongly this form to the http server.
176 <?php if ($cfg['CtrlArrowsMoving']) { ?>
177 <!-- Set on key handler for moving using by Ctrl+arrows -->
178 <script src="./js/keyhandler.js" type="text/javascript"></script>
179 <script type="text/javascript">
180 //<![CDATA[
181 var switch_movement = 0;
182 document.onkeydown = onKeyDownArrowsHandler;
183 //]]>
184 </script>
185 <?php } ?>
187 <!-- Insert/Edit form -->
188 <form method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?>>
189 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
190 <input type="hidden" name="goto" value="<?php echo htmlspecialchars($goto); ?>" />
191 <input type="hidden" name="err_url" value="<?php echo htmlspecialchars($err_url); ?>" />
192 <input type="hidden" name="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
193 <?php
194 if (isset($primary_keys)) {
195 foreach ($primary_key_array as $rowcount => $primary_key) {
196 echo '<input type="hidden" name="primary_key[' . $rowcount . ']" value="' . htmlspecialchars(trim($primary_key)) . '" />'. "\n";
199 echo "\n";
201 if ($cfg['PropertiesIconic'] === true || $cfg['PropertiesIconic'] === 'both') {
202 if ($cfg['PropertiesIconic'] === 'both') {
203 $iconic_spacer = '<div class="nowrap">';
204 } else {
205 $iconic_spacer = '';
208 $titles['Browse'] = $iconic_spacer . '<img width="16" height="16" src="' . $pmaThemeImage . 'b_browse.png" alt="' . $strBrowseForeignValues . '" title="' . $strBrowseForeignValues . '" border="0" />';
210 if ($cfg['PropertiesIconic'] === 'both') {
211 $titles['Browse'] .= '&nbsp;' . $strBrowseForeignValues . '</div>';
213 } else {
214 $titles['Browse'] = $strBrowseForeignValues;
217 // Set if we passed the first timestamp field
218 $timestamp_seen = 0;
219 $fields_cnt = PMA_DBI_num_rows($table_def);
221 // Set a flag here because the 'if' would not be valid in the loop
222 // if we set a value in some field
223 $insert_mode = (!isset($row) ? TRUE : FALSE);
224 if ($insert_mode) {
225 $loop_array = array();
226 for ($i = 0; $i < $cfg['InsertRows']; $i++) {
227 $loop_array[] = FALSE;
229 } else {
230 $loop_array = $row;
233 while ($trow = PMA_DBI_fetch_assoc($table_def)) {
234 $trow_table_def[] = $trow;
237 $tabindex = 0;
238 $tabindex_for_function = +3000;
239 $tabindex_for_null = +6000;
240 $tabindex_for_value = 0;
241 $o_rows = 0;
242 $biggest_max_file_size = 0;
244 // user can toggle the display of Function column
245 // (currently does not work for multi-edits)
246 $url_params['db'] = $db;
247 $url_params['table'] = $table;
248 if (isset($primary_key)) {
249 $url_params['primary_key'] = trim($primary_key);
251 if (! empty($sql_query)) {
252 $url_params['sql_query'] = $sql_query;
255 if (! $cfg['ShowFunctionFields']) {
256 $this_url_params = array_merge($url_params,
257 array('ShowFunctionFields' => 1));
258 echo $strShow . ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . $strFunction . '</a>' . "\n";
261 foreach ($loop_array as $vrowcount => $vrow) {
262 if ($vrow === FALSE) {
263 unset($vrow);
266 $jsvkey = $vrowcount;
267 $browse_foreigners_uri = '&amp;pk=' . $vrowcount;
268 $vkey = '[multi_edit][' . $jsvkey . ']';
270 $vresult = (isset($result) && is_array($result) && isset($result[$vrowcount]) ? $result[$vrowcount] : $result);
271 if ($insert_mode && $vrowcount > 0) {
272 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $vrowcount . '" id="insert_ignore_check_' . $vrowcount . '" />';
273 echo '<label for="insert_ignore_check_' . $vrowcount . '">' . $strIgnore . '</label><br />' . "\n";
276 <table>
277 <tr>
278 <th><?php echo $strField; ?></th>
279 <th><?php echo $strType; ?></th>
280 <?php
281 if ($cfg['ShowFunctionFields']) {
282 $this_url_params = array_merge($url_params,
283 array('ShowFunctionFields' => 0));
284 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . $strHide . '">' . $strFunction . '</a></th>' . "\n";
287 <th><?php echo $strNull; ?></th>
288 <th><?php echo $strValue; ?></th>
289 </tr>
290 <?php
292 // garvin: For looping on multiple rows, we need to reset any variable used inside the loop to indicate sth.
293 $timestamp_seen = 0;
294 unset($first_timestamp);
296 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
297 $m_rows = $o_rows + 1;
299 $odd_row = true;
300 for ($i = 0; $i < $fields_cnt; $i++) {
301 $row_table_def = $trow_table_def[$i];
302 $row_table_def['True_Type'] = preg_replace('@\(.*@s', '', $row_table_def['Type']);
304 $field = $row_table_def['Field'];
305 $field_html = htmlspecialchars($field);
306 $field_md5 = md5($field);
308 $unnullify_trigger = $chg_evt_handler . "=\"return unNullify('" . PMA_escapeJsString($field_html) . "', '" . PMA_escapeJsString($jsvkey) . "')\"";
309 $field_name_appendix = $vkey . '[' . $field_html . ']';
310 $field_name_appendix_md5 = $field_md5 . $vkey . '[]';
313 // removed previous PHP3-workaround that caused a problem with
314 // field names like '000'
315 //$rowfield = $field;
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 // $row_table_def['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 ($row_table_def['Type'] == 'datetime'
334 && !isset($row_table_def['Default'])
335 && isset($row_table_def['Null'])
336 && $row_table_def['Null'] == 'YES') {
337 $row_table_def['Default'] = null;
340 if ($row_table_def['Type'] == 'datetime'
341 && (!isset($row_table_def['Default']))
342 && (!is_null($row_table_def['Default']))) {
343 // INSERT case
344 if ($insert_mode) {
345 if (isset($vrow)) {
346 $vrow[$field] = date('Y-m-d H:i:s', time());
347 } else {
348 $vrow = array($field => date('Y-m-d H:i:s', time()));
351 // UPDATE case with an empty and not NULL value under PHP4
352 elseif (empty($vrow[$field]) && is_null($vrow[$field])) {
353 $vrow[$field] = date('Y-m-d H:i:s', time());
354 } // end if... elseif...
356 $len = (preg_match('@float|double@', $row_table_def['Type']))
357 ? 100
358 : PMA_DBI_field_len($vresult, $i);
359 $first_timestamp = 0;
361 $field_name = $field_html;
362 if (isset($comments_map[$field])) {
363 $field_name = '<span style="border-bottom: 1px dashed black;" title="'
364 . htmlspecialchars($comments_map[$field]) . '">' . $field_name . '</span>';
368 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
369 <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($row_table_def['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center"><?php echo $field_name; ?></td>
371 <?php
372 // The type column
373 $is_binary = stristr($row_table_def['Type'], 'binary');
374 $is_blob = stristr($row_table_def['Type'], 'blob');
375 $is_char = stristr($row_table_def['Type'], 'char');
376 switch ($row_table_def['True_Type']) {
377 case 'set':
378 $type = 'set';
379 $type_nowrap = '';
380 break;
381 case 'enum':
382 $type = 'enum';
383 $type_nowrap = '';
384 break;
385 case 'timestamp':
386 if (!$timestamp_seen) { // can only occur once per table
387 $timestamp_seen = 1;
388 $first_timestamp = 1;
390 $type = $row_table_def['Type'];
391 $type_nowrap = ' nowrap="nowrap"';
392 break;
394 default:
395 $type = $row_table_def['Type'];
396 $type_nowrap = ' nowrap="nowrap"';
397 break;
400 <td align="center"<?php echo $type_nowrap; ?>>
401 <?php echo $type; ?>
402 </td>
404 <?php
406 // Prepares the field value
407 $real_null_value = FALSE;
408 if (isset($vrow)) {
409 // On a BLOB that can have a NULL value, the is_null() returns
410 // true if it has no content but for me this is different than
411 // having been set explicitely to NULL so I put an exception here
412 if (! $is_blob && function_exists('is_null') && is_null($vrow[$field])) {
413 $real_null_value = TRUE;
414 $vrow[$field] = '';
415 $special_chars = '';
416 $data = $vrow[$field];
417 } elseif ($row_table_def['True_Type'] == 'bit') {
418 $special_chars = PMA_printable_bit_value($vrow[$field], $len);
419 } else {
420 // loic1: special binary "characters"
421 if ($is_binary || $is_blob) {
422 $vrow[$field] = str_replace("\x00", '\0', $vrow[$field]);
423 $vrow[$field] = str_replace("\x08", '\b', $vrow[$field]);
424 $vrow[$field] = str_replace("\x0a", '\n', $vrow[$field]);
425 $vrow[$field] = str_replace("\x0d", '\r', $vrow[$field]);
426 $vrow[$field] = str_replace("\x1a", '\Z', $vrow[$field]);
427 } // end if
428 $special_chars = htmlspecialchars($vrow[$field]);
429 $data = $vrow[$field];
430 } // end if... else...
431 // loic1: if a timestamp field value is not included in an update
432 // statement MySQL auto-update it to the current timestamp
433 // lem9: however, things have changed since MySQL 4.1, so
434 // it's better to set a fields_prev in this situation
435 $backup_field = (PMA_MYSQL_INT_VERSION < 40100 && $row_table_def['True_Type'] == 'timestamp')
436 ? ''
437 : '<input type="hidden" name="fields_prev' . $field_name_appendix . '" value="' . htmlspecialchars($vrow[$field]) . '" />';
438 } else {
439 // loic1: display default values
440 if (!isset($row_table_def['Default'])) {
441 $row_table_def['Default'] = '';
442 $real_null_value = TRUE;
443 $data = '';
444 } else {
445 $data = $row_table_def['Default'];
447 if ($row_table_def['True_Type'] == 'bit') {
448 $special_chars = PMA_printable_bit_value($row_table_def['Default'], $len);
449 } else {
450 $special_chars = htmlspecialchars($row_table_def['Default']);
452 $backup_field = '';
455 $idindex = ($o_rows * $fields_cnt) + $i + 1;
456 $tabindex = (($idindex - 1) * 3) + 1;
458 // The function column
459 // -------------------
460 // Change by Bernard M. Piller <bernard@bmpsystems.com>
461 // We don't want binary data to be destroyed
462 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
463 // stored or retrieved" so it does not mean that the contents is
464 // binary
465 if ($cfg['ShowFunctionFields']) {
466 if (($cfg['ProtectBinary'] && $is_blob && !$is_upload)
467 || ($cfg['ProtectBinary'] == 'all' && $is_binary)) {
468 echo ' <td align="center">' . $strBinary . '</td>' . "\n";
469 } elseif (strstr($row_table_def['True_Type'], 'enum') || strstr($row_table_def['True_Type'], 'set')) {
470 echo ' <td align="center">--</td>' . "\n";
471 } else {
473 <td>
474 <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">
475 <option></option>
476 <?php
477 $selected = '';
479 // garvin: Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
480 // or something similar. Then directly look up the entry in the RestrictFunctions array,
481 // which will then reveal the available dropdown options
482 if (isset($cfg['RestrictFunctions'])
483 && isset($cfg['RestrictColumnTypes'])
484 && isset($cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])])
485 && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])]])) {
486 $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])];
487 $dropdown = $cfg['RestrictFunctions'][$current_func_type];
488 $default_function = $cfg['DefaultFunctions'][$current_func_type];
489 } else {
490 $dropdown = array();
491 $default_function = '';
494 $dropdown_built = array();
495 $op_spacing_needed = FALSE;
496 // garvin: loop on the dropdown array and print all available options for that field.
497 $cnt_dropdown = count($dropdown);
498 for ($j = 0; $j < $cnt_dropdown; $j++) {
499 // Is current function defined as default?
500 // For MySQL < 4.1.2, for the first timestamp we set as
501 // default function the one defined in config (which
502 // should be NOW()).
503 // For MySQL >= 4.1.2, we don't set the default function
504 // if there is a default value for the timestamp
505 // (not including CURRENT_TIMESTAMP)
506 // and the column does not have the
507 // ON UPDATE DEFAULT TIMESTAMP attribute.
509 if (PMA_MYSQL_INT_VERSION < 40102
510 || (PMA_MYSQL_INT_VERSION >= 40102
511 && !($row_table_def['True_Type'] == 'timestamp'
512 && !empty($row_table_def['Default'])
513 && !isset($analyzed_sql[0]['create_table_fields'][$field]['on_update_current_timestamp'])))) {
514 $selected = ($first_timestamp && $dropdown[$j] == $cfg['DefaultFunctions']['first_timestamp'])
515 || (!$first_timestamp && $dropdown[$j] == $default_function)
516 ? ' selected="selected"'
517 : '';
519 echo ' ';
520 echo '<option' . $selected . '>' . $dropdown[$j] . '</option>' . "\n";
521 $dropdown_built[$dropdown[$j]] = 'TRUE';
522 $op_spacing_needed = TRUE;
525 // garvin: For compatibility's sake, do not let out all other functions. Instead
526 // print a separator (blank) and then show ALL functions which weren't shown
527 // yet.
528 $cnt_functions = count($cfg['Functions']);
529 for ($j = 0; $j < $cnt_functions; $j++) {
530 if (!isset($dropdown_built[$cfg['Functions'][$j]]) || $dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
531 // Is current function defined as default?
532 $selected = ($first_timestamp && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
533 || (!$first_timestamp && $cfg['Functions'][$j] == $default_function)
534 ? ' selected="selected"'
535 : '';
536 if ($op_spacing_needed == TRUE) {
537 echo ' ';
538 echo '<option value="">--------</option>' . "\n";
539 $op_spacing_needed = FALSE;
542 echo ' ';
543 echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
545 } // end for
546 unset($selected);
548 </select>
549 </td>
550 <?php
552 } // end if ($cfg['ShowFunctionFields'])
555 // The null column
556 // ---------------
557 echo ' <td>' . "\n";
558 if ($row_table_def['Null'] == 'YES') {
559 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
560 if ($real_null_value && !$first_timestamp) {
561 echo ' value="on"';
563 echo ' />' . "\n";
565 if (!(($cfg['ProtectBinary'] && $is_blob) || ($cfg['ProtectBinary'] == 'all' && $is_binary))) {
567 echo ' <input type="checkbox" tabindex="' . ($tabindex + $tabindex_for_null) . '"'
568 . ' name="fields_null' . $field_name_appendix . '"';
569 if ($real_null_value && !$first_timestamp) {
570 echo ' checked="checked"';
572 echo ' id="field_' . ($idindex) . '_2"';
573 $onclick = ' onclick="if (this.checked) {nullify(';
574 if (strstr($row_table_def['True_Type'], 'enum')) {
575 if (strlen($row_table_def['Type']) > 20) {
576 $onclick .= '1, ';
577 } else {
578 $onclick .= '2, ';
580 } elseif (strstr($row_table_def['True_Type'], 'set')) {
581 $onclick .= '3, ';
582 } elseif ($foreigners && isset($foreigners[$field])) {
583 $onclick .= '4, ';
584 } else {
585 $onclick .= '5, ';
587 $onclick .= '\'' . PMA_escapeJsString($field_html) . '\', \'' . $field_md5 . '\', \'' . PMA_escapeJsString($vkey) . '\'); this.checked = true}; return true" />' . "\n";
588 echo $onclick;
589 } else {
590 echo ' <input type="hidden" name="fields_null' . $field_name_appendix . '"';
591 if ($real_null_value && !$first_timestamp) {
592 echo ' value="on"';
594 echo ' />' . "\n";
597 echo ' </td>' . "\n";
599 // The value column (depends on type)
600 // ----------------
602 require './libraries/get_foreign.lib.php';
604 if (isset($foreign_link) && $foreign_link == true) {
606 <td>
607 <?php echo $backup_field . "\n"; ?>
608 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
609 value="foreign" />
610 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
611 value="" id="field_<?php echo ($idindex); ?>_3A" />
612 <input type="text" name="field_<?php echo $field_name_appendix_md5; ?>"
613 class="textfield" <?php echo $unnullify_trigger; ?>
614 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
615 id="field_<?php echo ($idindex); ?>_3"
616 value="<?php echo htmlspecialchars($data); ?>" />
617 <script type="text/javascript">
618 //<![CDATA[
619 document.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes,resizable=yes\'); return false"');
620 document.write(' href="browse_foreigners.php?');
621 document.write('<?php echo PMA_generate_common_url($db, $table); ?>');
622 document.writeln('&amp;field=<?php echo PMA_escapeJsString(urlencode($field) . $browse_foreigners_uri); ?>">');
623 document.writeln('<?php echo str_replace("'", "\'", $titles['Browse']); ?></a>');
624 //]]>
625 </script>
626 </td>
627 <?php
628 } elseif (isset($disp_row) && is_array($disp_row)) {
630 <td>
631 <?php echo $backup_field . "\n"; ?>
632 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
633 value="foreign" />
634 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
635 value="" id="field_<?php echo $idindex; ?>_3A" />
636 <select name="field_<?php echo $field_name_appendix_md5; ?>"
637 <?php echo $unnullify_trigger; ?>
638 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
639 id="field_<?php echo ($idindex); ?>_3">
640 <?php echo PMA_foreignDropdown($disp_row, $foreign_field, $foreign_display, $data, $cfg['ForeignKeyMaxLimit']); ?>
641 </select>
642 </td>
643 <?php
644 unset($disp_row);
645 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($type, 'longtext')) {
647 <td>&nbsp;</td>
648 </tr>
649 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
650 <td colspan="5" align="right">
651 <?php echo $backup_field . "\n"; ?>
652 <textarea name="fields<?php echo $field_name_appendix; ?>"
653 rows="<?php echo ($cfg['TextareaRows']*2); ?>"
654 cols="<?php echo ($cfg['TextareaCols']*2); ?>"
655 dir="<?php echo $text_dir; ?>"
656 id="field_<?php echo ($idindex); ?>_3"
657 <?php echo $unnullify_trigger; ?>
658 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
659 ><?php echo $special_chars; ?></textarea>
660 </td>
661 <?php
662 } elseif (strstr($type, 'text')) {
664 <td>
665 <?php 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 </td>
675 <?php
676 echo "\n";
677 if (strlen($special_chars) > 32000) {
678 echo ' <td>' . $strTextAreaLength . '</td>' . "\n";
680 } elseif ($type == 'enum') {
681 $enum = PMA_getEnumSetOptions($row_table_def['Type']);
682 $enum_cnt = count($enum);
684 <td>
685 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="enum" />
686 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
687 <?php
688 echo "\n" . ' ' . $backup_field;
690 // show dropdown or radio depend on length
691 if (strlen($row_table_def['Type']) > 20) {
692 echo "\n";
694 <select name="field_<?php echo $field_name_appendix_md5; ?>"
695 <?php echo $unnullify_trigger; ?>
696 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
697 id="field_<?php echo ($idindex); ?>_3">
698 <option value=""></option>
699 <?php
700 echo "\n";
702 for ($j = 0; $j < $enum_cnt; $j++) {
703 // Removes automatic MySQL escape format
704 $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
705 echo ' ';
706 //echo '<option value="' . htmlspecialchars($enum_atom) . '"';
707 echo '<option value="' . htmlspecialchars($enum_atom) . '"';
708 if ($data == $enum_atom
709 || ($data == '' && (!isset($primary_key) || $row_table_def['Null'] != 'YES')
710 && isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
711 echo ' selected="selected"';
713 echo '>' . htmlspecialchars($enum_atom) . '</option>' . "\n";
714 } // end for
717 </select>
718 <?php
719 } else {
720 echo "\n";
721 for ($j = 0; $j < $enum_cnt; $j++) {
722 // Removes automatic MySQL escape format
723 $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
724 echo ' ';
725 echo '<input type="radio" name="field_' . $field_name_appendix_md5 . '"';
726 echo ' value="' . htmlspecialchars($enum_atom) . '"';
727 echo ' id="field_' . ($idindex) . '_3_' . $j . '"';
728 echo ' onclick="';
729 echo "if (typeof(document.forms['insertForm'].elements['fields_null"
730 . $field_name_appendix . "']) != 'undefined') {document.forms['insertForm'].elements['fields_null"
731 . $field_name_appendix . "'].checked = false}";
732 echo '"';
733 if ($data == $enum_atom
734 || ($data == '' && (!isset($primary_key) || $row_table_def['Null'] != 'YES')
735 && isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
736 echo ' checked="checked"';
738 echo ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
739 echo '<label for="field_' . $idindex . '_3_' . $j . '">'
740 . htmlspecialchars($enum_atom) . '</label>' . "\n";
741 } // end for
743 } // end else
744 echo "\n";
746 </td>
747 <?php
748 echo "\n";
749 } elseif ($type == 'set') {
750 $set = PMA_getEnumSetOptions($row_table_def['Type']);
752 if (isset($vset)) {
753 unset($vset);
755 for ($vals = explode(',', $data); list($t, $k) = each($vals);) {
756 $vset[$k] = 1;
758 $countset = count($set);
759 $size = min(4, $countset);
761 <td>
762 <?php echo $backup_field . "\n"; ?>
763 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="set" />
764 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
765 <select name="field_<?php echo $field_name_appendix_md5; ?>"
766 size="<?php echo $size; ?>"
767 multiple="multiple" <?php echo $unnullify_trigger; ?>
768 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
769 id="field_<?php echo ($idindex); ?>_3">
770 <?php
771 echo "\n";
772 for ($j = 0; $j < $countset; $j++) {
773 echo ' ';
774 //echo '<option value="'. htmlspecialchars($set[$j]) . '"';
775 echo '<option value="'. htmlspecialchars($set[$j]) . '"';
776 if (isset($vset[$set[$j]]) && $vset[$set[$j]]) {
777 echo ' selected="selected"';
779 echo '>' . htmlspecialchars($set[$j]) . '</option>' . "\n";
780 } // end for
782 </select>
783 </td>
784 <?php
786 // Change by Bernard M. Piller <bernard@bmpsystems.com>
787 // We don't want binary data destroyed
788 elseif ($is_binary || $is_blob) {
789 if (($cfg['ProtectBinary'] && $is_blob)
790 || ($cfg['ProtectBinary'] == 'all' && $is_binary)) {
791 echo "\n";
793 <td>
794 <?php
795 echo $strBinaryDoNotEdit;
796 if (isset($data)) {
797 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
798 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
799 unset($data_size);
801 echo "\n";
803 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="protected" />
804 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
805 <?php
806 } elseif ($is_blob) {
807 echo "\n";
809 <td>
810 <?php echo $backup_field . "\n"; ?>
811 <textarea name="fields<?php echo $field_name_appendix; ?>"
812 rows="<?php echo $cfg['TextareaRows']; ?>"
813 cols="<?php echo $cfg['TextareaCols']; ?>"
814 dir="<?php echo $text_dir; ?>"
815 id="field_<?php echo ($idindex); ?>_3"
816 <?php echo $unnullify_trigger; ?>
817 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
818 ><?php echo $special_chars; ?></textarea>
819 <?php
821 } else {
822 // field size should be at least 4 and max 40
823 $fieldsize = min(max($len, 4), 40);
824 echo "\n";
826 <td>
827 <?php echo $backup_field . "\n"; ?>
828 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
829 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
830 class="textfield" <?php echo $unnullify_trigger; ?>
831 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
832 id="field_<?php echo ($idindex); ?>_3" />
833 <?php
834 } // end if...elseif...else
836 // Upload choice (only for BLOBs because the binary
837 // attribute does not imply binary contents)
838 // (displayed whatever value the ProtectBinary has)
840 if ($is_upload && $is_blob) {
841 echo '<br />';
842 echo '<input type="file" name="fields_upload_' . $field_html . $vkey . '" class="textfield" id="field_' . $idindex . '_3" size="10" />&nbsp;';
844 // find maximum upload size, based on field type
846 * @todo with functions this is not so easy, as you can basically
847 * process any data with function like MD5
849 $max_field_sizes = array(
850 'tinyblob' => '256',
851 'blob' => '65536',
852 'mediumblob' => '16777216',
853 'longblob' => '4294967296'); // yeah, really
855 $this_field_max_size = $max_upload_size; // from PHP max
856 if ($this_field_max_size > $max_field_sizes[$type]) {
857 $this_field_max_size = $max_field_sizes[$type];
859 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
860 // do not generate here the MAX_FILE_SIZE, because we should
861 // put only one in the form to accommodate the biggest field
862 if ($this_field_max_size > $biggest_max_file_size) {
863 $biggest_max_file_size = $this_field_max_size;
867 if (!empty($cfg['UploadDir'])) {
868 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
869 if ($files === FALSE) {
870 echo ' <font color="red">' . $strError . '</font><br />' . "\n";
871 echo ' ' . $strWebServerUploadDirectoryError . "\n";
872 } elseif (!empty($files)) {
873 echo "<br />\n";
874 echo ' <i>' . $strOr . '</i>' . ' ' . $strWebServerUploadDirectory . ':<br />' . "\n";
875 echo ' <select size="1" name="fields_uploadlocal_' . $field_html . $vkey . '">' . "\n";
876 echo ' <option value="" selected="selected"></option>' . "\n";
877 echo $files;
878 echo ' </select>' . "\n";
880 } // end if (web-server upload directory)
882 echo '</td>';
884 } // end elseif (binary or blob)
885 else {
886 // field size should be at least 4 and max 40
887 $fieldsize = min(max($len, 4), 40);
889 <td>
890 <?php
891 echo $backup_field . "\n";
892 if ($is_char && ($cfg['CharEditing'] == 'textarea' || strpos($data, "\n") !== FALSE)) {
893 echo "\n";
895 <textarea name="fields<?php echo $field_name_appendix; ?>"
896 rows="<?php echo $cfg['CharTextareaRows']; ?>"
897 cols="<?php echo $cfg['CharTextareaCols']; ?>"
898 dir="<?php echo $text_dir; ?>"
899 id="field_<?php echo ($idindex); ?>_3"
900 <?php echo $unnullify_trigger; ?>
901 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
902 ><?php echo $special_chars; ?></textarea>
903 <?php
904 } else {
906 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
907 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
908 class="textfield" <?php echo $unnullify_trigger; ?>
909 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
910 id="field_<?php echo ($idindex); ?>_3" />
911 <?php
912 if ($row_table_def['Extra'] == 'auto_increment') {
914 <input type="hidden" name="auto_increment<?php echo $field_name_appendix; ?>" value="1" />
915 <?php
916 } // end if
917 if (substr($type, 0, 9) == 'timestamp') {
919 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="timestamp" />
920 <?php
922 if ($row_table_def['True_Type'] == 'bit') {
924 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="bit" />
925 <?php
927 if ($type == 'date' || $type == 'datetime' || substr($type, 0, 9) == 'timestamp') {
929 <script type="text/javascript">
930 //<![CDATA[
931 document.write('<a title="<?php echo $strCalendar;?>"');
932 document.write(' href="javascript:openCalendar(\'<?php echo PMA_generate_common_url();?>\', \'insertForm\', \'field_<?php echo ($idindex); ?>_3\', \'<?php echo (PMA_MYSQL_INT_VERSION >= 40100 && substr($type, 0, 9) == 'timestamp') ? 'datetime' : substr($type, 0, 9); ?>\')">');
933 document.write('<img class="calendar"');
934 document.write(' src="<?php echo $pmaThemeImage; ?>b_calendar.png"');
935 document.write(' alt="<?php echo $strCalendar; ?>"/></a>');
936 //]]>
937 </script>
938 <?php
942 </td>
943 <?php
946 </tr>
947 <?php
948 $odd_row = !$odd_row;
949 } // end for
950 $o_rows++;
952 <tr>
953 <th colspan="5" align="right" class="tblFooters">
954 <input type="submit" value="<?php echo $strGo; ?>" />&nbsp;
955 </th>
956 </tr>
957 <?php
958 echo ' </table><br />';
959 } // end foreach on multi-edit
961 <br />
963 <fieldset>
964 <table border="0" cellpadding="5" cellspacing="0">
965 <tr>
966 <td valign="middle" nowrap="nowrap">
967 <select name="submit_type" tabindex="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
968 <?php
969 if (isset($primary_key)) {
971 <option value="<?php echo $strSave; ?>"><?php echo $strSave; ?></option>
972 <?php
975 <option value="<?php echo $strInsertAsNewRow; ?>"><?php echo $strInsertAsNewRow; ?></option>
976 </select>
977 <?php
978 echo "\n";
980 if (!isset($after_insert)) {
981 $after_insert = 'back';
984 </td>
985 <td valign="middle">
986 &nbsp;&nbsp;&nbsp;<b><?php echo $strAndThen; ?></b>&nbsp;&nbsp;&nbsp;
987 </td>
988 <td valign="middle" nowrap="nowrap">
989 <select name="after_insert">
990 <option value="back" <?php echo ($after_insert == 'back' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertBack; ?></option>
991 <option value="new_insert" <?php echo ($after_insert == 'new_insert' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertNewInsert; ?></option>
992 <?php
993 if (isset($primary_key)) {
995 <option value="same_insert" <?php echo ($after_insert == 'same_insert' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertSame; ?></option>
996 <?php
997 // If we have just numeric primary key, we can also edit next
998 // in 2.8.2, we were looking for `field_name` = numeric_value
999 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $primary_key)) {
1000 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1001 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $primary_key)) {
1003 <option value="edit_next" <?php echo ($after_insert == 'edit_next' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertNext; ?></option>
1004 <?php
1008 </select>
1009 </td>
1010 </tr>
1012 <tr>
1013 <td>
1014 <?php echo PMA_showHint($strUseTabKey); ?>
1015 </td>
1016 <td colspan="3" align="right" valign="middle">
1017 <input type="submit" value="<?php echo $strGo; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 6); ?>" id="buttonYes" />
1018 <input type="reset" value="<?php echo $strReset; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 7); ?>" />
1019 </td>
1020 </tr>
1021 </table>
1022 </fieldset>
1023 <?php if ($biggest_max_file_size > 0) {
1024 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
1025 } ?>
1026 </form>
1027 <?php
1028 if ($insert_mode) {
1030 <!-- Restart insertion form -->
1031 <form method="post" action="tbl_replace.php" name="restartForm" >
1032 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
1033 <input type="hidden" name="goto" value="<?php echo htmlspecialchars($goto); ?>" />
1034 <input type="hidden" name="err_url" value="<?php echo htmlspecialchars($err_url); ?>" />
1035 <input type="hidden" name="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
1036 <?php
1037 if (isset($primary_keys)) {
1038 foreach ($primary_key_array as $rowcount => $primary_key) {
1039 echo '<input type="hidden" name="primary_key[' . $rowcount . ']" value="' . htmlspecialchars(trim($primary_key)) . '" />'. "\n";
1042 $tmp = '<select name="insert_rows" id="insert_rows" onchange="this.form.submit();" >' . "\n";
1043 $option_values = array(1,2,5,10,15,20,30,40);
1044 foreach ($option_values as $value) {
1045 $tmp .= '<option value="' . $value . '"';
1046 if ($value == $cfg['InsertRows']) {
1047 $tmp .= ' selected="selected"';
1049 $tmp .= '>' . $value . '</option>' . "\n";
1051 $tmp .= '</select>' . "\n";
1052 echo "\n" . sprintf($strRestartInsertion, $tmp);
1053 unset($tmp);
1054 echo '<noscript><input type="submit" value="' . $strGo . '" /></noscript>' . "\n";
1055 echo '</form>' . "\n";
1059 * Displays the footer
1061 require_once './libraries/footer.inc.php';