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