From 53b7f7d1d501566b649478f1f2623fd2fff45dcf Mon Sep 17 00:00:00 2001 From: johnnyq Date: Mon, 24 Apr 2023 16:48:47 -0400 Subject: [PATCH] Feature: Client CSV Exportation --- client_export_modal.php | 23 +++++++++++++++++++++++ clients.php | 8 +++++++- post.php | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 client_export_modal.php diff --git a/client_export_modal.php b/client_export_modal.php new file mode 100644 index 00000000..95426c7e --- /dev/null +++ b/client_export_modal.php @@ -0,0 +1,23 @@ + diff --git a/clients.php b/clients.php index 6c6dc8ba..966c47df 100644 --- a/clients.php +++ b/clients.php @@ -41,7 +41,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
-
+
@@ -50,6 +50,11 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
+
+
+ +
+
" id="advancedFilter">
@@ -290,5 +295,6 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); num_rows > 0){ + $delimiter = ","; + $filename = $session_company_name . "-Clients-" . date('Y-m-d') . ".csv"; + + //create a file pointer + $f = fopen('php://memory', 'w'); + + //set column headers + $fields = array('Client Name', 'Industry', 'Referral', 'Website', 'Primary Address', 'Contact Name', 'Contact Phone', 'Extension', 'Contact Mobile', 'Contact Email', 'Creation 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['client_name'], $row['client_type'], $row['client_referral'], $row['client_website'], $row['location_address'] . ' ' . $row['location_city'] . ' ' . $row['location_state'] . ' ' . $row['location_zip'], $row['contact_name'], formatPhoneNumber($row['contact_phone']), $row['contact_extension'], formatPhoneNumber($row['contact_mobile']), $row['contact_email'], $row['client_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($_POST['add_calendar'])){ $name = sanitizeInput($_POST['name']);