From 53cf6526992bc04c1fce3e3bff9e9082eacbe8d8 Mon Sep 17 00:00:00 2001 From: Lucas Mascaro Date: Tue, 15 Dec 2015 09:24:20 +0100 Subject: [PATCH] =?UTF-8?q?PLUS=20DE=20VERIFICATIOOOOOOOOON=20+=20r=C3=A9p?= =?UTF-8?q?onse=20diff=C3=A9rente=20suivant=20le=20type=20de=20requete?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- coverage/StaticRepo.php.html | 4 +- coverage/dashboard.html | 2 +- coverage/index.html | 2 +- coverage/repos/MedecinRepo.php.html | 2 +- coverage/repos/PatientRepo.php.html | 2 +- coverage/repos/RDVRepo.php.html | 2 +- coverage/repos/StatsRepo.php.html | 2 +- coverage/repos/dashboard.html | 2 +- coverage/repos/index.html | 2 +- managers/Medecin.class.php | 53 ++++++++++--- managers/Patient.class.php | 115 +++++++++++++++++++++++---- managers/RDV.class.php | 117 ++++++++++++++++++++++------ managers/index.php | 2 + 13 files changed, 248 insertions(+), 59 deletions(-) diff --git a/coverage/StaticRepo.php.html b/coverage/StaticRepo.php.html index 92beda0..6e0bff6 100755 --- a/coverage/StaticRepo.php.html +++ b/coverage/StaticRepo.php.html @@ -307,7 +307,7 @@
118
        switch($dbtype){
119
            // [1] 'M' / 'F' 
120
            case 'Civilite': -
121
                $checker = $checker && is_string($variable) && in_array($variable,['M','F']); +
121
                $checker = $checker && is_string($variable) && in_array($variable, ['M','F']);
122
                break;
123
124
            // [2] Chaine de caractère (longueur variable) @@ -366,7 +366,7 @@ Dead Code

- Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.0 at Thu Dec 10 10:51:32 UTC 2015. + Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.3 at Tue Dec 15 8:23:37 UTC 2015.

diff --git a/coverage/dashboard.html b/coverage/dashboard.html index 6c1a65c..7d2b492 100755 --- a/coverage/dashboard.html +++ b/coverage/dashboard.html @@ -146,7 +146,7 @@ diff --git a/coverage/index.html b/coverage/index.html index d3a53a6..ee047e3 100755 --- a/coverage/index.html +++ b/coverage/index.html @@ -136,7 +136,7 @@ High: 90% to 100%

- Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.0 at Thu Dec 10 10:51:32 UTC 2015. + Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.3 at Tue Dec 15 8:23:37 UTC 2015.

diff --git a/coverage/repos/MedecinRepo.php.html b/coverage/repos/MedecinRepo.php.html index 04424d7..52e2944 100755 --- a/coverage/repos/MedecinRepo.php.html +++ b/coverage/repos/MedecinRepo.php.html @@ -318,7 +318,7 @@ Dead Code

- Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.0 at Thu Dec 10 10:51:32 UTC 2015. + Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.3 at Tue Dec 15 8:23:37 UTC 2015.

diff --git a/coverage/repos/PatientRepo.php.html b/coverage/repos/PatientRepo.php.html index b2e260e..1f46bbc 100755 --- a/coverage/repos/PatientRepo.php.html +++ b/coverage/repos/PatientRepo.php.html @@ -385,7 +385,7 @@ Dead Code

- Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.0 at Thu Dec 10 10:51:32 UTC 2015. + Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.3 at Tue Dec 15 8:23:37 UTC 2015.

diff --git a/coverage/repos/RDVRepo.php.html b/coverage/repos/RDVRepo.php.html index e1fa590..843a591 100755 --- a/coverage/repos/RDVRepo.php.html +++ b/coverage/repos/RDVRepo.php.html @@ -365,7 +365,7 @@ Dead Code

- Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.0 at Thu Dec 10 10:51:32 UTC 2015. + Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.3 at Tue Dec 15 8:23:37 UTC 2015.

diff --git a/coverage/repos/StatsRepo.php.html b/coverage/repos/StatsRepo.php.html index 797197a..deeea19 100755 --- a/coverage/repos/StatsRepo.php.html +++ b/coverage/repos/StatsRepo.php.html @@ -213,7 +213,7 @@ Dead Code

- Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.0 at Thu Dec 10 10:51:32 UTC 2015. + Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.3 at Tue Dec 15 8:23:37 UTC 2015.

diff --git a/coverage/repos/dashboard.html b/coverage/repos/dashboard.html index c1336f4..983e68e 100755 --- a/coverage/repos/dashboard.html +++ b/coverage/repos/dashboard.html @@ -141,7 +141,7 @@ diff --git a/coverage/repos/index.html b/coverage/repos/index.html index 2832cc7..50723c4 100755 --- a/coverage/repos/index.html +++ b/coverage/repos/index.html @@ -193,7 +193,7 @@ High: 90% to 100%

- Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.0 at Thu Dec 10 10:51:32 UTC 2015. + Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.3 at Tue Dec 15 8:23:37 UTC 2015.

diff --git a/managers/Medecin.class.php b/managers/Medecin.class.php index 78202ca..0b2436a 100755 --- a/managers/Medecin.class.php +++ b/managers/Medecin.class.php @@ -10,24 +10,55 @@ class Medecin { public function add($params){ if(MedecinRepo::add($params['civilite'],strtolower($params['prenom']),strtolower($params['nom'])) !==FALSE){ - Response::quickResponse(200, json_encode([ - 'status' => 'success', - 'title' => 'Création enregistrée!', - 'message' => 'Le médecin '.$params['prenom'].' '.$params['nom'].' a bien été créé.' - ])); + if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){ + $response = new Response(); + $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Medecins.php?type=creation"); + $response->send(); + }else{ + Response::quickResponse(200, json_encode([ + 'status' => 'success', + 'title' => 'Création effectuée!', + 'message' => 'Le médecin '.$params['prenom'].' '.$params['nom'].' a bien été créé.' + ])); + } }else{ - Response::quickResponse(200, json_encode([ - 'status' => 'error', - 'title' => 'Erreur de création!' - ])); + if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){ + $response = new Response(); + $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Medecins.php?type=error"); + $response->send(); + }else{ + Response::quickResponse(200, json_encode([ + 'status' => 'error', + 'title' => 'Erreur de création!' + ])); + } } } public function delete($params){ if(MedecinRepo::delete($params['id_medecin']) !==FALSE){ - Response::quickResponse(200, json_encode(['status'=>'success'])); + if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){ + $response = new Response(); + $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Medecins.php?type=supression"); + $response->send(); + }else{ + Response::quickResponse(200, json_encode([ + 'status' => 'success', + 'title' => 'Médecin supprimé!', + 'message' => '' + ])); + } }else{ - Response::quickResponse(200, json_encode(['status'=>'error'])); + if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){ + $response = new Response(); + $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Medecins.php?type=error"); + $response->send(); + }else{ + Response::quickResponse(200, json_encode([ + 'status' => 'error', + 'title' => 'Erreur lors de la supression!' + ])); + } } } diff --git a/managers/Patient.class.php b/managers/Patient.class.php index 0bc99ab..23ea4d8 100755 --- a/managers/Patient.class.php +++ b/managers/Patient.class.php @@ -9,34 +9,117 @@ class Patient { public function add($params){ - $params['date_naissance'] = DateTime::createFromFormat('d/m/Y', $params['date_naissance']); - if(PatientRepo::add($params['civilite'],strtolower($params['prenom']),strtolower($params['nom']),$params['adresse'],$params['adresse2'],$params['ville'],$params['code_postal'], - $params['date_naissance']->format('Y-m-d'),$params['lieu_naissance'],$params['num_secu'],$params['medecin_traitant']) !== FALSE){ - Response::quickResponse(200, json_encode([ - 'status' => 'success', - 'title' => 'Création enregistrée!', - 'message' => 'Le patient '.$params['prenom'].' '.$params['nom'].' a bien été créé.' - ])); + if(StaticRepo::checkParam($params['date_naissance'],'Date')){ + $params['num_secu'] = str_replace(' ','',$params['num_secu']); + $params['date_naissance'] = DateTime::createFromFormat('d/m/Y', $params['date_naissance']); + if(PatientRepo::add($params['civilite'],strtolower($params['prenom']),strtolower($params['nom']),$params['adresse'],$params['adresse2'],$params['ville'],$params['code_postal'], + $params['date_naissance']->format('Y-m-d'),$params['lieu_naissance'],$params['num_secu'],$params['medecin_traitant']) !== FALSE){ + if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){ + $response = new Response(); + $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=creation"); + $response->send(); + }else{ + Response::quickResponse(200, json_encode([ + 'status' => 'success', + 'title' => 'Création effectuée!', + 'message' => 'Le patient '.$params['prenom'].' '.$params['nom'].' a bien été créé.' + ])); + } + }else{ + if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){ + $response = new Response(); + $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=error"); + $response->send(); + }else{ + Response::quickResponse(200, json_encode([ + 'status' => 'error', + 'title' => 'Erreur de création!' + ])); + } + } }else{ - Response::quickResponse(200, json_encode([ 'status' => 'error' ])); + if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){ + $response = new Response(); + $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=error"); + $response->send(); + }else{ + Response::quickResponse(200, json_encode([ + 'status' => 'error', + 'title' => 'Erreur de paramètre', + 'message' => 'Date incorrecte' + ])); + } } } public function update($params){ - $params['date_naissance'] = DateTime::createFromFormat('d/m/Y', $params['date_naissance']); - if(PatientRepo::update($params['id_patient'],$params['civilite'],strtolower($params['prenom']),strtolower($params['nom']),$params['adresse'],$params['adresse2'],$params['ville'],$params['cope_postal'], - $params['date_naissance']->format('Y-m-d'),$params['lieu_naissance'],$params['num_secu'],$params['medecin_traitant']) !==FALSE){ - Response::quickResponse(200, json_encode(['status'=>'success'])); + if(StaticRepo::checkParam($params['date_naissance'],'Date')){ + $params['num_secu'] = str_replace(' ','',$params['num_secu']); + $params['date_naissance'] = DateTime::createFromFormat('d/m/Y', $params['date_naissance']); + if(PatientRepo::update($params['id_patient'],$params['civilite'],strtolower($params['prenom']),strtolower($params['nom']),$params['adresse'],$params['adresse2'],$params['ville'],$params['cope_postal'], + $params['date_naissance']->format('Y-m-d'),$params['lieu_naissance'],$params['num_secu'],$params['medecin_traitant']) !==FALSE){ + if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){ + $response = new Response(); + $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=maj"); + $response->send(); + }else{ + Response::quickResponse(200, json_encode([ + 'status' => 'success', + 'title' => 'Modification effectuée!', + 'message' => 'Le patient '.$params['prenom'].' '.$params['nom'].' a bien été modifié.' + ])); + } + }else{ + if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){ + $response = new Response(); + $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=error"); + $response->send(); + }else{ + Response::quickResponse(200, json_encode([ + 'status' => 'error', + 'title' => 'Erreur de création!' + ])); + } + } }else{ - Response::quickResponse(200, json_encode(['status'=>'error'])); + if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){ + $response = new Response(); + $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=error"); + $response->send(); + }else{ + Response::quickResponse(200, json_encode([ + 'status' => 'error', + 'title' => 'Erreur de paramètre', + 'message' => 'Date incorrecte' + ])); + } } } public function delete($params){ if(PatientRepo::delete($params['id_patient']) !==FALSE){ - Response::quickResponse(200, json_encode(['status'=>'success'])); + if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){ + $response = new Response(); + $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=supression"); + $response->send(); + }else{ + Response::quickResponse(200, json_encode([ + 'status' => 'success', + 'title' => 'Supression effectuée!', + 'message' => 'Le patient a bien été supprimé.' + ])); + } }else{ - Response::quickResponse(200, json_encode(['status'=>'error'])); + if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){ + $response = new Response(); + $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=error"); + $response->send(); + }else{ + Response::quickResponse(200, json_encode([ + 'status' => 'error', + 'title' => 'Erreur lors de la supression!' + ])); + } } } diff --git a/managers/RDV.class.php b/managers/RDV.class.php index e4c7075..37e247c 100755 --- a/managers/RDV.class.php +++ b/managers/RDV.class.php @@ -9,40 +9,113 @@ class RDV { public function add($params){ - $params['date'] = DateTime::createFromFormat('d/m/Y', $params['date']); - if(RDVRepo::add($params['date']->format('Y-m-d').' '.$params['heure'].':00',$params['duree'],$params['id_patient'],$params['id_medecin']) !==FALSE){ - $response = new Response(); - $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultation.php?type=creation"); - $response->send(); + if(StaticRepo::checkParam($params['date_naissance'],'Date')) { + $params['date'] = DateTime::createFromFormat('d/m/Y', $params['date']); + if (RDVRepo::add($params['date']->format('Y-m-d') . ' ' . $params['heure'] . ':00', $params['duree'], $params['id_patient'], $params['id_medecin']) !== FALSE) { + if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){ + $response = new Response(); + $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=creation"); + $response->send(); + }else{ + Response::quickResponse(200, json_encode([ + 'status' => 'success', + 'title' => 'Création effectuée!', + 'message' => 'La consultation du '.$params['date']->format('d/m/Y').' à '.$params['heure'].' a bien été créée.' + ])); + } + }else{ + if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){ + $response = new Response(); + $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=error"); + $response->send(); + }else{ + Response::quickResponse(200, json_encode([ + 'status' => 'error', + 'title' => 'Erreur de création!' + ])); + } + } }else{ - $response = new Response(500); - $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultation.php?type=error"); - $response->send(); + if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){ + $response = new Response(); + $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=error"); + $response->send(); + }else{ + Response::quickResponse(200, json_encode([ + 'status' => 'error', + 'title' => 'Erreur de paramètre', + 'message' => 'Date incorrecte' + ])); + } } } public function delete($params){ if(RDVRepo::delete($params['id_consultation']) !==FALSE){ - $response = new Response(); - $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultation.php?type=supression"); - $response->send(); + if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){ + $response = new Response(); + $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=supression"); + $response->send(); + }else{ + Response::quickResponse(200, json_encode([ + 'status' => 'success', + 'title' => 'Supression effectuée!', + 'message' => 'La consultation a bien été supprimée.' + ])); + } }else{ - $response = new Response(500); - $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultation.php?type=error"); - $response->send(); + if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){ + $response = new Response(); + $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=error"); + $response->send(); + }else{ + Response::quickResponse(200, json_encode([ + 'status' => 'error', + 'title' => 'Erreur lors de la supression!' + ])); + } } } public function update($params){ - $params['date'] = DateTime::createFromFormat('d/m/Y', $params['date']); - if(RDVRepo::updateDateTime($params['id_consultation'],$params['date']->format('Y-m-d').' '.$params['heure'].':00') !==FALSE){ - $response = new Response(); - $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultation.php?type=maj"); - $response->send(); + if(StaticRepo::checkParam($params['date_naissance'],'Date')) { + $params['date'] = DateTime::createFromFormat('d/m/Y', $params['date']); + if (RDVRepo::updateDateTime($params['id_consultation'], $params['date']->format('Y-m-d') . ' ' . $params['heure'] . ':00') !== FALSE) { + if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){ + $response = new Response(); + $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=maj"); + $response->send(); + }else{ + Response::quickResponse(200, json_encode([ + 'status' => 'success', + 'title' => 'Modification effectuée!', + 'message' => 'La consultation du '.$params['date']->format('d/m/Y').' à '.$params['heure'].'a bien été mis àjour.' + ])); + } + }else{ + if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){ + $response = new Response(); + $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=error"); + $response->send(); + }else{ + Response::quickResponse(200, json_encode([ + 'status' => 'error', + 'title' => 'Erreur de mise a jour!' + ])); + } + } }else{ - $response = new Response(500); - $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultation.php?type=error"); - $response->send(); + if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){ + $response = new Response(); + $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=error"); + $response->send(); + }else{ + Response::quickResponse(200, json_encode([ + 'status' => 'error', + 'title' => 'Erreur de paramètre', + 'message' => 'Date incorrecte' + ])); + } } } diff --git a/managers/index.php b/managers/index.php index d2ec853..43feed9 100755 --- a/managers/index.php +++ b/managers/index.php @@ -4,6 +4,8 @@ $GLOBALS['compression'] = true; //variable globale pour accéder aux dossiers des managers $GLOBALS['managers_dir'] = dirname(__FILE__); +//Headers de la requete +$GLOBALS['headers'] = apache_request_headers(); session_start(); if($GLOBALS['compression']){