Subversion Repositories oidplus

Rev

Rev 1294 | Rev 1299 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1294 Rev 1295
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 * OIDplus 2.0
4
 * OIDplus 2.0
5
 * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
5
 * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
6
 *
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with 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
9
 * You may obtain a copy of the License at
10
 *
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
17
 * limitations under the License.
18
 */
18
 */
19
 
19
 
20
namespace ViaThinkSoft\OIDplus;
20
namespace ViaThinkSoft\OIDplus;
21
 
21
 
22
// phpcs:disable PSR1.Files.SideEffects
22
// phpcs:disable PSR1.Files.SideEffects
23
\defined('INSIDE_OIDPLUS') or die;
23
\defined('INSIDE_OIDPLUS') or die;
24
// phpcs:enable PSR1.Files.SideEffects
24
// phpcs:enable PSR1.Files.SideEffects
25
 
25
 
26
class OIDplusPagePublicObjects extends OIDplusPagePluginPublic
26
class OIDplusPagePublicObjects extends OIDplusPagePluginPublic
27
        implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1, /* oobeEntry, oobeRequested */
27
        implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1, /* oobeEntry, oobeRequested */
28
                   INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_2, /* modifyContent */
28
                   INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_2, /* modifyContent */
29
                   INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8, /* getNotifications */
29
                   INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8, /* getNotifications */
30
                   INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_9  /* restApi* */
30
                   INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_9  /* restApi* */
31
                   // Important: Do NOT implement INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7, because our getAlternativesForQuery() is the one that calls others!
31
                   // Important: Do NOT implement INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7, because our getAlternativesForQuery() is the one that calls others!
32
{
32
{
33
 
33
 
34
        /**
34
        /**
35
         * @param string|OIDplusObject $ot
35
         * @param string|OIDplusObject $ot
36
         * @return string|null
36
         * @return string|null
37
         */
37
         */
38
        private function get_treeicon_root($ot)/*: ?string*/ {
38
        private function get_treeicon_root($ot)/*: ?string*/ {
39
                $root = $ot::parse($ot::root());
39
                $root = $ot::parse($ot::root());
40
                if (!$root) return null;
40
                if (!$root) return null;
41
                return $root->getIcon();
41
                return $root->getIcon();
42
        }
42
        }
43
 
43
 
44
        /**
44
        /**
45
         * @param string $id
45
         * @param string $id
46
         * @param string $old_ra
46
         * @param string $old_ra
47
         * @param string $new_ra
47
         * @param string $new_ra
48
         * @return void
48
         * @return void
49
         * @throws OIDplusConfigInitializationException
49
         * @throws OIDplusConfigInitializationException
50
         * @throws OIDplusException
50
         * @throws OIDplusException
51
         */
51
         */
52
        private function ra_change_rec(string $id, string $old_ra, string $new_ra) {
52
        private function ra_change_rec(string $id, string $old_ra, string $new_ra) {
53
                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));
53
                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));
54
                OIDplusObject::resetObjectInformationCache();
54
                OIDplusObject::resetObjectInformationCache();
55
 
55
 
56
                $res = OIDplus::db()->query("select id from ###objects where parent = ? and ".OIDplus::db()->getSlang()->isNullFunction('ra_email',"''")." = ?", array($id, $old_ra));
56
                $res = OIDplus::db()->query("select id from ###objects where parent = ? and ".OIDplus::db()->getSlang()->isNullFunction('ra_email',"''")." = ?", array($id, $old_ra));
57
                while ($row = $res->fetch_array()) {
57
                while ($row = $res->fetch_array()) {
58
                        $this->ra_change_rec($row['id'], $old_ra, $new_ra);
58
                        $this->ra_change_rec($row['id'], $old_ra, $new_ra);
59
                }
59
                }
60
        }
60
        }
61
 
61
 
62
        /**
62
        /**
63
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_2
63
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_2
64
         * @param string $id
64
         * @param string $id
65
         * @param string $title
65
         * @param string $title
66
         * @param string $icon
66
         * @param string $icon
67
         * @param string $text
67
         * @param string $text
68
         * @return void
68
         * @return void
69
         * @throws \ViaThinkSoft\OIDplus\OIDplusException
69
         * @throws \ViaThinkSoft\OIDplus\OIDplusException
70
         */
70
         */
71
        public function modifyContent(string $id, string &$title, string &$icon, string &$text) {
71
        public function modifyContent(string $id, string &$title, string &$icon, string &$text) {
72
                $payload = '<br /> <a href="'.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE)
72
                $payload = '<br /> <a href="'.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE)
73
                        .'rest/v1/objects/'.htmlentities($id).'" class="gray_footer_font" target="_blank">'._L('REST API').'</a> '
73
                        .'rest/v1/objects/'.htmlentities($id).'" class="gray_footer_font" target="_blank">'._L('REST API').'</a> '
74
                        .'(<a '.OIDplus::gui()->link('oidplus:rest_api_information_admin$endpoints:1.3.6.1.4.1.37476.2.5.2.4.1.0').' class="gray_footer_font">'._L('Documentation').'</a>)';
74
                        .'(<a '.OIDplus::gui()->link('oidplus:rest_api_information_admin$endpoints:1.3.6.1.4.1.37476.2.5.2.4.1.0').' class="gray_footer_font">'._L('Documentation').'</a>)';
75
 
75
 
76
                $text = str_replace('<!-- MARKER 6 -->', '<!-- MARKER 6 -->'.$payload, $text);
76
                $text = str_replace('<!-- MARKER 6 -->', '<!-- MARKER 6 -->'.$payload, $text);
77
        }
77
        }
78
 
78
 
79
        /**
79
        /**
80
         * Implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_9
-
 
81
         * @param string $requestMethod
-
 
82
         * @param string $endpoint
80
         * @param string $endpoint
83
         * @param array $json_in
81
         * @param array $json_in
84
         * @return array|false
82
         * @return never-return
85
         */
83
         */
86
        public function restApiCall(string $requestMethod, string $endpoint, array $json_in) {
84
        private function restApiCall_OPTIONS(string $endpoint, array $json_in) {
87
                if (str_starts_with($endpoint, 'objects/')) {
-
 
88
                        $id = substr($endpoint, strlen('objects/'));
-
 
89
                        if ($requestMethod == "OPTIONS") {
-
 
90
                                header("access-control-allow-credentials: true");
85
                header("access-control-allow-credentials: true");
91
                                header("access-control-allow-headers: Keep-Alive,User-Agent,Authorization");
86
                header("access-control-allow-headers: Keep-Alive,User-Agent,Authorization");
92
                                header("access-control-allow-methods: GET, PUT, POST, DELETE, PATCH, OPTIONS");
87
                header("access-control-allow-methods: GET, PUT, POST, DELETE, PATCH, OPTIONS");
93
                                header("access-control-allow-origin: *");
88
                header("access-control-allow-origin: *");
94
                                http_response_code(204/*No content*/);
89
                http_response_code(204/*No content*/);
95
                                OIDplus::invoke_shutdown();
90
                OIDplus::invoke_shutdown();
96
                                die(); // return array();
91
                die(); // return array();
97
                        }
92
        }
-
 
93
 
-
 
94
        /**
-
 
95
         * @param string $endpoint
-
 
96
         * @param array $json_in
-
 
97
         * @return array
-
 
98
         */
-
 
99
        private function restApiCall_GET(string $endpoint, array $json_in): array {
98
                        else if ($requestMethod == "GET"/*Select*/) {
100
                $id = substr($endpoint, strlen('objects/'));
99
                                $obj = OIDplusObject::findFitting($id);
101
                $obj = OIDplusObject::findFitting($id);
100
                                if (!$obj) throw new OIDplusException(_L('The object %1 was not found in this database.', $id), null, 404);
102
                if (!$obj) throw new OIDplusException(_L('The object %1 was not found in this database.', $id), null, 404);
101
 
103
 
102
                                if (!$obj->userHasReadRights()) throw new OIDplusException('Insufficient authorization to read information about this object.', null, 401);
104
                if (!$obj->userHasReadRights()) throw new OIDplusException('Insufficient authorization to read information about this object.', null, 401);
103
 
105
 
104
                                $output = array();
106
                $output = array();
105
 
107
 
106
                                $output['status'] = 0/*OK*/;
108
                $output['status'] = 0/*OK*/;
107
                                $output['status_bits'] = [];
109
                $output['status_bits'] = [];
108
 
110
 
109
                                //$output['id'] = $obj->nodeId(true);
111
                //$output['id'] = $obj->nodeId(true);
110
                                $output['ra_email'] = $obj->getRaMail();
112
                $output['ra_email'] = $obj->getRaMail();
111
                                $output['comment'] = $obj->getComment();
113
                $output['comment'] = $obj->getComment();
112
                                $output['confidential'] = $obj->isConfidential();
114
                $output['confidential'] = $obj->isConfidential();
113
                                $output['title'] = $obj->getTitle();
115
                $output['title'] = $obj->getTitle();
114
                                $output['description'] = $obj->getDescription();
116
                $output['description'] = $obj->getDescription();
115
 
117
 
116
                                if ($obj instanceof OIDplusOid) {
118
                if ($obj instanceof OIDplusOid) {
117
                                        $output['asn1ids'] = array(); // TODO: Rename to oid-alphanum-id ?
119
                        $output['asn1ids'] = array(); // TODO: Rename to oid-alphanum-id ?
118
                                        foreach ($obj->getAsn1Ids() as $asn) {
120
                        foreach ($obj->getAsn1Ids() as $asn) {
119
                                                $output['asn1ids'][] = $asn->getName();
121
                                $output['asn1ids'][] = $asn->getName();
120
                                        }
122
                        }
121
 
123
 
122
                                        $output['iris'] = array(); // TODO: Rename to oid-unicode-label ?
124
                        $output['iris'] = array(); // TODO: Rename to oid-unicode-label ?
123
                                        foreach ($obj->getIris() as $iri) {
125
                        foreach ($obj->getIris() as $iri) {
124
                                                $output['iris'][] = $iri->getName();
126
                                $output['iris'][] = $iri->getName();
125
                                        }
127
                        }
126
                                }
128
                }
127
 
129
 
128
                                http_response_code(200);
130
                http_response_code(200);
129
                                return $output;
131
                return $output;
-
 
132
        }
-
 
133
 
-
 
134
        /**
-
 
135
         * @param string $endpoint
-
 
136
         * @param array $json_in
-
 
137
         * @return array
-
 
138
         */
-
 
139
        private function restApiCall_PUT(string $endpoint, array $json_in): array {
130
                        } else if ($requestMethod == "PUT"/*Replace*/) {
140
                $id = substr($endpoint, strlen('objects/'));
131
                                $obj = OIDplusObject::parse($id);
141
                $obj = OIDplusObject::parse($id);
132
                                if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!', 'PUT', $id), null, 400);
142
                if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!', 'PUT', $id), null, 400);
133
 
143
 
134
                                $params = array();
144
                $params = array();
135
                                $params['id'] = $id;
145
                $params['id'] = $id;
136
                                $params['ra_email'] = $json_in['ra_email'] ?? '';
146
                $params['ra_email'] = $json_in['ra_email'] ?? '';
137
                                $params['comment'] = $json_in['comment'] ?? '';
147
                $params['comment'] = $json_in['comment'] ?? '';
138
                                $params['confidential'] = $json_in['confidential'] ?? false;
148
                $params['confidential'] = $json_in['confidential'] ?? false;
139
                                $params['title'] = $json_in['title'] ?? '';
149
                $params['title'] = $json_in['title'] ?? '';
140
                                $params['description'] = $json_in['description'] ?? '';
150
                $params['description'] = $json_in['description'] ?? '';
141
                                $params['asn1ids'] = $json_in['asn1ids'] ?? array();
151
                $params['asn1ids'] = $json_in['asn1ids'] ?? array();
142
                                $params['iris'] = $json_in['iris'] ?? array();
152
                $params['iris'] = $json_in['iris'] ?? array();
143
 
153
 
144
                                if (OIDplusObject::exists($id)) {
154
                if (OIDplusObject::exists($id)) {
145
                                        // TODO: Problem: The superior RA cannot set title/description, so they cannot perform the PUT command!
155
                        // TODO: Problem: The superior RA cannot set title/description, so they cannot perform the PUT command!
146
                                        $output = self::action_Update($params);
156
                        $output = self::action_Update($params);
147
                                } else {
157
                } else {
148
                                        $params['parent'] = $obj->getParent();
158
                        $params['parent'] = $obj->getParent();
149
                                        $params['id_fully_qualified'] = true;
159
                        $params['id_fully_qualified'] = true;
150
                                        $output = self::action_Insert($params);
160
                        $output = self::action_Insert($params);
151
                                }
161
                }
152
 
162
 
153
                                $output['status_bits'] = [];
163
                $output['status_bits'] = [];
154
                                if (($output['status'] & 1) == 1) $output['status_bits'][1] = 'RA is not registered, but it can be invited';
164
                if (($output['status'] & 1) == 1) $output['status_bits'][1] = 'RA is not registered, but it can be invited';
155
                                if (($output['status'] & 2) == 2) $output['status_bits'][2] = 'RA is not registered and it cannot be invited';
165
                if (($output['status'] & 2) == 2) $output['status_bits'][2] = 'RA is not registered and it cannot be invited';
156
                                if (($output['status'] & 4) == 4) $output['status_bits'][4] = 'OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset';
166
                if (($output['status'] & 4) == 4) $output['status_bits'][4] = 'OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset';
157
                                if (($output['status'] & 8) == 8) $output['status_bits'][8] = 'User has write rights to the freshly created OID';
167
                if (($output['status'] & 8) == 8) $output['status_bits'][8] = 'User has write rights to the freshly created OID';
158
 
168
 
159
                                http_response_code(200);
169
                http_response_code(200);
160
                                return $output;
170
                return $output;
-
 
171
        }
-
 
172
 
-
 
173
        /**
161
                        } else if ($requestMethod == "POST"/*Insert*/) {
174
         * @param string $endpoint
162
                                $params = $json_in;
175
         * @param array $json_in
-
 
176
         * @return array
-
 
177
         */
-
 
178
        private function restApiCall_POST(string $endpoint, array $json_in): array {
-
 
179
                $id = substr($endpoint, strlen('objects/'));
163
                                $obj = OIDplusObject::parse($id);
180
                $obj = OIDplusObject::parse($id);
164
                                if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!', 'GET', $id), null, 400);
181
                if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!', 'GET', $id), null, 400);
-
 
182
                $params = $json_in;
165
                                $params['parent'] = $obj->getParent();
183
                $params['parent'] = $obj->getParent();
166
                                $params['id_fully_qualified'] = true;
184
                $params['id_fully_qualified'] = true;
167
                                $params['id'] = $id;
185
                $params['id'] = $id;
168
                                $output = self::action_Insert($params);
186
                $output = self::action_Insert($params);
169
 
187
 
170
                                $output['status_bits'] = [];
188
                $output['status_bits'] = [];
171
                                if (($output['status'] & 1) == 1) $output['status_bits'][1] = 'RA is not registered, but it can be invited';
189
                if (($output['status'] & 1) == 1) $output['status_bits'][1] = 'RA is not registered, but it can be invited';
172
                                if (($output['status'] & 2) == 2) $output['status_bits'][2] = 'RA is not registered and it cannot be invited';
190
                if (($output['status'] & 2) == 2) $output['status_bits'][2] = 'RA is not registered and it cannot be invited';
173
                                if (($output['status'] & 4) == 4) $output['status_bits'][4] = 'OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset';
191
                if (($output['status'] & 4) == 4) $output['status_bits'][4] = 'OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset';
174
                                if (($output['status'] & 8) == 8) $output['status_bits'][8] = 'User has write rights to the freshly created OID';
192
                if (($output['status'] & 8) == 8) $output['status_bits'][8] = 'User has write rights to the freshly created OID';
175
 
193
 
176
                                http_response_code(200);
194
                http_response_code(200);
177
                                return $output;
195
                return $output;
-
 
196
        }
-
 
197
 
-
 
198
        /**
-
 
199
         * @param string $endpoint
-
 
200
         * @param array $json_in
-
 
201
         * @return array
-
 
202
         */
-
 
203
        private function restApiCall_PATCH(string $endpoint, array $json_in): array {
178
                        } else if ($requestMethod == "PATCH"/*Modify*/) {
204
                $id = substr($endpoint, strlen('objects/'));
179
                                $params = $json_in;
205
                $params = $json_in;
180
                                $params['id'] = $id;
206
                $params['id'] = $id;
181
                                $output = self::action_Update($params);
207
                $output = self::action_Update($params);
182
 
208
 
183
                                $output['status_bits'] = [];
209
                $output['status_bits'] = [];
184
                                if (($output['status'] & 1) == 1) $output['status_bits'][1] = 'RA is not registered, but it can be invited';
210
                if (($output['status'] & 1) == 1) $output['status_bits'][1] = 'RA is not registered, but it can be invited';
185
                                if (($output['status'] & 2) == 2) $output['status_bits'][2] = 'RA is not registered and it cannot be invited';
211
                if (($output['status'] & 2) == 2) $output['status_bits'][2] = 'RA is not registered and it cannot be invited';
186
                                if (($output['status'] & 4) == 4) $output['status_bits'][4] = 'OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset';
212
                if (($output['status'] & 4) == 4) $output['status_bits'][4] = 'OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset';
187
                                if (($output['status'] & 8) == 8) $output['status_bits'][8] = 'User has write rights to the freshly created OID';
213
                if (($output['status'] & 8) == 8) $output['status_bits'][8] = 'User has write rights to the freshly created OID';
188
 
214
 
189
                                http_response_code(200);
215
                http_response_code(200);
190
                                return $output;
216
                return $output;
-
 
217
        }
-
 
218
 
-
 
219
        /**
-
 
220
         * @param string $endpoint
-
 
221
         * @param array $json_in
-
 
222
         * @return array
-
 
223
         */
-
 
224
        private function restApiCall_DELETE(string $endpoint, array $json_in): array {
191
                        } else if ($requestMethod == "DELETE"/*Delete*/) {
225
                $id = substr($endpoint, strlen('objects/'));
192
                                $params = $json_in;
226
                $params = $json_in;
193
                                $params['id'] = $id;
227
                $params['id'] = $id;
194
                                $output = self::action_Delete($params);
228
                $output = self::action_Delete($params);
195
 
229
 
196
                                $output['status_bits'] = [];
230
                $output['status_bits'] = [];
197
 
231
 
198
                                http_response_code(200);
232
                http_response_code(200);
199
                                return $output;
233
                return $output;
-
 
234
        }
-
 
235
 
-
 
236
        /**
-
 
237
         * Implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_9
-
 
238
         * @param string $requestMethod
-
 
239
         * @param string $endpoint
-
 
240
         * @param array $json_in
-
 
241
         * @return array|false
-
 
242
         */
-
 
243
        public function restApiCall(string $requestMethod, string $endpoint, array $json_in) {
-
 
244
                if (str_starts_with($endpoint, 'objects/')) {
-
 
245
                        if ($requestMethod == "OPTIONS") {
-
 
246
                                $this->restApiCall_OPTIONS($endpoint, $json_in);
-
 
247
                        }  else if ($requestMethod == "GET"/*Select*/) {
-
 
248
                                return $this->restApiCall_GET($endpoint, $json_in);
-
 
249
                        } else if ($requestMethod == "PUT"/*Replace*/) {
-
 
250
                                return $this->restApiCall_PUT($endpoint, $json_in);
-
 
251
                        } else if ($requestMethod == "POST"/*Insert*/) {
-
 
252
                                return $this->restApiCall_POST($endpoint, $json_in);
-
 
253
                        } else if ($requestMethod == "PATCH"/*Modify*/) {
-
 
254
                                return $this->restApiCall_PATCH($endpoint, $json_in);
-
 
255
                        } else if ($requestMethod == "DELETE"/*Delete*/) {
-
 
256
                                return $this->restApiCall_DELETE($endpoint, $json_in);
200
                        } else {
257
                        } else {
201
                                //throw new OIDplusException(_L("Not implemented"), null, 501);
258
                                //throw new OIDplusException(_L("Not implemented"), null, 501);
202
                                throw new OIDplusException(_L("Unsupported request method"), null, 400);
259
                                throw new OIDplusException(_L("Unsupported request method"), null, 400);
203
                        }
260
                        }
204
                } else {
261
                } else {
205
                        return false;
262
                        return false;
206
                }
263
                }
207
        }
264
        }
208
 
265
 
209
        /**
266
        /**
210
         * Implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_9
267
         * Implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_9
211
         * Outputs information about valid endpoints
268
         * Outputs information about valid endpoints
212
         * @param string $kind Reserved for different kind of output format (i.e. OpenAPI "TODO"). Currently only 'html' is implemented
269
         * @param string $kind Reserved for different kind of output format (i.e. OpenAPI "TODO"). Currently only 'html' is implemented
213
         * @return string
270
         * @return string
214
         */
271
         */
215
        public function restApiInfo(string $kind='html'): string {
272
        public function restApiInfo(string $kind='html'): string {
216
                if ($kind === 'html') {
273
                if ($kind === 'html') {
217
                        $struct = [
274
                        $struct = [
218
                                _L('Receive') => [
275
                                _L('Receive') => [
219
                                        '<b>GET</b> '.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'rest/v1/objects/<abbr title="'._L('e.g. %1', 'oid:2.999').'">[id]</abbr>',
276
                                        '<b>GET</b> '.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'rest/v1/objects/<abbr title="'._L('e.g. %1', 'oid:2.999').'">[id]</abbr>',
220
                                        _L('Input parameters') => [
277
                                        _L('Input parameters') => [
221
                                                '<i>'._L('None').'</i>'
278
                                                '<i>'._L('None').'</i>'
222
                                        ],
279
                                        ],
223
                                        _L('Output parameters') => [
280
                                        _L('Output parameters') => [
224
                                                'status ('._L('<0 is error, >=0 is success').')',
281
                                                'status ('._L('<0 is error, >=0 is success').')',
225
                                                'status_bits',
282
                                                'status_bits',
226
                                                'error ('._L('if an error occurred').')',
283
                                                'error ('._L('if an error occurred').')',
227
                                                'ra_email',
284
                                                'ra_email',
228
                                                'comment',
285
                                                'comment',
229
                                                'iris ('._L('for OID only').')',
286
                                                'iris ('._L('for OID only').')',
230
                                                'asn1ids ('._L('for OID only').')',
287
                                                'asn1ids ('._L('for OID only').')',
231
                                                'confidential',
288
                                                'confidential',
232
                                                'title',
289
                                                'title',
233
                                                'description'
290
                                                'description'
234
                                        ]
291
                                        ]
235
                                ],
292
                                ],
236
                                _L('Re-Create') => [
293
                                _L('Re-Create') => [
237
                                        '<b>PUT</b> '.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'rest/v1/objects/<abbr title="'._L('e.g. %1', 'oid:2.999').'">[id]</abbr>',
294
                                        '<b>PUT</b> '.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'rest/v1/objects/<abbr title="'._L('e.g. %1', 'oid:2.999').'">[id]</abbr>',
238
                                        _L('Input parameters') => [
295
                                        _L('Input parameters') => [
239
                                                'ra_email ('._L('optional').')',
296
                                                'ra_email ('._L('optional').')',
240
                                                'comment ('._L('optional').')',
297
                                                'comment ('._L('optional').')',
241
                                                'iris ('._L('optional').')',
298
                                                'iris ('._L('optional').')',
242
                                                'asn1ids ('._L('optional').')',
299
                                                'asn1ids ('._L('optional').')',
243
                                                'confidential ('._L('optional').')',
300
                                                'confidential ('._L('optional').')',
244
                                                'title ('._L('optional').')',
301
                                                'title ('._L('optional').')',
245
                                                'description ('._L('optional').')'
302
                                                'description ('._L('optional').')'
246
                                        ],
303
                                        ],
247
                                        _L('Output parameters') => [
304
                                        _L('Output parameters') => [
248
                                                'status ('._L('<0 is error, >=0 is success').')',
305
                                                'status ('._L('<0 is error, >=0 is success').')',
249
                                                'status_bits',
306
                                                'status_bits',
250
                                                'error ('._L('if an error occurred').')',
307
                                                'error ('._L('if an error occurred').')',
251
                                                'inserted_id ('._L('if it was created').')'
308
                                                'inserted_id ('._L('if it was created').')'
252
                                        ]
309
                                        ]
253
                                ],
310
                                ],
254
                                _L('Create') => [
311
                                _L('Create') => [
255
                                        '<b>POST</b> '.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'rest/v1/objects/<abbr title="'._L('e.g. %1', 'oid:2.999').'">[id]</abbr>',
312
                                        '<b>POST</b> '.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'rest/v1/objects/<abbr title="'._L('e.g. %1', 'oid:2.999').'">[id]</abbr>',
256
                                        _L('Input parameters') => [
313
                                        _L('Input parameters') => [
257
                                                'ra_email ('._L('optional').')',
314
                                                'ra_email ('._L('optional').')',
258
                                                'comment ('._L('optional').')',
315
                                                'comment ('._L('optional').')',
259
                                                'iris ('._L('optional').')',
316
                                                'iris ('._L('optional').')',
260
                                                'asn1ids ('._L('optional').')',
317
                                                'asn1ids ('._L('optional').')',
261
                                                'confidential ('._L('optional').')',
318
                                                'confidential ('._L('optional').')',
262
                                                'title ('._L('optional').')',
319
                                                'title ('._L('optional').')',
263
                                                'description ('._L('optional').')'
320
                                                'description ('._L('optional').')'
264
                                        ],
321
                                        ],
265
                                        _L('Output parameters') => [
322
                                        _L('Output parameters') => [
266
                                                'status ('._L('<0 is error, >=0 is success').')',
323
                                                'status ('._L('<0 is error, >=0 is success').')',
267
                                                'status_bits',
324
                                                'status_bits',
268
                                                'error ('._L('if an error occurred').')',
325
                                                'error ('._L('if an error occurred').')',
269
                                                'inserted_id'
326
                                                'inserted_id'
270
                                        ]
327
                                        ]
271
                                ],
328
                                ],
272
                                _L('Update') => [
329
                                _L('Update') => [
273
                                        '<b>PATCH</b> '.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'rest/v1/objects/<abbr title="'._L('e.g. %1', 'oid:2.999').'">[id]</abbr>',
330
                                        '<b>PATCH</b> '.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'rest/v1/objects/<abbr title="'._L('e.g. %1', 'oid:2.999').'">[id]</abbr>',
274
                                        _L('Input parameters') => [
331
                                        _L('Input parameters') => [
275
                                                'ra_email ('._L('optional').')',
332
                                                'ra_email ('._L('optional').')',
276
                                                'comment ('._L('optional').')',
333
                                                'comment ('._L('optional').')',
277
                                                'iris ('._L('optional').')',
334
                                                'iris ('._L('optional').')',
278
                                                'asn1ids ('._L('optional').')',
335
                                                'asn1ids ('._L('optional').')',
279
                                                'confidential ('._L('optional').')',
336
                                                'confidential ('._L('optional').')',
280
                                                'title ('._L('optional').')',
337
                                                'title ('._L('optional').')',
281
                                                'description ('._L('optional').')'
338
                                                'description ('._L('optional').')'
282
                                        ],
339
                                        ],
283
                                        _L('Output parameters') => [
340
                                        _L('Output parameters') => [
284
                                                'status ('._L('<0 is error, >=0 is success').')',
341
                                                'status ('._L('<0 is error, >=0 is success').')',
285
                                                'status_bits',
342
                                                'status_bits',
286
                                                'error ('._L('if an error occurred').')',
343
                                                'error ('._L('if an error occurred').')',
287
                                        ]
344
                                        ]
288
                                ],
345
                                ],
289
                                _L('Remove') => [
346
                                _L('Remove') => [
290
                                        '<b>DELETE</b> '.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'rest/v1/objects/<abbr title="'._L('e.g. %1', 'oid:2.999').'">[id]</abbr>',
347
                                        '<b>DELETE</b> '.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'rest/v1/objects/<abbr title="'._L('e.g. %1', 'oid:2.999').'">[id]</abbr>',
291
                                        _L('Input parameters') => [
348
                                        _L('Input parameters') => [
292
                                                '<i>'._L('None').'</i>'
349
                                                '<i>'._L('None').'</i>'
293
                                        ],
350
                                        ],
294
                                        _L('Output parameters') => [
351
                                        _L('Output parameters') => [
295
                                                'status ('._L('<0 is error, >=0 is success').')',
352
                                                'status ('._L('<0 is error, >=0 is success').')',
296
                                                'status_bits',
353
                                                'status_bits',
297
                                                'error ('._L('if an error occurred').')',
354
                                                'error ('._L('if an error occurred').')',
298
                                        ]
355
                                        ]
299
                                ]
356
                                ]
300
                        ];
357
                        ];
301
                        return array_to_html_ul_li($struct);
358
                        return array_to_html_ul_li($struct);
302
                } else {
359
                } else {
303
                        throw new OIDplusException(_L('Invalid REST API information format'), null, 500);
360
                        throw new OIDplusException(_L('Invalid REST API information format'), null, 500);
304
                }
361
                }
305
        }
362
        }
306
 
363
 
307
        /**
364
        /**
308
         * @param array $params id
365
         * @param array $params id
309
         * @return array status<0 Error, =0 Success
366
         * @return array status<0 Error, =0 Success
310
         * @throws OIDplusConfigInitializationException
367
         * @throws OIDplusConfigInitializationException
311
         * @throws OIDplusException
368
         * @throws OIDplusException
312
         */
369
         */
313
        private function action_Delete(array $params): array {
370
        private function action_Delete(array $params): array {
314
                _CheckParamExists($params, 'id');
371
                _CheckParamExists($params, 'id');
315
                $id = $params['id'];
372
                $id = $params['id'];
316
                $obj = OIDplusObject::parse($id);
373
                $obj = OIDplusObject::parse($id);
317
                if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','DELETE',$id));
374
                if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','DELETE',$id));
318
 
375
 
319
                if (!OIDplusObject::exists($id)) {
376
                if (!OIDplusObject::exists($id)) {
320
                        throw new OIDplusException(_L('Object %1 does not exist',$id), null, 404);
377
                        throw new OIDplusException(_L('Object %1 does not exist',$id), null, 404);
321
                }
378
                }
322
 
379
 
323
                // Check if permitted
380
                // Check if permitted
324
                if (!$obj->userHasParentalWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the superior RA to delete this OID.'), null, 401);
381
                if (!$obj->userHasParentalWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the superior RA to delete this OID.'), null, 401);
325
 
382
 
326
                foreach (OIDplus::getAllPlugins() as $plugin) {
383
                foreach (OIDplus::getAllPlugins() as $plugin) {
327
                        if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) {
384
                        if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) {
328
                                $plugin->beforeObjectDelete($id);
385
                                $plugin->beforeObjectDelete($id);
329
                        }
386
                        }
330
                }
387
                }
331
 
388
 
332
                OIDplus::logger()->log("V2:[WARN]OID(%1)+[OK/WARN]SUPOIDRA(%1)+[OK/INFO]A", "Object '%1' (recursively) deleted", $id);
389
                OIDplus::logger()->log("V2:[WARN]OID(%1)+[OK/WARN]SUPOIDRA(%1)+[OK/INFO]A", "Object '%1' (recursively) deleted", $id);
333
                OIDplus::logger()->log("V2:[CRIT]OIDRA(%1)", "Lost ownership of object '%1' because it was deleted", $id);
390
                OIDplus::logger()->log("V2:[CRIT]OIDRA(%1)", "Lost ownership of object '%1' because it was deleted", $id);
334
 
391
 
335
                if ($parentObj = $obj->getParent()) {
392
                if ($parentObj = $obj->getParent()) {
336
                        $parent_oid = $parentObj->nodeId();
393
                        $parent_oid = $parentObj->nodeId();
337
                        OIDplus::logger()->log("V2:[WARN]OID(%2)", "Object '%1' (recursively) deleted", $id, $parent_oid);
394
                        OIDplus::logger()->log("V2:[WARN]OID(%2)", "Object '%1' (recursively) deleted", $id, $parent_oid);
338
                }
395
                }
339
 
396
 
340
                // Delete object
397
                // Delete object
341
                OIDplus::db()->query("delete from ###objects where id = ?", array($id));
398
                OIDplus::db()->query("delete from ###objects where id = ?", array($id));
342
                OIDplusObject::resetObjectInformationCache();
399
                OIDplusObject::resetObjectInformationCache();
343
 
400
 
344
                // Delete orphan stuff
401
                // Delete orphan stuff
345
                foreach (OIDplus::getEnabledObjectTypes() as $ot) {
402
                foreach (OIDplus::getEnabledObjectTypes() as $ot) {
346
                        do {
403
                        do {
347
                                $res = OIDplus::db()->query("select tchild.id from ###objects tchild " .
404
                                $res = OIDplus::db()->query("select tchild.id from ###objects tchild " .
348
                                        "left join ###objects tparent on tparent.id = tchild.parent " .
405
                                        "left join ###objects tparent on tparent.id = tchild.parent " .
349
                                        "where tchild.parent <> ? and tchild.id like ? and tparent.id is null;", array($ot::root(), $ot::root().'%'));
406
                                        "where tchild.parent <> ? and tchild.id like ? and tparent.id is null;", array($ot::root(), $ot::root().'%'));
350
                                if (!$res->any()) break;
407
                                if (!$res->any()) break;
351
 
408
 
352
                                while ($row = $res->fetch_array()) {
409
                                while ($row = $res->fetch_array()) {
353
                                        $id_to_delete = $row['id'];
410
                                        $id_to_delete = $row['id'];
354
                                        OIDplus::logger()->log("V2:[CRIT]OIDRA(%2)", "Lost ownership of object '%2' because one of the superior objects ('%1') was recursively deleted", $id, $id_to_delete);
411
                                        OIDplus::logger()->log("V2:[CRIT]OIDRA(%2)", "Lost ownership of object '%2' because one of the superior objects ('%1') was recursively deleted", $id, $id_to_delete);
355
                                        OIDplus::db()->query("delete from ###objects where id = ?", array($id_to_delete));
412
                                        OIDplus::db()->query("delete from ###objects where id = ?", array($id_to_delete));
356
                                        OIDplusObject::resetObjectInformationCache();
413
                                        OIDplusObject::resetObjectInformationCache();
357
                                }
414
                                }
358
                        } while (true);
415
                        } while (true);
359
                }
416
                }
360
                OIDplus::db()->query("delete from ###asn1id where well_known = ? and oid not in (select id from ###objects where id like 'oid:%')", array(false));
417
                OIDplus::db()->query("delete from ###asn1id where well_known = ? and oid not in (select id from ###objects where id like 'oid:%')", array(false));
361
                OIDplus::db()->query("delete from ###iri    where well_known = ? and oid not in (select id from ###objects where id like 'oid:%')", array(false));
418
                OIDplus::db()->query("delete from ###iri    where well_known = ? and oid not in (select id from ###objects where id like 'oid:%')", array(false));
362
 
419
 
363
                foreach (OIDplus::getAllPlugins() as $plugin) {
420
                foreach (OIDplus::getAllPlugins() as $plugin) {
364
                        if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) {
421
                        if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) {
365
                                $plugin->afterObjectDelete($id);
422
                                $plugin->afterObjectDelete($id);
366
                        }
423
                        }
367
                }
424
                }
368
 
425
 
369
                return array("status" => 0);
426
                return array("status" => 0);
370
        }
427
        }
371
 
428
 
372
        /**
429
        /**
373
         * @param array $params id, ra_email, comment, iris, asn1ids, confidential, title, description
430
         * @param array $params id, ra_email, comment, iris, asn1ids, confidential, title, description
374
         * @return array status<0 Error, =0 Success, with the following bitfields for further information:
431
         * @return array status<0 Error, =0 Success, with the following bitfields for further information:
375
         *             x+1 = RA is not registered, but it can be invited
432
         *             x+1 = RA is not registered, but it can be invited
376
         *             x+2 = RA is not registered and it cannot be invited
433
         *             x+2 = RA is not registered and it cannot be invited
377
         *             x+4 = OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset
434
         *             x+4 = OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset
378
         *             x+8 = User has write rights to the freshly created OID
435
         *             x+8 = User has write rights to the freshly created OID
379
         * @throws OIDplusConfigInitializationException
436
         * @throws OIDplusConfigInitializationException
380
         * @throws OIDplusException
437
         * @throws OIDplusException
381
         */
438
         */
382
        private function action_Update(array $params): array {
439
        private function action_Update(array $params): array {
383
                _CheckParamExists($params, 'id');
440
                _CheckParamExists($params, 'id');
384
                $id = $params['id'];
441
                $id = $params['id'];
385
                $obj = OIDplusObject::parse($id);
442
                $obj = OIDplusObject::parse($id);
386
                if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','UPDATE',$id));
443
                if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','UPDATE',$id));
387
 
444
 
388
                if (!OIDplusObject::exists($id)) {
445
                if (!OIDplusObject::exists($id)) {
389
                        throw new OIDplusException(_L('Object %1 does not exist',$id), null, 404);
446
                        throw new OIDplusException(_L('Object %1 does not exist',$id), null, 404);
390
                }
447
                }
391
 
448
 
392
                // Check if permitted
449
                // Check if permitted
393
                if (isset($params['title']) || isset($params['description'])) {
450
                if (isset($params['title']) || isset($params['description'])) {
394
                        if (!$obj->userHasWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the RA to update this OID.'), null, 401);
451
                        if (!$obj->userHasWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the RA to update this OID.'), null, 401);
395
                }
452
                }
396
                if (isset($params['ra_email']) || isset($params['comment']) || isset($params['iris']) || isset($params['asn1ids']) || isset($params['confidential'])) {
453
                if (isset($params['ra_email']) || isset($params['comment']) || isset($params['iris']) || isset($params['asn1ids']) || isset($params['confidential'])) {
397
                        if (!$obj->userHasParentalWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the superior RA to update this OID.'), null, 401);
454
                        if (!$obj->userHasParentalWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the superior RA to update this OID.'), null, 401);
398
                }
455
                }
399
 
456
 
400
                foreach (OIDplus::getAllPlugins() as $plugin) {
457
                foreach (OIDplus::getAllPlugins() as $plugin) {
401
                        if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) {
458
                        if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) {
402
                                $plugin->beforeObjectUpdateSuperior($id, $params);
459
                                $plugin->beforeObjectUpdateSuperior($id, $params);
403
                        }
460
                        }
404
                }
461
                }
405
 
462
 
406
                // First, do a simulation for ASN.1 IDs and IRIs to check if there are any problems (then an Exception will be thrown)
463
                // First, do a simulation for ASN.1 IDs and IRIs to check if there are any problems (then an Exception will be thrown)
407
                if ($obj::ns() == 'oid') {
464
                if ($obj::ns() == 'oid') {
408
                        assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
465
                        assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
409
                        if (!$obj->isWellKnown()) {
466
                        if (!$obj->isWellKnown()) {
410
                                if (isset($params['iris'])) {
467
                                if (isset($params['iris'])) {
411
                                        $ids = ($params['iris'] == '') ? array() : (is_array($params['iris']) ? $params['iris'] : explode(',',$params['iris']));
468
                                        $ids = ($params['iris'] == '') ? array() : (is_array($params['iris']) ? $params['iris'] : explode(',',$params['iris']));
412
                                        $ids = array_map('trim',$ids);
469
                                        $ids = array_map('trim',$ids);
413
                                        $obj->replaceIris($ids, true);
470
                                        $obj->replaceIris($ids, true);
414
                                }
471
                                }
415
 
472
 
416
                                if (isset($params['asn1ids'])) {
473
                                if (isset($params['asn1ids'])) {
417
                                        $ids = ($params['asn1ids'] == '') ? array() : (is_array($params['asn1ids']) ? $params['asn1ids'] : explode(',',$params['asn1ids']));
474
                                        $ids = ($params['asn1ids'] == '') ? array() : (is_array($params['asn1ids']) ? $params['asn1ids'] : explode(',',$params['asn1ids']));
418
                                        $ids = array_map('trim',$ids);
475
                                        $ids = array_map('trim',$ids);
419
                                        $obj->replaceAsn1Ids($ids, true);
476
                                        $obj->replaceAsn1Ids($ids, true);
420
                                }
477
                                }
421
                        }
478
                        }
422
                }
479
                }
423
 
480
 
424
                // RA E-Mail change
481
                // RA E-Mail change
425
                if (isset($params['ra_email'])) {
482
                if (isset($params['ra_email'])) {
426
                        // Validate RA email address
483
                        // Validate RA email address
427
                        $new_ra = $params['ra_email'] ?? '';
484
                        $new_ra = $params['ra_email'] ?? '';
428
                        if ($obj::ns() == 'oid') {
485
                        if ($obj::ns() == 'oid') {
429
                                assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
486
                                assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
430
                                if ($obj->isWellKnown()) {
487
                                if ($obj->isWellKnown()) {
431
                                        $new_ra = '';
488
                                        $new_ra = '';
432
                                }
489
                                }
433
                        }
490
                        }
434
                        if (!empty($new_ra) && !OIDplus::mailUtils()->validMailAddress($new_ra)) {
491
                        if (!empty($new_ra) && !OIDplus::mailUtils()->validMailAddress($new_ra)) {
435
                                throw new OIDplusException(_L('Invalid RA email address'));
492
                                throw new OIDplusException(_L('Invalid RA email address'));
436
                        }
493
                        }
437
 
494
 
438
                        // Change RA recursively
495
                        // Change RA recursively
439
                        $current_ra = $obj->getRaMail() ?? '';
496
                        $current_ra = $obj->getRaMail() ?? '';
440
                        if ($new_ra != $current_ra) {
497
                        if ($new_ra != $current_ra) {
441
                                OIDplus::logger()->log("V2:[INFO]OID(%1)+[OK/INFO]SUPOIDRA(%1)+[OK/INFO]A", "RA of object '%1' changed from '%2' to '%3'", $id, $current_ra, $new_ra);
498
                                OIDplus::logger()->log("V2:[INFO]OID(%1)+[OK/INFO]SUPOIDRA(%1)+[OK/INFO]A", "RA of object '%1' changed from '%2' to '%3'", $id, $current_ra, $new_ra);
442
                                if (!empty($current_ra)) OIDplus::logger()->log("V2:[WARN]RA(%2)", "Lost ownership of object '%1' due to RA transfer of superior RA / admin.", $id, $current_ra, $new_ra);
499
                                if (!empty($current_ra)) OIDplus::logger()->log("V2:[WARN]RA(%2)", "Lost ownership of object '%1' due to RA transfer of superior RA / admin.", $id, $current_ra, $new_ra);
443
                                if (!empty($new_ra)) OIDplus::logger()->log("V2:[INFO]RA(%3)", "Gained ownership of object '%1' due to RA transfer of superior RA / admin.", $id, $current_ra, $new_ra);
500
                                if (!empty($new_ra)) OIDplus::logger()->log("V2:[INFO]RA(%3)", "Gained ownership of object '%1' due to RA transfer of superior RA / admin.", $id, $current_ra, $new_ra);
444
                                if ($parentObj = $obj->getParent()) {
501
                                if ($parentObj = $obj->getParent()) {
445
                                        $parent_oid = $parentObj->nodeId();
502
                                        $parent_oid = $parentObj->nodeId();
446
                                        OIDplus::logger()->log("V2:[INFO]OID(%4)", "RA of object '%1' changed from '%2' to '%3'", $id, $current_ra, $new_ra, $parent_oid);
503
                                        OIDplus::logger()->log("V2:[INFO]OID(%4)", "RA of object '%1' changed from '%2' to '%3'", $id, $current_ra, $new_ra, $parent_oid);
447
                                }
504
                                }
448
                                $this->ra_change_rec($id, $current_ra, $new_ra); // Recursively change inherited RAs
505
                                $this->ra_change_rec($id, $current_ra, $new_ra); // Recursively change inherited RAs
449
                        }
506
                        }
450
                }
507
                }
451
 
508
 
452
                // Log if confidentially flag was changed
509
                // Log if confidentially flag was changed
453
                OIDplus::logger()->log("V2:[INFO]OID(%1)+[OK/INFO]SUPOIDRA(%1)+[OK/INFO]A", "Identifiers/Confidential flag of object '%1' updated", $id); // TODO: Check if they were ACTUALLY updated!
510
                OIDplus::logger()->log("V2:[INFO]OID(%1)+[OK/INFO]SUPOIDRA(%1)+[OK/INFO]A", "Identifiers/Confidential flag of object '%1' updated", $id); // TODO: Check if they were ACTUALLY updated!
454
                if ($parentObj = $obj->getParent()) {
511
                if ($parentObj = $obj->getParent()) {
455
                        $parent_oid = $parentObj->nodeId();
512
                        $parent_oid = $parentObj->nodeId();
456
                        OIDplus::logger()->log("V2:[INFO]OID(%2)", "Identifiers/Confidential flag of object '%1' updated", $id, $parent_oid); // TODO: Check if they were ACTUALLY updated!
513
                        OIDplus::logger()->log("V2:[INFO]OID(%2)", "Identifiers/Confidential flag of object '%1' updated", $id, $parent_oid); // TODO: Check if they were ACTUALLY updated!
457
                }
514
                }
458
 
515
 
459
                // Replace ASN.1 IDs und IRIs
516
                // Replace ASN.1 IDs und IRIs
460
                if ($obj::ns() == 'oid') {
517
                if ($obj::ns() == 'oid') {
461
                        assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
518
                        assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
462
                        if (!$obj->isWellKnown()) {
519
                        if (!$obj->isWellKnown()) {
463
                                if (isset($params['iris'])) {
520
                                if (isset($params['iris'])) {
464
                                        $ids = ($params['iris'] == '') ? array() : (is_array($params['iris']) ? $params['iris'] : explode(',',$params['iris']));
521
                                        $ids = ($params['iris'] == '') ? array() : (is_array($params['iris']) ? $params['iris'] : explode(',',$params['iris']));
465
                                        $ids = array_map('trim',$ids);
522
                                        $ids = array_map('trim',$ids);
466
                                        $obj->replaceIris($ids, false);
523
                                        $obj->replaceIris($ids, false);
467
                                }
524
                                }
468
 
525
 
469
                                if (isset($params['asn1ids'])) {
526
                                if (isset($params['asn1ids'])) {
470
                                        $ids = ($params['asn1ids'] == '') ? array() : (is_array($params['asn1ids']) ? $params['asn1ids'] : explode(',',$params['asn1ids']));
527
                                        $ids = ($params['asn1ids'] == '') ? array() : (is_array($params['asn1ids']) ? $params['asn1ids'] : explode(',',$params['asn1ids']));
471
                                        $ids = array_map('trim',$ids);
528
                                        $ids = array_map('trim',$ids);
472
                                        $obj->replaceAsn1Ids($ids, false);
529
                                        $obj->replaceAsn1Ids($ids, false);
473
                                }
530
                                }
474
                        }
531
                        }
475
 
532
 
476
                        // TODO: Check if any identifiers have been actually changed,
533
                        // TODO: Check if any identifiers have been actually changed,
477
                        // and log it to OID($id), OID($parent), ... (see above)
534
                        // and log it to OID($id), OID($parent), ... (see above)
478
                }
535
                }
479
 
536
 
480
                if (isset($params['confidential'])) {
537
                if (isset($params['confidential'])) {
481
                        $confidential = oidplus_is_true($params['confidential']);
538
                        $confidential = oidplus_is_true($params['confidential']);
482
                        OIDplus::db()->query("UPDATE ###objects SET confidential = ? WHERE id = ?", array($confidential, $id));
539
                        OIDplus::db()->query("UPDATE ###objects SET confidential = ? WHERE id = ?", array($confidential, $id));
483
                        OIDplusObject::resetObjectInformationCache();
540
                        OIDplusObject::resetObjectInformationCache();
484
                }
541
                }
485
 
542
 
486
                if (isset($params['comment'])) {
543
                if (isset($params['comment'])) {
487
                        $comment = $params['comment'];
544
                        $comment = $params['comment'];
488
                        OIDplus::db()->query("UPDATE ###objects SET comment = ? WHERE id = ?", array($comment, $id));
545
                        OIDplus::db()->query("UPDATE ###objects SET comment = ? WHERE id = ?", array($comment, $id));
489
                        OIDplusObject::resetObjectInformationCache();
546
                        OIDplusObject::resetObjectInformationCache();
490
                }
547
                }
491
 
548
 
492
                if (isset($params['title']) || isset($params['description'])) {
549
                if (isset($params['title']) || isset($params['description'])) {
493
                        OIDplus::logger()->log("V2:[INFO]OID(%1)+[OK/INFO]OIDRA(%1)+[OK/INFO]A", "Title/Description of object '%1' updated", $id);
550
                        OIDplus::logger()->log("V2:[INFO]OID(%1)+[OK/INFO]OIDRA(%1)+[OK/INFO]A", "Title/Description of object '%1' updated", $id);
494
                }
551
                }
495
 
552
 
496
                if (isset($params['title'])) {
553
                if (isset($params['title'])) {
497
                        $title = $params['title'];
554
                        $title = $params['title'];
498
                        OIDplus::db()->query("UPDATE ###objects SET title = ? WHERE id = ?", array($title, $id));
555
                        OIDplus::db()->query("UPDATE ###objects SET title = ? WHERE id = ?", array($title, $id));
499
                        OIDplusObject::resetObjectInformationCache();
556
                        OIDplusObject::resetObjectInformationCache();
500
                }
557
                }
501
 
558
 
502
                if (isset($params['description'])) {
559
                if (isset($params['description'])) {
503
                        $description = $params['description'];
560
                        $description = $params['description'];
504
                        OIDplus::db()->query("UPDATE ###objects SET description = ? WHERE id = ?", array($description, $id));
561
                        OIDplus::db()->query("UPDATE ###objects SET description = ? WHERE id = ?", array($description, $id));
505
                        OIDplusObject::resetObjectInformationCache();
562
                        OIDplusObject::resetObjectInformationCache();
506
                }
563
                }
507
 
564
 
508
                OIDplus::db()->query("UPDATE ###objects SET updated = ".OIDplus::db()->sqlDate()." WHERE id = ?", array($id));
565
                OIDplus::db()->query("UPDATE ###objects SET updated = ".OIDplus::db()->sqlDate()." WHERE id = ?", array($id));
509
                OIDplusObject::resetObjectInformationCache();
566
                OIDplusObject::resetObjectInformationCache();
510
 
567
 
511
                $status = 0;
568
                $status = 0;
512
 
569
 
513
                if (!empty($new_ra)) {
570
                if (!empty($new_ra)) {
514
                        $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($new_ra));
571
                        $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($new_ra));
515
                        $invitePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.92'); // OIDplusPageRaInvite
572
                        $invitePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.92'); // OIDplusPageRaInvite
516
                        if (!$res->any()) $status = !is_null($invitePlugin) && OIDplus::config()->getValue('ra_invitation_enabled') ? 1 : 2;
573
                        if (!$res->any()) $status = !is_null($invitePlugin) && OIDplus::config()->getValue('ra_invitation_enabled') ? 1 : 2;
517
                }
574
                }
518
 
575
 
519
                if ($obj::ns() == 'oid') {
576
                if ($obj::ns() == 'oid') {
520
                        assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
577
                        assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
521
                        if ($obj->isWellKnown()) {
578
                        if ($obj->isWellKnown()) {
522
                                $status += 4;
579
                                $status += 4;
523
                        }
580
                        }
524
                }
581
                }
525
 
582
 
526
                if ($obj->userHasWriteRights()) {
583
                if ($obj->userHasWriteRights()) {
527
                        $status += 8;
584
                        $status += 8;
528
                }
585
                }
529
 
586
 
530
                foreach (OIDplus::getAllPlugins() as $plugin) {
587
                foreach (OIDplus::getAllPlugins() as $plugin) {
531
                        if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) {
588
                        if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) {
532
                                $plugin->afterObjectUpdateSuperior($id, $params);
589
                                $plugin->afterObjectUpdateSuperior($id, $params);
533
                        }
590
                        }
534
                }
591
                }
535
 
592
 
536
                return array("status" => $status);
593
                return array("status" => $status);
537
        }
594
        }
538
 
595
 
539
        /**
596
        /**
540
         * @param array $params parent, id (relative!), ra_email, comment, iris, asn1ids, confidential, title, description
597
         * @param array $params parent, id (relative!), ra_email, comment, iris, asn1ids, confidential, title, description
541
         * @return array status=<0 Error, =0 Success, with the following bitfields for further information:
598
         * @return array status=<0 Error, =0 Success, with the following bitfields for further information:
542
         *             x+1 = RA is not registered, but it can be invited
599
         *             x+1 = RA is not registered, but it can be invited
543
         *             x+2 = RA is not registered and it cannot be invited
600
         *             x+2 = RA is not registered and it cannot be invited
544
         *             x+4 = OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset
601
         *             x+4 = OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset
545
         *             x+8 = User has write rights to the freshly created OID
602
         *             x+8 = User has write rights to the freshly created OID
546
         * @throws OIDplusConfigInitializationException
603
         * @throws OIDplusConfigInitializationException
547
         * @throws OIDplusException
604
         * @throws OIDplusException
548
         */
605
         */
549
        private function action_Insert(array $params): array {
606
        private function action_Insert(array $params): array {
550
                // Check if you have write rights on the parent (to create a new object)
607
                // Check if you have write rights on the parent (to create a new object)
551
                _CheckParamExists($params, 'parent');
608
                _CheckParamExists($params, 'parent');
552
                $objParent = OIDplusObject::parse($params['parent']);
609
                $objParent = OIDplusObject::parse($params['parent']);
553
                if (!$objParent) throw new OIDplusException(_L('%1 action failed because parent object "%2" cannot be parsed!','INSERT',$params['parent']));
610
                if (!$objParent) throw new OIDplusException(_L('%1 action failed because parent object "%2" cannot be parsed!','INSERT',$params['parent']));
554
 
611
 
555
                if (!$objParent->isRoot()) {
612
                if (!$objParent->isRoot()) {
556
                        $idParent = $objParent->nodeId();
613
                        $idParent = $objParent->nodeId();
557
                        if (!OIDplusObject::exists($idParent)) {
614
                        if (!OIDplusObject::exists($idParent)) {
558
                                throw new OIDplusException(_L('Parent object %1 does not exist',$idParent), null, 404);
615
                                throw new OIDplusException(_L('Parent object %1 does not exist',$idParent), null, 404);
559
                        }
616
                        }
560
                }
617
                }
561
 
618
 
562
                if (!$objParent->userHasWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the correct RA to insert an OID at this arc.'), null, 401);
619
                if (!$objParent->userHasWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the correct RA to insert an OID at this arc.'), null, 401);
563
 
620
 
564
                // Check if the ID is valid
621
                // Check if the ID is valid
565
                _CheckParamExists($params, 'id');
622
                _CheckParamExists($params, 'id');
566
                if ($params['id'] == '') throw new OIDplusException(_L('ID may not be empty'));
623
                if ($params['id'] == '') throw new OIDplusException(_L('ID may not be empty'));
567
 
624
 
568
                // For the root objects, let the user also enter a WEID
625
                // For the root objects, let the user also enter a WEID
569
                if ($objParent::ns() == 'oid') {
626
                if ($objParent::ns() == 'oid') {
570
                        assert($objParent instanceof OIDplusOid); //assert(get_class($objParent) === "ViaThinkSoft\OIDplus\OIDplusOid");
627
                        assert($objParent instanceof OIDplusOid); //assert(get_class($objParent) === "ViaThinkSoft\OIDplus\OIDplusOid");
571
                        if (strtolower(substr(trim($params['id']),0,5)) === 'weid:') {
628
                        if (strtolower(substr(trim($params['id']),0,5)) === 'weid:') {
572
                                if ($objParent->isRoot()) {
629
                                if ($objParent->isRoot()) {
573
                                        $params['id'] = \Frdl\Weid\WeidOidConverter::weid2oid($params['id']);
630
                                        $params['id'] = \Frdl\Weid\WeidOidConverter::weid2oid($params['id']);
574
                                        if ($params['id'] === false) {
631
                                        if ($params['id'] === false) {
575
                                                throw new OIDplusException(_L('Invalid WEID'));
632
                                                throw new OIDplusException(_L('Invalid WEID'));
576
                                        }
633
                                        }
577
                                } else {
634
                                } else {
578
                                        throw new OIDplusException(_L('You can use the WEID syntax only at your object tree root.'));
635
                                        throw new OIDplusException(_L('You can use the WEID syntax only at your object tree root.'));
579
                                }
636
                                }
580
                        }
637
                        }
581
                }
638
                }
582
 
639
 
583
                // Determine absolute OID name
640
                // Determine absolute OID name
584
                // Note: At addString() and parse(), the syntax of the ID will be checked
641
                // Note: At addString() and parse(), the syntax of the ID will be checked
585
                if (oidplus_is_true($params['id_fully_qualified'] ?? false)) {
642
                if (oidplus_is_true($params['id_fully_qualified'] ?? false)) {
586
                        // For REST API, the ID is absolute (because this is what is in the URL). We need to verify that ID and Parent matches.
643
                        // For REST API, the ID is absolute (because this is what is in the URL). We need to verify that ID and Parent matches.
587
                        $id = $params['id'];
644
                        $id = $params['id'];
588
                        $obj = OIDplusObject::parse($id);
645
                        $obj = OIDplusObject::parse($id);
589
                        $objParentTest = !$obj ? null : $obj->getParent();
646
                        $objParentTest = !$obj ? null : $obj->getParent();
590
                        if (!$objParentTest || !$objParentTest->equals($objParent)) throw new OIDplusException(_L('Cannot verify that %1 has parent %2', $obj->nodeId(), $objParent->nodeId()));
647
                        if (!$objParentTest || !$objParentTest->equals($objParent)) throw new OIDplusException(_L('Cannot verify that %1 has parent %2', $obj->nodeId(), $objParent->nodeId()));
591
                } else {
648
                } else {
592
                        // For AJAX/UI, the ID is relative to the parent. The absolute ID will be created by PHP's addString(), because JavaScript cannot know the syntax of the Object Type plugin
649
                        // For AJAX/UI, the ID is relative to the parent. The absolute ID will be created by PHP's addString(), because JavaScript cannot know the syntax of the Object Type plugin
593
                        $id = $objParent->addString($params['id']);
650
                        $id = $objParent->addString($params['id']);
594
                        $obj = OIDplusObject::parse($id);
651
                        $obj = OIDplusObject::parse($id);
595
                }
652
                }
596
                if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','INSERT',$id));
653
                if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','INSERT',$id));
597
 
654
 
598
                // Check, if the OID exists
655
                // Check, if the OID exists
599
                if (OIDplusObject::exists($id)) {
656
                if (OIDplusObject::exists($id)) {
600
                        throw new OIDplusException(_L('Object %1 already exists!',$id));
657
                        throw new OIDplusException(_L('Object %1 already exists!',$id));
601
                }
658
                }
602
 
659
 
603
                foreach (OIDplus::getAllPlugins() as $plugin) {
660
                foreach (OIDplus::getAllPlugins() as $plugin) {
604
                        if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) {
661
                        if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) {
605
                                $plugin->beforeObjectInsert($id, $params);
662
                                $plugin->beforeObjectInsert($id, $params);
606
                        }
663
                        }
607
                }
664
                }
608
 
665
 
609
                // First simulate if there are any problems of ASN.1 IDs und IRIs
666
                // First simulate if there are any problems of ASN.1 IDs und IRIs
610
                if ($obj::ns() == 'oid') {
667
                if ($obj::ns() == 'oid') {
611
                        assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
668
                        assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
612
                        if (!$obj->isWellKnown()) {
669
                        if (!$obj->isWellKnown()) {
613
                                if (isset($params['iris'])) {
670
                                if (isset($params['iris'])) {
614
                                        $ids = ($params['iris'] == '') ? array() : (is_array($params['iris']) ? $params['iris'] : explode(',',$params['iris']));
671
                                        $ids = ($params['iris'] == '') ? array() : (is_array($params['iris']) ? $params['iris'] : explode(',',$params['iris']));
615
                                        $ids = array_map('trim',$ids);
672
                                        $ids = array_map('trim',$ids);
616
                                        $obj->replaceIris($ids, true);
673
                                        $obj->replaceIris($ids, true);
617
                                }
674
                                }
618
 
675
 
619
                                if (isset($params['asn1ids'])) {
676
                                if (isset($params['asn1ids'])) {
620
                                        $ids = ($params['asn1ids'] == '') ? array() : (is_array($params['asn1ids']) ? $params['asn1ids'] : explode(',',$params['asn1ids']));
677
                                        $ids = ($params['asn1ids'] == '') ? array() : (is_array($params['asn1ids']) ? $params['asn1ids'] : explode(',',$params['asn1ids']));
621
                                        $ids = array_map('trim',$ids);
678
                                        $ids = array_map('trim',$ids);
622
                                        $obj->replaceAsn1Ids($ids, true);
679
                                        $obj->replaceAsn1Ids($ids, true);
623
                                }
680
                                }
624
                        }
681
                        }
625
                }
682
                }
626
 
683
 
627
                // Apply superior RA change
684
                // Apply superior RA change
628
                $parent = $params['parent'];
685
                $parent = $params['parent'];
629
                $ra_email = $params['ra_email'] ?? '';
686
                $ra_email = $params['ra_email'] ?? '';
630
                if ($obj::ns() == 'oid') {
687
                if ($obj::ns() == 'oid') {
631
                        assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
688
                        assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
632
                        if ($obj->isWellKnown()) {
689
                        if ($obj->isWellKnown()) {
633
                                $ra_email = '';
690
                                $ra_email = '';
634
                        }
691
                        }
635
                }
692
                }
636
                if (!empty($ra_email) && !OIDplus::mailUtils()->validMailAddress($ra_email)) {
693
                if (!empty($ra_email) && !OIDplus::mailUtils()->validMailAddress($ra_email)) {
637
                        throw new OIDplusException(_L('Invalid RA email address'));
694
                        throw new OIDplusException(_L('Invalid RA email address'));
638
                }
695
                }
639
 
696
 
640
                if (empty($ra_email)) {
697
                if (empty($ra_email)) {
641
                        OIDplus::logger()->log("V2:[INFO]OID(%2)+[INFO]OID(%1)+[OK/INFO]OIDRA(%2)+[OK/INFO]A", "Object '%1' created, without defined RA, superior object is '%2'", $id, $parent);
698
                        OIDplus::logger()->log("V2:[INFO]OID(%2)+[INFO]OID(%1)+[OK/INFO]OIDRA(%2)+[OK/INFO]A", "Object '%1' created, without defined RA, superior object is '%2'", $id, $parent);
642
                } else {
699
                } else {
643
                        OIDplus::logger()->log("V2:[INFO]OID(%2)+[INFO]OID(%1)+[OK/INFO]OIDRA(%2)+[OK/INFO]A", "Object '%1' created, given to RA '%3', superior object is '%2'", $id, $parent, $ra_email);
700
                        OIDplus::logger()->log("V2:[INFO]OID(%2)+[INFO]OID(%1)+[OK/INFO]OIDRA(%2)+[OK/INFO]A", "Object '%1' created, given to RA '%3', superior object is '%2'", $id, $parent, $ra_email);
644
                }
701
                }
645
                if (!empty($ra_email)) {
702
                if (!empty($ra_email)) {
646
                        OIDplus::logger()->log("V2:[INFO]RA(%2)", "Gained ownership of newly created object '%1'", $id, $ra_email);
703
                        OIDplus::logger()->log("V2:[INFO]RA(%2)", "Gained ownership of newly created object '%1'", $id, $ra_email);
647
                }
704
                }
648
 
705
 
649
                $confidential = oidplus_is_true($params['confidential'] ?? false);
706
                $confidential = oidplus_is_true($params['confidential'] ?? false);
650
                $comment = $params['comment'] ?? '';
707
                $comment = $params['comment'] ?? '';
651
                $title = $params['title'] ?? ''; // This is very special (only useable in REST API): The superior RA can set the title during creation, even if they lose their ownership by delegating afterwards!
708
                $title = $params['title'] ?? ''; // This is very special (only useable in REST API): The superior RA can set the title during creation, even if they lose their ownership by delegating afterwards!
652
                $description = $params['description'] ?? ''; // This is very special (only useable in REST API): The superior RA can set the title during creation, even if they lose their ownership by delegating afterwards!
709
                $description = $params['description'] ?? ''; // This is very special (only useable in REST API): The superior RA can set the title during creation, even if they lose their ownership by delegating afterwards!
653
 
710
 
654
                if (strlen($id) > OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH')) {
711
                if (strlen($id) > OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH')) {
655
                        $maxlen = OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH');
712
                        $maxlen = OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH');
656
                        throw new OIDplusException(_L('The identifier %1 is too long (max allowed length: %2)',$id,$maxlen));
713
                        throw new OIDplusException(_L('The identifier %1 is too long (max allowed length: %2)',$id,$maxlen));
657
                }
714
                }
658
 
715
 
659
                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));
716
                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));
660
                OIDplusObject::resetObjectInformationCache();
717
                OIDplusObject::resetObjectInformationCache();
661
 
718
 
662
                // Set ASN.1 IDs und IRIs
719
                // Set ASN.1 IDs und IRIs
663
                if ($obj::ns() == 'oid') {
720
                if ($obj::ns() == 'oid') {
664
                        assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
721
                        assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
665
                        if (!$obj->isWellKnown()) {
722
                        if (!$obj->isWellKnown()) {
666
                                if (isset($params['iris'])) {
723
                                if (isset($params['iris'])) {
667
                                        $ids = ($params['iris'] == '') ? array() : (is_array($params['iris']) ? $params['iris'] : explode(',',$params['iris']));
724
                                        $ids = ($params['iris'] == '') ? array() : (is_array($params['iris']) ? $params['iris'] : explode(',',$params['iris']));
668
                                        $ids = array_map('trim',$ids);
725
                                        $ids = array_map('trim',$ids);
669
                                        $obj->replaceIris($ids, false);
726
                                        $obj->replaceIris($ids, false);
670
                                }
727
                                }
671
 
728
 
672
                                if (isset($params['asn1ids'])) {
729
                                if (isset($params['asn1ids'])) {
673
                                        $ids = ($params['asn1ids'] == '') ? array() : (is_array($params['asn1ids']) ? $params['asn1ids'] : explode(',',$params['asn1ids']));
730
                                        $ids = ($params['asn1ids'] == '') ? array() : (is_array($params['asn1ids']) ? $params['asn1ids'] : explode(',',$params['asn1ids']));
674
                                        $ids = array_map('trim',$ids);
731
                                        $ids = array_map('trim',$ids);
675
                                        $obj->replaceAsn1Ids($ids, false);
732
                                        $obj->replaceAsn1Ids($ids, false);
676
                                }
733
                                }
677
                        }
734
                        }
678
                }
735
                }
679
 
736
 
680
                $status = 0;
737
                $status = 0;
681
 
738
 
682
                if (!empty($ra_email)) {
739
                if (!empty($ra_email)) {
683
                        // Do we need to notify that the RA does not exist?
740
                        // Do we need to notify that the RA does not exist?
684
                        $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($ra_email));
741
                        $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($ra_email));
685
                        $invitePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.92'); // OIDplusPageRaInvite
742
                        $invitePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.92'); // OIDplusPageRaInvite
686
                        if (!$res->any()) $status = !is_null($invitePlugin) && OIDplus::config()->getValue('ra_invitation_enabled') ? 1 : 2;
743
                        if (!$res->any()) $status = !is_null($invitePlugin) && OIDplus::config()->getValue('ra_invitation_enabled') ? 1 : 2;
687
                }
744
                }
688
 
745
 
689
                if ($obj::ns() == 'oid') {
746
                if ($obj::ns() == 'oid') {
690
                        assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
747
                        assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
691
                        if ($obj->isWellKnown()) {
748
                        if ($obj->isWellKnown()) {
692
                                $status += 4;
749
                                $status += 4;
693
                        }
750
                        }
694
                }
751
                }
695
 
752
 
696
                if ($obj->userHasWriteRights()) {
753
                if ($obj->userHasWriteRights()) {
697
                        $status += 8;
754
                        $status += 8;
698
                }
755
                }
699
 
756
 
700
                foreach (OIDplus::getAllPlugins() as $plugin) {
757
                foreach (OIDplus::getAllPlugins() as $plugin) {
701
                        if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) {
758
                        if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) {
702
                                $plugin->afterObjectInsert($id, $params);
759
                                $plugin->afterObjectInsert($id, $params);
703
                        }
760
                        }
704
                }
761
                }
705
 
762
 
706
                return array(
763
                return array(
707
                        "status" => $status,
764
                        "status" => $status,
708
                        "inserted_id" => $id
765
                        "inserted_id" => $id
709
                );
766
                );
710
        }
767
        }
711
 
768
 
712
        /**
769
        /**
713
         * Generate UUID (will be used by a few plugins)
770
         * Generate UUID (will be used by a few plugins)
714
         * @param array $params Nothing
771
         * @param array $params Nothing
715
         * @return array status=0 success, status<0 error. If success, then also uuid, intval
772
         * @return array status=0 success, status<0 error. If success, then also uuid, intval
716
         * @throws OIDplusConfigInitializationException
773
         * @throws OIDplusConfigInitializationException
717
         * @throws OIDplusException
774
         * @throws OIDplusException
718
         */
775
         */
719
        private function action_UuidGen(array $params): array {
776
        private function action_UuidGen(array $params): array {
720
                $uuid = gen_uuid(OIDplus::config()->getValue('uuid_prefer_timebased', '1') == '1');
777
                $uuid = gen_uuid(OIDplus::config()->getValue('uuid_prefer_timebased', '1') == '1');
721
                if (!$uuid) return array("status" => -1);
778
                if (!$uuid) return array("status" => -1);
722
                return array(
779
                return array(
723
                        "status" => 0,
780
                        "status" => 0,
724
                        "uuid" => $uuid,
781
                        "uuid" => $uuid,
725
                        "intval" => substr(uuid_to_oid($uuid),strlen('2.25.'))
782
                        "intval" => substr(uuid_to_oid($uuid),strlen('2.25.'))
726
                );
783
                );
727
        }
784
        }
728
 
785
 
729
        /**
786
        /**
730
         * @param string $actionID
787
         * @param string $actionID
731
         * @param array $params
788
         * @param array $params
732
         * @return array
789
         * @return array
733
         * @throws OIDplusConfigInitializationException
790
         * @throws OIDplusConfigInitializationException
734
         * @throws OIDplusException
791
         * @throws OIDplusException
735
         */
792
         */
736
        public function action(string $actionID, array $params): array {
793
        public function action(string $actionID, array $params): array {
737
                if ($actionID == 'Delete') {
794
                if ($actionID == 'Delete') {
738
                        return $this->action_Delete($params);
795
                        return $this->action_Delete($params);
739
                } else if ($actionID == 'Update') {
796
                } else if ($actionID == 'Update') {
740
                        return $this->action_Update($params);
797
                        return $this->action_Update($params);
741
                } else if ($actionID == 'Insert') {
798
                } else if ($actionID == 'Insert') {
742
                        return $this->action_Insert($params);
799
                        return $this->action_Insert($params);
743
                } else if ($actionID == 'generate_uuid') {
800
                } else if ($actionID == 'generate_uuid') {
744
                        return $this->action_UuidGen($params);
801
                        return $this->action_UuidGen($params);
745
                } else {
802
                } else {
746
                        return parent::action($actionID, $params);
803
                        return parent::action($actionID, $params);
747
                }
804
                }
748
        }
805
        }
749
 
806
 
750
        /**
807
        /**
751
         * @param bool $html
808
         * @param bool $html
752
         * @return void
809
         * @return void
753
         * @throws OIDplusException
810
         * @throws OIDplusException
754
         */
811
         */
755
        public function init(bool $html=true) {
812
        public function init(bool $html=true) {
756
                OIDplus::config()->prepareConfigKey('oobe_objects_done', '"Out Of Box Experience" wizard for OIDplusPagePublicObjects done once?', '0', OIDplusConfig::PROTECTION_HIDDEN, function($value) {});
813
                OIDplus::config()->prepareConfigKey('oobe_objects_done', '"Out Of Box Experience" wizard for OIDplusPagePublicObjects done once?', '0', OIDplusConfig::PROTECTION_HIDDEN, function($value) {});
757
                OIDplus::config()->prepareConfigKey('oid_grid_show_weid', 'Show WEID/Base36 column in CRUD grid of OIDs?', '1', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
814
                OIDplus::config()->prepareConfigKey('oid_grid_show_weid', 'Show WEID/Base36 column in CRUD grid of OIDs?', '1', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
758
                        if (!is_numeric($value) || ($value < 0) || ($value > 1)) {
815
                        if (!is_numeric($value) || ($value < 0) || ($value > 1)) {
759
                                throw new OIDplusException(_L('Please enter a valid value (0=no, 1=yes).'));
816
                                throw new OIDplusException(_L('Please enter a valid value (0=no, 1=yes).'));
760
                        }
817
                        }
761
                });
818
                });
762
                OIDplus::config()->prepareConfigKey('uuid_prefer_timebased', 'Preferred UUID Generator version? 1=Timebased (Very secure, but reveals the MAC address of the server); 4=Random (has a very, very tiny change to generate duplicates)', '1', OIDplusConfig::PROTECTION_HIDDEN, function($value) {
819
                OIDplus::config()->prepareConfigKey('uuid_prefer_timebased', 'Preferred UUID Generator version? 1=Timebased (Very secure, but reveals the MAC address of the server); 4=Random (has a very, very tiny change to generate duplicates)', '1', OIDplusConfig::PROTECTION_HIDDEN, function($value) {
763
                        if (($value != '1') && ($value != '4')) {
820
                        if (($value != '1') && ($value != '4')) {
764
                                throw new OIDplusException(_L('Please enter a valid value (1=Timebased, 4=Random).'));
821
                                throw new OIDplusException(_L('Please enter a valid value (1=Timebased, 4=Random).'));
765
                        }
822
                        }
766
                });
823
                });
767
        }
824
        }
768
 
825
 
769
        /**
826
        /**
770
         * @param string $id
827
         * @param string $id
771
         * @param array $out
828
         * @param array $out
772
         * @return array|false
829
         * @return array|false
773
         * @throws OIDplusException
830
         * @throws OIDplusException
774
         */
831
         */
775
        private function tryObject(string $id, array &$out) {
832
        private function tryObject(string $id, array &$out) {
776
                $parent = null;
833
                $parent = null;
777
                $res = null;
834
                $res = null;
778
                $row = null;
835
                $row = null;
779
                $obj = OIDplusObject::parse($id);
836
                $obj = OIDplusObject::parse($id);
780
                if (!$obj) return false;
837
                if (!$obj) return false;
781
                if ($obj->isRoot()) {
838
                if ($obj->isRoot()) {
782
                        $obj->getContentPage($out['title'], $out['text'], $out['icon']);
839
                        $obj->getContentPage($out['title'], $out['text'], $out['icon']);
783
                        $objParent = null; // $obj->getParent();
840
                        $objParent = null; // $obj->getParent();
784
                } else {
841
                } else {
785
                        $obj = OIDplusObject::findFitting($id); // this time, the object will be found, not just the object type
842
                        $obj = OIDplusObject::findFitting($id); // this time, the object will be found, not just the object type
786
                        if (!$obj) {
843
                        if (!$obj) {
787
                                return false;
844
                                return false;
788
                        } else {
845
                        } else {
789
                                $obj->getContentPage($out['title'], $out['text'], $out['icon']);
846
                                $obj->getContentPage($out['title'], $out['text'], $out['icon']);
790
                                if (empty($out['title'])) $out['title'] = $obj->defaultTitle();
847
                                if (empty($out['title'])) $out['title'] = $obj->defaultTitle();
791
                                if (empty($out['title'])) $out['title'] = explode(':',$obj->nodeId(),2)[1];
848
                                if (empty($out['title'])) $out['title'] = explode(':',$obj->nodeId(),2)[1];
792
                                $objParent = $obj->getParent();
849
                                $objParent = $obj->getParent();
793
                        }
850
                        }
794
                }
851
                }
795
                return array($id, $obj, $objParent);
852
                return array($id, $obj, $objParent);
796
        }
853
        }
797
 
854
 
798
        /**
855
        /**
799
         * @param string $id
856
         * @param string $id
800
         * @return array
857
         * @return array
801
         */
858
         */
802
        public static function getAlternativesForQuery(string $id): array {
859
        public static function getAlternativesForQuery(string $id): array {
803
                // Attention: This is NOT an implementation of INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7!
860
                // Attention: This is NOT an implementation of INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7!
804
                //            This is the function that calls getAlternativesForQuery() of every plugin that implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7
861
                //            This is the function that calls getAlternativesForQuery() of every plugin that implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7
805
 
862
 
806
                // e.g. used for "Reverse Alt Id"
863
                // e.g. used for "Reverse Alt Id"
807
                $alternatives = array();
864
                $alternatives = array();
808
                foreach (OIDplus::getAllPlugins() as $plugin) {
865
                foreach (OIDplus::getAllPlugins() as $plugin) {
809
                        if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7) {
866
                        if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7) {
810
                                $tmp = $plugin->getAlternativesForQuery($id);
867
                                $tmp = $plugin->getAlternativesForQuery($id);
811
                                if (is_array($tmp)) {
868
                                if (is_array($tmp)) {
812
                                        $alternatives = array_merge($tmp, $alternatives);
869
                                        $alternatives = array_merge($tmp, $alternatives);
813
                                }
870
                                }
814
                        }
871
                        }
815
                }
872
                }
816
 
873
 
817
                // If something is more than one time, remove it
874
                // If something is more than one time, remove it
818
                $alternatives = array_unique($alternatives);
875
                $alternatives = array_unique($alternatives);
819
 
876
 
820
                // If a plugin accidentally added the own ID, remove it. This function lists only alternatives, not the own ID
877
                // If a plugin accidentally added the own ID, remove it. This function lists only alternatives, not the own ID
821
                $alternatives_tmp = array();
878
                $alternatives_tmp = array();
822
                foreach ($alternatives as $alt) {
879
                foreach ($alternatives as $alt) {
823
                        if ($alt !== $id) $alternatives_tmp[] = $alt;
880
                        if ($alt !== $id) $alternatives_tmp[] = $alt;
824
                }
881
                }
825
                return $alternatives_tmp;
882
                return $alternatives_tmp;
826
        }
883
        }
827
 
884
 
828
        /**
885
        /**
829
         * @param string $id
886
         * @param string $id
830
         * @param array $out
887
         * @param array $out
831
         * @param bool $handled
888
         * @param bool $handled
832
         * @return void
889
         * @return void
833
         * @throws OIDplusConfigInitializationException
890
         * @throws OIDplusConfigInitializationException
834
         * @throws OIDplusException
891
         * @throws OIDplusException
835
         */
892
         */
836
        public function gui(string $id, array &$out, bool &$handled) {
893
        public function gui(string $id, array &$out, bool &$handled) {
837
                if ($id === 'oidplus:system') {
894
                if ($id === 'oidplus:system') {
838
                        $handled = true;
895
                        $handled = true;
839
 
896
 
840
                        $out['title'] = OIDplus::config()->getValue('system_title');
897
                        $out['title'] = OIDplus::config()->getValue('system_title');
841
                        $out['icon'] = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png';
898
                        $out['icon'] = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png';
842
 
899
 
843
                        if (file_exists(OIDplus::localpath() . 'userdata/welcome/welcome$'.OIDplus::getCurrentLang().'.html')) {
900
                        if (file_exists(OIDplus::localpath() . 'userdata/welcome/welcome$'.OIDplus::getCurrentLang().'.html')) {
844
                                $cont = file_get_contents(OIDplus::localpath() . 'userdata/welcome/welcome$'.OIDplus::getCurrentLang().'.html');
901
                                $cont = file_get_contents(OIDplus::localpath() . 'userdata/welcome/welcome$'.OIDplus::getCurrentLang().'.html');
845
                        } else if (file_exists(OIDplus::localpath() . 'userdata/welcome/welcome.html')) {
902
                        } else if (file_exists(OIDplus::localpath() . 'userdata/welcome/welcome.html')) {
846
                                $cont = file_get_contents(OIDplus::localpath() . 'userdata/welcome/welcome.html');
903
                                $cont = file_get_contents(OIDplus::localpath() . 'userdata/welcome/welcome.html');
847
                        } else if (file_exists(__DIR__ . '/welcome$'.OIDplus::getCurrentLang().'.html')) {
904
                        } else if (file_exists(__DIR__ . '/welcome$'.OIDplus::getCurrentLang().'.html')) {
848
                                $cont = file_get_contents(__DIR__ . '/welcome$'.OIDplus::getCurrentLang().'.html');
905
                                $cont = file_get_contents(__DIR__ . '/welcome$'.OIDplus::getCurrentLang().'.html');
849
                        } else if (file_exists(__DIR__ . '/welcome.html')) {
906
                        } else if (file_exists(__DIR__ . '/welcome.html')) {
850
                                $cont = file_get_contents(__DIR__ . '/welcome.html');
907
                                $cont = file_get_contents(__DIR__ . '/welcome.html');
851
                        } else {
908
                        } else {
852
                                $cont = '';
909
                                $cont = '';
853
                        }
910
                        }
854
 
911
 
855
                        if ($cont) {
912
                        if ($cont) {
856
                                list($html, $js, $css) = extractHtmlContents($cont);
913
                                list($html, $js, $css) = extractHtmlContents($cont);
857
                                $cont = '';
914
                                $cont = '';
858
                                if (!empty($js)) $cont .= "<script>\n$js\n</script>";
915
                                if (!empty($js)) $cont .= "<script>\n$js\n</script>";
859
                                if (!empty($css)) $cont .= "<style>\n$css\n</style>";
916
                                if (!empty($css)) $cont .= "<style>\n$css\n</style>";
860
                                $cont .= stripHtmlComments($html);
917
                                $cont .= stripHtmlComments($html);
861
                        }
918
                        }
862
 
919
 
863
                        $out['text'] = $cont;
920
                        $out['text'] = $cont;
864
 
921
 
865
                        if (strpos($out['text'], '%%OBJECT_TYPE_LIST%%') !== false) {
922
                        if (strpos($out['text'], '%%OBJECT_TYPE_LIST%%') !== false) {
866
                                $tmp = '<ul>';
923
                                $tmp = '<ul>';
867
                                foreach (OIDplus::getEnabledObjectTypes() as $ot) {
924
                                foreach (OIDplus::getEnabledObjectTypes() as $ot) {
868
                                        $tmp .= '<li><a '.OIDplus::gui()->link($ot::root()).'>'.htmlentities($ot::objectTypeTitle()).'</a></li>';
925
                                        $tmp .= '<li><a '.OIDplus::gui()->link($ot::root()).'>'.htmlentities($ot::objectTypeTitle()).'</a></li>';
869
                                }
926
                                }
870
                                $tmp .= '</ul>';
927
                                $tmp .= '</ul>';
871
                                $out['text'] = str_replace('%%OBJECT_TYPE_LIST%%', $tmp, $out['text']);
928
                                $out['text'] = str_replace('%%OBJECT_TYPE_LIST%%', $tmp, $out['text']);
872
                        }
929
                        }
873
                }
930
                }
874
 
931
 
875
                // Never answer to an object type that is called 'oidplus:',
932
                // Never answer to an object type that is called 'oidplus:',
876
                // otherwise, an object type plugin could break the whole system!
933
                // otherwise, an object type plugin could break the whole system!
877
                else if ((strpos($id,':') !== false) && (!str_starts_with($id,'oidplus:'))) {
934
                else if ((strpos($id,':') !== false) && (!str_starts_with($id,'oidplus:'))) {
878
 
935
 
879
                        // --- Try to find the object or an alternative
936
                        // --- Try to find the object or an alternative
880
 
937
 
881
                        $test = $this->tryObject($id, $out);
938
                        $test = $this->tryObject($id, $out);
882
                        if ($test === false) {
939
                        if ($test === false) {
883
                                // try to find an alternative
940
                                // try to find an alternative
884
                                $alternatives = $this->getAlternativesForQuery($id);
941
                                $alternatives = $this->getAlternativesForQuery($id);
885
                                foreach ($alternatives as $alternative) {
942
                                foreach ($alternatives as $alternative) {
886
                                        $test = $this->tryObject($alternative, $out);
943
                                        $test = $this->tryObject($alternative, $out);
887
                                        if ($test !== false) break; // found something
944
                                        if ($test !== false) break; // found something
888
                                }
945
                                }
889
                        }
946
                        }
890
                        if ($test !== false) {
947
                        if ($test !== false) {
891
                                list($id, $obj, $objParent) = $test;
948
                                list($id, $obj, $objParent) = $test;
892
                        } else {
949
                        } else {
893
                                $objParent = null; // to avoid warnings
950
                                $objParent = null; // to avoid warnings
894
                        }
951
                        }
895
 
952
 
896
                        // --- If the object type is disabled or not an object at all (e.g. "oidplus:"), then $handled=false
953
                        // --- If the object type is disabled or not an object at all (e.g. "oidplus:"), then $handled=false
897
                        //     If the object type is enabled but object not found, $handled=true
954
                        //     If the object type is enabled but object not found, $handled=true
898
 
955
 
899
                        $obj = OIDplusObject::parse($id);
956
                        $obj = OIDplusObject::parse($id);
900
 
957
 
901
                        if ($test === false) {
958
                        if ($test === false) {
902
                                if (!$obj) {
959
                                if (!$obj) {
903
                                        // Object type disabled or not known (e.g. ObjectType "oidplus:").
960
                                        // Object type disabled or not known (e.g. ObjectType "oidplus:").
904
                                        $handled = false;
961
                                        $handled = false;
905
                                        return;
962
                                        return;
906
                                } else {
963
                                } else {
907
                                        // Object type enabled but identifier not in database
964
                                        // Object type enabled but identifier not in database
908
                                        $handled = true;
965
                                        $handled = true;
909
                                        if (isset($_SERVER['SCRIPT_FILENAME']) && (strtolower(basename($_SERVER['SCRIPT_FILENAME'])) !== 'ajax.php')) { // don't send HTTP error codes in ajax.php, because we want a page and not a JavaScript alert box, when someone enters an invalid OID in the GoTo-Box
966
                                        if (isset($_SERVER['SCRIPT_FILENAME']) && (strtolower(basename($_SERVER['SCRIPT_FILENAME'])) !== 'ajax.php')) { // don't send HTTP error codes in ajax.php, because we want a page and not a JavaScript alert box, when someone enters an invalid OID in the GoTo-Box
910
                                                http_response_code(404);
967
                                                http_response_code(404);
911
                                        }
968
                                        }
912
                                        throw new OIDplusHtmlException(_L('The object %1 was not found in this database.','<code>'.htmlentities($id).'</code>'), _L('Object not found'));
969
                                        throw new OIDplusHtmlException(_L('The object %1 was not found in this database.','<code>'.htmlentities($id).'</code>'), _L('Object not found'));
913
                                }
970
                                }
914
                        } else {
971
                        } else {
915
                                $handled = true;
972
                                $handled = true;
916
                        }
973
                        }
917
 
974
 
918
                        unset($test);
975
                        unset($test);
919
 
976
 
920
                        // --- If found, do we have read rights?
977
                        // --- If found, do we have read rights?
921
 
978
 
922
                        if (!$obj->userHasReadRights()) {
979
                        if (!$obj->userHasReadRights()) {
923
                                if (isset($_SERVER['SCRIPT_FILENAME']) && (strtolower(basename($_SERVER['SCRIPT_FILENAME'])) !== 'ajax.php')) { // don't send HTTP error codes in ajax.php, because we want a page and not a JavaScript alert box, when someone enters an invalid OID in the GoTo-Box
980
                                if (isset($_SERVER['SCRIPT_FILENAME']) && (strtolower(basename($_SERVER['SCRIPT_FILENAME'])) !== 'ajax.php')) { // don't send HTTP error codes in ajax.php, because we want a page and not a JavaScript alert box, when someone enters an invalid OID in the GoTo-Box
924
                                        http_response_code(403);
981
                                        http_response_code(403);
925
                                }
982
                                }
926
                                throw new OIDplusHtmlException(_L('Please <a %1>log in</a> to receive information about this object.',OIDplus::gui()->link('oidplus:login')), _L('Access denied'), 401);
983
                                throw new OIDplusHtmlException(_L('Please <a %1>log in</a> to receive information about this object.',OIDplus::gui()->link('oidplus:login')), _L('Access denied'), 401);
927
                        }
984
                        }
928
 
985
 
929
                        // ---
986
                        // ---
930
 
987
 
931
                        $out['text'] = '<!-- MARKER 1 -->' . $out['text']; // use this to better control modifyContent!
988
                        $out['text'] = '<!-- MARKER 1 -->' . $out['text']; // use this to better control modifyContent!
932
 
989
 
933
                        if ($objParent) {
990
                        if ($objParent) {
934
                                if ($objParent->isRoot()) {
991
                                if ($objParent->isRoot()) {
935
                                        $parent_link_text = $objParent->objectTypeTitle();
992
                                        $parent_link_text = $objParent->objectTypeTitle();
936
                                        $out['text'] = '<p><a '.OIDplus::gui()->link($objParent->root()).'><img src="img/arrow_back.png" width="16" alt="'._L('Go back').'"> '._L('Parent node: %1',htmlentities($parent_link_text)).'</a></p>' . $out['text'];
993
                                        $out['text'] = '<p><a '.OIDplus::gui()->link($objParent->root()).'><img src="img/arrow_back.png" width="16" alt="'._L('Go back').'"> '._L('Parent node: %1',htmlentities($parent_link_text)).'</a></p>' . $out['text'];
937
                                } else {
994
                                } else {
938
                                        $parent_title = $objParent->getTitle();
995
                                        $parent_title = $objParent->getTitle();
939
                                        if (empty($parent_title) && ($objParent->ns() == 'oid')) {
996
                                        if (empty($parent_title) && ($objParent->ns() == 'oid')) {
940
                                                assert($objParent instanceof OIDplusOid); //assert(get_class($objParent) === "ViaThinkSoft\OIDplus\OIDplusOid");
997
                                                assert($objParent instanceof OIDplusOid); //assert(get_class($objParent) === "ViaThinkSoft\OIDplus\OIDplusOid");
941
                                                // If not title is available, then use an ASN.1 identifier
998
                                                // If not title is available, then use an ASN.1 identifier
942
                                                $res_asn = OIDplus::db()->query("select name from ###asn1id where oid = ?", array($objParent->nodeId()));
999
                                                $res_asn = OIDplus::db()->query("select name from ###asn1id where oid = ?", array($objParent->nodeId()));
943
                                                if ($res_asn->any()) {
1000
                                                if ($res_asn->any()) {
944
                                                        $row_asn = $res_asn->fetch_array();
1001
                                                        $row_asn = $res_asn->fetch_array();
945
                                                        $parent_title = $row_asn['name']; // TODO: multiple ASN1 ids?
1002
                                                        $parent_title = $row_asn['name']; // TODO: multiple ASN1 ids?
946
                                                }
1003
                                                }
947
                                        }
1004
                                        }
948
 
1005
 
949
                                        $parent_link_text = empty($parent_title) ? explode(':',$objParent->nodeId())[1] : $parent_title.' ('.explode(':',$objParent->nodeId())[1].')';
1006
                                        $parent_link_text = empty($parent_title) ? explode(':',$objParent->nodeId())[1] : $parent_title.' ('.explode(':',$objParent->nodeId())[1].')';
950
 
1007
 
951
                                        $out['text'] = '<p><a '.OIDplus::gui()->link($objParent->nodeId()).'><img src="img/arrow_back.png" width="16" alt="'._L('Go back').'"> '._L('Parent node: %1',htmlentities($parent_link_text)).'</a></p>' . $out['text'];
1008
                                        $out['text'] = '<p><a '.OIDplus::gui()->link($objParent->nodeId()).'><img src="img/arrow_back.png" width="16" alt="'._L('Go back').'"> '._L('Parent node: %1',htmlentities($parent_link_text)).'</a></p>' . $out['text'];
952
                                }
1009
                                }
953
                        } else {
1010
                        } else {
954
                                $parent_link_text = _L('Go back to front page');
1011
                                $parent_link_text = _L('Go back to front page');
955
                                $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'];
1012
                                $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'];
956
                        }
1013
                        }
957
 
1014
 
958
                        $out['text'] = '<!-- MARKER 0 -->' . $out['text']; // use this to better control modifyContent!
1015
                        $out['text'] = '<!-- MARKER 0 -->' . $out['text']; // use this to better control modifyContent!
959
 
1016
 
960
                        // ---
1017
                        // ---
961
 
1018
 
962
                        $out['text'] .= '<!-- MARKER 2 -->'; // use this to better control modifyContent!
1019
                        $out['text'] .= '<!-- MARKER 2 -->'; // use this to better control modifyContent!
963
 
1020
 
964
                        if ($obj) {
1021
                        if ($obj) {
965
                                $title = $obj->getTitle() ?? '';
1022
                                $title = $obj->getTitle() ?? '';
966
                                $description = $obj->getDescription() ?? '';
1023
                                $description = $obj->getDescription() ?? '';
967
                                if (empty(strip_tags($description)) && (stripos($description,'<img') === false)) {
1024
                                if (empty(strip_tags($description)) && (stripos($description,'<img') === false)) {
968
                                        if (empty($title)) {
1025
                                        if (empty($title)) {
969
                                                $desc = '<p><i>'._L('No description for this object available').'</i></p>';
1026
                                                $desc = '<p><i>'._L('No description for this object available').'</i></p>';
970
                                        } else {
1027
                                        } else {
971
                                                $desc = $title;
1028
                                                $desc = $title;
972
                                        }
1029
                                        }
973
                                } else {
1030
                                } else {
974
                                        $desc = self::objDescription($description);
1031
                                        $desc = self::objDescription($description);
975
                                }
1032
                                }
976
 
1033
 
977
                                // $description is the description in the OID table (which the user edits)
1034
                                // $description is the description in the OID table (which the user edits)
978
                                // $desc is the thing that is shown (it can be a title if no description is there, or an MCE editor if the user has write rights)
1035
                                // $desc is the thing that is shown (it can be a title if no description is there, or an MCE editor if the user has write rights)
979
 
1036
 
980
                                if ($obj->userHasWriteRights()) {
1037
                                if ($obj->userHasWriteRights()) {
981
                                        $rand = ++self::$crudCounter;
1038
                                        $rand = ++self::$crudCounter;
982
                                        $desc = '<noscript><p><font color="red">'._L('You need to enable JavaScript to edit title or description of this object.').'</font></p>'.$desc.'</noscript>';
1039
                                        $desc = '<noscript><p><font color="red">'._L('You need to enable JavaScript to edit title or description of this object.').'</font></p>'.$desc.'</noscript>';
983
                                        $desc .= '<div class="container box" style="display:none" id="descbox_'.$rand.'">';
1040
                                        $desc .= '<div class="container box" style="display:none" id="descbox_'.$rand.'">';
984
                                        $desc .= _L('Title').': <input type="text" name="title" id="titleedit" value="'.htmlentities($title).'"><br><br>'._L('Description').':<br>';
1041
                                        $desc .= _L('Title').': <input type="text" name="title" id="titleedit" value="'.htmlentities($title).'"><br><br>'._L('Description').':<br>';
985
                                        $desc .= self::showMCE('description', $description);
1042
                                        $desc .= self::showMCE('description', $description);
986
                                        $desc .= '<button type="button" name="update_desc" id="update_desc" class="btn btn-success btn-xs update" onclick="OIDplusPagePublicObjects.updateDesc()">'._L('Update description').'</button>';
1043
                                        $desc .= '<button type="button" name="update_desc" id="update_desc" class="btn btn-success btn-xs update" onclick="OIDplusPagePublicObjects.updateDesc()">'._L('Update description').'</button>';
987
                                        $desc .= '</div>';
1044
                                        $desc .= '</div>';
988
                                        $desc .= '<script>$("#descbox_'.$rand.'")[0].style.display = "block";</script>';
1045
                                        $desc .= '<script>$("#descbox_'.$rand.'")[0].style.display = "block";</script>';
989
                                }
1046
                                }
990
                        } else {
1047
                        } else {
991
                                $desc = '';
1048
                                $desc = '';
992
                        }
1049
                        }
993
 
1050
 
994
                        // ---
1051
                        // ---
995
 
1052
 
996
                        if (strpos($out['text'], '%%DESC%%') !== false) {
1053
                        if (strpos($out['text'], '%%DESC%%') !== false) {
997
                                $out['text'] = str_replace('%%DESC%%', $desc, $out['text']);
1054
                                $out['text'] = str_replace('%%DESC%%', $desc, $out['text']);
998
                        }
1055
                        }
999
                        if (strpos($out['text'], '%%CRUD%%') !== false) {
1056
                        if (strpos($out['text'], '%%CRUD%%') !== false) {
1000
                                $out['text'] = str_replace('%%CRUD%%', self::showCrud($obj->nodeId()), $out['text']);
1057
                                $out['text'] = str_replace('%%CRUD%%', self::showCrud($obj->nodeId()), $out['text']);
1001
                        }
1058
                        }
1002
                        if (strpos($out['text'], '%%RA_INFO%%') !== false) {
1059
                        if (strpos($out['text'], '%%RA_INFO%%') !== false) {
1003
                                $out['text'] = str_replace('%%RA_INFO%%', OIDplusPagePublicRaInfo::showRaInfo($obj->getRaMail()), $out['text']);
1060
                                $out['text'] = str_replace('%%RA_INFO%%', OIDplusPagePublicRaInfo::showRaInfo($obj->getRaMail()), $out['text']);
1004
                        }
1061
                        }
1005
 
1062
 
1006
                        $out['text'] .= '<!-- MARKER 3 -->'; // use this to better control modifyContent!
1063
                        $out['text'] .= '<!-- MARKER 3 -->'; // use this to better control modifyContent!
1007
                        $out['text'] .= '<!-- MARKER 4 -->'; // use this to better control modifyContent!
1064
                        $out['text'] .= '<!-- MARKER 4 -->'; // use this to better control modifyContent!
1008
                        $out['text'] .= '<!-- MARKER 5 -->'; // use this to better control modifyContent!
1065
                        $out['text'] .= '<!-- MARKER 5 -->'; // use this to better control modifyContent!
1009
                        $alt_ids = $obj->getAltIds();
1066
                        $alt_ids = $obj->getAltIds();
1010
                        if (count($alt_ids) > 0) {
1067
                        if (count($alt_ids) > 0) {
1011
                                $out['text'] .= '<h2>'._L('Alternative Identifiers').'</h2>';
1068
                                $out['text'] .= '<h2>'._L('Alternative Identifiers').'</h2>';
1012
 
1069
 
1013
                                // Sorty by namespace
1070
                                // Sorty by namespace
1014
                                usort($alt_ids, function(OIDplusAltId $a, OIDplusAltId $b) {
1071
                                usort($alt_ids, function(OIDplusAltId $a, OIDplusAltId $b) {
1015
                                        if($a->getNamespace() > $b->getNamespace()) {
1072
                                        if($a->getNamespace() > $b->getNamespace()) {
1016
                                                return 1;
1073
                                                return 1;
1017
                                        }
1074
                                        }
1018
                                        elseif($a->getNamespace() < $b->getNamespace()) {
1075
                                        elseif($a->getNamespace() < $b->getNamespace()) {
1019
                                                return -1;
1076
                                                return -1;
1020
                                        }
1077
                                        }
1021
                                        else {
1078
                                        else {
1022
                                                return 0;
1079
                                                return 0;
1023
                                        }
1080
                                        }
1024
                                });
1081
                                });
1025
 
1082
 
1026
                                $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
1083
                                $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
1027
                                $out['text'] .= '<table class="table table-bordered table-striped">';
1084
                                $out['text'] .= '<table class="table table-bordered table-striped">';
1028
                                $out['text'] .= '<thead>';
1085
                                $out['text'] .= '<thead>';
1029
                                $out['text'] .= '<tr><th>'._L('Identifier').'</th><th>'._L('Description').'</th></tr>';
1086
                                $out['text'] .= '<tr><th>'._L('Identifier').'</th><th>'._L('Description').'</th></tr>';
1030
                                $out['text'] .= '</thead>';
1087
                                $out['text'] .= '</thead>';
1031
                                $out['text'] .= '<tbody>';
1088
                                $out['text'] .= '<tbody>';
1032
                                foreach ($alt_ids as $alt_id) {
1089
                                foreach ($alt_ids as $alt_id) {
1033
                                        $ns = $alt_id->getNamespace();
1090
                                        $ns = $alt_id->getNamespace();
1034
                                        $aid = $alt_id->getId();
1091
                                        $aid = $alt_id->getId();
1035
                                        $aiddesc = $alt_id->getDescription();
1092
                                        $aiddesc = $alt_id->getDescription();
1036
                                        $suffix = $alt_id->getSuffix();
1093
                                        $suffix = $alt_id->getSuffix();
1037
                                        $out['text'] .= '<tr><td>'.htmlentities($ns.':'.$aid).($suffix ? '<br/><font size="-1">'.htmlentities($suffix).'</font>' : '').'</td><td>'.htmlentities($aiddesc).'</td></tr>';
1094
                                        $out['text'] .= '<tr><td>'.htmlentities($ns.':'.$aid).($suffix ? '<br/><font size="-1">'.htmlentities($suffix).'</font>' : '').'</td><td>'.htmlentities($aiddesc).'</td></tr>';
1038
                                }
1095
                                }
1039
                                $out['text'] .= '</tbody>';
1096
                                $out['text'] .= '</tbody>';
1040
                                $out['text'] .= '</table>';
1097
                                $out['text'] .= '</table>';
1041
                                $out['text'] .= '</div></div>';
1098
                                $out['text'] .= '</div></div>';
1042
                        }
1099
                        }
1043
 
1100
 
1044
                        $out['text'] .= '<!-- MARKER 6 -->'; // use this to better control modifyContent!
1101
                        $out['text'] .= '<!-- MARKER 6 -->'; // use this to better control modifyContent!
1045
                        $out['text'] .= '<!-- MARKER 7 -->'; // use this to better control modifyContent!
1102
                        $out['text'] .= '<!-- MARKER 7 -->'; // use this to better control modifyContent!
1046
                        $out['text'] .= '<!-- MARKER 8 -->'; // use this to better control modifyContent!
1103
                        $out['text'] .= '<!-- MARKER 8 -->'; // use this to better control modifyContent!
1047
                        $out['text'] .= '<!-- MARKER 9 -->'; // use this to better control modifyContent!
1104
                        $out['text'] .= '<!-- MARKER 9 -->'; // use this to better control modifyContent!
1048
 
1105
 
1049
                        foreach (OIDplus::getAllPlugins() as $plugin) {
1106
                        foreach (OIDplus::getAllPlugins() as $plugin) {
1050
                                if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_2) {
1107
                                if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_2) {
1051
                                        $plugin->modifyContent($obj->nodeId(), $out['title'], $out['icon'], $out['text']);
1108
                                        $plugin->modifyContent($obj->nodeId(), $out['title'], $out['icon'], $out['text']);
1052
                                }
1109
                                }
1053
                        }
1110
                        }
1054
 
1111
 
1055
                        for ($i=0; $i<=9; $i++) $out['text'] = str_replace("<!-- MARKER $i -->", '', $out['text']);
1112
                        for ($i=0; $i<=9; $i++) $out['text'] = str_replace("<!-- MARKER $i -->", '', $out['text']);
1056
                }
1113
                }
1057
        }
1114
        }
1058
 
1115
 
1059
        /**
1116
        /**
1060
         * @param array $json
1117
         * @param array $json
1061
         * @param array $out
1118
         * @param array $out
1062
         * @return void
1119
         * @return void
1063
         */
1120
         */
1064
        private function publicSitemap_rec(array $json, array &$out) {
1121
        private function publicSitemap_rec(array $json, array &$out) {
1065
                foreach ($json as $x) {
1122
                foreach ($json as $x) {
1066
                        if (isset($x['id']) && $x['id']) {
1123
                        if (isset($x['id']) && $x['id']) {
1067
                                $out[] = $x['id'];
1124
                                $out[] = $x['id'];
1068
                        }
1125
                        }
1069
                        if (isset($x['children'])) {
1126
                        if (isset($x['children'])) {
1070
                                $this->publicSitemap_rec($x['children'], $out);
1127
                                $this->publicSitemap_rec($x['children'], $out);
1071
                        }
1128
                        }
1072
                }
1129
                }
1073
        }
1130
        }
1074
 
1131
 
1075
        /**
1132
        /**
1076
         * @param array $out
1133
         * @param array $out
1077
         * @return void
1134
         * @return void
1078
         */
1135
         */
1079
        public function publicSitemap(array &$out) {
1136
        public function publicSitemap(array &$out) {
1080
                $json = array();
1137
                $json = array();
1081
                $this->tree($json, null/*RA EMail*/, false/*HTML tree algorithm*/, "*"/*display all*/);
1138
                $this->tree($json, null/*RA EMail*/, false/*HTML tree algorithm*/, "*"/*display all*/);
1082
                $this->publicSitemap_rec($json, $out);
1139
                $this->publicSitemap_rec($json, $out);
1083
        }
1140
        }
1084
 
1141
 
1085
        /**
1142
        /**
1086
         * @param array $json
1143
         * @param array $json
1087
         * @param string|null $ra_email
1144
         * @param string|null $ra_email
1088
         * @param bool $nonjs
1145
         * @param bool $nonjs
1089
         * @param string $req_goto
1146
         * @param string $req_goto
1090
         * @return bool
1147
         * @return bool
1091
         * @throws OIDplusConfigInitializationException
1148
         * @throws OIDplusConfigInitializationException
1092
         * @throws OIDplusException
1149
         * @throws OIDplusException
1093
         */
1150
         */
1094
        public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
1151
        public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
1095
                if ($nonjs) {
1152
                if ($nonjs) {
1096
                        $json[] = array(
1153
                        $json[] = array(
1097
                                'id' => 'oidplus:system',
1154
                                'id' => 'oidplus:system',
1098
                                'icon' => OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png',
1155
                                'icon' => OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png',
1099
                                'text' => _L('System')
1156
                                'text' => _L('System')
1100
                        );
1157
                        );
1101
 
1158
 
1102
                        $objGoto = OIDplusObject::findFitting($req_goto);
1159
                        $objGoto = OIDplusObject::findFitting($req_goto);
1103
                        $objGotoParent = $objGoto ? $objGoto->getParent() : null;
1160
                        $objGotoParent = $objGoto ? $objGoto->getParent() : null;
1104
                        $parent = $objGotoParent ? $objGotoParent->nodeId() : '';
1161
                        $parent = $objGotoParent ? $objGotoParent->nodeId() : '';
1105
 
1162
 
1106
                        $objTypesChildren = array();
1163
                        $objTypesChildren = array();
1107
                        foreach (OIDplus::getEnabledObjectTypes() as $ot) {
1164
                        foreach (OIDplus::getEnabledObjectTypes() as $ot) {
1108
                                $icon = $this->get_treeicon_root($ot);
1165
                                $icon = $this->get_treeicon_root($ot);
1109
 
1166
 
1110
                                $json[] = array(
1167
                                $json[] = array(
1111
                                        'id' => $ot::root(),
1168
                                        'id' => $ot::root(),
1112
                                        'icon' => $icon,
1169
                                        'icon' => $icon,
1113
                                        'text' => $ot::objectTypeTitle()
1170
                                        'text' => $ot::objectTypeTitle()
1114
                                );
1171
                                );
1115
 
1172
 
1116
                                $tmp = OIDplusObject::parse($req_goto);
1173
                                $tmp = OIDplusObject::parse($req_goto);
1117
                                if ($tmp && ($ot == get_class($tmp))) {
1174
                                if ($tmp && ($ot == get_class($tmp))) {
1118
                                        // 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
1175
                                        // 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
1119
                                        //       on the other hand, for giving search engines content, this is good enough
1176
                                        //       on the other hand, for giving search engines content, this is good enough
1120
                                        if (empty($parent)) {
1177
                                        if (empty($parent)) {
1121
                                                $res = OIDplus::db()->query("select * from ###objects where " .
1178
                                                $res = OIDplus::db()->query("select * from ###objects where " .
1122
                                                                            "parent = ? or " .
1179
                                                                            "parent = ? or " .
1123
                                                                            "id = ? ", array($req_goto, $req_goto));
1180
                                                                            "id = ? ", array($req_goto, $req_goto));
1124
                                        } else {
1181
                                        } else {
1125
                                                $res = OIDplus::db()->query("select * from ###objects where " .
1182
                                                $res = OIDplus::db()->query("select * from ###objects where " .
1126
                                                                            "parent = ? or " .
1183
                                                                            "parent = ? or " .
1127
                                                                            "id = ? or " .
1184
                                                                            "id = ? or " .
1128
                                                                            "id = ? ", array($req_goto, $req_goto, $parent));
1185
                                                                            "id = ? ", array($req_goto, $req_goto, $parent));
1129
                                        }
1186
                                        }
1130
                                        $res->naturalSortByField('id');
1187
                                        $res->naturalSortByField('id');
1131
 
1188
 
1132
                                        $z_used = 0;
1189
                                        $z_used = 0;
1133
                                        $y_used = 0;
1190
                                        $y_used = 0;
1134
                                        $x_used = 0;
1191
                                        $x_used = 0;
1135
                                        $stufe = 0;
1192
                                        $stufe = 0;
1136
                                        $menu_entries = array();
1193
                                        $menu_entries = array();
1137
                                        $stufen = array();
1194
                                        $stufen = array();
1138
                                        while ($row = $res->fetch_object()) {
1195
                                        while ($row = $res->fetch_object()) {
1139
                                                $obj = OIDplusObject::parse($row->id);
1196
                                                $obj = OIDplusObject::parse($row->id);
1140
                                                if (!$obj) continue; // might happen if the objectType is not available/loaded
1197
                                                if (!$obj) continue; // might happen if the objectType is not available/loaded
1141
                                                if (!$obj->userHasReadRights()) continue;
1198
                                                if (!$obj->userHasReadRights()) continue;
1142
                                                $txt = ($row->title ?? '') == '' ? '' : ' -- '.htmlentities($row->title);
1199
                                                $txt = ($row->title ?? '') == '' ? '' : ' -- '.htmlentities($row->title);
1143
 
1200
 
1144
                                                if ($row->id == $parent) { $stufe=0; $z_used++; }
1201
                                                if ($row->id == $parent) { $stufe=0; $z_used++; }
1145
                                                if ($row->id == $req_goto) { $stufe=1; $y_used++; }
1202
                                                if ($row->id == $req_goto) { $stufe=1; $y_used++; }
1146
                                                if ($row->parent == $req_goto) { $stufe=2; $x_used++; }
1203
                                                if ($row->parent == $req_goto) { $stufe=2; $x_used++; }
1147
 
1204
 
1148
                                                $menu_entry = array('id' => $row->id, 'icon' => '', 'text' => $txt, 'indent' => 0);
1205
                                                $menu_entry = array('id' => $row->id, 'icon' => '', 'text' => $txt, 'indent' => 0);
1149
                                                $menu_entries[] = $menu_entry;
1206
                                                $menu_entries[] = $menu_entry;
1150
                                                $stufen[] = $stufe;
1207
                                                $stufen[] = $stufe;
1151
                                        }
1208
                                        }
1152
                                        if ($x_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 2) $menu_entry['indent'] += 1;
1209
                                        if ($x_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 2) $menu_entry['indent'] += 1;
1153
                                        if ($y_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 1) $menu_entry['indent'] += 1;
1210
                                        if ($y_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 1) $menu_entry['indent'] += 1;
1154
                                        if ($z_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 0) $menu_entry['indent'] += 1;
1211
                                        if ($z_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 0) $menu_entry['indent'] += 1;
1155
                                        $json = array_merge($json, $menu_entries);
1212
                                        $json = array_merge($json, $menu_entries);
1156
                                }
1213
                                }
1157
                        }
1214
                        }
1158
 
1215
 
1159
                        return true;
1216
                        return true;
1160
                } else {
1217
                } else {
1161
                        if ($req_goto === "*") {
1218
                        if ($req_goto === "*") {
1162
                                $goto_path = true; // display everything recursively
1219
                                $goto_path = true; // display everything recursively
1163
                        } else if ($req_goto !== "") {
1220
                        } else if ($req_goto !== "") {
1164
                                $goto = $req_goto;
1221
                                $goto = $req_goto;
1165
                                $path = array();
1222
                                $path = array();
1166
                                while (true) {
1223
                                while (true) {
1167
                                        $path[] = $goto;
1224
                                        $path[] = $goto;
1168
                                        $objGoto = OIDplusObject::findFitting($goto);
1225
                                        $objGoto = OIDplusObject::findFitting($goto);
1169
                                        if (!$objGoto) break;
1226
                                        if (!$objGoto) break;
1170
                                        $objGotoParent = $objGoto->getParent();
1227
                                        $objGotoParent = $objGoto->getParent();
1171
                                        $goto = $objGotoParent ? $objGotoParent->nodeId() : '';
1228
                                        $goto = $objGotoParent ? $objGotoParent->nodeId() : '';
1172
                                        if ($goto == '') continue;
1229
                                        if ($goto == '') continue;
1173
                                }
1230
                                }
1174
 
1231
 
1175
                                $goto_path = array_reverse($path);
1232
                                $goto_path = array_reverse($path);
1176
                        } else {
1233
                        } else {
1177
                                $goto_path = null;
1234
                                $goto_path = null;
1178
                        }
1235
                        }
1179
 
1236
 
1180
                        $objTypesChildren = array();
1237
                        $objTypesChildren = array();
1181
                        foreach (OIDplus::getEnabledObjectTypes() as $ot) {
1238
                        foreach (OIDplus::getEnabledObjectTypes() as $ot) {
1182
                                $icon = $this->get_treeicon_root($ot);
1239
                                $icon = $this->get_treeicon_root($ot);
1183
 
1240
 
1184
                                $child = array('id' => $ot::root(),
1241
                                $child = array('id' => $ot::root(),
1185
                                               'text' => $ot::objectTypeTitle(),
1242
                                               'text' => $ot::objectTypeTitle(),
1186
                                               'state' => array("opened" => true),
1243
                                               'state' => array("opened" => true),
1187
                                               'icon' => $icon,
1244
                                               'icon' => $icon,
1188
                                               'children' => OIDplus::menuUtils()->tree_populate($ot::root(), $goto_path)
1245
                                               'children' => OIDplus::menuUtils()->tree_populate($ot::root(), $goto_path)
1189
                                               );
1246
                                               );
1190
                                if ($child['icon'] && !file_exists($child['icon'])) $child['icon'] = null; // default icon (folder)
1247
                                if ($child['icon'] && !file_exists($child['icon'])) $child['icon'] = null; // default icon (folder)
1191
                                $objTypesChildren[] = $child;
1248
                                $objTypesChildren[] = $child;
1192
                        }
1249
                        }
1193
 
1250
 
1194
                        $json[] = array(
1251
                        $json[] = array(
1195
                                'id' => "oidplus:system",
1252
                                'id' => "oidplus:system",
1196
                                'text' => _L('Objects'),
1253
                                'text' => _L('Objects'),
1197
                                'state' => array(
1254
                                'state' => array(
1198
                                        "opened" => true,
1255
                                        "opened" => true,
1199
                                        // "selected" => true)  // "selected" is buggy:
1256
                                        // "selected" => true)  // "selected" is buggy:
1200
                                        // 1) The select-event will not be triggered upon loading
1257
                                        // 1) The select-event will not be triggered upon loading
1201
                                        // 2) The nodes directly blow cannot be opened (loading infinite time)
1258
                                        // 2) The nodes directly blow cannot be opened (loading infinite time)
1202
                                ),
1259
                                ),
1203
                                'icon' => OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png',
1260
                                'icon' => OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png',
1204
                                'children' => $objTypesChildren
1261
                                'children' => $objTypesChildren
1205
                        );
1262
                        );
1206
 
1263
 
1207
                        return true;
1264
                        return true;
1208
                }
1265
                }
1209
        }
1266
        }
1210
 
1267
 
1211
        /**
1268
        /**
1212
         * @param string $request
1269
         * @param string $request
1213
         * @return array|false
1270
         * @return array|false
1214
         */
1271
         */
1215
        public function tree_search(string $request) {
1272
        public function tree_search(string $request) {
1216
                $ary = array();
1273
                $ary = array();
1217
                $found_leaf = false;
1274
                $found_leaf = false;
1218
                if ($obj = OIDplusObject::parse($request)) {
1275
                if ($obj = OIDplusObject::parse($request)) {
1219
                        $found_leaf = OIDplusObject::exists($request);
1276
                        $found_leaf = OIDplusObject::exists($request);
1220
                        do {
1277
                        do {
1221
                                if ($obj->userHasReadRights()) {
1278
                                if ($obj->userHasReadRights()) {
1222
                                        $ary[] = $obj->nodeId();
1279
                                        $ary[] = $obj->nodeId();
1223
                                }
1280
                                }
1224
                        } while ($obj = $obj->getParent());
1281
                        } while ($obj = $obj->getParent());
1225
                        $ary = array_reverse($ary);
1282
                        $ary = array_reverse($ary);
1226
                }
1283
                }
1227
                if (!$found_leaf) {
1284
                if (!$found_leaf) {
1228
                        $alternatives = $this->getAlternativesForQuery($request);
1285
                        $alternatives = $this->getAlternativesForQuery($request);
1229
                        foreach ($alternatives as $alternative) {
1286
                        foreach ($alternatives as $alternative) {
1230
                                $ary_ = array();
1287
                                $ary_ = array();
1231
                                if ($obj = OIDplusObject::parse($alternative)) {
1288
                                if ($obj = OIDplusObject::parse($alternative)) {
1232
                                        if ($obj->userHasReadRights() && OIDplusObject::exists($alternative)) {
1289
                                        if ($obj->userHasReadRights() && OIDplusObject::exists($alternative)) {
1233
                                                do {
1290
                                                do {
1234
                                                        $ary_[] = $obj->nodeId();
1291
                                                        $ary_[] = $obj->nodeId();
1235
                                                } while ($obj = $obj->getParent());
1292
                                                } while ($obj = $obj->getParent());
1236
                                                $ary_ = array_reverse($ary_);
1293
                                                $ary_ = array_reverse($ary_);
1237
                                        }
1294
                                        }
1238
                                }
1295
                                }
1239
                                if (!empty($ary_)) {
1296
                                if (!empty($ary_)) {
1240
                                        $ary = $ary_;
1297
                                        $ary = $ary_;
1241
                                        break;
1298
                                        break;
1242
                                }
1299
                                }
1243
                        }
1300
                        }
1244
                }
1301
                }
1245
                return $ary;
1302
                return $ary;
1246
        }
1303
        }
1247
 
1304
 
1248
        /**
1305
        /**
1249
         * @var int
1306
         * @var int
1250
         */
1307
         */
1251
        private static $crudCounter = 0;
1308
        private static $crudCounter = 0;
1252
 
1309
 
1253
        /**
1310
        /**
1254
         * @param string $parent
1311
         * @param string $parent
1255
         * @return string
1312
         * @return string
1256
         * @throws OIDplusConfigInitializationException
1313
         * @throws OIDplusConfigInitializationException
1257
         * @throws OIDplusException
1314
         * @throws OIDplusException
1258
         */
1315
         */
1259
        protected static function showCrud(string $parent='oid:'): string {
1316
        protected static function showCrud(string $parent='oid:'): string {
1260
                $items_total = 0;
1317
                $items_total = 0;
1261
                $items_hidden = 0;
1318
                $items_hidden = 0;
1262
 
1319
 
1263
                $objParent = OIDplusObject::parse($parent);
1320
                $objParent = OIDplusObject::parse($parent);
1264
                if (!$objParent) return '';
1321
                if (!$objParent) return '';
1265
                $parentNS = $objParent::ns();
1322
                $parentNS = $objParent::ns();
1266
 
1323
 
1267
                // http://www.oid-info.com/cgi-bin/display?a=list-by-category&category=Not%20allocating%20identifiers
1324
                // http://www.oid-info.com/cgi-bin/display?a=list-by-category&category=Not%20allocating%20identifiers
1268
                $no_asn1 = array(
1325
                $no_asn1 = array(
1269
                        'oid:1.3.6.1.4.1',
1326
                        'oid:1.3.6.1.4.1',
1270
                        'oid:1.3.6.1.4.1.37476.9000',
1327
                        'oid:1.3.6.1.4.1.37476.9000',
1271
                        'oid:1.3.6.1.4.1.37553.8.8',
1328
                        'oid:1.3.6.1.4.1.37553.8.8',
1272
                        'oid:2.16.276.1',
1329
                        'oid:2.16.276.1',
1273
                        //'oid:2.25', // according to Olivier, it is OK that UUID owners define their own ASN.1 ID, since the ASN.1 ID is not required to be unique
1330
                        //'oid:2.25', // according to Olivier, it is OK that UUID owners define their own ASN.1 ID, since the ASN.1 ID is not required to be unique
1274
                        //'oid:1.2.840.113556.1.8000.2554' // Adhoc (GUID/UUID-based) customer use. It is probably the same case as the UUID OIDs, after all, these are UUIDs, too.
1331
                        //'oid:1.2.840.113556.1.8000.2554' // Adhoc (GUID/UUID-based) customer use. It is probably the same case as the UUID OIDs, after all, these are UUIDs, too.
1275
                );
1332
                );
1276
 
1333
 
1277
                // http://www.oid-info.com/cgi-bin/display?a=list-by-category&category=Not%20allocating%20Unicode%20labels
1334
                // http://www.oid-info.com/cgi-bin/display?a=list-by-category&category=Not%20allocating%20Unicode%20labels
1278
                $no_iri = array(
1335
                $no_iri = array(
1279
                        'oid:1.2.250.1',
1336
                        'oid:1.2.250.1',
1280
                        'oid:1.3.6.1.4.1',
1337
                        'oid:1.3.6.1.4.1',
1281
                        'oid:1.3.6.1.4.1.37476.9000',
1338
                        'oid:1.3.6.1.4.1.37476.9000',
1282
                        'oid:1.3.6.1.4.1.37553.8.8',
1339
                        'oid:1.3.6.1.4.1.37553.8.8',
1283
                        'oid:2.16.276.1',
1340
                        'oid:2.16.276.1',
1284
                        'oid:2.25'
1341
                        'oid:2.25'
1285
                );
1342
                );
1286
 
1343
 
1287
                $accepts_asn1 = ($parentNS == 'oid') && (!in_array($objParent->nodeId(), $no_asn1)) && (!is_uuid_oid($objParent->nodeId(),true));
1344
                $accepts_asn1 = ($parentNS == 'oid') && (!in_array($objParent->nodeId(), $no_asn1)) && (!is_uuid_oid($objParent->nodeId(),true));
1288
                $accepts_iri  = ($parentNS == 'oid') && (!in_array($objParent->nodeId(), $no_iri)) && (!is_uuid_oid($objParent->nodeId(),true));
1345
                $accepts_iri  = ($parentNS == 'oid') && (!in_array($objParent->nodeId(), $no_iri)) && (!is_uuid_oid($objParent->nodeId(),true));
1289
 
1346
 
1290
                $result = OIDplus::db()->query("select o.*, r.ra_name " .
1347
                $result = OIDplus::db()->query("select o.*, r.ra_name " .
1291
                                               "from ###objects o " .
1348
                                               "from ###objects o " .
1292
                                               "left join ###ra r on r.email = o.ra_email " .
1349
                                               "left join ###ra r on r.email = o.ra_email " .
1293
                                               "where parent = ? ", array($parent));
1350
                                               "where parent = ? ", array($parent));
1294
                $result->naturalSortByField('id');
1351
                $result->naturalSortByField('id');
1295
 
1352
 
1296
                $rows = array();
1353
                $rows = array();
1297
                while ($row = $result->fetch_object()) {
1354
                while ($row = $result->fetch_object()) {
1298
                        $obj = OIDplusObject::parse($row->id);
1355
                        $obj = OIDplusObject::parse($row->id);
1299
                        if ($obj) $rows[] = array($obj,$row);
1356
                        if ($obj) $rows[] = array($obj,$row);
1300
                }
1357
                }
1301
 
1358
 
1302
                $enable_weid_presentation = OIDplus::config()->getValue('oid_grid_show_weid');
1359
                $enable_weid_presentation = OIDplus::config()->getValue('oid_grid_show_weid');
1303
 
1360
 
1304
                $output  = '<div class="container box"><div id="suboid_table" class="table-responsive">';
1361
                $output  = '<div class="container box"><div id="suboid_table" class="table-responsive">';
1305
                $output .= '<table id="crudTable" class="table table-bordered table-striped">';
1362
                $output .= '<table id="crudTable" class="table table-bordered table-striped">';
1306
                $output .= '<thead>';
1363
                $output .= '<thead>';
1307
                $output .= '    <tr>';
1364
                $output .= '    <tr>';
1308
                $output .= '         <th>'._L('ID').(($parentNS == 'gs1') ? ' '._L('(without check digit)') : '').'</th>';
1365
                $output .= '         <th>'._L('ID').(($parentNS == 'gs1') ? ' '._L('(without check digit)') : '').'</th>';
1309
                if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) {
1366
                if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) {
1310
                        $output .= '         <th><abbr title="'._L('Binary-to-text encoding used for WEIDs').'">'._L('Base36').'</abbr></th>';
1367
                        $output .= '         <th><abbr title="'._L('Binary-to-text encoding used for WEIDs').'">'._L('Base36').'</abbr></th>';
1311
                }
1368
                }
1312
                if ($parentNS == 'oid') {
1369
                if ($parentNS == 'oid') {
1313
                        if ($accepts_asn1) $output .= '      <th>'._L('ASN.1 IDs (comma sep.)').'</th>';
1370
                        if ($accepts_asn1) $output .= '      <th>'._L('ASN.1 IDs (comma sep.)').'</th>';
1314
                        if ($accepts_iri)  $output .= '      <th>'._L('IRI IDs (comma sep.)').'</th>';
1371
                        if ($accepts_iri)  $output .= '      <th>'._L('IRI IDs (comma sep.)').'</th>';
1315
                }
1372
                }
1316
                $output .= '         <th>'._L('RA').'</th>';
1373
                $output .= '         <th>'._L('RA').'</th>';
1317
                $output .= '         <th>'._L('Comment').'</th>';
1374
                $output .= '         <th>'._L('Comment').'</th>';
1318
                if ($objParent->userHasWriteRights()) {
1375
                if ($objParent->userHasWriteRights()) {
1319
                        $output .= '         <th>'._L('Hide').'</th>';
1376
                        $output .= '         <th>'._L('Hide').'</th>';
1320
                        $output .= '         <th>'._L('Update').'</th>';
1377
                        $output .= '         <th>'._L('Update').'</th>';
1321
                        $output .= '         <th>'._L('Delete').'</th>';
1378
                        $output .= '         <th>'._L('Delete').'</th>';
1322
                }
1379
                }
1323
                $output .= '         <th>'._L('Created').'</th>';
1380
                $output .= '         <th>'._L('Created').'</th>';
1324
                $output .= '         <th>'._L('Updated').'</th>';
1381
                $output .= '         <th>'._L('Updated').'</th>';
1325
                $output .= '    </tr>';
1382
                $output .= '    </tr>';
1326
                $output .= '</thead>';
1383
                $output .= '</thead>';
1327
 
1384
 
1328
                $output .= '<tbody>';
1385
                $output .= '<tbody>';
1329
                foreach ($rows as list($obj,$row)) {
1386
                foreach ($rows as list($obj,$row)) {
1330
                        $items_total++;
1387
                        $items_total++;
1331
                        if (!$obj->userHasReadRights()) {
1388
                        if (!$obj->userHasReadRights()) {
1332
                                $items_hidden++;
1389
                                $items_hidden++;
1333
                                continue;
1390
                                continue;
1334
                        }
1391
                        }
1335
 
1392
 
1336
                        $show_id = $obj->crudShowId($objParent);
1393
                        $show_id = $obj->crudShowId($objParent);
1337
 
1394
 
1338
                        $asn1ids = array();
1395
                        $asn1ids = array();
1339
                        $res2 = OIDplus::db()->query("select name from ###asn1id where oid = ? order by lfd", array($row->id));
1396
                        $res2 = OIDplus::db()->query("select name from ###asn1id where oid = ? order by lfd", array($row->id));
1340
                        while ($row2 = $res2->fetch_array()) {
1397
                        while ($row2 = $res2->fetch_array()) {
1341
                                $asn1ids[] = $row2['name'];
1398
                                $asn1ids[] = $row2['name'];
1342
                        }
1399
                        }
1343
 
1400
 
1344
                        $iris = array();
1401
                        $iris = array();
1345
                        $res2 = OIDplus::db()->query("select name from ###iri where oid = ? order by lfd", array($row->id));
1402
                        $res2 = OIDplus::db()->query("select name from ###iri where oid = ? order by lfd", array($row->id));
1346
                        while ($row2 = $res2->fetch_array()) {
1403
                        while ($row2 = $res2->fetch_array()) {
1347
                                $iris[] = $row2['name'];
1404
                                $iris[] = $row2['name'];
1348
                        }
1405
                        }
1349
 
1406
 
1350
                        $date_created = is_null($row->created) || (explode(' ', $row->created)[0] == '0000-00-00') ? '' : explode(' ', $row->created)[0];
1407
                        $date_created = is_null($row->created) || (explode(' ', $row->created)[0] == '0000-00-00') ? '' : explode(' ', $row->created)[0];
1351
                        $date_updated = is_null($row->updated) || (explode(' ', $row->updated)[0] == '0000-00-00') ? '' : explode(' ', $row->updated)[0];
1408
                        $date_updated = is_null($row->updated) || (explode(' ', $row->updated)[0] == '0000-00-00') ? '' : explode(' ', $row->updated)[0];
1352
 
1409
 
1353
                        $output .= '<tr>';
1410
                        $output .= '<tr>';
1354
                        $output .= '     <td><a href="?goto='.urlencode($row->id).'" onclick="openAndSelectNode('.js_escape($row->id).', '.js_escape($parent).'); return false;">'.htmlentities($show_id).'</a>';
1411
                        $output .= '     <td><a href="?goto='.urlencode($row->id).'" onclick="openAndSelectNode('.js_escape($row->id).', '.js_escape($parent).'); return false;">'.htmlentities($show_id).'</a>';
1355
                        if ($enable_weid_presentation && ($parentNS == 'oid') && $objParent->isRoot()) {
1412
                        if ($enable_weid_presentation && ($parentNS == 'oid') && $objParent->isRoot()) {
1356
                                // To save space horizontal space, the WEIDs were written below the OIDs
1413
                                // To save space horizontal space, the WEIDs were written below the OIDs
1357
                                assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
1414
                                assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
1358
                                $output .= '<br>'.$obj->getWeidNotation(true);
1415
                                $output .= '<br>'.$obj->getWeidNotation(true);
1359
                        }
1416
                        }
1360
                        $output .= '</td>';
1417
                        $output .= '</td>';
1361
                        if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) {
1418
                        if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) {
1362
                                assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
1419
                                assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
1363
                                $output .= '    <td>'.htmlentities($obj->weidArc()).'</td>';
1420
                                $output .= '    <td>'.htmlentities($obj->weidArc()).'</td>';
1364
                        }
1421
                        }
1365
                        if ($objParent->userHasWriteRights()) {
1422
                        if ($objParent->userHasWriteRights()) {
1366
                                if ($parentNS == 'oid') {
1423
                                if ($parentNS == 'oid') {
1367
                                        if ($accepts_asn1) $output .= '     <td><input type="text" id="asn1ids_'.$row->id.'" value="'.implode(', ', $asn1ids).'"></td>';
1424
                                        if ($accepts_asn1) $output .= '     <td><input type="text" id="asn1ids_'.$row->id.'" value="'.implode(', ', $asn1ids).'"></td>';
1368
                                        if ($accepts_iri)  $output .= '     <td><input type="text" id="iris_'.$row->id.'" value="'.implode(', ', $iris).'"></td>';
1425
                                        if ($accepts_iri)  $output .= '     <td><input type="text" id="iris_'.$row->id.'" value="'.implode(', ', $iris).'"></td>';
1369
                                }
1426
                                }
1370
                                $output .= '     <td><input type="text" id="ra_email_'.$row->id.'" value="'.htmlentities($row->ra_email ?? '').'"></td>';
1427
                                $output .= '     <td><input type="text" id="ra_email_'.$row->id.'" value="'.htmlentities($row->ra_email ?? '').'"></td>';
1371
                                $output .= '     <td><input type="text" id="comment_'.$row->id.'" value="'.htmlentities($row->comment ?? '').'"></td>';
1428
                                $output .= '     <td><input type="text" id="comment_'.$row->id.'" value="'.htmlentities($row->comment ?? '').'"></td>';
1372
                                $output .= '     <td><input type="checkbox" id="hide_'.$row->id.'" '.($row->confidential ? 'checked' : '').'></td>';
1429
                                $output .= '     <td><input type="checkbox" id="hide_'.$row->id.'" '.($row->confidential ? 'checked' : '').'></td>';
1373
                                $output .= '     <td><button type="button" name="update_'.$row->id.'" id="update_'.$row->id.'" class="btn btn-success btn-xs update" onclick="OIDplusPagePublicObjects.crudActionUpdate('.js_escape($row->id).', '.js_escape($parent).')">'._L('Update').'</button></td>';
1430
                                $output .= '     <td><button type="button" name="update_'.$row->id.'" id="update_'.$row->id.'" class="btn btn-success btn-xs update" onclick="OIDplusPagePublicObjects.crudActionUpdate('.js_escape($row->id).', '.js_escape($parent).')">'._L('Update').'</button></td>';
1374
                                $output .= '     <td><button type="button" name="delete_'.$row->id.'" id="delete_'.$row->id.'" class="btn btn-danger btn-xs delete" onclick="OIDplusPagePublicObjects.crudActionDelete('.js_escape($row->id).', '.js_escape($parent).')">'._L('Delete').'</button></td>';
1431
                                $output .= '     <td><button type="button" name="delete_'.$row->id.'" id="delete_'.$row->id.'" class="btn btn-danger btn-xs delete" onclick="OIDplusPagePublicObjects.crudActionDelete('.js_escape($row->id).', '.js_escape($parent).')">'._L('Delete').'</button></td>';
1375
                                $output .= '     <td>'.$date_created.'</td>';
1432
                                $output .= '     <td>'.$date_created.'</td>';
1376
                                $output .= '     <td>'.$date_updated.'</td>';
1433
                                $output .= '     <td>'.$date_updated.'</td>';
1377
                        } else {
1434
                        } else {
1378
                                if ($parentNS == 'oid') {
1435
                                if ($parentNS == 'oid') {
1379
                                        if ($asn1ids == '') $asn1ids = '<i>'._L('(none)').'</i>';
1436
                                        if ($asn1ids == '') $asn1ids = '<i>'._L('(none)').'</i>';
1380
                                        if ($iris == '') $iris = '<i>'._L('(none)').'</i>';
1437
                                        if ($iris == '') $iris = '<i>'._L('(none)').'</i>';
1381
                                        $asn1ids_ext = array();
1438
                                        $asn1ids_ext = array();
1382
                                        foreach ($asn1ids as $asn1id) {
1439
                                        foreach ($asn1ids as $asn1id) {
1383
                                                $asn1ids_ext[] = '<a href="?goto='.urlencode($row->id).'" onclick="openAndSelectNode('.js_escape($row->id).', '.js_escape($parent).'); return false;">'.$asn1id.'</a>';
1440
                                                $asn1ids_ext[] = '<a href="?goto='.urlencode($row->id).'" onclick="openAndSelectNode('.js_escape($row->id).', '.js_escape($parent).'); return false;">'.$asn1id.'</a>';
1384
                                        }
1441
                                        }
1385
                                        if ($accepts_asn1) $output .= '     <td>'.implode(', ', $asn1ids_ext).'</td>';
1442
                                        if ($accepts_asn1) $output .= '     <td>'.implode(', ', $asn1ids_ext).'</td>';
1386
                                        if ($accepts_iri)  $output .= '     <td>'.implode(', ', $iris).'</td>';
1443
                                        if ($accepts_iri)  $output .= '     <td>'.implode(', ', $iris).'</td>';
1387
                                }
1444
                                }
1388
                                $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>';
1445
                                $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>';
1389
                                $output .= '     <td>'.htmlentities($row->comment ?? '').'</td>';
1446
                                $output .= '     <td>'.htmlentities($row->comment ?? '').'</td>';
1390
                                $output .= '     <td>'.$date_created.'</td>';
1447
                                $output .= '     <td>'.$date_created.'</td>';
1391
                                $output .= '     <td>'.$date_updated.'</td>';
1448
                                $output .= '     <td>'.$date_updated.'</td>';
1392
                        }
1449
                        }
1393
                        $output .= '</tr>';
1450
                        $output .= '</tr>';
1394
                }
1451
                }
1395
                $output .= '</tbody>';
1452
                $output .= '</tbody>';
1396
 
1453
 
1397
                $parent_ra_email = $objParent->getRaMail() ;
1454
                $parent_ra_email = $objParent->getRaMail() ;
1398
 
1455
 
1399
                // "Create OID" row
1456
                // "Create OID" row
1400
                if ($objParent->userHasWriteRights()) {
1457
                if ($objParent->userHasWriteRights()) {
1401
                        $output .= '<tfoot>';
1458
                        $output .= '<tfoot>';
1402
                        $output .= '<tr>';
1459
                        $output .= '<tr>';
1403
                        $prefix = $objParent->crudInsertPrefix();
1460
                        $prefix = $objParent->crudInsertPrefix();
1404
 
1461
 
1405
                        $suffix = $objParent->crudInsertSuffix();
1462
                        $suffix = $objParent->crudInsertSuffix();
1406
                        foreach (OIDplus::getObjectTypePlugins() as $plugin) {
1463
                        foreach (OIDplus::getObjectTypePlugins() as $plugin) {
1407
                                if (($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_6) && ($plugin::getObjectTypeClassName()::ns() == $parentNS)) {
1464
                                if (($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_6) && ($plugin::getObjectTypeClassName()::ns() == $parentNS)) {
1408
                                        $suffix .= $plugin->gridGeneratorLinks($objParent);
1465
                                        $suffix .= $plugin->gridGeneratorLinks($objParent);
1409
                                }
1466
                                }
1410
                        }
1467
                        }
1411
 
1468
 
1412
                        if ($parentNS == 'guid') {
1469
                        if ($parentNS == 'guid') {
1413
                                $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:275px">'.$suffix.'</td>';
1470
                                $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:275px">'.$suffix.'</td>';
1414
                        } else if ($parentNS == 'oid') {
1471
                        } else if ($parentNS == 'oid') {
1415
                                // TODO: Idea: Give a class name, e.g. "OID" and then with a oid-specific CSS make the width individual. So, every plugin has more control over the appearance and widths of the input fields
1472
                                // TODO: Idea: Give a class name, e.g. "OID" and then with a oid-specific CSS make the width individual. So, every plugin has more control over the appearance and widths of the input fields
1416
                                if ($objParent->nodeId() === 'oid:2.25') {
1473
                                if ($objParent->nodeId() === 'oid:2.25') {
1417
                                        $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:345px">'.$suffix.'</td>';
1474
                                        $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:345px">'.$suffix.'</td>';
1418
                                        if ($enable_weid_presentation) $output .= '     <td>&nbsp;</td>'; // For UUID-OIDs, you must generate a valid one. Don't be tempted to create one using the Base36 input!
1475
                                        if ($enable_weid_presentation) $output .= '     <td>&nbsp;</td>'; // For UUID-OIDs, you must generate a valid one. Don't be tempted to create one using the Base36 input!
1419
                                } else if ($objParent->isRoot()) {
1476
                                } else if ($objParent->isRoot()) {
1420
                                        $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:345px">'.$suffix.'</td>';
1477
                                        $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:345px">'.$suffix.'</td>';
1421
                                        if ($enable_weid_presentation) $output .= ''; // WEID-editor not available for root nodes at the moment. For the moment you need to enter the OID (TODO: Create JavaScript WEID encoder/decoder)
1478
                                        if ($enable_weid_presentation) $output .= ''; // WEID-editor not available for root nodes at the moment. For the moment you need to enter the OID (TODO: Create JavaScript WEID encoder/decoder)
1422
                                } else {
1479
                                } else {
1423
                                        if ($enable_weid_presentation) {
1480
                                        if ($enable_weid_presentation) {
1424
                                                $output .= '     <td>'.$prefix.' <input oninput="OIDplusPagePublicObjects.frdl_oidid_change()" type="text" id="id" value="" style="width:100%;min-width:100px">'.$suffix.'</td>';
1481
                                                $output .= '     <td>'.$prefix.' <input oninput="OIDplusPagePublicObjects.frdl_oidid_change()" type="text" id="id" value="" style="width:100%;min-width:100px">'.$suffix.'</td>';
1425
                                                $output .= '     <td><input type="text" name="weid" id="weid" value="" oninput="OIDplusPagePublicObjects.frdl_weid_change()" style="width:100%;min-width:100px"></td>';
1482
                                                $output .= '     <td><input type="text" name="weid" id="weid" value="" oninput="OIDplusPagePublicObjects.frdl_weid_change()" style="width:100%;min-width:100px"></td>';
1426
                                        } else {
1483
                                        } else {
1427
                                                $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:100px">'.$suffix.'</td>';
1484
                                                $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:100px">'.$suffix.'</td>';
1428
                                        }
1485
                                        }
1429
                                }
1486
                                }
1430
                        } else {
1487
                        } else {
1431
                                $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:100px">'.$suffix.'</td>';
1488
                                $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:100px">'.$suffix.'</td>';
1432
                        }
1489
                        }
1433
                        if ($accepts_asn1) $output .= '     <td><input type="text" id="asn1ids" value=""></td>';
1490
                        if ($accepts_asn1) $output .= '     <td><input type="text" id="asn1ids" value=""></td>';
1434
                        if ($accepts_iri)  $output .= '     <td><input type="text" id="iris" value=""></td>';
1491
                        if ($accepts_iri)  $output .= '     <td><input type="text" id="iris" value=""></td>';
1435
                        $output .= '     <td><input type="text" id="ra_email" value="'.htmlentities($parent_ra_email ?? '').'"></td>';
1492
                        $output .= '     <td><input type="text" id="ra_email" value="'.htmlentities($parent_ra_email ?? '').'"></td>';
1436
                        $output .= '     <td><input type="text" id="comment" value=""></td>';
1493
                        $output .= '     <td><input type="text" id="comment" value=""></td>';
1437
                        $output .= '     <td><input type="checkbox" id="hide"></td>';
1494
                        $output .= '     <td><input type="checkbox" id="hide"></td>';
1438
                        $output .= '     <td><button type="button" name="insert" id="insert" class="btn btn-success btn-xs update" onclick="OIDplusPagePublicObjects.crudActionInsert('.js_escape($parent).')">'._L('Insert').'</button></td>';
1495
                        $output .= '     <td><button type="button" name="insert" id="insert" class="btn btn-success btn-xs update" onclick="OIDplusPagePublicObjects.crudActionInsert('.js_escape($parent).')">'._L('Insert').'</button></td>';
1439
                        $output .= '     <td></td>';
1496
                        $output .= '     <td></td>';
1440
                        $output .= '     <td></td>';
1497
                        $output .= '     <td></td>';
1441
                        $output .= '     <td></td>';
1498
                        $output .= '     <td></td>';
1442
                        $output .= '</tr>';
1499
                        $output .= '</tr>';
1443
                        $output .= '</tfoot>';
1500
                        $output .= '</tfoot>';
1444
                } else {
1501
                } else {
1445
                        if ($items_total-$items_hidden == 0) {
1502
                        if ($items_total-$items_hidden == 0) {
1446
                                $cols = ($parentNS == 'oid') ? 7 : 5;
1503
                                $cols = ($parentNS == 'oid') ? 7 : 5;
1447
                                if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) {
1504
                                if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) {
1448
                                        $cols++;
1505
                                        $cols++;
1449
                                }
1506
                                }
1450
                                $output .= '<tfoot>';
1507
                                $output .= '<tfoot>';
1451
                                $output .= '<tr><td colspan="'.$cols.'">'._L('No items available').'</td></tr>';
1508
                                $output .= '<tr><td colspan="'.$cols.'">'._L('No items available').'</td></tr>';
1452
                                $output .= '</tfoot>';
1509
                                $output .= '</tfoot>';
1453
                        }
1510
                        }
1454
                }
1511
                }
1455
 
1512
 
1456
                $output .= '</table>';
1513
                $output .= '</table>';
1457
                $output .= '</div></div>';
1514
                $output .= '</div></div>';
1458
 
1515
 
1459
                if ($items_hidden == 1) {
1516
                if ($items_hidden == 1) {
1460
                        $output .= '<p>'._L('One item is hidden. Please <a %1>log in</a> to see it.',$items_hidden,OIDplus::gui()->link('oidplus:login')).'</p>';
1517
                        $output .= '<p>'._L('One item is hidden. Please <a %1>log in</a> to see it.',$items_hidden,OIDplus::gui()->link('oidplus:login')).'</p>';
1461
                } else if ($items_hidden > 1) {
1518
                } else if ($items_hidden > 1) {
1462
                        $output .= '<p>'._L('%1 items are hidden. Please <a %2>log in</a> to see them.',$items_hidden,OIDplus::gui()->link('oidplus:login')).'</p>';
1519
                        $output .= '<p>'._L('%1 items are hidden. Please <a %2>log in</a> to see them.',$items_hidden,OIDplus::gui()->link('oidplus:login')).'</p>';
1463
                }
1520
                }
1464
 
1521
 
1465
                return $output;
1522
                return $output;
1466
        }
1523
        }
1467
 
1524
 
1468
        /**
1525
        /**
1469
         * @param string $html
1526
         * @param string $html
1470
         * @return string
1527
         * @return string
1471
         */
1528
         */
1472
        protected static function objDescription(string $html): string {
1529
        protected static function objDescription(string $html): string {
1473
                // We allow HTML, but no hacking
1530
                // We allow HTML, but no hacking
1474
                $html = anti_xss($html);
1531
                $html = anti_xss($html);
1475
 
1532
 
1476
                return trim_br($html);
1533
                return trim_br($html);
1477
        }
1534
        }
1478
 
1535
 
1479
        /**
1536
        /**
1480
         * 'quickbars' added 11 July 2019: Disabled because of two problems:
1537
         * 'quickbars' added 11 July 2019: Disabled because of two problems:
1481
         *                                 1. When you load TinyMCE via AJAX using the left menu, the quickbar is immediately shown, even if TinyMCE does not have the focus
1538
         *                                 1. When you load TinyMCE via AJAX using the left menu, the quickbar is immediately shown, even if TinyMCE does not have the focus
1482
         *                                 2. When you load a page without TinyMCE using the left menu, the quickbar is still visible, although there is no edit
1539
         *                                 2. When you load a page without TinyMCE using the left menu, the quickbar is still visible, although there is no edit
1483
         * 'colorpicker', 'textcolor' and 'contextmenu' added in 07 April 2020, because it is built in in the core.
1540
         * 'colorpicker', 'textcolor' and 'contextmenu' added in 07 April 2020, because it is built in in the core.
1484
         * 'importcss' added 17 September 2020, because it breaks the "Format/Style" dropdown box ("styleselect" toolbar)
1541
         * 'importcss' added 17 September 2020, because it breaks the "Format/Style" dropdown box ("styleselect" toolbar)
1485
         * 'legacyoutput' added 24 September 2021, because it is declared as deprecated
1542
         * 'legacyoutput' added 24 September 2021, because it is declared as deprecated
1486
         * 'spellchecker' added 6 October 2021, because it is declared as deprecated and marked for removal in TinyMCE 6.0
1543
         * 'spellchecker' added 6 October 2021, because it is declared as deprecated and marked for removal in TinyMCE 6.0
1487
         * 'imagetools' and 'toc' added 23 February 2022, because they are declared as deprecated and marked for removal in TinyMCE 6.0 ("moving to premium")
1544
         * 'imagetools' and 'toc' added 23 February 2022, because they are declared as deprecated and marked for removal in TinyMCE 6.0 ("moving to premium")
1488
         * @var string[]
1545
         * @var string[]
1489
         */
1546
         */
1490
        public static $exclude_tinymce_plugins = array('fullpage', 'bbcode', 'quickbars', 'colorpicker', 'textcolor', 'contextmenu', 'importcss', 'legacyoutput', 'spellchecker', 'imagetools', 'toc');
1547
        public static $exclude_tinymce_plugins = array('fullpage', 'bbcode', 'quickbars', 'colorpicker', 'textcolor', 'contextmenu', 'importcss', 'legacyoutput', 'spellchecker', 'imagetools', 'toc');
1491
 
1548
 
1492
        /**
1549
        /**
1493
         * @param string $name
1550
         * @param string $name
1494
         * @param string $content
1551
         * @param string $content
1495
         * @return string
1552
         * @return string
1496
         * @throws OIDplusConfigInitializationException
1553
         * @throws OIDplusConfigInitializationException
1497
         * @throws OIDplusException
1554
         * @throws OIDplusException
1498
         */
1555
         */
1499
        protected static function showMCE(string $name, string $content): string {
1556
        protected static function showMCE(string $name, string $content): string {
1500
                $mce_plugins = array();
1557
                $mce_plugins = array();
1501
                foreach (glob(OIDplus::localpath().'vendor/tinymce/tinymce/plugins/*') as $m) { // */
1558
                foreach (glob(OIDplus::localpath().'vendor/tinymce/tinymce/plugins/*') as $m) { // */
1502
                        $mce_plugins[] = basename($m);
1559
                        $mce_plugins[] = basename($m);
1503
                }
1560
                }
1504
 
1561
 
1505
                foreach (self::$exclude_tinymce_plugins as $exclude) {
1562
                foreach (self::$exclude_tinymce_plugins as $exclude) {
1506
                        $index = array_search($exclude, $mce_plugins);
1563
                        $index = array_search($exclude, $mce_plugins);
1507
                        if ($index !== false) unset($mce_plugins[$index]);
1564
                        if ($index !== false) unset($mce_plugins[$index]);
1508
                }
1565
                }
1509
 
1566
 
1510
                $oidplusLang = OIDplus::getCurrentLang();
1567
                $oidplusLang = OIDplus::getCurrentLang();
1511
 
1568
 
1512
                $langCandidates = array(
1569
                $langCandidates = array(
1513
                        strtolower(substr($oidplusLang,0,2)).'_'.strtoupper(substr($oidplusLang,2,2)), // de_DE
1570
                        strtolower(substr($oidplusLang,0,2)).'_'.strtoupper(substr($oidplusLang,2,2)), // de_DE
1514
                        strtolower(substr($oidplusLang,0,2)) // de
1571
                        strtolower(substr($oidplusLang,0,2)) // de
1515
                );
1572
                );
1516
                $tinyMCELang = '';
1573
                $tinyMCELang = '';
1517
                foreach ($langCandidates as $candidate) {
1574
                foreach ($langCandidates as $candidate) {
1518
                        if (file_exists(OIDplus::localpath().'vendor/tweeb/tinymce-i18n/langs/'.$candidate.'.js')) {
1575
                        if (file_exists(OIDplus::localpath().'vendor/tweeb/tinymce-i18n/langs/'.$candidate.'.js')) {
1519
                                $tinyMCELang = $candidate;
1576
                                $tinyMCELang = $candidate;
1520
                                break;
1577
                                break;
1521
                        }
1578
                        }
1522
                }
1579
                }
1523
 
1580
 
1524
                $out = '<script>
1581
                $out = '<script>
1525
                                tinymce.EditorManager.baseURL = "vendor/tinymce/tinymce";
1582
                                tinymce.EditorManager.baseURL = "vendor/tinymce/tinymce";
1526
                                tinymce.init({
1583
                                tinymce.init({
1527
                                        document_base_url: "'.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'",
1584
                                        document_base_url: "'.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'",
1528
                                        selector: "#'.$name.'",
1585
                                        selector: "#'.$name.'",
1529
                                        height: 200,
1586
                                        height: 200,
1530
                                        statusbar: false,
1587
                                        statusbar: false,
1531
//                                      menubar:false,
1588
//                                      menubar:false,
1532
//                                      toolbar: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table | fontsizeselect",
1589
//                                      toolbar: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table | fontsizeselect",
1533
                                        toolbar: "undo redo | styleselect | bold italic underline forecolor | bullist numlist | outdent indent | table | fontsizeselect",
1590
                                        toolbar: "undo redo | styleselect | bold italic underline forecolor | bullist numlist | outdent indent | table | fontsizeselect",
1534
                                        plugins: "'.implode(' ', $mce_plugins).'",
1591
                                        plugins: "'.implode(' ', $mce_plugins).'",
1535
                                        mobile: {
1592
                                        mobile: {
1536
                                                theme: "mobile",
1593
                                                theme: "mobile",
1537
                                                toolbar: "undo redo | styleselect | bold italic underline forecolor | bullist numlist | outdent indent | table | fontsizeselect",
1594
                                                toolbar: "undo redo | styleselect | bold italic underline forecolor | bullist numlist | outdent indent | table | fontsizeselect",
1538
                                                plugins: "'.implode(' ', $mce_plugins).'"
1595
                                                plugins: "'.implode(' ', $mce_plugins).'"
1539
                                        }
1596
                                        }
1540
                                        '.($tinyMCELang == '' ? '' : ', language : "'.$tinyMCELang.'"').'
1597
                                        '.($tinyMCELang == '' ? '' : ', language : "'.$tinyMCELang.'"').'
1541
                                        '.($tinyMCELang == '' ? '' : ', language_url : "'.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'vendor/tweeb/tinymce-i18n/langs/'.$tinyMCELang.'.js"').'
1598
                                        '.($tinyMCELang == '' ? '' : ', language_url : "'.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'vendor/tweeb/tinymce-i18n/langs/'.$tinyMCELang.'.js"').'
1542
                                });
1599
                                });
1543
 
1600
 
1544
                                pageChangeRequestCallbacks.push([OIDplusPagePublicObjects.cbQueryTinyMCE, "#'.$name.'"]);
1601
                                pageChangeRequestCallbacks.push([OIDplusPagePublicObjects.cbQueryTinyMCE, "#'.$name.'"]);
1545
                                pageChangeCallbacks.push([OIDplusPagePublicObjects.cbRemoveTinyMCE, "#'.$name.'"]);
1602
                                pageChangeCallbacks.push([OIDplusPagePublicObjects.cbRemoveTinyMCE, "#'.$name.'"]);
1546
                        </script>';
1603
                        </script>';
1547
 
1604
 
1548
                $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?
1605
                $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?
1549
 
1606
 
1550
                $out .= '<textarea name="'.htmlentities($name).'" id="'.htmlentities($name).'">'.trim($content).'</textarea><br>';
1607
                $out .= '<textarea name="'.htmlentities($name).'" id="'.htmlentities($name).'">'.trim($content).'</textarea><br>';
1551
 
1608
 
1552
                return $out;
1609
                return $out;
1553
        }
1610
        }
1554
 
1611
 
1555
        /**
1612
        /**
1556
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1
1613
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1
1557
         * @return bool
1614
         * @return bool
1558
         * @throws OIDplusException
1615
         * @throws OIDplusException
1559
         */
1616
         */
1560
        public function oobeRequested(): bool {
1617
        public function oobeRequested(): bool {
1561
                return OIDplus::config()->getValue('oobe_objects_done') == '0';
1618
                return OIDplus::config()->getValue('oobe_objects_done') == '0';
1562
        }
1619
        }
1563
 
1620
 
1564
        /**
1621
        /**
1565
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1
1622
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1
1566
         * @param int $step
1623
         * @param int $step
1567
         * @param bool $do_edits
1624
         * @param bool $do_edits
1568
         * @param bool $errors_happened
1625
         * @param bool $errors_happened
1569
         * @return void
1626
         * @return void
1570
         */
1627
         */
1571
        public function oobeEntry(int $step, bool $do_edits, bool &$errors_happened)/*: void*/ {
1628
        public function oobeEntry(int $step, bool $do_edits, bool &$errors_happened)/*: void*/ {
1572
                echo '<h2>'._L('Step %1: Enable/Disable object type plugins',$step).'</h2>';
1629
                echo '<h2>'._L('Step %1: Enable/Disable object type plugins',$step).'</h2>';
1573
                echo '<p>'._L('Which object types do you want to manage using OIDplus?').'</p>';
1630
                echo '<p>'._L('Which object types do you want to manage using OIDplus?').'</p>';
1574
 
1631
 
1575
                $enabled_ary = array();
1632
                $enabled_ary = array();
1576
 
1633
 
1577
                foreach (OIDplus::getEnabledObjectTypes() as $ot) {
1634
                foreach (OIDplus::getEnabledObjectTypes() as $ot) {
1578
                        echo '<input type="checkbox" name="enable_ot_'.$ot::ns().'" id="enable_ot_'.$ot::ns().'"';
1635
                        echo '<input type="checkbox" name="enable_ot_'.$ot::ns().'" id="enable_ot_'.$ot::ns().'"';
1579
                        if (isset($_POST['sent'])) {
1636
                        if (isset($_POST['sent'])) {
1580
                                if (isset($_POST['enable_ot_'.$ot::ns()])) {
1637
                                if (isset($_POST['enable_ot_'.$ot::ns()])) {
1581
                                        echo ' checked';
1638
                                        echo ' checked';
1582
                                        $enabled_ary[] = $ot::ns();
1639
                                        $enabled_ary[] = $ot::ns();
1583
                                }
1640
                                }
1584
                        } else {
1641
                        } else {
1585
                                echo ' checked';
1642
                                echo ' checked';
1586
                        }
1643
                        }
1587
                        echo '> <label for="enable_ot_'.$ot::ns().'">'.htmlentities($ot::objectTypeTitle()).'</label><br>';
1644
                        echo '> <label for="enable_ot_'.$ot::ns().'">'.htmlentities($ot::objectTypeTitle()).'</label><br>';
1588
                }
1645
                }
1589
 
1646
 
1590
                foreach (OIDplus::getDisabledObjectTypes() as $ot) {
1647
                foreach (OIDplus::getDisabledObjectTypes() as $ot) {
1591
                        echo '<input type="checkbox" name="enable_ot_'.$ot::ns().'" id="enable_ot_'.$ot::ns().'"';
1648
                        echo '<input type="checkbox" name="enable_ot_'.$ot::ns().'" id="enable_ot_'.$ot::ns().'"';
1592
                        if (isset($_POST['sent'])) {
1649
                        if (isset($_POST['sent'])) {
1593
                                if (isset($_POST['enable_ot_'.$ot::ns()])) {
1650
                                if (isset($_POST['enable_ot_'.$ot::ns()])) {
1594
                                        echo ' checked';
1651
                                        echo ' checked';
1595
                                        $enabled_ary[] = $ot::ns();
1652
                                        $enabled_ary[] = $ot::ns();
1596
                                }
1653
                                }
1597
                        } else {
1654
                        } else {
1598
                                echo ''; // <-- difference
1655
                                echo ''; // <-- difference
1599
                        }
1656
                        }
1600
                        echo '> <label for="enable_ot_'.$ot::ns().'">'.htmlentities($ot::objectTypeTitle()).'</label><br>';
1657
                        echo '> <label for="enable_ot_'.$ot::ns().'">'.htmlentities($ot::objectTypeTitle()).'</label><br>';
1601
                }
1658
                }
1602
 
1659
 
1603
                $htmlmsg = '';
1660
                $htmlmsg = '';
1604
                if ($do_edits) {
1661
                if ($do_edits) {
1605
                        try {
1662
                        try {
1606
                                OIDplus::config()->setValue('objecttypes_enabled', implode(';', $enabled_ary));
1663
                                OIDplus::config()->setValue('objecttypes_enabled', implode(';', $enabled_ary));
1607
                                OIDplus::config()->setValue('oobe_objects_done', '1');
1664
                                OIDplus::config()->setValue('oobe_objects_done', '1');
1608
                        } catch (\Exception $e) {
1665
                        } catch (\Exception $e) {
1609
                                $htmlmsg = $e instanceof OIDplusException ? $e->getHtmlMessage() : htmlentities($e->getMessage());
1666
                                $htmlmsg = $e instanceof OIDplusException ? $e->getHtmlMessage() : htmlentities($e->getMessage());
1610
                                $errors_happened = true;
1667
                                $errors_happened = true;
1611
                        }
1668
                        }
1612
                }
1669
                }
1613
 
1670
 
1614
                echo ' <font color="red"><b>'.$htmlmsg.'</b></font>';
1671
                echo ' <font color="red"><b>'.$htmlmsg.'</b></font>';
1615
        }
1672
        }
1616
 
1673
 
1617
        /**
1674
        /**
1618
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8
1675
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8
1619
         * @param string|null $user
1676
         * @param string|null $user
1620
         * @return array
1677
         * @return array
1621
         * @throws OIDplusException
1678
         * @throws OIDplusException
1622
         */
1679
         */
1623
        public function getNotifications(string $user=null): array {
1680
        public function getNotifications(string $user=null): array {
1624
                $notifications = array();
1681
                $notifications = array();
1625
                $res = OIDplus::db()->query("select id, title from ###objects");
1682
                $res = OIDplus::db()->query("select id, title from ###objects");
1626
                $res->naturalSortByField('id');
1683
                $res->naturalSortByField('id');
1627
                if ($res->any()) {
1684
                if ($res->any()) {
1628
                        $is_admin_logged_in = OIDplus::authUtils()->isAdminLoggedIn(); // run just once, for performance
1685
                        $is_admin_logged_in = OIDplus::authUtils()->isAdminLoggedIn(); // run just once, for performance
1629
                        while ($row = $res->fetch_array()) {
1686
                        while ($row = $res->fetch_array()) {
1630
                                if (empty($row['title'])) {
1687
                                if (empty($row['title'])) {
1631
                                        if ($user === 'admin') {
1688
                                        if ($user === 'admin') {
1632
                                                $accept = $is_admin_logged_in;
1689
                                                $accept = $is_admin_logged_in;
1633
                                        } else {
1690
                                        } else {
1634
                                                $accept = false;
1691
                                                $accept = false;
1635
                                                if ($obj = OIDplusObject::parse($row['id'])) {
1692
                                                if ($obj = OIDplusObject::parse($row['id'])) {
1636
                                                        if ($obj->userHasWriteRights($user)) {
1693
                                                        if ($obj->userHasWriteRights($user)) {
1637
                                                                $accept = true;
1694
                                                                $accept = true;
1638
                                                        }
1695
                                                        }
1639
                                                }
1696
                                                }
1640
                                        }
1697
                                        }
1641
 
1698
 
1642
                                        if ($accept) {
1699
                                        if ($accept) {
1643
                                                $notifications[] = new OIDplusNotification('WARN', _L('Object %1 has no title.', '<a '.OIDplus::gui()->link($row['id']).'>'.htmlentities($row['id']).'</a>'));
1700
                                                $notifications[] = new OIDplusNotification('WARN', _L('Object %1 has no title.', '<a '.OIDplus::gui()->link($row['id']).'>'.htmlentities($row['id']).'</a>'));
1644
                                        }
1701
                                        }
1645
                                }
1702
                                }
1646
                        }
1703
                        }
1647
                }
1704
                }
1648
                return $notifications;
1705
                return $notifications;
1649
        }
1706
        }
1650
 
1707
 
1651
}
1708
}
1652
 
1709