-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdatepropseller.php
190 lines (158 loc) · 4.29 KB
/
updatepropseller.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
<?php
session_start();
?>
<?php
include("connection.php");
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'];
}
if(isset($_POST['submit'])){
$filename=$_FILES['img']['name'];
$tempfilename=$_FILES['img']['tmp_name'];
$image=$filename[0];
//$img=$_POST['img'];
$id= $_POST['propid'];
$area=$_POST['area'];
$type=$_POST['type'];
$location=$_POST['location'];
$nroom=$_POST['rooms'];
$nbed=$_POST['beds'];
$max=$_POST['max'];
$min=$_POST['min'];
$deal=$_POST['deal'];
function checkarea($numm){
if($numm < 0 ){
throw new Exception("Invalid Area !");
}
}
try
{checkarea($area);}
catch(Exception $e){
$emsg=$e->getMessage();
trigger_error("Invalid Area shouls be more than 0! ");
echo "<script>alert('$emsg')</script>";
echo '<script>window.location.href= "MyProperties.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(' $emsg')</script>";
echo '<script>window.location.href= "MyProperties.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($nbed , $nroom);}
catch(Exception $e){
$emsg=$e->getMessage();
echo "<script>alert('$emsg')</script>";
trigger_error("");
$acctype=$_SESSION['acctype'];
if($acctype=="3"){
echo '<script>window.location.href= "adminview.php";</script>';
}
if($acctype=="2"){
echo '<script>window.location.href= "MyProperties.php";</script>';
}
die();
}
if (isset($_POST['availability'])){
$ava=1;
}
else
$ava=0;
$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('$emsg')</script>";
$acctype=$_SESSION['acctype'];
if($acctype=="3"){
echo '<script>window.location.href= "adminview.php";</script>';
}
if($acctype=="2"){
echo '<script>window.location.href= "MyProperties.php";</script>';
}
die();
}
$usql=" UPDATE `property`
SET `type`='$type',
`roomnum`='$nroom',
`bednum`='$nbed',
`area`='$area',
`location`='$location',
`deal`='$deal',
`maxprice`='$max',
`minprice`='$min',
`availability`='$ava'
WHERE sellerID='$username' AND propertyID='$id'";
$dsql="DELETE FROM `pictures` WHERE propertyID=$id";
if(mysqli_query($conn,$usql)){
error_log("$usql..",3,"databaseoperations.log");
$acctype=$_SESSION['acctype'];
if($acctype=="2"){
echo '<script>window.location.href= "MyProperties.php";</script>';
}
}
else{
$errorconn=mysqli_error($conn);
trigger_error("$errorconn usql line 146 updatepropseller.php");
}
if(mysqli_query($conn,$dsql)){
$dres=mysqli_query($conn,$dsql);
error_log("$dsql..",3,"databaseoperations.log");
} else{
$errorconn=mysqli_error($conn);
$errorconn=mysqli_error($conn);
trigger_error("$errorconn dsql line 155 updatepropseller.php");
}
for($i=0;$i<count($filename);$i++){
if(!empty($filename[$i])){
$name=$filename[$i];
$tempname = $tempfilename[$i];
$psql="INSERT INTO `pictures`(`picture`, `sellerID`, `propertyID`) VALUES ('$name','$username','$id')";
move_uploaded_file($tempname,"img/".$name);
if(mysqli_query($conn,$psql)){
error_log("$psql..",3,"databaseoperations.log");
// $res=mysqli_query($conn,$psql);
}else{
$errorconn=mysqli_error($conn);
trigger_error("$errorconn psql line 170 updatepropseller.php");
}
}
}
if (isset($_POST['cancel'])){
$acctype=$_SESSION['acctype'];
if($acctype=="3"){
echo '<script>window.location.href= "adminview.php";</script>';
}
if($acctype=="2"){
echo '<script>window.location.href= "MyProperties.php";</script>';
}
}}
mysqli_close($conn);
?>