Subversion Repositories oidplus

Rev

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