Skip to content

Commit

Permalink
Change inventory report to work without groups and add search field
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian-Roth committed Jul 21, 2019
1 parent 3e67a77 commit dde4d9d
Showing 1 changed file with 97 additions and 88 deletions.
185 changes: 97 additions & 88 deletions packages/web/lib/reports/inventory_report.report.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,116 +37,109 @@ public function file()
array('class' => 'col-xs-4'),
array('class' => 'col-xs-8 form-group')
);
$fields = array();
$groupNames = self::getSubObjectIDs(
'Group',
'',
'name'
);
$groupNames = array_values(
array_filter(
array_unique(
(array)$groupNames
)
)
);
if (is_array($groupNames) && count($groupNames) > 0) {
$groupNames = array_values(
array_filter(
array_unique(
(array)$groupNames
)
)
);
natcasesort($groupNames);
$groupSelForm = self::selectForm(
'groupsearch',
$groupNames
);
unset($groupNames);
$fields += array('<label for="groupsearch">'
. _('Enter a group name to search for')
. '</label>' => $groupSelForm
);
} else {
$fields += array('<label for="groupsearch">'
. _('Enter a group name to search for')
. '</label>' => _('No groups defined, search will return all hosts.')
);
}
if (in_array('location', (array)self::$pluginsinstalled)) {
$locationNames = self::getSubObjectIDs(
'Location',
'',
'name'
);
natcasesort($locationNames);
if (count($locationNames) > 0) {
);
if (is_array($locationNames) && count($locationNames) > 0) {
natcasesort($locationNames);
$locationSelForm = self::selectForm(
'locationsearch',
$locationNames
);
unset($locationNames);
$fields += array('<label for="locationsearch">'
. _('Enter a location name to search for')
. '</label>' => $locationSelForm
);
}
}
if (in_array('site', (array)self::$pluginsinstalled)) {
$siteNames = self::getSubObjectIDs(
'site',
'',
'name'
);
natcasesort($siteNames);
if (count($siteNames) > 0) {
);
if (is_array($siteNames) && count($siteNames) > 0) {
natcasesort($siteNames);
$siteSelForm = self::selectForm(
'sitesearch',
$siteNames
);
);
unset($siteNames);
$fields += array('<label for="sitesearch">'
. _('Enter a site name to search for')
. '</label>' => $siteSelForm
);
}
}
$sysproductNames = self::getSubObjectIDs(
'inventory',
'',
'sysproduct'
);
$sysproductNames = array_values(
array_filter(
array_unique(
(array)$sysproductNames
)
)
);
natcasesort($groupNames);
natcasesort($sysproductNames);

if (count($groupNames) > 0) {
$groupSelForm = self::selectForm(
'groupsearch',
$groupNames
);
unset($groupNames);
}
if (count($sysproductNames) > 0) {
if (is_array($sysproductNames) && count($sysproductNames) > 0) {
$sysproductNames = array_values(
array_filter(
array_unique(
(array)$sysproductNames
)
)
);
natcasesort($sysproductNames);
$sysproductSelForm = self::selectForm(
'sysproductsearch',
$sysproductNames
);
);
unset($sysproductNames);
}

$fields = array(
'<label for="groupsearch">'
. _('Enter a group name to search for')
. '</label>' => $groupSelForm,
'<label for="sysproductsearch">'
$fields += array('<label for="sysproductsearch">'
. _('Enter a model name to search for')
. '</label>' => $sysproductSelForm,
'<label for="performsearch">'
. '</label>' => $sysproductSelForm
);
}
$fields += array('<label for="hostpattern">'
. _('Search pattern') . '</label>'
=> '<input type="text" name="hostpattern" placeholder="Search... leave empty for all elements" class="form-control" />'
) + array('<label for="performsearch">'
. _('Perform search')
. '</label>' => '<button type="submit" name="performsearch" '
. 'class="btn btn-info btn-block" id="performsearch">'
. _('Search')
. '</button>'
);
if (in_array('location', (array)self::$pluginsinstalled)) {
self::arrayInsertAfter(
'<label for="groupsearch">'
. _('Enter a group name to search for')
. '</label>',
$fields,
'<label for="locationsearch">'
. _('Enter a location name to search for')
. '</label>',
$locationSelForm
);
}
if (in_array('site', (array)self::$pluginsinstalled)) {
self::arrayInsertAfter(
'<label for="groupsearch">'
. _('Enter a group name to search for')
. '</label>',
$fields,
'<label for="sitesearch">'
. _('Enter a site name to search for')
. '</label>',
$siteSelForm
);
}
array_walk($fields, $this->fieldsToData);
echo '<div class="col-xs-9">';
echo '<div class="panel panel-info">';
Expand Down Expand Up @@ -178,10 +171,6 @@ public function filePost()
INPUT_POST,
'groupsearch'
);
if (!$groupsearch) {
$groupsearch = '%';
}

$locationsearch = filter_input(
INPUT_POST,
'locationsearch'
Expand All @@ -197,7 +186,15 @@ public function filePost()
if (!$sysproductsearch) {
$sysproductsearch = '%';
}

$hostpattern = filter_input(
INPUT_POST,
'hostpattern'
);
if (!$hostpattern) {
$hostpattern = '%';
} else {
$hostpattern = '%' . $hostpattern . '%';
}
array_walk(
self::$inventoryCsvHead,
function (&$classGet, &$csvHeader) {
Expand Down Expand Up @@ -225,17 +222,19 @@ function (&$classGet, &$csvHeader) {
array()
);

$groupIDs = self::getSubObjectIDs(
'Group',
array('name' => $groupsearch),
'id'
);

$groupHostIDs = self::getSubObjectIDs(
'GroupAssociation',
array('groupID' => $groupIDs),
'hostID'
);
$groupHostIDs = array();
if ($groupsearch) {
$groupIDs = self::getSubObjectIDs(
'Group',
array('name' => $groupsearch),
'id'
);
$groupHostIDs = self::getSubObjectIDs(
'GroupAssociation',
array('groupID' => $groupIDs),
'hostID'
);
}
if (in_array('location', (array)self::$pluginsinstalled) && $locationsearch) {
$locationIDs = self::getSubObjectIDs(
'Location',
Expand Down Expand Up @@ -269,14 +268,24 @@ function (&$classGet, &$csvHeader) {
);
$groupHostIDs = array_intersect($sysproductIDs, $groupHostIDs);

Route::listem(
'host',
'name',
'false',
array(
'id' => $groupHostIDs
if ($groupsearch) {
Route::listem(
'host',
'name',
'false',
array(
'id' => $groupHostIDs,
'name' => $hostpattern
)
);
);
} else {
Route::listem(
'host',
'name',
'false',
array('name' => $hostpattern)
);
}

$Hosts = json_decode(
Route::getData()
Expand Down

0 comments on commit dde4d9d

Please sign in to comment.