blob: b3aa258e13feadfe1c2bdc757d6b5abd42ec96df [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001<?php
2class listings {
3 public static function renderFilterDialog($form, $select) {
4 global $_GET;
5 ?>
6 <dialog class="mdl-dialog" id="filter">
7 <form action="<?=$form?>" method="GET" enctype="multipart/form-data">
8 <h4 class="mdl-dialog__title">Filtrar lista</h4>
9 <div class="mdl-dialog__content">
10 <h5>Categorías</h5>
11 <label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="cat-1">
12 <input type="checkbox" id="cat-1" name="categories[-1]" class="mdl-checkbox__input" value="1"<?=(($select["enabled"]["categories"] && in_array(-1, $select["selected"]["categories"])) ? " checked" : "")?>>
13 <span class="mdl-checkbox__label">Sin categoría</span>
14 </label>
15 <?php
16 foreach (categories::getAll(false, false, true) as $c) {
17 $haschilds = (count($c["childs"]) > 0);
18 if ($haschilds) {
19 $subcategories_arr = [];
20 foreach ($c["childs"] as $child) {
21 $subcategories_arr[] = "&ldquo;".security::htmlsafe($child["name"])."&rdquo;";
22 }
23 $subcategories = implode(", ", $subcategories_arr);
24 }
25 ?>
26 <label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="cat<?=(int)$c["id"]?>">
27 <input type="checkbox" id="cat<?=(int)$c["id"]?>" name="categories[<?=(int)$c["id"]?>]" class="mdl-checkbox__input" value="1"<?=(($select["enabled"]["categories"] && in_array($c["id"], $select["selected"]["categories"])) ? " checked" : "")?>>
28 <span class="mdl-checkbox__label"><?=security::htmlsafe($c["name"])?> <?php if ($haschilds) { ?><i id="haschilds<?=(int)$c["id"]?>" class="material-icons help">info</i><?php } ?></span>
29 </label>
30 <?php
31 if ($haschilds) {
32 ?>
33 <div class="mdl-tooltip" for="haschilds<?=(int)$c["id"]?>">Esta categoría incluye la<?=(count($c["childs"]) == 1 ? "" : "s")?> subcategoría<?=(count($c["childs"]) == 1 ? "" : "s")?> <?=$subcategories?></div>
34 <?php
35 }
36 }
37 ?>
38 <h5>Empresas</h5>
39 <?php
40 foreach (companies::getAll() as $id => $company) {
41 ?>
42 <label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="comp<?=(int)$id?>">
43 <input type="checkbox" id="comp<?=(int)$id?>" name="companies[<?=(int)$id?>]" class="mdl-checkbox__input" value="1"<?=(($select["enabled"]["companies"] && in_array($id, $select["selected"]["companies"])) ? " checked" : "")?>>
44 <span class="mdl-checkbox__label"><?=security::htmlsafe($company)?></span>
45 </label>
46 <?php
47 }
48 ?>
49 <h5>Tipos de usuario</h5>
50 <?php
51 foreach (security::$types as $id => $type) {
52 ?>
53 <label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="type<?=(int)$id?>">
54 <input type="checkbox" id="type<?=(int)$id?>" name="types[<?=(int)$id?>]" class="mdl-checkbox__input" value="1"<?=(($select["enabled"]["types"] && in_array($id, $select["selected"]["types"])) ? " checked" : "")?>>
55 <span class="mdl-checkbox__label"><?=security::htmlsafe($type)?></span>
56 </label>
57 <?php
58 }
59
60 if ($form == "workers.php") {
61 echo "<h5>Horario actual</h5>";
62 foreach (schedules::$workerScheduleStatusShort as $id => $type) {
63 ?>
64 <label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="schedulesstatus<?=(int)$id?>">
65 <input type="checkbox" id="schedulesstatus<?=(int)$id?>" name="schedulesstatus[<?=(int)$id?>]" class="mdl-checkbox__input" value="1"<?=(isset($_GET["schedulesstatus"][(int)$id]) ? " checked" : "")?>>
66 <span class="mdl-checkbox__label mdl-color-text--<?=security::htmlsafe(schedules::$workerScheduleStatusColors[$id])?>"><?=security::htmlsafe($type)?></span>
67 </label>
68 <?php
69 }
70 }
71 ?>
72 </div>
73 <div class="mdl-dialog__actions">
74 <button type="submit" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--accent">Filtrar</button>
75 <button onclick="event.preventDefault(); document.querySelector('#filter').close();" class="mdl-button mdl-js-button mdl-js-ripple-effect cancel">Cancelar</button>
76 </div>
77 </form>
78 </dialog>
79 <?php
80 }
81
82 public static function buildSelect($form) {
83 global $select, $selectedSchedulesStatus, $_GET;
84
85 $select = array("enabled" => [], "selected" => []);
86
87 foreach (people::$filters as $f) {
88 $select["enabled"][$f] = isset($_GET[$f]);
89 if ($select["enabled"][$f]) {
90 $select["selected"][$f] = (isset($_GET[$f]) ? array_keys($_GET[$f]) : []);
91 }
92 }
93
94 if ($form == "workers.php") {
95 if (isset($_GET["schedulesstatus"]) && is_array($_GET["schedulesstatus"]) && count($_GET["schedulesstatus"])) {
96 $selectedSchedulesStatus = array_keys($_GET["schedulesstatus"]);
97 } else {
98 $selectedSchedulesStatus = false;
99 }
100 }
101 }
102}