From 5d760d4992105ca46e95bd99b2f642434c7f8bdf Mon Sep 17 00:00:00 2001 From: LAUNAY Samuel <107540223+Lainow@users.noreply.github.com> Date: Wed, 21 Feb 2024 12:36:56 +0100 Subject: [PATCH] Migrate all pages to Twig --- front/computergroup.php | 8 +- front/credential.php | 8 +- front/databaseparam.php | 8 +- inc/computergroup.class.php | 52 +++-- inc/computergroupdynamic.class.php | 12 +- inc/computergroupstatic.class.php | 189 +++++----------- inc/contactlog.class.php | 212 ++++++++---------- inc/credential.class.php | 92 +++----- inc/databaseparam.class.php | 67 +++--- inc/databaseparam_computergroup.class.php | 179 ++++++--------- inc/databaseparam_credential.class.php | 184 ++++++--------- inc/menu.class.php | 65 +++--- setup.php | 2 +- templates/computergroup.html.twig | 29 +++ templates/computergroupstatic.html.twig | 126 +++++++++++ templates/contactlog.html.twig | 62 +++++ templates/credential.html.twig | 62 +++++ templates/databaseparam.html.twig | 48 ++++ .../databaseparam_computergroup.html.twig | 119 ++++++++++ templates/databaseparam_credential.html.twig | 120 ++++++++++ 20 files changed, 1022 insertions(+), 622 deletions(-) create mode 100644 templates/computergroup.html.twig create mode 100644 templates/computergroupstatic.html.twig create mode 100644 templates/contactlog.html.twig create mode 100644 templates/credential.html.twig create mode 100644 templates/databaseparam.html.twig create mode 100644 templates/databaseparam_computergroup.html.twig create mode 100644 templates/databaseparam_credential.html.twig diff --git a/front/computergroup.php b/front/computergroup.php index b24d8d2..44b6291 100644 --- a/front/computergroup.php +++ b/front/computergroup.php @@ -32,7 +32,13 @@ Session::checkRight("config", UPDATE); -Html::header(PluginDatabaseinventoryComputerGroup::getTypeName(Session::getPluralNumber()), $_SERVER['PHP_SELF'], "admin", "PluginDatabaseinventoryMenu", "computergroup"); +Html::header( + PluginDatabaseinventoryComputerGroup::getTypeName(Session::getPluralNumber()), + $_SERVER['PHP_SELF'], + "admin", + "PluginDatabaseinventoryMenu", + "computergroup" +); Search::show('PluginDatabaseinventoryComputerGroup'); diff --git a/front/credential.php b/front/credential.php index 94bd61e..a0b0fe7 100644 --- a/front/credential.php +++ b/front/credential.php @@ -32,7 +32,13 @@ Session::checkRight("config", UPDATE); -Html::header(PluginDatabaseinventoryCredential::getTypeName(Session::getPluralNumber()), $_SERVER['PHP_SELF'], "admin", "PluginDatabaseinventoryMenu", "credential"); +Html::header( + PluginDatabaseinventoryCredential::getTypeName(Session::getPluralNumber()), + $_SERVER['PHP_SELF'], + "admin", + "PluginDatabaseinventoryMenu", + "credential" +); Search::show('PluginDatabaseinventoryCredential'); diff --git a/front/databaseparam.php b/front/databaseparam.php index a9ca79d..0548471 100644 --- a/front/databaseparam.php +++ b/front/databaseparam.php @@ -32,7 +32,13 @@ Session::checkRight("config", UPDATE); -Html::header(PluginDatabaseinventoryDatabaseParam::getTypeName(Session::getPluralNumber()), $_SERVER['PHP_SELF'], "admin", "PluginDatabaseinventoryMenu", "databaseparam"); +Html::header( + PluginDatabaseinventoryDatabaseParam::getTypeName(Session::getPluralNumber()), + $_SERVER['PHP_SELF'], + "admin", + "PluginDatabaseinventoryMenu", + "databaseparam" +); Search::show('PluginDatabaseinventoryDatabaseParam'); diff --git a/inc/computergroup.class.php b/inc/computergroup.class.php index 8461941..e60878c 100644 --- a/inc/computergroup.class.php +++ b/inc/computergroup.class.php @@ -1,5 +1,35 @@ . + * ------------------------------------------------------------------------- + * @copyright Copyright (C) 2021-2023 by Teclib'. + * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html + * @link https://services.glpi-network.com + * ------------------------------------------------------------------------- + */ + +use Glpi\Application\View\TemplateRenderer; + /** * ------------------------------------------------------------------------- * DatabaseInventory plugin for GLPI @@ -142,27 +172,13 @@ public function rawSearchOptions() public function showForm($ID, array $options = []) { - $rand = mt_rand(); $this->initForm($ID, $options); - $this->showFormHeader($options); - - echo ""; - echo ""; - echo Html::input( - 'name', + TemplateRenderer::getInstance()->display( + '@databaseinventory/computergroup.html.twig', [ - 'value' => $this->fields["name"], - 'id' => "textfield_name$rand", + 'item' => $this ] ); - echo ""; - echo ""; - echo ""; - echo ""; - - $this->showFormButtons($options); return true; } @@ -259,7 +275,7 @@ public static function uninstall(Migration $migration) public static function getIcon() { - return "fas fa-list-alt"; + return "ti ti-sitemap"; } public function post_purgeItem() diff --git a/inc/computergroupdynamic.class.php b/inc/computergroupdynamic.class.php index a0b9fea..9eedba7 100644 --- a/inc/computergroupdynamic.class.php +++ b/inc/computergroupdynamic.class.php @@ -72,10 +72,12 @@ public static function getSpecificValueToDisplay($field, $values, array $options switch ($field) { case 'search': $count = 0; - if (strpos($values['id'], Search::NULLVALUE) === false) { - $computergroup_dynamic = new PluginDatabaseinventoryComputerGroupDynamic(); - $computergroup_dynamic->getFromDB($values['id']); - $count = $computergroup_dynamic->countDynamicItems(); + if (isset($values['id'])) { + if (strpos($values['id'], Search::NULLVALUE) === false) { + $computergroup_dynamic = new PluginDatabaseinventoryComputerGroupDynamic(); + $computergroup_dynamic->getFromDB($values['id']); + $count = $computergroup_dynamic->countDynamicItems(); + } } return ($count) ? $count : ' 0 '; @@ -183,7 +185,6 @@ private static function showForItem(PluginDatabaseinventoryComputerGroup $comput } $canedit = $computergroup->canEdit($ID); - echo "
"; if ($canedit) { $firsttime = true; // load dynamic search criteria from DB if exist @@ -236,7 +237,6 @@ function() { ); "); } - echo "
"; } return true; diff --git a/inc/computergroupstatic.class.php b/inc/computergroupstatic.class.php index b00fcd6..28c62bb 100644 --- a/inc/computergroupstatic.class.php +++ b/inc/computergroupstatic.class.php @@ -1,5 +1,35 @@ . + * ------------------------------------------------------------------------- + * @copyright Copyright (C) 2021-2023 by Teclib'. + * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html + * @link https://services.glpi-network.com + * ------------------------------------------------------------------------- + */ + +use Glpi\Application\View\TemplateRenderer; + /** * ------------------------------------------------------------------------- * DatabaseInventory plugin for GLPI @@ -91,136 +121,39 @@ private static function showForItem(PluginDatabaseinventoryComputerGroup $comput return false; } - $datas = []; - $used = []; - $params = [ - 'SELECT' => '*', - 'FROM' => self::getTable(), - 'WHERE' => ['plugin_databaseinventory_computergroups_id' => $ID], - ]; - - $iterator = $DB->request($params); - foreach ($iterator as $data) { - $datas[] = $data; - $used [] = $data['computers_id']; - } - $number = count($datas); - - $rand = mt_rand(); - - echo "
"; - if ($computergroup->canAddItem('itemtype')) { - echo "
"; - echo "
"; - - echo ""; - echo ""; - echo ""; - - echo ""; - echo "
" . __('Add an item') . "
"; - Dropdown::show( - "Computer", - [ - "name" => "computers_id", - "used" => $used, - "condition" => ["is_dynamic" => true] - ] - ); - echo ""; - - echo Html::hidden('plugin_databaseinventory_computergroups_id', ['value' => $ID]); - echo Html::submit(_x('button', 'Add'), ['name' => 'add_staticcomputer']); - echo "
"; - Html::closeForm(); - echo "
"; - } - echo "
"; - - $canread = $computergroup->can($ID, READ); - $canedit = $computergroup->can($ID, UPDATE); - echo "
"; - if ($canread) { - echo "
"; - if ($canedit) { - Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); - $massiveactionparams = ['num_displayed' - => min($_SESSION['glpilist_limit'], $number), - 'specific_actions' - => ['purge' => _x('button', 'Remove')], - 'container' - => 'mass' . __CLASS__ . $rand - ]; - Html::showMassiveActions($massiveactionparams); - } - echo ""; - $header_begin = ""; - $header_top = ''; - $header_bottom = ''; - $header_end = ''; - - if ($canedit) { - $header_top .= ""; - $header_bottom .= ""; - } - - $header_end .= ""; - $header_end .= ""; - $header_end .= ""; - $header_end .= ""; - $header_end .= ""; - $header_end .= ""; - echo $header_begin . $header_top . $header_end; - - foreach ($datas as $data) { - $computer = new Computer(); - $computer->getFromDB($data["computers_id"]); - $linkname = $computer->fields["name"]; - $itemtype = Computer::getType(); - if ($_SESSION["glpiis_ids_visible"] || empty($computer->fields["name"])) { - $linkname = sprintf(__('%1$s (%2$s)'), $linkname, $computer->fields["id"]); - } - $link = $itemtype::getFormURLWithID($computer->fields["id"]); - $name = "" . $linkname . ""; - echo ""; - - if ($canedit) { - echo ""; - } - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - } - echo $header_begin . $header_bottom . $header_end; - - echo "
" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); - $header_top .= "" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); - $header_bottom .= "" . __('Name') . "" . __('Automatic inventory') . "" . Entity::getTypeName(1) . "" . __('Serial number') . "" . __('Inventory number') . "
"; - Html::showMassiveActionCheckBox(__CLASS__, $data["id"]); - echo "fields['is_deleted']) && $computer->fields['is_deleted']) ? "class='tab_bg_2_2'" : "") - . ">" . $name . "" . Dropdown::getYesNo($computer->fields['is_dynamic']) . "" . Dropdown::getDropdownName( - "glpi_entities", - $computer->fields['entities_id'] - ); - echo "" - . (isset($computer->fields["serial"]) ? "" . $computer->fields["serial"] . "" : "-") - . "" - . (isset($computer->fields["otherserial"]) ? "" . $computer->fields["otherserial"] . "" : "-") - . "
"; - if ($canedit && $number) { - $massiveactionparams['ontop'] = false; - Html::showMassiveActions($massiveactionparams); - Html::closeForm(); + $staticsgroups = new PluginDatabaseinventoryComputerGroupStatic(); + $staticgrouplist = $staticsgroups->find( + [ + 'plugin_databaseinventory_computergroups_id' => $ID + ] + ); + + $computers = new Computer(); + $listofcomputers = []; + $used = []; + foreach ($staticgrouplist as $staticgroup) { + $used[] = $staticgroup['computers_id']; + if ($computers->getFromDB($staticgroup['computers_id'])) { + $listofcomputers[] = $computers->fields + + [ + 'entityname' => Entity::getById($computers->fields['entities_id'])->fields['completename'], + 'link' => $computers->getLinkURL(), + 'idcompgroupstatic' => $staticgroup['id'], + ]; } - echo "
"; } - echo "
"; + TemplateRenderer::getInstance()->display( + '@databaseinventory/computergroupstatic.html.twig', + [ + 'item' => PluginDatabaseinventoryDatabaseParam::getById($ID), + 'computerslist' => $listofcomputers, + 'groupstaticclass' => PluginDatabaseinventoryComputerGroupStatic::class, + 'canread' => $computergroup->can($ID, READ), + 'canedit' => $computergroup->can($ID, UPDATE), + 'canadd' => $computergroup->canAddItem('itemtype'), + 'used' => $used, + ] + ); return true; } diff --git a/inc/contactlog.class.php b/inc/contactlog.class.php index 802a69a..97a0f33 100644 --- a/inc/contactlog.class.php +++ b/inc/contactlog.class.php @@ -1,5 +1,35 @@ . + * ------------------------------------------------------------------------- + * @copyright Copyright (C) 2021-2023 by Teclib'. + * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html + * @link https://services.glpi-network.com + * ------------------------------------------------------------------------- + */ + +use Glpi\Application\View\TemplateRenderer; + /** * ------------------------------------------------------------------------- * DatabaseInventory plugin for GLPI @@ -81,139 +111,93 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ private static function showForDatabaseParams(PluginDatabaseinventoryDatabaseParam $databaseparams) { - /** @var DBmysql $DB */ - global $DB; - $ID = $databaseparams->getField('id'); if (!$databaseparams->can($ID, UPDATE)) { return false; } - $datas = []; - $params = [ - 'SELECT' => '*', - 'FROM' => self::getTable(), - 'WHERE' => ['plugin_databaseinventory_databaseparams_id' => $ID], - ]; - - $iterator = $DB->request($params); - foreach ($iterator as $data) { - $datas[] = $data; - } - $rand = mt_rand(); - - $canread = $databaseparams->can($ID, READ); - echo "
"; - if ($canread) { - echo "
"; - echo ""; - $header_begin = ""; - $header_top = ''; - $header_bottom = ''; - $header_end = ''; - - $header_end .= ""; - $header_end .= ""; - $header_end .= ""; - $header_end .= ""; - echo $header_begin . $header_top . $header_end; - - foreach ($datas as $data) { - echo ""; - - $credential = new PluginDatabaseinventoryCredential(); - $credential->getFromDB($data["plugin_databaseinventory_credentials_id"]); - $credential_link = PluginDatabaseinventoryCredential::getFormURLWithID($credential->fields["id"]); - $credential_linkname = $credential->fields["name"]; - $name = "" . $credential_linkname . ""; - - echo ""; - - $agent = new Agent(); - $agent->getFromDB($data["agents_id"]); - $agent_link = Agent::getFormURLWithID($data["agents_id"]); - $agent_linkname = $agent->fields["name"]; - $name = "" . $agent_linkname . ""; - echo ""; - - echo ""; - echo ""; - echo ""; + $contactlog = new PluginDatabaseinventoryContactLog(); + $contactloglist = $contactlog->find( + [ + 'plugin_databaseinventory_databaseparams_id' => $ID + ] + ); + + $credential = new PluginDatabaseinventoryCredential(); + $agent = new Agent(); + $listofctlog = []; + foreach ($contactloglist as $dbpctlog) { + if ($credential->getFromDB($dbpctlog['plugin_databaseinventory_credentials_id'])) { + $linkcred = $credential->getLinkURL(); + $credname = $credential->fields['name']; + } + if ($agent->getFromDB($dbpctlog['agents_id'])) { + $linkagent = $agent->getLinkURL(); + $agentname = $agent->fields['name']; + } + if (isset($linkcred) || isset($linkagent)) { + $listofctlog[] = $dbpctlog + [ + 'linkcred' => $linkcred ?? '', + 'linkagent' => $linkagent ?? '', + 'credname' => $credname ?? '', + 'agentname' => $agentname ?? '', + ]; } - echo $header_begin . $header_bottom . $header_end; - - echo "
" . PluginDatabaseinventoryCredential::getTypeName(0) . "" . Agent::getTypeName(0) . "" . __('Date') . "
" . $name . "" . $name . "" . $data["date_creation"] . "
"; - echo "
"; } - echo "
"; + TemplateRenderer::getInstance()->display( + '@databaseinventory/contactlog.html.twig', + [ + 'itemtype' => PluginDatabaseinventoryDatabaseParam::getType(), + 'contactlogs' => $listofctlog, + 'canread' => $databaseparams->can($ID, READ) + ] + ); return true; } private static function showForAgent(Agent $agent) { - /** @var DBmysql $DB */ - global $DB; - $ID = $agent->getField('id'); if (!$agent->can($ID, UPDATE)) { return false; } - $datas = []; - $params = [ - 'SELECT' => '*', - 'FROM' => self::getTable(), - 'WHERE' => ['agents_id' => $ID], - ]; - - $iterator = $DB->request($params); - foreach ($iterator as $data) { - $datas[] = $data; - } - $rand = mt_rand(); - - $canread = $agent->can($ID, READ); - echo "
"; - if ($canread) { - echo "
"; - echo ""; - $header_begin = ""; - $header_top = ''; - $header_bottom = ''; - $header_end = ''; - - $header_end .= ""; - $header_end .= ""; - $header_end .= ""; - $header_end .= ""; - echo $header_begin . $header_top . $header_end; - - foreach ($datas as $data) { - echo ""; - - $credential = new PluginDatabaseinventoryCredential(); - $credential->getFromDB($data["plugin_databaseinventory_credentials_id"]); - $credential_link = PluginDatabaseinventoryCredential::getFormURLWithID($credential->fields["id"]); - $credential_linkname = $credential->fields["name"]; - $name = "" . $credential_linkname . ""; - echo ""; - - $databaseparams = new PluginDatabaseinventoryDatabaseParam(); - $databaseparams->getFromDB($data["plugin_databaseinventory_databaseparams_id"]); - $databaseparams_link = PluginDatabaseinventoryDatabaseParam::getFormURLWithID($data["plugin_databaseinventory_databaseparams_id"]); - $databaseparams_linkname = $databaseparams->fields["name"]; - $name = "" . $databaseparams_linkname . ""; - echo ""; - - echo ""; - echo ""; - echo ""; + $contactlog = new PluginDatabaseinventoryContactLog(); + $contactloglist = $contactlog->find( + [ + 'agents_id' => $ID + ] + ); + + $credential = new PluginDatabaseinventoryCredential(); + $dbparam = new PluginDatabaseinventoryDatabaseParam(); + $listofctlog = []; + foreach ($contactloglist as $dbpctlog) { + if ($credential->getFromDB($dbpctlog['plugin_databaseinventory_credentials_id'])) { + $linkcred = $credential->getLinkURL(); + $credname = $credential->fields['name']; + } + if ($dbparam->getFromDB($dbpctlog['plugin_databaseinventory_databaseparams_id'])) { + $linkdbparam = $dbparam->getLinkURL(); + $dbparamname = $dbparam->fields['name']; + } + if (isset($linkcred)) { + $listofctlog[] = $dbpctlog + [ + 'linkcred' => $linkcred, + 'linkdbparam' => $linkdbparam ?? '', + 'credname' => $credname ?? '', + 'dbparamname' => $dbparamname ?? '', + ]; } - echo $header_begin . $header_bottom . $header_end; - echo "
" . PluginDatabaseinventoryCredential::getTypeName(0) . "" . PluginDatabaseinventoryDatabaseParam::getTypeName(0) . "" . __('Date') . "
" . $name . "" . $name . "" . $data["date_creation"] . "
"; - echo "
"; } - echo "
"; + TemplateRenderer::getInstance()->display( + '@databaseinventory/contactlog.html.twig', + [ + 'itemtype' => Agent::getType(), + 'contactlogs' => $listofctlog, + 'canread' => $agent->can($ID, READ) + ] + ); return true; } diff --git a/inc/credential.class.php b/inc/credential.class.php index 4358f0a..afd89d6 100644 --- a/inc/credential.class.php +++ b/inc/credential.class.php @@ -1,5 +1,35 @@ . + * ------------------------------------------------------------------------- + * @copyright Copyright (C) 2021-2023 by Teclib'. + * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html + * @link https://services.glpi-network.com + * ------------------------------------------------------------------------- + */ + +use Glpi\Application\View\TemplateRenderer; + /** * ------------------------------------------------------------------------- * DatabaseInventory plugin for GLPI @@ -103,69 +133,13 @@ public function rawSearchOptions() public function showForm($ID, array $options = []) { - $rand = mt_rand(); $this->initForm($ID, $options); - $this->showFormHeader($options); - - echo ""; - $rand = mt_rand(); - echo ""; - echo ""; - echo Html::input( - 'name', - [ - 'value' => $this->fields["name"], - 'id' => "textfield_name$rand", - ] - ); - echo ""; - echo ""; - Dropdown::showNumber( - 'port', - [ - 'value' => empty($this->fields['port']) ? 0 : $this->fields['port'], - 'min' => 0, - 'max' => 99999, - 'step' => 1, - 'rand' => $rand - ] - ); - echo ""; - - echo ""; - echo ""; - echo Html::input( - 'login', + TemplateRenderer::getInstance()->display( + '@databaseinventory/credential.html.twig', [ - 'value' => $this->fields["login"], - 'id' => "textfield_login$rand", + 'item' => $this ] ); - echo ""; - echo ""; - - echo ""; - if ($ID > 0) { - echo "  " . __('Clear'); - } - echo ""; - - echo ""; - echo ""; - echo Html::input( - 'socket', - [ - 'value' => $this->fields["socket"], - 'id' => "textfield_login$rand", - ] - ); - - echo ""; - echo ""; - PluginDatabaseinventoryCredentialType::dropdown(['value' => $this->fields["plugin_databaseinventory_credentialtypes_id"], 'rand' => $rand, 'comments' => false]); - echo ""; - - $this->showFormButtons($options); return true; } diff --git a/inc/databaseparam.class.php b/inc/databaseparam.class.php index 984cc0a..2ed6cc7 100644 --- a/inc/databaseparam.class.php +++ b/inc/databaseparam.class.php @@ -1,5 +1,35 @@ . + * ------------------------------------------------------------------------- + * @copyright Copyright (C) 2021-2023 by Teclib'. + * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html + * @link https://services.glpi-network.com + * ------------------------------------------------------------------------- + */ + +use Glpi\Application\View\TemplateRenderer; + /** * ------------------------------------------------------------------------- * DatabaseInventory plugin for GLPI @@ -186,44 +216,13 @@ public function defineTabs($options = []) public function showForm($ID, array $options = []) { - $rand = mt_rand(); $this->initForm($ID, $options); - $this->showFormHeader($options); - - echo ""; - echo ""; - echo ""; - echo Html::input( - 'name', - [ - 'value' => $this->fields["name"], - 'id' => "textfield_name$rand", - ] - ); - echo ""; - echo ""; - Dropdown::showYesNo('is_active', $this->fields['is_active']); - echo ""; - - echo ""; - echo ""; - Dropdown::showYesNo('partial_inventory', $this->fields['partial_inventory']); - echo ""; - echo ""; - Dropdown::showNumber( - 'execution_delay', + TemplateRenderer::getInstance()->display( + '@databaseinventory/databaseparam.html.twig', [ - 'value' => empty($this->fields['execution_delay']) ? 0 : $this->fields['execution_delay'], - 'min' => 0, - 'max' => 24, - 'unit' => 'hour', - 'step' => 1, - 'rand' => $rand + 'item' => $this ] ); - echo ""; - - $this->showFormButtons($options); return true; } diff --git a/inc/databaseparam_computergroup.class.php b/inc/databaseparam_computergroup.class.php index 13954df..a58a5da 100644 --- a/inc/databaseparam_computergroup.class.php +++ b/inc/databaseparam_computergroup.class.php @@ -1,5 +1,35 @@ . + * ------------------------------------------------------------------------- + * @copyright Copyright (C) 2021-2023 by Teclib'. + * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html + * @link https://services.glpi-network.com + * ------------------------------------------------------------------------- + */ + +use Glpi\Application\View\TemplateRenderer; + /** * ------------------------------------------------------------------------- * DatabaseInventory plugin for GLPI @@ -83,129 +113,46 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ private static function showForItem(PluginDatabaseinventoryDatabaseParam $databaseparams) { - /** @var DBmysql $DB */ - global $DB; - $ID = $databaseparams->getField('id'); if (!$databaseparams->can($ID, UPDATE)) { return false; } - $datas = []; - $used = []; - $params = [ - 'SELECT' => '*', - 'FROM' => self::getTable(), - 'WHERE' => ['plugin_databaseinventory_databaseparams_id' => $ID], - ]; - - $iterator = $DB->request($params); - foreach ($iterator as $data) { - $datas[] = $data; - $used[] = $data['plugin_databaseinventory_computergroups_id']; - } - $number = count($datas); - - $rand = mt_rand(); - - echo "
"; - if ($databaseparams->canAddItem('itemtype')) { - echo "
"; - echo ""; - - echo ""; - echo ""; - echo ""; - - echo ""; - echo "
" . __('Add computer group', 'databaseinventory') . "
"; - Dropdown::show( - "PluginDatabaseinventoryComputerGroup", - [ - "name" => "plugin_databaseinventory_computergroups_id", - "used" => $used, - ] - ); - echo ""; - - echo Html::hidden('plugin_databaseinventory_databaseparams_id', ['value' => $ID]); - echo Html::submit(_x('button', 'Add'), ['name' => 'add_computergroup']); - echo "
"; - Html::closeForm(); - echo "
"; - } - echo "
"; - - $canread = $databaseparams->can($ID, READ); - $canedit = $databaseparams->can($ID, UPDATE); - echo "
"; - if ($canread) { - echo "
"; - if ($canedit) { - Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); - $massiveactionparams = [ - 'num_displayed' => min($_SESSION['glpilist_limit'], $number), - 'specific_actions' => ['purge' => _x('button', 'Remove')], - 'container' => 'mass' . __CLASS__ . $rand, - ]; - Html::showMassiveActions($massiveactionparams); - } - echo ""; - $header_begin = ""; - $header_top = ''; - $header_bottom = ''; - $header_end = ''; - - if ($canedit) { - $header_top .= ""; - $header_bottom .= ""; - } - - $header_end .= ""; - $header_end .= ""; - $header_end .= ""; - $header_end .= ""; - $header_end .= ""; - echo $header_begin . $header_top . $header_end; - - foreach ($datas as $data) { - $computergroup = new PluginDatabaseinventoryComputerGroup(); - $computergroup->getFromDB($data["plugin_databaseinventory_computergroups_id"]); - $linkname = $computergroup->fields["name"]; - $itemtype = PluginDatabaseinventoryComputerGroup::getType(); - if ($_SESSION["glpiis_ids_visible"] || empty($computergroup->fields["name"])) { - $linkname = sprintf(__('%1$s (%2$s)'), $linkname, $computergroup->fields["id"]); - } - $link = $itemtype::getFormURLWithID($computergroup->fields["id"]); - $name = "" . $linkname . ""; - echo ""; - - if ($canedit) { - echo ""; - } - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - } - echo $header_begin . $header_bottom . $header_end; - - echo "
" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); - $header_top .= "" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); - $header_bottom .= "" . __('Name') . "" . __('Comment') . "" . __('Number of dynamic items', 'databaseinventory') . "" . __('Number of static items', 'databaseinventory') . "
"; - Html::showMassiveActionCheckBox(__CLASS__, $data["id"]); - echo "" . $name . "" . $computergroup->fields["comment"] . "" . $computergroup->countDynamicItem() . "" . $computergroup->countStaticItem() . "
"; - if ($canedit && $number) { - $massiveactionparams['ontop'] = false; - Html::showMassiveActions($massiveactionparams); - Html::closeForm(); + $databaseparamcgroup = new PluginDatabaseinventoryDatabaseParam_ComputerGroup(); + $dbpcgrouplist = $databaseparamcgroup->find( + [ + 'plugin_databaseinventory_databaseparams_id' => $ID + ] + ); + + $dbcgroups = new PluginDatabaseinventoryComputerGroup(); + $listofcgroups = []; + $used = []; + foreach ($dbpcgrouplist as $dbpcgroup) { + $used[] = $dbpcgroup['plugin_databaseinventory_computergroups_id']; + if ($dbcgroups->getFromDB($dbpcgroup['plugin_databaseinventory_computergroups_id'])) { + $listofcgroups[] = $dbcgroups->fields + + [ + 'link' => $dbcgroups->getLinkURL(), + 'nbdynamicitems' => $dbcgroups->countDynamicItem(), + 'nbstaticitems' => $dbcgroups->countStaticItem(), + 'iddbparamcgroup' => $dbpcgroup['id'], + ]; } - echo "
"; } - echo "
"; + TemplateRenderer::getInstance()->display( + '@databaseinventory/databaseparam_computergroup.html.twig', + [ + 'item' => PluginDatabaseinventoryDatabaseParam::getById($ID), + 'compgrouplist' => $listofcgroups, + 'compgroupclass' => PluginDatabaseinventoryComputerGroup::class, + 'dbparamgroupclass' => PluginDatabaseinventoryDatabaseParam_ComputerGroup::class, + 'canread' => $databaseparams->can($ID, READ), + 'canedit' => $databaseparams->can($ID, UPDATE), + 'canadd' => $databaseparams->canAddItem('itemtype'), + 'used' => $used, + ] + ); return true; } diff --git a/inc/databaseparam_credential.class.php b/inc/databaseparam_credential.class.php index d009dcc..2f87227 100644 --- a/inc/databaseparam_credential.class.php +++ b/inc/databaseparam_credential.class.php @@ -1,5 +1,35 @@ . + * ------------------------------------------------------------------------- + * @copyright Copyright (C) 2021-2023 by Teclib'. + * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html + * @link https://services.glpi-network.com + * ------------------------------------------------------------------------- + */ + +use Glpi\Application\View\TemplateRenderer; + /** * ------------------------------------------------------------------------- * DatabaseInventory plugin for GLPI @@ -83,131 +113,49 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ private static function showForItem(PluginDatabaseinventoryDatabaseParam $databaseparams) { - /** @var DBmysql $DB */ - global $DB; - $ID = $databaseparams->getField('id'); if (!$databaseparams->can($ID, UPDATE)) { return false; } - $datas = []; - $used = []; - $params = [ - 'SELECT' => '*', - 'FROM' => self::getTable(), - 'WHERE' => ['plugin_databaseinventory_databaseparams_id' => $ID], - ]; - - $iterator = $DB->request($params); - foreach ($iterator as $data) { - $datas[] = $data; - $used[] = $data['plugin_databaseinventory_credentials_id']; - } - $number = count($datas); - - $rand = mt_rand(); - - echo "
"; - if ($databaseparams->canAddItem('itemtype')) { - echo "
"; - echo ""; - - echo ""; - echo ""; - echo ""; - - echo ""; - echo "
" . __('Add credential', 'databaseinventory') . "
"; - Dropdown::show( - "PluginDatabaseinventoryCredential", - [ - "name" => "plugin_databaseinventory_credentials_id", - "used" => $used, - ] - ); - echo ""; - - echo Html::hidden('plugin_databaseinventory_databaseparams_id', ['value' => $ID]); - echo Html::submit(_x('button', 'Add'), ['name' => 'add_credential']); - echo "
"; - Html::closeForm(); - echo "
"; - } - echo "
"; - - $canread = $databaseparams->can($ID, READ); - $canedit = $databaseparams->can($ID, UPDATE); - echo "
"; - if ($canread) { - echo "
"; - if ($canedit) { - Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); - $massiveactionparams = [ - 'num_displayed' => min($_SESSION['glpilist_limit'], $number), - 'specific_actions' => ['purge' => _x('button', 'Remove')], - 'container' => 'mass' . __CLASS__ . $rand, - ]; - Html::showMassiveActions($massiveactionparams); - } - echo ""; - $header_begin = ""; - $header_top = ''; - $header_bottom = ''; - $header_end = ''; - - if ($canedit) { - $header_top .= ""; - $header_bottom .= ""; - } - - $header_end .= ""; - $header_end .= ""; - $header_end .= ""; - $header_end .= ""; - $header_end .= ""; - $header_end .= ""; - echo $header_begin . $header_top . $header_end; - - foreach ($datas as $data) { - $credential = new PluginDatabaseinventoryCredential(); - $credential->getFromDB($data["plugin_databaseinventory_credentials_id"]); - $linkname = $credential->fields["name"]; - $itemtype = PluginDatabaseinventoryCredential::getType(); - if ($_SESSION["glpiis_ids_visible"] || empty($credential->fields["name"])) { - $linkname = sprintf(__('%1$s (%2$s)'), $linkname, $credential->fields["id"]); - } - $link = $itemtype::getFormURLWithID($credential->fields["id"]); - $name = "" . $linkname . ""; - echo ""; - - if ($canedit) { - echo ""; - } - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; + $databaseparamcredentials = new PluginDatabaseinventoryDatabaseParam_Credential(); + $dbpcredentialslist = $databaseparamcredentials->find( + [ + 'plugin_databaseinventory_databaseparams_id' => $ID + ] + ); + + $dbcredentials = new PluginDatabaseinventoryCredential(); + $listofcredentials = []; + $used = []; + foreach ($dbpcredentialslist as $dbpcredential) { + $used[] = $dbpcredential['plugin_databaseinventory_credentials_id']; + if ($dbcredentials->getFromDB($dbpcredential['plugin_databaseinventory_credentials_id'])) { + $listofcredentials[] = $dbcredentials->fields + + [ + 'type' => Dropdown::getDropdownName( + PluginDatabaseinventoryCredentialType::getTable(), + $dbcredentials->fields['plugin_databaseinventory_credentialtypes_id'] + ), + 'link' => $dbcredentials->getLinkURL(), + 'iddbparamcredential' => $dbpcredential['id'], + ]; } - echo $header_begin . $header_bottom . $header_end; - - echo "
" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); - $header_top .= "" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); - $header_bottom .= "" . __('Name') . "" . __('Login') . "" . __('Port') . "" . __('Socket') . "" . __('Type') . "
"; - Html::showMassiveActionCheckBox(__CLASS__, $data["id"]); - echo "" . $name . "" . $credential->fields["login"] . "" . $credential->fields["port"] . "" . $credential->fields["socket"] . "" . Dropdown::getDropdownName(PluginDatabaseinventoryCredentialType::getTable(), $credential->fields['plugin_databaseinventory_credentialtypes_id']); - echo "
"; - if ($canedit && $number) { - $massiveactionparams['ontop'] = false; - Html::showMassiveActions($massiveactionparams); - Html::closeForm(); - } - echo "
"; } - echo "
"; + TemplateRenderer::getInstance()->display( + '@databaseinventory/databaseparam_credential.html.twig', + [ + 'item' => PluginDatabaseinventoryDatabaseParam::getById($ID), + 'credentiallist' => $listofcredentials, + 'credentialclass' => PluginDatabaseinventoryCredential::class, + 'credentialtypeclass' => PluginDatabaseinventoryDatabaseParam_Credential::class, + 'canread' => $databaseparams->can($ID, READ), + 'canedit' => $databaseparams->can($ID, UPDATE), + 'canadd' => $databaseparams->canAddItem('itemtype'), + 'used' => $used, + ] + ); + return true; } diff --git a/inc/menu.class.php b/inc/menu.class.php index 99d79f2..8330f23 100644 --- a/inc/menu.class.php +++ b/inc/menu.class.php @@ -37,49 +37,64 @@ public static function getMenuName() public static function getMenuContent() { + $links_class = [ + PluginDatabaseinventoryComputerGroup::class, + PluginDatabaseinventoryDatabaseParam::class, + PluginDatabaseinventoryCredential::class + ]; + + $links = []; + foreach ($links_class as $link) { + $link_text = + "" . $link::getTypeName(Session::getPluralNumber()) . ""; + $links["$link_text"] = $link::getSearchURL(false); + } + $menu = [ 'title' => self::getMenuName(), - 'page' => self::getSearchURL(false), + 'page' => PluginDatabaseinventoryDatabaseParam::getSearchURL(false), 'icon' => 'fas fa-database', + 'options' => [], + 'links' => $links, ]; - if (PluginDatabaseinventoryDatabaseParam::canView()) { - $menu['options']['databaseparam'] = [ - 'title' => PluginDatabaseinventoryDatabaseParam::getTypeName(2), - 'page' => PluginDatabaseinventoryDatabaseParam::getSearchURL(false), - 'icon' => PluginDatabaseinventoryDatabaseParam::getIcon(), - ]; + $menu['options']['databaseparam'] = [ + 'title' => PluginDatabaseinventoryDatabaseParam::getTypeName(2), + 'page' => PluginDatabaseinventoryDatabaseParam::getSearchURL(false), + 'icon' => PluginDatabaseinventoryDatabaseParam::getIcon(), + 'links' => $links, + ]; + if (true) { $menu['options']['databaseparam']['links'] = [ 'search' => PluginDatabaseinventoryDatabaseParam::getSearchURL(false), 'add' => PluginDatabaseinventoryDatabaseParam::getFormURL(false), - ]; + ] + $links; } + $menu['options']['computergroup'] = [ + 'title' => PluginDatabaseinventoryComputerGroup::getTypeName(2), + 'page' => PluginDatabaseinventoryComputerGroup::getSearchURL(false), + 'icon' => PluginDatabaseinventoryComputerGroup::getIcon(), + 'links' => $links, + ]; - if (PluginDatabaseinventoryComputerGroup::canView()) { - $menu['options']['computergroup'] = [ - 'title' => PluginDatabaseinventoryComputerGroup::getTypeName(2), - 'page' => PluginDatabaseinventoryComputerGroup::getSearchURL(false), - 'icon' => PluginDatabaseinventoryComputerGroup::getIcon(), - ]; - + if (true) { $menu['options']['computergroup']['links'] = [ 'search' => PluginDatabaseinventoryComputerGroup::getSearchURL(false), 'add' => PluginDatabaseinventoryComputerGroup::getFormURL(false), - ]; + ] + $links; } - - if (PluginDatabaseinventoryCredential::canView()) { - $menu['options']['credential'] = [ - 'title' => PluginDatabaseinventoryCredential::getTypeName(2), - 'page' => PluginDatabaseinventoryCredential::getSearchURL(false), - 'icon' => PluginDatabaseinventoryCredential::getIcon(), - ]; - + $menu['options']['credential'] = [ + 'title' => PluginDatabaseinventoryCredential::getTypeName(2), + 'page' => PluginDatabaseinventoryCredential::getSearchURL(false), + 'icon' => PluginDatabaseinventoryCredential::getIcon(), + 'links' => $links, + ]; + if (true) { $menu['options']['credential']['links'] = [ 'search' => PluginDatabaseinventoryCredential::getSearchURL(false), 'add' => PluginDatabaseinventoryCredential::getFormURL(false), - ]; + ] + $links; } return $menu; diff --git a/setup.php b/setup.php index a5cf8f2..207b9c0 100644 --- a/setup.php +++ b/setup.php @@ -48,7 +48,7 @@ function plugin_init_databaseinventory() $PLUGIN_HOOKS['csrf_compliant']['databaseinventory'] = true; - $PLUGIN_HOOKS['config_page']['databaseinventory'] = 'front/menu.php'; + $PLUGIN_HOOKS['config_page']['databaseinventory'] = 'front/databaseparam.php'; if (!Plugin::isPluginActive('databaseinventory')) { return; diff --git a/templates/computergroup.html.twig b/templates/computergroup.html.twig new file mode 100644 index 0000000..106fb7d --- /dev/null +++ b/templates/computergroup.html.twig @@ -0,0 +1,29 @@ +{# + # ------------------------------------------------------------------------- + # DatabaseInventory plugin for GLPI + # ------------------------------------------------------------------------- + # + # LICENSE + # + # This file is part of DatabaseInventory. + # + # DatabaseInventory is free software; you can redistribute it and/or modify + # it under the terms of the GNU General Public License as published by + # the Free Software Foundation; either version 3 of the License, or + # (at your option) any later version. + # + # DatabaseInventory is distributed in the hope that it will be useful, + # but WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + # GNU General Public License for more details. + # + # You should have received a copy of the GNU General Public License + # along with DatabaseInventory. If not, see . + # ------------------------------------------------------------------------- + # @copyright Copyright (C) 2021-2023 by Teclib'. + # @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html + # @link https://services.glpi-network.com + # ------------------------------------------------------------------------- + #} + +{% extends "generic_show_form.html.twig" %} \ No newline at end of file diff --git a/templates/computergroupstatic.html.twig b/templates/computergroupstatic.html.twig new file mode 100644 index 0000000..db47e97 --- /dev/null +++ b/templates/computergroupstatic.html.twig @@ -0,0 +1,126 @@ +{# + # ------------------------------------------------------------------------- + # DatabaseInventory plugin for GLPI + # ------------------------------------------------------------------------- + # + # LICENSE + # + # This file is part of DatabaseInventory. + # + # DatabaseInventory is free software; you can redistribute it and/or modify + # it under the terms of the GNU General Public License as published by + # the Free Software Foundation; either version 3 of the License, or + # (at your option) any later version. + # + # DatabaseInventory is distributed in the hope that it will be useful, + # but WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + # GNU General Public License for more details. + # + # You should have received a copy of the GNU General Public License + # along with DatabaseInventory. If not, see . + # ------------------------------------------------------------------------- + # @copyright Copyright (C) 2021-2023 by Teclib'. + # @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html + # @link https://services.glpi-network.com + # ------------------------------------------------------------------------- + #} + +{% import "components/form/fields_macros.html.twig" as fields %} +{% set rand = random() %} + +{% block more_fields %} + {% if canadd %} + + +
+ {{ fields.dropdownField( + "Computer", + 'computers_id', + '', + __('Add'), + { + 'used': used, + 'condition': {'is_dynamic': 1}, + } + ) }} + + {% set btn_add %} + + {% endset %} + {{ fields.htmlField( + '', + btn_add, + '' + ) }} + + {{ fields.hiddenField( + 'plugin_databaseinventory_computergroups_id', + item.getID(), + )}} +
+ + {% endif %} + {% if canread %} + {% if computerslist is not empty %} +
+ + + + + {% set table_id = 'package_subitem_' ~ rand %} + + + + {% if canedit %} + + {% endif %} + + + + + + + + {% for computer in computerslist %} + + {% if canedit %} + + {% endif %} + + {% if computer['is_dynamic'] == 1 %} + {% set is_dynamic = __('Yes') %} + {% else %} + {% set is_dynamic = __('No') %} + {% endif %} + + + + + + {% endfor %} + +
+ + {{ __('Name') }}{{ __('Automatic inventory') }}{{ __('Entity') }}{{ __('Serial number') }}{{ __('Inventory number') }}
+ {% set checked = session('glpimassiveactionselected')[groupstaticclass][computer['idcompgroupstatic']] ?? false %} + + {{ computer['name'] }}{{ is_dynamic }}{{ computer['entityname'] }}{{ computer['serial'] }}{{ computer['otherserial'] }}
+
+ {% endif %} + {% endif %} +{% endblock %} \ No newline at end of file diff --git a/templates/contactlog.html.twig b/templates/contactlog.html.twig new file mode 100644 index 0000000..e3f154e --- /dev/null +++ b/templates/contactlog.html.twig @@ -0,0 +1,62 @@ +{# + # ------------------------------------------------------------------------- + # DatabaseInventory plugin for GLPI + # ------------------------------------------------------------------------- + # + # LICENSE + # + # This file is part of DatabaseInventory. + # + # DatabaseInventory is free software; you can redistribute it and/or modify + # it under the terms of the GNU General Public License as published by + # the Free Software Foundation; either version 3 of the License, or + # (at your option) any later version. + # + # DatabaseInventory is distributed in the hope that it will be useful, + # but WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + # GNU General Public License for more details. + # + # You should have received a copy of the GNU General Public License + # along with DatabaseInventory. If not, see . + # ------------------------------------------------------------------------- + # @copyright Copyright (C) 2021-2023 by Teclib'. + # @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html + # @link https://services.glpi-network.com + # ------------------------------------------------------------------------- + #} + +{% import "components/form/fields_macros.html.twig" as fields %} + +{% block more_fields %} + {% if canread %} + {% if contactlogs is not empty %} + {% set tableheader %} + + {{ __('Credentials') }} + {% if itemtype == 'Agent' %} + {{ __('DatabaseParam') }} + {% else %} + {{ __('Agents') }} + {% endif %} + {{ __('Date') }} + + {% endset %} + + {{ tableheader }} + {% for contactlog in contactlogs %} + + + {% if itemtype == 'Agent' %} + + {% else %} + + {% endif %} + + + {% endfor %} + {{ tableheader }} +
{{ contactlog['credname'] }} {{ contactlog['dbparamname'] }} {{ contactlog['agentname'] }}{{ contactlog['date_creation'] }}
+ {% endif %} + {% endif %} +{% endblock %} \ No newline at end of file diff --git a/templates/credential.html.twig b/templates/credential.html.twig new file mode 100644 index 0000000..be13da5 --- /dev/null +++ b/templates/credential.html.twig @@ -0,0 +1,62 @@ +{# + # ------------------------------------------------------------------------- + # DatabaseInventory plugin for GLPI + # ------------------------------------------------------------------------- + # + # LICENSE + # + # This file is part of DatabaseInventory. + # + # DatabaseInventory is free software; you can redistribute it and/or modify + # it under the terms of the GNU General Public License as published by + # the Free Software Foundation; either version 3 of the License, or + # (at your option) any later version. + # + # DatabaseInventory is distributed in the hope that it will be useful, + # but WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + # GNU General Public License for more details. + # + # You should have received a copy of the GNU General Public License + # along with DatabaseInventory. If not, see . + # ------------------------------------------------------------------------- + # @copyright Copyright (C) 2021-2023 by Teclib'. + # @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html + # @link https://services.glpi-network.com + # ------------------------------------------------------------------------- + #} + +{% extends "generic_show_form.html.twig" %} +{% import "components/form/fields_macros.html.twig" as fields %} + +{% block more_fields %} + + {{ fields.dropdownNumberField( + 'port', + item.fields['port'], + __('Port', 'databaseinventory'), + {'min' : 0, 'max' : 99999, 'step' : 1} + )}} + + {{ fields.textField( + 'login', + item.fields['login'], + __('Login', 'databaseinventory'), + ) + }} + + {{ fields.passwordField( + 'password', + item.fields['password'], + __('Password', 'databaseinventory'), + {'clearable': false, 'is_disclosable' : true} + ) + }} + {{ fields.textField( + 'socket', + item.fields['socket'], + __('Socket', 'databaseinventory'), + ) + }} + +{% endblock %} \ No newline at end of file diff --git a/templates/databaseparam.html.twig b/templates/databaseparam.html.twig new file mode 100644 index 0000000..a6de483 --- /dev/null +++ b/templates/databaseparam.html.twig @@ -0,0 +1,48 @@ +{# + # ------------------------------------------------------------------------- + # DatabaseInventory plugin for GLPI + # ------------------------------------------------------------------------- + # + # LICENSE + # + # This file is part of DatabaseInventory. + # + # DatabaseInventory is free software; you can redistribute it and/or modify + # it under the terms of the GNU General Public License as published by + # the Free Software Foundation; either version 3 of the License, or + # (at your option) any later version. + # + # DatabaseInventory is distributed in the hope that it will be useful, + # but WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + # GNU General Public License for more details. + # + # You should have received a copy of the GNU General Public License + # along with DatabaseInventory. If not, see . + # ------------------------------------------------------------------------- + # @copyright Copyright (C) 2021-2023 by Teclib'. + # @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html + # @link https://services.glpi-network.com + # ------------------------------------------------------------------------- + #} + +{% extends "generic_show_form.html.twig" %} +{% import "components/form/fields_macros.html.twig" as fields %} + +{% block more_fields %} + + {{ fields.dropdownYesNo( + 'partial_inventory', + item.fields['partial_inventory'], + __('Execution frequency for partial inventory', 'databaseinventory'), + ) + }} + + {{ fields.dropdownNumberField( + 'execution_delay', + item.fields['execution_delay'], + __('Execution delay', 'databaseinventory'), + {'min' : 0, 'max' : 24, 'step' : 1, 'unit' : 'hour'} + )}} + +{% endblock %} \ No newline at end of file diff --git a/templates/databaseparam_computergroup.html.twig b/templates/databaseparam_computergroup.html.twig new file mode 100644 index 0000000..4561596 --- /dev/null +++ b/templates/databaseparam_computergroup.html.twig @@ -0,0 +1,119 @@ +{# + # ------------------------------------------------------------------------- + # DatabaseInventory plugin for GLPI + # ------------------------------------------------------------------------- + # + # LICENSE + # + # This file is part of DatabaseInventory. + # + # DatabaseInventory is free software; you can redistribute it and/or modify + # it under the terms of the GNU General Public License as published by + # the Free Software Foundation; either version 3 of the License, or + # (at your option) any later version. + # + # DatabaseInventory is distributed in the hope that it will be useful, + # but WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + # GNU General Public License for more details. + # + # You should have received a copy of the GNU General Public License + # along with DatabaseInventory. If not, see . + # ------------------------------------------------------------------------- + # @copyright Copyright (C) 2021-2023 by Teclib'. + # @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html + # @link https://services.glpi-network.com + # ------------------------------------------------------------------------- + #} + +{% import "components/form/fields_macros.html.twig" as fields %} +{% set rand = random() %} + +{% block more_fields %} + {% if canadd %} +
+ +
+ {{ fields.dropdownField( + compgroupclass, + 'plugin_databaseinventory_computergroups_id', + '', + __('Add'), + { + 'used': used, + } + ) }} + + {% set btn_add %} + + {% endset %} + + {{ fields.htmlField( + '', + btn_add, + '' + ) }} + + {{ fields.hiddenField( + 'plugin_databaseinventory_databaseparams_id', + item.getID(), + )}} +
+
+ {% endif %} + {% if canread %} + {% if compgrouplist is not empty %} +
+ + + + + {% set table_id = 'package_subitem_' ~ rand %} + + + + {% if canedit %} + + {% endif %} + + + + + + + {% for compgroup in compgrouplist %} + + {% if canedit %} + + {% endif %} + + + + + + {% endfor %} + +
+ + {{ __('Name') }}{{ __('Comment') }}{{ __('Number of dynamic items') }}{{ __('Number of static items') }}
+ {% set checked = session('glpimassiveactionselected')[dbparamgroupclass][compgroup['iddbparamcgroup']] ?? false %} + + {{ compgroup['name'] }}{{ compgroup['comment'] }}{{ compgroup['nbdynamicitems'] }}{{ compgroup['nbstaticitems'] }}
+
+ {% endif %} + {% endif %} +{% endblock %} \ No newline at end of file diff --git a/templates/databaseparam_credential.html.twig b/templates/databaseparam_credential.html.twig new file mode 100644 index 0000000..9851095 --- /dev/null +++ b/templates/databaseparam_credential.html.twig @@ -0,0 +1,120 @@ +{# + # ------------------------------------------------------------------------- + # DatabaseInventory plugin for GLPI + # ------------------------------------------------------------------------- + # + # LICENSE + # + # This file is part of DatabaseInventory. + # + # DatabaseInventory is free software; you can redistribute it and/or modify + # it under the terms of the GNU General Public License as published by + # the Free Software Foundation; either version 3 of the License, or + # (at your option) any later version. + # + # DatabaseInventory is distributed in the hope that it will be useful, + # but WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + # GNU General Public License for more details. + # + # You should have received a copy of the GNU General Public License + # along with DatabaseInventory. If not, see . + # ------------------------------------------------------------------------- + # @copyright Copyright (C) 2021-2023 by Teclib'. + # @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html + # @link https://services.glpi-network.com + # ------------------------------------------------------------------------- + #} + +{% import "components/form/fields_macros.html.twig" as fields %} +{% set rand = random() %} + +{% block more_fields %} + {% if canadd %} +
+ +
+ {{ fields.dropdownField( + credentialclass, + 'plugin_databaseinventory_credentials_id', + '', + __('Add'), + { + 'used': used, + } + ) }} + + {% set btn_add %} + + {% endset %} + + {{ fields.htmlField( + '', + btn_add, + '' + ) }} + + {{ fields.hiddenField( + 'plugin_databaseinventory_databaseparams_id', + item.getID(), + )}} +
+
+ {% endif %} + {% if canread %} + {% if credentiallist is not empty %} +
+ + + + + {% set table_id = 'package_subitem_' ~ rand %} + + + + {% if canedit %} + + {% endif %} + + + + + + + + {% for credential in credentiallist %} + {% if canedit %} + + {% endif %} + + + + + + + {% endfor %} + +
+ + {{ __('Name') }}{{ __('Login') }}{{ __('Port') }}{{ __('Socket') }}{{ __('Type') }}
+ {% set checked = session('glpimassiveactionselected')[credentialtypeclass][credential['iddbparamcredential']] ?? false %} + + {{ credential['name'] }}{{ credential['login'] }}{{ credential['port'] }}{{ credential['socket'] }}{{ credential['type'] }}
+
+ {% endif %} + {% endif %} +{% endblock %} \ No newline at end of file