-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatch_share_act.php
109 lines (88 loc) · 2.46 KB
/
watch_share_act.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/* --- GenderWatchProtocole · watch_share_act.php ------
Modifie les accès à un watch donné
Peut être un ajout ou une supression d'accès
---------------------------------------------*/
include("header.php");
include("data_watch.php");
// Ouverture DB
include("db.php");
// Pour renvoyer avec les infos
$stop = False;
function go_back()
{
global $stop;
$stop = True;
$get = array(
"msg" => "Modification des accès impossible."
);
header("Location:watch_share.php?" . http_build_query($get));
}
if ($user_data["id"] != $watch_data["created_by"]) {
go_back();
}
// Vérification infos présentes
if (!isset($_POST["action"])) {
go_back();
}
if ($_POST["action"] == "remove") {
if (!isset($_POST["id"])) {
go_back();
}
}
if ($_POST["action"] == "add") {
if (!isset($_POST["name"])) {
go_back();
}
}
// Ajout
try {
if ($_POST["action"] == "add") {
$name = $_POST["name"];
//Récupération de l'ID
$getID = $database->prepare("SELECT id FROM authorized_user WHERE user = ?");
$getID->execute(array($name));
$id = $getID->fetch();
$getID->closeCursor();
$id = $id["id"];
// Vérification id
if (!isset($id) or $id == "") {
go_back();
}
// Récupération anciens droits
$oldaccessQ = $database->query("SELECT user_access FROM watch WHERE id = " . $watch_data["id"]);
$oldaccess = $oldaccessQ->fetch();
$oldaccessQ->closeCursor();
$oldaccess = $oldaccess["user_access"];
//Ajout accès
$newaccess = $oldaccess . $id . ",";
if (!$stop) {
$database->exec("
UPDATE watch SET user_access = '" . $newaccess . "' WHERE id = " . $watch_data["id"]);
}
header("Location:watch_share.php");
}
} catch (Exception $e) {
go_back();
}
// Suppression
try {
if ($_POST["action"] == "remove") {
$id = $_POST["id"];
// Récupération anciens droits
$oldaccessQ = $database->query("SELECT user_access FROM watch WHERE id = " . $watch_data["id"]);
$oldaccess = $oldaccessQ->fetch();
$oldaccessQ->closeCursor();
$oldaccess = $oldaccess["user_access"];
//Suppression accès
$newaccess = preg_replace("#" . $id . ",#", "", $oldaccess);
if (!$stop) {
$database->exec("
UPDATE watch SET user_access = '" . $newaccess . "' WHERE id = " . $watch_data["id"]);
}
header("Location:watch_share.php");
}
} catch (Exception $e) {
go_back();
}
?>