3 // vim: expandtab sw=4 ts=4 sts=4:
7 * Get the variables sent or posted to this script and displays the header
9 require('./libraries/grab_globals.lib.php3');
10 $js_to_run = 'tbl_change.js';
11 require('./header.inc.php3');
12 require('./libraries/relation.lib.php3'); // foreign keys
16 * Displays the query submitted and its result
18 if (!empty($message)) {
21 $goto = 'tbl_properties.php3'
23 . '&convcharset=' . $convcharset
24 . '&server=' . $server
25 . '&db=' . urlencode($db)
26 . '&table=' . urlencode($table)
27 . '&$show_query=1'
28 . '&sql_query=' . urlencode($disp_query);
32 if (isset($sql_query)) {
33 $sql_query_cpy = $sql_query;
36 if (isset($disp_query)) {
37 $sql_query = (get_magic_quotes_gpc() ?
stripslashes($disp_query) : $disp_query);
39 PMA_showMessage($message);
40 if (isset($goto_cpy)) {
44 if (isset($sql_query_cpy)) {
45 $sql_query = $sql_query_cpy;
46 unset($sql_query_cpy);
49 if (get_magic_quotes_gpc()) {
50 if (!empty($sql_query)) {
51 $sql_query = stripslashes($sql_query);
53 if (!empty($primary_key)) {
54 $primary_key = stripslashes($primary_key);
60 * Defines the url to return to in case of error in a sql statement
63 $goto = 'db_details.php3';
65 if ($goto != 'db_details.php3' && $goto != 'tbl_properties.php3') {
70 . '&convcharset=' . $convcharset
71 . '&server=' . $server
72 . '&db=' . urlencode($db)
73 . (($goto == 'tbl_properties.php3') ?
'&table=' . urlencode($table) : '');
78 * Ensures db and table are valid, else moves to the "parent" script
80 require('./libraries/db_table_exists.lib.php3');
84 * Sets parameters for links and displays top menu
86 $url_query = 'lang=' . $lang
87 . '&convcharset=' . $convcharset
88 . '&server=' . $server
89 . '&db=' . urlencode($db)
90 . '&table=' . urlencode($table)
91 . '&goto=tbl_properties.php3';
93 require('./tbl_properties_table_info.php3');
98 * Get the list of the fields of the current table
100 PMA_mysql_select_db($db);
101 $table_def = PMA_mysql_query('SHOW FIELDS FROM ' . PMA_backquote($table));
102 if (isset($primary_key)) {
103 $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key;
104 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
105 $row = PMA_mysql_fetch_array($result);
111 $goto = 'tbl_properties.php3'
113 . '&convcharset=' . $convcharset
114 . '&server=' . $server
115 . '&db=' . urlencode($db)
116 . '&table=' . urlencode($table)
117 . '&$show_query=1'
118 . '&sql_query=' . urlencode($local_query);
119 if (isset($sql_query)) {
120 $sql_query_cpy = $sql_query;
123 $sql_query = $local_query;
124 PMA_showMessage($strEmptyResultSet);
127 if (isset($sql_query_cpy)) {
128 $sql_query = $sql_query_cpy;
129 unset($sql_query_cpy);
131 } // end if (no record returned)
135 $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1';
136 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
141 // retrieve keys into foreign fields, if any
142 $cfgRelation = PMA_getRelationsParam();
143 $foreigners = ($cfgRelation['relwork'] ?
PMA_getForeigners($db, $table) : FALSE);
149 // loic1: autocomplete feature of IE kills the "onchange" event handler and it
150 // must be replaced by the "onpropertychange" one in this case
151 $chg_evt_handler = (PMA_USR_BROWSER_AGENT
== 'IE' && PMA_USR_BROWSER_VER
>= 5)
154 // Had to put the URI because when hosted on an https server,
155 // some browsers send wrongly this form to the http server.
158 <!-- Change table properties form
-->
159 <form method
="post" action
="tbl_replace.php3" name
="insertForm">
160 <input type
="hidden" name
="lang" value
="<?php echo $lang; ?>" />
161 <input type
="hidden" name
="convcharset" value
="<?php echo $convcharset; ?>" />
162 <input type
="hidden" name
="server" value
="<?php echo $server; ?>" />
163 <input type
="hidden" name
="db" value
="<?php echo htmlspecialchars($db); ?>" />
164 <input type
="hidden" name
="table" value
="<?php echo $table; ?>" />
165 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
166 <input type
="hidden" name
="pos" value
="<?php echo isset($pos) ? $pos : 0; ?>" />
167 <input type
="hidden" name
="session_max_rows" value
="<?php echo isset($session_max_rows) ? $session_max_rows : ''; ?>" />
168 <input type
="hidden" name
="disp_direction" value
="<?php echo isset($disp_direction) ? $disp_direction : ''; ?>" />
169 <input type
="hidden" name
="repeat_cells" value
="<?php echo isset($repeat_cells) ? $repeat_cells : ''; ?>" />
170 <input type
="hidden" name
="dontlimitchars" value
="<?php echo (isset($dontlimitchars) ? $dontlimitchars : 0); ?>" />
171 <input type
="hidden" name
="err_url" value
="<?php echo urlencode($err_url); ?>" />
172 <input type
="hidden" name
="sql_query" value
="<?php echo isset($sql_query) ? urlencode($sql_query) : ''; ?>" />
174 if (isset($primary_key)) {
176 <input type
="hidden" name
="primary_key" value
="<?php echo urlencode($primary_key); ?>" />
182 <table border
="<?php echo $cfg['Border']; ?>">
184 <th
><?php
echo $strField; ?
></th
>
185 <th
><?php
echo $strType; ?
></th
>
187 if ($cfg['ShowFunctionFields']) {
188 echo ' <th>' . $strFunction . '</th>' . "\n";
191 <th
><?php
echo $strNull; ?
></th
>
192 <th
><?php
echo $strValue; ?
></th
>
196 // Set if we passed the first timestamp field
198 $fields_cnt = mysql_num_rows($table_def);
200 // Set a flag here because the 'if' would not be valid in the loop
201 // if we set a value in some field
202 $insert_mode = (!isset($row) ?
TRUE : FALSE);
204 for ($i = 0; $i < $fields_cnt; $i++
) {
205 // Display the submit button after every 15 lines --swix
206 // (wanted to use an <a href="#bottom"> and <a name> instead,
207 // but it didn't worked because of the <base href>)
209 if ((($i %
15) == 0) && ($i != 0)) {
212 <th colspan
="5" align
="right">
213 <input type
="submit" value
="<?php echo $strGo; ?>" /> 
;
220 $row_table_def = PMA_mysql_fetch_array($table_def);
221 $field = $row_table_def['Field'];
222 // loic1: current date should not be set as default if the field is NULL
223 // for the current row
224 // lem9: but do not put here the current datetime if there is a default
225 // value (the real default value will be set in the
226 // Default value logic below)
227 if ($row_table_def['Type'] == 'datetime'
228 && (!isset($row_table_def['Default']))) {
231 $row[$field] = date('Y-m-d H:i:s', time());
233 // UPDATE case with an empty and not NULL value under PHP4
234 else if (empty($row[$field]) && function_exists('is_null')) {
235 $row[$field] = (is_null($row[$field]) ?
$row[$field] : date('Y-m-d H:i:s', time()));
237 // UPDATE case with an empty value under PHP3
238 else if (empty($row[$field])) {
239 $row[$field] = date('Y-m-d H:i:s', time());
240 } // end if... else if... else if...
242 $len = (eregi('float|double', $row_table_def['Type']))
244 : @mysql_field_len
($result, $i);
245 $first_timestamp = 0;
247 $bgcolor = ($i %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
250 <td align
="center" bgcolor
="<?php echo $bgcolor; ?>"><?php
echo htmlspecialchars($field); ?
></td
>
255 $is_binary = eregi(' binary', $row_table_def['Type']);
256 $is_blob = eregi('blob', $row_table_def['Type']);
257 $is_char = eregi('char', $row_table_def['Type']);
258 $row_table_def['True_Type'] = ereg_replace('\\(.*', '', $row_table_def['Type']);
259 switch ($row_table_def['True_Type']) {
269 if (!$timestamp_seen) { // can only occur once per table
271 $first_timestamp = 1;
273 $type = $row_table_def['Type'];
274 $type_nowrap = ' nowrap="nowrap"';
278 $type = $row_table_def['Type'];
279 $type_nowrap = ' nowrap="nowrap"';
283 <td align
="center" bgcolor
="<?php echo $bgcolor; ?>"<?php
echo $type_nowrap; ?
>><?php
echo $type; ?
></td
>
287 // Prepares the field value
289 // loic1: null field value
290 if (!isset($row[$field])) {
291 $row[$field] = 'NULL';
293 $data = $row[$field];
295 // loic1: special binary "characters"
296 if ($is_binary ||
$is_blob) {
297 $row[$field] = str_replace("\x00", '\0', $row[$field]);
298 $row[$field] = str_replace("\x08", '\b', $row[$field]);
299 $row[$field] = str_replace("\x0a", '\n', $row[$field]);
300 $row[$field] = str_replace("\x0d", '\r', $row[$field]);
301 $row[$field] = str_replace("\x1a", '\Z', $row[$field]);
303 $special_chars = htmlspecialchars($row[$field]);
304 $data = $row[$field];
305 } // end if... else...
306 // loic1: if a timestamp field value is not included in an update
307 // statement MySQL auto-update it to the current timestamp
308 $backup_field = ($row_table_def['True_Type'] == 'timestamp')
310 : '<input type="hidden" name="fields_prev[' . urlencode($field) . ']" value="' . urlencode($row[$field]) . '" />';
312 // loic1: display default values
313 if (!isset($row_table_def['Default'])) {
314 $row_table_def['Default'] = '';
317 $data = $row_table_def['Default'];
319 $special_chars = htmlspecialchars($row_table_def['Default']);
323 // The function column
324 // -------------------
325 // Change by Bernard M. Piller <bernard@bmpsystems.com>
326 // We don't want binary data to be destroyed
327 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
328 // stored or retrieved" so it does not mean that the contents is
330 if ($cfg['ShowFunctionFields']) {
331 if (($cfg['ProtectBinary'] && $is_blob)
332 ||
($cfg['ProtectBinary'] == 'all' && $is_binary)) {
333 echo ' <td align="center" bgcolor="'. $bgcolor . '">' . $strBinary . '</td>' . "\n";
334 } else if (strstr($row_table_def['True_Type'], 'enum') ||
strstr($row_table_def['True_Type'], 'set')) {
335 echo ' <td align="center" bgcolor="'. $bgcolor . '">--</td>' . "\n";
338 <td bgcolor
="<?php echo $bgcolor; ?>">
339 <select name
="funcs[<?php echo urlencode($field); ?>]" <?php
echo $chg_evt_handler; ?
>="return unNullify('<?php echo urlencode($field); ?>')" tabindex
="<?php echo ($fields_cnt + $i + 1); ?>">
344 for ($j = 0; $j < count($cfg['Functions']); $j++
) {
345 // for default function = NOW() on first timestamp field
347 $selected = ($first_timestamp && $cfg['Functions'][$j] == 'NOW')
348 ?
' selected="selected"'
351 echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
359 } // end if ($cfg['ShowFunctionFields'])
364 echo ' <td bgcolor="' . $bgcolor . '">' . "\n";
365 if (!(($cfg['ProtectBinary'] && $is_blob) ||
($cfg['ProtectBinary'] == 'all' && $is_binary))
366 && $row_table_def['Null'] == 'YES') {
367 echo ' <input type="checkbox" tabindex="' . ((2 * $fields_cnt) +
$i +
1) . '"'
368 . ' name="fields_null[' . urlencode($field) . ']"';
369 if ($data == 'NULL' && !$first_timestamp) {
370 echo ' checked="checked"';
372 $onclick = ' onclick="if (this.checked) {nullify(';
373 if (strstr($row_table_def['True_Type'], 'enum')) {
374 if (strlen($row_table_def['Type']) > 20) {
379 } else if (strstr($row_table_def['True_Type'], 'set')) {
381 } else if ($foreigners && isset($foreigners[$field])) {
386 $onclick .= '\'' . urlencode($field) . '\', \'' . md5($field) . '\'); this.checked = true}; return true" />' . "\n";
389 echo ' ' . "\n";
391 echo ' </td>' . "\n";
393 // The value column (depends on type)
396 include('./libraries/get_foreign.lib.php3');
398 if (isset($disp) && $disp) {
400 <td bgcolor
="<?php echo $bgcolor; ?>">
401 <?php
echo $backup_field . "\n"; ?
>
402 <input type
="hidden" name
="fields[<?php echo urlencode($field); ?>]" value
="$foreign$" />
403 <select name
="field_<?php echo md5($field); ?>[]" <?php
echo $chg_evt_handler; ?
>="return unNullify('<?php echo urlencode($field); ?>')" tabindex
="<?php echo ($i + 1); ?>">
404 <option value
=""></option
>
407 while ($relrow = @PMA_mysql_fetch_array
($disp)) {
408 $key = $relrow[$foreign_field];
409 $value = (($foreign_display != FALSE) ?
' - ' . htmlspecialchars($relrow[$foreign_display]) : '');
410 echo ' <option value="' . htmlspecialchars($key) . '"';
412 echo ' selected="selected"';
414 echo '>' . htmlspecialchars($key) . $value . '</option>' . "\n";
416 echo ' </select>' . "\n";
417 echo ' </td>' . "\n";
420 else if (strstr($row_table_def['True_Type'], 'text')) {
422 <td bgcolor
="<?php echo $bgcolor; ?>">
423 <?php
echo $backup_field . "\n"; ?
>
424 <textarea name
="fields[<?php echo urlencode($field); ?>]" rows
="<?php echo $cfg['TextareaRows']; ?>" cols
="<?php echo $cfg['TextareaCols']; ?>" wrap
="virtual" dir
="<?php echo $text_dir; ?>"
425 <?php
echo $chg_evt_handler; ?
>="return unNullify('<?php echo urlencode($field); ?>')" tabindex
="<?php echo ($i + 1); ?>"><?php
echo $special_chars; ?
></textarea
>
429 if (strlen($special_chars) > 32000) {
430 echo ' <td bgcolor="' . $bgcolor . '">' . $strTextAreaLength . '</td>' . "\n";
433 else if (strstr($row_table_def['True_Type'], 'enum')) {
434 $enum = str_replace('enum(', '', $row_table_def['Type']);
435 $enum = ereg_replace('\\)$', '', $enum);
436 $enum = explode('\',\'', substr($enum, 1, -1));
437 $enum_cnt = count($enum);
439 <td bgcolor
="<?php echo $bgcolor; ?>">
440 <input type
="hidden" name
="fields[<?php echo urlencode($field); ?>]" value
="$enum$" />
442 echo "\n" . ' ' . $backup_field;
444 // show dropdown or radio depend on length
445 if (strlen($row_table_def['Type']) > 20) {
448 <select name
="field_<?php echo md5($field); ?>[]" <?php
echo $chg_evt_handler; ?
>="return unNullify('<?php echo urlencode($field); ?>')" tabindex
="<?php echo ($i + 1); ?>">
449 <option value
=""></option
>
453 for ($j = 0; $j < $enum_cnt; $j++
) {
454 // Removes automatic MySQL escape format
455 $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
457 echo '<option value="' . urlencode($enum_atom) . '"';
458 if ($data == $enum_atom
459 ||
($data == '' && (!isset($primary_key) ||
$row_table_def['Null'] != 'YES')
460 && isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
461 echo ' selected="selected"';
463 echo '>' . htmlspecialchars($enum_atom) . '</option>' . "\n";
472 for ($j = 0; $j < $enum_cnt; $j++
) {
473 // Removes automatic MySQL escape format
474 $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
476 echo '<input type="radio" name="field_' . md5($field) . '[]" value="' . urlencode($enum_atom) . '" id="radio_field_' . $j . '" onclick="if (typeof(document.forms[\'insertForm\'].elements[\'fields_null[' . urlencode($field) . ']\']) != \'undefined\') {document.forms[\'insertForm\'].elements[\'fields_null[' . urlencode($field) .']\'].checked = false}"';
477 if ($data == $enum_atom
478 ||
($data == '' && (!isset($primary_key) ||
$row_table_def['Null'] != 'YES')
479 && isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
480 echo ' checked="checked"';
482 echo 'tabindex="' . ($i +
1) . '" />' . "\n";
483 echo ' <label for="radio_field_' . $j . '">' . htmlspecialchars($enum_atom) . '</label>' . "\n";
493 else if (strstr($row_table_def['Type'], 'set')) {
494 $set = str_replace('set(', '', $row_table_def['Type']);
495 $set = ereg_replace('\)$', '', $set);
496 $set = explode(',', $set);
501 for ($vals = explode(',', $data); list($t, $k) = each($vals);) {
504 $size = min(4, count($set));
506 <td bgcolor
="<?php echo $bgcolor; ?>">
507 <?php
echo $backup_field . "\n"; ?
>
508 <input type
="hidden" name
="fields[<?php echo urlencode($field); ?>]" value
="$set$" />
509 <select name
="field_<?php echo md5($field); ?>[]" size
="<?php echo $size; ?>" multiple
="multiple" <?php
echo $chg_evt_handler; ?
>="return unNullify('<?php echo urlencode($field); ?>')" tabindex
="<?php echo ($i + 1); ?>" >
512 $countset = count($set);
513 for ($j = 0; $j < $countset;$j++
) {
514 $subset = substr($set[$j], 1, -1);
515 // Removes automatic MySQL escape format
516 $subset = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $subset));
518 echo '<option value="'. urlencode($subset) . '"';
519 if (isset($vset[$subset]) && $vset[$subset]) {
520 echo ' selected="selected"';
522 echo '>' . htmlspecialchars($subset) . '</option>' . "\n";
529 // Change by Bernard M. Piller <bernard@bmpsystems.com>
530 // We don't want binary data destroyed
531 else if ($is_binary ||
$is_blob) {
532 if (($cfg['ProtectBinary'] && $is_blob)
533 ||
($cfg['ProtectBinary'] == 'all' && $is_binary)) {
536 <td align
="center" bgcolor
="<?php echo $bgcolor; ?>">
537 <?php
echo $strBinaryDoNotEdit . "\n"; ?
>
540 } else if ($is_blob) {
543 <td bgcolor
="<?php echo $bgcolor; ?>">
544 <?php
echo $backup_field . "\n"; ?
>
545 <textarea name
="fields[<?php echo urlencode($field); ?>]" rows
="<?php echo $cfg['TextareaRows']; ?>" cols
="<?php echo $cfg['TextareaCols']; ?>" wrap
="virtual" dir
="<?php echo $text_dir; ?>"
546 <?php
echo $chg_evt_handler; ?
>="return unNullify('<?php echo urlencode($field); ?>')" tabindex
="<?php echo ($i + 1); ?>" ><?php
echo $special_chars; ?
></textarea
>
551 $fieldsize = $maxlength = 4;
553 $fieldsize = (($len > 40) ?
40 : $len);
558 <td bgcolor
="<?php echo $bgcolor; ?>">
559 <?php
echo $backup_field . "\n"; ?
>
560 <input type
="text" name
="fields[<?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); ?>')" tabindex
="<?php echo ($i + 1); ?>" />
563 } // end if...elseif...else
566 // For char or varchar, respect the maximum length (M); for other
567 // types (int or float), the length is not a limit on the values that
568 // can be entered, so let's be generous (20) (we could also use the
569 // real limits for each numeric type)
571 $fieldsize = (($len > 40) ?
40 : $len);
575 $fieldsize = $maxlength = 20;
576 } // end if... else...
579 <td bgcolor
="<?php echo $bgcolor; ?>">
580 <?php
echo $backup_field . "\n"; ?
>
582 if ($is_char && isset($cfg['CharEditing']) && ($cfg['CharEditing'] == 'textarea')) {
585 <textarea name
="fields[<?php echo urlencode($field); ?>]" rows
="<?php echo $cfg['CharTextareaRows']; ?>" cols
="<?php echo $cfg['CharTextareaCols']; ?>" wrap
="virtual" dir
="<?php echo $text_dir; ?>"
586 <?php
echo $chg_evt_handler; ?
>="return unNullify('<?php echo urlencode($field); ?>')" tabindex
="<?php echo ($i + 1); ?>" ><?php
echo $special_chars; ?
></textarea
>
591 <input type
="text" name
="fields[<?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); ?>')" tabindex
="<?php echo ($i + 1); ?>" />
609 <table cellpadding
="5">
611 <td valign
="middle" nowrap
="nowrap">
613 if (isset($primary_key)) {
615 <input type
="radio" name
="submit_type" value
="<?php echo $strSave; ?>" id
="radio_submit_type_save" checked
="checked" tabindex
="<?php echo ((3 * $fields_cnt) + 1); ?>" /><label
for="radio_submit_type_save"><?php
echo $strSave; ?
></label
><br
/>
616  
; 
; 
; 
; 
; 
;<?php
echo $strOr; ?
><br
/>
617 <input type
="radio" name
="submit_type" value
="<?php echo $strInsertAsNewRow; ?>" id
="radio_submit_type_insert_as_new_row" tabindex
="<?php echo ((3 * $fields_cnt) + 2); ?>" /><label
for="radio_submit_type_insert_as_new_row"><?php
echo $strInsertAsNewRow; ?
></label
>
622 <input type
="hidden" name
="submit_type" value
="<?php echo $strInsertAsNewRow; ?>" />
624 echo ' ' . $strInsertAsNewRow . "\n";
628 // Defines whether "insert a new row after the current insert" should be
629 // checked or not (keep this choice sticky)
630 $checked = (!empty($message)) ?
' checked="checked"' : '';
634  
; 
; 
;<b
>-- <?php
echo $strAnd; ?
> --</b
> 
; 
; 
;
636 <td valign
="middle" nowrap
="nowrap">
637 <input type
="radio" name
="after_insert" value
="back" id
="radio_after_insert_back" checked
="checked" tabindex
="<?php echo ((3 * $fields_cnt) + 3); ?>" /><label
for="radio_after_insert_back"><?php
echo $strAfterInsertBack; ?
></label
><br
/>
638  
; 
; 
; 
; 
; 
;<?php
echo $strOr; ?
><br
/>
639 <input type
="radio" name
="after_insert" value
="new_insert" id
="radio_after_insert_new_insert"<?php
echo $checked; ?
> tabindex
="<?php echo ((3 * $fields_cnt) + 4); ?>" /><label
for="radio_after_insert_new_insert"><?php
echo $strAfterInsertNewInsert; ?
></label
>
644 <td colspan
="3" align
="center" valign
="middle">
645 <input type
="submit" value
="<?php echo $strGo; ?>" tabindex
="<?php echo ((3 * $fields_cnt) + 5); ?>" />
655 * Displays the footer
658 require('./footer.inc.php3');