-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclass.config.php
More file actions
374 lines (348 loc) · 11.7 KB
/
Copy pathclass.config.php
File metadata and controls
374 lines (348 loc) · 11.7 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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
<?php
/**
* dbMultipleChoice
*
* @author Ralf Hertsch <ralf.hertsch@phpmanufaktur.de>
* @link https://phpmanufaktur.de
* @copyright 2010 - 2013 phpManufaktur by Ralf Hertsch
* @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
class dbMultipleChoiceCfg extends dbConnectLE {
const field_id = 'cfg_id';
const field_name = 'cfg_name';
const field_type = 'cfg_type';
const field_value = 'cfg_value';
const field_label = 'cfg_label';
const field_description = 'cfg_desc';
const field_status = 'cfg_status';
const field_update_by = 'cfg_update_by';
const field_update_when = 'cfg_update_when';
const status_active = 1;
const status_deleted = 0;
const type_undefined = 0;
const type_array = 7;
const type_boolean = 1;
const type_email = 2;
const type_float = 3;
const type_integer = 4;
const type_path = 5;
const type_string = 6;
const type_url = 8;
public $type_array = array(
self::type_undefined => '-UNDEFINED-',
self::type_array => 'ARRAY',
self::type_boolean => 'BOOLEAN',
self::type_email => 'E-MAIL',
self::type_float => 'FLOAT',
self::type_integer => 'INTEGER',
self::type_path => 'PATH',
self::type_string => 'STRING',
self::type_url => 'URL'
);
private $createTables = false;
private $message = '';
const cfgDeveloperMode = 'cfgDeveloperMode';
const cfgMaxItems = 'cfgMaxItems';
const cfgMinItems = 'cfgMinItems';
const cfgGroups = 'cfgGroups';
const cfgPreselectHTML = 'cfgPreselectHTML';
const cfgRememberQuestion = 'cfgRememberQuestion';
public $config_array = array(
//array('kit_label_cfg_developer_mode', self::cfgDeveloperMode, self::type_boolean, 0, 'kit_desc_cfg_developer_mode'),
array('mc_label_cfg_max_items', self::cfgMaxItems, self::type_integer, 5, 'mc_desc_cfg_max_items'),
array('mc_label_cfg_min_items', self::cfgMinItems, self::type_integer, 3, 'mc_desc_cfg_min_items'),
array('mc_label_cfg_groups', self::cfgGroups, self::type_array, 'Default', 'mc_desc_cfg_groups'),
array('mc_label_cfg_preselect_html', self::cfgPreselectHTML, self::type_boolean, 0, 'mc_desc_cfg_preselect_html'),
array('mc_label_cfg_remember_question', self::cfgRememberQuestion, self::type_boolean, 0, 'mc_desc_cfg_remember_question')
);
protected static $config_file = 'config.json';
protected static $table_prefix = TABLE_PREFIX;
public function __construct($createTables = false) {
$this->createTables = $createTables;
// use another table prefix?
if (file_exists(WB_PATH.'/modules/'.basename(dirname(__FILE__)).'/config.json')) {
$config = json_decode(file_get_contents(WB_PATH.'/modules/'.basename(dirname(__FILE__)).'/config.json'), true);
if (isset($config['table_prefix']))
self::$table_prefix = $config['table_prefix'];
}
parent::__construct();
$this->setTablePrefix(self::$table_prefix);
$this->setTableName('mod_mc_config');
$this->addFieldDefinition(self::field_id, "INT(11) NOT NULL AUTO_INCREMENT", true);
$this->addFieldDefinition(self::field_name, "VARCHAR(32) NOT NULL DEFAULT ''");
$this->addFieldDefinition(self::field_type, "TINYINT UNSIGNED NOT NULL DEFAULT '".self::type_undefined."'");
$this->addFieldDefinition(self::field_value, "VARCHAR(255) NOT NULL DEFAULT ''", false, false, true);
$this->addFieldDefinition(self::field_label, "VARCHAR(64) NOT NULL DEFAULT 'UNDEFINED'");
$this->addFieldDefinition(self::field_description, "VARCHAR(255) NOT NULL DEFAULT 'UNDEFINED'");
$this->addFieldDefinition(self::field_status, "TINYINT UNSIGNED NOT NULL DEFAULT '".self::status_active."'");
$this->addFieldDefinition(self::field_update_by, "VARCHAR(32) NOT NULL DEFAULT 'SYSTEM'");
$this->addFieldDefinition(self::field_update_when, "DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'");
$this->setIndexFields(array(self::field_name));
$this->checkFieldDefinitions();
// Tabelle erstellen
if ($this->createTables) {
if (!$this->sqlTableExists()) {
if (!$this->sqlCreateTable()) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
}
}
}
// Default Werte garantieren
if ($this->sqlTableExists()) {
$this->checkConfig();
}
// important: switch decoding OFF.
$this->setDecodeSpecialChars(false);
} // __construct()
public 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
/**
* Aktualisiert den Wert $new_value des Datensatz $name
*
* @param $new_value STR - Wert, der uebernommen werden soll
* @param $id INT - ID des Datensatz, dessen Wert aktualisiert werden soll
*
* @return BOOL Ergebnis
*
*/
public function setValueByName($new_value, $name) {
$where = array();
$where[self::field_name] = $name;
$config = array();
if (!$this->sqlSelectRecord($where, $config)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
return false;
}
if (sizeof($config) < 1) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, sprintf(mc_error_cfg_name, $name)));
return false;
}
return $this->setValue($new_value, $config[0][self::field_id]);
} // setValueByName()
/**
* Haengt einen Slash an das Ende des uebergebenen Strings
* wenn das letzte Zeichen noch kein Slash ist
*
* @param STR $path
* @return STR
*/
public function addSlash($path) {
$path = substr($path, strlen($path)-1, 1) == "/" ? $path : $path."/";
return $path;
}
/**
* Wandelt einen String in einen Float Wert um.
* Geht davon aus, dass Dezimalzahlen mit ',' und nicht mit '.'
* eingegeben wurden.
*
* @param STR $string
* @return FLOAT
*/
public function str2float($string) {
$string = str_replace('.', '', $string);
$string = str_replace(',', '.', $string);
$float = floatval($string);
return $float;
}
public function str2int($string) {
$string = str_replace('.', '', $string);
$string = str_replace(',', '.', $string);
$int = intval($string);
return $int;
}
/**
* Ueberprueft die uebergebene E-Mail Adresse auf logische Gueltigkeit
*
* @param STR $email
* @return BOOL
*/
public function validateEMail($email) {
if(preg_match("/^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$/i", $email)) {
return true; }
else {
return false; }
}
/**
* Aktualisiert den Wert $new_value des Datensatz $id
*
* @param $new_value STR - Wert, der uebernommen werden soll
* @param $id INT - ID des Datensatz, dessen Wert aktualisiert werden soll
*
* @return BOOL Ergebnis
*/
public function setValue($new_value, $id) {
$value = '';
$where = array();
$where[self::field_id] = $id;
$config = array();
if (!$this->sqlSelectRecord($where, $config)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
return false;
}
if (sizeof($config) < 1) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, sprintf(mc_error_cfg_id, $id)));
return false;
}
$config = $config[0];
switch ($config[self::field_type]):
case self::type_array:
// Funktion geht davon aus, dass $value als STR uebergeben wird!!!
$worker = explode(",", $new_value);
$data = array();
foreach ($worker as $item) {
$data[] = trim($item);
};
$value = implode(",", $data);
break;
case self::type_boolean:
$value = (bool) $new_value;
$value = (int) $value;
break;
case self::type_email:
if ($this->validateEMail($new_value)) {
$value = trim($new_value);
}
else {
$this->setMessage(sprintf(mc_msg_invalid_email, $new_value));
return false;
}
break;
case self::type_float:
$value = $this->str2float($new_value);
break;
case self::type_integer:
$value = $this->str2int($new_value);
break;
case self::type_url:
case self::type_path:
$value = $this->addSlash(trim($new_value));
break;
case self::type_string:
$value = (string) trim($new_value);
// Hochkommas demaskieren
$value = str_replace('"', '"', $value);
break;
endswitch;
unset($config[self::field_id]);
$config[self::field_value] = (string) $value;
$config[self::field_update_by] = isset($_SESSION['DISPLAY_NAME']) ? $_SESSION['DISPLAY_NAME'] : 'SYSTEM';
$config[self::field_update_when] = date('Y-m-d H:i:s');
if (!$this->sqlUpdateRecord($config, $where)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
return false;
}
return true;
} // setValue()
/**
* Gibt den angeforderten Wert zurueck
*
* @param $name - Bezeichner
*
* @return WERT entsprechend des TYP
*/
public function getValue($name) {
$result = '';
$where = array();
$where[self::field_name] = $name;
$config = array();
if (!$this->sqlSelectRecord($where, $config)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
return false;
}
if (sizeof($config) < 1) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, sprintf(mc_error_cfg_name, $name)));
return false;
}
$config = $config[0];
switch ($config[self::field_type]):
case self::type_array:
$result = explode(",", $config[self::field_value]);
break;
case self::type_boolean:
$result = (bool) $config[self::field_value];
break;
case self::type_email:
case self::type_path:
case self::type_string:
case self::type_url:
$result = (string) utf8_decode($config[self::field_value]);
break;
case self::type_float:
$result = (float) $config[self::field_value];
break;
case self::type_integer:
$result = (integer) $config[self::field_value];
break;
default:
$result = utf8_decode($config[self::field_value]);
break;
endswitch;
return $result;
} // getValue()
public function checkConfig() {
foreach ($this->config_array as $item) {
$where = array();
$where[self::field_name] = $item[1];
$check = array();
if (!$this->sqlSelectRecord($where, $check)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
return false;
}
if (sizeof($check) < 1) {
// Eintrag existiert nicht
$data = array();
$data[self::field_label] = $item[0];
$data[self::field_name] = $item[1];
$data[self::field_type] = $item[2];
$data[self::field_value] = $item[3];
$data[self::field_description] = $item[4];
$data[self::field_update_when] = date('Y-m-d H:i:s');
$data[self::field_update_by] = 'SYSTEM';
if (!$this->sqlInsertRecord($data)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->getError()));
return false;
}
}
}
return true;
}
} // class dbKITcfg
?>