Chinese Simplified update
[phpmyadmin/crack.git] / tbl_change.php
blobb454bb6d071fcd3cb1684c42eabd15ee6202ad66
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Displays form for editing and inserting new table rows
6 * register_globals_save (mark this file save for disabling register globals)
8 * @version $Id$
9 * @package phpMyAdmin
12 /**
13 * Gets the variables sent or posted to this script and displays the header
15 require_once './libraries/common.inc.php';
17 /**
18 * Ensures db and table are valid, else moves to the "parent" script
20 require_once './libraries/db_table_exists.lib.php';
23 /**
24 * Sets global variables.
25 * Here it's better to use a if, instead of the '?' operator
26 * to avoid setting a variable to '' when it's not present in $_REQUEST
28 /**
29 * @todo this one is badly named, it's really a WHERE condition
30 * and exists even for tables not having a primary key or unique key
32 if (isset($_REQUEST['primary_key'])) {
33 $primary_key = $_REQUEST['primary_key'];
35 if (isset($_SESSION['edit_next'])) {
36 $primary_key = $_SESSION['edit_next'];
37 unset($_SESSION['edit_next']);
38 $after_insert = 'edit_next';
40 if (isset($_REQUEST['sql_query'])) {
41 $sql_query = $_REQUEST['sql_query'];
43 if (isset($_REQUEST['ShowFunctionFields'])) {
44 $cfg['ShowFunctionFields'] = $_REQUEST['ShowFunctionFields'];
47 /**
48 * load relation data, foreign keys
50 require_once './libraries/relation.lib.php';
52 /**
53 * file listing
55 require_once './libraries/file_listing.php';
58 /**
59 * Defines the url to return to in case of error in a sql statement
60 * (at this point, $GLOBALS['goto'] will be set but could be empty)
62 if (empty($GLOBALS['goto'])) {
63 if (strlen($table)) {
64 // avoid a problem (see bug #2202709)
65 $GLOBALS['goto'] = 'tbl_sql.php';
66 } else {
67 $GLOBALS['goto'] = 'db_sql.php';
70 /**
71 * @todo check if we could replace by "db_|tbl_" - please clarify!?
73 $_url_params = array(
74 'db' => $db,
75 'sql_query' => $sql_query
78 if (preg_match('@^tbl_@', $GLOBALS['goto'])) {
79 $_url_params['table'] = $table;
82 $err_url = $GLOBALS['goto'] . PMA_generate_common_url($_url_params);
83 unset($_url_params);
86 /**
87 * Sets parameters for links
88 * where is this variable used?
89 * replace by PMA_generate_common_url($url_params);
91 $url_query = PMA_generate_common_url($url_params, 'html', '');
93 /**
94 * get table information
95 * @todo should be done by a Table object
97 require_once './libraries/tbl_info.inc.php';
99 /**
100 * Get comments for table fileds/columns
102 $comments_map = array();
104 if ($GLOBALS['cfg']['ShowPropertyComments']) {
105 $comments_map = PMA_getComments($db, $table);
109 * START REGULAR OUTPUT
113 * used in ./libraries/header.inc.php to load JavaScript library file
115 $GLOBALS['js_include'][] = 'tbl_change.js';
118 * HTTP and HTML headers
120 require_once './libraries/header.inc.php';
123 * Displays the query submitted and its result
125 * @todo where does $disp_message and $disp_query come from???
127 if (! empty($disp_message)) {
128 if (! isset($disp_query)) {
129 $disp_query = null;
131 PMA_showMessage($disp_message, $disp_query);
135 * Displays top menu links
137 require_once './libraries/tbl_links.inc.php';
141 * Get the analysis of SHOW CREATE TABLE for this table
142 * @todo should be handled by class Table
144 $show_create_table = PMA_DBI_fetch_value(
145 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
146 0, 1);
147 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
148 unset($show_create_table);
151 * Get the list of the fields of the current table
153 PMA_DBI_select_db($db);
154 $table_fields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ';',
155 null, null, null, PMA_DBI_QUERY_STORE);
156 $rows = array();
157 if (isset($primary_key)) {
158 // when in edit mode load all selected rows from table
159 $insert_mode = false;
160 if (is_array($primary_key)) {
161 $primary_key_array = $primary_key;
162 } else {
163 $primary_key_array = array(0 => $primary_key);
166 $result = array();
167 $found_unique_key = false;
168 foreach ($primary_key_array as $key_id => $primary_key) {
169 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . str_replace('&#93;', ']', $primary_key) . ';';
170 $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE);
171 $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]);
172 $primary_keys[$key_id] = str_replace('\\', '\\\\', $primary_key);
174 // No row returned
175 if (! $rows[$key_id]) {
176 unset($rows[$key_id], $primary_key_array[$key_id]);
177 PMA_showMessage($strEmptyResultSet, $local_query);
178 echo "\n";
179 require_once './libraries/footer.inc.php';
180 } else { // end if (no record returned)
181 $meta = PMA_DBI_get_fields_meta($result[$key_id]);
182 if ($tmp = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true)) {
183 $found_unique_key = true;
185 unset($tmp);
188 } else {
189 // no primary key given, just load first row - but what happens if tbale is empty?
190 $insert_mode = true;
191 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
192 $rows = array_fill(0, $cfg['InsertRows'], false);
195 // <markus@noga.de>
196 // retrieve keys into foreign fields, if any
197 $foreigners = PMA_getForeigners($db, $table);
201 * Displays the form
203 // loic1: autocomplete feature of IE kills the "onchange" event handler and it
204 // must be replaced by the "onpropertychange" one in this case
205 $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5 && PMA_USR_BROWSER_VER < 7)
206 ? 'onpropertychange'
207 : 'onchange';
208 // Had to put the URI because when hosted on an https server,
209 // some browsers send wrongly this form to the http server.
211 if ($cfg['CtrlArrowsMoving']) {
213 <!-- Set on key handler for moving using by Ctrl+arrows -->
214 <script src="./js/keyhandler.js" type="text/javascript"></script>
215 <script type="text/javascript">
216 //<![CDATA[
217 var switch_movement = 0;
218 document.onkeydown = onKeyDownArrowsHandler;
219 //]]>
220 </script>
221 <?php
224 $_form_params = array(
225 'db' => $db,
226 'table' => $table,
227 'goto' => $GLOBALS['goto'],
228 'err_url' => $err_url,
229 'sql_query' => $sql_query,
231 if (isset($primary_keys)) {
232 foreach ($primary_key_array as $key_id => $primary_key) {
233 $_form_params['primary_key[' . $key_id . ']'] = trim($primary_key);
238 <!-- Insert/Edit form -->
239 <form method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?>>
240 <?php
241 echo PMA_generate_common_hidden_inputs($_form_params);
243 $titles['Browse'] = PMA_getIcon('b_browse.png', $strBrowseForeignValues);
245 // Set if we passed the first timestamp field
246 $timestamp_seen = 0;
247 $fields_cnt = count($table_fields);
249 $tabindex = 0;
250 $tabindex_for_function = +3000;
251 $tabindex_for_null = +6000;
252 $tabindex_for_value = 0;
253 $o_rows = 0;
254 $biggest_max_file_size = 0;
256 // user can toggle the display of Function column
257 // (currently does not work for multi-edits)
258 $url_params['db'] = $db;
259 $url_params['table'] = $table;
260 if (isset($primary_key)) {
261 $url_params['primary_key'] = trim($primary_key);
263 if (! empty($sql_query)) {
264 $url_params['sql_query'] = $sql_query;
267 if (! $cfg['ShowFunctionFields']) {
268 $this_url_params = array_merge($url_params,
269 array('ShowFunctionFields' => 1));
270 echo $strShow . ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . $strFunction . '</a>' . "\n";
273 foreach ($rows as $row_id => $vrow) {
274 if ($vrow === false) {
275 unset($vrow);
278 $jsvkey = $row_id;
279 $browse_foreigners_uri = '&amp;pk=' . $row_id;
280 $vkey = '[multi_edit][' . $jsvkey . ']';
282 $vresult = (isset($result) && is_array($result) && isset($result[$row_id]) ? $result[$row_id] : $result);
283 if ($insert_mode && $row_id > 0) {
284 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $row_id . '" id="insert_ignore_check_' . $row_id . '" />';
285 echo '<label for="insert_ignore_check_' . $row_id . '">' . $strIgnore . '</label><br />' . "\n";
288 <table>
289 <thead>
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 </thead>
304 <tfoot>
305 <tr>
306 <th colspan="5" align="right" class="tblFooters">
307 <input type="submit" value="<?php echo $strGo; ?>" />
308 </th>
309 </tr>
310 </tfoot>
311 <tbody>
312 <?php
313 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
314 $m_rows = $o_rows + 1;
316 $odd_row = true;
317 for ($i = 0; $i < $fields_cnt; $i++) {
318 if (! isset($table_fields[$i]['processed'])) {
319 $table_fields[$i]['Field_html'] = htmlspecialchars($table_fields[$i]['Field']);
320 $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']);
321 // True_Type contains only the type (stops at first bracket)
322 $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']);
324 // d a t e t i m e
326 // loic1: current date should not be set as default if the field is NULL
327 // for the current row
328 // lem9: but do not put here the current datetime if there is a default
329 // value (the real default value will be set in the
330 // Default value logic below)
332 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
333 // $field['Default'] is not set if it contains NULL:
334 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime)
335 // but, look what we get if we switch to iso: (Default is NULL)
336 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime)
337 // so I force a NULL into it (I don't think it's possible
338 // to have an empty default value for DATETIME)
339 // then, the "if" after this one will work
340 if ($table_fields[$i]['Type'] == 'datetime'
341 && ! isset($table_fields[$i]['Default'])
342 && isset($table_fields[$i]['Null'])
343 && $table_fields[$i]['Null'] == 'YES') {
344 $table_fields[$i]['Default'] = null;
347 $table_fields[$i]['len'] =
348 preg_match('@float|double@', $table_fields[$i]['Type']) ? 100 : -1;
351 if (isset($comments_map[$table_fields[$i]['Field']])) {
352 $table_fields[$i]['Field_title'] = '<span style="border-bottom: 1px dashed black;" title="'
353 . htmlspecialchars($comments_map[$table_fields[$i]['Field']]) . '">'
354 . $table_fields[$i]['Field_html'] . '</span>';
355 } else {
356 $table_fields[$i]['Field_title'] = $table_fields[$i]['Field_html'];
359 // The type column
360 $table_fields[$i]['is_binary'] = stristr($table_fields[$i]['Type'], 'binary');
361 $table_fields[$i]['is_blob'] = stristr($table_fields[$i]['Type'], 'blob');
362 $table_fields[$i]['is_char'] = stristr($table_fields[$i]['Type'], 'char');
363 $table_fields[$i]['first_timestamp'] = false;
364 switch ($table_fields[$i]['True_Type']) {
365 case 'set':
366 $table_fields[$i]['pma_type'] = 'set';
367 $table_fields[$i]['wrap'] = '';
368 break;
369 case 'enum':
370 $table_fields[$i]['pma_type'] = 'enum';
371 $table_fields[$i]['wrap'] = '';
372 break;
373 case 'timestamp':
374 if (!$timestamp_seen) { // can only occur once per table
375 $timestamp_seen = 1;
376 $table_fields[$i]['first_timestamp'] = true;
378 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
379 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
380 break;
382 default:
383 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
384 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
385 break;
388 $field = $table_fields[$i];
389 $extracted_fieldspec = PMA_extractFieldSpec($field['Type']);
391 if (-1 === $field['len']) {
392 $field['len'] = PMA_DBI_field_len($vresult, $i);
395 $unnullify_trigger = $chg_evt_handler . "=\"return unNullify('"
396 . PMA_escapeJsString($field['Field_html']) . "', '"
397 . PMA_escapeJsString($jsvkey) . "')\"";
399 // Use an MD5 as an array index to avoid having special characters in the name atttibute (see bug #1746964 )
400 $field_name_appendix = $vkey . '[' . $field['Field_md5'] . ']';
401 $field_name_appendix_md5 = $field['Field_md5'] . $vkey . '[]';
404 if ($field['Type'] == 'datetime'
405 && ! isset($field['Default'])
406 && ! is_null($field['Default'])
407 && ($insert_mode || ! isset($vrow[$field['Field']]))) {
408 // INSERT case or
409 // UPDATE case with an NULL value
410 $vrow[$field['Field']] = date('Y-m-d H:i:s', time());
413 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
414 <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($field['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center">
415 <?php echo $field['Field_title']; ?>
416 <input type="hidden" name="fields_name<?php echo $field_name_appendix; ?>" value="<?php echo $field['Field_html']; ?>"/>
417 </td>
418 <td align="center"<?php echo $field['wrap']; ?>>
419 <?php echo $field['pma_type']; ?>
420 </td>
422 <?php
424 // Prepares the field value
425 $real_null_value = FALSE;
426 $special_chars_encoded = '';
427 if (isset($vrow)) {
428 // On a BLOB that can have a NULL value, the is_null() returns
429 // true if it has no content but for me this is different than
430 // having been set explicitely to NULL so I put an exception here
431 if (! $field['is_blob'] && is_null($vrow[$field['Field']])) {
432 $real_null_value = TRUE;
433 $vrow[$field['Field']] = '';
434 $special_chars = '';
435 $data = $vrow[$field['Field']];
436 } elseif ($field['True_Type'] == 'bit') {
437 $special_chars = PMA_printable_bit_value($vrow[$field['Field']], $extracted_fieldspec['spec_in_brackets']);
438 } else {
439 // loic1: special binary "characters"
440 if ($field['is_binary'] || $field['is_blob']) {
441 $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]);
442 } // end if
443 $special_chars = htmlspecialchars($vrow[$field['Field']]);
445 //We need to duplicate the first \n or otherwise we will lose the first newline entered in a VARCHAR or TEXT column
446 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
448 $data = $vrow[$field['Field']];
449 } // end if... else...
450 // loic1: if a timestamp field value is not included in an update
451 // statement MySQL auto-update it to the current timestamp
452 // lem9: however, things have changed since MySQL 4.1, so
453 // it's better to set a fields_prev in this situation
454 $backup_field = '<input type="hidden" name="fields_prev'
455 . $field_name_appendix . '" value="'
456 . htmlspecialchars($vrow[$field['Field']]) . '" />';
457 } else {
458 // loic1: display default values
459 if (!isset($field['Default'])) {
460 $field['Default'] = '';
461 $real_null_value = TRUE;
462 $data = '';
463 } else {
464 $data = $field['Default'];
466 if ($field['True_Type'] == 'bit') {
467 $special_chars = PMA_printable_bit_value($field['Default'], $extracted_fieldspec['spec_in_brackets']);
468 } else {
469 $special_chars = htmlspecialchars($field['Default']);
471 $backup_field = '';
474 $idindex = ($o_rows * $fields_cnt) + $i + 1;
475 $tabindex = (($idindex - 1) * 3) + 1;
477 // The function column
478 // -------------------
479 // Change by Bernard M. Piller <bernard@bmpsystems.com>
480 // We don't want binary data to be destroyed
481 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
482 // stored or retrieved" so it does not mean that the contents is
483 // binary
484 if ($cfg['ShowFunctionFields']) {
485 if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload)
486 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
487 echo ' <td align="center">' . $strBinary . '</td>' . "\n";
488 } elseif (strstr($field['True_Type'], 'enum') || strstr($field['True_Type'], 'set')) {
489 echo ' <td align="center">--</td>' . "\n";
490 } else {
492 <td>
493 <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">
494 <option></option>
495 <?php
496 $selected = '';
498 // garvin: Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
499 // or something similar. Then directly look up the entry in the RestrictFunctions array,
500 // which will then reveal the available dropdown options
501 if (isset($cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])])
502 && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])]])) {
503 $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])];
504 $dropdown = $cfg['RestrictFunctions'][$current_func_type];
505 $default_function = $cfg['DefaultFunctions'][$current_func_type];
506 } else {
507 $dropdown = array();
508 $default_function = '';
511 $dropdown_built = array();
512 $op_spacing_needed = FALSE;
514 // what function defined as default?
515 // for the first timestamp we don't set the default function
516 // if there is a default value for the timestamp
517 // (not including CURRENT_TIMESTAMP)
518 // and the column does not have the
519 // ON UPDATE DEFAULT TIMESTAMP attribute.
521 if ($field['True_Type'] == 'timestamp'
522 && empty($field['Default'])
523 && ! isset($analyzed_sql[0]['create_table_fields'][$field['Field']]['on_update_current_timestamp'])) {
524 $default_function = $cfg['DefaultFunctions']['first_timestamp'];
527 if ($field['Key'] == 'PRI'
528 && ($field['Type'] == 'char(36)' || $field['Type'] == 'varchar(36)')) {
529 $default_function = $cfg['DefaultFunctions']['pk_char36'];
532 // garvin: loop on the dropdown array and print all available options for that field.
533 foreach ($dropdown as $each_dropdown){
534 echo '<option';
535 if ($default_function === $each_dropdown) {
536 echo ' selected="selected"';
538 echo '>' . $each_dropdown . '</option>' . "\n";
539 $dropdown_built[$each_dropdown] = '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 = ($field['first_timestamp'] && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
551 || (!$field['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 $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', '');
576 echo ' <td>' . "\n";
577 if ($field['Null'] == 'YES') {
578 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
579 if ($real_null_value && !$field['first_timestamp']) {
580 echo ' value="on"';
582 echo ' />' . "\n";
584 if (!(($cfg['ProtectBinary'] && $field['is_blob']) || ($cfg['ProtectBinary'] == 'all' && $field['is_binary']))) {
586 echo ' <input type="checkbox" tabindex="' . ($tabindex + $tabindex_for_null) . '"'
587 . ' name="fields_null' . $field_name_appendix . '"';
588 if ($real_null_value && !$field['first_timestamp']) {
589 echo ' checked="checked"';
591 echo ' id="field_' . ($idindex) . '_2"';
592 $onclick = ' onclick="if (this.checked) {nullify(';
593 if (strstr($field['True_Type'], 'enum')) {
594 if (strlen($field['Type']) > 20) {
595 $onclick .= '1, ';
596 } else {
597 $onclick .= '2, ';
599 } elseif (strstr($field['True_Type'], 'set')) {
600 $onclick .= '3, ';
601 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == false) {
602 // foreign key in a drop-down
603 $onclick .= '4, ';
604 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == true) {
605 // foreign key with a browsing icon
606 $onclick .= '6, ';
607 } else {
608 $onclick .= '5, ';
610 $onclick .= '\'' . PMA_escapeJsString($field['Field_html']) . '\', \'' . $field['Field_md5'] . '\', \'' . PMA_escapeJsString($vkey) . '\'); this.checked = true}; return true" />' . "\n";
611 echo $onclick;
612 } else {
613 echo ' <input type="hidden" name="fields_null' . $field_name_appendix . '"';
614 if ($real_null_value && !$field['first_timestamp']) {
615 echo ' value="on"';
617 echo ' />' . "\n";
620 echo ' </td>' . "\n";
622 // The value column (depends on type)
623 // ----------------
624 // See bug #1667887 for the reason why we don't use the maxlength
625 // HTML attribute
627 echo ' <td>' . "\n";
628 if ($foreignData['foreign_link'] == true) {
629 echo $backup_field . "\n";
631 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
632 value="foreign" />
633 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
634 value="" id="field_<?php echo ($idindex); ?>_3A" />
635 <input type="text" name="field_<?php echo $field_name_appendix_md5; ?>"
636 class="textfield" <?php echo $unnullify_trigger; ?>
637 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
638 id="field_<?php echo ($idindex); ?>_3"
639 value="<?php echo htmlspecialchars($data); ?>" />
640 <script type="text/javascript">
641 //<![CDATA[
642 document.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes,resizable=yes\'); return false"');
643 document.write(' href="browse_foreigners.php?');
644 document.write('<?php echo PMA_generate_common_url($db, $table); ?>');
645 document.writeln('&amp;field=<?php echo PMA_escapeJsString(urlencode($field['Field']) . $browse_foreigners_uri); ?>">');
646 document.writeln('<?php echo str_replace("'", "\'", $titles['Browse']); ?></a>');
647 //]]>
648 </script>
649 <?php
650 } elseif (is_array($foreignData['disp_row'])) {
651 echo $backup_field . "\n";
653 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
654 value="foreign" />
655 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
656 value="" id="field_<?php echo $idindex; ?>_3A" />
657 <select name="field_<?php echo $field_name_appendix_md5; ?>"
658 <?php echo $unnullify_trigger; ?>
659 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
660 id="field_<?php echo ($idindex); ?>_3">
661 <?php echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?>
662 </select>
663 <?php
664 // still needed? :
665 unset($foreignData['disp_row']);
666 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
668 &nbsp;</td>
669 </tr>
670 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
671 <td colspan="5" align="right">
672 <?php echo $backup_field . "\n"; ?>
673 <textarea name="fields<?php echo $field_name_appendix; ?>"
674 rows="<?php echo ($cfg['TextareaRows']*2); ?>"
675 cols="<?php echo ($cfg['TextareaCols']*2); ?>"
676 dir="<?php echo $text_dir; ?>"
677 id="field_<?php echo ($idindex); ?>_3"
678 <?php echo $unnullify_trigger; ?>
679 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
680 ><?php echo $special_chars_encoded; ?></textarea>
681 <?php
682 } elseif (strstr($field['pma_type'], 'text')) {
683 echo $backup_field . "\n";
685 <textarea name="fields<?php echo $field_name_appendix; ?>"
686 rows="<?php echo $cfg['TextareaRows']; ?>"
687 cols="<?php echo $cfg['TextareaCols']; ?>"
688 dir="<?php echo $text_dir; ?>"
689 id="field_<?php echo ($idindex); ?>_3"
690 <?php echo $unnullify_trigger; ?>
691 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
692 ><?php echo $special_chars_encoded; ?></textarea>
693 <?php
694 echo "\n";
695 if (strlen($special_chars) > 32000) {
696 echo " </td>\n";
697 echo ' <td>' . $strTextAreaLength;
699 } elseif ($field['pma_type'] == 'enum') {
700 if (! isset($table_fields[$i]['values'])) {
701 $table_fields[$i]['values'] = array();
702 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
703 // Removes automatic MySQL escape format
704 $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
705 $table_fields[$i]['values'][] = array(
706 'plain' => $val,
707 'html' => htmlspecialchars($val),
711 $field_enum_values = $table_fields[$i]['values'];
713 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="enum" />
714 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
715 <?php
716 echo "\n" . ' ' . $backup_field . "\n";
718 // show dropdown or radio depend on length
719 if (strlen($field['Type']) > 20) {
721 <select name="field_<?php echo $field_name_appendix_md5; ?>"
722 <?php echo $unnullify_trigger; ?>
723 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
724 id="field_<?php echo ($idindex); ?>_3">
725 <option value="">&nbsp;</option>
726 <?php
727 echo "\n";
729 foreach ($field_enum_values as $enum_value) {
730 echo ' ';
731 echo '<option value="' . $enum_value['html'] . '"';
732 if ($data == $enum_value['plain']
733 || ($data == ''
734 && (! isset($primary_key) || $field['Null'] != 'YES')
735 && isset($field['Default'])
736 && $enum_value['plain'] == $field['Default'])) {
737 echo ' selected="selected"';
739 echo '>' . $enum_value['html'] . '</option>' . "\n";
740 } // end for
743 </select>
744 <?php
745 } else {
746 $j = 0;
747 foreach ($field_enum_values as $enum_value) {
748 echo ' ';
749 echo '<input type="radio" name="field_' . $field_name_appendix_md5 . '"';
750 echo ' value="' . $enum_value['html'] . '"';
751 echo ' id="field_' . ($idindex) . '_3_' . $j . '"';
752 echo ' onclick="';
753 echo "if (typeof(document.forms['insertForm'].elements['fields_null"
754 . $field_name_appendix . "']) != 'undefined') {document.forms['insertForm'].elements['fields_null"
755 . $field_name_appendix . "'].checked = false}";
756 echo '"';
757 if ($data == $enum_value['plain']
758 || ($data == ''
759 && (! isset($primary_key) || $field['Null'] != 'YES')
760 && isset($field['Default'])
761 && $enum_value['plain'] == $field['Default'])) {
762 echo ' checked="checked"';
764 echo ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
765 echo '<label for="field_' . $idindex . '_3_' . $j . '">'
766 . $enum_value['html'] . '</label>' . "\n";
767 $j++;
768 } // end for
769 } // end else
770 } elseif ($field['pma_type'] == 'set') {
771 if (! isset($table_fields[$i]['values'])) {
772 $table_fields[$i]['values'] = array();
773 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
774 $table_fields[$i]['values'][] = array(
775 'plain' => $val,
776 'html' => htmlspecialchars($val),
779 $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
781 $field_set_values = $table_fields[$i]['values'];
782 $select_size = $table_fields[$i]['select_size'];
784 $vset = array_flip(explode(',', $data));
785 echo $backup_field . "\n";
787 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="set" />
788 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
789 <select name="field_<?php echo $field_name_appendix_md5; ?>"
790 size="<?php echo $select_size; ?>"
791 multiple="multiple" <?php echo $unnullify_trigger; ?>
792 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
793 id="field_<?php echo ($idindex); ?>_3">
794 <?php
795 foreach ($field_set_values as $field_set_value) {
796 echo ' ';
797 echo '<option value="' . $field_set_value['html'] . '"';
798 if (isset($vset[$field_set_value['plain']])) {
799 echo ' selected="selected"';
801 echo '>' . $field_set_value['html'] . '</option>' . "\n";
802 } // end for
804 </select>
805 <?php
807 // Change by Bernard M. Piller <bernard@bmpsystems.com>
808 // We don't want binary data destroyed
809 elseif ($field['is_binary'] || $field['is_blob']) {
810 if (($cfg['ProtectBinary'] && $field['is_blob'])
811 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
812 echo "\n";
813 // rajk - for blobstreaming
814 $bs_reference_exists = FALSE;
816 if (isset ($tbl_type) && strlen ($tbl_type) > 0)
818 // load PMA_Config
819 $PMA_Config = $_SESSION['PMA_Config'];
821 if (!empty($PMA_Config))
823 $requiredTblType = $PMA_Config->get('PBXT_NAME');
825 if ($requiredTblType == strtolower ($tbl_type))
827 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
829 // check if blobstreaming plugins exist
830 if ($pluginsExist)
832 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
834 if (!empty($bs_tables) && strlen($db) > 0)
836 $bs_tables = $bs_tables[$db];
838 if (isset($bs_tables))
840 $allBSTablesExist = TRUE;
842 foreach ($bs_tables as $table_key=>$bs_tbl)
843 if (!$bs_tables[$table_key]['Exists'])
845 $allBSTablesExist = FALSE;
846 break;
849 if ($allBSTablesExist)
850 $bs_reference_exists = PMA_BS_ReferenceExists($data, $db);
851 } // end if (isset($bs_tables))
852 } // end if (!empty($bs_tables) && strlen($db) > 0)
853 } // end if ($pluginsExist)
854 } // end if ($requiredTblType == strtolower ($tbl_type))
855 } // end if (!empty($PMA_Config))
856 } // end if (isset ($tbl_type) && strlen ($tbl_type) > 0)
858 if ($bs_reference_exists)
860 echo '<input type="hidden" name="remove_blob_ref_' . $field['Field_md5'] . $vkey . '" value="' . $data . '" />';
861 echo '<input type="checkbox" name="remove_blob_repo_' . $field['Field_md5'] . $vkey . '" /> ' . $strBLOBRepositoryRemove . "<br />";
862 echo PMA_BS_CreateReferenceLink($data, $db);
863 echo "<br />";
865 else
867 echo $strBinaryDoNotEdit;
868 if (isset($data)) {
869 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
870 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
871 unset($data_size);
873 echo "\n";
874 } // end if ($bs_reference_exists)
876 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="protected" />
877 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
878 <?php
879 } elseif ($field['is_blob']) {
880 echo "\n";
881 echo $backup_field . "\n";
883 <textarea name="fields<?php echo $field_name_appendix; ?>"
884 rows="<?php echo $cfg['TextareaRows']; ?>"
885 cols="<?php echo $cfg['TextareaCols']; ?>"
886 dir="<?php echo $text_dir; ?>"
887 id="field_<?php echo ($idindex); ?>_3"
888 <?php echo $unnullify_trigger; ?>
889 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
890 ><?php echo $special_chars_encoded; ?></textarea>
891 <?php
893 } else {
894 // field size should be at least 4 and max 40
895 $fieldsize = min(max($field['len'], 4), 40);
896 echo "\n";
897 echo $backup_field . "\n";
899 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
900 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
901 class="textfield" <?php echo $unnullify_trigger; ?>
902 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
903 id="field_<?php echo ($idindex); ?>_3" />
904 <?php
905 } // end if...elseif...else
907 // Upload choice (only for BLOBs because the binary
908 // attribute does not imply binary contents)
909 // (displayed whatever value the ProtectBinary has)
911 if ($is_upload && $field['is_blob']) {
912 // added by rajk
913 // check if field type is of longblob
914 if ($field['pma_type'] == "longblob")
916 if (isset ($tbl_type) && strlen ($tbl_type) > 0)
918 // load PMA Config
919 $PMA_Config = $_SESSION['PMA_Config'];
921 // is PMA_Config's data loaded? continue only if it is
922 if (!empty($PMA_Config))
924 $requiredTblType = $PMA_Config->get('PBXT_NAME');
926 if ($requiredTblType == strtolower ($tbl_type))
928 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
930 // check if blobstreaming plugins exist
931 if ($pluginsExist)
933 $curlExists = $PMA_Config->get('CURL_EXISTS');
935 // check if CURL exists
936 if ($curlExists)
938 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
940 // check for BLOBStreamable databases and if current database name is provided
941 if (!empty($bs_tables) && strlen($db) > 0)
943 $bs_tables = $bs_tables[$db];
945 // check if reference to BLOBStreaming tables exists
946 if (isset($bs_tables))
948 $allBSTablesExist = TRUE;
950 foreach ($bs_tables as $table_key=>$bs_tbl)
951 if (!$bs_tables[$table_key]['Exists'])
953 $allBSTablesExist = FALSE;
954 break;
957 // check if necessary BLOBStreaming tables exist
958 if ($allBSTablesExist)
960 echo '<br />';
961 echo '<input type="checkbox" name="upload_blob_repo_' . $field['Field_md5'] . $vkey . '" /> ' . $strBLOBRepositoryUpload;
962 } // end if ($allBSTablesExist)
963 } // end if (isset($bs_tables)
964 } // end if (!empty($bs_tables) && strlen ($db) > 0)
965 } // end if ($curlExists)
966 } // end if ($pluginsExist)
967 } // end if ($requiredTblType == strtolower ($tbl_type))
968 } // end if (!empty($PMA_Config))
969 } // end if (isset ($tbl_type) && strlen ($tbl_type) > 0)
972 echo '<br />';
973 echo '<input type="file" name="fields_upload_' . $field['Field_md5'] . $vkey . '" class="textfield" id="field_' . $idindex . '_3" size="10" />&nbsp;';
975 // find maximum upload size, based on field type
977 * @todo with functions this is not so easy, as you can basically
978 * process any data with function like MD5
980 $max_field_sizes = array(
981 'tinyblob' => '256',
982 'blob' => '65536',
983 'mediumblob' => '16777216',
984 'longblob' => '4294967296'); // yeah, really
986 $this_field_max_size = $max_upload_size; // from PHP max
987 if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
988 $this_field_max_size = $max_field_sizes[$field['pma_type']];
990 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
991 // do not generate here the MAX_FILE_SIZE, because we should
992 // put only one in the form to accommodate the biggest field
993 if ($this_field_max_size > $biggest_max_file_size) {
994 $biggest_max_file_size = $this_field_max_size;
998 if (!empty($cfg['UploadDir'])) {
999 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
1000 if ($files === FALSE) {
1001 echo ' <font color="red">' . $strError . '</font><br />' . "\n";
1002 echo ' ' . $strWebServerUploadDirectoryError . "\n";
1003 } elseif (!empty($files)) {
1004 echo "<br />\n";
1005 echo ' <i>' . $strOr . '</i>' . ' ' . $strWebServerUploadDirectory . ':<br />' . "\n";
1006 echo ' <select size="1" name="fields_uploadlocal_' . $field['Field_md5'] . $vkey . '">' . "\n";
1007 echo ' <option value="" selected="selected"></option>' . "\n";
1008 echo $files;
1009 echo ' </select>' . "\n";
1011 } // end if (web-server upload directory)
1012 } // end elseif (binary or blob)
1013 else {
1014 // field size should be at least 4 and max 40
1015 $fieldsize = min(max($field['len'], 4), 40);
1016 echo $backup_field . "\n";
1017 if ($field['is_char'] && ($cfg['CharEditing'] == 'textarea' || strpos($data, "\n") !== FALSE)) {
1018 echo "\n";
1020 <textarea name="fields<?php echo $field_name_appendix; ?>"
1021 rows="<?php echo $cfg['CharTextareaRows']; ?>"
1022 cols="<?php echo $cfg['CharTextareaCols']; ?>"
1023 dir="<?php echo $text_dir; ?>"
1024 id="field_<?php echo ($idindex); ?>_3"
1025 <?php echo $unnullify_trigger; ?>
1026 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
1027 ><?php echo $special_chars_encoded; ?></textarea>
1028 <?php
1029 } else {
1031 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
1032 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
1033 class="textfield" <?php echo $unnullify_trigger; ?>
1034 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
1035 id="field_<?php echo ($idindex); ?>_3" />
1036 <?php
1037 if ($field['Extra'] == 'auto_increment') {
1039 <input type="hidden" name="auto_increment<?php echo $field_name_appendix; ?>" value="1" />
1040 <?php
1041 } // end if
1042 if (substr($field['pma_type'], 0, 9) == 'timestamp') {
1044 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="timestamp" />
1045 <?php
1047 if ($field['True_Type'] == 'bit') {
1049 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="bit" />
1050 <?php
1052 if ($field['pma_type'] == 'date' || $field['pma_type'] == 'datetime' || substr($field['pma_type'], 0, 9) == 'timestamp') {
1054 <script type="text/javascript">
1055 //<![CDATA[
1056 document.write('<a title="<?php echo $strCalendar;?>"');
1057 document.write(' href="javascript:openCalendar(\'<?php echo PMA_generate_common_url();?>\', \'insertForm\', \'field_<?php echo ($idindex); ?>_3\', \'<?php echo (substr($field['pma_type'], 0, 9) == 'timestamp') ? 'datetime' : substr($field['pma_type'], 0, 9); ?>\')">');
1058 document.write('<img class="calendar"');
1059 document.write(' src="<?php echo $pmaThemeImage; ?>b_calendar.png"');
1060 document.write(' alt="<?php echo $strCalendar; ?>"/></a>');
1061 //]]>
1062 </script>
1063 <?php
1068 </td>
1069 </tr>
1070 <?php
1071 $odd_row = !$odd_row;
1072 } // end for
1073 $o_rows++;
1074 echo ' </tbody></table><br />';
1075 } // end foreach on multi-edit
1077 <br />
1079 <fieldset>
1080 <table border="0" cellpadding="5" cellspacing="0">
1081 <tr>
1082 <td valign="middle" nowrap="nowrap">
1083 <select name="submit_type" tabindex="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
1084 <?php
1085 if (isset($primary_key)) {
1087 <option value="<?php echo $strSave; ?>"><?php echo $strSave; ?></option>
1088 <?php
1091 <option value="<?php echo $strInsertAsNewRow; ?>"><?php echo $strInsertAsNewRow; ?></option>
1092 </select>
1093 <?php
1094 echo "\n";
1096 if (!isset($after_insert)) {
1097 $after_insert = 'back';
1100 </td>
1101 <td valign="middle">
1102 &nbsp;&nbsp;&nbsp;<strong><?php echo $strAndThen; ?></strong>&nbsp;&nbsp;&nbsp;
1103 </td>
1104 <td valign="middle" nowrap="nowrap">
1105 <select name="after_insert">
1106 <option value="back" <?php echo ($after_insert == 'back' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertBack; ?></option>
1107 <option value="new_insert" <?php echo ($after_insert == 'new_insert' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertNewInsert; ?></option>
1108 <?php
1109 if (isset($primary_key)) {
1111 <option value="same_insert" <?php echo ($after_insert == 'same_insert' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertSame; ?></option>
1112 <?php
1113 // If we have just numeric primary key, we can also edit next
1114 // in 2.8.2, we were looking for `field_name` = numeric_value
1115 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $primary_key)) {
1116 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1117 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $primary_key)) {
1119 <option value="edit_next" <?php echo ($after_insert == 'edit_next' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertNext; ?></option>
1120 <?php
1124 </select>
1125 </td>
1126 </tr>
1128 <tr>
1129 <td>
1130 <?php echo PMA_showHint($strUseTabKey); ?>
1131 </td>
1132 <td colspan="3" align="right" valign="middle">
1133 <input type="submit" value="<?php echo $strGo; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 6); ?>" id="buttonYes" />
1134 <input type="reset" value="<?php echo $strReset; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 7); ?>" />
1135 </td>
1136 </tr>
1137 </table>
1138 </fieldset>
1139 <?php if ($biggest_max_file_size > 0) {
1140 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
1141 } ?>
1142 </form>
1143 <?php
1144 if ($insert_mode) {
1146 <!-- Restart insertion form -->
1147 <form method="post" action="tbl_replace.php" name="restartForm" >
1148 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
1149 <input type="hidden" name="goto" value="<?php echo htmlspecialchars($GLOBALS['goto']); ?>" />
1150 <input type="hidden" name="err_url" value="<?php echo htmlspecialchars($err_url); ?>" />
1151 <input type="hidden" name="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
1152 <?php
1153 if (isset($primary_keys)) {
1154 foreach ($primary_key_array as $key_id => $primary_key) {
1155 echo '<input type="hidden" name="primary_key[' . $key_id . ']" value="' . htmlspecialchars(trim($primary_key)) . '" />'. "\n";
1158 $tmp = '<select name="insert_rows" id="insert_rows" onchange="this.form.submit();" >' . "\n";
1159 $option_values = array(1,2,5,10,15,20,30,40);
1160 foreach ($option_values as $value) {
1161 $tmp .= '<option value="' . $value . '"';
1162 if ($value == $cfg['InsertRows']) {
1163 $tmp .= ' selected="selected"';
1165 $tmp .= '>' . $value . '</option>' . "\n";
1167 $tmp .= '</select>' . "\n";
1168 echo "\n" . sprintf($strRestartInsertion, $tmp);
1169 unset($tmp);
1170 echo '<noscript><input type="submit" value="' . $strGo . '" /></noscript>' . "\n";
1171 echo '</form>' . "\n";
1175 * Displays the footer
1177 require_once './libraries/footer.inc.php';