]>
Commit | Line | Data |
---|---|---|
cd5d0af0 VP |
1 | <?php |
2 | ||
3 | require_once "../common.php"; | |
4 | require_once "../connection.php"; | |
5 | ||
6 | header('Content-Type: application/json'); | |
7 | ||
8 | if (!isset($_SESSION['id'])) | |
9 | die("Access denied"); | |
10 | ||
11 | if (!isset($_GET) || empty($_GET)) | |
12 | { | |
13 | if ($list = $rpc->user()->getAll()) | |
14 | echo json_encode($list); | |
15 | else | |
16 | echo json_encode(["error" => "No users found"]); | |
17 | die(); | |
18 | } | |
19 | elseif (isset($_GET['lookup'])) | |
20 | { | |
21 | if ($user = $rpc->user()->get($_GET['lookup'])) | |
22 | echo json_encode($user); | |
23 | else | |
24 | echo json_encode(["error" => "User not found"]); | |
25 | die(); | |
26 | } | |
27 | ||
28 | else // we're filtering | |
29 | { | |
30 | if (!($list = $rpc->user()->getAll())) | |
31 | { | |
32 | echo json_encode(["error" => "No users found"]); | |
33 | die(); | |
34 | } | |
35 | ||
36 | $return_list = []; | |
37 | ||
38 | if (isset($_GET['nick']) && !empty($_GET['nick']) && $nick = strtolower($_GET['nick'])) | |
39 | { | |
40 | foreach ($list as $user) | |
41 | { | |
42 | if (strstr(strtolower($user->name), $nick)) | |
43 | $return_list[] = $user; | |
44 | } | |
45 | } | |
46 | if (isset($_GET['hostname']) && !empty($_GET['hostname']) && $nick = strtolower($_GET['hostname'])) | |
47 | { | |
48 | foreach ($list as $user) | |
49 | { | |
50 | if (strstr(strtolower($user->name), $nick)) | |
51 | $return_list[] = $user; | |
52 | } | |
53 | } | |
54 | echo json_encode($return_list); | |
55 | ||
56 | } |