From 9d095611fb4cdbbcb15b5419be0166c84bee9f59 Mon Sep 17 00:00:00 2001 From: "johnny@pittpc.com" Date: Tue, 2 Feb 2021 19:11:05 -0500 Subject: [PATCH] Renamed table field trip_starting_location to just trip_source added export trips as CSV in POST, new DB Dump --- add_trip_copy_modal.php | 2 +- add_trip_modal.php | 2 +- client_trips.php | 10 +- clients_new.php | 192 --------------------------- db.sql | 4 +- dist/img/AdminLTELogo.png | Bin 10380 -> 0 bytes dist/img/avatar.png | Bin 8543 -> 0 bytes dist/img/avatar04.png | Bin 14037 -> 0 bytes dist/img/avatar2.png | Bin 8836 -> 0 bytes dist/img/avatar3.png | Bin 9780 -> 0 bytes dist/img/avatar5.png | Bin 8007 -> 0 bytes dist/img/boxed-bg.jpg | Bin 123770 -> 0 bytes dist/img/boxed-bg.png | Bin 43694 -> 0 bytes dist/img/credit/american-express.png | Bin 2205 -> 0 bytes dist/img/credit/cirrus.png | Bin 1593 -> 0 bytes dist/img/credit/mastercard.png | Bin 1593 -> 0 bytes dist/img/credit/mestro.png | Bin 1588 -> 0 bytes dist/img/credit/paypal.png | Bin 2046 -> 0 bytes dist/img/credit/paypal2.png | Bin 1372 -> 0 bytes dist/img/credit/visa.png | Bin 1137 -> 0 bytes dist/img/default-150x150.png | Bin 373 -> 0 bytes dist/img/icons.png | Bin 1154 -> 0 bytes dist/img/photo1.png | Bin 673900 -> 0 bytes dist/img/photo2.png | Bin 424395 -> 0 bytes dist/img/photo3.jpg | Bin 392079 -> 0 bytes dist/img/photo4.jpg | Bin 1179224 -> 0 bytes dist/img/prod-1.jpg | Bin 48315 -> 0 bytes dist/img/prod-2.jpg | Bin 34222 -> 0 bytes dist/img/prod-3.jpg | Bin 21839 -> 0 bytes dist/img/prod-4.jpg | Bin 27963 -> 0 bytes dist/img/prod-5.jpg | Bin 33929 -> 0 bytes dist/img/user1-128x128.jpg | Bin 2879 -> 0 bytes dist/img/user2-160x160.jpg | Bin 7070 -> 0 bytes dist/img/user3-128x128.jpg | Bin 3511 -> 0 bytes dist/img/user4-128x128.jpg | Bin 3477 -> 0 bytes dist/img/user5-128x128.jpg | Bin 6446 -> 0 bytes dist/img/user6-128x128.jpg | Bin 4342 -> 0 bytes dist/img/user7-128x128.jpg | Bin 6434 -> 0 bytes dist/img/user8-128x128.jpg | Bin 5060 -> 0 bytes edit_trip_modal.php | 2 +- post.php | 43 +++++- test.php | 12 -- trips.php | 12 +- 43 files changed, 55 insertions(+), 224 deletions(-) delete mode 100644 clients_new.php delete mode 100644 dist/img/AdminLTELogo.png delete mode 100644 dist/img/avatar.png delete mode 100644 dist/img/avatar04.png delete mode 100644 dist/img/avatar2.png delete mode 100644 dist/img/avatar3.png delete mode 100644 dist/img/avatar5.png delete mode 100644 dist/img/boxed-bg.jpg delete mode 100644 dist/img/boxed-bg.png delete mode 100644 dist/img/credit/american-express.png delete mode 100644 dist/img/credit/cirrus.png delete mode 100644 dist/img/credit/mastercard.png delete mode 100644 dist/img/credit/mestro.png delete mode 100644 dist/img/credit/paypal.png delete mode 100644 dist/img/credit/paypal2.png delete mode 100644 dist/img/credit/visa.png delete mode 100644 dist/img/default-150x150.png delete mode 100644 dist/img/icons.png delete mode 100644 dist/img/photo1.png delete mode 100644 dist/img/photo2.png delete mode 100644 dist/img/photo3.jpg delete mode 100644 dist/img/photo4.jpg delete mode 100644 dist/img/prod-1.jpg delete mode 100644 dist/img/prod-2.jpg delete mode 100644 dist/img/prod-3.jpg delete mode 100644 dist/img/prod-4.jpg delete mode 100644 dist/img/prod-5.jpg delete mode 100644 dist/img/user1-128x128.jpg delete mode 100644 dist/img/user2-160x160.jpg delete mode 100644 dist/img/user3-128x128.jpg delete mode 100644 dist/img/user4-128x128.jpg delete mode 100644 dist/img/user5-128x128.jpg delete mode 100644 dist/img/user6-128x128.jpg delete mode 100644 dist/img/user7-128x128.jpg delete mode 100644 dist/img/user8-128x128.jpg delete mode 100644 test.php diff --git a/add_trip_copy_modal.php b/add_trip_copy_modal.php index 10d78567..d7dc18ff 100644 --- a/add_trip_copy_modal.php +++ b/add_trip_copy_modal.php @@ -55,7 +55,7 @@
- + diff --git a/add_trip_modal.php b/add_trip_modal.php index c1cc7156..72142765 100644 --- a/add_trip_modal.php +++ b/add_trip_modal.php @@ -51,7 +51,7 @@
- +
diff --git a/client_trips.php b/client_trips.php index 154f8c24..2ae322d1 100644 --- a/client_trips.php +++ b/client_trips.php @@ -50,7 +50,7 @@ if(isset($_GET['dtf'])){ } $sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM trips - WHERE (trip_purpose LIKE '%$q%' OR trip_starting_location LIKE '%$q%' OR trip_destination LIKE '%$q%') + WHERE (trip_purpose LIKE '%$q%' OR trip_source LIKE '%$q%' OR trip_destination LIKE '%$q%') AND DATE(trip_date) BETWEEN '$dtf' AND '$dtt' AND company_id = $session_company_id AND client_id = $client_id @@ -83,7 +83,7 @@ $total_pages = ceil($total_found_rows / 10); Date Purpose - From + From To Miles Action @@ -96,7 +96,7 @@ $total_pages = ceil($total_found_rows / 10); $trip_id = $row['trip_id']; $trip_date = $row['trip_date']; $trip_purpose = $row['trip_purpose']; - $trip_starting_location = $row['trip_starting_location']; + $trip_source = $row['trip_source']; $trip_destination = $row['trip_destination']; $trip_miles = $row['trip_miles']; $round_trip = $row['round_trip']; @@ -115,7 +115,7 @@ $total_pages = ceil($total_found_rows / 10); - + @@ -124,7 +124,7 @@ $total_pages = ceil($total_found_rows / 10);
diff --git a/post.php b/post.php index c41c32de..86528492 100644 --- a/post.php +++ b/post.php @@ -983,14 +983,14 @@ if(isset($_GET['delete_product'])){ if(isset($_POST['add_trip'])){ $date = strip_tags(mysqli_real_escape_string($mysqli,$_POST['date'])); - $starting_location = strip_tags(mysqli_real_escape_string($mysqli,$_POST['starting_location'])); + $source = strip_tags(mysqli_real_escape_string($mysqli,$_POST['source'])); $destination = strip_tags(mysqli_real_escape_string($mysqli,$_POST['destination'])); $miles = floatval($_POST['miles']); $roundtrip = intval($_POST['roundtrip']); $purpose = strip_tags(mysqli_real_escape_string($mysqli,$_POST['purpose'])); $client_id = intval($_POST['client']); - mysqli_query($mysqli,"INSERT INTO trips SET trip_date = '$date', trip_starting_location = '$starting_location', trip_destination = '$destination', trip_miles = $miles, round_trip = $roundtrip, trip_purpose = '$purpose', trip_created_at = NOW(), client_id = $client_id, company_id = $session_company_id"); + mysqli_query($mysqli,"INSERT INTO trips SET trip_date = '$date', trip_source = '$source', trip_destination = '$destination', trip_miles = $miles, round_trip = $roundtrip, trip_purpose = '$purpose', trip_created_at = NOW(), client_id = $client_id, company_id = $session_company_id"); //Logging mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Trip', log_action = 'Created', log_description = '$date', log_created_at = NOW(), company_id = $session_company_id, user_id = $session_user_id"); @@ -1005,14 +1005,14 @@ if(isset($_POST['edit_trip'])){ $trip_id = intval($_POST['trip_id']); $date = strip_tags(mysqli_real_escape_string($mysqli,$_POST['date'])); - $starting_location = strip_tags(mysqli_real_escape_string($mysqli,$_POST['starting_location'])); + $source = strip_tags(mysqli_real_escape_string($mysqli,$_POST['source'])); $destination = strip_tags(mysqli_real_escape_string($mysqli,$_POST['destination'])); $miles = floatval($_POST['miles']); $roundtrip = intval($_POST['roundtrip']); $purpose = strip_tags(mysqli_real_escape_string($mysqli,$_POST['purpose'])); $client_id = intval($_POST['client']); - mysqli_query($mysqli,"UPDATE trips SET trip_date = '$date', trip_starting_location = '$starting_location', trip_destination = '$destination', trip_miles = $miles, trip_purpose = '$purpose', round_trip = $roundtrip, trip_updated_at = NOW(), client_id = $client_id WHERE trip_id = $trip_id AND company_id = $session_company_id"); + mysqli_query($mysqli,"UPDATE trips SET trip_date = '$date', trip_source = '$source', trip_destination = '$destination', trip_miles = $miles, trip_purpose = '$purpose', round_trip = $roundtrip, trip_updated_at = NOW(), client_id = $client_id WHERE trip_id = $trip_id AND company_id = $session_company_id"); //Logging mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Trip', log_action = 'Modified', log_description = '$date', log_created_at = NOW(), company_id = $session_company_id, user_id = $session_user_id"); @@ -3840,4 +3840,39 @@ if(isset($_GET['force_recurring'])){ } //End Force Recurring +if(isset($_GET['export_trips_csv'])){ + //get records from database + $query = $db->query("SELECT * FROM trips ORDER BY trip_date DESC"); + + if($query->num_rows > 0){ + $delimiter = ","; + $filename = "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 = $query->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); + } + exit; + +} + ?> \ No newline at end of file diff --git a/test.php b/test.php deleted file mode 100644 index 6afbba46..00000000 --- a/test.php +++ /dev/null @@ -1,12 +0,0 @@ -"; -echo $stripped_phone; - -?> \ No newline at end of file diff --git a/trips.php b/trips.php index 55f934b4..a76a0b3c 100644 --- a/trips.php +++ b/trips.php @@ -50,7 +50,7 @@ } $sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM trips - WHERE (trip_purpose LIKE '%$q%' OR trip_starting_location LIKE '%$q%' OR trip_destination LIKE '%$q%') + WHERE (trip_purpose LIKE '%$q%' OR trip_source LIKE '%$q%' OR trip_destination LIKE '%$q%') AND DATE(trip_date) BETWEEN '$dtf' AND '$dtt' AND company_id = $session_company_id ORDER BY $sb $o LIMIT $record_from, $record_to"); @@ -82,8 +82,8 @@ Date Purpose - From - To + Source + Destination Miles Action @@ -95,7 +95,7 @@ $trip_id = $row['trip_id']; $trip_date = $row['trip_date']; $trip_purpose = $row['trip_purpose']; - $trip_starting_location = $row['trip_starting_location']; + $trip_source = $row['trip_source']; $trip_destination = $row['trip_destination']; $trip_miles = $row['trip_miles']; $round_trip = $row['round_trip']; @@ -111,7 +111,7 @@ - + @@ -120,7 +120,7 @@