Rev 277 | Rev 328 | 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) { |
28 | if (is_subclass_of($plugin, OIDplusPagePluginPublic::class)) { |
||
29 | $plugin->tree($json, null, true, $static_node_id); |
||
30 | } |
||
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 == '#')) { |
||
281 | daniel-mar | 50 | foreach (OIDplus::getPagePlugins() as $plugin) { |
51 | if (is_subclass_of($plugin, OIDplusPagePluginPublic::class)) { |
||
52 | $plugin->tree($json, null, false, $req_goto); |
||
53 | } |
||
61 | daniel-mar | 54 | } |
2 | daniel-mar | 55 | } else { |
106 | daniel-mar | 56 | $json = self::tree_populate($req_id); |
2 | daniel-mar | 57 | } |
58 | |||
59 | return json_encode($json); |
||
60 | } |
||
61 | |||
104 | daniel-mar | 62 | public static function tree_populate($parent, $goto_path=null) { |
2 | daniel-mar | 63 | $children = array(); |
64 | |||
65 | $parentObj = OIDplusObject::parse($parent); |
||
66 | |||
67 | @list($namespace, $oid) = explode(':', $parent, 2); |
||
68 | if ($namespace == 'oid') $oid = substr($oid, 1); // führenden Punkt entfernen |
||
69 | |||
281 | daniel-mar | 70 | if (is_array($goto_path)) array_shift($goto_path); |
71 | |||
2 | daniel-mar | 72 | $confidential_oids = array(); |
73 | |||
261 | daniel-mar | 74 | $res = OIDplus::db()->query("select id from ###objects where confidential = '1'"); |
236 | daniel-mar | 75 | while ($row = $res->fetch_array()) { |
2 | daniel-mar | 76 | $confidential_oids[] = $row['id']; |
77 | } |
||
78 | |||
261 | daniel-mar | 79 | $res = OIDplus::db()->query("select * from ###objects where parent = ? order by ".OIDplus::db()->natOrder('id'), array($parent)); |
236 | daniel-mar | 80 | while ($row = $res->fetch_array()) { |
2 | daniel-mar | 81 | $obj = OIDplusObject::parse($row['id']); |
82 | |||
83 | if (!$obj->userHasReadRights()) continue; |
||
84 | |||
85 | $child = array(); |
||
86 | $child['id'] = $row['id']; |
||
87 | |||
88 | // Anzeigenamen (relative OID) bestimmen |
||
89 | $child['text'] = $obj->jsTreeNodeName($parentObj); |
||
104 | daniel-mar | 90 | $child['text'] .= empty($row['title']) ? /*' -- <i>'.htmlentities('Title missing').'</i>'*/ '' : ' -- <b>' . htmlentities($row['title']) . '</b>'; |
2 | daniel-mar | 91 | |
92 | $is_confidential = false; |
||
93 | foreach ($confidential_oids as $test) { |
||
94 | $is_confidential |= ($row['id'] === $test) || (strpos($row['id'],$test.'.') === 0); |
||
95 | } |
||
96 | if ($is_confidential) { |
||
97 | $child['text'] = '<font color="gray"><i>'.$child['text'].'</i></font>'; |
||
98 | } |
||
99 | |||
100 | // Icon bestimmen |
||
101 | $child['icon'] = $obj->getIcon($row); |
||
102 | |||
103 | // Feststellen, ob es weitere Unter-OIDs gibt |
||
281 | daniel-mar | 104 | if ($goto_path === true) { |
2 | daniel-mar | 105 | $child['children'] = self::tree_populate($row['id'], $goto_path); |
106 | $child['state'] = array("opened" => true); |
||
281 | daniel-mar | 107 | } else if (!is_null($goto_path) && (count($goto_path) > 0) && ($goto_path[0] === $row['id'])) { |
108 | $child['children'] = self::tree_populate($row['id'], $goto_path); |
||
109 | $child['state'] = array("opened" => true); |
||
2 | daniel-mar | 110 | } else { |
150 | daniel-mar | 111 | $obj_children = $obj->getChildren(); |
145 | daniel-mar | 112 | |
113 | // Variant 1: Fast, but does not check for hidden OIDs |
||
150 | daniel-mar | 114 | //$child_count = count($obj_children); |
145 | daniel-mar | 115 | |
116 | // variant 2 |
||
117 | $child_count = 0; |
||
150 | daniel-mar | 118 | foreach ($obj_children as $obj_test) { |
145 | daniel-mar | 119 | if (!$obj_test->userHasReadRights()) continue; |
120 | $child_count++; |
||
121 | } |
||
122 | |||
123 | $child['children'] = $child_count > 0; |
||
2 | daniel-mar | 124 | } |
125 | |||
126 | $children[] = $child; |
||
127 | } |
||
128 | |||
129 | return $children; |
||
130 | } |
||
131 | } |