diff --git a/managers/Medecin.class.php b/managers/Medecin.class.php index df77a08..063f0b6 100755 --- a/managers/Medecin.class.php +++ b/managers/Medecin.class.php @@ -107,4 +107,55 @@ class Medecin } } + + + 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 '.$params['Prenom'].' '.strtoupper($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'].'/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(); + } + } + } + } \ No newline at end of file diff --git a/repositories/repos/MedecinRepo.php b/repositories/repos/MedecinRepo.php index a8586f2..6ef2e81 100755 --- a/repositories/repos/MedecinRepo.php +++ b/repositories/repos/MedecinRepo.php @@ -86,4 +86,11 @@ class MedecinRepo } + + public static function update($id, $nom, $prenom){ + + $req = StaticRepo::getConnexion()->prepare("UPDATE Medecin SET Nom = :nom, Prenom = :prenom WHERE Id = :id"); + return $req->execute([ ':nom' => strtoupper($nom), ':prenom' => $prenom, ':id' => $id ]); + } + }