Subversion Repositories oidplus

Rev

Rev 356 | Rev 424 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 356 Rev 360
Line 20... Line 20...
20
require_once __DIR__ . '/includes/oidplus.inc.php';
20
require_once __DIR__ . '/includes/oidplus.inc.php';
21
 
21
 
22
try {
22
try {
23
        OIDplus::init(false);
23
        OIDplus::init(false);
24
 
24
 
25
        if (!isset($_REQUEST['action'])) throw new OIDplusException("Action ID is missing");
25
        if (!isset($_REQUEST['action'])) throw new OIDplusException(_L('Action ID is missing'));
26
 
26
 
27
        $json_out = null;
27
        $json_out = null;
28
 
28
 
29
        if (isset($_REQUEST['plugin']) && ($_REQUEST['plugin'] != '')) {
29
        if (isset($_REQUEST['plugin']) && ($_REQUEST['plugin'] != '')) {
30
 
30
 
31
                // Actions handled by plugins
31
                // Actions handled by plugins
32
 
32
 
33
                $plugin = OIDplus::getPluginByOid($_REQUEST['plugin']);
33
                $plugin = OIDplus::getPluginByOid($_REQUEST['plugin']);
34
                if (!$plugin) {
34
                if (!$plugin) {
35
                        throw new OIDplusException("Plugin with OID '".$_REQUEST['plugin']."' not found");
35
                        throw new OIDplusException(_L('Plugin with OID "%1" not found',$_REQUEST['plugin']));
36
                }
36
                }
37
 
37
 
38
                if (!OIDplus::baseconfig()->getValue('DISABLE_AJAX_TRANSACTIONS',false) && OIDplus::db()->transaction_supported()) {
38
                if (!OIDplus::baseconfig()->getValue('DISABLE_AJAX_TRANSACTIONS',false) && OIDplus::db()->transaction_supported()) {
39
                        OIDplus::db()->transaction_begin();
39
                        OIDplus::db()->transaction_begin();
40
                }
40
                }
Line 46... Line 46...
46
                        }
46
                        }
47
                }
47
                }
48
 
48
 
49
                $json_out = $plugin->action($_REQUEST['action'], $params);
49
                $json_out = $plugin->action($_REQUEST['action'], $params);
50
                if (!is_array($json_out)) {
50
                if (!is_array($json_out)) {
51
                        throw new OIDplusException("Plugin with OID '".$_REQUEST['plugin']."' did not output array of result data");
51
                        throw new OIDplusException(_L('Plugin with OID %1 did not output array of result data',$_REQUEST['plugin']));
52
                }
52
                }
53
                if (!isset($json_out['status'])) $json_out['status'] = -1;
53
                if (!isset($json_out['status'])) $json_out['status'] = -1;
54
 
54
 
55
                if (!OIDplus::baseconfig()->getValue('DISABLE_AJAX_TRANSACTIONS',false) && OIDplus::db()->transaction_supported()) {
55
                if (!OIDplus::baseconfig()->getValue('DISABLE_AJAX_TRANSACTIONS',false) && OIDplus::db()->transaction_supported()) {
56
                        OIDplus::db()->transaction_commit();
56
                        OIDplus::db()->transaction_commit();
Line 63... Line 63...
63
                if (isset($_REQUEST['action']) && ($_REQUEST['action'] == 'get_description')) {
63
                if (isset($_REQUEST['action']) && ($_REQUEST['action'] == 'get_description')) {
64
                        // Action:     get_description
64
                        // Action:     get_description
65
                        // Method:     GET / POST
65
                        // Method:     GET / POST
66
                        // Parameters: id
66
                        // Parameters: id
67
                        // Outputs:    JSON
67
                        // Outputs:    JSON
68
                        if (!isset($_REQUEST['id'])) throw new OIDplusException("Invalid args");
68
                        if (!isset($_REQUEST['id'])) throw new OIDplusException(_L('Invalid arguments'));
69
                        try {
69
                        try {
70
                                $json_out = OIDplus::gui()::generateContentPage($_REQUEST['id']);
70
                                $json_out = OIDplus::gui()::generateContentPage($_REQUEST['id']);
71
                        } catch (Exception $e) {
71
                        } catch (Exception $e) {
72
                                $json_out = array();
72
                                $json_out = array();
73
                                $json_out['title'] = 'Error';
73
                                $json_out['title'] = _L('Error');
74
                                $json_out['icon'] = 'img/error_big.png';
74
                                $json_out['icon'] = 'img/error_big.png';
75
                                $json_out['text'] = $e->getMessage();
75
                                $json_out['text'] = $e->getMessage();
76
                        }
76
                        }
77
                } else if (isset($_REQUEST['action']) && ($_REQUEST['action'] == 'tree_search')) {
77
                } else if (isset($_REQUEST['action']) && ($_REQUEST['action'] == 'tree_search')) {
78
                        // Action:     tree_search
78
                        // Action:     tree_search
79
                        // Method:     GET / POST
79
                        // Method:     GET / POST
80
                        // Parameters: search
80
                        // Parameters: search
81
                        // Outputs:    JSON
81
                        // Outputs:    JSON
82
                        if (!isset($_REQUEST['search'])) throw new OIDplusException("Invalid args");
82
                        if (!isset($_REQUEST['search'])) throw new OIDplusException(_L('Invalid arguments'));
83
 
83
 
84
                        $found = false;
84
                        $found = false;
85
                        foreach (OIDplus::getPagePlugins() as $plugin) {
85
                        foreach (OIDplus::getPagePlugins() as $plugin) {
86
                                $json_out = $plugin->tree_search($_REQUEST['search']);
86
                                $json_out = $plugin->tree_search($_REQUEST['search']);
87
                                if ($json_out) {
87
                                if ($json_out) {
Line 96... Line 96...
96
                } else if (isset($_REQUEST['action']) && ($_REQUEST['action'] == 'tree_load')) {
96
                } else if (isset($_REQUEST['action']) && ($_REQUEST['action'] == 'tree_load')) {
97
                        // Action:     tree_load
97
                        // Action:     tree_load
98
                        // Method:     GET / POST
98
                        // Method:     GET / POST
99
                        // Parameters: id; goto (optional)
99
                        // Parameters: id; goto (optional)
100
                        // Outputs:    JSON
100
                        // Outputs:    JSON
101
                        if (!isset($_REQUEST['id'])) throw new OIDplusException("Invalid args");
101
                        if (!isset($_REQUEST['id'])) throw new OIDplusException(_L('Invalid arguments'));
102
                        $json_out = OIDplus::menuUtils()->json_tree($_REQUEST['id'], isset($_REQUEST['goto']) ? $_REQUEST['goto'] : '');
102
                        $json_out = OIDplus::menuUtils()->json_tree($_REQUEST['id'], isset($_REQUEST['goto']) ? $_REQUEST['goto'] : '');
103
                } else {
103
                } else {
104
                        throw new OIDplusException('Invalid action ID');
104
                        throw new OIDplusException(_L('Invalid action ID'));
105
                }
105
                }
106
        }
106
        }
107
 
107
 
108
        @header('Content-Type:application/json; charset=utf-8');
108
        @header('Content-Type:application/json; charset=utf-8');
109
        echo json_encode($json_out);
109
        echo json_encode($json_out);