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