Copyright (C) 2005 James Grant This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ?> var]['val'] = $r->val; $var[$r->var]['desc'] = $r->description; $var[$r->var]['category'] = $r->category; $var[$r->var]['ord'] = $r->ord; } return $var; } function config_editor_parse_from_http_headers($array_name) { $ans = array(); if(!is_array($_POST[$array_name])) return $ans; $keys = array_keys($_POST[$array_name]); foreach($keys as $id) { $ans[$id] = stripslashes($_POST[$array_name][$id]); } return $ans; } function config_editor_require_vars($category, $year, $varlist) { global $config; foreach($varlist as $v) { if(isset($config[$v])) continue; /* FInd var with year = -1 */ $q = mysql_query("SELECT * FROM config WHERE ". "var='$v' AND year='-1'"); if(mysql_num_rows($q) != 1) { /* Insert a dummy */ mysql_query("INSERT INTO `config` (`var`, `val`, `description`, `category`, `year`, `ord`) VALUES ('$v', '', '', '$category', $year, 99999)"); } else { $r = mysql_fetch_object($q); mysql_query("INSERT INTO `config` (`var`, `val`, `description`, `category`, `year`, `ord`) VALUES ('$v', '{$r->val}', '{$r->description}', '$category', '$year', {$r->ord})"); } } } /* A complete question editor. Just call it with the * section you want to edit, a year, the array_name to use for * POSTing and GETting the questions (so you can put more than one * edtior on a single page), and give it $_SERVER['PHP_SELF'], because * php_self inside this function is this file. * FUTURE WORK: it would be nice to hide the order, and just implement * a bunch of up/down arrows, and dynamically compute the order for * all elements */ function config_editor($category, $year, $array_name, $self) { global $config; if($_POST['action']=="update") { $var = config_editor_parse_from_http_headers($array_name); $varkeys = array_keys($var); foreach($varkeys as $k) { $val = mysql_escape_string(stripslashes($var[$k])); $v = mysql_escape_string(stripslashes($k)); mysql_query("UPDATE config SET val=\"$val\" WHERE var=\"$v\" AND `year`='$year'"); print mysql_error(); // echo "Saving {$v} = $val
"; } echo happy(i18n("Configuration Updated")); } /* Load questions, then handle up and down, because with up and down we * have to modify 2 questions to maintain the order */ $var = config_editor_load($category, $year); echo "
"; echo ""; $varkeys = array_keys($var); //compute the optimal input size to use $biggest=0; foreach($varkeys as $k) { if(strlen($var[$k]['val'])>$biggest) $biggest=strlen($var[$k]['val']); } if($biggest>30) $size=30; else $size=$biggest+1; foreach($varkeys as $k) { print(""); print(""); print(""; } print("
{$var[$k]['desc']}"); print("\n"); echo "
"); print("\n"); print("\n"); print("\n"); echo "
"; } ?>