-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit_new_personne.php
70 lines (57 loc) · 2.15 KB
/
init_new_personne.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
<?php
/* --- GenderWatchProtocole · init_new_personne.php ------
Initialise une nuvelle personne de new_personne.php
1: Vérifie que cette personne soit valide
=> Sinon, repost les infos et renvoie avec un méta
2: Initialise l'entrée dans table personnes_watch
---------------------------------------------*/
// Pour récupérer les cookies
session_start();
// Ouverture DB
include("db.php");
// Pour renvoyer avec les infos
function go_back($new_personne_name, $new_personne_gender, $new_personne_role)
{
$get = array(
"new_personne_name" => $new_personne_name,
"new_personne_gender" => $new_personne_gender,
"new_personne_role" => $new_personne_role,
"msg" => "Impossible de créer la personne"
);
header("Location:new_personne.php?" . http_build_query($get));
}
// Vérification infos présentes
if (isset($_POST["new_personne_name"])
and isset($_POST["new_personne_gender"])
and isset($_POST["new_personne_role"])
and $_POST["new_personne_name"] != ""
and in_array($_POST["new_personne_gender"], array("F", "T", "H"))
and in_array($_POST["new_personne_role"], array("", "M"))) {
$new_personne_name = htmlspecialchars((string)$_POST["new_personne_name"]);
$new_personne_gender = htmlspecialchars((string)$_POST["new_personne_gender"]);
$new_personne_role = htmlspecialchars((string)$_POST["new_personne_role"]);
try {
// Créer l'entrée dans la table watch
$add_watch = $database->prepare(
"INSERT INTO personnes_watch
(watch, nom, genre, role, temps_parlé, parole_longue, parole_courte, parle_depuis)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?)");
$add_watch->execute(array(
$_SESSION["current_watch"],
$new_personne_name,
$new_personne_gender,
$new_personne_role,
0,
0,
0,
0));
// Redirection vers le menu principal
header("Location:watch.php");
} catch (Exception $e) {
go_back($_POST["new_personne_name"], $_POST["new_personne_gender"], $_POST["new_personne_role"]);
}
} else {
go_back($_POST["new_personne_name"], $_POST["new_personne_gender"], $_POST["new_personne_role"]);
}
?>