Subversion Repositories oidplus

Rev

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 OIDplusGuid extends OIDplusObject {
  21.         private $guid;
  22.  
  23.         public function __construct($guid) {
  24.                 $this->guid = $guid;
  25.         }
  26.  
  27.         public static function parse($node_id) {
  28.                 @list($namespace, $guid) = explode(':', $node_id, 2);
  29.                 if ($namespace !== 'guid') return false;
  30.                 return new self($guid);
  31.         }
  32.  
  33.         public static function objectTypeTitle() {
  34.                 return "Globally Unique Identifier (GUID)";
  35.         }
  36.  
  37.         public static function objectTypeTitleShort() {
  38.                 return "GUID";
  39.         }
  40.  
  41.         public static function ns() {
  42.                 return 'guid';
  43.         }
  44.  
  45.         public static function root() {
  46.                 return 'guid:';
  47.         }
  48.  
  49.         public function isRoot() {
  50.                 return $this->guid == '';
  51.         }
  52.  
  53.         public function nodeId() {
  54.                 return 'guid:'.$this->guid;
  55.         }
  56.  
  57.         public function addString($str) {
  58.                 // TODO!
  59.                 return 'guid:'.$str;
  60.         }
  61.  
  62.         public function crudShowId(OIDplusObject $parent) {
  63.                 return $this->guid;
  64.         }
  65.  
  66.         public function crudInsertPrefix() {
  67.                 return '';
  68.         }
  69.  
  70.         public function jsTreeNodeName(OIDplusObject $parent = null) {
  71.                 if ($parent == null) return $this->objectTypeTitle();
  72.                 return $this->guid;
  73.         }
  74.  
  75.         public function defaultTitle() {
  76.                 return $this->guid;
  77.         }
  78.  
  79.         public function getContentPage(&$title, &$content) {
  80.                 if ($this->isRoot()) {
  81.                         $title = OIDplusGuid::objectTypeTitle();
  82.  
  83.                         $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."objects where parent = '".OIDplus::db()->real_escape_string(self::root())."'");
  84.                         if (OIDplus::db()->num_rows($res) > 0) {
  85.                                 $content  = 'Please select a GUID in the tree view at the left to show its contents.';
  86.                         } else {
  87.                                 $content  = 'Currently, no GUID is registered in the system.';
  88.                         }
  89.  
  90.                         if (OIDplus::authUtils()::isAdminLoggedIn()) {
  91.                                 $content .= '<h2>Manage root objects</h2>';
  92.                         } else {
  93.                                 $content .= '<h2>Available objects</h2>';
  94.                         }
  95.                         $content .= '%%CRUD%%';
  96.                 } else {
  97.                         $content = '<h2>Description</h2><br><br>%%DESC%%<br><br>'; // TODO: add more meta information about the object type
  98.  
  99.                         if ($this->userHasWriteRights()) {
  100.                                 $content .= '<h2>Create or change subsequent objects</h2>';
  101.                         } else {
  102.                                 $content .= '<h2>Subsequent objects</h2>';
  103.                         }
  104.                         $content .= '%%CRUD%%';
  105.                 }
  106.         }
  107. }
  108.  
  109. OIDplusObject::$registeredObjectTypes[] = 'OIDplusGuid';
  110.  
  111.