-
Notifications
You must be signed in to change notification settings - Fork 2
/
admin_dash.php
410 lines (381 loc) · 15.5 KB
/
admin_dash.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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
<?php
session_start();
require_once "database.php";
//Memanggil kelas database
$pdo = new database();
$edit_form = false;
$view_order = false;
//Init
$garisLintang = "";
$garisBujur = "";
//Jika user belum login dan membuka ini, maka langsung diarahkan ke halaman login
if(isset($_SESSION['email']) == 0){
exit("<h1>Access Denied</h1>");
}
//Akses selain e-mail admin akan ditolak
//Ubah e-mailnya jika ingin mengganti akun admin
if($_SESSION['email'] != 'admin@laundryonlinemks.com'){
exit("<h1>Access Denied</h1>");
}
//Memunculkan data customers
$rows = $pdo -> showData();
//Memunculkan data order
$orders = $pdo -> showPesanan();
//Menghapus data
if (isset($_POST['delete'])){
//Jika tekan hapus admin
//Ubah nomor jika id admin berubah
if($_POST['id'] == 1){
echo('<div class="alert alert-danger" role="alert">');
echo('Tidak bisa hapus administrator');
echo('</div>');
}
else{
$pdo -> deleteData($_POST['id']);
header("Location: admin_dash.php#customers");
}
}
//Mengambil data dan menaruh di kotak edit customer
if(isset($_GET['edit'])){
$data = $pdo -> getData($_GET['edit']);
$edit_form = true;
$name = $data['name'];
$email = $data['email'];
$nomor_telepon = $data['nomor_telepon'];
$id = $data['id'];
}
//Mengambil data dan menaruh di kotak view order
if(isset($_GET['view'])){
$pemesanan = $pdo -> getOrder($_GET['view']);
$view_order = true;
$userId = $pemesanan['id_user'];
$jenisLaundry = $pemesanan['jenis_laundry'];
$massaBarang = $pemesanan['massa_barang'];
$jumlahBarang = $pemesanan['jumlah_barang'];
$waktuPengambilan = $pemesanan['waktu_pengambilan'];
$waktuPengantaran = $pemesanan['waktu_pengantaran'];
$alamat = $pemesanan['alamat'];
$catatan = $pemesanan['catatan'];
$garisLintang = "".$pemesanan['garis_lintang'].", ";
$garisBujur = $pemesanan['garis_bujur'];
$hargaTotal = $pemesanan['harga_total'];
$statusPemesanan = $pemesanan['status_pemesanan'];
$orderId = $pemesanan['id'];
$listSatuan = $pemesanan['list_satuan'];
}
//Mengupdate data customers
if(isset($_POST['update'])){
$update = $pdo -> updateData($_POST['nama'], $_POST['email'], $_POST['password'], $_POST['nomor_telepon'], $id);
header("Location: admin_dash.php#customers");
}
//Mengupdate data order
if(isset($_POST['update_order'])){
$radio_status = $_POST['status'];
$update = $pdo -> updateStatus($radio_status, $orderId);
header("Location: admin_dash.php#pesanan");
}
//Untuk tombol membatalkan edit
if(isset($_POST['cancel'])){
header("Location: admin_dash.php#customers");
}
//Untuk tombol membatalkan edit
if(isset($_POST['cancel_update'])){
header("Location: admin_dash.php#pesanan");
}
//Mengambil jumlah data customers
$banyakdata = $pdo -> banyak_data();
//Mengambil jumlah data pesanan
$banyakpesanan = $pdo -> banyak_pesanan();
?>
<!DOCTYPE html>
<head>
<title>Dashboard Admin - Laundry OnLine</title>
<script src="js/jquery-3.5.1.js"></script>
<script src="bootstrap/js/bootstrap.bundle.js"></script>
<script src="bootstrap/jquery.dataTables.min.js"></script>
<script src="bootstrap/dataTables.bootstrap4.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCKtmUDqFDJ8-D3F0nJM4bpiD4hAR-fzeo"></script>
<link rel="stylesheet" href="bootstrap/css/bootstrap.css">
<link rel="stylesheet" href="css/dash.css">
<link rel="stylesheet" href="bootstrap/dataTables.bootstrap4.min.css">
</head>
<body>
<!-- Navbar -->
<nav id="navbar-admin" class="navbar navbar-expand-lg navbar-dark bg-primary">
<a class="navbar-brand" href="/admin_dash.php"><b>Laundry OnLine</b></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="#beranda">Beranda <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#statistik">Statistik</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#pesanan">Pesanan</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#customers">Profil Customers</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="/logout.php">Logout</a>
</li>
</ul>
</div>
</nav>
<!-- Isi -->
<div data-spy="scroll" data-target="#navbar-admin" data-offset="0">
<div class="jumbotron jumbotron-fluid">
<div class="container">
<h1 id ="beranda" class="display-4">Selamat datang, <?php echo $_SESSION['name']; ?>!</h1>
<br>
<p class="lead">Anda berada di ruang admin, cek pesanan dan profil pelanggan disini.</p>
</div>
</div>
<div class="jumbotron jumbotron-fluid bg-white">
<div class="container">
<h1 class="tengah" id ="statistik">Statistik</h1>
<p class="tengah">Melihat berapa banyak pesanan dan pelanggan yang terdaftar.
</p>
<br>
<div class="row">
<div class="col-6"><div class="tengah"><h3>Pesanan</h3></div></div>
<div class="col-6"><div class="tengah"><h3>Pelanggan</h3></div></div>
</div>
<br>
<div class="row">
<div class="col-6"><div class="tengah"><img src="images/pesanan.png" width="100px"></div></div>
<div class="col-6"><div class="tengah"><img src="images/users.png" width="100px"></div></div>
</div>
<br>
<div class="row">
<div class="col-6"><div class="tengah"><h5><?php echo $banyakpesanan ?> pesanan</h5></div></div>
<div class="col-6"><div class="tengah"><h5><?php echo $banyakdata; ?> pelanggan</h5></div></div>
</div>
</div>
</div>
<div class="jumbotron jumbotron-fluid bg-light">
<div class="container">
<h1 class="tengah" id ="pesanan">Pesanan</h1>
<p class="tengah">Daftar pesanan dari pelanggan.
</p>
<br>
<table id="pagination" class="table table-striped table-bordered">
<thead>
<tr>
<th scope="col">ID User</th>
<th scope="col">Jenis Laundry</th>
<th scope="col">List Satuan</th>
<th scope="col">Massa Barang</th>
<th scope="col">Jumlah Barang</th>
<th scope="col">Harga Total</th>
<th scope="col">Status Pemesanan</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php
foreach( $orders as $order){
?>
<tr>
<th scope="row"><?=$order['id_user'] ?></th>
<td><?=$order['jenis_laundry'] ?></td>
<td><?=$order['list_satuan'] ?></td>
<td><?=$order['massa_barang'] ?></td>
<td><?=$order['jumlah_barang'] ?></td>
<td><?=$order['harga_total'] ?></td>
<td><?=$order['status_pemesanan'] ?></td>
<td>
<form action="admin_dash.php?view=<?php echo $order['id']; ?>#pesanan" method="post">
<input type="hidden" name="id" value="<?=$order['id']?>">
<input type="submit" value="View" name="view">
</form>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<br><br>
<?php
if ($view_order == false){
// Kosong
}
else{
?>
<h4 class="tengah">View Data</h4>
<ul>
<li>ID User : <?php echo $userId; ?></li><br>
<li>Jenis Laundry : <?php echo $jenisLaundry; ?></li><br>
<li>List Satuan : <?php echo $listSatuan; ?></li><br>
<li>Massa Barang : <?php echo $massaBarang; ?></li><br>
<li>Jumlah Barang : <?php echo $jumlahBarang; ?></li><br>
<li>Waktu Pengambilan : <?php echo $waktuPengambilan; ?></li><br>
<li>Waktu Pengantaran : <?php echo $waktuPengantaran; ?></li><br>
<li>Alamat : <?php echo $alamat; ?></li><br>
<li>Catatan : <?php echo $catatan; ?></li><br>
<li>Harga Total : <?php echo $hargaTotal; ?></li><br>
<li>Lokasi : </li><br>
<div id="googleMaps" style="width:50%; height:440px; border:solid black 1px;"></div>
<br>
<form method="post">
<li>Status Pemesanan :</li><br>
<input type="radio" id="tunggu_konfirmasi" name="status" value="Tunggu Konfirmasi" checked>
<label for="tunggu_konfirmasi">Tunggu Konfirmasi</label><br>
<input type="radio" id="diambil_kurir" name="status" value="Kurir mengambil laundry">
<label for="diambil_kurir">Kurir mengambil laundry</label><br>
<input type="radio" id="dicuci" name="status" value="Sementara dicuci">
<label for="dicuci">Sementara dicuci</label><br>
<input type="radio" id="diantar_kurir" name="status" value="Kurir mengantar laundry">
<label for="diantar_kurir">Kurir mengantar laundry</label><br>
<input type="radio" id="selesai" name="status" value="Selesai">
<label for="selesai">Selesai</label>
</ul>
<?php
}
?>
<?php
if($view_order == false){
//Kosong
}
else{ ?>
<p class="tengah">
<input type="submit" name="update_order" value="Update"/>
<input type="submit" name="cancel_update" value="Cancel"/>
</p>
</form>
<?php
}
?>
</div>
</div>
<div class="jumbotron jumbotron-fluid bg-white">
<div class="container">
<h1 class="tengah" id ="customers">Profil Pelanggan</h1>
<p class="tengah">Daftar pelanggan yang terdaftar.
</p>
<br>
<table id="pagination2" class="table table-striped table-bordered">
<thead>
<tr>
<th scope="col">ID User</th>
<th scope="col">Nama</th>
<th scope="col">E-mail</th>
<th scope="col">Nomor Telepon</th>
<th scope="col">Edit</th>
<th scope="col">Delete</th>
</tr>
</thead>
<tbody>
<?php
foreach ( $rows as $row ) {
?>
<tr>
<th><?=$row['id']?></th>
<th><?=$row['name'] ?></th>
<td><?=$row['email'] ?></td>
<td><?=$row['nomor_telepon']?></td>
<td>
<form action="admin_dash.php?edit=<?php echo $row['id']; ?>#customers" method="post">
<input type="hidden" name="id" value="<?=$row['id']?>">
<input type="submit" value="Edit" name="edit">
</form>
</td>
<td>
<form method="post">
<input type="hidden" name="id" value="<?=$row['id']?>">
<input type="submit" value="Delete" name="delete">
</form>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<br>
<?php
if($edit_form == false){
// Kosong
}
else{ ?>
<!-- Untuk memunculkan edit customer -->
<h4 class="tengah">Edit customer</h4>
<form method="post">
<p class="tengah">Nama : </p>
<p class="tengah"><input type="text" class = "tengah" name="nama" value="<?php echo $name; ?>"></p>
<p class="tengah">E-mail : </p>
<p class="tengah"><input type="email" class = "tengah" name="email" value="<?php echo $email; ?>"></p>
<p class="tengah">Password : </p>
<p class="tengah"><input type="password" class = "tengah" name="password" id="password"></p>
<p class="tengah"><input type="checkbox" onclick="myFunction()"> Show Password</p>
<p class="tengah">Nomor Telepon : </p>
<p class="tengah"><input type="text" class="tengah" name="nomor_telepon" value="<?php echo $nomor_telepon; ?>"></p>
<?php
} ?>
<br>
<?php
if($edit_form == false){ ?>
<?php
}
else{ ?>
<p class="tengah"><input type="submit" name="update" value="Update"/>
<input type="submit" name="cancel" value="Cancel"/>
</p>
</form>
<?php
} ?>
</div>
</div>
<!-- Footer -->
<footer class="page-footer font-small blue">
<div class="footer-copyright text-center py-3 bg-dark text-white">© 2020 Copyright:
<a href="https://laundryonlinemks.com/"> Laundry OnLine</a>
</div>
</footer>
</div>
</div>
</body>
<script>
//Menggunakan library DataTables
$(document).ready(function() {
$('#pagination').DataTable();
} );
$(document).ready(function() {
$('#pagination2').DataTable();
} );
//Memunculkan password
function myFunction(){
var x = document.getElementById("password");
if (x.type === "password"){
x.type = "text";
}
else{
x.type = "password";
}
}
// fungsi initialize untuk mempersiapkan peta
function initMap() {
// Menentukan koordinat awal peta, perbesaran, serta jenis peta
var propertiPeta = {
center:new google.maps.LatLng(<?php echo $garisLintang; ?> <?php echo $garisBujur; ?>),
zoom:15,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
// Inisiasi peta sesuai dengan Id yang telah ditentukan
var peta = new google.maps.Map(document.getElementById("googleMaps"), propertiPeta);
// Menambahkan penanda pada peta
var marker=new google.maps.Marker({
position: new google.maps.LatLng(<?php echo $garisLintang; ?> <?php echo $garisBujur; ?>),
map: peta,
animation: google.maps.Animation.BOUNCE
});
}
// event jendela dimuat
google.maps.event.addDomListener(window, 'load', initMap);
</script>