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