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