Subversion Repositories oidplus

Rev

Rev 1199 | Rev 1202 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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