Add appointment modification and deletion queries

This commit is contained in:
coolneng 2020-07-10 23:36:48 +02:00
parent 2e2e0b67f0
commit a6262a5b38
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
2 changed files with 42 additions and 1 deletions

View File

@ -15,7 +15,7 @@ function fetchDoctor($pdo){
function listEvents($pdo){
$doctor = fetchDoctor($pdo);
$events = fetchCalendarEvents($pdo, $doctor);
return json_encode($events);
return $events;
}
@ -35,6 +35,32 @@ function appointmentCreation(){
}
function appointmentModification(){
$data = $_POST;
$pdo = connectDatabase();
editAppointment($pdo, $data);
closeDatabase($pdo);
header('location: appointment.php');
}
function appointmentDeletion(){
$id = $_POST["id"];
$pdo = connectDatabase();
editAppointment($pdo, $id);
closeDatabase($pdo);
header('location: appointment.php');
}
if(isset($_POST["create"])){
appointmentCreation();
}
if(isset($_POST["edit"])){
appointmentModification();
}
if(isset($_POST["delete"])){
appointmentDeletion();
}

View File

@ -407,3 +407,18 @@ function createAppointment($pdo, $data){
$data["doctor"], $data["observaciones"], $data["paciente"]]);
return "Cita creada con éxito";
}
function editAppointment($pdo, $data){
$query = "UPDATE cita SET (fecha, hora, duracion, medico, observaciones, paciente) VALUES (?,?,?,?,?,?)";
$pdo->prepare($query)->execute([$data["fecha"], $data["hora"], $data["duracion"],
$data["doctor"], $data["observaciones"], $data["paciente"]]);
return "Cita modificada con éxito";
}
function deleteAppointment($pdo, $id){
$statement = "DELETE FROM cita where id=?";
$pdo->prepare($statement)->execute([$id]);
return "Cita borrada con éxito";
}