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 | require_once(__DIR__."/../core.php"); |
| 22 | security::checkType(security::ADMIN, security::METHOD_NOTFOUND); |
| 23 | |
| 24 | if (!isset($_GET["id"])) { |
| 25 | security::notFound(); |
| 26 | } |
| 27 | |
| 28 | $id = (int)$_GET["id"]; |
| 29 | |
| 30 | $worker = workers::get($id); |
| 31 | if ($worker === false) security::notFound(); |
| 32 | ?> |
| 33 | |
| 34 | <dynscript> |
| 35 | document.getElementById("additem").addEventListener("click", e => { |
| 36 | dynDialog.load("dynamic/addworkhistoryitem.php?id="+parseInt(document.getElementById("additem").getAttribute("worker-id"))); |
| 37 | }); |
| 38 | |
| 39 | document.querySelectorAll(".edititem").forEach(el => { |
| 40 | el.addEventListener("click", e => { |
| 41 | dynDialog.load("dynamic/editworkhistoryitem.php?id="+parseInt(el.getAttribute("data-id"))); |
| 42 | }); |
| 43 | }); |
| 44 | |
| 45 | document.querySelectorAll(".deleteitem").forEach(el => { |
| 46 | el.addEventListener("click", e => { |
| 47 | dynDialog.load("dynamic/deleteworkhistoryitem.php?id="+parseInt(el.getAttribute("data-id"))); |
| 48 | }); |
| 49 | }); |
| 50 | </dynscript> |
| 51 | |
| 52 | <style> |
| 53 | #dynDialog { |
| 54 | max-width: 380px; |
| 55 | width: auto; |
| 56 | } |
| 57 | |
| 58 | #dynDialog .mdl-list { |
| 59 | margin-top: 0; |
| 60 | padding-top: 0; |
| 61 | } |
| 62 | |
| 63 | .float-right { |
| 64 | float: right; |
| 65 | } |
| 66 | </style> |
| 67 | |
| 68 | <h4 class="mdl-dialog__title">Historial de altas y bajas</h4> |
| 69 | <div class="mdl-dialog__content"> |
| 70 | <p><b>Persona:</b> <?=security::htmlsafe($worker["name"])?><br> |
| 71 | <b>Empresa:</b> <?=security::htmlsafe($worker["companyname"])?></p> |
| 72 | |
| 73 | <div class="float-right"><button id="additem" class="mdl-button mdl-js-button mdl-js-ripple-effect" worker-id="<?=(int)$worker["id"]?>"><i class="material-icons">add</i> Añadir alta/baja</button></div> |
| 74 | <div style="clear: both;"></div> |
| 75 | |
| 76 | <?php |
| 77 | $items = workers::getWorkHistory($id); |
| 78 | |
| 79 | if ($items === false) { |
| 80 | echo "<p>Ha ocurrido un problema cargando los elementos del historial.</p>"; |
| 81 | } elseif (!count($items)) { |
| 82 | echo "<p>No hay ningún elmento en el historial, así que el aplicativo está considerando que el trabajador está de baja.</p>"; |
| 83 | } else { |
| 84 | echo '<ul class="mdl-list">'; |
| 85 | foreach ($items as $item) { |
| 86 | $icon = security::htmlsafe(workers::affiliationStatusIcon($item["status"]) ?? "indeterminate_check_box"); |
| 87 | $helper = workers::affiliationStatusHelper($item["status"]); |
| 88 | $day = date("d/m/Y", $item["day"]); |
| 89 | $isAutomatic = workers::isAutomaticAffiliation($item["status"]); |
| 90 | echo '<li class="mdl-list__item '.($isAutomatic ? 'mdl-list__item--two-line' : '').'"> |
| 91 | <span class="mdl-list__item-primary-content"> |
| 92 | <i class="material-icons mdl-list__item-icon">'.security::htmlsafe($icon).'</i> |
| 93 | <span>'.security::htmlsafe($helper).' ('.security::htmlsafe($day).')</span> |
| 94 | '.($isAutomatic ? '<span class="mdl-list__item-sub-title">Registro automático</span>' : '').' |
| 95 | </span> |
| 96 | <button class="mdl-list__item-secondar-action mdl-button mdl-js-button mdl-button--icon mdl-js-ripple-effect edititem" data-id="'.(int)$item["id"].'"> |
| 97 | <i class="material-icons">edit</i> |
| 98 | </button> |
| 99 | <button class="mdl-list__item-secondar-action mdl-button mdl-js-button mdl-button--icon mdl-js-ripple-effect deleteitem" data-id="'.(int)$item["id"].'"> |
| 100 | <i class="material-icons">delete</i> |
| 101 | </button> |
| 102 | </li>'; |
| 103 | } |
| 104 | echo "</ul>"; |
| 105 | } |
| 106 | ?> |
| 107 | </div> |
| 108 | <div class="mdl-dialog__actions"> |
| 109 | <button data-dyndialog-close class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--accent">Cerrar</button> |
| 110 | </div> |