Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame] | 1 | <?php |
Adrià Vilanova Martínez | 5af8651 | 2023-12-02 20:44:16 +0100 | [diff] [blame^] | 2 | /* |
| 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 bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame] | 21 | require_once(__DIR__."/../core.php"); |
| 22 | security::checkType(security::ADMIN, security::METHOD_NOTFOUND); |
| 23 | |
| 24 | if (!isset($_GET["id"])) { |
| 25 | security::notFound(); |
| 26 | } |
| 27 | |
| 28 | $id = (int)$_GET["id"]; |
| 29 | |
| 30 | $c = calendars::get($id); |
| 31 | |
| 32 | if ($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> |
| 45 | textarea.code { |
| 46 | width: 100%; |
| 47 | height: 100px; |
| 48 | } |
| 49 | </style> |
| 50 | |
| 51 | <dynscript> |
| 52 | document.querySelector("textarea.code").select(); |
| 53 | |
| 54 | document.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> |