Subversion Repositories oidplus

Rev

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