projet-php/managers/Medecin.class.php

161 lines
7.8 KiB
PHP
Raw Permalink Normal View History

<?php
function customCompression($input, $compression){
if( $compression ) return strtr(base64_encode(addslashes(gzcompress(serialize($input),9))), '+/=', '-_,');
else return unserialize(gzuncompress(stripslashes(base64_decode(strtr($input, '-_,', '+/=')))));
}
/**
* Created by PhpStorm.
* User: seekdasky
* Date: 10/12/15
* Time: 10:02
*/
class Medecin
{
public function add($params){
2015-12-22 18:35:35 +00:00
/* CREATION REUSSIE */
if(MedecinRepo::add($params['civilite'],strtolower($params['prenom']),strtolower($params['nom'])) !==FALSE){
2015-12-22 18:35:35 +00:00
$_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();
2015-12-22 18:35:35 +00:00
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->send();
2015-12-17 08:53:09 +00:00
}
2015-12-22 18:35:35 +00:00
/* ERREUR DE CREATION */
2015-12-17 08:53:09 +00:00
}else{
2015-12-22 18:35:35 +00:00
$_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{
2015-12-17 08:53:09 +00:00
$response = new Response();
2015-12-22 18:35:35 +00:00
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
2015-12-17 08:53:09 +00:00
$response->send();
}
}
}
2015-12-17 09:58:06 +00:00
public function search($params){
2015-12-22 18:35:35 +00:00
/* RECHERCHE REUSSIE */
2015-12-17 09:58:06 +00:00
if( ($medList=MedecinRepo::search(strtolower($params['nom']), strtolower($params['prenom']))) !== FALSE ){
2015-12-22 18:35:35 +00:00
$_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{
2015-12-17 09:58:06 +00:00
$response = new Response();
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message.'&medecins='.customCompression(json_encode($_medecins), true));
2015-12-17 09:58:06 +00:00
$response->send();
}
}else{
2015-12-22 18:35:35 +00:00
$_status = 'error';
$_title = 'Erreur lors de la recherche!';
$_message = 'Certains champs étaient incorrects. Réessayez!';
2015-12-22 23:04:57 +00:00
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{
2015-12-17 09:58:06 +00:00
$response = new Response();
2015-12-22 18:35:35 +00:00
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
2015-12-17 09:58:06 +00:00
$response->send();
}
}
}
public function delete($params){
if( MedecinRepo::delete($params['id_medecin']) !== FALSE ){
$_status = 'success';
$_title = 'Médecin supprimé!';
$_message = 'Le médecin 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();
2015-12-22 18:35:35 +00:00
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->send();
2015-12-17 08:53:09 +00:00
}
2015-12-17 08:53:09 +00:00
}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{
2015-12-17 08:53:09 +00:00
$response = new Response();
2015-12-22 18:35:35 +00:00
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
2015-12-17 08:53:09 +00:00
$response->send();
}
}
}
2016-01-03 16:15:44 +00:00
public function update($params){
if( StaticRepo::checkParam($params['Id'], 'Numeric') && StaticRepo::checkParam($params['Prenom'], 'String45') && StaticRepo::checkParam($params['Nom'], 'String45') ){
// si la modification réussit
if( MedecinRepo::update($params['Id'], $params['Nom'], $params['Prenom']) ){
$_status = 'success';
$_title = 'Médecin modifié!';
$_message = 'Le médecin <strong>'.$params['Prenom'].' '.strtoupper($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'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->send();
}
}else{
$_status = 'error';
$_title = 'Erreur de modification!';
$_message = 'La modification a échoué. 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();
}
}
// erreur de params
}else{
$_status = 'error';
$_title = 'Erreur de paramètres!';
$_message = 'Un des champs 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'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->send();
}
}
}
}