Subversion Repositories oidplus

Rev

Rev 93 | 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 OIDplusTree {
  21.  
  22.         public static function nonjs_menu() {
  23.                 $json = array();
  24.  
  25.                 foreach (OIDplus::getPagePlugins('public') as $plugin) {
  26.                         $plugin->tree($json, null, true);
  27.                 }
  28.  
  29.                 $static_node_id = isset($_REQUEST['goto']) ? $_REQUEST['goto'] : 'oidplus:system';
  30.  
  31.                 foreach ($json as $x) {
  32.                         if ($static_node_id == $x['id']) echo '<b>';
  33.                         if (isset($x['indent'])) echo str_repeat('&nbsp', $x['indent']*5);
  34.                         echo '<a href="?goto='.urlencode($x['id']).'">';
  35.                         if (!empty($x['icon'])) echo '<img src="'.$x['icon'].'" alt="'.$x['id'].' icon"> ';
  36.                         echo htmlentities($x['text']).'</a><br>';
  37.                         if ($static_node_id == $x['id']) echo '</b>';
  38.                 }
  39.  
  40.         }
  41.  
  42.         public static function json_tree($req_id, $req_goto) {
  43.  
  44.                 if (!isset($req_id) || ($req_id == '#')) {
  45.                         foreach (OIDplus::getPagePlugins('public') as $plugin) {
  46.                                 $plugin->tree($json);
  47.                         }
  48.                 } else {
  49.                         $json = self::tree_populate($req_id, null, false);
  50.                 }
  51.  
  52.                 return json_encode($json);
  53.         }
  54.  
  55.         public static function tree_populate($parent, $goto_path=null) {
  56.                 $children = array();
  57.  
  58.                 $parentObj = OIDplusObject::parse($parent);
  59.  
  60.                 @list($namespace, $oid) = explode(':', $parent, 2);
  61.                 if ($namespace == 'oid') $oid = substr($oid, 1); // führenden Punkt entfernen
  62.  
  63.                 if (!is_null($goto_path)) array_shift($goto_path);
  64.  
  65.                 $confidential_oids = array();
  66.  
  67.                 $res = OIDplus::db()->query("select id from ".OIDPLUS_TABLENAME_PREFIX."objects where confidential = '1'");
  68.                 while ($row = OIDplus::db()->fetch_array($res)) {
  69.                         $confidential_oids[] = $row['id'];
  70.                 }
  71.  
  72.                 $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."objects where parent = '".OIDplus::db()->real_escape_string($parent)."' order by ".OIDplus::db()->natOrder('id'));
  73.                 while ($row = OIDplus::db()->fetch_array($res)) {
  74.                         $obj = OIDplusObject::parse($row['id']);
  75.  
  76.                         if (!$obj->userHasReadRights()) continue;
  77.  
  78.                         $child = array();
  79.                         $child['id'] = $row['id'];
  80.  
  81.                         // Anzeigenamen (relative OID) bestimmen
  82.                         $child['text'] = $obj->jsTreeNodeName($parentObj);
  83.                         $child['text'] .= empty($row['title']) ? /*' -- <i>'.htmlentities('Title missing').'</i>'*/ '' : ' -- <b>' . htmlentities($row['title']) . '</b>';
  84.  
  85.                         $is_confidential = false;
  86.                         foreach ($confidential_oids as $test) {
  87.                                 $is_confidential |= ($row['id'] === $test) || (strpos($row['id'],$test.'.') === 0);
  88.                         }
  89.                         if ($is_confidential) {
  90.                                 $child['text'] = '<font color="gray"><i>'.$child['text'].'</i></font>';
  91.                         }
  92.  
  93.                         // Icon bestimmen
  94.                         $child['icon'] = $obj->getIcon($row);
  95.  
  96.                         // Feststellen, ob es weitere Unter-OIDs gibt
  97.                         if (!is_null($goto_path) && (count($goto_path) > 0) && ($goto_path[0] === $row['id'])) {
  98.                                 $child['children'] = self::tree_populate($row['id'], $goto_path);
  99.                                 $child['state'] = array("opened" => true);
  100.                         } else {
  101.                                 $res2 = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."objects where parent = '".OIDplus::db()->real_escape_string($row['id'])."'");
  102.                                 $child['children'] = OIDplus::db()->num_rows($res2) > 0;
  103.                         }
  104.  
  105.                         $children[] = $child;
  106.                 }
  107.  
  108.                 return $children;
  109.         }
  110. }
  111.