From 23d6c38317700ea2ae3aa4340a595e83d4dc56a5 Mon Sep 17 00:00:00 2001 From: nicrausaz <n.crausaz99@gmail.com> Date: Tue, 5 Mar 2019 14:42:33 +0100 Subject: [PATCH] fix files ok --- canapEPFL/cible.php | 3 ++ canapEPFL/form.php | 4 +- canapEPFL/helpers.php | 51 ++++++++++--------- canapEPFL/models/PersonnalData.php | 1 - canapEPFL/models/PersonnalDataValidator.php | 2 +- canapEPFL/script.js | 6 +-- .../templates/formParts/edit/annexes.php | 4 +- .../formParts/edit/filieresinfos.php | 1 + canapEPFL/templates/formParts/new/annexes.php | 30 +++++------ 9 files changed, 54 insertions(+), 48 deletions(-) diff --git a/canapEPFL/cible.php b/canapEPFL/cible.php index ea370a4..693fb8d 100644 --- a/canapEPFL/cible.php +++ b/canapEPFL/cible.php @@ -28,8 +28,11 @@ // create dir + move files in it $filesPath = createFilesFolder($candidateData->rootpath, $candidateId); + // TODO: check if i can pass only candidateData $candidateData = uploadAllFiles($filesPath, $candidateData->fichiers, $candidateData); + // print_r($candidateData->fichiers); + // insert files in DB insertFiles($pdo, $candidateData->fichiers, $candidateId, $candidateData->rootpath); diff --git a/canapEPFL/form.php b/canapEPFL/form.php index 71facd4..5b8faf8 100644 --- a/canapEPFL/form.php +++ b/canapEPFL/form.php @@ -108,7 +108,9 @@ </div> <!-- / Conditions --> <button class="btn btn-primary btn-block" type="submit">Terminer</button> - <button class="btn btn-secondary btn-block" id="cancelEditBtn" type="button">Annuler</button> + <?php if (isset($_GET['edit'])) { ?> + <button class="btn btn-secondary btn-block" id="cancelEditBtn" type="button">Annuler</button> + <?php } ?> </div> <!-- / div all --> </form> diff --git a/canapEPFL/helpers.php b/canapEPFL/helpers.php index 57e6caa..65e884e 100644 --- a/canapEPFL/helpers.php +++ b/canapEPFL/helpers.php @@ -25,20 +25,20 @@ function uploadFile(&$candidateData, $pathAnnexes, $file, $key, $name){ $extension = strtolower(strrchr($file['name'], '.')); $file['name'] = $name . $extension; move_uploaded_file($file['tmp_name'], $pathAnnexes . $file['name']); - $candidateData->fichiers[$name] = $file['name']; - unset($candidateData->fichiers[$key]); + $candidateData->fichiers[$name]['name'] = $file['name']; + // unset($candidateData->fichiers[$key]); } -function uploadAllFiles($pathAnnexes, $postedFiles, $candidateData){ - uploadFile($candidateData, $pathAnnexes, $postedFiles['photo'], 'photo', "photo-passeport"); - uploadFile($candidateData, $pathAnnexes, $postedFiles['idCard'], 'idCard', "carte-identite"); - uploadFile($candidateData, $pathAnnexes, $postedFiles['cv'], 'cv', "curriculum-vitae"); - uploadFile($candidateData, $pathAnnexes, $postedFiles['lettre'], 'lettre', "lettre-motivation"); +function uploadAllFiles($pathAnnexes, $postedFiles, $candidateData) { + uploadFile($candidateData, $pathAnnexes, $postedFiles['photo-passeport'], 'photo-passeport', "photo-passeport"); + uploadFile($candidateData, $pathAnnexes, $postedFiles['carte-identite'], 'carte-identite', "carte-identite"); + uploadFile($candidateData, $pathAnnexes, $postedFiles['curriculum-vitae'], 'curriculum-vitae', "curriculum-vitae"); + uploadFile($candidateData, $pathAnnexes, $postedFiles['lettre-motivation'], 'lettre-motivation', "lettre-motivation"); for ($i = 1; $i <= 9; $i++){ - if (array_key_exists('certifs'.$i, $postedFiles)){ - if (!($postedFiles['certifs'.$i]['name'] == "")) { - uploadFile($candidateData, $pathAnnexes, $postedFiles['certifs'.$i], 'certifs'.$i, "annexe".$i); + if (array_key_exists('annexe'.$i, $postedFiles)){ + if (!($postedFiles['annexe'.$i]['name'] == "")) { + uploadFile($candidateData, $pathAnnexes, $postedFiles['annexe'.$i], 'annexe'.$i, "annexe".$i); } } } @@ -194,9 +194,9 @@ function insertFiles ($pdo, $files, $applicantId, $filesPath) { $sqlreq = "INSERT INTO file (file_name, file_path, fk_applicant_id) VALUES (:file_name, :file_path, :fk_applicant_id)"; foreach ($files as $file) { - $filePath = $userPath . $file; + $filePath = $userPath . $file['name']; $query = $pdo->prepare($sqlreq); - $query->bindParam(':file_name', $file, PDO::PARAM_STR); + $query->bindParam(':file_name', $file['name'], PDO::PARAM_STR); $query->bindParam(':file_path', $filePath, PDO::PARAM_STR); $query->bindParam(':fk_applicant_id', $applicantId, PDO::PARAM_INT); $query->execute(); @@ -353,7 +353,7 @@ function updatePostulation ($pdo, $posted_data) { $query = $pdo->prepare($sqlreq); $query->bindParam(':id', $posted_data->id, PDO::PARAM_STR); $query->bindParam(':applicant_maturity', $posted_data->maturite, PDO::PARAM_BOOL); - $query->bindParam(':applicant_it_section', $posted_data->filiere, PDO::PARAM_BOOL); + $query->bindParam(':applicant_it_section', $posted_data->filiere, PDO::PARAM_STR); $query->bindParam(':applicant_gender', $posted_data->genreApprenti, PDO::PARAM_STR); $query->bindParam(':applicant_address_street', $posted_data->addresseApprentiComplete['rue'], PDO::PARAM_STR); $query->bindParam(':applicant_address_npa', $posted_data->addresseApprentiComplete['NPA'], PDO::PARAM_STR); @@ -412,6 +412,7 @@ function updatePostulation ($pdo, $posted_data) { $query->bindParam(':responsible_phone', $sec_rep['telephone'], PDO::PARAM_STR); $query->execute(); } + // TODO: si nouveau, insert // update scolarities $to_add = []; @@ -460,19 +461,19 @@ function updatePostulation ($pdo, $posted_data) { $sqlreq = "UPDATE training SET training_job=:training_job, training_company=:training_company WHERE fk_applicant_id=:applicant_id AND training_id=:training_id"; -foreach ($posted_data->stages as $training) { - if (isset($training['id'])) { - $query = $pdo->prepare($sqlreq); - $query->bindParam(':applicant_id', $posted_data->id, PDO::PARAM_INT); - $query->bindParam(':training_id', $training['id'], PDO::PARAM_INT); - $query->bindParam(':training_company', $training['metier'], PDO::PARAM_STR); - $query->bindParam(':training_job', $training['employeur'], PDO::PARAM_STR); - $query->execute(); - } else { - array_push($to_add, $training); + foreach ($posted_data->stages as $training) { + if (isset($training['id'])) { + $query = $pdo->prepare($sqlreq); + $query->bindParam(':applicant_id', $posted_data->id, PDO::PARAM_INT); + $query->bindParam(':training_id', $training['id'], PDO::PARAM_INT); + $query->bindParam(':training_company', $training['metier'], PDO::PARAM_STR); + $query->bindParam(':training_job', $training['employeur'], PDO::PARAM_STR); + $query->execute(); + } else { + array_push($to_add, $training); + } } -} -insertTrainings($pdo, $to_add, $posted_data->id); + insertTrainings($pdo, $to_add, $posted_data->id); // Update files foreach ($posted_files as $key => $file) { diff --git a/canapEPFL/models/PersonnalData.php b/canapEPFL/models/PersonnalData.php index 08e2faa..53e95a7 100644 --- a/canapEPFL/models/PersonnalData.php +++ b/canapEPFL/models/PersonnalData.php @@ -135,7 +135,6 @@ class PersonnalData { } } private function setFiles ($postedFiles, $ids) { - // Clear empty files foreach ($postedFiles as $key => $file) { if ($file['error'] != 0) { unset($postedFiles[$key]); diff --git a/canapEPFL/models/PersonnalDataValidator.php b/canapEPFL/models/PersonnalDataValidator.php index 7399717..c1b3533 100644 --- a/canapEPFL/models/PersonnalDataValidator.php +++ b/canapEPFL/models/PersonnalDataValidator.php @@ -126,7 +126,7 @@ class PersonnalDataValidator { private function filesValid () { $filesToCheck = $this->personnalData->fichiers; $validExt = ['.pdf', '.jpeg', '.png', '.jpg']; - $requiredKeys = ['photo', 'idCard', 'cv', 'lettre', 'certifs1']; + $requiredKeys = ['photo-passeport', 'carte-identite', 'curriculum-vitae', 'lettre-motivation']; foreach($filesToCheck as $key => $file) { // Pour les fichiers obligatoire diff --git a/canapEPFL/script.js b/canapEPFL/script.js index dca62d0..2e70c44 100644 --- a/canapEPFL/script.js +++ b/canapEPFL/script.js @@ -152,9 +152,9 @@ function initAddChildButtons() { $('#addInputFile').click(function () { var nextIndex = $('#newCertifZone > tbody').children().length + 1; if (nextIndex < 10) { - $('#newCertifZone').append('<tr><td><label for="certifs' + nextIndex + '">Annexe supplémentaire</label><br>' - + '<input type="file" name="certifs' + nextIndex + '" class="upload-input" id="certifs' + nextIndex + '" onchange="changeTitleFile(this)"/>' - + '<label for="certifs' + nextIndex + '" class="btn btn-secondary btn-sm icon-right">Choisir...</label><br>' + $('#newCertifZone').append('<tr><td><label for="annexe' + nextIndex + '">Annexe supplémentaire</label><br>' + + '<input type="file" name="annexe' + nextIndex + '" class="upload-input" id="annexe' + nextIndex + '" onchange="changeTitleFile(this)"/>' + + '<label for="annexe' + nextIndex + '" class="btn btn-secondary btn-sm icon-right">Choisir...</label><br>' + '<small class="error" class="form-text text-muted"></small></td></tr>'); if (nextIndex == 9) { $('#addInputFile').hide(750); diff --git a/canapEPFL/templates/formParts/edit/annexes.php b/canapEPFL/templates/formParts/edit/annexes.php index 1b1f92c..135f01d 100644 --- a/canapEPFL/templates/formParts/edit/annexes.php +++ b/canapEPFL/templates/formParts/edit/annexes.php @@ -62,7 +62,7 @@ </td> </tr> </table> - </div> - <button type="button" class="btn btn-primary btn-sm mt-3 mb-2" id="addInputFile">Ajouter une annexe</button> --> + </div> --> + <button type="button" class="btn btn-primary btn-sm mt-3 mb-2" id="addInputFile">Ajouter une annexe</button> <!-- region/ Annexes supplémentaires --> </div> \ No newline at end of file diff --git a/canapEPFL/templates/formParts/edit/filieresinfos.php b/canapEPFL/templates/formParts/edit/filieresinfos.php index 4d3781a..a788c4a 100644 --- a/canapEPFL/templates/formParts/edit/filieresinfos.php +++ b/canapEPFL/templates/formParts/edit/filieresinfos.php @@ -1,4 +1,5 @@ <div class="form-group"> +<?= $current_post['applicant_it_section'] ?> <label>Filières informatiques:*</label> <div class="custom-control custom-radio"> <input type="radio" name="filInfo" id="fill1" class="custom-control-input" value="developpementApplications" <?php echo ($current_post['applicant_it_section'] == "developpementApplications") ? "checked=\"checked\"" : ''; ?>> diff --git a/canapEPFL/templates/formParts/new/annexes.php b/canapEPFL/templates/formParts/new/annexes.php index f6ad19c..9ec82bd 100644 --- a/canapEPFL/templates/formParts/new/annexes.php +++ b/canapEPFL/templates/formParts/new/annexes.php @@ -4,10 +4,10 @@ <!-- Annexes obligatoires --> <div class="form-group mt-3" id="files"> <div class="form-group"> - <label for="photo">Photo passeport <strong>couleur: *</strong></label> - <input type="file" name="photo" class="upload-input" id="photo" onchange="changeTitleFile(this)" data-required/> + <label for="photo-passeport">Photo passeport <strong>couleur: *</strong></label> + <input type="file" name="photo-passeport" class="upload-input" id="photo-passeport" onchange="changeTitleFile(this)" data-required/> <br> - <label for="photo" class="btn btn-secondary btn-sm icon-right"> + <label for="photo-passeport" class="btn btn-secondary btn-sm icon-right"> Choisir... </label> <br> @@ -15,10 +15,10 @@ </div> <div class="form-group"> - <label for="idCard">Copie carte d'indentité / passeport: *</label> - <input type="file" name="idCard" class="upload-input" id="idCard" onchange="changeTitleFile(this)" data-required/> + <label for="carte-identite">Copie carte d'indentité / passeport: *</label> + <input type="file" name="carte-identite" class="upload-input" id="carte-identite" onchange="changeTitleFile(this)" data-required/> <br> - <label for="idCard" class="btn btn-secondary btn-sm icon-right"> + <label for="carte-identite" class="btn btn-secondary btn-sm icon-right"> Choisir... </label> <br> @@ -26,10 +26,10 @@ </div> <div class="form-group"> - <label for="cv">Curriculum Vitae: *</label> - <input type="file" name="cv" class="upload-input" id="cv" onchange="changeTitleFile(this)" data-required/> + <label for="curriculum-vitae">Curriculum Vitae: *</label> + <input type="file" name="curriculum-vitae" class="upload-input" id="curriculum-vitae" onchange="changeTitleFile(this)" data-required/> <br> - <label for="cv" class="btn btn-secondary btn-sm icon-right"> + <label for="curriculum-vitae" class="btn btn-secondary btn-sm icon-right"> Choisir... </label> <br> @@ -37,10 +37,10 @@ </div> <div class="form-group"> - <label for="lettre">Lettre de motivation: *</label> - <input type="file" name="lettre" class="upload-input" id="lettre" onchange="changeTitleFile(this)" data-required/> + <label for="lettre-motivation">Lettre de motivation: *</label> + <input type="file" name="lettre-motivation" class="upload-input" id="lettre-motivation" onchange="changeTitleFile(this)" data-required/> <br> - <label for="lettre" class="btn btn-secondary btn-sm icon-right"> + <label for="lettre-motivation" class="btn btn-secondary btn-sm icon-right"> Choisir... </label> <br> @@ -75,10 +75,10 @@ <table id="newCertifZone"> <tr> <td> - <label for="certifs1">Certificats, diplômes et bulletins de notes des derniers 3-4 semestres:</label> - <input type="file" name="certifs1" class="upload-input" id="certifs1" onchange="changeTitleFile(this)"/> + <label for="annexe1">Certificats, diplômes et bulletins de notes des derniers 3-4 semestres:</label> + <input type="file" name="annexe1" class="upload-input" id="annexe1" onchange="changeTitleFile(this)"/> <br> - <label for="certifs1" class="btn btn-secondary btn-sm icon-right"> + <label for="annexe1" class="btn btn-secondary btn-sm icon-right"> Choisir... </label> <br> -- GitLab