-
Notifications
You must be signed in to change notification settings - Fork 0
/
visionnage_album.php
257 lines (203 loc) · 12 KB
/
visionnage_album.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<!DOCTYPE html>
<html>
<head>
<title>ECEpic</title>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="album.css">
<link rel="stylesheet" type="text/css" href="menu.css">
<link rel="stylesheet" type="text/css" href="parser.css">
</head>
<body onkeydown="testEchap(event)">
<?php
try
{
$bdd = new PDO('mysql:host=localhost;dbname=ecepic;charset=utf8', 'root', '');
}
catch (Exception $e)
{
die('Erreur : ' . $e->getMessage());
}
?>
<?php include('menu.php'); ?>
<!--Code pour ajouter une photo à l'album-->
<?php
if(isset($_POST['ajout_a_album']))
{
$request_ajouter_a_album = $bdd->prepare('INSERT INTO album_photo (ID_album, ID_photo) VALUES (?, ?)');
$request_id_album = $bdd->prepare('SELECT ID FROM album WHERE title = ?');
$request_id_album->execute(array($_POST['album_cible']));
$reponse_id_album = $request_id_album->fetch();
$request_ajouter_a_album->execute(array($reponse_id_album['ID'], $_POST['photo_tomove']));
}
?>
<?php
$photo_bdd_request = $bdd->query('SELECT * FROM photos');
while($photo_bdd_answer = $photo_bdd_request->fetch())
{
$identifiant_photo_trash = 's' . $photo_bdd_answer['ID'];
if(isset($_POST[$identifiant_photo_trash]))
{
$delete_photo = $bdd->prepare('DELETE FROM photos WHERE ID = ?');
$delete_photo->execute(array($photo_bdd_answer['ID']));
$delete_photo_album = $bdd->prepare('DELETE FROM album_photo WHERE ID_photo = ?');
$delete_photo_album->execute(array($photo_bdd_answer['ID']));
}
$identifiant_photo_add_album = 'add' . $photo_bdd_answer['ID'];
if(isset($_POST[$identifiant_photo_add_album]))
{
echo('<div class="ajout_album">');
echo('<form method="POST" action ="" enctype="multipart/form-data">');
echo('Veuillez sélectionner l\'album dans lequel ajouter la photo:<br>');
echo('<select name="album_cible" id="album">');
$requete_id_user_album = $bdd->prepare('SELECT ID FROM users WHERE pseudo = ?');
$requete_id_user_album->execute(array($_SESSION['user']));
$reponse_id_user_album = $requete_id_user_album->fetch();
$requete_albums_name = $bdd->prepare('SELECT * FROM album WHERE ID_owner = ?');
$requete_albums_name->execute(array($reponse_id_user_album['ID']));
while($reponse_albums_name = $requete_albums_name->fetch())
{
echo('<option value="' . $reponse_albums_name['title'] . '"">' . $reponse_albums_name['title'] .'</option>');
}
echo('</select>');
echo('<input type="text" value="'. $photo_bdd_answer['ID'] .'"name="photo_tomove" style="display:none;"/>');
echo('<br><input value="valider" type="submit" name="ajout_a_album"/>');
echo('<input value="annuler" type="submit" name="annuler"/>');
echo('</form>');
echo('</div>');
}
}
$photo_bdd_request->closeCursor();
?>
<?php
$album_requete = $bdd->prepare('SELECT title FROM album WHERE ID = ?');
$album_requete->execute(array($_GET['id_album']));
$album_reponse = $album_requete->fetch();
echo('<h1 class = "album_page_title">' . $album_reponse['title'] . '</h1>');
$photo_album_requete = $bdd->prepare('SELECT ID_photo FROM album_photo WHERE ID_album = ?');
$photo_album_requete->execute(array($_GET['id_album']));
while($photo_album_reponse = $photo_album_requete->fetch())
{
$photos_requete = $bdd->prepare('SELECT * FROM photos WHERE ID = ?');
$photos_requete->execute(array($photo_album_reponse['ID_photo']));
$requete_id_user = $bdd->prepare('SELECT ID from users WHERE pseudo = ?');
$requete_id_user->execute(array($_SESSION['user']));
$id_user = $requete_id_user->fetch();
while($photos_reponse = $photos_requete->fetch())
{
if($photos_reponse['public'] == 1 || $photos_reponse['ID_owner'] == $id_user['ID'])
{
echo('<div class="bloc_photo">');
//récupère le nom du propriétaire de la photo et son avatar
$requete_pseudo_owner = $bdd->prepare('SELECT pseudo, avatar FROM users, photos WHERE users.ID = ?');
$requete_pseudo_owner -> execute(array($photos_reponse['ID_owner']));
$pseudo_owner = $requete_pseudo_owner->fetch();
//affichage de l'avatar du propriétaire de la photo si il en a un
if(!empty($pseudo_owner['avatar']))
{
echo('<p class="paragraph_owner">' . '<a href="profil.php?pseudo=' . $pseudo_owner['pseudo'] .'"> ' . '<img class = "avatar_owner" src="'.$pseudo_owner['avatar'].'"/></a>');
}
else
{
echo('<p class="paragraph_owner">' . '<a href="profil.php?pseudo=' . $pseudo_owner['pseudo'] .'"> ' . '<img class = "avatar_owner" src="avatars/unknown.png"/></a>');
}
if($pseudo_owner['pseudo'] == $_SESSION['user'])
{
$name_trash= 's' . $photos_reponse['ID'];
echo('<form method="POST" action ="" enctype="multipart/form-data">');
echo('<input class = "float_right" src="ressources/trash.png" type="image" value="submit" name="' . $name_trash . '" /> ');
echo('</form>');
//echo('<img class = "float_right" src="ressources/trash.png"/>');
echo('<img class = "float_right" src="ressources/edit_information.png"/>');
}
$name_add= 'add' . $photos_reponse['ID'];
echo('<form method="POST" action ="" enctype="multipart/form-data">');
echo('<input class = "float_right" src="ressources/add_to_album.png" type="image" value="submit" name="' . $name_add . '" /> ');
echo('</form>');
echo('<img class = "float_right" src="ressources/exif.png"/>');
//affiche le pseudo du propriétaire de la photo
echo('<a href="profil.php?pseudo=' . $pseudo_owner['pseudo'] .'"><span class="name_owner">' . $pseudo_owner['pseudo'] . '</span></a>');
//Affiche le nom de la photo si elle en a un
if(!empty($photos_reponse['name']))
{
echo('<br/><span class="name_photo">' . $photos_reponse['name'] . '</span></p>');
}
else
{
echo('</p>');
}
$path_image = $photos_reponse['path'];
if(isset($_POST['modification']))
{
$req = $bdd->prepare('UPDATE photos SET public = :public, location = :location,theme = :theme,name = :name WHERE ID = :photos_requete');
$req->execute(array(
'public' => $_POST['visibilité_mod'],
'location' => $_POST['lieu_mod'],
'theme' => $_POST['categorie_mod'],
'name' => $_POST['titre_mod'],
'photos_requete' => $photos_reponse['ID'],
));
echo('<br/><br/><br/> Félicitations vos données de la photo ont été modifiées');
}
//include("parser_exif.php");
//affichage de la photo
echo('<p class="image">' . '<img class = "photo" src="'.$photos_reponse['path'].'"/>' . '</p>');
//affichage info sur la photo et modif
if($pseudo_owner['pseudo'] == $_SESSION['user'])
{
echo('<div class="modif_photo">');
echo('<form method="POST" action="" enctype="multipart/form-data">
Changer la visibilité de la photo :
<br />
<input type="radio" name="visibilité_mod" value="1" id="public" /> <label for="public">Publique</label><br />
<input type="radio" name="visibilité_mod" value="0" id="privé" /> <label for="privé">privé</label><br />
Changer le titre de la photo<br/>
<textarea name="titre_mod" id="titre_mod"></textarea><br/>
Changer le lieu de la photo<br/>
<input type="text" name="lieu_mod" /><br/>
Changer la catégorie de la photo<br/>
<select name="categorie_mod" id="categorie_mod">
<option value="Voiture">Voiture</option>
<option value="paysage">Paysage</option>
<option value="portrait">Portrait</option>
<option value="sport">Sport</option>
<option value="technologie">Technologie</option>
<option value="animaux">Animaux</option>
<option value="nourriture">nourriture</option>
<option value="autres">Autres</option>
</select>
<br/>
<br/>
<input value="Modifier" type="submit" name="modification"/>
</form>
<br/> OU <br/>
<br/>
<input value="Supprimer" type="submit" name="suppression" />
</div>
');
}
//affichage de la localisation de la photo
if(!empty($photos_reponse['location']))
{
echo('<p class="description"> <img class = "logo_description" src="ressources/location.png"/>' . '<a href="https://www.google.fr/maps/search/'.$photos_reponse['location'].'" target="blank" title="Cliquer pour accéder à une carte">' . $photos_reponse['location'] . '</a>' . '</p>');
}
//affichage de la date de la photo
if(!empty($photos_reponse['date']))
{
$date=date_create($photos_reponse['date']);
echo('<p class="description"> <img class = "logo_description" src="ressources/date.png"/>' . date_format($date, "d M Y H:i"));
}
//affichage du thème de la photo
if(!empty($photos_reponse['theme']))
{
echo('<p class="description"> <img class = "logo_description" src="ressources/theme.png"/>' . $photos_reponse['theme'] . '</p>');
}
echo('</div>');
}
}
}
echo('<script src="jquery-1.11.0.min.js"></script>');
echo('<script src="jquery-migrate-1.2.1.min.js"></script>');
?>
</body>
</html>