Skip to content
Snippets Groups Projects
Commit ce72220b authored by nicrausaz's avatar nicrausaz
Browse files

add applicant's responsibles working

parent 0ea31a59
No related branches found
No related tags found
No related merge requests found
......@@ -39,7 +39,6 @@
// $_SESSION['formError'] = false;
// unset($_SESSION);
// include("templates/confirmationText.php");
echo "done";
} else {
$_SESSION['formError'] = true;
$_SESSION['postedForm'] = $_POST;
......
......@@ -64,6 +64,51 @@ function uploadAllFiles($pathAnnexes, $postedFiles, $candidateData){
function insertDataIntoDB ($pdo, $candidateData) {
echo "<pre>";
print_r($candidateData);
$id = insertPersonalInfos($pdo, $candidateData);
insertResponsibles($pdo, $candidateData->representants, $id);
// create reponsable then
// responsables
// $pdo->bindParam(':fk_applicant_main_responsible', $candidateData->$job, PDO::PARAM_STR);
// $pdo->bindParam(':fk_applicant_sec_responsible', $candidateData->$job, PDO::PARAM_STR);
// files
}
function insertResponsibles ($pdo, $representants, $applicantId) {
$addedRepIds = [];
// insert responsibles
$sqlreq = "INSERT INTO responsible (responsible_gender, responsible_name, responsible_fsname, responsible_street, responsible_npa, responsible_phone)
VALUES (:responsible_gender, :responsible_name, :responsible_fsname, :responsible_street, :responsible_npa, :responsible_phone)";
foreach ($representants as $rep) {
if ($rep['nom'] != '') {
$query = $pdo->prepare($sqlreq);
$query->bindParam(':responsible_gender', $rep['genre'], PDO::PARAM_STR);
$query->bindParam(':responsible_name', $rep['nom'], PDO::PARAM_STR);
$query->bindParam(':responsible_fsname', $rep['prenom'], PDO::PARAM_STR);
$query->bindParam(':responsible_street', $rep['addresse']['rue'], PDO::PARAM_STR);
$query->bindParam(':responsible_npa', $rep['addresse']['NPA'], PDO::PARAM_STR);
$query->bindParam(':responsible_phone', $rep['telephone'], PDO::PARAM_STR);
$query->execute();
array_push($addedRepIds, $pdo->lastInsertId());
}
}
// link responsibles
$main_rep_id = $addedRepIds[0] ? $addedRepIds[0] : null;
$sec_rep_id = $addedRepIds[1] ? $addedRepIds[1] : null;
$sqlreq = "UPDATE applicant SET fk_applicant_main_responsible=:fk_applicant_main_responsible, fk_applicant_sec_responsible=:fk_applicant_sec_responsible WHERE applicant_id=:applicant_id";
$query = $pdo->prepare($sqlreq);
$query->bindParam(':fk_applicant_main_responsible', $main_rep_id, PDO::PARAM_INT);
$query->bindParam(':fk_applicant_sec_responsible', $sec_rep_id, PDO::PARAM_INT);
$query->bindParam(':applicant_id', $applicantId, PDO::PARAM_INT);
$query->execute();
}
function insertPersonalInfos ($pdo, $candidateData) {
$sqlreq = "INSERT INTO applicant
(applicant_formation, applicant_it_section, applicant_formation_location, applicant_maturity, applicant_gender, applicant_name, applicant_fsname, applicant_address_street, applicant_address_npa, applicant_home_phone, applicant_personal_phone, applicant_mail, applicant_birthdate, applicant_origin, applicant_nationality, applicant_foreign_authorization, applicant_avs, applicant_main_language, applicant_speaks_french, applicant_speaks_german, applicant_speaks_english, applicant_speaks_other, applicant_has_majority, applicant_scolarity_end, applicant_already_applicant, applicant_already_applicant_year, applicant_application_date, applicant_application_status, fk_applicant_main_responsible, fk_applicant_sec_responsible)
VALUES (:applicant_formation, :applicant_it_section, :applicant_formation_location, :applicant_maturity, :applicant_gender, :applicant_name, :applicant_fsname, :applicant_address_street, :applicant_address_npa, :applicant_home_phone, :applicant_personal_phone, :applicant_mail, :applicant_birthdate, :applicant_origin, :applicant_nationality, :applicant_foreign_authorization, :applicant_avs, :applicant_main_language, :applicant_speaks_french, :applicant_speaks_german, :applicant_speaks_english, :applicant_speaks_other, :applicant_has_majority, :applicant_scolarity_end, :applicant_already_applicant, :applicant_already_applicant_year, NOW(), 'new', null, null)";
......@@ -99,18 +144,7 @@ function insertDataIntoDB ($pdo, $candidateData) {
$query->bindParam(':applicant_already_applicant', $candidateData->dejaCandidat, PDO::PARAM_BOOL);
$query->bindParam(':applicant_already_applicant_year', $candidateData->anneeCandidature, PDO::PARAM_STR);
try {
$query->execute();
} catch(Exception $e) {
echo $e;
}
// create reponsable then
// responsables
// $pdo->bindParam(':fk_applicant_main_responsible', $candidateData->$job, PDO::PARAM_STR);
// $pdo->bindParam(':fk_applicant_sec_responsible', $candidateData->$job, PDO::PARAM_STR);
// files
$query->execute();
return $pdo->lastInsertId();
}
?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment