-
Notifications
You must be signed in to change notification settings - Fork 1
/
manage-insert.php
232 lines (196 loc) · 9.07 KB
/
manage-insert.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
<!-- manage-insert.php -->
<?php
session_start();
include_once 'dbCon.php';
$con = connect();
if (isset($_POST['regascus'])){
$fullname = $_POST['fullname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$address = $_POST['address'];
$password = $_POST['password'];
$role = 2;
// existing email chaeck
$checkSQL = "SELECT * FROM `restaurant_info` WHERE email = '$email';";
$checkresult = $con->query($checkSQL);
if ($checkresult->num_rows > 0) {
echo '<script>alert("Restaurant With This Email Is Already Exists.")</script>';
echo '<script>window.location="register.php"</script>';
}else{
if (isset($_FILES['image'])) {
// files handle
$targetDirectory = "dashboard/user-image/";
// get the file name
$file_name = $_FILES['image']['name'];
// get the mime type
$file_mime_type = $_FILES['image']['type'];
// get the file size
$file_size = $_FILES['image']['size'];
// get the file in temporary
$file_tmp = $_FILES['image']['tmp_name'];
// get the file extension, pathinfo($variable_name,FLAG)
$extension = pathinfo($file_name,PATHINFO_EXTENSION);
//register as customer
if ($extension =="jpg" || $extension =="png" || $extension =="jpeg"){
move_uploaded_file($file_tmp,$targetDirectory.$file_name);
$iquery="INSERT INTO `restaurant_info`(`restaurent_name`, `email`, `phone`, `address`, `logo`, `password`, `role`)
VALUES ('$fullname','$email','$phone','$address','$file_name','$password','$role');";
if ($con->query($iquery) === TRUE) {
echo '<script>alert("You Register successfully")</script>';
echo '<script>window.location="login.php"</script>';
}else {
echo "Error: " . $iquery . "<br>" . $con->error;
}
}else{
echo '<script>alert("Required JPG,PNG,GIF in Logo Field.")</script>';
echo '<script>window.location="register.php"</script>';
}
}else{
$file_name = "";
$iquery="INSERT INTO `restaurant_info`(`restaurent_name`, `email`, `phone`, `address`, `logo`, `password`, `role`)
VALUES ('$fullname','$email','$phone','$address','$file_name','$password','$role');";
if ($con->query($iquery) === TRUE) {
echo '<script>alert("New faculty added successfully")</script>';
echo '<script>window.location="register.php"</script>';
}else {
echo "Error: " . $iquery . "<br>" . $con->error;
}
}
}
}
//register as restaurant
if (isset($_POST['regasres'])){
$fullname = $_POST['fullname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$bkashnumber = $_POST['bkashnumber'];
$address = $_POST['address'];
$area = $_POST['area'];
$password = $_POST['password'];
$role = 1;
$checkSQL = "SELECT * FROM `restaurant_info` WHERE email = '$email';";
$checkresult = $con->query($checkSQL);
if ($checkresult->num_rows > 0) {
echo '<script>alert("Restaurant With This Email Is Already Exist.")</script>';
echo '<script>window.location="register.php"</script>';
}else{
if (isset($_FILES['image'])) {
// files handle
$targetDirectory = "dashboard/user-image/";
// get the file name
$file_name = $_FILES['image']['name'];
// get the mime type
$file_mime_type = $_FILES['image']['type'];
// get the file size
$file_size = $_FILES['image']['size'];
// get the file in temporary
$file_tmp = $_FILES['image']['tmp_name'];
// get the file extension, pathinfo($variable_name,FLAG)
$extension = pathinfo($file_name,PATHINFO_EXTENSION);
if ($extension =="jpg" || $extension =="png" || $extension =="jpeg"){
move_uploaded_file($file_tmp,$targetDirectory.$file_name);
$iquery="INSERT INTO `restaurant_info`(`restaurent_name`, `email`, `phone`, `address`, `location`, `logo`, `password`, `role`)
VALUES ('$fullname','$email','$phone', '$address','$area','$file_name','$password','$role');";
if ($con->query($iquery) === TRUE) {
echo '<script>alert("Restaurant added successfully")</script>';
echo '<script>window.location="login.php"</script>';
$id = $con->insert_id;
include 'dashboard/mailSender.php';
$mail->Body = '<html><body>
Verify your account.. click the link below.
http://localhost/tablereservation/verifyaccount.php?email='.$email.'&id='.$id.'&auth='.$password.'
</body></html>';
$mail->addAddress($email, "Booking Approve");
if($mail->send()) {
echo '<script>alert("Restaurant added successfully")</script>';
echo '<script>window.location="verifyaccount.php?view=verifyaccount&email='.$email.'&id='.$id.'&auth='.$password.'"</script>';
echo '<script>alert("Restaurant added successfully")</script>';
// echo '<script>window.location="login.php"</script>';
}else{
echo '<script>alert("Restaurant added successfully")</script>';
echo '<script>window.location="login.php"</script>';
}
}else {
echo "Error: " . $iquery . "<br>" . $con->error;
}
}else{
echo '<script>alert("Required JPG,PNG,GIF in Logo Field.")</script>';
echo '<script>window.location="register.php"</script>';
}
}else{
$file_name = "";
$iquery="INSERT INTO `restaurant_info`( `restaurent_name`, `email`, `phone`, `address`, `location`, `logo`, `password`, `role`)
VALUES ('$fullname','$email','$phone', '$address','$area', '$file_name','$password','$role');";
if ($con->query($iquery) === TRUE) {
echo '<script>alert("New faculty added successfully")</script>';
echo '<script>window.location="login.php"</script>';
}else {
echo "Error: " . $iquery . "<br>" . $con->error;
}
}
}
}
if (isset($_POST['book'])) {
$bdinsert = false;
$u_id = $_SESSION['id'];
$res_id = $_POST['res_id'];
$reservation_name = $_POST['reservation_name'];
$reservation_phone = $_POST['reservation_phone'];
$reservation_date = $_POST['reservation_date'];
$reservation_time = $_POST['reservation_time'];
$total_price = $_POST['total_price'];
$transactionid = $_POST['transaction_id'];
date_default_timezone_set("Asia/Dhaka");
$make_time =date("h:i:sa");
$make_date =date("Y-m-d");
$booking_id= uniqid();
$iquery="INSERT INTO `booking_details`(`booking_id`,`res_id`,`c_id`,`make_date`, `make_time`, `name`, `phone`, `booking_date`, `booking_time`, `bill`,`transactionid`)
VALUES ('$booking_id','$res_id','$u_id','$make_date','$make_time','$reservation_name','$reservation_phone','$reservation_date','$reservation_time','$total_price','$transactionid');";
if ($con->query($iquery) === TRUE) {
$bdinsert = true;
}else {
echo "Error: " . $iquery . "<br>" . $con->error;
}
$cinsert = false;
if ($bdinsert == true) {
for($q = 0; $q < count($_POST["chair"]); $q++){
$c_id = $_POST['chair'][$q];
$chair_no = "";
$sql5 = "SELECT * FROM `restaurant_chair` WHERE id = '$c_id';";
$result5 = $con->query($sql5);
foreach ($result5 as $r5) {
$chair_no = $r5['chair_no'];
}
$ciQuery = "INSERT INTO `booking_chair`(`booking_id`, `chair_id`, `chair_no`)
VALUES ('$booking_id','$c_id','$chair_no');";
if ($con->query($ciQuery) === TRUE) {
$cinsert = true;
}else {
echo "Error: " . $ciQuery . "<br>" . $con->error;
}
}
}
$iinsert = false;
if ($cinsert == true) {
for($i = 0; $i < count($_POST["item"]); $i++){
$i_id = $_POST['item'][$i];
$qty = $_POST['qty'][$i];
$itmQuery = "INSERT INTO `booking_menus`(`booking_id`, `item_id`, `qty`)
VALUES ('$booking_id','$i_id','$qty');";
if ($con->query($itmQuery) === TRUE) {
$iinsert = true;
}else {
echo "Error: " . $itmQuery . "<br>" . $con->error;
}
}
}
if ($bdinsert == true && $cinsert == true && $iinsert == true) {
echo '<script>alert("Your booking is done. You will get an email soon.")</script>';
echo '<script>window.location="index.php"</script>';
}else {
echo "Error: " . $iquery . "<br>" . $con->error;
echo "Error: " . $ciQuery . "<br>" . $con->error;
echo "Error: " . $iquery . "<br>" . $con->error;
}
}
?>