From a5a0cc7be36a279a3677e8f5549cdd95dc87c791 Mon Sep 17 00:00:00 2001 From: LAUNAY Samuel <107540223+Lainow@users.noreply.github.com> Date: Tue, 26 Sep 2023 14:51:23 +0200 Subject: [PATCH 1/9] fix(plugin) warning on computers group page --- inc/computergroupdynamic.class.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/inc/computergroupdynamic.class.php b/inc/computergroupdynamic.class.php index 258a042..6b4c0fb 100644 --- a/inc/computergroupdynamic.class.php +++ b/inc/computergroupdynamic.class.php @@ -74,10 +74,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 '; @@ -150,11 +152,13 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ private function countDynamicItems() { $count = 0; - $search_params = Search::manageParams('Computer', unserialize($this->fields['search'])); - $data = Search::prepareDatasForSearch('Computer', $search_params); - Search::constructSQL($data); - Search::constructData($data); - $count = $data['data']['totalcount']; + if (isset($this->fields['search'])) { + $search_params = Search::manageParams('Computer', unserialize($this->fields['search'])); + $data = Search::prepareDatasForSearch('Computer', $search_params); + Search::constructSQL($data); + Search::constructData($data); + $count = $data['data']['totalcount']; + } return $count; } From aa7861633289a3844a5bc4efa48e26fcefd20a62 Mon Sep 17 00:00:00 2001 From: LAUNAY Samuel <107540223+Lainow@users.noreply.github.com> Date: Tue, 26 Sep 2023 15:17:50 +0200 Subject: [PATCH 2/9] feat(plugin) pass all html in twig --- front/computergroup.php | 8 +- front/credential.php | 8 +- front/databaseparam.php | 8 +- inc/computergroup.class.php | 22 +- inc/computergroupdynamic.class.php | 24 +-- inc/computergroupstatic.class.php | 155 +++----------- inc/contactlog.class.php | 193 ++++++------------ inc/credential.class.php | 63 +----- inc/databaseparam.class.php | 38 +--- inc/databaseparam_computergroup.class.php | 144 +++---------- inc/databaseparam_credential.class.php | 150 ++++---------- inc/menu.class.php | 88 ++++---- setup.php | 2 +- templates/computergroup.html.twig | 1 + templates/computergroupstatic.html.twig | 98 +++++++++ templates/contactlog.html.twig | 34 +++ templates/credential.html.twig | 34 +++ templates/databaseparam.html.twig | 20 ++ .../databaseparam_computergroup.html.twig | 91 +++++++++ templates/databaseparam_credential.html.twig | 92 +++++++++ 20 files changed, 627 insertions(+), 646 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 27a847b..ecb30ab 100644 --- a/inc/computergroup.class.php +++ b/inc/computergroup.class.php @@ -1,4 +1,5 @@ initForm($ID, $options); - $this->showFormHeader($options); - - $rand = mt_rand(); - 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; } diff --git a/inc/computergroupdynamic.class.php b/inc/computergroupdynamic.class.php index 6b4c0fb..022e57c 100644 --- a/inc/computergroupdynamic.class.php +++ b/inc/computergroupdynamic.class.php @@ -74,12 +74,10 @@ public static function getSpecificValueToDisplay($field, $values, array $options switch ($field) { case 'search': $count = 0; - if (isset($values['id'])) { - if (strpos($values['id'], Search::NULLVALUE) === false) { - $computergroup_dynamic = new PluginDatabaseinventoryComputerGroupDynamic(); - $computergroup_dynamic->getFromDB($values['id']); - $count = $computergroup_dynamic->countDynamicItems(); - } + if (strpos($values['id'], Search::NULLVALUE) === false) { + $computergroup_dynamic = new PluginDatabaseinventoryComputerGroupDynamic(); + $computergroup_dynamic->getFromDB($values['id']); + $count = $computergroup_dynamic->countDynamicItems(); } return ($count) ? $count : ' 0 '; @@ -152,13 +150,11 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ private function countDynamicItems() { $count = 0; - if (isset($this->fields['search'])) { - $search_params = Search::manageParams('Computer', unserialize($this->fields['search'])); - $data = Search::prepareDatasForSearch('Computer', $search_params); - Search::constructSQL($data); - Search::constructData($data); - $count = $data['data']['totalcount']; - } + $search_params = Search::manageParams('Computer', unserialize($this->fields['search'])); + $data = Search::prepareDatasForSearch('Computer', $search_params); + Search::constructSQL($data); + Search::constructData($data); + $count = $data['data']['totalcount']; return $count; } @@ -191,7 +187,6 @@ private static function showForItem(PluginDatabaseinventoryComputerGroup $comput } $canedit = $computergroup->canEdit($ID); - echo "
"; if ($canedit) { $firsttime = true; // load dynamic search criteria from DB if exist @@ -244,7 +239,6 @@ function() { ); "); } - echo "
"; } return true; diff --git a/inc/computergroupstatic.class.php b/inc/computergroupstatic.class.php index 32e9ae2..ad84c6f 100644 --- a/inc/computergroupstatic.class.php +++ b/inc/computergroupstatic.class.php @@ -1,4 +1,5 @@ '*', - '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); - - echo "
"; - if ($computergroup->canAddItem('itemtype')) { - $rand = mt_rand(); - echo "
"; - echo "
"; - - echo ""; - echo ""; - echo ""; - - echo ""; - echo "
" . __('Add an item') . "
"; - Dropdown::show( - "Computer", + $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 + [ - "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 + 'entityname' => Entity::getById($computers->fields['entities_id'])->fields['completename'], + 'link' => $computers->getLinkURL(), + 'idcompgroupstatic' => $staticgroup['id'], ]; - 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(); } - 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 f5e78bd..0cc849d 100644 --- a/inc/contactlog.class.php +++ b/inc/contactlog.class.php @@ -1,4 +1,5 @@ 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); - $canedit = false; - echo "
"; - if ($canread) { - echo "
"; - echo ""; - $header_begin = ""; - $header_top = ''; - $header_bottom = ''; - $header_end = ''; - - if ($canedit) { - $header_top .= ""; - $header_bottom .= ""; + $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']; } - - $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 ""; + 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 "
" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); - $header_top .= "" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); - $header_bottom .= "" . 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) { - 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); - $canedit = false; - echo "
"; - if ($canread) { - echo "
"; - echo ""; - $header_begin = ""; - $header_top = ''; - $header_bottom = ''; - $header_end = ''; - - if ($canedit) { - $header_top .= ""; - $header_bottom .= ""; + $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']; } - - $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 ""; + if ($dbparam->getFromDB($dbpctlog['plugin_databaseinventory_databaseparams_id'])) { + $linkdbparam = $dbparam->getLinkURL(); + $dbparamname = $dbparam->fields['name']; + } + if (isset($linkcred) || isset($linkagent)) { + $listofctlog[] = $dbpctlog + [ + 'linkcred' => $linkcred ?? '', + 'linkdbparam' => $linkdbparam ?? '', + 'credname' => $credname ?? '', + 'dbparamname' => $dbparamname ?? '', + ]; } - echo $header_begin . $header_bottom . $header_end; - echo "
" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); - $header_top .= "" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); - $header_bottom .= "" . 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 9a29d04..9b14fac 100644 --- a/inc/credential.class.php +++ b/inc/credential.class.php @@ -1,4 +1,5 @@ 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 a3ffedb..95c1607 100644 --- a/inc/databaseparam.class.php +++ b/inc/databaseparam.class.php @@ -1,4 +1,5 @@ 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 ee8d751..afd3ae3 100644 --- a/inc/databaseparam_computergroup.class.php +++ b/inc/databaseparam_computergroup.class.php @@ -1,4 +1,5 @@ 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); - - echo "
"; - if ($databaseparams->canAddItem('itemtype')) { - $rand = mt_rand(); - echo "
"; - echo ""; - - echo ""; - echo ""; - echo ""; - - echo ""; - echo "
" . __('Add computer group', 'databaseinventory') . "
"; - Dropdown::show( - "PluginDatabaseinventoryComputerGroup", + $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 + [ - "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, + 'link' => $dbcgroups->getLinkURL(), + 'nbdynamicitems' => $dbcgroups->countDynamicItem(), + 'nbstaticitems' => $dbcgroups->countStaticItem(), + 'iddbparamcgroup' => $dbpcgroup['id'], ]; - 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(); } - 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 faa01cb..d0f8b8a 100644 --- a/inc/databaseparam_credential.class.php +++ b/inc/databaseparam_credential.class.php @@ -1,4 +1,5 @@ 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); - - echo "
"; - if ($databaseparams->canAddItem('itemtype')) { - $rand = mt_rand(); - echo "
"; - echo ""; - - echo ""; - echo ""; - echo ""; - - echo ""; - echo "
" . __('Add credential', 'databaseinventory') . "
"; - Dropdown::show( - "PluginDatabaseinventoryCredential", + + $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 + [ - "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, + 'type' => Dropdown::getDropdownName( + PluginDatabaseinventoryCredentialType::getTable(), + $dbcredentials->fields['plugin_databaseinventory_credentialtypes_id'] + ), + 'link' => $dbcredentials->getLinkURL(), + 'iddbparamcredential' => $dbpcredential['id'], ]; - 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 ""; - } - 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 92cabf6..23e4722 100644 --- a/inc/menu.class.php +++ b/inc/menu.class.php @@ -37,55 +37,65 @@ 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(2), - '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), - ]; - } + 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), - ]; - } + if (true) { + $menu['options']['computergroup']['links'] = [ + 'search' => PluginDatabaseinventoryComputerGroup::getSearchURL(false), + 'add' => PluginDatabaseinventoryComputerGroup::getFormURL(false), + ] + $links; } + $menu['options']['credential'] = [ + 'title' => PluginDatabaseinventoryCredential::getTypeName(2), + 'page' => PluginDatabaseinventoryCredential::getSearchURL(false), + 'icon' => PluginDatabaseinventoryCredential::getIcon(), + 'links' => $links, + ]; - if (PluginDatabaseinventoryCredential::canView()) { - $menu['options']['credential'] = [ - 'title' => PluginDatabaseinventoryCredential::getTypeName(2), - 'page' => PluginDatabaseinventoryCredential::getSearchURL(false), - 'icon' => PluginDatabaseinventoryCredential::getIcon(), - ]; - - if (true) { - $menu['options']['credential']['links'] = [ - 'search' => PluginDatabaseinventoryCredential::getSearchURL(false), - 'add' => PluginDatabaseinventoryCredential::getFormURL(false), - ]; - } + 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 455067f..ccf30c3 100644 --- a/setup.php +++ b/setup.php @@ -47,7 +47,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 false; diff --git a/templates/computergroup.html.twig b/templates/computergroup.html.twig new file mode 100644 index 0000000..c0629eb --- /dev/null +++ b/templates/computergroup.html.twig @@ -0,0 +1 @@ +{% 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..c09835e --- /dev/null +++ b/templates/computergroupstatic.html.twig @@ -0,0 +1,98 @@ +{% 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..fddfcaf --- /dev/null +++ b/templates/contactlog.html.twig @@ -0,0 +1,34 @@ +{% 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..b545b6c --- /dev/null +++ b/templates/credential.html.twig @@ -0,0 +1,34 @@ +{% 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..119aef2 --- /dev/null +++ b/templates/databaseparam.html.twig @@ -0,0 +1,20 @@ +{% 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..2335017 --- /dev/null +++ b/templates/databaseparam_computergroup.html.twig @@ -0,0 +1,91 @@ +{% 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..38546bd --- /dev/null +++ b/templates/databaseparam_credential.html.twig @@ -0,0 +1,92 @@ +{% 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 From 526d4a2a47fdfb343cf77bd8d98b43d2d70d86f1 Mon Sep 17 00:00:00 2001 From: LAUNAY Samuel <107540223+Lainow@users.noreply.github.com> Date: Tue, 26 Sep 2023 15:56:35 +0200 Subject: [PATCH 3/9] fix(plugin) fix warning in computergroup page --- inc/computergroupdynamic.class.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/inc/computergroupdynamic.class.php b/inc/computergroupdynamic.class.php index 022e57c..d4ad184 100644 --- a/inc/computergroupdynamic.class.php +++ b/inc/computergroupdynamic.class.php @@ -74,10 +74,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 '; From eed1ebafb7019e9a1aa2a32868164542788c1e94 Mon Sep 17 00:00:00 2001 From: LAUNAY Samuel <107540223+Lainow@users.noreply.github.com> Date: Mon, 20 Nov 2023 09:47:23 +0100 Subject: [PATCH 4/9] Fix header blocks errors --- inc/computergroup.class.php | 1 + inc/computergroupstatic.class.php | 11 ++++++----- inc/contactlog.class.php | 1 + inc/credential.class.php | 1 + inc/databaseparam.class.php | 1 + inc/databaseparam_computergroup.class.php | 13 +++++++------ inc/databaseparam_credential.class.php | 17 +++++++++-------- 7 files changed, 26 insertions(+), 19 deletions(-) diff --git a/inc/computergroup.class.php b/inc/computergroup.class.php index 90a9cf1..5bbd605 100644 --- a/inc/computergroup.class.php +++ b/inc/computergroup.class.php @@ -1,4 +1,5 @@ getFromDB($staticgroup['computers_id'])) { $listofcomputers[] = $computers->fields + - [ - 'entityname' => Entity::getById($computers->fields['entities_id'])->fields['completename'], - 'link' => $computers->getLinkURL(), - 'idcompgroupstatic' => $staticgroup['id'], - ]; + [ + 'entityname' => Entity::getById($computers->fields['entities_id'])->fields['completename'], + 'link' => $computers->getLinkURL(), + 'idcompgroupstatic' => $staticgroup['id'], + ]; } } TemplateRenderer::getInstance()->display( diff --git a/inc/contactlog.class.php b/inc/contactlog.class.php index c18d8e5..d327e20 100644 --- a/inc/contactlog.class.php +++ b/inc/contactlog.class.php @@ -1,4 +1,5 @@ getFromDB($dbpcgroup['plugin_databaseinventory_computergroups_id'])) { $listofcgroups[] = $dbcgroups->fields + - [ - 'link' => $dbcgroups->getLinkURL(), - 'nbdynamicitems' => $dbcgroups->countDynamicItem(), - 'nbstaticitems' => $dbcgroups->countStaticItem(), - 'iddbparamcgroup' => $dbpcgroup['id'], - ]; + [ + 'link' => $dbcgroups->getLinkURL(), + 'nbdynamicitems' => $dbcgroups->countDynamicItem(), + 'nbstaticitems' => $dbcgroups->countStaticItem(), + 'iddbparamcgroup' => $dbpcgroup['id'], + ]; } } TemplateRenderer::getInstance()->display( diff --git a/inc/databaseparam_credential.class.php b/inc/databaseparam_credential.class.php index c25eb64..5dea0f7 100644 --- a/inc/databaseparam_credential.class.php +++ b/inc/databaseparam_credential.class.php @@ -1,4 +1,5 @@ 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'], - ]; + [ + 'type' => Dropdown::getDropdownName( + PluginDatabaseinventoryCredentialType::getTable(), + $dbcredentials->fields['plugin_databaseinventory_credentialtypes_id'] + ), + 'link' => $dbcredentials->getLinkURL(), + 'iddbparamcredential' => $dbpcredential['id'], + ]; } } TemplateRenderer::getInstance()->display( From 663ac0a75e150ff99f249a771b5e844203af973c Mon Sep 17 00:00:00 2001 From: LAUNAY Samuel <107540223+Lainow@users.noreply.github.com> Date: Mon, 20 Nov 2023 09:53:34 +0100 Subject: [PATCH 5/9] Fix PHPStan error --- inc/contactlog.class.php | 2 +- inc/menu.class.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/contactlog.class.php b/inc/contactlog.class.php index d327e20..b48a4f3 100644 --- a/inc/contactlog.class.php +++ b/inc/contactlog.class.php @@ -153,7 +153,7 @@ private static function showForAgent(Agent $agent) $linkdbparam = $dbparam->getLinkURL(); $dbparamname = $dbparam->fields['name']; } - if (isset($linkcred) || isset($linkagent)) { + if (isset($linkcred)) { $listofctlog[] = $dbpctlog + [ 'linkcred' => $linkcred ?? '', 'linkdbparam' => $linkdbparam ?? '', diff --git a/inc/menu.class.php b/inc/menu.class.php index a50178d..8330f23 100644 --- a/inc/menu.class.php +++ b/inc/menu.class.php @@ -51,7 +51,7 @@ public static function getMenuContent() } $menu = [ - 'title' => self::getMenuName(2), + 'title' => self::getMenuName(), 'page' => PluginDatabaseinventoryDatabaseParam::getSearchURL(false), 'icon' => 'fas fa-database', 'options' => [], From 32f41fc0bdd0d4ecad38252300241731fa9be08b Mon Sep 17 00:00:00 2001 From: LAUNAY Samuel <107540223+Lainow@users.noreply.github.com> Date: Mon, 20 Nov 2023 09:56:44 +0100 Subject: [PATCH 6/9] Fix linkcred PHPStan error --- inc/contactlog.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/contactlog.class.php b/inc/contactlog.class.php index b48a4f3..3a1519e 100644 --- a/inc/contactlog.class.php +++ b/inc/contactlog.class.php @@ -155,7 +155,7 @@ private static function showForAgent(Agent $agent) } if (isset($linkcred)) { $listofctlog[] = $dbpctlog + [ - 'linkcred' => $linkcred ?? '', + 'linkcred' => $linkcred, 'linkdbparam' => $linkdbparam ?? '', 'credname' => $credname ?? '', 'dbparamname' => $dbparamname ?? '', From 8f2654148cea7d76b1b7d3a888b2f675a752e99d Mon Sep 17 00:00:00 2001 From: LAUNAY Samuel <107540223+Lainow@users.noreply.github.com> Date: Mon, 20 Nov 2023 10:00:59 +0100 Subject: [PATCH 7/9] Fix all headers --- templates/computergroup.html.twig | 28 +++++++++++++++++++ templates/computergroupstatic.html.twig | 28 +++++++++++++++++++ templates/contactlog.html.twig | 28 +++++++++++++++++++ templates/credential.html.twig | 28 +++++++++++++++++++ templates/databaseparam.html.twig | 28 +++++++++++++++++++ .../databaseparam_computergroup.html.twig | 28 +++++++++++++++++++ templates/databaseparam_credential.html.twig | 28 +++++++++++++++++++ 7 files changed, 196 insertions(+) diff --git a/templates/computergroup.html.twig b/templates/computergroup.html.twig index c0629eb..106fb7d 100644 --- a/templates/computergroup.html.twig +++ b/templates/computergroup.html.twig @@ -1 +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 index c09835e..db47e97 100644 --- a/templates/computergroupstatic.html.twig +++ b/templates/computergroupstatic.html.twig @@ -1,3 +1,31 @@ +{# + # ------------------------------------------------------------------------- + # 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() %} diff --git a/templates/contactlog.html.twig b/templates/contactlog.html.twig index fddfcaf..e3f154e 100644 --- a/templates/contactlog.html.twig +++ b/templates/contactlog.html.twig @@ -1,3 +1,31 @@ +{# + # ------------------------------------------------------------------------- + # 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 %} diff --git a/templates/credential.html.twig b/templates/credential.html.twig index b545b6c..be13da5 100644 --- a/templates/credential.html.twig +++ b/templates/credential.html.twig @@ -1,3 +1,31 @@ +{# + # ------------------------------------------------------------------------- + # 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 %} diff --git a/templates/databaseparam.html.twig b/templates/databaseparam.html.twig index 119aef2..a6de483 100644 --- a/templates/databaseparam.html.twig +++ b/templates/databaseparam.html.twig @@ -1,3 +1,31 @@ +{# + # ------------------------------------------------------------------------- + # 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 %} diff --git a/templates/databaseparam_computergroup.html.twig b/templates/databaseparam_computergroup.html.twig index 2335017..4561596 100644 --- a/templates/databaseparam_computergroup.html.twig +++ b/templates/databaseparam_computergroup.html.twig @@ -1,3 +1,31 @@ +{# + # ------------------------------------------------------------------------- + # 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() %} diff --git a/templates/databaseparam_credential.html.twig b/templates/databaseparam_credential.html.twig index 38546bd..9851095 100644 --- a/templates/databaseparam_credential.html.twig +++ b/templates/databaseparam_credential.html.twig @@ -1,3 +1,31 @@ +{# + # ------------------------------------------------------------------------- + # 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() %} From 3d5afab44fbe9811166a549976e37f21b60d655e Mon Sep 17 00:00:00 2001 From: LAUNAY Samuel <107540223+Lainow@users.noreply.github.com> Date: Mon, 20 Nov 2023 10:07:05 +0100 Subject: [PATCH 8/9] Fix headers missed --- inc/computergroup.class.php | 28 +++++++++++++++++++++++ inc/computergroupstatic.class.php | 28 +++++++++++++++++++++++ inc/contactlog.class.php | 28 +++++++++++++++++++++++ inc/credential.class.php | 28 +++++++++++++++++++++++ inc/databaseparam.class.php | 28 +++++++++++++++++++++++ inc/databaseparam_computergroup.class.php | 28 +++++++++++++++++++++++ inc/databaseparam_credential.class.php | 28 +++++++++++++++++++++++ 7 files changed, 196 insertions(+) diff --git a/inc/computergroup.class.php b/inc/computergroup.class.php index 5bbd605..ded7327 100644 --- a/inc/computergroup.class.php +++ b/inc/computergroup.class.php @@ -1,5 +1,33 @@ . + * ------------------------------------------------------------------------- + * @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; /** diff --git a/inc/computergroupstatic.class.php b/inc/computergroupstatic.class.php index d4b694a..28c62bb 100644 --- a/inc/computergroupstatic.class.php +++ b/inc/computergroupstatic.class.php @@ -1,5 +1,33 @@ . + * ------------------------------------------------------------------------- + * @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; /** diff --git a/inc/contactlog.class.php b/inc/contactlog.class.php index 3a1519e..97a0f33 100644 --- a/inc/contactlog.class.php +++ b/inc/contactlog.class.php @@ -1,5 +1,33 @@ . + * ------------------------------------------------------------------------- + * @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; /** diff --git a/inc/credential.class.php b/inc/credential.class.php index 78892b5..afd89d6 100644 --- a/inc/credential.class.php +++ b/inc/credential.class.php @@ -1,5 +1,33 @@ . + * ------------------------------------------------------------------------- + * @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; /** diff --git a/inc/databaseparam.class.php b/inc/databaseparam.class.php index 0cb1ea6..2ed6cc7 100644 --- a/inc/databaseparam.class.php +++ b/inc/databaseparam.class.php @@ -1,5 +1,33 @@ . + * ------------------------------------------------------------------------- + * @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; /** diff --git a/inc/databaseparam_computergroup.class.php b/inc/databaseparam_computergroup.class.php index b260e8d..a58a5da 100644 --- a/inc/databaseparam_computergroup.class.php +++ b/inc/databaseparam_computergroup.class.php @@ -1,5 +1,33 @@ . + * ------------------------------------------------------------------------- + * @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; /** diff --git a/inc/databaseparam_credential.class.php b/inc/databaseparam_credential.class.php index 5dea0f7..2f87227 100644 --- a/inc/databaseparam_credential.class.php +++ b/inc/databaseparam_credential.class.php @@ -1,5 +1,33 @@ . + * ------------------------------------------------------------------------- + * @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; /** From be97fa751b6c493abaa3b1cd95775c63726aaf1d Mon Sep 17 00:00:00 2001 From: stonebuzz Date: Wed, 21 Feb 2024 09:07:45 +0100 Subject: [PATCH 9/9] update icon --- inc/computergroup.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/computergroup.class.php b/inc/computergroup.class.php index ded7327..e60878c 100644 --- a/inc/computergroup.class.php +++ b/inc/computergroup.class.php @@ -275,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()