Updated documentation.
[openemr.git] / interface / main / myadmin / tbl_change.php
blobef3900431d66ae92c93a50cdd8406deeff974f93
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
6 /**
7 * Get the variables sent or posted to this script and displays the header
8 */
9 require_once('./libraries/grab_globals.lib.php');
10 $js_to_run = 'tbl_change.js';
11 require_once('./header.inc.php');
12 require_once('./libraries/relation.lib.php'); // foreign keys
15 /**
16 * Displays the query submitted and its result
18 if (!empty($disp_message)) {
19 if (isset($goto)) {
20 $goto_cpy = $goto;
21 $goto = 'tbl_properties.php?'
22 . PMA_generate_common_url($db, $table)
23 . '&amp;$show_query=1'
24 . '&amp;sql_query=' . (isset($disp_query) ? urlencode($disp_query) : '');
25 } else {
26 $show_query = '1';
28 if (isset($sql_query)) {
29 $sql_query_cpy = $sql_query;
30 unset($sql_query);
32 if (isset($disp_query)) {
33 $sql_query = $disp_query;
35 PMA_showMessage($disp_message);
36 if (isset($goto_cpy)) {
37 $goto = $goto_cpy;
38 unset($goto_cpy);
40 if (isset($sql_query_cpy)) {
41 $sql_query = $sql_query_cpy;
42 unset($sql_query_cpy);
47 /**
48 * Defines the url to return to in case of error in a sql statement
50 if (!isset($goto)) {
51 $goto = 'db_details.php';
53 if (!preg_match('@^(db_details|tbl_properties|tbl_select)@', $goto)) {
54 $err_url = $goto . "?" . PMA_generate_common_url($db) . "&amp;sql_query=" . urlencode($sql_query);
55 } else {
56 $err_url = $goto . '?'
57 . PMA_generate_common_url($db)
58 . ((preg_match('@^(tbl_properties|tbl_select)@', $goto)) ? '&amp;table=' . urlencode($table) : '');
62 /**
63 * Ensures db and table are valid, else moves to the "parent" script
65 require('./libraries/db_table_exists.lib.php');
68 /**
69 * Sets parameters for links and displays top menu
71 $url_query = PMA_generate_common_url($db, $table)
72 . '&amp;goto=tbl_properties.php';
74 require('./tbl_properties_table_info.php');
75 echo '<br />';
78 /**
79 * Get the list of the fields of the current table
81 PMA_mysql_select_db($db);
82 $table_def = PMA_mysql_query('SHOW FIELDS FROM ' . PMA_backquote($table));
83 if (isset($primary_key)) {
84 if (is_array($primary_key)) {
85 $primary_key_array = $primary_key;
86 } else {
87 $primary_key_array = array(0 => $primary_key);
90 $row = array();
91 $result = array();
92 foreach($primary_key_array AS $rowcount => $primary_key) {
93 $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key;
94 $result[$rowcount] = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
95 $row[$rowcount] = PMA_mysql_fetch_array($result[$rowcount]);
96 $primary_keys[$rowcount] = $primary_key;
98 // No row returned
99 if (!$row[$rowcount]) {
100 unset($row[$rowcount]);
101 unset($primary_key_array[$rowcount]);
102 $goto_cpy = $goto;
103 $goto = 'tbl_properties.php?'
104 . PMA_generate_common_url($db, $table)
105 . '&amp;$show_query=1'
106 . '&amp;sql_query=' . urlencode($local_query);
107 if (isset($sql_query)) {
108 $sql_query_cpy = $sql_query;
109 unset($sql_query);
111 $sql_query = $local_query;
112 PMA_showMessage($strEmptyResultSet);
113 $goto = $goto_cpy;
114 unset($goto_cpy);
115 if (isset($sql_query_cpy)) {
116 $sql_query = $sql_query_cpy;
117 unset($sql_query_cpy);
119 } // end if (no record returned)
121 } else {
122 $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1';
123 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
124 unset($row);
127 // <markus@noga.de>
128 // retrieve keys into foreign fields, if any
129 $cfgRelation = PMA_getRelationsParam();
130 $foreigners = ($cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : FALSE);
134 * Displays the form
136 // loic1: autocomplete feature of IE kills the "onchange" event handler and it
137 // must be replaced by the "onpropertychange" one in this case
138 $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5)
139 ? 'onpropertychange'
140 : 'onchange';
141 // Had to put the URI because when hosted on an https server,
142 // some browsers send wrongly this form to the http server.
145 <?php if ($cfg['CtrlArrowsMoving']) { ?>
146 <!-- Set on key handler for moving using by Ctrl+arrows -->
147 <script type="text/javascript" language="javascript">
148 <!--
149 document.onkeydown = onKeyDownArrowsHandler;
150 // -->
151 </script>
152 <?php } ?>
154 <!-- Change table properties form -->
155 <form method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) echo ' enctype="multipart/form-data"'; ?>>
156 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
157 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
158 <input type="hidden" name="pos" value="<?php echo isset($pos) ? $pos : 0; ?>" />
159 <input type="hidden" name="session_max_rows" value="<?php echo isset($session_max_rows) ? $session_max_rows : ''; ?>" />
160 <input type="hidden" name="disp_direction" value="<?php echo isset($disp_direction) ? $disp_direction : ''; ?>" />
161 <input type="hidden" name="repeat_cells" value="<?php echo isset($repeat_cells) ? $repeat_cells : ''; ?>" />
162 <input type="hidden" name="dontlimitchars" value="<?php echo (isset($dontlimitchars) ? $dontlimitchars : 0); ?>" />
163 <input type="hidden" name="err_url" value="<?php echo urlencode($err_url); ?>" />
164 <input type="hidden" name="sql_query" value="<?php echo isset($sql_query) ? urlencode($sql_query) : ''; ?>" />
165 <?php
166 if (isset($primary_key_array)) {
167 foreach($primary_key_array AS $primary_key) {
169 <input type="hidden" name="primary_key[]" value="<?php echo urlencode($primary_key); ?>" />
170 <?php
173 echo "\n";
175 if ($cfg['PropertiesIconic'] == true) {
176 // We need to copy the value or else the == 'both' check will always return true
177 $propicon = (string)$cfg['PropertiesIconic'];
179 if ($propicon == 'both') {
180 $iconic_spacer = '<nobr>';
181 } else {
182 $iconic_spacer = '';
185 $titles['Browse'] = $iconic_spacer . '<img width="12" height="13" src="images/button_browse.png" alt="' . $strBrowseForeignValues . '" title="' . $strBrowseForeignValues . '" border="0" />';
187 if ($propicon == 'both') {
188 $titles['Browse'] .= '&nbsp;' . $strBrowseForeignValues . '</nobr>';
190 } else {
191 $titles['Browse'] = $strBrowseForeignValues;
194 // Set if we passed the first timestamp field
195 $timestamp_seen = 0;
196 $fields_cnt = mysql_num_rows($table_def);
198 // Set a flag here because the 'if' would not be valid in the loop
199 // if we set a value in some field
200 $insert_mode = (!isset($row) ? TRUE : FALSE);
201 $loop_array = (isset($row) ? $row : array(0 => FALSE));
203 while ($trow = PMA_mysql_fetch_array($table_def)) {
204 $trow_table_def[] = $trow;
207 $o_rows = 0;
208 foreach($loop_array AS $vrowcount => $vrow) {
209 if ($vrow === FALSE) {
210 unset($vrow);
213 $vresult = (isset($result) && is_array($result) && isset($result[$vrowcount]) ? $result[$vrowcount] : $result);
215 <table border="<?php echo $cfg['Border']; ?>">
216 <tr>
217 <th><?php echo $strField; ?></th>
218 <th><?php echo $strType; ?></th>
219 <?php
220 if ($cfg['ShowFunctionFields']) {
221 echo ' <th>' . $strFunction . '</th>' . "\n";
224 <th><?php echo $strNull; ?></th>
225 <th><?php echo $strValue; ?></th>
226 </tr>
227 <?php
229 if ($insert_mode) {
230 $vkey = '';
231 $browse_foreigners_uri = '';
232 } else {
233 $vkey = '[multi_edit][' . urlencode($primary_keys[$vrowcount]) . ']';
234 $browse_foreigners_uri = '&amp;pk=' . urlencode($primary_keys[$vrowcount]);
237 // garvin: For looping on multiple rows, we need to reset any variable used inside the loop to indicate sth.
238 $timestamp_seen = 0;
239 unset($first_timestamp);
241 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
242 $m_rows = $o_rows + 1;
244 for ($i = 0; $i < $fields_cnt; $i++) {
245 // Display the submit button after every 15 lines --swix
246 // (wanted to use an <a href="#bottom"> and <a name> instead,
247 // but it didn't worked because of the <base href>)
249 if ((($i % 15) == 0) && ($i != 0)) {
251 <tr>
252 <th colspan="5" align="right">
253 <input type="submit" value="<?php echo $strGo; ?>" />&nbsp;
254 </th>
255 </tr>
256 <?php
257 } // end if
258 echo "\n";
260 $row_table_def = $trow_table_def[$i];
261 $row_table_def['True_Type'] = preg_replace('@\(.*@s', '', $row_table_def['Type']);
263 $field = $row_table_def['Field'];
265 // garvin: possible workaround. If current field is numerical, do not try to
266 // access the result-array with its 'associative' key but with its numerical
267 // represantation.
268 if (is_numeric($field)) {
269 $rowfield = $i;
270 } else {
271 $rowfield = $field;
274 // d a t e t i m e
276 // loic1: current date should not be set as default if the field is NULL
277 // for the current row
278 // lem9: but do not put here the current datetime if there is a default
279 // value (the real default value will be set in the
280 // Default value logic below)
281 if ($row_table_def['Type'] == 'datetime'
282 && (!isset($row_table_def['Default']))) {
283 // INSERT case
284 if ($insert_mode) {
285 if (isset($vrow)) {
286 $vrow[$rowfield] = date('Y-m-d H:i:s', time());
287 } else {
288 $vrow = array($rowfield => date('Y-m-d H:i:s', time()));
291 // UPDATE case with an empty and not NULL value under PHP4
292 else if (empty($vrow[$rowfield]) && is_null($vrow[$rowfield])) {
293 $vrow[$rowfield] = date('Y-m-d H:i:s', time());
294 } // end if... else if...
296 $len = (preg_match('@float|double@', $row_table_def['Type']))
297 ? 100
298 : @mysql_field_len($vresult, $i);
299 $first_timestamp = 0;
301 $bgcolor = ($i % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
303 <tr>
304 <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($row_table_def['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center" bgcolor="<?php echo $bgcolor; ?>"><?php echo htmlspecialchars($field); ?></td>
305 <?php
306 echo "\n";
308 // The type column
309 $is_binary = stristr($row_table_def['Type'], ' binary');
310 $is_blob = stristr($row_table_def['Type'], 'blob');
311 $is_char = stristr($row_table_def['Type'], 'char');
312 switch ($row_table_def['True_Type']) {
313 case 'set':
314 $type = 'set';
315 $type_nowrap = '';
316 break;
317 case 'enum':
318 $type = 'enum';
319 $type_nowrap = '';
320 break;
321 case 'timestamp':
322 if (!$timestamp_seen) { // can only occur once per table
323 $timestamp_seen = 1;
324 $first_timestamp = 1;
326 $type = $row_table_def['Type'];
327 $type_nowrap = ' nowrap="nowrap"';
328 break;
330 default:
331 $type = $row_table_def['Type'];
332 $type_nowrap = ' nowrap="nowrap"';
333 break;
336 <td align="center" bgcolor="<?php echo $bgcolor; ?>"<?php echo $type_nowrap; ?>>
337 <?php echo $type; ?>
338 </td>
339 <?php
340 echo "\n";
342 // Prepares the field value
343 $real_null_value = FALSE;
344 if (isset($vrow)) {
345 if (!isset($vrow[$rowfield])
346 || (function_exists('is_null') && is_null($vrow[$rowfield]))) {
347 $real_null_value = TRUE;
348 $vrow[$rowfield] = '';
349 $special_chars = '';
350 $data = $vrow[$rowfield];
351 } else {
352 // loic1: special binary "characters"
353 if ($is_binary || $is_blob) {
354 $vrow[$rowfield] = str_replace("\x00", '\0', $vrow[$rowfield]);
355 $vrow[$rowfield] = str_replace("\x08", '\b', $vrow[$rowfield]);
356 $vrow[$rowfield] = str_replace("\x0a", '\n', $vrow[$rowfield]);
357 $vrow[$rowfield] = str_replace("\x0d", '\r', $vrow[$rowfield]);
358 $vrow[$rowfield] = str_replace("\x1a", '\Z', $vrow[$rowfield]);
359 } // end if
360 $special_chars = htmlspecialchars($vrow[$rowfield]);
361 $data = $vrow[$rowfield];
362 } // end if... else...
363 // loic1: if a timestamp field value is not included in an update
364 // statement MySQL auto-update it to the current timestamp
365 $backup_field = ($row_table_def['True_Type'] == 'timestamp')
366 ? ''
367 : '<input type="hidden" name="fields_prev' . $vkey . '[' . urlencode($field) . ']" value="' . urlencode($vrow[$rowfield]) . '" />';
368 } else {
369 // loic1: display default values
370 if (!isset($row_table_def['Default'])) {
371 $row_table_def['Default'] = '';
372 $real_null_value = TRUE;
373 $data = '';
374 //$data = 'NULL';
375 } else {
376 $data = $row_table_def['Default'];
378 $special_chars = htmlspecialchars($row_table_def['Default']);
379 $backup_field = '';
382 // The function column
383 // -------------------
384 // Change by Bernard M. Piller <bernard@bmpsystems.com>
385 // We don't want binary data to be destroyed
386 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
387 // stored or retrieved" so it does not mean that the contents is
388 // binary
389 if ($cfg['ShowFunctionFields']) {
390 if (($cfg['ProtectBinary'] && $is_blob)
391 || ($cfg['ProtectBinary'] == 'all' && $is_binary)) {
392 echo ' <td align="center" bgcolor="'. $bgcolor . '">' . $strBinary . '</td>' . "\n";
393 } else if (strstr($row_table_def['True_Type'], 'enum') || strstr($row_table_def['True_Type'], 'set')) {
394 echo ' <td align="center" bgcolor="'. $bgcolor . '">--</td>' . "\n";
395 } else {
397 <td bgcolor="<?php echo $bgcolor; ?>">
398 <select name="funcs<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $vkey; ?>')" tabindex="<?php echo ($fields_cnt + ($i * $m_rows) + 1); ?>" id="field_<?php echo $i * $m_rows; ?>_1">
399 <option></option>
400 <?php
401 echo "\n";
402 $selected = '';
404 // garvin: Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
405 // or something similar. Then directly look up the entry in the RestrictFunctions array,
406 // which will then reveal the available dropdown options
407 if (isset($cfg['RestrictFunctions']) && isset($cfg['RestrictColumnTypes']) && isset($cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])]) && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])]])) {
408 $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])];
409 $dropdown = $cfg['RestrictFunctions'][$current_func_type];
410 $default_function = $cfg['DefaultFunctions'][$current_func_type];
411 } else {
412 $dropdown = array();
415 $dropdown_built = array();
416 $op_spacing_needed = FALSE;
418 // garvin: loop on the dropdown array and print all available options for that field.
419 $cnt_dropdown = count($dropdown);
420 for ($j = 0; $j < $cnt_dropdown; $j++) {
421 // Is current function defined as default?
422 $selected = ($first_timestamp && $dropdown[$j] == $cfg['DefaultFunctions']['first_timestamp'])
423 || (!$first_timestamp && $dropdown[$j] == $default_function)
424 ? ' selected="selected"'
425 : '';
426 echo ' ';
427 echo '<option' . $selected . '>' . $dropdown[$j] . '</option>' . "\n";
428 $dropdown_built[$dropdown[$j]] = 'TRUE';
429 $op_spacing_needed = TRUE;
432 // garvin: For compatibility's sake, do not let out all other functions. Instead
433 // print a seperator (blank) and then show ALL functions which weren't shown
434 // yet.
435 $cnt_functions = count($cfg['Functions']);
436 for ($j = 0; $j < $cnt_functions; $j++) {
437 if (!isset($dropdown_built[$cfg['Functions'][$j]]) || $dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
438 // Is current function defined as default?
439 $selected = ($first_timestamp && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
440 || (!$first_timestamp && $cfg['Functions'][$j] == $default_function)
441 ? ' selected="selected"'
442 : '';
443 if ($op_spacing_needed == TRUE) {
444 echo ' ';
445 echo '<option value="">--------</option>' . "\n";
446 $op_spacing_needed = FALSE;
449 echo ' ';
450 echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
452 } // end for
453 unset($selected);
455 </select>
456 </td>
457 <?php
459 } // end if ($cfg['ShowFunctionFields'])
460 echo "\n";
462 // The null column
463 // ---------------
464 echo ' <td bgcolor="' . $bgcolor . '">' . "\n";
465 if (!(($cfg['ProtectBinary'] && $is_blob) || ($cfg['ProtectBinary'] == 'all' && $is_binary))
466 && $row_table_def['Null'] == 'YES') {
467 echo ' <input type="checkbox" tabindex="' . ((2 * $fields_cnt) + ($i * $m_rows) + 1) . '"'
468 . ' name="fields_null' . $vkey . '[' . urlencode($field) . ']"';
469 //if ($data == 'NULL' && !$first_timestamp) {
470 if ($real_null_value && !$first_timestamp) {
471 echo ' checked="checked"';
473 echo ' id="field_' . ($i * $m_rows) . '_2"';
474 $onclick = ' onclick="if (this.checked) {nullify(';
475 if (strstr($row_table_def['True_Type'], 'enum')) {
476 if (strlen($row_table_def['Type']) > 20) {
477 $onclick .= '1, ';
478 } else {
479 $onclick .= '2, ';
481 } else if (strstr($row_table_def['True_Type'], 'set')) {
482 $onclick .= '3, ';
483 } else if ($foreigners && isset($foreigners[$field])) {
484 $onclick .= '4, ';
485 } else {
486 $onclick .= '5, ';
488 $onclick .= '\'' . urlencode($field) . '\', \'' . md5($field) . '\', \'' . $vkey . '\'); this.checked = true}; return true" />' . "\n";
489 echo $onclick;
490 } else {
491 echo ' &nbsp;' . "\n";
493 echo ' </td>' . "\n";
495 // The value column (depends on type)
496 // ----------------
498 require('./libraries/get_foreign.lib.php');
500 if (isset($foreign_link) && $foreign_link == true) {
502 <td bgcolor="<?php echo $bgcolor; ?>">
503 <?php echo $backup_field . "\n"; ?>
504 <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="foreign" />
505 <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="" id="field_<?php echo ($i * $m_rows); ?>_1" />
506 <input type="text" name="field_<?php echo md5($field); ?><?php echo $vkey; ?>[]" class="textfield" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $vkey; ?>')" tabindex="<?php echo (($i * $m_rows) + 1); ?>" id="field_<?php echo ($i * $mrows); ?>_3" value="<?php echo htmlspecialchars($data); ?>" />
507 <script type="text/javascript" language="javascript">
508 document.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes\'); return false" href="browse_foreigners.php?<?php echo PMA_generate_common_url($db, $table); ?>&amp;field=<?php echo urlencode($field) . $browse_foreigners_uri; ?>"><?php echo str_replace("'", "\'", $titles['Browse']); ?></a>');
509 </script>
510 </td>
511 <?php
512 } else if (isset($disp) && $disp) {
514 <td bgcolor="<?php echo $bgcolor; ?>">
515 <?php echo $backup_field . "\n"; ?>
516 <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="foreign" />
517 <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="" id="field_<?php echo $i; ?>_1" />
518 <select name="field_<?php echo md5($field); ?><?php echo $vkey; ?>[]" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $vkey; ?>')" tabindex="<?php echo (($i * $m_rows) + 1); ?>" id="field_<?php echo ($i * $m_rows); ?>_3">
519 <?php echo PMA_foreignDropdown($disp, $foreign_field, $foreign_display, $data, 100); ?>
520 </select>
521 </td>
522 <?php
523 unset($disp);
525 else if ($cfg['LongtextDoubleTextarea'] && strstr($type, 'longtext')) {
527 <td bgcolor="<?php echo $bgcolor; ?>">&nbsp;</td>
528 </tr>
529 <tr>
530 <td colspan="4" align="right" bgcolor="<?php echo $bgcolor; ?>">
531 <?php echo $backup_field . "\n"; ?>
532 <textarea name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" rows="<?php echo ($cfg['TextareaRows']*2); ?>" cols="<?php echo ($cfg['TextareaCols']*2); ?>" wrap="virtual" dir="<?php echo $text_dir; ?>" id="field_<?php echo ($i * $m_rows); ?>_3"
533 <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $vkey; ?>')" tabindex="<?php echo (($i * $m_rows) + 1); ?>"><?php echo $special_chars; ?></textarea>
534 </td>
535 <?php
537 else if (strstr($type, 'text')) {
539 <td bgcolor="<?php echo $bgcolor; ?>">
540 <?php echo $backup_field . "\n"; ?>
541 <textarea name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" rows="<?php echo $cfg['TextareaRows']; ?>" cols="<?php echo $cfg['TextareaCols']; ?>" wrap="virtual" dir="<?php echo $text_dir; ?>" id="field_<?php echo ($i * $m_rows); ?>_3"
542 <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $vkey; ?>')" tabindex="<?php echo (($i * $m_rows) + 1); ?>"><?php echo $special_chars; ?></textarea>
543 </td>
544 <?php
545 echo "\n";
546 if (strlen($special_chars) > 32000) {
547 echo ' <td bgcolor="' . $bgcolor . '">' . $strTextAreaLength . '</td>' . "\n";
550 else if ($type == 'enum') {
551 $enum = PMA_getEnumSetOptions($row_table_def['Type']);
552 $enum_cnt = count($enum);
554 <td bgcolor="<?php echo $bgcolor; ?>">
555 <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="enum" />
556 <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="" />
557 <?php
558 echo "\n" . ' ' . $backup_field;
560 // show dropdown or radio depend on length
561 if (strlen($row_table_def['Type']) > 20) {
562 echo "\n";
564 <select name="field_<?php echo md5($field); ?><?php echo $vkey; ?>[]" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $vkey; ?>')" tabindex="<?php echo (($i * $m_rows) + 1); ?>" id="field_<?php echo ($i * $m_rows); ?>_3">
565 <option value=""></option>
566 <?php
567 echo "\n";
569 for ($j = 0; $j < $enum_cnt; $j++) {
570 // Removes automatic MySQL escape format
571 $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
572 echo ' ';
573 echo '<option value="' . htmlspecialchars($enum_atom) . '"';
574 if ($data == $enum_atom
575 || ($data == '' && (!isset($primary_key) || $row_table_def['Null'] != 'YES')
576 && isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
577 echo ' selected="selected"';
579 echo '>' . htmlspecialchars($enum_atom) . '</option>' . "\n";
580 } // end for
583 </select>
584 <?php
585 } // end if
586 else {
587 echo "\n";
588 for ($j = 0; $j < $enum_cnt; $j++) {
589 // Removes automatic MySQL escape format
590 $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
591 echo ' ';
592 echo '<input type="radio" name="field_' . md5($field) . $vkey . '[]" value="' . urlencode($enum_atom) . '" id="field_' . ($i*$m_rows) . '_3_' . $j . '" onclick="if (typeof(document.forms[\'insertForm\'].elements[\'fields_null' . str_replace('"', '\"', $vkey) . '[' . urlencode($field) . ']\']) != \'undefined\') {document.forms[\'insertForm\'].elements[\'fields_null' . str_replace('"', '\"', $vkey) . '[' . urlencode($field) .']\'].checked = false}"';
593 if ($data == $enum_atom
594 || ($data == '' && (!isset($primary_key) || $row_table_def['Null'] != 'YES')
595 && isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
596 echo ' checked="checked"';
598 echo 'tabindex="' . (($i * $m_rows) + 1) . '" />' . "\n";
599 echo ' <label for="field_' . ($i * $m_rows) . '_3_' . $j . '">' . htmlspecialchars($enum_atom) . '</label>' . "\n";
600 } // end for
602 } // end else
603 echo "\n";
605 </td>
606 <?php
607 echo "\n";
609 else if ($type == 'set') {
610 $set = PMA_getEnumSetOptions($row_table_def['Type']);
612 if (isset($vset)) {
613 unset($vset);
615 for ($vals = explode(',', $data); list($t, $k) = each($vals);) {
616 $vset[$k] = 1;
618 $countset = count($set);
619 $size = min(4, $countset);
621 <td bgcolor="<?php echo $bgcolor; ?>">
622 <?php echo $backup_field . "\n"; ?>
623 <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="set" />
624 <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="" />
625 <select name="field_<?php echo md5($field); ?><?php echo $vkey; ?>[]" size="<?php echo $size; ?>" multiple="multiple" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $vkey; ?>')" tabindex="<?php echo (($i * $m_rows) + 1); ?>" id="field_<?php echo ($i * $m_rows); ?>_3">
626 <?php
627 echo "\n";
628 for ($j = 0; $j < $countset; $j++) {
629 echo ' ';
630 echo '<option value="'. htmlspecialchars($set[$j]) . '"';
631 if (isset($vset[$set[$j]]) && $vset[$set[$j]]) {
632 echo ' selected="selected"';
634 echo '>' . htmlspecialchars($set[$j]) . '</option>' . "\n";
635 } // end for
637 </select>
638 </td>
639 <?php
641 // Change by Bernard M. Piller <bernard@bmpsystems.com>
642 // We don't want binary data destroyed
643 else if ($is_binary || $is_blob) {
644 if (($cfg['ProtectBinary'] && $is_blob)
645 || ($cfg['ProtectBinary'] == 'all' && $is_binary)) {
646 echo "\n";
648 <td align="center" bgcolor="<?php echo $bgcolor; ?>">
649 <?php
650 echo $strBinaryDoNotEdit;
651 if (isset($data)) {
652 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
653 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
654 unset($data_size);
656 echo "\n";
658 <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="protected" />
659 <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="" />
660 <?php
661 } else if ($is_blob) {
662 echo "\n";
664 <td bgcolor="<?php echo $bgcolor; ?>">
665 <?php echo $backup_field . "\n"; ?>
666 <textarea name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" rows="<?php echo $cfg['TextareaRows']; ?>" cols="<?php echo $cfg['TextareaCols']; ?>" wrap="virtual" dir="<?php echo $text_dir; ?>" id="field_<?php echo ($i*$m_rows); ?>_3"
667 <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $vkey; ?>')" tabindex="<?php echo (($i * $m_rows) + 1); ?>" ><?php echo $special_chars; ?></textarea>
668 <?php
670 } else {
671 if ($len < 4) {
672 $fieldsize = $maxlength = 4;
673 } else {
674 $fieldsize = (($len > 40) ? 40 : $len);
675 $maxlength = $len;
677 echo "\n";
679 <td bgcolor="<?php echo $bgcolor; ?>">
680 <?php echo $backup_field . "\n"; ?>
681 <input type="text" name="fields<?php echo $vkey; ?>[<?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); ?>', '<?php echo $vkey; ?>')" tabindex="<?php echo (($i * $m_rows) + 1); ?>" id="field_<?php echo ($i * $m_rows); ?>_3" />
682 <?php
683 } // end if...elseif...else
685 // Upload choice (only for BLOBs because the binary
686 // attribute does not imply binary contents)
687 // (displayed whatever value the ProtectBinary has)
689 if ($is_upload && $is_blob) {
690 echo '<input type="file" name="fields_upload_' . urlencode($field) . $vkey . '" class="textfield" id="field_' . ($i * $m_rows) . '_3" />';
693 if (!empty($cfg['UploadDir'])) {
694 if (substr($cfg['UploadDir'], -1) != '/') {
695 $cfg['UploadDir'] .= '/';
697 if ($handle = @opendir($cfg['UploadDir'])) {
698 $is_first = 0;
699 while ($file = @readdir($handle)) {
700 if (is_file($cfg['UploadDir'] . $file) && !PMA_checkFileExtensions($file, '.sql')) {
701 if ($is_first == 0) {
702 echo "<br />\n";
703 echo ' <i>' . $strOr . '</i>' . ' ' . $strWebServerUploadDirectory . '&nbsp;:<br />' . "\n";
704 echo ' <select size="1" name="fields_uploadlocal_' . urlencode($field) . $vkey . '">' . "\n";
705 echo ' <option value="" selected="selected"></option>' . "\n";
706 } // end if (is_first)
707 echo ' <option value="' . htmlspecialchars($file) . '">' . htmlspecialchars($file) . '</option>' . "\n";
708 $is_first++;
709 } // end if (is_file)
710 } // end while
711 if ($is_first > 0) {
712 echo ' </select>' . "\n";
713 } // end if (isfirst > 0)
714 @closedir($handle);
715 } else {
716 echo ' <font color="red">' . $strError . '</font><br />' . "\n";
717 echo ' ' . $strWebServerUploadDirectoryError . "\n";
719 } // end if (web-server upload directory)
721 echo '</td>';
723 } // end else if ( binary or blob)
724 else {
725 // For char or varchar, respect the maximum length (M); for other
726 // types (int or float), the length is not a limit on the values that
727 // can be entered, so let's be generous (20) (we could also use the
728 // real limits for each numeric type)
729 if ($is_char) {
730 $fieldsize = (($len > 40) ? 40 : $len);
731 $maxlength = $len;
733 else {
734 $fieldsize = $maxlength = 20;
735 } // end if... else...
736 echo "\n";
738 <td bgcolor="<?php echo $bgcolor; ?>">
739 <?php echo $backup_field . "\n"; ?>
740 <?php
741 if ($is_char && isset($cfg['CharEditing']) && ($cfg['CharEditing'] == 'textarea')) {
742 echo "\n";
744 <textarea name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" rows="<?php echo $cfg['CharTextareaRows']; ?>" cols="<?php echo $cfg['CharTextareaCols']; ?>" wrap="virtual" dir="<?php echo $text_dir; ?>" id="field_<?php echo ($i * $m_rows); ?>_3"
745 <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $vkey; ?>')" tabindex="<?php echo (($i * $m_rows) + 1); ?>" ><?php echo $special_chars; ?></textarea>
746 <?php
747 } else {
748 echo "\n";
750 <input type="text" name="fields<?php echo $vkey; ?>[<?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); ?>', '<?php echo $vkey; ?>')" tabindex="<?php echo (($i * $m_rows) + 1); ?>" id="field_<?php echo ($i * $m_rows); ?>_3" />
751 <?php
753 echo "\n";
755 </td>
756 <?php
758 echo "\n";
760 </tr>
761 <?php
762 echo "\n";
763 } // end for
764 $o_rows++;
765 echo ' </table><br />';
766 } // end foreach on multi-edit
768 <br />
770 <table cellpadding="5">
771 <tr>
772 <td valign="middle" nowrap="nowrap">
773 <?php
774 if (isset($primary_key)) {
776 <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 />
777 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $strOr; ?><br />
778 <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>
779 <?php
780 } else {
781 echo "\n";
783 <input type="hidden" name="submit_type" value="<?php echo $strInsertAsNewRow; ?>" />
784 <?php
785 echo ' ' . $strInsertAsNewRow . "\n";
787 echo "\n";
789 // Defines whether "insert a new row after the current insert" should be
790 // checked or not (keep this choice sticky)
791 // but do not check both radios, because Netscape 4.8 would display both checked
792 if (!empty($disp_message)) {
793 $checked_after_insert_new_insert = ' checked="checked"';
794 $checked_after_insert_back = '';
795 } else {
796 $checked_after_insert_back = ' checked="checked"';
797 $checked_after_insert_new_insert = '';
800 </td>
801 <td valign="middle">
802 &nbsp;&nbsp;&nbsp;<b>-- <?php echo $strAnd; ?> --</b>&nbsp;&nbsp;&nbsp;
803 </td>
804 <td valign="middle" nowrap="nowrap">
805 <input type="radio" name="after_insert" value="back" id="radio_after_insert_back" <?php echo $checked_after_insert_back; ?> tabindex="<?php echo ((3 * $fields_cnt) + 3); ?>" /><label for="radio_after_insert_back"><?php echo $strAfterInsertBack; ?></label><br />
806 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $strOr; ?><br />
807 <input type="radio" name="after_insert" value="new_insert" id="radio_after_insert_new_insert"<?php echo $checked_after_insert_new_insert; ?> tabindex="<?php echo ((3 * $fields_cnt) + 4); ?>" /><label for="radio_after_insert_new_insert"><?php echo $strAfterInsertNewInsert; ?></label>
808 </td>
809 </tr>
811 <tr>
812 <td colspan="3" align="right" valign="middle">
813 <input type="submit" value="<?php echo $strGo; ?>" tabindex="<?php echo ((3 * $fields_cnt) + 5); ?>" />
814 <input type="reset" value="<?php echo $strReset; ?>" tabindex="<?php echo ((3 * $fields_cnt) + 6); ?>" />
815 </td>
816 </tr>
817 </table>
819 </form>
822 <?php
824 * Displays the footer
826 echo "\n";
827 require_once('./footer.inc.php');