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 | class incidentsView { |
| 22 | public static $limitOptions = [10, 15, 20, 30, 40, 50]; |
| 23 | |
| 24 | public static $incidentsMsgs = [ |
| 25 | ["added", "Se ha añadido la incidencia correctamente."], |
| 26 | ["modified", "Se ha modificado la incidencia correctamente."], |
| 27 | ["removed", "Se ha eliminado la incidencia correctamente."], |
| 28 | ["invalidated", "Se ha invalidado la incidencia correctamente."], |
| 29 | ["empty", "Faltan datos por introducir en el formulario."], |
| 30 | ["unexpected", "Ha ocurrido un error inesperado. Inténtelo de nuevo en unos segundos."], |
| 31 | ["cannotmodify", "No se pueden modificar la incidencia porque ya ha sido registrada o se ha invalidado manualmente."], |
| 32 | ["verified1", "Se ha verificado la incidencia correctamente."], |
| 33 | ["verified0", "Se ha rechazado la incidencia correctamente."], |
| 34 | ["overlap", "La incidencia no se ha añadido porque se solapa con otra incidencia del mismo trabajador."], |
| 35 | ["order", "La hora de inicio debe ser anterior a la hora de fin."], |
| 36 | ["addedemailnotsent", "La incidencia se ha añadido, pero no se ha podido enviar un correo de notificación a los responsables de la categoría del trabajador. Por favor, notifica a estas personas manualmente."], |
| 37 | ["filesize", "El tamaño del archivo adjunto es demasiado grande (el límite es de ".files::READABLE_MAX_SIZE.")"], |
| 38 | ["filetype", "El formato del archivo no está soportado."], |
| 39 | ["attachmentadded", "Se ha añadido el archivo adjunto correctamente."], |
| 40 | ["attachmentdeleted", "Se ha eliminado el archivo adjunto correctamente."], |
| 41 | ["addedrecurring", "Se han añadido todas las incidencias pertinentes correctamente."], |
| 42 | ["unexpectedrecurring", "Ha habido algún problema añadiendo alguna(s) o todas las incidencias que se tenían que crear."], |
| 43 | ["addednotautovalidated", "La incidencia se ha añadido, pero no se ha podido autovalidar."], |
| 44 | ["deleteincidentsbulksuccess", "Las incidencias se han eliminado/invalidado correctamente."], |
| 45 | ["deleteincidentsbulkpartialsuccess", "Algunas incidencias (o todas) no se han podido eliminar/invalidar. Por favor, comprueba el resultado de la acción."] |
| 46 | ]; |
| 47 | |
| 48 | public static function renderIncidents(&$incidents, &$companies, $scrollable = false, $showPersonAndCompany = true, $isForWorker = false, $isForValidationView = false, $isForMassEdit = false, $continueUrl = "incidents.php") { |
| 49 | global $conf, $renderIncidentsAutoIncremental; |
| 50 | if (!isset($renderIncidentsAutoIncremental)) $renderIncidentsAutoIncremental = 0; |
| 51 | $menu = ""; |
| 52 | |
| 53 | $safeContinueUrl = security::htmlsafe(urlencode($continueUrl)); |
| 54 | |
| 55 | if ($isForMassEdit) { |
| 56 | ?> |
| 57 | <div class="left-actions"> |
| 58 | <button id="deleteincidentsbulk" class="mdl-button mdl-js-button mdl-button--icon mdl-js-ripple-effect"><i class="material-icons icon">delete</i></button> |
| 59 | </div> |
| 60 | <?php |
| 61 | } |
| 62 | ?> |
| 63 | <div class="mdl-shadow--2dp overflow-wrapper incidents-wrapper<?=($scrollable ? " incidents-wrapper--scrollable" : "")?>"> |
| 64 | <table class="incidents"> |
| 65 | <?php |
| 66 | if ($isForValidationView || $isForMassEdit) { |
| 67 | ?> |
| 68 | <tr class="artificial-height"> |
| 69 | <?php if ($conf["debug"]) echo "<td></td>"; ?> |
| 70 | <td class="icon-cell has-checkbox"> |
| 71 | <label for="checkboxall_i_<?=$renderIncidentsAutoIncremental?>" class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" data-check-all="true"> |
| 72 | <input type="checkbox" id="checkboxall_i_<?=$renderIncidentsAutoIncremental?>" class="mdl-checkbox__input" autocomplete="off"> |
| 73 | </label> |
| 74 | </td> |
| 75 | <?php if ($conf["debug"]) echo "<td></td>"; ?> |
| 76 | <td></td> |
| 77 | <?php if (!$isForValidationView) echo "<td></td>"; ?> |
| 78 | <td></td> |
| 79 | <?php if ($showPersonAndCompany) echo "<td></td><td></td>"; ?> |
| 80 | <td></td> |
| 81 | </tr> |
| 82 | <?php |
| 83 | } |
| 84 | |
| 85 | foreach ($incidents as $incident) { |
| 86 | $id = (int)$incident["id"]."_".(int)$renderIncidentsAutoIncremental; |
| 87 | $canEdit = (!$isForWorker && !in_array($incident["state"], incidents::$cannotEditStates)) || ($isForWorker && in_array($incident["state"], incidents::$workerCanEditStates)); |
| 88 | $canRemove = (!$isForWorker && in_array($incident["state"], incidents::$canRemoveStates)) || ($isForWorker && in_array($incident["state"], incidents::$workerCanRemoveStates)); |
| 89 | $canInvalidate = !$isForWorker && in_array($incident["state"], incidents::$canInvalidateStates); |
| 90 | $attachments = count(incidents::getAttachmentsFromIncident($incident)); |
| 91 | ?> |
| 92 | <tr<?=(in_array($incident["state"], incidents::$invalidStates) ? ' class="mdl-color-text--grey-700 line-through"' : '')?>> |
| 93 | <?php if ($conf["debug"]) { ?><td><?=(int)$incident["id"]?></td><?php } ?> |
| 94 | <?php |
| 95 | if ($isForValidationView || $isForMassEdit) { |
| 96 | ?> |
| 97 | <td class="icon-cell has-checkbox"> |
| 98 | <label for="checkbox_i_<?=$id?>" class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect"> |
| 99 | <input type="checkbox" id="checkbox_i_<?=$id?>" data-incident="<?=(int)$incident["id"]?>" class="mdl-checkbox__input"<?=($isForMassEdit && !in_array($incident["state"], incidents::$canRemoveStates) && !in_array($incident["state"], incidents::$canInvalidateStates) ? " disabled" : "")?> autocomplete="off"> |
| 100 | </label> |
| 101 | </td> |
| 102 | <?php |
| 103 | } |
| 104 | |
| 105 | if (!$isForValidationView) { |
| 106 | ?> |
| 107 | <td class="icon-cell"> |
| 108 | <i id="state<?=$id?>" class="material-icons <?=security::htmlsafe(incidents::$stateIconColors[$incident["state"]])?>"><?=security::htmlsafe(incidents::$stateIcons[$incident["state"]])?></i> |
| 109 | </td> |
| 110 | <?php |
| 111 | visual::addTooltip("state".$id, security::htmlsafe(incidents::$stateTooltips[$incident["state"]])); |
| 112 | } |
| 113 | ?> |
| 114 | <td class="can-strike"><?=security::htmlsafe($incident["typename"])?></td> |
| 115 | <?php if ($showPersonAndCompany) { |
| 116 | ?> |
| 117 | <td class="can-strike"><span data-dyndialog-href="dynamic/user.php?id=<?=(int)$incident["personid"]?>"><?=security::htmlsafe($incident["workername"])?></span></td> |
| 118 | <td class="can-strike"><?=security::htmlsafe($companies[$incident["companyid"]])?></td> |
| 119 | <?php |
| 120 | } |
| 121 | ?> |
| 122 | <td class="can-strike"><?=strftime("%d %b %Y", $incident["day"])." ".security::htmlsafe($incident["allday"] ? "(todo el día)" : schedules::sec2time($incident["begins"])."-".schedules::sec2time($incident["ends"]))?></td> |
| 123 | <td> |
| 124 | <a href="dynamic/editincidentcomment.php?id=<?=(int)$incident["id"]?>&continue=<?=$safeContinueUrl?>" data-dyndialog-href="dynamic/editincidentcomment.php?id=<?=(int)$incident["id"]?>&continue=<?=$safeContinueUrl?>" class="mdl-button mdl-js-button mdl-button--icon mdl-js-ripple-effect" title="Ver/editar las observaciones"><i class="material-icons icon"><?=(empty($incident["details"]) && empty($incident["workerdetails"]) ? "mode_" : "")?>comment</i></a> |
| 125 | <span<?=($attachments > 0 ? ' class="mdl-badge mdl-badge--overlap" data-badge="'.$attachments.'"' : '')?>><a href="dynamic/incidentattachments.php?id=<?=(int)$incident["id"]?>&continue=<?=$safeContinueUrl?>" data-dyndialog-href="dynamic/incidentattachments.php?id=<?=(int)$incident["id"]?>&continue=<?=$safeContinueUrl?>" class="mdl-button mdl-js-button mdl-button--icon mdl-js-ripple-effect" title="Ver/gestionar los archivos adjuntos"><i class="material-icons icon">attach_file</i></a></span> |
| 126 | <button id="actions<?=$id?>" class="mdl-button mdl-js-button mdl-button--icon mdl-js-ripple-effect custom-actions-btn"><i class="material-icons icon">more_vert</i></button> |
| 127 | <?php |
| 128 | $menu .= '<ul class="mdl-menu mdl-menu--unaligned mdl-js-menu mdl-js-ripple-effect" for="actions'.$id.'">'; |
| 129 | |
| 130 | if ($canEdit) $menu .= '<a href="dynamic/editincident.php?id='.(int)$incident["id"].'&continue='.$safeContinueUrl.'" data-dyndialog-href="dynamic/editincident.php?id='.(int)$incident["id"].'&continue='.$safeContinueUrl.'"><li class="mdl-menu__item">Editar</li></a>'; |
| 131 | |
| 132 | if ($canRemove) $menu .= '<a href="dynamic/deleteincident.php?id='.(int)$incident["id"].'&continue='.$safeContinueUrl.'" data-dyndialog-href="dynamic/deleteincident.php?id='.(int)$incident["id"].'&continue='.$safeContinueUrl.'"><li class="mdl-menu__item">Eliminar</li></a>'; |
| 133 | |
| 134 | if ($canInvalidate) $menu .= '<a href="dynamic/invalidateincident.php?id='.(int)$incident["id"].'&continue='.$safeContinueUrl.'" data-dyndialog-href="dynamic/invalidateincident.php?id='.(int)$incident["id"].'&continue='.$safeContinueUrl.'"><li class="mdl-menu__item">Invalidar</li></a>'; |
| 135 | |
| 136 | $menu .= '<a href="dynamic/authorsincident.php?id='.(int)$incident["id"].'&continue='.$safeContinueUrl.'" data-dyndialog-href="dynamic/authorsincident.php?id='.(int)$incident["id"].'&continue='.$safeContinueUrl.'"><li class="mdl-menu__item">Autoría</li></a></ul>'; |
| 137 | |
| 138 | if ($incident["state"] == incidents::STATE_UNVERIFIED && !$isForWorker) { |
| 139 | ?> |
| 140 | <form action="doverifyincident.php" method="POST" class="verification-actions"> |
| 141 | <input type="hidden" name="id" value="<?=(int)$incident["id"]?>"> |
| 142 | <?php visual::addContinueInput($continueUrl); ?> |
| 143 | <button name="value" value="1" class="mdl-button mdl-js-button mdl-button--icon mdl-js-ripple-effect"><i class="material-icons mdl-color-text--green">check</i></button><button name="value" value="0" class="mdl-button mdl-js-button mdl-button--icon mdl-js-ripple-effect"><i class="material-icons mdl-color-text--red">close</i></button> |
| 144 | </form> |
| 145 | <?php |
| 146 | } |
| 147 | ?> |
| 148 | </td> |
| 149 | </tr> |
| 150 | <?php |
| 151 | $renderIncidentsAutoIncremental++; |
| 152 | } |
| 153 | ?> |
| 154 | </table> |
| 155 | <?php echo $menu; ?> |
| 156 | </div> |
| 157 | <?php |
| 158 | } |
| 159 | |
| 160 | public static function renderIncidentForm(&$workers, $valueFunction, $textFunction, &$companies, $isForWorker = false, $recurrent = false, $continueUrl = false) { |
| 161 | $prefix = ($recurrent ? "recurring" : ""); |
| 162 | ?> |
| 163 | <script> |
| 164 | window.addEventListener("load", e1 => { |
| 165 | document.getElementById("<?=$prefix?>allday").addEventListener("change", e => { |
| 166 | var partialtime = document.getElementById("<?=$prefix?>partialtime"); |
| 167 | if (e.target.checked) { |
| 168 | partialtime.classList.add("notvisible"); |
| 169 | } else { |
| 170 | partialtime.classList.remove("notvisible"); |
| 171 | } |
| 172 | }); |
| 173 | <?php |
| 174 | if ($recurrent) { |
| 175 | ?> |
| 176 | var defaultFields = [ |
| 177 | { |
| 178 | "name": "day", |
| 179 | "min": 0, |
| 180 | "max": 4 |
| 181 | }, |
| 182 | { |
| 183 | "name": "type", |
| 184 | "min": 1, |
| 185 | "max": 2 |
| 186 | } |
| 187 | ]; |
| 188 | |
| 189 | defaultFields.forEach(field => { |
| 190 | for (var i = field.min; i <= field.max; i++) { |
| 191 | document.querySelector("[for=\""+field.name+"-"+i+"\"]").MaterialCheckbox.check(); |
| 192 | |
| 193 | var checkbox = document.getElementById(field.name+"-"+i); |
| 194 | checkbox.checked = true; |
| 195 | if ("createEvent" in document) { |
| 196 | var evt = document.createEvent("HTMLEvents"); |
| 197 | evt.initEvent("change", false, true); |
| 198 | checkbox.dispatchEvent(evt); |
| 199 | } |
| 200 | } |
| 201 | }); |
| 202 | <?php |
| 203 | } |
| 204 | ?> |
| 205 | }); |
| 206 | </script> |
| 207 | <dialog class="mdl-dialog" id="add<?=$prefix?>incident"> |
| 208 | <form action="doadd<?=$prefix?>incident.php" method="POST" autocomplete="off"> |
| 209 | <?php |
| 210 | if ($continueUrl !== false) visual::addContinueInput($continueUrl); |
| 211 | helpView::renderHelpButton(help::PLACE_INCIDENT_FORM, true, true); |
| 212 | ?> |
| 213 | <h4 class="mdl-dialog__title">Añade una incidencia<?=($recurrent ? " recurrente" : "")?></h4> |
| 214 | <div class="mdl-dialog__content"> |
| 215 | <div class="mdlext-selectfield mdlext-js-selectfield mdlext-selectfield--floating-label"> |
| 216 | <select name="worker" id="<?=$prefix?>worker" class="mdlext-selectfield__select" data-required> |
| 217 | <option></option> |
| 218 | <?php |
| 219 | foreach ($workers as $worker) { |
| 220 | if ($worker["hidden"] == 1) continue; |
| 221 | echo '<option value="'.security::htmlsafe($valueFunction($worker, $companies)).'">'.security::htmlsafe($textFunction($worker, $companies)).'</option>'; |
| 222 | } |
| 223 | ?> |
| 224 | </select> |
| 225 | <label for="<?=$prefix?>worker" class="mdlext-selectfield__label">Trabajador</label> |
| 226 | </div> |
| 227 | <br> |
| 228 | <div class="mdlext-selectfield mdlext-js-selectfield mdlext-selectfield--floating-label"> |
| 229 | <select name="type" id="<?=$prefix?>type" class="mdlext-selectfield__select" data-required> |
| 230 | <option></option> |
| 231 | <?php |
| 232 | foreach (incidents::getTypesForm($isForWorker) as $i) { |
| 233 | echo '<option value="'.(int)$i["id"].'">'.security::htmlsafe($i["name"]).'</option>'; |
| 234 | } |
| 235 | ?> |
| 236 | </select> |
| 237 | <label for="<?=$prefix?>type" class="mdlext-selectfield__label">Tipo</label> |
| 238 | </div> |
| 239 | |
| 240 | <?php |
| 241 | if ($isForWorker) { |
| 242 | echo "<p>Para usar un tipo de incidencia que no esté en la lista, debes ponerte en contacto con RRHH para que rellenen ellos la incidencia manualmente.</p>"; |
| 243 | } |
| 244 | ?> |
| 245 | |
| 246 | <?php |
| 247 | if ($recurrent) { |
| 248 | ?> |
| 249 | <h5>Recurrencia</h5> |
| 250 | <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label"> |
| 251 | <input class="mdl-textfield__input" type="date" name="firstday" id="<?=$prefix?>firstday" autocomplete="off" data-required> |
| 252 | <label class="mdl-textfield__label always-focused" for="<?=$prefix?>firstday">Día de inicio</label> |
| 253 | </div> |
| 254 | <br> |
| 255 | <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label"> |
| 256 | <input class="mdl-textfield__input" type="date" name="lastday" id="<?=$prefix?>lastday" autocomplete="off" data-required> |
| 257 | <label class="mdl-textfield__label always-focused" for="<?=$prefix?>lastday">Día de fin</label> |
| 258 | </div> |
| 259 | <br> |
| 260 | <div class="mdlext-selectfield mdlext-js-selectfield mdlext-selectfield--floating-label"> |
| 261 | <div id="dayMenu" class="mdlext-selectfield__select mdl-custom-selectfield__select" tabindex="0">-</div> |
| 262 | <ul class="mdl-menu mdl-menu--bottom mdl-js-menu mdl-custom-multiselect mdl-custom-multiselect-js" for="dayMenu"> |
| 263 | <?php |
| 264 | foreach (calendars::$days as $id => $day) { |
| 265 | ?> |
| 266 | <li class="mdl-menu__item mdl-custom-multiselect__item"> |
| 267 | <label class="mdl-checkbox mdl-js-checkbox" for="day-<?=(int)$id?>"> |
| 268 | <input type="checkbox" id="day-<?=(int)$id?>" name="day[]" value="<?=(int)$id?>" data-value="<?=(int)$id?>" class="mdl-checkbox__input"> |
| 269 | <span class="mdl-checkbox__label"><?=security::htmlsafe($day)?></span> |
| 270 | </label> |
| 271 | </li> |
| 272 | <?php |
| 273 | } |
| 274 | ?> |
| 275 | </ul> |
| 276 | <label for="day" class="mdlext-selectfield__label always-focused mdl-color-text--primary">Día de la semana</label> |
| 277 | </div> |
| 278 | <br> |
| 279 | <div class="mdlext-selectfield mdlext-js-selectfield mdlext-selectfield--floating-label"> |
| 280 | <div id="dayType" class="mdlext-selectfield__select mdl-custom-selectfield__select" tabindex="0">-</div> |
| 281 | <ul class="mdl-menu mdl-menu--bottom mdl-js-menu mdl-custom-multiselect mdl-custom-multiselect-js" for="dayType"> |
| 282 | <?php |
| 283 | foreach (calendars::$types as $id => $type) { |
| 284 | if ($id == calendars::TYPE_FESTIU) continue; |
| 285 | ?> |
| 286 | <li class="mdl-menu__item mdl-custom-multiselect__item"> |
| 287 | <label class="mdl-checkbox mdl-js-checkbox" for="type-<?=(int)$id?>"> |
| 288 | <input type="checkbox" id="type-<?=(int)$id?>" name="daytype[]" value="<?=(int)$id?>" data-value="<?=(int)$id?>" class="mdl-checkbox__input"> |
| 289 | <span class="mdl-checkbox__label"><?=security::htmlsafe($type)?></span> |
| 290 | </label> |
| 291 | </li> |
| 292 | <?php |
| 293 | } |
| 294 | ?> |
| 295 | </ul> |
| 296 | <label for="day" class="mdlext-selectfield__label always-focused mdl-color-text--primary">Tipo de día</label> |
| 297 | </div> |
| 298 | <h5>Afectación</h5> |
| 299 | <?php |
| 300 | } else { |
| 301 | ?> |
| 302 | <h5>Afectación</h5> |
| 303 | <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label"> |
| 304 | <input class="mdl-textfield__input" type="date" name="day" id="<?=$prefix?>day" autocomplete="off" data-required> |
| 305 | <label class="mdl-textfield__label always-focused" for="<?=$prefix?>day">Día</label> |
| 306 | </div> |
| 307 | <br> |
| 308 | <?php |
| 309 | } |
| 310 | ?> |
| 311 | <p> |
| 312 | <label class="mdl-switch mdl-js-switch mdl-js-ripple-effect" for="<?=$prefix?>allday"> |
| 313 | <input type="checkbox" id="<?=$prefix?>allday" name="allday" value="1" class="mdl-switch__input"> |
| 314 | <span class="mdl-switch__label">Día entero</span> |
| 315 | </label> |
| 316 | </p> |
| 317 | <div id="<?=$prefix?>partialtime">De <input type="time" name="begins"> a <input type="time" name="ends"></div> |
| 318 | |
| 319 | <h5>Detalles adicionales</h5> |
| 320 | <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label"> |
| 321 | <textarea class="mdl-textfield__input" name="details" id="<?=$prefix?>details"></textarea> |
| 322 | <label class="mdl-textfield__label" for="<?=$prefix?>details">Observaciones (opcional)</label> |
| 323 | </div> |
| 324 | <?php |
| 325 | if (!$isForWorker && !$recurrent) { |
| 326 | ?> |
| 327 | <p> |
| 328 | <label class="mdl-switch mdl-js-switch mdl-js-ripple-effect" for="<?=$prefix?>autoverify"> |
| 329 | <input type="checkbox" id="<?=$prefix?>autoverify" name="autoverify" value="1" class="mdl-switch__input" checked> |
| 330 | <span class="mdl-switch__label">Saltar la cola de revisión</span> |
| 331 | </label> |
| 332 | </p> |
| 333 | <?php |
| 334 | } |
| 335 | |
| 336 | if (!$isForWorker) echo "<p>Las observaciones aparecerán en los PDFs que se exporten.</p>"; |
| 337 | else echo "<p>Las observaciones serán únicamente visibles para los administradores del sistema.</p><p>Al añadir la incidencia, se guardará tu <a href=\"https://help.gnome.org/users/gnome-help/stable/net-what-is-ip-address.html.es\" target=\"_blank\" rel=\"noopener noreferrer\">dirección IP</a> y la fecha y hora actual para autovalidar la incidencia.</p>"; |
| 338 | if (!$recurrent) echo '<p>Después de crear la incidencia podrás añadir archivos adjuntos haciendo clic en el botón <i class="material-icons" style="vertical-align: middle;">attach_file</i>.</p>'; |
| 339 | ?> |
| 340 | </div> |
| 341 | <div class="mdl-dialog__actions"> |
| 342 | <button type="submit" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--accent">Añadir</button> |
| 343 | <button onclick="event.preventDefault(); document.querySelector('#add<?=$prefix?>incident').close();" class="mdl-button mdl-js-button mdl-js-ripple-effect cancel">Cancelar</button> |
| 344 | </div> |
| 345 | </form> |
| 346 | </dialog> |
| 347 | <?php |
| 348 | } |
| 349 | |
| 350 | public static function renderFilterDialog($select) { |
| 351 | global $_GET; |
| 352 | ?> |
| 353 | <style> |
| 354 | #filter { |
| 355 | max-width: 300px; |
| 356 | width: auto; |
| 357 | } |
| 358 | |
| 359 | #filter .mdl-checkbox { |
| 360 | height: auto; |
| 361 | } |
| 362 | </style> |
| 363 | <dialog class="mdl-dialog" id="filter"> |
| 364 | <form action="incidents.php" method="GET" enctype="multipart/form-data"> |
| 365 | <h4 class="mdl-dialog__title">Filtrar lista</h4> |
| 366 | <div class="mdl-dialog__content"> |
| 367 | <h5>Por fecha</h5> |
| 368 | <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label"> |
| 369 | <input class="mdl-textfield__input" type="date" name="begins" id="begins" autocomplete="off" <?=$select["enabled"]["begins"] ? " value=\"".security::htmlsafe($select["selected"]["begins"])."\"" : ""?>> |
| 370 | <label class="mdl-textfield__label always-focused" for="begins">Fecha inicio (opcional)</label> |
| 371 | </div> |
| 372 | <br> |
| 373 | <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label"> |
| 374 | <input class="mdl-textfield__input" type="date" name="ends" id="ends" autocomplete="off" <?=$select["enabled"]["ends"] ? " value=\"".security::htmlsafe($select["selected"]["ends"])."\"" : ""?>> |
| 375 | <label class="mdl-textfield__label always-focused" for="ends">Fecha fin (opcional)</label> |
| 376 | </div> |
| 377 | <h5>Por estado <i id="tt_incidentstatusnotpaginated" class="material-icons help">info</i></h5> |
| 378 | <div class="mdl-tooltip" for="tt_incidentstatusnotpaginated">Al filtrar por estado, la página de resultados no estará paginada y saldrán todos los resultados en una misma página. La acción podría consumir bastantes recursos y tomar más tiempo del habitual.</div> |
| 379 | <?php |
| 380 | foreach (incidents::$statesOrderForFilters as $id) { |
| 381 | ?> |
| 382 | <label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="state<?=(int)$id?>"> |
| 383 | <input type="checkbox" id="state<?=(int)$id?>" name="states[<?=(int)$id?>]" class="mdl-checkbox__input" value="1"<?=(($select["enabled"]["states"] && in_array($id, $select["selected"]["states"])) ? " checked" : "")?>> |
| 384 | <span class="mdl-checkbox__label"><?=security::htmlsafe(incidents::$stateTooltips[$id])?></span> |
| 385 | </label> |
| 386 | <?php |
| 387 | } |
| 388 | ?> |
| 389 | <h5>Por tipo</h5> |
| 390 | <?php |
| 391 | $types = incidents::getTypes(); |
| 392 | if ($types !== false) { |
| 393 | foreach ($types as $type) { |
| 394 | ?> |
| 395 | <label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="type<?=(int)$type["id"]?>"> |
| 396 | <input type="checkbox" id="type<?=(int)$type["id"]?>" name="types[<?=(int)$type["id"]?>]" class="mdl-checkbox__input" value="1"<?=(($select["enabled"]["types"] && in_array($type["id"], $select["selected"]["types"])) ? " checked" : "")?>> |
| 397 | <span class="mdl-checkbox__label"><?=security::htmlsafe($type["name"])?></span> |
| 398 | </label> |
| 399 | <?php |
| 400 | } |
| 401 | } |
| 402 | ?> |
| 403 | <h5>Miscelánea</h5> |
| 404 | <?php |
| 405 | foreach (incidents::$filtersSwitchHelper as $f => $helper) { |
| 406 | foreach (incidents::$filtersSwitchOptions as $value => $option) { |
| 407 | ?> |
| 408 | <label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="<?=security::htmlsafe($f).(int)$value?>"> |
| 409 | <input type="checkbox" id="<?=security::htmlsafe($f).(int)$value?>" name="<?=security::htmlsafe($f)?>[<?=(int)$value?>]" class="mdl-checkbox__input" value="1"<?=(($select["enabled"][$f] && in_array($value, $select["selected"][$f])) ? " checked" : "")?>> |
| 410 | <span class="mdl-checkbox__label"><?=security::htmlsafe($option." ".$helper)?></span> |
| 411 | </label> |
| 412 | <?php |
| 413 | } |
| 414 | } |
| 415 | ?> |
| 416 | </div> |
| 417 | <div class="mdl-dialog__actions"> |
| 418 | <button type="submit" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--accent">Filtrar</button> |
| 419 | <button onclick="event.preventDefault(); document.querySelector('#filter').close();" class="mdl-button mdl-js-button mdl-js-ripple-effect cancel">Cancelar</button> |
| 420 | </div> |
| 421 | </form> |
| 422 | </dialog> |
| 423 | <?php |
| 424 | } |
| 425 | |
| 426 | public static function buildSelect() { |
| 427 | global $select, $_GET; |
| 428 | |
| 429 | $select = array("showPendingQueue" => false, "isAnyEnabled" => false, "pageUrl" => "", "pageUrlHasParameters" => false, "showResultsPaginated" => true, "enabled" => [], "selected" => []); |
| 430 | |
| 431 | $parameters = []; |
| 432 | |
| 433 | foreach (incidents::$filters as $f) { |
| 434 | $fType = incidents::$filtersType[$f]; |
| 435 | |
| 436 | switch ($fType) { |
| 437 | case incidents::FILTER_TYPE_ARRAY: |
| 438 | $select["enabled"][$f] = isset($_GET[$f]); |
| 439 | break; |
| 440 | |
| 441 | case incidents::FILTER_TYPE_INT: |
| 442 | $select["enabled"][$f] = isset($_GET[$f]) && $_GET[$f] !== ""; |
| 443 | break; |
| 444 | |
| 445 | case incidents::FILTER_TYPE_STRING: |
| 446 | $select["enabled"][$f] = isset($_GET[$f]) && !empty($_GET[$f]); |
| 447 | break; |
| 448 | } |
| 449 | |
| 450 | if ($select["enabled"][$f]) { |
| 451 | switch ($fType) { |
| 452 | case incidents::FILTER_TYPE_ARRAY: |
| 453 | $select["selected"][$f] = (isset($_GET[$f]) ? array_keys($_GET[$f]) : []); |
| 454 | foreach ($select["selected"][$f] as $value) { |
| 455 | $parameters[] = urlencode($f)."[".urlencode($value)."]=1"; |
| 456 | } |
| 457 | break; |
| 458 | |
| 459 | case incidents::FILTER_TYPE_INT: |
| 460 | $select["selected"][$f] = (int)$_GET[$f]; |
| 461 | $parameters[] = urlencode($f)."=".(int)$_GET[$f]; |
| 462 | break; |
| 463 | |
| 464 | case incidents::FILTER_TYPE_STRING: |
| 465 | $select["selected"][$f] = $_GET[$f]; |
| 466 | $parameters[] = urlencode($f)."=".urlencode($_GET[$f]); |
| 467 | break; |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | foreach ($select["enabled"] as $enabled) { |
| 473 | if ($enabled) { |
| 474 | $select["isAnyEnabled"] = true; |
| 475 | break; |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | if (!$select["isAnyEnabled"] || (isset($_GET["forceQueue"]) && $_GET["forceQueue"] == "1")) $select["showPendingQueue"] = true; |
| 480 | |
| 481 | $select["pageUrlHasParameters"] = (count($parameters) > 0); |
| 482 | $select["pageUrl"] = "incidents.php".($select["pageUrlHasParameters"] ? "?".implode("&", $parameters) : ""); |
| 483 | $select["showResultsPaginated"] = !$select["enabled"]["states"]; |
| 484 | } |
| 485 | |
| 486 | public static function handleIncidentShortcuts() { |
| 487 | global $_GET; |
| 488 | if (isset($_GET["goTo"])) { |
| 489 | switch ($_GET["goTo"]) { |
| 490 | case "today": |
| 491 | security::go("incidents.php?page=".(int)incidents::todayPage()); |
| 492 | break; |
| 493 | } |
| 494 | } |
| 495 | } |
| 496 | } |