Subversion Repositories oidplus

Rev

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