blob: ad60760a1bf5f8bdcdc54ff8c97f65ec88c78176 [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::ADMIN, security::METHOD_NOTFOUND);
23
24if (!isset($_GET["id"])) {
25 security::notFound();
26}
27
28$id = (int)$_GET["id"];
29
30$c = calendars::get($id);
31
32if ($c === false) {
33 security::notFound();
34}
35
36$details = json_decode($c["details"], true);
37$export = array(
38 "begins" => $c["begins"],
39 "ends" => $c["ends"],
40 "calendar" => $details
41);
42?>
43
44<style>
45textarea.code {
46 width: 100%;
47 height: 100px;
48}
49</style>
50
51<dynscript>
52document.querySelector("textarea.code").select();
53
54document.getElementById("copy").addEventListener("click", _ => {
55 navigator.clipboard.writeText(document.querySelector("textarea.code").value).then(_ => {
56 document.querySelector(".mdl-js-snackbar").MaterialSnackbar.showSnackbar({
57 message: "Se ha copiado el texto correctamente.",
58 timeout: 5000
59 });
60 }).catch(error => {
61 document.querySelector(".mdl-js-snackbar").MaterialSnackbar.showSnackbar({
62 message: "Ha ocurrido un error copiando el texto. Por favor, cópialo manualmente.",
63 timeout: 5000
64 });
65 console.error(error);
66 });
67});
68</dynscript>
69
70<h4 class="mdl-dialog__title">Exportar calendario</h4>
71<div class="mdl-dialog__content">
72 <p>Este es el código que contiene toda la información del calendario y que puedes usar de plantilla más tarde:</p>
73 <textarea class="code" readonly><?=security::htmlsafe(json_encode($export))?></textarea>
74</div>
75<div class="mdl-dialog__actions">
76 <button data-dyndialog-close class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--accent cancel">Cerrar</button>
77 <button id="copy" class="mdl-button mdl-js-button mdl-js-ripple-effect">Copiar</button>
78</div>