Translated using Weblate.
[phpmyadmin.git] / enum_editor.php
blob10e0ba30a95047bda22001319bea6b6085c086b7
1 <?php
3 /* vim: set expandtab sw=4 ts=4 sts=4: */
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.
10 * @package PhpMyAdmin
13 require_once './libraries/common.inc.php';
14 require_once './libraries/header_http.inc.php';
15 require_once './libraries/header_meta_style.inc.php';
17 </head>
18 <body>
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">
25 <h3>
26 <?php
27 if (empty($_GET['field'])) {
28 echo __('Values for a new column');
29 } else {
30 printf(__('Values for column %s'), '"' . htmlspecialchars($_GET['field']) . '"');
33 </h3>
34 <p><?php echo PMA_getImage('s_info.png') . __('Enter each value in a separate field'); ?></p>
35 <table id="values">
36 <?php
37 // Get the enum values
38 $values = array();
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.
53 $values = array();
54 $in_string = false;
55 $buffer = '';
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 == "'") {
60 $in_string = true;
61 } else if ($in_string && $curr == "\\" && $next == "\\") {
62 $buffer .= "&#92;";
63 $i++;
64 } else if ($in_string && $next == "'" && ($curr == "'" || $curr == "\\")) {
65 $buffer .= "&#39;";
66 $i++;
67 } else if ($in_string && $curr == "'") {
68 $in_string = false;
69 $values[] = $buffer;
70 $buffer = '';
71 } else if ($in_string) {
72 $buffer .= $curr;
75 if (strlen($buffer) > 0) {
76 // The leftovers in the buffer are the last value (if any)
77 $values[] = $buffer;
80 // Escape double quotes
81 foreach ($values as $key => $value) {
82 $values[$key] = str_replace('"', "&quote;", $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.
86 if (! count($values)
87 || (count($values) == 1 && strlen($values[0]) == 0)
88 ) {
89 array_push($values, '', '', '');
91 // Add an empty value, if there was a request to do so
92 if (! empty($_GET['add_field'])) {
93 $values[] = '';
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
100 && $index > 0
101 && $index <= count($values)
103 unset($values[$index]);
107 // Display the values in text fields
108 $field_counter = 0;
109 foreach ($values as $value) {
110 $field_counter++;
111 echo sprintf(
112 '<tr><td><input class="text" type="text" size="30" value="%s" name="values[' . $field_counter . ']" />' . "\n",
113 $value
115 echo '</td><td>';
116 echo '<input class="drop" type="submit" value="' . __('Drop') . '" name="drop[' . $field_counter . ']" />' . "\n";
117 echo '</td></tr>' . "\n";
120 <tr><td>
121 <input type="submit" class="submit" value="<?php echo __('Go'); ?>" />
122 </td><td>
123 <input type="submit" class="submit" name="add_field" value="<?php echo __('Add a value'); ?>" />
124 </td></tr>
125 </table>
126 </div>
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>
131 <?php
132 // Escape quotes and slashes for usage with MySQL
133 foreach ($values as $key => $value) {
134 $values[$key] = "'";
135 $values[$key] .= str_replace(
136 array("'", "\\", "&#39;", "&#92;"),
137 array("''", '\\\\', "''", '\\\\'),
138 $value
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>
145 </div>
146 </fieldset>
147 </form>
148 </body>
149 </html>