This repository has been archived by the owner on Feb 21, 2019. It is now read-only.
forked from emaijala/MLInvoice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
base_logo.php
133 lines (119 loc) · 4.62 KB
/
base_logo.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
<?php
/*******************************************************************************
MLInvoice: web-based invoicing application.
Copyright (C) 2010-2015 Ere Maijala
This program is free software. See attached LICENSE.
*******************************************************************************/
/*******************************************************************************
MLInvoice: web-pohjainen laskutusohjelma.
Copyright (C) 2010-2015 Ere Maijala
Tämä ohjelma on vapaa. Lue oheinen LICENSE.
*******************************************************************************/
require_once 'sqlfuncs.php';
require_once 'miscfuncs.php';
require_once 'sessionfuncs.php';
require_once 'localize.php';
require_once 'htmlfuncs.php';
sesVerifySession();
$func = getRequest('func', 'view');
$baseId = getRequest('id', null);
if (!isset($baseId) || !is_numeric($baseId) || !isset($func))
exit();
$messages = '';
if ($func == 'clear') {
mysqli_param_query(
'UPDATE {prefix}base set logo_filename=null, logo_filesize=null, logo_filetype=null, logo_filedata=null WHERE id=?',
[
$baseId
]);
$messages .= $GLOBALS['locBaseLogoErased'] . "<br>\n";
} elseif ($func == 'upload') {
if ($_FILES['logo']['error'] != UPLOAD_ERR_OK) {
$messages .= $GLOBALS['locErrFileUploadFailed'] . "<br>\n";
} else {
$imageInfo = getimagesize($_FILES['logo']['tmp_name']);
if (!$imageInfo || !in_array($imageInfo['mime'],
[
'image/jpeg',
'image/png'
])) {
$messages .= $GLOBALS['locErrFileTypeInvalid'] . "<br>\n";
} else {
$file = fopen($_FILES['logo']['tmp_name'], 'rb');
if ($file === FALSE)
die('Could not process file upload - temp file missing');
$fsize = filesize($_FILES['logo']['tmp_name']);
$data = fread($file, $fsize);
fclose($file);
mysqli_param_query(
'UPDATE {prefix}base set logo_filename=?, logo_filesize=?, logo_filetype=?, logo_filedata=? WHERE id=?',
[
$_FILES['logo']['name'],
$fsize,
$imageInfo['mime'],
$data,
$baseId
]);
$messages .= $GLOBALS['locBaseLogoSaved'] . ' (' .
fileSizeToHumanReadable($fsize) . ")<br>\n";
}
}
} elseif ($func == 'view') {
$res = mysqli_param_query(
'SELECT logo_filename, logo_filesize, logo_filetype, logo_filedata FROM {prefix}base WHERE id=?',
[
$baseId
]);
if ($row = mysqli_fetch_assoc($res)) {
if (isset($row['logo_filename']) && isset($row['logo_filesize']) &&
isset($row['logo_filetype']) && isset($row['logo_filedata'])) {
header('Content-length: ' . $row['logo_filesize']);
header('Content-type: ' . $row['logo_filetype']);
header('Content-Disposition: inline; filename=' . $row['logo_filename']);
echo $row['logo_filedata'];
}
}
exit();
}
$maxUploadSize = getMaxUploadSize();
$row = mysqli_fetch_array(mysqli_query_check('SELECT @@max_allowed_packet'));
$maxPacket = $row[0];
if ($maxPacket < $maxUploadSize)
$maxFileSize = fileSizeToHumanReadable($maxPacket) . ' ' .
$GLOBALS['locBaseLogoSizeDBLimited'];
else
$maxFileSize = fileSizeToHumanReadable($maxUploadSize);
echo htmlPageStart(_PAGE_TITLE_);
?>
<div class="form">
<div class="message"><?php echo $messages?></div>
<div class="form_container ui-widget-content">
<div style="margin-bottom: 10px">
<img class="image" src="?func=view&id=<?php echo $baseId?>">
</div>
<form id="form_upload" enctype="multipart/form-data"
action="base_logo.php" method="POST">
<input type="hidden" name="func" value="upload"> <input type="hidden"
name="id" value="<?php echo $baseId?>">
<div class="label" style="clear: both; margin-top: 10px"><?php printf($GLOBALS['locBaseLogo'], $maxFileSize)?></div>
<div class="long">
<input name="logo" type="file">
</div>
<div class="form_buttons" style="clear: both">
<input type="submit"
value="<?php echo $GLOBALS['locBaseSaveLogo']?>">
</div>
</form>
<form id="form_erase" enctype="multipart/form-data"
action="base_logo.php" method="POST">
<input type="hidden" name="func" value="clear"> <input type="hidden"
name="id" value="<?php echo $baseId?>">
<div class="form_buttons" style="clear: both">
<input type="submit"
value="<?php echo $GLOBALS['locBaseEraseLogo']?>">
</div>
</form>
</div>
</div>
</body>
</html>