-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharticle_data.php
More file actions
164 lines (158 loc) · 10.8 KB
/
Copy patharticle_data.php
File metadata and controls
164 lines (158 loc) · 10.8 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
<table class="table table-hover">
<thead class="table-dark">
<tr>
<th>No</th>
<th class="w-25">Judul</th>
<th class="w-75">Isi</th>
<th class="w-25">Gambar</th>
<th class="w-25">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 article ORDER BY tanggal DESC LIMIT $limit_start, $limit";
$hasil = $conn->query($sql);
$no = 1;
while ($row = $hasil->fetch_assoc()) {
?>
<tr>
<td><?= $no++ ?></td>
<td>
<strong><?= $row["judul"] ?></strong>
<br>pada : <?= $row["tanggal"] ?>
<br>oleh : <?= $row["username"] ?>
</td>
<td><?= $row["isi"] ?></td>
<td>
<?php
if ($row["gambar"] != '') {
if (file_exists('img/' . $row["gambar"] . '')) {
?>
<img src="img/<?= $row["gambar"] ?>" width="100">
<?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 Article</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">Judul</label>
<input type="hidden" name="id" value="<?= $row["id"] ?>">
<input type="text" class="form-control" name="judul" placeholder="Tuliskan Judul Artikel" value="<?= $row["judul"] ?>" required>
</div>
<div class="mb-3">
<label for="floatingTextarea2">Isi</label>
<textarea class="form-control" placeholder="Tuliskan Isi Artikel" name="isi" required><?= $row["isi"] ?></textarea>
</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 Article</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 artikel "<strong><?= $row["judul"] ?></strong>"?</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 article";
$hasil1 = $conn->query($sql1);
$total_records = $hasil1->num_rows;
?>
<p>Total article : <?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>