From 0ce9ca7fd8c52fb595752b0c9988b964525f5e3f Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Thu, 17 Dec 2015 10:58:06 +0100 Subject: [PATCH] ... --- Consultations.php | 56 ++++++++++++++++++++---------- Medecins.php | 16 +++++++++ js/lib/API.js | 2 +- js/lib/adjust.js | 34 ++++++++++++++++++ js/medecins.js | 49 ++++++++++++++++++++++++++ js/patients.js | 28 --------------- managers/Medecin.class.php | 28 +++++++++++++++ managers/config/managers.json | 3 ++ repositories/StaticRepo.php | 6 ++-- repositories/repos/MedecinRepo.php | 20 +++++++---- 10 files changed, 185 insertions(+), 57 deletions(-) diff --git a/Consultations.php b/Consultations.php index 6e5c4c6..2d81ab2 100755 --- a/Consultations.php +++ b/Consultations.php @@ -65,13 +65,48 @@ $answerType = (isset($_GET['type'])) ? $_GET['type'] : null; echo ''; switch($answerType){ case 'creation': echo 'Patient créé.'; break; + case 'modification': echo 'Patient modifié.'; break; + case 'suppression': echo 'Patient supprimé.'; break; case 'error': echo 'Une erreur est survenue.'; break; default: echo 'rien à déclarer ? Non!'; break; } echo ''; - } - /*************************************/ + }/************************************/ + /* CONSULTER LES RENDEZ-VOUS */ + /*************************************/ ?> +
+
+ Mois à afficher.
+ + + + + + +

+ + + +
+ + + + + +
@@ -105,23 +140,6 @@ $answerType = (isset($_GET['type'])) ? $_GET['type'] : null;
- - - - -
-
-
-
-
- - - Clé de contrôle invalide. -
-
- diff --git a/Medecins.php b/Medecins.php index f6d909c..d8dbc5e 100755 --- a/Medecins.php +++ b/Medecins.php @@ -74,6 +74,22 @@ $answerType = (isset($_GET['type'])) ? $_GET['type'] : null; } /*************************************/ + /* CONSULTER LES MÉDECIN */ + /*************************************/ ?> +
+
+

Recherche par nom et/ou prénom:

+
+
+
+ + + +
+ +
+ +
diff --git a/js/lib/API.js b/js/lib/API.js index 82b8b71..5333741 100755 --- a/js/lib/API.js +++ b/js/lib/API.js @@ -77,7 +77,7 @@ APIClass.prototype = { this.xhr[i].open('POST', '/managers/', true); // on définit le HEADER - this.xhr[i].setRequestHeader('X-Requested-With', 'XMLHttpRequest'); + this.xhr[i].setRequestHeader('X-REQUESTED-WITH', 'XMLHttpRequest'); this.xhr[i].send( form ); } diff --git a/js/lib/adjust.js b/js/lib/adjust.js index d7cfe3e..2ad2f3f 100755 --- a/js/lib/adjust.js +++ b/js/lib/adjust.js @@ -26,6 +26,40 @@ function remClass(el, pClass){ +// var completeAccentList = "àAAÀAAÁÂÒÓÔÕÖØòÒÓÔÕ-ÖØòó_ôõöøÈÉÊËèéêëÇçÒÓÔÕÖØòÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ"; +var accentList = 'àÀÈÉÊËèéêëçîïúû'; + +/* Met à jour l'état visuel d'un si sa valeur correspond aux initères +* +* @pInputElement l'élément en question +* @pMinLength la taille minimum autorisée +* @pMaxLength la taille maximum autorisée +* @optAlpha [OPT] TRUE si uniquement alphanumérique +*/ +function checkVARCHAR(pInputElement, pMinLength, pMaxLength, optAlpha){ + var optAlpha = (arguments.length > 3) ? optAlpha : false; + optAlpha = (typeof optAlpha == 'boolean') ? optAlpha : false; + + var varcharRegExp; + + if( optAlpha ) varcharRegExp = new RegExp('^(['+accentList+'a-z]{'+pMinLength+','+pMaxLength+'})$', 'i'); // only alpha characters + else varcharRegExp = new RegExp('^(['+accentList+'\\w -]{'+ pMinLength+','+pMaxLength+'})$', 'i'); // any word character + + if( pInputElement.value.match(varcharRegExp) != null || pInputElement.value == '' ){ // si champ correct + addClass(pInputElement, 'validated'); + if( pInputElement.required ) remClass(pInputElement, 'invalid'); + }else{ + remClass(pInputElement, 'validated'); + + if( pInputElement.required ) addClass(pInputElement, 'invalid'); + } +} + + + + + + var notifState = false; // VRAI si affiché, sinon FAUX function notif(pType, pTitle, pMessage){ /* [0] Variables globales diff --git a/js/medecins.js b/js/medecins.js index dfbf9aa..79c6137 100755 --- a/js/medecins.js +++ b/js/medecins.js @@ -85,4 +85,53 @@ sbCreer.addEventListener('click', function(e){ }else{ // sinon on affiche l'erreur notif('error', 'Oups!', 'Certains champs sont requis ou incorrects.'); } +}, false); + + + + + + + + + +/* RECHERCHE DE MEDECINS */ +var srPrenom = document.getElementById('srPrenom'); +var srNom = document.getElementById('srNom'); +var sbCherche = document.getElementById('sbCherche'); + + +////////////////////////////// +// PRENOM & NOM (VARCHAR 45)// +////////////////////////////// +srPrenom.addEventListener('keyup', function(e){ checkVARCHAR(e.target, 1, 45, true); }, false); +srNom.addEventListener('keyup', function(e){ checkVARCHAR(e.target, 1, 45, true); }, false); + +////////////// +// SUBMIT() // +////////////// +sbCherche.addEventListener('click', function(e){ + e.preventDefault(); // on annule le submit() + + var correctNom = srNom.className.indexOf('validated') > -1; + var correctPrenom = srPrenom.className.indexOf('validated') > -1; + + if( correctPrenom || correctNom ){ // si tout es ok uniquement, on submit() + + var request = { + prenom: (correctPrenom) ? srPrenom.value : null, + nom: (correctNom) ? srNom.value : null + }; + + API.send('Medecin:search', request, function(e){ + notif(e.status, e.title, e.message); + + if( e.status == 'success' ) // on vide le formulaire si on a 'success' + sbCreer.parentNode.reset(); + }, false); + + + }else // sinon on affiche l'erreur + notif('error', 'Oups!', 'Certains champs sont requis ou incorrects.'); + }, false); \ No newline at end of file diff --git a/js/patients.js b/js/patients.js index 2cf2a28..8765129 100755 --- a/js/patients.js +++ b/js/patients.js @@ -30,34 +30,6 @@ inCk.append( inSecu, secuFormat, '1 99 19 99 999 999 99'); // on ajoute le -// var completeAccentList = "àAAÀAAÁÂÒÓÔÕÖØòÒÓÔÕ-ÖØòó_ôõöøÈÉÊËèéêëÇçÒÓÔÕÖØòÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ"; -var accentList = 'àÀÈÉÊËèéêëçîïúû'; - -/* Met à jour l'état visuel d'un si sa valeur correspond aux initères -* -* @pInputElement l'élément en question -* @pMinLength la taille minimum autorisée -* @pMaxLength la taille maximum autorisée -* @optAlpha [OPT] TRUE si uniquement alphanumérique -*/ -function checkVARCHAR(pInputElement, pMinLength, pMaxLength, optAlpha){ - var optAlpha = (arguments.length > 3) ? optAlpha : false; - optAlpha = (typeof optAlpha == 'boolean') ? optAlpha : false; - - var varcharRegExp; - - if( optAlpha ) varcharRegExp = new RegExp('^(['+accentList+'a-z]{'+pMinLength+','+pMaxLength+'})$', 'i'); // only alpha characters - else varcharRegExp = new RegExp('^(['+accentList+'\\w -]{'+ pMinLength+','+pMaxLength+'})$', 'i'); // any word character - - if( pInputElement.value.match(varcharRegExp) != null || pInputElement.value == '' ){ // si champ correct - addClass(pInputElement, 'validated'); - if( pInputElement.required ) remClass(pInputElement, 'invalid'); - }else{ - remClass(pInputElement, 'validated'); - - if( pInputElement.required ) addClass(pInputElement, 'invalid'); - } -} ////////////////////////////// // PRENOM & NOM (VARCHAR 45)// diff --git a/managers/Medecin.class.php b/managers/Medecin.class.php index 0999596..9e3cc5e 100755 --- a/managers/Medecin.class.php +++ b/managers/Medecin.class.php @@ -35,6 +35,34 @@ class Medecin } } + + public function search($params){ + if( ($medList=MedecinRepo::search(strtolower($params['nom']), strtolower($params['prenom']))) !== FALSE ){ + if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){ + Response::quickResponse(200, json_encode([ + 'status' => 'success', + 'medecins' => $medList + ])); + }else{ + $response = new Response(); + $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Medecins.php?type=creation"); + $response->send(); + } + }else{ + if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){ + Response::quickResponse(200, json_encode([ + 'status' => 'error', + 'title' => 'Oups!', + 'message' => 'Aucun médecin trouvé.' + ])); + }else{ + $response = new Response(); + $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Medecins.php?type=error"); + $response->send(); + } + } + } + public function delete($params){ if(MedecinRepo::delete($params['id_medecin']) !==FALSE){ if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){ diff --git a/managers/config/managers.json b/managers/config/managers.json index 407b7ab..caed29b 100755 --- a/managers/config/managers.json +++ b/managers/config/managers.json @@ -26,6 +26,9 @@ "add":{"method":"add", "role":0, "strict":false}, + "search":{"method":"search", + "role":0, + "strict":false}, "delete":{"method": "delete", "role": 0, "strict": false} diff --git a/repositories/StaticRepo.php b/repositories/StaticRepo.php index 26c4eee..329e733 100755 --- a/repositories/StaticRepo.php +++ b/repositories/StaticRepo.php @@ -63,13 +63,13 @@ class StaticRepo{ }else{ // on supprime les doublons des entrées (indice numérique) - foreach($fetchData as $i=>$val){ // pour toutes les entrées + foreach($fetchData as $i=>$val){ // pour toutes les entrées if( !mb_detect_encoding($val, 'UTF-8') ) $fetchData[$i] = utf8_encode($val); - if( is_int($i) ) // si l'indice est un entier - unset( $fetchData[$i] ); // on le supprime + if( is_int($i) ) // si l'indice est un entier + unset( $fetchData[$i] ); // on le supprime } } diff --git a/repositories/repos/MedecinRepo.php b/repositories/repos/MedecinRepo.php index cb28517..20ee313 100755 --- a/repositories/repos/MedecinRepo.php +++ b/repositories/repos/MedecinRepo.php @@ -42,15 +42,23 @@ class MedecinRepo return $req->execute(['id' => $idMedecin]); } - public static function search($nom,$prenom){ + public static function search($nom, $prenom){ - if(!StaticRepo::checkParam($prenom,'String45') && !StaticRepo::checkParam($nom,'String45')){return false;} + if( !StaticRepo::checkParam($prenom,'String45') && !StaticRepo::checkParam($nom,'String45') ) return false; - $req = StaticRepo::getConnexion()->prepare('SELECT * FROM Medecin WHERE Nom LIKE :nom AND Prenom LIKE :prenom'); - $req->execute(['nom' => $nom, - 'prenom' => $prenom]); + // on définit les valeurs (peuvent être nulles) + $optPrenom = ( !StaticRepo::checkParam($prenom,'String45') ) ? '%'.$prenom.'%' : '%'; + $optNom = ( !StaticRepo::checkParam($nom, 'String45') ) ? '%'.$nom.'%' : '%'; - return StaticRepo::delNumeric($req->fetchAll()); + + $req = StaticRepo::getConnexion()->query("SELECT * + FROM Medecin + WHERE Nom LIKE '".$optNom."' + AND Prenom LIKE '".$optPrenom."' + "); + + + return StaticRepo::delNumeric( $req->fetchAll() ); } public static function getPatients($idMedecin){