patch #2538358 [display] Conditions for relational display field
[phpmyadmin/crack.git] / tbl_change.php
blob43d20746c3e6ae93780ec85516f0beaf34553d04
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 */
11 /**
12 * Gets the variables sent or posted to this script and displays the header
14 require_once './libraries/common.inc.php';
16 /**
17 * Ensures db and table are valid, else moves to the "parent" script
19 require_once './libraries/db_table_exists.lib.php';
22 /**
23 * Sets global variables.
24 * Here it's better to use a if, instead of the '?' operator
25 * to avoid setting a variable to '' when it's not present in $_REQUEST
27 /**
28 * @todo this one is badly named, it's really a WHERE condition
29 * and exists even for tables not having a primary key or unique key
31 if (isset($_REQUEST['primary_key'])) {
32 $primary_key = $_REQUEST['primary_key'];
34 if (isset($_SESSION['edit_next'])) {
35 $primary_key = $_SESSION['edit_next'];
36 unset($_SESSION['edit_next']);
37 $after_insert = 'edit_next';
39 if (isset($_REQUEST['sql_query'])) {
40 $sql_query = $_REQUEST['sql_query'];
42 if (isset($_REQUEST['ShowFunctionFields'])) {
43 $cfg['ShowFunctionFields'] = $_REQUEST['ShowFunctionFields'];
46 /**
47 * load relation data, foreign keys
49 require_once './libraries/relation.lib.php';
51 /**
52 * file listing
54 require_once './libraries/file_listing.php';
57 /**
58 * Defines the url to return to in case of error in a sql statement
59 * (at this point, $GLOBALS['goto'] will be set but could be empty)
61 if (empty($GLOBALS['goto'])) {
62 if (strlen($table)) {
63 // avoid a problem (see bug #2202709)
64 $GLOBALS['goto'] = 'tbl_sql.php';
65 } else {
66 $GLOBALS['goto'] = 'db_sql.php';
69 /**
70 * @todo check if we could replace by "db_|tbl_" - please clarify!?
72 $_url_params = array(
73 'db' => $db,
74 'sql_query' => $sql_query
77 if (preg_match('@^tbl_@', $GLOBALS['goto'])) {
78 $_url_params['table'] = $table;
81 $err_url = $GLOBALS['goto'] . PMA_generate_common_url($_url_params);
82 unset($_url_params);
85 /**
86 * Sets parameters for links
87 * where is this variable used?
88 * replace by PMA_generate_common_url($url_params);
90 $url_query = PMA_generate_common_url($url_params, 'html', '');
92 /**
93 * get table information
94 * @todo should be done by a Table object
96 require_once './libraries/tbl_info.inc.php';
98 /**
99 * Get comments for table fileds/columns
101 $comments_map = array();
103 if ($GLOBALS['cfg']['ShowPropertyComments']) {
104 $comments_map = PMA_getComments($db, $table);
108 * START REGULAR OUTPUT
112 * used in ./libraries/header.inc.php to load JavaScript library file
114 $GLOBALS['js_include'][] = 'tbl_change.js';
117 * HTTP and HTML headers
119 require_once './libraries/header.inc.php';
122 * Displays the query submitted and its result
124 * @todo where does $disp_message and $disp_query come from???
126 if (! empty($disp_message)) {
127 if (! isset($disp_query)) {
128 $disp_query = null;
130 PMA_showMessage($disp_message, $disp_query);
134 * Displays top menu links
136 require_once './libraries/tbl_links.inc.php';
140 * Get the analysis of SHOW CREATE TABLE for this table
141 * @todo should be handled by class Table
143 $show_create_table = PMA_DBI_fetch_value(
144 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
145 0, 1);
146 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
147 unset($show_create_table);
150 * Get the list of the fields of the current table
152 PMA_DBI_select_db($db);
153 $table_fields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ';',
154 null, null, null, PMA_DBI_QUERY_STORE);
155 $rows = array();
156 if (isset($primary_key)) {
157 // when in edit mode load all selected rows from table
158 $insert_mode = false;
159 if (is_array($primary_key)) {
160 $primary_key_array = $primary_key;
161 } else {
162 $primary_key_array = array(0 => $primary_key);
165 $result = array();
166 $found_unique_key = false;
167 foreach ($primary_key_array as $key_id => $primary_key) {
168 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . str_replace('&#93;', ']', $primary_key) . ';';
169 $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE);
170 $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]);
171 $primary_keys[$key_id] = str_replace('\\', '\\\\', $primary_key);
173 // No row returned
174 if (! $rows[$key_id]) {
175 unset($rows[$key_id], $primary_key_array[$key_id]);
176 PMA_showMessage($strEmptyResultSet, $local_query);
177 echo "\n";
178 require_once './libraries/footer.inc.php';
179 } else { // end if (no record returned)
180 $meta = PMA_DBI_get_fields_meta($result[$key_id]);
181 if ($tmp = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true)) {
182 $found_unique_key = true;
184 unset($tmp);
187 } else {
188 // no primary key given, just load first row - but what happens if tbale is empty?
189 $insert_mode = true;
190 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
191 $rows = array_fill(0, $cfg['InsertRows'], false);
194 // <markus@noga.de>
195 // retrieve keys into foreign fields, if any
196 $foreigners = PMA_getForeigners($db, $table);
200 * Displays the form
202 // loic1: autocomplete feature of IE kills the "onchange" event handler and it
203 // must be replaced by the "onpropertychange" one in this case
204 $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5 && PMA_USR_BROWSER_VER < 7)
205 ? 'onpropertychange'
206 : 'onchange';
207 // Had to put the URI because when hosted on an https server,
208 // some browsers send wrongly this form to the http server.
210 if ($cfg['CtrlArrowsMoving']) {
212 <!-- Set on key handler for moving using by Ctrl+arrows -->
213 <script src="./js/keyhandler.js" type="text/javascript"></script>
214 <script type="text/javascript">
215 //<![CDATA[
216 var switch_movement = 0;
217 document.onkeydown = onKeyDownArrowsHandler;
218 //]]>
219 </script>
220 <?php
223 $_form_params = array(
224 'db' => $db,
225 'table' => $table,
226 'goto' => $GLOBALS['goto'],
227 'err_url' => $err_url,
228 'sql_query' => $sql_query,
230 if (isset($primary_keys)) {
231 foreach ($primary_key_array as $key_id => $primary_key) {
232 $_form_params['primary_key[' . $key_id . ']'] = trim($primary_key);
237 <!-- Insert/Edit form -->
238 <form method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?>>
239 <?php
240 echo PMA_generate_common_hidden_inputs($_form_params);
242 $titles['Browse'] = PMA_getIcon('b_browse.png', $strBrowseForeignValues);
244 // Set if we passed the first timestamp field
245 $timestamp_seen = 0;
246 $fields_cnt = count($table_fields);
248 $tabindex = 0;
249 $tabindex_for_function = +3000;
250 $tabindex_for_null = +6000;
251 $tabindex_for_value = 0;
252 $o_rows = 0;
253 $biggest_max_file_size = 0;
255 // user can toggle the display of Function column
256 // (currently does not work for multi-edits)
257 $url_params['db'] = $db;
258 $url_params['table'] = $table;
259 if (isset($primary_key)) {
260 $url_params['primary_key'] = trim($primary_key);
262 if (! empty($sql_query)) {
263 $url_params['sql_query'] = $sql_query;
266 if (! $cfg['ShowFunctionFields']) {
267 $this_url_params = array_merge($url_params,
268 array('ShowFunctionFields' => 1));
269 echo $strShow . ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . $strFunction . '</a>' . "\n";
272 foreach ($rows as $row_id => $vrow) {
273 if ($vrow === false) {
274 unset($vrow);
277 $jsvkey = $row_id;
278 $browse_foreigners_uri = '&amp;pk=' . $row_id;
279 $vkey = '[multi_edit][' . $jsvkey . ']';
281 $vresult = (isset($result) && is_array($result) && isset($result[$row_id]) ? $result[$row_id] : $result);
282 if ($insert_mode && $row_id > 0) {
283 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $row_id . '" id="insert_ignore_check_' . $row_id . '" />';
284 echo '<label for="insert_ignore_check_' . $row_id . '">' . $strIgnore . '</label><br />' . "\n";
287 <table>
288 <thead>
289 <tr>
290 <th><?php echo $strField; ?></th>
291 <th><?php echo $strType; ?></th>
292 <?php
293 if ($cfg['ShowFunctionFields']) {
294 $this_url_params = array_merge($url_params,
295 array('ShowFunctionFields' => 0));
296 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . $strHide . '">' . $strFunction . '</a></th>' . "\n";
299 <th><?php echo $strNull; ?></th>
300 <th><?php echo $strValue; ?></th>
301 </tr>
302 </thead>
303 <tfoot>
304 <tr>
305 <th colspan="5" align="right" class="tblFooters">
306 <input type="submit" value="<?php echo $strGo; ?>" />
307 </th>
308 </tr>
309 </tfoot>
310 <tbody>
311 <?php
312 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
313 $m_rows = $o_rows + 1;
315 $odd_row = true;
316 for ($i = 0; $i < $fields_cnt; $i++) {
317 if (! isset($table_fields[$i]['processed'])) {
318 $table_fields[$i]['Field_html'] = htmlspecialchars($table_fields[$i]['Field']);
319 $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']);
320 // True_Type contains only the type (stops at first bracket)
321 $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']);
323 // d a t e t i m e
325 // loic1: current date should not be set as default if the field is NULL
326 // for the current row
327 // lem9: but do not put here the current datetime if there is a default
328 // value (the real default value will be set in the
329 // Default value logic below)
331 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
332 // $field['Default'] is not set if it contains NULL:
333 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime)
334 // but, look what we get if we switch to iso: (Default is NULL)
335 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime)
336 // so I force a NULL into it (I don't think it's possible
337 // to have an empty default value for DATETIME)
338 // then, the "if" after this one will work
339 if ($table_fields[$i]['Type'] == 'datetime'
340 && ! isset($table_fields[$i]['Default'])
341 && isset($table_fields[$i]['Null'])
342 && $table_fields[$i]['Null'] == 'YES') {
343 $table_fields[$i]['Default'] = null;
346 $table_fields[$i]['len'] =
347 preg_match('@float|double@', $table_fields[$i]['Type']) ? 100 : -1;
350 if (isset($comments_map[$table_fields[$i]['Field']])) {
351 $table_fields[$i]['Field_title'] = '<span style="border-bottom: 1px dashed black;" title="'
352 . htmlspecialchars($comments_map[$table_fields[$i]['Field']]) . '">'
353 . $table_fields[$i]['Field_html'] . '</span>';
354 } else {
355 $table_fields[$i]['Field_title'] = $table_fields[$i]['Field_html'];
358 // The type column
359 $table_fields[$i]['is_binary'] = stristr($table_fields[$i]['Type'], 'binary');
360 $table_fields[$i]['is_blob'] = stristr($table_fields[$i]['Type'], 'blob');
361 $table_fields[$i]['is_char'] = stristr($table_fields[$i]['Type'], 'char');
362 $table_fields[$i]['first_timestamp'] = false;
363 switch ($table_fields[$i]['True_Type']) {
364 case 'set':
365 $table_fields[$i]['pma_type'] = 'set';
366 $table_fields[$i]['wrap'] = '';
367 break;
368 case 'enum':
369 $table_fields[$i]['pma_type'] = 'enum';
370 $table_fields[$i]['wrap'] = '';
371 break;
372 case 'timestamp':
373 if (!$timestamp_seen) { // can only occur once per table
374 $timestamp_seen = 1;
375 $table_fields[$i]['first_timestamp'] = true;
377 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
378 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
379 break;
381 default:
382 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
383 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
384 break;
387 $field = $table_fields[$i];
388 $extracted_fieldspec = PMA_extractFieldSpec($field['Type']);
390 if (-1 === $field['len']) {
391 $field['len'] = PMA_DBI_field_len($vresult, $i);
394 $unnullify_trigger = $chg_evt_handler . "=\"return unNullify('"
395 . PMA_escapeJsString($field['Field_html']) . "', '"
396 . PMA_escapeJsString($jsvkey) . "')\"";
397 $field_name_appendix = $vkey . '[' . $field['Field_html'] . ']';
398 $field_name_appendix_md5 = $field['Field_md5'] . $vkey . '[]';
401 if ($field['Type'] == 'datetime'
402 && ! isset($field['Default'])
403 && ! is_null($field['Default'])
404 && ($insert_mode || ! isset($vrow[$field['Field']]))) {
405 // INSERT case or
406 // UPDATE case with an NULL value
407 $vrow[$field['Field']] = date('Y-m-d H:i:s', time());
410 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
411 <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($field['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center"><?php echo $field['Field_title']; ?></td>
412 <td align="center"<?php echo $field['wrap']; ?>>
413 <?php echo $field['pma_type']; ?>
414 </td>
416 <?php
418 // Prepares the field value
419 $real_null_value = FALSE;
420 $special_chars_encoded = '';
421 if (isset($vrow)) {
422 // On a BLOB that can have a NULL value, the is_null() returns
423 // true if it has no content but for me this is different than
424 // having been set explicitely to NULL so I put an exception here
425 if (! $field['is_blob'] && is_null($vrow[$field['Field']])) {
426 $real_null_value = TRUE;
427 $vrow[$field['Field']] = '';
428 $special_chars = '';
429 $data = $vrow[$field['Field']];
430 } elseif ($field['True_Type'] == 'bit') {
431 $special_chars = PMA_printable_bit_value($vrow[$field['Field']], $extracted_fieldspec['spec_in_brackets']);
432 } else {
433 // loic1: special binary "characters"
434 if ($field['is_binary'] || $field['is_blob']) {
435 $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]);
436 } // end if
437 $special_chars = htmlspecialchars($vrow[$field['Field']]);
439 //We need to duplicate the first \n or otherwise we will lose the first newline entered in a VARCHAR or TEXT column
440 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
442 $data = $vrow[$field['Field']];
443 } // end if... else...
444 // loic1: if a timestamp field value is not included in an update
445 // statement MySQL auto-update it to the current timestamp
446 // lem9: however, things have changed since MySQL 4.1, so
447 // it's better to set a fields_prev in this situation
448 $backup_field = '<input type="hidden" name="fields_prev'
449 . $field_name_appendix . '" value="'
450 . htmlspecialchars($vrow[$field['Field']]) . '" />';
451 } else {
452 // loic1: display default values
453 if (!isset($field['Default'])) {
454 $field['Default'] = '';
455 $real_null_value = TRUE;
456 $data = '';
457 } else {
458 $data = $field['Default'];
460 if ($field['True_Type'] == 'bit') {
461 $special_chars = PMA_printable_bit_value($field['Default'], $extracted_fieldspec['spec_in_brackets']);
462 } else {
463 $special_chars = htmlspecialchars($field['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'] && $field['is_blob'] && !$is_upload)
480 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
481 echo ' <td align="center">' . $strBinary . '</td>' . "\n";
482 } elseif (strstr($field['True_Type'], 'enum') || strstr($field['True_Type'], 'set')) {
483 echo ' <td align="center">--</td>' . "\n";
484 } else {
486 <td>
487 <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">
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['RestrictColumnTypes'][strtoupper($field['True_Type'])])
496 && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])]])) {
497 $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])];
498 $dropdown = $cfg['RestrictFunctions'][$current_func_type];
499 $default_function = $cfg['DefaultFunctions'][$current_func_type];
500 } else {
501 $dropdown = array();
502 $default_function = '';
505 $dropdown_built = array();
506 $op_spacing_needed = FALSE;
508 // what function defined as default?
509 // for the first timestamp we don't set the default function
510 // if there is a default value for the timestamp
511 // (not including CURRENT_TIMESTAMP)
512 // and the column does not have the
513 // ON UPDATE DEFAULT TIMESTAMP attribute.
515 if ($field['True_Type'] == 'timestamp'
516 && empty($field['Default'])
517 && ! isset($analyzed_sql[0]['create_table_fields'][$field['Field']]['on_update_current_timestamp'])) {
518 $default_function = $cfg['DefaultFunctions']['first_timestamp'];
521 if ($field['Key'] == 'PRI'
522 && ($field['Type'] == 'char(36)' || $field['Type'] == 'varchar(36)')) {
523 $default_function = $cfg['DefaultFunctions']['pk_char36'];
526 // garvin: loop on the dropdown array and print all available options for that field.
527 foreach ($dropdown as $each_dropdown){
528 echo '<option';
529 if ($default_function === $each_dropdown) {
530 echo ' selected="selected"';
532 echo '>' . $each_dropdown . '</option>' . "\n";
533 $dropdown_built[$each_dropdown] = 'TRUE';
534 $op_spacing_needed = TRUE;
537 // garvin: For compatibility's sake, do not let out all other functions. Instead
538 // print a separator (blank) and then show ALL functions which weren't shown
539 // yet.
540 $cnt_functions = count($cfg['Functions']);
541 for ($j = 0; $j < $cnt_functions; $j++) {
542 if (!isset($dropdown_built[$cfg['Functions'][$j]]) || $dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
543 // Is current function defined as default?
544 $selected = ($field['first_timestamp'] && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
545 || (!$field['first_timestamp'] && $cfg['Functions'][$j] == $default_function)
546 ? ' selected="selected"'
547 : '';
548 if ($op_spacing_needed == TRUE) {
549 echo ' ';
550 echo '<option value="">--------</option>' . "\n";
551 $op_spacing_needed = FALSE;
554 echo ' ';
555 echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
557 } // end for
558 unset($selected);
560 </select>
561 </td>
562 <?php
564 } // end if ($cfg['ShowFunctionFields'])
567 // The null column
568 // ---------------
569 $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', '');
570 echo ' <td>' . "\n";
571 if ($field['Null'] == 'YES') {
572 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
573 if ($real_null_value && !$field['first_timestamp']) {
574 echo ' value="on"';
576 echo ' />' . "\n";
578 if (!(($cfg['ProtectBinary'] && $field['is_blob']) || ($cfg['ProtectBinary'] == 'all' && $field['is_binary']))) {
580 echo ' <input type="checkbox" tabindex="' . ($tabindex + $tabindex_for_null) . '"'
581 . ' name="fields_null' . $field_name_appendix . '"';
582 if ($real_null_value && !$field['first_timestamp']) {
583 echo ' checked="checked"';
585 echo ' id="field_' . ($idindex) . '_2"';
586 $onclick = ' onclick="if (this.checked) {nullify(';
587 if (strstr($field['True_Type'], 'enum')) {
588 if (strlen($field['Type']) > 20) {
589 $onclick .= '1, ';
590 } else {
591 $onclick .= '2, ';
593 } elseif (strstr($field['True_Type'], 'set')) {
594 $onclick .= '3, ';
595 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == false) {
596 // foreign key in a drop-down
597 $onclick .= '4, ';
598 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == true) {
599 // foreign key with a browsing icon
600 $onclick .= '6, ';
601 } else {
602 $onclick .= '5, ';
604 $onclick .= '\'' . PMA_escapeJsString($field['Field_html']) . '\', \'' . $field['Field_md5'] . '\', \'' . PMA_escapeJsString($vkey) . '\'); this.checked = true}; return true" />' . "\n";
605 echo $onclick;
606 } else {
607 echo ' <input type="hidden" name="fields_null' . $field_name_appendix . '"';
608 if ($real_null_value && !$field['first_timestamp']) {
609 echo ' value="on"';
611 echo ' />' . "\n";
614 echo ' </td>' . "\n";
616 // The value column (depends on type)
617 // ----------------
618 // See bug #1667887 for the reason why we don't use the maxlength
619 // HTML attribute
621 echo ' <td>' . "\n";
622 if ($foreignData['foreign_link'] == true) {
623 echo $backup_field . "\n";
625 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
626 value="foreign" />
627 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
628 value="" id="field_<?php echo ($idindex); ?>_3A" />
629 <input type="text" name="field_<?php echo $field_name_appendix_md5; ?>"
630 class="textfield" <?php echo $unnullify_trigger; ?>
631 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
632 id="field_<?php echo ($idindex); ?>_3"
633 value="<?php echo htmlspecialchars($data); ?>" />
634 <script type="text/javascript">
635 //<![CDATA[
636 document.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes,resizable=yes\'); return false"');
637 document.write(' href="browse_foreigners.php?');
638 document.write('<?php echo PMA_generate_common_url($db, $table); ?>');
639 document.writeln('&amp;field=<?php echo PMA_escapeJsString(urlencode($field['Field']) . $browse_foreigners_uri); ?>">');
640 document.writeln('<?php echo str_replace("'", "\'", $titles['Browse']); ?></a>');
641 //]]>
642 </script>
643 <?php
644 } elseif (is_array($foreignData['disp_row'])) {
645 echo $backup_field . "\n";
647 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
648 value="foreign" />
649 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
650 value="" id="field_<?php echo $idindex; ?>_3A" />
651 <select name="field_<?php echo $field_name_appendix_md5; ?>"
652 <?php echo $unnullify_trigger; ?>
653 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
654 id="field_<?php echo ($idindex); ?>_3">
655 <?php echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?>
656 </select>
657 <?php
658 // still needed? :
659 unset($foreignData['disp_row']);
660 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
662 &nbsp;</td>
663 </tr>
664 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
665 <td colspan="5" align="right">
666 <?php echo $backup_field . "\n"; ?>
667 <textarea name="fields<?php echo $field_name_appendix; ?>"
668 rows="<?php echo ($cfg['TextareaRows']*2); ?>"
669 cols="<?php echo ($cfg['TextareaCols']*2); ?>"
670 dir="<?php echo $text_dir; ?>"
671 id="field_<?php echo ($idindex); ?>_3"
672 <?php echo $unnullify_trigger; ?>
673 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
674 ><?php echo $special_chars_encoded; ?></textarea>
675 <?php
676 } elseif (strstr($field['pma_type'], 'text')) {
677 echo $backup_field . "\n";
679 <textarea name="fields<?php echo $field_name_appendix; ?>"
680 rows="<?php echo $cfg['TextareaRows']; ?>"
681 cols="<?php echo $cfg['TextareaCols']; ?>"
682 dir="<?php echo $text_dir; ?>"
683 id="field_<?php echo ($idindex); ?>_3"
684 <?php echo $unnullify_trigger; ?>
685 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
686 ><?php echo $special_chars_encoded; ?></textarea>
687 <?php
688 echo "\n";
689 if (strlen($special_chars) > 32000) {
690 echo " </td>\n";
691 echo ' <td>' . $strTextAreaLength;
693 } elseif ($field['pma_type'] == 'enum') {
694 if (! isset($table_fields[$i]['values'])) {
695 $table_fields[$i]['values'] = array();
696 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
697 // Removes automatic MySQL escape format
698 $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
699 $table_fields[$i]['values'][] = array(
700 'plain' => $val,
701 'html' => htmlspecialchars($val),
705 $field_enum_values = $table_fields[$i]['values'];
707 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="enum" />
708 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
709 <?php
710 echo "\n" . ' ' . $backup_field . "\n";
712 // show dropdown or radio depend on length
713 if (strlen($field['Type']) > 20) {
715 <select name="field_<?php echo $field_name_appendix_md5; ?>"
716 <?php echo $unnullify_trigger; ?>
717 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
718 id="field_<?php echo ($idindex); ?>_3">
719 <option value="">&nbsp;</option>
720 <?php
721 echo "\n";
723 foreach ($field_enum_values as $enum_value) {
724 echo ' ';
725 echo '<option value="' . $enum_value['html'] . '"';
726 if ($data == $enum_value['plain']
727 || ($data == ''
728 && (! isset($primary_key) || $field['Null'] != 'YES')
729 && isset($field['Default'])
730 && $enum_value['plain'] == $field['Default'])) {
731 echo ' selected="selected"';
733 echo '>' . $enum_value['html'] . '</option>' . "\n";
734 } // end for
737 </select>
738 <?php
739 } else {
740 $j = 0;
741 foreach ($field_enum_values as $enum_value) {
742 echo ' ';
743 echo '<input type="radio" name="field_' . $field_name_appendix_md5 . '"';
744 echo ' value="' . $enum_value['html'] . '"';
745 echo ' id="field_' . ($idindex) . '_3_' . $j . '"';
746 echo ' onclick="';
747 echo "if (typeof(document.forms['insertForm'].elements['fields_null"
748 . $field_name_appendix . "']) != 'undefined') {document.forms['insertForm'].elements['fields_null"
749 . $field_name_appendix . "'].checked = false}";
750 echo '"';
751 if ($data == $enum_value['plain']
752 || ($data == ''
753 && (! isset($primary_key) || $field['Null'] != 'YES')
754 && isset($field['Default'])
755 && $enum_value['plain'] == $field['Default'])) {
756 echo ' checked="checked"';
758 echo ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
759 echo '<label for="field_' . $idindex . '_3_' . $j . '">'
760 . $enum_value['html'] . '</label>' . "\n";
761 $j++;
762 } // end for
763 } // end else
764 } elseif ($field['pma_type'] == 'set') {
765 if (! isset($table_fields[$i]['values'])) {
766 $table_fields[$i]['values'] = array();
767 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
768 $table_fields[$i]['values'][] = array(
769 'plain' => $val,
770 'html' => htmlspecialchars($val),
773 $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
775 $field_set_values = $table_fields[$i]['values'];
776 $select_size = $table_fields[$i]['select_size'];
778 $vset = array_flip(explode(',', $data));
779 echo $backup_field . "\n";
781 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="set" />
782 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
783 <select name="field_<?php echo $field_name_appendix_md5; ?>"
784 size="<?php echo $select_size; ?>"
785 multiple="multiple" <?php echo $unnullify_trigger; ?>
786 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
787 id="field_<?php echo ($idindex); ?>_3">
788 <?php
789 foreach ($field_set_values as $field_set_value) {
790 echo ' ';
791 echo '<option value="' . $field_set_value['html'] . '"';
792 if (isset($vset[$field_set_value['plain']])) {
793 echo ' selected="selected"';
795 echo '>' . $field_set_value['html'] . '</option>' . "\n";
796 } // end for
798 </select>
799 <?php
801 // Change by Bernard M. Piller <bernard@bmpsystems.com>
802 // We don't want binary data destroyed
803 elseif ($field['is_binary'] || $field['is_blob']) {
804 if (($cfg['ProtectBinary'] && $field['is_blob'])
805 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
806 echo "\n";
807 // rajk - for blobstreaming
808 $bs_reference_exists = FALSE;
810 if (isset ($tbl_type) && strlen ($tbl_type) > 0)
812 // load PMA_Config
813 $PMA_Config = $_SESSION['PMA_Config'];
815 if (!empty($PMA_Config))
817 $requiredTblType = $PMA_Config->get('PBXT_NAME');
819 if ($requiredTblType == strtolower ($tbl_type))
821 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
823 // check if blobstreaming plugins exist
824 if ($pluginsExist)
826 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
828 if (!empty($bs_tables) && strlen($db) > 0)
830 $bs_tables = $bs_tables[$db];
832 if (isset($bs_tables))
834 $allBSTablesExist = TRUE;
836 foreach ($bs_tables as $table_key=>$bs_tbl)
837 if (!$bs_tables[$table_key]['Exists'])
839 $allBSTablesExist = FALSE;
840 break;
843 if ($allBSTablesExist)
844 $bs_reference_exists = PMA_BS_ReferenceExists($data, $db);
845 } // end if (isset($bs_tables))
846 } // end if (!empty($bs_tables) && strlen($db) > 0)
847 } // end if ($pluginsExist)
848 } // end if ($requiredTblType == strtolower ($tbl_type))
849 } // end if (!empty($PMA_Config))
850 } // end if (isset ($tbl_type) && strlen ($tbl_type) > 0)
852 if ($bs_reference_exists)
854 echo '<input type="hidden" name="remove_blob_ref_' . $field['Field_html'] . $vkey . '" value="' . $data . '" />';
855 echo '<input type="checkbox" name="remove_blob_repo_' . $field['Field_html'] . $vkey . '" /> ' . $strBLOBRepositoryRemove . "<br />";
856 echo PMA_BS_CreateReferenceLink($data, $db);
857 echo "<br />";
859 else
861 echo $strBinaryDoNotEdit;
862 if (isset($data)) {
863 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
864 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
865 unset($data_size);
867 echo "\n";
868 } // end if ($bs_reference_exists)
870 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="protected" />
871 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
872 <?php
873 } elseif ($field['is_blob']) {
874 echo "\n";
875 echo $backup_field . "\n";
877 <textarea name="fields<?php echo $field_name_appendix; ?>"
878 rows="<?php echo $cfg['TextareaRows']; ?>"
879 cols="<?php echo $cfg['TextareaCols']; ?>"
880 dir="<?php echo $text_dir; ?>"
881 id="field_<?php echo ($idindex); ?>_3"
882 <?php echo $unnullify_trigger; ?>
883 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
884 ><?php echo $special_chars_encoded; ?></textarea>
885 <?php
887 } else {
888 // field size should be at least 4 and max 40
889 $fieldsize = min(max($field['len'], 4), 40);
890 echo "\n";
891 echo $backup_field . "\n";
893 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
894 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
895 class="textfield" <?php echo $unnullify_trigger; ?>
896 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
897 id="field_<?php echo ($idindex); ?>_3" />
898 <?php
899 } // end if...elseif...else
901 // Upload choice (only for BLOBs because the binary
902 // attribute does not imply binary contents)
903 // (displayed whatever value the ProtectBinary has)
905 if ($is_upload && $field['is_blob']) {
906 // added by rajk
907 // check if field type is of longblob
908 if ($field['pma_type'] == "longblob")
910 if (isset ($tbl_type) && strlen ($tbl_type) > 0)
912 // load PMA Config
913 $PMA_Config = $_SESSION['PMA_Config'];
915 // is PMA_Config's data loaded? continue only if it is
916 if (!empty($PMA_Config))
918 $requiredTblType = $PMA_Config->get('PBXT_NAME');
920 if ($requiredTblType == strtolower ($tbl_type))
922 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
924 // check if blobstreaming plugins exist
925 if ($pluginsExist)
927 $curlExists = $PMA_Config->get('CURL_EXISTS');
929 // check if CURL exists
930 if ($curlExists)
932 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
934 // check for BLOBStreamable databases and if current database name is provided
935 if (!empty($bs_tables) && strlen($db) > 0)
937 $bs_tables = $bs_tables[$db];
939 // check if reference to BLOBStreaming tables exists
940 if (isset($bs_tables))
942 $allBSTablesExist = TRUE;
944 foreach ($bs_tables as $table_key=>$bs_tbl)
945 if (!$bs_tables[$table_key]['Exists'])
947 $allBSTablesExist = FALSE;
948 break;
951 // check if necessary BLOBStreaming tables exist
952 if ($allBSTablesExist)
954 echo '<br />';
955 echo '<input type="checkbox" name="upload_blob_repo_' . $field['Field_html'] . $vkey . '" /> ' . $strBLOBRepositoryUpload;
956 } // end if ($allBSTablesExist)
957 } // end if (isset($bs_tables)
958 } // end if (!empty($bs_tables) && strlen ($db) > 0)
959 } // end if ($curlExists)
960 } // end if ($pluginsExist)
961 } // end if ($requiredTblType == strtolower ($tbl_type))
962 } // end if (!empty($PMA_Config))
963 } // end if (isset ($tbl_type) && strlen ($tbl_type) > 0)
966 echo '<br />';
967 echo '<input type="file" name="fields_upload_' . $field['Field_html'] . $vkey . '" class="textfield" id="field_' . $idindex . '_3" size="10" />&nbsp;';
969 // find maximum upload size, based on field type
971 * @todo with functions this is not so easy, as you can basically
972 * process any data with function like MD5
974 $max_field_sizes = array(
975 'tinyblob' => '256',
976 'blob' => '65536',
977 'mediumblob' => '16777216',
978 'longblob' => '4294967296'); // yeah, really
980 $this_field_max_size = $max_upload_size; // from PHP max
981 if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
982 $this_field_max_size = $max_field_sizes[$field['pma_type']];
984 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
985 // do not generate here the MAX_FILE_SIZE, because we should
986 // put only one in the form to accommodate the biggest field
987 if ($this_field_max_size > $biggest_max_file_size) {
988 $biggest_max_file_size = $this_field_max_size;
992 if (!empty($cfg['UploadDir'])) {
993 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
994 if ($files === FALSE) {
995 echo ' <font color="red">' . $strError . '</font><br />' . "\n";
996 echo ' ' . $strWebServerUploadDirectoryError . "\n";
997 } elseif (!empty($files)) {
998 echo "<br />\n";
999 echo ' <i>' . $strOr . '</i>' . ' ' . $strWebServerUploadDirectory . ':<br />' . "\n";
1000 echo ' <select size="1" name="fields_uploadlocal_' . $field['Field_html'] . $vkey . '">' . "\n";
1001 echo ' <option value="" selected="selected"></option>' . "\n";
1002 echo $files;
1003 echo ' </select>' . "\n";
1005 } // end if (web-server upload directory)
1006 } // end elseif (binary or blob)
1007 else {
1008 // field size should be at least 4 and max 40
1009 $fieldsize = min(max($field['len'], 4), 40);
1010 echo $backup_field . "\n";
1011 if ($field['is_char'] && ($cfg['CharEditing'] == 'textarea' || strpos($data, "\n") !== FALSE)) {
1012 echo "\n";
1014 <textarea name="fields<?php echo $field_name_appendix; ?>"
1015 rows="<?php echo $cfg['CharTextareaRows']; ?>"
1016 cols="<?php echo $cfg['CharTextareaCols']; ?>"
1017 dir="<?php echo $text_dir; ?>"
1018 id="field_<?php echo ($idindex); ?>_3"
1019 <?php echo $unnullify_trigger; ?>
1020 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
1021 ><?php echo $special_chars_encoded; ?></textarea>
1022 <?php
1023 } else {
1025 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
1026 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
1027 class="textfield" <?php echo $unnullify_trigger; ?>
1028 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
1029 id="field_<?php echo ($idindex); ?>_3" />
1030 <?php
1031 if ($field['Extra'] == 'auto_increment') {
1033 <input type="hidden" name="auto_increment<?php echo $field_name_appendix; ?>" value="1" />
1034 <?php
1035 } // end if
1036 if (substr($field['pma_type'], 0, 9) == 'timestamp') {
1038 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="timestamp" />
1039 <?php
1041 if ($field['True_Type'] == 'bit') {
1043 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="bit" />
1044 <?php
1046 if ($field['pma_type'] == 'date' || $field['pma_type'] == 'datetime' || substr($field['pma_type'], 0, 9) == 'timestamp') {
1048 <script type="text/javascript">
1049 //<![CDATA[
1050 document.write('<a title="<?php echo $strCalendar;?>"');
1051 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); ?>\')">');
1052 document.write('<img class="calendar"');
1053 document.write(' src="<?php echo $pmaThemeImage; ?>b_calendar.png"');
1054 document.write(' alt="<?php echo $strCalendar; ?>"/></a>');
1055 //]]>
1056 </script>
1057 <?php
1062 </td>
1063 </tr>
1064 <?php
1065 $odd_row = !$odd_row;
1066 } // end for
1067 $o_rows++;
1068 echo ' </tbody></table><br />';
1069 } // end foreach on multi-edit
1071 <br />
1073 <fieldset>
1074 <table border="0" cellpadding="5" cellspacing="0">
1075 <tr>
1076 <td valign="middle" nowrap="nowrap">
1077 <select name="submit_type" tabindex="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
1078 <?php
1079 if (isset($primary_key)) {
1081 <option value="<?php echo $strSave; ?>"><?php echo $strSave; ?></option>
1082 <?php
1085 <option value="<?php echo $strInsertAsNewRow; ?>"><?php echo $strInsertAsNewRow; ?></option>
1086 </select>
1087 <?php
1088 echo "\n";
1090 if (!isset($after_insert)) {
1091 $after_insert = 'back';
1094 </td>
1095 <td valign="middle">
1096 &nbsp;&nbsp;&nbsp;<strong><?php echo $strAndThen; ?></strong>&nbsp;&nbsp;&nbsp;
1097 </td>
1098 <td valign="middle" nowrap="nowrap">
1099 <select name="after_insert">
1100 <option value="back" <?php echo ($after_insert == 'back' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertBack; ?></option>
1101 <option value="new_insert" <?php echo ($after_insert == 'new_insert' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertNewInsert; ?></option>
1102 <?php
1103 if (isset($primary_key)) {
1105 <option value="same_insert" <?php echo ($after_insert == 'same_insert' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertSame; ?></option>
1106 <?php
1107 // If we have just numeric primary key, we can also edit next
1108 // in 2.8.2, we were looking for `field_name` = numeric_value
1109 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $primary_key)) {
1110 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1111 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $primary_key)) {
1113 <option value="edit_next" <?php echo ($after_insert == 'edit_next' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertNext; ?></option>
1114 <?php
1118 </select>
1119 </td>
1120 </tr>
1122 <tr>
1123 <td>
1124 <?php echo PMA_showHint($strUseTabKey); ?>
1125 </td>
1126 <td colspan="3" align="right" valign="middle">
1127 <input type="submit" value="<?php echo $strGo; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 6); ?>" id="buttonYes" />
1128 <input type="reset" value="<?php echo $strReset; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 7); ?>" />
1129 </td>
1130 </tr>
1131 </table>
1132 </fieldset>
1133 <?php if ($biggest_max_file_size > 0) {
1134 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
1135 } ?>
1136 </form>
1137 <?php
1138 if ($insert_mode) {
1140 <!-- Restart insertion form -->
1141 <form method="post" action="tbl_replace.php" name="restartForm" >
1142 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
1143 <input type="hidden" name="goto" value="<?php echo htmlspecialchars($GLOBALS['goto']); ?>" />
1144 <input type="hidden" name="err_url" value="<?php echo htmlspecialchars($err_url); ?>" />
1145 <input type="hidden" name="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
1146 <?php
1147 if (isset($primary_keys)) {
1148 foreach ($primary_key_array as $key_id => $primary_key) {
1149 echo '<input type="hidden" name="primary_key[' . $key_id . ']" value="' . htmlspecialchars(trim($primary_key)) . '" />'. "\n";
1152 $tmp = '<select name="insert_rows" id="insert_rows" onchange="this.form.submit();" >' . "\n";
1153 $option_values = array(1,2,5,10,15,20,30,40);
1154 foreach ($option_values as $value) {
1155 $tmp .= '<option value="' . $value . '"';
1156 if ($value == $cfg['InsertRows']) {
1157 $tmp .= ' selected="selected"';
1159 $tmp .= '>' . $value . '</option>' . "\n";
1161 $tmp .= '</select>' . "\n";
1162 echo "\n" . sprintf($strRestartInsertion, $tmp);
1163 unset($tmp);
1164 echo '<noscript><input type="submit" value="' . $strGo . '" /></noscript>' . "\n";
1165 echo '</form>' . "\n";
1169 * Displays the footer
1171 require_once './libraries/footer.inc.php';