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