. @package archires @author Nelly Mahu-Lasson, Xavier Caillaud @copyright Copyright (c) 2016-2021 Archires plugin team @license AGPL License 3.0 or (at your option) any later version http://www.gnu.org/licenses/agpl-3.0-standalone.html @link https://forge.glpi-project.org/projects/archires @since version 2.2 -------------------------------------------------------------------------- */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access directly to this file"); } class PluginArchiresView extends CommonDBTM { static $rightname = "plugin_archires"; const PLUGIN_ARCHIRES_NETWORK_COLOR = 0; const PLUGIN_ARCHIRES_VLAN_COLOR = 1; const PLUGIN_ARCHIRES_JPEG_FORMAT = 0; const PLUGIN_ARCHIRES_PNG_FORMAT = 1; const PLUGIN_ARCHIRES_GIF_FORMAT = 2; const PLUGIN_ARCHIRES_SVG_FORMAT = 3; static function getTypeName($nb=0) { return _n('View', 'Views', $nb); } function rawSearchOptions() { $tab = []; $tab[] = ['id' => 'common', 'name' => self::getTypeName(2)]; $tab[] = ['id' => '1', 'table' => $this->getTable(), 'field' =>'name', 'name' => __('Name'), 'datatype' => 'itemlink', 'itemlink_type' => $this->getType()]; $tab[] = ['id' => '2', 'table' => $this->getTable(), 'field' => 'computer', 'name' => _n('Computer', 'Computers', 2), 'datatype' => 'bool']; $tab[] = ['id' => '3', 'table' => $this->getTable(), 'field' => 'networking', 'name' => _n('Network equipment', 'Network equipments', 2, 'archires'), 'datatype' => 'bool']; $tab[] = ['id' => '4', 'table' => $this->getTable(), 'field' => 'printer', 'name' => _n('Printer', 'Printers', 2), 'datatype' => 'bool']; $tab[] = ['id' => '5', 'table' => $this->getTable(), 'field' => 'peripheral', 'name' => _n('Device', 'Devices', 2), 'datatype' => 'bool']; $tab[] = ['id' => '6', 'table' => $this->getTable(), 'field' => 'phone', 'name' => _n('Phone', 'Phones', 2), 'datatype' => 'bool']; $tab[] = ['id' => '7', 'table' => $this->getTable(), 'field' => 'display_ports', 'name' => __('Display sockets', 'archires'), 'datatype' => 'text']; $tab[] = ['id' => '8', 'table' => $this->getTable(), 'field' => 'display_ip', 'name' => __('Display IP/Mask', 'archires'), 'datatype' => 'bool']; $tab[] = ['id' => '9', 'table' => $this->getTable(), 'field' => 'display_type', 'name' => __('Display item types', 'archires'), 'datatype' => 'bool']; $tab[] = ['id' => '10', 'table' => $this->getTable(), 'field' => 'display_state', 'name' => __('Display item statuses', 'archires'), 'datatype' => 'bool']; $tab[] = ['id' => '11', 'table' => $this->getTable(), 'field' => 'display_location', 'name' => __('Display item locations', 'archires'), 'datatype' => 'bool']; $tab[] = ['id' => '12', 'table' => $this->getTable(), 'field' => 'display_entity', 'name' => __('Display item entities', 'archires'), 'datatype' => 'bool']; $tab[] = ['id' => '13', 'table' => $this->getTable(), 'field' => 'engine', 'name' => __('Rendering engine', 'archires')]; $tab[] = ['id' => '14', 'table' => $this->getTable(), 'field' => 'format', 'name' => __('Image format', 'archires')]; $tab[] = ['id' => '15', 'table' => $this->getTable(), 'field' => 'color', 'name' => __('Color', 'archires')]; return $tab; } function dropdownObject($obj) { global $DB; $dbu = new DbUtils(); $ID = $obj->fields["id"]; $query = ['SELECT' => ['id', 'name'], 'FROM' => $obj->getTable(), 'WHERE' => ['is_deleted' => 0]]; // Add Restrict to current entities if ($obj->isEntityAssign()) { $query['WHERE'] += $dbu->getEntitiesRestrictCriteria($obj->getTable()); } $query['ORDER'] = 'name ASC'; if ($result = $DB->request($query)) { if (count($result)) { echo ""; } } } function dropdownView($obj,$default) { global $DB; if (isset($obj->fields["id"])) { $default = $obj->fields["plugin_archires_views_id"]; } $query = ['SELECT' => ['id', 'name'], 'FROM' => $this->getTable(), 'WHERE' => ['is_deleted' => 0, 'entities_id' => $_SESSION["glpiactive_entity"]], 'ORDER' => 'name ASC']; echo ""; } static function linkToAllViews($item) { echo "
"; echo "getID()."&querytype=".$item->getType()."\">". __('See all views', 'archires'); echo "
"; } function viewSelect($obj,$plugin_archires_views_id,$select=0) { global $CFG_GLPI,$DB; $querytype = get_class($obj); $ID = $obj->fields["id"]; $object_view = $obj->fields["plugin_archires_views_id"]; if (!isset($plugin_archires_views_id)) { $plugin_archires_views_id = $object_view; } if ($select) { // display only echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
".__('Display', 'archires'); $this->dropdownObject($obj); echo "".self::getTypeName(2); $this->dropdownView(-1, $plugin_archires_views_id); echo ""; echo " "; echo " "; echo "
"; Html::closeForm(); } echo "[".__('SVG')."]"; } function showForm($ID, $options=[]) { $this->initForm($ID, $options); $this->showFormHeader($options); echo ""; echo "".__('Name').""; echo ""; Html::autocompletionTextField($this, "name", ['size' => 20]); echo ""; echo "".__('Display of items', 'archires').""; echo ""; echo ""._n('Computer', 'Computers', 2).""; echo ""; Dropdown::showYesNo("computer",$this->fields["computer"]); echo ""; echo ""._n('Network equipment', 'Network equipments', 2, 'archires').""; echo ""; Dropdown::showYesNo("networking",$this->fields["networking"]); echo ""; echo ""; echo ""._n('Printer', 'Printers', 2).""; echo ""; Dropdown::showYesNo("printer",$this->fields["printer"]); echo ""; echo ""._n('Device', 'Devices', 2).""; echo ""; Dropdown::showYesNo("peripheral",$this->fields["peripheral"]); echo ""; echo ""; echo ""._n('Phone', 'Phones', 2).""; echo ""; Dropdown::showYesNo("phone",$this->fields["phone"]); echo " "; echo "".__('Display description', 'archires').""; echo ""; echo "".__('Display sockets', 'archires').""; echo ""; echo "".__('Display IP/Mask', 'archires').""; echo ""; Dropdown::showYesNo("display_ip",$this->fields["display_ip"]); echo ""; echo ""; echo "".__('Display item types', 'archires').""; echo ""; Dropdown::showYesNo("display_type",$this->fields["display_type"]); echo ""; echo "".__('Display item statuses', 'archires').""; echo ""; Dropdown::showYesNo("display_state",$this->fields["display_state"]); echo ""; echo ""; echo "".__('Display item locations', 'archires').""; echo ""; Dropdown::showYesNo("display_location",$this->fields["display_location"]); echo ""; echo "".__('Display item entities', 'archires').""; echo ""; Dropdown::showYesNo("display_entity",$this->fields["display_entity"]); echo ""; echo "".__('Generation', 'archires').""; echo ""; echo "".__('Rendering engine', 'archires').""; echo " "; Html::showToolTip(nl2br(__('With neato, the sockets will not be displayed', 'archires'))); echo ""; echo "".__('Image format', 'archires').""; echo ""; echo ""; echo "".__('Color', 'archires').""; echo ""; $this->showFormButtons($options); return true; } static function showView($item) { global $DB; $plugin_archires_views_id = $item->fields["plugin_archires_views_id"]; if (!$plugin_archires_views_id) { return false; } $view = new self(); $view->getFromDB($plugin_archires_views_id); $name_config = $view->fields["name"]; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; $engine = ''; if ($view->fields["engine"] != 0) { $engine = "Neato"; } else { $engine = "Dot"; } echo ""; echo "
".sprintf(__('%1$s: %2$s'), self::getTypeName(1), $name_config); echo "
".__('Display of items', 'archires')."".__('Display description', 'archires')."".__('Generation', 'archires'). "
"; if ($view->fields["computer"] != 0) { printf(__('%1$s: %2$s'), _n('Computer', 'Computers', 2), __('Yes')); } else { printf(__('%1$s: %2$s'), _n('Computer', 'Computers', 2), __('No')); } echo "
"; if ($view->fields["networking"] != 0) { printf(__('%1$s: %2$s'), _n('Network equipment', 'Network equipments', 2, 'archires'), __('Yes')); } else { printf(__('%1$s: %2$s'), _n('Network equipment', 'Network equipments', 2, 'archires'), __('No')); } echo "
"; if ($view->fields["printer"] !=0 ) { printf(__('%1$s: %2$s'), _n('Printer', 'Printers', 2), __('Yes')); } else { printf(__('%1$s: %2$s'), _n('Printer', 'Printers', 2), __('No')); } echo "
"; if ($view->fields["peripheral"]!=0) { printf(__('%1$s: %2$s'), _n('Device', 'Devices', 2), __('Yes')); } else { printf(__('%1$s: %2$s'), _n('Device', 'Devices', 2), __('No')); } echo "
"; if ($view->fields["phone"] != 0) { printf(__('%1$s: %2$s'), _n('Phone', 'Phones', 2), __('Yes')); } else { printf(__('%1$s: %2$s'), _n('Phone', 'Phones', 2), __('No')); } echo "
"; if ($view->fields["display_ports"] != 0) { printf(__('%1$s: %2$s'), __('Display sockets', 'archires'), __('Yes')); } else { printf(__('%1$s: %2$s'), __('Display sockets', 'archires'), __('No')); } echo "
"; if ($view->fields["display_ip"] != 0) { printf(__('%1$s: %2$s'), __('Display IP/Mask', 'archires'), __('Yes')); } else { printf(__('%1$s: %2$s'), __('Display IP/Mask', 'archires'), __('No')); } echo "
"; if ($view->fields["display_type"] != 0) { printf(__('%1$s: %2$s'), __('Display item types', 'archires'), __('Yes')); } else { printf(__('%1$s: %2$s'), __('Display item types', 'archires'), __('No')); } echo "
"; if ($view->fields["display_state"] != 0) { printf(__('%1$s: %2$s'), __('Display item statuses', 'archires'), __('Yes')); } else { printf(__('%1$s: %2$s'), __('Display item statuses', 'archires'), __('No')); } echo "
"; if ($view->fields["display_location"] != 0) { printf(__('%1$s: %2$s'), __('Display item locations', 'archires'), __('Yes')); } else { printf(__('%1$s: %2$s'), __('Display item locations', 'archires'), __('No')); } echo "
"; if ($view->fields["display_entity"] != 0) { printf(__('%1$s: %2$s'), __('Display item entities', 'archires'), __('Yes')); } else { printf(__('%1$s: %2$s'), __('Display item entities', 'archires'), __('No')); } echo "
". sprintf(__('%1$s: %2$s'), __('All'), sprintf(__('%1$s %2$s'), __('Rendering engine', 'archires'), $engine)); echo "
"; $format_graph = ''; if ($view->fields["format"] == self::PLUGIN_ARCHIRES_JPEG_FORMAT) { $format_graph = "jpeg"; } else if ($view->fields["format"] == self::PLUGIN_ARCHIRES_PNG_FORMAT) { $format_graph = "png"; } else if ($view->fields["format"] == self::PLUGIN_ARCHIRES_GIF_FORMAT) { $format_graph = "gif"; } printf(__('%1$s: %2$s'), __('Image format', 'archires'), $format_graph); echo "
"; } static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) { switch ($item->getType()) { case 'PluginArchiresApplianceQuery' : case 'PluginArchiresLocationQuery' : case 'PluginArchiresNetworkEquipmentQuery' : switch ($tabnum) { case 1 : self::showView($item); break; } break; } return true; } function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { if (!$withtemplate && Session::haveRight("plugin_archires", READ)) { switch ($item->getType()) { case 'PluginArchiresApplianceQuery' : case 'PluginArchiresLocationQuery' : case 'PluginArchiresNetworkEquipmentQuery' : return self::getTypeName(1); } } return ''; } }