Subversion Repositories oidplus

Rev

Rev 1219 | Rev 1261 | 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') {
1259 daniel-mar 322
                        $uuid = gen_uuid(OIDplus::config()->getValue('uuid_prefer_timebased', '1') == '1');
635 daniel-mar 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
                });
1259 daniel-mar 504
                OIDplus::config()->prepareConfigKey('uuid_prefer_timebased', 'Preferred UUID Generator version? 1=Timebased (Very secure, but reveals the MAC address of the server); 4=Random (has a very, very tiny change to generate duplicates)', '1', OIDplusConfig::PROTECTION_HIDDEN, function($value) {
505
                        if (($value != '1') && ($value != '4')) {
506
                                throw new OIDplusException(_L('Please enter a valid value (1=Timebased, 4=Random).'));
507
                        }
508
                });
635 daniel-mar 509
        }
510
 
1116 daniel-mar 511
        /**
1130 daniel-mar 512
         * @param string $id
513
         * @param array $out
1116 daniel-mar 514
         * @return array|false
515
         * @throws OIDplusException
516
         */
1130 daniel-mar 517
        private function tryObject(string $id, array &$out) {
951 daniel-mar 518
                $parent = null;
519
                $res = null;
520
                $row = null;
954 daniel-mar 521
                $obj = OIDplusObject::parse($id);
1116 daniel-mar 522
                if (!$obj) return false;
954 daniel-mar 523
                if ($obj->isRoot()) {
524
                        $obj->getContentPage($out['title'], $out['text'], $out['icon']);
977 daniel-mar 525
                        $objParent = null; // $obj->getParent();
954 daniel-mar 526
                } else {
977 daniel-mar 527
                        $obj = OIDplusObject::findFitting($id); // this time, the object will be found, not just the object type
528
                        if (!$obj) {
954 daniel-mar 529
                                return false;
530
                        } else {
531
                                $obj->getContentPage($out['title'], $out['text'], $out['icon']);
532
                                if (empty($out['title'])) $out['title'] = explode(':',$obj->nodeId(),2)[1];
977 daniel-mar 533
                                $objParent = $obj->getParent();
953 daniel-mar 534
                        }
951 daniel-mar 535
                }
977 daniel-mar 536
                return array($id, $obj, $objParent);
951 daniel-mar 537
        }
538
 
1116 daniel-mar 539
        /**
1130 daniel-mar 540
         * @param string $id
1116 daniel-mar 541
         * @return array
542
         */
1130 daniel-mar 543
        public static function getAlternativesForQuery(string $id): array {
1131 daniel-mar 544
                // Attention: This is NOT an implementation of INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7!
545
                //            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 546
 
951 daniel-mar 547
                // e.g. used for "Reverse Alt Id"
548
                $alternatives = array();
1005 daniel-mar 549
                foreach (OIDplus::getAllPlugins() as $plugin) {
1131 daniel-mar 550
                        if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7) {
551
                                $tmp = $plugin->getAlternativesForQuery($id);
951 daniel-mar 552
                                if (is_array($tmp)) {
553
                                        $alternatives = array_merge($tmp, $alternatives);
554
                                }
555
                        }
556
                }
968 daniel-mar 557
 
558
                // If something is more than one time, remove it
951 daniel-mar 559
                $alternatives = array_unique($alternatives);
968 daniel-mar 560
 
561
                // If a plugin accidentally added the own ID, remove it. This function lists only alternatives, not the own ID
562
                $alternatives_tmp = array();
563
                foreach ($alternatives as $alt) {
564
                        if ($alt !== $id) $alternatives_tmp[] = $alt;
565
                }
1130 daniel-mar 566
                return $alternatives_tmp;
951 daniel-mar 567
        }
568
 
1116 daniel-mar 569
        /**
570
         * @param string $id
571
         * @param array $out
572
         * @param bool $handled
573
         * @return void
574
         * @throws OIDplusConfigInitializationException
575
         * @throws OIDplusException
576
         */
577
        public function gui(string $id, array &$out, bool &$handled) {
635 daniel-mar 578
                if ($id === 'oidplus:system') {
579
                        $handled = true;
580
 
581
                        $out['title'] = OIDplus::config()->getValue('system_title');
801 daniel-mar 582
                        $out['icon'] = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png';
635 daniel-mar 583
 
584
                        if (file_exists(OIDplus::localpath() . 'userdata/welcome/welcome$'.OIDplus::getCurrentLang().'.html')) {
585
                                $cont = file_get_contents(OIDplus::localpath() . 'userdata/welcome/welcome$'.OIDplus::getCurrentLang().'.html');
586
                        } else if (file_exists(OIDplus::localpath() . 'userdata/welcome/welcome.html')) {
587
                                $cont = file_get_contents(OIDplus::localpath() . 'userdata/welcome/welcome.html');
588
                        } else if (file_exists(__DIR__ . '/welcome$'.OIDplus::getCurrentLang().'.html')) {
589
                                $cont = file_get_contents(__DIR__ . '/welcome$'.OIDplus::getCurrentLang().'.html');
590
                        } else if (file_exists(__DIR__ . '/welcome.html')) {
591
                                $cont = file_get_contents(__DIR__ . '/welcome.html');
592
                        } else {
593
                                $cont = '';
594
                        }
595
 
1143 daniel-mar 596
                        if ($cont) {
597
                                list($html, $js, $css) = extractHtmlContents($cont);
598
                                $cont = '';
599
                                if (!empty($js)) $cont .= "<script>\n$js\n</script>";
600
                                if (!empty($css)) $cont .= "<style>\n$css\n</style>";
601
                                $cont .= stripHtmlComments($html);
602
                        }
635 daniel-mar 603
 
604
                        $out['text'] = $cont;
605
 
606
                        if (strpos($out['text'], '%%OBJECT_TYPE_LIST%%') !== false) {
607
                                $tmp = '<ul>';
608
                                foreach (OIDplus::getEnabledObjectTypes() as $ot) {
609
                                        $tmp .= '<li><a '.OIDplus::gui()->link($ot::root()).'>'.htmlentities($ot::objectTypeTitle()).'</a></li>';
610
                                }
611
                                $tmp .= '</ul>';
612
                                $out['text'] = str_replace('%%OBJECT_TYPE_LIST%%', $tmp, $out['text']);
613
                        }
614
                }
615
 
957 daniel-mar 616
                // Never answer to an object type that is called 'oidplus:',
617
                // otherwise, an object type plugin could break the whole system!
618
                else if ((strpos($id,':') !== false) && (!str_starts_with($id,'oidplus:'))) {
635 daniel-mar 619
 
955 daniel-mar 620
                        // --- Try to find the object or an alternative
635 daniel-mar 621
 
951 daniel-mar 622
                        $test = $this->tryObject($id, $out);
623
                        if ($test === false) {
955 daniel-mar 624
                                // try to find an alternative
952 daniel-mar 625
                                $alternatives = $this->getAlternativesForQuery($id);
951 daniel-mar 626
                                foreach ($alternatives as $alternative) {
627
                                        $test = $this->tryObject($alternative, $out);
955 daniel-mar 628
                                        if ($test !== false) break; // found something
635 daniel-mar 629
                                }
630
                        }
955 daniel-mar 631
                        if ($test !== false) {
977 daniel-mar 632
                                list($id, $obj, $objParent) = $test;
1132 daniel-mar 633
                        } else {
634
                                $objParent = null; // to avoid warnings
955 daniel-mar 635
                        }
636
 
637
                        // --- If the object type is disabled or not an object at all (e.g. "oidplus:"), then $handled=false
638
                        //     If the object type is enabled but object not found, $handled=true
639
 
970 daniel-mar 640
                        $obj = OIDplusObject::parse($id);
955 daniel-mar 641
 
951 daniel-mar 642
                        if ($test === false) {
1116 daniel-mar 643
                                if (!$obj) {
955 daniel-mar 644
                                        // Object type disabled or not known (e.g. ObjectType "oidplus:").
645
                                        $handled = false;
646
                                        return;
647
                                } else {
648
                                        // Object type enabled but identifier not in database
649
                                        $handled = true;
650
                                        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
651
                                                http_response_code(404);
652
                                        }
1206 daniel-mar 653
                                        throw new OIDplusHtmlException(_L('The object %1 was not found in this database.','<code>'.htmlentities($id).'</code>'), _L('Object not found'));
955 daniel-mar 654
                                }
655
                        } else {
656
                                $handled = true;
657
                        }
658
 
659
                        unset($test);
660
 
661
                        // --- If found, do we have read rights?
662
 
663
                        if (!$obj->userHasReadRights()) {
843 daniel-mar 664
                                if (isset($_SERVER['SCRIPT_FILENAME']) && (strtolower(basename($_SERVER['SCRIPT_FILENAME'])) !== 'ajax.php')) { // don't send HTTP error codes in ajax.php, because we want a page and not a JavaScript alert box, when someone enters an invalid OID in the GoTo-Box
955 daniel-mar 665
                                        http_response_code(403);
843 daniel-mar 666
                                }
1206 daniel-mar 667
                                throw new OIDplusHtmlException(_L('Please <a %1>log in</a> to receive information about this object.',OIDplus::gui()->link('oidplus:login')), _L('Access denied'));
635 daniel-mar 668
                        }
669
 
670
                        // ---
671
 
977 daniel-mar 672
                        if ($objParent) {
673
                                if ($objParent->isRoot()) {
674
                                        $parent_link_text = $objParent->objectTypeTitle();
675
                                        $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 676
                                } else {
977 daniel-mar 677
                                        $parent_title = $objParent->getTitle();
678
                                        if (empty($parent_title) && ($objParent->ns() == 'oid')) {
1116 daniel-mar 679
                                                assert($objParent instanceof OIDplusOid); //assert(get_class($objParent) === "ViaThinkSoft\OIDplus\OIDplusOid");
977 daniel-mar 680
                                                // If not title is available, then use an ASN.1 identifier
681
                                                $res_asn = OIDplus::db()->query("select name from ###asn1id where oid = ?", array($objParent->nodeId()));
682
                                                if ($res_asn->any()) {
683
                                                        $row_asn = $res_asn->fetch_array();
684
                                                        $parent_title = $row_asn['name']; // TODO: multiple ASN1 ids?
635 daniel-mar 685
                                                }
977 daniel-mar 686
                                        }
635 daniel-mar 687
 
977 daniel-mar 688
                                        $parent_link_text = empty($parent_title) ? explode(':',$objParent->nodeId())[1] : $parent_title.' ('.explode(':',$objParent->nodeId())[1].')';
635 daniel-mar 689
 
977 daniel-mar 690
                                        $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 691
                                }
692
                        } else {
693
                                $parent_link_text = _L('Go back to front page');
694
                                $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'];
695
                        }
696
 
697
                        // ---
698
 
977 daniel-mar 699
                        if ($obj) {
1144 daniel-mar 700
                                $title = $obj->getTitle() ?? '';
701
                                $description = $obj->getDescription() ?? '';
999 daniel-mar 702
                                if (empty(strip_tags($description)) && (stripos($description,'<img') === false)) {
977 daniel-mar 703
                                        if (empty($title)) {
635 daniel-mar 704
                                                $desc = '<p><i>'._L('No description for this object available').'</i></p>';
705
                                        } else {
977 daniel-mar 706
                                                $desc = $title;
635 daniel-mar 707
                                        }
708
                                } else {
977 daniel-mar 709
                                        $desc = self::objDescription($description);
635 daniel-mar 710
                                }
711
 
1144 daniel-mar 712
                                // $description is the description in the OID table (which the user edits)
713
                                // $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)
714
 
635 daniel-mar 715
                                if ($obj->userHasWriteRights()) {
716
                                        $rand = ++self::$crudCounter;
717
                                        $desc = '<noscript><p><b>'._L('You need to enable JavaScript to edit title or description of this object.').'</b></p>'.$desc.'</noscript>';
718
                                        $desc .= '<div class="container box" style="display:none" id="descbox_'.$rand.'">';
977 daniel-mar 719
                                        $desc .= _L('Title').': <input type="text" name="title" id="titleedit" value="'.htmlentities($title).'"><br><br>'._L('Description').':<br>';
720
                                        $desc .= self::showMCE('description', $description);
635 daniel-mar 721
                                        $desc .= '<button type="button" name="update_desc" id="update_desc" class="btn btn-success btn-xs update" onclick="OIDplusPagePublicObjects.updateDesc()">'._L('Update description').'</button>';
722
                                        $desc .= '</div>';
723
                                        $desc .= '<script>$("#descbox_'.$rand.'")[0].style.display = "block";</script>';
724
                                }
725
                        } else {
726
                                $desc = '';
727
                        }
728
 
729
                        // ---
730
 
731
                        if (strpos($out['text'], '%%DESC%%') !== false)
732
                                $out['text'] = str_replace('%%DESC%%',    $desc,                              $out['text']);
733
                        if (strpos($out['text'], '%%CRUD%%') !== false)
856 daniel-mar 734
                                $out['text'] = str_replace('%%CRUD%%',    self::showCrud($obj->nodeId()),     $out['text']);
635 daniel-mar 735
                        if (strpos($out['text'], '%%RA_INFO%%') !== false)
977 daniel-mar 736
                                $out['text'] = str_replace('%%RA_INFO%%', OIDplusPagePublicRaInfo::showRaInfo($obj->getRaMail()), $out['text']);
635 daniel-mar 737
 
738
                        $alt_ids = $obj->getAltIds();
739
                        if (count($alt_ids) > 0) {
740
                                $out['text'] .= '<h2>'._L('Alternative Identifiers').'</h2>';
1138 daniel-mar 741
 
742
                                // Sorty by namespace
743
                                usort($alt_ids, function(OIDplusAltId $a, OIDplusAltId $b) {
744
                                        if($a->getNamespace() > $b->getNamespace()) {
745
                                                return 1;
746
                                        }
747
                                        elseif($a->getNamespace() < $b->getNamespace()) {
748
                                                return -1;
749
                                        }
750
                                        else {
751
                                                return 0;
752
                                        }
753
                                });
754
 
755
                                $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
756
                                $out['text'] .= '<table class="table table-bordered table-striped">';
757
                                $out['text'] .= '<thead>';
758
                                $out['text'] .= '<tr><th>'._L('Identifier').'</th><th>'._L('Description').'</th></tr>';
759
                                $out['text'] .= '</thead>';
760
                                $out['text'] .= '<tbody>';
635 daniel-mar 761
                                foreach ($alt_ids as $alt_id) {
762
                                        $ns = $alt_id->getNamespace();
763
                                        $aid = $alt_id->getId();
764
                                        $aiddesc = $alt_id->getDescription();
945 daniel-mar 765
                                        $suffix = $alt_id->getSuffix();
1138 daniel-mar 766
                                        $out['text'] .= '<tr><td>'.htmlentities($ns.':'.$aid).($suffix ? '<br/><font size="-1">'.htmlentities($suffix).'</font>' : '').'</td><td>'.htmlentities($aiddesc).'</td></tr>';
635 daniel-mar 767
                                }
1138 daniel-mar 768
                                $out['text'] .= '</tbody>';
769
                                $out['text'] .= '</table>';
770
                                $out['text'] .= '</div></div>';
635 daniel-mar 771
                        }
772
 
1005 daniel-mar 773
                        foreach (OIDplus::getAllPlugins() as $plugin) {
1131 daniel-mar 774
                                if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_2) {
775
                                        $plugin->modifyContent($obj->nodeId(), $out['title'], $out['icon'], $out['text']);
635 daniel-mar 776
                                }
777
                        }
778
                }
779
        }
780
 
1116 daniel-mar 781
        /**
1130 daniel-mar 782
         * @param array $json
783
         * @param array $out
1116 daniel-mar 784
         * @return void
785
         */
1130 daniel-mar 786
        private function publicSitemap_rec(array $json, array &$out) {
635 daniel-mar 787
                foreach ($json as $x) {
788
                        if (isset($x['id']) && $x['id']) {
789
                                $out[] = $x['id'];
790
                        }
791
                        if (isset($x['children'])) {
792
                                $this->publicSitemap_rec($x['children'], $out);
793
                        }
794
                }
795
        }
796
 
1116 daniel-mar 797
        /**
798
         * @param array $out
799
         * @return void
800
         */
801
        public function publicSitemap(array &$out) {
635 daniel-mar 802
                $json = array();
1116 daniel-mar 803
                $this->tree($json, null/*RA EMail*/, false/*HTML tree algorithm*/, "*"/*display all*/);
635 daniel-mar 804
                $this->publicSitemap_rec($json, $out);
805
        }
806
 
1116 daniel-mar 807
        /**
808
         * @param array $json
809
         * @param string|null $ra_email
810
         * @param bool $nonjs
811
         * @param string $req_goto
812
         * @return bool
813
         * @throws OIDplusConfigInitializationException
814
         * @throws OIDplusException
815
         */
816
        public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
635 daniel-mar 817
                if ($nonjs) {
818
                        $json[] = array(
819
                                'id' => 'oidplus:system',
801 daniel-mar 820
                                'icon' => OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png',
635 daniel-mar 821
                                'text' => _L('System')
822
                        );
823
 
977 daniel-mar 824
                        $objGoto = OIDplusObject::findFitting($req_goto);
998 daniel-mar 825
                        $objGotoParent = $objGoto ? $objGoto->getParent() : null;
977 daniel-mar 826
                        $parent = $objGotoParent ? $objGotoParent->nodeId() : '';
635 daniel-mar 827
 
828
                        $objTypesChildren = array();
829
                        foreach (OIDplus::getEnabledObjectTypes() as $ot) {
830
                                $icon = $this->get_treeicon_root($ot);
831
 
832
                                $json[] = array(
833
                                        'id' => $ot::root(),
834
                                        'icon' => $icon,
835
                                        'text' => $ot::objectTypeTitle()
836
                                );
837
 
954 daniel-mar 838
                                $tmp = OIDplusObject::parse($req_goto);
1116 daniel-mar 839
                                if ($tmp && ($ot == get_class($tmp))) {
635 daniel-mar 840
                                        // 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
841
                                        //       on the other hand, for giving search engines content, this is good enough
842
                                        if (empty($parent)) {
843
                                                $res = OIDplus::db()->query("select * from ###objects where " .
844
                                                                            "parent = ? or " .
1148 daniel-mar 845
                                                                            "id = ? ", array($req_goto, $req_goto));
635 daniel-mar 846
                                        } else {
847
                                                $res = OIDplus::db()->query("select * from ###objects where " .
848
                                                                            "parent = ? or " .
849
                                                                            "id = ? or " .
1148 daniel-mar 850
                                                                            "id = ? ", array($req_goto, $req_goto, $parent));
635 daniel-mar 851
                                        }
1156 daniel-mar 852
                                        $res->naturalSortByField('id');
635 daniel-mar 853
 
854
                                        $z_used = 0;
855
                                        $y_used = 0;
856
                                        $x_used = 0;
857
                                        $stufe = 0;
858
                                        $menu_entries = array();
859
                                        $stufen = array();
860
                                        while ($row = $res->fetch_object()) {
861
                                                $obj = OIDplusObject::parse($row->id);
1116 daniel-mar 862
                                                if (!$obj) continue; // might happen if the objectType is not available/loaded
635 daniel-mar 863
                                                if (!$obj->userHasReadRights()) continue;
1219 daniel-mar 864
                                                $txt = ($row->title ?? '') == '' ? '' : ' -- '.htmlentities($row->title);
635 daniel-mar 865
 
866
                                                if ($row->id == $parent) { $stufe=0; $z_used++; }
867
                                                if ($row->id == $req_goto) { $stufe=1; $y_used++; }
868
                                                if ($row->parent == $req_goto) { $stufe=2; $x_used++; }
869
 
870
                                                $menu_entry = array('id' => $row->id, 'icon' => '', 'text' => $txt, 'indent' => 0);
871
                                                $menu_entries[] = $menu_entry;
872
                                                $stufen[] = $stufe;
873
                                        }
874
                                        if ($x_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 2) $menu_entry['indent'] += 1;
875
                                        if ($y_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 1) $menu_entry['indent'] += 1;
876
                                        if ($z_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 0) $menu_entry['indent'] += 1;
877
                                        $json = array_merge($json, $menu_entries);
878
                                }
879
                        }
880
 
881
                        return true;
882
                } else {
1116 daniel-mar 883
                        if ($req_goto === "*") {
635 daniel-mar 884
                                $goto_path = true; // display everything recursively
1116 daniel-mar 885
                        } else if ($req_goto !== "") {
635 daniel-mar 886
                                $goto = $req_goto;
887
                                $path = array();
888
                                while (true) {
889
                                        $path[] = $goto;
977 daniel-mar 890
                                        $objGoto = OIDplusObject::findFitting($goto);
891
                                        if (!$objGoto) break;
892
                                        $objGotoParent = $objGoto->getParent();
893
                                        $goto = $objGotoParent ? $objGotoParent->nodeId() : '';
635 daniel-mar 894
                                        if ($goto == '') continue;
895
                                }
896
 
897
                                $goto_path = array_reverse($path);
898
                        } else {
899
                                $goto_path = null;
900
                        }
901
 
902
                        $objTypesChildren = array();
903
                        foreach (OIDplus::getEnabledObjectTypes() as $ot) {
904
                                $icon = $this->get_treeicon_root($ot);
905
 
906
                                $child = array('id' => $ot::root(),
907
                                               'text' => $ot::objectTypeTitle(),
908
                                               'state' => array("opened" => true),
909
                                               'icon' => $icon,
910
                                               'children' => OIDplus::menuUtils()->tree_populate($ot::root(), $goto_path)
911
                                               );
1122 daniel-mar 912
                                if ($child['icon'] && !file_exists($child['icon'])) $child['icon'] = null; // default icon (folder)
635 daniel-mar 913
                                $objTypesChildren[] = $child;
914
                        }
915
 
916
                        $json[] = array(
917
                                'id' => "oidplus:system",
918
                                'text' => _L('Objects'),
919
                                'state' => array(
920
                                        "opened" => true,
921
                                        // "selected" => true)  // "selected" is buggy:
922
                                        // 1) The select-event will not be triggered upon loading
923
                                        // 2) The nodes directly blow cannot be opened (loading infinite time)
924
                                ),
801 daniel-mar 925
                                'icon' => OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png',
635 daniel-mar 926
                                'children' => $objTypesChildren
927
                        );
928
 
929
                        return true;
930
                }
931
        }
932
 
1116 daniel-mar 933
        /**
934
         * @param string $request
935
         * @return array|false
936
         */
937
        public function tree_search(string $request) {
635 daniel-mar 938
                $ary = array();
951 daniel-mar 939
                $found_leaf = false;
635 daniel-mar 940
                if ($obj = OIDplusObject::parse($request)) {
951 daniel-mar 941
                        $found_leaf = OIDplusObject::exists($request);
942
                        do {
943
                                if ($obj->userHasReadRights()) {
635 daniel-mar 944
                                        $ary[] = $obj->nodeId();
951 daniel-mar 945
                                }
946
                        } while ($obj = $obj->getParent());
947
                        $ary = array_reverse($ary);
948
                }
949
                if (!$found_leaf) {
952 daniel-mar 950
                        $alternatives = $this->getAlternativesForQuery($request);
951 daniel-mar 951
                        foreach ($alternatives as $alternative) {
952
                                $ary_ = array();
953
                                if ($obj = OIDplusObject::parse($alternative)) {
954
                                        if ($obj->userHasReadRights() && OIDplusObject::exists($alternative)) {
955
                                                do {
956
                                                        $ary_[] = $obj->nodeId();
957
                                                } while ($obj = $obj->getParent());
958
                                                $ary_ = array_reverse($ary_);
959
                                        }
960
                                }
961
                                if (!empty($ary_)) {
962
                                        $ary = $ary_;
963
                                        break;
964
                                }
635 daniel-mar 965
                        }
966
                }
967
                return $ary;
968
        }
969
 
1116 daniel-mar 970
        /**
971
         * @var int
972
         */
635 daniel-mar 973
        private static $crudCounter = 0;
974
 
1116 daniel-mar 975
        /**
1121 daniel-mar 976
         * @param string $parent
977
         * @return string
1116 daniel-mar 978
         * @throws OIDplusConfigInitializationException
979
         * @throws OIDplusException
980
         */
1121 daniel-mar 981
        protected static function showCrud(string $parent='oid:'): string {
635 daniel-mar 982
                $items_total = 0;
983
                $items_hidden = 0;
984
 
985
                $objParent = OIDplusObject::parse($parent);
1121 daniel-mar 986
                if (!$objParent) return '';
635 daniel-mar 987
                $parentNS = $objParent::ns();
988
 
989
                // http://www.oid-info.com/cgi-bin/display?a=list-by-category&category=Not%20allocating%20identifiers
990
                $no_asn1 = array(
991
                        'oid:1.3.6.1.4.1',
992
                        'oid:1.3.6.1.4.1.37476.9000',
993
                        'oid:1.3.6.1.4.1.37553.8.8',
994
                        'oid:2.16.276.1',
719 daniel-mar 995
                        //'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
996
                        //'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 997
                );
998
 
999
                // http://www.oid-info.com/cgi-bin/display?a=list-by-category&category=Not%20allocating%20Unicode%20labels
1000
                $no_iri = array(
1001
                        'oid:1.2.250.1',
1002
                        'oid:1.3.6.1.4.1',
1003
                        'oid:1.3.6.1.4.1.37476.9000',
1004
                        'oid:1.3.6.1.4.1.37553.8.8',
1005
                        'oid:2.16.276.1',
1006
                        'oid:2.25'
1007
                );
1008
 
1009
                $accepts_asn1 = ($parentNS == 'oid') && (!in_array($objParent->nodeId(), $no_asn1)) && (!is_uuid_oid($objParent->nodeId(),true));
1010
                $accepts_iri  = ($parentNS == 'oid') && (!in_array($objParent->nodeId(), $no_iri)) && (!is_uuid_oid($objParent->nodeId(),true));
1011
 
1012
                $result = OIDplus::db()->query("select o.*, r.ra_name " .
1013
                                               "from ###objects o " .
1014
                                               "left join ###ra r on r.email = o.ra_email " .
1148 daniel-mar 1015
                                               "where parent = ? ", array($parent));
1156 daniel-mar 1016
                $result->naturalSortByField('id');
635 daniel-mar 1017
 
693 daniel-mar 1018
                $rows = array();
1019
                while ($row = $result->fetch_object()) {
1020
                        $obj = OIDplusObject::parse($row->id);
1121 daniel-mar 1021
                        if ($obj) $rows[] = array($obj,$row);
693 daniel-mar 1022
                }
1023
 
1024
                $enable_weid_presentation = OIDplus::config()->getValue('oid_grid_show_weid');
1025
 
1116 daniel-mar 1026
                $output  = '<div class="container box"><div id="suboid_table" class="table-responsive">';
1259 daniel-mar 1027
                $output .= '<table id="crudTable" class="table table-bordered table-striped">';
1138 daniel-mar 1028
                $output .= '<thead>';
635 daniel-mar 1029
                $output .= '    <tr>';
1030
                $output .= '         <th>'._L('ID').(($parentNS == 'gs1') ? ' '._L('(without check digit)') : '').'</th>';
692 daniel-mar 1031
                if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) {
693 daniel-mar 1032
                        $output .= '         <th><abbr title="'._L('Binary-to-text encoding used for WEIDs').'">'._L('Base36').'</abbr></th>';
1033
                }
635 daniel-mar 1034
                if ($parentNS == 'oid') {
1035
                        if ($accepts_asn1) $output .= '      <th>'._L('ASN.1 IDs (comma sep.)').'</th>';
1036
                        if ($accepts_iri)  $output .= '      <th>'._L('IRI IDs (comma sep.)').'</th>';
1037
                }
1038
                $output .= '         <th>'._L('RA').'</th>';
1039
                $output .= '         <th>'._L('Comment').'</th>';
1040
                if ($objParent->userHasWriteRights()) {
1041
                        $output .= '         <th>'._L('Hide').'</th>';
1042
                        $output .= '         <th>'._L('Update').'</th>';
1043
                        $output .= '         <th>'._L('Delete').'</th>';
1044
                }
1045
                $output .= '         <th>'._L('Created').'</th>';
1046
                $output .= '         <th>'._L('Updated').'</th>';
1047
                $output .= '    </tr>';
1138 daniel-mar 1048
                $output .= '</thead>';
1141 daniel-mar 1049
 
1138 daniel-mar 1050
                $output .= '<tbody>';
635 daniel-mar 1051
                foreach ($rows as list($obj,$row)) {
1052
                        $items_total++;
1053
                        if (!$obj->userHasReadRights()) {
1054
                                $items_hidden++;
1055
                                continue;
1056
                        }
1057
 
1058
                        $show_id = $obj->crudShowId($objParent);
1059
 
1060
                        $asn1ids = array();
1061
                        $res2 = OIDplus::db()->query("select name from ###asn1id where oid = ? order by lfd", array($row->id));
1062
                        while ($row2 = $res2->fetch_array()) {
1063
                                $asn1ids[] = $row2['name'];
1064
                        }
1065
 
1066
                        $iris = array();
1067
                        $res2 = OIDplus::db()->query("select name from ###iri where oid = ? order by lfd", array($row->id));
1068
                        while ($row2 = $res2->fetch_array()) {
1069
                                $iris[] = $row2['name'];
1070
                        }
1071
 
1058 daniel-mar 1072
                        $date_created = is_null($row->created) || (explode(' ', $row->created)[0] == '0000-00-00') ? '' : explode(' ', $row->created)[0];
1073
                        $date_updated = is_null($row->updated) || (explode(' ', $row->updated)[0] == '0000-00-00') ? '' : explode(' ', $row->updated)[0];
635 daniel-mar 1074
 
1075
                        $output .= '<tr>';
693 daniel-mar 1076
                        $output .= '     <td><a href="?goto='.urlencode($row->id).'" onclick="openAndSelectNode('.js_escape($row->id).', '.js_escape($parent).'); return false;">'.htmlentities($show_id).'</a>';
1077
                        if ($enable_weid_presentation && ($parentNS == 'oid') && $objParent->isRoot()) {
1078
                                // To save space horizontal space, the WEIDs were written below the OIDs
1116 daniel-mar 1079
                                assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
693 daniel-mar 1080
                                $output .= '<br>'.$obj->getWeidNotation(true);
1081
                        }
1082
                        $output .= '</td>';
1083
                        if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) {
1116 daniel-mar 1084
                                assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
693 daniel-mar 1085
                                $output .= '    <td>'.htmlentities($obj->weidArc()).'</td>';
1086
                        }
635 daniel-mar 1087
                        if ($objParent->userHasWriteRights()) {
1088
                                if ($parentNS == 'oid') {
1089
                                        if ($accepts_asn1) $output .= '     <td><input type="text" id="asn1ids_'.$row->id.'" value="'.implode(', ', $asn1ids).'"></td>';
1090
                                        if ($accepts_iri)  $output .= '     <td><input type="text" id="iris_'.$row->id.'" value="'.implode(', ', $iris).'"></td>';
1091
                                }
1219 daniel-mar 1092
                                $output .= '     <td><input type="text" id="ra_email_'.$row->id.'" value="'.htmlentities($row->ra_email ?? '').'"></td>';
1093
                                $output .= '     <td><input type="text" id="comment_'.$row->id.'" value="'.htmlentities($row->comment ?? '').'"></td>';
635 daniel-mar 1094
                                $output .= '     <td><input type="checkbox" id="hide_'.$row->id.'" '.($row->confidential ? 'checked' : '').'></td>';
1095
                                $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>';
1096
                                $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>';
1097
                                $output .= '     <td>'.$date_created.'</td>';
1098
                                $output .= '     <td>'.$date_updated.'</td>';
1099
                        } else {
1100
                                if ($parentNS == 'oid') {
693 daniel-mar 1101
                                        if ($asn1ids == '') $asn1ids = '<i>'._L('(none)').'</i>';
1102
                                        if ($iris == '') $iris = '<i>'._L('(none)').'</i>';
635 daniel-mar 1103
                                        $asn1ids_ext = array();
1104
                                        foreach ($asn1ids as $asn1id) {
1105
                                                $asn1ids_ext[] = '<a href="?goto='.urlencode($row->id).'" onclick="openAndSelectNode('.js_escape($row->id).', '.js_escape($parent).'); return false;">'.$asn1id.'</a>';
1106
                                        }
1107
                                        if ($accepts_asn1) $output .= '     <td>'.implode(', ', $asn1ids_ext).'</td>';
1108
                                        if ($accepts_iri)  $output .= '     <td>'.implode(', ', $iris).'</td>';
1109
                                }
1219 daniel-mar 1110
                                $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>';
1111
                                $output .= '     <td>'.htmlentities($row->comment ?? '').'</td>';
635 daniel-mar 1112
                                $output .= '     <td>'.$date_created.'</td>';
1113
                                $output .= '     <td>'.$date_updated.'</td>';
1114
                        }
1115
                        $output .= '</tr>';
1116
                }
1141 daniel-mar 1117
                $output .= '</tbody>';
635 daniel-mar 1118
 
1121 daniel-mar 1119
                $parent_ra_email = $objParent->getRaMail() ;
693 daniel-mar 1120
 
692 daniel-mar 1121
                // "Create OID" row
635 daniel-mar 1122
                if ($objParent->userHasWriteRights()) {
1141 daniel-mar 1123
                        $output .= '<tfoot>';
635 daniel-mar 1124
                        $output .= '<tr>';
1121 daniel-mar 1125
                        $prefix = $objParent->crudInsertPrefix();
693 daniel-mar 1126
 
1121 daniel-mar 1127
                        $suffix = $objParent->crudInsertSuffix();
693 daniel-mar 1128
                        foreach (OIDplus::getObjectTypePlugins() as $plugin) {
1137 daniel-mar 1129
                                if (($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_6) && ($plugin::getObjectTypeClassName()::ns() == $parentNS)) {
1131 daniel-mar 1130
                                        $suffix .= $plugin->gridGeneratorLinks($objParent);
693 daniel-mar 1131
                                }
1132
                        }
1133
 
1134
                        if ($parentNS == 'guid') {
695 daniel-mar 1135
                                $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:275px">'.$suffix.'</td>';
693 daniel-mar 1136
                        } else if ($parentNS == 'oid') {
635 daniel-mar 1137
                                // 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 1138
                                if ($objParent->nodeId() === 'oid:2.25') {
695 daniel-mar 1139
                                        $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:345px">'.$suffix.'</td>';
693 daniel-mar 1140
                                        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!
1141
                                } else if ($objParent->isRoot()) {
695 daniel-mar 1142
                                        $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:345px">'.$suffix.'</td>';
693 daniel-mar 1143
                                        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 1144
                                } else {
693 daniel-mar 1145
                                        if ($enable_weid_presentation) {
695 daniel-mar 1146
                                                $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 1147
                                                $output .= '     <td><input type="text" name="weid" id="weid" value="" oninput="OIDplusPagePublicObjects.frdl_weid_change()" style="width:100%;min-width:100px"></td>';
1148
                                        } else {
695 daniel-mar 1149
                                                $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:100px">'.$suffix.'</td>';
693 daniel-mar 1150
                                        }
635 daniel-mar 1151
                                }
1152
                        } else {
695 daniel-mar 1153
                                $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:100px">'.$suffix.'</td>';
635 daniel-mar 1154
                        }
1155
                        if ($accepts_asn1) $output .= '     <td><input type="text" id="asn1ids" value=""></td>';
1156
                        if ($accepts_iri)  $output .= '     <td><input type="text" id="iris" value=""></td>';
1137 daniel-mar 1157
                        $output .= '     <td><input type="text" id="ra_email" value="'.htmlentities($parent_ra_email ?? '').'"></td>';
635 daniel-mar 1158
                        $output .= '     <td><input type="text" id="comment" value=""></td>';
1159
                        $output .= '     <td><input type="checkbox" id="hide"></td>';
1160
                        $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>';
1161
                        $output .= '     <td></td>';
1162
                        $output .= '     <td></td>';
1163
                        $output .= '     <td></td>';
1164
                        $output .= '</tr>';
1141 daniel-mar 1165
                        $output .= '</tfoot>';
635 daniel-mar 1166
                } else {
1167
                        if ($items_total-$items_hidden == 0) {
1168
                                $cols = ($parentNS == 'oid') ? 7 : 5;
692 daniel-mar 1169
                                if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) {
1170
                                        $cols++;
693 daniel-mar 1171
                                }
1138 daniel-mar 1172
                                $output .= '<tfoot>';
635 daniel-mar 1173
                                $output .= '<tr><td colspan="'.$cols.'">'._L('No items available').'</td></tr>';
1138 daniel-mar 1174
                                $output .= '</tfoot>';
635 daniel-mar 1175
                        }
1176
                }
1177
 
1178
                $output .= '</table>';
1179
                $output .= '</div></div>';
1180
 
1181
                if ($items_hidden == 1) {
1182
                        $output .= '<p>'._L('One item is hidden. Please <a %1>log in</a> to see it.',$items_hidden,OIDplus::gui()->link('oidplus:login')).'</p>';
1183
                } else if ($items_hidden > 1) {
1184
                        $output .= '<p>'._L('%1 items are hidden. Please <a %2>log in</a> to see them.',$items_hidden,OIDplus::gui()->link('oidplus:login')).'</p>';
1185
                }
1186
 
1187
                return $output;
1188
        }
1189
 
1116 daniel-mar 1190
        /**
1130 daniel-mar 1191
         * @param string $html
1192
         * @return string
1116 daniel-mar 1193
         */
1130 daniel-mar 1194
        protected static function objDescription(string $html): string {
635 daniel-mar 1195
                // We allow HTML, but no hacking
1196
                $html = anti_xss($html);
1197
 
1198
                return trim_br($html);
1199
        }
1200
 
1116 daniel-mar 1201
        /**
1202
         * 'quickbars' added 11 July 2019: Disabled because of two problems:
1203
         *                                 1. When you load TinyMCE via AJAX using the left menu, the quickbar is immediately shown, even if TinyMCE does not have the focus
1204
         *                                 2. When you load a page without TinyMCE using the left menu, the quickbar is still visible, although there is no edit
1205
         * 'colorpicker', 'textcolor' and 'contextmenu' added in 07 April 2020, because it is built in in the core.
1206
         * 'importcss' added 17 September 2020, because it breaks the "Format/Style" dropdown box ("styleselect" toolbar)
1207
         * 'legacyoutput' added 24 September 2021, because it is declared as deprecated
1208
         * 'spellchecker' added 6 October 2021, because it is declared as deprecated and marked for removal in TinyMCE 6.0
1209
         * 'imagetools' and 'toc' added 23 February 2022, because they are declared as deprecated and marked for removal in TinyMCE 6.0 ("moving to premium")
1210
         * @var string[]
1211
         */
753 daniel-mar 1212
        public static $exclude_tinymce_plugins = array('fullpage', 'bbcode', 'quickbars', 'colorpicker', 'textcolor', 'contextmenu', 'importcss', 'legacyoutput', 'spellchecker', 'imagetools', 'toc');
635 daniel-mar 1213
 
1116 daniel-mar 1214
        /**
1130 daniel-mar 1215
         * @param string $name
1216
         * @param string $content
1116 daniel-mar 1217
         * @return string
1218
         * @throws OIDplusConfigInitializationException
1219
         * @throws OIDplusException
1220
         */
1130 daniel-mar 1221
        protected static function showMCE(string $name, string $content): string {
635 daniel-mar 1222
                $mce_plugins = array();
1223
                foreach (glob(OIDplus::localpath().'vendor/tinymce/tinymce/plugins/*') as $m) { // */
1224
                        $mce_plugins[] = basename($m);
1225
                }
1226
 
1227
                foreach (self::$exclude_tinymce_plugins as $exclude) {
1228
                        $index = array_search($exclude, $mce_plugins);
1229
                        if ($index !== false) unset($mce_plugins[$index]);
1230
                }
1231
 
1232
                $oidplusLang = OIDplus::getCurrentLang();
1233
 
1234
                $langCandidates = array(
1235
                        strtolower(substr($oidplusLang,0,2)).'_'.strtoupper(substr($oidplusLang,2,2)), // de_DE
1236
                        strtolower(substr($oidplusLang,0,2)) // de
1237
                );
1238
                $tinyMCELang = '';
1239
                foreach ($langCandidates as $candidate) {
1240
                        if (file_exists(OIDplus::localpath().'vendor/tweeb/tinymce-i18n/langs/'.$candidate.'.js')) {
1241
                                $tinyMCELang = $candidate;
1242
                                break;
1243
                        }
1244
                }
1245
 
1246
                $out = '<script>
1247
                                tinymce.EditorManager.baseURL = "vendor/tinymce/tinymce";
1248
                                tinymce.init({
801 daniel-mar 1249
                                        document_base_url: "'.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'",
635 daniel-mar 1250
                                        selector: "#'.$name.'",
1251
                                        height: 200,
1252
                                        statusbar: false,
1253
//                                      menubar:false,
1254
//                                      toolbar: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table | fontsizeselect",
1255
                                        toolbar: "undo redo | styleselect | bold italic underline forecolor | bullist numlist | outdent indent | table | fontsizeselect",
1256
                                        plugins: "'.implode(' ', $mce_plugins).'",
1257
                                        mobile: {
1258
                                                theme: "mobile",
1259
                                                toolbar: "undo redo | styleselect | bold italic underline forecolor | bullist numlist | outdent indent | table | fontsizeselect",
1260
                                                plugins: "'.implode(' ', $mce_plugins).'"
1261
                                        }
1262
                                        '.($tinyMCELang == '' ? '' : ', language : "'.$tinyMCELang.'"').'
801 daniel-mar 1263
                                        '.($tinyMCELang == '' ? '' : ', language_url : "'.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'vendor/tweeb/tinymce-i18n/langs/'.$tinyMCELang.'.js"').'
635 daniel-mar 1264
                                });
1265
 
1266
                                pageChangeRequestCallbacks.push([OIDplusPagePublicObjects.cbQueryTinyMCE, "#'.$name.'"]);
1267
                                pageChangeCallbacks.push([OIDplusPagePublicObjects.cbRemoveTinyMCE, "#'.$name.'"]);
1268
                        </script>';
1269
 
1270
                $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?
1271
 
1272
                $out .= '<textarea name="'.htmlentities($name).'" id="'.htmlentities($name).'">'.trim($content).'</textarea><br>';
1273
 
1274
                return $out;
1275
        }
1276
 
1116 daniel-mar 1277
        /**
1131 daniel-mar 1278
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1
1116 daniel-mar 1279
         * @return bool
1280
         * @throws OIDplusException
1281
         */
635 daniel-mar 1282
        public function oobeRequested(): bool {
1283
                return OIDplus::config()->getValue('oobe_objects_done') == '0';
1284
        }
1285
 
1116 daniel-mar 1286
        /**
1131 daniel-mar 1287
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1
1125 daniel-mar 1288
         * @param int $step
1289
         * @param bool $do_edits
1290
         * @param bool $errors_happened
1116 daniel-mar 1291
         * @return void
1292
         */
1125 daniel-mar 1293
        public function oobeEntry(int $step, bool $do_edits, bool &$errors_happened)/*: void*/ {
1055 daniel-mar 1294
                echo '<h2>'._L('Step %1: Enable/Disable object type plugins',$step).'</h2>';
635 daniel-mar 1295
                echo '<p>'._L('Which object types do you want to manage using OIDplus?').'</p>';
1296
 
1297
                $enabled_ary = array();
1298
 
1299
                foreach (OIDplus::getEnabledObjectTypes() as $ot) {
1300
                        echo '<input type="checkbox" name="enable_ot_'.$ot::ns().'" id="enable_ot_'.$ot::ns().'"';
1033 daniel-mar 1301
                        if (isset($_POST['sent'])) {
1302
                                if (isset($_POST['enable_ot_'.$ot::ns()])) {
635 daniel-mar 1303
                                        echo ' checked';
1304
                                        $enabled_ary[] = $ot::ns();
1305
                                }
1306
                        } else {
1307
                                echo ' checked';
1308
                        }
1309
                        echo '> <label for="enable_ot_'.$ot::ns().'">'.htmlentities($ot::objectTypeTitle()).'</label><br>';
1310
                }
1311
 
1312
                foreach (OIDplus::getDisabledObjectTypes() as $ot) {
1313
                        echo '<input type="checkbox" name="enable_ot_'.$ot::ns().'" id="enable_ot_'.$ot::ns().'"';
1033 daniel-mar 1314
                        if (isset($_POST['sent'])) {
1315
                                if (isset($_POST['enable_ot_'.$ot::ns()])) {
635 daniel-mar 1316
                                        echo ' checked';
1317
                                        $enabled_ary[] = $ot::ns();
1318
                                }
1319
                        } else {
1320
                                echo ''; // <-- difference
1321
                        }
1322
                        echo '> <label for="enable_ot_'.$ot::ns().'">'.htmlentities($ot::objectTypeTitle()).'</label><br>';
1323
                }
1324
 
1201 daniel-mar 1325
                $htmlmsg = '';
635 daniel-mar 1326
                if ($do_edits) {
1327
                        try {
1328
                                OIDplus::config()->setValue('objecttypes_enabled', implode(';', $enabled_ary));
1329
                                OIDplus::config()->setValue('oobe_objects_done', '1');
1050 daniel-mar 1330
                        } catch (\Exception $e) {
1201 daniel-mar 1331
                                $htmlmsg = $e instanceof OIDplusException ? $e->getHtmlMessage() : htmlentities($e->getMessage());
635 daniel-mar 1332
                                $errors_happened = true;
1333
                        }
1334
                }
1335
 
1201 daniel-mar 1336
                echo ' <font color="red"><b>'.$htmlmsg.'</b></font>';
635 daniel-mar 1337
        }
1338
 
1116 daniel-mar 1339
        /**
1131 daniel-mar 1340
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8
1130 daniel-mar 1341
         * @param string|null $user
1116 daniel-mar 1342
         * @return array
1343
         * @throws OIDplusException
1344
         */
1130 daniel-mar 1345
        public function getNotifications(string $user=null): array {
1000 daniel-mar 1346
                $notifications = array();
1148 daniel-mar 1347
                $res = OIDplus::db()->query("select id, title from ###objects");
1156 daniel-mar 1348
                $res->naturalSortByField('id');
1000 daniel-mar 1349
                if ($res->any()) {
1350
                        $is_admin_logged_in = OIDplus::authUtils()->isAdminLoggedIn(); // run just once, for performance
1351
                        while ($row = $res->fetch_array()) {
1352
                                if (empty($row['title'])) {
1353
                                        if ($user === 'admin') {
1354
                                                $accept = $is_admin_logged_in;
1355
                                        } else {
1356
                                                $accept = false;
1357
                                                if ($obj = OIDplusObject::parse($row['id'])) {
1358
                                                        if ($obj->userHasWriteRights($user)) {
1359
                                                                $accept = true;
1360
                                                        }
1361
                                                }
1362
                                        }
1363
 
1364
                                        if ($accept) {
1202 daniel-mar 1365
                                                $notifications[] = new OIDplusNotification('WARN', _L('Object %1 has no title.', '<a '.OIDplus::gui()->link($row['id']).'>'.htmlentities($row['id']).'</a>'));
1000 daniel-mar 1366
                                        }
1367
                                }
1368
                        }
1369
                }
1370
                return $notifications;
1371
        }
1372
 
693 daniel-mar 1373
}