-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReservation.php
More file actions
179 lines (110 loc) · 4.41 KB
/
Copy pathReservation.php
File metadata and controls
179 lines (110 loc) · 4.41 KB
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
<?php
namespace App\Reservation;
use App\GlobalClasses\Message;
use App\GlobalClasses\Utility;
use App\Model\Database as DB;
class Reservation extends DB{
public $id="";
public $date="";
public $time_slot="";
public $invoice_id="";
public $table_info="";
public function __construct()
{
parent::__construct();
}
public function prepare($data=array()){
if(array_key_exists('id',$data)){
$this->id=$data['id'];
}
if(array_key_exists('reservationDate',$data)){
$this->date=$data['reservationDate'];
}
if(array_key_exists('reservationTimeSlot',$data)){
$this->time_slot=$data['reservationTimeSlot'];
}
if(array_key_exists('invoiceID',$data)){
$this->invoice_id=$data['invoiceID'];
}
if(array_key_exists('reservationTable',$data)){
$this->table_info=$data['reservationTable'];
}
return $this;
}
public function store(){
$query="INSERT INTO `restaurant`.`reservation` (`date`, `time_slot`, `invoice_id`, `table_info`) VALUES ('".$this->date."', '".$this->time_slot."', '".$this->invoice_id."', '".$this->table_info."')";
$result= mysqli_query($this->conn,$query);
if ($result) {
Message::message("
<div class=\"alert success\">
<strong>Success!</strong> $this->table_info has been reserved successfully.
</div>");
return Utility::redirect('');
} else {
Message::message("
<div class=\"alert danger\">
<strong>Fail!</strong> Data has not been stored successfully.
</div>");
return Utility::redirect('');
}
}
public function getInvoiceID($table_info, $date, $time_slot){
$query="SELECT * FROM `restaurant`.`reservation` WHERE `table_info`='".$table_info."'". " AND `date`='".$date."'". " AND `time_slot`='".$time_slot."'";
$result= mysqli_query($this->conn,$query);
$row= mysqli_fetch_object($result);
$countRows= mysqli_num_rows($result);
if($countRows>0)
return $row->invoice_id;
else
return "";
}// end of view()
public function isBooked($table_info,$date,$time_slot){
$query="SELECT * FROM `restaurant`.`reservation` WHERE `table_info`='".$table_info."'". " AND `date`='".$date."'". " AND `time_slot`='".$time_slot."'";
$result= mysqli_query($this->conn,$query);
$countRows= mysqli_num_rows($result);
if($countRows>0)
return True;
else
return False;
}// end of isBooked
// if( $reservation->isAlreadyReserved($invoice)) echo $reservation->getTableInfo($invoice)." was reserved on ".$reservation->getReservationDate($invoice) . " between " .$reservation->getReservationTimeSlot($invoice);
public function isInvoiceExits($invoice){
$query="SELECT * FROM `restaurant`.`reservation` WHERE `invoice_id`='".$invoice."'";
$result= mysqli_query($this->conn,$query);
$countRows= mysqli_num_rows($result);
if($countRows>0)
return True;
else
return False;
}
public function getTableInfo($invoice){
$query="SELECT * FROM `restaurant`.`reservation` WHERE `invoice_id`='".$invoice."'";
$result= mysqli_query($this->conn,$query);
$row= mysqli_fetch_object($result);
$countRows= mysqli_num_rows($result);
if($countRows>0)
return $row->table_info;
else
return "";
}
public function getReservationDate($invoice){
$query="SELECT * FROM `restaurant`.`reservation` WHERE `invoice_id`='".$invoice."'";
$result= mysqli_query($this->conn,$query);
$row= mysqli_fetch_object($result);
$countRows= mysqli_num_rows($result);
if($countRows>0)
return $row->date;
else
return "";
}
public function getReservationTimeSlot($invoice){
$query="SELECT * FROM `restaurant`.`reservation` WHERE `invoice_id`='".$invoice."'";
$result= mysqli_query($this->conn,$query);
$row= mysqli_fetch_object($result);
$countRows= mysqli_num_rows($result);
if($countRows>0)
return $row->time_slot;
else
return "";
}
}