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