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 listings { |
| 22 | public static function renderFilterDialog($form, $select) { |
| 23 | global $_GET; |
| 24 | ?> |
| 25 | <dialog class="mdl-dialog" id="filter"> |
| 26 | <form action="<?=$form?>" method="GET" enctype="multipart/form-data"> |
| 27 | <h4 class="mdl-dialog__title">Filtrar lista</h4> |
| 28 | <div class="mdl-dialog__content"> |
| 29 | <h5>Categorías</h5> |
| 30 | <label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="cat-1"> |
| 31 | <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" : "")?>> |
| 32 | <span class="mdl-checkbox__label">Sin categoría</span> |
| 33 | </label> |
| 34 | <?php |
| 35 | foreach (categories::getAll(false, false, true) as $c) { |
| 36 | $haschilds = (count($c["childs"]) > 0); |
| 37 | if ($haschilds) { |
| 38 | $subcategories_arr = []; |
| 39 | foreach ($c["childs"] as $child) { |
| 40 | $subcategories_arr[] = "“".security::htmlsafe($child["name"])."”"; |
| 41 | } |
| 42 | $subcategories = implode(", ", $subcategories_arr); |
| 43 | } |
| 44 | ?> |
| 45 | <label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="cat<?=(int)$c["id"]?>"> |
| 46 | <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" : "")?>> |
| 47 | <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> |
| 48 | </label> |
| 49 | <?php |
| 50 | if ($haschilds) { |
| 51 | ?> |
| 52 | <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> |
| 53 | <?php |
| 54 | } |
| 55 | } |
| 56 | ?> |
| 57 | <h5>Empresas</h5> |
| 58 | <?php |
| 59 | foreach (companies::getAll() as $id => $company) { |
| 60 | ?> |
| 61 | <label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="comp<?=(int)$id?>"> |
| 62 | <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" : "")?>> |
| 63 | <span class="mdl-checkbox__label"><?=security::htmlsafe($company)?></span> |
| 64 | </label> |
| 65 | <?php |
| 66 | } |
| 67 | ?> |
| 68 | <h5>Tipos de usuario</h5> |
| 69 | <?php |
| 70 | foreach (security::$types as $id => $type) { |
| 71 | ?> |
| 72 | <label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="type<?=(int)$id?>"> |
| 73 | <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" : "")?>> |
| 74 | <span class="mdl-checkbox__label"><?=security::htmlsafe($type)?></span> |
| 75 | </label> |
| 76 | <?php |
| 77 | } |
| 78 | |
| 79 | if ($form == "workers.php") { |
| 80 | echo "<h5>Horario actual</h5>"; |
| 81 | foreach (schedules::$workerScheduleStatusShort as $id => $type) { |
| 82 | ?> |
| 83 | <label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="schedulesstatus<?=(int)$id?>"> |
| 84 | <input type="checkbox" id="schedulesstatus<?=(int)$id?>" name="schedulesstatus[<?=(int)$id?>]" class="mdl-checkbox__input" value="1"<?=(isset($_GET["schedulesstatus"][(int)$id]) ? " checked" : "")?>> |
| 85 | <span class="mdl-checkbox__label mdl-color-text--<?=security::htmlsafe(schedules::$workerScheduleStatusColors[$id])?>"><?=security::htmlsafe($type)?></span> |
| 86 | </label> |
| 87 | <?php |
| 88 | } |
| 89 | } |
| 90 | ?> |
| 91 | </div> |
| 92 | <div class="mdl-dialog__actions"> |
| 93 | <button type="submit" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--accent">Filtrar</button> |
| 94 | <button onclick="event.preventDefault(); document.querySelector('#filter').close();" class="mdl-button mdl-js-button mdl-js-ripple-effect cancel">Cancelar</button> |
| 95 | </div> |
| 96 | </form> |
| 97 | </dialog> |
| 98 | <?php |
| 99 | } |
| 100 | |
| 101 | public static function buildSelect($form) { |
| 102 | global $select, $selectedSchedulesStatus, $_GET; |
| 103 | |
| 104 | $select = array("enabled" => [], "selected" => []); |
| 105 | |
| 106 | foreach (people::$filters as $f) { |
| 107 | $select["enabled"][$f] = isset($_GET[$f]); |
| 108 | if ($select["enabled"][$f]) { |
| 109 | $select["selected"][$f] = (isset($_GET[$f]) ? array_keys($_GET[$f]) : []); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | if ($form == "workers.php") { |
| 114 | if (isset($_GET["schedulesstatus"]) && is_array($_GET["schedulesstatus"]) && count($_GET["schedulesstatus"])) { |
| 115 | $selectedSchedulesStatus = array_keys($_GET["schedulesstatus"]); |
| 116 | } else { |
| 117 | $selectedSchedulesStatus = false; |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | } |