-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
289 lines (274 loc) · 12 KB
/
index.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
<?php
session_start();
//Heroku
$cleardb_url = parse_url(getenv("CLEARDB_DATABASE_URL"));
$cleardb_server = $cleardb_url["host"];
$cleardb_username = $cleardb_url["user"];
$cleardb_password = $cleardb_url["pass"];
$cleardb_db = substr($cleardb_url["path"],1);
$active_group = 'default';
$query_builder = TRUE;
$conn = mysqli_connect($cleardb_server, $cleardb_username, $cleardb_password, $cleardb_db);
include('connection.php');
//echo 'hi'.$cleardb_url;
/*
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo nl2br("\nConnected successfully to " . $db . " database.\n\n\n");*/
if(!$_SESSION['logged_in']) { //check if user login or not
header("location:login_form.php");
die();
}
if(isset($_POST['submit-report']))
{
include('send_report.php');
unset($_POST['submit-report']);
}
if (!$conn)
{
die("Unable to connect to MySQL database, error: " . mysqli_connect_error());
}
date_default_timezone_set("Asia/Kuala_Lumpur");
$column_per_rows = 4;
$query = "SELECT * FROM post ORDER BY `POST_DATETIME` DESC";
$active_button = "all";
if (isset($_POST['filter_category']))
{
if($_POST['filter_category'] == "All")
{
$query = "SELECT * FROM post ORDER BY `POST_DATETIME` DESC";
}
else if($_POST['filter_category'] == "Food")
{
$query = "SELECT * FROM `post` WHERE `POST_CATEGORY` = 'Food' ORDER BY `POST_DATETIME` DESC ";
$active_button = "food";
}
else if($_POST['filter_category'] == "Non-Food")
{
$query = "SELECT * FROM `post` WHERE `POST_CATEGORY` = 'Non-Food' ORDER BY `POST_DATETIME` DESC ";
$active_button = "nonfood";
}
}
unset($_POST['filter_category']);
$result = mysqli_query($conn, $query);
$number_of_rows = mysqli_num_rows($result);
$number_of_flex_rows = intdiv($number_of_rows, $column_per_rows) + 1;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<style>html{visibility: hidden;opacity:0;}</style>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/x-icon" href="https://64.media.tumblr.com/34d27d0e919fd4a61946def0c6659b63/tumblr_inline_mgfxr4hoqm1roozkr.gif">
<link rel="stylesheet" href="aliff-styles.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src='https://kit.fontawesome.com/a076d05399.js' crossorigin='anonymous'></script>
<script src="jquery-3.6.0.js"></script>
<script src="home.js"></script>
<title>Rizqi | Feed</title>
</head>
<body>
<!-- Report Modal Popup Start -->
<div class="report-modal-popup-container" id="report-overlay">
<div class="report-form-panel">
<button id="report-form-panel-close-button">X</button>
<div class="report-form-panel-title">Report Form</div>
<br>
<form method="post" action="" id="report-form">
<input type="hidden" id="reporting_post_id" name="reporting_post_id" value="">
<label for="report-category-select-menu">Category:</label>
<select id="report-category-select-menu" name="report_category">
<option value="Dangerous Or Illegal Items">Dangerous Or Illegal Items</option>
<option value="Violent Or Inappropriate">Violent Or Inappropriate</option>
<option value="Dangerous Substances">Dangerous Substances</option>
<option value="Fraud">Fraud</option>
<option value="Spam">Spam</option>
<option value="Other">Other</option>
</select>
<br><br>
<label for="report-description-textarea">Description:</label>
<textarea name="report_description" class="report-description-textarea"></textarea>
<br>
<input type="submit" value="Submit" name="submit-report">
</form>
</div>
</div>
<!-- Report Modal Popup End -->
<!-- Header Start -->
<header id="header">
<h4 class="logo">Rizqi <i class="fa fa-handshake-o"></i></h4>
<nav id="nav">
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="createpost.php">Post</a></li>
<li><a href="profileinfo.php">My Profile</a></li>
<li><a href="logout.php" class="button" style="text-decoration: none;">Logout</a></li>
</ul>
</nav>
</header>
<!-- Header End -->
<div class="feed-page-wrapper">
<!-- Page Title Start -->
<section id="banner">
<div class="feed-title-container">
<span class="feed-title">Items Feed</span>
</div>
<!-- Page Title End -->
<!-- Filter Buttons Container Start -->
<div class="filter-buttons-container">
<form action = "" method="post">
<input type="submit" value="All" class="filter-button" id="all-button" name="filter_category"></input>
</form>
<form action = "" method="post">
<input type="submit" value="Food" class="filter-button" id="food-button" name="filter_category"></input>
</form>
<form action = "" method="post">
<input type="submit" value="Non-Food" class="filter-button" id="nonfood-button" name="filter_category"></input>
</form>
</div>
</section>
<!-- Filter Buttons Container End -->
<!-- Active Filter Buttons Script Start-->
<?php
if($active_button == "all")
{
echo("
<script>
document.getElementById('all-button').classList.add('active-button');
</script>
");
}
else if($active_button == "food")
{
echo("
<script>
document.getElementById('food-button').classList.add('active-button');
</script>
");
}
if($active_button == "nonfood")
{
echo("
<script>
document.getElementById('nonfood-button').classList.add('active-button');
</script>
");
}
?>
<!-- Active Filter Buttons Script End -->
<!-- Feed Flex Row Start -->
<?php
$current_flex_row_number = 0;
$current_column_number = 0;
for($current_flex_row_number; $current_flex_row_number < $number_of_flex_rows; $current_flex_row_number++)
{
?>
<div class="feed-item-row-container">
<?php
while($row = mysqli_fetch_assoc($result))
{
?>
<!-- Feed Item Start -->
<div class="feed-item-container">
<div class="feed-item-image-container">
<?php echo ('<img src="data:image/png;base64,'.base64_encode($row['POST_PICTURE']).'" class="feed-item-picture"/>'); ?>
</div>
<!-- Below Section Start -->
<div class="feed-item-below-section-container">
<div class="feed-item-name">
<?php
echo $row["POST_ITEM_NAME"];
?>
</div>
<br>
<div class="feed-item-quantity" style="font-size:20px">
<i class='fa fa-plus-square' style='font-size:20px;color:#191035'></i> <?php
echo $row['POST_QUANTITY'];
?> Left
</div>
<div class="feed-item-location" style="font-size:20px">
<i class="fa fa-map-pin" style="font-size:20px; color: #191035;"></i> <?php
echo $row['POST_LOCATION'];
?>
</div>
<div class="feed-item-description" style="font-size:20px">
<i class='fa fa-info-circle' style='font-size:20px;color:#191035'></i> <?php
echo $row['POST_DESCRIPTION'];
?>
</div>
<?php
$current_user_id = $row['USER_ID'];
$user_query = "SELECT `USER_NAME`, `USER_EMAIL`, `USER_PHONE_NUMBER`, `USER_PICTURE` FROM `user` WHERE USER_ID = $current_user_id;";
$user_result = mysqli_query($conn, $user_query);
if (!$user_result)
{
echo("Error performing MySQL query.");
}
$user_result_row = mysqli_fetch_assoc($user_result);
?>
<br>
<div class="feed-item-user-profile-picture-container">
<?php echo ('<img src="data:image/png;base64,'.base64_encode($user_result_row['USER_PICTURE']).'" class="feed-item-user-profile-picture"/>'); ?>
</div>
<div class="feed-item-username">
<?php
echo $user_result_row['USER_NAME'];
?>
</div>
<div class="feed-item-user-email">
<?php
echo $user_result_row['USER_EMAIL'];
?>
</div>
<br>
<div class="feed-item-interaction-buttons-container">
<a href="https://wa.me/<?php echo($user_result_row['USER_PHONE_NUMBER']); ?>" target="_blank">
<button class="contact">
Contact Me
</button>
</a>
<button class="report" post_id="<?php echo($row['POST_ID']) ?>">Report</button>
</div>
<br>
<div class="feed-item-time-elapsed">
<?php
$post_date = new DateTime($row["POST_DATETIME"]);
$current_date = new DateTime();
$time_difference = $current_date->diff($post_date);
echo("Posted " . $time_difference->format('%m Months %d Days %H Hours %i Minutes %s Seconds ') . "ago.");
?>
</div>
</div>
<!-- Below Section End -->
</div>
<!-- Feed Item End -->
<?php
$current_column_number++;
if($current_column_number == $column_per_rows)
{
break;
}
}
?>
</div>
<!-- Feed Flex Row End -->
<?php
$current_column_number = 0;
}
?>
</div>
<br>
<!-- Page Wrapper End -->
<footer id="footer">
<ul class="copyright">
<li>© Rizqi. All rights reserved.</li>
</ul>
<br>
<ul class="icons">
<li><a href="https://github.com/teohsinyee/Rizqi-SDGs-Solution" ><span class="label">Github</span></a></li>
</ul><br>
</footer>
</body>
</html>