");
$Cancel_process=false;
$id=get_int("id");
$Value = get_var("Value");
$Explanation = get_var("Explanation");
$Ac_view = get_var("ac_view");
$Ac_edit = get_var("ac_edit");
$Ac_audit = get_var("ac_audit");
$Ac_jc = get_var("ac_jc");
$Ac_registration = get_var("ac_registration");
$Ac_localorg = get_var("ac_localorg");
$Ac_chair = get_var("ac_chair");
$Default = get_var("Default");
$Empty = get_var("empty");
// Action= is the default
if( !isset($_REQUEST['cmd']) || !in_array($_REQUEST['cmd'], array("info", "edit", "save", "setcategory")) ) $_REQUEST['cmd']="";
if( in_array($_REQUEST['cmd'], array("info", "edit", "save")) AND !$Cancel_process ) {
#################
### Load Data ###
#################
$query="SELECT `Name`, `Value`, `RegEx`, `Explanation`, `ac_view`, `ac_edit`, `ac_audit`, `ac_jc`, `ac_registration`, `ac_localorg`, `ac_chair`, ".(in_array("setup_admin", $_SESSION['sess_functions']) ? "'edit'" : "`ac_".$accessField."`")." AS `access`, `default`, `empty`
FROM `setup` WHERE `id`=".addslashes($id);
if( @mysql_num_rows( $res=doquery($query) )==1 ) {
// Ok, load data
$row=mysql_fetch_array($res);
if( $_REQUEST['cmd']=="info" || $row['access']=="edit" ) {
$Name=$row['Name'];
if( $_REQUEST['cmd']=="info" || $_REQUEST['cmd']=="edit" ) $Value=$row['Value']; // Only load value when editing
$RegEx=$row['RegEx'];
if( !($_REQUEST['cmd']=="save" AND in_array("setup_admin", $_SESSION['sess_functions'])) ) {
$Explanation=$row['Explanation'];
$Ac_view=$row['ac_view'];
$Ac_edit=$row['ac_edit'];
$Ac_audit=$row['ac_audit'];
$Ac_jc=$row['ac_jc'];
$Ac_registration=$row['ac_registration'];
$Ac_localorg=$row['ac_localorg'];
$Ac_chair=$row['ac_chair'];
}
if( (!($_REQUEST['cmd']=="save" AND in_array("setup_admin", $_SESSION['sess_functions']))) OR !in_array("setup_admin", $_SESSION['sess_functions']) ) {
$Default=$row['default'];
$Empty=$row['empty'];
}
}else {
echoln("You are not authorized to edit this entry.");
$Cancel_process=true;
}
}else {
// No result, error loading data
echoln("Unable to find data for this entry.");
$Cancel_process=true;
}
}
if( ($_REQUEST['cmd']=="save") AND (!$Cancel_process) ) {
###################
### ERROR CHECK ###
###################
$Error_msg = array();
$Error=false;
// Check for errors before saving
switch( $RegEx ) { // /(^ $)/
case "[url]":
$re="/(^http(s)?:\/\/(\w|-|_)+(\.(\w|-|_)+)*\.[a-zA-Z]{2,4}(:\d{1,5})?\/.*$)/";
$re_msg="This is not a valid url. Please supply a valid one.";
break;
case "[email]":
$re="/(^(\w|\.|-|\+)+@(\w|-)+(\.(\w|-)+)*\.[a-zA-Z]{2,4}$)/";
$re_msg="This is not a valid e-mail address. Please supply a valid one.";
break;
case "[int]":
$re="/(^-?\d+$)/";
$re_msg="This is not an integer. Please supply an integer.";
break;
case "[date]":
$re="/^(([0-2][0-9])|30|31)\.((0[0-9])|(1[0-2]))\.(19|20)[0-9]{2}$/";
$re_msg="This is not a valid date. Please supply the date as 'dd.mm.yyyy'.";
break;
case "[datetime]":
$re = "/^(([0-2][0-9])|30|31)\.((0[0-9])|(1[0-2]))\.(19|20)[0-9]{2} [0-2][0-9]:[0-5][0-9]$/";
$re_msg = "This is not a valid date and time. Please supply the date as 'dd.mm.yyyy hh:mm'.";
break;
case "[phone]":
$re="/(^(\+)?(\d| |-){6,50}$)/";
$re_msg="This is not a valid telephone number. Please supply a valid one (starting with + and containing only numbers, spaces and dashes.";
break;
case "[bool]":
$re="/(^(true|false)$)/";
$re_msg="Please choose one of the options given.";
break;
case "[text]";
$re="/.*/";
break;
default:
$re1="/(^\[.+(\|.+)+\]$)/";
$re2="/(^\/.+\/$)/";
if( preg_match($re1,$RegEx) ) {
// [ | | ]
$re="/(^".substr($RegEx, 1, -1)."$)/";
$re_msg="Please choose one of the options given.";
}elseif( preg_match($re2,$RegEx) ) {
// RegEx provided
$re=$RegEx;
$re_msg="The value provided is not valid.";
}elseif( !strlen($RegEx) ) {
// No restrictions
$re="/(^.*$)/";
}else {
// Unknown
$Error_msg[] = "Unknown kind of value. Contact the webmaster.";
$Error=true;
}
}
if( !$Error AND !preg_match($re, $Value) ) {
if( $Empty=="yes" AND $Value=="" ) {
// empty value, this is allowed for this item
}else {
// Error in value
$Error_msg[] = $re_msg;
$Error=true;
}
}
if( in_array("setup_admin", $_SESSION['sess_functions']) AND !$Error AND !preg_match($re, $Default) ) {
if( $Default=="" ) {
// empty default, this is allowed for this item
}else {
// Error in value
$Error_msg[] = "$re_msg";
$Error=true;
}
}
if( !$Error ) {
#################
### SAVE DATA ###
#################
if( in_array("setup_admin", $_SESSION['sess_functions']) )
$query="UPDATE `setup` SET `Value`='".addslashes($Value)."', `Explanation`='".addslashes($Explanation)."', `ac_view`='".addslashes($Ac_view)."',
`ac_edit`='".addslashes($Ac_edit)."', `ac_audit`='".addslashes($Ac_audit)."', `ac_jc`='".addslashes($Ac_jc)."', `ac_registration`='".addslashes($Ac_registration)."',
`ac_localorg`='".addslashes($Ac_localorg)."', `ac_chair`='".addslashes($Ac_chair)."', `default`='".addslashes($Default)."', `empty`='".addslashes($Empty)."'
WHERE `id`=".addslashes($id);
else
$query="UPDATE `setup` SET `Value`='".addslashes($Value)."' WHERE `id`=".addslashes($id);
if( doquery($query) ) {
// Saving succeeded
echoln("Option saved successfully.");
}else {
// Saving failed
echoln("Unable to update option.");
$Cancel_process=true;
}
}else {
// Error found, reshow form
echoln("
");
for( $i=0; $i".$Error_msg[$i]."");
}
echoln("
");
$_REQUEST['cmd']="edit";
$Cancel_process=false;
}
}elseif( !$Cancel_process ) {
// Not save action, so there were no errors
$Error=false;
}
if( $_REQUEST['cmd']=="setcategory" ) {
################
### Category ###
################
if( isset($_REQUEST['category']) ) $_SESSION['setup_category']=$_REQUEST['category'];
}
if( ($_REQUEST['cmd']=="edit" || $_REQUEST['cmd']=="info") AND (!$Cancel_process) ) {
#################
### Show form ###
#################
echoln("Back");
if( $_REQUEST['cmd']=="edit" ) {
echoln("");
echoln("");
}
}else {
#################
### Show list ###
#################
if( $_SESSION['setup_category'] == "jc" && !$setup['CandidateAdminOpen'] ) {
echoln("
Warning: master lock on candidatures in place. When configuration is done, contact the webmaster to have the lock removed. Candidating will not be available with this lock.
Warning: master lock on applications in place. When configuration is done, contact the webmaster to have the lock removed. Applying will not be available with this lock.
");
}
// Category
$query="SELECT `category` FROM `setup` ".(in_array("setup_admin", $_SESSION['sess_functions']) ? "" : "WHERE `ac_".$accessField."`='edit' OR `ac_".$accessField."`='view' ")."GROUP BY `category` ORDER BY `category`";
if( @mysql_num_rows( $res=doquery($query) )>0 ) {
echoln("");
$QW="WHERE `category`='".addslashes($_SESSION['setup_category'])."' ".(in_array("setup_admin", $_SESSION['sess_functions']) ? "" : "AND (`ac_".$accessField."`='edit' OR `ac_".$accessField."`='view')");
}else {
$QW="";
}
$query="SELECT `id`, `Name`, `Value`, `Explanation`, ".(in_array("setup_admin", $_SESSION['sess_functions']) ? "'edit'" : "`ac_".$accessField."`")." AS `access`, `empty`, `default`
FROM `setup` $QW
ORDER BY `Name`";
if( @mysql_num_rows( $res=doquery($query) )>0 ) {
echoln("