Subversion Repositories oidplus

Rev

Rev 104 | 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.                 $static_node_id = isset($_REQUEST['goto']) ? $_REQUEST['goto'] : 'oidplus:system';
  26.  
  27.                 foreach (OIDplus::getPagePlugins('public') as $plugin) {
  28.                         $plugin->tree($json, null, true, $static_node_id);
  29.                 }
  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.         // req_id comes from jsTree via AJAX
  43.         // req_goto comes from the user (GET argument)
  44.         public static function json_tree($req_id, $req_goto) {
  45.                 $json = array();
  46.  
  47.                 if (!isset($req_id) || ($req_id == '#')) {
  48.                         // 'ra' and 'admin' pages will not be iterated, because they usually have no tree icon, or an icon underneath the login section
  49.                         foreach (OIDplus::getPagePlugins('public') as $plugin) {
  50.                                 $plugin->tree($json, null, false, $req_goto);
  51.                         }
  52.                 } else {
  53.                         $json = self::tree_populate($req_id);
  54.                 }
  55.  
  56.                 return json_encode($json);
  57.         }
  58.  
  59.         public static function tree_populate($parent, $goto_path=null) {
  60.                 $children = array();
  61.  
  62.                 $parentObj = OIDplusObject::parse($parent);
  63.  
  64.                 @list($namespace, $oid) = explode(':', $parent, 2);
  65.                 if ($namespace == 'oid') $oid = substr($oid, 1); // führenden Punkt entfernen
  66.  
  67.                 if (!is_null($goto_path)) array_shift($goto_path);
  68.  
  69.                 $confidential_oids = array();
  70.  
  71.                 $res = OIDplus::db()->query("select id from ".OIDPLUS_TABLENAME_PREFIX."objects where confidential = '1'");
  72.                 while ($row = OIDplus::db()->fetch_array($res)) {
  73.                         $confidential_oids[] = $row['id'];
  74.                 }
  75.  
  76.                 $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."objects where parent = '".OIDplus::db()->real_escape_string($parent)."' order by ".OIDplus::db()->natOrder('id'));
  77.                 while ($row = OIDplus::db()->fetch_array($res)) {
  78.                         $obj = OIDplusObject::parse($row['id']);
  79.  
  80.                         if (!$obj->userHasReadRights()) continue;
  81.  
  82.                         $child = array();
  83.                         $child['id'] = $row['id'];
  84.  
  85.                         // Anzeigenamen (relative OID) bestimmen
  86.                         $child['text'] = $obj->jsTreeNodeName($parentObj);
  87.                         $child['text'] .= empty($row['title']) ? /*' -- <i>'.htmlentities('Title missing').'</i>'*/ '' : ' -- <b>' . htmlentities($row['title']) . '</b>';
  88.  
  89.                         $is_confidential = false;
  90.                         foreach ($confidential_oids as $test) {
  91.                                 $is_confidential |= ($row['id'] === $test) || (strpos($row['id'],$test.'.') === 0);
  92.                         }
  93.                         if ($is_confidential) {
  94.                                 $child['text'] = '<font color="gray"><i>'.$child['text'].'</i></font>';
  95.                         }
  96.  
  97.                         // Icon bestimmen
  98.                         $child['icon'] = $obj->getIcon($row);
  99.  
  100.                         // Feststellen, ob es weitere Unter-OIDs gibt
  101.                         if (!is_null($goto_path) && (count($goto_path) > 0) && ($goto_path[0] === $row['id'])) {
  102.                                 $child['children'] = self::tree_populate($row['id'], $goto_path);
  103.                                 $child['state'] = array("opened" => true);
  104.                         } else {
  105.                                 $res2 = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."objects where parent = '".OIDplus::db()->real_escape_string($row['id'])."'");
  106.                                 $child['children'] = OIDplus::db()->num_rows($res2) > 0;
  107.                         }
  108.  
  109.                         $children[] = $child;
  110.                 }
  111.  
  112.                 return $children;
  113.         }
  114. }
  115.