-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_list.php
87 lines (82 loc) · 3.16 KB
/
user_list.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'db_connect.php' ?>
<div class="col-lg-12">
<div class="card card-outline card-success">
<div class="card-header">
<div class="card-tools">
<a class="btn btn-block btn-sm btn-default btn-flat border-primary" href="./index.php?page=new_user"><i class="fa fa-plus"></i> Add New User</a>
</div>
</div>
<div class="card-body">
<table class="table tabe-hover table-bordered" id="list">
<thead>
<tr>
<th class="text-center">#</th>
<th>Name</th>
<th>Email</th>
<th>Role</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
$type = array('',"Admin","Teacher","HOD", "Lipik", "Principal");
$qry = $conn->query("SELECT *,concat(user_name,' ',user_surname) as name FROM gpd_users order by concat(user_name,' ',user_surname) asc");
while($row= $qry->fetch_assoc()):
?>
<tr>
<th class="text-center"><?php echo $i++ ?></th>
<td><b><?php echo ucwords($row['name']) ?></b></td>
<td><b><?php echo $row['user_email'] ?></b></td>
<td><b><?php echo $type[$row['user_type_id']] ?></b></td>
<td class="text-center">
<button type="button" class="btn btn-default btn-sm btn-flat border-info wave-effect text-info dropdown-toggle" data-toggle="dropdown" aria-expanded="true">
Action
</button>
<div class="dropdown-menu" style="">
<a class="dropdown-item view_user" href="javascript:void(0)" data-id="<?php echo $row['user_id'] ?>">View</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="./index.php?page=edit_user&id=<?php echo $row['user_id'] ?>">Edit</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item delete_user" href="javascript:void(0)" data-id="<?php echo $row['user_id'] ?>">Delete</a>
</div>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$('#list').dataTable();
// Use event delegation for dynamically added elements
$(document).on('click', '.view_user', function(){
uni_modal("<i class='fa fa-id-card'></i> User Details","view_user.php?id="+$(this).attr('data-id'));
});
$(document).on('click', '.delete_user', function(){
var userId = $(this).attr('data-id');
console.log("Deleting user with ID: " + userId); // Debugging: Check if userId is correct
_conf("Are you sure to delete this USER ?","delete_user", [userId]);
});
});
function delete_user(userId){
console.log("called");
start_load();
$.ajax({
url: 'ajax.php?action=delete_user',
method: 'POST',
data: {id: userId},
success: function(resp){
console.log(resp);
if(resp == 1){
alert_toast("Data successfully deleted", 'success');
setTimeout(function(){
location.reload();
}, 1500);
}
}
});
}
</script>