diff --git a/Medecins.php b/Medecins.php
index 2c9c00a..55b26a5 100755
--- a/Medecins.php
+++ b/Medecins.php
@@ -5,8 +5,13 @@ if(!Authentification::checkUser(0)){
die();
};
-// formattage $_GET['type']
-$answerType = (isset($_GET['type'])) ? $_GET['type'] : null;
+/* REPONSE DU MANAGER */
+$managerStatus = (isset($_GET['status'])) ? $_GET['status'] : null;
+$managerTitle = (isset($_GET['title'])) ? $_GET['title'] : 'Oups!';
+$managerMessage = (isset($_GET['message'])) ? $_GET['message'] : 'Erreur interne!';
+
+// on récupère la liste des médecins si donnée
+$medecinsSearch = ( isset($_GET['medecins']) ) ? json_decode($_GET['medecins'], true) : [];
?>
@@ -32,11 +37,11 @@ $answerType = (isset($_GET['type'])) ? $_GET['type'] : null;
-
+
'>
-
Oups!
-
Certains champs sont incorrects. Veuillez réessayer.
+
+
@@ -63,30 +68,36 @@ $answerType = (isset($_GET['type'])) ? $_GET['type'] : null;
- ';
- switch($answerType){
- case 'creation': echo 'Médecin créé.'; break;
- case 'error': echo 'Une erreur est survenue.'; break;
- default: echo 'rien à déclarer ? Non!'; break;
- }
- echo '';
-
- }
- /*************************************/
+
+
+ Résultats:
+
+ ';
+
+ echo ''.(($MED['Civilite']=='M')?'Monsieur':'Madame').' | ';
+ echo ''.$MED['Prenom'].' | ';
+ echo ''.strtoupper($MED['Nom']).' | ';
+
+ echo '';
+ }}
+
+ ?>
+
diff --git a/js/medecins.js b/js/medecins.js
index 79c6137..028a1f7 100755
--- a/js/medecins.js
+++ b/js/medecins.js
@@ -113,8 +113,8 @@ srNom.addEventListener('keyup', function(e){ checkVARCHAR(e.target, 1, 45, tr
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;
+ var correctNom = srNom.className.indexOf('validated') > -1 && srNom.value.length > 0;
+ var correctPrenom = srPrenom.className.indexOf('validated') > -1 && srPrenom.value.length > 0;
if( correctPrenom || correctNom ){ // si tout es ok uniquement, on submit()
@@ -124,8 +124,14 @@ sbCherche.addEventListener('click', function(e){
};
API.send('Medecin:search', request, function(e){
- notif(e.status, e.title, e.message);
+ if( e.status != 'success' )
+ notif(e.status, e.title, e.message);
+ if( e.hasOwnProperty('medecins') )
+ displaySearchedMedecins(e.medecins);
+ else
+ displaySearchedMedecins([]);
+
if( e.status == 'success' ) // on vide le formulaire si on a 'success'
sbCreer.parentNode.reset();
}, false);
@@ -134,4 +140,28 @@ sbCherche.addEventListener('click', function(e){
}else // sinon on affiche l'erreur
notif('error', 'Oups!', 'Certains champs sont requis ou incorrects.');
-}, false);
\ No newline at end of file
+}, false);
+
+
+
+////////////////////////////////////////////
+// AFFICHAGE DES MEDECINS DE LA RECHERCHE //
+////////////////////////////////////////////
+function displaySearchedMedecins(foundMedecins){
+ var container = document.getElementById('searchResult');
+ var content = '
';
+
+ for( var i = 0 ; i < foundMedecins.length ; i++ ){
+ content += '';
+ content += ''+ ((foundMedecins[i].Civilite=='M')?'Monsieur':'Madame') + ' | ';
+ content += ''+ foundMedecins[i].Prenom + ' | ';
+ content += ''+ foundMedecins[i].Nom.toUpperCase() + ' | ';
+ content += '
';
+ }
+
+ content += '
';
+
+
+ // on vide le container
+ container.innerHTML = content;
+}
\ No newline at end of file
diff --git a/managers/Medecin.class.php b/managers/Medecin.class.php
index 9e3cc5e..edd7f3f 100755
--- a/managers/Medecin.class.php
+++ b/managers/Medecin.class.php
@@ -9,27 +9,32 @@
class Medecin
{
public function add($params){
+
+ /* CREATION REUSSIE */
if(MedecinRepo::add($params['civilite'],strtolower($params['prenom']),strtolower($params['nom'])) !==FALSE){
- if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){
- 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{
+ $_status = 'success';
+ $_title = 'Création effectué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::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
+ else{
$response = new Response();
- $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Medecins.php?type=creation");
+ $response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->send();
}
+
+ /* ERREUR DE CREATION */
}else{
- if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){
- Response::quickResponse(200, json_encode([
- 'status' => 'error',
- 'title' => 'Erreur de création!'
- ]));
- }else{
+ $_status = 'error';
+ $_title = 'Erreur de création!';
+ $_message = 'Certains champs étaient incorrects. Réessayez!';
+
+ if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' )
+ Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
+ else{
$response = new Response();
- $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Medecins.php?type=error");
+ $response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->send();
}
}
@@ -37,18 +42,26 @@ class Medecin
public function search($params){
+
+ /* RECHERCHE REUSSIE */
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{
+ $_status = 'success';
+ $_title = 'Recherche effectuée!';
+ $_message = '
'.count($medList).' médecin(s) trouvé(s)!';
+ $_medecins = $medList;
+
+ if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' )
+ Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message, 'medecins' => $_medecins ]));
+ else{
$response = new Response();
- $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Medecins.php?type=creation");
+ $response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message.'&medecins='.json_encode($_medecins));
$response->send();
}
}else{
+ $_status = 'error';
+ $_title = 'Erreur lors de la recherche!';
+ $_message = 'Certains champs étaient incorrects. Réessayez!';
+
if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){
Response::quickResponse(200, json_encode([
'status' => 'error',
@@ -57,7 +70,7 @@ class Medecin
]));
}else{
$response = new Response();
- $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Medecins.php?type=error");
+ $response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->send();
}
}
@@ -73,7 +86,7 @@ class Medecin
]));
}else{
$response = new Response();
- $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Medecins.php?type=supression");
+ $response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->send();
}
}else{
@@ -84,7 +97,7 @@ class Medecin
]));
}else{
$response = new Response();
- $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Medecins.php?type=error");
+ $response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->send();
}
}
diff --git a/managers/Patient.class.php b/managers/Patient.class.php
index 5d6c998..91e5f91 100755
--- a/managers/Patient.class.php
+++ b/managers/Patient.class.php
@@ -14,41 +14,44 @@ class Patient
$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::quickResponse(200, json_encode([
- 'status' => 'success',
- 'title' => 'Création effectuée!',
- 'message' => 'Le patient '.$params['prenom'].' '.$params['nom'].' a bien été créé.'
- ]));
- }else{
+ $_status = 'success';
+ $_title = 'Création effectuée!';
+ $_message = 'Le patient
'.$params['prenom'].' '.$params['nom'].' a bien été créé.';
+
+ if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' )
+ Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
+ else{
$response = new Response();
- $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=creation");
+ $response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$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' => 'Erreur de création!'
- ]));
- }else{
+ $_status = 'error';
+ $_title = 'Erreur de création!';
+ $_message = 'Certains champs étaient incorrects. Réessayez!';
+
+ if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' )
+ Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
+ else{
$response = new Response();
- $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=error");
+ $response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$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' => 'Erreur de paramètre',
- 'message' => 'Date incorrecte'
- ]));
- }else{
+ $_status = 'error';
+ $_title = 'Erreur de création!';
+ $_message = 'Le format de la date est incorrect. Réessayez!';
+
+ if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' )
+ Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
+ else{
$response = new Response();
- $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=error");
+ $response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->send();
}
+
}
}
@@ -58,39 +61,42 @@ class Patient
$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::quickResponse(200, json_encode([
- 'status' => 'success',
- 'title' => 'Modification effectuée!',
- 'message' => 'Le patient '.$params['prenom'].' '.$params['nom'].' a bien été modifié.'
- ]));
- }else{
+
+ $_status = 'success';
+ $_title = 'Modification effectuée!';
+ $_message = 'Le patient
'.$params['prenom'].' '.$params['nom'].' a bien été modifié.';
+
+ if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' )
+ Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
+ else{
$response = new Response();
- $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=maj");
+ $response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$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' => 'Erreur de création!'
- ]));
- }else{
+ $_status = 'error';
+ $_title = 'Erreur de modification!';
+ $_message = 'Certains champs étaient incorrects. Réessayez!';
+
+ if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' )
+ Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
+ else{
$response = new Response();
- $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=error");
+ $response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$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' => 'Erreur de paramètre',
- 'message' => 'Date incorrecte'
- ]));
- }else{
+ $_status = 'error';
+ $_title = 'Erreur de modification!';
+ $_message = 'Le format de la date est incorrect. Réessayez!';
+
+ if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' )
+ Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
+ else{
$response = new Response();
- $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=error");
+ $response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->send();
}
}
@@ -98,26 +104,29 @@ class Patient
public function delete($params){
if(PatientRepo::delete($params['id_patient']) !==FALSE){
- if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
- Response::quickResponse(200, json_encode([
- 'status' => 'success',
- 'title' => 'Supression effectuée!',
- 'message' => 'Le patient a bien été supprimé.'
- ]));
- }else{
+
+ $_status = 'success';
+ $_title = 'Patient supprimé!';
+ $_message = 'Le patient a bien été supprimé de la base de données!';
+
+ if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' )
+ Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
+ else{
$response = new Response();
- $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=supression");
+ $response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$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' => 'Erreur lors de la supression!'
- ]));
- }else{
+ $_status = 'error';
+ $_title = 'Erreur de suppression!';
+ $_message = 'Erreur lors de la suppression. Réessayez!';
+
+ if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' )
+ Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
+ else{
$response = new Response();
- $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=error");
+ $response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->send();
}
}
diff --git a/repositories/StaticRepo.php b/repositories/StaticRepo.php
index 329e733..60e8c9c 100755
--- a/repositories/StaticRepo.php
+++ b/repositories/StaticRepo.php
@@ -120,36 +120,36 @@ class StaticRepo{
switch($dbtype){
// [1] 'M' / 'F'
case 'Civilite':
- $checker = $checker && is_string($variable) && in_array($variable, ['M','F']);
+ $checker = $checker && !is_null($variable) && is_string($variable) && in_array($variable, ['M','F']);
break;
// [2] Chaine de caractère (longueur variable)
case 'String':
- $checker = $checker && is_string($variable) && strlen($variable) <= $len;
+ $checker = $checker && !is_null($variable) && is_string($variable) && strlen($variable) > 0 && strlen($variable) <= $len;
break;
case 'Integer':
- $checker = $checker && is_int($variable) && $variable
query("SELECT *
FROM Medecin
WHERE Nom LIKE '".$optNom."'
AND Prenom LIKE '".$optPrenom."'
- ");
+ ORDER BY Nom, Prenom ASC");
return StaticRepo::delNumeric( $req->fetchAll() );