Subversion Repositories oidplus

Rev

Rev 145 | 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. if (!defined('IN_OIDPLUS')) die();
  21.  
  22. class OIDplusTree {
  23.  
  24.         public static function nonjs_menu() {
  25.                 $json = array();
  26.  
  27.                 $static_node_id = isset($_REQUEST['goto']) ? $_REQUEST['goto'] : 'oidplus:system';
  28.  
  29.                 foreach (OIDplus::getPagePlugins('public') as $plugin) {
  30.                         $plugin->tree($json, null, true, $static_node_id);
  31.                 }
  32.  
  33.                 foreach ($json as $x) {
  34.                         if ($static_node_id == $x['id']) echo '<b>';
  35.                         if (isset($x['indent'])) echo str_repeat('&nbsp', $x['indent']*5);
  36.                         echo '<a href="?goto='.urlencode($x['id']).'">';
  37.                         if (!empty($x['icon'])) echo '<img src="'.$x['icon'].'" alt=""> ';
  38.                         echo htmlentities($x['text']).'</a><br>';
  39.                         if ($static_node_id == $x['id']) echo '</b>';
  40.                 }
  41.  
  42.         }
  43.  
  44.         // req_id comes from jsTree via AJAX
  45.         // req_goto comes from the user (GET argument)
  46.         public static function json_tree($req_id, $req_goto) {
  47.                 $json = array();
  48.  
  49.                 if (!isset($req_id) || ($req_id == '#')) {
  50.                         // 'ra' and 'admin' pages will not be iterated, because they usually have no tree icon, or an icon underneath the login section
  51.                         foreach (OIDplus::getPagePlugins('public') as $plugin) {
  52.                                 $plugin->tree($json, null, false, $req_goto);
  53.                         }
  54.                 } else {
  55.                         $json = self::tree_populate($req_id);
  56.                 }
  57.  
  58.                 return json_encode($json);
  59.         }
  60.  
  61.         public static function tree_populate($parent, $goto_path=null) {
  62.                 $children = array();
  63.  
  64.                 $parentObj = OIDplusObject::parse($parent);
  65.  
  66.                 @list($namespace, $oid) = explode(':', $parent, 2);
  67.                 if ($namespace == 'oid') $oid = substr($oid, 1); // führenden Punkt entfernen
  68.  
  69.                 if (!is_null($goto_path)) array_shift($goto_path);
  70.  
  71.                 $confidential_oids = array();
  72.  
  73.                 $res = OIDplus::db()->query("select id from ".OIDPLUS_TABLENAME_PREFIX."objects where confidential = '1'");
  74.                 while ($row = OIDplus::db()->fetch_array($res)) {
  75.                         $confidential_oids[] = $row['id'];
  76.                 }
  77.  
  78.                 $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."objects where parent = ? order by ".OIDplus::db()->natOrder('id'), array($parent));
  79.                 while ($row = OIDplus::db()->fetch_array($res)) {
  80.                         $obj = OIDplusObject::parse($row['id']);
  81.  
  82.                         if (!$obj->userHasReadRights()) continue;
  83.  
  84.                         $child = array();
  85.                         $child['id'] = $row['id'];
  86.  
  87.                         // Anzeigenamen (relative OID) bestimmen
  88.                         $child['text'] = $obj->jsTreeNodeName($parentObj);
  89.                         $child['text'] .= empty($row['title']) ? /*' -- <i>'.htmlentities('Title missing').'</i>'*/ '' : ' -- <b>' . htmlentities($row['title']) . '</b>';
  90.  
  91.                         $is_confidential = false;
  92.                         foreach ($confidential_oids as $test) {
  93.                                 $is_confidential |= ($row['id'] === $test) || (strpos($row['id'],$test.'.') === 0);
  94.                         }
  95.                         if ($is_confidential) {
  96.                                 $child['text'] = '<font color="gray"><i>'.$child['text'].'</i></font>';
  97.                         }
  98.  
  99.                         // Icon bestimmen
  100.                         $child['icon'] = $obj->getIcon($row);
  101.  
  102.                         // Feststellen, ob es weitere Unter-OIDs gibt
  103.                         if (!is_null($goto_path) && (count($goto_path) > 0) && ($goto_path[0] === $row['id'])) {
  104.                                 $child['children'] = self::tree_populate($row['id'], $goto_path);
  105.                                 $child['state'] = array("opened" => true);
  106.                         } else {
  107.                                 $obj_children = $obj->getChildren();
  108.  
  109.                                 // Variant 1: Fast, but does not check for hidden OIDs
  110.                                 //$child_count = count($obj_children);
  111.  
  112.                                 // variant 2
  113.                                 $child_count = 0;
  114.                                 foreach ($obj_children as $obj_test) {
  115.                                         if (!$obj_test->userHasReadRights()) continue;
  116.                                         $child_count++;
  117.                                 }
  118.  
  119.                                 $child['children'] = $child_count > 0;
  120.                         }
  121.  
  122.                         $children[] = $child;
  123.                 }
  124.  
  125.                 return $children;
  126.         }
  127. }
  128.