Subversion Repositories oidplus

Rev

Rev 264 | Rev 296 | 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 {
150 daniel-mar 27
        OIDplus::db()->transaction_begin();
107 daniel-mar 28
        $handled = false;
29
 
30
        // Action:     (actions defined by plugins)
31
        // Method:     GET / POST
32
        // Parameters: ...
33
        // Outputs:    ...
281 daniel-mar 34
        foreach (OIDplus::getPagePlugins() as $plugin) {
107 daniel-mar 35
                $plugin->action($handled);
281 daniel-mar 36
                if ($handled) break;
107 daniel-mar 37
        }
38
 
39
        // Action:     get_description
40
        // Method:     GET / POST
41
        // Parameters: id
42
        // Outputs:    JSON
43
        if (isset($_REQUEST["action"]) && ($_REQUEST['action'] == 'get_description')) {
256 daniel-mar 44
                // This code is the very base functionality (load content page) and therefore won't be in a plugin
107 daniel-mar 45
                $handled = true;
250 daniel-mar 46
                if (!isset($_REQUEST['id'])) throw new OIDplusException("Invalid args");
107 daniel-mar 47
                try {
48
                        $out = OIDplus::gui()::generateContentPage($_REQUEST['id']);
49
                } catch(Exception $e) {
50
                        $out = array();
51
                        $out['title'] = 'Error';
52
                        $out['icon'] = 'img/error_big.png';
53
                        $out['text'] = $e->getMessage();
54
                }
55
                echo json_encode($out);
56
        }
57
 
108 daniel-mar 58
        // === jsTree ===
59
 
107 daniel-mar 60
        // Action:     tree_search
61
        // Method:     GET / POST
62
        // Parameters: search
63
        // Outputs:    JSON
64
        if (isset($_REQUEST["action"]) && ($_REQUEST['action'] == 'tree_search')) {
256 daniel-mar 65
                // This code is the very base functionality (menu handling)
107 daniel-mar 66
                $handled = true;
250 daniel-mar 67
                if (!isset($_REQUEST['search'])) throw new OIDplusException("Invalid args");
108 daniel-mar 68
 
69
                $found = false;
281 daniel-mar 70
                foreach (OIDplus::getPagePlugins() as $plugin) {
108 daniel-mar 71
                        $res = $plugin->tree_search($_REQUEST['search']);
72
                        if ($res) {
73
                                echo json_encode($res);
74
                                $found = true;
75
                                break;
76
                        }
107 daniel-mar 77
                }
108 daniel-mar 78
 
79
                if (!$found) {
80
                        echo json_encode(array());
81
                }
107 daniel-mar 82
        }
83
 
84
        // Action:     tree_load
85
        // Method:     GET / POST
86
        // Parameters: id; goto (optional)
87
        // Outputs:    JSON
88
        if (isset($_REQUEST["action"]) && ($_REQUEST['action'] == 'tree_load')) {
256 daniel-mar 89
                // This code is the very base functionality (menu handling)
107 daniel-mar 90
                $handled = true;
250 daniel-mar 91
                if (!isset($_REQUEST['id'])) throw new OIDplusException("Invalid args");
92
                $json = OIDplus::menuUtils()->json_tree($_REQUEST['id'], isset($_REQUEST['goto']) ? $_REQUEST['goto'] : '');
107 daniel-mar 93
                echo $json;
94
        }
95
 
96
        if (!$handled) {
250 daniel-mar 97
                throw new OIDplusException('Invalid action ID');
107 daniel-mar 98
        }
150 daniel-mar 99
 
100
        OIDplus::db()->transaction_commit();
107 daniel-mar 101
} catch (Exception $e) {
239 daniel-mar 102
        try {
103
                OIDplus::db()->transaction_rollback();
104
        } catch (Exception $e1) {
105
        }
256 daniel-mar 106
 
107 daniel-mar 107
        $ary = array();
108
        $ary['error'] = $e->getMessage();
239 daniel-mar 109
        $out = json_encode($ary);
110
 
111
        if ($out === false) {
112
                // Some modules (like ODBC) might output non-UTF8 data
113
                $ary['error'] = utf8_encode($e->getMessage());
114
                $out = json_encode($ary);
115
        }
256 daniel-mar 116
 
239 daniel-mar 117
        die($out);
107 daniel-mar 118
}
119
 
120
# ---
121
 
122
function _ra_change_rec($id, $old_ra, $new_ra) {
264 daniel-mar 123
        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 124
 
261 daniel-mar 125
        $res = OIDplus::db()->query("select id from ###objects where parent = ? and ifnull(ra_email,'') = ?", array($id, $old_ra));
236 daniel-mar 126
        while ($row = $res->fetch_array()) {
107 daniel-mar 127
                _ra_change_rec($row['id'], $old_ra, $new_ra);
128
        }
129
}