From a6262a5b38ddaed866f5446756070da9136ab0b4 Mon Sep 17 00:00:00 2001 From: coolneng Date: Fri, 10 Jul 2020 23:36:48 +0200 Subject: [PATCH] Add appointment modification and deletion queries --- src/appointment_management.php | 28 +++++++++++++++++++++++++++- src/database.php | 15 +++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/appointment_management.php b/src/appointment_management.php index de63db9..141df14 100644 --- a/src/appointment_management.php +++ b/src/appointment_management.php @@ -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(); +} diff --git a/src/database.php b/src/database.php index 970735d..6a3822e 100644 --- a/src/database.php +++ b/src/database.php @@ -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"; +}