Subversion Repositories oidplus

Rev

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

Rev Author Line No. Line
104 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
5
 * Copyright 2019 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
 
256 daniel-mar 20
class OIDplusPagePublicObjects extends OIDplusPagePluginPublic {
104 daniel-mar 21
 
320 daniel-mar 22
        private function ra_change_rec($id, $old_ra, $new_ra) {
23
                OIDplus::db()->query("update ###objects set ra_email = ?, updated = ".OIDplus::db()->sqlDate()." where id = ? and ifnull(ra_email,'') = ?", array($new_ra, $id, $old_ra));
24
 
25
                $res = OIDplus::db()->query("select id from ###objects where parent = ? and ifnull(ra_email,'') = ?", array($id, $old_ra));
26
                while ($row = $res->fetch_array()) {
27
                        $this->ra_change_rec($row['id'], $old_ra, $new_ra);
28
                }
29
        }
30
 
321 daniel-mar 31
        public function action($actionID, $params) {
256 daniel-mar 32
 
33
                // Action:     Delete
34
                // Method:     POST
35
                // Parameters: id
36
                // Outputs:    Text
321 daniel-mar 37
                if ($actionID == 'Delete') {
38
                        $id = $params['id'];
256 daniel-mar 39
                        $obj = OIDplusObject::parse($id);
360 daniel-mar 40
                        if ($obj === null) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','DELETE',$id));
256 daniel-mar 41
 
261 daniel-mar 42
                        if (OIDplus::db()->query("select id from ###objects where id = ?", array($id))->num_rows() == 0) {
360 daniel-mar 43
                                throw new OIDplusException(_L('Object %1 does not exist',$id));
256 daniel-mar 44
                        }
45
 
46
                        // Check if permitted
360 daniel-mar 47
                        if (!$obj->userHasParentalWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the superior RA to delete this OID.'));
256 daniel-mar 48
 
321 daniel-mar 49
                        foreach (OIDplus::getPagePlugins() as $plugin) {
50
                                if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.3')) {
51
                                        $plugin->beforeObjectDelete($id);
52
                                }
53
                        }
54
 
288 daniel-mar 55
                        OIDplus::logger()->log("[WARN]OID($id)+[?WARN/!OK]SUPOIDRA($id)?/[?INFO/!OK]A?", "Object '$id' (recursively) deleted");
56
                        OIDplus::logger()->log("[CRIT]OIDRA($id)!", "Lost ownership of object '$id' because it was deleted");
256 daniel-mar 57
 
58
                        if ($parentObj = $obj->getParent()) {
288 daniel-mar 59
                                $parent_oid = $parentObj->nodeId();
60
                                OIDplus::logger()->log("[WARN]OID($parent_oid)", "Object '$id' (recursively) deleted");
256 daniel-mar 61
                        }
62
 
63
                        // Delete object
261 daniel-mar 64
                        OIDplus::db()->query("delete from ###objects where id = ?", array($id));
256 daniel-mar 65
 
66
                        // Delete orphan stuff
67
                        foreach (OIDplus::getEnabledObjectTypes() as $ot) {
68
                                do {
261 daniel-mar 69
                                        $res = OIDplus::db()->query("select tchild.id from ###objects tchild " .
70
                                                                    "left join ###objects tparent on tparent.id = tchild.parent " .
256 daniel-mar 71
                                                                    "where tchild.parent <> ? and tchild.id like ? and tparent.id is null;", array($ot::root(), $ot::root().'%'));
72
                                        if ($res->num_rows() == 0) break;
73
 
74
                                        while ($row = $res->fetch_array()) {
75
                                                $id_to_delete = $row['id'];
288 daniel-mar 76
                                                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");
261 daniel-mar 77
                                                OIDplus::db()->query("delete from ###objects where id = ?", array($id_to_delete));
256 daniel-mar 78
                                        }
79
                                } while (true);
80
                        }
261 daniel-mar 81
                        OIDplus::db()->query("delete from ###asn1id where well_known = '0' and oid not in (select id from ###objects where id like 'oid:%')");
82
                        OIDplus::db()->query("delete from ###iri    where well_known = '0' and oid not in (select id from ###objects where id like 'oid:%')");
256 daniel-mar 83
 
321 daniel-mar 84
                        foreach (OIDplus::getPagePlugins() as $plugin) {
85
                                if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.3')) {
86
                                        $plugin->afterObjectDelete($id);
87
                                }
88
                        }
89
 
328 daniel-mar 90
                        return array("status" => 0);
256 daniel-mar 91
                }
92
 
93
                // Action:     Update
94
                // Method:     POST
95
                // Parameters: id, ra_email, comment, iris, asn1ids, confidential
96
                // Outputs:    Text
321 daniel-mar 97
                else if ($actionID == 'Update') {
98
                        $id = $params['id'];
256 daniel-mar 99
                        $obj = OIDplusObject::parse($id);
360 daniel-mar 100
                        if ($obj === null) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','UPDATE',$id));
256 daniel-mar 101
 
261 daniel-mar 102
                        if (OIDplus::db()->query("select id from ###objects where id = ?", array($id))->num_rows() == 0) {
360 daniel-mar 103
                                throw new OIDplusException(_L('Object %1 does not exist',$id));
256 daniel-mar 104
                        }
105
 
106
                        // Check if permitted
360 daniel-mar 107
                        if (!$obj->userHasParentalWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the superior RA to update this OID.'));
256 daniel-mar 108
 
321 daniel-mar 109
                        foreach (OIDplus::getPagePlugins() as $plugin) {
110
                                if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.3')) {
111
                                        $plugin->beforeObjectUpdateSuperior($id, $params);
112
                                }
113
                        }
114
 
256 daniel-mar 115
                        // Validate RA email address
321 daniel-mar 116
                        $new_ra = $params['ra_email'];
256 daniel-mar 117
                        if (!empty($new_ra) && !OIDplus::mailUtils()->validMailAddress($new_ra)) {
360 daniel-mar 118
                                throw new OIDplusException(_L('Invalid RA email address'));
256 daniel-mar 119
                        }
120
 
121
                        // First, do a simulation for ASN.1 IDs and IRIs to check if there are any problems (then an Exception will be thrown)
122
                        if ($obj::ns() == 'oid') {
321 daniel-mar 123
                                $ids = ($params['iris'] == '') ? array() : explode(',',$params['iris']);
256 daniel-mar 124
                                $ids = array_map('trim',$ids);
125
                                $obj->replaceIris($ids, true);
126
 
321 daniel-mar 127
                                $ids = ($params['asn1ids'] == '') ? array() : explode(',',$params['asn1ids']);
256 daniel-mar 128
                                $ids = array_map('trim',$ids);
129
                                $obj->replaceAsn1Ids($ids, true);
130
                        }
131
 
132
                        // Change RA recursively
261 daniel-mar 133
                        $res = OIDplus::db()->query("select ra_email from ###objects where id = ?", array($id));
256 daniel-mar 134
                        if ($row = $res->fetch_array()) {
135
                                $current_ra = $row['ra_email'];
136
                                if ($new_ra != $current_ra) {
288 daniel-mar 137
                                        OIDplus::logger()->log("[INFO]OID($id)+[?INFO/!OK]SUPOIDRA($id)?/[?INFO/!OK]A?", "RA of object '$id' changed from '$current_ra' to '$new_ra'");
138
                                        OIDplus::logger()->log("[WARN]RA($current_ra)!",           "Lost ownership of object '$id' due to RA transfer of superior RA / admin.");
139
                                        OIDplus::logger()->log("[INFO]RA($new_ra)!",               "Gained ownership of object '$id' due to RA transfer of superior RA / admin.");
256 daniel-mar 140
                                        if ($parentObj = $obj->getParent()) {
288 daniel-mar 141
                                                $parent_oid = $parentObj->nodeId();
142
                                                OIDplus::logger()->log("[INFO]OID($parent_oid)", "RA of object '$id' changed from '$current_ra' to '$new_ra'");
256 daniel-mar 143
                                        }
320 daniel-mar 144
                                        $this->ra_change_rec($id, $current_ra, $new_ra); // Inherited RAs rekursiv mitändern
256 daniel-mar 145
                                }
146
                        }
147
 
148
                        // Log if confidentially flag was changed
288 daniel-mar 149
                        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!
256 daniel-mar 150
                        if ($parentObj = $obj->getParent()) {
288 daniel-mar 151
                                $parent_oid = $parentObj->nodeId();
152
                                OIDplus::logger()->log("[INFO]OID($parent_oid)", "Identifiers/Confidential flag of object '$id' updated"); // TODO: Check if they were ACTUALLY updated!
256 daniel-mar 153
                        }
154
 
155
                        // Replace ASN.1 IDs und IRIs
156
                        if ($obj::ns() == 'oid') {
321 daniel-mar 157
                                $ids = ($params['iris'] == '') ? array() : explode(',',$params['iris']);
256 daniel-mar 158
                                $ids = array_map('trim',$ids);
159
                                $obj->replaceIris($ids, false);
160
 
321 daniel-mar 161
                                $ids = ($params['asn1ids'] == '') ? array() : explode(',',$params['asn1ids']);
256 daniel-mar 162
                                $ids = array_map('trim',$ids);
163
                                $obj->replaceAsn1Ids($ids, false);
164
 
165
                                // TODO: Check if any identifiers have been actually changed,
166
                                // and log it to OID($id), OID($parent), ... (see above)
167
                        }
168
 
321 daniel-mar 169
                        $confidential = $params['confidential'] == 'true';
170
                        $comment = $params['comment'];
264 daniel-mar 171
                        OIDplus::db()->query("UPDATE ###objects SET confidential = ?, comment = ?, updated = ".OIDplus::db()->sqlDate()." WHERE id = ?", array($confidential, $comment, $id));
256 daniel-mar 172
 
173
                        $status = 0;
174
 
175
                        if (!empty($new_ra)) {
261 daniel-mar 176
                                $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($new_ra));
380 daniel-mar 177
                                $invitePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.92'); // OIDplusPageRaInvite
178
                                if ($res->num_rows() == 0) $status = !is_null($invitePlugin) && OIDplus::config()->getValue('ra_invitation_enabled') ? 1 : 2;
256 daniel-mar 179
                        }
180
 
321 daniel-mar 181
                        foreach (OIDplus::getPagePlugins() as $plugin) {
182
                                if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.3')) {
183
                                        $plugin->afterObjectUpdateSuperior($id, $params);
184
                                }
185
                        }
186
 
328 daniel-mar 187
                        return array("status" => $status);
256 daniel-mar 188
                }
189
 
190
                // Action:     Update2
191
                // Method:     POST
192
                // Parameters: id, title, description
193
                // Outputs:    Text
321 daniel-mar 194
                else if ($actionID == 'Update2') {
195
                        $id = $params['id'];
256 daniel-mar 196
                        $obj = OIDplusObject::parse($id);
360 daniel-mar 197
                        if ($obj === null) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','UPDATE2',$id));
256 daniel-mar 198
 
261 daniel-mar 199
                        if (OIDplus::db()->query("select id from ###objects where id = ?", array($id))->num_rows() == 0) {
360 daniel-mar 200
                                throw new OIDplusException(_L('Object %1 does not exist',$id));
256 daniel-mar 201
                        }
202
 
203
                        // Check if allowed
360 daniel-mar 204
                        if (!$obj->userHasWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the RA to update this OID.'));
256 daniel-mar 205
 
321 daniel-mar 206
                        foreach (OIDplus::getPagePlugins() as $plugin) {
207
                                if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.3')) {
208
                                        $plugin->beforeObjectUpdateSelf($id, $params);
209
                                }
210
                        }
211
 
288 daniel-mar 212
                        OIDplus::logger()->log("[INFO]OID($id)+[?INFO/!OK]OIDRA($id)?/[?INFO/!OK]A?", "Title/Description of object '$id' updated");
256 daniel-mar 213
 
321 daniel-mar 214
                        OIDplus::db()->query("UPDATE ###objects SET title = ?, description = ?, updated = ".OIDplus::db()->sqlDate()." WHERE id = ?", array($params['title'], $params['description'], $id));
256 daniel-mar 215
 
321 daniel-mar 216
                        foreach (OIDplus::getPagePlugins() as $plugin) {
217
                                if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.3')) {
218
                                        $plugin->afterObjectUpdateSelf($id, $params);
219
                                }
220
                        }
221
 
328 daniel-mar 222
                        return array("status" => 0);
256 daniel-mar 223
                }
224
 
225
                // Action:     Insert
226
                // Method:     POST
227
                // Parameters: parent, id, ra_email, confidential, iris, asn1ids
228
                // Outputs:    Text
321 daniel-mar 229
                else if ($actionID == 'Insert') {
256 daniel-mar 230
                        // Validated are: ID, ra email, asn1 ids, iri ids
231
 
232
                        // Check if you have write rights on the parent (to create a new object)
321 daniel-mar 233
                        $objParent = OIDplusObject::parse($params['parent']);
360 daniel-mar 234
                        if ($objParent === null) throw new OIDplusException(_L('%1 action failed because parent object "%2" cannot be parsed!','INSERT',$params['parent']));
256 daniel-mar 235
 
261 daniel-mar 236
                        if (!$objParent::root() && (OIDplus::db()->query("select id from ###objects where id = ?", array($objParent->nodeId()))->num_rows() == 0)) {
360 daniel-mar 237
                                throw new OIDplusException(_L('Parent object %1 does not exist','".($objParent->nodeId())."'));
256 daniel-mar 238
                        }
239
 
360 daniel-mar 240
                        if (!$objParent->userHasWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the correct RA to insert an OID at this arc.'));
256 daniel-mar 241
 
242
                        // Check if the ID is valid
360 daniel-mar 243
                        if ($params['id'] == '') throw new OIDplusException(_L('ID may not be empty'));
256 daniel-mar 244
 
245
                        // Determine absolute OID name
246
                        // Note: At addString() and parse(), the syntax of the ID will be checked
321 daniel-mar 247
                        $id = $objParent->addString($params['id']);
256 daniel-mar 248
 
249
                        // Check, if the OID exists
261 daniel-mar 250
                        $test = OIDplus::db()->query("select id from ###objects where id = ?", array($id));
256 daniel-mar 251
                        if ($test->num_rows() >= 1) {
360 daniel-mar 252
                                throw new OIDplusException(_L('Object %1 already exists!',$id));
256 daniel-mar 253
                        }
254
 
255
                        $obj = OIDplusObject::parse($id);
360 daniel-mar 256
                        if ($obj === null) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','INSERT',$id));
256 daniel-mar 257
 
321 daniel-mar 258
                        foreach (OIDplus::getPagePlugins() as $plugin) {
259
                                if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.3')) {
260
                                        $plugin->beforeObjectInsert($id, $params);
261
                                }
262
                        }
263
 
256 daniel-mar 264
                        // First simulate if there are any problems of ASN.1 IDs und IRIs
265
                        if ($obj::ns() == 'oid') {
321 daniel-mar 266
                                $ids = ($params['iris'] == '') ? array() : explode(',',$params['iris']);
256 daniel-mar 267
                                $ids = array_map('trim',$ids);
268
                                $obj->replaceAsn1Ids($ids, true);
269
 
321 daniel-mar 270
                                $ids = ($params['asn1ids'] == '') ? array() : explode(',',$params['asn1ids']);
256 daniel-mar 271
                                $ids = array_map('trim',$ids);
272
                                $obj->replaceIris($ids, true);
273
                        }
274
 
275
                        // Apply superior RA change
321 daniel-mar 276
                        $parent = $params['parent'];
277
                        $ra_email = $params['ra_email'];
256 daniel-mar 278
                        if (!empty($ra_email) && !OIDplus::mailUtils()->validMailAddress($ra_email)) {
360 daniel-mar 279
                                throw new OIDplusException(_L('Invalid RA email address'));
256 daniel-mar 280
                        }
281
 
288 daniel-mar 282
                        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'";
256 daniel-mar 283
                        if (!empty($ra_email)) {
288 daniel-mar 284
                                OIDplus::logger()->log("[INFO]RA($ra_email)!", "Gained ownership of newly created object '$id'");
256 daniel-mar 285
                        }
286
 
321 daniel-mar 287
                        $confidential = $params['confidential'] == 'true';
288
                        $comment = $params['comment'];
256 daniel-mar 289
                        $title = '';
290
                        $description = '';
291
 
261 daniel-mar 292
                        if (strlen($id) > OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH')) {
360 daniel-mar 293
                                $maxlen = OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH');
294
                                throw new OIDplusException(_L('The identifier %1 is too long (max allowed length: %2)',$id,$maxlen));
256 daniel-mar 295
                        }
296
 
264 daniel-mar 297
                        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));
256 daniel-mar 298
 
299
                        // Set ASN.1 IDs und IRIs
300
                        if ($obj::ns() == 'oid') {
321 daniel-mar 301
                                $ids = ($params['iris'] == '') ? array() : explode(',',$params['iris']);
256 daniel-mar 302
                                $ids = array_map('trim',$ids);
303
                                $obj->replaceIris($ids, false);
304
 
321 daniel-mar 305
                                $ids = ($params['asn1ids'] == '') ? array() : explode(',',$params['asn1ids']);
256 daniel-mar 306
                                $ids = array_map('trim',$ids);
307
                                $obj->replaceAsn1Ids($ids, false);
308
                        }
309
 
310
                        $status = 0;
311
 
312
                        if (!empty($ra_email)) {
313
                                // Do we need to notify that the RA does not exist?
261 daniel-mar 314
                                $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($ra_email));
380 daniel-mar 315
                                $invitePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.92'); // OIDplusPageRaInvite
316
                                if ($res->num_rows() == 0) $status = !is_null($invitePlugin) && OIDplus::config()->getValue('ra_invitation_enabled') ? 1 : 2;
256 daniel-mar 317
                        }
318
 
321 daniel-mar 319
                        foreach (OIDplus::getPagePlugins() as $plugin) {
320
                                if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.3')) {
321
                                        $plugin->afterObjectInsert($id, $params);
322
                                }
323
                        }
324
 
328 daniel-mar 325
                        return array("status" => $status);
321 daniel-mar 326
                } else {
360 daniel-mar 327
                        throw new OIDplusException(_L('Unknown action ID'));
256 daniel-mar 328
                }
104 daniel-mar 329
        }
330
 
331
        public function init($html=true) {
362 daniel-mar 332
                OIDplus::config()->prepareConfigKey('oobe_objects_done', '"Out Of Box Experience" wizard for OIDplusPagePublicObjects done once?', '0', OIDplusConfig::PROTECTION_HIDDEN, function($value) {});
104 daniel-mar 333
        }
334
 
335
        public function gui($id, &$out, &$handled) {
336
                if ($id === 'oidplus:system') {
337
                        $handled = true;
338
 
321 daniel-mar 339
                        $out['title'] = OIDplus::config()->getValue('system_title');
241 daniel-mar 340
                        $out['icon'] = OIDplus::webpath(__DIR__).'system_big.png';
104 daniel-mar 341
 
360 daniel-mar 342
                        if (file_exists(OIDplus::basePath() . '/userdata/welcome/welcome$'.OIDplus::getCurrentLang().'.html')) {
386 daniel-mar 343
                                $cont = file_get_contents(OIDplus::basePath() . '/userdata/welcome/welcome$'.OIDplus::getCurrentLang().'.html');
360 daniel-mar 344
                        } else if (file_exists(OIDplus::basePath() . '/userdata/welcome/welcome.html')) {
386 daniel-mar 345
                                $cont = file_get_contents(OIDplus::basePath() . '/userdata/welcome/welcome.html');
360 daniel-mar 346
                        } else if (file_exists(__DIR__ . '/welcome$'.OIDplus::getCurrentLang().'.html')) {
386 daniel-mar 347
                                $cont = file_get_contents(__DIR__ . '/welcome$'.OIDplus::getCurrentLang().'.html');
256 daniel-mar 348
                        } else if (file_exists(__DIR__ . '/welcome.html')) {
386 daniel-mar 349
                                $cont = file_get_contents(__DIR__ . '/welcome.html');
256 daniel-mar 350
                        } else {
386 daniel-mar 351
                                $cont = '';
256 daniel-mar 352
                        }
386 daniel-mar 353
 
354
                        list($html, $js, $css) = extractHtmlContents($cont);
355
                        $cont = '';
356
                        if (!empty($js))  $cont .= "<script>\n$js\n</script>";
357
                        if (!empty($css)) $cont .= "<style>\n$css\n</style>";
358
                        $cont .= $html;
359
 
360
                        $out['text'] = $cont;
256 daniel-mar 361
 
104 daniel-mar 362
                        if (strpos($out['text'], '%%OBJECT_TYPE_LIST%%') !== false) {
363
                                $tmp = '<ul>';
227 daniel-mar 364
                                foreach (OIDplus::getEnabledObjectTypes() as $ot) {
250 daniel-mar 365
                                        $tmp .= '<li><a '.OIDplus::gui()->link($ot::root()).'>'.htmlentities($ot::objectTypeTitle()).'</a></li>';
104 daniel-mar 366
                                }
367
                                $tmp .= '</ul>';
368
                                $out['text'] = str_replace('%%OBJECT_TYPE_LIST%%', $tmp, $out['text']);
369
                        }
370
 
281 daniel-mar 371
                        return;
104 daniel-mar 372
                }
117 daniel-mar 373
 
256 daniel-mar 374
                try {
375
                        $obj = OIDplusObject::parse($id);
376
                } catch (Exception $e) {
377
                        $obj = null;
378
                }
379
 
380
                if (!is_null($obj)) {
381
                        $handled = true;
382
 
383
                        if (!$obj->userHasReadRights()) {
360 daniel-mar 384
                                $out['title'] = _L('Access denied');
256 daniel-mar 385
                                $out['icon'] = 'img/error_big.png';
360 daniel-mar 386
                                $out['text'] = '<p>'._L('Please <a %1>log in</a> to receive information about this object.',OIDplus::gui()->link('oidplus:login')).'</p>';
281 daniel-mar 387
                                return;
256 daniel-mar 388
                        }
389
 
390
                        $parent = null;
391
                        $res = null;
392
                        $row = null;
393
                        $matches_any_registered_type = false;
394
                        foreach (OIDplus::getEnabledObjectTypes() as $ot) {
395
                                if ($obj = $ot::parse($id)) {
396
                                        $matches_any_registered_type = true;
397
                                        if ($obj->isRoot()) {
398
                                                $obj->getContentPage($out['title'], $out['text'], $out['icon']);
399
                                                $parent = null; // $obj->getParent();
400
                                                break;
401
                                        } else {
261 daniel-mar 402
                                                $res = OIDplus::db()->query("select * from ###objects where id = ?", array($obj->nodeId()));
256 daniel-mar 403
                                                if ($res->num_rows() == 0) {
404
                                                        http_response_code(404);
360 daniel-mar 405
                                                        $out['title'] = _L('Object not found');
256 daniel-mar 406
                                                        $out['icon'] = 'img/error_big.png';
360 daniel-mar 407
                                                        $out['text'] = _L('The object %1 was not found in this database.','<code>'.htmlentities($id).'</code>');
281 daniel-mar 408
                                                        return;
256 daniel-mar 409
                                                } else {
410
                                                        $row = $res->fetch_array(); // will be used further down the code
411
                                                        $obj->getContentPage($out['title'], $out['text'], $out['icon']);
412
                                                        if (empty($out['title'])) $out['title'] = explode(':',$id,2)[1];
413
                                                        $parent = $obj->getParent();
414
                                                        break;
415
                                                }
416
                                        }
417
                                }
418
                        }
419
                        if (!$matches_any_registered_type) {
420
                                http_response_code(404);
360 daniel-mar 421
                                $out['title'] = _L('Object not found');
256 daniel-mar 422
                                $out['icon'] = 'img/error_big.png';
360 daniel-mar 423
                                $out['text'] = _L('The object %1 was not found in this database.','<code>'.htmlentities($id).'</code>');
281 daniel-mar 424
                                return;
256 daniel-mar 425
                        }
426
 
427
                        // ---
428
 
429
                        if ($parent) {
430
                                if ($parent->isRoot()) {
431
 
432
                                        $parent_link_text = $parent->objectTypeTitle();
366 daniel-mar 433
                                        $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'];
256 daniel-mar 434
 
435
                                } else {
261 daniel-mar 436
                                        $res_ = OIDplus::db()->query("select * from ###objects where id = ?", array($parent->nodeId()));
256 daniel-mar 437
                                        if ($res_->num_rows() > 0) {
438
                                                $row_ = $res_->fetch_array();
439
 
440
                                                $parent_title = $row_['title'];
441
                                                if (empty($parent_title) && ($parent->ns() == 'oid')) {
442
                                                        // If not title is available, then use an ASN.1 identifier
261 daniel-mar 443
                                                        $res_ = OIDplus::db()->query("select name from ###asn1id where oid = ?", array($parent->nodeId()));
256 daniel-mar 444
                                                        if ($res_->num_rows() > 0) {
445
                                                                $row_ = $res_->fetch_array();
446
                                                                $parent_title = $row_['name']; // TODO: multiple ASN1 ids?
447
                                                        }
448
                                                }
449
 
450
                                                $parent_link_text = empty($parent_title) ? explode(':',$parent->nodeId())[1] : $parent_title.' ('.explode(':',$parent->nodeId())[1].')';
451
 
366 daniel-mar 452
                                                $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'];
256 daniel-mar 453
                                        } else {
454
                                                $out['text'] = '';
455
                                        }
456
                                }
457
                        } else {
360 daniel-mar 458
                                $parent_link_text = _L('Go back to front page');
366 daniel-mar 459
                                $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'];
256 daniel-mar 460
                        }
461
 
462
                        // ---
463
 
464
                        if (!is_null($row) && isset($row['description'])) {
465
                                if (empty($row['description'])) {
466
                                        if (empty($row['title'])) {
360 daniel-mar 467
                                                $desc = '<p><i>'._L('No description for this object available').'</i></p>';
256 daniel-mar 468
                                        } else {
469
                                                $desc = $row['title'];
470
                                        }
471
                                } else {
472
                                        $desc = self::objDescription($row['description']);
473
                                }
474
 
475
                                if ($obj->userHasWriteRights()) {
476
                                        $rand = ++self::$crudCounter;
360 daniel-mar 477
                                        $desc = '<noscript><p><b>'._L('You need to enable JavaScript to edit title or description of this object.').'</b></p>'.$desc.'</noscript>';
256 daniel-mar 478
                                        $desc .= '<div class="container box" style="display:none" id="descbox_'.$rand.'">';
360 daniel-mar 479
                                        $desc .= _L('Title').': <input type="text" name="title" id="titleedit" value="'.htmlentities($row['title']).'"><br><br>'._L('Description').':<br>';
256 daniel-mar 480
                                        $desc .= self::showMCE('description', $row['description']);
360 daniel-mar 481
                                        $desc .= '<button type="button" name="update_desc" id="update_desc" class="btn btn-success btn-xs update" onclick="updateDesc()">'._L('Update description').'</button>';
256 daniel-mar 482
                                        $desc .= '</div>';
483
                                        $desc .= '<script>document.getElementById("descbox_'.$rand.'").style.display = "block";</script>';
484
                                }
485
                        } else {
486
                                $desc = '';
487
                        }
488
 
489
                        // ---
490
 
491
                        if (strpos($out['text'], '%%DESC%%') !== false)
492
                                $out['text'] = str_replace('%%DESC%%',    $desc,                              $out['text']);
493
                        if (strpos($out['text'], '%%CRUD%%') !== false)
494
                                $out['text'] = str_replace('%%CRUD%%',    self::showCrud($id),                $out['text']);
495
                        if (strpos($out['text'], '%%RA_INFO%%') !== false)
496
                                $out['text'] = str_replace('%%RA_INFO%%', OIDplusPagePublicRaInfo::showRaInfo($row['ra_email']), $out['text']);
497
 
498
                        $alt_ids = $obj->getAltIds();
499
                        if (count($alt_ids) > 0) {
360 daniel-mar 500
                                $out['text'] .= '<h2>'._L('Alternative Identifiers').'</h2>';
256 daniel-mar 501
                                foreach ($alt_ids as $alt_id) {
502
                                        $ns = $alt_id->getNamespace();
503
                                        $aid = $alt_id->getId();
504
                                        $aiddesc = $alt_id->getDescription();
505
                                        $out['text'] .= "$aiddesc <code>$ns:$aid</code><br>";
506
                                }
507
                        }
508
 
304 daniel-mar 509
                        foreach (OIDplus::getPagePlugins() as $plugin) {
510
                                if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.2')) {
511
                                        $plugin->modifyContent($id, $out['title'], $out['icon'], $out['text']);
512
                                }
513
                        }
256 daniel-mar 514
                }
104 daniel-mar 515
        }
516
 
282 daniel-mar 517
        private function publicSitemap_rec($json, &$out) {
518
                foreach ($json as $x) {
519
                        if (isset($x['id']) && $x['id']) {
360 daniel-mar 520
                                $out[] = $x['id'];
282 daniel-mar 521
                        }
522
                        if (isset($x['children'])) {
523
                                $this->publicSitemap_rec($x['children'], $out);
524
                        }
525
                }
526
        }
527
 
528
        public function publicSitemap(&$out) {
529
                $json = array();
530
                $this->tree($json, null/*RA EMail*/, false/*HTML tree algorithm*/, true/*display all*/);
531
                $this->publicSitemap_rec($json, $out);
532
        }
533
 
106 daniel-mar 534
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
104 daniel-mar 535
                if ($nonjs) {
360 daniel-mar 536
                        $json[] = array('id' => 'oidplus:system', 'icon' => OIDplus::webpath(__DIR__).'system.png', 'text' => _L('System'));
104 daniel-mar 537
 
538
                        $parent = '';
261 daniel-mar 539
                        $res = OIDplus::db()->query("select parent from ###objects where id = ?", array($req_goto));
236 daniel-mar 540
                        while ($row = $res->fetch_object()) {
104 daniel-mar 541
                                $parent = $row->parent;
542
                        }
543
 
544
                        $objTypesChildren = array();
227 daniel-mar 545
                        foreach (OIDplus::getEnabledObjectTypes() as $ot) {
104 daniel-mar 546
                                $icon = 'plugins/objectTypes/'.$ot::ns().'/img/treeicon_root.png';
547
                                $json[] = array('id' => $ot::root(), 'icon' => $icon, 'text' => $ot::objectTypeTitle());
548
 
549
                                try {
106 daniel-mar 550
                                        $tmp = OIDplusObject::parse($req_goto);
104 daniel-mar 551
                                } catch (Exception $e) {
552
                                        $tmp = null;
553
                                }
554
                                if (!is_null($tmp) && ($ot == get_class($tmp))) {
555
                                        // 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
556
                                        //       on the other hand, for giving search engines content, this is good enough
150 daniel-mar 557
                                        if (empty($parent)) {
261 daniel-mar 558
                                                $res = OIDplus::db()->query("select * from ###objects where " .
150 daniel-mar 559
                                                                                   "parent = ? or " .
560
                                                                                   "id = ? " .
561
                                                                                   "order by ".OIDplus::db()->natOrder('id'), array($req_goto, $req_goto));
562
                                        } else {
261 daniel-mar 563
                                                $res = OIDplus::db()->query("select * from ###objects where " .
150 daniel-mar 564
                                                                                   "parent = ? or " .
565
                                                                                   "id = ? or " .
566
                                                                                   "id = ? ".
567
                                                                                   "order by ".OIDplus::db()->natOrder('id'), array($req_goto, $req_goto, $parent));
568
                                        }
569
 
104 daniel-mar 570
                                        $z_used = 0;
571
                                        $y_used = 0;
572
                                        $x_used = 0;
573
                                        $stufe = 0;
574
                                        $menu_entries = array();
575
                                        $stufen = array();
236 daniel-mar 576
                                        while ($row = $res->fetch_object()) {
104 daniel-mar 577
                                                $obj = OIDplusObject::parse($row->id);
578
                                                if (is_null($obj)) continue; // might happen if the objectType is not available/loaded
579
                                                if (!$obj->userHasReadRights()) continue;
580
                                                $txt = $row->title == '' ? '' : ' -- '.htmlentities($row->title);
581
 
582
                                                if ($row->id == $parent) { $stufe=0; $z_used++; }
106 daniel-mar 583
                                                if ($row->id == $req_goto) { $stufe=1; $y_used++; }
584
                                                if ($row->parent == $req_goto) { $stufe=2; $x_used++; }
104 daniel-mar 585
 
586
                                                $menu_entry = array('id' => $row->id, 'icon' => '', 'text' => $txt, 'indent' => 0);
587
                                                $menu_entries[] = $menu_entry;
588
                                                $stufen[] = $stufe;
589
                                        }
590
                                        if ($x_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 2) $menu_entry['indent'] += 1;
591
                                        if ($y_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 1) $menu_entry['indent'] += 1;
592
                                        if ($z_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 0) $menu_entry['indent'] += 1;
593
                                        $json = array_merge($json, $menu_entries);
594
                                }
595
                        }
596
 
597
                        return true;
598
                } else {
281 daniel-mar 599
                        if ($req_goto === true) {
600
                                $goto_path = true; // display everything recursively
601
                        } else if (isset($req_goto)) {
145 daniel-mar 602
                                $goto = $req_goto;
603
                                $path = array();
604
                                while (true) {
605
                                        $path[] = $goto;
261 daniel-mar 606
                                        $res = OIDplus::db()->query("select parent from ###objects where id = ?", array($goto));
236 daniel-mar 607
                                        if ($res->num_rows() == 0) break;
608
                                        $row = $res->fetch_array();
145 daniel-mar 609
                                        $goto = $row['parent'];
150 daniel-mar 610
                                        if ($goto == '') continue;
145 daniel-mar 611
                                }
104 daniel-mar 612
 
145 daniel-mar 613
                                $goto_path = array_reverse($path);
104 daniel-mar 614
                        } else {
615
                                $goto_path = null;
616
                        }
617
 
618
                        $objTypesChildren = array();
227 daniel-mar 619
                        foreach (OIDplus::getEnabledObjectTypes() as $ot) {
145 daniel-mar 620
                                $child = array('id' => $ot::root(),
621
                                               'text' => $ot::objectTypeTitle(),
622
                                               'state' => array("opened" => true),
623
                                               'icon' => 'plugins/objectTypes/'.$ot::ns().'/img/treeicon_root.png',
250 daniel-mar 624
                                               'children' => OIDplus::menuUtils()->tree_populate($ot::root(), $goto_path)
145 daniel-mar 625
                                               );
104 daniel-mar 626
                                if (!file_exists($child['icon'])) $child['icon'] = null; // default icon (folder)
627
                                $objTypesChildren[] = $child;
628
                        }
629
 
630
                        $json[] = array(
631
                                'id' => "oidplus:system",
360 daniel-mar 632
                                'text' => _L('Objects'),
104 daniel-mar 633
                                'state' => array(
634
                                        "opened" => true,
635
                                        // "selected" => true)  // "selected" ist buggy: 1) Das select-Event wird beim Laden nicht gefeuert 2) Die direkt untergeordneten Knoten lassen sich nicht öffnen (laden für ewig)
636
                                ),
241 daniel-mar 637
                                'icon' => OIDplus::webpath(__DIR__).'system.png',
104 daniel-mar 638
                                'children' => $objTypesChildren
639
                        );
640
 
641
                        return true;
642
                }
643
        }
108 daniel-mar 644
 
645
        public function tree_search($request) {
646
                $ary = array();
647
                if ($obj = OIDplusObject::parse($request)) {
648
                        if ($obj->userHasReadRights()) {
649
                                do {
650
                                        $ary[] = $obj->nodeId();
651
                                } while ($obj = $obj->getParent());
652
                                $ary = array_reverse($ary);
653
                        }
654
                }
655
                return $ary;
656
        }
256 daniel-mar 657
 
658
        private static $crudCounter = 0;
659
 
660
        protected static function showCrud($parent='oid:') {
661
                $items_total = 0;
662
                $items_hidden = 0;
663
 
664
                $objParent = OIDplusObject::parse($parent);
665
                $parentNS = $objParent::ns();
666
 
667
                $result = OIDplus::db()->query("select o.*, r.ra_name " .
261 daniel-mar 668
                                               "from ###objects o " .
669
                                               "left join ###ra r on r.email = o.ra_email " .
256 daniel-mar 670
                                               "where parent = ? " .
671
                                               "order by ".OIDplus::db()->natOrder('id'), array($parent));
672
                $rows = array();
673
                if ($parentNS == 'oid') {
674
                        $one_weid_available = $objParent->isWeid(true);
675
                        while ($row = $result->fetch_object()) {
676
                                $obj = OIDplusObject::parse($row->id);
677
                                $rows[] = array($obj,$row);
678
                                if (!$one_weid_available) {
679
                                        if ($obj->isWeid(true)) $one_weid_available = true;
680
                                }
681
                        }
682
                } else {
683
                        $one_weid_available = false;
684
                        while ($row = $result->fetch_object()) {
685
                                $obj = OIDplusObject::parse($row->id);
686
                                $rows[] = array($obj,$row);
687
                        }
688
                }
689
 
690
                $output = '';
691
                $output .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
692
                $output .= '<table class="table table-bordered table-striped">';
693
                $output .= '    <tr>';
360 daniel-mar 694
                $output .= '         <th>'._L('ID').(($parentNS == 'gs1') ? ' '._L('(without check digit)') : '').'</th>';
256 daniel-mar 695
                if ($parentNS == 'oid') {
360 daniel-mar 696
                        if ($one_weid_available) $output .= '        <th>'._L('WEID').'</th>';
697
                        $output .= '         <th>'._L('ASN.1 IDs (comma sep.)').'</th>';
698
                        $output .= '         <th>'._L('IRI IDs (comma sep.)').'</th>';
256 daniel-mar 699
                }
360 daniel-mar 700
                $output .= '         <th>'._L('RA').'</th>';
701
                $output .= '         <th>'._L('Comment').'</th>';
256 daniel-mar 702
                if ($objParent->userHasWriteRights()) {
360 daniel-mar 703
                        $output .= '         <th>'._L('Hide').'</th>';
704
                        $output .= '         <th>'._L('Update').'</th>';
705
                        $output .= '         <th>'._L('Delete').'</th>';
256 daniel-mar 706
                }
360 daniel-mar 707
                $output .= '         <th>'._L('Created').'</th>';
708
                $output .= '         <th>'._L('Updated').'</th>';
256 daniel-mar 709
                $output .= '    </tr>';
710
 
711
                foreach ($rows as list($obj,$row)) {
712
                        $items_total++;
713
                        if (!$obj->userHasReadRights()) {
714
                                $items_hidden++;
715
                                continue;
716
                        }
717
 
718
                        $show_id = $obj->crudShowId($objParent);
719
 
720
                        $asn1ids = array();
261 daniel-mar 721
                        $res2 = OIDplus::db()->query("select name from ###asn1id where oid = ? order by lfd", array($row->id));
256 daniel-mar 722
                        while ($row2 = $res2->fetch_array()) {
723
                                $asn1ids[] = $row2['name'];
724
                        }
725
 
726
                        $iris = array();
261 daniel-mar 727
                        $res2 = OIDplus::db()->query("select name from ###iri where oid = ? order by lfd", array($row->id));
256 daniel-mar 728
                        while ($row2 = $res2->fetch_array()) {
729
                                $iris[] = $row2['name'];
730
                        }
731
 
732
                        $date_created = explode(' ', $row->created)[0] == '0000-00-00' ? '' : explode(' ', $row->created)[0];
733
                        $date_updated = explode(' ', $row->updated)[0] == '0000-00-00' ? '' : explode(' ', $row->updated)[0];
734
 
735
                        $output .= '<tr>';
736
                        $output .= '     <td><a href="?goto='.urlencode($row->id).'" onclick="openAndSelectNode('.js_escape($row->id).', '.js_escape($parent).'); return false;">'.htmlentities($show_id).'</a></td>';
737
                        if ($objParent->userHasWriteRights()) {
738
                                if ($parentNS == 'oid') {
739
                                        if ($one_weid_available) {
740
                                                if ($obj->isWeid(false)) {
741
                                                        $output .= '    <td>'.$obj->weidArc().'</td>';
742
                                                } else {
360 daniel-mar 743
                                                        $output .= '    <td>'._L('n/a').'</td>';
256 daniel-mar 744
                                                }
745
                                        }
746
                                        $output .= '     <td><input type="text" id="asn1ids_'.$row->id.'" value="'.implode(', ', $asn1ids).'"></td>';
747
                                        $output .= '     <td><input type="text" id="iris_'.$row->id.'" value="'.implode(', ', $iris).'"></td>';
748
                                }
749
                                $output .= '     <td><input type="text" id="ra_email_'.$row->id.'" value="'.htmlentities($row->ra_email).'"></td>';
750
                                $output .= '     <td><input type="text" id="comment_'.$row->id.'" value="'.htmlentities($row->comment).'"></td>';
751
                                $output .= '     <td><input type="checkbox" id="hide_'.$row->id.'" '.($row->confidential ? 'checked' : '').'></td>';
360 daniel-mar 752
                                $output .= '     <td><button type="button" name="update_'.$row->id.'" id="update_'.$row->id.'" class="btn btn-success btn-xs update" onclick="crudActionUpdate('.js_escape($row->id).', '.js_escape($parent).')">'._L('Update').'</button></td>';
753
                                $output .= '     <td><button type="button" name="delete_'.$row->id.'" id="delete_'.$row->id.'" class="btn btn-danger btn-xs delete" onclick="crudActionDelete('.js_escape($row->id).', '.js_escape($parent).')">'._L('Delete').'</button></td>';
256 daniel-mar 754
                                $output .= '     <td>'.$date_created.'</td>';
755
                                $output .= '     <td>'.$date_updated.'</td>';
756
                        } else {
360 daniel-mar 757
                                if ($asn1ids == '') $asn1ids = '<i>'._L('(none)').'</i>';
758
                                if ($iris == '') $iris = '<i>'._L('(none)').'</i>';
256 daniel-mar 759
                                if ($parentNS == 'oid') {
760
                                        if ($one_weid_available) {
761
                                                if ($obj->isWeid(false)) {
762
                                                        $output .= '    <td>'.$obj->weidArc().'</td>';
763
                                                } else {
360 daniel-mar 764
                                                        $output .= '    <td>'._L('n/a').'</td>';
256 daniel-mar 765
                                                }
766
                                        }
767
                                        $asn1ids_ext = array();
768
                                        foreach ($asn1ids as $asn1id) {
769
                                                $asn1ids_ext[] = '<a href="?goto='.urlencode($row->id).'" onclick="openAndSelectNode('.js_escape($row->id).', '.js_escape($parent).'); return false;">'.$asn1id.'</a>';
770
                                        }
771
                                        $output .= '     <td>'.implode(', ', $asn1ids_ext).'</td>';
772
                                        $output .= '     <td>'.implode(', ', $iris).'</td>';
773
                                }
774
                                $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>';
775
                                $output .= '     <td>'.htmlentities($row->comment).'</td>';
776
                                $output .= '     <td>'.$date_created.'</td>';
777
                                $output .= '     <td>'.$date_updated.'</td>';
778
                        }
779
                        $output .= '</tr>';
780
                }
781
 
261 daniel-mar 782
                $result = OIDplus::db()->query("select * from ###objects where id = ?", array($parent));
256 daniel-mar 783
                $parent_ra_email = $result->num_rows() > 0 ? $result->fetch_object()->ra_email : '';
784
 
785
                if ($objParent->userHasWriteRights()) {
786
                        $output .= '<tr>';
787
                        $prefix = is_null($objParent) ? '' : $objParent->crudInsertPrefix();
788
                        if ($parentNS == 'oid') {
789
                                if ($objParent->isWeid(true)) {
790
                                        $output .= '     <td>'.$prefix.' <input oninput="frdl_oidid_change()" type="text" id="id" value="" style="width:100%;min-width:100px"></td>'; // TODO: idee classname vergeben, z.B. "OID" und dann mit einem oid-spezifischen css die breite einstellbar machen, somit hat das plugin mehr kontrolle über das aussehen und die mindestbreiten
791
                                        $output .= '     <td><input type="text" name="weid" id="weid" value="" oninput="frdl_weid_change()"></td>';
792
                                } else {
793
                                        $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:50px"></td>'; // TODO: idee classname vergeben, z.B. "OID" und dann mit einem oid-spezifischen css die breite einstellbar machen, somit hat das plugin mehr kontrolle über das aussehen und die mindestbreiten
794
                                        if ($one_weid_available) $output .= '     <td></td>'; // WEID-editor not available for root nodes. Do it manually, please
795
                                }
796
                        } else {
797
                                $output .= '     <td>'.$prefix.' <input type="text" id="id" value=""></td>';
798
                        }
799
                        if ($parentNS == 'oid') $output .= '     <td><input type="text" id="asn1ids" value=""></td>';
800
                        if ($parentNS == 'oid') $output .= '     <td><input type="text" id="iris" value=""></td>';
801
                        $output .= '     <td><input type="text" id="ra_email" value="'.htmlentities($parent_ra_email).'"></td>';
802
                        $output .= '     <td><input type="text" id="comment" value=""></td>';
803
                        $output .= '     <td><input type="checkbox" id="hide"></td>';
360 daniel-mar 804
                        $output .= '     <td><button type="button" name="insert" id="insert" class="btn btn-success btn-xs update" onclick="crudActionInsert('.js_escape($parent).')">'._L('Insert').'</button></td>';
256 daniel-mar 805
                        $output .= '     <td></td>';
806
                        $output .= '     <td></td>';
807
                        $output .= '     <td></td>';
808
                        $output .= '</tr>';
809
                } else {
810
                        if ($items_total-$items_hidden == 0) {
811
                                $cols = ($parentNS == 'oid') ? 7 : 5;
812
                                if ($one_weid_available) $cols++;
360 daniel-mar 813
                                $output .= '<tr><td colspan="'.$cols.'">'._L('No items available').'</td></tr>';
256 daniel-mar 814
                        }
815
                }
816
 
817
                $output .= '</table>';
818
                $output .= '</div></div>';
819
 
820
                if ($items_hidden == 1) {
360 daniel-mar 821
                        $output .= '<p>'._L('One item is hidden. Please <a %1>log in</a> to see it.',$items_hidden,OIDplus::gui()->link('oidplus:login')).'</p>';
256 daniel-mar 822
                } else if ($items_hidden > 1) {
360 daniel-mar 823
                        $output .= '<p>'._L('%1 items are hidden. Please <a %2>log in</a> to see them.',$items_hidden,OIDplus::gui()->link('oidplus:login')).'</p>';
256 daniel-mar 824
                }
825
 
826
                return $output;
827
        }
828
 
829
        protected static function objDescription($html) {
830
                // We allow HTML, but no hacking
831
                $html = anti_xss($html);
832
 
833
                return trim_br($html);
834
        }
835
 
836
        // 'quickbars' added 11 July 2019: Disabled because of two problems:
837
        //                                 1. When you load TinyMCE via AJAX using the left menu, the quickbar is immediately shown, even if TinyMCE does not have the focus
838
        //                                 2. When you load a page without TinyMCE using the left menu, the quickbar is still visible, although there is no edit
839
        // 'colorpicker', 'textcolor' and 'contextmenu' added in 07 April 2020, because it is built in in the core.
840
        public static $exclude_tinymce_plugins = array('fullpage', 'bbcode', 'quickbars', 'colorpicker', 'textcolor', 'contextmenu');
841
 
842
        protected static function showMCE($name, $content) {
843
                $mce_plugins = array();
294 daniel-mar 844
                foreach (glob(OIDplus::basePath().'/3p/tinymce/plugins/*') as $m) { // */
256 daniel-mar 845
                        $mce_plugins[] = basename($m);
846
                }
847
 
848
                foreach (self::$exclude_tinymce_plugins as $exclude) {
849
                        $index = array_search($exclude, $mce_plugins);
850
                        if ($index !== false) unset($mce_plugins[$index]);
851
                }
852
 
853
                $out = '<script>
854
                                tinymce.remove("#'.$name.'");
855
                                tinymce.EditorManager.baseURL = "3p/tinymce";
856
                                tinymce.init({
857
                                        document_base_url: "'.OIDplus::getSystemUrl().'",
858
                                        selector: "#'.$name.'",
859
                                        height: 200,
860
                                        statusbar: false,
861
//                                      menubar:false,
862
//                                      toolbar: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table | fontsizeselect",
863
                                        toolbar: "undo redo | styleselect | bold italic underline forecolor | bullist numlist | outdent indent | table | fontsizeselect",
864
                                        plugins: "'.implode(' ', $mce_plugins).'",
865
                                        mobile: {
866
                                                theme: "mobile",
867
                                                toolbar: "undo redo | styleselect | bold italic underline forecolor | bullist numlist | outdent indent | table | fontsizeselect",
868
                                                plugins: "'.implode(' ', $mce_plugins).'"
869
                                        }
870
 
871
                                });
872
                        </script>';
873
 
874
                $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?
875
 
876
                $out .= '<textarea name="'.htmlentities($name).'" id="'.htmlentities($name).'">'.trim($content).'</textarea><br>';
877
 
878
                return $out;
879
        }
880
 
292 daniel-mar 881
        public function implementsFeature($id) {
362 daniel-mar 882
                if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.1') return true; // oobeEntry, oobeRequested()
292 daniel-mar 883
                return false;
884
        }
362 daniel-mar 885
 
886
        public function oobeRequested(): bool {
887
                // Interface 1.3.6.1.4.1.37476.2.5.2.3.1
292 daniel-mar 888
 
362 daniel-mar 889
                return OIDplus::config()->getValue('oobe_objects_done') == '0';
890
        }
891
 
292 daniel-mar 892
        public function oobeEntry($step, $do_edits, &$errors_happened)/*: void*/ {
893
                // Interface 1.3.6.1.4.1.37476.2.5.2.3.1
894
 
360 daniel-mar 895
                echo '<p><u>'._L('Step %1: Enable/Disable object type plugins',$step).'</u></p>';
896
                echo '<p>'._L('Which object types do you want to manage using OIDplus?').'</p>';
292 daniel-mar 897
 
898
                $enabled_ary = array();
899
 
900
                foreach (OIDplus::getEnabledObjectTypes() as $ot) {
901
                        echo '<input type="checkbox" name="enable_ot_'.$ot::ns().'" id="enable_ot_'.$ot::ns().'"';
902
                        if (isset($_REQUEST['sent'])) {
903
                                if (isset($_REQUEST['enable_ot_'.$ot::ns()])) {
904
                                        echo ' checked';
905
                                        $enabled_ary[] = $ot::ns();
906
                                }
907
                        } else {
908
                                echo ' checked';
909
                        }
910
                        echo '> <label for="enable_ot_'.$ot::ns().'">'.htmlentities($ot::objectTypeTitle()).'</label><br>';
911
                }
912
 
913
                foreach (OIDplus::getDisabledObjectTypes() as $ot) {
914
                        echo '<input type="checkbox" name="enable_ot_'.$ot::ns().'" id="enable_ot_'.$ot::ns().'"';
915
                        if (isset($_REQUEST['sent'])) {
916
                                if (isset($_REQUEST['enable_ot_'.$ot::ns()])) {
917
                                        echo ' checked';
918
                                        $enabled_ary[] = $ot::ns();
919
                                }
920
                        } else {
921
                                echo ''; // <-- difference
922
                        }
923
                        echo '> <label for="enable_ot_'.$ot::ns().'">'.htmlentities($ot::objectTypeTitle()).'</label><br>';
924
                }
925
 
926
                $msg = '';
927
                if ($do_edits) {
928
                        try {
929
                                OIDplus::config()->setValue('objecttypes_enabled', implode(';', $enabled_ary));
362 daniel-mar 930
                                OIDplus::config()->setValue('oobe_objects_done', '1');
292 daniel-mar 931
                        } catch (Exception $e) {
932
                                $msg = $e->getMessage();
933
                                $errors_happened = true;
934
                        }
935
                }
936
 
937
                echo ' <font color="red"><b>'.$msg.'</b></font>';
938
        }
939
 
361 daniel-mar 940
}