blob: 3fe7179e3c38499bdd3c3d1f2e8ccc0710daf73f [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001<?php
2class help {
3 const PLACE_INCIDENT_FORM = 0;
4 const PLACE_VALIDATION_PAGE = 1;
5 const PLACE_REGISTRY_PAGE = 2;
6 const PLACE_EXPORT_REGISTRY_PAGE = 3;
7
8 public static $places = [0, 1, 2, 3];
9 public static $placesName = [
10 0 => "Formulario de incidencias",
11 1 => "Página de validación",
12 2 => "Página de listado de registros",
13 3 => "Página de exportar registro"
14 ];
15
16 public static function exists($place) {
17 global $con;
18
19 $splace = (int)$place;
20
21 $query = mysqli_query($con, "SELECT 1 FROM help WHERE place = $splace");
22
23 return (mysqli_num_rows($query) > 0);
24 }
25
26 public static function set($place, $url) {
27 global $con;
28
29 if (!in_array($place, self::$places)) return -1;
30 if ($url !== "" && !filter_var($url, FILTER_VALIDATE_URL)) return 1;
31
32 $splace = (int)$place;
33 $surl = db::sanitize($url);
34
35 if (self::exists($place)) return (mysqli_query($con, "UPDATE help SET url = '$surl' WHERE place = $splace LIMIT 1") ? 0 : -1);
36 else return (mysqli_query($con, "INSERT INTO help (place, url) VALUES ('$splace', '$surl')") ? 0 : -1);
37 }
38
39 public static function get($place) {
40 global $con;
41
42 if (!in_array($place, self::$places)) return false;
43 $splace = (int)$place;
44
45 $query = mysqli_query($con, "SELECT url FROM help WHERE place = $splace");
46
47 if (mysqli_num_rows($query) > 0) {
48 $url = mysqli_fetch_assoc($query)["url"];
49 return ($url === "" ? false : $url);
50 } else return false;
51 }
52}