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

update file

parent 23d6c383
No related branches found
No related tags found
No related merge requests found
...@@ -31,8 +31,6 @@ ...@@ -31,8 +31,6 @@
// TODO: check if i can pass only candidateData // TODO: check if i can pass only candidateData
$candidateData = uploadAllFiles($filesPath, $candidateData->fichiers, $candidateData); $candidateData = uploadAllFiles($filesPath, $candidateData->fichiers, $candidateData);
// print_r($candidateData->fichiers);
// insert files in DB // insert files in DB
insertFiles($pdo, $candidateData->fichiers, $candidateId, $candidateData->rootpath); insertFiles($pdo, $candidateData->fichiers, $candidateId, $candidateData->rootpath);
......
...@@ -475,14 +475,29 @@ function updatePostulation ($pdo, $posted_data) { ...@@ -475,14 +475,29 @@ function updatePostulation ($pdo, $posted_data) {
} }
insertTrainings($pdo, $to_add, $posted_data->id); insertTrainings($pdo, $to_add, $posted_data->id);
// Update files // Update files
foreach ($posted_files as $key => $file) { $sqlreq = "UPDATE file SET file_path=:file_path
$file_data = getOneFile($pdo, $file['id'], $posted_data->id); WHERE fk_applicant_id=:applicant_id AND file_id=:file_id";
if (!move_uploaded_file($file['tmp_name'], $file_data['file_path'])) {
// Erreur: Le fichier est ouvert foreach ($posted_files as $key => $file) {
$_SESSION['edit_error']['files'] = "Erreur lors du remplacement du fichier" . $_FILES['file'.$i]['name'] . ", réessayez plus tard."; $file_data = getOneFile($pdo, $file['id'], $posted_data->id);
$extension = strtolower("." . pathinfo($file['name'])['extension']);
$path = preg_replace('/\\.[^.\\s]{3,4}$/', '', $file_data['file_path']) . $extension;
if (!move_uploaded_file($file['tmp_name'], $path)) {
// Erreur: Le fichier est ouvert
echo "err";
$_SESSION['edit_error']['files'] = "Erreur lors du remplacement d'un fichier, réessayez plus tard.";
} else {
// success, update db
$query = $pdo->prepare($sqlreq);
$query->bindParam(':applicant_id', $posted_data->id, PDO::PARAM_INT);
$query->bindParam(':file_path', $path, PDO::PARAM_STR);
$query->bindParam(':file_id', $file_data['file_id'], PDO::PARAM_STR);
$query->execute();
// TODO: old delete file ?
}
} }
}
// header('Location: viewpostulation.php'); // header('Location: viewpostulation.php');
} }
#endregion #endregion
......
...@@ -4,9 +4,7 @@ ...@@ -4,9 +4,7 @@
<small>Remplacez ou ajouter des annexes (le fichier actuel est conservé si il n'est pas remplacé)</small> <small>Remplacez ou ajouter des annexes (le fichier actuel est conservé si il n'est pas remplacé)</small>
<br> <br>
<small>Formats autorisés: <b>PDF, JPG, JPEG, PNG</b></small> <small>Formats autorisés: <b>PDF, JPG, JPEG, PNG</b></small>
<!-- Annexes obligatoires -->
<div class="form-group mt-3" id="files"> <div class="form-group mt-3" id="files">
<?php foreach ($files as $key => $file) { <?php foreach ($files as $key => $file) {
$name = preg_replace('/\\.[^.\\s]{3,4}$/', '', $file['file_name']); $name = preg_replace('/\\.[^.\\s]{3,4}$/', '', $file['file_name']);
?> ?>
...@@ -22,47 +20,5 @@ ...@@ -22,47 +20,5 @@
<small class="error" class="form-text text-muted"></small> <small class="error" class="form-text text-muted"></small>
</div> </div>
<?php } ?> <?php } ?>
<!-- / Annexes obligatoires -->
<!-- Annexes spécifiques -->
<!-- <div class="form-group" id="polyOnly">
<label for="gimch">Attestation de tests d'aptitudes GIM-CH (polymécanicien):</label>
<input type="file" name="gimch" class="upload-input" id="gimch" onchange="changeTitleFile(this)"/>
<br>
<label for="gimch" class="btn btn-secondary btn-sm icon-right">
Remplacer...
</label>
<br>
<small class="error" class="form-text text-muted"></small>
</div> -->
<!-- <div class="form-group" id="griTest">
<label for="griTestInput">Attestation de tests d'aptitudes GRI (informaticien):</label>
<input type="file" name="griTestInput" class="upload-input" id="griTestInput" onchange="changeTitleFile(this)"/>
<br>
<label for="griTestInput" class="btn btn-secondary btn-sm icon-right">
Remplacer...
</label>
<br>
<small class="error" class="form-text text-muted"></small>
</div> -->
<!-- / Annexes spécifiques -->
<!-- Annexes supplémentaires -->
<!-- <div class="form-group">
<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)"/>
<br>
<label for="certifs1" class="btn btn-secondary btn-sm icon-right">
Remplacer...
</label>
<br>
<small class="error" class="form-text text-muted"></small>
</td>
</tr>
</table>
</div> -->
<button type="button" class="btn btn-primary btn-sm mt-3 mb-2" id="addInputFile">Ajouter une annexe</button> <button type="button" class="btn btn-primary btn-sm mt-3 mb-2" id="addInputFile">Ajouter une annexe</button>
<!-- region/ Annexes supplémentaires -->
</div> </div>
\ 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