diff --git a/database/db.sql b/database/db.sql index e083278..4057232 100644 --- a/database/db.sql +++ b/database/db.sql @@ -67,7 +67,7 @@ CREATE TABLE IF NOT EXISTS calendario ( horario VARCHAR(15) NOT NULL, sabado_habil BOOLEAN DEFAULT FALSE, domingo_habil BOOLEAN DEFAULT FALSE, - duracion_cita_por_defecto INT DEFAULT 60, + duracion_cita_por_defecto INT, medico INT, PRIMARY KEY (id, medico), FOREIGN KEY (medico) diff --git a/src/appointment.php b/src/appointment.php index 6d89b0c..9c57e56 100644 --- a/src/appointment.php +++ b/src/appointment.php @@ -18,28 +18,29 @@
- - - diff --git a/src/appointment_management.php b/src/appointment_management.php index da96e34..de63db9 100644 --- a/src/appointment_management.php +++ b/src/appointment_management.php @@ -8,28 +8,33 @@ function fetchDoctor($pdo){ $user = finduser($pdo, $_SESSION["user"]); return $user[0][4]; } - $data = $_POST; - return $_POST["medico"]; + return $_GET["medico"]; } -function listEvents(){ - $pdo = connectDatabase(); +function listEvents($pdo){ $doctor = fetchDoctor($pdo); $events = fetchCalendarEvents($pdo, $doctor); - closeDatabase($pdo); - echo json_encode($events); + return json_encode($events); } -function listHolidays(){ - $pdo = connectDatabase(); +function listHolidays($pdo){ $doctor = fetchDoctor($pdo); $holidays = fetchDoctorHolidays($pdo, $doctor); - closeDatabase($pdo); - echo json_encode($holidays); + return json_encode($holidays); } -listEvents(); -listHolidays(); +function appointmentCreation(){ + $data = $_POST; + $pdo = connectDatabase(); + createAppointment($pdo, $data); + closeDatabase($pdo); + header('location: appointment.php'); +} + + +if(isset($_POST["create"])){ + appointmentCreation(); +} diff --git a/src/database.php b/src/database.php index 043801f..2c6bdd6 100644 --- a/src/database.php +++ b/src/database.php @@ -316,7 +316,7 @@ function fetchCalendarEvents($pdo, $doctor) $query = "SELECT * from cita WHERE medico=?"; $result = $pdo->prepare($query); $result->execute([$doctor]); - $data = $result->fetchAll(); + $data = $result->fetchAll(PDO::FETCH_ASSOC); return $data; } @@ -326,7 +326,7 @@ function fetchCalendarSettings($pdo, $doctor) $query = "SELECT * from calendario WHERE medico=?"; $result = $pdo->prepare($query); $result->execute([$doctor]); - $data = $result->fetch(); + $data = $result->fetch(PDO::FETCH_ASSOC); if(empty($data[8])){ $data[8] = 60; } @@ -339,6 +339,14 @@ function fetchDoctorHolidays($pdo, $doctor) $query = "SELECT * FROM festivo WHERE medico IS NULL OR medico=?"; $result = $pdo->prepare($query); $result->execute([$doctor]); - $data = $result->fetchAll(); + $data = $result->fetchAll(PDO::FETCH_ASSOC); return $data; } + + +function createAppointment($pdo, $data){ + $query = "INSERT INTO cita (fecha, hora, duracion, medico, observaciones, paciente) VALUES (?,?,?,?,?,?)"; + $pdo->prepare($query)->execute([$data["fecha"], $data["hora"], $data["duracion"], + $data["medico"], $data["observaciones"], $data["paciente"]]); + return "Cita creada con éxito"; +}