Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame] | 1 | <?php |
Adrià Vilanova Martínez | 5af8651 | 2023-12-02 20:44:16 +0100 | [diff] [blame] | 2 | /* |
| 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 bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame] | 21 | require_once("core.php"); |
| 22 | security::checkType(security::WORKER); |
| 23 | security::checkWorkerUIEnabled(); |
| 24 | |
| 25 | $isAdmin = security::isAllowed(security::ADMIN); |
| 26 | |
| 27 | if (!security::checkParams("GET", [ |
| 28 | ["id", security::PARAM_ISINT] |
| 29 | ])) { |
| 30 | security::go((security::isAdminView() ? "workers.php" : "userschedule.php?id=".(int)$_SESSION["id"])); |
| 31 | } |
| 32 | |
| 33 | $id = (int)$_GET["id"]; |
| 34 | |
| 35 | $schedule = schedules::get($id); |
| 36 | |
| 37 | if ($schedule === false) { |
| 38 | security::go((security::isAdminView() ? "workers.php" : "userschedule.php?id=".(int)$_SESSION["id"])); |
| 39 | } |
| 40 | |
| 41 | $worker = workers::get($schedule["worker"]); |
| 42 | |
| 43 | if ($worker === false) { |
| 44 | security::go((security::isAdminView() ? "workers.php" : "userschedule.php?id=".(int)$_SESSION["id"])."?msg=unexpected"); |
| 45 | } |
| 46 | |
| 47 | if (!$isAdmin && people::userData("id") != $worker["person"]) { |
| 48 | security::notFound(); |
| 49 | } |
| 50 | |
| 51 | $plaintext = isset($_GET["plaintext"]) && $_GET["plaintext"] == "1"; |
| 52 | |
| 53 | $mdHeaderRowBefore = visual::backBtn((security::isAdminView() ? "userschedule.php?id=".$worker["person"] : "userschedule.php?id=".(int)$_SESSION["id"])); |
| 54 | ?> |
| 55 | <!DOCTYPE html> |
| 56 | <html> |
| 57 | <head> |
| 58 | <title><?php echo $conf["appName"]; ?></title> |
| 59 | <?php visual::includeHead(); ?> |
| 60 | <link rel="stylesheet" href="css/dashboard.css"> |
| 61 | <link rel="stylesheet" href="css/schedule.css"> |
| 62 | |
| 63 | <?php |
| 64 | if (security::isAdminView()) { |
| 65 | ?> |
| 66 | <style> |
| 67 | .addday { |
| 68 | position: fixed; |
| 69 | bottom: 16px; |
| 70 | right: 16px; |
| 71 | z-index: 1000; |
| 72 | } |
| 73 | </style> |
| 74 | <?php |
| 75 | } |
| 76 | ?> |
| 77 | </head> |
| 78 | <?php visual::printBodyTag(); ?> |
| 79 | <div class="mdl-layout mdl-js-layout mdl-layout--fixed-header mdl-layout--fixed-drawer"> |
| 80 | <?php |
| 81 | visual::includeNav(); |
| 82 | |
| 83 | if (security::isAdminView()) { |
| 84 | ?> |
| 85 | <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> |
| 86 | <?php |
| 87 | } |
| 88 | ?> |
| 89 | <main class="mdl-layout__content"> |
| 90 | <div class="page-content"> |
| 91 | <div class="main mdl-shadow--4dp"> |
| 92 | <div class="actions"> |
| 93 | <?php |
| 94 | if (security::isAdminView()) { |
| 95 | ?> |
| 96 | <form action="doactiveschedule.php" method="POST" style="display: inline-block;"> |
| 97 | <input type="hidden" name="id" value="<?=(int)$schedule["id"]?>"> |
| 98 | <input type="hidden" name="value" value="<?=((int)$schedule["active"] + 1)%2?>"> |
| 99 | <button class="mdl-button mdl-js-button mdl-button--raised mdl-button--accent mdl-js-ripple-effect" ><?=($schedule["active"] == 0 ? "Activar" : "Desactivar")?></button> |
| 100 | </form> |
| 101 | <?php |
| 102 | } |
| 103 | ?> |
| 104 | <button id="menu" class="mdl-button mdl-js-button mdl-button--icon mdl-js-ripple-effect"><i class="material-icons">more_vert</i></button> |
| 105 | </div> |
| 106 | |
| 107 | <ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu mdl-js-ripple-effect" for="menu"> |
| 108 | <?php |
| 109 | if (security::isAdminView()) { |
| 110 | ?> |
| 111 | <a data-dyndialog-href="dynamic/editschedule.php?id=<?=(int)$schedule["id"]?>" href="dynamic/editschedule.php?id=<?=(int)$schedule["id"]?>"><li class="mdl-menu__item">Editar detalles</li></a> |
| 112 | <a data-dyndialog-href="dynamic/deleteschedule.php?id=<?=(int)$schedule["id"]?>" href="dynamic/deleteschedule.php?id=<?=(int)$schedule["id"]?>"><li class="mdl-menu__item">Eliminar</li></a> |
| 113 | <?php |
| 114 | } |
| 115 | ?> |
| 116 | <a href="schedule.php?id=<?=(int)$schedule["id"]?>&plaintext=<?=($plaintext ? "0" : "1")?>"><li class="mdl-menu__item"><?=($plaintext ? "Versión enriquecida" : "Versión en texto plano")?></li></a> |
| 117 | </ul> |
| 118 | |
| 119 | <h2>Horario semanal</h2> |
| 120 | |
| 121 | <p> |
| 122 | <b>Trabajador:</b> <?=security::htmlsafe($worker["name"])?> (<?=security::htmlsafe($worker["companyname"])?>)<br> |
| 123 | <b>Validez:</b> del <?=security::htmlsafe(date("d/m/Y", $schedule["begins"]))?> al <?=security::htmlsafe(date("d/m/Y", $schedule["ends"]))?><br> |
| 124 | <b>Activo:</b> <?=($schedule["active"] == 1 ? visual::YES : visual::NO)?> |
| 125 | </p> |
| 126 | |
| 127 | <?php |
| 128 | if ($plaintext) { |
| 129 | echo "<hr>"; |
| 130 | |
| 131 | $flag = false; |
| 132 | foreach ($schedule["days"] as $typeday) { |
| 133 | if (security::isAdminView()) { |
| 134 | schedulesView::renderPlainSchedule($typeday, true, function($day) { |
| 135 | return "dynamic/editday.php?id=".(int)$day["id"]; |
| 136 | }, function ($day) { |
| 137 | return "dynamic/deleteday.php?id=".(int)$day["id"]; |
| 138 | }, $flag); |
| 139 | } else { |
| 140 | schedulesView::renderPlainSchedule($typeday, false, null, null, $flag); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | if (!$flag) { |
| 145 | echo "<p>Este horario todavía no está configurado.</p>".(security::isAdminView() ? "<p>Haz clic en el botón de la parte inferior derecha para empezar a rellenar los horarios diarios.</p>" : ""); |
| 146 | } |
| 147 | } else { |
| 148 | foreach (calendars::$types as $tdid => $type) { |
| 149 | if ($tdid == calendars::TYPE_FESTIU) continue; |
| 150 | |
| 151 | $tdisset = isset($schedule["days"][$tdid]); |
| 152 | |
| 153 | echo "<h4>".security::htmlsafe(calendars::$types[$tdid])."</h4>"; |
| 154 | |
| 155 | if ($tdisset) { |
| 156 | if (security::isAdminView()) { |
| 157 | schedulesView::renderSchedule($schedule["days"][$tdid], true, function($day) { |
| 158 | return "dynamic/editday.php?id=".(int)$day["id"]; |
| 159 | }, function ($day) { |
| 160 | return "dynamic/deleteday.php?id=".(int)$day["id"]; |
| 161 | }); |
| 162 | } else { |
| 163 | schedulesView::renderSchedule($schedule["days"][$tdid], false, null, null); |
| 164 | } |
| 165 | } else { |
| 166 | echo "<p>Todavía no hay configurado ningún horario en días del tipo \"".security::htmlsafe(calendars::$types[$tdid])."\".</p>"; |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | ?> |
| 171 | |
| 172 | <?php visual::printDebug("schedules::get(".(int)$schedule["id"].")", $schedule); ?> |
| 173 | </div> |
| 174 | </div> |
| 175 | </main> |
| 176 | </div> |
| 177 | |
| 178 | <?php |
| 179 | if (security::isAdminView()) { |
| 180 | ?> |
| 181 | <dialog class="mdl-dialog" id="addday"> |
| 182 | <form action="doadddayschedule.php" method="POST" autocomplete="off"> |
| 183 | <input type="hidden" name="id" value="<?=(int)$schedule["id"]?>"> |
| 184 | <h4 class="mdl-dialog__title">Añade un nuevo horario</h4> |
| 185 | <div class="mdl-dialog__content"> |
| 186 | <h5>Día</h5> |
| 187 | <div class="mdlext-selectfield mdlext-js-selectfield mdlext-selectfield--floating-label"> |
| 188 | <div id="dayMenu" class="mdlext-selectfield__select mdl-custom-selectfield__select" tabindex="0">-</div> |
| 189 | <ul class="mdl-menu mdl-menu--bottom mdl-js-menu mdl-custom-multiselect mdl-custom-multiselect-js" for="dayMenu"> |
| 190 | <?php |
| 191 | foreach (calendars::$days as $id => $day) { |
| 192 | ?> |
| 193 | <li class="mdl-menu__item mdl-custom-multiselect__item"> |
| 194 | <label class="mdl-checkbox mdl-js-checkbox" for="day-<?=(int)$id?>"> |
| 195 | <input type="checkbox" id="day-<?=(int)$id?>" name="day[]" value="<?=(int)$id?>" data-value="<?=(int)$id?>" class="mdl-checkbox__input"> |
| 196 | <span class="mdl-checkbox__label"><?=security::htmlsafe($day)?></span> |
| 197 | </label> |
| 198 | </li> |
| 199 | <?php |
| 200 | } |
| 201 | ?> |
| 202 | </ul> |
| 203 | <label for="day" class="mdlext-selectfield__label always-focused mdl-color-text--primary">Día de la semana</label> |
| 204 | </div> |
| 205 | <br> |
| 206 | <div class="mdlext-selectfield mdlext-js-selectfield mdlext-selectfield--floating-label"> |
| 207 | <div id="dayType" class="mdlext-selectfield__select mdl-custom-selectfield__select" tabindex="0">-</div> |
| 208 | <ul class="mdl-menu mdl-menu--bottom mdl-js-menu mdl-custom-multiselect mdl-custom-multiselect-js" for="dayType"> |
| 209 | <?php |
| 210 | foreach (calendars::$types as $id => $type) { |
| 211 | if ($id == calendars::TYPE_FESTIU) continue; |
| 212 | ?> |
| 213 | <li class="mdl-menu__item mdl-custom-multiselect__item"> |
| 214 | <label class="mdl-checkbox mdl-js-checkbox" for="type-<?=(int)$id?>"> |
| 215 | <input type="checkbox" id="type-<?=(int)$id?>" name="type[]" value="<?=(int)$id?>" data-value="<?=(int)$id?>" class="mdl-checkbox__input"> |
| 216 | <span class="mdl-checkbox__label"><?=security::htmlsafe($type)?></span> |
| 217 | </label> |
| 218 | </li> |
| 219 | <?php |
| 220 | } |
| 221 | ?> |
| 222 | </ul> |
| 223 | <label for="day" class="mdlext-selectfield__label always-focused mdl-color-text--primary">Tipo de día</label> |
| 224 | </div> |
| 225 | |
| 226 | <h5>Jornada laboral</h5> |
| 227 | <p>De <input type="time" name="beginswork" required> a <input type="time" name="endswork" required></p> |
| 228 | |
| 229 | <h5>Desayuno</h5> |
| 230 | <p>De <input type="time" name="beginsbreakfast"> a <input type="time" name="endsbreakfast"></p> |
| 231 | |
| 232 | <h5>Comida</h5> |
| 233 | <p>De <input type="time" name="beginslunch"> a <input type="time" name="endslunch"></p> |
| 234 | </div> |
| 235 | <div class="mdl-dialog__actions"> |
| 236 | <button type="submit" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--primary">Crear</button> |
| 237 | <button onclick="event.preventDefault(); document.querySelector('#addday').close();" class="mdl-button mdl-js-button mdl-js-ripple-effect cancel">Cancelar</button> |
| 238 | </div> |
| 239 | </form> |
| 240 | </dialog> |
| 241 | |
| 242 | <script src="js/schedule.js"></script> |
| 243 | <?php |
| 244 | } |
| 245 | |
| 246 | visual::smartSnackbar([ |
| 247 | ["added", "Se ha añadido el horario correctamente."], |
| 248 | ["modified", "Se ha modificado el horario correctamente."], |
| 249 | ["deleted", "Se ha eliminado el horario diario correctamente."], |
| 250 | ["empty", "Faltan datos por introducir en el formulario."], |
| 251 | ["unexpected", "Ha ocurrido un error inesperado. Inténtelo de nuevo en unos segundos."], |
| 252 | ["errorcheck1", "La hora de inicio debe ser anterior a la hora de fin."], |
| 253 | ["errorcheck2", "El desayuno y comida deben estar dentro del horario de trabajo."], |
| 254 | ["errorcheck3", "El desayuno y comida no se pueden solapar."], |
| 255 | ["errorcheck4", "El horario de trabajo no puede ser nulo."], |
| 256 | ["existing", "Algunos horarios que has intentado introducir ya existían. Estos no se han añadido."], |
| 257 | ["activeswitched0", "Horario desactivado correctamente."], |
| 258 | ["activeswitched1", "Horario activado correctamente."], |
| 259 | ["order", "La fecha de inicio debe ser anterior a la fecha de fin."] |
| 260 | ]); |
| 261 | ?> |
| 262 | </body> |
| 263 | </html> |