Subversion Repositories oidplus

Rev

Rev 1141 | Rev 1144 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 - 2023 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. namespace ViaThinkSoft\OIDplus;
  21.  
  22. // phpcs:disable PSR1.Files.SideEffects
  23. \defined('INSIDE_OIDPLUS') or die;
  24. // phpcs:enable PSR1.Files.SideEffects
  25.  
  26. class OIDplusPagePublicObjects extends OIDplusPagePluginPublic
  27.         implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1, /* oobeEntry, oobeRequested */
  28.                    INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8  /* getNotifications */
  29.                    // Important: Do NOT implement INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7, because our getAlternativesForQuery() is the one that calls others!
  30. {
  31.  
  32.         /**
  33.          * @param string|OIDplusObject $ot
  34.          * @return string|null
  35.          */
  36.         private function get_treeicon_root($ot)/*: ?string*/ {
  37.                 $root = $ot::parse($ot::root());
  38.                 if (!$root) return null;
  39.                 return $root->getIcon();
  40.         }
  41.  
  42.         /**
  43.          * @param string $id
  44.          * @param string $old_ra
  45.          * @param string $new_ra
  46.          * @return void
  47.          * @throws OIDplusConfigInitializationException
  48.          * @throws OIDplusException
  49.          */
  50.         private function ra_change_rec(string $id, string $old_ra, string $new_ra) {
  51.                 OIDplus::db()->query("update ###objects set ra_email = ?, updated = ".OIDplus::db()->sqlDate()." where id = ? and ".OIDplus::db()->getSlang()->isNullFunction('ra_email',"''")." = ?", array($new_ra, $id, $old_ra));
  52.                 OIDplusObject::resetObjectInformationCache();
  53.  
  54.                 $res = OIDplus::db()->query("select id from ###objects where parent = ? and ".OIDplus::db()->getSlang()->isNullFunction('ra_email',"''")." = ?", array($id, $old_ra));
  55.                 while ($row = $res->fetch_array()) {
  56.                         $this->ra_change_rec($row['id'], $old_ra, $new_ra);
  57.                 }
  58.         }
  59.  
  60.         /**
  61.          * @param string $actionID
  62.          * @param array $params
  63.          * @return array
  64.          * @throws OIDplusConfigInitializationException
  65.          * @throws OIDplusException
  66.          */
  67.         public function action(string $actionID, array $params): array {
  68.  
  69.                 // Action:     Delete
  70.                 // Method:     POST
  71.                 // Parameters: id
  72.                 // Outputs:    <0 Error, =0 Success
  73.                 if ($actionID == 'Delete') {
  74.                         _CheckParamExists($params, 'id');
  75.                         $id = $params['id'];
  76.                         $obj = OIDplusObject::parse($id);
  77.                         if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','DELETE',$id));
  78.  
  79.                         if (!OIDplusObject::exists($id)) {
  80.                                 throw new OIDplusException(_L('Object %1 does not exist',$id));
  81.                         }
  82.  
  83.                         // Check if permitted
  84.                         if (!$obj->userHasParentalWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the superior RA to delete this OID.'));
  85.  
  86.                         foreach (OIDplus::getAllPlugins() as $plugin) {
  87.                                 if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) {
  88.                                         $plugin->beforeObjectDelete($id);
  89.                                 }
  90.                         }
  91.  
  92.                         OIDplus::logger()->log("[WARN]OID($id)+[?WARN/!OK]SUPOIDRA($id)?/[?INFO/!OK]A?", "Object '$id' (recursively) deleted");
  93.                         OIDplus::logger()->log("[CRIT]OIDRA($id)!", "Lost ownership of object '$id' because it was deleted");
  94.  
  95.                         if ($parentObj = $obj->getParent()) {
  96.                                 $parent_oid = $parentObj->nodeId();
  97.                                 OIDplus::logger()->log("[WARN]OID($parent_oid)", "Object '$id' (recursively) deleted");
  98.                         }
  99.  
  100.                         // Delete object
  101.                         OIDplus::db()->query("delete from ###objects where id = ?", array($id));
  102.                         OIDplusObject::resetObjectInformationCache();
  103.  
  104.                         // Delete orphan stuff
  105.                         foreach (OIDplus::getEnabledObjectTypes() as $ot) {
  106.                                 do {
  107.                                         $res = OIDplus::db()->query("select tchild.id from ###objects tchild " .
  108.                                                                     "left join ###objects tparent on tparent.id = tchild.parent " .
  109.                                                                     "where tchild.parent <> ? and tchild.id like ? and tparent.id is null;", array($ot::root(), $ot::root().'%'));
  110.                                         if (!$res->any()) break;
  111.  
  112.                                         while ($row = $res->fetch_array()) {
  113.                                                 $id_to_delete = $row['id'];
  114.                                                 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");
  115.                                                 OIDplus::db()->query("delete from ###objects where id = ?", array($id_to_delete));
  116.                                                 OIDplusObject::resetObjectInformationCache();
  117.                                         }
  118.                                 } while (true);
  119.                         }
  120.                         OIDplus::db()->query("delete from ###asn1id where well_known = ? and oid not in (select id from ###objects where id like 'oid:%')", array(false));
  121.                         OIDplus::db()->query("delete from ###iri    where well_known = ? and oid not in (select id from ###objects where id like 'oid:%')", array(false));
  122.  
  123.                         foreach (OIDplus::getAllPlugins() as $plugin) {
  124.                                 if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) {
  125.                                         $plugin->afterObjectDelete($id);
  126.                                 }
  127.                         }
  128.  
  129.                         return array("status" => 0);
  130.                 }
  131.  
  132.                 // Action:     Update
  133.                 // Method:     POST
  134.                 // Parameters: id, ra_email, comment, iris, asn1ids, confidential
  135.                 // Outputs:    <0 Error, =0 Success, with following bitfields for further information:
  136.                 //             1 = RA is not registered
  137.                 //             2 = RA is not registered, but it cannot be invited
  138.                 //             4 = OID is a well-known OID, so RA, ASN.1 and IRI identifiers were reset
  139.                 else if ($actionID == 'Update') {
  140.                         _CheckParamExists($params, 'id');
  141.                         $id = $params['id'];
  142.                         $obj = OIDplusObject::parse($id);
  143.                         if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','UPDATE',$id));
  144.  
  145.                         if (!OIDplusObject::exists($id)) {
  146.                                 throw new OIDplusException(_L('Object %1 does not exist',$id));
  147.                         }
  148.  
  149.                         // Check if permitted
  150.                         if (!$obj->userHasParentalWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the superior RA to update this OID.'));
  151.  
  152.                         foreach (OIDplus::getAllPlugins() as $plugin) {
  153.                                 if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) {
  154.                                         $plugin->beforeObjectUpdateSuperior($id, $params);
  155.                                 }
  156.                         }
  157.  
  158.                         // First, do a simulation for ASN.1 IDs and IRIs to check if there are any problems (then an Exception will be thrown)
  159.                         if ($obj::ns() == 'oid') {
  160.                                 assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
  161.                                 if (!$obj->isWellKnown()) {
  162.                                         if (isset($params['iris'])) {
  163.                                                 $ids = ($params['iris'] == '') ? array() : explode(',',$params['iris']);
  164.                                                 $ids = array_map('trim',$ids);
  165.                                                 $obj->replaceIris($ids, true);
  166.                                         }
  167.  
  168.                                         if (isset($params['asn1ids'])) {
  169.                                                 $ids = ($params['asn1ids'] == '') ? array() : explode(',',$params['asn1ids']);
  170.                                                 $ids = array_map('trim',$ids);
  171.                                                 $obj->replaceAsn1Ids($ids, true);
  172.                                         }
  173.                                 }
  174.                         }
  175.  
  176.                         // RA E-Mail change
  177.                         if (isset($params['ra_email'])) {
  178.                                 // Validate RA email address
  179.                                 $new_ra = $params['ra_email'] ?? '';
  180.                                 if ($obj::ns() == 'oid') {
  181.                                         assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
  182.                                         if ($obj->isWellKnown()) {
  183.                                                 $new_ra = '';
  184.                                         }
  185.                                 }
  186.                                 if (!empty($new_ra) && !OIDplus::mailUtils()->validMailAddress($new_ra)) {
  187.                                         throw new OIDplusException(_L('Invalid RA email address'));
  188.                                 }
  189.  
  190.                                 // Change RA recursively
  191.                                 $current_ra = $obj->getRaMail() ?? '';
  192.                                 if ($new_ra != $current_ra) {
  193.                                         OIDplus::logger()->log("[INFO]OID($id)+[?INFO/!OK]SUPOIDRA($id)?/[?INFO/!OK]A?", "RA of object '$id' changed from '$current_ra' to '$new_ra'");
  194.                                         OIDplus::logger()->log("[WARN]RA($current_ra)!",           "Lost ownership of object '$id' due to RA transfer of superior RA / admin.");
  195.                                         OIDplus::logger()->log("[INFO]RA($new_ra)!",               "Gained ownership of object '$id' due to RA transfer of superior RA / admin.");
  196.                                         if ($parentObj = $obj->getParent()) {
  197.                                                 $parent_oid = $parentObj->nodeId();
  198.                                                 OIDplus::logger()->log("[INFO]OID($parent_oid)", "RA of object '$id' changed from '$current_ra' to '$new_ra'");
  199.                                         }
  200.                                         $this->ra_change_rec($id, $current_ra, $new_ra); // Recursively change inherited RAs
  201.                                 }
  202.                         }
  203.  
  204.                         // Log if confidentially flag was changed
  205.                         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!
  206.                         if ($parentObj = $obj->getParent()) {
  207.                                 $parent_oid = $parentObj->nodeId();
  208.                                 OIDplus::logger()->log("[INFO]OID($parent_oid)", "Identifiers/Confidential flag of object '$id' updated"); // TODO: Check if they were ACTUALLY updated!
  209.                         }
  210.  
  211.                         // Replace ASN.1 IDs und IRIs
  212.                         if ($obj::ns() == 'oid') {
  213.                                 assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
  214.                                 if (!$obj->isWellKnown()) {
  215.                                         if (isset($params['iris'])) {
  216.                                                 $ids = ($params['iris'] == '') ? array() : explode(',',$params['iris']);
  217.                                                 $ids = array_map('trim',$ids);
  218.                                                 $obj->replaceIris($ids, false);
  219.                                         }
  220.  
  221.                                         if (isset($params['asn1ids'])) {
  222.                                                 $ids = ($params['asn1ids'] == '') ? array() : explode(',',$params['asn1ids']);
  223.                                                 $ids = array_map('trim',$ids);
  224.                                                 $obj->replaceAsn1Ids($ids, false);
  225.                                         }
  226.                                 }
  227.  
  228.                                 // TODO: Check if any identifiers have been actually changed,
  229.                                 // and log it to OID($id), OID($parent), ... (see above)
  230.                         }
  231.  
  232.                         if (isset($params['confidential'])) {
  233.                                 $confidential = $params['confidential'] == 'true';
  234.                                 OIDplus::db()->query("UPDATE ###objects SET confidential = ? WHERE id = ?", array($confidential, $id));
  235.                                 OIDplusObject::resetObjectInformationCache();
  236.                         }
  237.  
  238.                         if (isset($params['comment'])) {
  239.                                 $comment = $params['comment'];
  240.                                 OIDplus::db()->query("UPDATE ###objects SET comment = ? WHERE id = ?", array($comment, $id));
  241.                                 OIDplusObject::resetObjectInformationCache();
  242.                         }
  243.  
  244.                         OIDplus::db()->query("UPDATE ###objects SET updated = ".OIDplus::db()->sqlDate()." WHERE id = ?", array($id));
  245.                         OIDplusObject::resetObjectInformationCache();
  246.  
  247.                         $status = 0;
  248.  
  249.                         if (!empty($new_ra)) {
  250.                                 $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($new_ra));
  251.                                 $invitePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.92'); // OIDplusPageRaInvite
  252.                                 if (!$res->any()) $status = !is_null($invitePlugin) && OIDplus::config()->getValue('ra_invitation_enabled') ? 1 : 2;
  253.                         }
  254.  
  255.                         if ($obj::ns() == 'oid') {
  256.                                 assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
  257.                                 if ($obj->isWellKnown()) {
  258.                                         $status += 4;
  259.                                 }
  260.                         }
  261.  
  262.                         foreach (OIDplus::getAllPlugins() as $plugin) {
  263.                                 if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) {
  264.                                         $plugin->afterObjectUpdateSuperior($id, $params);
  265.                                 }
  266.                         }
  267.  
  268.                         return array("status" => $status);
  269.                 }
  270.  
  271.                 // Action:     Update2
  272.                 // Method:     POST
  273.                 // Parameters: id, title, description
  274.                 // Outputs:    <0 Error, =0 Success
  275.                 else if ($actionID == 'Update2') {
  276.                         _CheckParamExists($params, 'id');
  277.                         $id = $params['id'];
  278.                         $obj = OIDplusObject::parse($id);
  279.                         if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','UPDATE2',$id));
  280.  
  281.                         if (!OIDplusObject::exists($id)) {
  282.                                 throw new OIDplusException(_L('Object %1 does not exist',$id));
  283.                         }
  284.  
  285.                         // Check if allowed
  286.                         if (!$obj->userHasWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the RA to update this OID.'));
  287.  
  288.                         foreach (OIDplus::getAllPlugins() as $plugin) {
  289.                                 if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) {
  290.                                         $plugin->beforeObjectUpdateSelf($id, $params);
  291.                                 }
  292.                         }
  293.  
  294.                         OIDplus::logger()->log("[INFO]OID($id)+[?INFO/!OK]OIDRA($id)?/[?INFO/!OK]A?", "Title/Description of object '$id' updated");
  295.  
  296.                         if (isset($params['title'])) {
  297.                                 $title = $params['title'];
  298.                                 OIDplus::db()->query("UPDATE ###objects SET title = ? WHERE id = ?", array($title, $id));
  299.                                 OIDplusObject::resetObjectInformationCache();
  300.                         }
  301.  
  302.                         if (isset($params['description'])) {
  303.                                 $description = $params['description'];
  304.                                 OIDplus::db()->query("UPDATE ###objects SET description = ? WHERE id = ?", array($description, $id));
  305.                                 OIDplusObject::resetObjectInformationCache();
  306.                         }
  307.  
  308.                         OIDplus::db()->query("UPDATE ###objects SET updated = ".OIDplus::db()->sqlDate()." WHERE id = ?", array($id));
  309.                         OIDplusObject::resetObjectInformationCache();
  310.  
  311.                         foreach (OIDplus::getAllPlugins() as $plugin) {
  312.                                 if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) {
  313.                                         $plugin->afterObjectUpdateSelf($id, $params);
  314.                                 }
  315.                         }
  316.  
  317.                         return array("status" => 0);
  318.                 }
  319.  
  320.                 // Generate UUID
  321.                 else if ($actionID == 'generate_uuid') {
  322.                         $uuid = gen_uuid();
  323.                         if (!$uuid) return array("status" => 1);
  324.                         return array(
  325.                                 "status" => 0,
  326.                                 "uuid" => $uuid,
  327.                                 "intval" => substr(uuid_to_oid($uuid),strlen('2.25.'))
  328.                         );
  329.                 }
  330.  
  331.                 // Action:     Insert
  332.                 // Method:     POST
  333.                 // Parameters: parent, id, ra_email, confidential, iris, asn1ids
  334.                 // Outputs:    status=<0 Error, =0 Success, with following bitfields for further information:
  335.                 //             1 = RA is not registered
  336.                 //             2 = RA is not registered, but it cannot be invited
  337.                 //             4 = OID is a well-known OID, so RA, ASN.1 and IRI identifiers were reset
  338.                 else if ($actionID == 'Insert') {
  339.                         // Check if you have write rights on the parent (to create a new object)
  340.                         _CheckParamExists($params, 'parent');
  341.                         $objParent = OIDplusObject::parse($params['parent']);
  342.                         if (!$objParent) throw new OIDplusException(_L('%1 action failed because parent object "%2" cannot be parsed!','INSERT',$params['parent']));
  343.  
  344.                         if (!$objParent->isRoot()) {
  345.                                 $idParent = $objParent->nodeId();
  346.                                 if (!OIDplusObject::exists($idParent)) {
  347.                                         throw new OIDplusException(_L('Parent object %1 does not exist',$idParent));
  348.                                 }
  349.                         }
  350.  
  351.                         if (!$objParent->userHasWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the correct RA to insert an OID at this arc.'));
  352.  
  353.                         // Check if the ID is valid
  354.                         _CheckParamExists($params, 'id');
  355.                         if ($params['id'] == '') throw new OIDplusException(_L('ID may not be empty'));
  356.  
  357.                         // For the root objects, let the user also enter a WEID
  358.                         if ($objParent::ns() == 'oid') {
  359.                                 assert($objParent instanceof OIDplusOid); //assert(get_class($objParent) === "ViaThinkSoft\OIDplus\OIDplusOid");
  360.                                 if (strtolower(substr(trim($params['id']),0,5)) === 'weid:') {
  361.                                         if ($objParent->isRoot()) {
  362.                                                 $params['id'] = \Frdl\Weid\WeidOidConverter::weid2oid($params['id']);
  363.                                                 if ($params['id'] === false) {
  364.                                                         throw new OIDplusException(_L('Invalid WEID'));
  365.                                                 }
  366.                                         } else {
  367.                                                 throw new OIDplusException(_L('You can use the WEID syntax only at your object tree root.'));
  368.                                         }
  369.                                 }
  370.                         }
  371.  
  372.                         // Determine absolute OID name
  373.                         // Note: At addString() and parse(), the syntax of the ID will be checked
  374.                         $id = $objParent->addString($params['id']);
  375.  
  376.                         // Check, if the OID exists
  377.                         if (OIDplusObject::exists($id)) {
  378.                                 throw new OIDplusException(_L('Object %1 already exists!',$id));
  379.                         }
  380.  
  381.                         $obj = OIDplusObject::parse($id);
  382.                         if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','INSERT',$id));
  383.  
  384.                         foreach (OIDplus::getAllPlugins() as $plugin) {
  385.                                 if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) {
  386.                                         $plugin->beforeObjectInsert($id, $params);
  387.                                 }
  388.                         }
  389.  
  390.                         // First simulate if there are any problems of ASN.1 IDs und IRIs
  391.                         if ($obj::ns() == 'oid') {
  392.                                 assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
  393.                                 if (!$obj->isWellKnown()) {
  394.                                         if (isset($params['iris'])) {
  395.                                                 $ids = ($params['iris'] == '') ? array() : explode(',',$params['iris']);
  396.                                                 $ids = array_map('trim',$ids);
  397.                                                 $obj->replaceIris($ids, true);
  398.                                         }
  399.  
  400.                                         if (isset($params['asn1ids'])) {
  401.                                                 $ids = ($params['asn1ids'] == '') ? array() : explode(',',$params['asn1ids']);
  402.                                                 $ids = array_map('trim',$ids);
  403.                                                 $obj->replaceAsn1Ids($ids, true);
  404.                                         }
  405.                                 }
  406.                         }
  407.  
  408.                         // Apply superior RA change
  409.                         $parent = $params['parent'];
  410.                         $ra_email = $params['ra_email'] ?? '';
  411.                         if ($obj::ns() == 'oid') {
  412.                                 assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
  413.                                 if ($obj->isWellKnown()) {
  414.                                         $ra_email = '';
  415.                                 }
  416.                         }
  417.                         if (!empty($ra_email) && !OIDplus::mailUtils()->validMailAddress($ra_email)) {
  418.                                 throw new OIDplusException(_L('Invalid RA email address'));
  419.                         }
  420.  
  421.                         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'";
  422.                         if (!empty($ra_email)) {
  423.                                 OIDplus::logger()->log("[INFO]RA($ra_email)!", "Gained ownership of newly created object '$id'");
  424.                         }
  425.  
  426.                         $confidential = isset($params['confidential']) && $params['confidential'] == 'true';
  427.                         $comment = $params['comment'] ?? '';
  428.                         $title = '';
  429.                         $description = '';
  430.  
  431.                         if (strlen($id) > OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH')) {
  432.                                 $maxlen = OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH');
  433.                                 throw new OIDplusException(_L('The identifier %1 is too long (max allowed length: %2)',$id,$maxlen));
  434.                         }
  435.  
  436.                         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));
  437.                         OIDplusObject::resetObjectInformationCache();
  438.  
  439.                         // Set ASN.1 IDs und IRIs
  440.                         if ($obj::ns() == 'oid') {
  441.                                 assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
  442.                                 if (!$obj->isWellKnown()) {
  443.                                         if (isset($params['iris'])) {
  444.                                                 $ids = ($params['iris'] == '') ? array() : explode(',',$params['iris']);
  445.                                                 $ids = array_map('trim',$ids);
  446.                                                 $obj->replaceIris($ids, false);
  447.                                         }
  448.  
  449.                                         if (isset($params['asn1ids'])) {
  450.                                                 $ids = ($params['asn1ids'] == '') ? array() : explode(',',$params['asn1ids']);
  451.                                                 $ids = array_map('trim',$ids);
  452.                                                 $obj->replaceAsn1Ids($ids, false);
  453.                                         }
  454.                                 }
  455.                         }
  456.  
  457.                         $status = 0;
  458.  
  459.                         if (!empty($ra_email)) {
  460.                                 // Do we need to notify that the RA does not exist?
  461.                                 $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($ra_email));
  462.                                 $invitePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.92'); // OIDplusPageRaInvite
  463.                                 if (!$res->any()) $status = !is_null($invitePlugin) && OIDplus::config()->getValue('ra_invitation_enabled') ? 1 : 2;
  464.                         }
  465.  
  466.                         if ($obj::ns() == 'oid') {
  467.                                 assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
  468.                                 if ($obj->isWellKnown()) {
  469.                                         $status += 4;
  470.                                 }
  471.                         }
  472.  
  473.                         foreach (OIDplus::getAllPlugins() as $plugin) {
  474.                                 if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) {
  475.                                         $plugin->afterObjectInsert($id, $params);
  476.                                 }
  477.                         }
  478.  
  479.                         return array(
  480.                                 "status" => $status,
  481.                                 "inserted_id" => $id
  482.                         );
  483.                 } else {
  484.                         return parent::action($actionID, $params);
  485.                 }
  486.         }
  487.  
  488.         /**
  489.          * @param bool $html
  490.          * @return void
  491.          * @throws OIDplusException
  492.          */
  493.         public function init(bool $html=true) {
  494.                 OIDplus::config()->prepareConfigKey('oobe_objects_done', '"Out Of Box Experience" wizard for OIDplusPagePublicObjects done once?', '0', OIDplusConfig::PROTECTION_HIDDEN, function($value) {});
  495.                 OIDplus::config()->prepareConfigKey('oid_grid_show_weid', 'Show WEID/Base36 column in CRUD grid of OIDs?', '1', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
  496.                         if (!is_numeric($value) || ($value < 0) || ($value > 1)) {
  497.                                 throw new OIDplusException(_L('Please enter a valid value (0=no, 1=yes).'));
  498.                         }
  499.                 });
  500.         }
  501.  
  502.         /**
  503.          * @param string $id
  504.          * @param array $out
  505.          * @return array|false
  506.          * @throws OIDplusException
  507.          */
  508.         private function tryObject(string $id, array &$out) {
  509.                 $parent = null;
  510.                 $res = null;
  511.                 $row = null;
  512.                 $obj = OIDplusObject::parse($id);
  513.                 if (!$obj) return false;
  514.                 if ($obj->isRoot()) {
  515.                         $obj->getContentPage($out['title'], $out['text'], $out['icon']);
  516.                         $objParent = null; // $obj->getParent();
  517.                 } else {
  518.                         $obj = OIDplusObject::findFitting($id); // this time, the object will be found, not just the object type
  519.                         if (!$obj) {
  520.                                 return false;
  521.                         } else {
  522.                                 $obj->getContentPage($out['title'], $out['text'], $out['icon']);
  523.                                 if (empty($out['title'])) $out['title'] = explode(':',$obj->nodeId(),2)[1];
  524.                                 $objParent = $obj->getParent();
  525.                         }
  526.                 }
  527.                 return array($id, $obj, $objParent);
  528.         }
  529.  
  530.         /**
  531.          * @param string $id
  532.          * @return array
  533.          */
  534.         public static function getAlternativesForQuery(string $id): array {
  535.                 // Attention: This is NOT an implementation of INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7!
  536.                 //            This is the function that calls getAlternativesForQuery() of every plugin that implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7
  537.  
  538.                 // e.g. used for "Reverse Alt Id"
  539.                 $alternatives = array();
  540.                 foreach (OIDplus::getAllPlugins() as $plugin) {
  541.                         if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7) {
  542.                                 $tmp = $plugin->getAlternativesForQuery($id);
  543.                                 if (is_array($tmp)) {
  544.                                         $alternatives = array_merge($tmp, $alternatives);
  545.                                 }
  546.                         }
  547.                 }
  548.  
  549.                 // If something is more than one time, remove it
  550.                 $alternatives = array_unique($alternatives);
  551.  
  552.                 // If a plugin accidentally added the own ID, remove it. This function lists only alternatives, not the own ID
  553.                 $alternatives_tmp = array();
  554.                 foreach ($alternatives as $alt) {
  555.                         if ($alt !== $id) $alternatives_tmp[] = $alt;
  556.                 }
  557.                 return $alternatives_tmp;
  558.         }
  559.  
  560.         /**
  561.          * @param string $id
  562.          * @param array $out
  563.          * @param bool $handled
  564.          * @return void
  565.          * @throws OIDplusConfigInitializationException
  566.          * @throws OIDplusException
  567.          */
  568.         public function gui(string $id, array &$out, bool &$handled) {
  569.                 if ($id === 'oidplus:system') {
  570.                         $handled = true;
  571.  
  572.                         $out['title'] = OIDplus::config()->getValue('system_title');
  573.                         $out['icon'] = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png';
  574.  
  575.                         if (file_exists(OIDplus::localpath() . 'userdata/welcome/welcome$'.OIDplus::getCurrentLang().'.html')) {
  576.                                 $cont = file_get_contents(OIDplus::localpath() . 'userdata/welcome/welcome$'.OIDplus::getCurrentLang().'.html');
  577.                         } else if (file_exists(OIDplus::localpath() . 'userdata/welcome/welcome.html')) {
  578.                                 $cont = file_get_contents(OIDplus::localpath() . 'userdata/welcome/welcome.html');
  579.                         } else if (file_exists(__DIR__ . '/welcome$'.OIDplus::getCurrentLang().'.html')) {
  580.                                 $cont = file_get_contents(__DIR__ . '/welcome$'.OIDplus::getCurrentLang().'.html');
  581.                         } else if (file_exists(__DIR__ . '/welcome.html')) {
  582.                                 $cont = file_get_contents(__DIR__ . '/welcome.html');
  583.                         } else {
  584.                                 $cont = '';
  585.                         }
  586.  
  587.                         if ($cont) {
  588.                                 list($html, $js, $css) = extractHtmlContents($cont);
  589.                                 $cont = '';
  590.                                 if (!empty($js)) $cont .= "<script>\n$js\n</script>";
  591.                                 if (!empty($css)) $cont .= "<style>\n$css\n</style>";
  592.                                 $cont .= stripHtmlComments($html);
  593.                         }
  594.  
  595.                         $out['text'] = $cont;
  596.  
  597.                         if (strpos($out['text'], '%%OBJECT_TYPE_LIST%%') !== false) {
  598.                                 $tmp = '<ul>';
  599.                                 foreach (OIDplus::getEnabledObjectTypes() as $ot) {
  600.                                         $tmp .= '<li><a '.OIDplus::gui()->link($ot::root()).'>'.htmlentities($ot::objectTypeTitle()).'</a></li>';
  601.                                 }
  602.                                 $tmp .= '</ul>';
  603.                                 $out['text'] = str_replace('%%OBJECT_TYPE_LIST%%', $tmp, $out['text']);
  604.                         }
  605.                 }
  606.  
  607.                 // Never answer to an object type that is called 'oidplus:',
  608.                 // otherwise, an object type plugin could break the whole system!
  609.                 else if ((strpos($id,':') !== false) && (!str_starts_with($id,'oidplus:'))) {
  610.  
  611.                         // --- Try to find the object or an alternative
  612.  
  613.                         $test = $this->tryObject($id, $out);
  614.                         if ($test === false) {
  615.                                 // try to find an alternative
  616.                                 $alternatives = $this->getAlternativesForQuery($id);
  617.                                 foreach ($alternatives as $alternative) {
  618.                                         $test = $this->tryObject($alternative, $out);
  619.                                         if ($test !== false) break; // found something
  620.                                 }
  621.                         }
  622.                         if ($test !== false) {
  623.                                 list($id, $obj, $objParent) = $test;
  624.                         } else {
  625.                                 $objParent = null; // to avoid warnings
  626.                         }
  627.  
  628.                         // --- If the object type is disabled or not an object at all (e.g. "oidplus:"), then $handled=false
  629.                         //     If the object type is enabled but object not found, $handled=true
  630.  
  631.                         $obj = OIDplusObject::parse($id);
  632.  
  633.                         if ($test === false) {
  634.                                 if (!$obj) {
  635.                                         // Object type disabled or not known (e.g. ObjectType "oidplus:").
  636.                                         $handled = false;
  637.                                         return;
  638.                                 } else {
  639.                                         // Object type enabled but identifier not in database
  640.                                         $handled = true;
  641.                                         if (isset($_SERVER['SCRIPT_FILENAME']) && (strtolower(basename($_SERVER['SCRIPT_FILENAME'])) !== 'ajax.php')) { // don't send HTTP error codes in ajax.php, because we want a page and not a JavaScript alert box, when someone enters an invalid OID in the GoTo-Box
  642.                                                 http_response_code(404);
  643.                                         }
  644.                                         $out['title'] = _L('Object not found');
  645.                                         $out['icon'] = 'img/error.png';
  646.                                         $out['text'] = _L('The object %1 was not found in this database.','<code>'.htmlentities($id).'</code>');
  647.                                         return;
  648.                                 }
  649.                         } else {
  650.                                 $handled = true;
  651.                         }
  652.  
  653.                         unset($test);
  654.  
  655.                         // --- If found, do we have read rights?
  656.  
  657.                         if (!$obj->userHasReadRights()) {
  658.                                 if (isset($_SERVER['SCRIPT_FILENAME']) && (strtolower(basename($_SERVER['SCRIPT_FILENAME'])) !== 'ajax.php')) { // don't send HTTP error codes in ajax.php, because we want a page and not a JavaScript alert box, when someone enters an invalid OID in the GoTo-Box
  659.                                         http_response_code(403);
  660.                                 }
  661.                                 $out['title'] = _L('Access denied');
  662.                                 $out['icon'] = 'img/error.png';
  663.                                 $out['text'] = '<p>'._L('Please <a %1>log in</a> to receive information about this object.',OIDplus::gui()->link('oidplus:login')).'</p>';
  664.                                 return;
  665.                         }
  666.  
  667.                         // ---
  668.  
  669.                         if ($objParent) {
  670.                                 if ($objParent->isRoot()) {
  671.                                         $parent_link_text = $objParent->objectTypeTitle();
  672.                                         $out['text'] = '<p><a '.OIDplus::gui()->link($objParent->root()).'><img src="img/arrow_back.png" width="16" alt="'._L('Go back').'"> '._L('Parent node: %1',htmlentities($parent_link_text)).'</a></p>' . $out['text'];
  673.                                 } else {
  674.                                         $parent_title = $objParent->getTitle();
  675.                                         if (empty($parent_title) && ($objParent->ns() == 'oid')) {
  676.                                                 assert($objParent instanceof OIDplusOid); //assert(get_class($objParent) === "ViaThinkSoft\OIDplus\OIDplusOid");
  677.                                                 // If not title is available, then use an ASN.1 identifier
  678.                                                 $res_asn = OIDplus::db()->query("select name from ###asn1id where oid = ?", array($objParent->nodeId()));
  679.                                                 if ($res_asn->any()) {
  680.                                                         $row_asn = $res_asn->fetch_array();
  681.                                                         $parent_title = $row_asn['name']; // TODO: multiple ASN1 ids?
  682.                                                 }
  683.                                         }
  684.  
  685.                                         $parent_link_text = empty($parent_title) ? explode(':',$objParent->nodeId())[1] : $parent_title.' ('.explode(':',$objParent->nodeId())[1].')';
  686.  
  687.                                         $out['text'] = '<p><a '.OIDplus::gui()->link($objParent->nodeId()).'><img src="img/arrow_back.png" width="16" alt="'._L('Go back').'"> '._L('Parent node: %1',htmlentities($parent_link_text)).'</a></p>' . $out['text'];
  688.                                 }
  689.                         } else {
  690.                                 $parent_link_text = _L('Go back to front page');
  691.                                 $out['text'] = '<p><a '.OIDplus::gui()->link('oidplus:system').'><img src="img/arrow_back.png" width="16" alt="'._L('Go back').'"> '.htmlentities($parent_link_text).'</a></p>' . $out['text'];
  692.                         }
  693.  
  694.                         // ---
  695.  
  696.                         if ($obj) {
  697.                                 $title = $obj->getTitle();
  698.                                 $description = $obj->getDescription();
  699.                                 if (empty(strip_tags($description)) && (stripos($description,'<img') === false)) {
  700.                                         if (empty($title)) {
  701.                                                 $desc = '<p><i>'._L('No description for this object available').'</i></p>';
  702.                                         } else {
  703.                                                 $desc = $title;
  704.                                         }
  705.                                 } else {
  706.                                         $desc = self::objDescription($description);
  707.                                 }
  708.  
  709.                                 if ($obj->userHasWriteRights()) {
  710.                                         $rand = ++self::$crudCounter;
  711.                                         $desc = '<noscript><p><b>'._L('You need to enable JavaScript to edit title or description of this object.').'</b></p>'.$desc.'</noscript>';
  712.                                         $desc .= '<div class="container box" style="display:none" id="descbox_'.$rand.'">';
  713.                                         $desc .= _L('Title').': <input type="text" name="title" id="titleedit" value="'.htmlentities($title).'"><br><br>'._L('Description').':<br>';
  714.                                         $desc .= self::showMCE('description', $description);
  715.                                         $desc .= '<button type="button" name="update_desc" id="update_desc" class="btn btn-success btn-xs update" onclick="OIDplusPagePublicObjects.updateDesc()">'._L('Update description').'</button>';
  716.                                         $desc .= '</div>';
  717.                                         $desc .= '<script>$("#descbox_'.$rand.'")[0].style.display = "block";</script>';
  718.                                 }
  719.                         } else {
  720.                                 $desc = '';
  721.                         }
  722.  
  723.                         // ---
  724.  
  725.                         if (strpos($out['text'], '%%DESC%%') !== false)
  726.                                 $out['text'] = str_replace('%%DESC%%',    $desc,                              $out['text']);
  727.                         if (strpos($out['text'], '%%CRUD%%') !== false)
  728.                                 $out['text'] = str_replace('%%CRUD%%',    self::showCrud($obj->nodeId()),     $out['text']);
  729.                         if (strpos($out['text'], '%%RA_INFO%%') !== false)
  730.                                 $out['text'] = str_replace('%%RA_INFO%%', OIDplusPagePublicRaInfo::showRaInfo($obj->getRaMail()), $out['text']);
  731.  
  732.                         $alt_ids = $obj->getAltIds();
  733.                         if (count($alt_ids) > 0) {
  734.                                 $out['text'] .= '<h2>'._L('Alternative Identifiers').'</h2>';
  735.  
  736.                                 // Sorty by namespace
  737.                                 usort($alt_ids, function(OIDplusAltId $a, OIDplusAltId $b) {
  738.                                         if($a->getNamespace() > $b->getNamespace()) {
  739.                                                 return 1;
  740.                                         }
  741.                                         elseif($a->getNamespace() < $b->getNamespace()) {
  742.                                                 return -1;
  743.                                         }
  744.                                         else {
  745.                                                 return 0;
  746.                                         }
  747.                                 });
  748.  
  749.                                 $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
  750.                                 $out['text'] .= '<table class="table table-bordered table-striped">';
  751.                                 $out['text'] .= '<thead>';
  752.                                 $out['text'] .= '<tr><th>'._L('Identifier').'</th><th>'._L('Description').'</th></tr>';
  753.                                 $out['text'] .= '</thead>';
  754.                                 $out['text'] .= '<tbody>';
  755.                                 foreach ($alt_ids as $alt_id) {
  756.                                         $ns = $alt_id->getNamespace();
  757.                                         $aid = $alt_id->getId();
  758.                                         $aiddesc = $alt_id->getDescription();
  759.                                         $suffix = $alt_id->getSuffix();
  760.                                         $out['text'] .= '<tr><td>'.htmlentities($ns.':'.$aid).($suffix ? '<br/><font size="-1">'.htmlentities($suffix).'</font>' : '').'</td><td>'.htmlentities($aiddesc).'</td></tr>';
  761.                                 }
  762.                                 $out['text'] .= '</tbody>';
  763.                                 $out['text'] .= '</table>';
  764.                                 $out['text'] .= '</div></div>';
  765.                         }
  766.  
  767.                         foreach (OIDplus::getAllPlugins() as $plugin) {
  768.                                 if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_2) {
  769.                                         $plugin->modifyContent($obj->nodeId(), $out['title'], $out['icon'], $out['text']);
  770.                                 }
  771.                         }
  772.                 }
  773.         }
  774.  
  775.         /**
  776.          * @param array $json
  777.          * @param array $out
  778.          * @return void
  779.          */
  780.         private function publicSitemap_rec(array $json, array &$out) {
  781.                 foreach ($json as $x) {
  782.                         if (isset($x['id']) && $x['id']) {
  783.                                 $out[] = $x['id'];
  784.                         }
  785.                         if (isset($x['children'])) {
  786.                                 $this->publicSitemap_rec($x['children'], $out);
  787.                         }
  788.                 }
  789.         }
  790.  
  791.         /**
  792.          * @param array $out
  793.          * @return void
  794.          */
  795.         public function publicSitemap(array &$out) {
  796.                 $json = array();
  797.                 $this->tree($json, null/*RA EMail*/, false/*HTML tree algorithm*/, "*"/*display all*/);
  798.                 $this->publicSitemap_rec($json, $out);
  799.         }
  800.  
  801.         /**
  802.          * @param array $json
  803.          * @param string|null $ra_email
  804.          * @param bool $nonjs
  805.          * @param string $req_goto
  806.          * @return bool
  807.          * @throws OIDplusConfigInitializationException
  808.          * @throws OIDplusException
  809.          */
  810.         public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
  811.                 if ($nonjs) {
  812.                         $json[] = array(
  813.                                 'id' => 'oidplus:system',
  814.                                 'icon' => OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png',
  815.                                 'text' => _L('System')
  816.                         );
  817.  
  818.                         $objGoto = OIDplusObject::findFitting($req_goto);
  819.                         $objGotoParent = $objGoto ? $objGoto->getParent() : null;
  820.                         $parent = $objGotoParent ? $objGotoParent->nodeId() : '';
  821.  
  822.                         $objTypesChildren = array();
  823.                         foreach (OIDplus::getEnabledObjectTypes() as $ot) {
  824.                                 $icon = $this->get_treeicon_root($ot);
  825.  
  826.                                 $json[] = array(
  827.                                         'id' => $ot::root(),
  828.                                         'icon' => $icon,
  829.                                         'text' => $ot::objectTypeTitle()
  830.                                 );
  831.  
  832.                                 $tmp = OIDplusObject::parse($req_goto);
  833.                                 if ($tmp && ($ot == get_class($tmp))) {
  834.                                         // 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
  835.                                         //       on the other hand, for giving search engines content, this is good enough
  836.                                         if (empty($parent)) {
  837.                                                 $res = OIDplus::db()->query("select * from ###objects where " .
  838.                                                                             "parent = ? or " .
  839.                                                                             "id = ? " .
  840.                                                                             "order by ".OIDplus::db()->natOrder('id'), array($req_goto, $req_goto));
  841.                                         } else {
  842.                                                 $res = OIDplus::db()->query("select * from ###objects where " .
  843.                                                                             "parent = ? or " .
  844.                                                                             "id = ? or " .
  845.                                                                             "id = ? ".
  846.                                                                             "order by ".OIDplus::db()->natOrder('id'), array($req_goto, $req_goto, $parent));
  847.                                         }
  848.  
  849.                                         $z_used = 0;
  850.                                         $y_used = 0;
  851.                                         $x_used = 0;
  852.                                         $stufe = 0;
  853.                                         $menu_entries = array();
  854.                                         $stufen = array();
  855.                                         while ($row = $res->fetch_object()) {
  856.                                                 $obj = OIDplusObject::parse($row->id);
  857.                                                 if (!$obj) continue; // might happen if the objectType is not available/loaded
  858.                                                 if (!$obj->userHasReadRights()) continue;
  859.                                                 $txt = $row->title == '' ? '' : ' -- '.htmlentities($row->title);
  860.  
  861.                                                 if ($row->id == $parent) { $stufe=0; $z_used++; }
  862.                                                 if ($row->id == $req_goto) { $stufe=1; $y_used++; }
  863.                                                 if ($row->parent == $req_goto) { $stufe=2; $x_used++; }
  864.  
  865.                                                 $menu_entry = array('id' => $row->id, 'icon' => '', 'text' => $txt, 'indent' => 0);
  866.                                                 $menu_entries[] = $menu_entry;
  867.                                                 $stufen[] = $stufe;
  868.                                         }
  869.                                         if ($x_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 2) $menu_entry['indent'] += 1;
  870.                                         if ($y_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 1) $menu_entry['indent'] += 1;
  871.                                         if ($z_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 0) $menu_entry['indent'] += 1;
  872.                                         $json = array_merge($json, $menu_entries);
  873.                                 }
  874.                         }
  875.  
  876.                         return true;
  877.                 } else {
  878.                         if ($req_goto === "*") {
  879.                                 $goto_path = true; // display everything recursively
  880.                         } else if ($req_goto !== "") {
  881.                                 $goto = $req_goto;
  882.                                 $path = array();
  883.                                 while (true) {
  884.                                         $path[] = $goto;
  885.                                         $objGoto = OIDplusObject::findFitting($goto);
  886.                                         if (!$objGoto) break;
  887.                                         $objGotoParent = $objGoto->getParent();
  888.                                         $goto = $objGotoParent ? $objGotoParent->nodeId() : '';
  889.                                         if ($goto == '') continue;
  890.                                 }
  891.  
  892.                                 $goto_path = array_reverse($path);
  893.                         } else {
  894.                                 $goto_path = null;
  895.                         }
  896.  
  897.                         $objTypesChildren = array();
  898.                         foreach (OIDplus::getEnabledObjectTypes() as $ot) {
  899.                                 $icon = $this->get_treeicon_root($ot);
  900.  
  901.                                 $child = array('id' => $ot::root(),
  902.                                                'text' => $ot::objectTypeTitle(),
  903.                                                'state' => array("opened" => true),
  904.                                                'icon' => $icon,
  905.                                                'children' => OIDplus::menuUtils()->tree_populate($ot::root(), $goto_path)
  906.                                                );
  907.                                 if ($child['icon'] && !file_exists($child['icon'])) $child['icon'] = null; // default icon (folder)
  908.                                 $objTypesChildren[] = $child;
  909.                         }
  910.  
  911.                         $json[] = array(
  912.                                 'id' => "oidplus:system",
  913.                                 'text' => _L('Objects'),
  914.                                 'state' => array(
  915.                                         "opened" => true,
  916.                                         // "selected" => true)  // "selected" is buggy:
  917.                                         // 1) The select-event will not be triggered upon loading
  918.                                         // 2) The nodes directly blow cannot be opened (loading infinite time)
  919.                                 ),
  920.                                 'icon' => OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png',
  921.                                 'children' => $objTypesChildren
  922.                         );
  923.  
  924.                         return true;
  925.                 }
  926.         }
  927.  
  928.         /**
  929.          * @param string $request
  930.          * @return array|false
  931.          */
  932.         public function tree_search(string $request) {
  933.                 $ary = array();
  934.                 $found_leaf = false;
  935.                 if ($obj = OIDplusObject::parse($request)) {
  936.                         $found_leaf = OIDplusObject::exists($request);
  937.                         do {
  938.                                 if ($obj->userHasReadRights()) {
  939.                                         $ary[] = $obj->nodeId();
  940.                                 }
  941.                         } while ($obj = $obj->getParent());
  942.                         $ary = array_reverse($ary);
  943.                 }
  944.                 if (!$found_leaf) {
  945.                         $alternatives = $this->getAlternativesForQuery($request);
  946.                         foreach ($alternatives as $alternative) {
  947.                                 $ary_ = array();
  948.                                 if ($obj = OIDplusObject::parse($alternative)) {
  949.                                         if ($obj->userHasReadRights() && OIDplusObject::exists($alternative)) {
  950.                                                 do {
  951.                                                         $ary_[] = $obj->nodeId();
  952.                                                 } while ($obj = $obj->getParent());
  953.                                                 $ary_ = array_reverse($ary_);
  954.                                         }
  955.                                 }
  956.                                 if (!empty($ary_)) {
  957.                                         $ary = $ary_;
  958.                                         break;
  959.                                 }
  960.                         }
  961.                 }
  962.                 return $ary;
  963.         }
  964.  
  965.         /**
  966.          * @var int
  967.          */
  968.         private static $crudCounter = 0;
  969.  
  970.         /**
  971.          * @param string $parent
  972.          * @return string
  973.          * @throws OIDplusConfigInitializationException
  974.          * @throws OIDplusException
  975.          */
  976.         protected static function showCrud(string $parent='oid:'): string {
  977.                 $items_total = 0;
  978.                 $items_hidden = 0;
  979.  
  980.                 $objParent = OIDplusObject::parse($parent);
  981.                 if (!$objParent) return '';
  982.                 $parentNS = $objParent::ns();
  983.  
  984.                 // http://www.oid-info.com/cgi-bin/display?a=list-by-category&category=Not%20allocating%20identifiers
  985.                 $no_asn1 = array(
  986.                         'oid:1.3.6.1.4.1',
  987.                         'oid:1.3.6.1.4.1.37476.9000',
  988.                         'oid:1.3.6.1.4.1.37553.8.8',
  989.                         'oid:2.16.276.1',
  990.                         //'oid:2.25', // according to Olivier, it is OK that UUID owners define their own ASN.1 ID, since the ASN.1 ID is not required to be unique
  991.                         //'oid:1.2.840.113556.1.8000.2554' // Adhoc (GUID/UUID-based) customer use. It is probably the same case as the UUID OIDs, after all, these are UUIDs, too.
  992.                 );
  993.  
  994.                 // http://www.oid-info.com/cgi-bin/display?a=list-by-category&category=Not%20allocating%20Unicode%20labels
  995.                 $no_iri = array(
  996.                         'oid:1.2.250.1',
  997.                         'oid:1.3.6.1.4.1',
  998.                         'oid:1.3.6.1.4.1.37476.9000',
  999.                         'oid:1.3.6.1.4.1.37553.8.8',
  1000.                         'oid:2.16.276.1',
  1001.                         'oid:2.25'
  1002.                 );
  1003.  
  1004.                 $accepts_asn1 = ($parentNS == 'oid') && (!in_array($objParent->nodeId(), $no_asn1)) && (!is_uuid_oid($objParent->nodeId(),true));
  1005.                 $accepts_iri  = ($parentNS == 'oid') && (!in_array($objParent->nodeId(), $no_iri)) && (!is_uuid_oid($objParent->nodeId(),true));
  1006.  
  1007.                 $result = OIDplus::db()->query("select o.*, r.ra_name " .
  1008.                                                "from ###objects o " .
  1009.                                                "left join ###ra r on r.email = o.ra_email " .
  1010.                                                "where parent = ? " .
  1011.                                                "order by ".OIDplus::db()->natOrder('id'), array($parent));
  1012.  
  1013.                 $rows = array();
  1014.                 while ($row = $result->fetch_object()) {
  1015.                         $obj = OIDplusObject::parse($row->id);
  1016.                         if ($obj) $rows[] = array($obj,$row);
  1017.                 }
  1018.  
  1019.                 $enable_weid_presentation = OIDplus::config()->getValue('oid_grid_show_weid');
  1020.  
  1021.                 $output  = '<div class="container box"><div id="suboid_table" class="table-responsive">';
  1022.                 $output .= '<table class="table table-bordered table-striped">';
  1023.                 $output .= '<thead>';
  1024.                 $output .= '    <tr>';
  1025.                 $output .= '         <th>'._L('ID').(($parentNS == 'gs1') ? ' '._L('(without check digit)') : '').'</th>';
  1026.                 if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) {
  1027.                         $output .= '         <th><abbr title="'._L('Binary-to-text encoding used for WEIDs').'">'._L('Base36').'</abbr></th>';
  1028.                 }
  1029.                 if ($parentNS == 'oid') {
  1030.                         if ($accepts_asn1) $output .= '      <th>'._L('ASN.1 IDs (comma sep.)').'</th>';
  1031.                         if ($accepts_iri)  $output .= '      <th>'._L('IRI IDs (comma sep.)').'</th>';
  1032.                 }
  1033.                 $output .= '         <th>'._L('RA').'</th>';
  1034.                 $output .= '         <th>'._L('Comment').'</th>';
  1035.                 if ($objParent->userHasWriteRights()) {
  1036.                         $output .= '         <th>'._L('Hide').'</th>';
  1037.                         $output .= '         <th>'._L('Update').'</th>';
  1038.                         $output .= '         <th>'._L('Delete').'</th>';
  1039.                 }
  1040.                 $output .= '         <th>'._L('Created').'</th>';
  1041.                 $output .= '         <th>'._L('Updated').'</th>';
  1042.                 $output .= '    </tr>';
  1043.                 $output .= '</thead>';
  1044.  
  1045.                 $output .= '<tbody>';
  1046.                 foreach ($rows as list($obj,$row)) {
  1047.                         $items_total++;
  1048.                         if (!$obj->userHasReadRights()) {
  1049.                                 $items_hidden++;
  1050.                                 continue;
  1051.                         }
  1052.  
  1053.                         $show_id = $obj->crudShowId($objParent);
  1054.  
  1055.                         $asn1ids = array();
  1056.                         $res2 = OIDplus::db()->query("select name from ###asn1id where oid = ? order by lfd", array($row->id));
  1057.                         while ($row2 = $res2->fetch_array()) {
  1058.                                 $asn1ids[] = $row2['name'];
  1059.                         }
  1060.  
  1061.                         $iris = array();
  1062.                         $res2 = OIDplus::db()->query("select name from ###iri where oid = ? order by lfd", array($row->id));
  1063.                         while ($row2 = $res2->fetch_array()) {
  1064.                                 $iris[] = $row2['name'];
  1065.                         }
  1066.  
  1067.                         $date_created = is_null($row->created) || (explode(' ', $row->created)[0] == '0000-00-00') ? '' : explode(' ', $row->created)[0];
  1068.                         $date_updated = is_null($row->updated) || (explode(' ', $row->updated)[0] == '0000-00-00') ? '' : explode(' ', $row->updated)[0];
  1069.  
  1070.                         $output .= '<tr>';
  1071.                         $output .= '     <td><a href="?goto='.urlencode($row->id).'" onclick="openAndSelectNode('.js_escape($row->id).', '.js_escape($parent).'); return false;">'.htmlentities($show_id).'</a>';
  1072.                         if ($enable_weid_presentation && ($parentNS == 'oid') && $objParent->isRoot()) {
  1073.                                 // To save space horizontal space, the WEIDs were written below the OIDs
  1074.                                 assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
  1075.                                 $output .= '<br>'.$obj->getWeidNotation(true);
  1076.                         }
  1077.                         $output .= '</td>';
  1078.                         if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) {
  1079.                                 assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
  1080.                                 $output .= '    <td>'.htmlentities($obj->weidArc()).'</td>';
  1081.                         }
  1082.                         if ($objParent->userHasWriteRights()) {
  1083.                                 if ($parentNS == 'oid') {
  1084.                                         if ($accepts_asn1) $output .= '     <td><input type="text" id="asn1ids_'.$row->id.'" value="'.implode(', ', $asn1ids).'"></td>';
  1085.                                         if ($accepts_iri)  $output .= '     <td><input type="text" id="iris_'.$row->id.'" value="'.implode(', ', $iris).'"></td>';
  1086.                                 }
  1087.                                 $output .= '     <td><input type="text" id="ra_email_'.$row->id.'" value="'.htmlentities($row->ra_email).'"></td>';
  1088.                                 $output .= '     <td><input type="text" id="comment_'.$row->id.'" value="'.htmlentities($row->comment).'"></td>';
  1089.                                 $output .= '     <td><input type="checkbox" id="hide_'.$row->id.'" '.($row->confidential ? 'checked' : '').'></td>';
  1090.                                 $output .= '     <td><button type="button" name="update_'.$row->id.'" id="update_'.$row->id.'" class="btn btn-success btn-xs update" onclick="OIDplusPagePublicObjects.crudActionUpdate('.js_escape($row->id).', '.js_escape($parent).')">'._L('Update').'</button></td>';
  1091.                                 $output .= '     <td><button type="button" name="delete_'.$row->id.'" id="delete_'.$row->id.'" class="btn btn-danger btn-xs delete" onclick="OIDplusPagePublicObjects.crudActionDelete('.js_escape($row->id).', '.js_escape($parent).')">'._L('Delete').'</button></td>';
  1092.                                 $output .= '     <td>'.$date_created.'</td>';
  1093.                                 $output .= '     <td>'.$date_updated.'</td>';
  1094.                         } else {
  1095.                                 if ($parentNS == 'oid') {
  1096.                                         if ($asn1ids == '') $asn1ids = '<i>'._L('(none)').'</i>';
  1097.                                         if ($iris == '') $iris = '<i>'._L('(none)').'</i>';
  1098.                                         $asn1ids_ext = array();
  1099.                                         foreach ($asn1ids as $asn1id) {
  1100.                                                 $asn1ids_ext[] = '<a href="?goto='.urlencode($row->id).'" onclick="openAndSelectNode('.js_escape($row->id).', '.js_escape($parent).'); return false;">'.$asn1id.'</a>';
  1101.                                         }
  1102.                                         if ($accepts_asn1) $output .= '     <td>'.implode(', ', $asn1ids_ext).'</td>';
  1103.                                         if ($accepts_iri)  $output .= '     <td>'.implode(', ', $iris).'</td>';
  1104.                                 }
  1105.                                 $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>';
  1106.                                 $output .= '     <td>'.htmlentities($row->comment).'</td>';
  1107.                                 $output .= '     <td>'.$date_created.'</td>';
  1108.                                 $output .= '     <td>'.$date_updated.'</td>';
  1109.                         }
  1110.                         $output .= '</tr>';
  1111.                 }
  1112.                 $output .= '</tbody>';
  1113.  
  1114.                 $parent_ra_email = $objParent->getRaMail() ;
  1115.  
  1116.                 // "Create OID" row
  1117.                 if ($objParent->userHasWriteRights()) {
  1118.                         $output .= '<tfoot>';
  1119.                         $output .= '<tr>';
  1120.                         $prefix = $objParent->crudInsertPrefix();
  1121.  
  1122.                         $suffix = $objParent->crudInsertSuffix();
  1123.                         foreach (OIDplus::getObjectTypePlugins() as $plugin) {
  1124.                                 if (($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_6) && ($plugin::getObjectTypeClassName()::ns() == $parentNS)) {
  1125.                                         $suffix .= $plugin->gridGeneratorLinks($objParent);
  1126.                                 }
  1127.                         }
  1128.  
  1129.                         if ($parentNS == 'guid') {
  1130.                                 $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:275px">'.$suffix.'</td>';
  1131.                         } else if ($parentNS == 'oid') {
  1132.                                 // TODO: Idea: Give a class name, e.g. "OID" and then with a oid-specific CSS make the width individual. So, every plugin has more control over the appearance and widths of the input fields
  1133.                                 if ($objParent->nodeId() === 'oid:2.25') {
  1134.                                         $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:345px">'.$suffix.'</td>';
  1135.                                         if ($enable_weid_presentation) $output .= '     <td>&nbsp;</td>'; // For UUID-OIDs, you must generate a valid one. Don't be tempted to create one using the Base36 input!
  1136.                                 } else if ($objParent->isRoot()) {
  1137.                                         $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:345px">'.$suffix.'</td>';
  1138.                                         if ($enable_weid_presentation) $output .= ''; // WEID-editor not available for root nodes at the moment. For the moment you need to enter the OID (TODO: Create JavaScript WEID encoder/decoder)
  1139.                                 } else {
  1140.                                         if ($enable_weid_presentation) {
  1141.                                                 $output .= '     <td>'.$prefix.' <input oninput="OIDplusPagePublicObjects.frdl_oidid_change()" type="text" id="id" value="" style="width:100%;min-width:100px">'.$suffix.'</td>';
  1142.                                                 $output .= '     <td><input type="text" name="weid" id="weid" value="" oninput="OIDplusPagePublicObjects.frdl_weid_change()" style="width:100%;min-width:100px"></td>';
  1143.                                         } else {
  1144.                                                 $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:100px">'.$suffix.'</td>';
  1145.                                         }
  1146.                                 }
  1147.                         } else {
  1148.                                 $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:100px">'.$suffix.'</td>';
  1149.                         }
  1150.                         if ($accepts_asn1) $output .= '     <td><input type="text" id="asn1ids" value=""></td>';
  1151.                         if ($accepts_iri)  $output .= '     <td><input type="text" id="iris" value=""></td>';
  1152.                         $output .= '     <td><input type="text" id="ra_email" value="'.htmlentities($parent_ra_email ?? '').'"></td>';
  1153.                         $output .= '     <td><input type="text" id="comment" value=""></td>';
  1154.                         $output .= '     <td><input type="checkbox" id="hide"></td>';
  1155.                         $output .= '     <td><button type="button" name="insert" id="insert" class="btn btn-success btn-xs update" onclick="OIDplusPagePublicObjects.crudActionInsert('.js_escape($parent).')">'._L('Insert').'</button></td>';
  1156.                         $output .= '     <td></td>';
  1157.                         $output .= '     <td></td>';
  1158.                         $output .= '     <td></td>';
  1159.                         $output .= '</tr>';
  1160.                         $output .= '</tfoot>';
  1161.                 } else {
  1162.                         if ($items_total-$items_hidden == 0) {
  1163.                                 $cols = ($parentNS == 'oid') ? 7 : 5;
  1164.                                 if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) {
  1165.                                         $cols++;
  1166.                                 }
  1167.                                 $output .= '<tfoot>';
  1168.                                 $output .= '<tr><td colspan="'.$cols.'">'._L('No items available').'</td></tr>';
  1169.                                 $output .= '</tfoot>';
  1170.                         }
  1171.                 }
  1172.  
  1173.                 $output .= '</table>';
  1174.                 $output .= '</div></div>';
  1175.  
  1176.                 if ($items_hidden == 1) {
  1177.                         $output .= '<p>'._L('One item is hidden. Please <a %1>log in</a> to see it.',$items_hidden,OIDplus::gui()->link('oidplus:login')).'</p>';
  1178.                 } else if ($items_hidden > 1) {
  1179.                         $output .= '<p>'._L('%1 items are hidden. Please <a %2>log in</a> to see them.',$items_hidden,OIDplus::gui()->link('oidplus:login')).'</p>';
  1180.                 }
  1181.  
  1182.                 return $output;
  1183.         }
  1184.  
  1185.         /**
  1186.          * @param string $html
  1187.          * @return string
  1188.          */
  1189.         protected static function objDescription(string $html): string {
  1190.                 // We allow HTML, but no hacking
  1191.                 $html = anti_xss($html);
  1192.  
  1193.                 return trim_br($html);
  1194.         }
  1195.  
  1196.         /**
  1197.          * 'quickbars' added 11 July 2019: Disabled because of two problems:
  1198.          *                                 1. When you load TinyMCE via AJAX using the left menu, the quickbar is immediately shown, even if TinyMCE does not have the focus
  1199.          *                                 2. When you load a page without TinyMCE using the left menu, the quickbar is still visible, although there is no edit
  1200.          * 'colorpicker', 'textcolor' and 'contextmenu' added in 07 April 2020, because it is built in in the core.
  1201.          * 'importcss' added 17 September 2020, because it breaks the "Format/Style" dropdown box ("styleselect" toolbar)
  1202.          * 'legacyoutput' added 24 September 2021, because it is declared as deprecated
  1203.          * 'spellchecker' added 6 October 2021, because it is declared as deprecated and marked for removal in TinyMCE 6.0
  1204.          * 'imagetools' and 'toc' added 23 February 2022, because they are declared as deprecated and marked for removal in TinyMCE 6.0 ("moving to premium")
  1205.          * @var string[]
  1206.          */
  1207.         public static $exclude_tinymce_plugins = array('fullpage', 'bbcode', 'quickbars', 'colorpicker', 'textcolor', 'contextmenu', 'importcss', 'legacyoutput', 'spellchecker', 'imagetools', 'toc');
  1208.  
  1209.         /**
  1210.          * @param string $name
  1211.          * @param string $content
  1212.          * @return string
  1213.          * @throws OIDplusConfigInitializationException
  1214.          * @throws OIDplusException
  1215.          */
  1216.         protected static function showMCE(string $name, string $content): string {
  1217.                 $mce_plugins = array();
  1218.                 foreach (glob(OIDplus::localpath().'vendor/tinymce/tinymce/plugins/*') as $m) { // */
  1219.                         $mce_plugins[] = basename($m);
  1220.                 }
  1221.  
  1222.                 foreach (self::$exclude_tinymce_plugins as $exclude) {
  1223.                         $index = array_search($exclude, $mce_plugins);
  1224.                         if ($index !== false) unset($mce_plugins[$index]);
  1225.                 }
  1226.  
  1227.                 $oidplusLang = OIDplus::getCurrentLang();
  1228.  
  1229.                 $langCandidates = array(
  1230.                         strtolower(substr($oidplusLang,0,2)).'_'.strtoupper(substr($oidplusLang,2,2)), // de_DE
  1231.                         strtolower(substr($oidplusLang,0,2)) // de
  1232.                 );
  1233.                 $tinyMCELang = '';
  1234.                 foreach ($langCandidates as $candidate) {
  1235.                         if (file_exists(OIDplus::localpath().'vendor/tweeb/tinymce-i18n/langs/'.$candidate.'.js')) {
  1236.                                 $tinyMCELang = $candidate;
  1237.                                 break;
  1238.                         }
  1239.                 }
  1240.  
  1241.                 $out = '<script>
  1242.                                 tinymce.EditorManager.baseURL = "vendor/tinymce/tinymce";
  1243.                                 tinymce.init({
  1244.                                         document_base_url: "'.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'",
  1245.                                         selector: "#'.$name.'",
  1246.                                         height: 200,
  1247.                                         statusbar: false,
  1248. //                                      menubar:false,
  1249. //                                      toolbar: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table | fontsizeselect",
  1250.                                         toolbar: "undo redo | styleselect | bold italic underline forecolor | bullist numlist | outdent indent | table | fontsizeselect",
  1251.                                         plugins: "'.implode(' ', $mce_plugins).'",
  1252.                                         mobile: {
  1253.                                                 theme: "mobile",
  1254.                                                 toolbar: "undo redo | styleselect | bold italic underline forecolor | bullist numlist | outdent indent | table | fontsizeselect",
  1255.                                                 plugins: "'.implode(' ', $mce_plugins).'"
  1256.                                         }
  1257.                                         '.($tinyMCELang == '' ? '' : ', language : "'.$tinyMCELang.'"').'
  1258.                                         '.($tinyMCELang == '' ? '' : ', language_url : "'.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'vendor/tweeb/tinymce-i18n/langs/'.$tinyMCELang.'.js"').'
  1259.                                 });
  1260.  
  1261.                                 pageChangeRequestCallbacks.push([OIDplusPagePublicObjects.cbQueryTinyMCE, "#'.$name.'"]);
  1262.                                 pageChangeCallbacks.push([OIDplusPagePublicObjects.cbRemoveTinyMCE, "#'.$name.'"]);
  1263.                         </script>';
  1264.  
  1265.                 $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?
  1266.  
  1267.                 $out .= '<textarea name="'.htmlentities($name).'" id="'.htmlentities($name).'">'.trim($content).'</textarea><br>';
  1268.  
  1269.                 return $out;
  1270.         }
  1271.  
  1272.         /**
  1273.          * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1
  1274.          * @return bool
  1275.          * @throws OIDplusException
  1276.          */
  1277.         public function oobeRequested(): bool {
  1278.                 return OIDplus::config()->getValue('oobe_objects_done') == '0';
  1279.         }
  1280.  
  1281.         /**
  1282.          * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1
  1283.          * @param int $step
  1284.          * @param bool $do_edits
  1285.          * @param bool $errors_happened
  1286.          * @return void
  1287.          */
  1288.         public function oobeEntry(int $step, bool $do_edits, bool &$errors_happened)/*: void*/ {
  1289.                 echo '<h2>'._L('Step %1: Enable/Disable object type plugins',$step).'</h2>';
  1290.                 echo '<p>'._L('Which object types do you want to manage using OIDplus?').'</p>';
  1291.  
  1292.                 $enabled_ary = array();
  1293.  
  1294.                 foreach (OIDplus::getEnabledObjectTypes() as $ot) {
  1295.                         echo '<input type="checkbox" name="enable_ot_'.$ot::ns().'" id="enable_ot_'.$ot::ns().'"';
  1296.                         if (isset($_POST['sent'])) {
  1297.                                 if (isset($_POST['enable_ot_'.$ot::ns()])) {
  1298.                                         echo ' checked';
  1299.                                         $enabled_ary[] = $ot::ns();
  1300.                                 }
  1301.                         } else {
  1302.                                 echo ' checked';
  1303.                         }
  1304.                         echo '> <label for="enable_ot_'.$ot::ns().'">'.htmlentities($ot::objectTypeTitle()).'</label><br>';
  1305.                 }
  1306.  
  1307.                 foreach (OIDplus::getDisabledObjectTypes() as $ot) {
  1308.                         echo '<input type="checkbox" name="enable_ot_'.$ot::ns().'" id="enable_ot_'.$ot::ns().'"';
  1309.                         if (isset($_POST['sent'])) {
  1310.                                 if (isset($_POST['enable_ot_'.$ot::ns()])) {
  1311.                                         echo ' checked';
  1312.                                         $enabled_ary[] = $ot::ns();
  1313.                                 }
  1314.                         } else {
  1315.                                 echo ''; // <-- difference
  1316.                         }
  1317.                         echo '> <label for="enable_ot_'.$ot::ns().'">'.htmlentities($ot::objectTypeTitle()).'</label><br>';
  1318.                 }
  1319.  
  1320.                 $msg = '';
  1321.                 if ($do_edits) {
  1322.                         try {
  1323.                                 OIDplus::config()->setValue('objecttypes_enabled', implode(';', $enabled_ary));
  1324.                                 OIDplus::config()->setValue('oobe_objects_done', '1');
  1325.                         } catch (\Exception $e) {
  1326.                                 $msg = $e->getMessage();
  1327.                                 $errors_happened = true;
  1328.                         }
  1329.                 }
  1330.  
  1331.                 echo ' <font color="red"><b>'.$msg.'</b></font>';
  1332.         }
  1333.  
  1334.         /**
  1335.          * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8
  1336.          * @param string|null $user
  1337.          * @return array
  1338.          * @throws OIDplusException
  1339.          */
  1340.         public function getNotifications(string $user=null): array {
  1341.                 $notifications = array();
  1342.                 $res = OIDplus::db()->query("select id, title from ###objects order by ".OIDplus::db()->natOrder('id'));
  1343.                 if ($res->any()) {
  1344.                         $is_admin_logged_in = OIDplus::authUtils()->isAdminLoggedIn(); // run just once, for performance
  1345.                         while ($row = $res->fetch_array()) {
  1346.                                 if (empty($row['title'])) {
  1347.                                         if ($user === 'admin') {
  1348.                                                 $accept = $is_admin_logged_in;
  1349.                                         } else {
  1350.                                                 $accept = false;
  1351.                                                 if ($obj = OIDplusObject::parse($row['id'])) {
  1352.                                                         if ($obj->userHasWriteRights($user)) {
  1353.                                                                 $accept = true;
  1354.                                                         }
  1355.                                                 }
  1356.                                         }
  1357.  
  1358.                                         if ($accept) {
  1359.                                                 $notifications[] = array('WARN', _L('Object %1 has no title.', '<a '.OIDplus::gui()->link($row['id']).'>'.$row['id'].'</a>'));
  1360.                                         }
  1361.                                 }
  1362.                         }
  1363.                 }
  1364.                 return $notifications;
  1365.         }
  1366.  
  1367. }
  1368.