-
Notifications
You must be signed in to change notification settings - Fork 0
/
membership.php
308 lines (252 loc) · 10.4 KB
/
membership.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
<?php
session_start();
// membatasi halaman sebelum login
if (!isset($_SESSION["login"])){
echo "<script>
alert('login dulu bang');
document.location.href = 'login.php';
</script>";
exit;
}
$title = 'Laporan Membership Aktif';
include 'layout/navbar.php';
// tampil seluruh data
$data_akun = select("SELECT * FROM akun WHERE membership=1" );
//tampil data berdasarkan user login
$id_akun = $_SESSION['id_akun'];
$data_bylogin = select("SELECT * FROM akun WHERE id_akun = $id_akun");
//jika tombol tambah di tekan dijalnkan script berikut
if(isset($_POST['tambah'])) {
if (create_akun($_POST) > 0) {
echo "<script>
alert('Data akun Berhasil Ditambahkan');
document.location.href = 'crud-modal.php';
</script>";
} else {
echo "<script>
alert('Data akun Gagal Di tambahkan');
document.location.href = 'crud-modal.php';
</script>";
}
}
//jika tombol ubah di tekan dijalnkan script berikut
if(isset($_POST['ubah'])) {
if (update_akun($_POST) > 0) {
echo "<script>
alert('Data akun Berhasil Diubah');
document.location.href = 'crud-modal.php';
</script>";
} else {
echo "<script>
alert('Data akun Gagal Di ubah');
document.location.href = 'crud-modal.php';
</script>";
}
}
?>
<br>
<br>
<br>
<div class="container mt-5">
<div class="d-flex justify-content-between">
<h1><i class="fas fa-list"></i> Laporan Membership Aktif</h1>
<div>
<a href="membership-print.php" target="_blank" class="btn btn-primary">Print</a>
</div>
</div>
<hr>
<h7 >Peringatan : </h7><br><br>
<p>di sini merupakan tempat hasil karaya anda dimasukan dalam arsif di terbitkan dalam sebuah website anda dapat melihat laporan karya anda disini</p>
<hr>
<br>
<!-- <?php if($_SESSION['level'] == 1 ) : ?>
<button type="button" class="btn btn-primary mb-1" data-bs-toggle="modal"
data-bs-target="#modalTambah">tambah</button>
<?php endif; ?> -->
<!-- MENAMPILKAN DATA TABEL-->
<table class="table table-bordered table-striped mt-3" id="table">
<thead>
<tr>
<th>No</th>
<th>Nama</th>
<th>Username</th>
<th>Email</th>
<th>Password</th>
<th>Total harga membership</th>
<th>Mulai berlangganan</th>
<th>Expired</th>
<th>Aksi</th>
</tr>
</thead>
<tbody>
<?php $no =1; ?>
<!-- tampil seluruh data-->
<?php if ($_SESSION['level'] == 1) : ?>
<?php foreach($data_akun as $akun) : ?>
<tr>
<td> <?= $no++; ?></td>
<td> <?= $akun['nama']; ?></td>
<td> <?= $akun['username']; ?></td>
<td> <?= $akun['email']; ?></td>
<td>Password Ter-enkripsi</td>
<td> <?= $akun['membership'] ? 'Rp299.000' : 'Belum membership'; ?></td>
<td> <?= select("SELECT tgl_disetujui FROM membership WHERE id_akun = {$akun['id_akun']}")[0]['tgl_disetujui'] ?? 'Menunggu persetujuan' ?></td>
<td> <?= select("SELECT tgl_expired FROM membership WHERE id_akun = {$akun['id_akun']}")[0]['tgl_expired'] ?? 'Menunggu persetujuan' ?></td>
<td class="text-center">
<button type="button" class="btn btn-success mb-1" data-bs-toggle="modal"
data-bs-target="#modalUbah<?= $akun['id_akun']?>">Ubah</button>
<button type="button" class="btn btn-danger mb-1" data-bs-toggle="modal"
data-bs-target="#modalHapus<?= $akun['id_akun']?>">Hapus</button>
</td>
</tr>
<?php endforeach; ?>
<?php else :?>
<!-- tampil data berdasarkan user pengguna login-->
<?php foreach($data_bylogin as $akun) : ?>
<tr>
<td> <?= $no++; ?></td>
<td> <?= $akun['nama']; ?></td>
<td> <?= $akun['username']; ?></td>
<td> <?= $akun['email']; ?></td>
<td>Password Ter-enkripsi</td>
<td> <?= $akun['membership'] ? 'Rp299.000' : 'Belum membership'; ?></td>
<td> <?= select("SELECT tgl_disetujui FROM membership WHERE id_akun = {$akun['id_akun']}")[0]['tgl_disetujui'] ?? 'Menunggu persetujuan' ?></td>
<td> <?= select("SELECT tgl_expired FROM membership WHERE id_akun = {$akun['id_akun']}")[0]['tgl_expired'] ?? 'Menunggu persetujuan' ?></td>
<td class="text-center">
<button type="button" class="btn btn-success mb-1" data-bs-toggle="modal"
data-bs-target="#modalUbah<?= $akun['id_akun']?>">Ubah</button>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
<!-- Modal tambah -->
<div class="modal fade" id="modalTambah" tabindex="-1" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header bg-primary text-white">
<h1 class="modal-title fs-5" id="exampleModalLabel">Tambah Akun</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="" method="post">
<div class="mb-3">
<label for="nama">Nama</label>
<input type="text" name="nama" id="nama" class="form-control" required>
</div>
<div class="mb-3">
<label for="username">Username</label>
<input type="text" name="username" id="username" class="form-control" required>
</div>
<div class="mb-3">
<label for="email">Email</label>
<input type="email" name="email" id="email" class="form-control" required>
</div>
<div class="mb-3">
<label for="password">Password</label>
<input type="password" name="password" id="password" class="form-control"
required minlength="6">
</div>
<div class="mb-3">
<label for="level">Level</label>
<select name="level" id="level" class="form-control" required>
<option value="">-- pilih level --</option>
<option value="1">Admin</option>
<option value="3">User</option>
<!-- <option value="3">pengguna</option> -->
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Kembali</button>
<button type="submit" name="tambah" class="btn btn-primary">Tambah</button>
</div>
</form>
</div>
</div>
</div>
<!-- Modal ubah -->
<?php foreach($data_akun as $akun) : ?>
<div class="modal fade" id="modalUbah<?= $akun['id_akun'];?>" tabindex="-1" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header bg-succes text-white">
<h1 class="modal-title fs-5" id="exampleModalLabel">Ubah Akun</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="" method="post">
<input type="hidden" name="id_akun" value="<?= $akun['id_akun']; ?>">
<div class="mb-3">
<label for="nama">Nama</label>
<input type="text" name="nama" id="nama" class="form-control"
value="<?= $akun['nama'];?>" required>
</div>
<div class="mb-3">
<label for="username">Username</label>
<input type="text" name="username" id="username" class="form-control"
value="<?= $akun['username'];?>" required>
</div>
<div class="mb-3">
<label for="email">Email</label>
<input type="email" name="email" id="email" class="form-control"
value="<?= $akun['email']; ?>" required>
</div>
<div class="mb-3">
<label for="password">Password
<small>(Masukan password baru)</small>
</label>
<input type="password" name="password" id="password" class="form-control"
required minlength="6">
</div>
<?php if ($_SESSION['level'] == 1) : ?>
<div class="mb-3">
<label for="level">Level</label>
<select name="level" id="level" class="form-control" required>
<?php $level = $akun['level']; ?>
<option value="1" <?= $level == '1' ? 'selected' : null ?>>Admin</option>
<option value="3" <?= $level == '3' ? 'selected' : null ?>>User</option>
<!-- <option value="3" <?= $level == '3' ? 'selected' : null ?>>pengguna</option> -->
</select>
</div>
<!-- hidden -->
<?php else :?>
<input type="hidden" name="level" value="<?= $akun['level']; ?>">
<?php endif; ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Kembali</button>
<button type="ubah" name="ubah" class="btn btn-success">Ubah</button>
</div>
</form>
</div>
</div>
</div>
<?php endforeach;?>
<!-- Modal Hapus -->
<?php foreach($data_akun as $akun) : ?>
<div class="modal fade" id="modalHapus<?= $akun['id_akun'];?>" tabindex="-1" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header bg-danger text-white">
<h1 class="modal-title fs-5" id="exampleModalLabel">Hapus Akun</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>Yakin anda menghapus akun : <?= $akun['nama']; ?> .? </p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
<a href="hapus-akun.php?id_akun=<?= $akun['id_akun']; ?>" class="btn
btn-danger">Hapus</a>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
<?php include 'layout/footer.php'; ?>