-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbootstrap.php
162 lines (139 loc) · 5.53 KB
/
bootstrap.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
<?php
error_reporting(E_ALL);
ini_set('display_errors', $_SERVER['SERVER_NAME'] === 'localhost' ? 1 : 0);
date_default_timezone_set('Europe/Berlin');
if (is_file(__DIR__ . '/../library/SetaPDF/Autoload.php')) {
// if the demos are bundled with setapdf
require_once __DIR__ . '/../library/SetaPDF/Autoload.php';
} else {
// if you use composer
require_once __DIR__ . '/vendor/autoload.php';
}
// otherwise include your setapdf directory INSTEAD
//require_once __DIR__ . '/../SetaPDF/library/SetaPDF/Autoload.php';
$assetsDirectory = __DIR__ . '/assets';
$classesDirectory = __DIR__ . '/classes';
$dir = dirname($_SERVER['SCRIPT_NAME']);
if (strpos($dir, '/public/') !== false) {
$basePath = substr($dir, 0, strpos($dir, '/public/')) . '/public/';
} else {
$basePath = '/';
}
function displayFiles($files, $iframe = true, $multiple = false, $upload = false)
{
if (isset($_GET['f'])) {
if ($multiple) {
if (is_array($_GET['f'])) {
$result = [];
foreach ($_GET['f'] as $f) {
if (is_scalar($f) && isset($files[$f])) {
$result[] = $files[$f];
}
}
if (count($result) > 0) {
return $result;
}
}
} else {
if (is_scalar($_GET['f']) && isset($files[$_GET['f']])) {
return $files[$_GET['f']];
}
}
}
if ($upload) {
if (isset($_FILES['upload']) && $_FILES['upload']['error'] === 0) {
return [
'file' => $_FILES['upload']['tmp_name'],
'filename' => $_FILES['upload']['name']
];
}
}
echo '<html><head>';
echo '<link rel="stylesheet" type="text/css" href="' . $GLOBALS['basePath'] . 'layout/demo.css"/></head><body>';
echo '<form id="demoInput"' . ($iframe ? ' target="pdfFrame"' : '');
if ($upload) {
echo ' method="post" enctype="multipart/form-data"';
}
echo '>';
if ($upload) {
echo '<div class="uploadRow"><input type="file" name="upload" /><input type="submit" /></div>';
}
// list the files
foreach ($files as $f => $path) {
if (is_array($path)) {
$displayValue = isset($path['displayValue']) ? $path['displayValue'] : null;
} else {
$displayValue = basename($path);
}
if ($multiple) {
echo '<label for="file'. $f . '">';
echo '<input type="checkbox" name="f[]" value="' . $f . '" id="file'. $f . '" onclick="checkSubmitBtn(this)" />';
echo htmlspecialchars($displayValue) . '</label><br />';
} else {
echo '<a href="?' . http_build_query(['f' => $f]) . '"' . ($iframe ? ' target="pdfFrame"' : ''). '>'
. htmlspecialchars($displayValue) . '</a><br />';
}
}
if ($multiple) {
echo '<script>checkSubmitBtn=function(e){var d=0,btn=document.getElementById("submitBtn");document.getElementsByName("f[]").forEach(function(n){d|=n.checked});btn.disabled=!d;}</script>';
echo '<input type="submit" value="run" id="submitBtn" disabled/>';
}
echo '</form>';
if ($iframe) {
echo '<iframe width="100%" name="pdfFrame" src="about:blank"/>';
}
echo '</body></html>';
die();
}
function displaySelect($label, $data, $iframe = true, $displayValueKey = null)
{
if (!isset($_GET['data']) || !array_key_exists($_GET['data'], $data)) {
echo '<html><head>';
echo '<link rel="stylesheet" type="text/css" href="' . $GLOBALS['basePath'] . 'layout/demo.css"/></head><body>';
echo '<div id="demoInput">';
echo '<form method="GET"';
if ($iframe) {
echo ' target="pdfFrame"';
}
echo '><label for="data">' . htmlspecialchars($label) . '</label>'
. '<select id="data" name="data" onchange="if(this.value)this.form.submit();">'
. '<option value="">--- please choose ---</option>';
foreach ($data as $value => $displayValue) {
if (is_array($displayValue)) {
$displayValueKey = $displayValueKey !== null ? $displayValueKey : key($displayValue);
$displayValue = $displayValue[$displayValueKey];
} elseif ($displayValueKey === true) {
$displayValue = $value;
}
echo '<option value="' . htmlspecialchars($value) . '">' . htmlspecialchars($displayValue) . '</option>';
}
echo '</select></form></div>';
if ($iframe) {
echo '<iframe width="100%" name="pdfFrame" src="about:blank"/>';
}
echo '</body></html>';
die();
}
return $_GET['data'];
}
function displayText($label, $defaultValue = '', $iframe = false, $iframeUrl = 'about:blank')
{
if (!isset($_GET['data'])) {
echo '<html><head>';
echo '<link rel="stylesheet" type="text/css" href="' . $GLOBALS['basePath'] . 'layout/demo.css"/></head><body>';
echo '<div id="demoInput">';
echo '<form method="GET"';
if ($iframe) {
echo ' target="pdfFrame"';
}
echo '><label for="data">' . htmlspecialchars($label) . '</label>'
. '<input id="data" name="data" value="' . htmlspecialchars($defaultValue) . '" />';
echo '</select><button type="submit">GO</button></form></div>';
if ($iframe) {
echo '<iframe width="100%" name="pdfFrame" src="' . $iframeUrl . '"/>';
}
echo '</body></html>';
die();
}
return $_GET['data'];
}