From c2daaeb2d205ed9b197b0924c5485320bd7e5dfc Mon Sep 17 00:00:00 2001 From: nicrausaz <n.crausaz99@gmail.com> Date: Tue, 26 Feb 2019 13:52:18 +0100 Subject: [PATCH] fix birthdate --- canapEPFL/helpers.php | 23 +++++++++++-------- canapEPFL/models/PersonnalData.php | 2 +- canapEPFL/models/PersonnalDataValidator.php | 2 +- canapEPFL/script.js | 3 +++ .../personnalInfosTable.php | 5 +++- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/canapEPFL/helpers.php b/canapEPFL/helpers.php index 22a8609..7bdc9d7 100644 --- a/canapEPFL/helpers.php +++ b/canapEPFL/helpers.php @@ -286,6 +286,7 @@ function deletePostulation ($pdo, $id, $sciper, $rep1, $rep2) { $query->execute(); // delete files from server + // TODO: check this $filesToRemove = getFilesById($pdo, $id); foreach ($filesToRemove as $key => $file) { unlink($file['file_path']); @@ -317,8 +318,6 @@ function updatePostulation ($pdo, $id, $posted_data) { echo "<pre>"; print_r($posted_data); - // update applicant data - // -- applicant_birthdate= :applicant_birthdate, $sqlreq = "UPDATE applicant SET applicant_maturity= :applicant_maturity, @@ -327,6 +326,7 @@ function updatePostulation ($pdo, $id, $posted_data) { applicant_address_npa= :applicant_address_npa, applicant_home_phone= :applicant_home_phone, applicant_personal_phone= :applicant_personal_phone, + applicant_birthdate= :applicant_birthdate, applicant_origin= :applicant_origin, applicant_nationality= :applicant_nationality, applicant_foreign_authorization= :applicant_foreign_authorization, @@ -343,28 +343,31 @@ function updatePostulation ($pdo, $id, $posted_data) { applicant_application_updated_date= :applicant_application_updated_date WHERE applicant_id=:id"; + $datetime_now = date("Y-m-d H:i:s"); + $query = $pdo->prepare($sqlreq); $query->bindParam(':id', $id, PDO::PARAM_STR); - $query->bindParam(':applicant_maturity', $posted_data['applicant_maturity'], PDO::PARAM_STR); + $query->bindParam(':applicant_maturity', $posted_data['applicant_maturity'], PDO::PARAM_BOOL); $query->bindParam(':applicant_gender', $posted_data['applicant_gender'], PDO::PARAM_STR); $query->bindParam(':applicant_address_street', $posted_data['applicant_address_street'], PDO::PARAM_STR); $query->bindParam(':applicant_address_npa', $posted_data['applicant_address_npa'], PDO::PARAM_STR); $query->bindParam(':applicant_home_phone', $posted_data['applicant_home_phone'], PDO::PARAM_STR); $query->bindParam(':applicant_personal_phone', $posted_data['applicant_personal_phone'], PDO::PARAM_STR); + $query->bindParam(':applicant_birthdate', $posted_data['applicant_birthdate'], PDO::PARAM_STR); $query->bindParam(':applicant_origin', $posted_data['applicant_origin'], PDO::PARAM_STR); $query->bindParam(':applicant_nationality', $posted_data['applicant_nationality'], PDO::PARAM_STR); $query->bindParam(':applicant_foreign_authorization', $posted_data['applicant_foreign_authorization'], PDO::PARAM_STR); $query->bindParam(':applicant_avs', $posted_data['applicant_avs'], PDO::PARAM_STR); $query->bindParam(':applicant_main_language', $posted_data['applicant_main_language'], PDO::PARAM_STR); - $query->bindParam(':applicant_speaks_french', $posted_data['applicant_speaks_french'], PDO::PARAM_STR); - $query->bindParam(':applicant_speaks_german', $posted_data['applicant_speaks_german'], PDO::PARAM_STR); - $query->bindParam(':applicant_speaks_english', $posted_data['applicant_speaks_english'], PDO::PARAM_STR); - $query->bindParam(':applicant_speaks_other', $posted_data['applicant_speaks_other'], PDO::PARAM_STR); - $query->bindParam(':applicant_has_majority', $posted_data['applicant_has_majority'], PDO::PARAM_STR); - $query->bindParam(':applicant_already_applicant', $posted_data['applicant_already_applicant'], PDO::PARAM_STR); + $query->bindParam(':applicant_speaks_french', $posted_data['applicant_speaks_french'], PDO::PARAM_BOOL); + $query->bindParam(':applicant_speaks_german', $posted_data['applicant_speaks_german'], PDO::PARAM_BOOL); + $query->bindParam(':applicant_speaks_english', $posted_data['applicant_speaks_english'], PDO::PARAM_BOOL); + $query->bindParam(':applicant_speaks_other', $posted_data['applicant_speaks_other'], PDO::PARAM_BOOL); + $query->bindParam(':applicant_has_majority', $posted_data['applicant_has_majority'], PDO::PARAM_BOOL); + $query->bindParam(':applicant_already_applicant', $posted_data['applicant_already_applicant'], PDO::PARAM_BOOL); $query->bindParam(':applicant_already_applicant_year', $posted_data['applicant_already_applicant_year'], PDO::PARAM_STR); $query->bindParam(':applicant_scolarity_end', $posted_data['applicant_scolarity_end'], PDO::PARAM_STR); - $query->bindParam(':applicant_application_updated_date', date("Y-m-d H:i:s"), PDO::PARAM_STR); + $query->bindParam(':applicant_application_updated_date', $datetime_now, PDO::PARAM_STR); $query->execute(); diff --git a/canapEPFL/models/PersonnalData.php b/canapEPFL/models/PersonnalData.php index 684d754..cbad02d 100644 --- a/canapEPFL/models/PersonnalData.php +++ b/canapEPFL/models/PersonnalData.php @@ -56,7 +56,7 @@ class PersonnalData { $this->telFixeApprenti = $postedData['telApp']; $this->telMobileApprenti = $postedData['phoneApp']; $this->mailApprenti = $postedData['mailApp']; - $this->dateNaissanceApprenti = date('Y-m-d', strtotime($postedData['birthApp'])); + $this->dateNaissanceApprenti = $postedData['birthApp']; $this->origineApprenti = $postedData['originApp']; $this->nationaliteApprenti = $postedData['nationApp']; $this->permisEtranger = $postedData['permisEtrangerApp']; diff --git a/canapEPFL/models/PersonnalDataValidator.php b/canapEPFL/models/PersonnalDataValidator.php index 3248efe..7399717 100644 --- a/canapEPFL/models/PersonnalDataValidator.php +++ b/canapEPFL/models/PersonnalDataValidator.php @@ -67,7 +67,7 @@ class PersonnalDataValidator { } private function isBirthDateValid ($birthDate) { - $birthYear = date('Y', strtotime($birthDate)); + $birthYear = explode('/', $birthDate)[2]; $actualYear = date('Y'); if (($birthYear > $actualYear - 60) && ($birthYear <= $actualYear - 13)) { diff --git a/canapEPFL/script.js b/canapEPFL/script.js index f8560e2..8ccfcba 100644 --- a/canapEPFL/script.js +++ b/canapEPFL/script.js @@ -262,6 +262,9 @@ function initEdits() { } }); + $.datepicker.setDefaults($.datepicker.regional["fr"]); + $("#applicant_birthdate").datepicker({ minDate: '-60y', maxDate: '-13y', dateFormat: "dd/mm/yy" }); + $('#editPost').click(function () { $('#editPost').prop('disabled', true); $('#confirmEditPost').show(); diff --git a/canapEPFL/templates/viewPostulationTables/personnalInfosTable.php b/canapEPFL/templates/viewPostulationTables/personnalInfosTable.php index 6c08dd6..1f88697 100644 --- a/canapEPFL/templates/viewPostulationTables/personnalInfosTable.php +++ b/canapEPFL/templates/viewPostulationTables/personnalInfosTable.php @@ -65,7 +65,10 @@ </tr> <tr> <td>Date de naissance</td> - <td><?= date('d/m/Y', strtotime($postulation['applicant_birthdate'])) ?></td> + <td> + <span class="postulationDataSpans"><?= $postulation['applicant_birthdate'] ?></span> + <input type="text" autocomplete="none" placeholder="jj/mm/aaaa" name="applicant_birthdate" id="applicant_birthdate" class="form-control editPostInputs" value="<?= $postulation['applicant_birthdate'] ?>" /> + </td> </tr> <tr> <td>Origine</td> -- GitLab