blob: 2b772770018a09eae012af2aaf9a37b1df726b8d [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 +010021class help {
22 const PLACE_INCIDENT_FORM = 0;
23 const PLACE_VALIDATION_PAGE = 1;
24 const PLACE_REGISTRY_PAGE = 2;
25 const PLACE_EXPORT_REGISTRY_PAGE = 3;
26
27 public static $places = [0, 1, 2, 3];
28 public static $placesName = [
29 0 => "Formulario de incidencias",
30 1 => "Página de validación",
31 2 => "Página de listado de registros",
32 3 => "Página de exportar registro"
33 ];
34
35 public static function exists($place) {
36 global $con;
37
38 $splace = (int)$place;
39
40 $query = mysqli_query($con, "SELECT 1 FROM help WHERE place = $splace");
41
42 return (mysqli_num_rows($query) > 0);
43 }
44
45 public static function set($place, $url) {
46 global $con;
47
48 if (!in_array($place, self::$places)) return -1;
49 if ($url !== "" && !filter_var($url, FILTER_VALIDATE_URL)) return 1;
50
51 $splace = (int)$place;
52 $surl = db::sanitize($url);
53
54 if (self::exists($place)) return (mysqli_query($con, "UPDATE help SET url = '$surl' WHERE place = $splace LIMIT 1") ? 0 : -1);
55 else return (mysqli_query($con, "INSERT INTO help (place, url) VALUES ('$splace', '$surl')") ? 0 : -1);
56 }
57
58 public static function get($place) {
59 global $con;
60
61 if (!in_array($place, self::$places)) return false;
62 $splace = (int)$place;
63
64 $query = mysqli_query($con, "SELECT url FROM help WHERE place = $splace");
65
66 if (mysqli_num_rows($query) > 0) {
67 $url = mysqli_fetch_assoc($query)["url"];
68 return ($url === "" ? false : $url);
69 } else return false;
70 }
71}