blob: a3eebe5a40bd180ec8c063458bc80ecc78fd4412 [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" : "workerschedule.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" : "workerschedule.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?msg=unexpected" : "workerschedule.php?msg=unexpected"));
31}
32
33$mdHeaderRowBefore = visual::backBtn("workerschedule.php".(security::isAdminView() ? "?id=".$id : ""));
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 <?php
42 if (security::isAdminView()) {
43 ?>
44 <style>
45 .addschedule {
46 position: fixed;
47 bottom: 16px;
48 right: 16px;
49 z-index: 1000;
50 }
51 </style>
52 <?php
53 }
54 ?>
55</head>
56<?php visual::printBodyTag(); ?>
57 <div class="mdl-layout mdl-js-layout mdl-layout--fixed-header mdl-layout--fixed-drawer">
58 <?php
59 visual::includeNav();
60
61 if (security::isAdminView()) {
62 ?>
63 <button class="addschedule 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>
64 <?php
65 }
66 ?>
67 <main class="mdl-layout__content">
68 <div class="page-content">
69 <div class="main mdl-shadow--4dp">
70 <?php $title = (security::isAdminView() ? "Horarios de &ldquo;".security::htmlsafe($p["name"])."&rdquo;" : "Todos los horarios"); ?>
71 <h2><?=$title?></h2>
72
73 <?php
74 if (count($workers)) {
75 foreach ($workers as $w) {
76 $schedules = schedules::getAll((int)$w["id"], security::isAdminView());
77
78 echo "<h4>".security::htmlsafe($companies[$w["company"]])."</h4>";
79
80 if (count($schedules)) {
81 foreach ($schedules as $s) {
82 ?>
83 <a href="schedule.php?id=<?=(int)$s["id"]?>" class="clicky-container">
84 <div class="clicky mdl-js-ripple-effect">
85 <div class="text">
86 <span class="title"><?=security::htmlsafe(date("d/m/Y", $s["begins"]))?> - <?=security::htmlsafe(date("d/m/Y", $s["ends"]))?></span><br>
87 <span class="description">Activo: <?=($s["active"] == 1 ? visual::YES : visual::NO)?></span>
88 </div>
89 <div class="mdl-ripple"></div>
90 </div>
91 </a>
92 <?php
93 }
94 } else {
95 echo "<p>".(security::isAdminView() ? "Todavía no se ha definido ningún horario para este trabajador en esta empresa" : "Todavía no se ha definido ningún horario para esta empresa.")."</p>";
96 }
97
98 visual::printDebug("schedules::getAll(".(int)$w["id"].")", $schedules);
99 }
100 } else {
101 echo "<p>".(security::isAdminView() ? "Antes de poder definir horarios para este trabajador deberías darlo de alta en alguna empresa." : "Todavía no se te ha definido ningún horario.")."</p>";
102 }
103 ?>
104 </div>
105 </div>
106 </main>
107 </div>
108
109 <?php
110 if (security::isAdminView()) {
111 ?>
112 <dialog class="mdl-dialog" id="addschedule">
113 <form action="doaddschedule.php" method="POST" autocomplete="off">
114 <h4 class="mdl-dialog__title">Crea un nuevo horario semanal</h4>
115 <div class="mdl-dialog__content">
116 <div class="mdlext-selectfield mdlext-js-selectfield mdlext-selectfield--floating-label">
117 <select name="worker" id="worker" class="mdlext-selectfield__select" data-required>
118 <?php
119 foreach ($workers as $w) {
120 echo '<option value="'.(int)$w["id"].'">'.security::htmlsafe($companies[$w["company"]]).'</option>';
121 }
122 ?>
123 </select>
124 <label for="worker" class="mdlext-selectfield__label">Empresa</label>
125 </div>
126 <br>
127 <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
128 <input class="mdl-textfield__input" type="date" name="begins" id="begins" autocomplete="off" data-required>
129 <label class="mdl-textfield__label always-focused" for="begins">Fecha inicio de validez</label>
130 </div>
131 <br>
132 <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
133 <input class="mdl-textfield__input" type="date" name="ends" id="ends" autocomplete="off" data-required>
134 <label class="mdl-textfield__label always-focused" for="ends">Fecha fin de validez</label>
135 </div>
136 </div>
137 <div class="mdl-dialog__actions">
138 <button type="submit" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--accent">Crear</button>
139 <button onclick="event.preventDefault(); document.querySelector('#addschedule').close();" class="mdl-button mdl-js-button mdl-js-ripple-effect cancel">Cancelar</button>
140 </div>
141 </form>
142 </dialog>
143 <?php
144 }
145 ?>
146
147 <?php
148 visual::smartSnackbar([
149 ["deleted", "Se ha eliminado el horario semanal correctamente."],
150 ["empty", "Faltan datos por introducir en el formulario."],
151 ["unexpected", "Ha ocurrido un error inesperado. Inténtelo de nuevo en unos segundos."],
152 ["overlaps", "El horario que intentabas añadir se solapa con otro."],
153 ["order", "La fecha de inicio debe ser anterior a la fecha de fin."]
154 ]);
155 ?>
156
157 <?php if (security::isAdminView()) { ?><script src="js/userschedule.js"></script><?php } ?>
158</body>
159</html>