-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgallery_data.php
More file actions
155 lines (149 loc) · 10 KB
/
Copy pathgallery_data.php
File metadata and controls
155 lines (149 loc) · 10 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
<table class="table table-hover">
<thead class="table-dark">
<tr>
<th>No</th>
<th class="w-25">Tanggal</th>
<th class="w-50">Gambar</th>
<th class="w-50">Aksi</th>
</tr>
</thead>
<tbody>
<?php
include "koneksi.php";
$hlm = (isset($_POST['hlm'])) ? $_POST['hlm'] : 1;
$limit = 3;
$limit_start = ($hlm - 1) * $limit;
$no = $limit_start + 1;
$sql = "SELECT * FROM gallery ORDER BY tanggal DESC LIMIT $limit_start, $limit";
$hasil = $conn->query($sql);
$no = 1;
while ($row = $hasil->fetch_assoc()) {
?>
<tr>
<td><?= $no++ ?></td>
<td>
pada : <?= $row["tanggal"] ?>
<br>oleh : <?= $row["username"] ?>
</td>
<td>
<?php
if ($row["gambar"] != '') {
if (file_exists('img/' . $row["gambar"] . '')) {
?>
<img src="img/<?= $row["gambar"] ?>" width="100" class="image-thumbnail" alt="Thumbnail Image" data-large="img/<?= $row["gambar"] ?>">
<?php
}
}
?>
</td>
<td>
<a href="#" title="edit" class="badge rounded-pill text-bg-success" data-bs-toggle="modal" data-bs-target="#modalEdit<?= $row["id"] ?>"><i class="bi bi-pencil"></i></a>
<a href="#" title="delete" class="badge rounded-pill text-bg-danger" data-bs-toggle="modal" data-bs-target="#modalHapus<?= $row["id"] ?>"><i class="bi bi-x-circle"></i></a>
<!-- Awal Modal Edit -->
<div class="modal fade" id="modalEdit<?= $row["id"] ?>" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="staticBackdropLabel">Edit Gallery</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form method="post" action="" enctype="multipart/form-data">
<div class="modal-body">
<div class="mb-3">
<input type="hidden" name="id" value="<?=$row["id"] ?>">
</div>
<div class="mb-3">
<label for="formGroupExampleInput2" class="form-label">Ganti Gambar</label>
<input type="file" class="form-control" name="gambar">
</div>
<div class="mb-3">
<label for="formGroupExampleInput3" class="form-label">Gambar Lama</label>
<?php
if ($row["gambar"] != '') {
if (file_exists('img/' . $row["gambar"] . '')) {
?>
<br><img src="img/<?= $row["gambar"] ?>" width="100">
<?php
}
}
?>
<input type="hidden" name="gambar_lama" value="<?= $row["gambar"] ?>">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<input type="submit" value="simpan" name="simpan" class="btn btn-primary">
</div>
</form>
</div>
</div>
</div>
<!-- Akhir Modal Edit -->
<!-- Awal Modal Hapus -->
<div class="modal fade" id="modalHapus<?= $row["id"] ?>" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="staticBackdropLabel">Konfirmasi Hapus Gambar</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form method="post" action="" enctype="multipart/form-data">
<div class="modal-body">
<div class="mb-3">
<label for="formGroupExampleInput" class="form-label">Yakin akan menghapus Gambar?</label>
<input type="hidden" name="id" value="<?= $row["id"] ?>">
<input type="hidden" name="gambar" value="<?= $row["gambar"] ?>">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">batal</button>
<input type="submit" value="hapus" name="hapus" class="btn btn-primary">
</div>
</form>
</div>
</div>
</div>
<!-- Akhir Modal Hapus -->
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
$sql1 = "SELECT * FROM gallery";
$hasil1 = $conn->query($sql1);
$total_records = $hasil1->num_rows;
?>
<p>Total Gallery : <?php echo $total_records; ?></p>
<nav class="mb-2">
<ul class="pagination justify-content-end">
<?php
$jumlah_page = ceil($total_records / $limit);
$jumlah_number = 1; //jumlah halaman ke kanan dan kiri dari halaman yang aktif
$start_number = ($hlm > $jumlah_number)? $hlm - $jumlah_number : 1;
$end_number = ($hlm < ($jumlah_page - $jumlah_number))? $hlm + $jumlah_number : $jumlah_page;
if($hlm == 1){
echo '<li class="page-item disabled"><a class="page-link" href="#">First</a></li>';
echo '<li class="page-item disabled"><a class="page-link" href="#"><span aria-hidden="true">«</span></a></li>';
} else {
$link_prev = ($hlm > 1)? $hlm - 1 : 1;
echo '<li class="page-item halaman" id="1"><a class="page-link" href="#">First</a></li>';
echo '<li class="page-item halaman" id="'.$link_prev.'"><a class="page-link" href="#"><span aria-hidden="true">«</span></a></li>';
}
for($i = $start_number; $i <= $end_number; $i++){
$link_active = ($hlm == $i)? ' active' : '';
echo '<li class="page-item halaman '.$link_active.'" id="'.$i.'"><a class="page-link" href="#">'.$i.'</a></li>';
}
if($hlm == $jumlah_page){
echo '<li class="page-item disabled"><a class="page-link" href="#"><span aria-hidden="true">»</span></a></li>';
echo '<li class="page-item disabled"><a class="page-link" href="#">Last</a></li>';
} else {
$link_next = ($hlm < $jumlah_page)? $hlm + 1 : $jumlah_page;
echo '<li class="page-item halaman" id="'.$link_next.'"><a class="page-link" href="#"><span aria-hidden="true">»</span></a></li>';
echo '<li class="page-item halaman" id="'.$jumlah_page.'"><a class="page-link" href="#">Last</a></li>';
}
?>
</ul>
</nav>