-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathposts.php
More file actions
206 lines (204 loc) · 11.1 KB
/
posts.php
File metadata and controls
206 lines (204 loc) · 11.1 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
<?php
include 'dbconn.php';
include 'magic.php';
if (session_status() == PHP_SESSION_NONE) {
session_start();
if($_SESSION['fname']==''){header('Location:login.php');}
}
$user_id = $_SESSION['user_id'];
$visiting_id = 0;
if(isset($_GET['v_id'])){
$visiting_id = $_GET['v_id'];
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="simple-grid.css">
<link rel="stylesheet" type="text/css" href="main.css">
<script src="jquery-3.1.0.min.js"></script>
<script>
function postOptions(option, post_id, user_id) {
if(option=='deletePost'){
$.post("deletePost.php",{ p_id: post_id,u_id :user_id });
window.location.href = "index.php";
} else if (option=='editPost') {
window.location.href = "editPost.html";
}
}
function friendStatusMouseOver()
{
var buttonContent = document.getElementById("friend_status").innerHTML.trim();
if(buttonContent == "Request Sent"){
document.getElementById("friend_status").innerHTML = "Delete Request";
}
if(buttonContent == "Friends :)"){
statusButton.innerHTML = "Unfriend";
}
}
function friendStatusMouseOut()
{
var buttonContent = document.getElementById("friend_status").innerHTML.trim();
if(buttonContent == "Delete Request"){
document.getElementById("friend_status").innerHTML = "Request Sent";
}
if(buttonContent == "Unfriend"){
statusButton.innerHTML = "Friends :)";
}
}
</script>
</head>
<body>
<nav class="row">
<span class="col-1-sm"></span>
<span class="col-2-sm"><a href="index.php" style="text-decoration:none;">F.R.I.E.N.D.S</a></span>
<span class="col-6-sm"></span>
<span id="navbarname" class="col-1-sm"><?php echo $_SESSION['fname']?></span>
<span class="col-1-sm">
<a href="mailto:fbtests.reportbug@gmail.com?Subject=Bug%20Report%20on%20FRIENDS">
<img src="photos/contribute_bug.png" title="Report Bug" style="max-height:1em;width:auto;">
</a>
</span>
<span id="logoutbtn" class="col-1-sm"><a href="logout.php" tabindex="-1">!</a></span>
</nav>
<div id="sidenav" class="sidenav">
<span class=""><a href="index.php">Feed</a></span>
<span class=""><a href="posts.php?v_id=<?= $user_id ?>">Posts</a></span>
<span class=""><a href="photos.php">Photos</a></span>
<span class=""><a href="events.php">Events</a></span>
<span class=""><a href="friends.php">Friends
<?php
connect();
$sqlcount = 'SELECT COUNT(USER_ID) AS P_F FROM USERS WHERE
USER_ID IN (SELECT USER_ID1 AS U_ID FROM FRIENDS WHERE (USER_ID2='.$user_id.') AND ACCEPT_DATE IS NULL)';
$result = $conn->query($sqlcount);
if ($result->num_rows > 0) {
while($row_cursor = $result->fetch_assoc()) {
$p_f = $row_cursor['P_F'];
if($p_f==0){
echo '';
}
else{
echo '<span class="badge">'.$row_cursor['P_F'].'</span>';
}
}
}
disconnect();
?>
</a>
</span>
<span class="shouts-link"><a href="shouts.php">Shouts</a></span>
<span class="report-bug"><a href="mailto:fbtests.reportbug@gmail.com?Subject=Bug%20Report%20on%20FRIENDS">Report Bug</a>
</div>
<div class="middle-content">
<div id="profile-header" class="row">
<?php
connect();
$sqlprofile = "SELECT FNAME,LNAME,DP FROM USERS WHERE USER_ID=$visiting_id";
$resultprofile = $conn->query($sqlprofile);
if ($resultprofile->num_rows > 0) {
while($row_cursor_profile = $resultprofile->fetch_assoc()) { ?>
<?php
$dplink = $row_cursor_profile['DP'];
if($dplink==''){
$dplink='"photos/empty_profile.png"';
}
else{
$dplink='"photos/'.$row_cursor_profile['DP'].'"';
}
?>
<img class="col-2-sm box" src=<?= $dplink?> />
<span id="profile-name" class="col-5"><?= $row_cursor_profile['FNAME']?> <?= $row_cursor_profile['LNAME'] ?>'s Profile</span>
<form method="post" action="addFriend.php">
<input type="text" name="receiver_id" value="<?= $visiting_id ?>" hidden>
<input type="text" name="sender_id" value="<?= $user_id ?>" hidden>
<a class="" id="add_dp_button" class="col-3" href="adddp.php"<?php if($visiting_id!=$user_id) {echo "hidden";}?>>Change DP
</a><br>
<a class="" id="delete_dp_button" class="col-3" href="deletedp.php"<?php if($visiting_id!=$user_id) {echo "hidden";}?>>Delete DP
</a>
<button id="friend_status" onmouseover="friendStatusMouseOver()" onmouseout="friendStatusMouseOut()" class="col-3" type="submit"<?php if($visiting_id==$user_id) {echo "hidden";}?>>
<?php
$sql = "SELECT ACCEPT_DATE FROM FRIENDS WHERE USER_ID1=".$visiting_id." AND USER_ID2=".$user_id;
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
if($row['ACCEPT_DATE']==NULL){echo "Accept Request";}
else {echo "Friends :)";}
}
} else {
$sql = "SELECT ACCEPT_DATE FROM FRIENDS WHERE USER_ID1=".$user_id." AND USER_ID2=".$visiting_id;
$result = $conn->query($sql);
if ($result->num_rows == 0) {echo "Add Friend";}
else {
while($row = $result->fetch_assoc()) {
if($row['ACCEPT_DATE']==NULL){echo "Request Sent";}
else {echo "Friends :)";}
}
}
}
?>
</button>
</form>
<?php }
}?>
</div>
<div id="posts">
<?php
connect();
$sql = 'SELECT POST_ID,USER_ID,FNAME,LNAME,DP,CONTENT,UNIX_TIMESTAMP(ADD_DATE) AS ADD_DATE FROM POST NATURAL JOIN USERS WHERE
USER_ID ='.$visiting_id.' AND (
USER_ID IN (SELECT USER_ID2 AS U_ID FROM FRIENDS WHERE (USER_ID1='.$user_id.') AND ACCEPT_DATE IS NOT NULL) OR
USER_ID IN (SELECT USER_ID1 AS U_ID FROM FRIENDS WHERE (USER_ID2='.$user_id.') AND ACCEPT_DATE IS NOT NULL) OR
USER_ID IN (SELECT USER_ID AS U_ID FROM USERS WHERE USER_ID='.$user_id.'))
ORDER BY ADD_DATE DESC';
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row_cursor = $result->fetch_assoc()) { ?>
<?php
$dplink = $row_cursor['DP'];
if($dplink==''){
$dplink='"photos/empty_profile.png"';
}
else{
$dplink='"photos/'.$row_cursor['DP'].'"';
}
?>
<div class="box">
<p class="row">
<img class="col-2-sm box dp-in-post" src=<?= $dplink?> />
<span class="col-9-sm"><a href="posts.php?v_id=<?= $row_cursor['USER_ID'] ?>"><span class="posted-by"><?= $row_cursor['FNAME'] ?> </span>
<span class="posted-by"> <?= $row_cursor['LNAME'] ?> </span> </a>
<span class="posted-on"> <?= before($row_cursor['ADD_DATE']) ?></span></span>
<?php $post_id=$row_cursor['POST_ID']; ?>
<span class="col-1-sm">
<select onchange="postOptions(this.value,<?= $post_id ?>,<?= $user_id ?>)" class="post-options">
<option value=""></option>
<option value="deletePost">Delete Post</option></span>
</select>
</span>
</p>
<p id="post_content" class="row post"> <?php echo $row_cursor['CONTENT'] ?></p>
<div id="photos-div" class="row">
<?php
$sqlP = "SELECT PHOTO_ID,LINK FROM PHOTOS WHERE POST_ID='".$post_id."'";
$resultP = $conn->query($sqlP);
if ($resultP->num_rows > 0) {
while($row_cursorP = $resultP->fetch_assoc()) { ?>
<img class="photo-display" src="<?= 'photos/'.$row_cursorP['LINK'] ?>">
<?php
}
} ?>
</div>
</div>
<?php
}
}
?>
<?php disconnect(); ?>
</div>
</div>
</body>
</html>