6 * Get the variables sent or posted to this script and displays the header
8 require('./libraries/grab_globals.lib.php3');
9 $js_to_run = 'tbl_change.js';
10 include('./header.inc.php3');
11 // Displays the query submitted and its result
12 if (!empty($message)) {
15 $goto = 'tbl_properties.php3'
17 . '&server=' . $server
18 . '&db=' . urlencode($db)
19 . '&table=' . urlencode($table)
20 . '&$show_query=y'
21 . '&sql_query=' . urlencode($disp_query);
25 if (isset($sql_query)) {
26 $sql_query_cpy = $sql_query;
29 if (isset($disp_query)) {
30 $sql_query = (get_magic_quotes_gpc() ?
stripslashes($disp_query) : $disp_query);
32 PMA_showMessage($message);
33 if (isset($goto_cpy)) {
37 if (isset($sql_query_cpy)) {
38 $sql_query = $sql_query_cpy;
39 unset($sql_query_cpy);
42 if (get_magic_quotes_gpc()) {
43 if (!empty($sql_query)) {
44 $sql_query = stripslashes($sql_query);
46 if (!empty($primary_key)) {
47 $primary_key = stripslashes($primary_key);
53 * Defines the url to return to in case of error in a sql statement
56 $goto = 'db_details.php3';
58 if ($goto != 'db_details.php3' && $goto != 'tbl_properties.php3') {
63 . '&server=' . $server
64 . '&db=' . urlencode($db)
65 . (($goto == 'tbl_properties.php3') ?
'&table=' . urlencode($table) : '');
70 * Get the list of the fields of the current table
73 $table_def = mysql_query('SHOW FIELDS FROM ' . PMA_backquote($table));
74 if (isset($primary_key)) {
75 $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key;
76 $result = mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
77 $row = mysql_fetch_array($result);
83 $goto = 'tbl_properties.php3'
85 . '&server=' . $server
86 . '&db=' . urlencode($db)
87 . '&table=' . urlencode($table)
88 . '&$show_query=y'
89 . '&sql_query=' . urlencode($local_query);
90 if (isset($sql_query)) {
91 $sql_query_cpy = $sql_query;
94 $sql_query = $local_query;
95 PMA_showMessage($strEmptyResultSet);
98 if (isset($sql_query_cpy)) {
99 $sql_query = $sql_query_cpy;
100 unset($sql_query_cpy);
102 } // end if (no record returned)
106 $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1';
107 $result = mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
115 // loic1: autocomplete feature of IE kills the "onchange" event handler and it
116 // must be replaced by the "onpropertychange" one in this case
117 $chg_evt_handler = (PMA_USR_BROWSER_AGENT
== 'IE' && PMA_USR_BROWSER_VER
>= 5)
120 // Had to put the URI because when hosted on an https server,
121 // some browsers send wrongly this form to the http server.
124 <!-- Change table properties form
-->
125 <form method
="post" action
="tbl_replace.php3" name
="insertForm">
126 <input type
="hidden" name
="lang" value
="<?php echo $lang; ?>" />
127 <input type
="hidden" name
="server" value
="<?php echo $server; ?>" />
128 <input type
="hidden" name
="db" value
="<?php echo $db; ?>" />
129 <input type
="hidden" name
="table" value
="<?php echo $table; ?>" />
130 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
131 <input type
="hidden" name
="pos" value
="<?php echo isset($pos) ? $pos : 0; ?>" />
132 <input type
="hidden" name
="session_max_rows" value
="<?php echo isset($session_max_rows) ? $session_max_rows : ''; ?>" />
133 <input type
="hidden" name
="disp_direction" value
="<?php echo isset($disp_direction) ? $disp_direction : ''; ?>" />
134 <input type
="hidden" name
="repeat_cells" value
="<?php echo isset($repeat_cells) ? $repeat_cells : ''; ?>" />
135 <input type
="hidden" name
="err_url" value
="<?php echo urlencode($err_url); ?>" />
136 <input type
="hidden" name
="sql_query" value
="<?php echo isset($sql_query) ? urlencode($sql_query) : ''; ?>" />
138 if (isset($primary_key)) {
140 <input type
="hidden" name
="primary_key" value
="<?php echo urlencode($primary_key); ?>" />
146 <table border
="<?php echo $cfgBorder; ?>">
148 <th
><?php
echo $strField; ?
></th
>
149 <th
><?php
echo $strType; ?
></th
>
151 if ($cfgShowFunctionFields) {
152 echo ' <th>' . $strFunction . '</th>' . "\n";
155 <th
><?php
echo $strNull; ?
></th
>
156 <th
><?php
echo $strValue; ?
></th
>
160 // Set if we passed the first timestamp field
162 $fields_cnt = mysql_num_rows($table_def);
164 for ($i = 0; $i < $fields_cnt; $i++
) {
165 $row_table_def = mysql_fetch_array($table_def);
166 $field = $row_table_def['Field'];
167 if ($row_table_def['Type'] == 'datetime' && empty($row[$field])) {
168 $row[$field] = date('Y-m-d H:i:s', time());
170 $len = (eregi('float|double', $row_table_def['Type']))
172 : @mysql_field_len
($result, $i);
173 $first_timestamp = 0;
175 $bgcolor = ($i %
2) ?
$cfgBgcolorOne : $cfgBgcolorTwo;
178 <td align
="center" bgcolor
="<?php echo $bgcolor; ?>"><?php
echo htmlspecialchars($field); ?
></td
>
183 $is_binary = eregi(' binary', $row_table_def['Type']);
184 $is_blob = eregi('blob', $row_table_def['Type']);
185 $row_table_def['True_Type'] = ereg_replace('\\(.*', '', $row_table_def['Type']);
186 switch ($row_table_def['True_Type']) {
196 if (!$timestamp_seen) { // can only occur once per table
198 $first_timestamp = 1;
200 $type = $row_table_def['Type'];
203 $type = $row_table_def['Type'];
204 $type_nowrap = ' nowrap="nowrap"';
208 <td align
="center" bgcolor
="<?php echo $bgcolor; ?>"<?php
echo $type_nowrap; ?
>><?php
echo $type; ?
></td
>
212 // Prepares the field value
214 // loic1: null field value
215 if (!isset($row[$field])) {
216 $row[$field] = 'NULL';
218 $data = $row[$field];
220 // loic1: special binary "characters"
221 if ($is_binary ||
$is_blob) {
222 $row[$field] = str_replace("\x00", '\0', $row[$field]);
223 $row[$field] = str_replace("\x08", '\b', $row[$field]);
224 $row[$field] = str_replace("\x0a", '\n', $row[$field]);
225 $row[$field] = str_replace("\x0d", '\r', $row[$field]);
226 $row[$field] = str_replace("\x1a", '\Z', $row[$field]);
228 $special_chars = htmlspecialchars($row[$field]);
229 $data = $row[$field];
230 } // end if... else...
231 // loic1: if a timestamp field value is not included in an update
232 // statement MySQL auto-update it to the current timestamp
233 $backup_field = ($row_table_def['True_Type'] == 'timestamp')
235 : '<input type="hidden" name="fields_prev[' . urlencode($field) . ']" value="' . urlencode($row[$field]) . '" />';
237 // loic1: display default values
238 if (!isset($row_table_def['Default'])) {
239 $row_table_def['Default'] = '';
242 $data = $row_table_def['Default'];
244 $special_chars = htmlspecialchars($row_table_def['Default']);
248 // The function column
249 // -------------------
250 // Change by Bernard M. Piller <bernard@bmpsystems.com>
251 // We don't want binary data to be destroyed
252 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
253 // stored or retrieved" so it does not mean that the contents is
255 if ($cfgShowFunctionFields) {
256 if (($cfgProtectBinary && $is_blob)
257 ||
($cfgProtectBinary == 'all' && $is_binary)) {
258 echo ' <td align="center" bgcolor="'. $bgcolor . '">' . $strBinary . '</td>' . "\n";
259 } else if (strstr($row_table_def['True_Type'], 'enum') ||
strstr($row_table_def['True_Type'], 'set')) {
260 echo ' <td align="center" bgcolor="'. $bgcolor . '">--</td>' . "\n";
263 <td bgcolor
="<?php echo $bgcolor; ?>">
264 <select name
="funcs[<?php echo urlencode($field); ?>]" <?php
echo $chg_evt_handler; ?
>="return unNullify('<?php echo urlencode($field); ?>')" tabindex
="<?php echo ($i+2*$fields_cnt); ?>" >
269 for ($j = 0; $j < count($cfgFunctions); $j++
) {
270 // for default function = NOW() on first timestamp field
272 $selected = ($first_timestamp && $cfgFunctions[$j] == 'NOW')
273 ?
' selected="selected"'
276 echo '<option' . $selected . '>' . $cfgFunctions[$j] . '</option>' . "\n";
284 } // end if ($cfgShowFunctionFields)
289 echo ' <td bgcolor="' . $bgcolor . '">' . "\n";
290 if (!(($cfgProtectBinary && $is_blob) ||
($cfgProtectBinary == 'all' && $is_binary))
291 && $row_table_def['Null'] == 'YES') {
292 echo ' <input type="checkbox" tabindex=' . ($i+
3*$fields_cnt) . '"'
293 . ' name="fields_null[' . urlencode($field) . ']"';
294 if ($data == 'NULL' && !$first_timestamp) {
295 echo ' checked="checked"';
297 $onclick = ' onclick="if (this.checked) {nullify(';
298 if (strstr($row_table_def['True_Type'], 'enum')) {
299 if (strlen($row_table_def['Type']) > 20) {
304 } else if (strstr($row_table_def['True_Type'], 'set')) {
309 $onclick .= '\'' . urlencode($field) . '\', \'' . md5($field) . '\'); this.checked = true}; return true" />' . "\n";
312 echo ' ' . "\n";
314 echo ' </td>' . "\n";
316 // The value column (depends on type)
318 if (strstr($row_table_def['True_Type'], 'text')) {
320 <td bgcolor
="<?php echo $bgcolor; ?>">
321 <?php
echo $backup_field . "\n"; ?
>
322 <textarea name
="fields[<?php echo urlencode($field); ?>]" rows
="<?php echo $cfgTextareaRows; ?>" cols
="<?php echo $cfgTextareaCols; ?>" wrap
="virtual" <?php
echo $chg_evt_handler; ?
>="return unNullify('<?php echo urlencode($field); ?>')" tabindex
="<?php echo $i; ?>"><?php
echo $special_chars; ?
></textarea
>
326 if (strlen($special_chars) > 32000) {
327 echo ' <td bgcolor="' . $bgcolor . '">' . $strTextAreaLength . '</td>' . "\n";
330 else if (strstr($row_table_def['True_Type'], 'enum')) {
331 $enum = str_replace('enum(', '', $row_table_def['Type']);
332 $enum = ereg_replace('\\)$', '', $enum);
333 $enum = explode('\',\'', substr($enum, 1, -1));
334 $enum_cnt = count($enum);
336 <td bgcolor
="<?php echo $bgcolor; ?>">
337 <input type
="hidden" name
="fields[<?php echo urlencode($field); ?>]" value
="$enum$" tabindex
="<?php echo $i+1; ?>" />
339 echo "\n" . ' ' . $backup_field;
341 // show dropdown or radio depend on length
342 if (strlen($row_table_def['Type']) > 20) {
345 <select name
="field_<?php echo md5($field); ?>[]" <?php
echo $chg_evt_handler; ?
>="return unNullify('<?php echo urlencode($field); ?>')" tabindex
="<?php echo $i+1; ?>">
346 <option value
=""></option
>
350 for ($j = 0; $j < $enum_cnt; $j++
) {
351 // Removes automatic MySQL escape format
352 $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
354 echo '<option value="' . urlencode($enum_atom) . '"';
355 if ($data == $enum_atom
356 ||
($data == '' && (!isset($primary_key) ||
$row_table_def['Null'] != 'YES')
357 && isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
358 echo ' selected="selected"';
360 echo '>' . htmlspecialchars($enum_atom) . '</option>' . "\n";
369 for ($j = 0; $j < $enum_cnt; $j++
) {
370 // Removes automatic MySQL escape format
371 $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
373 echo '<input type="radio" name="field_' . md5($field) . '[]" value="' . urlencode($enum_atom) . '" id="radio_field_' . md5($field) . '_' . urlencode($enum_atom) . '" onclick="if (typeof(document.forms[\'insertForm\'].elements[\'fields_null[' . urlencode($field) . ']\']) != \'undefined\') {document.forms[\'insertForm\'].elements[\'fields_null[' . urlencode($field) .']\'].checked = false}"';
374 if ($data == $enum_atom
375 ||
($data == '' && (!isset($primary_key) ||
$row_table_def['Null'] != 'YES')
376 && isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
377 echo ' checked="checked"';
379 echo 'tabindex="' . $i . '" />' . "\n";
380 echo ' <label for="radio_field_' . md5($field) . '_' . urlencode($enum_atom) . '">' . htmlspecialchars($enum_atom) . '</label>' . "\n";
390 else if (strstr($row_table_def['Type'], 'set')) {
391 $set = str_replace('set(', '', $row_table_def['Type']);
392 $set = ereg_replace('\)$', '', $set);
393 $set = explode(',', $set);
398 for ($vals = explode(',', $data); list($t, $k) = each($vals);) {
401 $size = min(4, count($set));
403 <td bgcolor
="<?php echo $bgcolor; ?>">
404 <?php
echo $backup_field . "\n"; ?
>
405 <input type
="hidden" name
="fields[<?php echo urlencode($field); ?>]" value
="$set$" />
406 <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; ?>" >
409 $countset = count($set);
410 for ($j = 0; $j < $countset;$j++
) {
411 $subset = substr($set[$j], 1, -1);
412 // Removes automatic MySQL escape format
413 $subset = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $subset));
415 echo '<option value="'. urlencode($subset) . '"';
416 if (isset($vset[$subset]) && $vset[$subset]) {
417 echo ' selected="selected"';
419 echo '>' . htmlspecialchars($subset) . '</option>' . "\n";
426 // Change by Bernard M. Piller <bernard@bmpsystems.com>
427 // We don't want binary data destroyed
428 else if ($is_binary ||
$is_blob) {
429 if (($cfgProtectBinary && $is_blob)
430 ||
($cfgProtectBinary == 'all' && $is_binary)) {
433 <td align
="center" bgcolor
="<?php echo $bgcolor; ?>">
434 <?php
echo $strBinaryDoNotEdit . "\n"; ?
>
437 } else if ($is_blob) {
440 <td bgcolor
="<?php echo $bgcolor; ?>">
441 <?php
echo $backup_field . "\n"; ?
>
442 <textarea name
="fields[<?php echo urlencode($field); ?>]" rows
="<?php echo $cfgTextareaRows; ?>" cols
="<?php echo $cfgTextareaCols; ?>" wrap
="virtual" <?php
echo $chg_evt_handler; ?
>="return unNullify('<?php echo urlencode($field); ?>')" tabindex
="<?php echo $i+1; ?>" ><?php
echo $special_chars; ?
></textarea
>
447 $fieldsize = $maxlength = 4;
449 $fieldsize = (($len > 40) ?
40 : $len);
454 <td bgcolor
="<?php echo $bgcolor; ?>">
455 <?php
echo $backup_field . "\n"; ?
>
456 <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; ?>" />
459 } // end if...elseif...else
463 $fieldsize = $maxlength = 4;
465 $fieldsize = (($len > 40) ?
40 : $len);
470 <td bgcolor
="<?php echo $bgcolor; ?>">
471 <?php
echo $backup_field . "\n"; ?
>
472 <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; ?>" />
486 <table cellpadding
="5">
488 <td valign
="middle" nowrap
="nowrap">
490 if (isset($primary_key)) {
492 <input type
="radio" name
="submit_type" value
="<?php echo $strSave; ?>" id
="radio_submit_type_save" checked
="checked" tabindex
="<?php echo $fields_cnt+1; ?>" /><label
for="radio_submit_type_save"><?php
echo $strSave; ?
></label
><br
/>
493  
; 
; 
; 
; 
; 
;<?php
echo $strOr; ?
><br
/>
494 <input type
="radio" name
="submit_type" value
="<?php echo $strInsertAsNewRow; ?>" id
="radio_submit_type_insert_as_new_row" tabindex
="<?php echo $fields_cnt+2; ?>" /><label
for="radio_submit_type_insert_as_new_row"><?php
echo $strInsertAsNewRow; ?
></label
>
499 <input type
="hidden" name
="submit_type" value
="<?php echo $strInsertAsNewRow; ?>" tabindex
="<?php echo $fields_cnt+3; ?>" />
501 echo ' ' . $strInsertAsNewRow . "\n";
505 // Defines whether "insert a new row after the current insert" should be
506 // checked or not (keep this choice sticky)
507 $checked = (!empty($message)) ?
' checked="checked"' : '';
511  
; 
; 
;<b
>-- <?php
echo $strAnd; ?
> --</b
> 
; 
; 
;
513 <td valign
="middle" nowrap
="nowrap">
514 <input type
="radio" name
="after_insert" value
="back" id
="radio_after_insert_back" checked
="checked" tabindex
="<?php echo $fields_cnt+4; ?>" /><label
for="radio_after_insert_back"><?php
echo $strAfterInsertBack; ?
></label
><br
/>
515  
; 
; 
; 
; 
; 
;<?php
echo $strOr; ?
><br
/>
516 <input type
="radio" name
="after_insert" value
="new_insert" id
="radio_after_insert_new_insert"<?php
echo $checked; ?
> tabindex
="<?php echo $fields_cnt+5; ?>" /><label
for="radio_after_insert_new_insert"><?php
echo $strAfterInsertNewInsert; ?
></label
>
521 <td colspan
="3" align
="center" valign
="middle">
522 <input type
="submit" value
="<?php echo $strGo; ?>" tabindex
="<?php echo $fields_cnt+6; ?>" />
532 * Displays the footer
535 require('./footer.inc.php3');