3 /* vim: set expandtab sw=4 ts=4 sts=4: */
5 * Displays a form for editing ENUM and SET values with more
6 * space (as an alternative to doing it in tbl_alter.php).
7 * This form is only for users with JavaScript disabled,
8 * users with JavaScript enabled will see a jQuery dialog.
13 require_once './libraries/common.inc.php';
14 require_once './libraries/header_http.inc.php';
15 require_once './libraries/header_meta_style.inc.php';
19 <form action
="enum_editor.php" method
="get">
20 <?php
echo PMA_generate_common_hidden_inputs(); ?
>
21 <input type
="hidden" name
="field" value
="<?php echo htmlspecialchars($_GET['field']); ?>" />
22 <fieldset
class="enum_editor_no_js">
23 <legend
><?php
echo __('ENUM/SET editor'); ?
></legend
>
24 <div
class="enum_editor_no_js">
27 if (empty($_GET['field'])) {
28 echo __('Values for a new column');
30 printf(__('Values for column %s'), '"' . htmlspecialchars($_GET['field']) . '"');
34 <p
><?php
echo PMA_getImage('s_info.png') . __('Enter each value in a separate field'); ?
></p
>
37 // Get the enum values
39 if (isset($_GET['values']) && is_array($_GET['values'])) { // If the values are in an array
40 // then this page was called from itself via the "Add a value", "Drop" or "Go" buttons
41 $values = $_GET['values'];
42 foreach ($values as $key => $value) {
43 $values[$key] = htmlentities($value);
45 } else if (isset($_GET['values']) && is_string($_GET['values'])){ // If the values are in a string
46 // then this page was called via a link from some external page
47 $values_string = htmlentities($_GET['values']);
48 // There is a JS port of the below parser in functions.js
49 // If you are fixing something here,
50 // you need to also update the JS port.
54 for ($i=0; $i<strlen($values_string); $i++
) {
55 $curr = $values_string[$i];
56 $next = $i == strlen($values_string)-1 ?
'' : $values_string[$i+
1];
57 if (! $in_string && $curr == "'") {
59 } else if ($in_string && $curr == "\\" && $next == "\\") {
62 } else if ($in_string && $next == "'" && ($curr == "'" ||
$curr == "\\")) {
65 } else if ($in_string && $curr == "'") {
69 } else if ($in_string) {
73 if (strlen($buffer) > 0) {
74 // The leftovers in the buffer are the last value (if any)
78 // Escape double quotes
79 foreach ($values as $key => $value) {
80 $values[$key] = str_replace('"', ""e;", $value);
82 // If there are no values, maybe the user is about to make a
83 // new list so we add a few for him/her to get started with.
85 ||
(count($values) == 1 && strlen($values[0]) == 0)
87 array_push($values, '', '', '');
89 // Add an empty value, if there was a request to do so
90 if (! empty($_GET['add_field'])) {
93 // Remove a value, given a valid index, from the list
94 // of values, if there was a request to do so.
95 if (isset($_GET['drop']) && is_array($_GET['drop'])) {
96 foreach ($_GET['drop'] as $index => $value){
97 if ((int)$index == $index
99 && $index <= count($values)
101 unset($values[$index]);
105 // Display the values in text fields
107 foreach ($values as $value) {
110 '<tr><td><input class="text" type="text" size="30" value="%s" name="values[' . $field_counter . ']" />' . "\n",
114 echo '<input class="drop" type="submit" value="' . __('Drop') . '" name="drop[' . $field_counter . ']" />' . "\n";
115 echo '</td></tr>' . "\n";
119 <input type
="submit" class="submit" value
="<?php echo __('Go'); ?>" />
121 <input type
="submit" class="submit" name
="add_field" value
="<?php echo __('Add a value'); ?>" />
125 <hr
class='enum_editor_no_js' />
126 <div id
="enum_editor_output">
127 <h3
><?php
echo __('Output'); ?
></h3
>
128 <p
><?php
echo PMA_getImage('s_info.png') . __('Copy and paste the joined values into the "Length/Values" field'); ?
></p
>
130 // Escape quotes and slashes for usage with MySQL
131 foreach ($values as $key => $value) {
133 $values[$key] .= str_replace(
134 array("'", "\\", "'", "\"),
135 array("''", '\\\\', "''", '\\\\'),
138 $values[$key] .= "'";
140 // Print out the values as a string
142 <textarea id
="joined_values" cols
="95" rows
="5"><?php
echo join(",", $values); ?
></textarea
>