\n"); $error_message = "You are not allowed access to the requested hot lunch schedule"; include "form.messages.php"; return; } } // Initialize the spreadsheet document type header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Cache-Control: private',false); header("Content-type: application/octet-stream; charset=utf-8"); header("Content-Disposition: attachment; filename=product-totals.csv"); header('Content-Transfer-Encoding: text'); echo("\xEF\xBB\xBF"); // Get set of products and the quantities $query = "SELECT product_name,package_qty,package_cost,sum(qty) " . "FROM hotlunch_order_items AS hloi, hotlunch_menu_products AS hlmp, supplier_products AS sp " . "WHERE hloi.school_num = $school_num " . "AND hlmp.school_num = $school_num " . "AND hlmp.supplier_product_num IN ( $supplierProducts ) " . "AND hloi.schedule_num = $schedule_num " . "AND hloi.menu_num IN ( $menuDates ) " . "AND hloi.menu_item_num = hlmp.menu_item_num " . "AND hloi.active != 'N' " . "AND sp.school_num = $supplier_school_num " . "AND sp.record_num = hlmp.supplier_product_num " . "GROUP BY 1,2,3 " . "ORDER BY 1"; $results = db_query($query); echo("Schedule: " . $hotlunch_schedule['schedule_name'] . "\n"); echo("Selected Products: $numProducts\n"); echo("Selected Dates: $numDates\n"); echo("\n"); echo("PRODUCT,PKG QTY,PKG COST,QTY SOLD,TOTAL COST\n"); // Process the results while ($row = db_fetch_array($results)) { // Output the results if (is_array($row)) { for ($i = 0; $i < count($row); $i++) { $value = ''; if (array_key_exists($i, $row)) $value = $row[$i]; echo('"' . $value . '",'); } echo($row[2] * intval(($row[3] + $row[1] - 1) / $row[1])); echo("\n"); } } ?>