Move the database logic to appointment_management

This commit is contained in:
coolneng 2020-06-25 21:15:52 +02:00
parent 63b1b72e88
commit b93df4005b
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
5 changed files with 57 additions and 22 deletions

View File

@ -21,13 +21,8 @@
$pdo = connectDatabase(); $pdo = connectDatabase();
?> ?>
<?php if($_SESSION["user_type"] == 2): ?> <?php if($_SESSION["user_type"] == 1): ?>
$user = finduser($pdo, $_SESSION["user"]); <form name="select_doctor" method="post" action="appointment_management.php">
$events = fetchCalendarEvents($pdo, $user[0][4]);
$holidays = fetchDoctorHolidays($pdo, $user[0][4]);
$calendar_settings = fetchCalendarSettings($pdo, $user[0][4]);
<?php else: ?>
<form name="select_doctor" method="get">
<?php $doctors = listDoctors($pdo); ?> <?php $doctors = listDoctors($pdo); ?>
<div class="input-group"> <div class="input-group">
<select id="medico" name="medico"> <select id="medico" name="medico">
@ -38,11 +33,6 @@
</select> </select>
<button class="create_btn" type="submit" name="select">Seleccionar</button> <button class="create_btn" type="submit" name="select">Seleccionar</button>
</div> </div>
<?php
$events = fetchCalendarEvents($pdo, $_GET["medico"]);
$holidays = fetchDoctorHolidays($pdo, $_GET["medico"]);
$calendar_settings = fetchCalendarSettings($pdo, $_GET["medico"]);
?>
<?php endif; ?> <?php endif; ?>
<?php closeDatabase($pdo); ?> <?php closeDatabase($pdo); ?>
<div class="response"></div> <div class="response"></div>

View File

@ -0,0 +1,48 @@
<?php
include'database.php';
session_start();
function fetchDoctor($pdo){
if($_SESSION["user_type"] == 2){
$user = finduser($pdo, $_SESSION["user"]);
return $user[0][4];
}
$data = $_POST;
return $_POST["medico"];
}
function listEvents(){
$pdo = connectDatabase();
$doctor = fetchDoctor($pdo);
$events = fetchCalendarEvents($pdo, $doctor);
closeDatabase($pdo);
return json_encode($events);
}
function listHolidays(){
$pdo = connectDatabase();
$doctor = fetchDoctor($pdo);
$holidays = fetchDoctorHolidays($pdo, $doctor);
closeDatabase($pdo);
return json_encode($holidays);
}
function listCalendarSettings(){
$pdo = connectDatabase();
$doctor = fetchDoctor($pdo);
$calendar_settings = fetchCalendarSettings($pdo, $doctor);
closeDatabase($pdo);
return json_encode($events);
}
if (isset($_GET["list"])) {
listEvents();
listHolidays();
listCalendarSettings();
header('location: appointment.php');
}

View File

@ -15,7 +15,7 @@
header: { header: {
left: 'prev,next today', left: 'prev,next,today',
center: 'title', center: 'title',
@ -24,7 +24,7 @@
}, },
events: "events.php", events: "appointment_management.php?list=1",
eventRender: function(event, element, view) { eventRender: function(event, element, view) {
@ -47,10 +47,9 @@
select: function(start, end, allDay) { select: function(start, end, allDay) {
var title = prompt('Event Title:'); var title = prompt('Título: ');
var duration = prompt('Duración: ');
if (title) {
var start = $.fullCalendar.formatDate(start, "Y-MM-DD HH:mm:ss"); var start = $.fullCalendar.formatDate(start, "Y-MM-DD HH:mm:ss");
@ -58,7 +57,7 @@
$.ajax({ $.ajax({
url: 'add_events.php', url: 'appointment_management.php',
data: 'title='+ title+'&start='+ start +'&end='+ end, data: 'title='+ title+'&start='+ start +'&end='+ end,
@ -86,11 +85,9 @@
}, },
true
); );
}
calendar.fullCalendar('unselect'); calendar.fullCalendar('unselect');

View File

@ -32,7 +32,7 @@
$pdo = connectDatabase(); $pdo = connectDatabase();
$list = listHolidays($pdo); $list = fetchHolidays($pdo);
foreach ($list as $row) : foreach ($list as $row) :
?> ?>

View File

@ -187,7 +187,7 @@ function fetchRegions($pdo)
return $data; return $data;
} }
function listHolidays($pdo) function fetchHolidays($pdo)
{ {
$query = "SELECT * FROM festivo"; $query = "SELECT * FROM festivo";
$result = $pdo->prepare($query); $result = $pdo->prepare($query);