-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclass.backend.php
More file actions
3268 lines (3125 loc) · 139 KB
/
Copy pathclass.backend.php
File metadata and controls
3268 lines (3125 loc) · 139 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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* kitForm
*
* @author Ralf Hertsch <ralf.hertsch@phpmanufaktur.de>
* @link http://phpmanufaktur.de
* @copyright 2011 - 2013
* @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
if (!defined('LEPTON_PATH'))
require_once WB_PATH.'/modules/'.basename(dirname(__FILE__)).'/wb2lepton.php';
require_once (LEPTON_PATH . '/modules/' . basename(dirname(__FILE__)) . '/initialize.php');
require_once (LEPTON_PATH . '/framework/functions.php');
class formBackend {
const request_action = 'act';
const request_add_free_field = 'aff';
const request_add_kit_field = 'akf';
const request_fields = 'fld';
const request_free_field_title = 'fft';
const request_import_file = 'impf';
const request_import_name = 'impn';
const request_protocol_id = 'pid';
const request_export = 'exp';
const request_move = 'mov';
const request_position = 'pos';
const request_sub_action = 'sub';
const action_about = 'abt';
const action_admin = 'adm';
const action_admin_check_duplicates = 'acd';
const action_admin_check_unpublished_feedback = 'acuf';
const action_admin_delete_protocol_id = 'adpi';
const action_admin_delete_unpublished = 'aduf';
const action_admin_delete_unpublished_kit = 'adufk';
const action_admin_exec_export_form_data = 'aeefd';
const action_admin_remove_duplicates = 'ard';
const action_admin_select_export_form_data = 'asefd';
const action_default = 'def';
const action_edit = 'edt';
const action_edit_check = 'edtc';
const action_import = 'imp';
const action_list = 'lst';
const action_protocol = 'pro';
const action_protocol_id = 'pid';
const action_up = 'up';
const action_down = 'down';
const action_move = 'mov';
private $page_link = '';
private $img_url = '';
private $template_path = '';
private $error = '';
private $message = '';
protected $lang = null;
protected $file_allowed_filetypes = 'jpg,gif,png,pdf,zip';
protected static $table_prefix = TABLE_PREFIX;
protected static $protocol_limit = 100;
public function __construct() {
global $I18n;
$this->page_link = ADMIN_URL . '/admintools/tool.php?tool=kit_form';
$this->template_path = LEPTON_PATH . '/modules/' . basename(dirname(__FILE__)) . '/htt/';
$this->img_url = LEPTON_URL . '/modules/' . basename(dirname(__FILE__)) . '/images/';
date_default_timezone_set(cfg_time_zone);
$this->lang = $I18n;
// use another table prefix or change protocol limit?
if (file_exists(LEPTON_PATH.'/modules/'.basename(dirname(__FILE__)).'/config.json')) {
$config = json_decode(file_get_contents(LEPTON_PATH.'/modules/'.basename(dirname(__FILE__)).'/config.json'), true);
if (isset($config['table_prefix']))
self::$table_prefix = $config['table_prefix'];
if (isset($config['protocol_limit']))
self::$protocol_limit = (int) $config['protocol_limit'];
}
} // __construct()
/**
* Check dependency to to other KIT modules
*
* @return boolean true on success
*/
public function checkDependency() {
// check dependency for KIT
global $PRECHECK;
global $database;
// need the precheck.php
require_once (LEPTON_PATH . '/modules/' . basename(dirname(__FILE__)) . '/precheck.php');
if (isset($PRECHECK['KIT']['kit'])) {
$table = self::$table_prefix . 'addons';
$version = $database->get_one("SELECT `version` FROM $table WHERE `directory`='kit'", MYSQL_ASSOC);
if (!version_compare($version, $PRECHECK['KIT']['kit']['VERSION'], $PRECHECK['KIT']['kit']['OPERATOR'])) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->lang->translate('Error: Please upgrade <b>{{ addon }}</b>, installed is release <b>{{ release }}</b>, needed is release <b>{{ needed }}</b>.', array(
'addon' => 'KeepInTouch',
'release' => $version,
'needed' => $PRECHECK['KIT']['kit']['VERSION']
))));
return false;
}
}
if (file_exists(LEPTON_PATH . '/modules/kit_dirlist/info.php')) {
// check only if kitDirList is installed
if (isset($PRECHECK['KIT']['kit_dirlist'])) {
$table = self::$table_prefix . 'addons';
$version = $database->get_one("SELECT `version` FROM $table WHERE `directory`='kit_dirlist'", MYSQL_ASSOC);
if (!version_compare($version, $PRECHECK['KIT']['kit_dirlist']['VERSION'], $PRECHECK['KIT']['kit_dirlist']['OPERATOR'])) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->lang->translate('Error: Please upgrade <b>{{ addon }}</b>, installed is release <b>{{ release }}</b>, needed is release <b>{{ needed }}</b>.', array(
'addon' => 'kitDirList',
'release' => $version,
'needed' => $PRECHECK['KIT']['kit_dirlist']['VERSION']
))));
return false;
}
}
} // if file_exists()
return true;
} // checkDependency()
/**
* Set $this->error to $error
*
* @param $error STR
*/
protected function setError($error) {
/*
* $debug = debug_backtrace(); $caller = next($debug); $this->error =
* sprintf('[%s::%s - %s] %s', basename($caller['file']),
* $caller['function'], $caller['line'], $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
/**
* Reset Error to empty String
*/
protected function clearError() {
$this->error = '';
}
/**
* 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()
/**
* Return the needed template
*
* @param $template string
* @param $template_data array
*/
protected function getTemplate($template, $template_data, $trigger_error=false) {
global $parser;
$template_path = LEPTON_PATH.'/modules/'.basename(dirname(__FILE__)).'/htt/';
// check if a custom template exists ...
$load_template = (file_exists($template_path.'custom.'.$template)) ? $template_path.'custom.'.$template : $template_path.$template;
try {
$result = $parser->get($load_template, $template_data);
} catch (Exception $e) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->lang->translate(
'Error executing the template <b>{{ template }}</b>: {{ error }}', array(
'template' => basename($load_template),
'error' => $e->getMessage()))));
if ($trigger_error)
trigger_error($this->getError(), E_USER_ERROR);
return false;
}
return $result;
} // getTemplate()
/**
* Converts a byte string from PHP.INI (i.e. 15M) into a integer byte value
*
* @param $value string
* @return integer - byte value
*/
protected function convertBytes($value) {
if (is_numeric($value)) {
return $value;
}
else {
$value_length = strlen($value);
$qty = substr($value, 0, $value_length - 1);
$unit = strtolower(substr($value, $value_length - 1));
switch ($unit) :
case 'k' :
$qty *= 1024;
break;
case 'm' :
$qty *= 1048576;
break;
case 'g' :
$qty *= 1073741824;
break;
endswitch
;
return $qty;
}
} // convertBytes
/**
* 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() {
$this->checkDependency();
$html_allowed = array();
foreach ($_REQUEST as $key => $value) {
if (!in_array($key, $html_allowed)) {
// special
if (strpos($key, 'html_free_') === 0) continue;
$_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;
case self::action_edit :
$result = $this->show(self::action_edit, $this->dlgFormEdit());
break;
case self::action_edit_check :
$result = $this->show(self::action_edit, $this->checkFormEdit());
break;
case self::action_protocol :
$result = $this->show(self::action_protocol, $this->dlgProtocolList());
break;
case self::action_protocol_id :
$result = $this->show(self::action_protocol, $this->dlgProtocolItem());
break;
case self::action_import :
$result = $this->show(self::action_edit, $this->importForm());
break;
case self::action_move :
$result = $this->show(self::action_edit, $this->checkMove());
break;
case self::action_admin:
$sub_action = (isset($_REQUEST[self::request_sub_action])) ? $_REQUEST[self::request_sub_action] : self::action_default;
switch ($sub_action):
case self::action_admin_check_duplicates:
$result = $this->show(self::action_admin, $this->checkDuplicates());
break;
case self::action_admin_remove_duplicates:
$result = $this->show(self::action_admin, $this->removeDuplicates());
break;
case self::action_admin_delete_protocol_id:
$result = $this->show(self::action_protocol, $this->deleteProtocolID());
break;
case self::action_admin_check_unpublished_feedback:
$result = $this->show(self::action_admin, $this->checkUnpublishedFeedback());
break;
case self::action_admin_delete_unpublished:
$result = $this->show(self::action_admin, $this->deleteUnpublishedFeedback(false));
break;
case self::action_admin_delete_unpublished_kit:
$result = $this->show(self::action_admin, $this->deleteUnpublishedFeedback(true));
break;
case self::action_admin_select_export_form_data:
$result = $this->show(self::action_admin, $this->selectExportFormData());
break;
case self::action_admin_exec_export_form_data:
$result = $this->show(self::action_admin, $this->execExportFormData());
break;
default:
$result = $this->show(self::action_admin, $this->dlgAdmin());
break;
endswitch;
break;
case self::action_list :
default :
$result = $this->show(self::action_list, $this->dlgFormList());
break;
endswitch;
echo $result;
} // action
/**
* Ausgabe des formatierten Ergebnis mit Navigationsleiste
*
* @param $action - aktives Navigationselement
* @param $content - Inhalt
* @return ECHO RESULT
*/
protected function show($action, $content) {
$tab_navigation_array = array(
self::action_list => $this->lang->translate('List'),
self::action_edit => $this->lang->translate('Edit'),
self::action_protocol => $this->lang->translate('Protocol'),
self::action_admin => $this->lang->translate('Admin'),
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(
'WB_URL' => LEPTON_URL,
'navigation' => $navigation,
'error' => ($this->isError()) ? 1 : 0,
'content' => ($this->isError()) ? $this->getError() : $content
);
return $this->getTemplate('backend.body.htt', $data);
} // show()
/**
* Check the created or edited form and createor update the database records
* and return the dlgFormEdit() dialog.
*
* @return string dlgFormEdit() or false on error
*/
protected function checkFormEdit() {
global $dbKITform;
global $dbKITformFields;
global $kitContactInterface;
global $dbKITformTableSort;
global $kitLibrary;
$checked = true;
$message = '';
$form_id = isset($_REQUEST[dbKITform::field_id]) ? $_REQUEST[dbKITform::field_id] : -1;
$form_data = $dbKITform->getFields();
unset($form_data[dbKITform::field_timestamp]);
foreach ($form_data as $field => $value) {
switch ($field) :
case dbKITform::field_id :
$form_data[$field] = $form_id;
break;
case dbKITform::field_name :
$form_data[$field] = isset($_REQUEST[$field]) ? $_REQUEST[$field] : '';
if (empty($form_data[$field])) {
$message .= $this->lang->translate('<p>The <b>form name</b> must contain 3 charactes at minimum!</p>');
$checked = false;
break;
}
$name = str_replace(' ', '_', strtolower(media_filename(trim($form_data[$field]))));
$SQL = sprintf("SELECT %s FROM %s WHERE %s='%s' AND %s!='%s'", dbKITform::field_id, $dbKITform->getTableName(), dbKITform::field_name, $name, dbKITform::field_status, dbKITform::status_deleted);
$result = array();
if (!$dbKITform->sqlExec($SQL, $result)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbKITform->getError()));
return false;
}
if (count($result) > 0) {
if (($form_id > 0) && ($result[0][dbKITform::field_id] !== $form_id)) {
// Formular kann nicht umbenannt werden, der
// Bezeichner wird bereits verwendet
$message .= $this->lang->translate('<p>The form name can not changed to <b>{{ name }}</b>, this name is already in use by the form with the <b>ID {{ id }}</b>.</p>', array(
'name' => $name,
'id' => sprintf('%03d', $result[0][dbKITform::field_id])
));
unset($_REQUEST[$field]);
$checked = false;
break;
}
elseif ($form_id < 1) {
// Der Bezeichner wird bereits verwendet
$message .= $this->lang->translate('<p>The name <b>{{ name }}</b> is already in use by the form with the <b>ID {{ id }}</b>, please use another name!</p>', array(
'name' => $name,
'id' => sprintf('%03d', $result[0][dbKITform::field_id])
));
unset($_REQUEST[$field]);
$checked = false;
break;
}
}
$form_data[$field] = $name;
break;
case dbKITform::field_title :
$form_data[$field] = isset($_REQUEST[$field]) ? $_REQUEST[$field] : '';
if (empty($form_data[$field]) || (strlen($form_data[$field]) < 6)) {
$message .= $this->lang->translate('<p>At minimum the form title must be 5 or more characters long!</p>');
$checked = false;
}
break;
case dbKITform::field_action :
case dbKITform::field_description :
case dbKITform::field_fields :
case dbKITform::field_must_fields :
$form_data[$field] = isset($_REQUEST[$field]) ? $_REQUEST[$field] : '';
break;
case dbKITform::field_status :
$form_data[$field] = isset($_REQUEST[$field]) ? $_REQUEST[$field] : dbKITform::status_locked;
if ($form_data[$field] == dbKITform::status_deleted) {
// Formular loeschen
$where = array(
dbKITform::field_id => $form_id
);
if (!$dbKITform->sqlDeleteRecord($where)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbKITform->getError()));
return false;
}
// Formular Items loeschen
$where = array(
dbKITformFields::field_form_id => $form_id
);
if (!$dbKITformFields->sqlDeleteRecord($where)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbKITform->getError()));
return false;
}
// es gibt nichts mehr zu tun, zurueck zur
// Uebersichtsliste
$this->lang->translate('<p>The form with the <b>ID {{ id }}</b> was successfully deleted.</p>', array(
'id' => sprintf('%03d', $form_id)
));
return $this->dlgFormList();
}
break;
case dbKITform::field_provider_id :
$form_data[$field] = isset($_REQUEST[$field]) ? $_REQUEST[$field] : -1;
if ($form_data[$field] == -1) {
// kein Diensleister ausgewaehlt
$message .= $this->lang->translate('<p>Please select a service provider for this form!</p>');
$checked = false;
}
break;
case dbKITform::field_email_cc :
$cc = isset($_REQUEST[$field]) ? $_REQUEST[$field] : '';
if (!empty($cc)) {
// CC Adressen auslesen
$cc_arr = explode(',', $cc);
$new_arr = array();
foreach ($cc_arr as $email) {
if (!$kitLibrary->validateEMail(trim($email))) {
$message .= $this->lang->translate('<p>The email address <b>{{ email }}</b> is not valid, please check your input.</p>', array(
'email' => $email
));
$checked = false;
}
$new_arr[] = trim($email);
}
$cc = implode(',', $new_arr);
}
$form_data[$field] = $cc;
break;
case dbKITform::field_email_html :
$form_data[$field] = isset($_REQUEST[$field]) ? $_REQUEST[$field] : dbKITform::html_off;
break;
case dbKITform::field_captcha :
$form_data[$field] = isset($_REQUEST[$field]) ? $_REQUEST[$field] : dbKITform::captcha_on;
break;
default :
// uebrige Felder ueberspringen
break;
endswitch
;
}
// Action Links pruefen
$links = array();
foreach ($dbKITform->action_array as $key => $text) {
if (isset($_REQUEST[$key])) $links[$key] = $_REQUEST[$key];
}
// ... und uebernehmen
$form_data[dbKITform::field_links] = http_build_query($links);
// pruefen ob ein Feld entfernt werden soll oder ob Felder als
// Pflichtfelder gesetzt werden sollen
$fields = explode(',', $form_data[dbKITform::field_fields]);
$must_fields = explode(',', $form_data[dbKITform::field_must_fields]);
foreach ($fields as $key => $value) {
if ($value < 100) {
// KIT Felder
$field_name = array_search($value, $kitContactInterface->index_array);
if (!isset($_REQUEST[$field_name])) {
$message .= $this->lang->translate('<p>The datafield <b>{{ field }}</b> was removed.</p>', array(
'field' => $kitContactInterface->field_array[$field_name]
));
unset($fields[$key]);
}
if (isset($_REQUEST['must_' . $field_name]) && !in_array($value, $must_fields)) {
$must_fields[] = $value;
}
}
else {
// allgemeine Felder
$further_check = true;
$where = array(
dbKITformFields::field_id => $value
);
$data = array();
if (!$dbKITformFields->sqlSelectRecord($where, $data)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbKITformFields->getError()));
return false;
}
if (count($data) < 1) {
continue;
/**
*
* @todo continue instead prompting error is only a workaround!
*/
// $this->setError(sprintf('[%s - %s] %s', __METHOD__,
// __LINE__, kit_error_invalid_id));
// return false;
}
$data = $data[0];
$field_name = $data[dbKITformFields::field_name];
$field_id = $data[dbKITformFields::field_id];
if (!isset($_REQUEST[$field_name])) {
// Feld entfernen
$message .= $this->lang->translate('<p>The datafield <b>{{ field }}</b> was removed.</p>', array(
'field' => $field_name
));
unset($fields[$key]);
$further_check = false;
// Tabelle aktualisieren
$where = array(
dbKITformFields::field_id => $field_id
);
if (!$dbKITformFields->sqlDeleteRecord($where)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbKITformFields->getError()));
return false;
}
}
if (isset($_REQUEST["must_$field_name"]) && !in_array($value, $must_fields)) {
$must_fields[] = $value;
}
if ($further_check) {
// erweiterte Pruefung der Felder in Abhaenigkeit des Feld
// Typen
switch ($data[dbKITformFields::field_type]) :
case dbKITformFields::type_text :
// Einfache Text Eingabefelder pruefen
$field_data = array(
dbKITformFields::field_name => (isset($_REQUEST['name_' . $field_name])) ? $_REQUEST['name_' . $field_name] : 'free_' . $field_id,
dbKITformFields::field_title => (isset($_REQUEST['title_' . $field_name])) ? $_REQUEST['title_' . $field_name] : 'title_' . $field_id,
dbKITformFields::field_value => (isset($_REQUEST['default_' . $field_name])) ? $_REQUEST['default_' . $field_name] : '',
dbKITformFields::field_data_type => (isset($_REQUEST['data_type_' . $field_name])) ? $_REQUEST['data_type_' . $field_name] : dbKITformFields::data_type_text,
dbKITformFields::field_hint => (isset($_REQUEST['hint_' . $field_name])) ? $_REQUEST['hint_' . $field_name] : ''
);
$where = array(
dbKITformFields::field_id => $field_id
);
if (!$dbKITformFields->sqlUpdateRecord($field_data, $where)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbKITformFields->getError()));
return false;
}
break;
case dbKITformFields::type_text_area :
// textarea pruefen
// first we have to check the additional settings for count and limit characters
$additional = array();
if (isset($_REQUEST["limit_chars_$field_name"])) {
if (intval($_REQUEST["limit_chars_$field_name"]) > 65534)
$additional['limit_chars'] = 65534;
elseif (intval($_REQUEST["limit_chars_$field_name"]) < 1)
$additional['limit_chars'] = -1;
else
$additional['limit_chars'] = intval($_REQUEST["limit_chars_$field_name"]);
}
else {
$additional['limit_chars'] = -1;
}
if (($additional['limit_chars'] > -1) || isset($_REQUEST["count_chars_$field_name"]))
$additional['count_chars'] = 1;
else
$additional['count_chars'] = 0;
$field_data = array(
dbKITformFields::field_name => (isset($_REQUEST['name_' . $field_name])) ? $_REQUEST['name_' . $field_name] : 'free_' . $field_id,
dbKITformFields::field_title => (isset($_REQUEST['title_' . $field_name])) ? $_REQUEST['title_' . $field_name] : 'title_' . $field_id,
dbKITformFields::field_value => (isset($_REQUEST['default_' . $field_name])) ? $_REQUEST['default_' . $field_name] : '',
dbKITformFields::field_data_type => dbKITformFields::data_type_text,
dbKITformFields::field_hint => (isset($_REQUEST['hint_' . $field_name])) ? $_REQUEST['hint_' . $field_name] : '',
dbKITformFields::field_type_add => http_build_query($additional)
);
$where = array(
dbKITformFields::field_id => $field_id
);
if (!$dbKITformFields->sqlUpdateRecord($field_data, $where)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbKITformFields->getError()));
return false;
}
break;
case dbKITformFields::type_file :
// FILE Type
$settings = array();
$parse = str_replace('&', '&', $data[dbKITformFields::field_type_add]);
parse_str($parse, $settings);
$upload_max_filesize = $this->convertBytes(ini_get('upload_max_filesize'));
$post_max_size = $this->convertBytes(ini_get('post_max_size'));
$max_filesize = $upload_max_filesize;
if ($upload_max_filesize > $post_max_size) $max_filesize = $post_max_size;
// check if the field NAME has changed ...
if ($settings['upload_method']['name'] != "upload_method_$field_name") {
$settings['upload_method']['name'] = "upload_method_$field_name";
$settings['file_types']['name'] = "file_types_$field_name";
$settings['max_file_size']['name'] = "max_file_size_$field_name";
}
// update settings ...
if (isset($_REQUEST["upload_method_$field_name"])) {
// check the upload method
$dummy = strtolower($_REQUEST["upload_method_$field_name"]);
switch ($dummy) :
case 'standard' :
$settings['upload_method']['value'] = 'standard';
break;
case 'uploadify' :
if (!file_exists(LEPTON_PATH . '/modules/kit_uploader/info.php')) {
// missing kitUploader
$message .= $this->lang->translate('<p>To use the upload method <b>uploadify</b> kitUploader must be installed!</p>');
$settings['upload_method']['value'] = 'standard';
break;
}
$settings['upload_method']['value'] = 'uploadify';
break;
default :
$checked = false;
$message .= $this->lang->translate('<p>Unknown upload method: <b>{{ method }}</b>, allowed methods are <i>standard</i> or <i>uploadify</i>.</p>', array(
'method' => $dummy
));
$settings['upload_method']['value'] = 'standard';
break;
endswitch
;
}
else {
$settings['upload_method']['value'] = 'standard';
}
if (isset($_REQUEST["file_types_$field_name"])) {
// set allowed file extensions, grant lowercase
// and remove spaces
$dummy = strtolower($_REQUEST["file_types_$field_name"]);
$dummy = str_replace(' ', '', $dummy);
$settings['file_types']['value'] = $dummy;
}
else {
$settings['file_types']['value'] = $this->file_allowed_filetypes;
}
if (isset($_REQUEST["max_file_size_$field_name"])) {
$max = (int) $_REQUEST["max_file_size_$field_name"];
if (($max * 1024 * 1024) > $max_filesize) {
$max = ($max_filesize / 1024 / 1024);
$message .= $this->lang->translate('<p>System does not allow uploads greater than <b>{{ max_filesize }} MB</b>. Please contact your webmaster to increase this value.</p>', array(
'max_filesize' => $max_filesize / 1024 / 1024
));
}
$settings['max_file_size']['value'] = $max;
}
else {
$settings['max_file_size']['value'] = $max_filesize / 1024 / 1024;
}
$field_data = array(
dbKITformFields::field_name => (isset($_REQUEST['name_' . $field_name])) ? $_REQUEST['name_' . $field_name] : 'free_' . $field_id,
dbKITformFields::field_title => (isset($_REQUEST['title_' . $field_name])) ? $_REQUEST['title_' . $field_name] : 'title_' . $field_id,
dbKITformFields::field_value => '',
dbKITformFields::field_data_type => dbKITformFields::data_type_undefined,
dbKITformFields::field_hint => (isset($_REQUEST['hint_' . $field_name])) ? $_REQUEST['hint_' . $field_name] : '',
dbKITformFields::field_type_add => http_build_query($settings)
);
$where = array(
dbKITformFields::field_id => $field_id
);
if (!$dbKITformFields->sqlUpdateRecord($field_data, $where)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbKITformFields->getError()));
return false;
}
break;
case dbKITformFields::type_checkbox :
// CHECKBOX pruefen
$cboxes = array();
$parse = str_replace('&', '&', $data[dbKITformFields::field_type_add]);
parse_str($parse, $cboxes);
$checkboxes = array();
foreach ($cboxes as $checkbox) {
$cb_name = $checkbox['name'];
if (!isset($_REQUEST['cb_active_' . $cb_name])) {
continue;
}
if (!empty($_REQUEST['cb_value_' . $cb_name])) $checkbox['value'] = $_REQUEST['cb_value_' . $cb_name];
if (!empty($_REQUEST['cb_text_' . $cb_name])) $checkbox['text'] = $_REQUEST['cb_text_' . $cb_name];
$checkbox['checked'] = (isset($_REQUEST['cb_checked_' . $cb_name])) ? 1 : 0;
$checkboxes[] = $checkbox;
}
// neue Checkboxen dazunehmen
if (isset($_REQUEST['cb_active_' . $field_id])) {
// es soll eine neue Checkbox uebernommen werden
if (isset($_REQUEST['cb_value_' . $field_id]) && !empty($_REQUEST['cb_value_' . $field_id]) && isset($_REQUEST['cb_text_' . $field_id]) && !empty($_REQUEST['cb_text_' . $field_id])) {
// ok - checkbox uebernehmen
$value = str_replace(' ', '_', strtolower(media_filename($_REQUEST['cb_value_' . $field_id])));
$checkboxes[] = array(
'name' => $field_id . '_' . $value,
'value' => $value,
'text' => $_REQUEST['cb_text_' . $field_id],
'checked' => isset($_REQUEST['cb_checked_' . $field_id]) ? 1 : 0
);
}
else {
// Definition der Checkbox ist nicht
// vollstaendig
$message .= $this->lang->translate('<p>The definition of the new checkbox is not complete. Please specify a <b>value</b> and a <b>text</b> for it!</p>');
}
}
// allgemeine Daten der Checkbox pruefen
$field_data = array(
dbKITformFields::field_name => (isset($_REQUEST['name_' . $field_name])) ? $_REQUEST['name_' . $field_name] : 'free_' . $field_id,
dbKITformFields::field_title => (isset($_REQUEST['title_' . $field_name])) ? $_REQUEST['title_' . $field_name] : 'title_' . $field_id,
dbKITformFields::field_value => (isset($_REQUEST['default_' . $field_name])) ? $_REQUEST['default_' . $field_name] : '',
dbKITformFields::field_data_type => dbKITformFields::data_type_undefined,
dbKITformFields::field_hint => (isset($_REQUEST['hint_' . $field_name])) ? $_REQUEST['hint_' . $field_name] : '',
dbKITformFields::field_type_add => http_build_query($checkboxes)
);
$where = array(
dbKITformFields::field_id => $field_id
);
if (!$dbKITformFields->sqlUpdateRecord($field_data, $where)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbKITformFields->getError()));
return false;
}
break;
case dbKITformFields::type_radio :
// RADIOBUTTON pruefen
$rbuttons = array();
$parse = str_replace('&', '&', $data[dbKITformFields::field_type_add]);
parse_str($parse, $rbuttons);
$radios = array();
foreach ($rbuttons as $radio) {
$rb_name = $radio['name'];
if (!isset($_REQUEST['rb_active_' . $rb_name])) continue;
if (!empty($_REQUEST['rb_value_' . $rb_name])) $radio['value'] = $_REQUEST['rb_value_' . $rb_name];
if (!empty($_REQUEST['rb_text_' . $rb_name])) $radio['text'] = $_REQUEST['rb_text_' . $rb_name];
$radio['checked'] = (isset($_REQUEST['rb_checked_' . $field_name]) && ($_REQUEST['rb_checked_' . $field_name] == $radio['value'])) ? 1 : 0;
$radios[] = $radio;
}
// neuen Radiobutton dazunehmen
if (isset($_REQUEST['rb_active_' . $field_id])) {
// es soll eine neuer Radio uebernommen werden
if (isset($_REQUEST['rb_value_' . $field_id]) && !empty($_REQUEST['rb_value_' . $field_id]) && isset($_REQUEST['rb_text_' . $field_id]) && !empty($_REQUEST['rb_text_' . $field_id])) {
// ok - radiobutton uebernehmen
$value = str_replace(' ', '_', strtolower(media_filename($_REQUEST['rb_value_' . $field_id])));
$radios[] = array(
'name' => $field_id . '_' . $value,
'value' => $value,
'text' => $_REQUEST['rb_text_' . $field_id],
'checked' => 0
);
}
else {
// Definition der Checkbox ist nicht
// vollstaendig
$message .= $this->lang->translate('<p>The definition of the new radiobutton is not complete. Please specify a <b>value</b> and a <b>text</b> for it!</p>');
}
}
// allgemeine Daten der Radiobuttons pruefen
$field_data = array(
dbKITformFields::field_name => (isset($_REQUEST['name_' . $field_name])) ? $_REQUEST['name_' . $field_name] : 'free_' . $field_id,
dbKITformFields::field_title => (isset($_REQUEST['title_' . $field_name])) ? $_REQUEST['title_' . $field_name] : 'title_' . $field_id,
dbKITformFields::field_value => (isset($_REQUEST['default_' . $field_name])) ? $_REQUEST['default_' . $field_name] : '',
dbKITformFields::field_data_type => dbKITformFields::data_type_undefined,
dbKITformFields::field_hint => (isset($_REQUEST['hint_' . $field_name])) ? $_REQUEST['hint_' . $field_name] : '',
dbKITformFields::field_type_add => http_build_query($radios)
);
$where = array(
dbKITformFields::field_id => $field_id
);
if (!$dbKITformFields->sqlUpdateRecord($field_data, $where)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbKITformFields->getError()));
return false;
}
break;
case dbKITformFields::type_select :
// SELECT Auswahlliste pruefen
$sOptions = array();
$parse = str_replace('&', '&', $data[dbKITformFields::field_type_add]);
parse_str($parse, $sOptions);
$options = array();
foreach ($sOptions as $option) {
$opt_name = $option['name'];
if (!isset($_REQUEST['opt_active_' . $opt_name])) continue;
if (!empty($_REQUEST['opt_value_' . $opt_name])) $option['value'] = $_REQUEST['opt_value_' . $opt_name];
if (!empty($_REQUEST['opt_text_' . $opt_name])) $option['text'] = $_REQUEST['opt_text_' . $opt_name];
$option['checked'] = (isset($_REQUEST['opt_checked_' . $field_name]) && ($_REQUEST['opt_checked_' . $field_name] == $option['value'])) ? 1 : 0;
$options[] = $option;
}
// neues Auswahlfeld dazunehmen
if (isset($_REQUEST['opt_active_' . $field_id])) {
// es soll eine neuer OPTION Eintrag uebernommen
// werden
if (isset($_REQUEST['opt_value_' . $field_id]) && !empty($_REQUEST['opt_value_' . $field_id]) && isset($_REQUEST['opt_text_' . $field_id]) && !empty($_REQUEST['opt_text_' . $field_id])) {
// ok - OPTION uebernehmen
$value = str_replace(' ', '_', strtolower(media_filename($_REQUEST['opt_value_' . $field_id])));
$options[] = array(
'name' => $field_id . '_' . $value,
'value' => $value,
'text' => $_REQUEST['opt_text_' . $field_id],
'checked' => 0
);
}
else {
// Definition der Auswahlliste ist nicht
// vollstaendig
$message .= $this->lang->translate('<p>The definition of the new selection list is not complete. Please specify a <b>value</b> and a <b>text</b> for it!</p>');
}
}
// allgemeine Daten der Auswahlliste pruefen
$field_data = array(
dbKITformFields::field_name => (isset($_REQUEST['name_' . $field_name])) ? $_REQUEST['name_' . $field_name] : 'free_' . $field_id,
dbKITformFields::field_title => (isset($_REQUEST['title_' . $field_name])) ? $_REQUEST['title_' . $field_name] : 'title_' . $field_id,
dbKITformFields::field_value => (isset($_REQUEST['size_' . $field_name])) ? $_REQUEST['size_' . $field_name] : '1',
dbKITformFields::field_data_type => dbKITformFields::data_type_undefined,
dbKITformFields::field_hint => (isset($_REQUEST['hint_' . $field_name])) ? $_REQUEST['hint_' . $field_name] : '',
dbKITformFields::field_type_add => http_build_query($options)
);
$where = array(
dbKITformFields::field_id => $field_id
);
if (!$dbKITformFields->sqlUpdateRecord($field_data, $where)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbKITformFields->getError()));
return false;
}
break;
case dbKITformFields::type_html :
// Daten fuer das HTML Feld pruefen
$field_data = array(
dbKITformFields::field_name => (isset($_REQUEST['name_' . $field_name])) ? $_REQUEST['name_' . $field_name] : 'free_' . $field_id,
dbKITformFields::field_title => (isset($_REQUEST['title_' . $field_name])) ? $_REQUEST['title_' . $field_name] : 'title_' . $field_id,
dbKITformFields::field_value => (isset($_REQUEST['html_' . $field_name])) ? $_REQUEST['html_' . $field_name] : '',
dbKITformFields::field_hint => (isset($_REQUEST['hint_' . $field_name])) ? $_REQUEST['hint_' . $field_name] : '',
dbKITformFields::field_data_type => dbKITformFields::data_type_text
);
$where = array(
dbKITformFields::field_id => $field_id
);
if (!$dbKITformFields->sqlUpdateRecord($field_data, $where)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbKITformFields->getError()));
return false;
}
break;
case dbKITformFields::type_hidden :
// Daten fuer versteckte Felder pruefen
$field_data = array(
dbKITformFields::field_name => (isset($_REQUEST['name_' . $field_name])) ? $_REQUEST['name_' . $field_name] : 'free_' . $field_id,
dbKITformFields::field_title => (isset($_REQUEST['title_' . $field_name])) ? $_REQUEST['title_' . $field_name] : 'title_' . $field_id,
dbKITformFields::field_value => (isset($_REQUEST['value_' . $field_name])) ? $_REQUEST['value_' . $field_name] : '',
dbKITformFields::field_data_type => dbKITformFields::data_type_text
);
$where = array(
dbKITformFields::field_id => $field_id
);
if (!$dbKITformFields->sqlUpdateRecord($field_data, $where)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbKITformFields->getError()));
return false;
}
break;
case dbKITformFields::type_delayed :
// check the data for delayed transmissions
$type_add = array();
if (isset($_REQUEST['text_' . $field_name])) {
$type_add = array(
'text' => $_REQUEST['text_' . $field_name]
);
}
$field_data = array(
dbKITformFields::field_name => dbKITformFields::kit_delayed_transmission,
dbKITformFields::field_title => (isset($_REQUEST['title_' . $field_name])) ? $_REQUEST['title_' . $field_name] : 'title_' . $field_id,
dbKITformFields::field_value => 1,
dbKITformFields::field_data_type => dbKITformFields::data_type_integer,
dbKITformFields::field_hint => (isset($_REQUEST['hint_' . $field_name])) ? $_REQUEST['hint_' . $field_name] : '',
dbKITformFields::field_type_add => http_build_query($type_add)
);
$where = array(
dbKITformFields::field_id => $field_id
);
if (!$dbKITformFields->sqlUpdateRecord($field_data, $where)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbKITformFields->getError()));
return false;
}
break;
default :
$message .= $this->lang->translate('<p>The datatype {{ datatype }} is not supported!</p>', array(
'datatype' => $data[dbKITformFields::field_type]
));
endswitch
;
}
}
}
$form_data[dbKITform::field_fields] = implode(',', $fields);
// pruefen ob Pflichtfelder zurueckgestuft werden sollen
foreach ($must_fields as $key => $value) {