blob: e46ee88ec7db27644ceda5e8f2d5c867ecb25339 [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001<?php
2require_once("core.php");
3security::checkType(security::WORKER);
4security::checkWorkerUIEnabled();
5
6$isAdmin = security::isAllowed(security::ADMIN);
7
8if (!security::checkParams("GET", [
9 ["id", security::PARAM_ISINT]
10])) {
11 security::go((security::isAdminView() ? "workers.php" : "workerhome.php"));
12}
13
14$id = (int)$_GET["id"];
15
16if (!$isAdmin && people::userData("id") != $id) {
17 security::notFound();
18}
19
20$p = people::get($id);
21
22if ($p === false) {
23 security::go((security::isAdminView() ? "workers.php" : "workerhome.php"));
24}
25
26$workers = workers::getPersonWorkers((int)$p["id"]);
27$companies = companies::getAll();
28
29if ($workers === false || $companies === false) {
30 security::go((security::isAdminView() ? "workers.php" : "workerhome.php")."?msg=unexpected");
31}
32
33if (security::isAdminView()) $mdHeaderRowBefore = visual::backBtn("workers.php");
34?>
35<!DOCTYPE html>
36<html>
37<head>
38 <title><?php echo $conf["appName"]; ?></title>
39 <?php visual::includeHead(); ?>
40 <link rel="stylesheet" href="css/dashboard.css">
41 <link rel="stylesheet" href="css/incidents.css">
42
43 <style>
44 .addincident, .addrecurringincident {
45 z-index: 1000;
46 }
47
48 .addincident {
49 position: fixed;
50 bottom: 16px;
51 right: 16px;
52 }
53 <?php
54 if (security::isAdminView()) {
55 ?>
56 .addrecurringincident {
57 position: fixed;
58 bottom: 80px;
59 right: 25px;
60 }
61 <?php
62 }
63 ?>
64 </style>
65</head>
66<?php visual::printBodyTag(); ?>
67 <div class="mdl-layout mdl-js-layout mdl-layout--fixed-header mdl-layout--fixed-drawer">
68 <?php
69 visual::includeNav();
70 if (security::isAdminView()) {
71 ?>
72 <button class="addrecurringincident mdl-button mdl-js-button mdl-button--fab mdl-button--mini-fab mdl-color--grey-200"><i class="material-icons">repeat</i><span class="mdl-ripple"></span></button>
73 <?php
74 }
75 ?>
76 <button class="addincident mdl-button md-js-button mdl-button--fab mdl-js-ripple-effect mdl-button--accent"><i class="material-icons">add</i><span class="mdl-ripple"></span></button>
77 <main class="mdl-layout__content">
78 <div class="page-content">
79 <div class="main mdl-shadow--4dp">
80 <?php
81 $title = "Incidencias".(security::isAdminView() ? " de &ldquo;".security::htmlsafe($p["name"])."&rdquo;" : "");
82 ?>
83 <h2><?=$title?></h2>
84
85 <?php
86 if (count($workers)) {
87 foreach ($workers as $w) {
88 $incidents = incidents::getAll(false, 0, 0, (int)$w["id"]);
89
90 echo "<h4>".security::htmlsafe($companies[$w["company"]]).($w["hidden"] == 1 ? " <span class='mdl-color-text--grey-600'>(dada de baja)</span>" : "")."</h4>";
91
92 if (count($incidents)) {
93 incidentsView::renderIncidents($incidents, $companies, true, false, !security::isAdminView(), false, false, "userincidents.php?id=".(int)$p["id"]);
94 } else {
95 echo "<p>Todavía no existe ninguna incidencia ".(security::isAdminView() ? "para este trabajador " : "")."en esta empresa.</p>";
96 }
97
98 visual::printDebug("incidents::getAll(false, 0, 0, ".(int)$w["id"].")", $incidents);
99 }
100 } else {
101 echo "<p>".(security::isAdminView() ? "Antes de poder visualizar y añadir incidencias a este trabajador deberías darlo de alta en alguna empresa." : "No puedes visualizar ni añadir incidencias porque todavía no se te ha asignado ninguna empresa.")."</p>";
102 }
103 ?>
104 </div>
105 </div>
106 </main>
107 </div>
108
109 <?php
110 incidentsView::renderIncidentForm($workers, function(&$worker) {
111 return (int)$worker["id"];
112 }, function (&$worker, &$companies) {
113 return $worker["name"].' ('.$companies[$worker["company"]].')';
114 }, $companies, !$isAdmin, false, "userincidents.php?id=".(int)$p["id"]);
115
116 if (security::isAdminView()) {
117 incidentsView::renderIncidentForm($workers, function(&$worker) {
118 return (int)$worker["id"];
119 }, function (&$worker, &$companies) {
120 return $worker["name"].' ('.$companies[$worker["company"]].')';
121 }, $companies, false, true, "userincidents.php?id=".(int)$p["id"]);
122 ?>
123 <script>
124 window.addEventListener("load", function() {
125 document.querySelector(".addrecurringincident").addEventListener("click", function() {
126 document.querySelector("#addrecurringincident").showModal();
127 /* Or dialog.show(); to show the dialog without a backdrop. */
128 });
129 });
130 </script>
131 <?php
132 }
133
134 visual::renderTooltips();
135
136 visual::smartSnackbar(incidentsView::$incidentsMsgs);
137 ?>
138
139 <script src="js/userincidents.js"></script>
140 <script src="js/incidentsgeneric.js"></script>
141</body>
142</html>