Change time input to dropdown

This commit is contained in:
coolneng 2020-07-15 20:26:06 +02:00
parent 92cb51ae60
commit 393a508136
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
5 changed files with 81 additions and 18 deletions

View File

@ -23,6 +23,7 @@
$pdo = connectDatabase(); $pdo = connectDatabase();
$patients = listPatients($pdo); $patients = listPatients($pdo);
$calendar_settings = fetchCalendarSettings($pdo, $doctor); $calendar_settings = fetchCalendarSettings($pdo, $doctor);
$time_ranges = computeTimeRanges($pdo);
?> ?>
<?php if($_SESSION["user_type"] == 1 and !isset($_GET["medico"])): ?> <?php if($_SESSION["user_type"] == 1 and !isset($_GET["medico"])): ?>
<form name="select_doctor" method="get" action="appointment.php"> <form name="select_doctor" method="get" action="appointment.php">
@ -42,7 +43,12 @@
<form name="add_appointment" method="post" action="appointment_management.php"> <form name="add_appointment" method="post" action="appointment_management.php">
<div class="input-group"> <div class="input-group">
<label for="hora">Hora</label> <label for="hora">Hora</label>
<input type="time" name="hora" value=""> <select id="hora" name="hora">
<option>Seleccione una hora</option>
<?php foreach ($time_ranges as $row) : ?>
<option><?php echo $row; ?></option>
<?php endforeach ?>
</select>
</div> </div>
<div class="input-group"> <div class="input-group">
<label for="duracion">Duración</label> <label for="duracion">Duración</label>
@ -53,12 +59,12 @@
<input type="text" name="observaciones" value=""> <input type="text" name="observaciones" value="">
</div> </div>
<div class="input-group"> <div class="input-group">
<select id="paciente" name="paciente"> <select id="paciente" name="paciente">
<option>Seleccione un paciente</option> <option>Seleccione un paciente</option>
<?php foreach ($patients as $row) : ?> <?php foreach ($patients as $row) : ?>
<option value="<?php echo $row[0]; ?>"><?php echo $row[2]; ?></option> <option value="<?php echo $row[0]; ?>"><?php echo $row[2]; ?></option>
<?php endforeach ?> <?php endforeach ?>
</select> </select>
</div> </div>
<button class="create_btn" type="submit" name="create" >Añadir cita</button> <button class="create_btn" type="submit" name="create" >Añadir cita</button>
<?php $doctor = fetchDoctor($pdo); ?> <?php $doctor = fetchDoctor($pdo); ?>

View File

@ -22,6 +22,7 @@ function formatArray($data){
"description" => $row["observaciones"], "description" => $row["observaciones"],
"patient" => $row["documento_identificativo"], "patient" => $row["documento_identificativo"],
"end" => $row["fecha"] . " " . $row["end"], "end" => $row["fecha"] . " " . $row["end"],
"overlap" => false,
); );
} }
return $events; return $events;

View File

@ -60,6 +60,48 @@ function appointmentDeletion(){
} }
function getFloorCeiling($pdo){
$data = listCalendarSettings($pdo);
if($data["horario"] == "completo"){
$start = $data["hora_inicio_mañana"];
$end = $data["hora_fin_tarde"];
} else if($data["horario"] == "mañana"){
$start = $data["hora_inicio_mañana"];
$end = $data["hora_fin_mañana"];
} else {
$start = $data["hora_inicio_tarde"];
$end = $data["hora_fin_tarde"];
}
$range[] = array(
"start" => $start,
"end" => $end,
);
return $range[0];
}
function getTimeDiff(){
$current = time();
$addTime = strtotime("+30 mins", $current);
$diff = $addTime - $current;
return $diff;
}
function computeTimeRanges($pdo){
$range = getFloorCeiling($pdo);
$diff = getTimeDiff();
$start = strtotime($range["start"]);
$end = strtotime($range["end"]);
$time_range = array();
while($start < $end){
$time_range[] = date('G:i:s', $start);
$start += $diff;
}
return $time_range;
}
if(isset($_POST["create"])){ if(isset($_POST["create"])){
appointmentCreation(); appointmentCreation();
} }

View File

@ -30,15 +30,37 @@ function holidayDeletion()
} }
function calendarConfig() function setWorkingHours(&$data){
{ if(isset($data["hora_inicio_mañana"], $data["hora_fin_mañana"], $data["hora_inicio_tarde"], $data["hora_fin_tarde"])){
$data = $_POST; $data["horario"] = "completo";
} else if (isset($data["hora_inicio_mañana"], $data["hora_fin_mañana"])){
$data["horario"] = "mañana";
} else if (isset($data["hora_inicio_tarde"], $data["hora_fin_tarde"])){
$data["horario"] = "tarde";
}
}
function setUncheckedBoxes(&$data){
if (!isset($data["sabado_habil"])){ if (!isset($data["sabado_habil"])){
$data["sabado_habil"] = 0; $data["sabado_habil"] = 0;
} }
if (!isset($data["domingo_habil"])){ if (!isset($data["domingo_habil"])){
$data["domingo_habil"] = 0; $data["domingo_habil"] = 0;
} }
}
function sanitizeInputs(&$data){
setWorkingHours($data);
setUncheckedBoxes($data);
}
function calendarConfig()
{
$data = $_POST;
sanitizeInputs($data);
$pdo = connectDatabase(); $pdo = connectDatabase();
configureCalendar($pdo, $data); configureCalendar($pdo, $data);
closeDatabase($pdo); closeDatabase($pdo);

View File

@ -50,14 +50,6 @@
<label>Hora fin tarde</label> <label>Hora fin tarde</label>
<input type="time" name="hora_fin_tarde" value=""> <input type="time" name="hora_fin_tarde" value="">
</div> </div>
<div class="select-input">
<label>Horario</label>
<select id="horario" name="horario">
<option value="mañana">mañana</option>
<option value="tarde">tarde</option>
<option value="completo">completo</option>
</select>
</div>
<div class="input-group"> <div class="input-group">
<label>Sábado hábil</label> <label>Sábado hábil</label>
<input type="checkbox" name="sabado_habil" value="1"> <input type="checkbox" name="sabado_habil" value="1">