This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost_gest_list.php
77 lines (66 loc) · 2.06 KB
/
post_gest_list.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
require_once("php/tools.php");
require_once("php/database.php");
$user_id = isset($_SESSION["id"]) ? $_SESSION["id"] : "";
if ($user_id == "") {
header("location: login.php");
exit();
}
$id = isset($_POST["gest_id"]) ? $_POST["gest_id"] : "";
$nome = isset($_POST["nome"]) ? $_POST["nome"] : "";
$submit = isset($_POST["submit"]) ? $_POST["submit"] : "";
if (! in_array($submit, ["aggiungi", "modifica", "elimina"]) || ($submit != "aggiungi" && $id == "")) {
Tools::errCode(500);
exit();
}
$err = [];
if ($nome == "") {
array_push($err, "Nome è un campo richesto.");
} else {
if (strlen($nome) > 50)
array_push($err, "Il nome deve essere lungo al massimo 50 caratteri.");
if (! preg_match("/^[\w\s\-\.\:\'\[\]\,\/\"\x{00C0}-\x{017F}]+$/u", $nome))
array_push($err, "Il nome inserito contiene caratteri non ammessi.");
}
if ($err) {
$_SESSION["error"] = $err;
header("location: gest_list.php?id=" . $id);
exit();
}
try {
$connessione = new Database();
if ($submit == "aggiungi") {
$up = $connessione->insertLista($user_id, $nome);
$res = $up[0];
if ($res) $id = $up[1];
} elseif ($submit == "modifica" && $connessione->isListaDiUtente($id, $user_id))
$res = $connessione->updateLista($id, $nome);
elseif ($submit == "elimina" && $connessione->isListaDiUtente($id, $user_id)) {
$res = $connessione->deleteLista($id);
$id = "";
}
unset($connessione);
} catch (Exception) {
unset($connessione);
Tools::errCode(500);
exit();
}
if (! $res) {
if ($submit == "aggiungi") {
$_SESSION["error"] = ["Esiste già una lista con questo nome"];
header("location: gest_list.php");
} else {
$_SESSION["success"] = ["Nessuna modifica apportata."];
header("location: list.php?id=" . $id);
}
} elseif ($submit == "aggiungi") {
$_SESSION["success"] = ["Lista aggiunta correttamente."];
header("location: list.php?id=" . $id);
} elseif ($submit == "modifica") {
$_SESSION["success"] = ["Lista modificata correttamente."];
header("location: list.php?id=" . $id);
} else {
$_SESSION["success"] = ["Lista eliminata correttamente."];
header("location: lists.php");
}
?>