-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport.php
More file actions
52 lines (41 loc) · 1.51 KB
/
export.php
File metadata and controls
52 lines (41 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
require_once('inc/autoload.php');
$sql = "SELECT * FROM orders ";
$sql .= "WHERE cost_centre in (SELECT uid FROM cost_centres WHERE department = '" . $_SESSION['department'] . "') ";
$sql .= "ORDER BY orders.date DESC, orders.po DESC;";
//$orders = $db->rawQuery($sql);
$orders = $db->query($sql)->fetchAll();
$i = 0;
foreach ($orders AS $order) {
$cost_centre = new cost_centre($order['cost_centre']);
$user = new user($order['username']);
$row['uid'] = $order['uid'];
$row['username'] = $user->username;
$row['date'] = $order['date'];
$row['cost_centre_code'] = $cost_centre->code;
$row['cost_centre_name'] = $cost_centre->name;
$row['po'] = $order['po'];
$row['order_num'] = $order['order_num'];
$row['name'] = $order['name'];
$row['value'] = $order['value'];
$row['supplier'] = $order['supplier'];
$row['description'] = $order['description'];
$row['paid'] = $order['paid'];
$prod[$i] = $row;
$i++;
}
$output = fopen("php://output",'w') or die("Can't open php://output");
header("Content-Type:application/csv");
header("Content-Disposition:attachment;filename=budget_export.csv");
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="budget_export.csv"');
header('Pragma: no-cache');
header('Expires: 0');
fputcsv($output, array_keys($row));
if (isset($_SESSION['username'])) {
foreach($prod as $product) {
fputcsv($output, $product);
}
fclose($output) or die("Can't close php://output");
}
?>