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 | $p = people::get($_GET["id"]); |
| 29 | |
| 30 | if ($p === false) { |
| 31 | security::notFound(); |
| 32 | } |
| 33 | |
| 34 | $companies = companies::getAll(); |
| 35 | ?> |
| 36 | |
| 37 | <style> |
| 38 | .mdl-dialog__content { |
| 39 | color: rgba(0,0,0,.87)!important; |
| 40 | } |
| 41 | |
| 42 | #dynDialog { |
| 43 | max-width: 300px; |
| 44 | width: auto; |
| 45 | } |
| 46 | </style> |
| 47 | |
| 48 | <dynscript> |
| 49 | var person = <?=(int)$p["id"]?>; |
| 50 | |
| 51 | document.querySelectorAll("button[data-company-id]").forEach(btn => { |
| 52 | btn.addEventListener("click", e => { |
| 53 | var id = e.currentTarget.getAttribute("data-company-id"); |
| 54 | fetch("ajax/addpersontocompany.php", { |
| 55 | method: "post", |
| 56 | body: "person="+parseInt(person)+"&company="+parseInt(id), |
| 57 | headers: { |
| 58 | "Content-Type": "application/x-www-form-urlencoded" |
| 59 | } |
| 60 | }).then(response => { |
| 61 | response.text().then(text => console.log); |
| 62 | dynDialog.reload(); |
| 63 | }).catch(error => { |
| 64 | alert("Ha habido un error dando de alta a este trabajador de esta empresa: "+error); |
| 65 | }); |
| 66 | }); |
| 67 | }); |
| 68 | |
| 69 | document.querySelectorAll("button[data-worker-id]").forEach(btn => { |
| 70 | btn.addEventListener("click", e => { |
| 71 | var id = e.currentTarget.getAttribute("data-worker-id"); |
| 72 | dynDialog.load("dynamic/workhistory.php?id="+parseInt(id)); |
| 73 | }); |
| 74 | }); |
| 75 | </dynscript> |
| 76 | |
| 77 | <h4 class="mdl-dialog__title"><?=security::htmlsafe($p["name"])?></h4> |
| 78 | <div class="mdl-dialog__content"> |
Adrià Vilanova Martínez | 5af8651 | 2023-12-02 20:44:16 +0100 | [diff] [blame^] | 79 | <?php //do-not-add-license-header-here |
Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame] | 80 | $list = []; |
| 81 | $list["visible"] = ""; |
| 82 | $list["hidden"] = ""; |
| 83 | |
| 84 | $workers = workers::getPersonWorkers($p["id"]); |
| 85 | foreach ($workers as $w) { |
| 86 | $list[($w["hidden"] ? "hidden" : "visible")] .= '<li>'. |
| 87 | security::htmlsafe($companies[$w["company"]]).' |
| 88 | <button class="mdl-button mdl-js-button mdl-button--icon" title="Acceder al historial de altas y bajas" data-worker-id="'.(int)$w["id"].'"> |
| 89 | <i class="material-icons">history</i> |
| 90 | </button> |
| 91 | <br> |
| 92 | <span class="mdl-color-text--grey-600">'.($w["hidden"] ? "Dada de baja" : "Dada de alta").' el '.date("d/m/Y", $w["lastupdated"]).'</span></li>'; |
| 93 | } |
| 94 | ?> |
| 95 | <p><b>Dada de alta en:</b></p> |
| 96 | <?php |
| 97 | if (!empty($list["visible"])) { |
| 98 | echo "<ul>".$list["visible"]."</ul>"; |
| 99 | } |
| 100 | ?> |
| 101 | <p><b>Dada de baja en:</b></p> |
| 102 | <?php |
| 103 | if (!empty($list["hidden"])) { |
| 104 | echo "<ul>".$list["hidden"]."</ul>"; |
| 105 | } |
| 106 | ?> |
| 107 | <p><b>No dada de alta en:</b></p> |
| 108 | <ul> |
| 109 | <?php |
| 110 | foreach ($companies as $id => $name) { |
| 111 | if (in_array($id, $p["companies"])) continue; |
| 112 | ?> |
| 113 | <li><?=security::htmlsafe($name)?> <button class="mdl-button mdl-js-button mdl-button--icon mdl-color-text--green" title="Dar de alta en esta empresa" data-company-id="<?=(int)$id?>"><i class="material-icons">add</i></button></li> |
| 114 | <?php |
| 115 | } |
| 116 | ?> |
| 117 | </ul> |
| 118 | </div> |
| 119 | <div class="mdl-dialog__actions"> |
| 120 | <button data-dyndialog-close class="mdl-button mdl-js-button mdl-js-ripple-effect cancel">Cerrar</button> |
| 121 | </div> |