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();
$patients = listPatients($pdo);
$calendar_settings = fetchCalendarSettings($pdo, $doctor);
$time_ranges = computeTimeRanges($pdo);
?>
<?php if($_SESSION["user_type"] == 1 and !isset($_GET["medico"])): ?>
<form name="select_doctor" method="get" action="appointment.php">
@ -42,7 +43,12 @@
<form name="add_appointment" method="post" action="appointment_management.php">
<div class="input-group">
<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 class="input-group">
<label for="duracion">Duración</label>

View File

@ -22,6 +22,7 @@ function formatArray($data){
"description" => $row["observaciones"],
"patient" => $row["documento_identificativo"],
"end" => $row["fecha"] . " " . $row["end"],
"overlap" => false,
);
}
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"])){
appointmentCreation();
}

View File

@ -30,15 +30,37 @@ function holidayDeletion()
}
function calendarConfig()
{
$data = $_POST;
function setWorkingHours(&$data){
if(isset($data["hora_inicio_mañana"], $data["hora_fin_mañana"], $data["hora_inicio_tarde"], $data["hora_fin_tarde"])){
$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"])){
$data["sabado_habil"] = 0;
}
if (!isset($data["domingo_habil"])){
$data["domingo_habil"] = 0;
}
}
function sanitizeInputs(&$data){
setWorkingHours($data);
setUncheckedBoxes($data);
}
function calendarConfig()
{
$data = $_POST;
sanitizeInputs($data);
$pdo = connectDatabase();
configureCalendar($pdo, $data);
closeDatabase($pdo);

View File

@ -50,14 +50,6 @@
<label>Hora fin tarde</label>
<input type="time" name="hora_fin_tarde" value="">
</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">
<label>Sábado hábil</label>
<input type="checkbox" name="sabado_habil" value="1">