Skip to content

Commit

Permalink
Merged Client Trip and Global Trips along with exports into 1 managab…
Browse files Browse the repository at this point in the history
…le file
  • Loading branch information
johnnyq committed Feb 19, 2025
1 parent 1dee1b4 commit f8e4163
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 273 deletions.
2 changes: 1 addition & 1 deletion ajax/ajax_trip_copy.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
$trip_created_at = nullable_htmlentities($row['trip_created_at']);
$trip_archived_at = nullable_htmlentities($row['trip_archived_at']);
$round_trip = nullable_htmlentities($row['round_trip']);
$client_id = intval($row['client_id']);
$client_id = intval($row['trip_client_id']);

// Generate the HTML form content using output buffering.
ob_start();
Expand Down
2 changes: 1 addition & 1 deletion ajax/ajax_trip_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
$trip_created_at = nullable_htmlentities($row['trip_created_at']);
$trip_archived_at = nullable_htmlentities($row['trip_archived_at']);
$round_trip = nullable_htmlentities($row['round_trip']);
$client_id = intval($row['client_id']);
$client_id = intval($row['trip_client_id']);

// Generate the HTML form content using output buffering.
ob_start();
Expand Down
195 changes: 0 additions & 195 deletions client_trips.php

This file was deleted.

2 changes: 1 addition & 1 deletion includes/client_side_nav.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@
<?php } ?>

<li class="nav-item">
<a href="client_trips.php?client_id=<?php echo $client_id; ?>" class="nav-link <?php if (basename($_SERVER["PHP_SELF"]) == "client_trips.php") { echo "active"; } ?>">
<a href="trips.php?client_id=<?php echo $client_id; ?>" class="nav-link <?php if (basename($_SERVER["PHP_SELF"]) == "trips.php") { echo "active"; } ?>">
<i class="nav-icon fas fa-route"></i>
<p>
Trips
Expand Down
22 changes: 0 additions & 22 deletions modals/client_trip_export_modal.php

This file was deleted.

3 changes: 3 additions & 0 deletions modals/trip_export_modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
</button>
</div>
<form action="post.php" method="post" autocomplete="off">
<?php if (isset($_GET['client_id'])) { ?>
<input type="hidden" name="client_id" value="<?php echo $client_id; ?>">
<?php } ?>
<div class="modal-body bg-white">

<div class="form-group">
Expand Down
55 changes: 8 additions & 47 deletions post/user/trip.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@
}

if (isset($_POST['export_trips_csv'])) {

if (isset($_POST['client_id'])) {
$client_id = intval($_POST['client_id']);
$client_query = "AND trip_client_id = $client_id";
} else {
$client_query = '';
}

$date_from = sanitizeInput($_POST['date_from']);
$date_to = sanitizeInput($_POST['date_to']);
Expand All @@ -79,6 +86,7 @@
$sql = mysqli_query($mysqli,"SELECT * FROM trips
LEFT JOIN clients ON trip_client_id = client_id
WHERE $date_query
$client_query
ORDER BY trip_date DESC"
);

Expand Down Expand Up @@ -117,50 +125,3 @@
exit;

}

if (isset($_POST['export_client_trips_csv'])) {
$client_id = intval($_POST['client_id']);

//get records from database
$sql = mysqli_query($mysqli,"SELECT client_name FROM clients WHERE client_id = $client_id");
$row = mysqli_fetch_array($sql);

$client_name = sanitizeInput($row['client_name']);

$sql = mysqli_query($mysqli,"SELECT * FROM trips WHERE trip_client_id = $client_id ORDER BY trip_date ASC");

$count = mysqli_num_rows($sql);

if ($count > 0) {
$delimiter = ",";
$filename = $row['client_name'] . "-Trips-" . date('Y-m-d') . ".csv";

//create a file pointer
$f = fopen('php://memory', 'w');

//set column headers
$fields = array('Date', 'Purpose', 'Source', 'Destination', 'Miles');
fputcsv($f, $fields, $delimiter);

//output each row of the data, format line as csv and write to file pointer
while($row = $sql->fetch_assoc()){
$lineData = array($row['trip_date'], $row['trip_purpose'], $row['trip_source'], $row['trip_destination'], $row['trip_miles']);
fputcsv($f, $lineData, $delimiter);
}

//move back to beginning of file
fseek($f, 0);

//set headers to download file rather than displayed
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="' . $filename . '";');

//output all remaining data on a file pointer
fpassthru($f);

// Logging
logAction("Trip", "Export", "$session_name exported $count trip(s) to a CSV file for client $client_name", $client_id);
}
exit;

}
Loading

0 comments on commit f8e4163

Please sign in to comment.