6 * Get the variables sent or posted to this script and displays the header
8 require('./libraries/grab_globals.lib.php3');
9 include('./header.inc.php3');
10 // Displays the query submitted and its result
11 if (!empty($message)) {
14 $goto = 'tbl_properties.php3'
16 . '&server=' . $server
17 . '&db=' . urlencode($db)
18 . '&table=' . urlencode($table)
19 . '&$show_query=y'
20 . '&sql_query=' . urlencode($disp_query);
24 if (isset($sql_query)) {
25 $sql_query_cpy = $sql_query;
28 if (isset($disp_query)) {
29 $sql_query = (get_magic_quotes_gpc() ?
stripslashes($disp_query) : $disp_query);
31 PMA_showMessage($message);
32 if (isset($goto_cpy)) {
36 if (isset($sql_query_cpy)) {
37 $sql_query = $sql_query_cpy;
38 unset($sql_query_cpy);
41 if (get_magic_quotes_gpc()) {
42 if (!empty($sql_query)) {
43 $sql_query = stripslashes($sql_query);
45 if (!empty($primary_key)) {
46 $primary_key = stripslashes($primary_key);
52 * Defines the url to return to in case of error in a sql statement
55 $goto = 'db_details.php3';
57 if ($goto != 'db_details.php3' && $goto != 'tbl_properties.php3') {
62 . '&server=' . $server
63 . '&db=' . urlencode($db)
64 . (($goto == 'tbl_properties.php3') ?
'&table=' . urlencode($table) : '');
69 * Get the list of the fields of the current table
72 $table_def = mysql_query('SHOW FIELDS FROM ' . PMA_backquote($table));
73 if (isset($primary_key)) {
74 $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key;
75 $result = mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
76 $row = mysql_fetch_array($result);
82 $goto = 'tbl_properties.php3'
84 . '&server=' . $server
85 . '&db=' . urlencode($db)
86 . '&table=' . urlencode($table)
87 . '&$show_query=y'
88 . '&sql_query=' . urlencode($local_query);
89 if (isset($sql_query)) {
90 $sql_query_cpy = $sql_query;
93 $sql_query = $local_query;
94 PMA_showMessage($strEmptyResultSet);
97 if (isset($sql_query_cpy)) {
98 $sql_query = $sql_query_cpy;
99 unset($sql_query_cpy);
101 } // end if (no record returned)
105 $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1';
106 $result = mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
115 // Had to put the URI because when hosted on an https server,
116 // some browsers send wrongly this form to the http server.
119 <!-- Change table properties form
-->
120 <form method
="post" action
="tbl_replace.php3" name
="insertForm">
121 <input type
="hidden" name
="lang" value
="<?php echo $lang; ?>" />
122 <input type
="hidden" name
="server" value
="<?php echo $server; ?>" />
123 <input type
="hidden" name
="db" value
="<?php echo $db; ?>" />
124 <input type
="hidden" name
="table" value
="<?php echo $table; ?>" />
125 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
126 <input type
="hidden" name
="pos" value
="<?php echo isset($pos) ? $pos : 0; ?>" />
127 <input type
="hidden" name
="session_max_rows" value
="<?php echo isset($session_max_rows) ? $session_max_rows : ''; ?>" />
128 <input type
="hidden" name
="disp_direction" value
="<?php echo isset($disp_direction) ? $disp_direction : ''; ?>" />
129 <input type
="hidden" name
="repeat_cells" value
="<?php echo isset($repeat_cells) ? $repeat_cells : ''; ?>" />
130 <input type
="hidden" name
="err_url" value
="<?php echo urlencode($err_url); ?>" />
131 <input type
="hidden" name
="sql_query" value
="<?php echo isset($sql_query) ? urlencode($sql_query) : ''; ?>" />
133 if (isset($primary_key)) {
135 <input type
="hidden" name
="primary_key" value
="<?php echo urlencode($primary_key); ?>" />
141 <table border
="<?php echo $cfgBorder; ?>">
143 <th
><?php
echo $strField; ?
></th
>
144 <th
><?php
echo $strType; ?
></th
>
146 if ($cfgShowFunctionFields) {
147 echo ' <th>' . $strFunction . '</th>' . "\n";
150 <th
><?php
echo $strNull; ?
></th
>
151 <th
><?php
echo $strValue; ?
></th
>
155 // Set if we passed the first timestamp field (loic1: in insert mode only -not
157 $timestamp_seen = (isset($primary_key) ?
1 : 0);
158 $fields_cnt = mysql_num_rows($table_def);
160 for ($i = 0; $i < $fields_cnt; $i++
) {
161 $row_table_def = mysql_fetch_array($table_def);
162 $field = $row_table_def['Field'];
163 if ($row_table_def['Type'] == 'datetime' && empty($row[$field])) {
164 $row[$field] = date('Y-m-d H:i:s', time());
166 $len = @mysql_field_len
($result, $i);
167 $first_timestamp = 0;
169 $bgcolor = ($i %
2) ?
$cfgBgcolorOne : $cfgBgcolorTwo;
172 <td align
="center" bgcolor
="<?php echo $bgcolor; ?>"><?php
echo htmlspecialchars($field); ?
></td
>
177 $is_binary = eregi(' binary', $row_table_def['Type']);
178 $is_blob = eregi('blob', $row_table_def['Type']);
179 $row_table_def['True_Type'] = ereg_replace('\\(.*', '', $row_table_def['Type']);
180 switch ($row_table_def['True_Type']) {
190 if (!$timestamp_seen) { // can only occur once per table
192 $first_timestamp = 1;
194 $type = $row_table_def['Type'];
197 $type = $row_table_def['Type'];
198 $type_nowrap = ' nowrap="nowrap"';
202 <td align
="center" bgcolor
="<?php echo $bgcolor; ?>"<?php
echo $type_nowrap; ?
>><?php
echo $type; ?
></td
>
206 // Prepares the field value
208 // loic1: null field value
209 if (!isset($row[$field])) {
210 $row[$field] = 'NULL';
212 $data = $row[$field];
214 // loic1: special binary "characters"
215 if ($is_binary ||
$is_blob) {
216 $row[$field] = str_replace("\x00", '\0', $row[$field]);
217 $row[$field] = str_replace("\x08", '\b', $row[$field]);
218 $row[$field] = str_replace("\x0a", '\n', $row[$field]);
219 $row[$field] = str_replace("\x0d", '\r', $row[$field]);
220 $row[$field] = str_replace("\x1a", '\Z', $row[$field]);
222 $special_chars = htmlspecialchars($row[$field]);
223 $data = $row[$field];
224 } // end if... else...
225 // loic1: if a timestamp field value is not included in an update
226 // statement MySQL auto-update it to the current timestamp
227 $backup_field = ($row_table_def['True_Type'] == 'timestamp')
229 : '<input type="hidden" name="fields_prev[' . urlencode($field) . ']" value="' . urlencode($row[$field]) . '" />';
231 // loic1: display default values
232 if (!isset($row_table_def['Default'])) {
233 $row_table_def['Default'] = '';
236 $data = $row_table_def['Default'];
238 $special_chars = htmlspecialchars($row_table_def['Default']);
242 // The function column
243 // -------------------
244 // Change by Bernard M. Piller <bernard@bmpsystems.com>
245 // We don't want binary data to be destroyed
246 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
247 // stored or retrieved" so it does not mean that the contents is
249 if ($cfgShowFunctionFields) {
250 if ((($cfgProtectBinary && $is_blob)
251 ||
($cfgProtectBinary == 'all' && $is_binary))
253 echo ' <td align="center" bgcolor="'. $bgcolor . '">' . $strBinary . '</td>' . "\n";
254 } else if (strstr($row_table_def['True_Type'], 'enum') ||
strstr($row_table_def['True_Type'], 'set')) {
255 echo ' <td align="center" bgcolor="'. $bgcolor . '">--</td>' . "\n";
258 <td bgcolor
="<?php echo $bgcolor; ?>">
259 <select name
="funcs[<?php echo urlencode($field); ?>]">
263 if (!$first_timestamp) {
264 for ($j = 0; $j < count($cfgFunctions); $j++
) {
266 echo '<option>' . $cfgFunctions[$j] . '</option>' . "\n";
269 // for default function = NOW() on first timestamp field
271 for ($j = 0; $j < count($cfgFunctions); $j++
) {
273 if ($cfgFunctions[$j] == 'NOW') {
274 echo '<option selected="selected">' . $cfgFunctions[$j] . '</option>' . "\n";
276 echo '<option>' . $cfgFunctions[$j] . '</option>' . "\n";
290 echo ' <td bgcolor="' . $bgcolor . '">' . "\n";
291 if ($row_table_def['Null'] == 'YES') {
292 echo ' <input type="checkbox"'
293 . ' name="fields_null[' . urlencode($field) . ']"';
294 if ($data == 'NULL') {
295 echo ' checked="checked"';
297 if (strstr($row_table_def['True_Type'], 'enum')) {
298 if (strlen($row_table_def['Type']) > 20) {
299 echo ' onclick="if (this.checked) {document.forms[\'insertForm\'].elements[\'field_' . md5($field) . '[]\'].selectedIndex = -1}; return true" />' . "\n";
301 echo ' onclick="if (this.checked) {var elts = document.forms[\'insertForm\'].elements[\'field_' . md5($field) . '[]\']; var elts_cnt = elts.length; for (var i = 0; i < elts_cnt; i++ ) {elts[i].checked = false}}; return true" />' . "\n";
303 } else if (strstr($row_table_def['True_Type'], 'set')) {
304 echo ' onclick="if (this.checked) {document.forms[\'insertForm\'].elements[\'field_' . md5($field) . '[]\'].selectedIndex = -1}; return true" />' . "\n";
306 echo ' onclick="if (this.checked) {document.forms[\'insertForm\'].elements[\'fields[' . urlencode($field) . ']\'].value = \'\'}; return true" />' . "\n";
309 echo ' ' . "\n";
311 echo ' </td>' . "\n";
313 // The value column (depends on type)
315 if (strstr($row_table_def['True_Type'], 'text')) {
317 <td bgcolor
="<?php echo $bgcolor; ?>">
318 <?php
echo $backup_field . "\n"; ?
>
319 <textarea name
="fields[<?php echo urlencode($field); ?>]" rows
="<?php echo $cfgTextareaRows; ?>" cols
="<?php echo $cfgTextareaCols; ?>" wrap
="virtual" onchange
="if (typeof(document.forms['insertForm'].elements['fields_null[<?php echo urlencode($field); ?>]']) != 'undefined') {document.forms['insertForm'].elements['fields_null[<?php echo urlencode($field); ?>]'].checked = false}"><?php
echo $special_chars; ?
></textarea
>
323 if (strlen($special_chars) > 32000) {
324 echo ' <td bgcolor="' . $bgcolor . '">' . $strTextAreaLength . '</td>' . "\n";
327 else if (strstr($row_table_def['True_Type'], 'enum')) {
328 $enum = str_replace('enum(', '', $row_table_def['Type']);
329 $enum = ereg_replace('\\)$', '', $enum);
330 $enum = explode('\',\'', substr($enum, 1, -1));
331 $enum_cnt = count($enum);
333 <td bgcolor
="<?php echo $bgcolor; ?>">
334 <input type
="hidden" name
="fields[<?php echo urlencode($field); ?>]" value
="$enum$" />
336 echo "\n" . ' ' . $backup_field;
338 // show dropdown or radio depend on length
339 if (strlen($row_table_def['Type']) > 20) {
342 <select name
="field_<?php echo md5($field); ?>[]" onchange
="if (typeof(document.forms['insertForm'].elements['fields_null[<?php echo urlencode($field); ?>]']) != 'undefined') {document.forms['insertForm'].elements['fields_null[<?php echo urlencode($field); ?>]'].checked = false}">
343 <option value
=""></option
>
347 for ($j = 0; $j < $enum_cnt; $j++
) {
348 // Removes automatic MySQL escape format
349 $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
351 echo '<option value="' . urlencode($enum_atom) . '"';
352 if ($data == $enum_atom
353 ||
($data == '' && (!isset($primary_key) ||
$row_table_def['Null'] != 'YES')
354 && isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
355 echo ' selected="selected"';
357 echo '>' . htmlspecialchars($enum_atom) . '</option>' . "\n";
366 for ($j = 0; $j < $enum_cnt; $j++
) {
367 // Removes automatic MySQL escape format
368 $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
370 echo '<input type="radio" name="field_' . md5($field) . '[]" value="' . 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}"';
371 if ($data == $enum_atom
372 ||
($data == '' && (!isset($primary_key) ||
$row_table_def['Null'] != 'YES')
373 && isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
374 echo ' checked="checked"';
377 echo ' ' . htmlspecialchars($enum_atom) . "\n";
387 else if (strstr($row_table_def['Type'], 'set')) {
388 $set = str_replace('set(', '', $row_table_def['Type']);
389 $set = ereg_replace('\)$', '', $set);
390 $set = explode(',', $set);
395 for ($vals = explode(',', $data); list($t, $k) = each($vals);) {
398 $size = min(4, count($set));
400 <td bgcolor
="<?php echo $bgcolor; ?>">
401 <?php
echo $backup_field . "\n"; ?
>
402 <input type
="hidden" name
="fields[<?php echo urlencode($field); ?>]" value
="$set$" />
403 <select name
="field_<?php echo md5($field); ?>[]" size
="<?php echo $size; ?>" multiple
="multiple" onchange
="if (typeof(document.forms['insertForm'].elements['fields_null[<?php echo urlencode($field); ?>]']) != 'undefined') {document.forms['insertForm'].elements['fields_null[<?php echo urlencode($field); ?>]'].checked = false}">
406 $countset = count($set);
407 for ($j = 0; $j < $countset;$j++
) {
408 $subset = substr($set[$j], 1, -1);
409 // Removes automatic MySQL escape format
410 $subset = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $subset));
412 echo '<option value="'. urlencode($subset) . '"';
413 if (isset($vset[$subset]) && $vset[$subset]) {
414 echo ' selected="selected"';
416 echo '>' . htmlspecialchars($subset) . '</option>' . "\n";
423 // Change by Bernard M. Piller <bernard@bmpsystems.com>
424 // We don't want binary data destroyed
425 else if ($is_binary ||
$is_blob) {
426 if (($cfgProtectBinary && $is_blob)
427 ||
($cfgProtectBinary == 'all' && $is_binary)) {
430 <td align
="center" bgcolor
="<?php echo $bgcolor; ?>">
431 <?php
echo $strBinaryDoNotEdit . "\n"; ?
>
434 } else if ($is_blob) {
437 <td bgcolor
="<?php echo $bgcolor; ?>">
438 <?php
echo $backup_field . "\n"; ?
>
439 <textarea name
="fields[<?php echo urlencode($field); ?>]" rows
="<?php echo $cfgTextareaRows; ?>" cols
="<?php echo $cfgTextareaCols; ?>" wrap
="virtual" onchange
="if (typeof(document.forms['insertForm'].elements['fields_null[<?php echo urlencode($field); ?>]']) != 'undefined') {document.forms['insertForm'].elements['fields_null[<?php echo urlencode($field); ?>]'].checked = false}"><?php
echo $special_chars; ?
></textarea
>
444 $fieldsize = $maxlength = 4;
446 $fieldsize = (($len > 40) ?
40 : $len);
451 <td bgcolor
="<?php echo $bgcolor; ?>">
452 <?php
echo $backup_field . "\n"; ?
>
453 <input type
="text" name
="fields[<?php echo urlencode($field); ?>]" value
="<?php echo $special_chars; ?>" size
="<?php echo $fieldsize; ?>" maxlength
="<?php echo $maxlength; ?>" onchange
="if (typeof(document.forms['insertForm'].elements['fields_null[<?php echo urlencode($field); ?>]']) != 'undefined') {document.forms['insertForm'].elements['fields_null[<?php echo urlencode($field); ?>]'].checked = false}" />
456 } // end if...elseif...else
460 $fieldsize = $maxlength = 4;
462 $fieldsize = (($len > 40) ?
40 : $len);
467 <td bgcolor
="<?php echo $bgcolor; ?>">
468 <?php
echo $backup_field . "\n"; ?
>
469 <input type
="text" name
="fields[<?php echo urlencode($field); ?>]" value
="<?php echo $special_chars; ?>" size
="<?php echo $fieldsize; ?>" maxlength
="<?php echo $maxlength; ?>" onchange
="if (typeof(document.forms['insertForm'].elements['fields_null[<?php echo urlencode($field); ?>]']) != 'undefined') {document.forms['insertForm'].elements['fields_null[<?php echo urlencode($field); ?>]'].checked = false}" />
483 <table cellpadding
="5">
485 <td valign
="middle" nowrap
="nowrap">
487 if (isset($primary_key)) {
489 <input type
="radio" name
="submit_type" value
="<?php echo $strSave; ?>" checked
="checked" /><?php
echo $strSave; ?
><br
/>
490  
; 
; 
; 
; 
; 
;<?php
echo $strOr; ?
><br
/>
491 <input type
="radio" name
="submit_type" value
="<?php echo $strInsertAsNewRow; ?>" /><?php
echo $strInsertAsNewRow. "\n"; ?
>
496 <input type
="hidden" name
="submit_type" value
="<?php echo $strInsertAsNewRow; ?>" />
498 echo ' ' . $strInsertAsNewRow . "\n";
504  
; 
; 
;<b
>-- <?php
echo $strAnd; ?
> --</b
> 
; 
; 
;
506 <td valign
="middle" nowrap
="nowrap">
507 <input type
="radio" name
="after_insert" value
="back" checked
="checked" /><?php
echo $strAfterInsertBack; ?
><br
/>
508  
; 
; 
; 
; 
; 
;<?php
echo $strOr; ?
><br
/>
509 <input type
="radio" name
="after_insert" value
="new_insert" /><?php
echo $strAfterInsertNewInsert . "\n"; ?
>
514 <td colspan
="3" align
="center" valign
="middle">
515 <input type
="submit" value
="<?php echo $strGo; ?>" />
525 * Displays the footer
528 require('./footer.inc.php3');