Subversion Repositories oidplus

Rev

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

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