-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.backend.php
2396 lines (2233 loc) · 90.5 KB
/
class.backend.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
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
/**
* kitEvent
*
* @author Team phpManufaktur <[email protected]>
* @link https://addons.phpmanufaktur.de/kitEvent
* @copyright 2011 Ralf Hertsch <[email protected]>
* @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
require_once (WB_PATH . '/modules/' . basename(dirname(__FILE__)) . '/initialize.php');
require_once (WB_PATH . '/modules/perma_link/class.interface.php');
require_once (WB_PATH . '/modules/' . basename(dirname(__FILE__)) . '/include/ical/iCalcreator.class.php');
require_once (WB_PATH . '/modules/' . basename(dirname(__FILE__)) . '/include/qrcode/qrlib.php');
require_once (WB_PATH . '/framework/functions-utf8.php');
require_once LEPTON_PATH.'/modules/manufaktur_config/class.dialog.php';
require_once LEPTON_PATH.'/modules/manufaktur_config/library.php';
global $manufakturConfig;
if (!is_object($manufakturConfig))
$manufakturConfig = new manufakturConfig('kit_event');
require_once LEPTON_PATH.'/modules/kit/class.interface.php';
global $kitContactInterface;
class eventBackend {
const REQUEST_ACTION = 'kea';
const REQUEST_SUB_ACTION = 'sub';
const REQUEST_ITEMS = 'its';
const REQUEST_TIME_START = 'ets';
const REQUEST_TIME_END = 'ete';
const REQUEST_SUGGESTION = 'sgg';
const REQUEST_SHOW_ALL = 'sa';
const REQUEST_COPY_ALL = 'ca';
const REQUEST_EVENT_GROUP = 'egrp';
const ACTION_ABOUT = 'abt';
const ACTION_CONFIG = 'cfg';
const ACTION_DEFAULT = 'def';
const ACTION_DELETE = 'del';
const ACTION_EDIT = 'edt';
const ACTION_EDIT_CHECK = 'edtc';
const ACTION_GROUP = 'grp';
const ACTION_GROUP_CHECK = 'grpc';
const ACTION_LIST = 'lst';
const ACTION_MESSAGES = 'msg';
const ACTION_MESSAGES_DETAIL = 'msgd';
const ACTION_SETTINGS = 'set';
const ACTION_KIT = 'kit';
const ACTION_CHECK_SUGGEST = 'sugc';
// needed for permaLink - must be similiar to the const in class.frontend.php!
const REQUEST_EVENT = 'evt';
const REQUEST_EVENT_DETAIL = 'det';
const REQUEST_EVENT_ID = 'id';
const ACTION_EVENT = 'evt';
const VIEW_ID = 'id';
private static $tab_navigation_array = array(
self::ACTION_LIST => 'TAB_LIST',
self::ACTION_EDIT => 'TAB_EDIT',
self::ACTION_MESSAGES => 'TAB_MESSAGES',
self::ACTION_KIT => 'KeepInTouch',
self::ACTION_SETTINGS => 'Settings',
self::ACTION_ABOUT => 'TAB_ABOUT',
);
private static $page_link = '';
private static $img_url = '';
private static $template_path = '';
private static $template_url = '';
private static $error = '';
private static $message = '';
// configuration values
protected static $cfgICalDir = null;
protected static $cfgICalCreate = null;
protected static $cfgPermaLinkCreate = null;
protected static $cfgQRCodeDir = null;
protected static $cfgQRCodeCreate = null;
protected static $cfgQRCodeSize = null;
protected static $cfgQRCodeECLevel = null;
protected static $cfgQRCodeMargin = null;
protected static $cfgQRCodeContent = null;
protected static $cfgDescriptionLong = null;
protected static $cfgDescriptionShort = null;
protected static $cfgFreeFieldLabel_1 = null;
protected static $cfgFreeFieldUseHTML_1 = null;
protected static $cfgFreeFieldLabel_2 = null;
protected static $cfgFreeFieldUseHTML_2 = null;
protected static $cfgFreeFieldLabel_3 = null;
protected static $cfgFreeFieldUseHTML_3 = null;
protected static $cfgFreeFieldLabel_4 = null;
protected static $cfgFreeFieldUseHTML_4 = null;
protected static $cfgFreeFieldLabel_5 = null;
protected static $cfgFreeFieldUseHTML_5 = null;
protected $lang = null;
public function __construct() {
global $I18n;
global $manufakturConfig;
$this->lang = $I18n;
self::$page_link = ADMIN_URL . '/admintools/tool.php?tool=kit_event';
self::$template_path = WB_PATH . '/modules/' . basename(dirname(__FILE__)) . '/templates/backend/';
self::$template_url = WB_URL . '/modules/' . basename(dirname(__FILE__)) . '/templates/backend/';
self::$img_url = WB_URL . '/modules/' . basename(dirname(__FILE__)) . '/images/';
date_default_timezone_set(CFG_TIME_ZONE);
// get the configuration values
self::$cfgICalDir = $manufakturConfig->getValue('cfg_event_ical_directory', 'kit_event');
self::$cfgICalCreate = $manufakturConfig->getValue('cfg_event_ical_create', 'kit_event');
self::$cfgPermaLinkCreate = $manufakturConfig->getValue('cfg_event_perma_link_create', 'kit_event');
self::$cfgQRCodeDir = $manufakturConfig->getValue('cfg_event_qr_code_directory', 'kit_event');
self::$cfgQRCodeCreate = $manufakturConfig->getValue('cfg_event_qr_code_create', 'kit_event');
self::$cfgQRCodeSize = $manufakturConfig->getValue('cfg_event_qr_code_size', 'kit_event');
self::$cfgQRCodeECLevel = $manufakturConfig->getValue('cfg_event_qr_code_ec_level', 'kit_event');
self::$cfgQRCodeMargin = $manufakturConfig->getValue('cfg_event_qr_code_margin', 'kit_event');
self::$cfgQRCodeContent = $manufakturConfig->getValue('cfg_event_qr_code_content', 'kit_event');
self::$cfgDescriptionLong = $manufakturConfig->getValue('cfg_event_use_long_description', 'kit_event');
self::$cfgDescriptionShort = $manufakturConfig->getValue('cfg_event_use_short_description', 'kit_event');
self::$cfgFreeFieldLabel_1 = $manufakturConfig->getValue('cfg_event_free_field_1', 'kit_event');
self::$cfgFreeFieldUseHTML_1 = $manufakturConfig->getValue('cfg_event_free_field_1_use_html', 'kit_event');
self::$cfgFreeFieldLabel_2 = $manufakturConfig->getValue('cfg_event_free_field_2', 'kit_event');
self::$cfgFreeFieldUseHTML_2 = $manufakturConfig->getValue('cfg_event_free_field_2_use_html', 'kit_event');
self::$cfgFreeFieldLabel_3 = $manufakturConfig->getValue('cfg_event_free_field_3', 'kit_event');
self::$cfgFreeFieldUseHTML_3 = $manufakturConfig->getValue('cfg_event_free_field_3_use_html', 'kit_event');
self::$cfgFreeFieldLabel_4 = $manufakturConfig->getValue('cfg_event_free_field_4', 'kit_event');
self::$cfgFreeFieldUseHTML_4 = $manufakturConfig->getValue('cfg_event_free_field_4_use_html', 'kit_event');
self::$cfgFreeFieldLabel_5 = $manufakturConfig->getValue('cfg_event_free_field_5', 'kit_event');
self::$cfgFreeFieldUseHTML_5 = $manufakturConfig->getValue('cfg_event_free_field_5_use_html', 'kit_event');
} // __construct()
/**
* Set self::$error to $error
*
* @param STR $error
*/
public function setError($error) {
$caller = next(debug_backtrace());
self::$error = sprintf('[%s::%s - %s] %s', basename($caller['file']), $caller['function'], $caller['line'], $error);
} // setError()
/**
* Get Error from self::$error;
*
* @return STR self::$error
*/
public function getError() {
return self::$error;
} // getError()
/**
* Check if self::$error is empty
*
* @return BOOL
*/
public function isError() {
return (bool) !empty(self::$error);
} // isError
/**
* Reset Error to empty String
*/
public function clearError() {
self::$error = '';
}
/**
* Set self::$message to $message
*
* @param STR $message
*/
public function setMessage($message) {
self::$message = $message;
} // setMessage()
/**
* Get Message from self::$message;
*
* @return STR self::$message
*/
public function getMessage() {
return self::$message;
} // getMessage()
/**
* Check if self::$message is empty
*
* @return BOOL
*/
public function isMessage() {
return (bool) !empty(self::$message);
} // isMessage
public function clearMessage() {
self::$message = '';
} // clearMessage()
/**
* Return Version of Module
*
* @return float
*/
public function getVersion() {
// read info.php into array
$info_text = file(WB_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()
/**
* Get the template, set the data and return the compiled result
*
* @param string $template the name of the template
* @param array $template_data
* @param boolean $trigger_error raise a trigger error on problems
* @return boolean|Ambigous <string, mixed>
*/
protected function getTemplate($template, $template_data, $trigger_error=false) {
global $parser;
// check if a language depending template exists
if (file_exists(self::$template_path.LANGUAGE.'/'.$template)) {
$template_path = self::$template_path.LANGUAGE.'/';
$template_data['TEMPLATE_URL'] = self::$template_url.LANGUAGE;
}
else {
$template_path = self::$template_path.'DE/';
$template_data['TEMPLATE_URL'] = self::$template_url.'DE';
}
// 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($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()
/**
* Verhindert XSS Cross Site Scripting
*
* @param Array REFERENCE $_REQUEST
* @return $request
*/
public 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()
public function action() {
$html_allowed = array(
'item_desc_long',
'item_desc_short'
);
foreach ($_REQUEST as $key => $value) {
if (stripos($key, 'amp;') == 0) {
// fix the problem, that the server does not proper rewrite & to &
$key = substr($key, 4);
$_REQUEST[$key] = $value;
unset($_REQUEST['amp;'.$key]);
}
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 :
$this->show(self::ACTION_ABOUT, $this->dlgAbout());
break;
case self::ACTION_DELETE:
$this->show(self::ACTION_MESSAGES, $this->actionDelete());
break;
case self::ACTION_EDIT :
$this->show(self::ACTION_EDIT, $this->dlgEditEvent());
break;
case self::ACTION_CHECK_SUGGEST:
$this->show(self::ACTION_EDIT, $this->checkSuggestEvent());
break;
case self::ACTION_EDIT_CHECK :
$this->show(self::ACTION_EDIT, $this->checkEditEvent());
break;
case self::ACTION_MESSAGES :
$this->show(self::ACTION_MESSAGES, $this->dlgMessages());
break;
case self::ACTION_MESSAGES_DETAIL :
$this->show(self::ACTION_MESSAGES, $this->dlgMessageDetail());
break;
case self::ACTION_SETTINGS:
$this->show(self::ACTION_SETTINGS, $this->actionConfiguration());
break;
case self::ACTION_LIST :
default :
$this->show(self::ACTION_LIST, $this->dlgList());
break;
endswitch
;
} // action
/**
* Ausgabe des formatierten Ergebnis mit Navigationsleiste
*
* @param string $action aktives Navigationselement
* @param string $content Inhalt
*
* @return ECHO RESULT
*/
public function show($action, $content) {
$navigation = array();
foreach (self::$tab_navigation_array as $key => $value) {
if ($key == self::ACTION_KIT)
$link = ADMIN_URL.'/admintools/tool.php?tool=kit&act=list';
else
$link = sprintf('%s&%s=%s', self::$page_link, self::REQUEST_ACTION, $key);
$navigation[] = array(
'active' => ($key == $action) ? 1 : 0,
'url' => $link,
'text' => $value
);
}
$data = array(
'WB_URL' => WB_URL,
'navigation' => $navigation,
'error' => ($this->isError()) ? 1 : 0,
'content' => ($this->isError()) ? $this->getError() : $content
);
echo $this->getTemplate('body.dwoo', $data);
} // show()
public function dlgList() {
global $database;
$tke = TABLE_PREFIX.'mod_kit_event';
$tkei = TABLE_PREFIX.'mod_kit_event_item';
if (isset($_REQUEST[self::REQUEST_SHOW_ALL]) && ($_REQUEST[self::REQUEST_SHOW_ALL] == 1)) {
$SQL = "SELECT * FROM `$tke`, `$tkei` WHERE $tke.item_id=$tkei.item_id AND `evt_status`!='-1' ORDER BY `evt_event_date_from`";
$this->setMessage($this->lang->translate('<p>All events are shown!</p>'));
}
else {
$start_date = date('Y-m-d H:i:s', mktime(0, 0, 0, date('m'), date('d') - 2, date('Y')));
$SQL = "SELECT * FROM `$tke`, `$tkei` WHERE $tke.item_id=$tkei.item_id AND `evt_status`!='-1' AND `evt_event_date_from`>='$start_date' ORDER BY `evt_event_date_from` ASC";
}
if (null === ($query = $database->query($SQL))) {
$this->setError($database->get_error());
return false;
}
$items = '';
$rows = array();
while (false !== ($event = $query->fetchRow(MYSQL_ASSOC))) {
// get the group name
$SQL = "SELECT `group_name` FROM `".TABLE_PREFIX."mod_kit_event_group` WHERE `group_id`='{$event['group_id']}'";
$grp = $database->get_one($SQL);
if ($database->is_error()) {
$this->setError($database->get_error());
return false;
}
$group = -1;
$rows[] = array(
'id_name' => 'evt_id',
'id_link' => sprintf('%s&%s', self::$page_link, http_build_query(array(
self::REQUEST_ACTION => self::ACTION_EDIT,
'evt_id' => $event['evt_id']
))),
'id' => sprintf('%04d', $event['evt_id']),
'date_from_name' => 'evt_event_date_from',
'date_from' => date(CFG_DATETIME_STR, strtotime($event['evt_event_date_from'])),
'date_to_name' => 'evt_event_date_to',
'date_to' => date(CFG_DATETIME_STR, strtotime($event['evt_event_date_to'])),
'group_name' => 'group_id',
'group' => $grp,
'part_max_name' => 'evt_participants_max',
'part_max' => $event['evt_participants_max'],
'part_total_name' => 'evt_participants_total',
'part_total' => $event['evt_participants_total'],
'deadline_name' => 'evt_deadline',
'deadline' => date(CFG_DATE_STR, strtotime($event['evt_deadline'])),
'title_name' => 'item_title',
'title' => $event['item_title']
);
}
// check if libraryAdmin exists
if (file_exists(WB_PATH.'/modules/libraryadmin/inc/class.LABackend.php')) {
require_once WB_PATH.'/modules/libraryadmin/inc/class.LABackend.php';
// create instance; if you're not using OOP, use a simple var, like $la
$libraryAdmin = new LABackend();
// load the preset
$libraryAdmin->loadPreset(array(
'module' => 'kit_event',
'lib' => 'lib_jquery',
'preset' => 'dataTable'
));
// print the preset
$libraryAdmin->printPreset();
}
$data = array(
'message' => array(
'active' => (int) $this->isMessage(),
'content' => $this->getMessage()
),
'rows' => $rows,
'show_all_link' => sprintf('%s&%s', self::$page_link, http_build_query(array(
self::REQUEST_ACTION => self::ACTION_LIST,
self::REQUEST_SHOW_ALL => 1
))),
);
return $this->getTemplate('event.list.dwoo', $data);
} // dlgList()
/**
* Sanitize variables and prepare them for saving in a MySQL record
*
* @param mixed $item
* @return mixed
*/
public static function sanitizeVariable($item) {
if (!is_array($item)) {
// undoing 'magic_quotes_gpc = On' directive
if (get_magic_quotes_gpc())
$item = stripcslashes($item);
$item = self::sanitizeText($item);
}
return $item;
} // sanitizeVariable()
/**
* Sanitize a text variable and prepare ist for saving in a MySQL record
*
* @param string $text
* @return string
*/
protected static function sanitizeText($text) {
$text = str_replace(array("<",">","\"","'"), array("<",">",""","'"), $text);
$text = mysql_real_escape_string($text);
return $text;
} // sanitizeText()
/**
* Unsanitize a text variable and prepare it for output
*
* @param string $text
* @return string
*/
public static function unsanitizeText($text) {
$text = stripcslashes($text);
$text = str_replace(array("<",">",""","'"), array("<",">","\"","'"), $text);
return $text;
} // unsanitizeText()
public function dlgSuggestEvent() {
global $database;
$tke = TABLE_PREFIX.'mod_kit_event';
$tkei = TABLE_PREFIX.'mod_kit_event_item';
$SQL = "SELECT $tkei.item_id, evt_event_date_from, item_title FROM `$tke`, `$tkei` ".
"WHERE $tke.item_id=$tkei.item_id AND `evt_status`!='-1' ORDER BY `evt_event_date_from` DESC";
if (null === ($query = $database->query($SQL))) {
$this->setError($database->get_error());
return false;
}
$suggest_options = array();
while (false !== ($event = $query->fetchRow(MYSQL_ASSOC))) {
$suggest_options[] = array(
'value' => $event['item_id'],
'text' => sprintf('[ %s ] %s', date(CFG_DATE_STR, strtotime($event['evt_event_date_from'])), $event['item_title'])
);
}
// gather the available event groups
$SQL = "SELECT `group_id`, `group_name` FROM `".TABLE_PREFIX."mod_kit_event_group` WHERE `group_status`='1'";
if (null === ($query = $database->query($SQL))) {
$this->setError($database->get_error());
return false;
}
$event_groups = array();
while (false !== ($group = $query->fetchRow(MYSQL_ASSOC))) {
$event_groups[] = array(
'value' => $group['group_id'],
'text' => $group['group_name']
);
}
$data = array(
'form' => array(
'name' => 'event_suggest',
'action' => self::$page_link
),
'action' => array(
'name' => self::REQUEST_ACTION,
'value' => self::ACTION_CHECK_SUGGEST
),
'suggest' => array(
'name' => self::REQUEST_SUGGESTION,
'value' => -1,
'options' => $suggest_options
),
'copy_datetime' => array(
'name' => self::REQUEST_COPY_ALL,
'value' => 1
),
'event_group' => array(
'name' => self::REQUEST_EVENT_GROUP,
'value' => -1,
'options' => $event_groups
)
);
return $this->getTemplate('event.suggest.dwoo', $data);
} // dlgSuggestEvent()
private function checkSuggestEvent() {
global $database;
// get the suggested event
$suggest_id = (isset($_REQUEST[self::REQUEST_SUGGESTION])) ? (int) $_REQUEST[self::REQUEST_SUGGESTION] : -1;
if ($suggest_id > 0) {
return $this->dlgEditEvent();
}
// check if already isset a event group
$event_group = (isset($_REQUEST[self::REQUEST_EVENT_GROUP])) ? (int) $_REQUEST[self::REQUEST_EVENT_GROUP] : -1;
if ($event_group > 0) {
return $this->dlgEditEvent();
}
// the user must specify a event group
$copy_datetime = (int) isset($_REQUEST[self::REQUEST_COPY_ALL]);
// gather the available event groups
$SQL = "SELECT `group_id`, `group_name` FROM `".TABLE_PREFIX."mod_kit_event_group` WHERE `group_status`='1'";
if (null === ($query = $database->query($SQL))) {
$this->setError($database->get_error());
return false;
}
$event_groups = array();
while (false !== ($group = $query->fetchRow(MYSQL_ASSOC))) {
$event_groups[] = array(
'value' => $group['group_id'],
'text' => $group['group_name']
);
}
$data = array(
'form' => array(
'name' => 'event_suggest',
'action' => self::$page_link
),
'action' => array(
'name' => self::REQUEST_ACTION,
'value' => self::ACTION_CHECK_SUGGEST
),
'suggest' => array(
'name' => self::REQUEST_SUGGESTION,
'value' => $suggest_id,
),
'copy_datetime' => array(
'name' => self::REQUEST_COPY_ALL,
'value' => $copy_datetime
),
'event_group' => array(
'name' => self::REQUEST_EVENT_GROUP,
'value' => -1,
'options' => $event_groups,
'count' => count($event_group)
)
);
return $this->getTemplate('event.group.dwoo', $data);
} // checkSuggestEvent()
protected function getDistributionValue($identifier) {
global $database;
$SQL = "SELECT `array_value` FROM `".TABLE_PREFIX."mod_kit_contact_array_cfg` WHERE `array_identifier`='$identifier'";
return $database->get_one($SQL, MYSQL_ASSOC);
} // getDistributionValue()
public function dlgEditEvent() {
global $database;
global $kitContactInterface;
$event_id = (isset($_REQUEST['evt_id']) && ($_REQUEST['evt_id'] > 0)) ? $_REQUEST['evt_id'] : -1;
if ($event_id !== -1) {
$tke = TABLE_PREFIX.'mod_kit_event';
$tkei = TABLE_PREFIX.'mod_kit_event_item';
$SQL = "SELECT * FROM `$tke`, `$tkei` WHERE $tke.item_id=$tkei.item_id AND $tke.evt_id='$event_id'";
if (null === ($query = $database->query($SQL))) {
$this->setError($database->get_error());
return false;
}
if ($query->numRows() < 1) {
$this->setError($this->lang->translate('Error: The id {{ id }} is invalid!', array('id' => $event_id)));
return false;
}
$event = $query->fetchRow(MYSQL_ASSOC);
$item_id = $event['item_id'];
if ((date('H', strtotime($event['evt_event_date_from'])) !== 0) && (date('i', strtotime($event['evt_event_date_from'])) !== 0)) {
$time_start = date(CFG_TIME_STR, strtotime($event['evt_event_date_from']));
}
else {
$time_start = '';
}
if ((date('H', strtotime($event['evt_event_date_to'])) !== 0) && (date('i', strtotime($event['evt_event_date_to'])) !== 0)) {
$time_end = date(CFG_TIME_STR, strtotime($event['evt_event_date_to']));
}
else {
$time_end = '';
}
}
elseif (!isset($_REQUEST[self::REQUEST_SUGGESTION])) {
// erster Aufruf - Datenuebernahme von bestehenden Events anbieten
$SQL = "SELECT `group_id` FROM `".TABLE_PREFIX."mod_kit_event_group` WHERE `group_status`='1'";
if (null === ($query = $database->query($SQL))) {
$this->setError($database->get_error());
return false;
}
if ($query->numRows() < 1) {
// there is no event group available, user must first create a event group
$this->setMessage($this->lang->translate('<p>Before you can create the first event you must define a event group at least.</p>'));
$_REQUEST[self::REQUEST_ACTION] = self::ACTION_SETTINGS;
$_REQUEST[self::REQUEST_SUB_ACTION] = self::ACTION_GROUP;
$this->action();
return true;
}
return $this->dlgSuggestEvent();
}
elseif (isset($_REQUEST[self::REQUEST_SUGGESTION]) && ($_REQUEST[self::REQUEST_SUGGESTION] != -1)) {
$item_id = -1;
// get the field names from mod_kit_event
$SQL = "SHOW FIELDS FROM `".TABLE_PREFIX."mod_kit_event`";
if (null === ($query = $database->query($SQL))) {
$this->setError($database->get_error());
return false;
}
$event = array();
while (false !== ($field = $query->fetchRow(MYSQL_ASSOC)))
$event[$field['Field']] = '';
$event['evt_status'] = 1;
$time_start = '';
$time_end = '';
$item_id = (int) $_REQUEST[self::REQUEST_SUGGESTION];
$SQL = "SELECT * FROM `".TABLE_PREFIX."mod_kit_event_item` WHERE `item_id`='$item_id'";
if (null === ($query = $database->query($SQL))) {
$this->setError($database->get_error());
return false;
}
$item = $query->fetchRow(MYSQL_ASSOC);
$event = array_merge($event, $item);
// check if all data should be taken
if (isset($_REQUEST[self::REQUEST_COPY_ALL])) {
$suggest_id = (int) $_REQUEST[self::REQUEST_SUGGESTION];
$SQL = "SELECT * FROM `".TABLE_PREFIX."mod_kit_event` WHERE `evt_id`='$suggest_id'";
if (null === ($query = $database->query($SQL))) {
$this->setError($database->get_error());
return false;
}
$evt = $query->fetchRow(MYSQL_ASSOC);
// we dont need participants total and the permaLink
unset($evt['evt_id']);
unset($evt['item_id']);
unset($evt['evt_participants_total']);
unset($evt['evt_perma_link']);
unset($evt['evt_ical_file']);
unset($evt['evt_qrcode_image']);
$evt['evt_status'] = 1;
$event = array_merge($event, $evt);
if ((date('H', strtotime($event['evt_event_date_from'])) !== 0) && (date('i', strtotime($event['evt_event_date_from'])) !== 0)) {
$time_start = date(CFG_TIME_STR, strtotime($event['evt_event_date_from']));
}
else {
$time_start = '';
}
if ((date('H', strtotime($event['evt_event_date_to'])) !== 0) && (date('i', strtotime($event['evt_event_date_to'])) !== 0)) {
$time_end = date(CFG_TIME_STR, strtotime($event['evt_event_date_to']));
}
else {
$time_end = '';
}
}
else {
// we need the event group
$suggest_id = (int) $_REQUEST[self::REQUEST_SUGGESTION];
$SQL = "SELECT `group_id` FROM `".TABLE_PREFIX."mod_kit_event` WHERE `evt_id`='$suggest_id'";
if (null === ($query = $database->query($SQL))) {
$this->setError($database->get_error());
return false;
}
$evt = $query->fetchRow(MYSQL_ASSOC);
$evt['evt_status'] = 1;
$event = array_merge($event, $evt);
}
$this->setMessage($this->lang->translate('<p>This event was taken from the previous event with the ID {{ id }}</p>',
array('id' => $_REQUEST[self::REQUEST_SUGGESTION])));
}
else {
$item_id = -1;
// get the field names from mod_kit_event
$SQL = "SHOW FIELDS FROM `".TABLE_PREFIX."mod_kit_event`";
if (null === ($query = $database->query($SQL))) {
$this->setError($database->get_error());
return false;
}
$event = array();
while (false !== ($field = $query->fetchRow(MYSQL_ASSOC)))
$event[$field['Field']] = '';
// set status to active
$event['evt_status'] = 1;
// set the event group
$event['group_id'] = (isset($_REQUEST[self::REQUEST_EVENT_GROUP])) ? (int) $_REQUEST[self::REQUEST_EVENT_GROUP] : -1;
// get the field names from mod_kit_event_item
$SQL = "SHOW FIELDS FROM `".TABLE_PREFIX."mod_kit_event_item`";
if (null === ($query = $database->query($SQL))) {
$this->setError($database->get_error());
return false;
}
$items = array();
while (false !== ($field = $query->fetchRow(MYSQL_ASSOC)))
$items[$field['Field']] = '';
$event = array_merge($event, $items);
$time_start = '';
$time_end = '';
}
foreach ($event as $key => $value) {
if (isset($_REQUEST[$key])) {
switch ($key) :
case 'evt_event_date_from' :
if (false !== ($x = strtotime($_REQUEST[$key]))) {
$event[$key] = date('Y-m-d H:i:s', $x);
$time_start = ((date('H', $x) !== 0) || (date('i', $x) !== 0)) ? date(CFG_TIME_STR, $x) : '';
}
break;
case 'evt_event_date_to' :
if (false !== ($x = strtotime($_REQUEST[$key]))) {
$event[$key] = date('Y-m-d H:i:s', $x);
$time_end = ((date('H', $x) !== 0) || (date('i', $x) !== 0)) ? date(CFG_TIME_STR, $x) : '';
}
break;
default :
$event[$key] = $_REQUEST[$key];
endswitch
;
}
}
if (isset($_REQUEST[self::REQUEST_TIME_START])) $time_start = $_REQUEST[self::REQUEST_TIME_START];
if (isset($_REQUEST[self::REQUEST_TIME_END])) $time_end = $_REQUEST[self::REQUEST_TIME_END];
// event group
$SQL = "SELECT * FROM `".TABLE_PREFIX."mod_kit_event_group` WHERE `group_status`='1'";
if (null === ($query = $database->query($SQL))) {
$this->setError($database->get_error());
return false;
}
$grps = array();
while (false !== ($grp = $query->fetchRow(MYSQL_ASSOC)))
$grps[] = $grp;
$group = array();
foreach ($grps as $grp) {
$group[] = array(
'selected' => ($grp['group_id'] == $event['group_id']) ? 1 : 0,
'value' => $grp['group_id'],
'text' => $grp['group_name']
);
}
$status = array(
'ACTIVE' => array(
'selected' => ($event['evt_status'] == 1) ? 1 : 0,
'value' => 1,
'text' => 'ACTIVE'
),
'LOCKED' => array(
'selected' => ($event['evt_status'] == 0) ? 1 : 0,
'value' => 0,
'text' => 'LOCKED'
),
'DELETED' => array(
'selected' => ($event['evt_status'] == -1) ? 1 : 0,
'value' => -1,
'text' => 'DELETED'
)
);
$organizer_ids = array();
$organizer_contact = array();
$organizer_default = -1;
$location_ids = array();
$location_contact = array();
$location_default = -1;
// get the Organizer ID's
if ($event['group_id'] != '-1') {
$SQL = "SELECT * FROM `".TABLE_PREFIX."mod_kit_event_group` WHERE `group_id`='{$event['group_id']}'";
if (null === ($query = $database->query($SQL))) {
$this->setError($database->get_error());
return false;
}
if ($query->numRows() == 1) {
// get the group settings
$event_group = $query->fetchRow(MYSQL_ASSOC);
if (!empty($event_group['kit_distribution_organizer'])) {
// get all organizer ID's
$ids = array();
if (!$kitContactInterface->getContactsByCategory($event_group['kit_distribution_organizer'], $ids)) {
$this->setError($kitContactInterface->getError());
return false;
}
foreach ($ids as $id) {
$contact = array();
if (!$kitContactInterface->getContact($id, $contact))
// no error prompts within the loop
continue;
$organizer_ids[] = $contact;
// set the contact data for the organizer
if ($id == $event['organizer_id'])
$organizer_contact = $contact;
}
}
if (!empty($event_group['kit_distribution_location'])) {
// get all location ID's
$ids = array();
if (!$kitContactInterface->getContactsByCategory($event_group['kit_distribution_location'], $ids)) {
$this->setError($kitContactInterface->getError());
return false;
}
foreach ($ids as $id) {
$contact = array();
if (!$kitContactInterface->getContact($id, $contact))
// no error prompts within the loop
continue;
$location_ids[] = $contact;
// set the contact data for the location
if ($id == $event['location_id'])
$location_contact = $contact;
}
}
}
}
if (empty($organizer_contact) && ($event['organizer_id'] > 0)) {
if (!$kitContactInterface->getContact($event['organizer_id'], $organizer_contact)) {
$this->setError($kitContactInterface->getError());
return false;
}
$organizer_default = $event['organizer_id'];
}
if (empty($location_contact) && ($event['location_id'] > 0)) {
if (!$kitContactInterface->getContact($event['location_id'], $location_contact)) {
$this->setError($kitContactInterface->getError());
return false;
}
$location_default = $event['location_id'];
}
$fields = array(
'id' => array(
'name' => 'evt_id',
'value' => $event_id
),
'date_from' => array(
'name' => 'evt_event_date_from',
'id' => 'datepicker_1',
'value' => (false !== ($x = strtotime($event['evt_event_date_from']))) ? date(CFG_DATE_STR, $x) : ''
),
'date_to' => array(
'name' => 'evt_event_date_to',
'id' => 'datepicker_2',
'value' => (false !== ($x = strtotime($event['evt_event_date_to']))) ? date(CFG_DATE_STR, $x) : ''
),
'time_start' => array(
'name' => self::REQUEST_TIME_START,
'value' => $time_start
),
'time_end' => array(
'name' => self::REQUEST_TIME_END,
'value' => $time_end
),
'publish_date_from' => array(
'name' => 'evt_publish_date_from',
'value' => (false !== ($x = strtotime($event['evt_publish_date_from']))) ? date(CFG_DATE_STR, $x) : '',
'id' => 'datepicker_3'
),
'publish_date_to' => array(
'name' => 'evt_publish_date_to',
'value' => (false !== ($x = strtotime($event['evt_publish_date_to']))) ? date(CFG_DATE_STR, $x) : '',
'id' => 'datepicker_4'
),
'participants_max' => array(
'name' => 'evt_participants_max',
'value' => $event['evt_participants_max']
),
'participants_total' => array(
'name' => 'evt_participants_total',
'value' => $event['evt_participants_total']
),
'deadline' => array(
'name' => 'evt_deadline',
'value' => (false !== ($x = strtotime($event['evt_deadline']))) ? date(CFG_DATE_STR, $x) : '',
'id' => 'datepicker_5'
),
'costs' => array(
'name' => 'item_costs',
'value' => sprintf(CFG_CURRENCY, number_format((float) $event['item_costs'], 2, CFG_DECIMAL_SEPARATOR, CFG_THOUSAND_SEPARATOR))
),
'group' => array(
'name' => 'group_id',
'value' => $group
),
'status' => array(
'name' => 'evt_status',
'value' => $status
),
'title' => array(
'name' => 'item_title',
'value' => $event['item_title']
),
'short_description' => array(
'name' => 'item_desc_short',
'value' => self::unsanitizeText($event['item_desc_short'])
),
'long_description' => array(
'name' => 'item_desc_long',
'value' => self::unsanitizeText($event['item_desc_long'])
),
'free_field' => array(
1 => array(
'active' => (int) !empty(self::$cfgFreeFieldLabel_1),
'use_html' => (int) self::$cfgFreeFieldUseHTML_1,