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