-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.backend.php
More file actions
333 lines (298 loc) · 9.8 KB
/
class.backend.php
File metadata and controls
333 lines (298 loc) · 9.8 KB
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<?php
/**
* toolConfirmationLog
*
* @author Ralf Hertsch <ralf.hertsch@phpmanufaktur.de>
* @link http://phpmanufaktur.de
* @copyright 2012
* @license MIT License (MIT) http://www.opensource.org/licenses/MIT
*/
// include class.secure.php to protect this file and the whole CMS!
if (defined('WB_PATH')) {
if (defined('LEPTON_VERSION'))
include(WB_PATH.'/framework/class.secure.php');
}
else {
$oneback = "../";
$root = $oneback;
$level = 1;
while (($level < 10) && (!file_exists($root.'/framework/class.secure.php'))) {
$root .= $oneback;
$level += 1;
}
if (file_exists($root.'/framework/class.secure.php')) {
include($root.'/framework/class.secure.php');
}
else {
trigger_error(sprintf("[ <b>%s</b> ] Can't include class.secure.php!", $_SERVER['SCRIPT_NAME']), E_USER_ERROR);
}
}
// end include class.secure.php
// wb2lepton compatibility
if (!defined('LEPTON_PATH')) require_once WB_PATH.'/modules/'.basename(dirname(__FILE__)).'/wb2lepton.php';
// load language depending onfiguration
if (!file_exists(LEPTON_PATH.'/modules/'.basename(dirname(__FILE__)).'/languages/'.LANGUAGE.'.cfg.php')) {
require_once(LEPTON_PATH.'/modules/'.basename(dirname(__FILE__)).'/languages/EN.cfg.php');
}
else {
require_once(LEPTON_PATH.'/modules/'.basename(dirname(__FILE__)).'/languages/'.LANGUAGE.'.cfg.php');
}
// use LEPTON 2.x I18n for access to language files
if (!class_exists('LEPTON_Helper_I18n')) require_once LEPTON_PATH.'/modules/'.basename(dirname(__FILE__)).'/framework/LEPTON/Helper/I18n.php';
global $I18n;
if (!is_object($I18n)) {
$I18n = new LEPTON_Helper_I18n();
}
else {
$I18n->addFile('DE.php', LEPTON_PATH.'/modules/'.basename(dirname(__FILE__)).'/languages/');
}
// initialize Dwoo
global $parser;
if (!class_exists('Dwoo')) {
require_once WB_PATH.'/modules/dwoo/include.php';
}
$cache_path = WB_PATH.'/temp/cache';
if (!file_exists($cache_path)) mkdir($cache_path, 0755, true);
$compiled_path = WB_PATH.'/temp/compiled';
if (!file_exists($compiled_path)) mkdir($compiled_path, 0755, true);
global $parser;
if (!is_object($parser)) $parser = new Dwoo($compiled_path, $cache_path);
class confirmationBackend {
const REQUEST_ACTION = 'act';
const ACTION_ABOUT = 'abt';
const ACTION_DEFAULT = 'def';
const ACTION_PROTOCOL = 'pro';
private $page_link = '';
private $img_url = '';
private $template_path = '';
private $error = '';
private $message = '';
protected $lang = null;
/**
* Constructor for the backend
*/
public function __construct() {
global $I18n;
$this->page_link = ADMIN_URL . '/admintools/tool.php?tool=tool_confirmation_log';
$this->template_path = LEPTON_PATH . '/modules/' . basename(dirname(__FILE__)) . '/templates/backend/';
$this->img_url = LEPTON_URL . '/modules/' . basename(dirname(__FILE__)) . '/images/';
date_default_timezone_set(CFG_TIME_ZONE);
$this->lang = $I18n;
} // __construct()
/**
* Set $this->error to $error
*
* @param $error STR
*/
protected function setError($error) {
$this->error = $error;
} // setError()
/**
* Get Error from $this->error;
*
* @return STR $this->error
*/
public function getError() {
return $this->error;
} // getError()
/**
* Check if $this->error is empty
*
* @return BOOL
*/
public function isError() {
return (bool) !empty($this->error);
} // isError
/**
* Set $this->message to $message
*
* @param $message STR
*/
protected function setMessage($message) {
$this->message = $message;
} // setMessage()
/**
* Get Message from $this->message;
*
* @return STR $this->message
*/
public function getMessage() {
return $this->message;
} // getMessage()
/**
* Check if $this->message is empty
*
* @return BOOL
*/
public function isMessage() {
return (bool) !empty($this->message);
} // isMessage
/**
* Return Version of Module
*
* @return FLOAT
*/
public function getVersion() {
// read info.php into array
$info_text = file(LEPTON_PATH . '/modules/' . basename(dirname(__FILE__)) . '/info.php');
if ($info_text == false) {
return -1;
}
// walk through array
foreach ($info_text as $item) {
if (strpos($item, '$module_version') !== false) {
// split string $module_version
$value = explode('=', $item);
// return floatval
return floatval(preg_replace('([\'";,\(\)[:space:][:alpha:]])', '', $value[1]));
}
}
return -1;
} // getVersion()
/**
* Load the desired template, execute the template engine and returns the
* resulting template
*
* @param $template STRING the file name of the template
* @param $template_data ARRAY the data for the template
* @return mixed BOOLEAN false or the template
*/
protected function getTemplate($template, $template_data) {
global $parser;
$result = '';
try {
$result = $parser->get($this->template_path . $template, $template_data);
} catch (Exception $e) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__,
$this->lang->translate('<p>Error executing template <b>{{ template }}</b>:</p><p>{{ error }}</p>',
array(
'template' => $template,
'error' => $e->getMessage())
)));
return false;
}
return $result;
} // getTemplate()
/**
* Verhindert XSS Cross Site Scripting
*
* @param $request REFERENCE ARRAY
* @return $request
*/
protected function xssPrevent(&$request) {
if (is_string($request)) {
$request = html_entity_decode($request);
$request = strip_tags($request);
$request = trim($request);
$request = stripslashes($request);
}
return $request;
} // xssPrevent()
/**
* The action handler of the class formBackend
*
* @return string dialog or error message
*/
public function action() {
$html_allowed = array();
foreach ($_REQUEST as $key => $value) {
if (!in_array($key, $html_allowed)) {
$_REQUEST[$key] = $this->xssPrevent($value);
}
}
isset($_REQUEST[self::REQUEST_ACTION]) ? $action = $_REQUEST[self::REQUEST_ACTION] : $action = self::ACTION_DEFAULT;
switch ($action):
case self::ACTION_ABOUT:
$result = $this->show(self::ACTION_ABOUT, $this->dlgAbout());
break;
default :
$result = $this->show(self::ACTION_PROTOCOL, $this->dlgProtocolList());
break;
endswitch;
echo $result;
} // action
/**
* Ausgabe des formatierten Ergebnis mit Navigationsleiste
*
* @param $action aktives Navigationselement
* @param $content Inhalt
* @return STRING $result
*/
protected function show($action, $content) {
$tab_navigation_array = array(
self::ACTION_PROTOCOL => $this->lang->translate('Protocol'),
self::ACTION_ABOUT => $this->lang->translate('About')
);
$navigation = array();
foreach ($tab_navigation_array as $key => $value) {
$navigation[] = array(
'active' => ($key == $action) ? 1 : 0,
'url' => sprintf('%s&%s=%s', $this->page_link, self::REQUEST_ACTION, $key),
'text' => $value
);
}
$data = array(
'navigation' => $navigation,
'error' => ($this->isError()) ? 1 : 0,
'content' => ($this->isError()) ? $this->getError() : $content
);
return $this->getTemplate('backend.body.htt', $data);
} // show()
/**
* Shows an about dialog
*
* @return string dialog
*/
protected function dlgAbout() {
$notes = file_get_contents(LEPTON_PATH . '/modules/' . basename(dirname(__FILE__)) . '/CHANGELOG');
$use_markdown = 0;
if (file_exists(LEPTON_PATH.'/modules/lib_markdown/standard/markdown.php')) {
require_once LEPTON_PATH.'/modules/lib_markdown/standard/markdown.php';
$notes = Markdown($notes);
$use_markdown = 1;
}
$data = array(
'version' => sprintf('%01.2f', $this->getVersion()),
//'img_url' => $this->img_url . '/kit_form_logo_400_267.jpg',
'release' => array(
'number' => $this->getVersion(),
'notes' => $notes,
'use_markdown' => $use_markdown
)
);
return $this->getTemplate('backend.about.htt', $data);
} // dlgAbout()
protected function dlgProtocolList() {
global $database;
$SQL = "SELECT * FROM ".TABLE_PREFIX."mod_confirmation_log ORDER BY `timestamp` DESC";
if (false === ($query = $database->query($SQL))) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $database->get_error()));
return false;
}
$fields = array();
while (false !== ($log = $query->fetchRow(MYSQL_ASSOC))) {
$fields[$log['id']] = array(
'id' => $log['id'],
'page_id' => $log['page_id'],
'second_id' => $log['second_id'],
'page_type' => $this->lang->translate($log['page_type']),
'page_title' => $log['page_title'],
'page_link' => $log['page_link'],
'page_url' => LEPTON_URL.$log['page_link'],
'installation_name' => $log['installation_name'],
'user_name' => (!empty($log['user_name'])) ? $log['user_name'] : $this->lang->translate('- none -'),
'user_email' => (!empty($log['user_email'])) ? $log['user_email'] : $this->lang->translate('- none -'),
'typed_name' => (!empty($log['typed_name'])) ? $log['typed_name'] : $this->lang->translate('- none -'),
'typed_email' => (!empty($log['typed_email'])) ? $log['typed_email'] : $this->lang->translate('- none -'),
'confirmed_at' => $log['confirmed_at'],
'status' => $this->lang->translate($log['status']),
'transmitted_at' => $log['transmitted_at'],
'timestamp' => $log['timestamp']
);
}
$data = array(
'fields' => $fields
);
return $this->getTemplate('backend.log.htt', $data);
} // dlgProtocolList()
}