-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_excel.php
More file actions
67 lines (57 loc) · 1.82 KB
/
Copy pathexport_excel.php
File metadata and controls
67 lines (57 loc) · 1.82 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
<?php
include 'config.php';
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=export_data.xls");
$type = $_GET['type'] ?? 'bukutamu';
$startDate = $_GET['startDate'] ?? '';
$endDate = $_GET['endDate'] ?? '';
echo "<table border='1'>";
if ($type === 'absensi') {
echo "<tr>
<th>Tanggal</th>
<th>Nama Guru</th>
<th>Hari</th>
<th>Jam Masuk</th>
<th>Jam Keluar</th>
</tr>";
$sql = "SELECT a.*, g.nama FROM absensi a
LEFT JOIN guru g ON a.id_guru = g.id";
if (!empty($startDate) && !empty($endDate)) {
$sql .= " WHERE a.tanggal BETWEEN '$startDate' AND '$endDate'";
}
$result = $conn->query($sql);
while ($row = $result->fetch_assoc()) {
echo "<tr>
<td>{$row['tanggal']}</td>
<td>{$row['nama']}</td>
<td>{$row['hari']}</td>
<td>{$row['jam_masuk']}</td>
<td>{$row['jam_keluar']}</td>
</tr>";
}
} else {
echo "<tr>
<th>Nama</th>
<th>Tujuan</th>
<th>Asal</th>
<th>Keperluan</th>
<th>Tanggal</th>
<th>Waktu</th>
</tr>";
$sql = "SELECT * FROM buku_tamu";
if (!empty($startDate) && !empty($endDate)) {
$sql .= " WHERE tanggal_kunjungan BETWEEN '$startDate' AND '$endDate'";
}
$result = $conn->query($sql);
while ($row = $result->fetch_assoc()) {
echo "<tr>
<td>{$row['nama']}</td>
<td>{$row['tujuan']}</td>
<td>{$row['asal']}</td>
<td>{$row['keperluan']}</td>
<td>{$row['tanggal_kunjungan']}</td>
<td>{$row['waktu_kunjungan']}</td>
</tr>";
}
}
echo "</table>";