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