-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpropertyDetails.php
252 lines (214 loc) · 8.81 KB
/
propertyDetails.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
<?php include('session.php'); ?>
<?php include("config.php"); ?>
<?php
if($_SERVER["REQUEST_METHOD"] == "POST") {
// username and password sent from form
if(!isset($_POST['date'])) {
$sql = "INSERT INTO Visit (Username, PropertyID, Rating) VALUES ('" . $_SESSION['login_user'] . "', '" . $_POST['id']. "', '" . $_POST['rating'] . "')";
$result = mysqli_query($db,$sql);
if($result == true) {
echo "<script type='text/javascript'>if(!alert(\"Successfully logged visit\")) document.location = 'visitHistory.php';</script>";
} else {
echo "<script type='text/javascript'>if(!alert(\"Error: Could not log visit\")) document.location = 'visitHistory.php';</script>";
}
} else {
$sql = "DELETE FROM `Visit` WHERE Username = '" . $_SESSION['login_user'] . "' AND PropertyID = '" . $_POST['id']. "'";
$result = mysqli_query($db,$sql);
if($result == true) {
echo "<script type='text/javascript'>if(!alert(\"Successfully un-logged visit\")) document.location = 'visitHistory.php';</script>";
} else {
echo "<script type='text/javascript'>alert('Error: Could not un-log visit');</script>";
}
}
}
?>
<?php
$findpropertywithID = mysqli_query($db, "SELECT * FROM Property WHERE ID = '" . $_GET['id'] . "'");
$foundproperty = mysqli_fetch_array($findpropertywithID);
$count = mysqli_num_rows($findpropertywithID);
if($count == 1) {
$ownerresult = mysqli_query($db, "SELECT * FROM User WHERE Username = '" . $foundproperty['Owner'] . "'");
$foundOwner = mysqli_fetch_array($ownerresult);
$visitresult = mysqli_query($db, "SELECT COUNT(*), AVG(Rating) FROM Visit WHERE PropertyID = '" . $foundproperty['ID'] . "'");
$visitrow = mysqli_fetch_array($visitresult);
$cropsresult = mysqli_query($db, "SELECT * FROM Has WHERE PropertyID = '" . $foundproperty['ID'] . "' AND ItemName NOT IN (SELECT Name FROM FarmItem WHERE Type = 'ANIMAL')");
$animalresult = mysqli_query($db, "SELECT * FROM Has WHERE PropertyID = '" . $foundproperty['ID'] . "' AND ItemName IN (SELECT Name FROM FarmItem WHERE Type = 'ANIMAL')");
$userhasvisited = false;
if($_SESSION['user_type'] == "VISITOR") {
$userhasvisitresult = mysqli_query($db, "SELECT * FROM Visit WHERE Username = '" . $_SESSION['login_user'] . "' AND PropertyID = '" . $foundproperty['ID']. "'");
$userhasvisited = (mysqli_num_rows($userhasvisitresult) == 1);
}
} else {
echo "<script type='text/javascript'>if(!alert(\"Could not find property\")) document.location = 'index.php';</script>";
}
?>
<!DOCTYPE html>
<html lang="en">
<?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>Property Details</h4>
<br>
</div>
</div> <!-- End Row -->
<div class ="row">
<div class = "col-md-4 offset-md-4">
<table class="table table-condensed table-sm table-striped sortable">
<thead>
</thead>
<tbody>
<tr>
<th>Name</th>
<td><?php echo $foundproperty['Name']; ?></td>
</tr>
<tr>
<th>Owner</th>
<td><?php echo $foundproperty['Owner']; ?></td>
</tr>
<tr>
<th>Owner Email</th>
<td><?php echo $foundOwner['Email']; ?></td>
</tr>
<tr>
<th>Visits</th>
<td><?php echo $visitrow['COUNT(*)']; ?></td>
</tr>
<tr>
<th>Street</th>
<td><?php echo $foundproperty['Street']; ?></td>
</tr>
<tr>
<th>City</th>
<td><?php echo $foundproperty['City']; ?></td>
</tr>
<tr>
<th>Zip</th>
<td><?php echo $foundproperty['Zip']; ?></td>
</tr>
<tr>
<th>Size (acres)</th>
<td><?php echo $foundproperty['Size']; ?></td>
</tr>
<tr>
<th>Avg Rating</th>
<td><?php echo $visitrow['AVG(Rating)']; ?></td>
</tr>
<tr>
<th>Type</th>
<td><?php echo $foundproperty['PropertyType']; ?></td>
</tr>
<tr>
<th>Public</th>
<td><?php if ($foundproperty['IsPublic'] == "0") {
echo "No";
} else {
echo "Yes";
} ?>
</td>
</tr>
<tr>
<th>Commercial</th>
<td><?php if ($foundproperty['IsCommercial'] == "0") {
echo "No";
} else {
echo "Yes";
} ?>
</td>
</tr>
<tr>
<th>ID</th>
<td><?php echo $foundproperty['ID']; ?></td>
</tr>
<tr>
<th>Crops</th>
<td><?php while ($row = mysqli_fetch_array($cropsresult))
echo $row["ItemName"] . " ";
?></td>
</tr>
<tr>
<th>Animals</th>
<td><?php while ($row = mysqli_fetch_array($animalresult))
echo $row["ItemName"] . " ";
?></td>
</tr>
</tbody>
</table>
</div> <!-- End Column -->
</div> <!-- End Row -->
<div class ="row">
<div class="col-md-12">
<?php if(!$userhasvisited && $_SESSION['user_type'] == 'VISITOR') { ?>
<form class="form-horizontal" action='propertyDetails.php' method='post'>
<input type="hidden" name="id" value=<?php echo "\"" . $foundproperty['ID'] . "\""; ?>>
<fieldset>
<div class ="row">
<div class = "col-md-4 offset-md-4">
<table class="table table-condensed table-sm sortable">
<thead>
</thead>
<tbody>
<tr>
<th>Rate Visit</th>
<td>
<div class="col-md-12">
<select id="rating" name="rating" class="form-control">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</div>
</td>
</tr>
</tbody>
</table>
<br> <br>
</div> <!-- End Column -->
</div> <!-- End Row -->
<div class="row">
<div class="col-md-3 offset-md-3">
<a><button class="btn btn-success style-bkg" style="width: 100%;"> Log Visit</button></a>
</div>
<!-- Uncomment and use this for the unlogging case
<div class="col-md-3 offset-md-3">
<a href="ownerDashboard.php"><button class="btn btn-success style-bkg" style="width: 100%;">✘ Un-Log Visit</button></a>
</div>
-->
<div class="col-md-3">
<a href="index.php"><div class="btn btn-secondary" style="width: 100%;">Back</div></a>
</div>
</div>
</fieldset>
</form>
<?php } else if($userhasvisited && $_SESSION['user_type'] == 'VISITOR') { ?>
<form class="form-horizontal" action='propertyDetails.php' method='post'>
<input type="hidden" name="id" value=<?php echo "\"" . $foundproperty['ID'] . "\""; ?>>
<input type="hidden" name="date" value=<?php echo "\"" . $_GET['date'] . "\""; ?>>
<div class="row">
<div class="col-md-3 offset-md-3">
<a><button class="btn btn-success style-bkg" style="width: 100%;">✘ Un-Log Visit</button></a>
</div>
<div class="col-md-3">
<a href="visitHistory.php"><div class="btn btn-secondary" style="width: 100%;">Back</div></a>
</div>
</div>
</form>
<?php } else { ?>
<div class="row">
<div class="col-md-4 offset-md-4">
<a href="index.php"><div class="btn btn-secondary" style="width: 100%;">Back</div></a>
</div>
</div>
<?php } ?>
</div> <!-- End Column -->
</div> <!-- End Row -->
<br> <br>
</div> <!-- End Container -->
</section>
</body>
</html>