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') {
66 if (!ereg('^(db_details|tbl_properties|tbl_select)', $goto)) {
71 . '&convcharset=' . $convcharset
72 . '&server=' . $server
73 . '&db=' . urlencode($db)
74 //. (($goto == 'tbl_properties.php3') ? '&table=' . urlencode($table) : '');
75 . ((ereg('^(tbl_properties|tbl_select)', $goto)) ?
'&table=' . urlencode($table) : '');
80 * Ensures db and table are valid, else moves to the "parent" script
82 require('./libraries/db_table_exists.lib.php3');
86 * Sets parameters for links and displays top menu
88 $url_query = 'lang=' . $lang
89 . '&convcharset=' . $convcharset
90 . '&server=' . $server
91 . '&db=' . urlencode($db)
92 . '&table=' . urlencode($table)
93 . '&goto=tbl_properties.php3';
95 require('./tbl_properties_table_info.php3');
100 * Get the list of the fields of the current table
102 PMA_mysql_select_db($db);
103 $table_def = PMA_mysql_query('SHOW FIELDS FROM ' . PMA_backquote($table));
104 if (isset($primary_key)) {
105 $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key;
106 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
107 $row = PMA_mysql_fetch_array($result);
113 $goto = 'tbl_properties.php3'
115 . '&convcharset=' . $convcharset
116 . '&server=' . $server
117 . '&db=' . urlencode($db)
118 . '&table=' . urlencode($table)
119 . '&$show_query=1'
120 . '&sql_query=' . urlencode($local_query);
121 if (isset($sql_query)) {
122 $sql_query_cpy = $sql_query;
125 $sql_query = $local_query;
126 PMA_showMessage($strEmptyResultSet);
129 if (isset($sql_query_cpy)) {
130 $sql_query = $sql_query_cpy;
131 unset($sql_query_cpy);
133 } // end if (no record returned)
137 $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1';
138 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
143 // retrieve keys into foreign fields, if any
144 $cfgRelation = PMA_getRelationsParam();
145 $foreigners = ($cfgRelation['relwork'] ?
PMA_getForeigners($db, $table) : FALSE);
151 // loic1: autocomplete feature of IE kills the "onchange" event handler and it
152 // must be replaced by the "onpropertychange" one in this case
153 $chg_evt_handler = (PMA_USR_BROWSER_AGENT
== 'IE' && PMA_USR_BROWSER_VER
>= 5)
156 // Had to put the URI because when hosted on an https server,
157 // some browsers send wrongly this form to the http server.
160 <!-- Change table properties form
-->
161 <form method
="post" action
="tbl_replace.php3" name
="insertForm">
162 <input type
="hidden" name
="lang" value
="<?php echo $lang; ?>" />
163 <input type
="hidden" name
="convcharset" value
="<?php echo $convcharset; ?>" />
164 <input type
="hidden" name
="server" value
="<?php echo $server; ?>" />
165 <input type
="hidden" name
="db" value
="<?php echo htmlspecialchars($db); ?>" />
166 <input type
="hidden" name
="table" value
="<?php echo $table; ?>" />
167 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
168 <input type
="hidden" name
="pos" value
="<?php echo isset($pos) ? $pos : 0; ?>" />
169 <input type
="hidden" name
="session_max_rows" value
="<?php echo isset($session_max_rows) ? $session_max_rows : ''; ?>" />
170 <input type
="hidden" name
="disp_direction" value
="<?php echo isset($disp_direction) ? $disp_direction : ''; ?>" />
171 <input type
="hidden" name
="repeat_cells" value
="<?php echo isset($repeat_cells) ? $repeat_cells : ''; ?>" />
172 <input type
="hidden" name
="dontlimitchars" value
="<?php echo (isset($dontlimitchars) ? $dontlimitchars : 0); ?>" />
173 <input type
="hidden" name
="err_url" value
="<?php echo urlencode($err_url); ?>" />
174 <input type
="hidden" name
="sql_query" value
="<?php echo isset($sql_query) ? urlencode($sql_query) : ''; ?>" />
176 if (isset($primary_key)) {
178 <input type
="hidden" name
="primary_key" value
="<?php echo urlencode($primary_key); ?>" />
184 <table border
="<?php echo $cfg['Border']; ?>">
186 <th
><?php
echo $strField; ?
></th
>
187 <th
><?php
echo $strType; ?
></th
>
189 if ($cfg['ShowFunctionFields']) {
190 echo ' <th>' . $strFunction . '</th>' . "\n";
193 <th
><?php
echo $strNull; ?
></th
>
194 <th
><?php
echo $strValue; ?
></th
>
198 // Set if we passed the first timestamp field
200 $fields_cnt = mysql_num_rows($table_def);
202 // Set a flag here because the 'if' would not be valid in the loop
203 // if we set a value in some field
204 $insert_mode = (!isset($row) ?
TRUE : FALSE);
206 for ($i = 0; $i < $fields_cnt; $i++
) {
207 // Display the submit button after every 15 lines --swix
208 // (wanted to use an <a href="#bottom"> and <a name> instead,
209 // but it didn't worked because of the <base href>)
211 if ((($i %
15) == 0) && ($i != 0)) {
214 <th colspan
="5" align
="right">
215 <input type
="submit" value
="<?php echo $strGo; ?>" /> 
;
222 $row_table_def = PMA_mysql_fetch_array($table_def);
223 $field = $row_table_def['Field'];
224 // loic1: current date should not be set as default if the field is NULL
225 // for the current row
226 // lem9: but do not put here the current datetime if there is a default
227 // value (the real default value will be set in the
228 // Default value logic below)
229 if ($row_table_def['Type'] == 'datetime'
230 && (!isset($row_table_def['Default']))) {
233 $row[$field] = date('Y-m-d H:i:s', time());
235 // UPDATE case with an empty and not NULL value under PHP4
236 else if (empty($row[$field]) && function_exists('is_null')) {
237 $row[$field] = (is_null($row[$field]) ?
$row[$field] : date('Y-m-d H:i:s', time()));
239 // UPDATE case with an empty value under PHP3
240 else if (empty($row[$field])) {
241 $row[$field] = date('Y-m-d H:i:s', time());
242 } // end if... else if... else if...
244 $len = (eregi('float|double', $row_table_def['Type']))
246 : @mysql_field_len
($result, $i);
247 $first_timestamp = 0;
249 $bgcolor = ($i %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
252 <td align
="center" bgcolor
="<?php echo $bgcolor; ?>"><?php
echo htmlspecialchars($field); ?
></td
>
257 $is_binary = eregi(' binary', $row_table_def['Type']);
258 $is_blob = eregi('blob', $row_table_def['Type']);
259 $is_char = eregi('char', $row_table_def['Type']);
260 $row_table_def['True_Type'] = ereg_replace('\\(.*', '', $row_table_def['Type']);
261 switch ($row_table_def['True_Type']) {
271 if (!$timestamp_seen) { // can only occur once per table
273 $first_timestamp = 1;
275 $type = $row_table_def['Type'];
276 $type_nowrap = ' nowrap="nowrap"';
280 $type = $row_table_def['Type'];
281 $type_nowrap = ' nowrap="nowrap"';
285 <td align
="center" bgcolor
="<?php echo $bgcolor; ?>"<?php
echo $type_nowrap; ?
>><?php
echo $type; ?
></td
>
289 // Prepares the field value
291 // loic1: null field value
292 if (!isset($row[$field])) {
293 $row[$field] = 'NULL';
295 $data = $row[$field];
297 // loic1: special binary "characters"
298 if ($is_binary ||
$is_blob) {
299 $row[$field] = str_replace("\x00", '\0', $row[$field]);
300 $row[$field] = str_replace("\x08", '\b', $row[$field]);
301 $row[$field] = str_replace("\x0a", '\n', $row[$field]);
302 $row[$field] = str_replace("\x0d", '\r', $row[$field]);
303 $row[$field] = str_replace("\x1a", '\Z', $row[$field]);
305 $special_chars = htmlspecialchars($row[$field]);
306 $data = $row[$field];
307 } // end if... else...
308 // loic1: if a timestamp field value is not included in an update
309 // statement MySQL auto-update it to the current timestamp
310 $backup_field = ($row_table_def['True_Type'] == 'timestamp')
312 : '<input type="hidden" name="fields_prev[' . urlencode($field) . ']" value="' . urlencode($row[$field]) . '" />';
314 // loic1: display default values
315 if (!isset($row_table_def['Default'])) {
316 $row_table_def['Default'] = '';
319 $data = $row_table_def['Default'];
321 $special_chars = htmlspecialchars($row_table_def['Default']);
325 // The function column
326 // -------------------
327 // Change by Bernard M. Piller <bernard@bmpsystems.com>
328 // We don't want binary data to be destroyed
329 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
330 // stored or retrieved" so it does not mean that the contents is
332 if ($cfg['ShowFunctionFields']) {
333 if (($cfg['ProtectBinary'] && $is_blob)
334 ||
($cfg['ProtectBinary'] == 'all' && $is_binary)) {
335 echo ' <td align="center" bgcolor="'. $bgcolor . '">' . $strBinary . '</td>' . "\n";
336 } else if (strstr($row_table_def['True_Type'], 'enum') ||
strstr($row_table_def['True_Type'], 'set')) {
337 echo ' <td align="center" bgcolor="'. $bgcolor . '">--</td>' . "\n";
340 <td bgcolor
="<?php echo $bgcolor; ?>">
341 <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); ?>">
346 for ($j = 0; $j < count($cfg['Functions']); $j++
) {
347 // for default function = NOW() on first timestamp field
349 $selected = ($first_timestamp && $cfg['Functions'][$j] == 'NOW')
350 ?
' selected="selected"'
353 echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
361 } // end if ($cfg['ShowFunctionFields'])
366 echo ' <td bgcolor="' . $bgcolor . '">' . "\n";
367 if (!(($cfg['ProtectBinary'] && $is_blob) ||
($cfg['ProtectBinary'] == 'all' && $is_binary))
368 && $row_table_def['Null'] == 'YES') {
369 echo ' <input type="checkbox" tabindex="' . ((2 * $fields_cnt) +
$i +
1) . '"'
370 . ' name="fields_null[' . urlencode($field) . ']"';
371 if ($data == 'NULL' && !$first_timestamp) {
372 echo ' checked="checked"';
374 $onclick = ' onclick="if (this.checked) {nullify(';
375 if (strstr($row_table_def['True_Type'], 'enum')) {
376 if (strlen($row_table_def['Type']) > 20) {
381 } else if (strstr($row_table_def['True_Type'], 'set')) {
383 } else if ($foreigners && isset($foreigners[$field])) {
388 $onclick .= '\'' . urlencode($field) . '\', \'' . md5($field) . '\'); this.checked = true}; return true" />' . "\n";
391 echo ' ' . "\n";
393 echo ' </td>' . "\n";
395 // The value column (depends on type)
398 include('./libraries/get_foreign.lib.php3');
400 if (isset($disp) && $disp) {
402 <td bgcolor
="<?php echo $bgcolor; ?>">
403 <?php
echo $backup_field . "\n"; ?
>
404 <input type
="hidden" name
="fields[<?php echo urlencode($field); ?>]" value
="$foreign$" />
405 <select name
="field_<?php echo md5($field); ?>[]" <?php
echo $chg_evt_handler; ?
>="return unNullify('<?php echo urlencode($field); ?>')" tabindex
="<?php echo ($i + 1); ?>">
406 <option value
=""></option
>
409 while ($relrow = @PMA_mysql_fetch_array
($disp)) {
410 $key = $relrow[$foreign_field];
411 $value = (($foreign_display != FALSE) ?
' - ' . htmlspecialchars($relrow[$foreign_display]) : '');
412 echo ' <option value="' . htmlspecialchars($key) . '"';
414 echo ' selected="selected"';
416 echo '>' . htmlspecialchars($key) . $value . '</option>' . "\n";
418 echo ' </select>' . "\n";
419 echo ' </td>' . "\n";
422 else if (strstr($row_table_def['True_Type'], 'text')) {
424 <td bgcolor
="<?php echo $bgcolor; ?>">
425 <?php
echo $backup_field . "\n"; ?
>
426 <textarea name
="fields[<?php echo urlencode($field); ?>]" rows
="<?php echo $cfg['TextareaRows']; ?>" cols
="<?php echo $cfg['TextareaCols']; ?>" wrap
="virtual" dir
="<?php echo $text_dir; ?>"
427 <?php
echo $chg_evt_handler; ?
>="return unNullify('<?php echo urlencode($field); ?>')" tabindex
="<?php echo ($i + 1); ?>"><?php
echo $special_chars; ?
></textarea
>
431 if (strlen($special_chars) > 32000) {
432 echo ' <td bgcolor="' . $bgcolor . '">' . $strTextAreaLength . '</td>' . "\n";
435 else if (strstr($row_table_def['True_Type'], 'enum')) {
436 $enum = str_replace('enum(', '', $row_table_def['Type']);
437 $enum = ereg_replace('\\)$', '', $enum);
438 $enum = explode('\',\'', substr($enum, 1, -1));
439 $enum_cnt = count($enum);
441 <td bgcolor
="<?php echo $bgcolor; ?>">
442 <input type
="hidden" name
="fields[<?php echo urlencode($field); ?>]" value
="$enum$" />
444 echo "\n" . ' ' . $backup_field;
446 // show dropdown or radio depend on length
447 if (strlen($row_table_def['Type']) > 20) {
450 <select name
="field_<?php echo md5($field); ?>[]" <?php
echo $chg_evt_handler; ?
>="return unNullify('<?php echo urlencode($field); ?>')" tabindex
="<?php echo ($i + 1); ?>">
451 <option value
=""></option
>
455 for ($j = 0; $j < $enum_cnt; $j++
) {
456 // Removes automatic MySQL escape format
457 $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
459 echo '<option value="' . urlencode($enum_atom) . '"';
460 if ($data == $enum_atom
461 ||
($data == '' && (!isset($primary_key) ||
$row_table_def['Null'] != 'YES')
462 && isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
463 echo ' selected="selected"';
465 echo '>' . htmlspecialchars($enum_atom) . '</option>' . "\n";
474 for ($j = 0; $j < $enum_cnt; $j++
) {
475 // Removes automatic MySQL escape format
476 $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
478 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}"';
479 if ($data == $enum_atom
480 ||
($data == '' && (!isset($primary_key) ||
$row_table_def['Null'] != 'YES')
481 && isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
482 echo ' checked="checked"';
484 echo 'tabindex="' . ($i +
1) . '" />' . "\n";
485 echo ' <label for="radio_field_' . $j . '">' . htmlspecialchars($enum_atom) . '</label>' . "\n";
495 else if (strstr($row_table_def['Type'], 'set')) {
496 $set = str_replace('set(', '', $row_table_def['Type']);
497 $set = ereg_replace('\)$', '', $set);
498 $set = explode(',', $set);
503 for ($vals = explode(',', $data); list($t, $k) = each($vals);) {
506 $size = min(4, count($set));
508 <td bgcolor
="<?php echo $bgcolor; ?>">
509 <?php
echo $backup_field . "\n"; ?
>
510 <input type
="hidden" name
="fields[<?php echo urlencode($field); ?>]" value
="$set$" />
511 <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); ?>" >
514 $countset = count($set);
515 for ($j = 0; $j < $countset;$j++
) {
516 $subset = substr($set[$j], 1, -1);
517 // Removes automatic MySQL escape format
518 $subset = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $subset));
520 echo '<option value="'. urlencode($subset) . '"';
521 if (isset($vset[$subset]) && $vset[$subset]) {
522 echo ' selected="selected"';
524 echo '>' . htmlspecialchars($subset) . '</option>' . "\n";
531 // Change by Bernard M. Piller <bernard@bmpsystems.com>
532 // We don't want binary data destroyed
533 else if ($is_binary ||
$is_blob) {
534 if (($cfg['ProtectBinary'] && $is_blob)
535 ||
($cfg['ProtectBinary'] == 'all' && $is_binary)) {
538 <td align
="center" bgcolor
="<?php echo $bgcolor; ?>">
539 <?php
echo $strBinaryDoNotEdit . "\n"; ?
>
542 } else if ($is_blob) {
545 <td bgcolor
="<?php echo $bgcolor; ?>">
546 <?php
echo $backup_field . "\n"; ?
>
547 <textarea name
="fields[<?php echo urlencode($field); ?>]" rows
="<?php echo $cfg['TextareaRows']; ?>" cols
="<?php echo $cfg['TextareaCols']; ?>" wrap
="virtual" dir
="<?php echo $text_dir; ?>"
548 <?php
echo $chg_evt_handler; ?
>="return unNullify('<?php echo urlencode($field); ?>')" tabindex
="<?php echo ($i + 1); ?>" ><?php
echo $special_chars; ?
></textarea
>
553 $fieldsize = $maxlength = 4;
555 $fieldsize = (($len > 40) ?
40 : $len);
560 <td bgcolor
="<?php echo $bgcolor; ?>">
561 <?php
echo $backup_field . "\n"; ?
>
562 <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); ?>" />
565 } // end if...elseif...else
568 // For char or varchar, respect the maximum length (M); for other
569 // types (int or float), the length is not a limit on the values that
570 // can be entered, so let's be generous (20) (we could also use the
571 // real limits for each numeric type)
573 $fieldsize = (($len > 40) ?
40 : $len);
577 $fieldsize = $maxlength = 20;
578 } // end if... else...
581 <td bgcolor
="<?php echo $bgcolor; ?>">
582 <?php
echo $backup_field . "\n"; ?
>
584 if ($is_char && isset($cfg['CharEditing']) && ($cfg['CharEditing'] == 'textarea')) {
587 <textarea name
="fields[<?php echo urlencode($field); ?>]" rows
="<?php echo $cfg['CharTextareaRows']; ?>" cols
="<?php echo $cfg['CharTextareaCols']; ?>" wrap
="virtual" dir
="<?php echo $text_dir; ?>"
588 <?php
echo $chg_evt_handler; ?
>="return unNullify('<?php echo urlencode($field); ?>')" tabindex
="<?php echo ($i + 1); ?>" ><?php
echo $special_chars; ?
></textarea
>
593 <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); ?>" />
611 <table cellpadding
="5">
613 <td valign
="middle" nowrap
="nowrap">
615 if (isset($primary_key)) {
617 <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
/>
618  
; 
; 
; 
; 
; 
;<?php
echo $strOr; ?
><br
/>
619 <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
>
624 <input type
="hidden" name
="submit_type" value
="<?php echo $strInsertAsNewRow; ?>" />
626 echo ' ' . $strInsertAsNewRow . "\n";
630 // Defines whether "insert a new row after the current insert" should be
631 // checked or not (keep this choice sticky)
632 $checked = (!empty($message)) ?
' checked="checked"' : '';
636  
; 
; 
;<b
>-- <?php
echo $strAnd; ?
> --</b
> 
; 
; 
;
638 <td valign
="middle" nowrap
="nowrap">
639 <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
/>
640  
; 
; 
; 
; 
; 
;<?php
echo $strOr; ?
><br
/>
641 <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
>
646 <td colspan
="3" align
="center" valign
="middle">
647 <input type
="submit" value
="<?php echo $strGo; ?>" tabindex
="<?php echo ((3 * $fields_cnt) + 5); ?>" />
657 * Displays the footer
660 require('./footer.inc.php3');