Rev 1050 | Rev 1086 | 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 |
||
511 | daniel-mar | 5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
2 | daniel-mar | 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 | |||
1050 | daniel-mar | 20 | namespace ViaThinkSoft\OIDplus; |
511 | daniel-mar | 21 | |
730 | daniel-mar | 22 | class OIDplusMenuUtils extends OIDplusBaseClass { |
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 | |||
281 | daniel-mar | 29 | foreach (OIDplus::getPagePlugins() as $plugin) { |
331 | daniel-mar | 30 | // Note: The system (OIDplusMenuUtils) does only show the menu of |
31 | // publicPage plugins. Menu entries for RAs and Admins are |
||
32 | // handled by the tree() function of the plugin publicPages/090_login |
||
281 | daniel-mar | 33 | if (is_subclass_of($plugin, OIDplusPagePluginPublic::class)) { |
34 | $plugin->tree($json, null, true, $static_node_id); |
||
35 | } |
||
61 | daniel-mar | 36 | } |
2 | daniel-mar | 37 | |
1066 | daniel-mar | 38 | $out = ''; |
2 | daniel-mar | 39 | foreach ($json as $x) { |
1066 | daniel-mar | 40 | if ($static_node_id == $x['id']) $out .= '<b>'; |
41 | if (isset($x['indent'])) $out .= str_repeat(' ', $x['indent']*5); |
||
360 | daniel-mar | 42 | $cur_lang = OIDplus::getCurrentLang(); |
1041 | daniel-mar | 43 | if ($cur_lang != OIDplus::getDefaultLang()) { |
1066 | daniel-mar | 44 | $out .= '<a href="?lang='.$cur_lang.'&goto='.urlencode($x['id']).'">'; |
360 | daniel-mar | 45 | } else { |
1066 | daniel-mar | 46 | $out .= '<a href="?goto='.urlencode($x['id']).'">'; |
360 | daniel-mar | 47 | } |
1066 | daniel-mar | 48 | if (!empty($x['icon'])) $out .= '<img src="'.$x['icon'].'" alt=""> '; |
49 | $out .= htmlentities($x['id']).' | '.htmlentities($x['text']).'</a><br>'; |
||
50 | if ($static_node_id == $x['id']) $out .= '</b>'; |
||
2 | daniel-mar | 51 | } |
1066 | daniel-mar | 52 | return $out; |
2 | daniel-mar | 53 | } |
54 | |||
106 | daniel-mar | 55 | // req_id comes from jsTree via AJAX |
56 | // req_goto comes from the user (GET argument) |
||
2 | daniel-mar | 57 | public static function json_tree($req_id, $req_goto) { |
106 | daniel-mar | 58 | $json = array(); |
2 | daniel-mar | 59 | |
60 | if (!isset($req_id) || ($req_id == '#')) { |
||
281 | daniel-mar | 61 | foreach (OIDplus::getPagePlugins() as $plugin) { |
331 | daniel-mar | 62 | // Note: The system (OIDplusMenuUtils) does only show the menu of |
63 | // publicPage plugins. Menu entries for RAs and Admins are |
||
64 | // handled by the tree() function of the plugin publicPages/090_login |
||
281 | daniel-mar | 65 | if (is_subclass_of($plugin, OIDplusPagePluginPublic::class)) { |
66 | $plugin->tree($json, null, false, $req_goto); |
||
67 | } |
||
61 | daniel-mar | 68 | } |
2 | daniel-mar | 69 | } else { |
106 | daniel-mar | 70 | $json = self::tree_populate($req_id); |
2 | daniel-mar | 71 | } |
72 | |||
541 | daniel-mar | 73 | self::addHrefIfRequired($json); |
74 | |||
328 | daniel-mar | 75 | return $json; |
2 | daniel-mar | 76 | } |
77 | |||
541 | daniel-mar | 78 | protected static function addHrefIfRequired(&$json) { |
79 | if (!is_array($json)) return; |
||
80 | foreach ($json as &$item) { |
||
542 | daniel-mar | 81 | if (isset($item['id'])) { |
82 | if (!isset($item['conditionalselect']) || ($item['conditionalselect'] != 'false')) { |
||
83 | if (!isset($item['a_attr'])) { |
||
84 | $item['a_attr'] = array("href" => "?goto=".urlencode($item['id'])); |
||
85 | } else if (!isset($item['a_attr']['href'])) { |
||
86 | $item['a_attr']['href'] = "?goto=".urlencode($item['id']); |
||
87 | } |
||
88 | } |
||
541 | daniel-mar | 89 | } |
542 | daniel-mar | 90 | |
541 | daniel-mar | 91 | if (isset($item['children'])) { |
92 | self::addHrefIfRequired($item['children']); |
||
93 | } |
||
94 | } |
||
95 | } |
||
96 | |||
104 | daniel-mar | 97 | public static function tree_populate($parent, $goto_path=null) { |
2 | daniel-mar | 98 | $children = array(); |
99 | |||
100 | $parentObj = OIDplusObject::parse($parent); |
||
101 | |||
102 | @list($namespace, $oid) = explode(':', $parent, 2); |
||
499 | daniel-mar | 103 | if ($namespace == 'oid') $oid = substr($oid, 1); // Remove leading dot |
2 | daniel-mar | 104 | |
281 | daniel-mar | 105 | if (is_array($goto_path)) array_shift($goto_path); |
331 | daniel-mar | 106 | |
2 | daniel-mar | 107 | $confidential_oids = array(); |
108 | |||
443 | daniel-mar | 109 | $res = OIDplus::db()->query("select id from ###objects where confidential = ?", array(true)); |
236 | daniel-mar | 110 | while ($row = $res->fetch_array()) { |
2 | daniel-mar | 111 | $confidential_oids[] = $row['id']; |
112 | } |
||
113 | |||
261 | daniel-mar | 114 | $res = OIDplus::db()->query("select * from ###objects where parent = ? order by ".OIDplus::db()->natOrder('id'), array($parent)); |
236 | daniel-mar | 115 | while ($row = $res->fetch_array()) { |
2 | daniel-mar | 116 | $obj = OIDplusObject::parse($row['id']); |
117 | |||
118 | if (!$obj->userHasReadRights()) continue; |
||
119 | |||
120 | $child = array(); |
||
121 | $child['id'] = $row['id']; |
||
122 | |||
499 | daniel-mar | 123 | // Determine display name (relative OID) |
2 | daniel-mar | 124 | $child['text'] = $obj->jsTreeNodeName($parentObj); |
104 | daniel-mar | 125 | $child['text'] .= empty($row['title']) ? /*' -- <i>'.htmlentities('Title missing').'</i>'*/ '' : ' -- <b>' . htmlentities($row['title']) . '</b>'; |
2 | daniel-mar | 126 | |
127 | $is_confidential = false; |
||
128 | foreach ($confidential_oids as $test) { |
||
129 | $is_confidential |= ($row['id'] === $test) || (strpos($row['id'],$test.'.') === 0); |
||
130 | } |
||
131 | if ($is_confidential) { |
||
132 | $child['text'] = '<font color="gray"><i>'.$child['text'].'</i></font>'; |
||
133 | } |
||
134 | |||
499 | daniel-mar | 135 | // Determine icon |
2 | daniel-mar | 136 | $child['icon'] = $obj->getIcon($row); |
137 | |||
499 | daniel-mar | 138 | // Check if there are more sub OIDs |
281 | daniel-mar | 139 | if ($goto_path === true) { |
2 | daniel-mar | 140 | $child['children'] = self::tree_populate($row['id'], $goto_path); |
141 | $child['state'] = array("opened" => true); |
||
281 | daniel-mar | 142 | } else if (!is_null($goto_path) && (count($goto_path) > 0) && ($goto_path[0] === $row['id'])) { |
143 | $child['children'] = self::tree_populate($row['id'], $goto_path); |
||
144 | $child['state'] = array("opened" => true); |
||
2 | daniel-mar | 145 | } else { |
150 | daniel-mar | 146 | $obj_children = $obj->getChildren(); |
145 | daniel-mar | 147 | |
148 | // Variant 1: Fast, but does not check for hidden OIDs |
||
150 | daniel-mar | 149 | //$child_count = count($obj_children); |
145 | daniel-mar | 150 | |
151 | // variant 2 |
||
152 | $child_count = 0; |
||
150 | daniel-mar | 153 | foreach ($obj_children as $obj_test) { |
145 | daniel-mar | 154 | if (!$obj_test->userHasReadRights()) continue; |
155 | $child_count++; |
||
156 | } |
||
157 | |||
158 | $child['children'] = $child_count > 0; |
||
2 | daniel-mar | 159 | } |
160 | |||
161 | $children[] = $child; |
||
162 | } |
||
163 | |||
164 | return $children; |
||
165 | } |
||
366 | daniel-mar | 166 | } |