-
Notifications
You must be signed in to change notification settings - Fork 0
/
addprop.php
250 lines (227 loc) · 7.67 KB
/
addprop.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
<?php
session_start();
?>
<html>
<?php
include("connection.php");
if(isset($_POST['submit'])){
$filename=$_FILES['img']['name'];
$tempfilename=$_FILES['img']['tmp_name'];
$type=$_POST['type'];
$rooms=$_POST['rooms'];
$beds=$_POST['beds'];
$area=$_POST['area'];
$location=$_POST['location'];
$deal=$_POST['deal'];
$max=$_POST['max'];
$min=$_POST['min'];
$image=$filename[0];
if(!isset($_SESSION['username']))
{ echo "<script>alert('you're not logged in');</script>";
echo '<script>window.location.href= "Login.php";</script>';
}
else{
$username=$_SESSION['username'];
}
function checkarea($numm){
if($numm < 0 ){
throw new Exception("Invalid Area shouls be more than 0!");
}
}
try
{checkarea($area);}
catch(Exception $e){
$emesg=$e->getMessage();
trigger_error("");
echo "<script>alert('$emesg')</script>";
echo '<script>window.location.href= "editpropseller.php";</script>';
die();
}
function checkminmax($maxn, $minn){
if($maxn < $minn ){
throw new Exception ("max price should be greater than min price");}
else if($maxn < 0 || $minn < 0){
throw new Exception("prices shouldn't be less than 0");
}
}
try{ checkminmax($max , $min);}
catch(Exception $e){
$emsg=$e->getMessage();
trigger_error("");
echo "<script>alert('$emesg')</script>";
echo '<script>window.location.href= "editpropseller.php";</script>';
die();
}
function checknums($beds , $rooms){
if($beds > 100 || $beds < 0 ){
throw new Exception("bed number should be between 100 and 0!");
}
else if($rooms <0 || $rooms >100){
throw new Exception("room number should be between 100 and 0!");
}
}
try{ checknums($beds , $rooms);}
catch(Exception $e){
$emsg=$e->getMessage();
echo "<script>alert('$emesg')</script>";
trigger_error("");
echo '<script>window.location.href= "editpropseller.php";</script>';
die();
}
$sql="INSERT INTO `property` ( `sellerID`, `type`, `roomnum`, `bednum`, `area`, `location`,
`deal`,`maxprice`, `minprice`)
VALUES (
'".$_SESSION['username']."'
,'".$_POST['type']."'
,'".$_POST['rooms']."'
,'".$_POST['beds']."'
,'".$_POST['area']."'
,'".$_POST['location']."'
,'".$_POST['deal']."'
,'".$_POST['max']."'
,'".$_POST['min']."'
)";
if(mysqli_query($conn,$sql)){
error_log("$sql..",3,"databaseoperations.log");
echo "<script>alert('Successfully added');</script>";
$sqls="SELECT `propertyID`FROM`property` WHERE sellerID='$username' AND location='$location'
AND type='$type' AND area='$area' AND roomnum='$rooms' AND bednum='$beds' AND maxprice='$max' AND minprice='$min'AND deal='$deal'";
if(mysqli_query($conn,$sqls)){
error_log("$sqls..",3,"databaseoperations.log");
$res=mysqli_query($conn,$sqls);
while($row=mysqli_fetch_assoc($res)){
$id2=$row['propertyID'];
}
}else{ trigger_error(""); }
}
else{
trigger_error("");
}
$numimages=count($filename);
function checkimg($imgn){
if($imgn < 2){
throw new Exception("must include more than one pic for your property!");
}
}
try{checkimg($numimages);}catch(Exception $e){
$emsg=$e->getMessage();
trigger_error("");
echo "<script>alert('$emesg')</script>";
echo '<script>window.location.href= "addprop.php";</script>';
die();
}
for($i=0; $i<=count($filename); $i++){
if(!empty($filename[$i])){
$name = $filename[$i];
$tempname = $tempfilename[$i];
$sqlp="INSERT INTO `pictures`(`picture`,`sellerID`,`propertyID`) VALUES('$name','".$_SESSION['username']."','$id2')";
move_uploaded_file($tempname,"img/".$name);
if(mysqli_query($conn,$sqlp)){
error_log("$sqlp..",3,"databaseoperations.log");
$ress=mysqli_query($conn,$sqlp);
}
else{ trigger_error("");
}
}//////end of if sqlp
}///end of for
}////end of is set
?>
<html lang="en">
<!--==========================
Header
============================-->
<?php include('header.php'); ?>
<?php
if(!isset($_SESSION['acctype']))
{ echo "<script>alert('you're not logged in');</script>";
echo '<script>window.location.href= "Login.php";</script>';
}
else{
$acctype=$_SESSION['acctype'];
if($acctype=="2")
{
?>
<header id="header">
<div class="container-fluid">
<div id="logo" class="pull-left">
<a href="index.php"><img src="img/Logo.png" alt="" title="" /></a>
</div>
<nav id="nav-menu-container">
<ul class="nav-menu">
<li><a href="index.php">Home</a></li>
<li class="menu-active"><a href="addprop.php">Add Properties</a></li>
<li><a href="MyProperties.php">Edit My Properties</a></li>
<li><a href="property.php">View all Properties</a></li>
<li><a href="responsetorequest.php">Requests</a></li>
<li><a href="messages.php">Messages</a></li>
<li><a href="feedback.php">Feedbacks</a></li>
<li><a href="searchQA.php">Q & A</a></li>
<li><a href="contactus.php">Contact Us</a></li>
<li><a href="editprofile.php">Edit Profile</a></li>
<li><a href="Logout.php">Log Out</a></li>
</nav><!-- #nav-menu-container -->
</div>
</header><!-- #header -->
<?php
}
else {
echo "<script>alert('You are not allowed to visit this page please register as a seller to view it');</script>";
echo '<script>window.location.href= "index.php";</script>';
}
}
?>
<section id="aboutus" class="wow fadeIn">
<div class="container text-center">
<h3>Add Your Property</h3>
</div>
</section>
<div class="container">
<div class="col-md-3">
<h1 class = "headersignup">Add Your Property</h1>
<div class="card-body card-block">
<form name="addprop" method = "POST" action ="" enctype='multipart/form-data'>
Location: <input type="text" name="location" class="form-control" required="required"/>
Area: <input type="number" name="area" class="form-control" required="required"/>
Type: <!---<input type="text" name="type" required="required"/> -->
<select name='type' class="form-control">
<?php require_once "get_Proptype.php"; ?>
</select>
Number of toilet: <input type="number" name="rooms" class="form-control" required="required"/>
Number of beds: <input type="number" name="beds" class="form-control" required="required"/>
DEAL:<select name='deal' class="form-control">
<?php require_once "get_Dealtype.php"; ?>
</select>
Max price: <input type="number" name="max" class="form-control" required="required"/>
Min price: <input type="number" name="min" class="form-control" required="required"/>
Property image: <input type="file" name="img[]" class="file-control" required="required" multiple="multiple" />
<br>
<div ><button class="submitaddprop" name='submit' type="submit">Submit</button></div>
</form>
</div>
</div>
</div>
</div>
<?php
mysqli_close($conn);
include('footer.php'); ?>
<a href="#" class="back-to-top"><i class="fa fa-chevron-up"></i></a>
<!-- Uncomment below i you want to use a preloader -->
<!-- <div id="preloader"></div> -->
<!-- JavaScript Libraries -->
<script src="lib/jquery/jquery.min.js"></script>
<script src="lib/jquery/jquery-migrate.min.js"></script>
<script src="lib/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="lib/easing/easing.min.js"></script>
<script src="lib/superfish/hoverIntent.js"></script>
<script src="lib/superfish/superfish.min.js"></script>
<script src="lib/wow/wow.min.js"></script>
<script src="lib/waypoints/waypoints.min.js"></script>
<script src="lib/counterup/counterup.min.js"></script>
<script src="lib/owlcarousel/owl.carousel.min.js"></script>
<script src="lib/isotope/isotope.pkgd.min.js"></script>
<script src="lib/lightbox/js/lightbox.min.js"></script>
<script src="lib/touchSwipe/jquery.touchSwipe.min.js"></script>
<!-- Contact Form JavaScript File -->
<script src="contactform/contactform.js"></script>
<!-- Template Main Javascript File -->
<script src="js/main.js"></script>