-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_fetch_update_user.php
86 lines (73 loc) · 2.82 KB
/
admin_fetch_update_user.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
<?php
include 'connect.php';
header('Content-type: application/json');
// FILE UNTUK RESPONSE UPDATE (UBAH JADI KETUA ATAU MEMBER) DAN AMBIL SEMUA USER.
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
// Update Status Ketua
if($_POST['type'] == 'UPDATE'){
$email = $_POST['email'];
$sql = "UPDATE user
SET ketua = (ketua+1) % 2
WHERE email = '$email'";
$stmt = $pdo->prepare($sql);
$stmt->execute();
}
// Read Semua User Kecuali Admin
// Bila $_POST['type'] = update maka akan mengupdate dan tampilan
// akan otomatis terganti karena bawahnya langsung di read
$sql = "SELECT email,
nama,
hp,
FLOOR(DATEDIFF(NOW(),lahir)/365.25) as umur,
ketua,
group_member
FROM user
WHERE email != '[email protected]'";
$stmt = $pdo->prepare($sql);
$stmt->execute();
// Isi DataTable
$output =
'<table id="manage-users" class="table table-bordered">
<thead>
<tr>
<th><b>No</b></th>
<th><b>Email</b></th>
<th><b>Nama</b></th>
<th><b>No HP</b></th>
<th><b>Action</b></th>
<th><b>Detail</b></th>
</tr>
</thead>';
$output .= '<tbody>';
$count = 0;
$detail_button = '<div class="container">
<div class="row">
<input type="submit" role="button" class="btn btn-info see-detail" href="#detail" data-bs-toggle="modal" value="See Detail">
</div>
</div>';
while($row = $stmt->fetch()){
$button = '<div class="container">
<div class="row">
<input type="submit" class="btn btn-warning ubah-ketua btn-block" data-email="' . $row['email'] . '" value="Ubah Jadi Member">
</div>
</div> ';
if( $row['ketua'] == 0 ){
$button = '<div class="container">
<div class="row">
<input type="submit" class="btn btn-success btn-block ubah-ketua" data-email="' . $row['email'] . '" value="Ubah Jadi Ketua">
</div>
</div>';
}
$output .= '<tr>
<td>'. ++$count .'</td>
<td>'. $row['email'] .'</td>
<td>'. $row['nama'] .'</td>
<td>'. $row['hp'] .'</td>
<td>'. $button .'</td>
<td>'. $detail_button .'</td>
</tr>';
}
$output .= '</tbody></table>';
echo json_encode(array('output' => $output));
}
?>