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