-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathiexport.php
49 lines (49 loc) · 3.78 KB
/
iexport.php
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
<?php
/*
* invoices.php
*
* Copyright 2018 Krzysztof Hrybacz <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
header('Content-Description: CSV Export');
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="export.csv"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
require_once('config.php');
session_start();
if ($_SESSION['login']=='') exit('Login error! <a href="' . $url . '/">Back</a>');
$link = mysqli_connect($sql, $sqluser, $sqlpass, $sqldb);
mysqli_set_charset($link,'utf8');
if ($_GET['order']=='DESC') $order=' DESC';
if ($_GET['sort']=='')
$result = mysqli_query($link,'SELECT `' . $_SESSION['company'] . '_invoices`.id,`' . $_SESSION['company'] . '_invoices`.invoiceid,`' . $_SESSION['company'] . '_invoices`.currency,`' . $_SESSION['company'] . '_invoices`.client,`' . $_SESSION['company'] . '_invoices`.total,`' . $_SESSION['company'] . '_invoices`.creation,`' . $_SESSION['company'] . '_clients`.fullname,`' . $_SESSION['company'] . '_clients`.company,`' . $_SESSION['company'] . '_clients`.address,`' . $_SESSION['company'] . '_clients`.mobile,`' . $_SESSION['company'] . '_clients`.mail FROM `' . $_SESSION['company'] . '_invoices` INNER JOIN `' . $_SESSION['company'] . '_clients` ON `' . $_SESSION['company'] . '_invoices`.client = `' . $_SESSION['company'] . '_clients`.id ORDER BY invoiceid,id;');
else
$result = mysqli_query($link,'SELECT `' . $_SESSION['company'] . '_invoices`.id,`' . $_SESSION['company'] . '_invoices`.invoiceid,`' . $_SESSION['company'] . '_invoices`.currency,`' . $_SESSION['company'] . '_invoices`.client,`' . $_SESSION['company'] . '_invoices`.total,`' . $_SESSION['company'] . '_invoices`.creation,`' . $_SESSION['company'] . '_clients`.fullname,`' . $_SESSION['company'] . '_clients`.company,`' . $_SESSION['company'] . '_clients`.address,`' . $_SESSION['company'] . '_clients`.mobile,`' . $_SESSION['company'] . '_clients`.mail FROM `' . $_SESSION['company'] . '_invoices` INNER JOIN `' . $_SESSION['company'] . '_clients` ON `' . $_SESSION['company'] . '_invoices`.client = `' . $_SESSION['company'] . '_clients`.id ORDER BY ' . $_GET['sort'] . $order . ',invoiceid,id;');
echo '"INVOICE ID","CLIENT NAME","CLIENT COMPANY","CLIENT ADDRESS","CLIENT MOBILE","CLIENT E-MAIL","CREATION DATE","INVOICE VALUE","INVOICE CURRENCY"';
echo "\n";
while ($row = mysqli_fetch_array($result))
if ($_GET['q']=='' || strpos(strtolower($row['id']), strtolower($_GET['q']))!==false || strpos(strtolower($row['company']), strtolower($_GET['q']))!==false || strpos(strtolower($row['fullname']), strtolower($_GET['q']))!==false || strpos(strtolower($row['creation']), strtolower($_GET['q']))!==false || strpos(strtolower($row['total']), strtolower($_GET['q']))!==false) {
echo $row['invoiceid'] . ',"' . $row['fullname'] . '","' . $row['company'] . '","' . $row['address'] . '","' . $row['mobile'] . '","' . $row['mail'] . '",' . $row['creation'] . ',' . number_format($row['total'],2,'.','') . ',' . $row['currency'];
echo "\n";
}
mysqli_free_result($result);
mysqli_close($link);
?>