blob: 07f644ffcde98500798195ee74790997a0c5e06a [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(__DIR__."/../core.php");
22security::checkType(security::WORKER, security::METHOD_NOTFOUND);
23security::checkWorkerUIEnabled();
24
25if (!isset($_GET["id"])) {
26 security::notFound();
27}
28
29$id = (int)$_GET["id"];
30
31$incident = incidents::get($id, true);
32if ($incident === false) security::notFound();
33
34$isAdmin = security::isAdminView();
35$status = incidents::getStatus($incident);
36
37if (($isAdmin && in_array($status, incidents::$cannotEditStates)) || (!$isAdmin && !in_array($status, incidents::$workerCanEditStates))) security::notFound();
38if (!$isAdmin) incidents::checkIncidentIsFromPerson($incident["id"]);
39?>
40
41<dynscript>
42document.getElementById("edit_allday").addEventListener("change", e => {
43 var partialtime = document.getElementById("edit_partialtime");
44 if (e.target.checked) {
45 partialtime.classList.add("notvisible");
46 } else {
47 partialtime.classList.remove("notvisible");
48 }
49});
50</dynscript>
51
52<form action="doeditincident.php" method="POST" autocomplete="off">
53 <input type="hidden" name="id" value="<?=(int)$id?>">
54 <?php visual::addContinueInput(); ?>
55 <h4 class="mdl-dialog__title">Editar incidencia</h4>
56 <div class="mdl-dialog__content">
57 <div class="mdlext-selectfield mdlext-js-selectfield mdlext-selectfield--floating-label">
58 <select name="type" id="edit_type" class="mdlext-selectfield__select" data-required>
59 <option></option>
60 <?php
61 foreach (incidents::getTypesForm() as $i) {
62 echo '<option value="'.(int)$i["id"].'"'.($i["id"] == $incident["type"] ? " selected" : "").'>'.security::htmlsafe($i["name"]).'</option>';
63 }
64 ?>
65 </select>
66 <label for="edit_type" class="mdlext-selectfield__label">Tipo</label>
67 </div>
68
69 <h5>Afectación</h5>
70 <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
71 <input class="mdl-textfield__input" type="date" name="day" id="edit_day" autocomplete="off" value="<?=security::htmlsafe(date("Y-m-d", $incident["day"]))?>" data-required>
72 <label class="mdl-textfield__label always-focused" for="edit_day">Día</label>
73 </div>
74 <br>
75 <p>
76 <label class="mdl-switch mdl-js-switch mdl-js-ripple-effect" for="edit_allday">
77 <input type="checkbox" id="edit_allday" name="allday" value="1" class="mdl-switch__input"<?=($incident["allday"] ? " checked" : "")?>>
78 <span class="mdl-switch__label">Día entero</span>
79 </label>
80 </p>
81 <div id="edit_partialtime"<?=($incident["allday"] ? ' class="notvisible"' : '')?>>De <input type="time" name="begins"<?=($incident["allday"] ? '' : ' value="'.schedules::sec2time($incident["begins"]).'"')?>> a <input type="time" name="ends"<?=($incident["allday"] ? '' : ' value="'.schedules::sec2time($incident["ends"]).'"')?>></div>
82 </div>
83 <div class="mdl-dialog__actions">
84 <button type="submit" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--accent">Editar</button>
85 <button data-dyndialog-close class="mdl-button mdl-js-button mdl-js-ripple-effect cancel">Cancelar</button>
86 </div>
87</form>