This repository was archived by the owner on Mar 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathamis.php
More file actions
executable file
·310 lines (276 loc) · 10.6 KB
/
Copy pathamis.php
File metadata and controls
executable file
·310 lines (276 loc) · 10.6 KB
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<?php
//Init page
include('inc/initPage.php');
//On enregistre l'activité
update_last_activity($_SESSION['ID'], $bdd);
//Vérifions qu'il s'agit d'une requete ajax
if(!isset($_GET['ajax']))
{
?>
<!DOCTYPE html>
<html>
<head>
<title>Liste d'amis</title>
<?php include(pagesRelativePath('common/head.php')); ?>
</head>
<body>
<?php include(pagesRelativePath('common/pageTop.php')); ?>
<h1 class='titre'>Liste d'amis</h1>
<?php
//Vérification de l'existence d'une demande d'action
if(isset($_GET['action']))
{
if(($_GET['action'] == 'supp') && (isset($_GET['id'])))
{
//Suppression d'un amis
$sql1 = "DELETE FROM amis WHERE (ID_personne = ".$_GET['id'].") && (ID_amis = ".$_SESSION['ID'].") ";
$sql2 = "DELETE FROM amis WHERE (ID_personne = ".$_SESSION['ID'].") && (ID_amis = ".$_GET['id'].") ";
//Execution des suppressions
$supp1 = $bdd->query($sql1);
$supp2 = $bdd->query($sql2);
}
if(($_GET['action'] == 'activer') && (isset($_GET['id'])))
{
//On vérifie que la demande existe
if(isset_demande_amis($_SESSION['ID'], $_GET['id'], $bdd))
{
//Insertion d'un amis
$sql1 = "UPDATE amis SET actif = 1 WHERE (ID_personne = ".$_SESSION['ID'].") && (ID_amis = ".$_GET['id'].")";
$sql2 = "INSERT INTO amis (ID_personne, ID_amis, actif) VALUES (".$_GET['id'].", ".$_SESSION['ID'].", 1) ";
//Execution des suppressions
$activ1 = $bdd->query($sql1);
$activ2 = $bdd->query($sql2);
}
else
{
//Message d'erreur
?><script>affiche_notification_erreur("Cette personne ne vous a pas demandée en ami !", "Erreur", 5);</script><?php
}
}
}
//Requete de recherche d'amis
$sql = "SELECT * FROM amis, utilisateurs WHERE amis.ID_amis = utilisateurs.ID AND amis.ID_personne = ".$_SESSION['ID']." ORDER BY utilisateurs.prenom";
//Exécution de la requete
$requeteamis = $bdd->query($sql);
//Affichage des résultats
echo "<table>";
echo "<tr><td>Amis</td><td>Actif</td></tr>";
while($afficheramis = $requeteamis->fetch())
{
//Si nécessaire, on ajoute ou supprime à un ami le droit de poster un texte sur ma page
if(isset($_GET['autoriser_post_page']))
{
//On vérifie si il s'agit de cet ami
if($_GET['autoriser_post_page'] == $afficheramis['ID_amis'])
{
//On inverse le droit
//Détermination du droit
$droit = ($afficheramis['autoriser_post_page'] == 1 ? 0 : 1);
//Modification de la base de données
$sql = "UPDATE amis SET autoriser_post_page = ? WHERE ID = ?";
$requete = $bdd->prepare($sql);
$requete->execute(array($droit, $afficheramis['ID']));
//Modification de la variable
$afficheramis['autoriser_post_page'] = $droit;
}
}
?>
<tr>
<td><?php
//Requete de recherche de l'avatar de la personne
echo avatar($afficheramis['ID_amis']);
echo $afficheramis['prenom']." ".$afficheramis['nom'];
?></td>
<td>
<?php
//Affichage de amis
if($afficheramis['actif'] == 0)
{
echo "Ami non accepté. <a href='".$_SERVER['PHP_SELF']."?action=activer&id=".$afficheramis['ID_amis']."'>Accepter</a>";
}
else
{
echo "Accepté";
}
?>
</td>
<td>
<a onClick='confirmaction("<?php echo $_SERVER['PHP_SELF']; ?>?action=supp&id=<?php echo $afficheramis['ID_amis']; ?>", "Supprimer cet ami ?");'>Supprimer cet ami</a>
</td>
<td>
<a href='index.php?id=<?php echo $afficheramis['ID_amis']; ?>'>Voir sa page</a>
</td>
<td><a onClick="affiche_chat_prive(<?php echo $afficheramis['ID_amis']; ?>)"><div class="img-private-chat-small"></div></td>
<td>
<div id='abonnement_<?php echo $afficheramis['ID_amis']; ?>' class='bouton_abonnement' onClick='get_abonnement(<?php echo $afficheramis['ID_amis']; ?>, 1);'>
<?php echo ($afficheramis['abonnement'] == 0 ? "S'abonner" : "<img src='".path_img_asset('succes.png')."' /> Abonné"); ?>
</div>
</td>
<td>
<!-- Autoriser ou non mes amis a faire des posts sur ma page -->
<a id='post_page_<?php echo $afficheramis['ID_amis']; ?>'
class='bouton_abonnement'
href='<?php echo $_SERVER['PHP_SELF']; ?>?autoriser_post_page=<?php echo $afficheramis["ID_amis"]; ?>'>
<?php if($afficheramis['autoriser_post_page'] == 0)
echo "Autoriser de faire des post sur ma page.";
else {
echo code_inc_img(path_img_asset('succes.png'), "Succè");
echo " Cet amis a le droit de faire des posts sur ma page.";
} ?>
</a>
</td>
</tr>
<?php
$amis = 1;
}
echo "</table>";
//Fermeture de la requete
$requeteamis->closeCursor();
if(!isset($amis))
{
echo "Vous n'avez pour le moment aucun amis. <br />";
}
?>
<hr>
<?php include(pagesRelativePath('common/pageBottom.php')); ?>
</body>
</html>
<?php
}
else
{
//Il s'agit bien d'une requete ajax
//On vérifie qu'il existe bien un HTTP_REFERER
if(!isset($_SERVER['HTTP_REFERER']))
die('Invalid call !');
//Requete de recherche d'amis
$sql = "SELECT * FROM amis, utilisateurs WHERE amis.ID_amis = utilisateurs.ID AND amis.ID_personne = ".$_SESSION['ID']." ORDER BY utilisateurs.last_activity DESC";
//Exécution de la requete
$requeteamis = $bdd->query($sql);
//Affichage des résultats
$amis = 0;
$liste_amis = array();
while($afficheramis = $requeteamis->fetch())
{
?>
<tr>
<td><?php
//Requete de recherche de l'avatar de la personne
$urlavatar = avatar($afficheramis['ID_amis'], "./", 1, 1, "", true);
echo "<img src='".$urlavatar."' style='height: ".(isset($_GET['grandavatar']) ? '32' : '16')."px; max-width: none;' />";
?></td><td class="nomlisteamis"><?php
echo "<a ";
//Pour le lien, on vérifie si l'appel vient de la page d'une personne
if(preg_match('/index.php/', $_SERVER['HTTP_REFERER']) OR !preg_match('/.php/', $_SERVER['HTTP_REFERER']))
{
//On est bien sur la page d'une personne, le chargement peut être optimisé
echo "href='#' onClick='change_page_personne(".$afficheramis['ID_amis'].");'";
}
else
{
//On n'est pas sur la page d'un ami, lien normal
echo "href='index.php?id=".$afficheramis['ID_amis']."' ";
}
echo " class='lien'>".corrige_caracteres_speciaux($afficheramis['prenom']." ".$afficheramis['nom'])."</a>";
?></td>
<td>
<?php
//Demande d'amis
if($afficheramis['actif'] == 0)
{
//Question
echo "Accepter ? ";
//Accept
echo "<a href='".$_SERVER['PHP_SELF']."?action=activer&id=".$afficheramis['ID_amis']."'>";
echo code_inc_img(path_img_asset('succes.png'), "Accepter l'invitation");
echo "</a> ";
//Refuse
echo "<a href='".$_SERVER['PHP_SELF']."?action=supp&id=".$afficheramis['ID_amis']."'>";
echo code_inc_img(path_img_asset('supp.png'), "Refuser l'invitation");
echo "</a>";
}
?>
</td>
<td>
<td>
<!-- Private chat -->
<a onClick="affiche_chat_prive(<?php echo $afficheramis['ID']; ?>); affiche_chat_prive(<?php echo $afficheramis['ID']; ?>);" >
<img class="fast_chat_prive_img" src='<?php echo path_img_asset('prive.png'); ?>' width="16" height="16" border='0'/>
</a>
</td>
</td>
<td>
<!-- Check availability -->
<?php
//On détermine si la personne est connectée
$time = time();
$time = $time-35;
if($time > $afficheramis['last_activity'])
//Looged in
echo "<img src='".path_img_asset('indisponible.png')."' title=\"Dernière connexion : ".adapte_date("plus de 35 secondes", $afficheramis['last_activity']).".\" class='indicateur_connexion' />";
else
echo "<img src='".path_img_asset('disponible.png')."' title=\"Connecté\" class='indicateur_connexion' />";
?>
</td>
</tr>
<?php
if(verifier_si_post_chat_prive_non_vu($_SESSION['ID'], $afficheramis['ID_amis'], $bdd))
{
?><tr>
<td colspan="5" class="new_private_chat_friend_list" onClick="affiche_chat_prive(<?php echo $afficheramis['ID_amis']; ?>)">
<span class="new_private_chat_friend_list">
<?php echo code_inc_img(path_img_asset('email.png')); ?>
Message privé non lu
</span>
</td>
</tr><?php
}
$amis++;
$liste_amis[$afficheramis['ID_amis']] = 1;
}
if($amis == 0)
{
echo "<td colspan='4'>";
echo "<p>Vos amis apparaîtront ici lorsque vous en aurez. Utilisez le formulaire de recherche afin de les chercher sur le site.</p>";
echo code_inc_img(path_img_asset('formulaire_recherche.png'), "Formulaire de recherche des amis");
echo "</td>";
}
//On fait maintenant la liste des non_amis qui ont déjà utilisé le chat privé avec la personne
//Récupération de la liste
$listpersonn = list_all_person_private_chatted($_SESSION['ID'], $bdd);
//On commence par "nettoyer la liste"
foreach($listpersonn as $id=>$valid)
{
//On vérifie que c'est n'est pas un amis
if(isset($liste_amis[$id]))
//On supprime la personne de la liste
unset($listpersonn[$id]);
}
//On vérifie si il reste des personnes
if(count($listpersonn) != 0)
{
//Message d'information
echo "<tr><td colspan='6' style='font-size: 70%;'>Autres personnes ayant déjà utilisé le chat privé avec vous :</td></tr>";
foreach($listpersonn as $id=>$valid)
{
//We show the persons
//We search the informations about the personn
$infoperson = cherchenomprenom($id, $bdd);
//We send to the user the informations
echo "<tr>";
echo "<td>";
echo avatar($id, $urlsite, 16, 16);
echo"</td><td colspan='2'>";
echo "<a href='index.php?id=".$id."' class='lien'>";
echo corrige_caracteres_speciaux($infoperson['prenom']." ".$infoperson['nom']);
echo "</a>";
echo "</td><td>";
echo "<a onClick='affiche_chat_prive(".$id.");' >";
echo code_inc_img(path_img_asset('prive.png'), "Ouvrir le chat privé", "16", "16");
echo "</a>";
echo "</td>";
echo "</tr>";
}
}
}
?>