blob: 5cfef9279ba7acaedef835e7d73fc5b77b179aba [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001<?php
Adrià Vilanova Martínez5af86512023-12-02 20:44:16 +01002/*
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 botbe50d492023-11-30 00:16:42 +010021require_once("core.php");
22security::checkType(security::WORKER);
23security::checkWorkerUIEnabled();
24
25$isAdmin = security::isAllowed(security::ADMIN);
26
27if (!security::checkParams("GET", [
28 ["id", security::PARAM_ISINT]
29])) {
30 security::go((security::isAdminView() ? "workers.php" : "workerhome.php"));
31}
32
33$id = (int)$_GET["id"];
34
35if (!$isAdmin && people::userData("id") != $id) {
36 security::notFound();
37}
38
39$p = people::get($id);
40
41if ($p === false) {
42 security::go((security::isAdminView() ? "workers.php" : "workerhome.php"));
43}
44
45$workers = workers::getPersonWorkers((int)$p["id"]);
46$companies = companies::getAll();
47
48if ($workers === false || $companies === false) {
49 security::go((security::isAdminView() ? "workers.php" : "workerhome.php")."?msg=unexpected");
50}
51
52if (security::isAdminView()) $mdHeaderRowBefore = visual::backBtn("workers.php");
53?>
54<!DOCTYPE html>
55<html>
56<head>
57 <title><?php echo $conf["appName"]; ?></title>
58 <?php visual::includeHead(); ?>
59 <link rel="stylesheet" href="css/dashboard.css">
60 <link rel="stylesheet" href="css/incidents.css">
61
62 <style>
63 .addincident, .addrecurringincident {
64 z-index: 1000;
65 }
66
67 .addincident {
68 position: fixed;
69 bottom: 16px;
70 right: 16px;
71 }
72 <?php
73 if (security::isAdminView()) {
74 ?>
75 .addrecurringincident {
76 position: fixed;
77 bottom: 80px;
78 right: 25px;
79 }
80 <?php
81 }
82 ?>
83 </style>
84</head>
85<?php visual::printBodyTag(); ?>
86 <div class="mdl-layout mdl-js-layout mdl-layout--fixed-header mdl-layout--fixed-drawer">
87 <?php
88 visual::includeNav();
89 if (security::isAdminView()) {
90 ?>
91 <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>
92 <?php
93 }
94 ?>
95 <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>
96 <main class="mdl-layout__content">
97 <div class="page-content">
98 <div class="main mdl-shadow--4dp">
99 <?php
100 $title = "Incidencias".(security::isAdminView() ? " de &ldquo;".security::htmlsafe($p["name"])."&rdquo;" : "");
101 ?>
102 <h2><?=$title?></h2>
103
104 <?php
105 if (count($workers)) {
106 foreach ($workers as $w) {
107 $incidents = incidents::getAll(false, 0, 0, (int)$w["id"]);
108
109 echo "<h4>".security::htmlsafe($companies[$w["company"]]).($w["hidden"] == 1 ? " <span class='mdl-color-text--grey-600'>(dada de baja)</span>" : "")."</h4>";
110
111 if (count($incidents)) {
112 incidentsView::renderIncidents($incidents, $companies, true, false, !security::isAdminView(), false, false, "userincidents.php?id=".(int)$p["id"]);
113 } else {
114 echo "<p>Todavía no existe ninguna incidencia ".(security::isAdminView() ? "para este trabajador " : "")."en esta empresa.</p>";
115 }
116
117 visual::printDebug("incidents::getAll(false, 0, 0, ".(int)$w["id"].")", $incidents);
118 }
119 } else {
120 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>";
121 }
122 ?>
123 </div>
124 </div>
125 </main>
126 </div>
127
128 <?php
129 incidentsView::renderIncidentForm($workers, function(&$worker) {
130 return (int)$worker["id"];
131 }, function (&$worker, &$companies) {
132 return $worker["name"].' ('.$companies[$worker["company"]].')';
133 }, $companies, !$isAdmin, false, "userincidents.php?id=".(int)$p["id"]);
134
135 if (security::isAdminView()) {
136 incidentsView::renderIncidentForm($workers, function(&$worker) {
137 return (int)$worker["id"];
138 }, function (&$worker, &$companies) {
139 return $worker["name"].' ('.$companies[$worker["company"]].')';
140 }, $companies, false, true, "userincidents.php?id=".(int)$p["id"]);
141 ?>
142 <script>
143 window.addEventListener("load", function() {
144 document.querySelector(".addrecurringincident").addEventListener("click", function() {
145 document.querySelector("#addrecurringincident").showModal();
146 /* Or dialog.show(); to show the dialog without a backdrop. */
147 });
148 });
149 </script>
150 <?php
151 }
152
153 visual::renderTooltips();
154
155 visual::smartSnackbar(incidentsView::$incidentsMsgs);
156 ?>
157
158 <script src="js/userincidents.js"></script>
159 <script src="js/incidentsgeneric.js"></script>
160</body>
161</html>