Subversion Repositories oidplus

Rev

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