Updated enum/set editor (submit button has only one function, escapes special characters, has more instructions for formatting
This commit is contained in:
@@ -10,50 +10,51 @@ require_once './libraries/header_meta_style.inc.php';
|
|||||||
<body>
|
<body>
|
||||||
<form action="enum_editor.php" method="get">
|
<form action="enum_editor.php" method="get">
|
||||||
<div id="enum_editor_no_js">
|
<div id="enum_editor_no_js">
|
||||||
<h3>Values for the column "<?php echo $_GET['field']; ?>"</h3>
|
<h3><?php echo __('Values for the column "' . urldecode($_GET['field']) . '"'); ?></h3>
|
||||||
<p>Enter each value in a separate field.</p>
|
<p><?php echo __('Enter each value in a separate field, enclosed in single quotes. If you ever need to put a backslash ("\") or a single quote ("\'") amongst those values, precede it with a backslash (for example \'\\\\xyz\' or \'a\\\'b\').'); ?></p>
|
||||||
<div id="values">
|
<div id="values">
|
||||||
<?php
|
<?php
|
||||||
// Get the new values from the submitted form or the old ones from tbl_alter.php
|
|
||||||
$values = '';
|
$values = '';
|
||||||
for($i = 1; $i <= $_GET['num_fields']; $i++) {
|
|
||||||
$input_name = "field" . $i;
|
|
||||||
$values .= $_GET[$input_name] . ',';
|
|
||||||
}
|
|
||||||
if (isset($_GET['values'])) {
|
if (isset($_GET['values'])) {
|
||||||
$values = urldecode($_GET['values']);
|
$values = urldecode($_GET['values']);
|
||||||
|
} elseif (isset($_GET['num_fields'])) {
|
||||||
|
for($field_num = 1; $field_num <= $_GET['num_fields']; $field_num++) {
|
||||||
|
$values .= $_GET['field' . $field_num] . ",";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Display the input fields containing each of the values, removing the empty ones
|
|
||||||
$field_counter = 0;
|
$field_counter = 0;
|
||||||
$stripped_values = array();
|
$stripped_values = array();
|
||||||
foreach(split(",", $values) as $value) {
|
foreach(split(",", $values) as $value) {
|
||||||
if(trim($value) != "") {
|
if(trim($value) != "") {
|
||||||
$field_counter++;
|
$field_counter++;
|
||||||
echo '<input type="text" size="30" value=' . $value . ' name="field' . $field_counter . '" />';
|
echo sprintf('<input type="text" size="30" value="%s" name="field' . $field_counter . '" />', htmlspecialchars($value));
|
||||||
$stripped_values[] = $value;
|
$stripped_values[] = htmlspecialchars($value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$total_fields = $field_counter;
|
||||||
// If extra fields are added, display them
|
// If extra fields are added, display them
|
||||||
if($_GET['add_extra_fields']) {
|
if(isset($_GET['extra_fields'])) {
|
||||||
$extra_fields = $_GET['extra_fields'];
|
$total_fields += $_GET['extra_fields'];
|
||||||
$total_fields = $extra_fields + $field_counter;
|
for($i = $field_counter+1; $i <= $total_fields; $i++) {
|
||||||
for($i = ($field_counter+1); $i <= $total_fields; $i++) {
|
|
||||||
echo '<input type="text" size="30" name="field' . $i . '"/>';
|
echo '<input type="text" size="30" name="field' . $i . '"/>';
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$total_fields = $field_counter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
<p>
|
<p>
|
||||||
<input type="checkbox" name="add_extra_fields"> Add <input type="text" value="1" name="extra_fields" size="2"/> more values
|
<a href="enum_editor.php?token=<?php echo urlencode($_GET['token']); ?>&field=<?php echo urlencode($_GET['field']); ?>&extra_fields=<?php echo $_GET['extra_fields'] + 1; ?>&values=<?php echo $values; ?>">
|
||||||
|
+ Restart insertion and add a new value
|
||||||
|
</a>
|
||||||
</p>
|
</p>
|
||||||
<input type="hidden" name="token" value="<?php echo $_GET['token']; ?>" />
|
<input type="hidden" name="token" value="<?php echo $_GET['token']; ?>" />
|
||||||
<input type="hidden" name="num_fields" value="<?php echo $total_fields; ?>" />
|
|
||||||
<input type="hidden" name="field" value="<?php echo $_GET['field']; ?>" />
|
<input type="hidden" name="field" value="<?php echo $_GET['field']; ?>" />
|
||||||
|
<input type="hidden" name="num_fields" value="<?php echo $total_fields; ?>" />
|
||||||
<input type="submit" value="Go" />
|
<input type="submit" value="Go" />
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div id="enum_editor_output">
|
<div id="enum_editor_output">
|
||||||
<h3>Output</h3>
|
<h3>Output</h3>
|
||||||
<p>Copy and paste the joined values into the "Length/Values" field</p>
|
<p>Copy and paste the joined values into the "Length/Values" field</p>
|
||||||
|
@@ -1786,9 +1786,11 @@ $(document).ready(function() {
|
|||||||
var values = $(this).parent().prev("input").attr("value").split(",");
|
var values = $(this).parent().prev("input").attr("value").split(",");
|
||||||
$.each(values, function(index, val) {
|
$.each(values, function(index, val) {
|
||||||
if(jQuery.trim(val) != "") {
|
if(jQuery.trim(val) != "") {
|
||||||
|
// escape the single quotes, except the mandatory ones enclosing the entire string
|
||||||
|
val = val.substr(1, val.length-2).replace(/'/g, "'");
|
||||||
|
// escape the greater-than symbol
|
||||||
|
val = val.replace(/>/g, ">");
|
||||||
$("#enum_editor #values").append("<input type='text' value=" + val + " />");
|
$("#enum_editor #values").append("<input type='text' value=" + val + " />");
|
||||||
} else {
|
|
||||||
$("#enum_editor #values").append("<input type='text' value='' />");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// So we know which column's data is being edited
|
// So we know which column's data is being edited
|
||||||
@@ -1806,30 +1808,26 @@ $(document).ready(function() {
|
|||||||
disable_popup();
|
disable_popup();
|
||||||
});
|
});
|
||||||
|
|
||||||
// When the submit button is clicked, put the data back into the original form if
|
// When "add a new value" is clicked, append an empty text field
|
||||||
// the "add x more values" checkbox is not checked. Otherwise, just insert x more
|
$("a[class='add_value']").click(function() {
|
||||||
// textboxes
|
$("#enum_editor #values").append("<input type='text' />");
|
||||||
$("#enum_editor input[type='submit']").click(function() {
|
|
||||||
if($("input[type='checkbox'][name='add_extra_fields']").attr("checked")) {
|
|
||||||
for(i = 0; i < $("input[type='text'][name='extra_fields']").attr("value"); i++) {
|
|
||||||
$("#enum_editor #values").append("<input type='text' />");
|
|
||||||
}
|
|
||||||
// Uncheck it
|
|
||||||
$("input[type='checkbox'][name='add_extra_fields']").removeAttr("checked");
|
|
||||||
} else {
|
|
||||||
var value_array = new Array();
|
|
||||||
$.each($("#enum_editor #values input"), function(index, input_element) {
|
|
||||||
val = jQuery.trim(input_element.value);
|
|
||||||
if(val != "") {
|
|
||||||
value_array.push("'" + val + "'");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
var values_id = $("#enum_editor input[type='hidden']").attr("value");
|
|
||||||
$("input[id='" + values_id + "']").attr("value", value_array.join(","));
|
|
||||||
disable_popup();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// When the submit button is clicked, put the data back into the original form
|
||||||
|
$("#enum_editor input[type='submit']").click(function() {
|
||||||
|
var value_array = new Array();
|
||||||
|
$.each($("#enum_editor #values input"), function(index, input_element) {
|
||||||
|
val = jQuery.trim(input_element.value);
|
||||||
|
if(val != "") {
|
||||||
|
value_array.push("'" + val + "'");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// get the Length/Values text field where this value belongs
|
||||||
|
var values_id = $("#enum_editor input[type='hidden']").attr("value");
|
||||||
|
$("input[id='" + values_id + "']").attr("value", value_array.join(","));
|
||||||
|
disable_popup();
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hides certain table structure actions, replacing them with the word "More". They are displayed
|
* Hides certain table structure actions, replacing them with the word "More". They are displayed
|
||||||
* in a dropdown menu when the user hovers over the word "More."
|
* in a dropdown menu when the user hovers over the word "More."
|
||||||
|
@@ -371,7 +371,7 @@ for ($i = 0; $i < $num_fields; $i++) {
|
|||||||
. ' class="textfield" />'
|
. ' class="textfield" />'
|
||||||
. '<p class="enum_notice" id="enum_notice_' . $i . '_' . ($ci - $ci_offset) . '">';
|
. '<p class="enum_notice" id="enum_notice_' . $i . '_' . ($ci - $ci_offset) . '">';
|
||||||
$content_cells[$i][$ci] .= __('ENUM or SET data too long?')
|
$content_cells[$i][$ci] .= __('ENUM or SET data too long?')
|
||||||
. '<a href="enum_editor.php?' . PMA_generate_common_url() . '&values=' . urlencode($length_to_display) . '&field=' . $field . '" class="open_enum_editor" target="blank"> '
|
. '<a onclick="return false;" href="enum_editor.php?' . PMA_generate_common_url() . '&values=' . urlencode($length_to_display) . '&field=' . (isset($row['Field']) ? urlencode($row['Field']) : "") . '" class="open_enum_editor" target="_blank"> '
|
||||||
. __('Get more editing space') . '</a></p>';
|
. __('Get more editing space') . '</a></p>';
|
||||||
$ci++;
|
$ci++;
|
||||||
|
|
||||||
@@ -797,9 +797,10 @@ if ($action == 'tbl_create.php') {
|
|||||||
|
|
||||||
<div id="enum_editor">
|
<div id="enum_editor">
|
||||||
<a class="close_enum_editor">Close</a>
|
<a class="close_enum_editor">Close</a>
|
||||||
<p>Enter each value in a separate field.</p>
|
<h3><?php echo __('Values for the column "' . (isset($row['Field']) ? urlencode($row['Field']) : "") . '"'); ?></h3>
|
||||||
|
<p><?php echo __('Enter each value in a separate field. If you ever need to put a backslash ("\") or a single quote ("\'") amongst those values, precede it with a backslash (for example \'\\\\xyz\' or \'a\\\'b\').'); ?></p>
|
||||||
<div id="values"></div>
|
<div id="values"></div>
|
||||||
<p><input type="checkbox" name="add_extra_fields" /> Add <input type="text" value="1" name="extra_fields" size="2" /> more values</p>
|
<p><a class="add_value">+ Add a new value</a></p>
|
||||||
<input type="submit" value="Go" /> <a class="cancel_enum_editor">Cancel</a>
|
<input type="submit" value="Go" /> <a class="cancel_enum_editor">Cancel</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user