forked from emaijala/MLInvoice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinvoice.php
executable file
·134 lines (124 loc) · 3.57 KB
/
invoice.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/**
* Printouts
*
* PHP version 5
*
* Copyright (C) 2004-2008 Samu Reinikainen
* Copyright (C) 2010-2018 Ere Maijala
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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
*
* @category MLInvoice
* @package MLInvoice\Base
* @author Ere Maijala <[email protected]>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://labs.fi/mlinvoice.eng.php
*/
// buffered, so we can redirect later if necessary
ini_set('implicit_flush', 'Off');
ob_start();
require_once 'sessionfuncs.php';
$authenticated = true;
$intInvoiceId = getRequest('id', false);
$printTemplate = getRequest('t', false);
$dateOverride = false;
$language = getRequest('l', false);
$uuid = getRequest('i', false);
$hash = getRequest('c', false);
$ts = getRequest('s', false);
if (false === $printTemplate || false === $language || false === $uuid
|| false === $hash || false === $ts
) {
if ($intInvoiceId) {
sesVerifySession();
} else {
return;
}
} else {
$authenticated = false;
}
require_once 'vendor/autoload.php';
require_once 'sqlfuncs.php';
require_once 'translator.php';
require_once 'datefuncs.php';
require_once 'miscfuncs.php';
if ($authenticated) {
$printTemplate = getRequest('template', 1);
$dateOverride = getRequest('date', false);
if (!is_string($dateOverride) || !ctype_digit($dateOverride)
|| strlen($dateOverride) != 8
) {
$dateOverride = false;
}
} else {
include_once 'hmac.php';
$reqHash = HMAC::createHMAC([$printTemplate, $language, $uuid, $ts]);
if ($reqHash !== $hash) {
return;
}
Translator::setActiveLanguage('', $language);
if (abs(time() - $ts) > 90 * 24 * 60 * 60) { // 90 days
die(Translator::translate('LinkExpired'));
}
$rows = dbParamQuery(
'SELECT id FROM {prefix}invoice WHERE uuid=?',
[$uuid]
);
if (!$rows) {
return;
}
$intInvoiceId = $rows[0]['id'];
}
if (!$intInvoiceId) {
if ($authenticated) {
die('Id missing');
}
return;
}
$rows = dbParamQuery(
'SELECT filename, parameters, output_filename from {prefix}print_template WHERE id=?',
[$printTemplate]
);
if (!$rows) {
if ($authenticated) {
die('Could not find print template');
}
return;
}
$row = $rows[0];
$printTemplateFile = $row['filename'];
$printParameters = $row['parameters'];
$printOutputFileName = $row['output_filename'];
if (!$authenticated) {
if (substr($printTemplateFile, -6) === '_email') {
$printTemplateFile = substr($printTemplateFile, -6);
}
$printParameters[1] = $language;
}
$printer = getInvoicePrinter($printTemplateFile);
$printer->init(
$intInvoiceId, $printParameters, $printOutputFileName,
$dateOverride, $printTemplate, $authenticated
);
$printer->printInvoice();
if ($authenticated && sesWriteAccess()) {
dbParamQuery(
'UPDATE {prefix}invoice SET print_date=? where id=?',
[
date('Ymd'),
$intInvoiceId
]
);
}