-
Notifications
You must be signed in to change notification settings - Fork 8
/
get_all_managers_users.php
84 lines (69 loc) · 2.38 KB
/
get_all_managers_users.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
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include "chech_restricted.php";
require "settings/database.class.php";
if(isset($_POST['searchTerm'])){
$select = $_POST["searchTerm"];
$sql = "SELECT * FROM users WHERE status='1'"; // AND username LIKE '%$select%'
}else{
$sql = "SELECT * FROM users WHERE status='1'";
}
$echo_data = "";
$db = new Database("formbuilder");
$conn = $db->getConnection();
$itemResultsAry = array();
$mngrsId = getManagersGroupId($conn,"managers");
$adminId = getManagersGroupId($conn,"administrator");
if($result = $conn->query($sql)) {
$count = mysqli_num_rows($result);
if($count > 0){
while($row = mysqli_fetch_assoc($result)){
$groups_ary = array();
$grps = $row['groups'];
if(strpos($grps,",") !== false){
$groups_ary = explode(",",$grps);
}else{
$groups_ary[] = $grps;
}
if(in_array($mngrsId, $groups_ary) || in_array($adminId, $groups_ary)){
$data_obj = new stdClass();
$data_obj->id = $row['id'];
$data_obj->text = $row['username'];
$itemResultsAry[] = $data_obj;
}
}
}
}
if(!empty($itemResultsAry)){
$data_obj = new stdClass();
$data_obj->results = $itemResultsAry;
$pagination_obj = new stdClass();
$pagination_obj->more = false;
$data_obj->pagination = $pagination_obj;
$echo_data = json_encode($data_obj);
echo $echo_data;
}else{
$data_obj = new stdClass();
$data_obj->results = [];
$pagination_obj = new stdClass();
$pagination_obj->more = false;
$data_obj->pagination = $pagination_obj;
$echo_data = json_encode($data_obj);
echo $echo_data;
}
function getManagersGroupId($conn,$group){
$mngrGrpId = "";
$sql = "SELECT indx FROM users_gropes WHERE group_name='$group'";
if($result = $conn->query($sql)) {
$count = mysqli_num_rows($result);
if($count > 0){
while($row = mysqli_fetch_assoc($result)){
$mngrGrpId = $row["indx"];
}
}
}
return $mngrGrpId;
}
?>