Subversion Repositories oidplus

Rev

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

Rev Author Line No. Line
2 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
class OIDplusTree {
21
 
104 daniel-mar 22
        public static function nonjs_menu() {
2 daniel-mar 23
                $json = array();
24
 
106 daniel-mar 25
                $static_node_id = isset($_REQUEST['goto']) ? $_REQUEST['goto'] : 'oidplus:system';
26
 
61 daniel-mar 27
                foreach (OIDplus::getPagePlugins('public') as $plugin) {
106 daniel-mar 28
                        $plugin->tree($json, null, true, $static_node_id);
61 daniel-mar 29
                }
2 daniel-mar 30
 
31
                foreach ($json as $x) {
32
                        if ($static_node_id == $x['id']) echo '<b>';
104 daniel-mar 33
                        if (isset($x['indent'])) echo str_repeat('&nbsp', $x['indent']*5);
34
                        echo '<a href="?goto='.urlencode($x['id']).'">';
35
                        if (!empty($x['icon'])) echo '<img src="'.$x['icon'].'" alt="'.$x['id'].' icon"> ';
36
                        echo htmlentities($x['text']).'</a><br>';
2 daniel-mar 37
                        if ($static_node_id == $x['id']) echo '</b>';
38
                }
39
 
40
        }
41
 
106 daniel-mar 42
        // req_id comes from jsTree via AJAX
43
        // req_goto comes from the user (GET argument)
2 daniel-mar 44
        public static function json_tree($req_id, $req_goto) {
106 daniel-mar 45
                $json = array();
2 daniel-mar 46
 
47
                if (!isset($req_id) || ($req_id == '#')) {
106 daniel-mar 48
                        // 'ra' and 'admin' pages will not be iterated, because they usually have no tree icon, or an icon underneath the login section
61 daniel-mar 49
                        foreach (OIDplus::getPagePlugins('public') as $plugin) {
106 daniel-mar 50
                                $plugin->tree($json, null, false, $req_goto);
61 daniel-mar 51
                        }
2 daniel-mar 52
                } else {
106 daniel-mar 53
                        $json = self::tree_populate($req_id);
2 daniel-mar 54
                }
55
 
56
                return json_encode($json);
57
        }
58
 
104 daniel-mar 59
        public static function tree_populate($parent, $goto_path=null) {
2 daniel-mar 60
                $children = array();
61
 
62
                $parentObj = OIDplusObject::parse($parent);
63
 
64
                @list($namespace, $oid) = explode(':', $parent, 2);
65
                if ($namespace == 'oid') $oid = substr($oid, 1); // führenden Punkt entfernen
66
 
67
                if (!is_null($goto_path)) array_shift($goto_path);
68
 
69
                $confidential_oids = array();
70
 
71
                $res = OIDplus::db()->query("select id from ".OIDPLUS_TABLENAME_PREFIX."objects where confidential = '1'");
72
                while ($row = OIDplus::db()->fetch_array($res)) {
73
                        $confidential_oids[] = $row['id'];
74
                }
75
 
76
                $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."objects where parent = '".OIDplus::db()->real_escape_string($parent)."' order by ".OIDplus::db()->natOrder('id'));
77
                while ($row = OIDplus::db()->fetch_array($res)) {
78
                        $obj = OIDplusObject::parse($row['id']);
79
 
80
                        if (!$obj->userHasReadRights()) continue;
81
 
82
                        $child = array();
83
                        $child['id'] = $row['id'];
84
 
85
                        // Anzeigenamen (relative OID) bestimmen
86
                        $child['text'] = $obj->jsTreeNodeName($parentObj);
104 daniel-mar 87
                        $child['text'] .= empty($row['title']) ? /*' -- <i>'.htmlentities('Title missing').'</i>'*/ '' : ' -- <b>' . htmlentities($row['title']) . '</b>';
2 daniel-mar 88
 
89
                        $is_confidential = false;
90
                        foreach ($confidential_oids as $test) {
91
                                $is_confidential |= ($row['id'] === $test) || (strpos($row['id'],$test.'.') === 0);
92
                        }
93
                        if ($is_confidential) {
94
                                $child['text'] = '<font color="gray"><i>'.$child['text'].'</i></font>';
95
                        }
96
 
97
                        // Icon bestimmen
98
                        $child['icon'] = $obj->getIcon($row);
99
 
100
                        // Feststellen, ob es weitere Unter-OIDs gibt
101
                        if (!is_null($goto_path) && (count($goto_path) > 0) && ($goto_path[0] === $row['id'])) {
102
                                $child['children'] = self::tree_populate($row['id'], $goto_path);
103
                                $child['state'] = array("opened" => true);
104
                        } else {
105
                                $res2 = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."objects where parent = '".OIDplus::db()->real_escape_string($row['id'])."'");
106
                                $child['children'] = OIDplus::db()->num_rows($res2) > 0;
107
                        }
108
 
109
                        $children[] = $child;
110
                }
111
 
112
                return $children;
113
        }
114
}