Avancée var

This commit is contained in:
xdrm-brackets 2015-12-22 19:35:35 +01:00
parent e1ba3b272f
commit 4c10c45038
6 changed files with 184 additions and 122 deletions

View File

@ -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;
<body>
<!-- BARRE DE NOTIFICATIONS -->
<div id='NOTIFBAR'>
<div id='NOTIFBAR' class='<?php echo ($managerStatus!=null) ? 'active '.$managerStatus : $managerStatus; ?>'>
<div></div>
<div>
<h3>Oups!</h3>
<p>Certains champs sont incorrects. Veuillez réessayer.</p>
<h3><?php echo $managerTitle; ?></h3>
<p><?php echo $managerMessage; ?></p>
<input type='button' value='Fermer'>
</div>
</div>
@ -63,30 +68,36 @@ $answerType = (isset($_GET['type'])) ? $_GET['type'] : null;
<!-- FIL D'ARIANE -->
<div id='BREADCRUMB'><a href='Dashboard.php'>Accueil</a> <a href='Medecins.php'>Gestion des médecins</a></a> </div>
<?php if( $answerType != null ){
echo '<span>';
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 '</span>';
}
/*************************************/
<?php/********************************/
/* CONSULTER LES MÉDECIN */
/*************************************/ ?>
<article data-title="Rechercher un médecin">
<form method='POST' action='managers/'>
<br><h4>Recherche par nom et/ou prénom:</h4>
<input type='text' id='srPrenom' name='prenom' placeholder='Prénom' value='' required><br>
<input type='text' id='srNom' name='nom' placeholder='NOM' value='' required><br>
<input type='text' id='srPrenom' name='prenom' placeholder='Prénom' value=''><br>
<input type='text' id='srNom' name='nom' placeholder='NOM' value=''><br>
<br>
<input type='hidden' name='command' value='Medecin:search'>
<input type='submit' id='sbCherche' value='Lancer la recherche'>
</form>
</form><br>
<h3>Résultats:</h3><br>
<table id='searchResult'>
<?php
// pour chaque médecin
foreach($medecinsSearch as $MED){ if( isset($MED['Civilite']) && isset($MED['Prenom']) && isset($MED['Nom']) ){
echo '<tr>';
echo '<td>'.(($MED['Civilite']=='M')?'Monsieur':'Madame').'</td>';
echo '<td>'.$MED['Prenom'].'</td>';
echo '<td>'.strtoupper($MED['Nom']).'</td>';
echo '</tr>';
}}
?>
</table>
</article>

View File

@ -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){
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);
@ -135,3 +141,27 @@ sbCherche.addEventListener('click', function(e){
notif('error', 'Oups!', 'Certains champs sont requis ou incorrects.');
}, false);
////////////////////////////////////////////
// AFFICHAGE DES MEDECINS DE LA RECHERCHE //
////////////////////////////////////////////
function displaySearchedMedecins(foundMedecins){
var container = document.getElementById('searchResult');
var content = '<table>';
for( var i = 0 ; i < foundMedecins.length ; i++ ){
content += '<tr>';
content += '<td>'+ ((foundMedecins[i].Civilite=='M')?'Monsieur':'Madame') + '</td>';
content += '<td>'+ foundMedecins[i].Prenom + '</td>';
content += '<td>'+ foundMedecins[i].Nom.toUpperCase() + '</td>';
content += '</tr>';
}
content += '</table>';
// on vide le container
container.innerHTML = content;
}

View File

@ -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 <strong>'.$params['prenom'].' '.$params['nom'].'</strong> 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 = '<strong>'.count($medList).'</strong> 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();
}
}

View File

@ -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 <strong>'.$params['prenom'].' '.$params['nom'].'</strong> 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 <strong>'.$params['prenom'].' '.$params['nom'].'</strong> 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();
}
}

View File

@ -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<pow(2, 32);
$checker = $checker && !is_null($variable) && is_int($variable) && $variable<pow(2, 32);
break;
case 'SmallInteger':
$checker = $checker && is_int($variable) && $variable<pow(2, 16);
$checker = $checker && !is_null($variable) && is_int($variable) && $variable<pow(2, 16);
break;
case 'TinyInteger':
$checker = $checker && is_int($variable) && $variable<pow(2, 8);
$checker = $checker && !is_null($variable) && is_int($variable) && $variable<pow(2, 8);
break;
case 'BigInteger':
$checker = $checker && is_int($variable) && $variable<pow(2, 64);
$checker = $checker && !is_null($variable) && is_int($variable) && $variable<pow(2, 64);
break;
case 'Date':
$checker = $checker && is_string($variable) && ( preg_match('/\d{2}\/\d{2}\/\d{4}/', $variable) || preg_match('/\d{4}-\d{2}-\d{2}/', $variable) );
$checker = $checker && !is_null($variable) && is_string($variable) && ( preg_match('/\d{2}\/\d{2}\/\d{4}/', $variable) || preg_match('/\d{4}-\d{2}-\d{2}/', $variable) );
break;
case 'Heure':
$checker = $checker && is_string($variable) && preg_match('/(\d+):(\d+)/is',$variable);
$checker = $checker && !is_null($variable) && is_string($variable) && preg_match('/(\d+):(\d+)/is',$variable);
break;
// [N] Type inconnu

View File

@ -47,15 +47,14 @@ class MedecinRepo
if( !StaticRepo::checkParam($prenom,'String45') && !StaticRepo::checkParam($nom,'String45') ) return false;
// on définit les valeurs (peuvent être nulles)
$optPrenom = ( !StaticRepo::checkParam($prenom,'String45') ) ? '%'.$prenom.'%' : '%';
$optNom = ( !StaticRepo::checkParam($nom, 'String45') ) ? '%'.$nom.'%' : '%';
$optPrenom = ( $prenom != 'null' && StaticRepo::checkParam($prenom,'String45') ) ? '%'.$prenom.'%' : '%';
$optNom = ( $nom != 'null' && StaticRepo::checkParam($nom, 'String45') ) ? '%'.$nom.'%' : '%';
$req = StaticRepo::getConnexion()->query("SELECT *
FROM Medecin
WHERE Nom LIKE '".$optNom."'
AND Prenom LIKE '".$optPrenom."'
");
ORDER BY Nom, Prenom ASC");
return StaticRepo::delNumeric( $req->fetchAll() );