Skip to content

Commit

Permalink
Dedup More Pagination code you now only have to define Sortby column …
Browse files Browse the repository at this point in the history
…and its order, also fixed issue when searching by date it would close on the first query
  • Loading branch information
johnnyq committed Feb 25, 2023
1 parent 704c8e4 commit 6f0017d
Show file tree
Hide file tree
Showing 42 changed files with 284 additions and 973 deletions.
10 changes: 4 additions & 6 deletions accounts.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<?php

require_once("inc_all.php");
// Default Column Sortby Filter
$sb = "account_name";
$o = "ASC";

if (!empty($_GET['sb'])) {
$sb = sanitizeInput($_GET['sb']);
} else {
$sb = "account_name";
}
require_once("inc_all.php");

//Rebuild URL
$url_query_strings_sb = http_build_query(array_merge($_GET, array('sb' => $sb, 'o' => $o)));
Expand Down
10 changes: 4 additions & 6 deletions categories.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

// Default Column Sortby Filter
$sb = "category_name";
$o = "ASC";

require_once("inc_all_settings.php");

if (isset($_GET['category'])) {
Expand All @@ -8,12 +12,6 @@
$category = "Expense";
}

if (!empty($_GET['sb'])) {
$sb = sanitizeInput($_GET['sb']);
} else {
$sb = "category_name";
}

//Rebuild URL
$url_query_strings_sb = http_build_query(array_merge($_GET, array('sb' => $sb, 'o' => $o)));

Expand Down
11 changes: 5 additions & 6 deletions client_assets.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php

// Default Column Sortby Filter
$sb = "asset_name";
$o = "ASC";

require_once("inc_all_client.php");

//Get Asset Counts
Expand Down Expand Up @@ -30,12 +35,6 @@
AND asset_archived_at IS NULL AND asset_client_id = $client_id"));
$other_count = intval($row['count']);

if (!empty($_GET['sb'])) {
$sb = sanitizeInput($_GET['sb']);
} else {
$sb = "asset_name";
}

//Asset Type from GET
if (isset($_GET['type']) && ($_GET['type']) == 'workstation') {
$type_query = "asset_type = 'desktop' OR asset_type = 'laptop'";
Expand Down
11 changes: 5 additions & 6 deletions client_certificates.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php
require_once("inc_all_client.php");

if (!empty($_GET['sb'])) {
$sb = sanitizeInput($_GET['sb']);
} else {
$sb = "certificate_name";
}
// Default Column Sortby Filter
$sb = "certificate_name";
$o = "ASC";

require_once("inc_all_client.php");

//Rebuild URL
$url_query_strings_sb = http_build_query(array_merge($_GET, array('sb' => $sb, 'o' => $o)));
Expand Down
23 changes: 4 additions & 19 deletions client_contacts.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
<?php

require_once("inc_all_client.php");
// Default Column Sortby Filter
$sb = "contact_name";
$o = "ASC";

if (isset($_GET['q'])) {
$q = sanitizeInput($_GET['q']);
//Phone Numbers
$n = preg_replace("/[^0-9]/", '', $q);
if (empty($n)) {
$n = $q;
}
} else {
$q = "";
//Phone Numbers
$n = "";
}

if (!empty($_GET['sb'])) {
$sb = sanitizeInput($_GET['sb']);
} else {
$sb = "contact_name";
}
require_once("inc_all_client.php");

//Rebuild URL
$url_query_strings_sb = http_build_query(array_merge($_GET, array('sb' => $sb, 'o' => $o)));
Expand Down
11 changes: 4 additions & 7 deletions client_documents.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

// Default Column Sortby Filter
$sb = "document_name";
$o = "ASC";

require_once("inc_all_client.php");

// Folder
Expand All @@ -9,13 +13,6 @@
$folder = 0;
}

// Sort by
if (!empty($_GET['sb'])) {
$sb = sanitizeInput($_GET['sb']);
} else {
$sb = "document_name";
}

// Search query SQL snippet
if (!empty($q)) {
$query_snippet = "AND (MATCH(document_content_raw) AGAINST ('$q') OR document_name LIKE '%$q%')";
Expand Down
10 changes: 4 additions & 6 deletions client_domains.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<?php

require_once("inc_all_client.php");
// Default Column Sortby Filter
$sb = "domain_name";
$o = "ASC";

if (!empty($_GET['sb'])) {
$sb = sanitizeInput($_GET['sb']);
} else {
$sb = "domain_name";
}
require_once("inc_all_client.php");

//Rebuild URL
$url_query_strings_sb = http_build_query(array_merge($_GET, array('sb' => $sb, 'o' => $o)));
Expand Down
17 changes: 5 additions & 12 deletions client_invoices.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
<?php
require_once("inc_all_client.php");

if (!empty($_GET['sb'])) {
$sb = sanitizeInput($_GET['sb']);
} else {
$sb = "invoice_number";
}

// Reverse default sort
if (!isset($_GET['o'])) {
$o = "DESC";
$disp = "ASC";
}
// Default Column Sortby Filter
$sb = "invoice_number";
$o = "DESC";

require_once("inc_all_client.php");

//Rebuild URL
$url_query_strings_sb = http_build_query(array_merge($_GET, array('sb' => $sb, 'o' => $o)));
Expand Down
25 changes: 6 additions & 19 deletions client_locations.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
<?php

require_once("inc_all_client.php");
// Default Column Sortby Filter
$sb = "location_name";
$o = "ASC";

if (isset($_GET['q'])) {
$q = sanitizeInput($_GET['q']);
//Phone Numbers
$phone_query = preg_replace("/[^0-9]/", '', $q);
if (empty($phone_query)) {
$phone_query = $q;
}
} else {
$q = "";
$phone_query = "";
}

if (!empty($_GET['sb'])) {
$sb = sanitizeInput($_GET['sb']);
} else {
$sb = "location_name";
}
require_once("inc_all_client.php");

//Rebuild URL
$url_query_strings_sb = http_build_query(array_merge($_GET, array('sb' => $sb, 'o' => $o)));
Expand All @@ -29,7 +15,8 @@
WHERE location_client_id = $client_id
AND location_archived_at IS NULL
AND (location_name LIKE '%$q%' OR location_address LIKE '%$q%' OR location_phone LIKE '%$phone_query%')
ORDER BY $sb $o LIMIT $record_from, $record_to");
ORDER BY $sb $o LIMIT $record_from, $record_to"
);

$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));

Expand Down
17 changes: 5 additions & 12 deletions client_logs.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
<?php
require_once("inc_all_client.php");

if (!empty($_GET['sb'])) {
$sb = sanitizeInput($_GET['sb']);
} else {
$sb = "log_id";
}

// Reverse default sort
if (!isset($_GET['o'])) {
$o = "DESC";
$disp = "ASC";
}
// Default Column Sortby Filter
$sb = "log_id";
$o = "DESC";

require_once("inc_all_client.php");

//Rebuild URL
$url_query_strings_sb = http_build_query(array_merge($_GET, array('sb' => $sb, 'o' => $o)));
Expand Down
11 changes: 5 additions & 6 deletions client_networks.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php
require_once("inc_all_client.php");

if (!empty($_GET['sb'])) {
$sb = sanitizeInput($_GET['sb']);
} else {
$sb = "network_name";
}
// Default Column Sortby Filter
$sb = "network_name";
$o = "ASC";

require_once("inc_all_client.php");

//Rebuild URL
$url_query_strings_sb = http_build_query(array_merge($_GET, array('sb' => $sb, 'o' => $o)));
Expand Down
17 changes: 5 additions & 12 deletions client_payments.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
<?php
require_once("inc_all_client.php");

if (!empty($_GET['sb'])) {
$sb = sanitizeInput($_GET['sb']);
} else {
$sb = "payment_date";
}

// Reverse default sort
if (!isset($_GET['o'])) {
$o = "DESC";
$disp = "ASC";
}
// Default Column Sortby Filter
$sb = "payment_date";
$o = "DESC";

require_once("inc_all_client.php");

//Rebuild URL
$url_query_strings_sb = http_build_query(array_merge($_GET, array('sb' => $sb, 'o' => $o)));
Expand Down
16 changes: 4 additions & 12 deletions client_quotes.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
<?php

require_once("inc_all_client.php");
// Default Column Sortby Filter
$sb = "quote_number";
$o = "DESC";

if (!empty($_GET['sb'])) {
$sb = sanitizeInput($_GET['sb']);
} else {
$sb = "quote_number";
}

// Reverse default sort
if (!isset($_GET['o'])) {
$o = "DESC";
$disp = "ASC";
}
require_once("inc_all_client.php");

//Rebuild URL
$url_query_strings_sb = http_build_query(array_merge($_GET, array('sb' => $sb, 'o' => $o)));
Expand Down
10 changes: 4 additions & 6 deletions client_recurring_invoices.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<?php

require_once("inc_all_client.php");
// Default Column Sortby Filter
$sb = "recurring_last_sent";
$o = "DESC";

if (!empty($_GET['sb'])) {
$sb = sanitizeInput($_GET['sb']);
} else {
$sb = "recurring_id";
}
require_once("inc_all_client.php");

//Rebuild URL
$url_query_strings_sb = http_build_query(array_merge($_GET, array('sb' => $sb, 'o' => $o)));
Expand Down
10 changes: 4 additions & 6 deletions client_services.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<?php

require_once("inc_all_client.php");
// Default Column Sortby Filter
$sb = "service_name";
$o = "ASC";

if (!empty($_GET['sb'])) {
$sb = sanitizeInput($_GET['sb']);
} else {
$sb = "service_name";
}
require_once("inc_all_client.php");

//Rebuild URL
$url_query_strings_sb = http_build_query(array_merge($_GET, array('sb' => $sb, 'o' => $o)));
Expand Down
20 changes: 5 additions & 15 deletions client_shared_items.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
<?php
require_once("inc_all_client.php");

if (isset($_GET['q'])) {
$q = sanitizeInput($_GET['q']);
//Phone Numbers
$phone_query = preg_replace("/[^0-9]/", '', $q);
if (empty($phone_query)) {
$phone_query = $q;
}
} else {
$q = "";
$phone_query = "";
}

// Sort
// Default Column Sortby Filter
$sb = "item_created_at";
$o = "DESC";

require_once("inc_all_client.php");

//Rebuild URL
$url_query_strings_sb = http_build_query(array_merge($_GET, array('sb' => $sb, 'o' => $o)));
Expand Down Expand Up @@ -44,7 +34,7 @@

<div class="col-md-4">
<div class="input-group mb-3 mb-md-0">
<input type="search" class="form-control" name="q" value="<?php if (isset($q)) { echo strip_tags(htmlentities($q)); } ?>" placeholder="Search Shared Items">
<input type="search" class="form-control" name="q" value="<?php if (isset($q)) { echo stripslashes(htmlentities($q)); } ?>" placeholder="Search Shared Items">
<div class="input-group-append">
<button class="btn btn-dark"><i class="fa fa-search"></i></button>
</div>
Expand Down
11 changes: 5 additions & 6 deletions client_software.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php
require_once("inc_all_client.php");

if (!empty($_GET['sb'])) {
$sb = sanitizeInput($_GET['sb']);
} else {
$sb = "software_name";
}
// Default Column Sortby Filter
$sb = "software_name";
$o = "ASC";

require_once("inc_all_client.php");

//Rebuild URL
$url_query_strings_sb = http_build_query(array_merge($_GET, array('sb' => $sb, 'o' => $o)));
Expand Down
Loading

0 comments on commit 6f0017d

Please sign in to comment.