Subversion Repositories oidplus

Rev

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

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 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 OIDplusMenuUtils {
  21.  
  22.         public static function nonjs_menu() {
  23.                 $json = array();
  24.  
  25.                 $static_node_id = isset($_REQUEST['goto']) ? $_REQUEST['goto'] : 'oidplus:system';
  26.  
  27.                 foreach (OIDplus::getPagePlugins() as $plugin) {
  28.                         // Note: The system (OIDplusMenuUtils) does only show the menu of
  29.                         //       publicPage plugins. Menu entries for RAs and Admins are
  30.                         //       handled by the tree() function of the plugin publicPages/090_login
  31.                         if (is_subclass_of($plugin, OIDplusPagePluginPublic::class)) {
  32.                                 $plugin->tree($json, null, true, $static_node_id);
  33.                         }
  34.                 }
  35.  
  36.                 foreach ($json as $x) {
  37.                         if ($static_node_id == $x['id']) echo '<b>';
  38.                         if (isset($x['indent'])) echo str_repeat('&nbsp', $x['indent']*5);
  39.                         $cur_lang = OIDplus::getCurrentLang();
  40.                         if ($cur_lang != OIDplus::DEFAULT_LANGUAGE) {
  41.                                 echo '<a href="?lang='.$cur_lang.'&amp;goto='.urlencode($x['id']).'">';
  42.                         } else {
  43.                                 echo '<a href="?goto='.urlencode($x['id']).'">';
  44.                         }
  45.                         if (!empty($x['icon'])) echo '<img src="'.$x['icon'].'" alt=""> ';
  46.                         echo htmlentities($x['text']).'</a><br>';
  47.                         if ($static_node_id == $x['id']) echo '</b>';
  48.                 }
  49.  
  50.         }
  51.  
  52.         // req_id comes from jsTree via AJAX
  53.         // req_goto comes from the user (GET argument)
  54.         public static function json_tree($req_id, $req_goto) {
  55.                 $json = array();
  56.  
  57.                 if (!isset($req_id) || ($req_id == '#')) {
  58.                         foreach (OIDplus::getPagePlugins() as $plugin) {
  59.                                 // Note: The system (OIDplusMenuUtils) does only show the menu of
  60.                                 //       publicPage plugins. Menu entries for RAs and Admins are
  61.                                 //       handled by the tree() function of the plugin publicPages/090_login
  62.                                 if (is_subclass_of($plugin, OIDplusPagePluginPublic::class)) {
  63.                                         $plugin->tree($json, null, false, $req_goto);
  64.                                 }
  65.                         }
  66.                 } else {
  67.                         $json = self::tree_populate($req_id);
  68.                 }
  69.  
  70.                 return $json;
  71.         }
  72.  
  73.         public static function tree_populate($parent, $goto_path=null) {
  74.                 $children = array();
  75.  
  76.                 $parentObj = OIDplusObject::parse($parent);
  77.  
  78.                 @list($namespace, $oid) = explode(':', $parent, 2);
  79.                 if ($namespace == 'oid') $oid = substr($oid, 1); // führenden Punkt entfernen
  80.  
  81.                 if (is_array($goto_path)) array_shift($goto_path);
  82.  
  83.                 $confidential_oids = array();
  84.  
  85.                 $res = OIDplus::db()->query("select id from ###objects where confidential = '1'");
  86.                 while ($row = $res->fetch_array()) {
  87.                         $confidential_oids[] = $row['id'];
  88.                 }
  89.  
  90.                 $res = OIDplus::db()->query("select * from ###objects where parent = ? order by ".OIDplus::db()->natOrder('id'), array($parent));
  91.                 while ($row = $res->fetch_array()) {
  92.                         $obj = OIDplusObject::parse($row['id']);
  93.  
  94.                         if (!$obj->userHasReadRights()) continue;
  95.  
  96.                         $child = array();
  97.                         $child['id'] = $row['id'];
  98.  
  99.                         // Anzeigenamen (relative OID) bestimmen
  100.                         $child['text'] = $obj->jsTreeNodeName($parentObj);
  101.                         $child['text'] .= empty($row['title']) ? /*' -- <i>'.htmlentities('Title missing').'</i>'*/ '' : ' -- <b>' . htmlentities($row['title']) . '</b>';
  102.  
  103.                         $is_confidential = false;
  104.                         foreach ($confidential_oids as $test) {
  105.                                 $is_confidential |= ($row['id'] === $test) || (strpos($row['id'],$test.'.') === 0);
  106.                         }
  107.                         if ($is_confidential) {
  108.                                 $child['text'] = '<font color="gray"><i>'.$child['text'].'</i></font>';
  109.                         }
  110.  
  111.                         // Icon bestimmen
  112.                         $child['icon'] = $obj->getIcon($row);
  113.  
  114.                         // Feststellen, ob es weitere Unter-OIDs gibt
  115.                         if ($goto_path === true) {
  116.                                 $child['children'] = self::tree_populate($row['id'], $goto_path);
  117.                                 $child['state'] = array("opened" => true);
  118.                         } else if (!is_null($goto_path) && (count($goto_path) > 0) && ($goto_path[0] === $row['id'])) {
  119.                                 $child['children'] = self::tree_populate($row['id'], $goto_path);
  120.                                 $child['state'] = array("opened" => true);
  121.                         } else {
  122.                                 $obj_children = $obj->getChildren();
  123.  
  124.                                 // Variant 1: Fast, but does not check for hidden OIDs
  125.                                 //$child_count = count($obj_children);
  126.  
  127.                                 // variant 2
  128.                                 $child_count = 0;
  129.                                 foreach ($obj_children as $obj_test) {
  130.                                         if (!$obj_test->userHasReadRights()) continue;
  131.                                         $child_count++;
  132.                                 }
  133.  
  134.                                 $child['children'] = $child_count > 0;
  135.                         }
  136.  
  137.                         $children[] = $child;
  138.                 }
  139.  
  140.                 return $children;
  141.         }
  142. }