grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026. -------------------------------------------------------------------------- */ /** @file * @brief */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } /** * Common GLPI object **/ class CommonGLPI { /// GLPI Item type cache : set dynamically calling getType protected $type = -1; /// Display list on Navigation Header protected $displaylist = true; /// Show Debug public $showdebug = false; /// Tab orientation : horizontal or vertical public $taborientation = 'horizontal'; /// Need to get item to show tab public $get_item_to_display_tab = false; static protected $othertabs = array(); /** * Return the localized name of the current Type * Should be overloaded in each new class * * @return string **/ static function getTypeName($nb=0) { return __('General'); } /** * Return the type of the object : class name * * @return string **/ static function getType() { return get_called_class(); } /** * Register tab on an objet * * @since version 0.83 * * @param $typeform string object class name to add tab on form * @param $typetab string object class name which manage the tab **/ static function registerStandardTab($typeform, $typetab) { if (isset(self::$othertabs[$typeform])) { self::$othertabs[$typeform][] = $typetab; } else { self::$othertabs[$typeform] = array($typetab); } } /** * Get the array of Tab managed by other types * Getter for plugin (ex PDF) to access protected property * * @since version 0.83 * * @param $typeform string object class name to add tab on form * * @return array of types **/ static function getOtherTabs($typeform) { if (isset(self::$othertabs[$typeform])) { return self::$othertabs[$typeform]; } return array(); } /** * Define tabs to display * * NB : Only called for existing object * * @param $options array * - withtemplate is a template view ? * * @return array containing the onglets **/ function defineTabs($options=array()) { $ong = array(); $this->addDefaultFormTab($ong); return $ong; } /** * return all the tabs for current object * * @since version 0.83 * * @param $options array * - withtemplate is a template view ? * * @return array containing the onglets **/ final function defineAllTabs($options=array()) { global $CFG_GLPI; $onglets = array(); // Tabs known by the object if ($this->isNewItem()) { $this->addDefaultFormTab($onglets); } else { $onglets = $this->defineTabs($options); } // Object with class with 'addtabon' attribute if (isset(self::$othertabs[$this->getType()]) && !$this->isNewItem()) { foreach (self::$othertabs[$this->getType()] as $typetab) { $this->addStandardTab($typetab, $onglets, $options); } } $class = $this->getType(); if (($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) && (!$this->isNewItem() || $this->showdebug) && (method_exists($class, 'showDebug') || InfoCom::canApplyOn($class) || in_array($class, $CFG_GLPI["reservation_types"]))) { $onglets[-2] = __('Debug'); } // // Single tab // if (empty($onglets)) { // $onglets['empty'] = $this->getTypeName(1); // } return $onglets; } /** * Add standard define tab * * @param $itemtype itemtype link to the tab * @param &$ong array defined tab array * @param $options array of options (for withtemplate) * * @return $this **/ function addStandardTab($itemtype, array &$ong, array $options) { $withtemplate = 0; if (isset($options['withtemplate'])) { $withtemplate = $options['withtemplate']; } switch ($itemtype) { default : if (!is_integer($itemtype) && ($obj = getItemForItemtype($itemtype))) { $titles = $obj->getTabNameForItem($this, $withtemplate); if (!is_array($titles)) { $titles = array(1 => $titles); } foreach ($titles as $key => $val) { if (!empty($val)) { $ong[$itemtype.'$'.$key] = $val; } } } break; } return $this; } /** * @since version 0.85 * * @param $ong array * * @return $this **/ function addDefaultFormTab(array &$ong) { global $CFG_GLPI; if (self::isLayoutExcludedPage() || !self::isLayoutWithMain() || !method_exists($this, "showForm")) { $ong[$this->getType().'$main'] = $this->getTypeName(1); } return $this; } /** * get menu content * * @since version 0.85 * * @return array for menu **/ static function getMenuContent() { $menu = array(); $type = static::getType(); $item = new $type(); $forbidden = $type::getForbiddenActionsForMenu(); $debug = false; if ($item instanceof CommonDBTM) { if ($type::canView()) { $menu['title'] = static::getMenuName(); $menu['shortcut'] = static::getMenuShorcut(); $menu['page'] = static::getSearchURL(false); $menu['links']['search'] = static::getSearchURL(false); if (!in_array('add', $forbidden) && $type::canCreate()) { if ($item->maybeTemplate()) { $menu['links']['add'] = '/front/setup.templates.php?'.'itemtype='.$type. '&add=1'; if (!in_array('template', $forbidden)) { $menu['links']['template'] = '/front/setup.templates.php?'.'itemtype='.$type. '&add=0'; } } else { $menu['links']['add'] = static::getFormURL(false); } } if ($data = static::getAdditionalMenuLinks()) { $menu['links'] += $data; } } } else { if (!method_exists($type, 'canView') || $item->canView()) { $menu['title'] = static::getMenuName(); $menu['shortcut'] = static::getMenuShorcut(); $menu['page'] = static::getSearchURL(false); $menu['links']['search'] = static::getSearchURL(false); } } if ($data = static::getAdditionalMenuOptions()) { $menu['options'] = $data; } if ($data = static::getAdditionalMenuContent()) { $newmenu[strtolower($type)] = $menu; // Force overwrite existing menu foreach ($data as $key => $val) { $newmenu[$key] = $val; } $newmenu['is_multi_entries'] = true; $menu = $newmenu; } if (count($menu)) { return $menu; } return false; } /** * get additional menu content * * @since version 0.85 * * @return array for menu **/ static function getAdditionalMenuContent() { return false; } /** * Get forbidden actions for menu : may be add / template * * @since version 0.85 * * @return array of forbidden actions **/ static function getForbiddenActionsForMenu() { return array(); } /** * Get additional menu options * * @since version 0.85 * * @return array of additional options **/ static function getAdditionalMenuOptions() { return false; } /** * Get additional menu links * * @since version 0.85 * * @return array of additional options **/ static function getAdditionalMenuLinks() { return false; } /** * Get menu shortcut * * @since version 0.85 * * @return character menu shortcut key **/ static function getMenuShorcut() { return ''; } /** * Get menu name * * @since version 0.85 * * @return character menu shortcut key **/ static function getMenuName() { return static::getTypeName(Session::getPluralNumber()); } /** * Get Tab Name used for itemtype * * NB : Only called for existing object * Must check right on what will be displayed + template * * @since version 0.83 * * @param $item CommonDBTM object for which the tab need to be displayed * @param $withtemplate boolean is a template object ? (default 0) * * @return string tab name **/ function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { return ''; } /** * show Tab content * * @since version 0.83 * * @param $item CommonGLPI object for which the tab need to be displayed * @param $tabnum integer tab number (default 1) * @param $withtemplate boolean is a template object ? (default 0) * * @return true **/ static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) { return false; } /** * display standard tab contents * * @param $item CommonGLPI object for which the tab need to be displayed * @param $tab string tab name * @param $withtemplate boolean is a template object ? (default 0) * @param $options array additional options to pass * * @return true **/ static function displayStandardTab(CommonGLPI $item, $tab, $withtemplate=0, $options=array()) { switch ($tab) { // All tab case -1 : // get tabs and loop over $ong = $item->defineAllTabs(array('withtemplate' => $withtemplate)); if (!self::isLayoutExcludedPage() && self::isLayoutWithMain()) { //on classical and vertical split; the main tab is always displayed array_shift($ong); } if (count($ong)) { foreach ($ong as $key => $val) { if ($key != 'empty') { echo "