2.2.4
[phpmyadmin/arisferyanto.git] / tbl_change.php3
blobb2aa1c5c49148db85dda79cba9467e5c32b46517
1 <?php
2 /* $Id$ */
5 /**
6 * Get the variables sent or posted to this script and displays the header
7 */
8 require('./libraries/grab_globals.lib.php3');
9 include('./header.inc.php3');
10 // Displays the query submitted and its result
11 if (!empty($message)) {
12 if (isset($goto)) {
13 $goto_cpy = $goto;
14 $goto = 'tbl_properties.php3'
15 . '?lang=' . $lang
16 . '&amp;server=' . $server
17 . '&amp;db=' . urlencode($db)
18 . '&amp;table=' . urlencode($table)
19 . '&amp;$show_query=y'
20 . '&amp;sql_query=' . urlencode($disp_query);
21 } else {
22 $show_query = 'y';
24 if (isset($sql_query)) {
25 $sql_query_cpy = $sql_query;
26 unset($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)) {
33 $goto = $goto_cpy;
34 unset($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);
48 } // end if
51 /**
52 * Defines the url to return to in case of error in a sql statement
54 if (!isset($goto)) {
55 $goto = 'db_details.php3';
57 if ($goto != 'db_details.php3' && $goto != 'tbl_properties.php3') {
58 $err_url = $goto;
59 } else {
60 $err_url = $goto
61 . '?lang=' . $lang
62 . '&amp;server=' . $server
63 . '&amp;db=' . urlencode($db)
64 . (($goto == 'tbl_properties.php3') ? '&amp;table=' . urlencode($table) : '');
68 /**
69 * Get the list of the fields of the current table
71 mysql_select_db($db);
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);
77 // No row returned
78 if (!$row) {
79 unset($row);
80 unset($primary_key);
81 $goto_cpy = $goto;
82 $goto = 'tbl_properties.php3'
83 . '?lang=' . $lang
84 . '&amp;server=' . $server
85 . '&amp;db=' . urlencode($db)
86 . '&amp;table=' . urlencode($table)
87 . '&amp;$show_query=y'
88 . '&amp;sql_query=' . urlencode($local_query);
89 if (isset($sql_query)) {
90 $sql_query_cpy = $sql_query;
91 unset($sql_query);
93 $sql_query = $local_query;
94 PMA_showMessage($strEmptyResultSet);
95 $goto = $goto_cpy;
96 unset($goto_cpy);
97 if (isset($sql_query_cpy)) {
98 $sql_query = $sql_query_cpy;
99 unset($sql_query_cpy);
101 } // end if (no record returned)
103 else
105 $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1';
106 $result = mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
107 unset($row);
112 * Displays the form
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) : ''; ?>" />
132 <?php
133 if (isset($primary_key)) {
135 <input type="hidden" name="primary_key" value="<?php echo urlencode($primary_key); ?>" />
136 <?php
138 echo "\n";
141 <table border="<?php echo $cfgBorder; ?>">
142 <tr>
143 <th><?php echo $strField; ?></th>
144 <th><?php echo $strType; ?></th>
145 <?php
146 if ($cfgShowFunctionFields) {
147 echo ' <th>' . $strFunction . '</th>' . "\n";
150 <th><?php echo $strNull; ?></th>
151 <th><?php echo $strValue; ?></th>
152 </tr>
154 <?php
155 // Set if we passed the first timestamp field (loic1: in insert mode only -not
156 // in edit mode-)
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;
171 <tr>
172 <td align="center" bgcolor="<?php echo $bgcolor; ?>"><?php echo htmlspecialchars($field); ?></td>
173 <?php
174 echo "\n";
176 // The type column
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']) {
181 case 'set':
182 $type = 'set';
183 $type_nowrap = '';
184 break;
185 case 'enum':
186 $type = 'enum';
187 $type_nowrap = '';
188 break;
189 case 'timestamp':
190 if (!$timestamp_seen) { // can only occur once per table
191 $timestamp_seen = 1;
192 $first_timestamp = 1;
194 $type = $row_table_def['Type'];
195 break;
196 default:
197 $type = $row_table_def['Type'];
198 $type_nowrap = ' nowrap="nowrap"';
199 break;
202 <td align="center" bgcolor="<?php echo $bgcolor; ?>"<?php echo $type_nowrap; ?>><?php echo $type; ?></td>
203 <?php
204 echo "\n";
206 // Prepares the field value
207 if (isset($row)) {
208 // loic1: null field value
209 if (!isset($row[$field])) {
210 $row[$field] = 'NULL';
211 $special_chars = '';
212 $data = $row[$field];
213 } else {
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]);
221 } // end if
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')
228 ? ''
229 : '<input type="hidden" name="fields_prev[' . urlencode($field) . ']" value="' . urlencode($row[$field]) . '" />';
230 } else {
231 // loic1: display default values
232 if (!isset($row_table_def['Default'])) {
233 $row_table_def['Default'] = '';
234 $data = 'NULL';
235 } else {
236 $data = $row_table_def['Default'];
238 $special_chars = htmlspecialchars($row_table_def['Default']);
239 $backup_field = '';
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
248 // binary
249 if ($cfgShowFunctionFields) {
250 if ((($cfgProtectBinary && $is_blob)
251 || ($cfgProtectBinary == 'all' && $is_binary))
252 && !empty($data)) {
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";
256 } else {
258 <td bgcolor="<?php echo $bgcolor; ?>">
259 <select name="funcs[<?php echo urlencode($field); ?>]">
260 <option></option>
261 <?php
262 echo "\n";
263 if (!$first_timestamp) {
264 for ($j = 0; $j < count($cfgFunctions); $j++) {
265 echo ' ';
266 echo '<option>' . $cfgFunctions[$j] . '</option>' . "\n";
268 } else {
269 // for default function = NOW() on first timestamp field
270 // -- swix/18jul01
271 for ($j = 0; $j < count($cfgFunctions); $j++) {
272 echo ' ';
273 if ($cfgFunctions[$j] == 'NOW') {
274 echo '<option selected="selected">' . $cfgFunctions[$j] . '</option>' . "\n";
275 } else {
276 echo '<option>' . $cfgFunctions[$j] . '</option>' . "\n";
278 } // end for
281 </select>
282 </td>
283 <?php
286 echo "\n";
288 // The null column
289 // ---------------
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";
300 } else {
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";
305 } else {
306 echo ' onclick="if (this.checked) {document.forms[\'insertForm\'].elements[\'fields[' . urlencode($field) . ']\'].value = \'\'}; return true" />' . "\n";
308 } else {
309 echo ' &nbsp;' . "\n";
311 echo ' </td>' . "\n";
313 // The value column (depends on type)
314 // ----------------
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>
320 </td>
321 <?php
322 echo "\n";
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$" />
335 <?php
336 echo "\n" . ' ' . $backup_field;
338 // show dropdown or radio depend on length
339 if (strlen($row_table_def['Type']) > 20) {
340 echo "\n";
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>
344 <?php
345 echo "\n";
347 for ($j = 0; $j < $enum_cnt; $j++) {
348 // Removes automatic MySQL escape format
349 $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
350 echo ' ';
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";
358 } // end for
361 </select>
362 <?php
363 } // end if
364 else {
365 echo "\n";
366 for ($j = 0; $j < $enum_cnt; $j++) {
367 // Removes automatic MySQL escape format
368 $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
369 echo ' ';
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"';
376 echo ' />' . "\n";
377 echo ' ' . htmlspecialchars($enum_atom) . "\n";
378 } // end for
380 } // end else
381 echo "\n";
383 </td>
384 <?php
385 echo "\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);
392 if (isset($vset)) {
393 unset($vset);
395 for ($vals = explode(',', $data); list($t, $k) = each($vals);) {
396 $vset[$k] = 1;
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}">
404 <?php
405 echo "\n";
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));
411 echo ' ';
412 echo '<option value="'. urlencode($subset) . '"';
413 if (isset($vset[$subset]) && $vset[$subset]) {
414 echo ' selected="selected"';
416 echo '>' . htmlspecialchars($subset) . '</option>' . "\n";
417 } // end for
419 </select>
420 </td>
421 <?php
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)) {
428 echo "\n";
430 <td align="center" bgcolor="<?php echo $bgcolor; ?>">
431 <?php echo $strBinaryDoNotEdit . "\n"; ?>
432 </td>
433 <?php
434 } else if ($is_blob) {
435 echo "\n";
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>
440 </td>
441 <?php
442 } else {
443 if ($len < 4) {
444 $fieldsize = $maxlength = 4;
445 } else {
446 $fieldsize = (($len > 40) ? 40 : $len);
447 $maxlength = $len;
449 echo "\n";
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}" />
454 </td>
455 <?php
456 } // end if...elseif...else
457 } // end else if
458 else {
459 if ($len < 4) {
460 $fieldsize = $maxlength = 4;
461 } else {
462 $fieldsize = (($len > 40) ? 40 : $len);
463 $maxlength = $len;
465 echo "\n";
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}" />
470 </td>
471 <?php
473 echo "\n";
475 </tr>
476 <?php
477 echo "\n";
478 } // end for
480 </table>
481 <br />
483 <table cellpadding="5">
484 <tr>
485 <td valign="middle" nowrap="nowrap">
486 <?php
487 if (isset($primary_key)) {
489 <input type="radio" name="submit_type" value="<?php echo $strSave; ?>" checked="checked" /><?php echo $strSave; ?><br />
490 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $strOr; ?><br />
491 <input type="radio" name="submit_type" value="<?php echo $strInsertAsNewRow; ?>" /><?php echo $strInsertAsNewRow. "\n"; ?>
492 <?php
493 } else {
494 echo "\n";
496 <input type="hidden" name="submit_type" value="<?php echo $strInsertAsNewRow; ?>" />
497 <?php
498 echo ' ' . $strInsertAsNewRow . "\n";
500 echo "\n"
502 </td>
503 <td valign="middle">
504 &nbsp;&nbsp;&nbsp;<b>-- <?php echo $strAnd; ?> --</b>&nbsp;&nbsp;&nbsp;
505 </td>
506 <td valign="middle" nowrap="nowrap">
507 <input type="radio" name="after_insert" value="back" checked="checked" /><?php echo $strAfterInsertBack; ?><br />
508 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $strOr; ?><br />
509 <input type="radio" name="after_insert" value="new_insert" /><?php echo $strAfterInsertNewInsert . "\n"; ?>
510 </td>
511 </tr>
513 <tr>
514 <td colspan="3" align="center" valign="middle">
515 <input type="submit" value="<?php echo $strGo; ?>" />
516 </td>
517 </tr>
518 </table>
520 </form>
523 <?php
525 * Displays the footer
527 echo "\n";
528 require('./footer.inc.php3');