-
Notifications
You must be signed in to change notification settings - Fork 1
/
userfriend.php
359 lines (254 loc) · 13.3 KB
/
userfriend.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
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
<?php
require './php_resources/check_session.php';
require './php_resources/checkUserFriend.php';
require './php_resources/dbConn.php';
require_once("./php_resources/configFriend.php");
require_once("./php_resources/function.php");
if(isset($_GET['submitModifyStatusComment'])){
?><script type="text/javascript">var flag= clientSideCommentsControl('<?php echo $_GET['commentsText'] ?>');
if(flag==true){<?php
require('./php_resources/commentsControl.php');
if($flag==true){
dbConnect();
$sql1 = "SELECT comments FROM messaggistato WHERE id = '".$_GET['modifyComment']."'";
$result= mysql_query($sql1);
$oldComment = mysql_fetch_row($result);
$divideString = explode(':',$_GET['commentMessage'],-1);
$oldComment[0]=preg_replace("/".$_GET['commentMessage']."#/",$divideString[0].":".$_GET['commentsText']."#",$oldComment[0],1);
$sql = "UPDATE `dbomarmohamed`.`messaggistato` SET `comments` = '".$oldComment[0]."' WHERE `messaggistato`.`id` = ".$_GET['modifyComment'].";";
$result = mysql_query($sql);
mysql_close();
}
?>}</script><?php
}
if(isset($_GET['deleteStatusComment'])){
dbConnect();
$sql1 = "SELECT comments FROM messaggistato WHERE id = '".$_GET['deleteStatusComment']."'";
$result= mysql_query($sql1);
$oldComment = mysql_fetch_row($result);
$oldComment[0]=preg_replace("/".$_GET['commentMessage']."#/","",$oldComment[0],1);
$sql = "UPDATE `dbomarmohamed`.`messaggistato` SET `comments` = '".$oldComment[0]."' WHERE `messaggistato`.`id` = ".$_GET['deleteStatusComment'].";";
$result = mysql_query($sql);
mysql_close();
}
if(isset($_GET['submitModifyComment'])){
require('./php_resources/commentsControl.php');
if($flag==true){
dbConnect();
$sql1 = "SELECT comments FROM immagini WHERE src = '".$_GET['modifyComment']."'";
$result= mysql_query($sql1);
$oldComment = mysql_fetch_row($result);
$divideString = explode(':',$_GET['commentMessage'],-1);
$oldComment[0]=preg_replace("/".$_GET['commentMessage']."#/",$divideString[0].":".$_GET['commentsText']."#",$oldComment[0],1);
$sql = "UPDATE `dbomarmohamed`.`immagini` SET `comments` = '".$oldComment[0]."' WHERE `immagini`.`src` = '".$_GET['modifyComment']."';";
$result = mysql_query($sql);
mysql_close();
}
}
if(isset($_GET['deleteComment'])){
dbConnect();
$sql1 = "SELECT comments FROM immagini WHERE src = '".$_GET['deleteComment']."'";
$result= mysql_query($sql1);
$oldComment = mysql_fetch_row($result);
$oldComment[0]=preg_replace("/".$_GET['commentMessage']."#/","",$oldComment[0],1);
$sql = "UPDATE `dbomarmohamed`.`immagini` SET `comments` = '".$oldComment[0]."' WHERE `immagini`.`src` = '".$_GET['deleteComment']."';";
$result = mysql_query($sql);
mysql_close();
header("Location: userfriend.php?friend=".$_GET['friend']."&index=".$_GET['index']."&src=".$_GET['src']);
}
require_once("./php_resources/gallery.php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>PartySmile - Just have fun! - I tuoi amici</title>
<link href="./CSS/sitestyle.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="js/commentsControl.js" charset="utf-8"></script>
</head>
<body>
<div class="container">
<?php require("header.php"); ?>
<div class="sidebar">
<ul class="nav">
<li><a href="home.php">Il tuo profilo</a></li>
<li><a href="news.php">Notizie</a></li>
<li class="selected"><a href="friends.php">Amici</a></li>
<li><a href="pictures.php">Foto</a></li>
<li><a href="logout.php">Logout</a></li>
</ul>
<!-- end .sidebar1 --></div>
<div class="content" id="content">
<?php
if(isset($_GET['deleteImage'])){
dbConnect();
$qry = "DELETE FROM `dbomarmohamed`.`immagini` WHERE `src` = '".$_GET ['deleteImage']."'";
$check = mysql_query($qry);
mysql_close();
unlink (DIR_IMMAGINI_GRANDI."/preview_".$_GET['deleteImage']);
unlink (DIR_IMMAGINI_PICCOLE . "/small_".$_GET['deleteImage']);
}
if(isset($_GET['saveComment'])){
require('./php_resources/commentsControl.php');
if($flag==true){
dbConnect();
$sql1 = "SELECT comments FROM messaggistato WHERE id = '".$_GET['id']."'";
$result= mysql_query($sql1);
$oldComment = mysql_fetch_row($result);
$sql2 = "UPDATE messaggistato SET comments = '".$oldComment[0]."".$_GET['commentsUsername'].":".$_GET['commentsText']."#' WHERE id = '".$_GET['id']."'";
mysql_query($sql2);
?><script type="text/javascript">
location.replace("./userfriend.php?friend=<?php echo $_GET['friend'] ?>");
</script> <?php
}
}
if(isset($_GET['newComment'])){
$lista_file = caricaDirectory($username);
require "./php_resources/commentsControl.php";
if($flag==true){
dbConnect();
$sql1 = "SELECT comments FROM immagini WHERE src = '".$lista_file[$_GET['index']]."'";
$result= mysql_query($sql1);
$oldComment = mysql_fetch_row($result);
$sql2 = "UPDATE immagini SET comments = '".$oldComment[0]."".$_SESSION['username'].":".$_GET['commentsText']."#' WHERE src = '".$lista_file[$_GET['index']]."'";
mysql_query($sql2);
mysql_close();
}
?><script type="text/javascript">
location.replace("./userfriend.php?friend=<?php echo $username ?>&index=<?php echo $_GET['index'] ?>&src=<?php echo $_GET['src'] ?>");
</script> <?php
}
$friend = str_replace('"', "",$_GET['friend']);
$sendRequest="";
if(isset($_GET['index'])){
$actualImageIndex=$_GET['index'];
$actualSrc=$_GET['src'];
?> <script type="text/javascript">openGallery('<?php echo $actualSrc ?>',<?php echo $actualImageIndex ?>);</script> <?php
}
dbConnect();
if(isset($_GET['request'])){
if($_GET['request']==1){
$qry = "INSERT INTO `dbomarmohamed`.`richiesteamicizia` (`sender`, `receiver`, `state`) VALUES('".$_SESSION['username']."','".$friend."','".$_GET['request']."')";
$check = mysql_query($qry);
}
else if($_GET['request']==0){
$qry = "DELETE FROM `dbomarmohamed`.`richiesteamicizia` WHERE (`richiesteamicizia`.`sender` = '".$_SESSION['username']."' AND`richiesteamicizia`.`receiver` = '".$friend."') OR (`richiesteamicizia`.`receiver` = '".$_SESSION['username']."' AND`richiesteamicizia`.`sender` = '".$friend."')";
$check = mysql_query($qry);
}
}
$qry = "SELECT sender,receiver,state FROM richiesteamicizia WHERE (sender = '".$_SESSION['username']."' OR receiver = '".$_SESSION['username']."') AND (sender = '".$friend."' OR receiver = '".$friend."')";
$check = mysql_query($qry);
$info = mysql_fetch_row($check);
if($info[2] == NULL | $info[2] == 0)
$sendRequest="<input class=\"button2\" type=\"button\" name=\"sendFriendRequest\" value=\"Invia richiesta di amicizia\" onclick=\"location.href='userfriend.php?friend=".$friend."&request=1';\">";
if($info[2] == 1)
$sendRequest="<input class=\"button2\" type=\"button\" name=\"deleteFriendRequest\" value=\"Annulla richiesta di amicizia\" onclick=\"location.href='userfriend.php?friend=".$friend."&request=0';\">";
if($info[2] == 2)
$sendRequest="<input class=\"button2\" type=\"button\" name=\"deleteFriend\" value=\"Rimuovi dagli amici\" onclick=\"location.href='userfriend.php?friend=".$friend."&request=0';\">";
?>
<h1>Profilo di <?php echo $friend; echo $sendRequest;?></h1>
<?php
if($info[2]== 2){
$qry = "SELECT * FROM utenti WHERE username = '".$_GET['friend']."'";
$check = mysql_query($qry);
$info = mysql_fetch_array($check);
?>
<h3>Informazioni personali</h3>
<p><img alt="avatar" src=" <?php echo $info['avatarpath'] ?>"><br>
Username: <?php echo $info['username']?> <br>
Email: <?php echo $info['email']?> <br>
Nome: <?php echo $info['name']?> <br>
Cognome: <?php echo $info['surname']?> <br>
Data di nascita: <?php echo date("d-m-Y", strtotime($info['birthdate']))?> <br>
Città di nascita: <?php echo $info['birthcity']?> <br>
Città attuale: <?php echo $info['actualcity']?> <br>
Situazione sentimentale: <?php echo $info['sentimentalsituation']?></p>
<h3>Messaggi di stato</h3>
<?php
$qry = "SELECT * FROM messaggistato WHERE username = '".$info['username']."' ORDER BY id DESC";
$check = mysql_query($qry);
$numberRows= mysql_num_rows($check);
if($numberRows>0){
while($info = mysql_fetch_array($check)){
?><div class="status"> <?php
echo "<p><b>",$info['username'],":</b> ",$info['statusmessage'],"</p>";
echo "<form class=\"form\" action=\"userfriend.php\" method=\"get\"><p><input type=\"text\" name=\"commentsText\" ><input type=\"hidden\" name=\"commentsUsername\" value=\"".$_SESSION['username']."\"><input type=\"hidden\" name=\"id\" value=\"".$info['id']."\"><input type=\"hidden\" name=\"friend\" value=\"".$_GET['friend']."\"><input type=\"submit\" name=\"saveComment\" value=\"Inserisci commento\" onclick=\"return clientSideCommentsControl(this.form);\"><input type=\"reset\" value=\"Cancella\"></p></form>";
echo "<h4 class=\"info\">Commenti</h4>";
$commentsArray = explode('#',$info['comments'],-1);
for($i=0;$i<count($commentsArray);$i++){
echo "<p>".$commentsArray[$i]."</p><br>";
$divideString = explode(':',$commentsArray[$i],-1);
if($divideString[0]==$_SESSION['username'] | $_SESSION['administrator']==1){
echo "<form class=\"form\" action=\"userfriend.php\" method=\"get\"><p><input type=\"text\" name=\"commentsText\" ><input type=\"hidden\" name=\"modifyComment\" value=\"".$info['id']."\"><input type=\"hidden\" name=\"friend\" value=\"".$_GET['friend']."\"><input type=\"hidden\" name=\"commentMessage\" value=\"".$commentsArray[$i]."\"><input type=\"submit\" name=\"submitModifyStatusComment\" value=\"Modifica\" onclick=\"return clientSideCommentsControl(this.form);\">";
echo "<input type=\"button\" name=\"deleteComment\" value=\"Elimina commento\" onclick=\"location.href='userfriend.php?friend=".$_GET['friend']."&deleteStatusComment=".$info['id']."&commentMessage=".$commentsArray[$i]."';\"></p></form>";
}
echo "<hr class=\"divide\">";
}
?></div>
<?php
}
}
else
echo("<p class=\"info2\">".$info['username']." non ha ancora scritto nessun messaggio di stato.</p>");
?>
<h3>Amici</h3>
<?php
$qry = "SELECT sender,receiver FROM richiesteamicizia WHERE (sender = '".$info['username']."' OR receiver = '".$info['username']."') AND state = 2";
$check = mysql_query($qry);
$numberRows= mysql_num_rows($check);
$friendFound="";
if($numberRows>0){
echo("<ul>");
while($info3 = mysql_fetch_array($check)){
if($info3['sender']!=$info['username'])
$friendFound=$info3['sender'];
else
$friendFound=$info3['receiver'];
echo "<li><a href=\"userfriend.php?friend=",$friendFound,"\">",$friendFound,"</a></li>";
}
echo("</ul>");
}
else
echo("<p class=\"info2\">Non è presente nessun utente di PartySmile nella lista degli amici di ".$info['username']."</p>");
?>
<h3>Fotografie</h3>
<?php
$lista_file = caricaDirectory($_GET['friend']);
if (count($lista_file) > 0) {
echo "<ul>";
for ($i = 0; $i < count($lista_file); $i++) {
echo "<li>", generaLinkImmagineFriend($_GET['friend'],$i, $lista_file[$i]);
if($_SESSION['administrator']==1){
echo "<-<input class=\"button5\" type=\"button\" name=\"deleteImage\" value=\"Elimina\" onclick=\"location.href='userfriend.php?friend=".$_GET['friend']."&deleteImage=".$lista_file[$i]."';\">";
}
echo "</li>";
}
echo "</ul>";
} else
echo "\t<p class=\"info2\">Non è presente alcuna immagine all'interno della galleria fotografica di ".$info['username'].".</p>\n";
} else
echo ("<p class=\"info2\">Non è possibile visualizzare le informazioni personali di un utente di PartySmile se non si è suo amico. Invia una richiesta d'amicizia ed attendi che il destinatario la accetti o meno.</p>");
?>
<!-- end .content --></div>
<div class="sidebar">
<ul class="nav">
<li><a href="personalinformation.php">Informazioni personali</a></li>
<?php
dbConnect();
$qry = "SELECT sender,state FROM richiesteamicizia WHERE receiver = '".$_SESSION['username']."' AND state = 1";
$check = mysql_query($qry);
$numberRows= mysql_num_rows($check);
if($numberRows==0){ ?>
<li><a href="notice.php">Notifiche (0)</a></li>
<?php }
else { ?>
<li><a href="notice.php">Notifiche (<?php echo $numberRows;?>)</a></li>
<?php } if($_SESSION['administrator']==1)
echo("<li><a href=\"administrationpanel.php\">Amministrazione sito</a></li>")?>
</ul>
<p class="info" id="errorMessage2"><?php echo($errorMessage2); ?></p>
<!-- end .sidebar2 --></div>
<?php require("footer.php");?>
<!-- end .container --></div>
</body>
</html>