sorry, wrong version checked in
[phpmyadmin/arisferyanto.git] / tbl_change.php
blob596ba6dc2ee5170beb24481d07c983d36be28a21
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 /**
6 * Get the variables sent or posted to this script and displays the header
7 */
8 require_once('./libraries/common.lib.php');
10 $js_to_run = 'tbl_change.js';
11 require_once('./header.inc.php');
12 require_once('./libraries/relation.lib.php'); // foreign keys
13 require_once('./libraries/file_listing.php'); // file listing
16 /**
17 * Displays the query submitted and its result
19 if (!empty($disp_message)) {
20 if (isset($goto)) {
21 $goto_cpy = $goto;
22 $goto = 'tbl_properties.php?'
23 . PMA_generate_common_url($db, $table)
24 . '&amp;$show_query=1'
25 . '&amp;sql_query=' . (isset($disp_query) ? urlencode($disp_query) : '');
26 } else {
27 $show_query = '1';
29 if (isset($sql_query)) {
30 $sql_query_cpy = $sql_query;
31 unset($sql_query);
33 if (isset($disp_query)) {
34 $sql_query = $disp_query;
36 PMA_showMessage($disp_message);
37 if (isset($goto_cpy)) {
38 $goto = $goto_cpy;
39 unset($goto_cpy);
41 if (isset($sql_query_cpy)) {
42 $sql_query = $sql_query_cpy;
43 unset($sql_query_cpy);
48 /**
49 * Defines the url to return to in case of error in a sql statement
51 if (!isset($goto)) {
52 $goto = 'db_details.php';
54 if (!preg_match('@^(db_details|tbl_properties|tbl_select)@', $goto)) {
55 $err_url = $goto . "?" . PMA_generate_common_url($db) . "&amp;sql_query=" . urlencode($sql_query);
56 } else {
57 $err_url = $goto . '?'
58 . PMA_generate_common_url($db)
59 . ((preg_match('@^(tbl_properties|tbl_select)@', $goto)) ? '&amp;table=' . urlencode($table) : '');
63 /**
64 * Ensures db and table are valid, else moves to the "parent" script
66 require_once('./libraries/db_table_exists.lib.php');
69 /**
70 * Sets parameters for links
72 $url_query = PMA_generate_common_url($db, $table)
73 . '&amp;goto=tbl_properties.php';
75 require_once('./tbl_properties_table_info.php');
77 /* Get comments */
79 $comments_map = array();
81 if ($GLOBALS['cfg']['ShowPropertyComments']) {
82 require_once('./libraries/relation.lib.php');
83 require_once('./libraries/transformations.lib.php');
85 $cfgRelation = PMA_getRelationsParam();
87 if ($cfgRelation['commwork']) {
88 $comments_map = PMA_getComments($db, $table);
92 /**
93 * Displays top menu links
95 require_once('./tbl_properties_links.php');
98 /**
99 * Get the analysis of SHOW CREATE TABLE for this table
101 $show_create_table = PMA_DBI_fetch_value(
102 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
103 0, 1 );
104 $analyzed_sql = PMA_SQP_analyze( PMA_SQP_parse( $show_create_table ) );
105 unset($show_create_table);
108 * Get the list of the fields of the current table
110 PMA_DBI_select_db($db);
111 $table_def = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', NULL, PMA_DBI_QUERY_STORE);
112 if (isset($primary_key)) {
113 if (is_array($primary_key)) {
114 $primary_key_array = $primary_key;
115 } else {
116 $primary_key_array = array(0 => $primary_key);
119 $row = array();
120 $result = array();
121 foreach ($primary_key_array AS $rowcount => $primary_key) {
122 $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';';
123 $result[$rowcount] = PMA_DBI_query($local_query, NULL, PMA_DBI_QUERY_STORE);
124 $row[$rowcount] = PMA_DBI_fetch_assoc($result[$rowcount]);
125 $primary_keys[$rowcount] = $primary_key;
127 // No row returned
128 if (!$row[$rowcount]) {
129 unset($row[$rowcount]);
130 unset($primary_key_array[$rowcount]);
131 $goto_cpy = $goto;
132 $goto = 'tbl_properties.php?'
133 . PMA_generate_common_url($db, $table)
134 . '&amp;$show_query=1'
135 . '&amp;sql_query=' . urlencode($local_query);
136 if (isset($sql_query)) {
137 $sql_query_cpy = $sql_query;
138 unset($sql_query);
140 $sql_query = $local_query;
141 PMA_showMessage($strEmptyResultSet);
142 $goto = $goto_cpy;
143 unset($goto_cpy);
144 if (isset($sql_query_cpy)) {
145 $sql_query = $sql_query_cpy;
146 unset($sql_query_cpy);
148 echo "\n";
149 require_once('./footer.inc.php');
150 } // end if (no record returned)
152 } else {
153 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1;', NULL, PMA_DBI_QUERY_STORE);
154 unset($row);
157 // <markus@noga.de>
158 // retrieve keys into foreign fields, if any
159 $cfgRelation = PMA_getRelationsParam();
160 $foreigners = ($cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : FALSE);
164 * Displays the form
166 // loic1: autocomplete feature of IE kills the "onchange" event handler and it
167 // must be replaced by the "onpropertychange" one in this case
168 $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5)
169 ? 'onpropertychange'
170 : 'onchange';
171 // Had to put the URI because when hosted on an https server,
172 // some browsers send wrongly this form to the http server.
175 <?php if ($cfg['CtrlArrowsMoving']) { ?>
176 <!-- Set on key handler for moving using by Ctrl+arrows -->
177 <script src="libraries/keyhandler.js" type="text/javascript" language="javascript"></script>
178 <script type="text/javascript" language="javascript">
179 <!--
180 var switch_movement = 0;
181 document.onkeydown = onKeyDownArrowsHandler;
182 // -->
183 </script>
184 <?php } ?>
186 <!-- Change table properties form -->
187 <form method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) echo ' enctype="multipart/form-data"'; ?>>
188 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
189 <input type="hidden" name="goto" value="<?php echo urlencode($goto); ?>" />
190 <input type="hidden" name="pos" value="<?php echo isset($pos) ? $pos : 0; ?>" />
191 <input type="hidden" name="session_max_rows" value="<?php echo isset($session_max_rows) ? $session_max_rows : ''; ?>" />
192 <input type="hidden" name="disp_direction" value="<?php echo isset($disp_direction) ? $disp_direction : ''; ?>" />
193 <input type="hidden" name="repeat_cells" value="<?php echo isset($repeat_cells) ? $repeat_cells : ''; ?>" />
194 <input type="hidden" name="dontlimitchars" value="<?php echo (isset($dontlimitchars) ? $dontlimitchars : 0); ?>" />
195 <input type="hidden" name="err_url" value="<?php echo urlencode($err_url); ?>" />
196 <input type="hidden" name="sql_query" value="<?php echo isset($sql_query) ? urlencode($sql_query) : ''; ?>" />
197 <?php
198 if (isset($primary_key_array)) {
199 foreach ($primary_key_array AS $primary_key) {
201 <input type="hidden" name="primary_key[]" value="<?php echo urlencode($primary_key); ?>" />
202 <?php
205 echo "\n";
207 if ($cfg['PropertiesIconic'] == true) {
208 // We need to copy the value or else the == 'both' check will always return true
209 $propicon = (string)$cfg['PropertiesIconic'];
211 if ($propicon == 'both') {
212 $iconic_spacer = '<div class="nowrap">';
213 } else {
214 $iconic_spacer = '';
217 $titles['Browse'] = $iconic_spacer . '<img width="16" height="16" src="' . $pmaThemeImage . 'b_browse.png" alt="' . $strBrowseForeignValues . '" title="' . $strBrowseForeignValues . '" border="0" />';
219 if ($propicon == 'both') {
220 $titles['Browse'] .= '&nbsp;' . $strBrowseForeignValues . '</div>';
222 } else {
223 $titles['Browse'] = $strBrowseForeignValues;
226 // Set if we passed the first timestamp field
227 $timestamp_seen = 0;
228 $fields_cnt = PMA_DBI_num_rows($table_def);
230 // Set a flag here because the 'if' would not be valid in the loop
231 // if we set a value in some field
232 $insert_mode = (!isset($row) ? TRUE : FALSE);
233 if ($insert_mode) {
234 $loop_array = array();
235 for ($i = 0; $i < $cfg['InsertRows']; $i++) $loop_array[] = FALSE;
236 } else {
237 $loop_array = $row;
240 while ($trow = PMA_DBI_fetch_assoc($table_def)) {
241 $trow_table_def[] = $trow;
244 $tabindex = 0;
245 $tabindex_for_function = +1000;
246 $tabindex_for_null = +2000;
247 $tabindex_for_value = 0;
248 $o_rows = 0;
249 $biggest_max_file_size = 0;
250 foreach ($loop_array AS $vrowcount => $vrow) {
251 if ($vrow === FALSE) {
252 unset($vrow);
255 if ($insert_mode) {
256 $jsvkey = $vrowcount;
257 $browse_foreigners_uri = '&amp;pk=' . $vrowcount;
258 } else {
259 $jsvkey = urlencode($primary_keys[$vrowcount]);
260 $browse_foreigners_uri = '&amp;pk=' . urlencode($primary_keys[$vrowcount]);
262 $vkey = '[multi_edit][' . $jsvkey . ']';
264 $vresult = (isset($result) && is_array($result) && isset($result[$vrowcount]) ? $result[$vrowcount] : $result);
265 if ($insert_mode && $vrowcount > 0) {
266 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $vrowcount . '" id="insert_ignore_check_' . $vrowcount . '" />';
267 echo '<label for="insert_ignore_check_' . $vrowcount . '">' . $strIgnore . '</label><br />' . "\n";
270 <table border="<?php echo $cfg['Border']; ?>" cellpadding="2" cellspacing="1">
271 <tr>
272 <th><?php echo $strField; ?></th>
273 <th><?php echo $strType; ?></th>
274 <?php
275 if ($cfg['ShowFunctionFields']) {
276 echo ' <th>' . $strFunction . '</th>' . "\n";
279 <th><?php echo $strNull; ?></th>
280 <th><?php echo $strValue; ?></th>
281 </tr>
282 <?php
284 // garvin: For looping on multiple rows, we need to reset any variable used inside the loop to indicate sth.
285 $timestamp_seen = 0;
286 unset($first_timestamp);
288 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
289 $m_rows = $o_rows + 1;
291 for ($i = 0; $i < $fields_cnt; $i++) {
292 // Display the submit button after every 15 lines --swix
293 // (wanted to use an <a href="#bottom"> and <a name> instead,
294 // but it didn't worked because of the <base href>)
296 if ((($o_rows * $fields_cnt + $i) % 15 == 0) && ($i + $o_rows != 0)) {
298 <tr>
299 <th colspan="5" align="right" class="tblFooters">
300 <input type="submit" value="<?php echo $strGo; ?>" />&nbsp;
301 </th>
302 </tr>
303 <?php
304 } // end if
305 echo "\n";
307 $row_table_def = $trow_table_def[$i];
308 $row_table_def['True_Type'] = preg_replace('@\(.*@s', '', $row_table_def['Type']);
310 $field = $row_table_def['Field'];
312 // removed previous PHP3-workaround that caused a problem with
313 // field names like '000'
314 $rowfield = $field;
316 // d a t e t i m e
318 // loic1: current date should not be set as default if the field is NULL
319 // for the current row
320 // lem9: but do not put here the current datetime if there is a default
321 // value (the real default value will be set in the
322 // Default value logic below)
324 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
325 // $row_table_def['Default'] is not set if it contains NULL:
326 // Array ( [Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime )
327 // but, look what we get if we switch to iso: (Default is NULL)
328 // Array ( [Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime )
329 // so I force a NULL into it (I don't think it's possible
330 // to have an empty default value for DATETIME)
331 // then, the "if" after this one will work
332 if ($row_table_def['Type'] == 'datetime'
333 && !isset($row_table_def['Default'])
334 && isset($row_table_def['Null'])
335 && $row_table_def['Null'] == 'YES') {
336 $row_table_def['Default'] = NULL;
339 if ($row_table_def['Type'] == 'datetime'
340 && (!isset($row_table_def['Default']))
341 && (!is_null($row_table_def['Default']))) {
342 // INSERT case
343 if ($insert_mode) {
344 if (isset($vrow)) {
345 $vrow[$rowfield] = date('Y-m-d H:i:s', time());
346 } else {
347 $vrow = array($rowfield => date('Y-m-d H:i:s', time()));
350 // UPDATE case with an empty and not NULL value under PHP4
351 else if (empty($vrow[$rowfield]) && is_null($vrow[$rowfield])) {
352 $vrow[$rowfield] = date('Y-m-d H:i:s', time());
353 } // end if... else if...
355 $len = (preg_match('@float|double@', $row_table_def['Type']))
356 ? 100
357 : PMA_DBI_field_len($vresult, $i);
358 $first_timestamp = 0;
360 $field_name = htmlspecialchars($field);
361 if (isset($comments_map[$field])) {
362 $field_name = '<span style="border-bottom: 1px dashed black;" title="' . htmlspecialchars($comments_map[$field]) . '">' . $field_name . '</span>';
365 $bgcolor = ($i % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
367 <tr>
368 <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($row_table_def['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center" bgcolor="<?php echo $bgcolor; ?>"><?php echo $field_name; ?></td>
369 <?php
370 echo "\n";
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" bgcolor="<?php echo $bgcolor; ?>"<?php echo $type_nowrap; ?>>
401 <?php echo $type; ?>
402 </td>
403 <?php
404 echo "\n";
406 // Prepares the field value
407 $real_null_value = FALSE;
408 if (isset($vrow)) {
409 if (!isset($vrow[$rowfield])
410 || (function_exists('is_null') && is_null($vrow[$rowfield]))) {
411 $real_null_value = TRUE;
412 $vrow[$rowfield] = '';
413 $special_chars = '';
414 $data = $vrow[$rowfield];
415 } else {
416 // loic1: special binary "characters"
417 if ($is_binary || $is_blob) {
418 $vrow[$rowfield] = str_replace("\x00", '\0', $vrow[$rowfield]);
419 $vrow[$rowfield] = str_replace("\x08", '\b', $vrow[$rowfield]);
420 $vrow[$rowfield] = str_replace("\x0a", '\n', $vrow[$rowfield]);
421 $vrow[$rowfield] = str_replace("\x0d", '\r', $vrow[$rowfield]);
422 $vrow[$rowfield] = str_replace("\x1a", '\Z', $vrow[$rowfield]);
423 } // end if
424 $special_chars = htmlspecialchars($vrow[$rowfield]);
425 $data = $vrow[$rowfield];
426 } // end if... else...
427 // loic1: if a timestamp field value is not included in an update
428 // statement MySQL auto-update it to the current timestamp
429 $backup_field = ($row_table_def['True_Type'] == 'timestamp')
430 ? ''
431 : '<input type="hidden" name="fields_prev' . $vkey . '[' . urlencode($field) . ']" value="' . urlencode($vrow[$rowfield]) . '" />';
432 } else {
433 // loic1: display default values
434 if (!isset($row_table_def['Default'])) {
435 $row_table_def['Default'] = '';
436 $real_null_value = TRUE;
437 $data = '';
438 } else {
439 $data = $row_table_def['Default'];
441 $special_chars = htmlspecialchars($row_table_def['Default']);
442 $backup_field = '';
445 $idindex = ($o_rows * $fields_cnt) + $i + 1;
446 $tabindex = (($idindex - 1) * 3) + 1;
448 // The function column
449 // -------------------
450 // Change by Bernard M. Piller <bernard@bmpsystems.com>
451 // We don't want binary data to be destroyed
452 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
453 // stored or retrieved" so it does not mean that the contents is
454 // binary
455 if ($cfg['ShowFunctionFields']) {
456 if (($cfg['ProtectBinary'] && $is_blob && !$is_upload)
457 || ($cfg['ProtectBinary'] == 'all' && $is_binary)) {
458 echo ' <td align="center" bgcolor="'. $bgcolor . '">' . $strBinary . '</td>' . "\n";
459 } else if (strstr($row_table_def['True_Type'], 'enum') || strstr($row_table_def['True_Type'], 'set')) {
460 echo ' <td align="center" bgcolor="'. $bgcolor . '">--</td>' . "\n";
461 } else {
463 <td bgcolor="<?php echo $bgcolor; ?>">
464 <select name="funcs<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $jsvkey; ?>')" tabindex="<?php echo ($tabindex + $tabindex_for_function); ?>" id="field_<?php echo $idindex; ?>_1">
465 <option></option>
466 <?php
467 echo "\n";
468 $selected = '';
470 // garvin: Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
471 // or something similar. Then directly look up the entry in the RestrictFunctions array,
472 // which will then reveal the available dropdown options
473 if (isset($cfg['RestrictFunctions']) && isset($cfg['RestrictColumnTypes']) && isset($cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])]) && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])]])) {
474 $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])];
475 $dropdown = $cfg['RestrictFunctions'][$current_func_type];
476 $default_function = $cfg['DefaultFunctions'][$current_func_type];
477 } else {
478 $dropdown = array();
479 $default_function = '';
482 $dropdown_built = array();
483 $op_spacing_needed = FALSE;
484 // garvin: loop on the dropdown array and print all available options for that field.
485 $cnt_dropdown = count($dropdown);
486 for ($j = 0; $j < $cnt_dropdown; $j++) {
487 // Is current function defined as default?
488 // For MySQL < 4.1.2, for the first timestamp we set as
489 // default function the one defined in config (which
490 // should be NOW() ).
491 // For MySQL >= 4.1.2, we don't set the default function
492 // if there is a default value for the timestamp
493 // (not including CURRENT_TIMESTAMP)
494 // and the column does not have the
495 // ON UPDATE DEFAULT TIMESTAMP attribute.
497 if (PMA_MYSQL_INT_VERSION < 40102
498 || (PMA_MYSQL_INT_VERSION >= 40102
499 && !($row_table_def['True_Type'] == 'timestamp' && !empty($row_table_def['Default']) && !isset($analyzed_sql[0]['create_table_fields'][$field]['on_update_current_timestamp'])))) {
500 $selected = ($first_timestamp && $dropdown[$j] == $cfg['DefaultFunctions']['first_timestamp'])
501 || (!$first_timestamp && $dropdown[$j] == $default_function)
502 ? ' selected="selected"'
503 : '';
505 echo ' ';
506 echo '<option' . $selected . '>' . $dropdown[$j] . '</option>' . "\n";
507 $dropdown_built[$dropdown[$j]] = 'TRUE';
508 $op_spacing_needed = TRUE;
511 // garvin: For compatibility's sake, do not let out all other functions. Instead
512 // print a separator (blank) and then show ALL functions which weren't shown
513 // yet.
514 $cnt_functions = count($cfg['Functions']);
515 for ($j = 0; $j < $cnt_functions; $j++) {
516 if (!isset($dropdown_built[$cfg['Functions'][$j]]) || $dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
517 // Is current function defined as default?
518 $selected = ($first_timestamp && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
519 || (!$first_timestamp && $cfg['Functions'][$j] == $default_function)
520 ? ' selected="selected"'
521 : '';
522 if ($op_spacing_needed == TRUE) {
523 echo ' ';
524 echo '<option value="">--------</option>' . "\n";
525 $op_spacing_needed = FALSE;
528 echo ' ';
529 echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
531 } // end for
532 unset($selected);
534 </select>
535 </td>
536 <?php
538 } // end if ($cfg['ShowFunctionFields'])
539 echo "\n";
541 // The null column
542 // ---------------
543 echo ' <td bgcolor="' . $bgcolor . '">' . "\n";
544 if (!(($cfg['ProtectBinary'] && $is_blob) || ($cfg['ProtectBinary'] == 'all' && $is_binary))
545 && $row_table_def['Null'] == 'YES') {
546 echo ' <input type="checkbox" tabindex="' . ($tabindex + $tabindex_for_null) . '"'
547 . ' name="fields_null' . $vkey . '[' . urlencode($field) . ']"';
548 if ($real_null_value && !$first_timestamp) {
549 echo ' checked="checked"';
551 echo ' id="field_' . ($idindex) . '_2"';
552 $onclick = ' onclick="if (this.checked) {nullify(';
553 if (strstr($row_table_def['True_Type'], 'enum')) {
554 if (strlen($row_table_def['Type']) > 20) {
555 $onclick .= '1, ';
556 } else {
557 $onclick .= '2, ';
559 } else if (strstr($row_table_def['True_Type'], 'set')) {
560 $onclick .= '3, ';
561 } else if ($foreigners && isset($foreigners[$field])) {
562 $onclick .= '4, ';
563 } else {
564 $onclick .= '5, ';
566 $onclick .= '\'' . urlencode($field) . '\', \'' . md5($field) . '\', \'' . $vkey . '\'); this.checked = true}; return true" />' . "\n";
567 echo $onclick;
568 } else {
569 echo ' &nbsp;' . "\n";
571 echo ' </td>' . "\n";
573 // The value column (depends on type)
574 // ----------------
576 require('./libraries/get_foreign.lib.php');
578 if (isset($foreign_link) && $foreign_link == true) {
580 <td bgcolor="<?php echo $bgcolor; ?>">
581 <?php echo $backup_field . "\n"; ?>
582 <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="foreign" />
583 <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="" id="field_<?php echo ($idindex); ?>_1" />
584 <input type="text" name="field_<?php echo md5($field); ?><?php echo $vkey; ?>[]" class="textfield" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $jsvkey; ?>')" tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>" id="field_<?php echo ($idindex); ?>_3" value="<?php echo htmlspecialchars($data); ?>" />
585 <script type="text/javascript" language="javascript">
586 document.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes,resizable=yes\'); return false" href="browse_foreigners.php?<?php echo PMA_generate_common_url($db, $table); ?>&amp;field=<?php echo urlencode($field) . $browse_foreigners_uri; ?>"><?php echo str_replace("'", "\'", $titles['Browse']); ?></a>');
587 </script>
588 </td>
589 <?php
590 } else if (isset($disp_row) && is_array($disp_row)) {
592 <td bgcolor="<?php echo $bgcolor; ?>">
593 <?php echo $backup_field . "\n"; ?>
594 <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="foreign" />
595 <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="" id="field_<?php echo $idindex; ?>_1" />
596 <select name="field_<?php echo md5($field); ?><?php echo $vkey; ?>[]" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $jsvkey; ?>')" tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>" id="field_<?php echo ($idindex); ?>_3">
597 <?php echo PMA_foreignDropdown($disp_row, $foreign_field, $foreign_display, $data, $cfg['ForeignKeyMaxLimit']); ?>
598 </select>
599 </td>
600 <?php
601 unset($disp_row);
603 else if ($cfg['LongtextDoubleTextarea'] && strstr($type, 'longtext')) {
605 <td bgcolor="<?php echo $bgcolor; ?>">&nbsp;</td>
606 </tr>
607 <tr>
608 <td colspan="4" align="right" bgcolor="<?php echo $bgcolor; ?>">
609 <?php echo $backup_field . "\n"; ?>
610 <textarea name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" rows="<?php echo ($cfg['TextareaRows']*2); ?>" cols="<?php echo ($cfg['TextareaCols']*2); ?>" dir="<?php echo $text_dir; ?>" id="field_<?php echo ($idindex); ?>_3"
611 <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $jsvkey; ?>')" tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"><?php echo $special_chars; ?></textarea>
612 </td>
613 <?php
615 else if (strstr($type, 'text')) {
617 <td bgcolor="<?php echo $bgcolor; ?>">
618 <?php echo $backup_field . "\n"; ?>
619 <textarea name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" rows="<?php echo $cfg['TextareaRows']; ?>" cols="<?php echo $cfg['TextareaCols']; ?>" dir="<?php echo $text_dir; ?>" id="field_<?php echo ($idindex); ?>_3"
620 <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $jsvkey; ?>')" tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"><?php echo $special_chars; ?></textarea>
621 </td>
622 <?php
623 echo "\n";
624 if (strlen($special_chars) > 32000) {
625 echo ' <td bgcolor="' . $bgcolor . '">' . $strTextAreaLength . '</td>' . "\n";
628 else if ($type == 'enum') {
629 $enum = PMA_getEnumSetOptions($row_table_def['Type']);
630 $enum_cnt = count($enum);
632 <td bgcolor="<?php echo $bgcolor; ?>">
633 <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="enum" />
634 <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="" />
635 <?php
636 echo "\n" . ' ' . $backup_field;
638 // show dropdown or radio depend on length
639 if (strlen($row_table_def['Type']) > 20) {
640 echo "\n";
642 <select name="field_<?php echo md5($field); ?><?php echo $vkey; ?>[]" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $jsvkey; ?>')" tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>" id="field_<?php echo ($idindex); ?>_3">
643 <option value=""></option>
644 <?php
645 echo "\n";
647 for ($j = 0; $j < $enum_cnt; $j++) {
648 // Removes automatic MySQL escape format
649 $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
650 echo ' ';
651 //echo '<option value="' . htmlspecialchars($enum_atom) . '"';
652 echo '<option value="' . urlencode($enum_atom) . '"';
653 if ($data == $enum_atom
654 || ($data == '' && (!isset($primary_key) || $row_table_def['Null'] != 'YES')
655 && isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
656 echo ' selected="selected"';
658 echo '>' . htmlspecialchars($enum_atom) . '</option>' . "\n";
659 } // end for
662 </select>
663 <?php
664 } // end if
665 else {
666 echo "\n";
667 for ($j = 0; $j < $enum_cnt; $j++) {
668 // Removes automatic MySQL escape format
669 $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
670 echo ' ';
671 echo '<input type="radio" name="field_' . md5($field) . $vkey . '[]" value="' . urlencode($enum_atom) . '" id="field_' . ($idindex) . '_3_' . $j . '" onclick="if (typeof(document.forms[\'insertForm\'].elements[\'fields_null' . str_replace('"', '\"', $vkey) . '[' . urlencode($field) . ']\']) != \'undefined\') {document.forms[\'insertForm\'].elements[\'fields_null' . str_replace('"', '\"', $vkey) . '[' . urlencode($field) .']\'].checked = false}"';
672 if ($data == $enum_atom
673 || ($data == '' && (!isset($primary_key) || $row_table_def['Null'] != 'YES')
674 && isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
675 echo ' checked="checked"';
677 echo 'tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
678 echo '<label for="field_' . $idindex . '_3_' . $j . '">' . htmlspecialchars($enum_atom) . '</label>' . "\n";
679 } // end for
681 } // end else
682 echo "\n";
684 </td>
685 <?php
686 echo "\n";
688 else if ($type == 'set') {
689 $set = PMA_getEnumSetOptions($row_table_def['Type']);
691 if (isset($vset)) {
692 unset($vset);
694 for ($vals = explode(',', $data); list($t, $k) = each($vals);) {
695 $vset[$k] = 1;
697 $countset = count($set);
698 $size = min(4, $countset);
700 <td bgcolor="<?php echo $bgcolor; ?>">
701 <?php echo $backup_field . "\n"; ?>
702 <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="set" />
703 <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="" />
704 <select name="field_<?php echo md5($field); ?><?php echo $vkey; ?>[]" size="<?php echo $size; ?>" multiple="multiple" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $jsvkey; ?>')" tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>" id="field_<?php echo ($idindex); ?>_3">
705 <?php
706 echo "\n";
707 for ($j = 0; $j < $countset; $j++) {
708 echo ' ';
709 //echo '<option value="'. htmlspecialchars($set[$j]) . '"';
710 echo '<option value="'. urlencode($set[$j]) . '"';
711 if (isset($vset[$set[$j]]) && $vset[$set[$j]]) {
712 echo ' selected="selected"';
714 echo '>' . htmlspecialchars($set[$j]) . '</option>' . "\n";
715 } // end for
717 </select>
718 </td>
719 <?php
721 // Change by Bernard M. Piller <bernard@bmpsystems.com>
722 // We don't want binary data destroyed
723 else if ($is_binary || $is_blob) {
724 if (($cfg['ProtectBinary'] && $is_blob)
725 || ($cfg['ProtectBinary'] == 'all' && $is_binary)) {
726 echo "\n";
728 <td bgcolor="<?php echo $bgcolor; ?>">
729 <?php
730 echo $strBinaryDoNotEdit;
731 if (isset($data)) {
732 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
733 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
734 unset($data_size);
736 echo "\n";
738 <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="protected" />
739 <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="" />
740 <?php
741 } else if ($is_blob) {
742 echo "\n";
744 <td bgcolor="<?php echo $bgcolor; ?>">
745 <?php echo $backup_field . "\n"; ?>
746 <textarea name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" rows="<?php echo $cfg['TextareaRows']; ?>" cols="<?php echo $cfg['TextareaCols']; ?>" dir="<?php echo $text_dir; ?>" id="field_<?php echo ($idindex); ?>_3"
747 <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $jsvkey; ?>')" tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>" ><?php echo $special_chars; ?></textarea>
748 <?php
750 } else {
751 if ($len < 4) {
752 $fieldsize = $maxlength = 4;
753 } else {
754 $fieldsize = (($len > 40) ? 40 : $len);
755 $maxlength = $len;
757 echo "\n";
759 <td bgcolor="<?php echo $bgcolor; ?>">
760 <?php echo $backup_field . "\n"; ?>
761 <input type="text" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>" maxlength="<?php echo $maxlength; ?>" class="textfield" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $jsvkey; ?>')" tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>" id="field_<?php echo ($idindex); ?>_3" />
762 <?php
763 } // end if...elseif...else
765 // Upload choice (only for BLOBs because the binary
766 // attribute does not imply binary contents)
767 // (displayed whatever value the ProtectBinary has)
769 if ($is_upload && $is_blob) {
770 echo '<br />';
771 echo '<input type="file" name="fields_upload_' . urlencode($field) . $vkey . '" class="textfield" id="field_' . ($idindex) . '_3" size="10" />&nbsp;';
773 // find maximum upload size, based on field type
774 // FIXME: with functions this is not so easy, as you can basically process any data with function like MD5
775 $max_field_sizes = array(
776 'tinyblob' => '256',
777 'blob' => '65536',
778 'mediumblob' => '16777216',
779 'longblob' => '4294967296'); // yeah, really
781 $this_field_max_size = $max_upload_size; // from PHP max
782 if ($this_field_max_size > $max_field_sizes[$type]) {
783 $this_field_max_size = $max_field_sizes[$type];
785 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
786 // do not generate here the MAX_FILE_SIZE, because we should
787 // put only one in the form to accommodate the biggest field
788 if ($this_field_max_size > $biggest_max_file_size) {
789 $biggest_max_file_size = $this_field_max_size;
793 if (!empty($cfg['UploadDir'])) {
794 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
795 if ($files === FALSE) {
796 echo ' <font color="red">' . $strError . '</font><br />' . "\n";
797 echo ' ' . $strWebServerUploadDirectoryError . "\n";
798 } elseif (!empty($files)) {
799 echo "<br />\n";
800 echo ' <i>' . $strOr . '</i>' . ' ' . $strWebServerUploadDirectory . ':<br />' . "\n";
801 echo ' <select size="1" name="fields_uploadlocal_' . urlencode($field) . $vkey . '">' . "\n";
802 echo ' <option value="" selected="selected"></option>' . "\n";
803 echo $files;
804 echo ' </select>' . "\n";
806 } // end if (web-server upload directory)
808 echo '</td>';
810 } // end else if ( binary or blob)
811 else {
812 // For char or varchar, respect the maximum length (M); for other
813 // types (int or float), the length is not a limit on the values that
814 // can be entered, so let's be generous (20) (we could also use the
815 // real limits for each numeric type)
816 // 2004-04-07, it turned out that 20 was not generous enough
817 // for the maxlength
818 if ($is_char) {
819 $fieldsize = (($len > 40) ? 40 : $len);
820 $maxlength = $len;
822 else {
823 $fieldsize = 20;
824 $maxlength = 99;
825 } // end if... else...
826 echo "\n";
828 <td bgcolor="<?php echo $bgcolor; ?>">
829 <?php echo $backup_field . "\n"; ?>
830 <?php
831 if ($is_char && isset($cfg['CharEditing']) && ($cfg['CharEditing'] == 'textarea')) {
832 echo "\n";
834 <textarea name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" rows="<?php echo $cfg['CharTextareaRows']; ?>" cols="<?php echo $cfg['CharTextareaCols']; ?>" dir="<?php echo $text_dir; ?>" id="field_<?php echo ($idindex); ?>_3"
835 <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $jsvkey; ?>')" tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>" ><?php echo $special_chars; ?></textarea>
836 <?php
837 } else {
838 echo "\n";
840 <input type="text" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>" maxlength="<?php echo $maxlength; ?>" class="textfield" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $jsvkey; ?>')" tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>" id="field_<?php echo ($idindex); ?>_3" />
841 <?php
842 if ($row_table_def['Extra'] == 'auto_increment') {
844 <input type="hidden" name="auto_increment<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="1" />
845 <?php
846 } // end if
847 if ($type == 'date' || $type == 'datetime' || substr($type, 0, 9) == 'timestamp') {
849 <script type="text/javascript">
850 <!--
851 document.write('<a title="<?php echo $strCalendar;?>" 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); ?>\')"><img class="calendar" src="<?php echo $pmaThemeImage; ?>b_calendar.png" alt="<?php echo $strCalendar; ?>"/></a>');
852 //-->
853 </script>
854 <?php
857 echo "\n";
859 </td>
860 <?php
862 echo "\n";
864 </tr>
865 <?php
866 echo "\n";
867 } // end for
868 $o_rows++;
869 echo ' </table><br />';
870 } // end foreach on multi-edit
872 <br />
874 <table border="0" cellpadding="5" cellspacing="0">
875 <tr>
876 <td valign="middle" nowrap="nowrap">
877 <select name="submit_type">
878 <?php
879 if (isset($primary_key)) {
881 <option value="<?php echo $strSave; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 1); ?>"><?php echo $strSave; ?></option>
882 <?php
885 <option value="<?php echo $strInsertAsNewRow; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 2); ?>"><?php echo $strInsertAsNewRow; ?></option>
886 </select>
887 <?php
888 echo "\n";
890 // Defines whether "insert another new row" should be
891 // selected or not (keep this choice sticky)
892 if (!empty($disp_message)) {
893 $selected_after_insert_new_insert = ' selected="selected"';
894 $selected_after_insert_back = '';
895 } else {
896 $selected_after_insert_back = ' selected="selected"';
897 $selected_after_insert_new_insert = '';
900 </td>
901 <td valign="middle">
902 &nbsp;&nbsp;&nbsp;<b><?php echo $strAndThen; ?></b>&nbsp;&nbsp;&nbsp;
903 </td>
904 <td valign="middle" nowrap="nowrap">
905 <select name="after_insert">
906 <option value="back" <?php echo $selected_after_insert_back; ?>><?php echo $strAfterInsertBack; ?></option>
907 <option value="new_insert" <?php echo $selected_after_insert_new_insert; ?>><?php echo $strAfterInsertNewInsert; ?></option>
908 <?php
909 if (isset($primary_key))
911 <option value="same_insert"><?php echo $strAfterInsertSame; ?></option>
912 <?php
913 // If we have just numeric primary key, we can also edit next
914 if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $primary_key)) {
916 <option value="edit_next"><?php echo $strAfterInsertNext; ?></option>
917 <?php
921 </select>
922 </td>
923 </tr>
925 <tr>
926 <td>
927 <?php echo PMA_showHint($strUseTabKey); ?>
928 </td>
929 <td colspan="3" align="right" valign="middle">
930 <input type="submit" value="<?php echo $strGo; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 6); ?>" id="buttonYes" />
931 <input type="reset" value="<?php echo $strReset; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 7); ?>" />
932 </td>
933 </tr>
934 </table>
935 <?php if ($biggest_max_file_size > 0) {
936 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
937 } ?>
939 </form>
942 <?php
944 * Displays the footer
946 echo "\n";
947 require_once('./footer.inc.php');