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