Subversion Repositories oidplus

Rev

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