blob: 582ad466283ce1b7e909a6eb3520b20990fb40b6 [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::ADMIN);
23
24$mdHeaderRowMore = '<div class="mdl-layout-spacer"></div>
25<div class="mdl-textfield mdl-js-textfield mdl-textfield--expandable
26 mdl-textfield--floating-label mdl-textfield--align-right">
27 <label class="mdl-button mdl-js-button mdl-button--icon"
28 for="usuario">
29 <i class="material-icons">search</i>
30 </label>
31 <div class="mdl-textfield__expandable-holder">
32 <input class="mdl-textfield__input" type="text" name="usuario"
33 id="usuario">
34 </div>
35</div>';
36
37listings::buildSelect("users.php");
38
39$categories = categories::getAll();
40$companies = companies::getAll();
41?>
42<!DOCTYPE html>
43<html>
44<head>
45 <title><?php echo $conf["appName"]; ?></title>
46 <?php visual::includeHead(); ?>
47 <link rel="stylesheet" href="css/dashboard.css">
48
49 <style>
50 .adduser {
51 position: fixed;
52 bottom: 16px;
53 right: 16px;
54 }
55 .importcsv {
56 position:fixed;
57 bottom: 80px;
58 right: 25px;
59 }
60 .filter {
61 position:fixed;
62 bottom: 126px;
63 right: 25px;
64 }
65 .adduser, .importcsv, .filter {
66 z-index: 1000;
67 }
68
69 @media (max-width: 655px) {
70 .extra {
71 display: none;
72 }
73 }
74
75 /* Hide datable's search box */
76 .dataTables_wrapper .mdl-grid:first-child {
77 display: none;
78 }
79 .dt-table {
80 padding: 0!important;
81 }
82 .dt-table .mdl-cell {
83 margin: 0!important;
84 }
85 #usuario {
86 position: relative;
87 }
88 </style>
89</head>
90<?php visual::printBodyTag(); ?>
91 <div class="mdl-layout mdl-js-layout mdl-layout--fixed-header mdl-layout--fixed-drawer">
92 <?php visual::includeNav(); ?>
93 <button class="adduser mdl-button md-js-button mdl-button--fab mdl-js-ripple-effect mdl-button--accent"><i class="material-icons">person_add</i><span class="mdl-ripple"></span></button>
94 <button class="importcsv mdl-button mdl-js-button mdl-button--fab mdl-button--mini-fab mdl-color--grey-200"><i class="material-icons">file_upload</i></button>
95 <button class="filter mdl-button mdl-js-button mdl-button--fab mdl-button--mini-fab mdl-color--grey-200"><i class="material-icons">filter_list</i></button>
96 <main class="mdl-layout__content">
97 <div class="page-content">
98 <div class="main mdl-shadow--4dp">
99 <h2>Personas</h2>
100 <div class="overflow-wrapper overflow-wrapper--for-table">
101 <table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp datatable">
102 <thead>
103 <tr>
104 <?php
105 if ($conf["debug"]) {
106 ?>
107 <th class="extra">ID</th>
108 <?php
109 }
110 ?>
111 <th class="mdl-data-table__cell--non-numeric">Nombre</th>
112 <th class="mdl-data-table__cell--non-numeric">Categoría</th>
113 <th class="mdl-data-table__cell--non-numeric extra">Tipo</th>
114 <th class="mdl-data-table__cell--centered">Baja</th>
115 <th class="mdl-data-table__cell--non-numeric"></th>
116 </tr>
117 </thead>
118 <tbody>
119 <?php
120 $people = people::getAll($select);
121 foreach ($people as $p) {
122 ?>
123 <tr>
124 <?php
125 if ($conf["debug"]) {
126 ?>
127 <td class="extra"><?=(int)$p["id"]?></td>
128 <?php
129 }
130 ?>
131 <td class="mdl-data-table__cell--non-numeric"><?=security::htmlsafe($p["name"])?></td>
132 <td class="mdl-data-table__cell--non-numeric"><?=security::htmlsafe(($p["categoryid"] == -1 ? "-" : $p["category"]))?></td>
133 <td class="mdl-data-table__cell--non-numeric extra"><?=security::htmlsafe(security::$types[$p["type"]])?></td>
134 <td class="mdl-data-table__cell--centered"><?=($p["baixa"] == 1 ? visual::YES : "")?></td>
135 <td class='mdl-data-table__cell--non-numeric'>
136 <a href='dynamic/user.php?id=<?=(int)$p['id']?>' data-dyndialog-href='dynamic/user.php?id=<?=(int)$p['id']?>' title='Ver información completa'><i class='material-icons icon'>open_in_new</i></a>
137 <?php if (security::isAllowed($p['type'])) { ?>
138 <a href='dynamic/edituser.php?id=<?=(int)$p['id']?>' data-dyndialog-href='dynamic/edituser.php?id=<?=(int)$p['id']?>' title='Editar persona'><i class='material-icons icon'>edit</i></a>
139 <?php } ?>
140 <a href='dynamic/companyuser.php?id=<?=(int)$p['id']?>' data-dyndialog-href='dynamic/companyuser.php?id=<?=(int)$p['id']?>' title='Ver y añadir empresas a la persona'><i class='material-icons icon'>work</i></a>
141 <?php if (count($p['companies'])) { ?>
142 <a href='workerschedule.php?id=<?=(int)$p['id']?>' title='Ver y gestionar los horarios de la persona'><i class='material-icons icon'>timelapse</i></a>
143 <a href='userincidents.php?id=<?=(int)$p['id']?>' title='Ver y gestionar las incidencias del trabajador'><i class='material-icons icon'>assignment_late</i></a>
144 <a href='userregistry.php?id=<?=(int)$p['id']?>' title='Ver y gestionar los registros del trabajador'><i class='material-icons icon'>list</i></a>
145 <?php } ?>
146 </td>
147 </tr>
148 <?php
149 }
150 ?>
151 </tbody>
152 </table>
153 </div>
154
155 <?php visual::printDebug("people::getAll(\$select)", $people); ?>
156 <?php visual::printDebug("\$select", $select); ?>
157 </div>
158 </div>
159 </main>
160 </div>
161
162 <dialog class="mdl-dialog" id="adduser">
163 <form action="doadduser.php" method="POST" autocomplete="off">
164 <h4 class="mdl-dialog__title">Añade un trabajador</h4>
165 <div class="mdl-dialog__content">
166 <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
167 <input class="mdl-textfield__input" type="text" name="username" id="username" autocomplete="off" data-required>
168 <label class="mdl-textfield__label" for="username">Nombre de usuario</label>
169 </div>
170 <br>
171 <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
172 <input class="mdl-textfield__input" type="text" name="name" id="name" autocomplete="off" data-required>
173 <label class="mdl-textfield__label" for="name">Nombre</label>
174 </div>
175 <br>
176 <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
177 <input class="mdl-textfield__input" type="text" name="dni" id="dni" autocomplete="off">
178 <label class="mdl-textfield__label" for="dni">DNI (opcional)</label>
179 </div>
180 <br>
181 <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
182 <input class="mdl-textfield__input" type="email" name="email" id="email" autocomplete="off">
183 <label class="mdl-textfield__label" for="email">Correo electrónico (opcional)</label>
184 </div>
185 <br>
186 <div class="mdlext-selectfield mdlext-js-selectfield mdlext-selectfield--floating-label">
187 <select name="category" id="category" class="mdlext-selectfield__select">
188 <option value="-1"></option>
189 <?php
190 foreach ($categories as $id => $category) {
191 echo '<option value="'.(int)$id.'">'.security::htmlsafe($category).'</option>';
192 }
193 ?>
194 </select>
195 <label for="category" class="mdlext-selectfield__label">Categoría (opcional)</label>
196 </div>
197 <br>
198 <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
199 <input class="mdl-textfield__input" type="password" name="password" id="password" autocomplete="off" data-required>
200 <label class="mdl-textfield__label" for="password">Contraseña</label>
201 </div>
202 <p><?=security::htmlsafe(security::$passwordHelperText)?></p>
203 <div class="mdlext-selectfield mdlext-js-selectfield mdlext-selectfield--floating-label" data-required>
204 <select name="type" id="type" class="mdlext-selectfield__select">
205 <?php
206 foreach (security::$types as $i => $type) {
207 echo '<option value="'.(int)$i.'"'.(security::isAllowed($i) ? "" : " disabled").'>'.security::htmlsafe($type).'</option>';
208 }
209 ?>
210 </select>
211 <label for="type" class="mdlext-selectfield__label">Tipo</label>
212 </div>
213 </div>
214 <div class="mdl-dialog__actions">
215 <button type="submit" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--accent">Añadir</button>
216 <button onclick="event.preventDefault(); document.querySelector('#adduser').close();" class="mdl-button mdl-js-button mdl-js-ripple-effect cancel">Cancelar</button>
217 </div>
218 </form>
219 </dialog>
220
221 <dialog class="mdl-dialog" id="importcsv">
222 <form action="csvimport.php" method="POST" enctype="multipart/form-data">
223 <h4 class="mdl-dialog__title">Importar CSV</h4>
224 <div class="mdl-dialog__content">
225 <p>Selecciona debajo el archivo CSV:</p>
226 <p><input type="file" name="file" accept=".csv" required></p>
227 <p>El formato de la cabecera debe ser: <code><?=security::htmlsafe(implode(";", csv::$fields))?></code></p>
228 <p>En la columna <code>category</code>, introduce el ID de la categoría ya creada en el sistema (o <code>-1</code> si no quieres definir una categoría para esa persona), y en la columna <code>companies</code> introduce una lista separada por comas de los IDs de las empresas que quieres añadir a esa persona.</p>
229 </div>
230 <div class="mdl-dialog__actions">
231 <button type="submit" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--accent">Importar</button>
232 <button onclick="event.preventDefault(); document.querySelector('#importcsv').close();" class="mdl-button mdl-js-button mdl-js-ripple-effect cancel">Cancelar</button>
233 </div>
234 </form>
235 </dialog>
236
237 <?php listings::renderFilterDialog("users.php", $select); ?>
238
239 <?php
240 visual::smartSnackbar([
241 ["added", "Se ha añadido la persona correctamente."],
242 ["modified", "Se ha modificado la persona correctamente."],
243 ["empty", "Faltan datos por introducir en el formulario o el correo electrónico es incorrecto."],
244 ["unexpected", "Ha ocurrido un error inesperado. Inténtelo de nuevo en unos segundos."],
245 ["couldntupdatepassword", "Se ha actualizado la información pero no se ha podido actualizar la contraseña. Inténtelo de nuevo en unos segundos."],
246 ["weakpassword", security::$passwordHelperText],
247 ["disabledsecondfactor", "Se ha desactivado la verificación en dos pasos correctamente."]
248 ]);
249 ?>
250
251 <script src="js/users.js"></script>
252 <script src="node_modules/jquery/dist/jquery.min.js"></script>
253 <script src="node_modules/datatables/media/js/jquery.dataTables.min.js"></script>
254 <script src="lib/datatables/dataTables.material.min.js"></script>
255</body>
256</html>