blob: 2402688c29f13293e91531847e849e9da851ecc5 [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001<?php
2require_once(__DIR__."/../core.php");
3security::checkType(security::WORKER, security::METHOD_NOTFOUND);
4security::checkWorkerUIEnabled();
5
6if (!isset($_GET["id"])) {
7 security::notFound();
8}
9
10$id = (int)$_GET["id"];
11
12$incident = incidents::get($id, true);
13if ($incident === false) security::notFound();
14
15$isAdmin = security::isAllowed(security::ADMIN);
16$status = incidents::getStatus($incident);
17
18$cantedit = in_array($status, incidents::$cannotEditCommentsStates);
19
20if (!$isAdmin) incidents::checkIncidentIsFromPerson($incident["id"]);
21?>
22
23<dynscript>
24document.querySelectorAll(".deleteattachment").forEach(el => {
25 el.addEventListener("click", e => {
26 dynDialog.load("dynamic/deleteattachment.php?id="+el.getAttribute("data-id")+"&name="+el.getAttribute("data-name")<?=(isset($_GET["continue"]) ? '+"&continue='.security::htmlsafe(urlencode($_GET["continue"])).'"' : '')?>);
27 });
28});
29</dynscript>
30
31<style>
32#dynDialog {
33 max-width: 380px;
34 width: auto;
35}
36
37.addAttachmentForm {
38 display: flex;
39 align-items: center;
40}
41
42.addAttachmentForm input[type="file"] {
43 width: 100%;
44 height: min-content;
45}
46
47.addAttachmentForm button {
48 min-width: min-content;
49}
50
51.attachmentDescription {
52 margin-top: 16px;
53}
54
55.attachmentDescription code {
56 font-size: 12px;
57}
58</style>
59
60<h4 class="mdl-dialog__title">Archivos adjuntos</h4>
61<div class="mdl-dialog__content">
62 <?php
63 $attachments = incidents::getAttachmentsFromIncident($incident);
64
65 if ($attachments === false) {
66 echo "<p>Ha ocurrido un problema cargando los archivos adjuntos.</p>";
67 } elseif (!count($attachments)) {
68 echo "<p>No hay ningún archivo adjunto</p>";
69 } else {
70 echo '<ul class="mdl-list">';
71 foreach ($attachments as $attachment) {
72 $extension = files::getFileExtension($attachment);
73 $icon = files::$mimeTypesIcons[$extension] ?? "broken_image";
74 $title = files::$readableMimeTypes[$extension] ?? "Documento desconocido";
75 echo '<li class="mdl-list__item">
76 <span class="mdl-list__item-primary-content">
77 <i class="material-icons mdl-list__item-icon">'.security::htmlsafe($icon).'</i>
78 '.security::htmlsafe($title).'
79 </span>
80 <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">
81 <i class="material-icons">open_in_new</i>
82 </a>'.
83 ($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).'">
84 <i class="material-icons">delete</i>
85 </button>').'
86 </li>';
87 }
88 echo "</ul>";
89 }
90
91 if (!$cantedit) {
92 ?>
93 <h5>Añade un archivo adjunto</h5>
94 <form action="doaddincidentattachment.php" method="POST" enctype="multipart/form-data" class="addAttachmentForm">
95 <input type="hidden" name="id" value="<?=(int)$incident["id"]?>">
96 <?php visual::addContinueInput(); ?>
97 <input type="file" name="file" accept="<?=security::htmlsafe(files::getAcceptAttribute())?>" required>
98 <button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--raised">Subir</button>
99 </form>
100 <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>
101 <?php
102 }
103 ?>
104</div>
105<div class="mdl-dialog__actions">
106 <button data-dyndialog-close class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--accent">Cerrar</button>
107</div>