forked from science-ation/science-ation
Add a function to the config editor to specify which variables the config
should contain. If the config doesn't find those variables for the current year, they are automatically copied in from year=-1. This means that we can update a database and add new config variables and not have to manually add each variable to the current year. It also means someone can't mess up the system and accidentally delete config variables, because they will be recreated.
This commit is contained in:
parent
808290f631
commit
ebd4666f51
@ -34,6 +34,10 @@ ogram; see the file COPYING. If not, write to
|
||||
echo "<a href=\"index.php\"><< ".i18n("Back to Administration")."</a>\n";
|
||||
echo "<a href=\"judges.php\"><< ".i18n("Back to Judges")."</a>\n";
|
||||
|
||||
config_editor_require_vars("Judge Scheduler", $config['FAIRYEAR'],
|
||||
array( "max_projects_per_team", "times_judged",
|
||||
"min_judges_per_team", "max_judges_per_team",
|
||||
"effort", "project_status") );
|
||||
config_editor("Judge Scheduler", $config['FAIRYEAR'], "var", $_SERVER['PHP_SELF']);
|
||||
|
||||
echo "<hr />";
|
||||
|
@ -51,6 +51,32 @@ function config_editor_parse_from_http_headers($array_name)
|
||||
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) {
|
||||
print("Not found in year -1");
|
||||
/* Insert a dummy */
|
||||
mysql_query("INSERT INTO `config` (`var`, `val`,
|
||||
`description`, `category`, `year`, `ord`)
|
||||
VALUES ('$v', '', '',
|
||||
'$category', $year, 99999)");
|
||||
} else {
|
||||
print("Found in year -1");
|
||||
$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
|
||||
|
Loading…
Reference in New Issue
Block a user