/** * Download CSV report (default) * * @return void */ public function downloadTask() { // Get filters $filters = array('sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'dDownloaded'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'ASC'), 'report-notes' => Request::getState($this->_option . '.' . $this->_controller . '.report-notes', 'report-notes', 0, 'int')); // request array to be returned $filters['returnFormat'] = 'array'; $filters['userInfo'] = true; $rowsRaw = Cart::getAllTransactions($filters); $date = date('d-m-Y'); $rows = array(); foreach ($rowsRaw as $row) { $rows[] = array($row['tId'], $row['tLastUpdated'], $row['Name'], $row['uidNumber']); } header("Content-Type: text/csv"); header("Content-Disposition: attachment; filename=cart-orders" . $date . ".csv"); // Disable caching header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1 header("Pragma: no-cache"); // HTTP 1.0 header("Expires: 0"); // Proxies $output = fopen("php://output", "w"); $row = array('Order ID', 'Order Placed', 'Purchased By', 'Purchased By (userId)'); fputcsv($output, $row); foreach ($rows as $row) { fputcsv($output, $row); } fclose($output); die; }