Subversion Repositories oidplus

Rev

Rev 281 | Rev 316 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
107 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
5
 * Copyright 2019 Daniel Marschall, ViaThinkSoft
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
 
20
require_once __DIR__ . '/includes/oidplus.inc.php';
21
 
22
OIDplus::init(false);
23
 
24
header('Content-Type:application/json; charset=utf-8');
25
 
26
try {
296 daniel-mar 27
        if (OIDplus::db()->transaction_supported()) {
28
                OIDplus::db()->transaction_begin();
29
        }
107 daniel-mar 30
        $handled = false;
31
 
32
        // Action:     (actions defined by plugins)
33
        // Method:     GET / POST
34
        // Parameters: ...
35
        // Outputs:    ...
281 daniel-mar 36
        foreach (OIDplus::getPagePlugins() as $plugin) {
107 daniel-mar 37
                $plugin->action($handled);
281 daniel-mar 38
                if ($handled) break;
107 daniel-mar 39
        }
40
 
41
        // Action:     get_description
42
        // Method:     GET / POST
43
        // Parameters: id
44
        // Outputs:    JSON
45
        if (isset($_REQUEST["action"]) && ($_REQUEST['action'] == 'get_description')) {
256 daniel-mar 46
                // This code is the very base functionality (load content page) and therefore won't be in a plugin
107 daniel-mar 47
                $handled = true;
250 daniel-mar 48
                if (!isset($_REQUEST['id'])) throw new OIDplusException("Invalid args");
107 daniel-mar 49
                try {
50
                        $out = OIDplus::gui()::generateContentPage($_REQUEST['id']);
51
                } catch(Exception $e) {
52
                        $out = array();
53
                        $out['title'] = 'Error';
54
                        $out['icon'] = 'img/error_big.png';
55
                        $out['text'] = $e->getMessage();
56
                }
57
                echo json_encode($out);
58
        }
59
 
108 daniel-mar 60
        // === jsTree ===
61
 
107 daniel-mar 62
        // Action:     tree_search
63
        // Method:     GET / POST
64
        // Parameters: search
65
        // Outputs:    JSON
66
        if (isset($_REQUEST["action"]) && ($_REQUEST['action'] == 'tree_search')) {
256 daniel-mar 67
                // This code is the very base functionality (menu handling)
107 daniel-mar 68
                $handled = true;
250 daniel-mar 69
                if (!isset($_REQUEST['search'])) throw new OIDplusException("Invalid args");
108 daniel-mar 70
 
71
                $found = false;
281 daniel-mar 72
                foreach (OIDplus::getPagePlugins() as $plugin) {
108 daniel-mar 73
                        $res = $plugin->tree_search($_REQUEST['search']);
74
                        if ($res) {
75
                                echo json_encode($res);
76
                                $found = true;
77
                                break;
78
                        }
107 daniel-mar 79
                }
108 daniel-mar 80
 
81
                if (!$found) {
82
                        echo json_encode(array());
83
                }
107 daniel-mar 84
        }
85
 
86
        // Action:     tree_load
87
        // Method:     GET / POST
88
        // Parameters: id; goto (optional)
89
        // Outputs:    JSON
90
        if (isset($_REQUEST["action"]) && ($_REQUEST['action'] == 'tree_load')) {
256 daniel-mar 91
                // This code is the very base functionality (menu handling)
107 daniel-mar 92
                $handled = true;
250 daniel-mar 93
                if (!isset($_REQUEST['id'])) throw new OIDplusException("Invalid args");
94
                $json = OIDplus::menuUtils()->json_tree($_REQUEST['id'], isset($_REQUEST['goto']) ? $_REQUEST['goto'] : '');
107 daniel-mar 95
                echo $json;
96
        }
97
 
98
        if (!$handled) {
250 daniel-mar 99
                throw new OIDplusException('Invalid action ID');
107 daniel-mar 100
        }
150 daniel-mar 101
 
296 daniel-mar 102
        if (OIDplus::db()->transaction_supported()) {
103
                OIDplus::db()->transaction_commit();
104
        }
107 daniel-mar 105
} catch (Exception $e) {
239 daniel-mar 106
        try {
296 daniel-mar 107
                if (OIDplus::db()->transaction_supported()) {
108
                        OIDplus::db()->transaction_rollback();
109
                }
239 daniel-mar 110
        } catch (Exception $e1) {
111
        }
256 daniel-mar 112
 
107 daniel-mar 113
        $ary = array();
114
        $ary['error'] = $e->getMessage();
239 daniel-mar 115
        $out = json_encode($ary);
116
 
117
        if ($out === false) {
118
                // Some modules (like ODBC) might output non-UTF8 data
119
                $ary['error'] = utf8_encode($e->getMessage());
120
                $out = json_encode($ary);
121
        }
256 daniel-mar 122
 
239 daniel-mar 123
        die($out);
107 daniel-mar 124
}
125
 
126
# ---
127
 
128
function _ra_change_rec($id, $old_ra, $new_ra) {
264 daniel-mar 129
        OIDplus::db()->query("update ###objects set ra_email = ?, updated = ".OIDplus::db()->sqlDate()." where id = ? and ifnull(ra_email,'') = ?", array($new_ra, $id, $old_ra));
107 daniel-mar 130
 
261 daniel-mar 131
        $res = OIDplus::db()->query("select id from ###objects where parent = ? and ifnull(ra_email,'') = ?", array($id, $old_ra));
236 daniel-mar 132
        while ($row = $res->fetch_array()) {
107 daniel-mar 133
                _ra_change_rec($row['id'], $old_ra, $new_ra);
134
        }
135
}