Subversion Repositories oidplus

Rev

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