patch #2255890 [lang] English-language cleanup
[phpmyadmin/crack.git] / tbl_change.php
blobc07e3ad9d73a723d12d1152834e91c2979025a3a
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 $GLOBALS['goto'] = 'db_sql.php';
64 /**
65 * @todo check if we could replace by "db_|tbl_" - please clarify!?
67 $_url_params = array(
68 'db' => $db,
69 'sql_query' => $sql_query
72 if (preg_match('@^tbl_@', $GLOBALS['goto'])) {
73 $_url_params['table'] = $table;
76 $err_url = $GLOBALS['goto'] . PMA_generate_common_url($_url_params);
77 unset($_url_params);
80 /**
81 * Sets parameters for links
82 * where is this variable used?
83 * replace by PMA_generate_common_url($url_params);
85 $url_query = PMA_generate_common_url($url_params, 'html', '');
87 /**
88 * get table information
89 * @todo should be done by a Table object
91 require_once './libraries/tbl_info.inc.php';
93 /**
94 * Get comments for table fileds/columns
96 $comments_map = array();
98 if ($GLOBALS['cfg']['ShowPropertyComments']) {
99 $comments_map = PMA_getComments($db, $table);
103 * START REGULAR OUTPUT
107 * used in ./libraries/header.inc.php to load JavaScript library file
109 $GLOBALS['js_include'][] = 'tbl_change.js';
112 * HTTP and HTML headers
114 require_once './libraries/header.inc.php';
117 * Displays the query submitted and its result
119 * @todo where does $disp_message and $disp_query come from???
121 if (! empty($disp_message)) {
122 if (! isset($disp_query)) {
123 $disp_query = null;
125 PMA_showMessage($disp_message, $disp_query);
129 * Displays top menu links
131 require_once './libraries/tbl_links.inc.php';
135 * Get the analysis of SHOW CREATE TABLE for this table
136 * @todo should be handled by class Table
138 $show_create_table = PMA_DBI_fetch_value(
139 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
140 0, 1);
141 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
142 unset($show_create_table);
145 * Get the list of the fields of the current table
147 PMA_DBI_select_db($db);
148 $table_fields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ';',
149 null, null, null, PMA_DBI_QUERY_STORE);
150 $rows = array();
151 if (isset($primary_key)) {
152 // when in edit mode load all selected rows from table
153 $insert_mode = false;
154 if (is_array($primary_key)) {
155 $primary_key_array = $primary_key;
156 } else {
157 $primary_key_array = array(0 => $primary_key);
160 $result = array();
161 $found_unique_key = false;
162 foreach ($primary_key_array as $key_id => $primary_key) {
163 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';';
164 $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE);
165 $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]);
166 $primary_keys[$key_id] = str_replace('\\', '\\\\', $primary_key);
168 // No row returned
169 if (! $rows[$key_id]) {
170 unset($rows[$key_id], $primary_key_array[$key_id]);
171 PMA_showMessage($strEmptyResultSet, $local_query);
172 echo "\n";
173 require_once './libraries/footer.inc.php';
174 } else { // end if (no record returned)
175 $meta = PMA_DBI_get_fields_meta($result[$key_id]);
176 if ($tmp = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true)) {
177 $found_unique_key = true;
179 unset($tmp);
182 } else {
183 // no primary key given, just load first row - but what happens if tbale is empty?
184 $insert_mode = true;
185 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
186 $rows = array_fill(0, $cfg['InsertRows'], false);
189 // <markus@noga.de>
190 // retrieve keys into foreign fields, if any
191 $foreigners = PMA_getForeigners($db, $table);
195 * Displays the form
197 // loic1: autocomplete feature of IE kills the "onchange" event handler and it
198 // must be replaced by the "onpropertychange" one in this case
199 $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5 && PMA_USR_BROWSER_VER < 7)
200 ? 'onpropertychange'
201 : 'onchange';
202 // Had to put the URI because when hosted on an https server,
203 // some browsers send wrongly this form to the http server.
205 if ($cfg['CtrlArrowsMoving']) {
207 <!-- Set on key handler for moving using by Ctrl+arrows -->
208 <script src="./js/keyhandler.js" type="text/javascript"></script>
209 <script type="text/javascript">
210 //<![CDATA[
211 var switch_movement = 0;
212 document.onkeydown = onKeyDownArrowsHandler;
213 //]]>
214 </script>
215 <?php
218 $_form_params = array(
219 'db' => $db,
220 'table' => $table,
221 'goto' => $GLOBALS['goto'],
222 'err_url' => $err_url,
223 'sql_query' => $sql_query,
225 if (isset($primary_keys)) {
226 foreach ($primary_key_array as $key_id => $primary_key) {
227 $_form_params['primary_key[' . $key_id . ']'] = trim($primary_key);
232 <!-- Insert/Edit form -->
233 <form method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?>>
234 <?php
235 echo PMA_generate_common_hidden_inputs($_form_params);
237 $titles['Browse'] = PMA_getIcon('b_browse.png', $strBrowseForeignValues);
239 // Set if we passed the first timestamp field
240 $timestamp_seen = 0;
241 $fields_cnt = count($table_fields);
243 $tabindex = 0;
244 $tabindex_for_function = +3000;
245 $tabindex_for_null = +6000;
246 $tabindex_for_value = 0;
247 $o_rows = 0;
248 $biggest_max_file_size = 0;
250 // user can toggle the display of Function column
251 // (currently does not work for multi-edits)
252 $url_params['db'] = $db;
253 $url_params['table'] = $table;
254 if (isset($primary_key)) {
255 $url_params['primary_key'] = trim($primary_key);
257 if (! empty($sql_query)) {
258 $url_params['sql_query'] = $sql_query;
261 if (! $cfg['ShowFunctionFields']) {
262 $this_url_params = array_merge($url_params,
263 array('ShowFunctionFields' => 1));
264 echo $strShow . ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . $strFunction . '</a>' . "\n";
267 foreach ($rows as $row_id => $vrow) {
268 if ($vrow === false) {
269 unset($vrow);
272 $jsvkey = $row_id;
273 $browse_foreigners_uri = '&amp;pk=' . $row_id;
274 $vkey = '[multi_edit][' . $jsvkey . ']';
276 $vresult = (isset($result) && is_array($result) && isset($result[$row_id]) ? $result[$row_id] : $result);
277 if ($insert_mode && $row_id > 0) {
278 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $row_id . '" id="insert_ignore_check_' . $row_id . '" />';
279 echo '<label for="insert_ignore_check_' . $row_id . '">' . $strIgnore . '</label><br />' . "\n";
282 <table>
283 <thead>
284 <tr>
285 <th><?php echo $strField; ?></th>
286 <th><?php echo $strType; ?></th>
287 <?php
288 if ($cfg['ShowFunctionFields']) {
289 $this_url_params = array_merge($url_params,
290 array('ShowFunctionFields' => 0));
291 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . $strHide . '">' . $strFunction . '</a></th>' . "\n";
294 <th><?php echo $strNull; ?></th>
295 <th><?php echo $strValue; ?></th>
296 </tr>
297 </thead>
298 <tfoot>
299 <tr>
300 <th colspan="5" align="right" class="tblFooters">
301 <input type="submit" value="<?php echo $strGo; ?>" />
302 </th>
303 </tr>
304 </tfoot>
305 <tbody>
306 <?php
307 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
308 $m_rows = $o_rows + 1;
310 $odd_row = true;
311 for ($i = 0; $i < $fields_cnt; $i++) {
312 if (! isset($table_fields[$i]['processed'])) {
313 $table_fields[$i]['Field_html'] = htmlspecialchars($table_fields[$i]['Field']);
314 $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']);
315 // True_Type contains only the type (stops at first bracket)
316 $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']);
318 // d a t e t i m e
320 // loic1: current date should not be set as default if the field is NULL
321 // for the current row
322 // lem9: but do not put here the current datetime if there is a default
323 // value (the real default value will be set in the
324 // Default value logic below)
326 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
327 // $field['Default'] is not set if it contains NULL:
328 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime)
329 // but, look what we get if we switch to iso: (Default is NULL)
330 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime)
331 // so I force a NULL into it (I don't think it's possible
332 // to have an empty default value for DATETIME)
333 // then, the "if" after this one will work
334 if ($table_fields[$i]['Type'] == 'datetime'
335 && ! isset($table_fields[$i]['Default'])
336 && isset($table_fields[$i]['Null'])
337 && $table_fields[$i]['Null'] == 'YES') {
338 $table_fields[$i]['Default'] = null;
341 $table_fields[$i]['len'] =
342 preg_match('@float|double@', $table_fields[$i]['Type']) ? 100 : -1;
345 if (isset($comments_map[$table_fields[$i]['Field']])) {
346 $table_fields[$i]['Field_title'] = '<span style="border-bottom: 1px dashed black;" title="'
347 . htmlspecialchars($comments_map[$table_fields[$i]['Field']]) . '">'
348 . $table_fields[$i]['Field_html'] . '</span>';
349 } else {
350 $table_fields[$i]['Field_title'] = $table_fields[$i]['Field_html'];
353 // The type column
354 $table_fields[$i]['is_binary'] = stristr($table_fields[$i]['Type'], 'binary');
355 $table_fields[$i]['is_blob'] = stristr($table_fields[$i]['Type'], 'blob');
356 $table_fields[$i]['is_char'] = stristr($table_fields[$i]['Type'], 'char');
357 $table_fields[$i]['first_timestamp'] = false;
358 switch ($table_fields[$i]['True_Type']) {
359 case 'set':
360 $table_fields[$i]['pma_type'] = 'set';
361 $table_fields[$i]['wrap'] = '';
362 break;
363 case 'enum':
364 $table_fields[$i]['pma_type'] = 'enum';
365 $table_fields[$i]['wrap'] = '';
366 break;
367 case 'timestamp':
368 if (!$timestamp_seen) { // can only occur once per table
369 $timestamp_seen = 1;
370 $table_fields[$i]['first_timestamp'] = true;
372 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
373 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
374 break;
376 default:
377 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
378 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
379 break;
382 $field = $table_fields[$i];
383 $extracted_fieldspec = PMA_extractFieldSpec($field['Type']);
385 if (-1 === $field['len']) {
386 $field['len'] = PMA_DBI_field_len($vresult, $i);
389 $unnullify_trigger = $chg_evt_handler . "=\"return unNullify('"
390 . PMA_escapeJsString($field['Field_html']) . "', '"
391 . PMA_escapeJsString($jsvkey) . "')\"";
392 $field_name_appendix = $vkey . '[' . $field['Field_html'] . ']';
393 $field_name_appendix_md5 = $field['Field_md5'] . $vkey . '[]';
396 if ($field['Type'] == 'datetime'
397 && ! isset($field['Default'])
398 && ! is_null($field['Default'])
399 && ($insert_mode || ! isset($vrow[$field['Field']]))) {
400 // INSERT case or
401 // UPDATE case with an NULL value
402 $vrow[$field['Field']] = date('Y-m-d H:i:s', time());
405 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
406 <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($field['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center"><?php echo $field['Field_title']; ?></td>
407 <td align="center"<?php echo $field['wrap']; ?>>
408 <?php echo $field['pma_type']; ?>
409 </td>
411 <?php
413 // Prepares the field value
414 $real_null_value = FALSE;
415 if (isset($vrow)) {
416 // On a BLOB that can have a NULL value, the is_null() returns
417 // true if it has no content but for me this is different than
418 // having been set explicitely to NULL so I put an exception here
419 if (! $field['is_blob'] && is_null($vrow[$field['Field']])) {
420 $real_null_value = TRUE;
421 $vrow[$field['Field']] = '';
422 $special_chars = '';
423 $data = $vrow[$field['Field']];
424 } elseif ($field['True_Type'] == 'bit') {
425 $special_chars = PMA_printable_bit_value($vrow[$field], $extracted_fieldspec['spec_in_brackets']);
426 } else {
427 // loic1: special binary "characters"
428 if ($field['is_binary'] || $field['is_blob']) {
429 $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]);
430 } // end if
431 $special_chars = htmlspecialchars($vrow[$field['Field']]);
433 //We need to duplicate the first \n or otherwise we will lose the first newline entered in a VARCHAR or TEXT column
434 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
436 $data = $vrow[$field['Field']];
437 } // end if... else...
438 // loic1: if a timestamp field value is not included in an update
439 // statement MySQL auto-update it to the current timestamp
440 // lem9: however, things have changed since MySQL 4.1, so
441 // it's better to set a fields_prev in this situation
442 $backup_field = '<input type="hidden" name="fields_prev'
443 . $field_name_appendix . '" value="'
444 . htmlspecialchars($vrow[$field['Field']]) . '" />';
445 } else {
446 // loic1: display default values
447 if (!isset($field['Default'])) {
448 $field['Default'] = '';
449 $real_null_value = TRUE;
450 $data = '';
451 } else {
452 $data = $field['Default'];
454 if ($field['True_Type'] == 'bit') {
455 $special_chars = PMA_printable_bit_value($field['Default'], $extracted_fieldspec['spec_in_brackets']);
456 } else {
457 $special_chars = htmlspecialchars($field['Default']);
459 $backup_field = '';
462 $idindex = ($o_rows * $fields_cnt) + $i + 1;
463 $tabindex = (($idindex - 1) * 3) + 1;
465 // The function column
466 // -------------------
467 // Change by Bernard M. Piller <bernard@bmpsystems.com>
468 // We don't want binary data to be destroyed
469 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
470 // stored or retrieved" so it does not mean that the contents is
471 // binary
472 if ($cfg['ShowFunctionFields']) {
473 if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload)
474 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
475 echo ' <td align="center">' . $strBinary . '</td>' . "\n";
476 } elseif (strstr($field['True_Type'], 'enum') || strstr($field['True_Type'], 'set')) {
477 echo ' <td align="center">--</td>' . "\n";
478 } else {
480 <td>
481 <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">
482 <option></option>
483 <?php
484 $selected = '';
486 // garvin: Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
487 // or something similar. Then directly look up the entry in the RestrictFunctions array,
488 // which will then reveal the available dropdown options
489 if (isset($cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])])
490 && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])]])) {
491 $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])];
492 $dropdown = $cfg['RestrictFunctions'][$current_func_type];
493 $default_function = $cfg['DefaultFunctions'][$current_func_type];
494 } else {
495 $dropdown = array();
496 $default_function = '';
499 $dropdown_built = array();
500 $op_spacing_needed = FALSE;
502 // what function defined as default?
503 // for the first timestamp we don't set the default function
504 // if there is a default value for the timestamp
505 // (not including CURRENT_TIMESTAMP)
506 // and the column does not have the
507 // ON UPDATE DEFAULT TIMESTAMP attribute.
509 if ($field['True_Type'] == 'timestamp'
510 && empty($field['Default'])
511 && ! isset($analyzed_sql[0]['create_table_fields'][$field['Field']]['on_update_current_timestamp'])) {
512 $default_function = $cfg['DefaultFunctions']['first_timestamp'];
515 if ($field['Key'] == 'PRI'
516 && ($field['Type'] == 'char(36)' || $field['Type'] == 'varchar(36)')) {
517 $default_function = $cfg['DefaultFunctions']['pk_char36'];
520 // garvin: loop on the dropdown array and print all available options for that field.
521 foreach ($dropdown as $each_dropdown){
522 echo '<option';
523 if ($default_function === $each_dropdown) {
524 echo ' selected="selected"';
526 echo '>' . $each_dropdown . '</option>' . "\n";
527 $dropdown_built[$each_dropdown] = 'TRUE';
528 $op_spacing_needed = TRUE;
531 // garvin: For compatibility's sake, do not let out all other functions. Instead
532 // print a separator (blank) and then show ALL functions which weren't shown
533 // yet.
534 $cnt_functions = count($cfg['Functions']);
535 for ($j = 0; $j < $cnt_functions; $j++) {
536 if (!isset($dropdown_built[$cfg['Functions'][$j]]) || $dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
537 // Is current function defined as default?
538 $selected = ($field['first_timestamp'] && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
539 || (!$field['first_timestamp'] && $cfg['Functions'][$j] == $default_function)
540 ? ' selected="selected"'
541 : '';
542 if ($op_spacing_needed == TRUE) {
543 echo ' ';
544 echo '<option value="">--------</option>' . "\n";
545 $op_spacing_needed = FALSE;
548 echo ' ';
549 echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
551 } // end for
552 unset($selected);
554 </select>
555 </td>
556 <?php
558 } // end if ($cfg['ShowFunctionFields'])
561 // The null column
562 // ---------------
563 echo ' <td>' . "\n";
564 if ($field['Null'] == 'YES') {
565 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
566 if ($real_null_value && !$field['first_timestamp']) {
567 echo ' value="on"';
569 echo ' />' . "\n";
571 if (!(($cfg['ProtectBinary'] && $field['is_blob']) || ($cfg['ProtectBinary'] == 'all' && $field['is_binary']))) {
573 echo ' <input type="checkbox" tabindex="' . ($tabindex + $tabindex_for_null) . '"'
574 . ' name="fields_null' . $field_name_appendix . '"';
575 if ($real_null_value && !$field['first_timestamp']) {
576 echo ' checked="checked"';
578 echo ' id="field_' . ($idindex) . '_2"';
579 $onclick = ' onclick="if (this.checked) {nullify(';
580 if (strstr($field['True_Type'], 'enum')) {
581 if (strlen($field['Type']) > 20) {
582 $onclick .= '1, ';
583 } else {
584 $onclick .= '2, ';
586 } elseif (strstr($field['True_Type'], 'set')) {
587 $onclick .= '3, ';
588 } elseif ($foreigners && isset($foreigners[$field['Field']])) {
589 $onclick .= '4, ';
590 } else {
591 $onclick .= '5, ';
593 $onclick .= '\'' . PMA_escapeJsString($field['Field_html']) . '\', \'' . $field['Field_md5'] . '\', \'' . PMA_escapeJsString($vkey) . '\'); this.checked = true}; return true" />' . "\n";
594 echo $onclick;
595 } else {
596 echo ' <input type="hidden" name="fields_null' . $field_name_appendix . '"';
597 if ($real_null_value && !$field['first_timestamp']) {
598 echo ' value="on"';
600 echo ' />' . "\n";
603 echo ' </td>' . "\n";
605 // The value column (depends on type)
606 // ----------------
607 // See bug #1667887 for the reason why we don't use the maxlength
608 // HTML attribute
610 $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', '');
611 echo ' <td>' . "\n";
612 if ($foreignData['foreign_link'] == true) {
613 echo $backup_field . "\n";
615 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
616 value="foreign" />
617 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
618 value="" id="field_<?php echo ($idindex); ?>_3A" />
619 <input type="text" name="field_<?php echo $field_name_appendix_md5; ?>"
620 class="textfield" <?php echo $unnullify_trigger; ?>
621 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
622 id="field_<?php echo ($idindex); ?>_3"
623 value="<?php echo htmlspecialchars($data); ?>" />
624 <script type="text/javascript">
625 //<![CDATA[
626 document.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes,resizable=yes\'); return false"');
627 document.write(' href="browse_foreigners.php?');
628 document.write('<?php echo PMA_generate_common_url($db, $table); ?>');
629 document.writeln('&amp;field=<?php echo PMA_escapeJsString(urlencode($field['Field']) . $browse_foreigners_uri); ?>">');
630 document.writeln('<?php echo str_replace("'", "\'", $titles['Browse']); ?></a>');
631 //]]>
632 </script>
633 <?php
634 } elseif (is_array($foreignData['disp_row'])) {
635 echo $backup_field . "\n";
637 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
638 value="foreign" />
639 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
640 value="" id="field_<?php echo $idindex; ?>_3A" />
641 <select name="field_<?php echo $field_name_appendix_md5; ?>"
642 <?php echo $unnullify_trigger; ?>
643 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
644 id="field_<?php echo ($idindex); ?>_3">
645 <?php echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?>
646 </select>
647 <?php
648 // still needed? :
649 unset($foreignData['disp_row']);
650 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
652 &nbsp;</td>
653 </tr>
654 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
655 <td colspan="5" align="right">
656 <?php echo $backup_field . "\n"; ?>
657 <textarea name="fields<?php echo $field_name_appendix; ?>"
658 rows="<?php echo ($cfg['TextareaRows']*2); ?>"
659 cols="<?php echo ($cfg['TextareaCols']*2); ?>"
660 dir="<?php echo $text_dir; ?>"
661 id="field_<?php echo ($idindex); ?>_3"
662 <?php echo $unnullify_trigger; ?>
663 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
664 ><?php echo $special_chars_encoded; ?></textarea>
665 <?php
666 } elseif (strstr($field['pma_type'], 'text')) {
667 echo $backup_field . "\n";
669 <textarea name="fields<?php echo $field_name_appendix; ?>"
670 rows="<?php echo $cfg['TextareaRows']; ?>"
671 cols="<?php echo $cfg['TextareaCols']; ?>"
672 dir="<?php echo $text_dir; ?>"
673 id="field_<?php echo ($idindex); ?>_3"
674 <?php echo $unnullify_trigger; ?>
675 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
676 ><?php echo $special_chars_encoded; ?></textarea>
677 <?php
678 echo "\n";
679 if (strlen($special_chars) > 32000) {
680 echo " </td>\n";
681 echo ' <td>' . $strTextAreaLength;
683 } elseif ($field['pma_type'] == 'enum') {
684 if (! isset($table_fields[$i]['values'])) {
685 $table_fields[$i]['values'] = array();
686 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
687 // Removes automatic MySQL escape format
688 $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
689 $table_fields[$i]['values'][] = array(
690 'plain' => $val,
691 'html' => htmlspecialchars($val),
695 $field_enum_values = $table_fields[$i]['values'];
697 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="enum" />
698 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
699 <?php
700 echo "\n" . ' ' . $backup_field . "\n";
702 // show dropdown or radio depend on length
703 if (strlen($field['Type']) > 20) {
705 <select name="field_<?php echo $field_name_appendix_md5; ?>"
706 <?php echo $unnullify_trigger; ?>
707 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
708 id="field_<?php echo ($idindex); ?>_3">
709 <option value="">&nbsp;</option>
710 <?php
711 echo "\n";
713 foreach ($field_enum_values as $enum_value) {
714 echo ' ';
715 echo '<option value="' . $enum_value['html'] . '"';
716 if ($data == $enum_value['plain']
717 || ($data == ''
718 && (! isset($primary_key) || $field['Null'] != 'YES')
719 && isset($field['Default'])
720 && $enum_value['plain'] == $field['Default'])) {
721 echo ' selected="selected"';
723 echo '>' . $enum_value['html'] . '</option>' . "\n";
724 } // end for
727 </select>
728 <?php
729 } else {
730 $j = 0;
731 foreach ($field_enum_values as $enum_value) {
732 echo ' ';
733 echo '<input type="radio" name="field_' . $field_name_appendix_md5 . '"';
734 echo ' value="' . $enum_value['html'] . '"';
735 echo ' id="field_' . ($idindex) . '_3_' . $j . '"';
736 echo ' onclick="';
737 echo "if (typeof(document.forms['insertForm'].elements['fields_null"
738 . $field_name_appendix . "']) != 'undefined') {document.forms['insertForm'].elements['fields_null"
739 . $field_name_appendix . "'].checked = false}";
740 echo '"';
741 if ($data == $enum_value['plain']
742 || ($data == ''
743 && (! isset($primary_key) || $field['Null'] != 'YES')
744 && isset($field['Default'])
745 && $enum_value['plain'] == $field['Default'])) {
746 echo ' checked="checked"';
748 echo ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
749 echo '<label for="field_' . $idindex . '_3_' . $j . '">'
750 . $enum_value['html'] . '</label>' . "\n";
751 $j++;
752 } // end for
753 } // end else
754 } elseif ($field['pma_type'] == 'set') {
755 if (! isset($table_fields[$i]['values'])) {
756 $table_fields[$i]['values'] = array();
757 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
758 $table_fields[$i]['values'][] = array(
759 'plain' => $val,
760 'html' => htmlspecialchars($val),
763 $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
765 $field_set_values = $table_fields[$i]['values'];
766 $select_size = $table_fields[$i]['select_size'];
768 $vset = array_flip(explode(',', $data));
769 echo $backup_field . "\n";
771 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="set" />
772 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
773 <select name="field_<?php echo $field_name_appendix_md5; ?>"
774 size="<?php echo $select_size; ?>"
775 multiple="multiple" <?php echo $unnullify_trigger; ?>
776 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
777 id="field_<?php echo ($idindex); ?>_3">
778 <?php
779 foreach ($field_set_values as $field_set_value) {
780 echo ' ';
781 echo '<option value="' . $field_set_value['html'] . '"';
782 if (isset($vset[$field_set_value['plain']])) {
783 echo ' selected="selected"';
785 echo '>' . $field_set_value['html'] . '</option>' . "\n";
786 } // end for
788 </select>
789 <?php
791 // Change by Bernard M. Piller <bernard@bmpsystems.com>
792 // We don't want binary data destroyed
793 elseif ($field['is_binary'] || $field['is_blob']) {
794 if (($cfg['ProtectBinary'] && $field['is_blob'])
795 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
796 echo "\n";
797 // rajk - for blobstreaming
798 $bs_reference_exists = FALSE;
800 if (isset ($tbl_type) && strlen ($tbl_type) > 0)
802 // load PMA_Config
803 $PMA_Config = $_SESSION['PMA_Config'];
805 if (!empty($PMA_Config))
807 $requiredTblType = $PMA_Config->get('PBXT_NAME');
809 if ($requiredTblType == strtolower ($tbl_type))
811 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
813 // check if blobstreaming plugins exist
814 if ($pluginsExist)
816 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
818 if (!empty($bs_tables) && strlen($db) > 0)
820 $bs_tables = $bs_tables[$db];
822 if (isset($bs_tables))
824 $allBSTablesExist = TRUE;
826 foreach ($bs_tables as $table_key=>$bs_tbl)
827 if (!$bs_tables[$table_key]['Exists'])
829 $allBSTablesExist = FALSE;
830 break;
833 if ($allBSTablesExist)
834 $bs_reference_exists = PMA_BS_ReferenceExists($data, $db);
835 } // end if (isset($bs_tables))
836 } // end if (!empty($bs_tables) && strlen($db) > 0)
837 } // end if ($pluginsExist)
838 } // end if ($requiredTblType == strtolower ($tbl_type))
839 } // end if (!empty($PMA_Config))
840 } // end if (isset ($tbl_type) && strlen ($tbl_type) > 0)
842 if ($bs_reference_exists)
844 echo '<input type="hidden" name="remove_blob_ref_' . $field['Field_html'] . $vkey . '" value="' . $data . '" />';
845 echo '<input type="checkbox" name="remove_blob_repo_' . $field['Field_html'] . $vkey . '" /> ' . $strBLOBRepositoryRemove . "<br />";
846 echo PMA_BS_CreateReferenceLink($data, $db);
847 echo "<br />";
849 else
851 echo $strBinaryDoNotEdit;
852 if (isset($data)) {
853 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
854 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
855 unset($data_size);
857 echo "\n";
858 } // end if ($bs_reference_exists)
860 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="protected" />
861 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
862 <?php
863 } elseif ($field['is_blob']) {
864 echo "\n";
865 echo $backup_field . "\n";
867 <textarea name="fields<?php echo $field_name_appendix; ?>"
868 rows="<?php echo $cfg['TextareaRows']; ?>"
869 cols="<?php echo $cfg['TextareaCols']; ?>"
870 dir="<?php echo $text_dir; ?>"
871 id="field_<?php echo ($idindex); ?>_3"
872 <?php echo $unnullify_trigger; ?>
873 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
874 ><?php echo $special_chars_encoded; ?></textarea>
875 <?php
877 } else {
878 // field size should be at least 4 and max 40
879 $fieldsize = min(max($field['len'], 4), 40);
880 echo "\n";
881 echo $backup_field . "\n";
883 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
884 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
885 class="textfield" <?php echo $unnullify_trigger; ?>
886 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
887 id="field_<?php echo ($idindex); ?>_3" />
888 <?php
889 } // end if...elseif...else
891 // Upload choice (only for BLOBs because the binary
892 // attribute does not imply binary contents)
893 // (displayed whatever value the ProtectBinary has)
895 if ($is_upload && $field['is_blob']) {
896 // added by rajk
897 // check if field type is of longblob
898 if ($field['pma_type'] == "longblob")
900 if (isset ($tbl_type) && strlen ($tbl_type) > 0)
902 // load PMA Config
903 $PMA_Config = $_SESSION['PMA_Config'];
905 // is PMA_Config's data loaded? continue only if it is
906 if (!empty($PMA_Config))
908 $requiredTblType = $PMA_Config->get('PBXT_NAME');
910 if ($requiredTblType == strtolower ($tbl_type))
912 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
914 // check if blobstreaming plugins exist
915 if ($pluginsExist)
917 $curlExists = $PMA_Config->get('CURL_EXISTS');
919 // check if CURL exists
920 if ($curlExists)
922 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
924 // check for BLOBStreamable databases and if current database name is provided
925 if (!empty($bs_tables) && strlen($db) > 0)
927 $bs_tables = $bs_tables[$db];
929 // check if reference to BLOBStreaming tables exists
930 if (isset($bs_tables))
932 $allBSTablesExist = TRUE;
934 foreach ($bs_tables as $table_key=>$bs_tbl)
935 if (!$bs_tables[$table_key]['Exists'])
937 $allBSTablesExist = FALSE;
938 break;
941 // check if necessary BLOBStreaming tables exist
942 if ($allBSTablesExist)
944 echo '<br />';
945 echo '<input type="checkbox" name="upload_blob_repo_' . $field['Field_html'] . $vkey . '" /> ' . $strBLOBRepositoryUpload;
946 } // end if ($allBSTablesExist)
947 } // end if (isset($bs_tables)
948 } // end if (!empty($bs_tables) && strlen ($db) > 0)
949 } // end if ($curlExists)
950 } // end if ($pluginsExist)
951 } // end if ($requiredTblType == strtolower ($tbl_type))
952 } // end if (!empty($PMA_Config))
953 } // end if (isset ($tbl_type) && strlen ($tbl_type) > 0)
956 echo '<br />';
957 echo '<input type="file" name="fields_upload_' . $field['Field_html'] . $vkey . '" class="textfield" id="field_' . $idindex . '_3" size="10" />&nbsp;';
959 // find maximum upload size, based on field type
961 * @todo with functions this is not so easy, as you can basically
962 * process any data with function like MD5
964 $max_field_sizes = array(
965 'tinyblob' => '256',
966 'blob' => '65536',
967 'mediumblob' => '16777216',
968 'longblob' => '4294967296'); // yeah, really
970 $this_field_max_size = $max_upload_size; // from PHP max
971 if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
972 $this_field_max_size = $max_field_sizes[$field['pma_type']];
974 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
975 // do not generate here the MAX_FILE_SIZE, because we should
976 // put only one in the form to accommodate the biggest field
977 if ($this_field_max_size > $biggest_max_file_size) {
978 $biggest_max_file_size = $this_field_max_size;
982 if (!empty($cfg['UploadDir'])) {
983 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
984 if ($files === FALSE) {
985 echo ' <font color="red">' . $strError . '</font><br />' . "\n";
986 echo ' ' . $strWebServerUploadDirectoryError . "\n";
987 } elseif (!empty($files)) {
988 echo "<br />\n";
989 echo ' <i>' . $strOr . '</i>' . ' ' . $strWebServerUploadDirectory . ':<br />' . "\n";
990 echo ' <select size="1" name="fields_uploadlocal_' . $field['Field_html'] . $vkey . '">' . "\n";
991 echo ' <option value="" selected="selected"></option>' . "\n";
992 echo $files;
993 echo ' </select>' . "\n";
995 } // end if (web-server upload directory)
996 } // end elseif (binary or blob)
997 else {
998 // field size should be at least 4 and max 40
999 $fieldsize = min(max($field['len'], 4), 40);
1000 echo $backup_field . "\n";
1001 if ($field['is_char'] && ($cfg['CharEditing'] == 'textarea' || strpos($data, "\n") !== FALSE)) {
1002 echo "\n";
1004 <textarea name="fields<?php echo $field_name_appendix; ?>"
1005 rows="<?php echo $cfg['CharTextareaRows']; ?>"
1006 cols="<?php echo $cfg['CharTextareaCols']; ?>"
1007 dir="<?php echo $text_dir; ?>"
1008 id="field_<?php echo ($idindex); ?>_3"
1009 <?php echo $unnullify_trigger; ?>
1010 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
1011 ><?php echo $special_chars_encoded; ?></textarea>
1012 <?php
1013 } else {
1015 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
1016 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
1017 class="textfield" <?php echo $unnullify_trigger; ?>
1018 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
1019 id="field_<?php echo ($idindex); ?>_3" />
1020 <?php
1021 if ($field['Extra'] == 'auto_increment') {
1023 <input type="hidden" name="auto_increment<?php echo $field_name_appendix; ?>" value="1" />
1024 <?php
1025 } // end if
1026 if (substr($field['pma_type'], 0, 9) == 'timestamp') {
1028 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="timestamp" />
1029 <?php
1031 if ($field['True_Type'] == 'bit') {
1033 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="bit" />
1034 <?php
1036 if ($field['pma_type'] == 'date' || $field['pma_type'] == 'datetime' || substr($field['pma_type'], 0, 9) == 'timestamp') {
1038 <script type="text/javascript">
1039 //<![CDATA[
1040 document.write('<a title="<?php echo $strCalendar;?>"');
1041 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); ?>\')">');
1042 document.write('<img class="calendar"');
1043 document.write(' src="<?php echo $pmaThemeImage; ?>b_calendar.png"');
1044 document.write(' alt="<?php echo $strCalendar; ?>"/></a>');
1045 //]]>
1046 </script>
1047 <?php
1052 </td>
1053 </tr>
1054 <?php
1055 $odd_row = !$odd_row;
1056 } // end for
1057 $o_rows++;
1058 echo ' </tbody></table><br />';
1059 } // end foreach on multi-edit
1061 <br />
1063 <fieldset>
1064 <table border="0" cellpadding="5" cellspacing="0">
1065 <tr>
1066 <td valign="middle" nowrap="nowrap">
1067 <select name="submit_type" tabindex="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
1068 <?php
1069 if (isset($primary_key)) {
1071 <option value="<?php echo $strSave; ?>"><?php echo $strSave; ?></option>
1072 <?php
1075 <option value="<?php echo $strInsertAsNewRow; ?>"><?php echo $strInsertAsNewRow; ?></option>
1076 </select>
1077 <?php
1078 echo "\n";
1080 if (!isset($after_insert)) {
1081 $after_insert = 'back';
1084 </td>
1085 <td valign="middle">
1086 &nbsp;&nbsp;&nbsp;<strong><?php echo $strAndThen; ?></strong>&nbsp;&nbsp;&nbsp;
1087 </td>
1088 <td valign="middle" nowrap="nowrap">
1089 <select name="after_insert">
1090 <option value="back" <?php echo ($after_insert == 'back' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertBack; ?></option>
1091 <option value="new_insert" <?php echo ($after_insert == 'new_insert' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertNewInsert; ?></option>
1092 <?php
1093 if (isset($primary_key)) {
1095 <option value="same_insert" <?php echo ($after_insert == 'same_insert' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertSame; ?></option>
1096 <?php
1097 // If we have just numeric primary key, we can also edit next
1098 // in 2.8.2, we were looking for `field_name` = numeric_value
1099 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $primary_key)) {
1100 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1101 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $primary_key)) {
1103 <option value="edit_next" <?php echo ($after_insert == 'edit_next' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertNext; ?></option>
1104 <?php
1108 </select>
1109 </td>
1110 </tr>
1112 <tr>
1113 <td>
1114 <?php echo PMA_showHint($strUseTabKey); ?>
1115 </td>
1116 <td colspan="3" align="right" valign="middle">
1117 <input type="submit" value="<?php echo $strGo; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 6); ?>" id="buttonYes" />
1118 <input type="reset" value="<?php echo $strReset; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 7); ?>" />
1119 </td>
1120 </tr>
1121 </table>
1122 </fieldset>
1123 <?php if ($biggest_max_file_size > 0) {
1124 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
1125 } ?>
1126 </form>
1127 <?php
1128 if ($insert_mode) {
1130 <!-- Restart insertion form -->
1131 <form method="post" action="tbl_replace.php" name="restartForm" >
1132 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
1133 <input type="hidden" name="goto" value="<?php echo htmlspecialchars($GLOBALS['goto']); ?>" />
1134 <input type="hidden" name="err_url" value="<?php echo htmlspecialchars($err_url); ?>" />
1135 <input type="hidden" name="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
1136 <?php
1137 if (isset($primary_keys)) {
1138 foreach ($primary_key_array as $key_id => $primary_key) {
1139 echo '<input type="hidden" name="primary_key[' . $key_id . ']" value="' . htmlspecialchars(trim($primary_key)) . '" />'. "\n";
1142 $tmp = '<select name="insert_rows" id="insert_rows" onchange="this.form.submit();" >' . "\n";
1143 $option_values = array(1,2,5,10,15,20,30,40);
1144 foreach ($option_values as $value) {
1145 $tmp .= '<option value="' . $value . '"';
1146 if ($value == $cfg['InsertRows']) {
1147 $tmp .= ' selected="selected"';
1149 $tmp .= '>' . $value . '</option>' . "\n";
1151 $tmp .= '</select>' . "\n";
1152 echo "\n" . sprintf($strRestartInsertion, $tmp);
1153 unset($tmp);
1154 echo '<noscript><input type="submit" value="' . $strGo . '" /></noscript>' . "\n";
1155 echo '</form>' . "\n";
1159 * Displays the footer
1161 require_once './libraries/footer.inc.php';