-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.admin.php
136 lines (135 loc) · 4.33 KB
/
list.admin.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
<?php
session_start();
$activeTitle = "Admin List";
$activePage = "admin.list";
require 'up.html.php';
require 'login.control.php';
?>
<?php
//!Tekil admin silme
if (isset($_GET['removeAdminid'])) {
$approves = array();
require 'db.php';
$remove_id = $_GET['removeAdminid'];
$sql = "DELETE FROM admins WHERE userid = :removeAdminid";
$SORGU = $DB->prepare($sql);
$SORGU->bindParam(':removeAdminid', $remove_id);
$SORGU->execute();
$approves[] = "Admin Deleted Successfully...";
}
?>
<?php
//!Tüm Adminleri silme
if (isset($_POST['removeAllAdmins'])) {
$approves = array();
require 'db.php';
$sql = "DELETE FROM admins WHERE userid != 1";
$SORGU = $DB->prepare($sql);
$SORGU->execute();
$approves[] = "All Admins Deleted Successfully...";
}
?>
<?php
//! Rol idsi 1 olan admin kullanıcılar listeyebilir
if ($_SESSION['role'] != 1) {
header("location: authorizationcontrol.php");
die();
}
?>
<?php require 'navbar.php'?>
<div class="container">
<?php
//! Başarılı mesajlarını göster
if (!empty($approves)) {
foreach ($approves as $approve) {
echo "<div class='position-fixed top-0 end-0 p-3' style='z-index: 5'>
<div class='toast align-items-center text-white bg-success border-0' role='alert' aria-live='assertive' aria-atomic='true' data-bs-delay='5000'>
<div class='d-flex'>
<div class='toast-body'>
$approve
</div>
<button type='button' class='btn-close btn-close-white me-2 m-auto' data-bs-dismiss='toast' aria-label='Close'></button>
</div>
</div>
</div>";
}
}
?>
<div class="row mt-3">
<div class='row justify-content-center text-center'>
<div class="col-sm-4 col-md-6 col-lg-8">
<h1 class='alert alert-primary mt-2'>Admin User List</h1>
</div>
<div class='row text-end'>
<p>
<a href='add.admin.php' class="btn btn-warning btn-sm ">
Add New Admin User <i class="bi bi-send"></i> </a>
</p>
</div>
</div>
<!-- tablo ile admin listeleme -->
<table id="example" class="table table-bordered table-striped " style="width:100%">
<thead>
<tr>
<th>User Id</th>
<th>Admin Image</th>
<th>User Name</th>
<th>Email</th>
<th>Gender</th>
<th>Create Date</th>
<th>Update</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
</div>
<?php
$id = $_SESSION['id'];
require_once 'db.php';
if ($_SESSION['id'] == 1) {
$SORGU = $DB->prepare("SELECT * FROM admins");
} else {
$SORGU = $DB->prepare("SELECT * FROM admins WHERE userid =:id");
$SORGU->bindParam(':id', $id);
}
$SORGU->execute();
$admins = $SORGU->fetchAll(PDO::FETCH_ASSOC);
//echo '<pre>'; print_r($admins);
?>
<div class="row justify-content-end ">
<div class="col-2">
<form method="post">
<?php if (count($admins) > 0) {?>
<button type="sumbit" name="removeAllAdmins" onclick="return confirm('Are you sure you want to delete all admins ?')" class="btn btn-danger float-end">Delete All Admins <i class="bi bi-trash"></i> </button>
<?php }?>
</form>
</div>
</div>
<?php
foreach ($admins as $admin) {
$gender = $admin['usergender'];
$gender = ($gender == 'M') ? 'Male' : 'Famale';
//! Kendi kullanıcısını silemez
if ($admin['userid'] == $_SESSION['id']) {
$deleteButton = "<span class='badge text-bg-danger fw-bold'>You Can't Delete Yourself !</span>";
} else {
$deleteButton = "<a href='list.admin.php?removeAdminid={$admin['userid']}' onclick='return confirm(\"Are you sure you want to delete {$admin['username']}?\")' class='btn btn-danger btn-sm'>Delete <i class='bi bi-trash'></i></a>";
}
echo "
<tr>
<th>{$admin['userid']}</th>
<td><img src='admin_images/{$admin['userimg']}' class='rounded-circle' width='100' height='100'></td>
<td><a class='link-primary link-offset-2 link-underline-opacity-25 link-underline-opacity-100-hover' href='view.admin.php?idAdmin={$admin['userid']}'>{$admin['username']}</a></td>
<td>{$admin['useremail']}</td>
<td>$gender</td>
<td>{$admin['createdate']}</td>
<td><a href='update.admin.php?idAdmin={$admin['userid']}' class='btn btn-success btn-sm'>Update <i class='bi bi-arrow-clockwise'></i></a></td>
<td>{$deleteButton}</td>
</tr>
";
}
?>
</tbody>
</table>
</div>
<?php require 'down.html.php';?>