science-ation/config_editor.inc.php
dave e7d726355d The new judge scheduler.
- Missing: Having a project judged more than once by different judging teams is
  untested, I don't htink it'll work properly, still working on that part.
- Missing: Auto updating the configuration if any of the variables are missing.
- Missing: A way to preserve judging questions (like willing_chair), so the
  user doesn't delete them and break the scheduler, OR, notice saying that the
  question has been deleted and the scheduler won't use the chair calculations,
  then we need a way to add them back in with the click of a button.
2006-08-01 19:43:15 +00:00

105 lines
3.2 KiB
PHP

<?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website: http://www.sfiab.ca
Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
Copyright (C) 2005 James Grant <james@lightbox.org>
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.
*/
?>
<?
function config_editor_load($append, $year)
{
$query = "SELECT * FROM config WHERE year='$year' ";
if($append != '') {
$query .= " AND var LIKE '{$append}%'";
}
$q = mysql_query($query);
print(mysql_error());
$var = array();
while($r=mysql_fetch_object($q)) {
$var[$r->var]['val'] = $r->val;
$var[$r->var]['desc'] = $r->description;
}
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;
}
/* 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($append, $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\"");
print mysql_error();
// echo "Saving {$v} = $val<br>";
}
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($append, $year);
echo "<form method=\"post\" action=\"$self\">";
echo "<table>";
$varkeys = array_keys($var);
foreach($varkeys as $k) {
print("<tr>");
print("<td>{$var[$k]['desc']}</td>");
print("<td>");
print("<input size=\"5\" type=\"text\" name=\"${array_name}[$k]\" value=\"".htmlspecialchars($var[$k]['val'])."\">\n");
echo "</td></tr>";
}
print("</table>");
print("<input type=hidden name=\"action\" value=\"update\" >\n");
print("<input type=\"submit\" value=\"".i18n("Save Configuration")."\" />\n");
echo "</form>";
}
?>