. */ if( !isset($candidate_id) ) { exit(); } include("./include/Cand.php"); include("./include/CandidateUI.php"); include("./include/CandidateMail.php"); $candidateStatus = candidate_status($Position); if( $setup['CandidateAdminOpen']==false ) { // Candidatures locked by admin echoln("The candidatures have been locked by the webmaster, as it is not ready to be used yet."); echoln("
Before the candidatures can open, the Juridical Commission has to finalize the setup first, please be a bit patient."); }elseif( $candidate_id == 0 && !is_before("CandidateEndReal") ) { // Candidatures deadline passed echoln("The candidature deadline passed, you cannot candidate any more."); echoln("
The deadline to candidate for any position was on ".$setup['CandidateEndReal'].". For next time you are suggested to candidate well before the deadline."); }elseif( $candidate_id == 0 && $candidateStatus != "open" ) { if( $candidateStatus == "closed" ) { echoln("The candidature deadline passed, you cannot candidate any more."); echoln("
The deadline to candidate for any position was on ".$setup['CandidateDeadline'].". After this date, only candidatures are possible for positions where there are not enough candidates yet. For next time you are suggested to candidate well before the deadline."); }else { echoln("Candidating for this position is temporally closed."); echoln("
The deadline to candidate for any position was on ".$setup['CandidateDeadline'].". After this date, only candidatures are possible for positions where there are not enough candidates yet. For this position, there are enough candidatures, but they are not all approved yet. In case some are rejected, candidating for this position will open again."); } }else { // Read extra questions $extraQuestions = array(); $query = "SELECT `id`, `question`, `maxlength` FROM `cand_extraquestions` WHERE `candidatepost_id` = " . addslashes($Position) . " ORDER BY `order`"; if( @mysql_num_rows( $res=doquery($query) )>0 ) { while( $row = mysql_fetch_assoc($res) ) { $extraQuestions[$row['id']] = $row; } } if( $candidate_id > 0 ) { $query = "SELECT `question_id`, `answer` FROM `cand_extraanswers` WHERE `cand_id` = " . addslashes($candidate_id); if( @mysql_num_rows( $res=doquery($query) )>0 ) { $extraAnswers = array(); while( $row = mysql_fetch_assoc($res) ) { $extraAnswers[$row['question_id']] = $row['answer']; } } } // Read the files from ./include/CandFields/*.php and add them to $fields; $fields = array(); $sepfields = array(); // All fields including separators $dir = dirname($_SERVER["SCRIPT_FILENAME"])."/include/CandFields/*.php"; if( is_dir(dirname($dir)) ) { foreach( glob($dir) as $file ) { if( is_file($file) ) { $field = substr(basename($file, ".php"), 3); if( $field != "Separator" ) { include($file); if( $field == "ExtraQuestion" ) { foreach( array_keys($extraQuestions) as $questionId ) { $fields[] = $field . "_" . $questionId; } }else { $fields[] = $field; } } if( $field == "ExtraQuestion" ) { foreach( array_keys($extraQuestions) as $questionId ) { $sepfields[] = $field . "_" . $questionId; } }else { $sepfields[] = $field; } } } }else { debug(dirname($dir)." does not exist, failed loading candidature form fields"); } // Load the values from MySQL in case we are editing $values = array(); if( $candidate_id>0 ) { $query="SELECT * FROM `candidates` WHERE `id`=".addslashes($candidate_id); if( @mysql_num_rows( $res=doquery($query) )==1 ) { $values = mysql_fetch_assoc($res); }else { echoln("Failed loading your candidature. Editing not possible. Switching back to a new candidature.

"); $candidate_id=0; } } // Create user interface $ui = new CandidateUI($candidate_id, $Position); // Create the classes, add a value (from aegee.org account (new) or from MySQL (edit)) $person = array(); for( $i=0; $i 0 ) { // Edit - get value from MySQL if( isset($extraAnswers[$questionId]) ) { $person[ $fields[$i] ]->init($extraAnswers[$questionId]); } } }else { $class="Cand".$fields[$i]; $person[ $fields[$i] ] = new $class($candidate_id); if( $candidate_id>0 ) { // Edit - get value from MySQL if( isset($values[ strtolower($fields[$i]) ]) ) $person[ $fields[$i] ]->init($values[ strtolower($fields[$i]) ]); }else { // New - get value from aegee.org account when available if( isset($_SESSION[ 'user_'.$fields[$i] ]) ) $person[ $fields[$i] ]->init($_SESSION[ 'user_'.$fields[$i] ]); } } } if( $candidate_id==0 ) $person['Position']->init($Position); // If new candidature, pre-select position if( $_SERVER['REQUEST_METHOD']=="POST" AND !isset($_REQUEST['login']) ) { // Try to save the form $error = false; // Check all fields $usefields = array(); for( $i=0; $iget_access( ($candidate_id==0) )==Cand::ACCESS_RW ) { $usefields[] = $fields[$i]; $error += !$person[ $fields[$i] ]->check(); } } if( $candidate_id==0 && $person['Position']->get_id()>0 ) { // New candidature, check for duplicate if( isset($_SESSION['sess_functions']) ) { $query="SELECT `id` FROM `candidates` WHERE ((`FirstName`='".addslashes($person['FirstName']->get())."' AND `LastName`='".addslashes($person['LastName']->get())."') OR `username`='".addslashes($person['FirstName']->get()." ".$person['LastName']->get())."') AND `Position`=".addslashes($person['Position']->get_id()); }else { $query="SELECT `id` FROM `candidates` WHERE ((`FirstName`='".addslashes($person['FirstName']->get())."' AND `LastName`='".addslashes($person['LastName']->get())."') OR (`username`='".addslashes(isset($_SESSION['sess_name'])?$_SESSION['sess_name']:"[unknown]")."' AND `username`!='') OR `username`='".addslashes($person['FirstName']->get()." ".$person['LastName']->get())."') AND `Position`=".addslashes($person['Position']->get_id()); } if( @mysql_num_rows( doquery($query) )>0 ) { // Duplicate entry $error_duplicate = true; $error += true; }else { $error_duplicate = false; } }else { $error_duplicate = false; } if( $error!=false ) { // Error, show them and reshow form if( abs($error)==1 ) echoln("Your candidature has not been accepted. The following error was found:"); else echoln("Your candidature has not been accepted. The following ".abs($error)." errors were found:"); echoln("

"); $_SERVER['REQUEST_METHOD']="GET"; }else { ######################## ### Form OK, save it ### ######################## $data = array(); $candvalues = array(); $candvalues['old']['username'] = (isset($values['username']) ? $values['username'] : ""); $candvalues['old']['Approved'] = (isset($values['Approved']) ? $values['Approved'] : ""); for( $i=0; $iget_sql( ($candidate_id==0) )); $candvalues = array_merge_recursive($candvalues, $person[ $fields[$i] ]->get_value( ($candidate_id==0) )); } if( $candidate_id==0 ) { ################ ### Save new ### ################ $sqlfield = "`username`, "; if( isset($_SESSION['access_user']) && $_SESSION['access_user'] ) { $sqlvalue = "'".addslashes($_SESSION['sess_name'])."', "; }else { $sqlvalue = "'', "; } $sqlfield .= "`Created`, `Modified`, "; $sqlvalue .= "'".date("Y-m-d H:i:s")."', '".date("Y-m-d H:i:s")."', "; $sqlfield .= "`Position`, "; $sqlvalue .= addslashes($Position) . ", "; $k = array_keys($data); for( $i=0; $iPlease wait while we process your candidature... (wait until you see 'ready')

"); flush(); $postSaveResult = true; for( $i=0; $ipost_save($savedCandId); } if( !$postSaveResult ) { echoln("Some actions failed, please open your application and check if everything is correct.
"); } if( $candidate_id==0 ) $cand_mail = new CandidateMail($candvalues['old'], $candvalues['new'], true, getinsertid()); else $cand_mail = new CandidateMail($candvalues['old'], $candvalues['new'], false, $candidate_id); $cand_mail->Send(); echoln("
Your candidature has been saved successfully."); echoln("

... ready

"); echoln("Your candidature has been processed. If you want to edit your candidature, come back to this page and log in with your ".$ldap->getSystemName()." account."); if( is_anon() || (isset($_SESSION['access_user']) && $_SESSION['access_user']) ) echoln("

Back"); else echoln("

Close window"); }else { echoln("Failed saving your candidature."); $_SERVER['REQUEST_METHOD']="GET"; } #debug(nl2br(strtr(print_r($candvalues, true), array(" " => " ")))); #debug(nl2br(strtr(print_r($data, true), array(" " => " ")))); #debug($query); } } ################# ### Show form ### ################# if( $_SERVER['REQUEST_METHOD']=="GET" OR isset($_REQUEST['login']) ) { // Show the form echoln($ui->Open(true)); for( $i=0; $iSeparator()); }else { if( $person[ $sepfields[$i] ]->get_access( ($candidate_id==0) )!=Cand::ACCESS_NO ) { // Show field echoln($ui->Add( $person[ $sepfields[$i] ]->get_print_name(), $person[ $sepfields[$i] ]->get_print_value( $person[ $sepfields[$i] ]->get_access( ($candidate_id==0) )!=Cand::ACCESS_RW ), $person[ $sepfields[$i] ]->is_error(), $person[ $sepfields[$i] ]->get_compulsory() )); } } } echoln($ui->Close(true)); } } ?>