Modification de médecin effective

This commit is contained in:
xdrm-brackets 2016-01-03 17:15:44 +01:00
parent 94ea76f86e
commit bb0be4db02
2 changed files with 58 additions and 0 deletions

View File

@ -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 <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();
}
}
}
}

View File

@ -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 ]);
}
}