blob: f9bcbac05333f0a83d95f229d1860c96400c3e8a [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::isAllowed(security::ADMIN);
35$status = incidents::getStatus($incident);
36
37$cantedit = in_array($status, incidents::$cannotEditCommentsStates);
38
39if (!$isAdmin) incidents::checkIncidentIsFromPerson($incident["id"]);
40?>
41
42<dynscript>
43document.querySelectorAll(".deleteattachment").forEach(el => {
44 el.addEventListener("click", e => {
45 dynDialog.load("dynamic/deleteattachment.php?id="+el.getAttribute("data-id")+"&name="+el.getAttribute("data-name")<?=(isset($_GET["continue"]) ? '+"&continue='.security::htmlsafe(urlencode($_GET["continue"])).'"' : '')?>);
46 });
47});
48</dynscript>
49
50<style>
51#dynDialog {
52 max-width: 380px;
53 width: auto;
54}
55
56.addAttachmentForm {
57 display: flex;
58 align-items: center;
59}
60
61.addAttachmentForm input[type="file"] {
62 width: 100%;
63 height: min-content;
64}
65
66.addAttachmentForm button {
67 min-width: min-content;
68}
69
70.attachmentDescription {
71 margin-top: 16px;
72}
73
74.attachmentDescription code {
75 font-size: 12px;
76}
77</style>
78
79<h4 class="mdl-dialog__title">Archivos adjuntos</h4>
80<div class="mdl-dialog__content">
81 <?php
82 $attachments = incidents::getAttachmentsFromIncident($incident);
83
84 if ($attachments === false) {
85 echo "<p>Ha ocurrido un problema cargando los archivos adjuntos.</p>";
86 } elseif (!count($attachments)) {
87 echo "<p>No hay ningún archivo adjunto</p>";
88 } else {
89 echo '<ul class="mdl-list">';
90 foreach ($attachments as $attachment) {
91 $extension = files::getFileExtension($attachment);
92 $icon = files::$mimeTypesIcons[$extension] ?? "broken_image";
93 $title = files::$readableMimeTypes[$extension] ?? "Documento desconocido";
94 echo '<li class="mdl-list__item">
95 <span class="mdl-list__item-primary-content">
96 <i class="material-icons mdl-list__item-icon">'.security::htmlsafe($icon).'</i>
97 '.security::htmlsafe($title).'
98 </span>
99 <a href="incidentattachment.php?id='.(int)$incident["id"].'&name='.security::htmlsafe($attachment).'" target="_blank" class="mdl-list__item-secondar-action mdl-button mdl-js-button mdl-button--icon mdl-js-ripple-effect">
100 <i class="material-icons">open_in_new</i>
101 </a>'.
102 ($cantedit ? '' : '<button class="mdl-list__item-secondar-action mdl-button mdl-js-button mdl-button--icon mdl-js-ripple-effect deleteattachment" data-id="'.(int)$id.'" data-name="'.security::htmlsafe($attachment).'">
103 <i class="material-icons">delete</i>
104 </button>').'
105 </li>';
106 }
107 echo "</ul>";
108 }
109
110 if (!$cantedit) {
111 ?>
112 <h5>Añade un archivo adjunto</h5>
113 <form action="doaddincidentattachment.php" method="POST" enctype="multipart/form-data" class="addAttachmentForm">
114 <input type="hidden" name="id" value="<?=(int)$incident["id"]?>">
115 <?php visual::addContinueInput(); ?>
116 <input type="file" name="file" accept="<?=security::htmlsafe(files::getAcceptAttribute())?>" required>
117 <button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--raised">Subir</button>
118 </form>
119 <div class="attachmentDescription">Se aceptan archivos de hasta <?=security::htmlsafe(files::READABLE_MAX_SIZE)?> con los siguientes formatos: <code><?=security::htmlsafe(files::getAcceptAttribute(true))?></code></div>
120 <?php
121 }
122 ?>
123</div>
124<div class="mdl-dialog__actions">
125 <button data-dyndialog-close class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--accent">Cerrar</button>
126</div>