Simplify / rework some of the filter header logic and update filter vars in the rest of the code

This commit is contained in:
johnnyq 2025-01-22 18:55:05 -05:00
parent 4fc39a7203
commit 606f3061d0
11 changed files with 72 additions and 86 deletions

View File

@ -9,21 +9,21 @@ require_once "includes/inc_all_admin.php";
// Log Type Filter
if (isset($_GET['type']) & !empty($_GET['type'])) {
$log_type_query = "AND (app_log_type = '" . sanitizeInput($_GET['type']) . "')";
$type = nullable_htmlentities($_GET['type']);
$type_filter = nullable_htmlentities($_GET['type']);
} else {
// Default - any
$log_type_query = '';
$type = '';
$type_filter = '';
}
// Log Category Filter
if (isset($_GET['category']) & !empty($_GET['catergory'])) {
$log_category_query = "AND (app_log_category = '" . sanitizeInput($_GET['category']) . "')";
$category = nullable_htmlentities($_GET['category']);
$category_filter = nullable_htmlentities($_GET['category']);
} else {
// Default - any
$log_category_query = '';
$category = '';
$category_filter = '';
}
//Rebuild URL
@ -63,14 +63,14 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
<div class="col-sm-2">
<div class="form-group">
<select class="form-control select2" name="type" onchange="this.form.submit()">
<option value="" <?php if ($type == "") { echo "selected"; } ?>>- All Types -</option>
<option value="">- All Types -</option>
<?php
$sql_types_filter = mysqli_query($mysqli, "SELECT DISTINCT app_log_type FROM app_logs ORDER BY app_log_type ASC");
while ($row = mysqli_fetch_array($sql_types_filter)) {
$log_type = nullable_htmlentities($row['app_log_type']);
?>
<option <?php if ($type == $log_type) { echo "selected"; } ?>><?php echo $log_type; ?></option>
<option <?php if ($type_filter == $log_type) { echo "selected"; } ?>><?php echo $log_type; ?></option>
<?php
}
?>
@ -82,14 +82,14 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
<div class="col-sm-2">
<div class="form-group">
<select class="form-control select2" name="category" onchange="this.form.submit()">
<option value="" <?php if ($category == "") { echo "selected"; } ?>>- All Categories -</option>
<option value="">- All Categories -</option>
<?php
$sql_categories_filter = mysqli_query($mysqli, "SELECT DISTINCT app_log_category FROM app_logs ORDER BY app_log_category ASC");
while ($row = mysqli_fetch_array($sql_categories_filter)) {
$log_category = nullable_htmlentities($row['app_log_category']);
?>
<option <?php if ($category == $log_category) { echo "selected"; } ?>><?php echo $log_category; ?></option>
<option <?php if ($category_filter == $log_category) { echo "selected"; } ?>><?php echo $log_category; ?></option>
<?php
}
?>

View File

@ -9,41 +9,41 @@ require_once "includes/inc_all_admin.php";
// User Filter
if (isset($_GET['user']) & !empty($_GET['user'])) {
$user_query = 'AND (log_user_id = ' . intval($_GET['user']) . ')';
$user = intval($_GET['user']);
$user_filter = intval($_GET['user']);
} else {
// Default - any
$user_query = '';
$user = '';
$user_filter = '';
}
// Client Filter
if (isset($_GET['client']) & !empty($_GET['client'])) {
$client_query = 'AND (log_client_id = ' . intval($_GET['client']) . ')';
$client = intval($_GET['client']);
$client_filter = intval($_GET['client']);
} else {
// Default - any
$client_query = '';
$client = '';
$client_filter = '';
}
// Log Type Filter
if (isset($_GET['type']) & !empty($_GET['type'])) {
$log_type_query = "AND (log_type = '" . sanitizeInput($_GET['type']) . "')";
$type = nullable_htmlentities($_GET['type']);
$type_filter = nullable_htmlentities($_GET['type']);
} else {
// Default - any
$log_type_query = '';
$type = '';
$type_filter = '';
}
// Log Action Filter
if (isset($_GET['action']) & !empty($_GET['action'])) {
$log_action_query = "AND (log_action = '" . sanitizeInput($_GET['action']) . "')";
$action = nullable_htmlentities($_GET['action']);
$action_filter = nullable_htmlentities($_GET['action']);
} else {
// Default - any
$log_action_query = '';
$action = '';
$action_filter = '';
}
//Rebuild URL
@ -87,7 +87,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
<div class="col-sm-2">
<div class="form-group">
<select class="form-control select2" name="client" onchange="this.form.submit()">
<option value="" <?php if ($client == "") { echo "selected"; } ?>>- All Clients -</option>
<option value="">- All Clients -</option>
<?php
$sql_clients_filter = mysqli_query($mysqli, "SELECT * FROM clients ORDER BY client_name ASC");
@ -95,7 +95,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
$client_id = intval($row['client_id']);
$client_name = nullable_htmlentities($row['client_name']);
?>
<option <?php if ($client == $client_id) { echo "selected"; } ?> value="<?php echo $client_id; ?>"><?php echo $client_name; ?></option>
<option <?php if ($client_filter == $client_id) { echo "selected"; } ?> value="<?php echo $client_id; ?>"><?php echo $client_name; ?></option>
<?php
}
?>
@ -107,7 +107,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
<div class="col-sm-2">
<div class="form-group">
<select class="form-control select2" name="user" onchange="this.form.submit()">
<option value="" <?php if ($user == "") { echo "selected"; } ?>>- All Users -</option>
<option value="">- All Users -</option>
<?php
$sql_users_filter = mysqli_query($mysqli, "SELECT * FROM users ORDER BY user_name ASC");
@ -115,7 +115,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
$user_id = intval($row['user_id']);
$user_name = nullable_htmlentities($row['user_name']);
?>
<option <?php if ($user == $user_id) { echo "selected"; } ?> value="<?php echo $user_id; ?>"><?php echo $user_name; ?></option>
<option <?php if ($user_filter == $user_id) { echo "selected"; } ?> value="<?php echo $user_id; ?>"><?php echo $user_name; ?></option>
<?php
}
?>
@ -127,14 +127,14 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
<div class="col-sm-2">
<div class="form-group">
<select class="form-control select2" name="type" onchange="this.form.submit()">
<option value="" <?php if ($type == "") { echo "selected"; } ?>>- All Types -</option>
<option value="">- All Types -</option>
<?php
$sql_types_filter = mysqli_query($mysqli, "SELECT DISTINCT log_type FROM logs ORDER BY log_type ASC");
while ($row = mysqli_fetch_array($sql_types_filter)) {
$log_type = nullable_htmlentities($row['log_type']);
?>
<option <?php if ($type == $log_type) { echo "selected"; } ?>><?php echo $log_type; ?></option>
<option <?php if ($type_filter == $log_type) { echo "selected"; } ?>><?php echo $log_type; ?></option>
<?php
}
?>
@ -146,14 +146,14 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
<div class="col-sm-2">
<div class="form-group">
<select class="form-control select2" name="action" onchange="this.form.submit()">
<option value="" <?php if ($action == "") { echo "selected"; } ?>>- All Actions -</option>
<option value="">- All Actions -</option>
<?php
$sql_actions_filter = mysqli_query($mysqli, "SELECT DISTINCT log_action FROM logs ORDER BY log_action ASC");
while ($row = mysqli_fetch_array($sql_actions_filter)) {
$log_action = nullable_htmlentities($row['log_action']);
?>
<option <?php if ($action == $log_action) { echo "selected"; } ?>><?php echo $log_action; ?></option>
<option <?php if ($action_filter == $log_action) { echo "selected"; } ?>><?php echo $log_action; ?></option>
<?php
}
?>

View File

@ -28,11 +28,11 @@ if (isset($_GET['type']) && ($_GET['type']) == 'workstation') {
// Location Filter
if (isset($_GET['location']) & !empty($_GET['location'])) {
$location_query = 'AND (asset_location_id = ' . intval($_GET['location']) . ')';
$location = intval($_GET['location']);
$location_filter = intval($_GET['location']);
} else {
// Default - any
$location_query = '';
$location = '';
$location_filter = '';
}
//Get Asset Counts
@ -159,7 +159,7 @@ if (mysqli_num_rows($os_sql) > 0) {
<div class="col-md-2">
<div class="input-group">
<select class="form-control select2" name="location" onchange="this.form.submit()">
<option value="" <?php if ($location == "") { echo "selected"; } ?>>- All Locations -</option>
<option value="">- All Locations -</option>
<?php
$sql_locations_filter = mysqli_query($mysqli, "SELECT * FROM locations WHERE location_client_id = $client_id AND location_archived_at IS NULL ORDER BY location_name ASC");
@ -167,7 +167,7 @@ if (mysqli_num_rows($os_sql) > 0) {
$location_id = intval($row['location_id']);
$location_name = nullable_htmlentities($row['location_name']);
?>
<option <?php if ($location == $location_id) { echo "selected"; } ?> value="<?php echo $location_id; ?>"><?php echo $location_name; ?></option>
<option <?php if ($location_filter == $location_id) { echo "selected"; } ?> value="<?php echo $location_id; ?>"><?php echo $location_name; ?></option>
<?php
}
?>

View File

@ -110,7 +110,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
<div class="col-md-2">
<div class="input-group">
<select class="form-control select2" name="location" onchange="this.form.submit()">
<option value="" <?php if ($location_filter == "") { echo "selected"; } ?>>- All Locations -</option>
<option value="">- All Locations -</option>
<?php
$sql_locations_filter = mysqli_query($mysqli, "SELECT * FROM locations WHERE location_client_id = $client_id AND location_archived_at IS NULL ORDER BY location_name ASC");

View File

@ -32,12 +32,12 @@ if (isset($_GET['tags']) && is_array($_GET['tags']) && !empty($_GET['tags'])) {
if (isset($_GET['location']) & !empty($_GET['location'])) {
$location_query = 'AND (a.asset_location_id = ' . intval($_GET['location']) . ')';
$location_query_innerjoin = 'INNER JOIN assets a on a.asset_id = l.login_asset_id ';
$location = intval($_GET['location']);
$location_filter = intval($_GET['location']);
} else {
// Default - any
$location_query_innerjoin = '';
$location_query = '';
$location = '';
$location_filter = '';
}
@ -106,7 +106,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
<div class="col-md-2">
<div class="input-group">
<select class="form-control select2" name="location" onchange="this.form.submit()">
<option value="" <?php if ($location == "") { echo "selected"; } ?>>- All Asset Locations -</option>
<option value="">- All Asset Locations -</option>
<?php
$sql_locations_filter = mysqli_query($mysqli, "SELECT * FROM locations WHERE location_client_id = $client_id AND location_archived_at IS NULL ORDER BY location_name ASC");
@ -114,7 +114,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
$location_id = intval($row['location_id']);
$location_name = nullable_htmlentities($row['location_name']);
?>
<option <?php if ($location == $location_id) { echo "selected"; } ?> value="<?php echo $location_id; ?>"><?php echo $location_name; ?></option>
<option <?php if ($location_filter == $location_id) { echo "selected"; } ?> value="<?php echo $location_id; ?>"><?php echo $location_name; ?></option>
<?php
}
?>

View File

@ -207,7 +207,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
<div class="form-group">
<label>Industry</label>
<select class="form-control select2" name="industry" onchange="this.form.submit()">
<option value="" <?php if ($industry_filter == "") { echo "selected"; } ?>>- All Industries -</option>
<option value="">- All Industries -</option>
<?php
$sql_industries_filter = mysqli_query($mysqli, "SELECT DISTINCT client_type FROM clients WHERE client_archived_at IS NULL AND client_type != '' ORDER BY client_type ASC");
@ -226,7 +226,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
<div class="form-group">
<label>Referral</label>
<select class="form-control select2" name="referral" onchange="this.form.submit()">
<option value="" <?php if ($referral_filter == "") { echo "selected"; } ?>>- All Referrals -</option>
<option value="">- All Referrals -</option>
<?php
$sql_referrals_filter = mysqli_query($mysqli, "SELECT DISTINCT client_referral FROM clients WHERE client_archived_at IS NULL AND client_referral != '' ORDER BY client_referral ASC");

View File

@ -25,29 +25,20 @@ if (isset($_GET['page'])) {
}
// Order
if (isset($_GET['order'])) {
if ($_GET['order'] == 'ASC') {
$order = "ASC";
$disp = "DESC";
} else {
$order = "DESC";
$disp = "ASC";
}
} elseif(isset($order)) {
if ($order == "ASC") {
$disp = "DESC";
} else {
$disp = "ASC";
}
if (isset($_GET['order']) && $_GET['order'] == 'ASC') {
$order = "ASC";
$disp = "DESC";
} else {
$order = "DESC";
$disp = "ASC";
}
// Set the order Icon
if (isset($sort)) {
if ($order == "ASC") {
$order_icon = "<i class='fas fa-sort-up'></i>";
} else {
$order_icon = "<i class='fas fa-sort-down'></i>";
}
if(isset($order) && $order == "ASC") {
$disp = "DESC";
$order_icon = "<i class='fas fa-sort-down'></i>";
} else {
$disp = "ASC";
$order_icon = "<i class='fas fa-sort-up'></i>";
}
// Search
@ -109,15 +100,10 @@ if ($_GET['canned_date'] == "custom" && !empty($_GET['dtf'])) {
}
// Archived
$archived = 0;
if (isset($_GET['archived'])) {
$archived = intval($_GET['archived']);
}
if ($archived == 1){
if (isset($_GET['archived']) && $_GET['archived'] == 1) {
$archived = 1;
$archive_query = "archived_at IS NOT NULL";
} else {
$archived = 0;
$archive_query = "archived_at IS NULL";
}

View File

@ -2,7 +2,7 @@
// Default Column Sortby/Order Filter
$sort = "invoice_number";
$order = "DESC";
$order = "ASC";
require_once "includes/inc_all.php";

View File

@ -12,21 +12,21 @@ enforceUserPermission('module_financial');
// Payment Method Filter
if (isset($_GET['method']) & !empty($_GET['method'])) {
$payment_method_query = "AND (payment_method = '" . sanitizeInput($_GET['method']) . "')";
$method = nullable_htmlentities($_GET['method']);
$method_filter = nullable_htmlentities($_GET['method']);
} else {
// Default - any
$payment_method_query = '';
$method = '';
$method_filter = '';
}
// Account Filter
if (isset($_GET['account']) & !empty($_GET['account'])) {
$account_query = 'AND (payment_account_id = ' . intval($_GET['account']) . ')';
$account = intval($_GET['account']);
$account_filter = intval($_GET['account']);
} else {
// Default - any
$account_query = '';
$account = '';
$account_filter = '';
}
//Rebuild URL
@ -69,7 +69,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
<div class="col-md-2">
<div class="form-group">
<select class="form-control select2" name="account" onchange="this.form.submit()">
<option value="" <?php if ($account == "") { echo "selected"; } ?>>- All Accounts -</option>
<option value="">- All Accounts -</option>
<?php
$sql_accounts_filter = mysqli_query($mysqli, "SELECT * FROM accounts WHERE account_archived_at IS NULL ORDER BY account_name ASC");
@ -77,7 +77,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
$account_id = intval($row['account_id']);
$account_name = nullable_htmlentities($row['account_name']);
?>
<option <?php if ($account == $account_id) { echo "selected"; } ?> value="<?php echo $account_id; ?>"><?php echo $account_name; ?></option>
<option <?php if ($account_filter == $account_id) { echo "selected"; } ?> value="<?php echo $account_id; ?>"><?php echo $account_name; ?></option>
<?php
}
?>
@ -89,14 +89,14 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
<div class="col-sm-2">
<div class="form-group">
<select class="form-control select2" name="method" onchange="this.form.submit()">
<option value="" <?php if ($method == "") { echo "selected"; } ?>>- All Payment Methods -</option>
<option value="">- All Payment Methods -</option>
<?php
$sql_payment_methods_filter = mysqli_query($mysqli, "SELECT DISTINCT payment_method FROM payments ORDER BY payment_method ASC");
while ($row = mysqli_fetch_array($sql_payment_methods_filter)) {
$payment_method = nullable_htmlentities($row['payment_method']);
?>
<option <?php if ($method == $payment_method) { echo "selected"; } ?>><?php echo $payment_method; ?></option>
<option <?php if ($method_filter == $payment_method) { echo "selected"; } ?>><?php echo $payment_method; ?></option>
<?php
}
?>

View File

@ -12,11 +12,11 @@ enforceUserPermission('module_sales');
// Category Filter
if (isset($_GET['category']) & !empty($_GET['category'])) {
$category_query = 'AND (category_id = ' . intval($_GET['category']) . ')';
$category = intval($_GET['category']);
$category_filter = intval($_GET['category']);
} else {
// Default - any
$category_query = '';
$category = '';
$category_filter = '';
}
//Rebuild URL
@ -70,7 +70,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
<div class="col-sm-2">
<div class="form-group">
<select class="form-control select2" name="category" onchange="this.form.submit()">
<option value="" <?php if ($category == "") { echo "selected"; } ?>>- All Categories -</option>
<option value="">- All Categories -</option>
<?php
$sql_categories_filter = mysqli_query($mysqli, "SELECT * FROM categories WHERE category_type = 'Income' ORDER BY category_name ASC");
@ -78,7 +78,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
$category_id = intval($row['category_id']);
$category_name = nullable_htmlentities($row['category_name']);
?>
<option <?php if ($category == $category_id) { echo "selected"; } ?> value="<?php echo $category_id; ?>"><?php echo $category_name; ?></option>
<option <?php if ($category_filter == $category_id) { echo "selected"; } ?> value="<?php echo $category_id; ?>"><?php echo $category_name; ?></option>
<?php
}
?>

View File

@ -11,21 +11,21 @@ enforceUserPermission('module_financial');
// Account Transfer From Filter
if (isset($_GET['account_from']) & !empty($_GET['account_from'])) {
$account_from_query = 'AND (expense_account_id = ' . intval($_GET['account_from']) . ')';
$account_from = intval($_GET['account_from']);
$account_from_filter = intval($_GET['account_from']);
} else {
// Default - any
$account_from_query = '';
$account_from = '';
$account_from_filter = '';
}
// Account Transfer To Filter
if (isset($_GET['account_to']) & !empty($_GET['account_to'])) {
$account_to_query = 'AND (revenue_account_id = ' . intval($_GET['account_to']) . ')';
$account_to = intval($_GET['account_to']);
$account_to_filter = intval($_GET['account_to']);
} else {
// Default - any
$account_to_query = '';
$account_to = '';
$account_to_filter = '';
}
@ -69,7 +69,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
</div>
</div>
</div>
<div class="collapse mt-3 <?php if (!empty($_GET['dtf']) || $_GET['canned_date'] !== "custom" || isset($_GET['account_from']) || isset($_GET['account_to']) ) { echo "show"; } ?>" id="advancedFilter">
<div class="collapse mt-3 <?php if (!empty($_GET['dtf']) || $_GET['canned_date'] !== "custom" || $account_from_filter || $account_to_filter ) { echo "show"; } ?>" id="advancedFilter">
<div class="row">
<div class="col-md-2">
<div class="form-group">
@ -103,7 +103,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
<div class="form-group">
<label>Account From</label>
<select class="form-control select2" name="account_from" onchange="this.form.submit()">
<option value="" <?php if ($account_from == "") { echo "selected"; } ?>>- All Accounts -</option>
<option value="">- All Accounts -</option>
<?php
$sql_accounts_from_filter = mysqli_query($mysqli, "SELECT * FROM accounts WHERE account_archived_at IS NULL ORDER BY account_name ASC");
@ -111,7 +111,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
$account_id = intval($row['account_id']);
$account_name = nullable_htmlentities($row['account_name']);
?>
<option <?php if ($account_from == $account_id) { echo "selected"; } ?> value="<?php echo $account_id; ?>"><?php echo $account_name; ?></option>
<option <?php if ($account_from_filter == $account_id) { echo "selected"; } ?> value="<?php echo $account_id; ?>"><?php echo $account_name; ?></option>
<?php
}
?>
@ -123,7 +123,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
<div class="form-group">
<label>Account To</label>
<select class="form-control select2" name="account_to" onchange="this.form.submit()">
<option value="" <?php if ($account_to == "") { echo "selected"; } ?>>- All Accounts -</option>
<option value="">- All Accounts -</option>
<?php
$sql_accounts_to_filter = mysqli_query($mysqli, "SELECT * FROM accounts WHERE account_archived_at IS NULL ORDER BY account_name ASC");
@ -131,7 +131,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
$account_id = intval($row['account_id']);
$account_name = nullable_htmlentities($row['account_name']);
?>
<option <?php if ($account_to == $account_id) { echo "selected"; } ?> value="<?php echo $account_id; ?>"><?php echo $account_name; ?></option>
<option <?php if ($account_to_filter == $account_id) { echo "selected"; } ?> value="<?php echo $account_id; ?>"><?php echo $account_name; ?></option>
<?php
}
?>