Subversion Repositories oidplus

Rev

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

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