102 lines
4.7 KiB
PHP
Executable File
102 lines
4.7 KiB
PHP
Executable File
<?php
|
|
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: seekdasky
|
|
* Date: 10/12/15
|
|
* Time: 10:02
|
|
*/
|
|
class Medecin
|
|
{
|
|
public function add($params){
|
|
|
|
/* CREATION REUSSIE */
|
|
if(MedecinRepo::add($params['civilite'],strtolower($params['prenom']),strtolower($params['nom'])) !==FALSE){
|
|
$_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?status='.$_status.'&title='.$_title.'&message='.$_message);
|
|
$response->send();
|
|
}
|
|
|
|
/* ERREUR DE CREATION */
|
|
}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?status='.$_status.'&title='.$_title.'&message='.$_message);
|
|
$response->send();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public function search($params){
|
|
|
|
/* RECHERCHE REUSSIE */
|
|
if( ($medList=MedecinRepo::search(strtolower($params['nom']), strtolower($params['prenom']))) !== FALSE ){
|
|
$_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?status='.$_status.'&title='.$_title.'&message='.$_message.'&medecins='.base64_encode(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' => $_status, 'title' => $_title, 'message' => $_message ]));
|
|
else{
|
|
$response = new Response();
|
|
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
|
|
$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' ){
|
|
Response::quickResponse(200, json_encode([
|
|
'status' => 'success',
|
|
'title' => 'Médecin supprimé!',
|
|
'message' => ''
|
|
]));
|
|
}else{
|
|
$response = new Response();
|
|
$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{
|
|
$response = new Response();
|
|
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
|
|
$response->send();
|
|
}
|
|
}
|
|
}
|
|
|
|
} |