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 the values are in an array
40 if (isset($_GET['values']) && is_array($_GET['values'])) {
41 // then this page was called from itself via the "Add a value", "Drop" or "Go" buttons
42 $values = $_GET['values'];
43 foreach ($values as $key => $value) {
44 $values[$key] = htmlentities($value);
46 // If the values are in a string
47 } elseif (isset($_GET['values']) && is_string($_GET['values'])) {
48 // then this page was called via a link from some external page
49 $values_string = htmlentities($_GET['values']);
50 // There is a JS port of the below parser in functions.js
51 // If you are fixing something here,
52 // you need to also update the JS port.
56 for ($i=0; $i<strlen($values_string); $i++
) {
57 $curr = $values_string[$i];
58 $next = $i == strlen($values_string)-1 ?
'' : $values_string[$i+
1];
59 if (! $in_string && $curr == "'") {
61 } else if ($in_string && $curr == "\\" && $next == "\\") {
64 } else if ($in_string && $next == "'" && ($curr == "'" ||
$curr == "\\")) {
67 } else if ($in_string && $curr == "'") {
71 } else if ($in_string) {
75 if (strlen($buffer) > 0) {
76 // The leftovers in the buffer are the last value (if any)
80 // Escape double quotes
81 foreach ($values as $key => $value) {
82 $values[$key] = str_replace('"', ""e;", $value);
84 // If there are no values, maybe the user is about to make a
85 // new list so we add a few for him/her to get started with.
87 ||
(count($values) == 1 && strlen($values[0]) == 0)
89 array_push($values, '', '', '');
91 // Add an empty value, if there was a request to do so
92 if (! empty($_GET['add_field'])) {
95 // Remove a value, given a valid index, from the list
96 // of values, if there was a request to do so.
97 if (isset($_GET['drop']) && is_array($_GET['drop'])) {
98 foreach ($_GET['drop'] as $index => $value) {
99 if ((int)$index == $index
101 && $index <= count($values)
103 unset($values[$index]);
107 // Display the values in text fields
109 foreach ($values as $value) {
112 '<tr><td><input class="text" type="text" size="30" value="%s" name="values[' . $field_counter . ']" />' . "\n",
116 echo '<input class="drop" type="submit" value="' . __('Drop') . '" name="drop[' . $field_counter . ']" />' . "\n";
117 echo '</td></tr>' . "\n";
121 <input type
="submit" class="submit" value
="<?php echo __('Go'); ?>" />
123 <input type
="submit" class="submit" name
="add_field" value
="<?php echo __('Add a value'); ?>" />
127 <hr
class='enum_editor_no_js' />
128 <div id
="enum_editor_output">
129 <h3
><?php
echo __('Output'); ?
></h3
>
130 <p
><?php
echo PMA_getImage('s_info.png') . __('Copy and paste the joined values into the "Length/Values" field'); ?
></p
>
132 // Escape quotes and slashes for usage with MySQL
133 foreach ($values as $key => $value) {
135 $values[$key] .= str_replace(
136 array("'", "\\", "'", "\"),
137 array("''", '\\\\', "''", '\\\\'),
140 $values[$key] .= "'";
142 // Print out the values as a string
144 <textarea id
="joined_values" cols
="95" rows
="5"><?php
echo join(",", $values); ?
></textarea
>