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