-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin_users.php
More file actions
155 lines (141 loc) · 6.56 KB
/
admin_users.php
File metadata and controls
155 lines (141 loc) · 6.56 KB
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
<?php
require "core/config.php";
if(!isset($_SESSION["user"])) header("Location: login.php");
$user=$_SESSION["user"];
$users=load_users();
if ($users[$user]["is_admin"] == false) die($lang["message"]["is_admin"]);
$table_theme = "w3-theme-light";
include "core/header.php";
echo '
<div class="w3-theme-white">
<header class="w3-container w3-text-theme">
<h4><strong><i class="fas fa-users"></i> '. $lang["admin_users"]["title"] .'</strong></h4>
</header>
<div class="w3-row-padding w3-margin-bottom">
<table class="w3-table w3-striped w3-theme-white">
<tr class="w3-theme w3-border w3-border-theme-light">
<td class="w3-center"><b>'. $lang["admin_users"]["user"] .'</b></td>
<td class="w3-center" style="width: 25%"><b>'. $lang["admin_users"]["option"] .'</b></td>
</tr>
';
$user_names = [];
$total_pages = 0;
foreach($users as $u=>$data) {
$user_names[$total_pages] = $u;
$total_pages += 1;
}
$adjacents = 6;
$targetpage = "admin_users.php";
$limit = 15;
$page = $_GET['page'];
if ($page)
$start = ($page - 1) * $limit;
else
$start = 0;
if ($page == 0)
$page = 1;
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total_pages/$limit);
$lpm1 = $lastpage - 1;
$pagination = "";
$i = $start;
while (1) {
if ($table_theme == "w3-theme-light")
$table_theme = "w3-theme-white";
else
$table_theme = "w3-theme-light";
echo '
<tr class="w3-theme-white">
<td class="w3-border '. $table_theme .' w3-border-theme-light w3-hover-text-theme" style="vertical-align: middle;">
<b>'. htmlspecialchars($user_names[$i]) .'</b>
</td>
<td class="w3-center '. $table_theme .' w3-border w3-border-theme-light" style="vertical-align: middle;">
<button class="w3-button w3-theme w3-hover-theme" onclick="delUser(\''. htmlspecialchars($user_names[$i]) .'\')"><i class="fas fa-trash"></i> <span class="w3-hide-small">'. $lang["button"]["delete"] .'</span></button>
<button class="w3-button w3-theme w3-hover-theme" onclick="banUser(\''. htmlspecialchars($user_names[$i]) .'\')"><i class="fas fa-user-lock"></i> <span class="w3-hide-small">'. $lang["button"]["ban"] .'</span></button>
<button class="w3-button w3-theme w3-hover-theme" onclick="unbanUser(\''. htmlspecialchars($user_names[$i]) .'\')"><i class="fas fa-user-check"></i> <span class="w3-hide-small">'. $lang["button"]["unban"] .'</span></button>
</td>
</tr>
';
if ($i > $total_pages - 2)
break;
else {
if ($i > $limit * $page)
break;
else
$i++;
}
}
echo '
</table>
</div>
';
if ($lastpage > 1) {
if ($page > 1)
$pagination.= "<a class='w3-button w3-theme-white w3-hover-theme' href='". $targetpage ."?page=". $prev ."'><</a> ";
else
$pagination.= "<span class='w3-button w3-theme-white w3-hover-theme'><</span> ";
if ($lastpage < 7 + ($adjacents * 2)) {
for ($counter = 1; $counter <= $lastpage; $counter++) {
if ($counter == $page)
$pagination.= "<span class='w3-button w3-theme-white w3-hover-theme'>". $counter ."</span>";
else
$pagination.= "<a class='w3-button w3-theme-white w3-hover-theme' href='". $targetpage ."?page=". $counter ."'>". $counter ."</a>";
}
} else if($lastpage > 5 + ($adjacents * 2)) {
if($page < 1 + ($adjacents * 2)) {
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) {
if ($counter == $page)
$pagination.= "<span class='w3-button w3-theme-white w3-hover-theme'>". $counter ."</span>";
else
$pagination.= "<a class='w3-button w3-theme-white w3-hover-theme' href='". $targetpage ."?page=". $counter ."'>". $counter ."</a>";
}
$pagination.= "...";
$pagination.= "<a class='w3-button w3-theme-white w3-hover-theme' href='". $targetpage ."?page=". $lpm1 ."'>". $lpm1 ."</a>";
$pagination.= "<a class='w3-button w3-theme-white w3-hover-theme' href='". $targetpage ."?page=". $lastpage ."'>". $lastpage ."</a>";
}
else if ($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) {
$pagination.= "<a class='w3-button w3-theme-white w3-hover-theme' href='". $targetpage ."?page=1'>1</a>";
$pagination.= "<a class='w3-button w3-theme-white w3-hover-theme' href='". $targetpage ."?page=2'>2</a>";
$pagination.= "...";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) {
if ($counter == $page)
$pagination.= "<span class='w3-button w3-theme-white w3-hover-theme'>". $counter ."</span>";
else
$pagination.= "<a href='". $targetpage ."?page=". $counter ."'>". $counter ."</a>";
}
$pagination.= "...";
$pagination.= "<a class='w3-button w3-theme-white w3-hover-theme' href='". $targetpage ."?page=". $lpm1 ."'>". $lpm1 ."</a>";
$pagination.= "<a class='w3-button w3-theme-white w3-hover-theme' href='". $targetpage ."?page=". $lastpage ."'>". $lastpage ."</a>";
} else {
$pagination.= "<a class='w3-button w3-theme-white w3-hover-theme' href='". $targetpage ."?page=1'>1</a>";
$pagination.= "<a class='w3-button w3-theme-white w3-hover-theme' href='". $targetpage ."?page=2'>2</a>";
$pagination.= "...";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) {
if ($counter == $page)
$pagination.= "<span class='w3-button w3-theme-white w3-hover-theme'>". $counter ."</span>";
else
$pagination.= "<a class='w3-button w3-theme-white w3-hover-theme' href='". $targetpage ."?page=". $counter."'>". $counter ."</a>";
}
}
}
if ($page < $counter - 1)
$pagination.= " <a class='w3-button w3-theme-white w3-hover-theme' href='". $targetpage ."?page=". $next ."'>></a>";
else
$pagination.= " <span class='w3-button w3-theme-white w3-hover-theme'>></span>";
}
echo '
<div class="w3-row-padding w3-margin-bottom">
'. $pagination .'
</div>
</div>
';
?>
<script>
function delUser(u){ fetch('core/bans.php',{method:'POST',headers:{"Content-Type":"application/x-www-form-urlencoded"},body:'action=del&user='+ u}).then(r=>r.text()).then(r=>alert(r)); }
function banUser(u){ fetch('core/bans.php',{method:'POST',headers:{"Content-Type":"application/x-www-form-urlencoded"},body:'action=ban&user='+ u}).then(r=>r.text()).then(r=>alert(r)); }
function unbanUser(u){ fetch('core/bans.php',{method:'POST',headers:{"Content-Type":"application/x-www-form-urlencoded"},body:'action=unban&user='+ u}).then(r=>r.text()).then(r=>alert(r)); }
</script>
<?php
include "core/footer.php";
?>