translation update
[phpmyadmin/crack.git] / tbl_change.php
blob9550b6423964fb4b32e37ea2f13c62e8dc3179f5
1 <?php
2 /**
3 * vim: expandtab sw=4 ts=4 sts=4:
4 * @version $Id$
5 */
7 /**
8 * Gets the variables sent or posted to this script and displays the header
9 */
10 require_once './libraries/common.lib.php';
12 /**
13 * Sets global variables.
14 * Here it's better to use a if, instead of the '?' operator
15 * to avoid setting a variable to '' when it's not present in $_REQUEST
17 if (isset($_REQUEST['pos'])) {
18 $pos = $_REQUEST['pos'];
20 if (isset($_REQUEST['session_max_rows'])) {
21 $session_max_rows = $_REQUEST['session_max_rows'];
23 if (isset($_REQUEST['disp_direction'])) {
24 $disp_direction = $_REQUEST['disp_direction'];
26 if (isset($_REQUEST['repeat_cells'])) {
27 $repeat_cells = $_REQUEST['repeat_cells'];
29 if (isset($_REQUEST['dontlimitchars'])) {
30 $dontlimitchars = $_REQUEST['dontlimitchars'];
32 if (isset($_REQUEST['primary_key'])) {
33 $primary_key = $_REQUEST['primary_key'];
35 if (isset($_REQUEST['sql_query'])) {
36 $sql_query = $_REQUEST['sql_query'];
38 if (isset($_REQUEST['ShowFunctionFields'])) {
39 $cfg['ShowFunctionFields'] = $_REQUEST['ShowFunctionFields'];
43 $js_to_run = 'tbl_change.js';
44 require_once './libraries/header.inc.php';
45 require_once './libraries/relation.lib.php'; // foreign keys
46 require_once './libraries/file_listing.php'; // file listing
49 /**
50 * Displays the query submitted and its result
52 if (! empty($disp_message)) {
53 if (! isset($disp_query)) {
54 $disp_query = null;
56 PMA_showMessage($disp_message, $disp_query);
60 /**
61 * Defines the url to return to in case of error in a sql statement
62 * (at this point, $goto might be set but empty)
64 if (empty($goto)) {
65 $goto = 'db_sql.php';
67 /**
68 * @todo check if we could replace by "db_|tbl_"
70 if (!preg_match('@^(db|tbl)_@', $goto)) {
71 $err_url = $goto . "?" . PMA_generate_common_url($db) . "&amp;sql_query=" . urlencode($sql_query);
72 } else {
73 $err_url = $goto . '?'
74 . PMA_generate_common_url($db)
75 . ((preg_match('@^(tbl_)@', $goto)) ? '&amp;table=' . urlencode($table) : '');
79 /**
80 * Ensures db and table are valid, else moves to the "parent" script
82 require_once './libraries/db_table_exists.lib.php';
85 /**
86 * Sets parameters for links
88 $url_query = PMA_generate_common_url($db, $table)
89 . '&amp;goto=tbl_sql.php';
91 require_once './libraries/tbl_info.inc.php';
93 /* Get comments */
95 $comments_map = array();
97 if ($GLOBALS['cfg']['ShowPropertyComments']) {
98 require_once './libraries/relation.lib.php';
99 require_once './libraries/transformations.lib.php';
101 $cfgRelation = PMA_getRelationsParam();
103 if ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) {
104 $comments_map = PMA_getComments($db, $table);
109 * Displays top menu links
111 require_once './libraries/tbl_links.inc.php';
115 * Get the analysis of SHOW CREATE TABLE for this table
117 $show_create_table = PMA_DBI_fetch_value(
118 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
119 0, 1 );
120 $analyzed_sql = PMA_SQP_analyze( PMA_SQP_parse( $show_create_table ) );
121 unset($show_create_table);
124 * Get the list of the fields of the current table
126 PMA_DBI_select_db($db);
127 $table_def = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
128 if (isset($primary_key)) {
129 if (is_array($primary_key)) {
130 $primary_key_array = $primary_key;
131 } else {
132 $primary_key_array = array(0 => $primary_key);
135 $row = array();
136 $result = array();
137 foreach ($primary_key_array as $rowcount => $primary_key) {
138 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';';
139 $result[$rowcount] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE);
140 $row[$rowcount] = PMA_DBI_fetch_assoc($result[$rowcount]);
141 $primary_keys[$rowcount] = $primary_key;
143 // No row returned
144 if (!$row[$rowcount]) {
145 unset($row[$rowcount], $primary_key_array[$rowcount]);
146 PMA_showMessage($strEmptyResultSet, $local_query);
147 echo "\n";
148 require_once './libraries/footer.inc.php';
149 } // end if (no record returned)
151 } else {
152 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
153 unset($row);
156 // <markus@noga.de>
157 // retrieve keys into foreign fields, if any
158 $cfgRelation = PMA_getRelationsParam();
159 $foreigners = ($cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : FALSE);
163 * Displays the form
165 // loic1: autocomplete feature of IE kills the "onchange" event handler and it
166 // must be replaced by the "onpropertychange" one in this case
167 $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5)
168 ? 'onpropertychange'
169 : 'onchange';
170 // Had to put the URI because when hosted on an https server,
171 // some browsers send wrongly this form to the http server.
174 <?php if ($cfg['CtrlArrowsMoving']) { ?>
175 <!-- Set on key handler for moving using by Ctrl+arrows -->
176 <script src="./js/keyhandler.js" type="text/javascript" language="javascript"></script>
177 <script type="text/javascript" language="javascript">
178 //<![CDATA[
179 var switch_movement = 0;
180 document.onkeydown = onKeyDownArrowsHandler;
181 //]]>
182 </script>
183 <?php } ?>
185 <!-- Change table properties form -->
186 <form method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?>>
187 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
188 <input type="hidden" name="goto" value="<?php echo htmlspecialchars($goto); ?>" />
189 <input type="hidden" name="pos" value="<?php echo isset($pos) ? $pos : 0; ?>" />
190 <input type="hidden" name="session_max_rows" value="<?php echo isset($session_max_rows) ? $session_max_rows : ''; ?>" />
191 <input type="hidden" name="disp_direction" value="<?php echo isset($disp_direction) ? $disp_direction : ''; ?>" />
192 <input type="hidden" name="repeat_cells" value="<?php echo isset($repeat_cells) ? $repeat_cells : ''; ?>" />
193 <input type="hidden" name="dontlimitchars" value="<?php echo (isset($dontlimitchars) ? $dontlimitchars : 0); ?>" />
194 <input type="hidden" name="err_url" value="<?php echo htmlspecialchars($err_url); ?>" />
195 <input type="hidden" name="sql_query" value="<?php echo isset($sql_query) ? htmlspecialchars($sql_query) : ''; ?>" />
196 <?php
197 if (isset($primary_key_array)) {
198 foreach ($primary_key_array as $primary_key) {
200 <input type="hidden" name="primary_key[]" value="<?php echo htmlspecialchars(trim($primary_key)); ?>" />
201 <?php
204 echo "\n";
206 if ($cfg['PropertiesIconic'] == true) {
207 // We need to copy the value or else the == 'both' check will always return true
208 $propicon = (string)$cfg['PropertiesIconic'];
210 if ($propicon == 'both') {
211 $iconic_spacer = '<div class="nowrap">';
212 } else {
213 $iconic_spacer = '';
216 $titles['Browse'] = $iconic_spacer . '<img width="16" height="16" src="' . $pmaThemeImage . 'b_browse.png" alt="' . $strBrowseForeignValues . '" title="' . $strBrowseForeignValues . '" border="0" />';
218 if ($propicon == 'both') {
219 $titles['Browse'] .= '&nbsp;' . $strBrowseForeignValues . '</div>';
221 } else {
222 $titles['Browse'] = $strBrowseForeignValues;
225 // Set if we passed the first timestamp field
226 $timestamp_seen = 0;
227 $fields_cnt = PMA_DBI_num_rows($table_def);
229 // Set a flag here because the 'if' would not be valid in the loop
230 // if we set a value in some field
231 $insert_mode = (!isset($row) ? TRUE : FALSE);
232 if ($insert_mode) {
233 $loop_array = array();
234 for ($i = 0; $i < $cfg['InsertRows']; $i++) {
235 $loop_array[] = FALSE;
237 } else {
238 $loop_array = $row;
241 while ($trow = PMA_DBI_fetch_assoc($table_def)) {
242 $trow_table_def[] = $trow;
245 $tabindex = 0;
246 $tabindex_for_function = +1000;
247 $tabindex_for_null = +2000;
248 $tabindex_for_value = 0;
249 $o_rows = 0;
250 $biggest_max_file_size = 0;
252 // user can toggle the display of Function column
253 // (currently does not work for multi-edits)
254 $url_params['db'] = $db;
255 $url_params['table'] = $table;
256 if (isset($primary_key)) {
257 $url_params['primary_key'] = trim($primary_key);
259 if (isset($sql_query)) {
260 $url_params['sql_query'] = $sql_query;
263 if (! $cfg['ShowFunctionFields']) {
264 $this_url_params = array_merge($url_params,
265 array('ShowFunctionFields' => 1));
266 echo $strShow . ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . $strFunction . '</a>' . "\n";
269 foreach ($loop_array as $vrowcount => $vrow) {
270 if ($vrow === FALSE) {
271 unset($vrow);
274 if ($insert_mode) {
275 $jsvkey = $vrowcount;
276 $browse_foreigners_uri = '&amp;pk=' . $vrowcount;
277 } else {
278 $jsvkey = htmlspecialchars(trim($primary_keys[$vrowcount]));
279 $browse_foreigners_uri = '&amp;pk=' . urlencode(trim($primary_keys[$vrowcount]));
281 $vkey = '[multi_edit][' . $jsvkey . ']';
283 $vresult = (isset($result) && is_array($result) && isset($result[$vrowcount]) ? $result[$vrowcount] : $result);
284 if ($insert_mode && $vrowcount > 0) {
285 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $vrowcount . '" id="insert_ignore_check_' . $vrowcount . '" />';
286 echo '<label for="insert_ignore_check_' . $vrowcount . '">' . $strIgnore . '</label><br />' . "\n";
289 <table>
290 <tr>
291 <th><?php echo $strField; ?></th>
292 <th><?php echo $strType; ?></th>
293 <?php
294 if ($cfg['ShowFunctionFields']) {
295 $this_url_params = array_merge($url_params,
296 array('ShowFunctionFields' => 0));
297 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . $strHide . '">' . $strFunction . '</a></th>' . "\n";
300 <th><?php echo $strNull; ?></th>
301 <th><?php echo $strValue; ?></th>
302 </tr>
303 <?php
305 // garvin: For looping on multiple rows, we need to reset any variable used inside the loop to indicate sth.
306 $timestamp_seen = 0;
307 unset($first_timestamp);
309 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
310 $m_rows = $o_rows + 1;
312 $odd_row = true;
313 for ($i = 0; $i < $fields_cnt; $i++) {
314 // Display the submit button after every 15 lines --swix
315 // (wanted to use an <a href="#bottom"> and <a name> instead,
316 // but it didn't worked because of the <base href>)
318 if ((($o_rows * $fields_cnt + $i) % 15 == 0) && ($i + $o_rows != 0)) {
320 <tr>
321 <th colspan="5" align="right" class="tblFooters">
322 <input type="submit" value="<?php echo $strGo; ?>" />&nbsp;
323 </th>
324 </tr>
325 <?php
326 } // end if
327 echo "\n";
329 $row_table_def = $trow_table_def[$i];
330 $row_table_def['True_Type'] = preg_replace('@\(.*@s', '', $row_table_def['Type']);
332 $field = $row_table_def['Field'];
333 $field_html = $field;
335 // removed previous PHP3-workaround that caused a problem with
336 // field names like '000'
337 $rowfield = $field;
339 // d a t e t i m e
341 // loic1: current date should not be set as default if the field is NULL
342 // for the current row
343 // lem9: but do not put here the current datetime if there is a default
344 // value (the real default value will be set in the
345 // Default value logic below)
347 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
348 // $row_table_def['Default'] is not set if it contains NULL:
349 // Array ( [Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime )
350 // but, look what we get if we switch to iso: (Default is NULL)
351 // Array ( [Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime )
352 // so I force a NULL into it (I don't think it's possible
353 // to have an empty default value for DATETIME)
354 // then, the "if" after this one will work
355 if ($row_table_def['Type'] == 'datetime'
356 && !isset($row_table_def['Default'])
357 && isset($row_table_def['Null'])
358 && $row_table_def['Null'] == 'YES') {
359 $row_table_def['Default'] = null;
362 if ($row_table_def['Type'] == 'datetime'
363 && (!isset($row_table_def['Default']))
364 && (!is_null($row_table_def['Default']))) {
365 // INSERT case
366 if ($insert_mode) {
367 if (isset($vrow)) {
368 $vrow[$rowfield] = date('Y-m-d H:i:s', time());
369 } else {
370 $vrow = array($rowfield => date('Y-m-d H:i:s', time()));
373 // UPDATE case with an empty and not NULL value under PHP4
374 elseif (empty($vrow[$rowfield]) && is_null($vrow[$rowfield])) {
375 $vrow[$rowfield] = date('Y-m-d H:i:s', time());
376 } // end if... elseif...
378 $len = (preg_match('@float|double@', $row_table_def['Type']))
379 ? 100
380 : PMA_DBI_field_len($vresult, $i);
381 $first_timestamp = 0;
383 $field_name = $field_html;
384 if (isset($comments_map[$field])) {
385 $field_name = '<span style="border-bottom: 1px dashed black;" title="' . htmlspecialchars($comments_map[$field]) . '">' . $field_name . '</span>';
389 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
390 <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($row_table_def['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center"><?php echo $field_name; ?></td>
392 <?php
393 // The type column
394 $is_binary = stristr($row_table_def['Type'], 'binary');
395 $is_blob = stristr($row_table_def['Type'], 'blob');
396 $is_char = stristr($row_table_def['Type'], 'char');
397 switch ($row_table_def['True_Type']) {
398 case 'set':
399 $type = 'set';
400 $type_nowrap = '';
401 break;
402 case 'enum':
403 $type = 'enum';
404 $type_nowrap = '';
405 break;
406 case 'timestamp':
407 if (!$timestamp_seen) { // can only occur once per table
408 $timestamp_seen = 1;
409 $first_timestamp = 1;
411 $type = $row_table_def['Type'];
412 $type_nowrap = ' nowrap="nowrap"';
413 break;
415 default:
416 $type = $row_table_def['Type'];
417 $type_nowrap = ' nowrap="nowrap"';
418 break;
421 <td align="center"<?php echo $type_nowrap; ?>>
422 <?php echo $type; ?>
423 </td>
425 <?php
427 // Prepares the field value
428 $real_null_value = FALSE;
429 if (isset($vrow)) {
430 if (!isset($vrow[$rowfield])
431 || (function_exists('is_null') && is_null($vrow[$rowfield]))) {
432 $real_null_value = TRUE;
433 $vrow[$rowfield] = '';
434 $special_chars = '';
435 $data = $vrow[$rowfield];
436 } else {
437 // loic1: special binary "characters"
438 if ($is_binary || $is_blob) {
439 $vrow[$rowfield] = str_replace("\x00", '\0', $vrow[$rowfield]);
440 $vrow[$rowfield] = str_replace("\x08", '\b', $vrow[$rowfield]);
441 $vrow[$rowfield] = str_replace("\x0a", '\n', $vrow[$rowfield]);
442 $vrow[$rowfield] = str_replace("\x0d", '\r', $vrow[$rowfield]);
443 $vrow[$rowfield] = str_replace("\x1a", '\Z', $vrow[$rowfield]);
444 } // end if
445 $special_chars = htmlspecialchars($vrow[$rowfield]);
446 $data = $vrow[$rowfield];
447 } // end if... else...
448 // loic1: if a timestamp field value is not included in an update
449 // statement MySQL auto-update it to the current timestamp
450 // lem9: however, things have changed since MySQL 4.1, so
451 // it's better to set a fields_prev in this situation
452 $backup_field = (PMA_MYSQL_INT_VERSION < 40100 && $row_table_def['True_Type'] == 'timestamp')
453 ? ''
454 : '<input type="hidden" name="fields_prev' . $vkey . '[' . $field_html . ']" value="' . htmlspecialchars($vrow[$rowfield]) . '" />';
455 } else {
456 // loic1: display default values
457 if (!isset($row_table_def['Default'])) {
458 $row_table_def['Default'] = '';
459 $real_null_value = TRUE;
460 $data = '';
461 } else {
462 $data = $row_table_def['Default'];
464 $special_chars = htmlspecialchars($row_table_def['Default']);
465 $backup_field = '';
468 $idindex = ($o_rows * $fields_cnt) + $i + 1;
469 $tabindex = (($idindex - 1) * 3) + 1;
471 // The function column
472 // -------------------
473 // Change by Bernard M. Piller <bernard@bmpsystems.com>
474 // We don't want binary data to be destroyed
475 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
476 // stored or retrieved" so it does not mean that the contents is
477 // binary
478 if ($cfg['ShowFunctionFields']) {
479 if (($cfg['ProtectBinary'] && $is_blob && !$is_upload)
480 || ($cfg['ProtectBinary'] == 'all' && $is_binary)) {
481 echo ' <td align="center">' . $strBinary . '</td>' . "\n";
482 } elseif (strstr($row_table_def['True_Type'], 'enum') || strstr($row_table_def['True_Type'], 'set')) {
483 echo ' <td align="center">--</td>' . "\n";
484 } else {
486 <td>
487 <select name="funcs<?php echo $vkey; ?>[<?php echo $field_html; ?>]" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo $field_html; ?>', '<?php echo $jsvkey; ?>')" tabindex="<?php echo ($tabindex + $tabindex_for_function); ?>" id="field_<?php echo $idindex; ?>_1">
488 <option></option>
489 <?php
490 $selected = '';
492 // garvin: Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
493 // or something similar. Then directly look up the entry in the RestrictFunctions array,
494 // which will then reveal the available dropdown options
495 if (isset($cfg['RestrictFunctions']) && isset($cfg['RestrictColumnTypes']) && isset($cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])]) && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])]])) {
496 $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])];
497 $dropdown = $cfg['RestrictFunctions'][$current_func_type];
498 $default_function = $cfg['DefaultFunctions'][$current_func_type];
499 } else {
500 $dropdown = array();
501 $default_function = '';
504 $dropdown_built = array();
505 $op_spacing_needed = FALSE;
506 // garvin: loop on the dropdown array and print all available options for that field.
507 $cnt_dropdown = count($dropdown);
508 for ($j = 0; $j < $cnt_dropdown; $j++) {
509 // Is current function defined as default?
510 // For MySQL < 4.1.2, for the first timestamp we set as
511 // default function the one defined in config (which
512 // should be NOW() ).
513 // For MySQL >= 4.1.2, we don't set the default function
514 // if there is a default value for the timestamp
515 // (not including CURRENT_TIMESTAMP)
516 // and the column does not have the
517 // ON UPDATE DEFAULT TIMESTAMP attribute.
519 if (PMA_MYSQL_INT_VERSION < 40102
520 || (PMA_MYSQL_INT_VERSION >= 40102
521 && !($row_table_def['True_Type'] == 'timestamp' && !empty($row_table_def['Default']) && !isset($analyzed_sql[0]['create_table_fields'][$field]['on_update_current_timestamp'])))) {
522 $selected = ($first_timestamp && $dropdown[$j] == $cfg['DefaultFunctions']['first_timestamp'])
523 || (!$first_timestamp && $dropdown[$j] == $default_function)
524 ? ' selected="selected"'
525 : '';
527 echo ' ';
528 echo '<option' . $selected . '>' . $dropdown[$j] . '</option>' . "\n";
529 $dropdown_built[$dropdown[$j]] = 'TRUE';
530 $op_spacing_needed = TRUE;
533 // garvin: For compatibility's sake, do not let out all other functions. Instead
534 // print a separator (blank) and then show ALL functions which weren't shown
535 // yet.
536 $cnt_functions = count($cfg['Functions']);
537 for ($j = 0; $j < $cnt_functions; $j++) {
538 if (!isset($dropdown_built[$cfg['Functions'][$j]]) || $dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
539 // Is current function defined as default?
540 $selected = ($first_timestamp && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
541 || (!$first_timestamp && $cfg['Functions'][$j] == $default_function)
542 ? ' selected="selected"'
543 : '';
544 if ($op_spacing_needed == TRUE) {
545 echo ' ';
546 echo '<option value="">--------</option>' . "\n";
547 $op_spacing_needed = FALSE;
550 echo ' ';
551 echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
553 } // end for
554 unset($selected);
556 </select>
557 </td>
558 <?php
560 } // end if ($cfg['ShowFunctionFields'])
563 // The null column
564 // ---------------
565 echo ' <td>' . "\n";
566 if ($row_table_def['Null'] == 'YES') {
567 echo ' <input type="hidden" name="fields_null_prev' . $vkey . '[' . $field_html . ']"';
568 if ($real_null_value && !$first_timestamp) {
569 echo ' value="on"';
571 echo ' />' . "\n";
573 if (!(($cfg['ProtectBinary'] && $is_blob) || ($cfg['ProtectBinary'] == 'all' && $is_binary)) ) {
575 echo ' <input type="checkbox" tabindex="' . ($tabindex + $tabindex_for_null) . '"'
576 . ' name="fields_null' . $vkey . '[' . $field_html . ']"';
577 if ($real_null_value && !$first_timestamp) {
578 echo ' checked="checked"';
580 echo ' id="field_' . ($idindex) . '_2"';
581 $onclick = ' onclick="if (this.checked) {nullify(';
582 if (strstr($row_table_def['True_Type'], 'enum')) {
583 if (strlen($row_table_def['Type']) > 20) {
584 $onclick .= '1, ';
585 } else {
586 $onclick .= '2, ';
588 } elseif (strstr($row_table_def['True_Type'], 'set')) {
589 $onclick .= '3, ';
590 } elseif ($foreigners && isset($foreigners[$field])) {
591 $onclick .= '4, ';
592 } else {
593 $onclick .= '5, ';
595 $onclick .= '\'' . $field_html . '\', \'' . md5($field) . '\', \'' . $vkey . '\'); this.checked = true}; return true" />' . "\n";
596 echo $onclick;
597 } else {
598 echo ' <input type="hidden" name="fields_null' . $vkey . '[' . $field_html . ']"';
599 if ($real_null_value && !$first_timestamp) {
600 echo ' value="on"';
602 echo ' />' . "\n";
605 echo ' </td>' . "\n";
607 // The value column (depends on type)
608 // ----------------
610 require './libraries/get_foreign.lib.php';
612 if (isset($foreign_link) && $foreign_link == true) {
614 <td>
615 <?php echo $backup_field . "\n"; ?>
616 <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo $field_html; ?>]" value="foreign" />
617 <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo $field_html; ?>]" value="" id="field_<?php echo ($idindex); ?>_1" />
618 <input type="text" name="field_<?php echo md5($field); ?><?php echo $vkey; ?>[]" class="textfield" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo $field_html; ?>', '<?php echo $jsvkey; ?>')" tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>" id="field_<?php echo ($idindex); ?>_3" value="<?php echo htmlspecialchars($data); ?>" />
619 <script type="text/javascript" language="javascript">
620 //<![CDATA[
621 document.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes,resizable=yes\'); return false"');
622 document.writeln(' href="browse_foreigners.php?');
623 document.writeln('<?php echo PMA_generate_common_url($db, $table); ?>');
624 document.writeln('&amp;field=<?php echo urlencode($field) . $browse_foreigners_uri; ?>">');
625 document.writeln('<?php echo str_replace("'", "\'", $titles['Browse']); ?></a>');
626 //]]>
627 </script>
628 </td>
629 <?php
630 } elseif (isset($disp_row) && is_array($disp_row)) {
632 <td>
633 <?php echo $backup_field . "\n"; ?>
634 <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo $field_html; ?>]" value="foreign" />
635 <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo $field_html; ?>]" value="" id="field_<?php echo $idindex; ?>_1" />
636 <select name="field_<?php echo md5($field); ?><?php echo $vkey; ?>[]" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo $field_html; ?>', '<?php echo $jsvkey; ?>')" tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>" id="field_<?php echo ($idindex); ?>_3">
637 <?php echo PMA_foreignDropdown($disp_row, $foreign_field, $foreign_display, $data, $cfg['ForeignKeyMaxLimit']); ?>
638 </select>
639 </td>
640 <?php
641 unset($disp_row);
642 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($type, 'longtext')) {
644 <td>&nbsp;</td>
645 </tr>
646 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
647 <td colspan="5" align="right">
648 <?php echo $backup_field . "\n"; ?>
649 <textarea name="fields<?php echo $vkey; ?>[<?php echo $field_html; ?>]" rows="<?php echo ($cfg['TextareaRows']*2); ?>" cols="<?php echo ($cfg['TextareaCols']*2); ?>" dir="<?php echo $text_dir; ?>" id="field_<?php echo ($idindex); ?>_3"
650 <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo $field_html; ?>', '<?php echo $jsvkey; ?>')" tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"><?php echo $special_chars; ?></textarea>
651 </td>
652 <?php
653 } elseif (strstr($type, 'text')) {
655 <td>
656 <?php echo $backup_field . "\n"; ?>
657 <textarea name="fields<?php echo $vkey; ?>[<?php echo $field_html; ?>]" rows="<?php echo $cfg['TextareaRows']; ?>" cols="<?php echo $cfg['TextareaCols']; ?>" dir="<?php echo $text_dir; ?>" id="field_<?php echo ($idindex); ?>_3"
658 <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo $field_html; ?>', '<?php echo $jsvkey; ?>')" tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"><?php echo $special_chars; ?></textarea>
659 </td>
660 <?php
661 echo "\n";
662 if (strlen($special_chars) > 32000) {
663 echo ' <td>' . $strTextAreaLength . '</td>' . "\n";
665 } elseif ($type == 'enum') {
666 $enum = PMA_getEnumSetOptions($row_table_def['Type']);
667 $enum_cnt = count($enum);
669 <td>
670 <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo $field_html; ?>]" value="enum" />
671 <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo $field_html; ?>]" value="" />
672 <?php
673 echo "\n" . ' ' . $backup_field;
675 // show dropdown or radio depend on length
676 if (strlen($row_table_def['Type']) > 20) {
677 echo "\n";
679 <select name="field_<?php echo md5($field); ?><?php echo $vkey; ?>[]" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo $field_html; ?>', '<?php echo $jsvkey; ?>')" tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>" id="field_<?php echo ($idindex); ?>_3">
680 <option value=""></option>
681 <?php
682 echo "\n";
684 for ($j = 0; $j < $enum_cnt; $j++) {
685 // Removes automatic MySQL escape format
686 $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
687 echo ' ';
688 //echo '<option value="' . htmlspecialchars($enum_atom) . '"';
689 echo '<option value="' . htmlspecialchars($enum_atom) . '"';
690 if ($data == $enum_atom
691 || ($data == '' && (!isset($primary_key) || $row_table_def['Null'] != 'YES')
692 && isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
693 echo ' selected="selected"';
695 echo '>' . htmlspecialchars($enum_atom) . '</option>' . "\n";
696 } // end for
699 </select>
700 <?php
701 } else {
702 echo "\n";
703 for ($j = 0; $j < $enum_cnt; $j++) {
704 // Removes automatic MySQL escape format
705 $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
706 echo ' ';
707 echo '<input type="radio" name="field_' . md5($field) . $vkey . '[]" value="' . htmlspecialchars($enum_atom) . '" id="field_' . ($idindex) . '_3_' . $j . '" onclick="if (typeof(document.forms[\'insertForm\'].elements[\'fields_null' . str_replace('"', '\"', $vkey) . '[' . $field_html . ']\']) != \'undefined\') {document.forms[\'insertForm\'].elements[\'fields_null' . str_replace('"', '\"', $vkey) . '[' . $field_html .']\'].checked = false}"';
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 ' checked="checked"';
713 echo 'tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
714 echo '<label for="field_' . $idindex . '_3_' . $j . '">' . htmlspecialchars($enum_atom) . '</label>' . "\n";
715 } // end for
717 } // end else
718 echo "\n";
720 </td>
721 <?php
722 echo "\n";
723 } elseif ($type == 'set') {
724 $set = PMA_getEnumSetOptions($row_table_def['Type']);
726 if (isset($vset)) {
727 unset($vset);
729 for ($vals = explode(',', $data); list($t, $k) = each($vals);) {
730 $vset[$k] = 1;
732 $countset = count($set);
733 $size = min(4, $countset);
735 <td>
736 <?php echo $backup_field . "\n"; ?>
737 <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo $field_html; ?>]" value="set" />
738 <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo $field_html; ?>]" value="" />
739 <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 $field_html; ?>', '<?php echo $jsvkey; ?>')" tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>" id="field_<?php echo ($idindex); ?>_3">
740 <?php
741 echo "\n";
742 for ($j = 0; $j < $countset; $j++) {
743 echo ' ';
744 //echo '<option value="'. htmlspecialchars($set[$j]) . '"';
745 echo '<option value="'. htmlspecialchars($set[$j]) . '"';
746 if (isset($vset[$set[$j]]) && $vset[$set[$j]]) {
747 echo ' selected="selected"';
749 echo '>' . htmlspecialchars($set[$j]) . '</option>' . "\n";
750 } // end for
752 </select>
753 </td>
754 <?php
756 // Change by Bernard M. Piller <bernard@bmpsystems.com>
757 // We don't want binary data destroyed
758 elseif ($is_binary || $is_blob) {
759 if (($cfg['ProtectBinary'] && $is_blob)
760 || ($cfg['ProtectBinary'] == 'all' && $is_binary)) {
761 echo "\n";
763 <td>
764 <?php
765 echo $strBinaryDoNotEdit;
766 if (isset($data)) {
767 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
768 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
769 unset($data_size);
771 echo "\n";
773 <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo $field_html; ?>]" value="protected" />
774 <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo $field_html; ?>]" value="" />
775 <?php
776 } elseif ($is_blob) {
777 echo "\n";
779 <td>
780 <?php echo $backup_field . "\n"; ?>
781 <textarea name="fields<?php echo $vkey; ?>[<?php echo $field_html; ?>]" rows="<?php echo $cfg['TextareaRows']; ?>" cols="<?php echo $cfg['TextareaCols']; ?>" dir="<?php echo $text_dir; ?>" id="field_<?php echo ($idindex); ?>_3"
782 <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo $field_html; ?>', '<?php echo $jsvkey; ?>')" tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>" ><?php echo $special_chars; ?></textarea>
783 <?php
785 } else {
786 if ($len < 4) {
787 $fieldsize = $maxlength = 4;
788 } else {
789 $fieldsize = (($len > 40) ? 40 : $len);
790 $maxlength = $len;
792 echo "\n";
794 <td>
795 <?php echo $backup_field . "\n"; ?>
796 <input type="text" name="fields<?php echo $vkey; ?>[<?php echo $field_html; ?>]" value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>" maxlength="<?php echo $maxlength; ?>" class="textfield" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo $field_html; ?>', '<?php echo $jsvkey; ?>')" tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>" id="field_<?php echo ($idindex); ?>_3" />
797 <?php
798 } // end if...elseif...else
800 // Upload choice (only for BLOBs because the binary
801 // attribute does not imply binary contents)
802 // (displayed whatever value the ProtectBinary has)
804 if ($is_upload && $is_blob) {
805 echo '<br />';
806 echo '<input type="file" name="fields_upload_' . $field_html . $vkey . '" class="textfield" id="field_' . ($idindex) . '_3" size="10" />&nbsp;';
808 // find maximum upload size, based on field type
810 * @todo with functions this is not so easy, as you can basically
811 * process any data with function like MD5
813 $max_field_sizes = array(
814 'tinyblob' => '256',
815 'blob' => '65536',
816 'mediumblob' => '16777216',
817 'longblob' => '4294967296'); // yeah, really
819 $this_field_max_size = $max_upload_size; // from PHP max
820 if ($this_field_max_size > $max_field_sizes[$type]) {
821 $this_field_max_size = $max_field_sizes[$type];
823 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
824 // do not generate here the MAX_FILE_SIZE, because we should
825 // put only one in the form to accommodate the biggest field
826 if ($this_field_max_size > $biggest_max_file_size) {
827 $biggest_max_file_size = $this_field_max_size;
831 if (!empty($cfg['UploadDir'])) {
832 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
833 if ($files === FALSE) {
834 echo ' <font color="red">' . $strError . '</font><br />' . "\n";
835 echo ' ' . $strWebServerUploadDirectoryError . "\n";
836 } elseif (!empty($files)) {
837 echo "<br />\n";
838 echo ' <i>' . $strOr . '</i>' . ' ' . $strWebServerUploadDirectory . ':<br />' . "\n";
839 echo ' <select size="1" name="fields_uploadlocal_' . $field_html . $vkey . '">' . "\n";
840 echo ' <option value="" selected="selected"></option>' . "\n";
841 echo $files;
842 echo ' </select>' . "\n";
844 } // end if (web-server upload directory)
846 echo '</td>';
848 } // end elseif ( binary or blob)
849 else {
850 // For char or varchar, respect the maximum length (M); for other
851 // types (int or float), the length is not a limit on the values that
852 // can be entered, so let's be generous (20) (we could also use the
853 // real limits for each numeric type)
854 // 2004-04-07, it turned out that 20 was not generous enough
855 // for the maxlength
856 if ($is_char) {
857 $fieldsize = (($len > 40) ? 40 : $len);
858 $maxlength = $len;
859 } else {
860 $fieldsize = 20;
861 $maxlength = 99;
862 } // end if... else...
864 <td>
865 <?php
866 echo $backup_field . "\n";
867 if ($is_char && ($cfg['CharEditing'] == 'textarea' || strpos($data, "\n") !== FALSE)) {
868 echo "\n";
870 <textarea name="fields<?php echo $vkey; ?>[<?php echo $field_html; ?>]" rows="<?php echo $cfg['CharTextareaRows']; ?>" cols="<?php echo $cfg['CharTextareaCols']; ?>" dir="<?php echo $text_dir; ?>" id="field_<?php echo ($idindex); ?>_3"
871 <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo $field_html; ?>', '<?php echo $jsvkey; ?>')" tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>" ><?php echo $special_chars; ?></textarea>
872 <?php
873 } else {
875 <input type="text" name="fields<?php echo $vkey; ?>[<?php echo $field_html; ?>]" value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>" maxlength="<?php echo $maxlength; ?>" class="textfield" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo $field_html; ?>', '<?php echo $jsvkey; ?>')" tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>" id="field_<?php echo ($idindex); ?>_3" />
876 <?php
877 if ($row_table_def['Extra'] == 'auto_increment') {
879 <input type="hidden" name="auto_increment<?php echo $vkey; ?>[<?php echo $field_html; ?>]" value="1" />
880 <?php
881 } // end if
882 if (substr($type, 0, 9) == 'timestamp') {
884 <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo $field_html; ?>]" value="timestamp" />
885 <?php
887 if ($type == 'date' || $type == 'datetime' || substr($type, 0, 9) == 'timestamp') {
889 <script type="text/javascript" language="javascript">
890 //<![CDATA[
891 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>');
892 //]]>
893 </script>
894 <?php
898 </td>
899 <?php
902 </tr>
903 <?php
904 $odd_row = !$odd_row;
905 } // end for
906 $o_rows++;
907 echo ' </table><br />';
908 } // end foreach on multi-edit
910 <br />
912 <table border="0" cellpadding="5" cellspacing="0">
913 <tr>
914 <td valign="middle" nowrap="nowrap">
915 <select name="submit_type" tabindex="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
916 <?php
917 if (isset($primary_key)) {
919 <option value="<?php echo $strSave; ?>"><?php echo $strSave; ?></option>
920 <?php
923 <option value="<?php echo $strInsertAsNewRow; ?>"><?php echo $strInsertAsNewRow; ?></option>
924 </select>
925 <?php
926 echo "\n";
928 if (!isset($after_insert)) {
929 $after_insert = 'back';
932 </td>
933 <td valign="middle">
934 &nbsp;&nbsp;&nbsp;<b><?php echo $strAndThen; ?></b>&nbsp;&nbsp;&nbsp;
935 </td>
936 <td valign="middle" nowrap="nowrap">
937 <select name="after_insert">
938 <option value="back" <?php echo ($after_insert == 'back' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertBack; ?></option>
939 <option value="new_insert" <?php echo ($after_insert == 'new_insert' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertNewInsert; ?></option>
940 <?php
941 if (isset($primary_key)) {
943 <option value="same_insert" <?php echo ($after_insert == 'same_insert' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertSame; ?></option>
944 <?php
945 // If we have just numeric primary key, we can also edit next
946 // in 2.8.2, we were looking for `field_name` = numeric_value
947 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $primary_key)) {
948 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
949 if (preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $primary_key)) {
951 <option value="edit_next"><?php echo $strAfterInsertNext; ?></option>
952 <?php
956 </select>
957 </td>
958 </tr>
960 <tr>
961 <td>
962 <?php echo PMA_showHint($strUseTabKey); ?>
963 </td>
964 <td colspan="3" align="right" valign="middle">
965 <input type="submit" value="<?php echo $strGo; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 6); ?>" id="buttonYes" />
966 <input type="reset" value="<?php echo $strReset; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 7); ?>" />
967 </td>
968 </tr>
969 </table>
970 <?php if ($biggest_max_file_size > 0) {
971 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
972 } ?>
974 </form>
976 <?php
978 * Displays the footer
980 require_once './libraries/footer.inc.php';