-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathusers_and_groups.php
369 lines (351 loc) · 12.8 KB
/
users_and_groups.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<?php
include "chech_restricted.php";
if(isset($_POST['table'])){
require 'settings/database.class.php';
$table = $_POST["table"];
$echo_data = "";
$db = new Database("formbuilder");
$conn = $db->getConnection();
if($table == "users"){
$echo_data = getUser($conn);
}else if($table == "groups"){
$echo_data = getGroups($conn);
}else if($table == "registration"){
$echo_data = getRegistrationRequests($conn);
}else if($table == "org_table"){
$echo_data = getOrgDepartments($conn);
}
echo $echo_data;
}
function getUser($conn){
$sql = "SELECT * FROM users";
$data = "";
if($result = $conn->query($sql)) {
$count = mysqli_num_rows($result);
if($count > 0){
$params_row = array();
$count_indx = 1;
while($row = mysqli_fetch_assoc($result)){
$statusName = array("Inactive", "Active");
$params_cell = array();
$params_cell[] = $count_indx;
$row_id = $row['id'] ;
$params_cell[] = $row_id;
$params_cell[] = $row['username'];
$params_cell[] = $row["email"];
$params_cell[] = getGroupsNames($conn, $row["groups"]);
$params_cell[] = getDepName($conn,$row["dep_id"]);
$params_cell[] = $statusName[(int)$row["status"]];
$btn = "<button type='button' class='btn btn-primary btn-sm' onclick='addUpdateUser(\"update\",\"$row_id\")' >Setting</button>";
if($row_id != 1){ //Admin user
$btn .= "<button type='button' class='btn btn-danger btn-sm' onclick='delete_user(\"$row_id\")' >Delete</button>";
}
$params_cell[] = $btn;
$params_row[] = $params_cell;
$count_indx++;
}
$data_obj = new stdClass();
$data_obj->draw = 1;
$data_obj->data = $params_row;
$data = json_encode($data_obj);
}else{
$data = '{
"draw": 0,
"recordsTotal": 0,
"data": [
]
}';
}
}else {
$data = '{
"draw": 0,
"recordsTotal": 0,
"data": [
]
}';
}
return $data;
}
function getGroups($conn){
$sql = "SELECT * FROM users_gropes";
$data = "";
if($result = $conn->query($sql)) {
$count = mysqli_num_rows($result);
if($count > 0){
$params_row = array();
$count_indx = 1;
while($row = mysqli_fetch_assoc($result)){
$params_cell = array();
$statusName = array("Inactive", "Active");
$params_cell[] = $count_indx;
$row_id = $row['indx'] ;
$params_cell[] = $row_id;
$params_cell[] = $row['group_name'];
$params_cell[] = $row["group_status"];
$params_cell[] = $statusName[(int)$row["group_status"]];
$admins_id = $row["admin_ids"];
$params_cell[] = getUserNames($conn,$admins_id);
$btn = "<button type='button' class='btn btn-primary btn-sm' onclick='addUpdateGroup(\"update\",\"$row_id\",\"$admins_id\",this)' >Setting</button>";
if($row_id != 1 && $row_id != 2){ //1=administrator group, 2=Managers group
$btn .= "<button type='button' class='btn btn-danger btn-sm' onclick='delete_group(\"$row_id\")' >Delete</button>";
}
$params_cell[] = $btn;
$params_row[] = $params_cell;
$count_indx++;
}
$data_obj = new stdClass();
$data_obj->draw = 1;
$data_obj->data = $params_row;
$data = json_encode($data_obj);
}else{
$data = '{
"draw": 0,
"recordsTotal": 0,
"data": [
]
}';
}
}else {
$data = '{
"draw": 0,
"recordsTotal": 0,
"data": [
]
}';
}
return $data;
}
function getUserNames($conn, $userIds){
if($userIds != ""){
$userIds_ary = array();
$userNames_ary = array();
if(strpos($userIds,",") !== false){
$userIds_ary = explode(",",$userIds);
}else{
$userIds_ary[] = $userIds;
}
foreach($userIds_ary as $userId){
$sql = "SELECT username FROM users WHERE id=$userId";
if($result = $conn->query($sql)) {
while($row = mysqli_fetch_assoc($result)){
$userNames_ary[] = $row["username"];
}
}
}
if(!empty($userNames_ary)){
return implode(",",$userNames_ary);
}else{
return "";
}
}else{
return "";
}
}
function getGroupsNames($conn, $groupsIds){
if($groupsIds != ""){
$groupsIds_ary = array();
$groupsNames_ary = array();
if(strpos($groupsIds,",") !== false){
$groupsIds_ary = explode(",",$groupsIds);
}else{
$groupsIds_ary[] = $groupsIds;
}
foreach($groupsIds_ary as $groupId){
$sql = "SELECT group_name FROM users_gropes WHERE indx=$groupId";
if($result = $conn->query($sql)) {
while($row = mysqli_fetch_assoc($result)){
$groupsNames_ary[] = $row["group_name"];
}
}
}
if(!empty($groupsNames_ary)){
return implode(",",$groupsNames_ary);
}else{
return "";
}
}else{
return "";
}
}
function getRegistrationRequests($conn){
$sql = "SELECT * FROM registration_request";
$data = "";
if($result = $conn->query($sql)) {
$count = mysqli_num_rows($result);
if($count > 0){
$params_row = array();
$count_indx = 1;
while($row = mysqli_fetch_assoc($result)){
$params_cell = array();
$params_cell[] = "";//$count_indx;
$row_id = $row['indx'] ;
$isConfirmed = $row["is_confirm"];
$params_cell[] = $row_id;
$params_cell[] = $row['user_name'];
$params_cell[] = $row["email"];
$params_cell[] = ($isConfirmed=="1")?"yes":"no";
$params_cell[] = "<button type='button' class='btn btn-info btn-sm' onclick='accept_user_request(\"$row_id\",\"$isConfirmed\")'>Accept</button><button type='button' class='btn btn-danger btn-sm' onclick='delete_registration(\"$row_id\",\"$isConfirmed\")' >Delete</button><input type='hidden' class='registration_ids' value='$row_id,$isConfirmed'>";
$params_row[] = $params_cell;
$count_indx++;
}
$data_obj = new stdClass();
$data_obj->draw = 1;
$data_obj->data = $params_row;
$data = json_encode($data_obj);
}else{
$data = '{
"draw": 0,
"recordsTotal": 0,
"data": [
]
}';
}
}else {
$data = '{
"draw": 0,
"recordsTotal": 0,
"data": [
]
}';
}
return $data;
}
function getOrgDepartments($conn){
$sql = "SELECT * FROM organization_tree";
$data = "";
if($result = $conn->query($sql)) {
$count = mysqli_num_rows($result);
if($count > 0){
$params_row = array();
$count_indx = 1;
while($row = mysqli_fetch_assoc($result)){
$params_cell = array();
$params_cell[] = $count_indx;
$dep_id = $row['id'] ;
$dep_name = $row['name'] ;
$prnt_id = $row["parent_id"];
$mngr_id = $row["dep_mngr_user_id"];
$params_cell[] = $dep_id;
$params_cell[] = $dep_name;
$params_cell[] = $prnt_id;
$params_cell[] = getDepName($conn,$prnt_id);
$params_cell[] = $mngr_id;
$params_cell[] = getUserNames($conn,$mngr_id);
//action,parentId,depId,depName,managerId
$btn = "<button type='button' class='btn btn-primary btn-sm' onclick='newOrUpdateDep(\"update\",\"$prnt_id\",\"$dep_id\",\"$dep_name\",\"$mngr_id\")' >Details</button>";
if($prnt_id != "0"){
$btn .= "<button type='button' class='btn btn-danger btn-sm' onclick='delSingleDepFromOrg(\"$dep_id\")' >Delete</button>";
}
$params_cell[] = $btn;
$params_row[] = $params_cell;
$count_indx++;
}
$data_obj = new stdClass();
$data_obj->draw = 1;
$data_obj->data = $params_row;
$data = json_encode($data_obj);
}else{
$data = '{
"draw": 0,
"recordsTotal": 0,
"data": [
]
}';
}
}else {
$data = '{
"draw": 0,
"recordsTotal": 0,
"data": [
]
}';
}
return $data;
}
function getDepName($conn,$dep_id){
if($dep_id == "0"){
return "";
}
$depName = "";
$sql = "SELECT name FROM organization_tree WHERE id=$dep_id";
if($result = $conn->query($sql)) {
while($row = mysqli_fetch_assoc($result)){
$depName = $row["name"];
}
}
return $depName;
}
if(!isset($echo_data)){
?>
<div class="users_groups_warper">
<div class="users_groups_column users_groups_tree">
<h4>Users and groups</h4><br>
<div id="users_groups_tree_content"></div>
</div>
<div class="users_groups_column users_groups_data">
<div class="users_groups_data_content" style="width:100%;height:100%">
<table id="users_groups_data_table" class="display" style="width:100%"></table>
<div id="org_tree_content"></div>
</div>
</div>
</div>
<div id="org_dep_win">
<div class="org_dep_warper dialog_form_container">
<input type="hidden" id="parent_dep_id" />
<input type="hidden" id="orgtree_dep_id" />
<input type="hidden" id="org_tree_action_type" />
<div class="row">
<div class="col-25">
<label for="dep_name">Dep name: </label>
</div>
<div class="col-75">
<input type="text" id="dep_name" required />
</div>
</div>
<div class="row parent-row">
<div class="col-25">
<label for="parent_dep_list">Dep. Parent: </label>
</div>
<div class="col-75">
<select id="parent_dep_list" style='width:80%;'></select>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="dep_manager">Dep manager: </label>
</div>
<div class="col-75">
<select id="dep_manager" style='width:80%;'></select>
</div>
</div>
<hr>
<div style="width:100%;text-align:center;font-size:20px;"><u>Select Users</u></div>
<div class="container">
<div class="row style-select">
<div class="col-md-12">
<div class="select-users-box-1">
<label style="width:100%;text-align:center;font-size:15px;">Available users</label>
<select multiple="multiple" class="form-control" id="available-users" style="height:100%">
</select>
</div>
<div class="select-users-arrows text-center">
<br/><br/><br/>
<input type='button' id='btnAllRight' value='>>' class="btn btn-info btn-sm" /><br />
<input type='button' id='btnRight' value='>' class="btn btn-info btn-sm" /><br />
<input type='button' id='btnLeft' value='<' class="btn btn-info btn-sm" /><br />
<input type='button' id='btnAllLeft' value='<<' class="btn btn-info btn-sm" />
</div>
<div class="select-users-box-2">
<label style="width:100%;text-align:center;font-size:15px;">Selected users</label>
<select multiple="multiple" class="form-control" id="selected-users" style="height:100%">
</select>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
</div>
<script>
</script>
<?php } ?>