-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtabel.php
More file actions
411 lines (358 loc) · 13.9 KB
/
Copy pathtabel.php
File metadata and controls
411 lines (358 loc) · 13.9 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
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
411
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Daftar Buku Tamu - GARIS</title>
<!-- Custom fonts & Bootstrap 5 -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@300;400;600;700&display=swap" rel="stylesheet">
<!-- DataTables CSS -->
<link href="https://cdn.datatables.net/1.11.5/css/dataTables.bootstrap5.min.css" rel="stylesheet">
<!-- Custom styles -->
<style>
body {
font-family: 'Nunito', sans-serif;
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
min-height: 100vh;
padding: 30px 0;
}
.container {
max-width: 1200px;
}
.logo-container {
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 2rem;
}
.logo-container img {
width: 70px;
height: auto;
filter: drop-shadow(0 5px 10px rgba(0, 0, 0, 0.1));
}
.logo-text {
margin-left: 15px;
}
.logo-text h2 {
margin: 0;
font-size: 1.5rem;
font-weight: 700;
color: #4e73df;
line-height: 1.2;
}
.card {
border: none;
border-radius: 15px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
overflow: hidden;
margin-bottom: 30px;
}
.card-header {
background: linear-gradient(135deg, #4e73df 0%, #6610f2 100%);
color: white;
border: none;
padding: 20px;
position: relative;
}
.card-header h3 {
margin: 0;
font-weight: 700;
font-size: 1.5rem;
}
.card-body {
padding: 30px;
}
.form-control, .form-select {
padding: 12px;
border-radius: 10px;
border: 1px solid #e1e5eb;
font-size: 1rem;
transition: all 0.3s;
}
.form-control:focus, .form-select:focus {
border-color: #4e73df;
box-shadow: 0 0 0 0.25rem rgba(78, 115, 223, 0.25);
}
.btn-primary {
background: linear-gradient(135deg, #4e73df 0%, #6610f2 100%);
border: none;
border-radius: 50px;
padding: 10px 20px;
font-weight: 600;
transition: all 0.3s;
}
.btn-primary:hover {
transform: translateY(-3px);
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}
.btn-success {
background: linear-gradient(135deg, #1cc88a 0%, #20c997 100%);
border: none;
border-radius: 50px;
padding: 10px 20px;
font-weight: 600;
transition: all 0.3s;
}
.btn-success:hover {
transform: translateY(-3px);
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}
.table {
margin-top: 20px;
border-collapse: separate;
border-spacing: 0;
}
.table th {
background-color: #f8f9fc;
font-weight: 700;
color: #4e73df;
border: none;
padding: 15px;
}
.table td {
vertical-align: middle;
padding: 15px;
border-top: 1px solid #e3e6f0;
}
.table-striped tbody tr:nth-of-type(odd) {
background-color: #f8f9fc;
}
.table-hover tbody tr:hover {
background-color: #eaecf4;
}
.img-thumbnail {
border-radius: 10px;
border: 2px solid #4e73df;
padding: 3px;
}
.back-btn {
display: inline-flex;
align-items: center;
color: #4e73df;
text-decoration: none;
font-weight: 600;
margin-bottom: 20px;
transition: all 0.3s;
}
.back-btn i {
margin-right: 8px;
}
.back-btn:hover {
transform: translateX(-3px);
color: #6610f2;
}
.filter-section {
background-color: #f8f9fc;
padding: 20px;
border-radius: 10px;
margin-bottom: 20px;
}
.filter-section .col-form-label {
font-weight: 600;
color: #4e73df;
}
.dataTables_filter input {
padding: 8px 12px;
border-radius: 50px;
border: 1px solid #e1e5eb;
}
.dataTables_length select {
padding: 8px;
border-radius: 10px;
border: 1px solid #e1e5eb;
}
.pagination .page-item.active .page-link {
background-color: #4e73df;
border-color: #4e73df;
}
.pagination .page-link {
color: #4e73df;
}
</style>
<!-- JS Libraries -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.11.5/js/dataTables.bootstrap5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.3/xlsx.full.min.js"></script>
</head>
<body>
<div class="container">
<!-- Logo dan Judul -->
<div class="logo-container">
<img src="assets/img/logo-grafika.png" alt="Logo GARIS">
<div class="logo-text">
<h2>Grafika Apresiasi Silaturahmi</h2>
<h2>GARIS</h2>
</div>
</div>
<a href="index.php" class="back-btn"><i class="fas fa-arrow-left"></i>Kembali ke Beranda</a>
<div class="card shadow">
<div class="card-header">
<h3><i class="fas fa-book me-2"></i>Daftar Tamu</h3>
</div>
<div class="card-body">
<!-- Filter -->
<div class="filter-section">
<div class="row align-items-center">
<div class="col-md-4">
<div class="mb-3 mb-md-0">
<label for="startDate" class="col-form-label">Dari Tanggal:</label>
<input type="date" id="startDate" class="form-control">
</div>
</div>
<div class="col-md-4">
<div class="mb-3 mb-md-0">
<label for="endDate" class="col-form-label">Sampai Tanggal:</label>
<input type="date" id="endDate" class="form-control">
</div>
</div>
<div class="col-md-4">
<div class="d-flex justify-content-md-end align-items-end h-100">
<button class="btn btn-success" id="filterBtn">
<i class="fas fa-filter me-2"></i>Filter
</button>
<button class="btn btn-primary ms-2" id="exportExcel">
<i class="fas fa-file-excel me-2"></i>Export
</button>
</div>
</div>
</div>
</div>
<!-- Tabel -->
<div class="table-responsive">
<table class="table table-striped table-hover" id="tabelTamu">
<thead>
<tr>
<th>Tanggal</th>
<th>Nama</th>
<th>Instansi</th>
<th>Asal</th>
<th>Pesan</th>
<th>Foto</th>
</tr>
</thead>
<tbody>
<!-- Data akan dimuat dari JavaScript -->
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- Custom script -->
<script>
$(document).ready(function () {
// Inisialisasi DataTable
let dataTable = $('#tabelTamu').DataTable({
language: {
search: "Cari:",
lengthMenu: "Tampilkan _MENU_ data",
info: "Menampilkan _START_ sampai _END_ dari _TOTAL_ data",
infoEmpty: "Menampilkan 0 sampai 0 dari 0 data",
infoFiltered: "(disaring dari _MAX_ total data)",
zeroRecords: "Tidak ada data yang ditemukan",
paginate: {
first: "Pertama",
last: "Terakhir",
next: "Selanjutnya",
previous: "Sebelumnya"
}
},
responsive: true
});
function loadTable(startDate = '', endDate = '') {
$.ajax({
url: 'tampil_bukutamu.php',
type: 'GET',
data: { startDate: startDate, endDate: endDate },
dataType: 'json',
beforeSend: function() {
// Clear previous data and show loading
dataTable.clear().draw();
$('.card-body').append('<div id="loading" class="text-center mt-4"><i class="fas fa-spinner fa-spin fa-2x text-primary"></i><p class="mt-2">Memuat data...</p></div>');
},
success: function (data) {
// Remove loading indicator
$('#loading').remove();
// Clear the table and add new data
dataTable.clear();
if (data.length === 0) {
// No data found
dataTable.draw();
} else {
// Add data to table
data.forEach(function (row) {
dataTable.row.add([
formatDate(row.tanggal_kunjungan),
row.nama,
row.instansi || '-',
row.asal,
row.keperluan,
'<img src="' + row.foto + '" width="60" class="img-thumbnail">'
]);
});
dataTable.draw();
}
},
error: function () {
$('#loading').remove();
alert("Gagal memuat data tamu.");
}
});
}
// Format tanggal ke format Indonesia
function formatDate(dateString) {
const options = {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric'
};
const date = new Date(dateString);
return date.toLocaleDateString('id-ID', options);
}
// Load saat halaman dibuka
loadTable();
// Filter berdasarkan tanggal
$('#filterBtn').on('click', function () {
const start = $('#startDate').val();
const end = $('#endDate').val();
if (start && end) {
if (new Date(start) > new Date(end)) {
alert("Tanggal awal tidak boleh lebih besar dari tanggal akhir!");
return;
}
loadTable(start, end);
} else if (!start && !end) {
loadTable();
} else {
alert("Mohon isi kedua tanggal untuk melakukan filter!");
}
});
// Export Excel
$('#exportExcel').click(function () {
if (dataTable.data().count() === 0) {
alert("Tidak ada data untuk diekspor!");
return;
}
// Create a workbook and worksheet
let wb = XLSX.utils.book_new();
// Convert the DataTable to a worksheet
let ws = XLSX.utils.table_to_sheet(document.getElementById("tabelTamu"));
// Add the worksheet to the workbook
XLSX.utils.book_append_sheet(wb, ws, "Daftar Tamu");
// Generate filename
let startDate = $('#startDate').val() || 'semua';
let endDate = $('#endDate').val() || 'data';
let filename = `daftar_tamu_${startDate}_${endDate}.xlsx`;
// Write the workbook and save the file
XLSX.writeFile(wb, filename);
});
});
</script>
</body>
</html>