Subversion Repositories oidplus

Rev

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