Define headers which to trust in configuration, thanks for help with this to Christia...
[phpmyadmin/crack.git] / tbl_change.php
blob7e71da6e6fef3520125ab9cf5d04d599ed54481a
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 /**
6 * Gets the variables sent or posted to this script and displays the header
7 */
8 require_once './libraries/common.lib.php';
10 /**
11 * Sets global variables.
12 * Here it's better to use a if, instead of the '?' operator
13 * to avoid setting a variable to '' when it's not present in $_REQUEST
15 if (isset($_REQUEST['pos'])) {
16 $pos = $_REQUEST['pos'];
18 if (isset($_REQUEST['session_max_rows'])) {
19 $session_max_rows = $_REQUEST['session_max_rows'];
21 if (isset($_REQUEST['disp_direction'])) {
22 $disp_direction = $_REQUEST['disp_direction'];
24 if (isset($_REQUEST['repeat_cells'])) {
25 $repeat_cells = $_REQUEST['repeat_cells'];
27 if (isset($_REQUEST['dontlimitchars'])) {
28 $dontlimitchars = $_REQUEST['dontlimitchars'];
30 if (isset($_REQUEST['primary_key'])) {
31 $primary_key = $_REQUEST['primary_key'];
33 if (isset($_REQUEST['sql_query'])) {
34 $sql_query = $_REQUEST['sql_query'];
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($goto)) {
49 $goto_cpy = $goto;
50 $goto = 'tbl_sql.php?'
51 . PMA_generate_common_url($db, $table)
52 . '&amp;$show_query=1'
53 . '&amp;sql_query=' . (isset($disp_query) ? urlencode($disp_query) : '');
54 } else {
55 $show_query = '1';
57 if (isset($sql_query)) {
58 $sql_query_cpy = $sql_query;
59 unset($sql_query);
61 if (isset($disp_query)) {
62 $sql_query = $disp_query;
64 PMA_showMessage($disp_message);
65 if (isset($goto_cpy)) {
66 $goto = $goto_cpy;
67 unset($goto_cpy);
69 if (isset($sql_query_cpy)) {
70 $sql_query = $sql_query_cpy;
71 unset($sql_query_cpy);
76 /**
77 * Defines the url to return to in case of error in a sql statement
78 * (at this point, $goto might be set but empty)
80 if (empty($goto)) {
81 $goto = 'db_sql.php';
83 /**
84 * @todo check if we could replace by "db_|tbl_"
86 if (!preg_match('@^(db|tbl)_@', $goto)) {
87 $err_url = $goto . "?" . PMA_generate_common_url($db) . "&amp;sql_query=" . urlencode($sql_query);
88 } else {
89 $err_url = $goto . '?'
90 . PMA_generate_common_url($db)
91 . ((preg_match('@^(tbl_)@', $goto)) ? '&amp;table=' . urlencode($table) : '');
95 /**
96 * Ensures db and table are valid, else moves to the "parent" script
98 require_once './libraries/db_table_exists.lib.php';
102 * Sets parameters for links
104 $url_query = PMA_generate_common_url($db, $table)
105 . '&amp;goto=tbl_sql.php';
107 require_once './libraries/tbl_info.inc.php';
109 /* Get comments */
111 $comments_map = array();
113 if ($GLOBALS['cfg']['ShowPropertyComments']) {
114 require_once './libraries/relation.lib.php';
115 require_once './libraries/transformations.lib.php';
117 $cfgRelation = PMA_getRelationsParam();
119 if ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) {
120 $comments_map = PMA_getComments($db, $table);
125 * Displays top menu links
127 require_once './libraries/tbl_links.inc.php';
131 * Get the analysis of SHOW CREATE TABLE for this table
133 $show_create_table = PMA_DBI_fetch_value(
134 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
135 0, 1 );
136 $analyzed_sql = PMA_SQP_analyze( PMA_SQP_parse( $show_create_table ) );
137 unset($show_create_table);
140 * Get the list of the fields of the current table
142 PMA_DBI_select_db($db);
143 $table_def = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
144 if (isset($primary_key)) {
145 if (is_array($primary_key)) {
146 $primary_key_array = $primary_key;
147 } else {
148 $primary_key_array = array(0 => $primary_key);
151 $row = array();
152 $result = array();
153 foreach ($primary_key_array AS $rowcount => $primary_key) {
154 $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';';
155 $result[$rowcount] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE);
156 $row[$rowcount] = PMA_DBI_fetch_assoc($result[$rowcount]);
157 $primary_keys[$rowcount] = $primary_key;
159 // No row returned
160 if (!$row[$rowcount]) {
161 unset($row[$rowcount]);
162 unset($primary_key_array[$rowcount]);
163 $goto_cpy = $goto;
164 $goto = 'tbl_sql.php?'
165 . PMA_generate_common_url($db, $table)
166 . '&amp;$show_query=1'
167 . '&amp;sql_query=' . urlencode($local_query);
168 if (isset($sql_query)) {
169 $sql_query_cpy = $sql_query;
170 unset($sql_query);
172 $sql_query = $local_query;
173 PMA_showMessage($strEmptyResultSet);
174 $goto = $goto_cpy;
175 unset($goto_cpy);
176 if (isset($sql_query_cpy)) {
177 $sql_query = $sql_query_cpy;
178 unset($sql_query_cpy);
180 echo "\n";
181 require_once './libraries/footer.inc.php';
182 } // end if (no record returned)
184 } else {
185 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
186 unset($row);
189 // <markus@noga.de>
190 // retrieve keys into foreign fields, if any
191 $cfgRelation = PMA_getRelationsParam();
192 $foreigners = ($cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : FALSE);
196 * Displays the form
198 // loic1: autocomplete feature of IE kills the "onchange" event handler and it
199 // must be replaced by the "onpropertychange" one in this case
200 $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5)
201 ? 'onpropertychange'
202 : 'onchange';
203 // Had to put the URI because when hosted on an https server,
204 // some browsers send wrongly this form to the http server.
207 <?php if ($cfg['CtrlArrowsMoving']) { ?>
208 <!-- Set on key handler for moving using by Ctrl+arrows -->
209 <script src="./js/keyhandler.js" type="text/javascript" language="javascript"></script>
210 <script type="text/javascript" language="javascript">
211 //<![CDATA[
212 var switch_movement = 0;
213 document.onkeydown = onKeyDownArrowsHandler;
214 //]]>
215 </script>
216 <?php } ?>
218 <!-- Change table properties form -->
219 <form method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?>>
220 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
221 <input type="hidden" name="goto" value="<?php echo urlencode($goto); ?>" />
222 <input type="hidden" name="pos" value="<?php echo isset($pos) ? $pos : 0; ?>" />
223 <input type="hidden" name="session_max_rows" value="<?php echo isset($session_max_rows) ? $session_max_rows : ''; ?>" />
224 <input type="hidden" name="disp_direction" value="<?php echo isset($disp_direction) ? $disp_direction : ''; ?>" />
225 <input type="hidden" name="repeat_cells" value="<?php echo isset($repeat_cells) ? $repeat_cells : ''; ?>" />
226 <input type="hidden" name="dontlimitchars" value="<?php echo (isset($dontlimitchars) ? $dontlimitchars : 0); ?>" />
227 <input type="hidden" name="err_url" value="<?php echo urlencode($err_url); ?>" />
228 <input type="hidden" name="sql_query" value="<?php echo isset($sql_query) ? urlencode($sql_query) : ''; ?>" />
229 <?php
230 if (isset($primary_key_array)) {
231 foreach ($primary_key_array AS $primary_key) {
233 <input type="hidden" name="primary_key[]" value="<?php echo urlencode($primary_key); ?>" />
234 <?php
237 echo "\n";
239 if ($cfg['PropertiesIconic'] == true) {
240 // We need to copy the value or else the == 'both' check will always return true
241 $propicon = (string)$cfg['PropertiesIconic'];
243 if ($propicon == 'both') {
244 $iconic_spacer = '<div class="nowrap">';
245 } else {
246 $iconic_spacer = '';
249 $titles['Browse'] = $iconic_spacer . '<img width="16" height="16" src="' . $pmaThemeImage . 'b_browse.png" alt="' . $strBrowseForeignValues . '" title="' . $strBrowseForeignValues . '" border="0" />';
251 if ($propicon == 'both') {
252 $titles['Browse'] .= '&nbsp;' . $strBrowseForeignValues . '</div>';
254 } else {
255 $titles['Browse'] = $strBrowseForeignValues;
258 // Set if we passed the first timestamp field
259 $timestamp_seen = 0;
260 $fields_cnt = PMA_DBI_num_rows($table_def);
262 // Set a flag here because the 'if' would not be valid in the loop
263 // if we set a value in some field
264 $insert_mode = (!isset($row) ? TRUE : FALSE);
265 if ($insert_mode) {
266 $loop_array = array();
267 for ($i = 0; $i < $cfg['InsertRows']; $i++) $loop_array[] = FALSE;
268 } else {
269 $loop_array = $row;
272 while ($trow = PMA_DBI_fetch_assoc($table_def)) {
273 $trow_table_def[] = $trow;
276 $tabindex = 0;
277 $tabindex_for_function = +1000;
278 $tabindex_for_null = +2000;
279 $tabindex_for_value = 0;
280 $o_rows = 0;
281 $biggest_max_file_size = 0;
282 foreach ($loop_array AS $vrowcount => $vrow) {
283 if ($vrow === FALSE) {
284 unset($vrow);
287 if ($insert_mode) {
288 $jsvkey = $vrowcount;
289 $browse_foreigners_uri = '&amp;pk=' . $vrowcount;
290 } else {
291 $jsvkey = urlencode($primary_keys[$vrowcount]);
292 $browse_foreigners_uri = '&amp;pk=' . urlencode($primary_keys[$vrowcount]);
294 $vkey = '[multi_edit][' . $jsvkey . ']';
296 $vresult = (isset($result) && is_array($result) && isset($result[$vrowcount]) ? $result[$vrowcount] : $result);
297 if ($insert_mode && $vrowcount > 0) {
298 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $vrowcount . '" id="insert_ignore_check_' . $vrowcount . '" />';
299 echo '<label for="insert_ignore_check_' . $vrowcount . '">' . $strIgnore . '</label><br />' . "\n";
302 <table>
303 <tr>
304 <th><?php echo $strField; ?></th>
305 <th><?php echo $strType; ?></th>
306 <?php
307 if ($cfg['ShowFunctionFields']) {
308 echo ' <th>' . $strFunction . '</th>' . "\n";
311 <th><?php echo $strNull; ?></th>
312 <th><?php echo $strValue; ?></th>
313 </tr>
314 <?php
316 // garvin: For looping on multiple rows, we need to reset any variable used inside the loop to indicate sth.
317 $timestamp_seen = 0;
318 unset($first_timestamp);
320 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
321 $m_rows = $o_rows + 1;
323 $odd_row = true;
324 for ($i = 0; $i < $fields_cnt; $i++) {
325 // Display the submit button after every 15 lines --swix
326 // (wanted to use an <a href="#bottom"> and <a name> instead,
327 // but it didn't worked because of the <base href>)
329 if ((($o_rows * $fields_cnt + $i) % 15 == 0) && ($i + $o_rows != 0)) {
331 <tr>
332 <th colspan="5" align="right" class="tblFooters">
333 <input type="submit" value="<?php echo $strGo; ?>" />&nbsp;
334 </th>
335 </tr>
336 <?php
337 } // end if
338 echo "\n";
340 $row_table_def = $trow_table_def[$i];
341 $row_table_def['True_Type'] = preg_replace('@\(.*@s', '', $row_table_def['Type']);
343 $field = $row_table_def['Field'];
345 // removed previous PHP3-workaround that caused a problem with
346 // field names like '000'
347 $rowfield = $field;
349 // d a t e t i m e
351 // loic1: current date should not be set as default if the field is NULL
352 // for the current row
353 // lem9: but do not put here the current datetime if there is a default
354 // value (the real default value will be set in the
355 // Default value logic below)
357 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
358 // $row_table_def['Default'] is not set if it contains NULL:
359 // Array ( [Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime )
360 // but, look what we get if we switch to iso: (Default is NULL)
361 // Array ( [Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime )
362 // so I force a NULL into it (I don't think it's possible
363 // to have an empty default value for DATETIME)
364 // then, the "if" after this one will work
365 if ($row_table_def['Type'] == 'datetime'
366 && !isset($row_table_def['Default'])
367 && isset($row_table_def['Null'])
368 && $row_table_def['Null'] == 'YES') {
369 $row_table_def['Default'] = null;
372 if ($row_table_def['Type'] == 'datetime'
373 && (!isset($row_table_def['Default']))
374 && (!is_null($row_table_def['Default']))) {
375 // INSERT case
376 if ($insert_mode) {
377 if (isset($vrow)) {
378 $vrow[$rowfield] = date('Y-m-d H:i:s', time());
379 } else {
380 $vrow = array($rowfield => date('Y-m-d H:i:s', time()));
383 // UPDATE case with an empty and not NULL value under PHP4
384 elseif (empty($vrow[$rowfield]) && is_null($vrow[$rowfield])) {
385 $vrow[$rowfield] = date('Y-m-d H:i:s', time());
386 } // end if... elseif...
388 $len = (preg_match('@float|double@', $row_table_def['Type']))
389 ? 100
390 : PMA_DBI_field_len($vresult, $i);
391 $first_timestamp = 0;
393 $field_name = htmlspecialchars($field);
394 if (isset($comments_map[$field])) {
395 $field_name = '<span style="border-bottom: 1px dashed black;" title="' . htmlspecialchars($comments_map[$field]) . '">' . $field_name . '</span>';
399 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
400 <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($row_table_def['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center"><?php echo $field_name; ?></td>
402 <?php
403 // The type column
404 $is_binary = stristr($row_table_def['Type'], ' binary');
405 $is_blob = stristr($row_table_def['Type'], 'blob');
406 $is_char = stristr($row_table_def['Type'], 'char');
407 switch ($row_table_def['True_Type']) {
408 case 'set':
409 $type = 'set';
410 $type_nowrap = '';
411 break;
412 case 'enum':
413 $type = 'enum';
414 $type_nowrap = '';
415 break;
416 case 'timestamp':
417 if (!$timestamp_seen) { // can only occur once per table
418 $timestamp_seen = 1;
419 $first_timestamp = 1;
421 $type = $row_table_def['Type'];
422 $type_nowrap = ' nowrap="nowrap"';
423 break;
425 default:
426 $type = $row_table_def['Type'];
427 $type_nowrap = ' nowrap="nowrap"';
428 break;
431 <td align="center"<?php echo $type_nowrap; ?>>
432 <?php echo $type; ?>
433 </td>
435 <?php
437 // Prepares the field value
438 $real_null_value = FALSE;
439 if (isset($vrow)) {
440 if (!isset($vrow[$rowfield])
441 || (function_exists('is_null') && is_null($vrow[$rowfield]))) {
442 $real_null_value = TRUE;
443 $vrow[$rowfield] = '';
444 $special_chars = '';
445 $data = $vrow[$rowfield];
446 } else {
447 // loic1: special binary "characters"
448 if ($is_binary || $is_blob) {
449 $vrow[$rowfield] = str_replace("\x00", '\0', $vrow[$rowfield]);
450 $vrow[$rowfield] = str_replace("\x08", '\b', $vrow[$rowfield]);
451 $vrow[$rowfield] = str_replace("\x0a", '\n', $vrow[$rowfield]);
452 $vrow[$rowfield] = str_replace("\x0d", '\r', $vrow[$rowfield]);
453 $vrow[$rowfield] = str_replace("\x1a", '\Z', $vrow[$rowfield]);
454 } // end if
455 $special_chars = htmlspecialchars($vrow[$rowfield]);
456 $data = $vrow[$rowfield];
457 } // end if... else...
458 // loic1: if a timestamp field value is not included in an update
459 // statement MySQL auto-update it to the current timestamp
460 // lem9: however, things have changed since MySQL 4.1, so
461 // it's better to set a fields_prev in this situation
462 $backup_field = (PMA_MYSQL_INT_VERSION < 40100 && $row_table_def['True_Type'] == 'timestamp')
463 ? ''
464 : '<input type="hidden" name="fields_prev' . $vkey . '[' . urlencode($field) . ']" value="' . urlencode($vrow[$rowfield]) . '" />';
465 } else {
466 // loic1: display default values
467 if (!isset($row_table_def['Default'])) {
468 $row_table_def['Default'] = '';
469 $real_null_value = TRUE;
470 $data = '';
471 } else {
472 $data = $row_table_def['Default'];
474 $special_chars = htmlspecialchars($row_table_def['Default']);
475 $backup_field = '';
478 $idindex = ($o_rows * $fields_cnt) + $i + 1;
479 $tabindex = (($idindex - 1) * 3) + 1;
481 // The function column
482 // -------------------
483 // Change by Bernard M. Piller <bernard@bmpsystems.com>
484 // We don't want binary data to be destroyed
485 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
486 // stored or retrieved" so it does not mean that the contents is
487 // binary
488 if ($cfg['ShowFunctionFields']) {
489 if (($cfg['ProtectBinary'] && $is_blob && !$is_upload)
490 || ($cfg['ProtectBinary'] == 'all' && $is_binary)) {
491 echo ' <td align="center">' . $strBinary . '</td>' . "\n";
492 } elseif (strstr($row_table_def['True_Type'], 'enum') || strstr($row_table_def['True_Type'], 'set')) {
493 echo ' <td align="center">--</td>' . "\n";
494 } else {
496 <td>
497 <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">
498 <option></option>
499 <?php
500 $selected = '';
502 // garvin: Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
503 // or something similar. Then directly look up the entry in the RestrictFunctions array,
504 // which will then reveal the available dropdown options
505 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'])]])) {
506 $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])];
507 $dropdown = $cfg['RestrictFunctions'][$current_func_type];
508 $default_function = $cfg['DefaultFunctions'][$current_func_type];
509 } else {
510 $dropdown = array();
511 $default_function = '';
514 $dropdown_built = array();
515 $op_spacing_needed = FALSE;
516 // garvin: loop on the dropdown array and print all available options for that field.
517 $cnt_dropdown = count($dropdown);
518 for ($j = 0; $j < $cnt_dropdown; $j++) {
519 // Is current function defined as default?
520 // For MySQL < 4.1.2, for the first timestamp we set as
521 // default function the one defined in config (which
522 // should be NOW() ).
523 // For MySQL >= 4.1.2, we don't set the default function
524 // if there is a default value for the timestamp
525 // (not including CURRENT_TIMESTAMP)
526 // and the column does not have the
527 // ON UPDATE DEFAULT TIMESTAMP attribute.
529 if (PMA_MYSQL_INT_VERSION < 40102
530 || (PMA_MYSQL_INT_VERSION >= 40102
531 && !($row_table_def['True_Type'] == 'timestamp' && !empty($row_table_def['Default']) && !isset($analyzed_sql[0]['create_table_fields'][$field]['on_update_current_timestamp'])))) {
532 $selected = ($first_timestamp && $dropdown[$j] == $cfg['DefaultFunctions']['first_timestamp'])
533 || (!$first_timestamp && $dropdown[$j] == $default_function)
534 ? ' selected="selected"'
535 : '';
537 echo ' ';
538 echo '<option' . $selected . '>' . $dropdown[$j] . '</option>' . "\n";
539 $dropdown_built[$dropdown[$j]] = 'TRUE';
540 $op_spacing_needed = TRUE;
543 // garvin: For compatibility's sake, do not let out all other functions. Instead
544 // print a separator (blank) and then show ALL functions which weren't shown
545 // yet.
546 $cnt_functions = count($cfg['Functions']);
547 for ($j = 0; $j < $cnt_functions; $j++) {
548 if (!isset($dropdown_built[$cfg['Functions'][$j]]) || $dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
549 // Is current function defined as default?
550 $selected = ($first_timestamp && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
551 || (!$first_timestamp && $cfg['Functions'][$j] == $default_function)
552 ? ' selected="selected"'
553 : '';
554 if ($op_spacing_needed == TRUE) {
555 echo ' ';
556 echo '<option value="">--------</option>' . "\n";
557 $op_spacing_needed = FALSE;
560 echo ' ';
561 echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
563 } // end for
564 unset($selected);
566 </select>
567 </td>
568 <?php
570 } // end if ($cfg['ShowFunctionFields'])
573 // The null column
574 // ---------------
575 echo ' <td>' . "\n";
576 if ($row_table_def['Null'] == 'YES') {
577 echo ' <input type="hidden" name="fields_null_prev' . $vkey . '[' . urlencode($field) . ']"';
578 if ($real_null_value && !$first_timestamp) {
579 echo ' value="on"';
581 echo ' />' . "\n";
583 if (!(($cfg['ProtectBinary'] && $is_blob) || ($cfg['ProtectBinary'] == 'all' && $is_binary)) ) {
585 echo ' <input type="checkbox" tabindex="' . ($tabindex + $tabindex_for_null) . '"'
586 . ' name="fields_null' . $vkey . '[' . urlencode($field) . ']"';
587 if ($real_null_value && !$first_timestamp) {
588 echo ' checked="checked"';
590 echo ' id="field_' . ($idindex) . '_2"';
591 $onclick = ' onclick="if (this.checked) {nullify(';
592 if (strstr($row_table_def['True_Type'], 'enum')) {
593 if (strlen($row_table_def['Type']) > 20) {
594 $onclick .= '1, ';
595 } else {
596 $onclick .= '2, ';
598 } elseif (strstr($row_table_def['True_Type'], 'set')) {
599 $onclick .= '3, ';
600 } elseif ($foreigners && isset($foreigners[$field])) {
601 $onclick .= '4, ';
602 } else {
603 $onclick .= '5, ';
605 $onclick .= '\'' . urlencode($field) . '\', \'' . md5($field) . '\', \'' . $vkey . '\'); this.checked = true}; return true" />' . "\n";
606 echo $onclick;
607 } else {
608 echo ' <input type="hidden" name="fields_null' . $vkey . '[' . urlencode($field) . ']"';
609 if ($real_null_value && !$first_timestamp) {
610 echo ' value="on"';
612 echo ' />' . "\n";
615 echo ' </td>' . "\n";
617 // The value column (depends on type)
618 // ----------------
620 require './libraries/get_foreign.lib.php';
622 if (isset($foreign_link) && $foreign_link == true) {
624 <td>
625 <?php echo $backup_field . "\n"; ?>
626 <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="foreign" />
627 <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="" id="field_<?php echo ($idindex); ?>_1" />
628 <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); ?>" />
629 <script type="text/javascript" language="javascript">
630 //<![CDATA[
631 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>');
632 //]]>
633 </script>
634 </td>
635 <?php
636 } elseif (isset($disp_row) && is_array($disp_row)) {
638 <td>
639 <?php echo $backup_field . "\n"; ?>
640 <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="foreign" />
641 <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="" id="field_<?php echo $idindex; ?>_1" />
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 <?php echo PMA_foreignDropdown($disp_row, $foreign_field, $foreign_display, $data, $cfg['ForeignKeyMaxLimit']); ?>
644 </select>
645 </td>
646 <?php
647 unset($disp_row);
648 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($type, 'longtext')) {
650 <td>&nbsp;</td>
651 </tr>
652 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
653 <td colspan="5" align="right">
654 <?php echo $backup_field . "\n"; ?>
655 <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"
656 <?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>
657 </td>
658 <?php
659 } elseif (strstr($type, 'text')) {
661 <td>
662 <?php echo $backup_field . "\n"; ?>
663 <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"
664 <?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>
665 </td>
666 <?php
667 echo "\n";
668 if (strlen($special_chars) > 32000) {
669 echo ' <td>' . $strTextAreaLength . '</td>' . "\n";
671 } elseif ($type == 'enum') {
672 $enum = PMA_getEnumSetOptions($row_table_def['Type']);
673 $enum_cnt = count($enum);
675 <td>
676 <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="enum" />
677 <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="" />
678 <?php
679 echo "\n" . ' ' . $backup_field;
681 // show dropdown or radio depend on length
682 if (strlen($row_table_def['Type']) > 20) {
683 echo "\n";
685 <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">
686 <option value=""></option>
687 <?php
688 echo "\n";
690 for ($j = 0; $j < $enum_cnt; $j++) {
691 // Removes automatic MySQL escape format
692 $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
693 echo ' ';
694 //echo '<option value="' . htmlspecialchars($enum_atom) . '"';
695 echo '<option value="' . urlencode($enum_atom) . '"';
696 if ($data == $enum_atom
697 || ($data == '' && (!isset($primary_key) || $row_table_def['Null'] != 'YES')
698 && isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
699 echo ' selected="selected"';
701 echo '>' . htmlspecialchars($enum_atom) . '</option>' . "\n";
702 } // end for
705 </select>
706 <?php
707 } else {
708 echo "\n";
709 for ($j = 0; $j < $enum_cnt; $j++) {
710 // Removes automatic MySQL escape format
711 $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
712 echo ' ';
713 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}"';
714 if ($data == $enum_atom
715 || ($data == '' && (!isset($primary_key) || $row_table_def['Null'] != 'YES')
716 && isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
717 echo ' checked="checked"';
719 echo 'tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
720 echo '<label for="field_' . $idindex . '_3_' . $j . '">' . htmlspecialchars($enum_atom) . '</label>' . "\n";
721 } // end for
723 } // end else
724 echo "\n";
726 </td>
727 <?php
728 echo "\n";
729 } elseif ($type == 'set') {
730 $set = PMA_getEnumSetOptions($row_table_def['Type']);
732 if (isset($vset)) {
733 unset($vset);
735 for ($vals = explode(',', $data); list($t, $k) = each($vals);) {
736 $vset[$k] = 1;
738 $countset = count($set);
739 $size = min(4, $countset);
741 <td>
742 <?php echo $backup_field . "\n"; ?>
743 <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="set" />
744 <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="" />
745 <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">
746 <?php
747 echo "\n";
748 for ($j = 0; $j < $countset; $j++) {
749 echo ' ';
750 //echo '<option value="'. htmlspecialchars($set[$j]) . '"';
751 echo '<option value="'. urlencode($set[$j]) . '"';
752 if (isset($vset[$set[$j]]) && $vset[$set[$j]]) {
753 echo ' selected="selected"';
755 echo '>' . htmlspecialchars($set[$j]) . '</option>' . "\n";
756 } // end for
758 </select>
759 </td>
760 <?php
762 // Change by Bernard M. Piller <bernard@bmpsystems.com>
763 // We don't want binary data destroyed
764 elseif ($is_binary || $is_blob) {
765 if (($cfg['ProtectBinary'] && $is_blob)
766 || ($cfg['ProtectBinary'] == 'all' && $is_binary)) {
767 echo "\n";
769 <td>
770 <?php
771 echo $strBinaryDoNotEdit;
772 if (isset($data)) {
773 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
774 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
775 unset($data_size);
777 echo "\n";
779 <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="protected" />
780 <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="" />
781 <?php
782 } elseif ($is_blob) {
783 echo "\n";
785 <td>
786 <?php echo $backup_field . "\n"; ?>
787 <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"
788 <?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>
789 <?php
791 } else {
792 if ($len < 4) {
793 $fieldsize = $maxlength = 4;
794 } else {
795 $fieldsize = (($len > 40) ? 40 : $len);
796 $maxlength = $len;
798 echo "\n";
800 <td>
801 <?php echo $backup_field . "\n"; ?>
802 <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" />
803 <?php
804 } // end if...elseif...else
806 // Upload choice (only for BLOBs because the binary
807 // attribute does not imply binary contents)
808 // (displayed whatever value the ProtectBinary has)
810 if ($is_upload && $is_blob) {
811 echo '<br />';
812 echo '<input type="file" name="fields_upload_' . urlencode($field) . $vkey . '" class="textfield" id="field_' . ($idindex) . '_3" size="10" />&nbsp;';
814 // find maximum upload size, based on field type
816 * @todo with functions this is not so easy, as you can basically
817 * process any data with function like MD5
819 $max_field_sizes = array(
820 'tinyblob' => '256',
821 'blob' => '65536',
822 'mediumblob' => '16777216',
823 'longblob' => '4294967296'); // yeah, really
825 $this_field_max_size = $max_upload_size; // from PHP max
826 if ($this_field_max_size > $max_field_sizes[$type]) {
827 $this_field_max_size = $max_field_sizes[$type];
829 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
830 // do not generate here the MAX_FILE_SIZE, because we should
831 // put only one in the form to accommodate the biggest field
832 if ($this_field_max_size > $biggest_max_file_size) {
833 $biggest_max_file_size = $this_field_max_size;
837 if (!empty($cfg['UploadDir'])) {
838 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
839 if ($files === FALSE) {
840 echo ' <font color="red">' . $strError . '</font><br />' . "\n";
841 echo ' ' . $strWebServerUploadDirectoryError . "\n";
842 } elseif (!empty($files)) {
843 echo "<br />\n";
844 echo ' <i>' . $strOr . '</i>' . ' ' . $strWebServerUploadDirectory . ':<br />' . "\n";
845 echo ' <select size="1" name="fields_uploadlocal_' . urlencode($field) . $vkey . '">' . "\n";
846 echo ' <option value="" selected="selected"></option>' . "\n";
847 echo $files;
848 echo ' </select>' . "\n";
850 } // end if (web-server upload directory)
852 echo '</td>';
854 } // end elseif ( binary or blob)
855 else {
856 // For char or varchar, respect the maximum length (M); for other
857 // types (int or float), the length is not a limit on the values that
858 // can be entered, so let's be generous (20) (we could also use the
859 // real limits for each numeric type)
860 // 2004-04-07, it turned out that 20 was not generous enough
861 // for the maxlength
862 if ($is_char) {
863 $fieldsize = (($len > 40) ? 40 : $len);
864 $maxlength = $len;
865 } else {
866 $fieldsize = 20;
867 $maxlength = 99;
868 } // end if... else...
870 <td>
871 <?php
872 echo $backup_field . "\n";
873 if ($is_char && ($cfg['CharEditing'] == 'textarea' || strpos($data, "\n") !== FALSE)) {
874 echo "\n";
876 <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"
877 <?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>
878 <?php
879 } else {
881 <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" />
882 <?php
883 if ($row_table_def['Extra'] == 'auto_increment') {
885 <input type="hidden" name="auto_increment<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="1" />
886 <?php
887 } // end if
888 if (substr($type, 0, 9) == 'timestamp') {
890 <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="timestamp" />
891 <?php
893 if ($type == 'date' || $type == 'datetime' || substr($type, 0, 9) == 'timestamp') {
895 <script type="text/javascript" language="javascript">
896 //<![CDATA[
897 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>');
898 //]]>
899 </script>
900 <?php
904 </td>
905 <?php
908 </tr>
909 <?php
910 $odd_row = !$odd_row;
911 } // end for
912 $o_rows++;
913 echo ' </table><br />';
914 } // end foreach on multi-edit
916 <br />
918 <table border="0" cellpadding="5" cellspacing="0">
919 <tr>
920 <td valign="middle" nowrap="nowrap">
921 <select name="submit_type" tabindex="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
922 <?php
923 if (isset($primary_key)) {
925 <option value="<?php echo $strSave; ?>"><?php echo $strSave; ?></option>
926 <?php
929 <option value="<?php echo $strInsertAsNewRow; ?>"><?php echo $strInsertAsNewRow; ?></option>
930 </select>
931 <?php
932 echo "\n";
934 if (!isset($after_insert)) {
935 $after_insert = 'back';
938 </td>
939 <td valign="middle">
940 &nbsp;&nbsp;&nbsp;<b><?php echo $strAndThen; ?></b>&nbsp;&nbsp;&nbsp;
941 </td>
942 <td valign="middle" nowrap="nowrap">
943 <select name="after_insert">
944 <option value="back" <?php echo ($after_insert == 'back' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertBack; ?></option>
945 <option value="new_insert" <?php echo ($after_insert == 'new_insert' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertNewInsert; ?></option>
946 <?php
947 if (isset($primary_key)) {
949 <option value="same_insert" <?php echo ($after_insert == 'same_insert' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertSame; ?></option>
950 <?php
951 // If we have just numeric primary key, we can also edit next
952 // in 2.8.2, we were looking for `field_name` = numeric_value
953 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $primary_key)) {
954 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
955 if (preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $primary_key)) {
957 <option value="edit_next"><?php echo $strAfterInsertNext; ?></option>
958 <?php
962 </select>
963 </td>
964 </tr>
966 <tr>
967 <td>
968 <?php echo PMA_showHint($strUseTabKey); ?>
969 </td>
970 <td colspan="3" align="right" valign="middle">
971 <input type="submit" value="<?php echo $strGo; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 6); ?>" id="buttonYes" />
972 <input type="reset" value="<?php echo $strReset; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 7); ?>" />
973 </td>
974 </tr>
975 </table>
976 <?php if ($biggest_max_file_size > 0) {
977 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
978 } ?>
980 </form>
982 <?php
984 * Displays the footer
986 require_once './libraries/footer.inc.php';