Subversion Repositories oidplus

Rev

Rev 403 | Rev 443 | 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
 
250 daniel-mar 20
class OIDplusMenuUtils {
2 daniel-mar 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
 
281 daniel-mar 27
                foreach (OIDplus::getPagePlugins() as $plugin) {
331 daniel-mar 28
                        // Note: The system (OIDplusMenuUtils) does only show the menu of
29
                        //       publicPage plugins. Menu entries for RAs and Admins are
30
                        //       handled by the tree() function of the plugin publicPages/090_login
281 daniel-mar 31
                        if (is_subclass_of($plugin, OIDplusPagePluginPublic::class)) {
32
                                $plugin->tree($json, null, true, $static_node_id);
33
                        }
61 daniel-mar 34
                }
2 daniel-mar 35
 
36
                foreach ($json as $x) {
37
                        if ($static_node_id == $x['id']) echo '<b>';
366 daniel-mar 38
                        if (isset($x['indent'])) echo str_repeat('&nbsp;', $x['indent']*5);
360 daniel-mar 39
                        $cur_lang = OIDplus::getCurrentLang();
40
                        if ($cur_lang != OIDplus::DEFAULT_LANGUAGE) {
41
                                echo '<a href="?lang='.$cur_lang.'&amp;goto='.urlencode($x['id']).'">';
42
                        } else {
43
                                echo '<a href="?goto='.urlencode($x['id']).'">';
44
                        }
127 daniel-mar 45
                        if (!empty($x['icon'])) echo '<img src="'.$x['icon'].'" alt=""> ';
423 daniel-mar 46
                        echo htmlentities($x['id']).' | '.htmlentities($x['text']).'</a><br>';
2 daniel-mar 47
                        if ($static_node_id == $x['id']) echo '</b>';
48
                }
49
 
50
        }
51
 
106 daniel-mar 52
        // req_id comes from jsTree via AJAX
53
        // req_goto comes from the user (GET argument)
2 daniel-mar 54
        public static function json_tree($req_id, $req_goto) {
106 daniel-mar 55
                $json = array();
2 daniel-mar 56
 
57
                if (!isset($req_id) || ($req_id == '#')) {
281 daniel-mar 58
                        foreach (OIDplus::getPagePlugins() as $plugin) {
331 daniel-mar 59
                                // Note: The system (OIDplusMenuUtils) does only show the menu of
60
                                //       publicPage plugins. Menu entries for RAs and Admins are
61
                                //       handled by the tree() function of the plugin publicPages/090_login
281 daniel-mar 62
                                if (is_subclass_of($plugin, OIDplusPagePluginPublic::class)) {
63
                                        $plugin->tree($json, null, false, $req_goto);
64
                                }
61 daniel-mar 65
                        }
2 daniel-mar 66
                } else {
106 daniel-mar 67
                        $json = self::tree_populate($req_id);
2 daniel-mar 68
                }
69
 
328 daniel-mar 70
                return $json;
2 daniel-mar 71
        }
72
 
104 daniel-mar 73
        public static function tree_populate($parent, $goto_path=null) {
2 daniel-mar 74
                $children = array();
75
 
76
                $parentObj = OIDplusObject::parse($parent);
77
 
78
                @list($namespace, $oid) = explode(':', $parent, 2);
79
                if ($namespace == 'oid') $oid = substr($oid, 1); // führenden Punkt entfernen
80
 
281 daniel-mar 81
                if (is_array($goto_path)) array_shift($goto_path);
331 daniel-mar 82
 
2 daniel-mar 83
                $confidential_oids = array();
84
 
261 daniel-mar 85
                $res = OIDplus::db()->query("select id from ###objects where confidential = '1'");
236 daniel-mar 86
                while ($row = $res->fetch_array()) {
2 daniel-mar 87
                        $confidential_oids[] = $row['id'];
88
                }
89
 
261 daniel-mar 90
                $res = OIDplus::db()->query("select * from ###objects where parent = ? order by ".OIDplus::db()->natOrder('id'), array($parent));
236 daniel-mar 91
                while ($row = $res->fetch_array()) {
2 daniel-mar 92
                        $obj = OIDplusObject::parse($row['id']);
93
 
94
                        if (!$obj->userHasReadRights()) continue;
95
 
96
                        $child = array();
97
                        $child['id'] = $row['id'];
98
 
99
                        // Anzeigenamen (relative OID) bestimmen
100
                        $child['text'] = $obj->jsTreeNodeName($parentObj);
104 daniel-mar 101
                        $child['text'] .= empty($row['title']) ? /*' -- <i>'.htmlentities('Title missing').'</i>'*/ '' : ' -- <b>' . htmlentities($row['title']) . '</b>';
2 daniel-mar 102
 
103
                        $is_confidential = false;
104
                        foreach ($confidential_oids as $test) {
105
                                $is_confidential |= ($row['id'] === $test) || (strpos($row['id'],$test.'.') === 0);
106
                        }
107
                        if ($is_confidential) {
108
                                $child['text'] = '<font color="gray"><i>'.$child['text'].'</i></font>';
109
                        }
110
 
111
                        // Icon bestimmen
112
                        $child['icon'] = $obj->getIcon($row);
113
 
114
                        // Feststellen, ob es weitere Unter-OIDs gibt
281 daniel-mar 115
                        if ($goto_path === true) {
2 daniel-mar 116
                                $child['children'] = self::tree_populate($row['id'], $goto_path);
117
                                $child['state'] = array("opened" => true);
281 daniel-mar 118
                        } else if (!is_null($goto_path) && (count($goto_path) > 0) && ($goto_path[0] === $row['id'])) {
119
                                $child['children'] = self::tree_populate($row['id'], $goto_path);
120
                                $child['state'] = array("opened" => true);
2 daniel-mar 121
                        } else {
150 daniel-mar 122
                                $obj_children = $obj->getChildren();
145 daniel-mar 123
 
124
                                // Variant 1: Fast, but does not check for hidden OIDs
150 daniel-mar 125
                                //$child_count = count($obj_children);
145 daniel-mar 126
 
127
                                // variant 2
128
                                $child_count = 0;
150 daniel-mar 129
                                foreach ($obj_children as $obj_test) {
145 daniel-mar 130
                                        if (!$obj_test->userHasReadRights()) continue;
131
                                        $child_count++;
132
                                }
133
 
134
                                $child['children'] = $child_count > 0;
2 daniel-mar 135
                        }
136
 
137
                        $children[] = $child;
138
                }
139
 
140
                return $children;
141
        }
366 daniel-mar 142
}