- Add a multiselect option to the config editor

This commit is contained in:
dave 2007-11-25 23:30:51 +00:00
parent f6cc5d7326
commit 57f62f7ab4
3 changed files with 27 additions and 5 deletions

View File

@ -48,7 +48,14 @@ function config_editor_parse_from_http_headers($array_name)
$keys = array_keys($_POST[$array_name]);
foreach($keys as $id) {
$ans[$id] = stripslashes($_POST[$array_name][$id]);
if(is_array($_POST[$array_name][$id])) {
$ans[$id] = array();
foreach($_POST[$array_name][$id] as $k=>$v) {
$ans[$id][$k]=stripslashes($v);
}
} else {
$ans[$id] = stripslashes($_POST[$array_name][$id]);
}
}
return $ans;
}
@ -122,7 +129,10 @@ function config_editor($category, $year, $array_name, $self)
$var = config_editor_parse_from_http_headers($array_name);
$varkeys = array_keys($var);
foreach($varkeys as $k) {
$val = mysql_escape_string(stripslashes($var[$k]));
if(is_array($var[$k]))
$val = mysql_escape_string(implode(',',$var[$k]));
else
$val = mysql_escape_string($var[$k]);
$v = mysql_escape_string(stripslashes($k));
mysql_query("UPDATE config SET val=\"$val\" WHERE var=\"$v\" AND `year`='$year'");
print mysql_error();
@ -171,7 +181,10 @@ function config_editor($category, $year, $array_name, $self)
print("<option $sel value=\"no\">No</option>");
print("</select>");
break;
case 'multisel':
$multiple = "multiple=\"multiple\"";
case "enum":
$val = split(',', $val);
$values = $var[$k]['type_values'];
/* Split values */
/* The PERL regex here matches any string of the form
@ -198,13 +211,19 @@ function config_editor($category, $year, $array_name, $self)
preg_match_all("/([^\|=]+)(?:=([^\|]+))?\|?/", $values, $regs);
// print_r($regs);
print("<select name=\"$name\">");
if($multiple != '') {
$sz = count($regs[1]);
if($sz > 5) $sz=5;
$multiple = "$multiple size=\"$sz\"";
$name="{$name}[]";
}
print("<select $multiple name=\"$name\">");
for($x=0; $x<count($regs[1]); $x++) {
$e_key = trim($regs[1][$x]);
$e_val = trim($regs[2][$x]);
if($e_val == "") $e_val = $e_key;
$sel = ($val == $e_key) ? 'selected=selected' : '';
$sel = in_array($e_key, $val) ? 'selected=selected' : '';
print("<option $sel value=\"$e_key\">$e_val</option>");
}
print("</select>");

View File

@ -1 +1 @@
66
67

3
db/db.update.67.sql Normal file
View File

@ -0,0 +1,3 @@
ALTER TABLE `config` CHANGE `type` `type` ENUM( '', 'yesno', 'number', 'text', 'enum', 'multisel' ) NOT NULL;