-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.php
283 lines (224 loc) · 7.48 KB
/
database.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
<?php
function upload(){
$namaFile = $_FILES['gambar']['name'];
$ukuranFile = $_FILES['gambar']['size'];
$error = $_FILES['gambar']['error'];
$tmpName = $_FILES['gambar']['tmp_name'];
if( $error === 4){
echo "<script>
alert('Tolong upload gambar!');
</script>";
return false;
}
$ekstensiGambarValid = ['jpg', 'jpeg', 'png'];
$ekstensiGambar = explode('.', $namaFile);
$ekstensiGambar = strtolower(end($ekstensiGambar));
if( !in_array($ekstensiGambar, $ekstensiGambarValid) ){
echo "<script>
alert('File yang diupload bukan gambar!');
</script>";
return false;
}
// cek jika ukurannya terlalu besar
if( $ukuranFile > 1000000) {
echo "<script>
alert('Ukuran gambar terlalu besar!');
</script>";
return false;
}
$namaFileBaru = uniqid();
$namaFileBaru .= '.';
$namaFileBaru .= $ekstensiGambar;
move_uploaded_file($tmpName, 'img/' . $namaFileBaru);
return $namaFileBaru;
}
class database{
private $host;
private $user;
private $pass;
private $database;
public $conn;
function __construct($host, $user, $pass, $database) {
$this->host = $host;
$this->user = $user;
$this->pass = $pass;
$this->database = $database;
$this->conn = new mysqli($this->host, $this->user, $this->pass, $this->database) or die ("could not connect to mysql");
if(!$this->conn){
return false;
} else {
return true;
}
}
}
class connect{
private $mysqli;
function __construct($conn){
$this->mysqli = $conn;
}
public function connect(){
$db = $this->mysqli->conn;
return $db;
}
}
class menu{
private $mysqli;
function __construct($conn) {
$this->mysqli = $conn;
}
public function tampilmkn() {
$db = $this->mysqli->conn;
$sql = "SELECT * FROM tbl_menu WHERE jenis = 'makanan' AND stok > 0";
$query = $db->query($sql);
return $query;
}
public function tampilmnm() {
$db = $this->mysqli->conn;
$sql = "SELECT * FROM tbl_menu WHERE jenis = 'minuman' AND stok > 0";
$query = $db->query($sql);
return $query;
}
public function tampilmenu(){
$db = $this->mysqli->conn;
$sql = "SELECT * FROM tbl_menu";
$query = $db->query($sql);
return $query;
}
public function transaksi(){
$db = $this->mysqli->conn;
$sql = "SELECT * FROM tbl_transaksi";
$query = $db->query($sql);
return $query;
}
public function selesai(){
$db = $this->mysqli->conn;
$sel = "SELECT * FROM tbl_transaksi WHERE status='waiting'";
$data = $db->query($sel);
return $data;
}
public function antrian(){
$db = $this->mysqli->conn;
$sel = "SELECT * FROM antrian LIMIT 5";
$data = $db->query($sel);
return $data;
}
}
class manipulasi{
public $mysqli;
public $data;
public $query;
function __construct($conn) {
$this->mysqli = $conn;
}
}
class manipmenu extends manipulasi{
public $mysqli;
public $query;
public function tambah($data){
$db = $this->mysqli->conn;
$id = htmlspecialchars($data['id']);
$nama = htmlspecialchars($data['nama']);
$stok = htmlspecialchars($data['stok']);
$harga = htmlspecialchars($data['harga']);
$jenis = htmlspecialchars($data['jenis']);
$name = str_replace(' ', '_', $nama);
$img = upload();
if( !$img){
return false;
}
$inputmenu = "INSERT INTO tbl_menu VALUES
('$id','$nama','$stok','$harga','$img','$jenis')";
$query = $db->query($inputmenu);
$addtransaksi = "ALTER TABLE tbl_transaksi ADD COLUMN $name INT(11) NOT NULL";
$db->query($addtransaksi);
return $query;
}
public function edit($data, $id){
$db = $this->mysqli->conn;
$getoldname = mysqli_query($db, "SELECT * FROM tbl_menu WHERE id_menu = '$id'");
$qry =mysqli_fetch_array($getoldname);
$oldname = $qry['nama'];
$name = str_replace(' ', '_', $oldname);
$id = htmlspecialchars($data['id']);
$nama = htmlspecialchars($data['nama']);
$stok = htmlspecialchars($data['stok']);
$harga = htmlspecialchars($data['harga']);
$jenis = htmlspecialchars($data['jenis']);
$name2 = str_replace(' ', '_', $nama);
$img = upload();
if( !$img){
return false;
}
$inputmenu = "UPDATE tbl_menu SET
id_menu='$id', nama='$nama', stok='$stok', harga='$harga', img='$img', jenis='$jenis' WHERE id_menu = '$id'";
$query = $db->query($inputmenu);
$edittransaksi = "ALTER TABLE tbl_transaksi CHANGE $name $name2 INT(11)";
$db->query($edittransaksi);
return $query;
}
public function hapus($id){
$db = $this->mysqli->conn;
$tampildat =mysqli_query($db, "SELECT * FROM tbl_menu WHERE id_menu = '$id'");
$dat =mysqli_fetch_array($tampildat);
$nama = $dat['nama'];
$name = str_replace(' ', '_', $nama);
$delmenu = "DELETE FROM tbl_menu WHERE id_menu = '$id'";
$query = $db->query($delmenu);
$delcolumn = "ALTER TABLE tbl_transaksi DROP COLUMN $name";
$db->query($delcolumn);
return $query;
}
}
class manipuser extends manipulasi{
public $mysqli;
public $query;
public function tampiluser(){
$db = $this->mysqli->conn;
$sql = "SELECT * FROM tbl_user WHERE level = 1 OR level = 2";
$query = $db->query($sql);
return $query;
}
public function tambahusr($data){
$db = $this->mysqli->conn;
$codename = htmlspecialchars($data['codename']);
$username = htmlspecialchars($data['username']);
$password = htmlspecialchars($data['password']);
$level = htmlspecialchars($data['level']);
$inputuser = "INSERT INTO tbl_user VALUES
('$codename','$username','$password','$level')";
$query = $db->query($inputuser);
return $query;
}
public function editusr($data, $id){
$db = $this->mysqli->conn;
$codename = htmlspecialchars($data['codename']);
$username = htmlspecialchars($data['username']);
$password = htmlspecialchars($data['password']);
$level = htmlspecialchars($data['level']);
$edituser = "UPDATE tbl_user SET
codename = '$codename', username = '$username', pass = '$password', level = '$level' WHERE codename = '$id'";
$query = $db->query($edituser);
return $query;
}
public function hapususr($id){
$db = $this->mysqli->conn;
$deluser = "DELETE FROM tbl_user WHERE codename = '$id'";
$query = $db->query($deluser);
return $query;
}
}
class reset{
public $mysqli;
public $data;
public $query;
function __construct($conn) {
$this->mysqli = $conn;
}
public function reset(){
$db = $this->mysqli->conn;
$reset = "DELETE a1 FROM antrian a1 INNER JOIN antrian a2 WHERE a1.status = 'selesai' AND a1.status = a2.status";
$query = $db->query($reset);
return $query;
}
}
?>