Files
itflow/agent/modals/software/software_export.php

156 lines
7.0 KiB
PHP

<?php
require_once '../../../includes/modal_header.php';
enforceUserPermission('module_support');
// Pre-filled from the software page's current filters. Everything here is editable -
// the export runs whatever this form posts, not whatever the page happened to show.
$client_id = intval($_GET['client_id'] ?? 0);
if ($client_id) {
enforceClientAccess();
}
// Search Filter
$q_filter = $_GET['q'] ?? '';
// Client Filter
$client_filter = intval($_GET['client'] ?? 0);
// Expiring In Filter
$expire_filter = $_GET['expire_days'] ?? '';
// Archived Filter
$archived_filter = (isset($_GET['archived']) && $_GET['archived'] == 1) ? 1 : 0;
// Attention tab and license type
$status_filters = softwareStatusFilters();
$status_filter = isset($status_filters[$_GET['status'] ?? '']) ? $_GET['status'] : '';
$license_type_filter = (string) ($_GET['license_type'] ?? '');
$software_type_filter = trim(strip_tags((string) ($_GET['software_type'] ?? '')));
$tag_filter = tagFilterIds();
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fas fa-fw fa-download me-2"></i>Export Licenses</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<?php exportTabsNav(); ?>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="client_id" value="<?= $client_id ?>">
<div class="modal-body">
<?php exportTabsFiltersOpen(); ?>
<div class="mb-3">
<label>Search</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-search"></i></span>
<input type="text" class="form-control" name="q" value="<?= stripslashes(escapeHtml($q_filter)) ?>" placeholder="Name, type, key, vendor">
</div>
</div>
<?php if (!$client_id) { ?>
<div class="mb-3">
<label>Client</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-user"></i></span>
<select class="form-select select2" name="client">
<option value="">- All Clients -</option>
<?php
$sql_clients_filter = mysqli_query($mysqli, "SELECT client_id, client_name, client_abbreviation FROM clients WHERE EXISTS (SELECT 1 FROM software WHERE software_client_id = client_id) ORDER BY client_name ASC");
while ($row = mysqli_fetch_assoc($sql_clients_filter)) {
$filter_client_id = intval($row['client_id']);
$filter_client_name = escapeHtml($row['client_name']);
?>
<option <?php if ($client_filter == $filter_client_id) { echo "selected"; } ?> value="<?= $filter_client_id ?>"<?= selectOptionClient($row['client_id'], $row['client_name'], $row['client_abbreviation'] ?? '') ?>><?= $filter_client_name ?></option>
<?php
}
?>
</select>
</div>
</div>
<?php } ?>
<div class="mb-3">
<label>Expiring In</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-hourglass-half"></i></span>
<select class="form-select select2" name="expire_days">
<option value="">- Any -</option>
<option <?php if ($expire_filter === 'expired') { echo "selected"; } ?> value="expired">Expired</option>
<?php foreach ([7, 30, 45, 60, 90] as $expire_option) { ?>
<option <?php if ($expire_filter !== '' && $expire_filter == $expire_option) { echo "selected"; } ?> value="<?= $expire_option ?>"><?= $expire_option ?> Days</option>
<?php } ?>
</select>
</div>
</div>
<div class="mb-3">
<label>Showing</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-filter"></i></span>
<select class="form-select select2" name="status">
<option value="">- All -</option>
<?php foreach ($status_filters as $status_key => $status_option) { ?>
<option <?php if ($status_filter === $status_key) { echo "selected"; } ?> value="<?= $status_key ?>"<?= selectOptionData(['icon' => 'fas ' . $status_option['icon']]) ?>><?= $status_option['label'] ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="mb-3">
<label>Software Type</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-layer-group"></i></span>
<select class="form-select select2" name="software_type">
<option value="">- Any -</option>
<?= categoryFilterOptionsHtml('software_type', $software_type_filter, "SELECT DISTINCT software_type FROM software WHERE software_type IS NOT NULL AND software_type <> ''" . ($client_id ? " AND software_client_id = $client_id" : '') . clientScopeSql('software_client_id')) ?>
</select>
</div>
</div>
<div class="mb-3">
<label>License Type</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-certificate"></i></span>
<select class="form-select select2" name="license_type">
<option value="">- Any -</option>
<?php foreach (array_unique(array_merge(array_keys(SOFTWARE_LICENSE_TYPES), $license_type_filter !== '' ? [$license_type_filter] : [])) as $license_type_option) { ?>
<option <?php if ($license_type_filter === $license_type_option) { echo "selected"; } ?><?= selectOptionData(['icon' => 'fas ' . softwareLicenseTypeIcon($license_type_option)]) ?>><?= escapeHtml($license_type_option) ?></option>
<?php } ?>
</select>
</div>
</div>
<?= tagExportFieldHtml('license', $tag_filter) ?>
<div class="mb-3">
<label>Archived</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-archive"></i></span>
<select class="form-select select2" name="archived">
<option <?php if (!$archived_filter) { echo "selected"; } ?> value="0">Active only</option>
<option <?php if ($archived_filter) { echo "selected"; } ?> value="1">Archived only</option>
</select>
</div>
</div>
<?php exportTabsColumns('software'); ?>
</div>
<div class="modal-footer">
<?php renderExportButtons('export_software'); ?>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';