blob: b111992936daa244095926f89c69d3a64b108bd6 [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001<?php
Adrià Vilanova Martínez5af86512023-12-02 20:44:16 +01002/*
3 * hores
4 * Copyright (c) 2023 Adrià Vilanova Martínez
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public
17 * License along with this program.
18 * If not, see http://www.gnu.org/licenses/.
19 */
20
Copybara botbe50d492023-11-30 00:16:42 +010021require_once("core.php");
22security::checkType(security::ADMIN);
23
24if (!security::checkParams("GET", [
25 ["id", security::PARAM_ISINT]
26])) {
27 security::go("scheduletemplates.php");
28}
29
30$id = (int)$_GET["id"];
31
32$template = schedules::getTemplate($id);
33
34if ($template === false) {
35 security::go("scheduletemplates.php");
36}
37
38$plaintext = isset($_GET["plaintext"]) && $_GET["plaintext"] == "1";
39
40$mdHeaderRowBefore = visual::backBtn("scheduletemplates.php");
41?>
42<!DOCTYPE html>
43<html>
44<head>
45 <title><?php echo $conf["appName"]; ?></title>
46 <?php visual::includeHead(); ?>
47 <link rel="stylesheet" href="css/dashboard.css">
48 <link rel="stylesheet" href="css/schedule.css">
49
50 <style>
51 .addday {
52 position: fixed;
53 bottom: 16px;
54 right: 16px;
55 z-index: 1000;
56 }
57 </style>
58</head>
59<?php visual::printBodyTag(); ?>
60 <div class="mdl-layout mdl-js-layout mdl-layout--fixed-header mdl-layout--fixed-drawer">
61 <?php visual::includeNav(); ?>
62 <button class="addday mdl-button md-js-button mdl-button--fab mdl-js-ripple-effect mdl-button--accent"><i class="material-icons">add</i><span class="mdl-ripple"></span></button>
63 <main class="mdl-layout__content">
64 <div class="page-content">
65 <div class="main mdl-shadow--4dp">
66 <div class="actions">
67 <button id="menu" class="mdl-button mdl-js-button mdl-button--icon mdl-js-ripple-effect"><i class="material-icons">more_vert</i></button>
68 </div>
69
70 <ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu mdl-js-ripple-effect" for="menu">
71 <a data-dyndialog-href="dynamic/editscheduletemplate.php?id=<?=(int)$template["id"]?>" href="dynamic/editscheduletemplate.php?id=<?=(int)$template["id"]?>"><li class="mdl-menu__item">Editar detalles</li></a>
72 <a data-dyndialog-href="dynamic/deletescheduletemplate.php?id=<?=(int)$template["id"]?>" href="dynamic/deletescheduletemplate.php?id=<?=(int)$template["id"]?>"><li class="mdl-menu__item">Eliminar</li></a>
73 <a href="scheduletemplate.php?id=<?=(int)$template["id"]?>&plaintext=<?=($plaintext ? "0" : "1")?>"><li class="mdl-menu__item"><?=($plaintext ? "Versión enriquecida" : "Versión en texto plano")?></li></a>
74 </ul>
75
76 <h2>Plantilla &ldquo;<?=security::htmlsafe($template["name"])?>&rdquo;</h2>
77
78 <p><b>Validez:</b> del <?=security::htmlsafe(date("d/m/Y", $template["begins"]))?> al <?=security::htmlsafe(date("d/m/Y", $template["ends"]))?></p>
79
80 <?php
81 if ($plaintext) {
82 echo "<hr>";
83
84 $flag = false;
85 foreach ($template["days"] as $typeday) {
86 schedulesView::renderPlainSchedule($typeday, true, function($day) {
87 return "dynamic/edittemplateday.php?id=".(int)$day["id"];
88 }, function ($day) {
89 return "dynamic/deletetemplateday.php?id=".(int)$day["id"];
90 }, $flag);
91 }
92
93 if (!$flag) {
94 echo "<p>Esta plantilla todavía no está configurada.</p><p>Haz clic en el botón de la parte inferior derecha para empezar a rellenar los horarios de la plantilla.</p>";
95 }
96 } else {
97 foreach (calendars::$types as $tdid => $type) {
98 if ($tdid == calendars::TYPE_FESTIU) continue;
99
100 $tdisset = isset($template["days"][$tdid]);
101
102 echo "<h4>".security::htmlsafe(calendars::$types[$tdid])."</h4>";
103
104 if ($tdisset) {
105 schedulesView::renderSchedule($template["days"][$tdid], true, function($day) {
106 return "dynamic/edittemplateday.php?id=".(int)$day["id"];
107 }, function ($day) {
108 return "dynamic/deletetemplateday.php?id=".(int)$day["id"];
109 });
110 } else {
111 echo "<p>Todavía no hay configurado ningún horario en días del tipo \"".security::htmlsafe(calendars::$types[$tdid])."\".</p>";
112 }
113 }
114 }
115 ?>
116
117 <?php visual::printDebug("schedules::getTemplate(".(int)$template["id"].")", $template); ?>
118 </div>
119 </div>
120 </main>
121 </div>
122
123 <dialog class="mdl-dialog" id="addday">
124 <form action="doadddayscheduletemplate.php" method="POST" autocomplete="off">
125 <input type="hidden" name="id" value="<?=(int)$template["id"]?>">
126 <h4 class="mdl-dialog__title">Añade un nuevo horario</h4>
127 <div class="mdl-dialog__content">
128 <h5>Día</h5>
129 <div class="mdlext-selectfield mdlext-js-selectfield mdlext-selectfield--floating-label">
130 <div id="dayMenu" class="mdlext-selectfield__select mdl-custom-selectfield__select" tabindex="0">-</div>
131 <ul class="mdl-menu mdl-menu--bottom mdl-js-menu mdl-custom-multiselect mdl-custom-multiselect-js" for="dayMenu">
132 <?php
133 foreach (calendars::$days as $id => $day) {
134 ?>
135 <li class="mdl-menu__item mdl-custom-multiselect__item">
136 <label class="mdl-checkbox mdl-js-checkbox" for="day-<?=(int)$id?>">
137 <input type="checkbox" id="day-<?=(int)$id?>" name="day[]" value="<?=(int)$id?>" data-value="<?=(int)$id?>" class="mdl-checkbox__input">
138 <span class="mdl-checkbox__label"><?=security::htmlsafe($day)?></span>
139 </label>
140 </li>
141 <?php
142 }
143 ?>
144 </ul>
145 <label for="day" class="mdlext-selectfield__label always-focused mdl-color-text--primary">Día de la semana</label>
146 </div>
147 <br>
148 <div class="mdlext-selectfield mdlext-js-selectfield mdlext-selectfield--floating-label">
149 <div id="dayType" class="mdlext-selectfield__select mdl-custom-selectfield__select" tabindex="0">-</div>
150 <ul class="mdl-menu mdl-menu--bottom mdl-js-menu mdl-custom-multiselect mdl-custom-multiselect-js" for="dayType">
151 <?php
152 foreach (calendars::$types as $id => $type) {
153 if ($id == calendars::TYPE_FESTIU) continue;
154 ?>
155 <li class="mdl-menu__item mdl-custom-multiselect__item">
156 <label class="mdl-checkbox mdl-js-checkbox" for="type-<?=(int)$id?>">
157 <input type="checkbox" id="type-<?=(int)$id?>" name="type[]" value="<?=(int)$id?>" data-value="<?=(int)$id?>" class="mdl-checkbox__input">
158 <span class="mdl-checkbox__label"><?=security::htmlsafe($type)?></span>
159 </label>
160 </li>
161 <?php
162 }
163 ?>
164 </ul>
165 <label for="day" class="mdlext-selectfield__label always-focused mdl-color-text--primary">Tipo de día</label>
166 </div>
167
168 <h5>Jornada laboral</h5>
169 <p>De <input type="time" name="beginswork" required> a <input type="time" name="endswork" required></p>
170
171 <h5>Desayuno</h5>
172 <p>De <input type="time" name="beginsbreakfast"> a <input type="time" name="endsbreakfast"></p>
173
174 <h5>Comida</h5>
175 <p>De <input type="time" name="beginslunch"> a <input type="time" name="endslunch"></p>
176 </div>
177 <div class="mdl-dialog__actions">
178 <button type="submit" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--primary">Crear</button>
179 <button onclick="event.preventDefault(); document.querySelector('#addday').close();" class="mdl-button mdl-js-button mdl-js-ripple-effect cancel">Cancelar</button>
180 </div>
181 </form>
182 </dialog>
183
184 <?php
185 visual::smartSnackbar([
186 ["added", "Se ha añadido el horario correctamente."],
187 ["modified", "Se ha modificado el horario correctamente."],
188 ["deleted", "Se ha eliminado el horario correctamente."],
189 ["empty", "Faltan datos por introducir en el formulario."],
190 ["unexpected", "Ha ocurrido un error inesperado. Inténtelo de nuevo en unos segundos."],
191 ["errorcheck1", "La hora de inicio debe ser anterior a la hora de fin."],
192 ["errorcheck2", "El desayuno y comida deben estar dentro del horario de trabajo."],
193 ["errorcheck3", "El desayuno y comida no se pueden solapar."],
194 ["errorcheck4", "El horario de trabajo no puede ser nulo."],
195 ["existing", "Algunos horarios que has intentado introducir ya existían. Estos no se han añadido."],
196 ["order", "La fecha de inicio debe ser anterior a la fecha de fin."]
197 ]);
198 ?>
199
200 <script src="js/schedule.js"></script>
201</body>
202</html>