Rev 1130 | Rev 1132 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
635 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
1086 | daniel-mar | 5 | * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft |
635 | 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; |
635 | daniel-mar | 21 | |
1086 | daniel-mar | 22 | // phpcs:disable PSR1.Files.SideEffects |
23 | \defined('INSIDE_OIDPLUS') or die; |
||
24 | // phpcs:enable PSR1.Files.SideEffects |
||
25 | |||
1131 | daniel-mar | 26 | class OIDplusPagePublicObjects extends OIDplusPagePluginPublic |
27 | implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1, /* oobeEntry, oobeRequested */ |
||
28 | INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8 /* getNotifications */ |
||
29 | // Important: Do NOT implement INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7, because our getAlternativesForQuery() is the one that calls others! |
||
30 | { |
||
635 | daniel-mar | 31 | |
1116 | daniel-mar | 32 | /** |
1130 | daniel-mar | 33 | * @param string|OIDplusObject $ot |
1116 | daniel-mar | 34 | * @return string|null |
35 | */ |
||
36 | private function get_treeicon_root($ot)/*: ?string*/ { |
||
1127 | daniel-mar | 37 | $root = $ot::parse($ot::root()); |
38 | if (!$root) return null; |
||
39 | return $root->getIcon(); |
||
635 | daniel-mar | 40 | } |
41 | |||
1116 | daniel-mar | 42 | /** |
1130 | daniel-mar | 43 | * @param string $id |
44 | * @param string $old_ra |
||
45 | * @param string $new_ra |
||
1116 | daniel-mar | 46 | * @return void |
47 | * @throws OIDplusConfigInitializationException |
||
48 | * @throws OIDplusException |
||
49 | */ |
||
1130 | daniel-mar | 50 | private function ra_change_rec(string $id, string $old_ra, string $new_ra) { |
635 | daniel-mar | 51 | OIDplus::db()->query("update ###objects set ra_email = ?, updated = ".OIDplus::db()->sqlDate()." where id = ? and ".OIDplus::db()->getSlang()->isNullFunction('ra_email',"''")." = ?", array($new_ra, $id, $old_ra)); |
978 | daniel-mar | 52 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 53 | |
54 | $res = OIDplus::db()->query("select id from ###objects where parent = ? and ".OIDplus::db()->getSlang()->isNullFunction('ra_email',"''")." = ?", array($id, $old_ra)); |
||
55 | while ($row = $res->fetch_array()) { |
||
56 | $this->ra_change_rec($row['id'], $old_ra, $new_ra); |
||
57 | } |
||
58 | } |
||
59 | |||
1116 | daniel-mar | 60 | /** |
61 | * @param string $actionID |
||
62 | * @param array $params |
||
63 | * @return array|int[] |
||
64 | * @throws OIDplusConfigInitializationException |
||
65 | * @throws OIDplusException |
||
66 | */ |
||
67 | public function action(string $actionID, array $params): array { |
||
635 | daniel-mar | 68 | |
69 | // Action: Delete |
||
70 | // Method: POST |
||
71 | // Parameters: id |
||
72 | // Outputs: <0 Error, =0 Success |
||
73 | if ($actionID == 'Delete') { |
||
74 | _CheckParamExists($params, 'id'); |
||
75 | $id = $params['id']; |
||
76 | $obj = OIDplusObject::parse($id); |
||
1116 | daniel-mar | 77 | if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','DELETE',$id)); |
635 | daniel-mar | 78 | |
977 | daniel-mar | 79 | if (!OIDplusObject::exists($id)) { |
635 | daniel-mar | 80 | throw new OIDplusException(_L('Object %1 does not exist',$id)); |
81 | } |
||
82 | |||
83 | // Check if permitted |
||
84 | if (!$obj->userHasParentalWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the superior RA to delete this OID.')); |
||
85 | |||
1005 | daniel-mar | 86 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 87 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) { |
88 | $plugin->beforeObjectDelete($id); |
||
635 | daniel-mar | 89 | } |
90 | } |
||
91 | |||
92 | OIDplus::logger()->log("[WARN]OID($id)+[?WARN/!OK]SUPOIDRA($id)?/[?INFO/!OK]A?", "Object '$id' (recursively) deleted"); |
||
93 | OIDplus::logger()->log("[CRIT]OIDRA($id)!", "Lost ownership of object '$id' because it was deleted"); |
||
94 | |||
95 | if ($parentObj = $obj->getParent()) { |
||
96 | $parent_oid = $parentObj->nodeId(); |
||
97 | OIDplus::logger()->log("[WARN]OID($parent_oid)", "Object '$id' (recursively) deleted"); |
||
98 | } |
||
99 | |||
100 | // Delete object |
||
101 | OIDplus::db()->query("delete from ###objects where id = ?", array($id)); |
||
978 | daniel-mar | 102 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 103 | |
104 | // Delete orphan stuff |
||
105 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
||
106 | do { |
||
107 | $res = OIDplus::db()->query("select tchild.id from ###objects tchild " . |
||
108 | "left join ###objects tparent on tparent.id = tchild.parent " . |
||
109 | "where tchild.parent <> ? and tchild.id like ? and tparent.id is null;", array($ot::root(), $ot::root().'%')); |
||
790 | daniel-mar | 110 | if (!$res->any()) break; |
635 | daniel-mar | 111 | |
112 | while ($row = $res->fetch_array()) { |
||
113 | $id_to_delete = $row['id']; |
||
114 | OIDplus::logger()->log("[CRIT]OIDRA($id_to_delete)!", "Lost ownership of object '$id_to_delete' because one of the superior objects ('$id') was recursively deleted"); |
||
115 | OIDplus::db()->query("delete from ###objects where id = ?", array($id_to_delete)); |
||
978 | daniel-mar | 116 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 117 | } |
118 | } while (true); |
||
119 | } |
||
120 | OIDplus::db()->query("delete from ###asn1id where well_known = ? and oid not in (select id from ###objects where id like 'oid:%')", array(false)); |
||
121 | OIDplus::db()->query("delete from ###iri where well_known = ? and oid not in (select id from ###objects where id like 'oid:%')", array(false)); |
||
122 | |||
1005 | daniel-mar | 123 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 124 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) { |
125 | $plugin->afterObjectDelete($id); |
||
635 | daniel-mar | 126 | } |
127 | } |
||
128 | |||
129 | return array("status" => 0); |
||
130 | } |
||
131 | |||
132 | // Action: Update |
||
133 | // Method: POST |
||
134 | // Parameters: id, ra_email, comment, iris, asn1ids, confidential |
||
135 | // Outputs: <0 Error, =0 Success, with following bitfields for further information: |
||
136 | // 1 = RA is not registered |
||
137 | // 2 = RA is not registered, but it cannot be invited |
||
138 | // 4 = OID is a well-known OID, so RA, ASN.1 and IRI identifiers were reset |
||
139 | else if ($actionID == 'Update') { |
||
140 | _CheckParamExists($params, 'id'); |
||
141 | $id = $params['id']; |
||
142 | $obj = OIDplusObject::parse($id); |
||
1116 | daniel-mar | 143 | if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','UPDATE',$id)); |
635 | daniel-mar | 144 | |
977 | daniel-mar | 145 | if (!OIDplusObject::exists($id)) { |
635 | daniel-mar | 146 | throw new OIDplusException(_L('Object %1 does not exist',$id)); |
147 | } |
||
148 | |||
149 | // Check if permitted |
||
150 | if (!$obj->userHasParentalWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the superior RA to update this OID.')); |
||
151 | |||
1005 | daniel-mar | 152 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 153 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) { |
154 | $plugin->beforeObjectUpdateSuperior($id, $params); |
||
635 | daniel-mar | 155 | } |
156 | } |
||
157 | |||
158 | // First, do a simulation for ASN.1 IDs and IRIs to check if there are any problems (then an Exception will be thrown) |
||
159 | if ($obj::ns() == 'oid') { |
||
1116 | daniel-mar | 160 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
635 | daniel-mar | 161 | if (!$obj->isWellKnown()) { |
162 | if (isset($params['iris'])) { |
||
163 | $ids = ($params['iris'] == '') ? array() : explode(',',$params['iris']); |
||
164 | $ids = array_map('trim',$ids); |
||
165 | $obj->replaceIris($ids, true); |
||
166 | } |
||
167 | |||
168 | if (isset($params['asn1ids'])) { |
||
169 | $ids = ($params['asn1ids'] == '') ? array() : explode(',',$params['asn1ids']); |
||
170 | $ids = array_map('trim',$ids); |
||
171 | $obj->replaceAsn1Ids($ids, true); |
||
172 | } |
||
173 | } |
||
174 | } |
||
175 | |||
176 | // RA E-Mail change |
||
177 | if (isset($params['ra_email'])) { |
||
178 | // Validate RA email address |
||
179 | $new_ra = $params['ra_email']; |
||
180 | if ($obj::ns() == 'oid') { |
||
1116 | daniel-mar | 181 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
635 | daniel-mar | 182 | if ($obj->isWellKnown()) { |
183 | $new_ra = ''; |
||
184 | } |
||
185 | } |
||
186 | if (!empty($new_ra) && !OIDplus::mailUtils()->validMailAddress($new_ra)) { |
||
187 | throw new OIDplusException(_L('Invalid RA email address')); |
||
188 | } |
||
189 | |||
190 | // Change RA recursively |
||
1130 | daniel-mar | 191 | $current_ra = $obj->getRaMail() ?? ''; |
977 | daniel-mar | 192 | if ($new_ra != $current_ra) { |
193 | OIDplus::logger()->log("[INFO]OID($id)+[?INFO/!OK]SUPOIDRA($id)?/[?INFO/!OK]A?", "RA of object '$id' changed from '$current_ra' to '$new_ra'"); |
||
194 | OIDplus::logger()->log("[WARN]RA($current_ra)!", "Lost ownership of object '$id' due to RA transfer of superior RA / admin."); |
||
195 | OIDplus::logger()->log("[INFO]RA($new_ra)!", "Gained ownership of object '$id' due to RA transfer of superior RA / admin."); |
||
196 | if ($parentObj = $obj->getParent()) { |
||
197 | $parent_oid = $parentObj->nodeId(); |
||
198 | OIDplus::logger()->log("[INFO]OID($parent_oid)", "RA of object '$id' changed from '$current_ra' to '$new_ra'"); |
||
635 | daniel-mar | 199 | } |
977 | daniel-mar | 200 | $this->ra_change_rec($id, $current_ra, $new_ra); // Recursively change inherited RAs |
635 | daniel-mar | 201 | } |
202 | } |
||
203 | |||
204 | // Log if confidentially flag was changed |
||
205 | OIDplus::logger()->log("[INFO]OID($id)+[?INFO/!OK]SUPOIDRA($id)?/[?INFO/!OK]A?", "Identifiers/Confidential flag of object '$id' updated"); // TODO: Check if they were ACTUALLY updated! |
||
206 | if ($parentObj = $obj->getParent()) { |
||
207 | $parent_oid = $parentObj->nodeId(); |
||
208 | OIDplus::logger()->log("[INFO]OID($parent_oid)", "Identifiers/Confidential flag of object '$id' updated"); // TODO: Check if they were ACTUALLY updated! |
||
209 | } |
||
210 | |||
211 | // Replace ASN.1 IDs und IRIs |
||
212 | if ($obj::ns() == 'oid') { |
||
1116 | daniel-mar | 213 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
635 | daniel-mar | 214 | if (!$obj->isWellKnown()) { |
215 | if (isset($params['iris'])) { |
||
216 | $ids = ($params['iris'] == '') ? array() : explode(',',$params['iris']); |
||
217 | $ids = array_map('trim',$ids); |
||
218 | $obj->replaceIris($ids, false); |
||
219 | } |
||
220 | |||
221 | if (isset($params['asn1ids'])) { |
||
222 | $ids = ($params['asn1ids'] == '') ? array() : explode(',',$params['asn1ids']); |
||
223 | $ids = array_map('trim',$ids); |
||
224 | $obj->replaceAsn1Ids($ids, false); |
||
225 | } |
||
226 | } |
||
227 | |||
228 | // TODO: Check if any identifiers have been actually changed, |
||
229 | // and log it to OID($id), OID($parent), ... (see above) |
||
230 | } |
||
231 | |||
232 | if (isset($params['confidential'])) { |
||
233 | $confidential = $params['confidential'] == 'true'; |
||
234 | OIDplus::db()->query("UPDATE ###objects SET confidential = ? WHERE id = ?", array($confidential, $id)); |
||
978 | daniel-mar | 235 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 236 | } |
237 | |||
238 | if (isset($params['comment'])) { |
||
239 | $comment = $params['comment']; |
||
240 | OIDplus::db()->query("UPDATE ###objects SET comment = ? WHERE id = ?", array($comment, $id)); |
||
978 | daniel-mar | 241 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 242 | } |
243 | |||
244 | OIDplus::db()->query("UPDATE ###objects SET updated = ".OIDplus::db()->sqlDate()." WHERE id = ?", array($id)); |
||
978 | daniel-mar | 245 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 246 | |
247 | $status = 0; |
||
248 | |||
249 | if (!empty($new_ra)) { |
||
250 | $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($new_ra)); |
||
251 | $invitePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.92'); // OIDplusPageRaInvite |
||
790 | daniel-mar | 252 | if (!$res->any()) $status = !is_null($invitePlugin) && OIDplus::config()->getValue('ra_invitation_enabled') ? 1 : 2; |
635 | daniel-mar | 253 | } |
254 | |||
255 | if ($obj::ns() == 'oid') { |
||
1116 | daniel-mar | 256 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
635 | daniel-mar | 257 | if ($obj->isWellKnown()) { |
258 | $status += 4; |
||
259 | } |
||
260 | } |
||
261 | |||
1005 | daniel-mar | 262 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 263 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) { |
264 | $plugin->afterObjectUpdateSuperior($id, $params); |
||
635 | daniel-mar | 265 | } |
266 | } |
||
267 | |||
268 | return array("status" => $status); |
||
269 | } |
||
270 | |||
271 | // Action: Update2 |
||
272 | // Method: POST |
||
273 | // Parameters: id, title, description |
||
274 | // Outputs: <0 Error, =0 Success |
||
275 | else if ($actionID == 'Update2') { |
||
276 | _CheckParamExists($params, 'id'); |
||
277 | $id = $params['id']; |
||
278 | $obj = OIDplusObject::parse($id); |
||
1116 | daniel-mar | 279 | if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','UPDATE2',$id)); |
635 | daniel-mar | 280 | |
977 | daniel-mar | 281 | if (!OIDplusObject::exists($id)) { |
635 | daniel-mar | 282 | throw new OIDplusException(_L('Object %1 does not exist',$id)); |
283 | } |
||
284 | |||
285 | // Check if allowed |
||
286 | if (!$obj->userHasWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the RA to update this OID.')); |
||
287 | |||
1005 | daniel-mar | 288 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 289 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) { |
290 | $plugin->beforeObjectUpdateSelf($id, $params); |
||
635 | daniel-mar | 291 | } |
292 | } |
||
293 | |||
294 | OIDplus::logger()->log("[INFO]OID($id)+[?INFO/!OK]OIDRA($id)?/[?INFO/!OK]A?", "Title/Description of object '$id' updated"); |
||
295 | |||
296 | if (isset($params['title'])) { |
||
297 | $title = $params['title']; |
||
298 | OIDplus::db()->query("UPDATE ###objects SET title = ? WHERE id = ?", array($title, $id)); |
||
978 | daniel-mar | 299 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 300 | } |
301 | |||
302 | if (isset($params['description'])) { |
||
303 | $description = $params['description']; |
||
304 | OIDplus::db()->query("UPDATE ###objects SET description = ? WHERE id = ?", array($description, $id)); |
||
978 | daniel-mar | 305 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 306 | } |
307 | |||
308 | OIDplus::db()->query("UPDATE ###objects SET updated = ".OIDplus::db()->sqlDate()." WHERE id = ?", array($id)); |
||
978 | daniel-mar | 309 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 310 | |
1005 | daniel-mar | 311 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 312 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) { |
313 | $plugin->afterObjectUpdateSelf($id, $params); |
||
635 | daniel-mar | 314 | } |
315 | } |
||
316 | |||
317 | return array("status" => 0); |
||
318 | } |
||
319 | |||
320 | // Generate UUID |
||
321 | else if ($actionID == 'generate_uuid') { |
||
322 | $uuid = gen_uuid(); |
||
323 | if (!$uuid) return array("status" => 1); |
||
324 | return array( |
||
325 | "status" => 0, |
||
326 | "uuid" => $uuid, |
||
327 | "intval" => substr(uuid_to_oid($uuid),strlen('2.25.')) |
||
328 | ); |
||
329 | } |
||
330 | |||
331 | // Action: Insert |
||
332 | // Method: POST |
||
333 | // Parameters: parent, id, ra_email, confidential, iris, asn1ids |
||
334 | // Outputs: status=<0 Error, =0 Success, with following bitfields for further information: |
||
335 | // 1 = RA is not registered |
||
336 | // 2 = RA is not registered, but it cannot be invited |
||
337 | // 4 = OID is a well-known OID, so RA, ASN.1 and IRI identifiers were reset |
||
338 | else if ($actionID == 'Insert') { |
||
339 | // Check if you have write rights on the parent (to create a new object) |
||
340 | _CheckParamExists($params, 'parent'); |
||
341 | $objParent = OIDplusObject::parse($params['parent']); |
||
1116 | daniel-mar | 342 | if (!$objParent) throw new OIDplusException(_L('%1 action failed because parent object "%2" cannot be parsed!','INSERT',$params['parent'])); |
635 | daniel-mar | 343 | |
977 | daniel-mar | 344 | if (!$objParent->isRoot()) { |
345 | $idParent = $objParent->nodeId(); |
||
346 | if (!OIDplusObject::exists($idParent)) { |
||
347 | throw new OIDplusException(_L('Parent object %1 does not exist',$idParent)); |
||
348 | } |
||
635 | daniel-mar | 349 | } |
350 | |||
351 | if (!$objParent->userHasWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the correct RA to insert an OID at this arc.')); |
||
352 | |||
353 | // Check if the ID is valid |
||
354 | _CheckParamExists($params, 'id'); |
||
355 | if ($params['id'] == '') throw new OIDplusException(_L('ID may not be empty')); |
||
356 | |||
772 | daniel-mar | 357 | // For the root objects, let the user also enter a WEID |
358 | if ($objParent::ns() == 'oid') { |
||
1116 | daniel-mar | 359 | assert($objParent instanceof OIDplusOid); //assert(get_class($objParent) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
772 | daniel-mar | 360 | if (strtolower(substr(trim($params['id']),0,5)) === 'weid:') { |
361 | if ($objParent->isRoot()) { |
||
1050 | daniel-mar | 362 | $params['id'] = \Frdl\Weid\WeidOidConverter::weid2oid($params['id']); |
772 | daniel-mar | 363 | if ($params['id'] === false) { |
364 | throw new OIDplusException(_L('Invalid WEID')); |
||
365 | } |
||
366 | } else { |
||
367 | throw new OIDplusException(_L('You can use the WEID syntax only at your object tree root.')); |
||
368 | } |
||
369 | } |
||
370 | } |
||
371 | |||
635 | daniel-mar | 372 | // Determine absolute OID name |
373 | // Note: At addString() and parse(), the syntax of the ID will be checked |
||
374 | $id = $objParent->addString($params['id']); |
||
375 | |||
376 | // Check, if the OID exists |
||
977 | daniel-mar | 377 | if (OIDplusObject::exists($id)) { |
635 | daniel-mar | 378 | throw new OIDplusException(_L('Object %1 already exists!',$id)); |
379 | } |
||
380 | |||
381 | $obj = OIDplusObject::parse($id); |
||
1116 | daniel-mar | 382 | if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','INSERT',$id)); |
635 | daniel-mar | 383 | |
1005 | daniel-mar | 384 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 385 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) { |
386 | $plugin->beforeObjectInsert($id, $params); |
||
635 | daniel-mar | 387 | } |
388 | } |
||
389 | |||
390 | // First simulate if there are any problems of ASN.1 IDs und IRIs |
||
391 | if ($obj::ns() == 'oid') { |
||
1116 | daniel-mar | 392 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
635 | daniel-mar | 393 | if (!$obj->isWellKnown()) { |
394 | if (isset($params['iris'])) { |
||
395 | $ids = ($params['iris'] == '') ? array() : explode(',',$params['iris']); |
||
396 | $ids = array_map('trim',$ids); |
||
397 | $obj->replaceIris($ids, true); |
||
398 | } |
||
399 | |||
400 | if (isset($params['asn1ids'])) { |
||
401 | $ids = ($params['asn1ids'] == '') ? array() : explode(',',$params['asn1ids']); |
||
402 | $ids = array_map('trim',$ids); |
||
403 | $obj->replaceAsn1Ids($ids, true); |
||
404 | } |
||
405 | } |
||
406 | } |
||
407 | |||
408 | // Apply superior RA change |
||
409 | $parent = $params['parent']; |
||
1130 | daniel-mar | 410 | $ra_email = $params['ra_email'] ?? ''; |
635 | daniel-mar | 411 | if ($obj::ns() == 'oid') { |
1116 | daniel-mar | 412 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
635 | daniel-mar | 413 | if ($obj->isWellKnown()) { |
414 | $ra_email = ''; |
||
415 | } |
||
416 | } |
||
417 | if (!empty($ra_email) && !OIDplus::mailUtils()->validMailAddress($ra_email)) { |
||
418 | throw new OIDplusException(_L('Invalid RA email address')); |
||
419 | } |
||
420 | |||
421 | OIDplus::logger()->log("[INFO]OID($parent)+[INFO]OID($id)+[?INFO/!OK]OIDRA($parent)?/[?INFO/!OK]A?", "Object '$id' created, ".(empty($ra_email) ? "without defined RA" : "given to RA '$ra_email'")).", superior object is '$parent'"; |
||
422 | if (!empty($ra_email)) { |
||
423 | OIDplus::logger()->log("[INFO]RA($ra_email)!", "Gained ownership of newly created object '$id'"); |
||
424 | } |
||
425 | |||
1130 | daniel-mar | 426 | $confidential = isset($params['confidential']) && $params['confidential'] == 'true'; |
427 | $comment = $params['comment'] ?? ''; |
||
635 | daniel-mar | 428 | $title = ''; |
429 | $description = ''; |
||
430 | |||
431 | if (strlen($id) > OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH')) { |
||
432 | $maxlen = OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH'); |
||
433 | throw new OIDplusException(_L('The identifier %1 is too long (max allowed length: %2)',$id,$maxlen)); |
||
434 | } |
||
435 | |||
436 | OIDplus::db()->query("INSERT INTO ###objects (id, parent, ra_email, confidential, comment, created, title, description) VALUES (?, ?, ?, ?, ?, ".OIDplus::db()->sqlDate().", ?, ?)", array($id, $parent, $ra_email, $confidential, $comment, $title, $description)); |
||
978 | daniel-mar | 437 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 438 | |
439 | // Set ASN.1 IDs und IRIs |
||
440 | if ($obj::ns() == 'oid') { |
||
1116 | daniel-mar | 441 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
635 | daniel-mar | 442 | if (!$obj->isWellKnown()) { |
443 | if (isset($params['iris'])) { |
||
444 | $ids = ($params['iris'] == '') ? array() : explode(',',$params['iris']); |
||
445 | $ids = array_map('trim',$ids); |
||
446 | $obj->replaceIris($ids, false); |
||
447 | } |
||
448 | |||
449 | if (isset($params['asn1ids'])) { |
||
450 | $ids = ($params['asn1ids'] == '') ? array() : explode(',',$params['asn1ids']); |
||
451 | $ids = array_map('trim',$ids); |
||
452 | $obj->replaceAsn1Ids($ids, false); |
||
453 | } |
||
454 | } |
||
455 | } |
||
456 | |||
457 | $status = 0; |
||
458 | |||
459 | if (!empty($ra_email)) { |
||
460 | // Do we need to notify that the RA does not exist? |
||
461 | $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($ra_email)); |
||
462 | $invitePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.92'); // OIDplusPageRaInvite |
||
790 | daniel-mar | 463 | if (!$res->any()) $status = !is_null($invitePlugin) && OIDplus::config()->getValue('ra_invitation_enabled') ? 1 : 2; |
635 | daniel-mar | 464 | } |
465 | |||
466 | if ($obj::ns() == 'oid') { |
||
1116 | daniel-mar | 467 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
635 | daniel-mar | 468 | if ($obj->isWellKnown()) { |
469 | $status += 4; |
||
470 | } |
||
471 | } |
||
472 | |||
1005 | daniel-mar | 473 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 474 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) { |
475 | $plugin->afterObjectInsert($id, $params); |
||
635 | daniel-mar | 476 | } |
477 | } |
||
478 | |||
479 | return array( |
||
480 | "status" => $status, |
||
481 | "inserted_id" => $id |
||
482 | ); |
||
483 | } else { |
||
1116 | daniel-mar | 484 | return parent::action($actionID, $params); |
635 | daniel-mar | 485 | } |
486 | } |
||
487 | |||
1116 | daniel-mar | 488 | /** |
489 | * @param bool $html |
||
490 | * @return void |
||
491 | * @throws OIDplusException |
||
492 | */ |
||
493 | public function init(bool $html=true) { |
||
635 | daniel-mar | 494 | OIDplus::config()->prepareConfigKey('oobe_objects_done', '"Out Of Box Experience" wizard for OIDplusPagePublicObjects done once?', '0', OIDplusConfig::PROTECTION_HIDDEN, function($value) {}); |
693 | daniel-mar | 495 | OIDplus::config()->prepareConfigKey('oid_grid_show_weid', 'Show WEID/Base36 column in CRUD grid of OIDs?', '1', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
496 | if (!is_numeric($value) || ($value < 0) || ($value > 1)) { |
||
497 | throw new OIDplusException(_L('Please enter a valid value (0=no, 1=yes).')); |
||
498 | } |
||
499 | }); |
||
635 | daniel-mar | 500 | } |
501 | |||
1116 | daniel-mar | 502 | /** |
1130 | daniel-mar | 503 | * @param string $id |
504 | * @param array $out |
||
1116 | daniel-mar | 505 | * @return array|false |
506 | * @throws OIDplusException |
||
507 | */ |
||
1130 | daniel-mar | 508 | private function tryObject(string $id, array &$out) { |
951 | daniel-mar | 509 | $parent = null; |
510 | $res = null; |
||
511 | $row = null; |
||
954 | daniel-mar | 512 | $obj = OIDplusObject::parse($id); |
1116 | daniel-mar | 513 | if (!$obj) return false; |
954 | daniel-mar | 514 | if ($obj->isRoot()) { |
515 | $obj->getContentPage($out['title'], $out['text'], $out['icon']); |
||
977 | daniel-mar | 516 | $objParent = null; // $obj->getParent(); |
954 | daniel-mar | 517 | } else { |
977 | daniel-mar | 518 | $obj = OIDplusObject::findFitting($id); // this time, the object will be found, not just the object type |
519 | if (!$obj) { |
||
954 | daniel-mar | 520 | return false; |
521 | } else { |
||
522 | $obj->getContentPage($out['title'], $out['text'], $out['icon']); |
||
523 | if (empty($out['title'])) $out['title'] = explode(':',$obj->nodeId(),2)[1]; |
||
977 | daniel-mar | 524 | $objParent = $obj->getParent(); |
953 | daniel-mar | 525 | } |
951 | daniel-mar | 526 | } |
977 | daniel-mar | 527 | return array($id, $obj, $objParent); |
951 | daniel-mar | 528 | } |
529 | |||
1116 | daniel-mar | 530 | /** |
1130 | daniel-mar | 531 | * @param string $id |
1116 | daniel-mar | 532 | * @return array |
533 | */ |
||
1130 | daniel-mar | 534 | public static function getAlternativesForQuery(string $id): array { |
1131 | daniel-mar | 535 | // Attention: This is NOT an implementation of INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7! |
536 | // This is the function that calls getAlternativesForQuery() of every plugin that implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7 |
||
968 | daniel-mar | 537 | |
951 | daniel-mar | 538 | // e.g. used for "Reverse Alt Id" |
539 | $alternatives = array(); |
||
1005 | daniel-mar | 540 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 541 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7) { |
542 | $tmp = $plugin->getAlternativesForQuery($id); |
||
951 | daniel-mar | 543 | if (is_array($tmp)) { |
544 | $alternatives = array_merge($tmp, $alternatives); |
||
545 | } |
||
546 | } |
||
547 | } |
||
968 | daniel-mar | 548 | |
549 | // If something is more than one time, remove it |
||
951 | daniel-mar | 550 | $alternatives = array_unique($alternatives); |
968 | daniel-mar | 551 | |
552 | // If a plugin accidentally added the own ID, remove it. This function lists only alternatives, not the own ID |
||
553 | $alternatives_tmp = array(); |
||
554 | foreach ($alternatives as $alt) { |
||
555 | if ($alt !== $id) $alternatives_tmp[] = $alt; |
||
556 | } |
||
1130 | daniel-mar | 557 | return $alternatives_tmp; |
951 | daniel-mar | 558 | } |
559 | |||
1116 | daniel-mar | 560 | /** |
561 | * @param string $id |
||
562 | * @param array $out |
||
563 | * @param bool $handled |
||
564 | * @return void |
||
565 | * @throws OIDplusConfigInitializationException |
||
566 | * @throws OIDplusException |
||
567 | */ |
||
568 | public function gui(string $id, array &$out, bool &$handled) { |
||
635 | daniel-mar | 569 | if ($id === 'oidplus:system') { |
570 | $handled = true; |
||
571 | |||
572 | $out['title'] = OIDplus::config()->getValue('system_title'); |
||
801 | daniel-mar | 573 | $out['icon'] = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png'; |
635 | daniel-mar | 574 | |
575 | if (file_exists(OIDplus::localpath() . 'userdata/welcome/welcome$'.OIDplus::getCurrentLang().'.html')) { |
||
576 | $cont = file_get_contents(OIDplus::localpath() . 'userdata/welcome/welcome$'.OIDplus::getCurrentLang().'.html'); |
||
577 | } else if (file_exists(OIDplus::localpath() . 'userdata/welcome/welcome.html')) { |
||
578 | $cont = file_get_contents(OIDplus::localpath() . 'userdata/welcome/welcome.html'); |
||
579 | } else if (file_exists(__DIR__ . '/welcome$'.OIDplus::getCurrentLang().'.html')) { |
||
580 | $cont = file_get_contents(__DIR__ . '/welcome$'.OIDplus::getCurrentLang().'.html'); |
||
581 | } else if (file_exists(__DIR__ . '/welcome.html')) { |
||
582 | $cont = file_get_contents(__DIR__ . '/welcome.html'); |
||
583 | } else { |
||
584 | $cont = ''; |
||
585 | } |
||
586 | |||
587 | list($html, $js, $css) = extractHtmlContents($cont); |
||
588 | $cont = ''; |
||
589 | if (!empty($js)) $cont .= "<script>\n$js\n</script>"; |
||
590 | if (!empty($css)) $cont .= "<style>\n$css\n</style>"; |
||
821 | daniel-mar | 591 | $cont .= stripHtmlComments($html); |
635 | daniel-mar | 592 | |
593 | $out['text'] = $cont; |
||
594 | |||
595 | if (strpos($out['text'], '%%OBJECT_TYPE_LIST%%') !== false) { |
||
596 | $tmp = '<ul>'; |
||
597 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
||
598 | $tmp .= '<li><a '.OIDplus::gui()->link($ot::root()).'>'.htmlentities($ot::objectTypeTitle()).'</a></li>'; |
||
599 | } |
||
600 | $tmp .= '</ul>'; |
||
601 | $out['text'] = str_replace('%%OBJECT_TYPE_LIST%%', $tmp, $out['text']); |
||
602 | } |
||
603 | } |
||
604 | |||
957 | daniel-mar | 605 | // Never answer to an object type that is called 'oidplus:', |
606 | // otherwise, an object type plugin could break the whole system! |
||
607 | else if ((strpos($id,':') !== false) && (!str_starts_with($id,'oidplus:'))) { |
||
635 | daniel-mar | 608 | |
955 | daniel-mar | 609 | // --- Try to find the object or an alternative |
635 | daniel-mar | 610 | |
951 | daniel-mar | 611 | $test = $this->tryObject($id, $out); |
612 | if ($test === false) { |
||
955 | daniel-mar | 613 | // try to find an alternative |
952 | daniel-mar | 614 | $alternatives = $this->getAlternativesForQuery($id); |
951 | daniel-mar | 615 | foreach ($alternatives as $alternative) { |
616 | $test = $this->tryObject($alternative, $out); |
||
955 | daniel-mar | 617 | if ($test !== false) break; // found something |
635 | daniel-mar | 618 | } |
619 | } |
||
955 | daniel-mar | 620 | if ($test !== false) { |
977 | daniel-mar | 621 | list($id, $obj, $objParent) = $test; |
955 | daniel-mar | 622 | } |
623 | |||
624 | // --- If the object type is disabled or not an object at all (e.g. "oidplus:"), then $handled=false |
||
625 | // If the object type is enabled but object not found, $handled=true |
||
626 | |||
970 | daniel-mar | 627 | $obj = OIDplusObject::parse($id); |
955 | daniel-mar | 628 | |
951 | daniel-mar | 629 | if ($test === false) { |
1116 | daniel-mar | 630 | if (!$obj) { |
955 | daniel-mar | 631 | // Object type disabled or not known (e.g. ObjectType "oidplus:"). |
632 | $handled = false; |
||
633 | return; |
||
634 | } else { |
||
635 | // Object type enabled but identifier not in database |
||
636 | $handled = true; |
||
637 | if (isset($_SERVER['SCRIPT_FILENAME']) && (strtolower(basename($_SERVER['SCRIPT_FILENAME'])) !== 'ajax.php')) { // don't send HTTP error codes in ajax.php, because we want a page and not a JavaScript alert box, when someone enters an invalid OID in the GoTo-Box |
||
638 | http_response_code(404); |
||
639 | } |
||
640 | $out['title'] = _L('Object not found'); |
||
641 | $out['icon'] = 'img/error.png'; |
||
642 | $out['text'] = _L('The object %1 was not found in this database.','<code>'.htmlentities($id).'</code>'); |
||
643 | return; |
||
644 | } |
||
645 | } else { |
||
646 | $handled = true; |
||
647 | } |
||
648 | |||
649 | unset($test); |
||
650 | |||
651 | // --- If found, do we have read rights? |
||
652 | |||
653 | if (!$obj->userHasReadRights()) { |
||
843 | daniel-mar | 654 | if (isset($_SERVER['SCRIPT_FILENAME']) && (strtolower(basename($_SERVER['SCRIPT_FILENAME'])) !== 'ajax.php')) { // don't send HTTP error codes in ajax.php, because we want a page and not a JavaScript alert box, when someone enters an invalid OID in the GoTo-Box |
955 | daniel-mar | 655 | http_response_code(403); |
843 | daniel-mar | 656 | } |
955 | daniel-mar | 657 | $out['title'] = _L('Access denied'); |
800 | daniel-mar | 658 | $out['icon'] = 'img/error.png'; |
955 | daniel-mar | 659 | $out['text'] = '<p>'._L('Please <a %1>log in</a> to receive information about this object.',OIDplus::gui()->link('oidplus:login')).'</p>'; |
635 | daniel-mar | 660 | return; |
661 | } |
||
662 | |||
663 | // --- |
||
664 | |||
977 | daniel-mar | 665 | if ($objParent) { |
666 | if ($objParent->isRoot()) { |
||
667 | $parent_link_text = $objParent->objectTypeTitle(); |
||
668 | $out['text'] = '<p><a '.OIDplus::gui()->link($objParent->root()).'><img src="img/arrow_back.png" width="16" alt="'._L('Go back').'"> '._L('Parent node: %1',htmlentities($parent_link_text)).'</a></p>' . $out['text']; |
||
635 | daniel-mar | 669 | } else { |
977 | daniel-mar | 670 | $parent_title = $objParent->getTitle(); |
671 | if (empty($parent_title) && ($objParent->ns() == 'oid')) { |
||
1116 | daniel-mar | 672 | assert($objParent instanceof OIDplusOid); //assert(get_class($objParent) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
977 | daniel-mar | 673 | // If not title is available, then use an ASN.1 identifier |
674 | $res_asn = OIDplus::db()->query("select name from ###asn1id where oid = ?", array($objParent->nodeId())); |
||
675 | if ($res_asn->any()) { |
||
676 | $row_asn = $res_asn->fetch_array(); |
||
677 | $parent_title = $row_asn['name']; // TODO: multiple ASN1 ids? |
||
635 | daniel-mar | 678 | } |
977 | daniel-mar | 679 | } |
635 | daniel-mar | 680 | |
977 | daniel-mar | 681 | $parent_link_text = empty($parent_title) ? explode(':',$objParent->nodeId())[1] : $parent_title.' ('.explode(':',$objParent->nodeId())[1].')'; |
635 | daniel-mar | 682 | |
977 | daniel-mar | 683 | $out['text'] = '<p><a '.OIDplus::gui()->link($objParent->nodeId()).'><img src="img/arrow_back.png" width="16" alt="'._L('Go back').'"> '._L('Parent node: %1',htmlentities($parent_link_text)).'</a></p>' . $out['text']; |
635 | daniel-mar | 684 | } |
685 | } else { |
||
686 | $parent_link_text = _L('Go back to front page'); |
||
687 | $out['text'] = '<p><a '.OIDplus::gui()->link('oidplus:system').'><img src="img/arrow_back.png" width="16" alt="'._L('Go back').'"> '.htmlentities($parent_link_text).'</a></p>' . $out['text']; |
||
688 | } |
||
689 | |||
690 | // --- |
||
691 | |||
977 | daniel-mar | 692 | if ($obj) { |
693 | $title = $obj->getTitle(); |
||
694 | $description = $obj->getDescription(); |
||
999 | daniel-mar | 695 | if (empty(strip_tags($description)) && (stripos($description,'<img') === false)) { |
977 | daniel-mar | 696 | if (empty($title)) { |
635 | daniel-mar | 697 | $desc = '<p><i>'._L('No description for this object available').'</i></p>'; |
698 | } else { |
||
977 | daniel-mar | 699 | $desc = $title; |
635 | daniel-mar | 700 | } |
701 | } else { |
||
977 | daniel-mar | 702 | $desc = self::objDescription($description); |
635 | daniel-mar | 703 | } |
704 | |||
705 | if ($obj->userHasWriteRights()) { |
||
706 | $rand = ++self::$crudCounter; |
||
707 | $desc = '<noscript><p><b>'._L('You need to enable JavaScript to edit title or description of this object.').'</b></p>'.$desc.'</noscript>'; |
||
708 | $desc .= '<div class="container box" style="display:none" id="descbox_'.$rand.'">'; |
||
977 | daniel-mar | 709 | $desc .= _L('Title').': <input type="text" name="title" id="titleedit" value="'.htmlentities($title).'"><br><br>'._L('Description').':<br>'; |
710 | $desc .= self::showMCE('description', $description); |
||
635 | daniel-mar | 711 | $desc .= '<button type="button" name="update_desc" id="update_desc" class="btn btn-success btn-xs update" onclick="OIDplusPagePublicObjects.updateDesc()">'._L('Update description').'</button>'; |
712 | $desc .= '</div>'; |
||
713 | $desc .= '<script>$("#descbox_'.$rand.'")[0].style.display = "block";</script>'; |
||
714 | } |
||
715 | } else { |
||
716 | $desc = ''; |
||
717 | } |
||
718 | |||
719 | // --- |
||
720 | |||
721 | if (strpos($out['text'], '%%DESC%%') !== false) |
||
722 | $out['text'] = str_replace('%%DESC%%', $desc, $out['text']); |
||
723 | if (strpos($out['text'], '%%CRUD%%') !== false) |
||
856 | daniel-mar | 724 | $out['text'] = str_replace('%%CRUD%%', self::showCrud($obj->nodeId()), $out['text']); |
635 | daniel-mar | 725 | if (strpos($out['text'], '%%RA_INFO%%') !== false) |
977 | daniel-mar | 726 | $out['text'] = str_replace('%%RA_INFO%%', OIDplusPagePublicRaInfo::showRaInfo($obj->getRaMail()), $out['text']); |
635 | daniel-mar | 727 | |
728 | $alt_ids = $obj->getAltIds(); |
||
729 | if (count($alt_ids) > 0) { |
||
730 | $out['text'] .= '<h2>'._L('Alternative Identifiers').'</h2>'; |
||
731 | foreach ($alt_ids as $alt_id) { |
||
732 | $ns = $alt_id->getNamespace(); |
||
733 | $aid = $alt_id->getId(); |
||
734 | $aiddesc = $alt_id->getDescription(); |
||
945 | daniel-mar | 735 | $suffix = $alt_id->getSuffix(); |
736 | $out['text'] .= "$aiddesc: <code>$ns:$aid</code>$suffix<br>"; |
||
635 | daniel-mar | 737 | } |
738 | } |
||
739 | |||
1005 | daniel-mar | 740 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 741 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_2) { |
742 | $plugin->modifyContent($obj->nodeId(), $out['title'], $out['icon'], $out['text']); |
||
635 | daniel-mar | 743 | } |
744 | } |
||
745 | } |
||
746 | } |
||
747 | |||
1116 | daniel-mar | 748 | /** |
1130 | daniel-mar | 749 | * @param array $json |
750 | * @param array $out |
||
1116 | daniel-mar | 751 | * @return void |
752 | */ |
||
1130 | daniel-mar | 753 | private function publicSitemap_rec(array $json, array &$out) { |
635 | daniel-mar | 754 | foreach ($json as $x) { |
755 | if (isset($x['id']) && $x['id']) { |
||
756 | $out[] = $x['id']; |
||
757 | } |
||
758 | if (isset($x['children'])) { |
||
759 | $this->publicSitemap_rec($x['children'], $out); |
||
760 | } |
||
761 | } |
||
762 | } |
||
763 | |||
1116 | daniel-mar | 764 | /** |
765 | * @param array $out |
||
766 | * @return void |
||
767 | */ |
||
768 | public function publicSitemap(array &$out) { |
||
635 | daniel-mar | 769 | $json = array(); |
1116 | daniel-mar | 770 | $this->tree($json, null/*RA EMail*/, false/*HTML tree algorithm*/, "*"/*display all*/); |
635 | daniel-mar | 771 | $this->publicSitemap_rec($json, $out); |
772 | } |
||
773 | |||
1116 | daniel-mar | 774 | /** |
775 | * @param array $json |
||
776 | * @param string|null $ra_email |
||
777 | * @param bool $nonjs |
||
778 | * @param string $req_goto |
||
779 | * @return bool |
||
780 | * @throws OIDplusConfigInitializationException |
||
781 | * @throws OIDplusException |
||
782 | */ |
||
783 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
||
635 | daniel-mar | 784 | if ($nonjs) { |
785 | $json[] = array( |
||
786 | 'id' => 'oidplus:system', |
||
801 | daniel-mar | 787 | 'icon' => OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png', |
635 | daniel-mar | 788 | 'text' => _L('System') |
789 | ); |
||
790 | |||
977 | daniel-mar | 791 | $objGoto = OIDplusObject::findFitting($req_goto); |
998 | daniel-mar | 792 | $objGotoParent = $objGoto ? $objGoto->getParent() : null; |
977 | daniel-mar | 793 | $parent = $objGotoParent ? $objGotoParent->nodeId() : ''; |
635 | daniel-mar | 794 | |
795 | $objTypesChildren = array(); |
||
796 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
||
797 | $icon = $this->get_treeicon_root($ot); |
||
798 | |||
799 | $json[] = array( |
||
800 | 'id' => $ot::root(), |
||
801 | 'icon' => $icon, |
||
802 | 'text' => $ot::objectTypeTitle() |
||
803 | ); |
||
804 | |||
954 | daniel-mar | 805 | $tmp = OIDplusObject::parse($req_goto); |
1116 | daniel-mar | 806 | if ($tmp && ($ot == get_class($tmp))) { |
635 | daniel-mar | 807 | // TODO: Instead of just having 3 levels (parent, this and children), it would be better if we'd had a full tree of all parents |
808 | // on the other hand, for giving search engines content, this is good enough |
||
809 | if (empty($parent)) { |
||
810 | $res = OIDplus::db()->query("select * from ###objects where " . |
||
811 | "parent = ? or " . |
||
812 | "id = ? " . |
||
813 | "order by ".OIDplus::db()->natOrder('id'), array($req_goto, $req_goto)); |
||
814 | } else { |
||
815 | $res = OIDplus::db()->query("select * from ###objects where " . |
||
816 | "parent = ? or " . |
||
817 | "id = ? or " . |
||
818 | "id = ? ". |
||
819 | "order by ".OIDplus::db()->natOrder('id'), array($req_goto, $req_goto, $parent)); |
||
820 | } |
||
821 | |||
822 | $z_used = 0; |
||
823 | $y_used = 0; |
||
824 | $x_used = 0; |
||
825 | $stufe = 0; |
||
826 | $menu_entries = array(); |
||
827 | $stufen = array(); |
||
828 | while ($row = $res->fetch_object()) { |
||
829 | $obj = OIDplusObject::parse($row->id); |
||
1116 | daniel-mar | 830 | if (!$obj) continue; // might happen if the objectType is not available/loaded |
635 | daniel-mar | 831 | if (!$obj->userHasReadRights()) continue; |
832 | $txt = $row->title == '' ? '' : ' -- '.htmlentities($row->title); |
||
833 | |||
834 | if ($row->id == $parent) { $stufe=0; $z_used++; } |
||
835 | if ($row->id == $req_goto) { $stufe=1; $y_used++; } |
||
836 | if ($row->parent == $req_goto) { $stufe=2; $x_used++; } |
||
837 | |||
838 | $menu_entry = array('id' => $row->id, 'icon' => '', 'text' => $txt, 'indent' => 0); |
||
839 | $menu_entries[] = $menu_entry; |
||
840 | $stufen[] = $stufe; |
||
841 | } |
||
842 | if ($x_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 2) $menu_entry['indent'] += 1; |
||
843 | if ($y_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 1) $menu_entry['indent'] += 1; |
||
844 | if ($z_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 0) $menu_entry['indent'] += 1; |
||
845 | $json = array_merge($json, $menu_entries); |
||
846 | } |
||
847 | } |
||
848 | |||
849 | return true; |
||
850 | } else { |
||
1116 | daniel-mar | 851 | if ($req_goto === "*") { |
635 | daniel-mar | 852 | $goto_path = true; // display everything recursively |
1116 | daniel-mar | 853 | } else if ($req_goto !== "") { |
635 | daniel-mar | 854 | $goto = $req_goto; |
855 | $path = array(); |
||
856 | while (true) { |
||
857 | $path[] = $goto; |
||
977 | daniel-mar | 858 | $objGoto = OIDplusObject::findFitting($goto); |
859 | if (!$objGoto) break; |
||
860 | $objGotoParent = $objGoto->getParent(); |
||
861 | $goto = $objGotoParent ? $objGotoParent->nodeId() : ''; |
||
635 | daniel-mar | 862 | if ($goto == '') continue; |
863 | } |
||
864 | |||
865 | $goto_path = array_reverse($path); |
||
866 | } else { |
||
867 | $goto_path = null; |
||
868 | } |
||
869 | |||
870 | $objTypesChildren = array(); |
||
871 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
||
872 | $icon = $this->get_treeicon_root($ot); |
||
873 | |||
874 | $child = array('id' => $ot::root(), |
||
875 | 'text' => $ot::objectTypeTitle(), |
||
876 | 'state' => array("opened" => true), |
||
877 | 'icon' => $icon, |
||
878 | 'children' => OIDplus::menuUtils()->tree_populate($ot::root(), $goto_path) |
||
879 | ); |
||
1122 | daniel-mar | 880 | if ($child['icon'] && !file_exists($child['icon'])) $child['icon'] = null; // default icon (folder) |
635 | daniel-mar | 881 | $objTypesChildren[] = $child; |
882 | } |
||
883 | |||
884 | $json[] = array( |
||
885 | 'id' => "oidplus:system", |
||
886 | 'text' => _L('Objects'), |
||
887 | 'state' => array( |
||
888 | "opened" => true, |
||
889 | // "selected" => true) // "selected" is buggy: |
||
890 | // 1) The select-event will not be triggered upon loading |
||
891 | // 2) The nodes directly blow cannot be opened (loading infinite time) |
||
892 | ), |
||
801 | daniel-mar | 893 | 'icon' => OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png', |
635 | daniel-mar | 894 | 'children' => $objTypesChildren |
895 | ); |
||
896 | |||
897 | return true; |
||
898 | } |
||
899 | } |
||
900 | |||
1116 | daniel-mar | 901 | /** |
902 | * @param string $request |
||
903 | * @return array|false |
||
904 | */ |
||
905 | public function tree_search(string $request) { |
||
635 | daniel-mar | 906 | $ary = array(); |
951 | daniel-mar | 907 | $found_leaf = false; |
635 | daniel-mar | 908 | if ($obj = OIDplusObject::parse($request)) { |
951 | daniel-mar | 909 | $found_leaf = OIDplusObject::exists($request); |
910 | do { |
||
911 | if ($obj->userHasReadRights()) { |
||
635 | daniel-mar | 912 | $ary[] = $obj->nodeId(); |
951 | daniel-mar | 913 | } |
914 | } while ($obj = $obj->getParent()); |
||
915 | $ary = array_reverse($ary); |
||
916 | } |
||
917 | if (!$found_leaf) { |
||
952 | daniel-mar | 918 | $alternatives = $this->getAlternativesForQuery($request); |
951 | daniel-mar | 919 | foreach ($alternatives as $alternative) { |
920 | $ary_ = array(); |
||
921 | if ($obj = OIDplusObject::parse($alternative)) { |
||
922 | if ($obj->userHasReadRights() && OIDplusObject::exists($alternative)) { |
||
923 | do { |
||
924 | $ary_[] = $obj->nodeId(); |
||
925 | } while ($obj = $obj->getParent()); |
||
926 | $ary_ = array_reverse($ary_); |
||
927 | } |
||
928 | } |
||
929 | if (!empty($ary_)) { |
||
930 | $ary = $ary_; |
||
931 | break; |
||
932 | } |
||
635 | daniel-mar | 933 | } |
934 | } |
||
935 | return $ary; |
||
936 | } |
||
937 | |||
1116 | daniel-mar | 938 | /** |
939 | * @var int |
||
940 | */ |
||
635 | daniel-mar | 941 | private static $crudCounter = 0; |
942 | |||
1116 | daniel-mar | 943 | /** |
1121 | daniel-mar | 944 | * @param string $parent |
945 | * @return string |
||
1116 | daniel-mar | 946 | * @throws OIDplusConfigInitializationException |
947 | * @throws OIDplusException |
||
948 | */ |
||
1121 | daniel-mar | 949 | protected static function showCrud(string $parent='oid:'): string { |
635 | daniel-mar | 950 | $items_total = 0; |
951 | $items_hidden = 0; |
||
952 | |||
953 | $objParent = OIDplusObject::parse($parent); |
||
1121 | daniel-mar | 954 | if (!$objParent) return ''; |
635 | daniel-mar | 955 | $parentNS = $objParent::ns(); |
956 | |||
957 | // http://www.oid-info.com/cgi-bin/display?a=list-by-category&category=Not%20allocating%20identifiers |
||
958 | $no_asn1 = array( |
||
959 | 'oid:1.3.6.1.4.1', |
||
960 | 'oid:1.3.6.1.4.1.37476.9000', |
||
961 | 'oid:1.3.6.1.4.1.37553.8.8', |
||
962 | 'oid:2.16.276.1', |
||
719 | daniel-mar | 963 | //'oid:2.25', // according to Olivier, it is OK that UUID owners define their own ASN.1 ID, since the ASN.1 ID is not required to be unique |
964 | //'oid:1.2.840.113556.1.8000.2554' // Adhoc (GUID/UUID-based) customer use. It is probably the same case as the UUID OIDs, after all, these are UUIDs, too. |
||
635 | daniel-mar | 965 | ); |
966 | |||
967 | // http://www.oid-info.com/cgi-bin/display?a=list-by-category&category=Not%20allocating%20Unicode%20labels |
||
968 | $no_iri = array( |
||
969 | 'oid:1.2.250.1', |
||
970 | 'oid:1.3.6.1.4.1', |
||
971 | 'oid:1.3.6.1.4.1.37476.9000', |
||
972 | 'oid:1.3.6.1.4.1.37553.8.8', |
||
973 | 'oid:2.16.276.1', |
||
974 | 'oid:2.25' |
||
975 | ); |
||
976 | |||
977 | $accepts_asn1 = ($parentNS == 'oid') && (!in_array($objParent->nodeId(), $no_asn1)) && (!is_uuid_oid($objParent->nodeId(),true)); |
||
978 | $accepts_iri = ($parentNS == 'oid') && (!in_array($objParent->nodeId(), $no_iri)) && (!is_uuid_oid($objParent->nodeId(),true)); |
||
979 | |||
980 | $result = OIDplus::db()->query("select o.*, r.ra_name " . |
||
981 | "from ###objects o " . |
||
982 | "left join ###ra r on r.email = o.ra_email " . |
||
983 | "where parent = ? " . |
||
984 | "order by ".OIDplus::db()->natOrder('id'), array($parent)); |
||
985 | |||
693 | daniel-mar | 986 | $rows = array(); |
987 | while ($row = $result->fetch_object()) { |
||
988 | $obj = OIDplusObject::parse($row->id); |
||
1121 | daniel-mar | 989 | if ($obj) $rows[] = array($obj,$row); |
693 | daniel-mar | 990 | } |
991 | |||
992 | $enable_weid_presentation = OIDplus::config()->getValue('oid_grid_show_weid'); |
||
993 | |||
1116 | daniel-mar | 994 | $output = '<div class="container box"><div id="suboid_table" class="table-responsive">'; |
635 | daniel-mar | 995 | $output .= '<table class="table table-bordered table-striped">'; |
996 | $output .= ' <tr>'; |
||
997 | $output .= ' <th>'._L('ID').(($parentNS == 'gs1') ? ' '._L('(without check digit)') : '').'</th>'; |
||
692 | daniel-mar | 998 | if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) { |
693 | daniel-mar | 999 | $output .= ' <th><abbr title="'._L('Binary-to-text encoding used for WEIDs').'">'._L('Base36').'</abbr></th>'; |
1000 | } |
||
635 | daniel-mar | 1001 | if ($parentNS == 'oid') { |
1002 | if ($accepts_asn1) $output .= ' <th>'._L('ASN.1 IDs (comma sep.)').'</th>'; |
||
1003 | if ($accepts_iri) $output .= ' <th>'._L('IRI IDs (comma sep.)').'</th>'; |
||
1004 | } |
||
1005 | $output .= ' <th>'._L('RA').'</th>'; |
||
1006 | $output .= ' <th>'._L('Comment').'</th>'; |
||
1007 | if ($objParent->userHasWriteRights()) { |
||
1008 | $output .= ' <th>'._L('Hide').'</th>'; |
||
1009 | $output .= ' <th>'._L('Update').'</th>'; |
||
1010 | $output .= ' <th>'._L('Delete').'</th>'; |
||
1011 | } |
||
1012 | $output .= ' <th>'._L('Created').'</th>'; |
||
1013 | $output .= ' <th>'._L('Updated').'</th>'; |
||
1014 | $output .= ' </tr>'; |
||
1015 | |||
1016 | foreach ($rows as list($obj,$row)) { |
||
1017 | $items_total++; |
||
1018 | if (!$obj->userHasReadRights()) { |
||
1019 | $items_hidden++; |
||
1020 | continue; |
||
1021 | } |
||
1022 | |||
1023 | $show_id = $obj->crudShowId($objParent); |
||
1024 | |||
1025 | $asn1ids = array(); |
||
1026 | $res2 = OIDplus::db()->query("select name from ###asn1id where oid = ? order by lfd", array($row->id)); |
||
1027 | while ($row2 = $res2->fetch_array()) { |
||
1028 | $asn1ids[] = $row2['name']; |
||
1029 | } |
||
1030 | |||
1031 | $iris = array(); |
||
1032 | $res2 = OIDplus::db()->query("select name from ###iri where oid = ? order by lfd", array($row->id)); |
||
1033 | while ($row2 = $res2->fetch_array()) { |
||
1034 | $iris[] = $row2['name']; |
||
1035 | } |
||
1036 | |||
1058 | daniel-mar | 1037 | $date_created = is_null($row->created) || (explode(' ', $row->created)[0] == '0000-00-00') ? '' : explode(' ', $row->created)[0]; |
1038 | $date_updated = is_null($row->updated) || (explode(' ', $row->updated)[0] == '0000-00-00') ? '' : explode(' ', $row->updated)[0]; |
||
635 | daniel-mar | 1039 | |
1040 | $output .= '<tr>'; |
||
693 | daniel-mar | 1041 | $output .= ' <td><a href="?goto='.urlencode($row->id).'" onclick="openAndSelectNode('.js_escape($row->id).', '.js_escape($parent).'); return false;">'.htmlentities($show_id).'</a>'; |
1042 | if ($enable_weid_presentation && ($parentNS == 'oid') && $objParent->isRoot()) { |
||
1043 | // To save space horizontal space, the WEIDs were written below the OIDs |
||
1116 | daniel-mar | 1044 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
693 | daniel-mar | 1045 | $output .= '<br>'.$obj->getWeidNotation(true); |
1046 | } |
||
1047 | $output .= '</td>'; |
||
1048 | if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) { |
||
1116 | daniel-mar | 1049 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
693 | daniel-mar | 1050 | $output .= ' <td>'.htmlentities($obj->weidArc()).'</td>'; |
1051 | } |
||
635 | daniel-mar | 1052 | if ($objParent->userHasWriteRights()) { |
1053 | if ($parentNS == 'oid') { |
||
1054 | if ($accepts_asn1) $output .= ' <td><input type="text" id="asn1ids_'.$row->id.'" value="'.implode(', ', $asn1ids).'"></td>'; |
||
1055 | if ($accepts_iri) $output .= ' <td><input type="text" id="iris_'.$row->id.'" value="'.implode(', ', $iris).'"></td>'; |
||
1056 | } |
||
1057 | $output .= ' <td><input type="text" id="ra_email_'.$row->id.'" value="'.htmlentities($row->ra_email).'"></td>'; |
||
1058 | $output .= ' <td><input type="text" id="comment_'.$row->id.'" value="'.htmlentities($row->comment).'"></td>'; |
||
1059 | $output .= ' <td><input type="checkbox" id="hide_'.$row->id.'" '.($row->confidential ? 'checked' : '').'></td>'; |
||
1060 | $output .= ' <td><button type="button" name="update_'.$row->id.'" id="update_'.$row->id.'" class="btn btn-success btn-xs update" onclick="OIDplusPagePublicObjects.crudActionUpdate('.js_escape($row->id).', '.js_escape($parent).')">'._L('Update').'</button></td>'; |
||
1061 | $output .= ' <td><button type="button" name="delete_'.$row->id.'" id="delete_'.$row->id.'" class="btn btn-danger btn-xs delete" onclick="OIDplusPagePublicObjects.crudActionDelete('.js_escape($row->id).', '.js_escape($parent).')">'._L('Delete').'</button></td>'; |
||
1062 | $output .= ' <td>'.$date_created.'</td>'; |
||
1063 | $output .= ' <td>'.$date_updated.'</td>'; |
||
1064 | } else { |
||
1065 | if ($parentNS == 'oid') { |
||
693 | daniel-mar | 1066 | if ($asn1ids == '') $asn1ids = '<i>'._L('(none)').'</i>'; |
1067 | if ($iris == '') $iris = '<i>'._L('(none)').'</i>'; |
||
635 | daniel-mar | 1068 | $asn1ids_ext = array(); |
1069 | foreach ($asn1ids as $asn1id) { |
||
1070 | $asn1ids_ext[] = '<a href="?goto='.urlencode($row->id).'" onclick="openAndSelectNode('.js_escape($row->id).', '.js_escape($parent).'); return false;">'.$asn1id.'</a>'; |
||
1071 | } |
||
1072 | if ($accepts_asn1) $output .= ' <td>'.implode(', ', $asn1ids_ext).'</td>'; |
||
1073 | if ($accepts_iri) $output .= ' <td>'.implode(', ', $iris).'</td>'; |
||
1074 | } |
||
1075 | $output .= ' <td><a '.OIDplus::gui()->link('oidplus:rainfo$'.str_replace('@','&',$row->ra_email)).'>'.htmlentities(empty($row->ra_name) ? str_replace('@','&',$row->ra_email) : $row->ra_name).'</a></td>'; |
||
1076 | $output .= ' <td>'.htmlentities($row->comment).'</td>'; |
||
1077 | $output .= ' <td>'.$date_created.'</td>'; |
||
1078 | $output .= ' <td>'.$date_updated.'</td>'; |
||
1079 | } |
||
1080 | $output .= '</tr>'; |
||
1081 | } |
||
1082 | |||
1121 | daniel-mar | 1083 | $parent_ra_email = $objParent->getRaMail() ; |
693 | daniel-mar | 1084 | |
692 | daniel-mar | 1085 | // "Create OID" row |
635 | daniel-mar | 1086 | if ($objParent->userHasWriteRights()) { |
1087 | $output .= '<tr>'; |
||
1121 | daniel-mar | 1088 | $prefix = $objParent->crudInsertPrefix(); |
693 | daniel-mar | 1089 | |
1121 | daniel-mar | 1090 | $suffix = $objParent->crudInsertSuffix(); |
693 | daniel-mar | 1091 | foreach (OIDplus::getObjectTypePlugins() as $plugin) { |
1131 | daniel-mar | 1092 | if (($plugin::getObjectTypeClassName()::ns() == $parentNS) && ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_6)) { |
1093 | $suffix .= $plugin->gridGeneratorLinks($objParent); |
||
693 | daniel-mar | 1094 | } |
1095 | } |
||
1096 | |||
1097 | if ($parentNS == 'guid') { |
||
695 | daniel-mar | 1098 | $output .= ' <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:275px">'.$suffix.'</td>'; |
693 | daniel-mar | 1099 | } else if ($parentNS == 'oid') { |
635 | daniel-mar | 1100 | // TODO: Idea: Give a class name, e.g. "OID" and then with a oid-specific CSS make the width individual. So, every plugin has more control over the appearance and widths of the input fields |
693 | daniel-mar | 1101 | if ($objParent->nodeId() === 'oid:2.25') { |
695 | daniel-mar | 1102 | $output .= ' <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:345px">'.$suffix.'</td>'; |
693 | daniel-mar | 1103 | if ($enable_weid_presentation) $output .= ' <td> </td>'; // For UUID-OIDs, you must generate a valid one. Don't be tempted to create one using the Base36 input! |
1104 | } else if ($objParent->isRoot()) { |
||
695 | daniel-mar | 1105 | $output .= ' <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:345px">'.$suffix.'</td>'; |
693 | daniel-mar | 1106 | if ($enable_weid_presentation) $output .= ''; // WEID-editor not available for root nodes at the moment. For the moment you need to enter the OID (TODO: Create JavaScript WEID encoder/decoder) |
635 | daniel-mar | 1107 | } else { |
693 | daniel-mar | 1108 | if ($enable_weid_presentation) { |
695 | daniel-mar | 1109 | $output .= ' <td>'.$prefix.' <input oninput="OIDplusPagePublicObjects.frdl_oidid_change()" type="text" id="id" value="" style="width:100%;min-width:100px">'.$suffix.'</td>'; |
693 | daniel-mar | 1110 | $output .= ' <td><input type="text" name="weid" id="weid" value="" oninput="OIDplusPagePublicObjects.frdl_weid_change()" style="width:100%;min-width:100px"></td>'; |
1111 | } else { |
||
695 | daniel-mar | 1112 | $output .= ' <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:100px">'.$suffix.'</td>'; |
693 | daniel-mar | 1113 | } |
635 | daniel-mar | 1114 | } |
1115 | } else { |
||
695 | daniel-mar | 1116 | $output .= ' <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:100px">'.$suffix.'</td>'; |
635 | daniel-mar | 1117 | } |
1118 | if ($accepts_asn1) $output .= ' <td><input type="text" id="asn1ids" value=""></td>'; |
||
1119 | if ($accepts_iri) $output .= ' <td><input type="text" id="iris" value=""></td>'; |
||
1120 | $output .= ' <td><input type="text" id="ra_email" value="'.htmlentities($parent_ra_email).'"></td>'; |
||
1121 | $output .= ' <td><input type="text" id="comment" value=""></td>'; |
||
1122 | $output .= ' <td><input type="checkbox" id="hide"></td>'; |
||
1123 | $output .= ' <td><button type="button" name="insert" id="insert" class="btn btn-success btn-xs update" onclick="OIDplusPagePublicObjects.crudActionInsert('.js_escape($parent).')">'._L('Insert').'</button></td>'; |
||
1124 | $output .= ' <td></td>'; |
||
1125 | $output .= ' <td></td>'; |
||
1126 | $output .= ' <td></td>'; |
||
1127 | $output .= '</tr>'; |
||
1128 | } else { |
||
1129 | if ($items_total-$items_hidden == 0) { |
||
1130 | $cols = ($parentNS == 'oid') ? 7 : 5; |
||
692 | daniel-mar | 1131 | if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) { |
1132 | $cols++; |
||
693 | daniel-mar | 1133 | } |
635 | daniel-mar | 1134 | $output .= '<tr><td colspan="'.$cols.'">'._L('No items available').'</td></tr>'; |
1135 | } |
||
1136 | } |
||
1137 | |||
1138 | $output .= '</table>'; |
||
1139 | $output .= '</div></div>'; |
||
1140 | |||
1141 | if ($items_hidden == 1) { |
||
1142 | $output .= '<p>'._L('One item is hidden. Please <a %1>log in</a> to see it.',$items_hidden,OIDplus::gui()->link('oidplus:login')).'</p>'; |
||
1143 | } else if ($items_hidden > 1) { |
||
1144 | $output .= '<p>'._L('%1 items are hidden. Please <a %2>log in</a> to see them.',$items_hidden,OIDplus::gui()->link('oidplus:login')).'</p>'; |
||
1145 | } |
||
1146 | |||
1147 | return $output; |
||
1148 | } |
||
1149 | |||
1116 | daniel-mar | 1150 | /** |
1130 | daniel-mar | 1151 | * @param string $html |
1152 | * @return string |
||
1116 | daniel-mar | 1153 | */ |
1130 | daniel-mar | 1154 | protected static function objDescription(string $html): string { |
635 | daniel-mar | 1155 | // We allow HTML, but no hacking |
1156 | $html = anti_xss($html); |
||
1157 | |||
1158 | return trim_br($html); |
||
1159 | } |
||
1160 | |||
1116 | daniel-mar | 1161 | /** |
1162 | * 'quickbars' added 11 July 2019: Disabled because of two problems: |
||
1163 | * 1. When you load TinyMCE via AJAX using the left menu, the quickbar is immediately shown, even if TinyMCE does not have the focus |
||
1164 | * 2. When you load a page without TinyMCE using the left menu, the quickbar is still visible, although there is no edit |
||
1165 | * 'colorpicker', 'textcolor' and 'contextmenu' added in 07 April 2020, because it is built in in the core. |
||
1166 | * 'importcss' added 17 September 2020, because it breaks the "Format/Style" dropdown box ("styleselect" toolbar) |
||
1167 | * 'legacyoutput' added 24 September 2021, because it is declared as deprecated |
||
1168 | * 'spellchecker' added 6 October 2021, because it is declared as deprecated and marked for removal in TinyMCE 6.0 |
||
1169 | * 'imagetools' and 'toc' added 23 February 2022, because they are declared as deprecated and marked for removal in TinyMCE 6.0 ("moving to premium") |
||
1170 | * @var string[] |
||
1171 | */ |
||
753 | daniel-mar | 1172 | public static $exclude_tinymce_plugins = array('fullpage', 'bbcode', 'quickbars', 'colorpicker', 'textcolor', 'contextmenu', 'importcss', 'legacyoutput', 'spellchecker', 'imagetools', 'toc'); |
635 | daniel-mar | 1173 | |
1116 | daniel-mar | 1174 | /** |
1130 | daniel-mar | 1175 | * @param string $name |
1176 | * @param string $content |
||
1116 | daniel-mar | 1177 | * @return string |
1178 | * @throws OIDplusConfigInitializationException |
||
1179 | * @throws OIDplusException |
||
1180 | */ |
||
1130 | daniel-mar | 1181 | protected static function showMCE(string $name, string $content): string { |
635 | daniel-mar | 1182 | $mce_plugins = array(); |
1183 | foreach (glob(OIDplus::localpath().'vendor/tinymce/tinymce/plugins/*') as $m) { // */ |
||
1184 | $mce_plugins[] = basename($m); |
||
1185 | } |
||
1186 | |||
1187 | foreach (self::$exclude_tinymce_plugins as $exclude) { |
||
1188 | $index = array_search($exclude, $mce_plugins); |
||
1189 | if ($index !== false) unset($mce_plugins[$index]); |
||
1190 | } |
||
1191 | |||
1192 | $oidplusLang = OIDplus::getCurrentLang(); |
||
1193 | |||
1194 | $langCandidates = array( |
||
1195 | strtolower(substr($oidplusLang,0,2)).'_'.strtoupper(substr($oidplusLang,2,2)), // de_DE |
||
1196 | strtolower(substr($oidplusLang,0,2)) // de |
||
1197 | ); |
||
1198 | $tinyMCELang = ''; |
||
1199 | foreach ($langCandidates as $candidate) { |
||
1200 | if (file_exists(OIDplus::localpath().'vendor/tweeb/tinymce-i18n/langs/'.$candidate.'.js')) { |
||
1201 | $tinyMCELang = $candidate; |
||
1202 | break; |
||
1203 | } |
||
1204 | } |
||
1205 | |||
1206 | $out = '<script> |
||
1207 | tinymce.EditorManager.baseURL = "vendor/tinymce/tinymce"; |
||
1208 | tinymce.init({ |
||
801 | daniel-mar | 1209 | document_base_url: "'.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'", |
635 | daniel-mar | 1210 | selector: "#'.$name.'", |
1211 | height: 200, |
||
1212 | statusbar: false, |
||
1213 | // menubar:false, |
||
1214 | // toolbar: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table | fontsizeselect", |
||
1215 | toolbar: "undo redo | styleselect | bold italic underline forecolor | bullist numlist | outdent indent | table | fontsizeselect", |
||
1216 | plugins: "'.implode(' ', $mce_plugins).'", |
||
1217 | mobile: { |
||
1218 | theme: "mobile", |
||
1219 | toolbar: "undo redo | styleselect | bold italic underline forecolor | bullist numlist | outdent indent | table | fontsizeselect", |
||
1220 | plugins: "'.implode(' ', $mce_plugins).'" |
||
1221 | } |
||
1222 | '.($tinyMCELang == '' ? '' : ', language : "'.$tinyMCELang.'"').' |
||
801 | daniel-mar | 1223 | '.($tinyMCELang == '' ? '' : ', language_url : "'.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'vendor/tweeb/tinymce-i18n/langs/'.$tinyMCELang.'.js"').' |
635 | daniel-mar | 1224 | }); |
1225 | |||
1226 | pageChangeRequestCallbacks.push([OIDplusPagePublicObjects.cbQueryTinyMCE, "#'.$name.'"]); |
||
1227 | pageChangeCallbacks.push([OIDplusPagePublicObjects.cbRemoveTinyMCE, "#'.$name.'"]); |
||
1228 | </script>'; |
||
1229 | |||
1230 | $content = htmlentities($content); // For some reason, if we want to display the text "<xyz>" in TinyMCE, we need to double-encode things! < will not be accepted, we need &lt; ... why? |
||
1231 | |||
1232 | $out .= '<textarea name="'.htmlentities($name).'" id="'.htmlentities($name).'">'.trim($content).'</textarea><br>'; |
||
1233 | |||
1234 | return $out; |
||
1235 | } |
||
1236 | |||
1116 | daniel-mar | 1237 | /** |
1131 | daniel-mar | 1238 | * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1 |
1116 | daniel-mar | 1239 | * @return bool |
1240 | * @throws OIDplusException |
||
1241 | */ |
||
635 | daniel-mar | 1242 | public function oobeRequested(): bool { |
1243 | return OIDplus::config()->getValue('oobe_objects_done') == '0'; |
||
1244 | } |
||
1245 | |||
1116 | daniel-mar | 1246 | /** |
1131 | daniel-mar | 1247 | * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1 |
1125 | daniel-mar | 1248 | * @param int $step |
1249 | * @param bool $do_edits |
||
1250 | * @param bool $errors_happened |
||
1116 | daniel-mar | 1251 | * @return void |
1252 | */ |
||
1125 | daniel-mar | 1253 | public function oobeEntry(int $step, bool $do_edits, bool &$errors_happened)/*: void*/ { |
1055 | daniel-mar | 1254 | echo '<h2>'._L('Step %1: Enable/Disable object type plugins',$step).'</h2>'; |
635 | daniel-mar | 1255 | echo '<p>'._L('Which object types do you want to manage using OIDplus?').'</p>'; |
1256 | |||
1257 | $enabled_ary = array(); |
||
1258 | |||
1259 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
||
1260 | echo '<input type="checkbox" name="enable_ot_'.$ot::ns().'" id="enable_ot_'.$ot::ns().'"'; |
||
1033 | daniel-mar | 1261 | if (isset($_POST['sent'])) { |
1262 | if (isset($_POST['enable_ot_'.$ot::ns()])) { |
||
635 | daniel-mar | 1263 | echo ' checked'; |
1264 | $enabled_ary[] = $ot::ns(); |
||
1265 | } |
||
1266 | } else { |
||
1267 | echo ' checked'; |
||
1268 | } |
||
1269 | echo '> <label for="enable_ot_'.$ot::ns().'">'.htmlentities($ot::objectTypeTitle()).'</label><br>'; |
||
1270 | } |
||
1271 | |||
1272 | foreach (OIDplus::getDisabledObjectTypes() as $ot) { |
||
1273 | echo '<input type="checkbox" name="enable_ot_'.$ot::ns().'" id="enable_ot_'.$ot::ns().'"'; |
||
1033 | daniel-mar | 1274 | if (isset($_POST['sent'])) { |
1275 | if (isset($_POST['enable_ot_'.$ot::ns()])) { |
||
635 | daniel-mar | 1276 | echo ' checked'; |
1277 | $enabled_ary[] = $ot::ns(); |
||
1278 | } |
||
1279 | } else { |
||
1280 | echo ''; // <-- difference |
||
1281 | } |
||
1282 | echo '> <label for="enable_ot_'.$ot::ns().'">'.htmlentities($ot::objectTypeTitle()).'</label><br>'; |
||
1283 | } |
||
1284 | |||
1285 | $msg = ''; |
||
1286 | if ($do_edits) { |
||
1287 | try { |
||
1288 | OIDplus::config()->setValue('objecttypes_enabled', implode(';', $enabled_ary)); |
||
1289 | OIDplus::config()->setValue('oobe_objects_done', '1'); |
||
1050 | daniel-mar | 1290 | } catch (\Exception $e) { |
635 | daniel-mar | 1291 | $msg = $e->getMessage(); |
1292 | $errors_happened = true; |
||
1293 | } |
||
1294 | } |
||
1295 | |||
1296 | echo ' <font color="red"><b>'.$msg.'</b></font>'; |
||
1297 | } |
||
1298 | |||
1116 | daniel-mar | 1299 | /** |
1131 | daniel-mar | 1300 | * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8 |
1130 | daniel-mar | 1301 | * @param string|null $user |
1116 | daniel-mar | 1302 | * @return array |
1303 | * @throws OIDplusException |
||
1304 | */ |
||
1130 | daniel-mar | 1305 | public function getNotifications(string $user=null): array { |
1000 | daniel-mar | 1306 | $notifications = array(); |
1012 | daniel-mar | 1307 | $res = OIDplus::db()->query("select id, title from ###objects order by ".OIDplus::db()->natOrder('id')); |
1000 | daniel-mar | 1308 | if ($res->any()) { |
1309 | $is_admin_logged_in = OIDplus::authUtils()->isAdminLoggedIn(); // run just once, for performance |
||
1310 | while ($row = $res->fetch_array()) { |
||
1311 | if (empty($row['title'])) { |
||
1312 | if ($user === 'admin') { |
||
1313 | $accept = $is_admin_logged_in; |
||
1314 | } else { |
||
1315 | $accept = false; |
||
1316 | if ($obj = OIDplusObject::parse($row['id'])) { |
||
1317 | if ($obj->userHasWriteRights($user)) { |
||
1318 | $accept = true; |
||
1319 | } |
||
1320 | } |
||
1321 | } |
||
1322 | |||
1323 | if ($accept) { |
||
1324 | $notifications[] = array('WARN', _L('Object %1 has no title.', '<a '.OIDplus::gui()->link($row['id']).'>'.$row['id'].'</a>')); |
||
1325 | } |
||
1326 | } |
||
1327 | } |
||
1328 | } |
||
1329 | return $notifications; |
||
1330 | } |
||
1331 | |||
693 | daniel-mar | 1332 | } |