Subversion Repositories oidplus

Rev

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