122 lines
5.8 KiB
PHP
Executable File
122 lines
5.8 KiB
PHP
Executable File
<?php
|
|
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: seekdasky
|
|
* Date: 10/12/15
|
|
* Time: 09:52
|
|
*/
|
|
class RDV
|
|
{
|
|
public function add($params){
|
|
if(StaticRepo::checkParam($params['date'],'Date')) {
|
|
$params['date'] = DateTime::createFromFormat('d/m/Y', $params['date']);
|
|
if (RDVRepo::add($params['date']->format('Y-m-d') . ' ' . $params['heure'] . ':00', $params['duree'], $params['id_patient'], $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' => 'Création effectuée!',
|
|
'message' => 'La consultation du '.$params['date']->format('d/m/Y').' à '.$params['heure'].' a bien été créée.'
|
|
]));
|
|
}else{
|
|
$response = new Response();
|
|
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.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' => 'Erreur de création!'
|
|
]));
|
|
}else{
|
|
$response->send();
|
|
$response = new Response();
|
|
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=error");
|
|
}
|
|
}
|
|
}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{
|
|
$response = new Response();
|
|
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=error");
|
|
$response->send();
|
|
}
|
|
}
|
|
}
|
|
|
|
public function delete($params){
|
|
if(RDVRepo::delete($params['id_consultation']) !==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' => 'La consultation a bien été supprimée.'
|
|
]));
|
|
}else{
|
|
$response = new Response();
|
|
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=supression");
|
|
$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']."/Consultations.php?type=error");
|
|
$response->send();
|
|
}
|
|
}
|
|
}
|
|
|
|
public function update($params){
|
|
if(StaticRepo::checkParam($params['date_naissance'],'Date')) {
|
|
$params['date'] = DateTime::createFromFormat('d/m/Y', $params['date']);
|
|
if (RDVRepo::updateDateTime($params['id_consultation'], $params['date']->format('Y-m-d') . ' ' . $params['heure'] . ':00') !== FALSE) {
|
|
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){
|
|
$response = new Response();
|
|
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=maj");
|
|
$response->send();
|
|
}else{
|
|
Response::quickResponse(200, json_encode([
|
|
'status' => 'success',
|
|
'title' => 'Modification effectuée!',
|
|
'message' => 'La consultation du '.$params['date']->format('d/m/Y').' à '.$params['heure'].'a bien été mis àjour.'
|
|
]));
|
|
}
|
|
}else{
|
|
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){
|
|
$response = new Response();
|
|
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=error");
|
|
$response->send();
|
|
}else{
|
|
Response::quickResponse(200, json_encode([
|
|
'status' => 'error',
|
|
'title' => 'Erreur de mise a jour!'
|
|
]));
|
|
}
|
|
}
|
|
}else{
|
|
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){
|
|
$response = new Response();
|
|
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=error");
|
|
$response->send();
|
|
}else{
|
|
Response::quickResponse(200, json_encode([
|
|
'status' => 'error',
|
|
'title' => 'Erreur de paramètre',
|
|
'message' => 'Date incorrecte'
|
|
]));
|
|
}
|
|
}
|
|
}
|
|
|
|
} |