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" : "workerschedule.php")); |
| 31 | } |
| 32 | |
| 33 | $id = (int)$_GET["id"]; |
| 34 | |
| 35 | if (!$isAdmin && people::userData("id") != $id) { |
| 36 | security::notFound(); |
| 37 | } |
| 38 | |
| 39 | $p = people::get($id); |
| 40 | |
| 41 | if ($p === false) { |
| 42 | security::go((security::isAdminView() ? "workers.php" : "workerschedule.php")); |
| 43 | } |
| 44 | |
| 45 | $workers = workers::getPersonWorkers((int)$p["id"]); |
| 46 | $companies = companies::getAll(); |
| 47 | |
| 48 | if ($workers === false || $companies === false) { |
| 49 | security::go((security::isAdminView() ? "workers.php?msg=unexpected" : "workerschedule.php?msg=unexpected")); |
| 50 | } |
| 51 | |
| 52 | $mdHeaderRowBefore = visual::backBtn("workerschedule.php".(security::isAdminView() ? "?id=".$id : "")); |
| 53 | ?> |
| 54 | <!DOCTYPE html> |
| 55 | <html> |
| 56 | <head> |
| 57 | <title><?php echo $conf["appName"]; ?></title> |
| 58 | <?php visual::includeHead(); ?> |
| 59 | <link rel="stylesheet" href="css/dashboard.css"> |
| 60 | <?php |
| 61 | if (security::isAdminView()) { |
| 62 | ?> |
| 63 | <style> |
| 64 | .addschedule { |
| 65 | position: fixed; |
| 66 | bottom: 16px; |
| 67 | right: 16px; |
| 68 | z-index: 1000; |
| 69 | } |
| 70 | </style> |
| 71 | <?php |
| 72 | } |
| 73 | ?> |
| 74 | </head> |
| 75 | <?php visual::printBodyTag(); ?> |
| 76 | <div class="mdl-layout mdl-js-layout mdl-layout--fixed-header mdl-layout--fixed-drawer"> |
| 77 | <?php |
| 78 | visual::includeNav(); |
| 79 | |
| 80 | if (security::isAdminView()) { |
| 81 | ?> |
| 82 | <button class="addschedule 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> |
| 83 | <?php |
| 84 | } |
| 85 | ?> |
| 86 | <main class="mdl-layout__content"> |
| 87 | <div class="page-content"> |
| 88 | <div class="main mdl-shadow--4dp"> |
| 89 | <?php $title = (security::isAdminView() ? "Horarios de “".security::htmlsafe($p["name"])."”" : "Todos los horarios"); ?> |
| 90 | <h2><?=$title?></h2> |
| 91 | |
| 92 | <?php |
| 93 | if (count($workers)) { |
| 94 | foreach ($workers as $w) { |
| 95 | $schedules = schedules::getAll((int)$w["id"], security::isAdminView()); |
| 96 | |
| 97 | echo "<h4>".security::htmlsafe($companies[$w["company"]])."</h4>"; |
| 98 | |
| 99 | if (count($schedules)) { |
| 100 | foreach ($schedules as $s) { |
| 101 | ?> |
| 102 | <a href="schedule.php?id=<?=(int)$s["id"]?>" class="clicky-container"> |
| 103 | <div class="clicky mdl-js-ripple-effect"> |
| 104 | <div class="text"> |
| 105 | <span class="title"><?=security::htmlsafe(date("d/m/Y", $s["begins"]))?> - <?=security::htmlsafe(date("d/m/Y", $s["ends"]))?></span><br> |
| 106 | <span class="description">Activo: <?=($s["active"] == 1 ? visual::YES : visual::NO)?></span> |
| 107 | </div> |
| 108 | <div class="mdl-ripple"></div> |
| 109 | </div> |
| 110 | </a> |
| 111 | <?php |
| 112 | } |
| 113 | } else { |
| 114 | echo "<p>".(security::isAdminView() ? "Todavía no se ha definido ningún horario para este trabajador en esta empresa" : "Todavía no se ha definido ningún horario para esta empresa.")."</p>"; |
| 115 | } |
| 116 | |
| 117 | visual::printDebug("schedules::getAll(".(int)$w["id"].")", $schedules); |
| 118 | } |
| 119 | } else { |
| 120 | echo "<p>".(security::isAdminView() ? "Antes de poder definir horarios para este trabajador deberías darlo de alta en alguna empresa." : "Todavía no se te ha definido ningún horario.")."</p>"; |
| 121 | } |
| 122 | ?> |
| 123 | </div> |
| 124 | </div> |
| 125 | </main> |
| 126 | </div> |
| 127 | |
| 128 | <?php |
| 129 | if (security::isAdminView()) { |
| 130 | ?> |
| 131 | <dialog class="mdl-dialog" id="addschedule"> |
| 132 | <form action="doaddschedule.php" method="POST" autocomplete="off"> |
| 133 | <h4 class="mdl-dialog__title">Crea un nuevo horario semanal</h4> |
| 134 | <div class="mdl-dialog__content"> |
| 135 | <div class="mdlext-selectfield mdlext-js-selectfield mdlext-selectfield--floating-label"> |
| 136 | <select name="worker" id="worker" class="mdlext-selectfield__select" data-required> |
| 137 | <?php |
| 138 | foreach ($workers as $w) { |
| 139 | echo '<option value="'.(int)$w["id"].'">'.security::htmlsafe($companies[$w["company"]]).'</option>'; |
| 140 | } |
| 141 | ?> |
| 142 | </select> |
| 143 | <label for="worker" class="mdlext-selectfield__label">Empresa</label> |
| 144 | </div> |
| 145 | <br> |
| 146 | <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label"> |
| 147 | <input class="mdl-textfield__input" type="date" name="begins" id="begins" autocomplete="off" data-required> |
| 148 | <label class="mdl-textfield__label always-focused" for="begins">Fecha inicio de validez</label> |
| 149 | </div> |
| 150 | <br> |
| 151 | <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label"> |
| 152 | <input class="mdl-textfield__input" type="date" name="ends" id="ends" autocomplete="off" data-required> |
| 153 | <label class="mdl-textfield__label always-focused" for="ends">Fecha fin de validez</label> |
| 154 | </div> |
| 155 | </div> |
| 156 | <div class="mdl-dialog__actions"> |
| 157 | <button type="submit" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--accent">Crear</button> |
| 158 | <button onclick="event.preventDefault(); document.querySelector('#addschedule').close();" class="mdl-button mdl-js-button mdl-js-ripple-effect cancel">Cancelar</button> |
| 159 | </div> |
| 160 | </form> |
| 161 | </dialog> |
| 162 | <?php |
| 163 | } |
| 164 | ?> |
| 165 | |
| 166 | <?php |
| 167 | visual::smartSnackbar([ |
| 168 | ["deleted", "Se ha eliminado el horario semanal correctamente."], |
| 169 | ["empty", "Faltan datos por introducir en el formulario."], |
| 170 | ["unexpected", "Ha ocurrido un error inesperado. Inténtelo de nuevo en unos segundos."], |
| 171 | ["overlaps", "El horario que intentabas añadir se solapa con otro."], |
| 172 | ["order", "La fecha de inicio debe ser anterior a la fecha de fin."] |
| 173 | ]); |
| 174 | ?> |
| 175 | |
| 176 | <?php if (security::isAdminView()) { ?><script src="js/userschedule.js"></script><?php } ?> |
| 177 | </body> |
| 178 | </html> |