From 6f33e3379c7ed5cc02f0d2312746866241a98f11 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Sat, 21 Aug 2021 16:37:40 -0400 Subject: [PATCH] Updated all Client Data Listings and added CSV Exports to Client Data --- client_assets.php | 21 +- client_certificates.php | 20 +- client_contacts.php | 6 +- client_domains.php | 20 +- client_invoices.php | 20 +- client_locations.php | 21 +- client_logins.php | 21 +- client_networks.php | 20 +- client_payments.php | 20 +- client_quotes.php | 20 +- client_recurring.php | 20 +- client_software.php | 20 +- client_tickets.php | 20 +- client_trips.php | 21 +- client_vendors.php | 21 +- post.php | 542 +++++++++++++++++++++++++++++++++++++++- trips.php | 1 - 17 files changed, 770 insertions(+), 64 deletions(-) diff --git a/client_assets.php b/client_assets.php index ec8748df7..99d0a8329 100644 --- a/client_assets.php +++ b/client_assets.php @@ -59,11 +59,24 @@
-
- -
- +
+ +
+
+ +
+ +
+
+ +
+ +
+

diff --git a/client_certificates.php b/client_certificates.php index aabddcd5d..c9afb8450 100644 --- a/client_certificates.php +++ b/client_certificates.php @@ -58,11 +58,23 @@
-
- -
- +
+ +
+
+ +
+ +
+
+ +
+
+ Export +
+
+

diff --git a/client_contacts.php b/client_contacts.php index db702afba..c792f28f1 100644 --- a/client_contacts.php +++ b/client_contacts.php @@ -67,10 +67,10 @@
-
+ diff --git a/client_domains.php b/client_domains.php index 8a7aba4b1..4b516c9c6 100644 --- a/client_domains.php +++ b/client_domains.php @@ -59,11 +59,23 @@
-
- -
- +
+ +
+
+ +
+ +
+
+ +
+
+ Export +
+
+

diff --git a/client_invoices.php b/client_invoices.php index df812939a..38d856334 100644 --- a/client_invoices.php +++ b/client_invoices.php @@ -60,11 +60,23 @@
-
- -
- +
+ +
+
+ +
+ +
+
+ +
+
+ Export +
+
+

diff --git a/client_locations.php b/client_locations.php index b3d55a4d0..164e23591 100644 --- a/client_locations.php +++ b/client_locations.php @@ -59,11 +59,24 @@
-
- -
- +
+ +
+
+ +
+ +
+
+ +
+ +
+

diff --git a/client_logins.php b/client_logins.php index 7ec79b834..b3794d8fa 100644 --- a/client_logins.php +++ b/client_logins.php @@ -59,11 +59,24 @@
-
- -
- +
+ +
+
+ +
+ +
+
+ +
+ +
+

diff --git a/client_networks.php b/client_networks.php index 868bd42ad..f6db112f4 100644 --- a/client_networks.php +++ b/client_networks.php @@ -59,11 +59,23 @@
-
- -
- +
+ +
+
+ +
+ +
+
+ +
+
+ Export +
+
+

diff --git a/client_payments.php b/client_payments.php index 574eb8787..0396c73fe 100644 --- a/client_payments.php +++ b/client_payments.php @@ -58,11 +58,23 @@
-
- -
- +
+ +
+
+ +
+ +
+
+
+ +
+
+ Export +
+

diff --git a/client_quotes.php b/client_quotes.php index 246bd24b3..92f02e84b 100644 --- a/client_quotes.php +++ b/client_quotes.php @@ -60,11 +60,23 @@
-
- -
- +
+ +
+
+ +
+ +
+
+ +
+
+ Export +
+
+

diff --git a/client_recurring.php b/client_recurring.php index 22809aa6f..360c640c0 100644 --- a/client_recurring.php +++ b/client_recurring.php @@ -60,11 +60,23 @@
-
- -
- +
+ +
+
+ +
+ +
+
+ +
+
+ Export +
+
+

diff --git a/client_software.php b/client_software.php index 24daafe7b..db021bf02 100644 --- a/client_software.php +++ b/client_software.php @@ -59,11 +59,23 @@
-
- -
- +
+ +
+
+ +
+ +
+
+ +
+
+ Export +
+
+

diff --git a/client_tickets.php b/client_tickets.php index 7aa77335a..07b4e3f57 100644 --- a/client_tickets.php +++ b/client_tickets.php @@ -59,11 +59,23 @@
-
- -
- +
+ +
+
+ +
+ +
+
+ +
+
+ Export +
+
+

diff --git a/client_trips.php b/client_trips.php index abb1d3d0c..f224c0b0c 100644 --- a/client_trips.php +++ b/client_trips.php @@ -70,11 +70,24 @@
-
- -
- +
+ +
+
+ +
+ +
+
+ +
+ +
+

diff --git a/client_vendors.php b/client_vendors.php index c59c758ce..096a617d3 100644 --- a/client_vendors.php +++ b/client_vendors.php @@ -59,11 +59,24 @@
-
- -
- +
+ +
+
+ +
+ +
+
+ +
+ +
+

diff --git a/post.php b/post.php index a831ecae4..18f3ad15e 100644 --- a/post.php +++ b/post.php @@ -4021,12 +4021,12 @@ $f = fopen('php://memory', 'w'); //set column headers - $fields = array('Name', 'Title', 'Email', 'Phone', 'Mobile'); + $fields = array('Name', 'Title', 'Email', 'Phone', 'Mobile', 'Notes'); 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['contact_name'], $row['contact_title'], $row['contact_email'], $row['contact_phone'], $row['contact_mobile']); + $lineData = array($row['contact_name'], $row['contact_title'], $row['contact_email'], $row['contact_phone'], $row['contact_mobile'], $row['contact_notes']); fputcsv($f, $lineData, $delimiter); } @@ -4063,12 +4063,546 @@ $f = fopen('php://memory', 'w'); //set column headers - $fields = array('Name', 'Address', 'City', 'State', 'Postal Code', 'Phone'); + $fields = array('Name', 'Address', 'City', 'State', 'Postal Code', 'Phone', 'Notes'); 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['location_name'], $row['location_address'], $row['location_city'], $row['location_state'], $row['location_zip'], $row['location_phone']); + $lineData = array($row['location_name'], $row['location_address'], $row['location_city'], $row['location_state'], $row['location_zip'], $row['location_phone'], $row['location_notes']); + 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; + +} + +if(isset($_GET['export_client_assets_csv'])){ + $client_id = intval($_GET['export_client_assets_csv']); + + //get records from database + $sql = mysqli_query($mysqli,"SELECT * FROM clients WHERE client_id = $client_id AND company_id = $session_company_id"); + $row = mysqli_fetch_array($sql); + + $client_name = $row['client_name']; + + $sql = mysqli_query($mysqli,"SELECT * FROM assets WHERE client_id = $client_id ORDER BY asset_name ASC"); + if($sql->num_rows > 0){ + $delimiter = ","; + $filename = $client_name . "-Assets-" . date('Y-m-d') . ".csv"; + + //create a file pointer + $f = fopen('php://memory', 'w'); + + //set column headers + $fields = array('Name', 'Type', 'Make', 'Model', 'Serial Number', 'MAC Address', 'IP Address', 'Operating System', 'Purchase Date', 'Warranty Expiration Date', 'Notes'); + 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['asset_name'], $row['asset_type'], $row['asset_make'], $row['asset_model'], $row['asset_serial'], $row['asset_mac'], $row['asset_ip'], $row['asset_os'], $row['asset_purchase_date'], $row['asset_warranty_expire'], $row['asset_notes']); + 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; + +} + +if(isset($_GET['export_client_software_csv'])){ + $client_id = intval($_GET['export_client_software_csv']); + + //get records from database + $sql = mysqli_query($mysqli,"SELECT * FROM clients WHERE client_id = $client_id AND company_id = $session_company_id"); + $row = mysqli_fetch_array($sql); + + $client_name = $row['client_name']; + + $sql = mysqli_query($mysqli,"SELECT * FROM software WHERE client_id = $client_id ORDER BY software_name ASC"); + if($sql->num_rows > 0){ + $delimiter = ","; + $filename = $client_name . "-Software-" . date('Y-m-d') . ".csv"; + + //create a file pointer + $f = fopen('php://memory', 'w'); + + //set column headers + $fields = array('Name', 'Type', 'License', 'Notes'); + 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['software_name'], $row['software_type'], $row['software_license'], $row['software_notes']); + 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; + +} + +if(isset($_GET['export_client_logins_csv'])){ + $client_id = intval($_GET['export_client_logins_csv']); + + //get records from database + $sql = mysqli_query($mysqli,"SELECT * FROM clients WHERE client_id = $client_id AND company_id = $session_company_id"); + $row = mysqli_fetch_array($sql); + + $client_name = $row['client_name']; + + $sql = mysqli_query($mysqli,"SELECT *, AES_DECRYPT(login_password, '$config_aes_key') AS login_password FROM logins WHERE client_id = $client_id ORDER BY login_name ASC"); + if($sql->num_rows > 0){ + $delimiter = ","; + $filename = $client_name . "-Logins-" . date('Y-m-d') . ".csv"; + + //create a file pointer + $f = fopen('php://memory', 'w'); + + //set column headers + $fields = array('Name', 'Username', 'Password', 'URL', 'Notes'); + 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['login_name'], $row['login_username'], $row['login_password'], $row['login_uri'], $row['login_note']); + 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; + +} + +if(isset($_GET['export_client_networks_csv'])){ + $client_id = intval($_GET['export_client_networks_csv']); + + //get records from database + $sql = mysqli_query($mysqli,"SELECT * FROM clients WHERE client_id = $client_id AND company_id = $session_company_id"); + $row = mysqli_fetch_array($sql); + + $client_name = $row['client_name']; + + $sql = mysqli_query($mysqli,"SELECT * FROM networks WHERE client_id = $client_id ORDER BY network_name ASC"); + if($sql->num_rows > 0){ + $delimiter = ","; + $filename = $client_name . "-Networks-" . date('Y-m-d') . ".csv"; + + //create a file pointer + $f = fopen('php://memory', 'w'); + + //set column headers + $fields = array('Name', 'vLAN', 'Network', 'Gateway', 'DHCP Range'); + 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['network_name'], $row['network_vlan'], $row['network'], $row['network_gateway'], $row['network_dhcp_range']); + 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; + +} + +if(isset($_GET['export_client_certificates_csv'])){ + $client_id = intval($_GET['export_client_certificates_csv']); + + //get records from database + $sql = mysqli_query($mysqli,"SELECT * FROM clients WHERE client_id = $client_id AND company_id = $session_company_id"); + $row = mysqli_fetch_array($sql); + + $client_name = $row['client_name']; + + $sql = mysqli_query($mysqli,"SELECT * FROM certificates WHERE client_id = $client_id ORDER BY certificate_name ASC"); + if($sql->num_rows > 0){ + $delimiter = ","; + $filename = $client_name . "-Certificates-" . date('Y-m-d') . ".csv"; + + //create a file pointer + $f = fopen('php://memory', 'w'); + + //set column headers + $fields = array('Name', 'Domain', 'Issuer', 'Expiration Date'); + 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['certificate_name'], $row['certificate_domain'], $row['certificate_issued_by'], $row['certificate_expire']); + 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; + +} + +if(isset($_GET['export_client_domains_csv'])){ + $client_id = intval($_GET['export_client_domains_csv']); + + //get records from database + $sql = mysqli_query($mysqli,"SELECT * FROM clients WHERE client_id = $client_id AND company_id = $session_company_id"); + $row = mysqli_fetch_array($sql); + + $client_name = $row['client_name']; + + $sql = mysqli_query($mysqli,"SELECT * FROM domains WHERE client_id = $client_id ORDER BY domain_name ASC"); + + if($sql->num_rows > 0){ + $delimiter = ","; + $filename = $client_name . "-Domains-" . date('Y-m-d') . ".csv"; + + //create a file pointer + $f = fopen('php://memory', 'w'); + + //set column headers + $fields = array('Domain', 'Registrar', 'Web Host', 'Expiration Date'); + 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['domain_name'], $row['domain_registrar'], $row['domain_webhost'], $row['domain_expire']); + 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; + +} + +if(isset($_GET['export_client_tickets_csv'])){ + $client_id = intval($_GET['export_client_tickets_csv']); + + //get records from database + $sql = mysqli_query($mysqli,"SELECT * FROM clients WHERE client_id = $client_id AND company_id = $session_company_id"); + $row = mysqli_fetch_array($sql); + + $client_name = $row['client_name']; + + $sql = mysqli_query($mysqli,"SELECT * FROM tickets WHERE client_id = $client_id ORDER BY ticket_number ASC"); + if($sql->num_rows > 0){ + $delimiter = ","; + $filename = $client_name . "-Tickets-" . date('Y-m-d') . ".csv"; + + //create a file pointer + $f = fopen('php://memory', 'w'); + + //set column headers + $fields = array('Ticket Number', 'Priority', 'Status', 'Subject', 'Date Opened', 'Date Closed'); + 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['ticket_number'], $row['ticket_priority'], $row['ticket_status'], $row['ticket_subject'], $row['ticket_created_at'], $row['ticket_closed_at']); + 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; + +} + +if(isset($_GET['export_client_vendors_csv'])){ + $client_id = intval($_GET['export_client_vendors_csv']); + + //get records from database + $sql = mysqli_query($mysqli,"SELECT * FROM clients WHERE client_id = $client_id AND company_id = $session_company_id"); + $row = mysqli_fetch_array($sql); + + $client_name = $row['client_name']; + + $sql = mysqli_query($mysqli,"SELECT * FROM vendors WHERE client_id = $client_id ORDER BY vendor_name ASC"); + if($sql->num_rows > 0){ + $delimiter = ","; + $filename = $client_name . "-Vendors-" . date('Y-m-d') . ".csv"; + + //create a file pointer + $f = fopen('php://memory', 'w'); + + //set column headers + $fields = array('Name', 'Description', 'Contact Name', 'Phone', 'Website', 'Account Number', 'Notes'); + 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['vendor_name'], $row['vendor_description'], $row['vendor_contact_name'], $row['vendor_phone'], $row['vendor_website'], $row['vendor_account_number'], $row['vendor_notes']); + 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; + +} + +if(isset($_GET['export_client_invoices_csv'])){ + $client_id = intval($_GET['export_client_invoices_csv']); + + //get records from database + $sql = mysqli_query($mysqli,"SELECT * FROM clients WHERE client_id = $client_id AND company_id = $session_company_id"); + $row = mysqli_fetch_array($sql); + + $client_name = $row['client_name']; + + $sql = mysqli_query($mysqli,"SELECT * FROM invoices WHERE client_id = $client_id ORDER BY invoice_number ASC"); + if($sql->num_rows > 0){ + $delimiter = ","; + $filename = $client_name . "-Invoices-" . date('Y-m-d') . ".csv"; + + //create a file pointer + $f = fopen('php://memory', 'w'); + + //set column headers + $fields = array('Invoice Number', 'Scope', 'Amount', 'Issued Date', 'Due Date', 'Status'); + 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['invoice_prefix'] . $row['invoice_number'], $row['invoice_scope'], $row['invoice_amount'], $row['invoice_date'], $row['invoice_due'], $row['invoice_status']); + 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; + +} + +if(isset($_GET['export_client_recurring_csv'])){ + $client_id = intval($_GET['export_client_recurring_csv']); + + //get records from database + $sql = mysqli_query($mysqli,"SELECT * FROM clients WHERE client_id = $client_id AND company_id = $session_company_id"); + $row = mysqli_fetch_array($sql); + + $client_name = $row['client_name']; + + $sql = mysqli_query($mysqli,"SELECT * FROM recurring WHERE client_id = $client_id ORDER BY recurring_number ASC"); + if($sql->num_rows > 0){ + $delimiter = ","; + $filename = $client_name . "-Recurring Invoices-" . date('Y-m-d') . ".csv"; + + //create a file pointer + $f = fopen('php://memory', 'w'); + + //set column headers + $fields = array('Recurring Number', 'Scope', 'Amount', 'Frequency', 'Date Created'); + 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['recurring_prefix'] . $row['recurring_number'], $row['recurring_scope'], $row['recurring_amount'], ucwords($row['recurring_frequency'] . "ly"), $row['recurring_created_at']); + 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; + +} + +if(isset($_GET['export_client_quotes_csv'])){ + $client_id = intval($_GET['export_client_quotes_csv']); + + //get records from database + $sql = mysqli_query($mysqli,"SELECT * FROM clients WHERE client_id = $client_id AND company_id = $session_company_id"); + $row = mysqli_fetch_array($sql); + + $client_name = $row['client_name']; + + $sql = mysqli_query($mysqli,"SELECT * FROM quotes WHERE client_id = $client_id ORDER BY quote_number ASC"); + if($sql->num_rows > 0){ + $delimiter = ","; + $filename = $client_name . "-Quotes-" . date('Y-m-d') . ".csv"; + + //create a file pointer + $f = fopen('php://memory', 'w'); + + //set column headers + $fields = array('Quote Number', 'Scope', 'Amount', 'Date', 'Status'); + 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['quote_prefix'] . $row['quote_number'], $row['quote_scope'], $row['quote_amount'], $row['quote_date'], $row['quote_status']); + 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; + +} + +if(isset($_GET['export_client_payments_csv'])){ + $client_id = intval($_GET['export_client_payments_csv']); + + //get records from database + $sql = mysqli_query($mysqli,"SELECT * FROM clients WHERE client_id = $client_id AND company_id = $session_company_id"); + $row = mysqli_fetch_array($sql); + + $client_name = $row['client_name']; + + $sql = mysqli_query($mysqli,"SELECT * FROM payments, invoices WHERE invoices.client_id = $client_id AND payments.invoice_id = invoices.invoice_id ORDER BY payment_date ASC"); + if($sql->num_rows > 0){ + $delimiter = ","; + $filename = $client_name . "-Payments-" . date('Y-m-d') . ".csv"; + + //create a file pointer + $f = fopen('php://memory', 'w'); + + //set column headers + $fields = array('Payment Date', 'Invoice Date', 'Invoice Number', 'Invoice Amount', 'Payment Amount', 'Payment Method', 'Referrence'); + 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['payment_date'], $row['invoice_date'], $row['invoice_prefix'] . $row['invoice_number'], $row['invoice_amount'], $row['payment_amount'], $row['payment_method'], $row['payment_reference']); + 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; + +} + +if(isset($_GET['export_client_trips_csv'])){ + $client_id = intval($_GET['export_client_trips_csv']); + + //get records from database + $sql = mysqli_query($mysqli,"SELECT * FROM clients WHERE client_id = $client_id AND company_id = $session_company_id"); + $row = mysqli_fetch_array($sql); + + $client_name = $row['client_name']; + + $sql = mysqli_query($mysqli,"SELECT * FROM trips WHERE client_id = $client_id ORDER BY trip_date ASC"); + if($sql->num_rows > 0){ + $delimiter = ","; + $filename = $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); } diff --git a/trips.php b/trips.php index eb64750e0..98f73d732 100644 --- a/trips.php +++ b/trips.php @@ -108,7 +108,6 @@