File size: 3,178 Bytes
07c3cdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<?php
$option = (isset($_POST["option"]))? $_POST["option"] : "";

$response = array();

switch ($option) {
    case "INS":
        $name = $_POST["name"];
        $description = $_POST["description"];
        $webSite     = $_POST["webSite"];
        $redirectUri = $_POST["redirectUri"];

        try {
            $arrayData = array(
                //"CLIENT_ID"   => "",
                "CLIENT_NAME" => $name,
                "CLIENT_DESCRIPTION" => $description,
                "CLIENT_WEBSITE" => $webSite,
                "REDIRECT_URI"   => $redirectUri,
                "USR_UID" => $_SESSION["USER_LOGGED"]
            );

            $oclient = new OauthClients();
            $result = $oclient->create($arrayData);

            $response["status"] = "OK";
            $response["data"]   = $result;
        } catch (Exception $e) {
            $response["status"]  = "ERROR";
            $response["message"] = $e->getMessage();
        }
        break;
    case "UPD":
        $oauthClientId = $_POST["oauthClientId"];
        $name = $_POST["name"];
        $description = $_POST["description"];
        $webSite     = $_POST["webSite"];
        $redirectUri = $_POST["redirectUri"];

        try {
            $arrayData = array(
                "CLIENT_ID"   => $oauthClientId,
                "CLIENT_NAME" => $name,
                "CLIENT_DESCRIPTION" => $description,
                "CLIENT_WEBSITE" => $webSite,
                "REDIRECT_URI"   => $redirectUri,
                "USR_UID" => $_SESSION["USER_LOGGED"]
            );

            $oclient = new OauthClients();
            $result = $oclient->update($arrayData);

            $response["status"] = "OK";
        } catch (Exception $e) {
            $response["status"]  = "ERROR";
            $response["message"] = $e->getMessage();
        }
        break;
    case "DEL":
        $oauthClientId = $_POST["oauthClientId"];

        try {
            $oclient = new OauthClients();
            $result = $oclient->remove($oauthClientId);

            $response["status"] = "OK";
        } catch (Exception $e) {
            $response["status"]  = "ERROR";
            $response["message"] = $e->getMessage();
        }
        break;
    case "LST":
        $pageSize = $_POST["pageSize"];
        $search = $_POST["search"];

        $sortField = (isset($_POST["sort"]))? $_POST["sort"]: "";
        $sortDir   = (isset($_POST["dir"]))? $_POST["dir"]: "";
        $start = (isset($_POST["start"]))? $_POST["start"]: 0;
        $limit = (isset($_POST["limit"]))? $_POST["limit"]: $pageSize;

        try {
            $oclient = new OauthClients();
            $result = $oclient->getAll(array("USR_UID" => $_SESSION["USER_LOGGED"], "SEARCH" => $search), $sortField, $sortDir, $start, $limit);

            $response["status"]  = "OK";
            $response["success"] = true;
            $response["resultTotal"] = $result["numRecTotal"];
            $response["resultRoot"]  = $result["data"];
        } catch (Exception $e) {
            $response["status"]  = "ERROR";
            $response["message"] = $e->getMessage();
        }
        break;
}

echo G::json_encode($response);