Skip to content

Commit

Permalink
Code deduplication/tidying
Browse files Browse the repository at this point in the history
- Move default pagination/sort/search query variable mapping to pagination_head.php
- Remove user_logs.php
  • Loading branch information
wrongecho committed Apr 14, 2022
1 parent ca62980 commit b4f2fdd
Show file tree
Hide file tree
Showing 50 changed files with 92 additions and 1,359 deletions.
56 changes: 12 additions & 44 deletions accounts.php
Original file line number Diff line number Diff line change
@@ -1,51 +1,19 @@
<?php include("inc_all.php"); ?>
<?php include("inc_all.php");

<?php

//Paging
if(isset($_GET['p'])){
$p = intval($_GET['p']);
$record_from = (($p)-1)*$_SESSION['records_per_page'];
$record_to = $_SESSION['records_per_page'];
}else{
$record_from = 0;
$record_to = $_SESSION['records_per_page'];
$p = 1;
}

if(isset($_GET['q'])){
$q = mysqli_real_escape_string($mysqli,$_GET['q']);
}else{
$q = "";
}

if(!empty($_GET['sb'])){
$sb = mysqli_real_escape_string($mysqli,$_GET['sb']);
}else{
$sb = "account_name";
}

if(isset($_GET['o'])){
if($_GET['o'] == 'ASC'){
$o = "ASC";
$disp = "DESC";
}else{
$o = "DESC";
$disp = "ASC";
}
}else{
$o = "ASC";
$disp = "DESC";
}
if(!empty($_GET['sb'])){
$sb = mysqli_real_escape_string($mysqli,$_GET['sb']);
}else{
$sb = "account_name";
}

//Rebuild URL
$url_query_strings_sb = http_build_query(array_merge($_GET,array('sb' => $sb, 'o' => $o)));
//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 accounts
WHERE account_name LIKE '%$q%' AND company_id = $session_company_id
ORDER BY $sb $o LIMIT $record_from, $record_to");
$sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM accounts
WHERE account_name LIKE '%$q%' AND company_id = $session_company_id
ORDER BY $sb $o LIMIT $record_from, $record_to");

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

?>

Expand Down
32 changes: 0 additions & 32 deletions assets.php
Original file line number Diff line number Diff line change
@@ -1,44 +1,12 @@
<?php include("inc_all.php");

//Paging
if(isset($_GET['p'])){
$p = intval($_GET['p']);
$record_from = (($p)-1)*$_SESSION['records_per_page'];
$record_to = $_SESSION['records_per_page'];
}else{
$record_from = 0;
$record_to = $_SESSION['records_per_page'];
$p = 1;
}

//Custom Query Filter
if(isset($_GET['q'])){
$q = mysqli_real_escape_string($mysqli,$_GET['q']);
}else{
$q = "";
}

//Column Filter
if(!empty($_GET['sb'])){
$sb = mysqli_real_escape_string($mysqli,$_GET['sb']);
}else{
$sb = "asset_name";
}

//Column Order Filter
if(isset($_GET['o'])){
if($_GET['o'] == 'ASC'){
$o = "ASC";
$disp = "DESC";
}else{
$o = "DESC";
$disp = "ASC";
}
}else{
$o = "ASC";
$disp = "DESC";
}

//Date From and Date To Filter
if(!empty($_GET['dtf'])){
$dtf = mysqli_real_escape_string($mysqli,$_GET['dtf']);
Expand Down
40 changes: 5 additions & 35 deletions campaigns.php
Original file line number Diff line number Diff line change
@@ -1,41 +1,11 @@
<?php include("inc_all.php");

//Paging
if(isset($_GET['p'])){
$p = intval($_GET['p']);
$record_from = (($p)-1)*$_SESSION['records_per_page'];
$record_to = $_SESSION['records_per_page'];
}else{
$record_from = 0;
$record_to = $_SESSION['records_per_page'];
$p = 1;
}

if(isset($_GET['q'])){
$q = mysqli_real_escape_string($mysqli,$_GET['q']);
}else{
$q = "";
}

if(!empty($_GET['sb'])){
$sb = mysqli_real_escape_string($mysqli,$_GET['sb']);
}else{
$sb = "campaign_created_at";
}

if(isset($_GET['o'])){
if($_GET['o'] == 'ASC'){
$o = "ASC";
$disp = "DESC";
}else{
$o = "DESC";
$disp = "ASC";
}
}else{
$o = "DESC";
$disp = "ASC";
}

if(empty($_GET['canned_date'])){
//Prevents lots of undefined variable errors.
// $dtf and $dtt will be set by the below else to 0000-00-00 / 9999-00-00
Expand Down Expand Up @@ -69,7 +39,7 @@
$dtt = date('Y-m-d');
}elseif($_GET['canned_date'] == "lastyear"){
$dtf = date('Y-m-d',strtotime("first day of january last year"));
$dtt = date('Y-m-d',strtotime("last day of december last year"));
$dtt = date('Y-m-d',strtotime("last day of december last year"));
}else{
$dtf = "0000-00-00";
$dtt = "9999-00-00";
Expand Down Expand Up @@ -149,7 +119,7 @@
<input type="date" class="form-control" name="dtt" value="<?php echo $dtt; ?>">
</div>
</div>
</div>
</div>
</div>
</form>
<hr>
Expand All @@ -170,7 +140,7 @@
</thead>
<tbody>
<?php

while($row = mysqli_fetch_array($sql)){
$campaign_id = $row['campaign_id'];
$campaign_name = $row['campaign_name'];
Expand Down Expand Up @@ -245,9 +215,9 @@
//include("campaign_copy_modal.php"); --doesnt exist yet
include("campaign_edit_modal.php");
include("campaign_test_modal.php");

}

?>

</tbody>
Expand Down
36 changes: 3 additions & 33 deletions categories.php
Original file line number Diff line number Diff line change
@@ -1,47 +1,17 @@
<?php include("inc_all_admin.php");

//Paging
if(isset($_GET['p'])){
$p = intval($_GET['p']);
$record_from = (($p)-1)*$_SESSION['records_per_page'];
$record_to = $_SESSION['records_per_page'];
if(isset($_GET['category'])){
$category = mysqli_real_escape_string($mysqli,$_GET['category']);
}else{
$record_from = 0;
$record_to = $_SESSION['records_per_page'];
$p = 1;
$category = "Expense";
}

if(isset($_GET['q'])){
$q = mysqli_real_escape_string($mysqli,$_GET['q']);
}else{
$q = "";
}

if(isset($_GET['category'])){
$category = mysqli_real_escape_string($mysqli,$_GET['category']);
}else{
$category = "Expense";
}

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

if(isset($_GET['o'])){
if($_GET['o'] == 'ASC'){
$o = "ASC";
$disp = "DESC";
}else{
$o = "DESC";
$disp = "ASC";
}
}else{
$o = "ASC";
$disp = "DESC";
}

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

Expand Down
30 changes: 0 additions & 30 deletions client_assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,42 +29,12 @@
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']);
$record_from = (($p)-1)*$_SESSION['records_per_page'];
$record_to = $_SESSION['records_per_page'];
}else{
$record_from = 0;
$record_to = $_SESSION['records_per_page'];
$p = 1;
}

if(isset($_GET['q'])){
$q = mysqli_real_escape_string($mysqli,$_GET['q']);
}else{
$q = "";
}

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

if(isset($_GET['o'])){
if($_GET['o'] == 'ASC'){
$o = "ASC";
$disp = "DESC";
}else{
$o = "DESC";
$disp = "ASC";
}
}else{
$o = "ASC";
$disp = "DESC";
}

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

//Paging
if(isset($_GET['p'])){
$p = intval($_GET['p']);
$record_from = (($p)-1)*$_SESSION['records_per_page'];
$record_to = $_SESSION['records_per_page'];
}else{
$record_from = 0;
$record_to = $_SESSION['records_per_page'];
$p = 1;
}

if(isset($_GET['q'])){
$q = mysqli_real_escape_string($mysqli,$_GET['q']);
}else{
$q = "";
}

if(!empty($_GET['sb'])){
$sb = mysqli_real_escape_string($mysqli,$_GET['sb']);
}else{
$sb = "certificate_name";
}

if(isset($_GET['o'])){
if($_GET['o'] == 'ASC'){
$o = "ASC";
$disp = "DESC";
}else{
$o = "DESC";
$disp = "ASC";
}
}else{
$o = "ASC";
$disp = "DESC";
}

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

Expand Down
25 changes: 0 additions & 25 deletions client_contacts.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
<?php

//Paging
if(isset($_GET['p'])){
$p = intval($_GET['p']);
$record_from = (($p)-1)*$_SESSION['records_per_page'];
$record_to = $_SESSION['records_per_page'];
}else{
$record_from = 0;
$record_to = $_SESSION['records_per_page'];
$p = 1;
}

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

}else{
$q = "";
//Phone Numbers
Expand All @@ -31,19 +19,6 @@
$sb = "contact_name";
}

if(isset($_GET['o'])){
if($_GET['o'] == 'ASC'){
$o = "ASC";
$disp = "DESC";
}else{
$o = "DESC";
$disp = "ASC";
}
}else{
$o = "ASC";
$disp = "DESC";
}

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

Expand Down
Loading

0 comments on commit b4f2fdd

Please sign in to comment.