Rev 1041 | Rev 1066 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1041 | Rev 1050 | ||
---|---|---|---|
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * OIDplus 2.0 |
4 | * OIDplus 2.0 |
5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
6 | * |
6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * you may not use this file except in compliance with 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 |
9 | * You may obtain a copy of the License at |
10 | * |
10 | * |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | * |
12 | * |
13 | * Unless required by applicable law or agreed to in writing, software |
13 | * Unless required by applicable law or agreed to in writing, software |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | * See the License for the specific language governing permissions and |
16 | * See the License for the specific language governing permissions and |
17 | * limitations under the License. |
17 | * limitations under the License. |
18 | */ |
18 | */ |
19 | 19 | ||
20 | if (!defined('INSIDE_OIDPLUS')) die(); |
20 | namespace ViaThinkSoft\OIDplus; |
21 | 21 | ||
22 | class OIDplusMenuUtils extends OIDplusBaseClass { |
22 | class OIDplusMenuUtils extends OIDplusBaseClass { |
23 | 23 | ||
24 | public static function nonjs_menu() { |
24 | public static function nonjs_menu() { |
25 | $json = array(); |
25 | $json = array(); |
26 | 26 | ||
27 | $static_node_id = isset($_REQUEST['goto']) ? $_REQUEST['goto'] : 'oidplus:system'; |
27 | $static_node_id = isset($_REQUEST['goto']) ? $_REQUEST['goto'] : 'oidplus:system'; |
28 | 28 | ||
29 | foreach (OIDplus::getPagePlugins() as $plugin) { |
29 | foreach (OIDplus::getPagePlugins() as $plugin) { |
30 | // Note: The system (OIDplusMenuUtils) does only show the menu of |
30 | // Note: The system (OIDplusMenuUtils) does only show the menu of |
31 | // publicPage plugins. Menu entries for RAs and Admins are |
31 | // publicPage plugins. Menu entries for RAs and Admins are |
32 | // handled by the tree() function of the plugin publicPages/090_login |
32 | // handled by the tree() function of the plugin publicPages/090_login |
33 | if (is_subclass_of($plugin, OIDplusPagePluginPublic::class)) { |
33 | if (is_subclass_of($plugin, OIDplusPagePluginPublic::class)) { |
34 | $plugin->tree($json, null, true, $static_node_id); |
34 | $plugin->tree($json, null, true, $static_node_id); |
35 | } |
35 | } |
36 | } |
36 | } |
37 | 37 | ||
38 | foreach ($json as $x) { |
38 | foreach ($json as $x) { |
39 | if ($static_node_id == $x['id']) echo '<b>'; |
39 | if ($static_node_id == $x['id']) echo '<b>'; |
40 | if (isset($x['indent'])) echo str_repeat(' ', $x['indent']*5); |
40 | if (isset($x['indent'])) echo str_repeat(' ', $x['indent']*5); |
41 | $cur_lang = OIDplus::getCurrentLang(); |
41 | $cur_lang = OIDplus::getCurrentLang(); |
42 | if ($cur_lang != OIDplus::getDefaultLang()) { |
42 | if ($cur_lang != OIDplus::getDefaultLang()) { |
43 | echo '<a href="?lang='.$cur_lang.'&goto='.urlencode($x['id']).'">'; |
43 | echo '<a href="?lang='.$cur_lang.'&goto='.urlencode($x['id']).'">'; |
44 | } else { |
44 | } else { |
45 | echo '<a href="?goto='.urlencode($x['id']).'">'; |
45 | echo '<a href="?goto='.urlencode($x['id']).'">'; |
46 | } |
46 | } |
47 | if (!empty($x['icon'])) echo '<img src="'.$x['icon'].'" alt=""> '; |
47 | if (!empty($x['icon'])) echo '<img src="'.$x['icon'].'" alt=""> '; |
48 | echo htmlentities($x['id']).' | '.htmlentities($x['text']).'</a><br>'; |
48 | echo htmlentities($x['id']).' | '.htmlentities($x['text']).'</a><br>'; |
49 | if ($static_node_id == $x['id']) echo '</b>'; |
49 | if ($static_node_id == $x['id']) echo '</b>'; |
50 | } |
50 | } |
51 | 51 | ||
52 | } |
52 | } |
53 | 53 | ||
54 | // req_id comes from jsTree via AJAX |
54 | // req_id comes from jsTree via AJAX |
55 | // req_goto comes from the user (GET argument) |
55 | // req_goto comes from the user (GET argument) |
56 | public static function json_tree($req_id, $req_goto) { |
56 | public static function json_tree($req_id, $req_goto) { |
57 | $json = array(); |
57 | $json = array(); |
58 | 58 | ||
59 | if (!isset($req_id) || ($req_id == '#')) { |
59 | if (!isset($req_id) || ($req_id == '#')) { |
60 | foreach (OIDplus::getPagePlugins() as $plugin) { |
60 | foreach (OIDplus::getPagePlugins() as $plugin) { |
61 | // Note: The system (OIDplusMenuUtils) does only show the menu of |
61 | // Note: The system (OIDplusMenuUtils) does only show the menu of |
62 | // publicPage plugins. Menu entries for RAs and Admins are |
62 | // publicPage plugins. Menu entries for RAs and Admins are |
63 | // handled by the tree() function of the plugin publicPages/090_login |
63 | // handled by the tree() function of the plugin publicPages/090_login |
64 | if (is_subclass_of($plugin, OIDplusPagePluginPublic::class)) { |
64 | if (is_subclass_of($plugin, OIDplusPagePluginPublic::class)) { |
65 | $plugin->tree($json, null, false, $req_goto); |
65 | $plugin->tree($json, null, false, $req_goto); |
66 | } |
66 | } |
67 | } |
67 | } |
68 | } else { |
68 | } else { |
69 | $json = self::tree_populate($req_id); |
69 | $json = self::tree_populate($req_id); |
70 | } |
70 | } |
71 | 71 | ||
72 | self::addHrefIfRequired($json); |
72 | self::addHrefIfRequired($json); |
73 | 73 | ||
74 | return $json; |
74 | return $json; |
75 | } |
75 | } |
76 | 76 | ||
77 | protected static function addHrefIfRequired(&$json) { |
77 | protected static function addHrefIfRequired(&$json) { |
78 | if (!is_array($json)) return; |
78 | if (!is_array($json)) return; |
79 | foreach ($json as &$item) { |
79 | foreach ($json as &$item) { |
80 | if (isset($item['id'])) { |
80 | if (isset($item['id'])) { |
81 | if (!isset($item['conditionalselect']) || ($item['conditionalselect'] != 'false')) { |
81 | if (!isset($item['conditionalselect']) || ($item['conditionalselect'] != 'false')) { |
82 | if (!isset($item['a_attr'])) { |
82 | if (!isset($item['a_attr'])) { |
83 | $item['a_attr'] = array("href" => "?goto=".urlencode($item['id'])); |
83 | $item['a_attr'] = array("href" => "?goto=".urlencode($item['id'])); |
84 | } else if (!isset($item['a_attr']['href'])) { |
84 | } else if (!isset($item['a_attr']['href'])) { |
85 | $item['a_attr']['href'] = "?goto=".urlencode($item['id']); |
85 | $item['a_attr']['href'] = "?goto=".urlencode($item['id']); |
86 | } |
86 | } |
87 | } |
87 | } |
88 | } |
88 | } |
89 | 89 | ||
90 | if (isset($item['children'])) { |
90 | if (isset($item['children'])) { |
91 | self::addHrefIfRequired($item['children']); |
91 | self::addHrefIfRequired($item['children']); |
92 | } |
92 | } |
93 | } |
93 | } |
94 | } |
94 | } |
95 | 95 | ||
96 | public static function tree_populate($parent, $goto_path=null) { |
96 | public static function tree_populate($parent, $goto_path=null) { |
97 | $children = array(); |
97 | $children = array(); |
98 | 98 | ||
99 | $parentObj = OIDplusObject::parse($parent); |
99 | $parentObj = OIDplusObject::parse($parent); |
100 | 100 | ||
101 | @list($namespace, $oid) = explode(':', $parent, 2); |
101 | @list($namespace, $oid) = explode(':', $parent, 2); |
102 | if ($namespace == 'oid') $oid = substr($oid, 1); // Remove leading dot |
102 | if ($namespace == 'oid') $oid = substr($oid, 1); // Remove leading dot |
103 | 103 | ||
104 | if (is_array($goto_path)) array_shift($goto_path); |
104 | if (is_array($goto_path)) array_shift($goto_path); |
105 | 105 | ||
106 | $confidential_oids = array(); |
106 | $confidential_oids = array(); |
107 | 107 | ||
108 | $res = OIDplus::db()->query("select id from ###objects where confidential = ?", array(true)); |
108 | $res = OIDplus::db()->query("select id from ###objects where confidential = ?", array(true)); |
109 | while ($row = $res->fetch_array()) { |
109 | while ($row = $res->fetch_array()) { |
110 | $confidential_oids[] = $row['id']; |
110 | $confidential_oids[] = $row['id']; |
111 | } |
111 | } |
112 | 112 | ||
113 | $res = OIDplus::db()->query("select * from ###objects where parent = ? order by ".OIDplus::db()->natOrder('id'), array($parent)); |
113 | $res = OIDplus::db()->query("select * from ###objects where parent = ? order by ".OIDplus::db()->natOrder('id'), array($parent)); |
114 | while ($row = $res->fetch_array()) { |
114 | while ($row = $res->fetch_array()) { |
115 | $obj = OIDplusObject::parse($row['id']); |
115 | $obj = OIDplusObject::parse($row['id']); |
116 | 116 | ||
117 | if (!$obj->userHasReadRights()) continue; |
117 | if (!$obj->userHasReadRights()) continue; |
118 | 118 | ||
119 | $child = array(); |
119 | $child = array(); |
120 | $child['id'] = $row['id']; |
120 | $child['id'] = $row['id']; |
121 | 121 | ||
122 | // Determine display name (relative OID) |
122 | // Determine display name (relative OID) |
123 | $child['text'] = $obj->jsTreeNodeName($parentObj); |
123 | $child['text'] = $obj->jsTreeNodeName($parentObj); |
124 | $child['text'] .= empty($row['title']) ? /*' -- <i>'.htmlentities('Title missing').'</i>'*/ '' : ' -- <b>' . htmlentities($row['title']) . '</b>'; |
124 | $child['text'] .= empty($row['title']) ? /*' -- <i>'.htmlentities('Title missing').'</i>'*/ '' : ' -- <b>' . htmlentities($row['title']) . '</b>'; |
125 | 125 | ||
126 | $is_confidential = false; |
126 | $is_confidential = false; |
127 | foreach ($confidential_oids as $test) { |
127 | foreach ($confidential_oids as $test) { |
128 | $is_confidential |= ($row['id'] === $test) || (strpos($row['id'],$test.'.') === 0); |
128 | $is_confidential |= ($row['id'] === $test) || (strpos($row['id'],$test.'.') === 0); |
129 | } |
129 | } |
130 | if ($is_confidential) { |
130 | if ($is_confidential) { |
131 | $child['text'] = '<font color="gray"><i>'.$child['text'].'</i></font>'; |
131 | $child['text'] = '<font color="gray"><i>'.$child['text'].'</i></font>'; |
132 | } |
132 | } |
133 | 133 | ||
134 | // Determine icon |
134 | // Determine icon |
135 | $child['icon'] = $obj->getIcon($row); |
135 | $child['icon'] = $obj->getIcon($row); |
136 | 136 | ||
137 | // Check if there are more sub OIDs |
137 | // Check if there are more sub OIDs |
138 | if ($goto_path === true) { |
138 | if ($goto_path === true) { |
139 | $child['children'] = self::tree_populate($row['id'], $goto_path); |
139 | $child['children'] = self::tree_populate($row['id'], $goto_path); |
140 | $child['state'] = array("opened" => true); |
140 | $child['state'] = array("opened" => true); |
141 | } else if (!is_null($goto_path) && (count($goto_path) > 0) && ($goto_path[0] === $row['id'])) { |
141 | } else if (!is_null($goto_path) && (count($goto_path) > 0) && ($goto_path[0] === $row['id'])) { |
142 | $child['children'] = self::tree_populate($row['id'], $goto_path); |
142 | $child['children'] = self::tree_populate($row['id'], $goto_path); |
143 | $child['state'] = array("opened" => true); |
143 | $child['state'] = array("opened" => true); |
144 | } else { |
144 | } else { |
145 | $obj_children = $obj->getChildren(); |
145 | $obj_children = $obj->getChildren(); |
146 | 146 | ||
147 | // Variant 1: Fast, but does not check for hidden OIDs |
147 | // Variant 1: Fast, but does not check for hidden OIDs |
148 | //$child_count = count($obj_children); |
148 | //$child_count = count($obj_children); |
149 | 149 | ||
150 | // variant 2 |
150 | // variant 2 |
151 | $child_count = 0; |
151 | $child_count = 0; |
152 | foreach ($obj_children as $obj_test) { |
152 | foreach ($obj_children as $obj_test) { |
153 | if (!$obj_test->userHasReadRights()) continue; |
153 | if (!$obj_test->userHasReadRights()) continue; |
154 | $child_count++; |
154 | $child_count++; |
155 | } |
155 | } |
156 | 156 | ||
157 | $child['children'] = $child_count > 0; |
157 | $child['children'] = $child_count > 0; |
158 | } |
158 | } |
159 | 159 | ||
160 | $children[] = $child; |
160 | $children[] = $child; |
161 | } |
161 | } |
162 | 162 | ||
163 | return $children; |
163 | return $children; |
164 | } |
164 | } |
165 | } |
165 | } |
166 | 166 |