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

base insert working

parent e7006177
No related branches found
No related tags found
No related merge requests found
......@@ -2,4 +2,5 @@ aspnet_client/
.user.ini
robots.txt
web.config
ndphpinfo.php
\ No newline at end of file
ndphpinfo.php
configs/db.php
\ No newline at end of file
......@@ -26,14 +26,20 @@
// 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);
// write in DB
insertDataIntoDB($pdo, $candidateData);
// Send mails
mailToResp($candidateData->prenomApprenti, $candidateData->nomApprenti, $candidateData->formation);
mailToApprenti($candidateData->mailApprenti, $candidateData->formation);
// mailToResp($candidateData->prenomApprenti, $candidateData->nomApprenti, $candidateData->formation);
// mailToApprenti($candidateData->mailApprenti, $candidateData->formation);
// kill session
$_SESSION['formError'] = false;
unset($_SESSION);
include("templates/confirmationText.php");
// $_SESSION['formError'] = false;
// unset($_SESSION);
// include("templates/confirmationText.php");
echo "done";
} else {
$_SESSION['formError'] = true;
$_SESSION['postedForm'] = $_POST;
......
<?php
$db_user = '';
$db_pass = '';
$pdo = new PDO('mysql:host=localhost;dbname=canap_dev', $db_user, $db_pass);
?>
\ No newline at end of file
......@@ -459,7 +459,7 @@
if ($_SESSION['formError']) {
echo "<script>showOnFormReturn(lieu);</script>";
}
// require_once('templates/footer.php'); (debug du $_POST)
// require_once('templates/footer.php'); // (debug du $_POST)
?>
</body>
</html>
\ No newline at end of file
<?php
function mailToResp($surname, $name, $job){
require_once("templates/mailToResp.php");
mail($to, $subject, $message, $headers);
require_once("templates/mailToResp.php");
mail($to, $subject, $message, $headers);
}
//vire les accents et remplace caractere non alphanumeric par '-'
// vire les accents et remplace caractere non alphanumeric par '-'
function checkChars ($toCheck) {
$toCheck = strtr($toCheck,
'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ',
'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
$toCheck = preg_replace('/([^.a-z0-9]+)/i', '-', $toCheck);
return $toCheck;
$toCheck = strtr($toCheck,
'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ',
'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
$toCheck = preg_replace('/([^.a-z0-9]+)/i', '-', $toCheck);
return $toCheck;
}
function mailToApprenti($to, $job){
require_once("templates/mailToApp.php");
mail($to, $subject, $message, $headers);
require_once("templates/mailToApp.php");
mail($to, $subject, $message, $headers);
}
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'];
$extension = strtolower(strrchr($file['name'], '.'));
$file['name'] = $name . $extension;
move_uploaded_file($file['tmp_name'], $pathAnnexes . $file['name']);
$candidateData->fichiers[$name] = $file['name'];
}
//Crée le dossier principal est ses 2 sous-dossiers
function createCandidateFolders($candidateData){
$paths = $candidateData->getPaths();
if (!mkdir($paths["pathInfos"], 0777, true)){
die('Echec lors de la création du dossier informations');
die('Echec lors de la création du dossier informations');
}
if (!mkdir($paths["pathAnnexes"], 0777, true)){
die('Echec lors de la création du dossier annexes');
die('Echec lors de la création du dossier annexes');
}
}
function uploadAllFiles($pathAnnexes, $postedFiles, $candidateData){
uploadFile($candidateData, $pathAnnexes, $postedFiles['photo'], "photo-passeport");
uploadFile($candidateData, $pathAnnexes, $postedFiles['idCard'], "carte-identite");
uploadFile($candidateData, $pathAnnexes, $postedFiles['cv'], "curriculum-vitae");
uploadFile($candidateData, $pathAnnexes, $postedFiles['lettre'], "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], "annexe".$i);
}
}
}
uploadFile($candidateData, $pathAnnexes, $postedFiles['photo'], "photo-passeport");
uploadFile($candidateData, $pathAnnexes, $postedFiles['idCard'], "carte-identite");
uploadFile($candidateData, $pathAnnexes, $postedFiles['cv'], "curriculum-vitae");
uploadFile($candidateData, $pathAnnexes, $postedFiles['lettre'], "lettre-motivation");
if($candidateData->formation=="polyMecanicien" && isset($postedFiles['gimch'])){
uploadFile($candidateData, $pathAnnexes, $postedFiles['gimch'], "certificat-gimch");
}
if($candidateData->formation=="informaticien" && isset($postedFiles['griTestInput'])){
uploadFile($candidateData, $pathAnnexes, $postedFiles['griTestInput'], "certificat-gri");
for ($i = 1; $i <= 9; $i++){
if (array_key_exists('certifs'.$i, $postedFiles)){
if (!($postedFiles['certifs'.$i]['name'] == "")) {
uploadFile($candidateData, $pathAnnexes, $postedFiles['certifs'.$i], "annexe".$i);
}
}
}
if($candidateData->formation=="polyMecanicien" && isset($postedFiles['gimch'])){
uploadFile($candidateData, $pathAnnexes, $postedFiles['gimch'], "certificat-gimch");
}
if($candidateData->formation=="informaticien" && isset($postedFiles['griTestInput'])){
uploadFile($candidateData, $pathAnnexes, $postedFiles['griTestInput'], "certificat-gri");
}
unset($candidateData->tmp_fichiers);
return $candidateData;
}
function insertDataIntoDB ($pdo, $candidateData) {
echo "<pre>";
print_r($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)";
// :fk_applicant_main_responsible, :fk_applicant_sec_responsible
$query = $pdo->prepare($sqlreq);
$query->bindParam(':applicant_formation', $candidateData->formation, PDO::PARAM_STR);
$query->bindParam(':applicant_it_section', $candidateData->filiere, PDO::PARAM_STR);
$query->bindParam(':applicant_formation_location', $candidateData->lieu, PDO::PARAM_STR);
$query->bindParam(':applicant_maturity', $candidateData->maturite, PDO::PARAM_BOOL);
$query->bindParam(':applicant_gender', $candidateData->genreApprenti, PDO::PARAM_STR);
$query->bindParam(':applicant_name', $candidateData->nomApprenti, PDO::PARAM_STR);
$query->bindParam(':applicant_fsname', $candidateData->prenomApprenti, PDO::PARAM_STR);
$query->bindParam(':applicant_address_street', $candidateData->addresseApprentiComplete['rue'], PDO::PARAM_STR);
$query->bindParam(':applicant_address_npa', $candidateData->addresseApprentiComplete['NPA'], PDO::PARAM_STR);
$query->bindParam(':applicant_home_phone', $candidateData->telFixeApprenti, PDO::PARAM_STR);
$query->bindParam(':applicant_personal_phone', $candidateData->telMobileApprenti, PDO::PARAM_STR);
$query->bindParam(':applicant_mail', $candidateData->mailApprenti, PDO::PARAM_STR);
$query->bindParam(':applicant_birthdate', $candidateData->dateNaissanceApprenti, PDO::PARAM_STR);
$query->bindParam(':applicant_origin', $candidateData->origineApprenti, PDO::PARAM_STR);
$query->bindParam(':applicant_nationality', $candidateData->nationaliteApprenti, PDO::PARAM_STR);
$query->bindParam(':applicant_foreign_authorization', $candidateData->permisEtranger, PDO::PARAM_STR);
$query->bindParam(':applicant_avs', $candidateData->numeroAVS, PDO::PARAM_STR);
$query->bindParam(':applicant_main_language', $candidateData->langueMaternelleApprenti, PDO::PARAM_STR);
$query->bindParam(':applicant_speaks_french', $test, PDO::PARAM_BOOL);
$query->bindParam(':applicant_speaks_german', $test, PDO::PARAM_BOOL);
$query->bindParam(':applicant_speaks_english', $test, PDO::PARAM_BOOL);
$query->bindParam(':applicant_speaks_other', $test, PDO::PARAM_BOOL);
$query->bindParam(':applicant_has_majority', $candidateData->majeur, PDO::PARAM_BOOL);
$query->bindParam(':applicant_scolarity_end', $candidateData->anneeFinScolarite, PDO::PARAM_STR);
$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);
unset($candidateData->tmp_fichiers);
return $candidateData;
// files
}
?>
\ No newline at end of file
......@@ -17,11 +17,11 @@ class PersonnalData {
"interactiveMediaDesigner" => "InteractiveMediaDesigners"
);
private $dateNow;
private $rootpath = '\\\\scxdata\\apprentis$\\candidatures\\nouvelles\\';
private $rootpath = 'D:/formdata/'; // \\\\scxdata\\apprentis$\\candidatures\\nouvelles\\
public $formation = "";
public $lieu = "";
public $filiere = "";
public $maturite = "false";
public $maturite = 0;
public $genreApprenti = "";
public $nomApprenti = "";
public $prenomApprenti = "";
......@@ -36,13 +36,13 @@ class PersonnalData {
public $numeroAVS = "";
public $langueMaternelleApprenti = "";
public $connaissancesLinguistiques = "";
public $majeur = "false";
public $majeur = 0;
public $representants = [];
public $scolarite = [];
public $anneeFinScolarite;
public $activitesProfessionnelles = [];
public $stages = [];
public $dejaCandidat = "false";
public $dejaCandidat = 0;
public $anneeCandidature = "";
public $datePostulation = "";
public $fichiers = [];
......@@ -57,7 +57,7 @@ class PersonnalData {
if($this->formation =="informaticien"){
$this->filiere = $postedData['filInfo'];
}
$this->maturite = $postedData['mpt'];
$this->maturite = $postedData['mpt'] == true;
$this->genreApprenti = $postedData['genreApp'];
$this->nomApprenti = $postedData['nameApp'];
$this->prenomApprenti = $postedData['surnameApp'];
......@@ -65,14 +65,14 @@ class PersonnalData {
$this->telFixeApprenti = $postedData['telApp'];
$this->telMobileApprenti = $postedData['phoneApp'];
$this->mailApprenti = $postedData['mailApp'];
$this->dateNaissanceApprenti = $postedData['birthApp'];
$this->dateNaissanceApprenti = date('Y-m-d', strtotime($postedData['birthApp']));
$this->origineApprenti = $postedData['originApp'];
$this->nationaliteApprenti = $postedData['nationApp'];
$this->permisEtranger = $postedData['permisEtrangerApp'];
$this->numeroAVS = $postedData['avsNumber'];
$this->langueMaternelleApprenti = $postedData['langApp'];
$this->setLanguages($postedData['languesApp']);
$this->majeur = $postedData['maj'];
$this->majeur = $postedData['maj'] == true;
if($this->majeur == "false"){
$this->setRepresentants();
}
......@@ -117,9 +117,9 @@ class PersonnalData {
}
}
}
private function setDejacand(){
$this->dejaCandidat = $this->postedData['dejaCand'];
if($this->postedData['dejaCand'] == "true"){
private function setDejacand () {
$this->dejaCandidat = $this->postedData['dejaCand'] == true;
if ($this->dejaCandidat) {
$this->anneeCandidature = $this->postedData['dejaCandAnnee'];
}
}
......@@ -141,14 +141,15 @@ 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;
}
}
......
......@@ -94,11 +94,11 @@ class PersonnalDataValidator {
}
}
}
private function dejaCandValid(){
if($this->personnalData->dejaCandidat == 'true'){
if($this->personnalData->anneeCandidature == ""){
private function dejaCandValid () {
if ($this->personnalData->dejaCandidat) {
if ($this->personnalData->anneeCandidature == "") {
$this->errors['anneeCandidature'] = 'Année de candidature non valide';
}else if(!is_numeric($this->personnalData->anneeCandidature)){
} else if (!is_numeric($this->personnalData->anneeCandidature)) {
$this->errors['anneeCandidature'] = 'Année de candidature non valide';
}
}
......@@ -114,7 +114,7 @@ class PersonnalDataValidator {
}
}
private function isEcoleValid(){
if(count($this->personnalData->scolarite)< 2){
if(count($this->personnalData->scolarite) < 2){
$this->errors['ecole'] = 'Informations école non valides';
}
}
......
......@@ -18,5 +18,6 @@
error_reporting(0);
// ini_set("display_errors", 1);
// error_reporting(E_ALL);
require('configs/db.php');
session_start();
?>
\ 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