From bb0be4db020b06097d43ca4f4d5229e380a6910c Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sun, 3 Jan 2016 17:15:44 +0100 Subject: [PATCH] =?UTF-8?q?Modification=20de=20m=C3=A9decin=20effective?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- managers/Medecin.class.php | 51 ++++++++++++++++++++++++++++++ repositories/repos/MedecinRepo.php | 7 ++++ 2 files changed, 58 insertions(+) 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 ]); + } + }