-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.php
223 lines (201 loc) · 8.5 KB
/
home.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
<?php
session_start();
if (!isset($_SESSION['UserID'])) {
header("Location:UserLogin/Login.php");
}
include "ban_check.php";
?>
<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">
<script src="https://kit.fontawesome.com/cee0f4dddc.js" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro&display=swap" rel="stylesheet">
<link href="Assets/css/home.css" rel="stylesheet">
<title>Home</title>
</head>
<body class="body-ssp-fb">
<?php
include "navbar_user.php";
function getPath($UserID)
{
$path = "profile_picture.png";
if (file_exists("ProfilePictures/$UserID/")) {
$files = scandir("ProfilePictures/$UserID/", 1);
if (sizeof($files) > 2) {
$path = "ProfilePictures/$UserID/$files[0]";
}
}
return $path;
}
?>
<div class="container-fluid">
<div class="row">
<div class="col-3 sticky-pane">
<div class="container-fluid mt-p-10-5 container-fitter shadow">
<form action="#" method="post" id="search_form">
<div class="form-group" id="input_fields">
<label for="keyword">Details Keyword:</label>
<input type="text" id="keyword" name="" class="form-control bottom-input">
<label for="minBudget">Minimum Budget:</label>
<input type="number" id="minBudget" name="" class="form-control bottom-input">
<label for="maxBudget">Maximum Budget:</label>
<input type="number" id="maxBudget" name="" class="form-control bottom-input">
<label for="location">Location:</label>
<input type="text" id="location" name="" class="form-control bottom-input">
<label for="startTime">Starts after:</label>
<input type="datetime-local" id="startTime" name="startTime" class="form-control">
<label for="endTime">Ends before:</label>
<input type="datetime-local" id="endTime" name="endTime" class="form-control">
</div>
<button type="button" id="filter" class="btn btn-primary form-control my-2" name="filter">Filter Posts</button>
</form>
</div>
</div>
<div class="col-6" id="post-column">
<?php
$currID = $_SESSION['UserID'];
$conn = mysqli_connect("localhost", "root", "", "TravellingBuddy");
$query = "SELECT user.UserID, user.UserName, posts.postID, posts.posterID, posts.location, posts.budget, posts.description, posts.startingTime, posts.endingTime, tempVotes.voteCount" .
" FROM user" .
" RIGHT JOIN posts ON user.UserID = posts.posterID" .
" LEFT JOIN (SELECT SUM(voteStatus) as voteCount, postID FROM votes GROUP BY(postID)) AS tempVotes ON posts.postID = tempVotes.postID ORDER BY posts.postID DESC";
$result = mysqli_query($conn, $query);
if (mysqli_num_rows($result) > 0) {
while ($userPost = mysqli_fetch_assoc($result)) {
include "Model/post_view.php";
}
}
?>
</div>
<div class="col-3">
<div class="container-fitter container-fluid shadow" id="join-column">
</div>
</div>
</div>
</div>
<?php
include "Assets/api/post_calls.php";
?>
<script src=" https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous">
</script>
<script src="Assets/scripts/post_function.js"></script>
<script>
function loadRequests() {
$.ajax({
type: 'post',
url: "Assets/api/load_requests.php",
success: function(data) {
document.getElementById("join-column").innerHTML = data;
}
})
}
$(document).ready(function() {
loadRequests();
});
var btnFilter = document.getElementById("filter");
btnFilter.addEventListener("click", reloadPosts)
function reloadPosts() {
var keyword = document.getElementById("keyword").value;
var minBudget = document.getElementById("minBudget").value;
var maxBudget = document.getElementById("maxBudget").value;
var location = document.getElementById("location").value;
var startTime = document.getElementById("startTime").value;
var endTime = document.getElementById("endTime").value;
keyword = '%' + keyword + '%';
if (minBudget.trim().length == 0) {
minBudget = 0;
}
if (maxBudget.trim().length == 0) {
maxBudget = 9999999;
}
if (minBudget > maxBudget) {
alert("Minimum budget can't be lower than maximum budget!");
}
location = '%' + location + '%';
if (startTime > endTime) {
alert("Can't start something after it ends!");
}
if (startTime.trim().length == 0) {
startTime = "1000-01-01 00:00:00"
}
if (endTime.trim().length == 0) {
endTime = "9999-12-31 11:59:59"
}
var extraQuery = "WHERE description LIKE '" + keyword + "' AND budget >= " + minBudget +
" AND budget <= " + maxBudget + " AND location LIKE '" + location + "' AND startingTime >= '" +
startTime.replace('T', ' ') + "' AND endingTime <= '" +
endTime.replace('T', ' ') + "'";
document.getElementById("post-column").innerHTML = "";
$.ajax({
type: 'POST',
url: "Assets/api/load_posts.php",
data: {
task: "UPDATE_POST",
extraQuery: extraQuery
},
success: function(data) {
document.getElementById("post-column").innerHTML = data;
}
});
}
function acceptUser(userID, postID) {
$.ajax({
type: 'POST',
url: "Assets/api/manage_requests.php",
data: {
task: 'ACCEPT',
userID: userID,
postID: postID
},
success: function(data) {
if (data == 1) {
loadRequests();
}
}
});
$.ajax({
type: 'POST',
url: "Assets/api/manage_notification.php",
data: {
task: 'MAKE',
postID: postID,
userID: userID,
about: 'ACCEPT'
}
});
}
function rejectUser(userID, postID) {
$.ajax({
type: 'POST',
url: "Assets/api/manage_requests.php",
data: {
task: 'REJECT',
userID: userID,
postID: postID
},
success: function(data) {
if (data == 1) {
loadRequests();
}
}
});
$.ajax({
type: 'POST',
url: "Assets/api/manage_notification.php",
data: {
task: 'MAKE',
postID: postID,
userID: userID,
about: 'REJECT'
}
});
}
</script>
</body>
</html>