blob: 0acfac3a44e606373ade03be112616308ef43183 [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001<?php
2require_once(__DIR__."/../core.php");
3security::checkType(security::ADMIN, security::METHOD_NOTFOUND);
4
5if (!isset($_GET["id"])) {
6 security::notFound();
7}
8
9$p = people::get($_GET["id"]);
10
11if ($p === false) {
12 security::notFound();
13}
14
15$companies = companies::getAll();
16?>
17
18<style>
19.mdl-dialog__content {
20 color: rgba(0,0,0,.87)!important;
21}
22
23#dynDialog {
24 max-width: 300px;
25 width: auto;
26}
27</style>
28
29<dynscript>
30var person = <?=(int)$p["id"]?>;
31
32document.querySelectorAll("button[data-company-id]").forEach(btn => {
33 btn.addEventListener("click", e => {
34 var id = e.currentTarget.getAttribute("data-company-id");
35 fetch("ajax/addpersontocompany.php", {
36 method: "post",
37 body: "person="+parseInt(person)+"&company="+parseInt(id),
38 headers: {
39 "Content-Type": "application/x-www-form-urlencoded"
40 }
41 }).then(response => {
42 response.text().then(text => console.log);
43 dynDialog.reload();
44 }).catch(error => {
45 alert("Ha habido un error dando de alta a este trabajador de esta empresa: "+error);
46 });
47 });
48});
49
50document.querySelectorAll("button[data-worker-id]").forEach(btn => {
51 btn.addEventListener("click", e => {
52 var id = e.currentTarget.getAttribute("data-worker-id");
53 dynDialog.load("dynamic/workhistory.php?id="+parseInt(id));
54 });
55});
56</dynscript>
57
58<h4 class="mdl-dialog__title"><?=security::htmlsafe($p["name"])?></h4>
59<div class="mdl-dialog__content">
60<?php
61$list = [];
62$list["visible"] = "";
63$list["hidden"] = "";
64
65$workers = workers::getPersonWorkers($p["id"]);
66foreach ($workers as $w) {
67 $list[($w["hidden"] ? "hidden" : "visible")] .= '<li>'.
68 security::htmlsafe($companies[$w["company"]]).'
69 <button class="mdl-button mdl-js-button mdl-button--icon" title="Acceder al historial de altas y bajas" data-worker-id="'.(int)$w["id"].'">
70 <i class="material-icons">history</i>
71 </button>
72 <br>
73 <span class="mdl-color-text--grey-600">'.($w["hidden"] ? "Dada de baja" : "Dada de alta").' el '.date("d/m/Y", $w["lastupdated"]).'</span></li>';
74}
75?>
76 <p><b>Dada de alta en:</b></p>
77 <?php
78 if (!empty($list["visible"])) {
79 echo "<ul>".$list["visible"]."</ul>";
80 }
81 ?>
82 <p><b>Dada de baja en:</b></p>
83 <?php
84 if (!empty($list["hidden"])) {
85 echo "<ul>".$list["hidden"]."</ul>";
86 }
87 ?>
88 <p><b>No dada de alta en:</b></p>
89 <ul>
90 <?php
91 foreach ($companies as $id => $name) {
92 if (in_array($id, $p["companies"])) continue;
93 ?>
94 <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>
95 <?php
96 }
97 ?>
98 </ul>
99</div>
100<div class="mdl-dialog__actions">
101 <button data-dyndialog-close class="mdl-button mdl-js-button mdl-js-ripple-effect cancel">Cerrar</button>
102</div>