'devices')); $where_array = build_devices_where_array($vars); $where = ' WHERE 1 '; $where .= implode('', $where_array); register_html_title("Devices"); foreach ($config['device_types'] as $entry) { $types[$entry['type']] = $entry; } $query_geocoding = ''; if ($config['geocoding']['enable']) { foreach ([ 'location_lat', 'location_lon', 'location_country', 'location_state', 'location_county', 'location_city' ] as $field) { if (isset($where_array[$field])) { $query_geocoding = ' LEFT JOIN `devices_locations` USING (`device_id`)'; break; } } } // Generate array with form elements $form_items = array(); foreach ([ 'os', 'hardware', 'vendor', 'version', 'features', 'type', 'distro' ] as $entry) { $query = "SELECT DISTINCT `$entry` FROM `devices`" . $query_geocoding; if (isset($where_array[$entry])) { $tmp = $where_array[$entry]; unset($where_array[$entry]); $query .= ' WHERE 1 ' . implode('', $where_array); $where_array[$entry] = $tmp; } else { //r($where_array); $query .= $where; } $query .= " AND `$entry` != '' $query_permitted"; $selected = dbFetchColumn($query); $query_all = "SELECT DISTINCT `$entry` FROM `devices` WHERE `$entry` != '' $query_permitted ORDER BY `$entry`"; foreach (dbFetchColumn($query_all) as $item) { $group = in_array($item, $selected, TRUE) ? "Listed" : "Other"; if ($entry === 'os') { $name = [ 'name' => $config['os'][$item]['text'], 'group' => $group ]; } elseif ($entry === 'type') { if (isset($types[$item])) { $name = [ 'name' => $types[$item]['text'], 'icon' => $types[$item]['icon'], 'group' => $group ]; } else { $name = [ 'name' => nicecase($item), 'icon' => $config['icon']['exclamation'], 'group' => $group ]; } } else { $name = [ 'name' => nicecase($item), 'group' => $group ]; } $form_items[$entry][$item] = $name; } } if (isset($form_items['os'])) { asort($form_items['os']); } $tmp = $where_array; if (isset($where_array['location'])) { unset($tmp['location']); } $query = "SELECT DISTINCT `devices`.`location` FROM `devices`" . $query_geocoding; $query .= ' WHERE 1 ' . implode('', $tmp); $query .= " $query_permitted"; $selected = dbFetchColumn($query); unset($tmp); foreach (get_locations() as $entry) { $group = in_array($entry, $selected, TRUE) ? "Listed" : "Other"; if ($entry === '') { $entry = OBS_VAR_UNSET; } $form_items['location'][$entry] = [ 'name' => $entry, 'group' => $group ]; } foreach (get_type_groups('device') as $entry) { $form_items['group'][$entry['group_id']] = $entry['group_name']; } //print_vars($form_items); $form_items['sort'] = array('hostname' => 'Hostname', 'domain' => 'Hostname in Domain Order', 'location' => 'Location', 'os' => 'Operating System', 'version' => 'Version', 'features' => 'Featureset', 'type' => 'Device Type', 'uptime' => 'Uptime'); $form = array('type' => 'rows', 'space' => '10px', 'submit_by_key' => TRUE, 'url' => generate_url($vars)); // First row $form['row'][0]['hostname'] = array( 'type' => 'text', 'name' => 'Hostname', 'value' => $vars['hostname'], 'width' => '100%', //'180px', 'placeholder' => TRUE); $form['row'][0]['location'] = array( 'type' => 'multiselect', 'name' => 'Select Locations', 'width' => '100%', //'180px', 'encode' => TRUE, 'value' => $vars['location'], 'groups' => [ 'Listed', 'Other' ], 'values' => $form_items['location']); $form['row'][0]['os'] = array( 'type' => 'multiselect', 'name' => 'Select OS', 'width' => '100%', //'180px', 'value' => $vars['os'], 'groups' => [ 'Listed', 'Other' ], 'values' => $form_items['os']); $form['row'][0]['hardware'] = array( 'type' => 'multiselect', 'name' => 'Select Hardware', 'width' => '100%', //'180px', 'value' => $vars['hardware'], 'groups' => [ 'Listed', 'Other' ], 'values' => $form_items['hardware']); $form['row'][0]['vendor'] = array( 'type' => 'multiselect', 'name' => 'Select Vendor', 'width' => '100%', //'180px', 'value' => $vars['vendor'], 'groups' => [ 'Listed', 'Other' ], 'values' => $form_items['vendor']); $form['row'][0]['group'] = array( 'type' => 'multiselect', 'name' => 'Select Groups', 'width' => '100%', //'180px', 'value' => $vars['group'], 'values' => $form_items['group']); // Select sort pull-rigth //$form['row'][0]['sort'] = array( // 'type' => 'select', // 'icon' => $config['icon']['sort'], // 'right' => TRUE, // 'width' => '100%', //'150px', // 'value' => $vars['sort'], // 'values' => $form_items['sort']); // Second row $form['row'][1]['sysname'] = array( 'type' => 'text', 'name' => 'sysName', 'value' => $vars['sysname'], 'width' => '100%', //'180px', 'placeholder' => TRUE); $form['row'][1]['location_text'] = array( 'type' => 'text', 'name' => 'Location', 'value' => $vars['location_text'], 'width' => '100%', //'180px', 'placeholder' => TRUE); $form['row'][1]['version'] = array( 'type' => 'multiselect', 'name' => 'Select OS Version', 'width' => '100%', //'180px', 'value' => $vars['version'], 'groups' => [ 'Listed', 'Other' ], 'values' => $form_items['version']); $form['row'][1]['features'] = array( 'type' => 'multiselect', 'name' => 'Select Featureset', 'width' => '100%', //'180px', 'value' => $vars['features'], 'groups' => [ 'Listed', 'Other' ], 'values' => $form_items['features']); $form['row'][1]['type'] = array( 'type' => 'multiselect', 'name' => 'Select Device Type', 'width' => '100%', //'180px', 'value' => $vars['type'], 'groups' => [ 'Listed', 'Other' ], // Order 'values' => $form_items['type']); // Select sort pull-right $form['row'][1]['sort'] = array( 'type' => 'select', 'icon' => $config['icon']['sort'], 'right' => TRUE, 'width' => '100%', //'150px', 'value' => $vars['sort'], 'values' => $form_items['sort']); // Third row $form['row'][2]['sysDescr'] = array( 'type' => 'text', 'name' => 'sysDescr', 'value' => $vars['sysDescr'], 'width' => '100%', //'180px', 'placeholder' => TRUE); $form['row'][2]['purpose'] = array( 'type' => 'text', 'name' => 'Description / Purpose', 'value' => $vars['purpose'], 'width' => '100%', //'180px', 'placeholder' => TRUE); $form['row'][2]['sysContact'] = array( 'type' => 'text', 'name' => 'sysContact', 'value' => $vars['sysContact'], 'width' => '100%', //'180px', 'placeholder' => TRUE); $form['row'][2]['distro'] = array( 'type' => 'multiselect', 'name' => 'Select Distro', 'width' => '100%', //'180px', 'value' => $vars['distro'], 'groups' => [ 'Listed', 'Other' ], 'values' => $form_items['distro']); $form['row'][2]['serial'] = array( 'type' => 'text', 'name' => 'Serial Number', 'value' => $vars['serial'], 'width' => '100%', //'180px', 'placeholder' => TRUE); $form['row'][2]['disabled'] = array( 'type' => 'switch-ng', //'on-text' => 'Disabled', 'on-color' => 'primary', 'on-icon' => 'icon-eye-close', //'off-text' => 'Enabled', 'off-icon' => 'icon-eye-open', 'grid' => 1, //'size' => 'large', //'height' => '15px', 'title' => 'Show Enabled/Disabled', //'placeholder' => 'Disabled', //'readonly' => TRUE, //'disabled' => TRUE, //'submit_by_key' => TRUE, 'value' => $vars['disabled'] ); // search button $form['row'][2]['search'] = array( 'type' => 'submit', //'name' => 'Search', //'class' => 'btn-primary', //'icon' => 'icon-search', 'grid' => 1, 'right' => TRUE, ); $panel_form = array('type' => 'rows', 'title' => 'Search Devices', 'space' => '10px', 'submit_by_key' => TRUE, 'url' => generate_url($vars)); $panel_form['row'][0] = array('hostname' => $form['row'][0]['hostname'], 'sysname' => $form['row'][1]['sysname']); $panel_form['row'][1] = array('sysDescr' => $form['row'][2]['sysDescr'], 'purpose' => $form['row'][2]['purpose']); $panel_form['row'][2] = array('sysContact' => $form['row'][2]['sysContact'], 'serial' => $form['row'][2]['serial']); $panel_form['row'][3] = array('location' => $form['row'][0]['location'], 'location_text' => $form['row'][1]['location_text']); $panel_form['row'][4]['os'] = $form['row'][0]['os']; $panel_form['row'][4]['version'] = $form['row'][1]['version']; $panel_form['row'][4]['distro'] = $form['row'][2]['distro']; $panel_form['row'][5]['hardware'] = $form['row'][0]['hardware']; $panel_form['row'][5]['vendor'] = $form['row'][0]['vendor']; $panel_form['row'][6]['type'] = $form['row'][1]['type']; $panel_form['row'][6]['features'] = $form['row'][1]['features']; $panel_form['row'][7]['group'] = $form['row'][0]['group']; $panel_form['row'][7]['group']['grid'] = 4; $panel_form['row'][7]['sort'] = $form['row'][1]['sort']; $panel_form['row'][7]['sort']['grid'] = 4; $panel_form['row'][7]['disabled'] = $form['row'][2]['disabled']; $panel_form['row'][7]['disabled']['grid'] = 2; $panel_form['row'][7]['search'] = $form['row'][2]['search']; $panel_form['row'][7]['search']['grid'] = 2; // Register custom panel register_html_panel(generate_form($panel_form)); if ($vars['searchbar'] !== "hide") { echo '