Added asset Type buttons under client assets and client asset type basge counts along with only display the nessessary fields based off the asset type chosen

This commit is contained in:
johnnyq 2022-01-21 14:25:41 -05:00
parent 08529ba193
commit 5ba2beafac
1 changed files with 87 additions and 3 deletions

View File

@ -1,5 +1,34 @@
<?php
//Get Asset Counts
//All Asset Count
$row = mysqli_fetch_assoc(mysqli_query($mysqli,"SELECT COUNT(*) AS count FROM assets WHERE asset_archived_at IS NULL AND asset_client_id = $client_id"));
$all_count = $row['count'];
//Workstation Count
$row = mysqli_fetch_assoc(mysqli_query($mysqli,"SELECT COUNT(*) AS count FROM assets WHERE (asset_type = 'laptop' OR asset_type = 'desktop')
AND asset_archived_at IS NULL AND asset_client_id = $client_id"));
$workstation_count = $row['count'];
//Server Count
$row = mysqli_fetch_assoc(mysqli_query($mysqli,"SELECT COUNT(*) AS count FROM assets WHERE (asset_type = 'server')
AND asset_archived_at IS NULL AND asset_client_id = $client_id"));
$server_count = $row['count'];
//Virtual Server Count
$row = mysqli_fetch_assoc(mysqli_query($mysqli,"SELECT COUNT(*) AS count FROM assets WHERE (asset_type = 'virtual machine')
AND asset_archived_at IS NULL AND asset_client_id = $client_id"));
$virtual_count = $row['count'];
//Network Count
$row = mysqli_fetch_assoc(mysqli_query($mysqli,"SELECT COUNT(*) AS count FROM assets WHERE (asset_type = 'Firewall/Router' OR asset_type = 'switch' OR asset_type = 'access point')
AND asset_archived_at IS NULL AND asset_client_id = $client_id"));
$network_count = $row['count'];
//Other Count
$row = mysqli_fetch_assoc(mysqli_query($mysqli,"SELECT COUNT(*) AS count FROM assets WHERE (asset_type NOT LIKE 'laptop' AND asset_type NOT LIKE 'desktop' AND asset_type NOT LIKE 'server' AND asset_type NOT LIKE 'virtual machine' AND asset_type NOT LIKE 'firewall/router' AND asset_type NOT LIKE 'switch' AND asset_type NOT LIKE 'access point')
AND asset_archived_at IS NULL AND asset_client_id = $client_id"));
$other_count = $row['count'];
//Paging
if(isset($_GET['p'])){
$p = intval($_GET['p']);
@ -36,12 +65,28 @@ if(isset($_GET['o'])){
$disp = "DESC";
}
//Asset Type from GET
if(isset($_GET['type']) && ($_GET['type']) == 'workstations'){
$type_query = "asset_type = 'desktop' OR asset_type = 'laptop'";
}elseif(isset($_GET['type']) && ($_GET['type']) == 'servers'){
$type_query = "asset_type = 'servers'";
}elseif(isset($_GET['type']) && ($_GET['type']) == 'virtual'){
$type_query = "asset_type = 'Virtual Machine'";
}elseif(isset($_GET['type']) && ($_GET['type']) == 'network'){
$type_query = "asset_type = 'Firewall/Router' OR asset_type = 'Switch' OR asset_type = 'Access Point'";
}elseif(isset($_GET['type']) && ($_GET['type']) == 'other'){
$type_query = "asset_type NOT LIKE 'laptop' AND asset_type NOT LIKE 'desktop' AND asset_type NOT LIKE 'server' AND asset_type NOT LIKE 'virtual machine' AND asset_type NOT LIKE 'firewall/router' AND asset_type NOT LIKE 'switch' AND asset_type NOT LIKE 'access point'";
}else{
$type_query = "asset_type LIKE '%'";
}
//Rebuild URL
$url_query_strings_sb = http_build_query(array_merge($_GET,array('sb' => $sb, 'o' => $o)));
$sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM assets LEFT JOIN contacts ON asset_contact_id = contact_id LEFT JOIN locations ON asset_location_id = location_id LEFT JOIN logins ON login_asset_id = asset_id
WHERE asset_client_id = $client_id
AND (asset_name LIKE '%$q%' OR asset_type LIKE '%$q%' OR asset_ip LIKE '%$q%' OR asset_make LIKE '%$q%' OR asset_model LIKE '%$q%' OR asset_serial LIKE '%$q%' OR asset_os LIKE '%$q%' OR contact_name LIKE '%$q%' OR location_name LIKE '%$q%')
AND (asset_name LIKE '%$q%' OR asset_type LIKE '%$q%' OR asset_ip LIKE '%$q%' OR asset_make LIKE '%$q%' OR asset_model LIKE '%$q%' OR asset_serial LIKE '%$q%' OR asset_os LIKE '%$q%' OR contact_name LIKE '%$q%' OR location_name LIKE '%$q%')
AND ($type_query)
ORDER BY $sb $o LIMIT $record_from, $record_to");
$num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
@ -59,6 +104,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
<form autocomplete="off">
<input type="hidden" name="client_id" value="<?php echo $client_id; ?>">
<input type="hidden" name="tab" value="<?php echo $_GET['tab']; ?>">
<input type="hidden" name="type" value="<?php echo $_GET['type']; ?>">
<div class="row">
<div class="col-md-4">
@ -69,8 +115,38 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
</div>
</div>
</div>
<div class="col-md-8">
<div class="col-sm-6">
<div class="btn-group">
<a href="?<?php echo $url_query_strings_sb; ?>&type=%" class="btn <?php if($_GET['type'] == '%' OR empty($_GET['type'])){ echo 'btn-primary'; }else{ echo 'btn-default'; } ?>">All Assets <span class="right badge badge-light"><?php echo $all_count; ?></span></a>
<?php
if($workstation_count > 0){ ?>
<a href="?<?php echo $url_query_strings_sb; ?>&type=workstations" class="btn <?php if($_GET['type'] == 'workstations'){ echo 'btn-primary'; }else{ echo 'btn-default'; } ?>"><i class="fa fa-fw fa-desktop"></i> Workstations <span class="right badge badge-light"><?php echo $workstation_count; ?></span></a>
<?php
} ?>
<?php
if($server_count > 0){ ?>
<a href="?<?php echo $url_query_strings_sb; ?>&type=servers" class="btn <?php if($_GET['type'] == 'servers'){ echo 'btn-primary'; }else{ echo 'btn-default'; } ?>"><i class="fa fa-fw fa-server"></i> Servers <span class="right badge badge-light"><?php echo $server_count; ?></span></a>
<?php
} ?>
<?php
if($virtual_count > 0){ ?>
<a href="?<?php echo $url_query_strings_sb; ?>&type=virtual" class="btn <?php if($_GET['type'] == 'virtual'){ echo 'btn-primary'; }else{ echo 'btn-default'; } ?>"><i class="fa fa-fw fa-cloud"></i> Virtual <span class="right badge badge-light"><?php echo $virtual_count; ?></span></a>
<?php
} ?>
<?php
if($network_count > 0){ ?>
<a href="?<?php echo $url_query_strings_sb; ?>&type=network" class="btn <?php if($_GET['type'] == 'network'){ echo 'btn-primary'; }else{ echo 'btn-default'; } ?>"><i class="fa fa-fw fa-network-wired"></i> Network <span class="right badge badge-light"><?php echo $network_count; ?></span></a>
<?php
} ?>
<?php
if($network_count > 0){ ?>
<a href="?<?php echo $url_query_strings_sb; ?>&type=other" class="btn <?php if($_GET['type'] == 'other'){ echo 'btn-primary'; }else{ echo 'btn-default'; } ?>"><i class="fa fa-fw fa-tag"></i> Other <span class="right badge badge-light"><?php echo $other_count; ?></span></a>
<?php
} ?>
</div>
</div>
<div class="col-md-2">
<div class="float-right">
<a href="post.php?export_client_<?php echo $_GET['tab']; ?>_csv=<?php echo $client_id; ?>" class="btn btn-default"><i class="fa fa-fw fa-download"></i> Export</a>
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#addAssetCSVModal"><i class="fa fa-fw fa-upload"></i> Import</button>
@ -88,9 +164,13 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
<th><a class="text-secondary" href="?<?php echo $url_query_strings_sb; ?>&sb=asset_type&o=<?php echo $disp; ?>">Type</a></th>
<th><a class="text-secondary" href="?<?php echo $url_query_strings_sb; ?>&sb=asset_make&o=<?php echo $disp; ?>">Make/Model</a></th>
<th><a class="text-secondary" href="?<?php echo $url_query_strings_sb; ?>&sb=asset_serial&o=<?php echo $disp; ?>">Serial Number</a></th>
<?php if($_GET['type'] !== 'network' AND $_GET['type'] !== 'other'){ ?>
<th><a class="text-secondary" href="?<?php echo $url_query_strings_sb; ?>&sb=asset_os&o=<?php echo $disp; ?>">Operating System</a></th>
<?php } ?>
<th><a class="text-secondary" href="?<?php echo $url_query_strings_sb; ?>&sb=asset_install_date&o=<?php echo $disp; ?>">Install Date</a></th>
<?php if($_GET['type'] !== 'network' AND $_GET['type'] !== 'other'){ ?>
<th><a class="text-secondary" href="?<?php echo $url_query_strings_sb; ?>&sb=contact_name&o=<?php echo $disp; ?>">Contact</a></th>
<?php } ?>
<th><a class="text-secondary" href="?<?php echo $url_query_strings_sb; ?>&sb=location_name&o=<?php echo $disp; ?>">Location</a></th>
<th class="text-center">Action</th>
</tr>
@ -229,9 +309,13 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
<td><?php echo $asset_type; ?></td>
<td><?php echo "$asset_make $asset_model"; ?></td>
<td><?php echo $asset_serial_display; ?></td>
<?php if($_GET['type'] !== 'network' AND $_GET['type'] !== 'other'){ ?>
<td><?php echo $asset_os_display; ?></td>
<?php } ?>
<td><?php echo $asset_install_date_display; ?></td>
<?php if($_GET['type'] !== 'network' AND $_GET['type'] !== 'other'){ ?>
<td><?php echo $contact_name; ?></td>
<?php } ?>
<td><?php echo $location_name; ?></td>
<td>
<div class="dropdown dropleft text-center">