Subversion Repositories oidplus

Rev

Rev 320 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

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