Updated enum/set editor (submit button has only one function, escapes special characters, has more instructions for formatting
This commit is contained in:
@@ -10,47 +10,48 @@ require_once './libraries/header_meta_style.inc.php';
|
||||
<body>
|
||||
<form action="enum_editor.php" method="get">
|
||||
<div id="enum_editor_no_js">
|
||||
<h3>Values for the column "<?php echo $_GET['field']; ?>"</h3>
|
||||
<p>Enter each value in a separate field.</p>
|
||||
<h3><?php echo __('Values for the column "' . urldecode($_GET['field']) . '"'); ?></h3>
|
||||
<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">
|
||||
<?php
|
||||
// Get the new values from the submitted form or the old ones from tbl_alter.php
|
||||
$values = '';
|
||||
for($i = 1; $i <= $_GET['num_fields']; $i++) {
|
||||
$input_name = "field" . $i;
|
||||
$values .= $_GET[$input_name] . ',';
|
||||
}
|
||||
if (isset($_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;
|
||||
$stripped_values = array();
|
||||
foreach(split(",", $values) as $value) {
|
||||
if(trim($value) != "") {
|
||||
$field_counter++;
|
||||
echo '<input type="text" size="30" value=' . $value . ' name="field' . $field_counter . '" />';
|
||||
$stripped_values[] = $value;
|
||||
echo sprintf('<input type="text" size="30" value="%s" name="field' . $field_counter . '" />', htmlspecialchars($value));
|
||||
$stripped_values[] = htmlspecialchars($value);
|
||||
}
|
||||
}
|
||||
|
||||
$total_fields = $field_counter;
|
||||
// If extra fields are added, display them
|
||||
if($_GET['add_extra_fields']) {
|
||||
$extra_fields = $_GET['extra_fields'];
|
||||
$total_fields = $extra_fields + $field_counter;
|
||||
for($i = ($field_counter+1); $i <= $total_fields; $i++) {
|
||||
if(isset($_GET['extra_fields'])) {
|
||||
$total_fields += $_GET['extra_fields'];
|
||||
for($i = $field_counter+1; $i <= $total_fields; $i++) {
|
||||
echo '<input type="text" size="30" name="field' . $i . '"/>';
|
||||
}
|
||||
} else {
|
||||
$total_fields = $field_counter;
|
||||
}
|
||||
|
||||
?>
|
||||
</div>
|
||||
<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>
|
||||
<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="num_fields" value="<?php echo $total_fields; ?>" />
|
||||
<input type="submit" value="Go" />
|
||||
</form>
|
||||
|
||||
|
@@ -1786,9 +1786,11 @@ $(document).ready(function() {
|
||||
var values = $(this).parent().prev("input").attr("value").split(",");
|
||||
$.each(values, function(index, 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 + " />");
|
||||
} else {
|
||||
$("#enum_editor #values").append("<input type='text' value='' />");
|
||||
}
|
||||
});
|
||||
// So we know which column's data is being edited
|
||||
@@ -1806,17 +1808,13 @@ $(document).ready(function() {
|
||||
disable_popup();
|
||||
});
|
||||
|
||||
// When the submit button is clicked, put the data back into the original form if
|
||||
// the "add x more values" checkbox is not checked. Otherwise, just insert x more
|
||||
// textboxes
|
||||
$("#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++) {
|
||||
// When "add a new value" is clicked, append an empty text field
|
||||
$("a[class='add_value']").click(function() {
|
||||
$("#enum_editor #values").append("<input type='text' />");
|
||||
}
|
||||
// Uncheck it
|
||||
$("input[type='checkbox'][name='add_extra_fields']").removeAttr("checked");
|
||||
} else {
|
||||
});
|
||||
|
||||
// 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);
|
||||
@@ -1824,10 +1822,10 @@ $(document).ready(function() {
|
||||
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();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
|
@@ -371,7 +371,7 @@ for ($i = 0; $i < $num_fields; $i++) {
|
||||
. ' class="textfield" />'
|
||||
. '<p class="enum_notice" id="enum_notice_' . $i . '_' . ($ci - $ci_offset) . '">';
|
||||
$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>';
|
||||
$ci++;
|
||||
|
||||
@@ -797,9 +797,10 @@ if ($action == 'tbl_create.php') {
|
||||
|
||||
<div id="enum_editor">
|
||||
<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>
|
||||
<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>
|
||||
</div>
|
||||
|
||||
|
Reference in New Issue
Block a user