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 @@