Translation update done using Pootle.
[phpmyadmin.git] / enum_editor.php
blob879023bcd2dd1aac9817f45b220360805fa57a2e
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 (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.
51 $values = array();
52 $in_string = false;
53 $buffer = '';
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 == "'") {
58 $in_string = true;
59 } else if ($in_string && $curr == "\\" && $next == "\\") {
60 $buffer .= "&#92;";
61 $i++;
62 } else if ($in_string && $next == "'" && ($curr == "'" || $curr == "\\")) {
63 $buffer .= "&#39;";
64 $i++;
65 } else if ($in_string && $curr == "'") {
66 $in_string = false;
67 $values[] = $buffer;
68 $buffer = '';
69 } else if ($in_string) {
70 $buffer .= $curr;
73 if (strlen($buffer) > 0) {
74 // The leftovers in the buffer are the last value (if any)
75 $values[] = $buffer;
78 // Escape double quotes
79 foreach ($values as $key => $value) {
80 $values[$key] = str_replace('"', "&quote;", $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.
84 if (! count($values)
85 || (count($values) == 1 && strlen($values[0]) == 0)
86 ) {
87 array_push($values, '', '', '');
89 // Add an empty value, if there was a request to do so
90 if (! empty($_GET['add_field'])) {
91 $values[] = '';
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
98 && $index > 0
99 && $index <= count($values)
101 unset($values[$index]);
105 // Display the values in text fields
106 $field_counter = 0;
107 foreach ($values as $value) {
108 $field_counter++;
109 echo sprintf(
110 '<tr><td><input class="text" type="text" size="30" value="%s" name="values[' . $field_counter . ']" />' . "\n",
111 $value
113 echo '</td><td>';
114 echo '<input class="drop" type="submit" value="' . __('Drop') . '" name="drop[' . $field_counter . ']" />' . "\n";
115 echo '</td></tr>' . "\n";
118 <tr><td>
119 <input type="submit" class="submit" value="<?php echo __('Go'); ?>" />
120 </td><td>
121 <input type="submit" class="submit" name="add_field" value="<?php echo __('Add a value'); ?>" />
122 </td></tr>
123 </table>
124 </div>
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>
129 <?php
130 // Escape quotes and slashes for usage with MySQL
131 foreach ($values as $key => $value) {
132 $values[$key] = "'";
133 $values[$key] .= str_replace(
134 array("'", "\\", "&#39;", "&#92;"),
135 array("''", '\\\\', "''", '\\\\'),
136 $value
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>
143 </div>
144 </fieldset>
145 </form>
146 </body>
147 </html>