blob: 365db3f183249f3b4cd5bb6f43b5b5ce0c469cb6 [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
27$id = $_GET["id"] ?? people::userData("id");
28$id = (int)$id;
29
30if (!$isAdmin && people::userData("id") != $id) {
31 security::notFound();
32}
33
34$p = people::get($id);
35
36if ($p === false) {
37 security::go((security::isAdminView() ? "workers.php" : "workerhome.php"));
38}
39
40if (security::isAdminView()) $mdHeaderRowBefore = visual::backBtn("workers.php");
41
42$plaintext = isset($_GET["plaintext"]) && $_GET["plaintext"] == "1";
43$companies = companies::getAll();
44?>
45<!DOCTYPE html>
46<html>
47<head>
48 <title><?php echo $conf["appName"]; ?></title>
49 <?php visual::includeHead(); ?>
50 <link rel="stylesheet" href="css/dashboard.css">
51 <link rel="stylesheet" href="css/schedule.css">
52</head>
53<?php visual::printBodyTag(); ?>
54 <div class="mdl-layout mdl-js-layout mdl-layout--fixed-header mdl-layout--fixed-drawer">
55 <?php visual::includeNav(); ?>
56 <main class="mdl-layout__content">
57 <div class="page-content">
58 <div class="main mdl-shadow--4dp">
59 <div class="actions">
60 <?php
61 if (!security::isAdminView()) {
62 ?>
63 <a href="workercalendar.php" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect"><i class="material-icons">today</i> Calendario laboral</a>
64 <?php
65 }
66 ?>
67 <a href="userschedule.php?id=<?=(int)$id?>" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect"><i class="material-icons">timelapse</i> <?=(security::isAdminView() ? "Administrar los horarios" : "Todos los horarios")?></a>
68 </div>
69
70 <h2>Horario actual<?=(security::isAdminView() ? " de &ldquo;".security::htmlsafe($p["name"])."&rdquo;" : "")?></h2>
71
72 <?php
73 $schedules = schedules::getCurrent($id);
74
75 if (!count($schedules)) {
76 echo "<p>Actualmente no tienes asignado ningún horario.</p>";
77 } else {
78 foreach ($schedules as $i => $schedule) {
79 $worker = workers::get($schedule["worker"]);
80
81 if (security::isAdminView()) {
82 ?>
83 <a href="schedule.php?id=<?=(int)$schedule["id"]?>" class="mdl-button mdl-js-button mdl-button--icon mdl-js-ripple-effect" style="float: right;"><i class="material-icons">edit</i><span class="mdl-ripple"></span></a>
84 <?php
85 }
86 ?>
87 <p>
88 <b>Empresa:</b> <?=$companies[$worker["company"]]?><br>
89 <b>Validez:</b> del <?=security::htmlsafe(date("d/m/Y", $schedule["begins"]))?> al <?=security::htmlsafe(date("d/m/Y", $schedule["ends"]))?>
90 </p>
91 <?php
92 if ($plaintext) {
93 $flag = false;
94 foreach ($schedule["days"] as $typeday) {
95 schedulesView::renderPlainSchedule($typeday, false, null, null, $flag);
96 }
97
98 if (!$flag) {
99 echo "<p>Tu horario todavía no está configurado.</p>";
100 }
101 } else {
102 foreach (calendars::$types as $tdid => $type) {
103 if ($tdid == calendars::TYPE_FESTIU) continue;
104
105 $tdisset = isset($schedule["days"][$tdid]);
106
107 echo "<h4>".security::htmlsafe(calendars::$types[$tdid])."</h4>";
108
109 if ($tdisset) {
110 schedulesView::renderSchedule($schedule["days"][$tdid], false, null, null);
111 } else {
112 echo "<p>Todavía no hay configurado ningún horario en días del tipo \"".security::htmlsafe(calendars::$types[$tdid])."\".</p>";
113 }
114 }
115 }
116
117 if ($i + 1 != count($schedules)) echo "<hr>";
118 }
119 }
120 ?>
121
122 <?php visual::printDebug("schedules::getCurrent()", $schedules); ?>
123 </div>
124 </div>
125 </main>
126 </div>
127
128 <?php
129 visual::smartSnackbar([
130 ["unexpected", "Ha ocurrido un error inesperado. Inténtelo de nuevo en unos segundos."]
131 ]);
132 ?>
133</body>
134</html>