-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_user_list.php
112 lines (79 loc) · 3.33 KB
/
admin_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
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
<?php
$title = 'User List';
include './php/config.php';
session_start();
$admin_id = $_SESSION['admin_id'];
if(!isset($admin_id)){
header('location:login.php');
}
if(isset($_GET['delete'])){
$id = $_GET['delete'];
$sql = "DELETE FROM users WHERE id = '$id'";
$result = mysqli_query($con, $sql);
if($result){
echo '<script>alert("User Deleted Successfully!");
window.location.href="admin_user_list.php";</script>';
} else {
echo '<script>alert("User not deleted!")</script>';
}
}
include './templates/admin_header.php';
?>
<link rel="stylesheet" href="./css/user_list.css">
<div class="main-container b-main">
<?php include './templates/admin_navigation.php' ?>
<div class="user-container">
<div class="user-list">
<h2>Our User List</h2><br>
<ul>
<?php
$select_user_list = mysqli_query($con, "SELECT * FROM users WHERE user_type = 'user'") or die('query failed');
if(mysqli_num_rows($select_user_list) > 0){
while($fetch_user_list = mysqli_fetch_assoc($select_user_list)){
?>
<?php $name = $fetch_user_list['firstName'] . ' ' . $fetch_user_list['lastName'] ?>
<li><i class="fa-solid fa-user"></i><span><?php echo $name; ?></span> -
<a href="admin_user_list.php?delete=<?php echo $fetch_user_list['id']; ?>" onclick="return confirm('Delete this user?');">Delete</a>
<?php
}
} else {
echo '<p class="empty">No users found!</p>';
}
?>
</ul>
<?php
if(isset($_GET['update'])){
$id = $_GET['update'];
$update_query = mysqli_query($con, "SELECT * FROM categories WHERE id = '$id'") or die('query failed');
if(mysqli_num_rows($update_query) > 0){
while($fetch_update = mysqli_fetch_assoc($update_query)){
?>
<form action="" method="post" id="cat-change-form">
<label for="update_name">Edit user Name :</label>
<div class="input-field cat-input-field">
<input type="hidden" name="update_id" value="<?php echo $fetch_update['id']; ?>">
<input type="text" name="update_name" id="update_name" placeholder="Title" value="<?php echo $fetch_update['name']; ?>" required>
</div>
<div class="card-btns">
<input type="submit" name="update" value="Update" class="btn update-btn">
<input type="reset" name="cancel" value="Close" id="close-cat-update" class="btn">
</div>
</form>
<?php
}
}
}else{
echo '<script>document.querySelector("#cat-change-form").style.display = "none";</script>';
}
?>
</div>
</div>
</div>
<script>
document.querySelector('#close-cat-update').onclick = () => {
document.querySelector('#cat-change-form').style.display = 'none';
}
</script>
<?php
include './templates/footer.php';
?>