-
Notifications
You must be signed in to change notification settings - Fork 0
/
Admin.php
executable file
·183 lines (175 loc) · 5.73 KB
/
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
session_start();
$title = "Admin Page";
include('header.php');
include('functions.php');
include('config/db.php');
$sql_all_role = "SELECT role,id FROM tbl_other WHERE id != '".$_SESSION['role']."'";
$sql_all_role_query = $conn->query($sql_all_role);
while($row = $sql_all_role_query->fetch_assoc()) {
$roles[] = $row;
}
$manager_sql = "SELECT tbl_info.id, tbl_other.role, tbl_login.email, tbl_login.isBlock, tbl_info.first_name, tbl_info.last_name FROM tbl_login LEFT JOIN tbl_info ON tbl_info.id = tbl_login.userid LEFT JOIN tbl_other ON tbl_other.id = tbl_login.role WHERE tbl_other.role = 'Manager'";
$all_manager_sql = $conn->query($manager_sql);
$customer_sql = "SELECT tbl_info.id, tbl_other.role, tbl_login.email, tbl_login.isBlock, tbl_info.first_name, tbl_info.last_name FROM tbl_login LEFT JOIN tbl_info ON tbl_info.id = tbl_login.userid LEFT JOIN tbl_other ON tbl_other.id = tbl_login.role WHERE tbl_other.role = 'Customer'";
$all_customer_sql = $conn->query($customer_sql);
?>
<div class="row">
<div class="col-md-4">
<?php
foreach($roles as $key => $role) {
echo '
<script type="text/javascript">
function logout() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
window.location.href = "/PHPRoleManagement/index.php";
}
};
xmlhttp.open("POST", "logout.php");
xmlhttp.send();
}
function get'.$role["role"].'() {
document.getElementById("home").innerHTML = "";
if("'.$role["role"].'" == "Manager") {
$("#manager").css("display","inline");
$("#customer").css("display","none");
$("#customer_add").css("display","none");
$("#manager_add").css("display","inline");
} else if("'.$role["role"].'" == "Customer") {
$("#customer").css("display","inline");
$("#manager").css("display","none");
$("#manager_add").css("display","none");
$("#customer_add").css("display","inline");
}
}
function addManager() {
window.location.href = "/PHPRoleManagement/manager_insert.php"
}
function addCustomer() {
window.location.href = "/PHPRoleManagement/customer_insert.php"
}
</script>
<div class="row mar-all">
<button type="button" class="btn btn-lg btn-success" onclick="get'.$role["role"].'()" id='.$role["id"].'>'.$role["role"].'</button>
</div>
';
}
?>
</div>
<div class="col-md-5 mar-top">
<h6 id="home">Welcome Admin</h6>
<div id="customer_add" class="mar-all" style="display: none;">
<?php
if(haspermission('Add Customer')) { ?>
<button type='button' class="btn btn-success mar-all float-right" onclick="addCustomer();">Add Customer</button>
<?php }
?>
</div>
<div id="customer" style="display: none;">
<table border=1 class=table-striped>
<thead>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<?php if(haspermission('Block Customer')) { ?>
<th>Block</th>
<?php } ?>
<!-- <th>Action</th> -->
</tr>
</thead>
<tbody>
<?php
while($row = $all_customer_sql->fetch_assoc()) {
if($row > 0) { ?>
<tr>
<td><?= $row['id']; ?></td>
<td><?= $row['first_name']; ?></td>
<td><?= $row['last_name']; ?></td>
<td><?= $row['email']; ?></td>
<?php if(haspermission('Block Customer')) { ?>
<td><?php
if($row['isBlock'] == 0) {
$block = 'Block';
echo '<a href="block_user.php?id='.$row['id'].'">'.$block.'</a>';
} else {
$block = 'UnBlock';
echo '<a href="unblock_user.php?id='.$row['id'].'">'.$block.'</a>';
}?>
</td>
<?php } ?>
</tr>
<?php } else {?>
<tr>
<td><?= "No Data Found"; ?></td>
</tr>
<?php
}
};
?>
</tbody>
</table>
</div>
<div id="manager_add" class="mar-all" style="display: none;">
<?php
if(haspermission('Add Manager')) { ?>
<button type='button' class="btn btn-success mar-all float-right" onclick="addManager();">Add Manager</button>
<?php }
?>
</div>
<div id="manager" style="display: none;">
<table border=1 class=table-striped>
<thead>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<?php if(haspermission('Block Manager')) { ?>
<th>Block</th>
<?php } ?>
</tr>
</thead>
<tbody>
<?php
while($row = $all_manager_sql->fetch_assoc()) {
if($row > 0) { ?>
<tr>
<td><?= $row['id']; ?></td>
<td><?= $row['first_name']; ?></td>
<td><?= $row['last_name']; ?></td>
<td><?= $row['email']; ?></td>
<?php if(haspermission('Block Manager')) { ?>
<td><?php
if($row['isBlock'] == 0) {
$block = 'Block';
echo '<a href="block_user.php?id='.$row['id'].'">'.$block.'</a>';
} else {
$block = 'UnBlock';
echo '<a href="unblock_user.php?id='.$row['id'].'">'.$block.'</a>';
}?>
</td>
<?php } ?>
</tr>
<?php } else {?>
<tr>
<td><?= "No Data Found"; ?></td>
</tr>
<?php
}
};
?>
</tbody>
</table>
</div>
</div>
<div class="col-md-2">
<button type='button' class="btn btn-danger mar-all float-right" onclick="logout()">Logout</button>
</div>
</div>
<?php
$conn->close();
?>