.
*/
include("./include/include.php");
admin_header();
if( !in_array("candidate_viewpositions", $_SESSION['sess_functions']) ) {
echoln("You are not authorized to see this page.");
}else {
echoln("
Candidates setup
");
$Cancel_process=false;
if( !in_array("candidate_editpositions", $_SESSION['sess_functions']) ) {
$_REQUEST['cmd'] = "";
}
$id = get_int('id');
$Position = stripslashes(get_var('position'));
$Places = get_int('places');
$Deadline = stripslashes(get_var('deadline'));
if( isset($_REQUEST['cmd']) && $_REQUEST['cmd']=="new" ) {
###########
### New ###
###########
$id = "";
$Position = "";
$Places = 1;
$Deadline = "auto";
}
if( isset($_REQUEST['cmd']) && ($_REQUEST['cmd']=="edit" || $_REQUEST['cmd']=="delete") && !$Cancel_process ) {
#################
### Load Data ###
#################
$query="SELECT `position`, `places`, `deadline`
FROM `candidatepost` WHERE `id`=".addslashes($id);
if( @mysql_num_rows( $res=doquery($query) )==1 ) {
// Ok, load data
$row = mysql_fetch_array($res);
$Position = $row['position'];
$Places = $row['places'];
$Deadline = $row['deadline'];
}else {
// Query failed
echoln("Error: unable to load the data. Please try again later.
");
$Cancel_process=true;
}
}
if( isset($_REQUEST['cmd']) && $_REQUEST['cmd']=="delete" && !$Cancel_process ) {
##############
### DELETE ###
##############
$query = "SELECT `Position` FROM `candidates` WHERE `Position`=".addslashes($id);
if( @mysql_num_rows( doquery($query) )==0 ) {
if( isset($_GET['confirm']) && $_GET['confirm']=="yes" ) {
// Delete this user
$query="DELETE FROM `candidatepost` WHERE `id`=".addslashes($id);
if( doquery($query) ) {
// Successfull
echoln("Successfully deleted '".$Position."'.");
}else {
// Error
echoln("Unable to delete position. Please try again.");
}
$_REQUEST['cmd']="";
}else {
// Ask for confirmation
echoln("Are you sure you want to delete '".$Position."'?");
echoln("Yes ");
echoln("No
");
}
}else {
echoln("There is already candidates for this position, you cannot delete it any more.");
debug("Number: ".mysql_num_rows( doquery($query) ));
$_REQUEST['cmd']="";
}
}
if( isset($_REQUEST['cmd']) && $_REQUEST['cmd']=="save" && !$Cancel_process ) {
###################
### ERROR CHECK ###
###################
echoln("");
$Error[0]=false;
// Check for errors before saving
//Position
if( strlen($Position)<3 OR strlen($Position)>48 ) {
echoln(" - The position should be maximum 48 characters.
");
$Error['position']=true; $Error[0]=true;
}
//Places
if( $Places<1 ) {
echoln(" - Please provide a positive number of available places.
");
$Error['places']=true; $Error[0]=true;
}
//Deadline
if( !in_array($Deadline, array('auto', 'open', 'closed')) ) {
echoln(" - Please select the deadline method.
");
$Error['Deadline']=true; $Error[0]=true;
}
if( !($id>0) ) {
// Check for duplicate user name
$query="SELECT `id` FROM `candidatepost` WHERE `position`='".addslashes($Position)."'";
if( @mysql_num_rows( doquery($query) )>0 ) {
echoln(" - There already exists a position with this name.
");
$Error['position']=true; $Error[0]=true;
}
}
echoln("
");
if( !$Error[0] ) {
#################
### SAVE DATA ###
#################
if( $id>0 ) {
// Edited entry, update
$query="UPDATE `candidatepost` SET `position`='".addslashes($Position)."', `places`=".addslashes($Places).", `deadline`='".addslashes($Deadline)."'
WHERE `id`=".addslashes($id);
if( doquery($query) ) {
// Saving succeeded
echoln("Position saved successfully.");
}else {
// Saving failed
echoln("Saving of position failed. Please try again.");
}
}else {
// New entry, insert and mail password
$query="INSERT INTO `candidatepost` (`position`, `places`, `deadline`)
VALUES ('".addslashes($Position)."', ".addslashes($Places).", '".addslashes($Deadline)."')";
if( doquery($query) ) {
$id = mysql_insert_id();
// Saving succeeded
echoln("New position saved successfully.");
}else {
// Saving failed
echoln("Saving of new position failed. Please try again.");
}
}
}else {
// Error found, reshow form
if( $id>0 ) {
$_REQUEST['cmd']="edit"; // id avail, so this was an edit
}else {
$_REQUEST['cmd']="new"; // id unavailable, so this was a new entry
}
}
}elseif( !$Cancel_process ) {
// Not save action, so there were no errors
$Error[0]=false;
}
if( isset($_REQUEST['cmd']) && ($_REQUEST['cmd']=="new" OR $_REQUEST['cmd']=="edit") AND !$Cancel_process ) {
#################
### Show form ###
#################
echoln("Back");
echoln("");
}elseif( !isset($_REQUEST['cmd']) || ($_REQUEST['cmd']!="delete" || ( $_REQUEST['cmd']=="delete" && isset($_GET['confirm']) && $_GET['confirm']=="yes" )) ) {
#################
### Show list ###
#################
if( !$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.
");
}
echoln("Add new position");
$query="SELECT `candidatepost`.`id`, `position`, `places`, `deadline`, COUNT(`cand_extraquestions`.`id`) AS `count_extraquestions` FROM `candidatepost` LEFT JOIN `cand_extraquestions` ON `cand_extraquestions`.`candidatepost_id` = `candidatepost`.`id` GROUP BY `candidatepost`.`id` , `position` , `places` , `deadline` ORDER BY `position`";
if( @mysql_num_rows( $res=doquery($query) )>0 ) {
echoln("");
echoln(" ");
echoln(" | Position | ");
echoln(" Vacant places | ");
echoln(" Deadline | ");
echoln(" | ");
echoln("
");
$i=0;
while( $row=mysql_fetch_array($res) ) {
$i++;
if( ($i%2)==1 )
echoln(" ");
else
echoln("
");
echoln(" | ".$row['position']." | ");
echoln(" ".$row['places']." | ");
echoln(" ".$row['deadline']." | ");
echoln(" ");
echoln(" edit ");
echoln(" delete ");
echoln(" questions (" . $row['count_extraquestions'] . ")");
echoln(" | ");
echoln("
");
}
echoln("
");
}
}
}
admin_footer();
?>