-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeletePhoto.php
87 lines (70 loc) · 2.32 KB
/
deletePhoto.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
<?php
session_start();
include_once $_SERVER['DOCUMENT_ROOT'].'/assets/config/functions.inc.php';
$outil = new Outils;
$isConnected = $outil->isConnected();
//récupère l'id dans l'url
$id = $_GET['id'];
//Permet de récupérer les données de la photo
$photo = new Photo(
[
'IdPhoto' => (int) $id
]
);
$photoManager = new PhotoManager($db);
$dataPhoto = $photoManager->recupDate($photo);
// Classe utilisateur
$user = new User(
[
'IdUser' => $_SESSION['idUser']
]
);
$userManager = new UserManager($db);
$dataUser = $userManager->recupData($user);
// ---- PARTIE VERIFICATION ---- \\
//Vérifier si l'utilisateur est connecté
if(!$isConnected) {
$outil->redirectUrl('/profil.php');
}
//Vérifier si la photo existe
if(!$dataPhoto) {
$outil->redirectUrl("/profil.php");
}
//Vérifier si la photo n'est pas acheté
if(!is_null($dataPhoto['isBuyPhoto'])) {
$outil->redirectUrl("/profil.php");
}
//Pass droit admin (car l'admin peut supprimer les photos de tout les photographes)
if($dataUser['rankUser'] != 3) {
//Vérifier si la photo appartient bien au photographe avant de la supprimer
if($dataPhoto['idUserPhotographer'] != $_SESSION['idUser']) {
$outil->redirectUrl("/profil.php");
}
}
// ---- PARTIE SUPPRESSION ---- \\
//Permet de supprimer les photos
$image = scandir("assets/images/photos");
for($i=0;$i<count($image);$i++) {
if($image[$i] != "." and $image[$i] != "..") {
$image[$i] = explode("_", $image[$i]);
if($image[$i][0] == $id) {
$linkImage = $_SERVER['DOCUMENT_ROOT'].'/assets/images/photos/'.$image[$i][0].'_'.$image[$i][1].'_'.$image[$i][2];
unlink( $linkImage );
}
}
}
//Permet de supprimer en base de donnée
$photo = new Photo(
[
'IdPhoto' => (int) $id
]
);
$photoManager = new PhotoManager($db);
$photoManager->deletePhotoForPhotographer($photo);
// redirection une fois finie
if($dataUser['rankUser'] != 3) {
$outil->redirectUrl("/profil.php");
} else {
$outil->redirectUrl("/admin/pages/photo/photo.php");
}
?>