-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuy.php
551 lines (515 loc) · 31.2 KB
/
buy.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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
<?php
session_start();
require './components/runSQLQuery.php';
require './components/setAlertFn.php';
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "easyhomes";
$conn = mysqli_connect($servername, $username, $password, $dbname, 3306);
?>
<?php
if(!empty($_POST['more']))
{
$_SESSION['property_id']=$_POST['more'];
header('location:property.php');
}
?>
<html>
<head>
<title>
Buy Property
</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php require './components/bootstrapcss.php' ?>
<style>
.landing {
min-height: 90vh;
}
.custImg {
width: 100%;
height: 200px;
object-fit: cover;
}
@media screen and (max-width: 768px) {
body > section.buy.py-5 > div > form > div > div:nth-child(2) > h3:nth-child(1) {
padding-top: 1rem;
}
}
</style>
<?php
require './components/showdownjs.php';
?>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBimqJizKom7LcizcvUdr-BGGq8dHEtCbE"></script>
<script>
let coords = [];
var position = [15.496596, 73.835353];
</script>
<?php
if($_SERVER['REQUEST_METHOD'] == 'GET') {
$lat = 0;
$lng = 0;
if(isset($_GET['latitude']))
$lat = floatval($_GET['latitude']);
if(isset($_GET['longitude']))
$lng = floatval($_GET['longitude']);
if($lat == 0 && $lng == 0) {
$lat = 15.496596;
$lng = 73.835353;
}
echo "<script>position = [$lat, $lng];</script>";
$lat_limits = [$lat-0.005, $lat+0.005];
$lng_limits = [$lng-0.005, $lng+0.005];
if(!isset($_SESSION['logged_id']))
{
$output = sql_query($conn, "SELECT * from property WHERE (latitude BETWEEN " . implode(' AND ', $lat_limits) . ") AND (longitude BETWEEN " . implode(' AND ', $lng_limits) . ")");
// $get=mysqli_query($conn,"Select * from property");
}
else
{
$user_id=$_SESSION['logged_id'];
// $get=sql_query($conn,"SELECT * from property WHERE property_id IN (SELECT distinct property_id from user_owns WHERE user_id!=$user_id)");
$output = sql_query($conn, "SELECT * from property WHERE property_id IN (SELECT DISTINCT property_id FROM user_owns WHERE user_id!=$user_id) AND (latitude BETWEEN " . implode(' AND ', $lat_limits) . ") AND (longitude BETWEEN " . implode(' AND ', $lng_limits) . ")");
}
while($row = $output->fetch_assoc()) {
// echo $row['property_id'] . '<br>';
$id = $row['property_id'];
$row_lat = $row['latitude'];
$row_lng = $row['longitude'];
echo "<script>coords.push([$row_lat, $row_lng, '$id'])</script>";
}
$_SESSION['output'] = $output;
}
?>
<script>
function initialize() {
var latlng = new google.maps.LatLng(position[0], position[1]);
const svgMarker = {
path: "M10.453 14.016l6.563-6.609-1.406-1.406-5.156 5.203-2.063-2.109-1.406 1.406zM12 2.016q2.906 0 4.945 2.039t2.039 4.945q0 1.453-0.727 3.328t-1.758 3.516-2.039 3.070-1.711 2.273l-0.75 0.797q-0.281-0.328-0.75-0.867t-1.688-2.156-2.133-3.141-1.664-3.445-0.75-3.375q0-2.906 2.039-4.945t4.945-2.039z",
fillColor: "green",
fillOpacity: 0.6,
strokeWeight: 0,
rotation: 0,
scale: 2,
anchor: new google.maps.Point(15, 30),
};
var myOptions = {
zoom: 16,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("mapCanvas"), myOptions);
marker = new google.maps.Marker({
position: latlng,
map: map,
title: "Latitude:"+position[0]+" | Longitude:"+position[1]
});
console.log(coords);
coords.forEach(coordinate => {
let latlng = new google.maps.LatLng(coordinate[0], coordinate[1]);
let marker = new google.maps.Marker({
position: latlng,
map: map,
title: "Property ID: " + coordinate[2],
icon: svgMarker
});
})
google.maps.event.addListener(map, 'click', function(event) {
var result = [event.latLng.lat(), event.latLng.lng()];
transition(result);
});
}
//Load google map
google.maps.event.addDomListener(window, 'load', initialize);
var numDeltas = 100;
var delay = 10; //milliseconds
var i = 0;
var deltaLat;
var deltaLng;
function transition(result){
i = 0;
deltaLat = (result[0] - position[0])/numDeltas;
deltaLng = (result[1] - position[1])/numDeltas;
moveMarker();
}
function moveMarker(){
position[0] += deltaLat;
position[1] += deltaLng;
var latlng = new google.maps.LatLng(position[0], position[1]);
marker.setTitle("Latitude:"+position[0]+" | Longitude:"+position[1]);
marker.setPosition(latlng);
document.querySelector("#latitude").value=position[0];
document.querySelector("#longitude").value=position[1];
if(i!=numDeltas){
i++;
setTimeout(moveMarker, delay);
}
}
</script>
<style>
#mapCanvas {
width: 95vw;
height: 95vw;
max-width: 500px;
max-height: 500px;
/* margin: 2rem; */
padding: 1rem;
}
</style>
</head>
<body>
<?php
require './components/navbar.php';
function validate($row, $minPrice, $maxPrice, $minArea, $maxArea, $category, $for) {
GLOBAL $conn;
$pid = $row['property_id'];
if($row['category'] == 'none') {
return false;
}
if($row['category'] == 'sale' || $row['category'] == 'both') {
$price = sql_query($conn, "SELECT price from sale_price where property_id = $pid");
$price = $price->fetch_row()[0];
// print_r($price);
}
else {
$price = sql_query($conn, "SELECT rprice from rent_price where property_id = $pid");
$price = $price->fetch_row()[0];
// print_r($price);
}
if(mysqli_num_rows(sql_query($conn, "SELECT * FROM property WHERE category!='none' and property_id = $pid and property_id IN (SELECT property_id FROM flat)"))) {
$type = 'flat';
}
else if(mysqli_num_rows(sql_query($conn, "SELECT * FROM property WHERE category!='none' and property_id = $pid and property_id IN (SELECT property_id FROM house)"))) {
$type = 'house';
}
else {
$type = 'plot';
}
// echo $row['category'] == $category , $price <= $maxPrice , $price >= $minPrice , $row['area'] <= $maxArea , $row['area'] >= $minArea , $type == $for . "<br>";
// echo ($row['category'] == $category && $price <= $maxPrice && $price >= $minPrice && $row['area'] <= $maxArea && $row['area'] >= $minArea && $type == $for);
// echo $pid . "<br>";
// echo $row['category'] . "==" . $for . "<BR>";
// echo $price . "between" . $maxPrice . " and " . $minPrice . "<BR>";
// echo $row['area'] . "between" . $maxArea . " and " . $minArea . "<BR>";
// echo $type . "==" . $category . "<BR>";
// echo "<br>";
if($row['category'] == $for && $price <= $maxPrice && $price >= $minPrice && $row['area'] <= $maxArea && $row['area'] >= $minArea && $type == $category) {
// echo $row['pid'];
return true;
}
return false;
}
?>
<section class="landing py-4 px-2 bg-light d-flex align-items-center">
<div class="container">
<div class="row align-items-center justify-content-between">
<div class="col-12 col-md-5 py-2 order-2 order-md-1">
<h1>Want to shift to a new home?</h1>
<p class="lead">At EasyHomes, we know that homes are more than just bricks and cement. They are feelings. Be it properties for sale or on rent, you'll find it all, here. All the goodies, with the added security of EasyHomes.</p>
<button class="btn btn-primary btn-lg">List Property</button>
</div>
<div class="col-10 mx-auto col-md-6 my-4 order-1 order-md-2">
<img src='./media/housebg3.jpg' alt="" class="img-fluid">
</div>
</div>
</div>
</section>
<section class="buy py-5">
<div class="container">
<h1 class="mb-4">Search properties for Sale/Rent</h1>
<form action="#" class="mx-auto mt-2" method="get">
<div class="d-block d-md-flex align-items-center justify-content-between gap-0 gap-md-3">
<div id="mapCanvas" class="mx-auto"></div>
<div style="flex-grow: 1;">
<h3 class="pb-1">Your Location</h3>
<div class="input-group mb-3">
<label for="latitude" class="input-group-text">Latitude</label>
<input type="text" id="latitude" name="latitude" class="form-control" placeholder="Search for a nearby place or landmark">
</div>
<div class="input-group mb-3">
<label for="longitude" class="input-group-text">Longitude</label>
<input type="text" id="longitude" name="longitude" class="form-control" placeholder="Search for a nearby place or landmark">
</div>
<h3 class="pb-1">Filters</h3>
<div class="input-group mb-3">
<label class="input-group-text" for="category">Category</label>
<select class="form-select" name="category" id="category">
<option value="house">House</option>
<option value="flat">Flat</option>
<option value="plot">Plot</option>
</select>
<label for="for" class="input-group-text">For</label>
<select class="form-select" name="for" id="for">
<option value="sale">Sale</option>
<option value="rent">Rent</option>
<option value="both">Sale and Rent</option>
</select>
</div>
<div class="input-group mb-3">
<label for="areaMin" class="input-group-text">Area</label>
<input type="number" class="form-control" name="areaMin" id="areaMin">
<label for="areaMax" class="input-group-text">To</label>
<input type="number" class="form-control" name="areaMax" id="areaMax">
</div>
<div class="input-group mb-3">
<label for="priceMin" class="input-group-text">Price</label>
<input type="number" class="form-control" name="priceMin" id="priceMin">
<label for="priceMax" class="input-group-text">To</label>
<input type="number" class="form-control" name="priceMax" id="priceMax">
</div>
<input type="submit" value="Submit" class="btn btn-primary">
</div>
</div>
</form>
<div class="search-results">
<h2 class="my-4">Search Results</h2>
<div class="cards d-flex justify-content-center flex-wrap gap-3">
<?php
$get=$output;
mysqli_data_seek($get, 0);
$rows=mysqli_num_rows($get);
if($rows>0)
{
while ($row = $get->fetch_assoc())
{
$priceMin = -10000;
$priceMax = 100000000000;
$areaMin = -10000;
$areaMax = 100000000000;
$for = "sale";
$category = "house";
if(isset($_GET['priceMin']))
$priceMin = $_GET['priceMin']==''?-10000:$_GET['priceMin'];
if(isset($_GET['priceMax']))
$priceMax = $_GET['priceMax']==''?100000000000:$_GET['priceMax'];
if(isset($_GET['areaMin']))
$areaMin = $_GET['areaMin']==''?-10000:$_GET['areaMin'];
if(isset($_GET['areaMax']))
$areaMax = $_GET['areaMax']==''?100000000000:$_GET['areaMax'];
if(isset($_GET['for']))
$for = $_GET['for']==''?"sale":$_GET['for'];
if(isset($_GET['category']))
$category = $_GET['category']==''?"house":$_GET['category'];
if(!validate($row, $priceMin, $priceMax, $areaMin, $areaMax, $category, $for)) {
continue;
}
$id=$row['property_id'];
$head = str_replace("# ","",explode(PHP_EOL,$row['description'])[0]);
// var_dump(explode(PHP_EOL,$row['description']));
$images = $row['images'];
if($row['category']=="sale")
{
$for="For Sale";
$get_price=mysqli_query($conn,"SELECT price FROM sale_price WHERE property_id=$id");
$price=mysqli_fetch_assoc($get_price);
}
else if($row['category']=="rent")
{
$for="For Rent";
$get_price=mysqli_query($conn,"SELECT rprice FROM rent_price WHERE property_id=$id");
$price=mysqli_fetch_assoc($get_price);
}
else
{
$for="For Sale and Rent";
$get_price=mysqli_query($conn,"SELECT price FROM sale_price WHERE property_id=$id");
$get_rprice=mysqli_query($conn,"SELECT rprice FROM rent_price WHERE property_id=$id");
$price=mysqli_fetch_assoc($get_price);
$rprice=mysqli_fetch_assoc($get_rprice);
}
?>
<div class="card" style="width: 18rem;">
<div id="property<?php echo $row['property_id'] ?>Carousal" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-inner">
<?php
$imagesArr = explode(',', $images);
if($images=='') {
$img = './media/defaultProperty.jpg';
echo "<div class='carousel-item active'>
<img src='$img' class='card-img-top custImg' alt='...'>
</div>";
}
else
for($i=0; $i<count($imagesArr); $i++) {
$active = "";
if($i==0) {
$active = "active";
}
$img = $imagesArr[$i];
echo "<div class='carousel-item $active'>
<img src='$img' class='card-img-top custImg' alt='...'>
</div>";
}
?>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#property<?php echo $row['property_id'] ?>Carousal" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#property<?php echo $row['property_id'] ?>Carousal" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
<div class="card-body">
<h5 class="card-title"><?php echo $head; ?></h5>
<p class="card-text"><?php echo $row['description'] ?></p>
<p class="card-text price lead"><?php
// echo $row['price'];
// echo $for."<br>";
if($for=="For Sale")
{
echo "Price: ₹".$price['price'];
}
else if($for=="For Rent")
{
echo "Rent Per Month: ₹".$price['rprice'];
}
else
{
echo "Price: ₹".$price['price']."<br>";
echo "Rent Per Month: ₹".$rprice['rprice'];
}
?></p>
<form action="#" method="POST">
<button class="btn btn-primary" name="more" type="submit" value="<?php echo $row['property_id'] ?>">More Details</button>
</form>
</div>
</div>
<?php
if(!empty($_POST['more']))
{
$_SESSION['property_id']=$_POST['more'];
header('location:property.php');
}
?>
<?php
}
}
else
{
echo "No Properties Listed with us in this category";
}
?>
</div>
</div>
<div class="search-results">
<h2 class="my-4">Hot Properties</h2>
<div class="cards d-flex justify-content-center flex-wrap gap-3">
<?php
$getproperty=sql_query($conn,"SELECT property_id FROM interested GROUP BY property_id ORDER BY count(*) DESC LIMIT 3");
while($property=$getproperty->fetch_assoc())
{
$pid=$property['property_id'];
$getprop=sql_query($conn,"SELECT * FROM property WHERE property_id=$pid and category!='none'");
$get=$getprop;
// mysqli_data_seek($get, 0);
$rows=mysqli_num_rows($get);
if($rows>0)
{
while ($row = $get->fetch_assoc())
{
$id=$row['property_id'];
$head = str_replace("# ","",explode(PHP_EOL,$row['description'])[0]);
// var_dump(explode(PHP_EOL,$row['description']));
$images = $row['images'];
if($row['category']=="sale")
{
$for="For Sale";
$get_price=mysqli_query($conn,"SELECT price FROM sale_price WHERE property_id=$id");
$price=mysqli_fetch_assoc($get_price);
}
else if($row['category']=="rent")
{
$for="For Rent";
$get_price=mysqli_query($conn,"SELECT rprice FROM rent_price WHERE property_id=$id");
$price=mysqli_fetch_assoc($get_price);
}
else
{
$for="For Sale and Rent";
$get_price=mysqli_query($conn,"SELECT price FROM sale_price WHERE property_id=$id");
$get_rprice=mysqli_query($conn,"SELECT rprice FROM rent_price WHERE property_id=$id");
$price=mysqli_fetch_assoc($get_price);
$rprice=mysqli_fetch_assoc($get_rprice);
}
?>
<div class="card" style="width: 18rem;">
<div id="property<?php echo $row['property_id'] ?>Carousal" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-inner">
<?php
$imagesArr = explode(',', $images);
if($images=='') {
$img = './media/defaultProperty.jpg';
echo "<div class='carousel-item active'>
<img src='$img' class='card-img-top custImg' alt='...'>
</div>";
}
else
for($i=0; $i<count($imagesArr); $i++) {
$active = "";
if($i==0) {
$active = "active";
}
$img = $imagesArr[$i];
echo "<div class='carousel-item $active'>
<img src='$img' class='card-img-top custImg' alt='...'>
</div>";
}
?>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#property<?php echo $row['property_id'] ?>Carousal" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#property<?php echo $row['property_id'] ?>Carousal" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
<div class="card-body">
<h5 class="card-title"><?php echo $head; ?></h5>
<p class="card-text"><?php echo $row['description'] ?></p>
<p class="card-text price lead"><?php
// echo $row['price'];
// echo $for."<br>";
if($for=="For Sale")
{
echo "Price: ₹".$price['price'];
}
else if($for=="For Rent")
{
echo "Rent Per Month: ₹".$price['rprice'];
}
else
{
echo "Price: ₹".$price['price']."<br>";
echo "Rent Per Month: ₹".$rprice['rprice'];
}
?></p>
<form action="#" method="POST">
<button class="btn btn-primary" name="more" type="submit" value="<?php echo $row['property_id'] ?>">More Details</button>
</form>
</div>
</div>
<?php
}
}
else
{
echo "No Properties Listed with us in this category";
}
}
?>
</div>
</div>
</div>
</section>
<?php
require './components/footer.php';
require './components/fontawesome.php';
require './components/bootstrapjs.php';
?>
</body>
</html>