-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathownerDashboard.php
360 lines (295 loc) · 14.8 KB
/
ownerDashboard.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
360
<?php include('session.php'); ?>
<?php
if($_SESSION['user_type'] != "OWNER") {
header("Location: index.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<?php include("config.php"); ?>
<?php include("head.php"); ?>
<body>
<?php include("navbar.php"); ?>
<section>
<div class="container">
<div class="row text-center title-space">
<div class="col-md-12">
<h4>Welcome <b><?php echo($_SESSION['login_user']); ?></b> </h4>
</div>
</div> <!-- End Row -->
<div class ="row">
<div class = "col-md-12">
<h6>Your Properties</h6>
<div class ="row">
<div class = "col-md-12">
<div class="text-center">
<button class="btn btn-primary style-bkg" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
🔍 Search Table
</button>
</div>
<div class="collapse" id="collapseExample">
<form class="form-horizontal" action="ownerDashboard.php" method = "GET">
<fieldset>
<br>
<input id="SEARCH" name="SEARCH" value="true" type = "hidden">
<div class="row rowspace">
<!-- Select Basic -->
<div class="col-md-2 offset-md-3">
<p>Search Name</p>
</div>
<!-- Search input-->
<div class="col-md-4">
<input id="inputName" name="inputName" type="search" placeholder="Search Name" class="form-control input-md">
</div>
</div> <!-- End Row -->
<div class="row rowspace">
<!-- Select Basic -->
<div class="col-md-2 offset-md-3">
<p>Search Street</p>
</div>
<!-- Search input-->
<div class="col-md-4">
<input id="inputStreet" name="inputStreet" type="search" placeholder="Search Street" class="form-control input-md">
</div>
</div> <!-- End Row -->
<div class="row rowspace">
<!-- Select Basic -->
<div class="col-md-2 offset-md-3">
<p>Search City</p>
</div>
<!-- Search input-->
<div class="col-md-4">
<input id="inputCity" name="inputCity" type="search" placeholder="Search City" class="form-control input-md">
</div>
</div> <!-- End Row -->
<div class="row rowspace">
<!-- Select Basic -->
<div class="col-md-2 offset-md-3">
<p>Search Zip</p>
</div>
<!-- Search input-->
<div class="col-md-4">
<input id="searchZip" name="searchZip" type="search" placeholder="Search Zip" class="form-control input-md">
</div>
</div> <!-- End Row -->
<div class="row rowspace">
<!-- Select Basic -->
<div class="col-md-2 offset-md-3">
<p>Search ID</p>
</div>
<!-- Search input-->
<div class="col-md-2">
<input id="searchIdFrom" name="searchIdFrom" type="search" placeholder="Start Value" class="form-control input-md">
</div>
<!-- Search input-->
<div class="col-md-2">
<input id="searchIdTo" name="searchIdTo" type="search" placeholder="End Value" class="form-control input-md">
</div>
</div> <!-- End Row -->
<div class="row rowspace">
<!-- Select Basic -->
<div class="col-md-2 offset-md-3">
<p>Search Visits</p>
</div>
<!-- Search input-->
<div class="col-md-2">
<input id="searchVisitsFrom" name="searchVisitsFrom" type="search" placeholder="Start Value" class="form-control input-md">
</div>
<!-- Search input-->
<div class="col-md-2">
<input id="searchVisitsTo" name="searchVisitsTo" type="search" placeholder="End Value" class="form-control input-md">
</div>
</div> <!-- End Row -->
<div class="row rowspace">
<!-- Select Basic -->
<div class="col-md-2 offset-md-3">
<p>Search Rating</p>
</div>
<!-- Search input-->
<div class="col-md-2">
<input id="searchRatsingFrom" name="searchRatingFrom" type="search" placeholder="Start Value" class="form-control input-md">
</div>
<!-- Search input-->
<div class="col-md-2">
<input id="searchRatingTo" name="searchRatingTo" type="search" placeholder="End Value" class="form-control input-md">
</div>
</div> <!-- End Row -->
<div class="row rowspace">
<!-- Select Basic -->
<div class="col-md-2 offset-md-3">
<p>Search Size</p>
</div>
<!-- Search input-->
<div class="col-md-2">
<input id="searchSizeFrom" name="searchSizeFrom" type="search" placeholder="Start Value" class="form-control input-md">
</div>
<!-- Search input-->
<div class="col-md-2">
<input id="searchSizeTo" name="searchSizeTo" type="search" placeholder="End Value" class="form-control input-md">
</div>
</div> <!-- End Row -->
<div class="row rowspace">
<div class="col-md-2 offset-md-3">
<select id="isPublic" name="isPublic" class="form-control">
<option value="2">Public?</option>
<option value="1">True</option>
<option value="0">False</option>
</select>
</div>
<div class="col-md-2">
<select id="isCommercial" name="isCommercial" class="form-control">
<option value="2">Commercial?</option>
<option value="1">True</option>
<option value="0">False</option>
</select>
</div>
<div class="col-md-2">
<select id="PropertyType" name="PropertyType" class="form-control">
<option value="0">Type?</option>
<option value="GARDEN">Garden</option>
<option value="ORCHARD">Orchard</option>
<option value="FARM">Farm</option>
</select>
</div>
<div class="col-md-2">
<select id="isApproved" name="isApproved" class="form-control">
<option value="2">Valid?</option>
<option value="1">True</option>
<option value="0">False</option>
</select>
</div>
</div> <!-- End Row --> <br>
<div class="row">
<!-- Submit Button -->
<div class="col-md-6 offset-md-5">
<input class="btn btn-primary style-bkg btn-md" type="submit" width="100%" value="Search Properties">
</div>
</div>
</fieldset>
</form>
</div> <!-- End Collapse Example -->
</div> <!-- End Column -->
</div> <!-- End Row -->
<br>
<div class ="row">
<div class = "col-md-12">
<div class="property-table table-scroll">
<table class="table table-striped table-sm sortable" id="people">
<thead class="thead-dark">
<tr>
<th scope="col">Manage</th>
<th scope="col">Name</th>
<th scope="col">Street</th>
<th scope="col">City</th>
<th scope="col">Zip</th>
<th scope="col">Size</th>
<th scope="col">Type</th>
<th scope="col">Public</th>
<th scope="col">Commercial</th>
<th scope="col">  ID</th>
<th scope="col">Valid</th>
<th scope="col">Visits</th>
<th scope="col">Rating</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM Property WHERE Owner = '" . $_SESSION['login_user'] . "'";
if (isset($_GET['SEARCH'])) {
if (isset($_GET['inputName']) && $_GET['inputName'] != NULL) {
$query .= " AND Name LIKE '%" . mysqli_real_escape_string($db, $_GET['inputName']) . "%'";
}
if (isset($_GET['inputCity']) && $_GET['inputCity'] != NULL) {
$query .= " AND City LIKE '%" . mysqli_real_escape_string($db, $_GET['inputCity']) . "%'";
}
if (isset($_GET['inputStreet']) && $_GET['inputStreet'] != NULL) {
$query .= " AND Street LIKE '%" . mysqli_real_escape_string($db, $_GET['inputStreet']) . "%'";
}
if (isset($_GET['isApproved']) && $_GET['isApproved'] != 2) {
if ($_GET['isApproved'] == 1) {
$query .= " AND ApprovedBy IS NOT NULL";
} else {
$query .= " AND ApprovedBy IS NULL";
}
}
if ($_GET['isCommercial'] != 2) {
$query .= " AND isCommercial = " . $_GET['isCommercial'];
}
if ($_GET['isPublic'] != 2) {
$query .= " AND isPublic = " . $_GET['isPublic'];
}
if ($_GET['PropertyType'] != '0') {
$query .= " AND PropertyType = '" . $_GET['PropertyType'] . "'";
}
if (isset($_GET['searchZip']) && $_GET['searchZip'] != NULL) {
$query .= " AND Zip = " . mysqli_real_escape_string($db, $_GET['searchZip']);
}
if (isset($_GET['searchSizeFrom']) && $_GET['searchSizeFrom'] != NULL) {
$sizeto = mysqli_real_escape_string($db, (isset($_GET['searchSizeTo']) && $_GET['searchSizeTo'] != NULL) ? $_GET['searchSizeTo'] : $_GET['searchSizeFrom']);
$query .= " AND Size >= " . mysqli_real_escape_string($db, $_GET['searchSizeFrom']) . " AND Size <= " . $sizeto;
}
if (isset($_GET['searchIdFrom']) && $_GET['searchIdFrom'] != NULL) {
$idto = mysqli_real_escape_string($db, (isset($_GET['searchIdTo']) && $_GET['searchIdTo'] != NULL) ? $_GET['searchIdTo'] : $_GET['searchIdFrom']);
$query .= " AND ID >= " . mysqli_real_escape_string($db, $_GET['searchIdFrom']) . " AND ID <= " . $idto;
}
if (isset($_GET['searchVisitsFrom']) && $_GET['searchVisitsFrom'] != NULL) {
$visitto = mysqli_real_escape_string($db, (isset($_GET['searchVisitsTo']) && $_GET['searchVisitsTo'] != NULL) ? $_GET['searchVisitsTo'] : $_GET['searchVisitFrom']);
if ($_GET['searchVisitFrom'] <= 0 && $visitto >= 0) {
$query .= " AND ID NOT IN (SELECT PropertyID as ID FROM Visit GROUP BY PropertyID HAVING COUNT(PropertyID) < " . mysqli_real_escape_string($db, $_GET['searchVisitsFrom']) . " OR COUNT(PropertyID) > " . $visitto . ")";
} else {
$query .= " AND ID IN (SELECT PropertyID as ID FROM Visit GROUP BY PropertyID HAVING COUNT(PropertyID) >= " . mysqli_real_escape_string($db, $_GET['searchVisitsFrom']) . " AND COUNT(PropertyID) <= " . $visitto . ")";
}
}
if (isset($_GET['searchRatingFrom']) && $_GET['searchRatingFrom'] != NULL) {
$ratingto = mysqli_real_escape_string($db, (isset($_GET['searchRatingTo']) && $_GET['searchRatingsTo'] != NULL) ? $_GET['searchRatingTo'] : $_GET['searchRatingFrom']);
$query .= " AND ID IN (SELECT PropertyID as ID FROM Visit GROUP BY PropertyID HAVING AVG(Rating) >= " . mysqli_real_escape_string($db, $_GET['searchRatingFrom']) . " AND AVG(Rating) <= " . $ratingto . ")";
}
}
$query .= " ORDER BY Name";
//echo "<br>" . $query . "<br>";
$result = mysqli_query($db, $query);
while ($row = mysqli_fetch_array($result)) {?>
<tr>
<th scope="row"><a href=<?php echo "manageProperty.php?id=" . $row['ID'];?>>Edit</a></th>
<td class="link-color"><a href=<?php echo "propertyDetails.php?id=" . $row['ID'];?>><?php echo $row['Name'];?></a></td>
<td><?php echo $row['Street'];?></td>
<td><?php echo $row['City'];?></td>
<td><?php echo $row['Zip'];?></td>
<td><?php echo $row['Size'];?></td>
<td><?php echo $row['PropertyType'];?></td>
<td><?php if ($row['IsPublic'] == "0") {
echo "No";
} else {
echo "Yes";
} ?>
</td>
<td><?php if ($row['IsCommercial'] == "0") {
echo "No";
} else {
echo "Yes";
} ?>
</td>
<td><?php echo $row['ID'];?></td>
<td><?php if ($row['ApprovedBy'] == NULL) {
echo "False";
} else {
echo "True";
} ?>
</td>
<td><?php
$visitsql = "SELECT COUNT(*), AVG(Rating) FROM Visit WHERE PropertyID = '" . $row['ID'] . "'";
$visitresult = mysqli_query($db, $visitsql);
$visitrow = mysqli_fetch_array($visitresult);
echo $visitrow['COUNT(*)'];?></td>
<td><?php echo $visitrow["AVG(Rating)"];?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div> <!-- End Property Table Wrapper -->
</div> <!-- End Column -->
</div> <!-- End Row -->
</div> <!-- End Container -->
</section>
</body>
</html>