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

fix files errors

parent c5e32b7b
No related branches found
No related tags found
No related merge requests found
......@@ -18,18 +18,21 @@
// Init dataValidator
$validator = new PersonnalDataValidator($candidateData);
if($validator->isValid()){
if($validator->isValid()) {
$candidateData->fichiers = $candidateData->tmp_fichiers;
// Create folders
createCandidateFolders($candidateData);
// Upload files
$candidateData = uploadAllFiles($candidateData->getPaths()["pathAnnexes"], $candidateData->tmp_fichiers, $candidateData);
$candidateData = uploadAllFiles($candidateData->getPaths()["pathAnnexes"], $candidateData->fichiers, $candidateData);
// Create JSON file and upload it
$encodedJson = (json_encode($candidateData,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT));
file_put_contents($candidateData->getPaths()["pathInfos"].'/informations.json', $encodedJson);
// Send mails
// Send mails
mailToResp($candidateData->prenomApprenti, $candidateData->nomApprenti, $candidateData->formation);
mailToApprenti($candidateData->mailApprenti, $candidateData->formation);
// kill session
$_SESSION['formError'] = false;
unset($_SESSION);
......
......@@ -22,7 +22,7 @@ function uploadFile(&$candidateData, $pathAnnexes, $file, $name){
$extension = strtolower(strrchr($file['name'], '.'));
$file['name'] = $name . $extension;
move_uploaded_file($file['tmp_name'], $pathAnnexes . $file['name']);
$candidateData->fichiers[$name] = $file['name'];
$candidateData->fichiersAnnexes[$name] = $file['name'];
}
//Crée le dossier principal est ses 2 sous-dossiers
......@@ -58,6 +58,7 @@ function uploadAllFiles($pathAnnexes, $postedFiles, $candidateData){
}
unset($candidateData->tmp_fichiers);
unset($candidateData->fichiers);
return $candidateData;
}
?>
\ No newline at end of file
......@@ -48,7 +48,7 @@ class PersonnalData {
public $fichiers = [];
public $tmp_fichiers = [];
public function __construct($postedData, $postedFiles) {
public function __construct ($postedData, $postedFiles) {
$this->dateNow = date('Y-m-d_H-i-s');
// Rempli les infos
$this->postedData = $postedData;
......@@ -85,7 +85,7 @@ class PersonnalData {
$this->tmp_fichiers = $this->setFiles($postedFiles);
}
private function setRepresentants(){
private function setRepresentants () {
$rep1 = array("genre"=>$this->postedData['genreRep1'],"nom"=>$this->postedData['nameRep1'],"prenom"=>$this->postedData['surnameRep1'],"addresse"=> array("rue"=>$this->postedData['adrRep1'],"NPA"=>$this->postedData['NPARep1']),"telephone"=>$this->postedData['telRep1']);
$rep2 = array("genre"=>$this->postedData['genreRep2'],"nom"=>$this->postedData['nameRep2'],"prenom"=>$this->postedData['surnameRep2'],"addresse"=> array("rue"=>$this->postedData['adrRep2'],"NPA"=>$this->postedData['NPARep2']),"telephone"=>$this->postedData['telRep2']);
......@@ -96,34 +96,34 @@ class PersonnalData {
array_push($this->representants, $rep2);
}
}
private function setScolarite(){
private function setScolarite () {
for ($i = 1; $i <= 5; $i++) {
if(array_key_exists('ecole'.$i, $this->postedData)){
array_push($this->scolarite, array("ecole"=>$this->postedData['ecole'.$i],"lieu"=>$this->postedData['lieuEcole'.$i],"niveau"=>$this->postedData['niveauEcole'.$i],"annees"=>$this->postedData['anneesEcole'.$i]));
}
}
}
private function setActivitesPro(){
private function setActivitesPro () {
for ($i = 1; $i <= 3; $i++) {
if(array_key_exists('employeurPro'.$i, $this->postedData)){
array_push($this->activitesProfessionnelles,array("employeur"=>$this->postedData['employeurPro'.$i],"lieu"=>$this->postedData['lieuPro'.$i],"activite"=>$this->postedData['activitePro'.$i],"annees"=>$this->postedData['anneesPro'.$i]));
}
}
}
private function setStages(){
private function setStages () {
for ($i = 1; $i <= 4; $i++) {
if(array_key_exists('activiteStage'.$i, $this->postedData)){
array_push($this->stages,array("metier"=>$this->postedData['activiteStage'.$i],"employeur"=>$this->postedData['entrepriseStage'.$i]));
}
}
}
private function setDejacand(){
private function setDejacand () {
$this->dejaCandidat = $this->postedData['dejaCand'];
if($this->postedData['dejaCand'] == "true"){
$this->anneeCandidature = $this->postedData['dejaCandAnnee'];
}
}
public function setLanguages($languages){
public function setLanguages ($languages) {
if(isset($languages) && is_array($languages)){
$this->connaissancesLinguistiques = $languages;
} else {
......@@ -141,14 +141,14 @@ class PersonnalData {
return $postedFiles;
}
public function getPaths(){
public function getPaths () {
$folderName = $this->dateNow."_".$this->mailApprenti;
$path = $this->rootpath.$this->formations[$this->formation].'/'.$folderName.'/';
$pathInfos = $path."informations/";
$pathAnnexes = $path."annexes/";
return ["pathInfos"=>$pathInfos, "pathAnnexes"=>$pathAnnexes, "path"=> $path];
}
public function getFormations(){
public function getFormations () {
return $this->formations;
}
}
......
......@@ -10,7 +10,7 @@ class PersonnalDataValidator {
$this->personnalData = $personnalData;
}
public function errors(){
public function errors () {
return $this->errors;
}
......@@ -128,24 +128,24 @@ class PersonnalDataValidator {
}
}
private function filesValid () {
$filesToCheck = $this->personnalData->fichiers;
$filesToCheck = $this->personnalData->tmp_fichiers;
$validExt = ['.pdf', '.jpeg', '.png', '.jpg'];
$requiredKeys = ['photo', 'idCard', 'cv', 'lettre', 'certifs1'];
foreach($filesToCheck as $key => $file) {
// Pour les fichiers obligatoire
if (in_array($file['name'], $requiredKeys)) {
// si fichier non fourni
if (!$file['error'] == 0) {
$this->errors['fichiers'] = 'Fichier(s) non fourni(s)';
}
}
// Check les formats
if ($file['name'] != "") {
$extension = strtolower(strrchr($file['name'], '.'));
if(!in_array($extension, $validExt)){
$this->errors['fichiers'] = 'Format de fichier(s) non valable(s)';
} else {
// Pour les fichiers obligatoire
if (in_array($file['name'], $requiredKeys)) {
// si fichier non fourni
if (!$file['error'] == 0) {
$this->errors['fichiers'] = 'Fichier(s) non fourni(s)';
}
}
}
}
}
......
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