-
Notifications
You must be signed in to change notification settings - Fork 35
/
index-export.php
201 lines (153 loc) · 3.47 KB
/
index-export.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
/*
Amberdms Billing System
(c) Copyright 2014 Amberdms Ltd
Please see LICENSE file for copyright information.
*/
/*
Include configuration + libraries
*/
include("include/config.php");
include("include/amberphplib/main.php");
log_debug("index", "Starting index-export.php");
/*
Fetch the page name to display, and perform security checks
*/
// get the page to display
if (!empty($_GET["page"]))
{
$page = $_GET["page"];
}
else
{
$page = "home.php";
}
// perform security checks on the page
// security_localphp prevents any nasties, and then we check the the page exists.
$page_valid = 0;
if (!security_localphp($page))
{
die("Sorry, the requested page could not be found - please check your URL.");
}
else
{
if (!@file_exists($page))
{
die("Sorry, the requested page could not be found - please check your URL.");
}
else
{
$page_valid = 1;
}
}
// get the mode to display
$mode = @security_script_input("/^[a-z]*$/", $_GET["mode"]);
if (!$mode)
{
die("No mode supplied!");
}
/*
Load the page
*/
if ($page_valid == 1)
{
log_debug("index", "Loading page $page");
// include PHP code
include($page);
// create new page object
$page_obj = New page_output;
// check permissions
if ($page_obj->check_permissions())
{
/*
Check data
*/
$page_valid = $page_obj->check_requirements();
/*
Run page logic, provided that the data was valid
*/
if ($page_valid)
{
$page_obj->execute();
}
}
else
{
// user has no valid permissions
$page_valid = 0;
error_render_noperms();
}
}
/*
Draw messages
*/
if (error_check())
{
print "<tr><td>";
log_error_render();
print "</td></tr>";
}
/*
Draw page data
*/
if ($page_valid)
{
/*
Setup HTTP headers we need for doing a file download
*/
$filename = "amberdms_bs_". time() .".$mode";
// required for IE, otherwise Content-disposition is ignored
if (ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');
// set the relevant content type
$file_extension = strtolower(substr(strrchr($filename,"."),1));
switch ($file_extension)
{
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpeg":
case "jpg": $ctype="image/jpg"; break;
default: $ctype="application/force-download";
}
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: $ctype");
header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
header("Content-Transfer-Encoding: binary");
// Not needed?
// // tell the browser how big the file is (in bytes)
// // most browers seem to ignore this, but it's vital in order to make IE 7 work.
// header("Content-Length: ". $this->data["file_size"] ."");
/*
Output page data
*/
switch ($mode)
{
case "csv":
$page_obj->render_csv();
break;
case "pdf":
$page_obj->render_pdf();
break;
case "ps":
$page_obj->render_ps();
break;
case "raw":
case "patch":
$page_obj->render_raw();
break;
case "pdf":
default:
print "Invalid mode supplied";
break;
}
}
?>