-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.php
4091 lines (3343 loc) · 139 KB
/
index.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
/***************************************************************
* Copyright notice
*
* (c) 2003-2020 Renzo Lauper ([email protected])
* (c) 2019-2020 Daniel Lerch
* All rights reserved
*
* This script is part of the kOOL project. The kOOL project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
* kOOL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
header('Content-Type: text/html; charset=ISO-8859-1');
ob_start(); //Ausgabe-Pufferung einschalten
$ko_path = "../";
$ko_menu_akt = "leute";
include_once($ko_path . "inc/ko.inc");
include_once("inc/leute.inc");
//get notifier instance
$notifier = koNotifier::Instance();
//Redirect to SSL if needed
ko_check_ssl();
if(!ko_module_installed("leute")) {
header("Location: ".$BASE_URL."index.php"); //Absolute URL
}
//Only allow checkin user if he submitted a form for a new address
if($_SESSION['ses_userid'] == ko_get_checkin_user_id() && ($_POST['async_form_tag'] != 'checkin_add_person' || $_SESSION['checkin_user'] != 'admin')) {
header('Location: '.$BASE_URL.'index.php'); exit;
}
ob_end_flush();
ko_get_access('leute');
if(ko_module_installed('kg')) ko_get_access('kg');
if(ko_module_installed('crm')) ko_get_access('crm');
if(ko_module_installed('groups')) {
ko_get_access('groups');
ko_get_groups($all_groups);
}
//kOOL Table Array
ko_include_kota(array('ko_leute', 'ko_kleingruppen'));
//*** Plugins einlesen:
$hooks = hook_include_main("leute,kg");
if(sizeof($hooks) > 0) foreach($hooks as $hook) include_once($hook);
// required for xls export: fills in the post-data from the previous request
if ($_SESSION['leute_export_xls_post'] != '' && $_POST['action'] == 'leute_submit_export_xls' && $_SESSION['show'] == 'xls_settings') {
foreach ($_SESSION['leute_export_xls_post'] as $k => $v) {
$_POST[$k] = $v;
}
$_SESSION['show'] = $_SESSION['leute_export_xls_post']['session_show'];
unset($_SESSION['leute_export_xls_post']);
$_POST['action'] = 'leute_action';
$_POST['id'] = 'excel';
$_POST['from_settings'] = 'true';
if ($_POST['sel_leute_force_family_firstname'] != '') {
$v = format_userinput($_POST['sel_leute_force_family_firstname'], 'uint', FALSE, 1);
if($v == 0 || $v == 1 || $v == 2) {
ko_save_userpref($_SESSION['ses_userid'], 'leute_force_family_firstname', $v);
}
}
ko_save_userpref($_SESSION['ses_userid'], 'leute_linebreak_columns', format_userinput($_POST['sel_linebreak_columns'], 'alphanumlist'));
ko_save_userpref($_SESSION['ses_userid'], 'export_table_format', format_userinput($_POST['export_table_format'], 'alphanum'));
}
else {
unset($_SESSION['leute_export_xls_post']);
}
// required for label export: fills in the post-data from the previous request
if ($_SESSION['leute_export_etiketten_post'] != '' && $_POST['action'] == 'submit_etiketten' && $_SESSION['show'] == 'etiketten_optionen') {
foreach ($_SESSION['leute_export_etiketten_post'] as $k => $v) {
$_POST[$k] = $v;
}
$_SESSION['show'] = $_SESSION['leute_export_etiketten_post']['session_show'];
unset($_SESSION['leute_export_etiketten_post']);
$_POST['action'] = 'leute_action';
$_POST['id'] = 'etiketten';
$_POST['from_settings'] = 'true';
// save userprefs (if necessary)
if ($_POST['sel_leute_force_family_firstname'] != '') {
$v = format_userinput($_POST['sel_leute_force_family_firstname'], 'uint', FALSE, 1);
if($v == 0 || $v == 1 || $v == 2) {
ko_save_userpref($_SESSION['ses_userid'], 'leute_force_family_firstname', $v);
}
}
}
else {
unset($_SESSION['leute_export_etiketten_post']);
}
//***Action auslesen:
if($_POST["action"]) {
$do_action = $_POST["action"];
$action_mode = "POST";
} else if($_GET["action"]) {
$do_action = $_GET["action"];
$action_mode = "GET";
} else {
$do_action = $action_mode = "";
}
if(FALSE === format_userinput($do_action, "alphanum+", TRUE, 50)) trigger_error("invalid action: ".$do_action, E_USER_ERROR);
//Reset show_start if from another module
if($_SERVER['HTTP_REFERER'] != '' && FALSE === strpos($_SERVER['HTTP_REFERER'], '/'.$ko_menu_akt.'/')) $_SESSION['show_start'] = 1;
switch($do_action) {
//Anzeige
case 'show_all':
if($_SESSION['show'] == 'show_all') $_SESSION['show_start'] = 1;
$_SESSION['show'] = 'show_all';
$onload_code = "form_set_focus('general_search');".$onload_code;
break;
case "show_adressliste":
$_SESSION["show"] = "show_adressliste";
$_SESSION["show_start"] = 1;
$onload_code = "form_set_focus('general_search');".$onload_code;
break;
case "geburtstagsliste":
if($access['leute']['MAX'] < 1) break;
$allowed_cols = ko_get_leute_admin_spalten($_SESSION['ses_userid'], 'all');
if(!is_array($allowed_cols['view']) || in_array('geburtsdatum', $allowed_cols['view'])) {
$_SESSION['show_start'] = 1;
$_SESSION["show"] = "geburtstagsliste";
}
break;
case "single_view":
$single_id = format_userinput($_GET["id"], "uint");
if($access['leute']['ALL'] > 0 || $access['leute'][$single_id] > 0) {
$_SESSION["show"] = "single_view";
}
break;
case 'show_aa':
if($access['leute']['MAX'] < 2) break;
if(!ko_get_setting('leute_allow_moderation') && $access['leute']['MAX'] < 4) break;
$_SESSION['show'] = $_SESSION['show_back'] = 'mutationsliste';
break;
case "groupsubscriptions":
if(isset($_GET['gid'])) {
if(!$_GET['gid']) unset($_SESSION['leute_gs_filter']);
else $_SESSION['leute_gs_filter'] = format_userinput($_GET['gid'], 'uint');
}
$_SESSION["show"] = "groupsubscriptions";
break;
//My-List
case "add_to_my_list":
foreach(explode(',', $_POST['ids']) as $c) {
if($c) {
if(FALSE === ($value = format_userinput($c, 'uint', TRUE, 10))) {
trigger_error("Not allowed my_list selection: $c_i", E_USER_ERROR);
}
if($value && !in_array($value, $_SESSION['my_list'])) $_SESSION['my_list'][$value] = $value;
}
}
ko_save_userpref($_SESSION["ses_userid"], "leute_my_list", serialize($_SESSION["my_list"]));
break;
case "del_from_my_list":
foreach(explode(',', $_POST['ids']) as $c) {
if($c) unset($_SESSION['my_list'][$c]);
}
ko_save_userpref($_SESSION["ses_userid"], "leute_my_list", serialize($_SESSION["my_list"]));
break;
case "clear_my_list":
$_SESSION["my_list"] = array();
ko_save_userpref($_SESSION["ses_userid"], "leute_my_list", serialize($_SESSION["my_list"]));
break;
case "show_my_list":
$_SESSION["show"] = "show_my_list";
if($_SESSION['show'] == 'show_my_list') $_SESSION['show_start'] = 1;
break;
//Neu
case "neue_person":
$_SESSION["show_back"] = $_SESSION["show"];
$_SESSION["show"] = "neue_person";
$onload_code = "form_set_first_input();".$onload_code;
break;
case "submit_neue_person":
case "submit_edit_person":
case "submit_als_neue_person":
list($table, $cols, $id, $hash) = explode('@', $_POST['id']);
if (!kota_check_all_mandatory_fields($_POST)) {
$notifier->addError(60);
if ($id > 0) {
$_POST['id'] = $id;
}
break;
}
//Beim Editieren auf korrekte Leute-ID prüfen
if($do_action == "submit_edit_person") {
if(!$id || !format_userinput($id, "uint", TRUE, 10)) break;
$leute_id = format_userinput($id, "uint");
ko_get_person_by_id($leute_id, $person);
$action = "submit_edit_person";
}
//New person or "save as new person" for an existing one
else if($do_action == "submit_als_neue_person" || $do_action == "submit_neue_person") {
//Create a new entry and store new id
$leute_id = db_insert_data("ko_leute", array("id" => "NULL", "crdate" => date("Y-m-d H:i:s"), "cruserid" => $_SESSION["ses_userid"]));
$GLOBALS['insertedIds']['ko_leute'][] = $leute_id;
//Simulate editing with new id
$action = "submit_edit_person";
//Everything as when editing, but a new LDAP entry has to be created
$ldap_new_entry = TRUE;
}//if(do_action == submit_als_neue_person)
else {
break;
}
if($access['leute']['MAX'] > 1 || (ko_get_setting("login_edit_person") == 1 && $leute_id == ko_get_logged_in_id())) {}
else {
if ($do_action != "submit_edit_person") {
db_delete_data('ko_leute', "WHERE `id` = '{$leute_id}'"); // TODO: is this okay?
}
break;
}
if ($do_action == "submit_edit_person") {
// Do initial save leute changes
ko_save_leute_changes($leute_id);
}
//LDAP
$do_ldap = ko_do_ldap();
//Datenbank-Spalten auslesen
$leute_cols = db_get_columns("ko_leute");
$col_namen = ko_get_leute_col_name();
//get the cols, for which this user has edit-rights (saved in allowed_cols[edit])
$allowed_cols = ko_get_leute_admin_spalten($_SESSION["ses_userid"], "all", $leute_id);
//Handle view and edit separately because if only one of them is set for a login,
//the test is_array() has to be called separately, so allowed_cols doesn't get turned into an array.
if(is_array($allowed_cols["view"]) && sizeof($allowed_cols["view"]) > 0) {
if($access['groups']['MAX'] > 0) $allowed_cols["view"][] = "groups";
if($access['kg']['MAX'] > 1) $allowed_cols["view"][] = "smallgroups";
}
if(is_array($allowed_cols["edit"]) && sizeof($allowed_cols["edit"]) > 0) {
if($access['groups']['MAX'] > 1) $allowed_cols["edit"][] = "groups";
if($access['kg']['MAX'] > 2) $allowed_cols["edit"][] = "smallgroups";
}
/* Familien-Daten speichern */
$old_famid = $person["famid"];
if(!is_array($allowed_cols["edit"]) || in_array("famid", $allowed_cols["edit"])) {
$do_update_familie = FALSE; //Familiendaten - falls nötig - erst nach Speichern der Person updaten
$new_familie = FALSE;
//Neue Familie
if($_POST["hid_new_family"] == 1) {
$save_famid = db_insert_data("ko_familie", array("nachname" => ""));
$new_familie = TRUE;
} else {
$save_famid = format_userinput($_POST["sel_familie"], "uint");
}
//Familie geändert
if($save_famid != $old_famid) {
$log_message .= getLL("leute_log_family").": $old_famid --> $save_famid, ";
//Update address before calling kota_process_data() below,
// as there ko_multiedit_familie() would store new address to old family
db_update_data('ko_leute', "WHERE `id` = '$leute_id'", array('famid' => $save_famid));
//Alte Familie löschen, falls keine Mitglieder mehr
if($old_famid != 0) {
$num = ko_get_personen_by_familie($old_famid, $asdf);
if($num < 1) {
db_update_data('ko_leute', "WHERE `famid` = '$old_famid'", array('famid' => '0', 'kinder' => '0'));
db_delete_data('ko_familie', "WHERE `famid` = '$old_famid'");
}
}
}
// save father, mother
$data['father'] = format_userinput($_POST['input_father'], 'uint');
$data['mother'] = format_userinput($_POST['input_mother'], 'uint');
// save famfunction
$data['famfunction'] = format_userinput($_POST['input_famfunction'], 'alphanum');
}//if(in_array(famid, allowed_cols[edit]))
else {
$save_famid = $person['famid'];
}
// Process KOTA part of submitted data
$kotaData = $_POST["koi"]["ko_leute"];
kota_process_data("ko_leute", $kotaData, "post", $log_, $leute_id, ($leute_id==0));
//Update fam fields
if($save_famid > 0) {
$familien_cols = db_get_columns('ko_familie');
foreach($familien_cols as $col_) {
$col = $col_['Field'];
//don't save not allowed columns (edit)
//kota_process_data() adds empty values for checkbox/switch inputs if they're not set in _POST
// so make sure to not store them on the family if no access is given, which makes them not to show up in _POST
if(is_array($allowed_cols['edit'])) {
if(!in_array($col, $allowed_cols['edit'])) continue;
} else if(is_array($allowed_cols['view'])) {
if(!in_array($col, $allowed_cols['view'])) continue;
}
if($col && isset($kotaData[$col])) {
$fam_data[$col] = $kotaData[$col];
} else if($col && isset($_POST['input_'.$col])) {
$fam_data[$col] = format_userinput($_POST['input_'.$col], 'text');
}
}
ko_update_familie($save_famid, $fam_data, $leute_id);
}
foreach($KOTA['ko_leute'] as $col => $def) {
if (substr($col, 0, 1) == '_') continue;
if (!is_array($def['form'])) continue;
if ($def['form']['type'] == 'html') continue;
if ($def['form']['dontsave']) continue;
if (in_array($col, $KOTA['ko_leute']['_form_layout']['_ignore_fields'])) continue;
//don't save not allowed columns (edit)
if(is_array($allowed_cols["edit"])) {
if(!in_array($col, $allowed_cols["edit"])) continue;
} else if(is_array($allowed_cols['view'])) {
if(!in_array($col, $allowed_cols["view"])) continue;
}
if (isset($kotaData[$col."_DELETE"]) && $person[$col]) {
if (!isset($kotaData[$col])) $data[$col] = '';
continue;
}
// Get value
if (!isset($kotaData[$col])) continue;
$value = $kotaData[$col];
if ($col == 'groups') {
// Handle groups
if (ko_module_installed("groups") && $access['groups']['MAX'] > 1) {
ko_groups_get_savestring($value, array("id" => $leute_id), $log, $person["groups"]);
$data['groups'] = $value;
//Store current datafields for versioning (stored with ko_save_leute_changes())
$datafields = ko_get_datafields($leute_id);
//Store datafields in DB
ko_groups_save_datafields($_POST["group_datafields"], array("id" => $leute_id, "groups" => $value, "old_groups" => $person["groups"]), $log2);
//Log-Message:
if(trim($log) != "") $log_message .= getLL("leute_log_groups").": $log";
if(trim($log2) != "") $log_message .= getLL("leute_log_datafields").": $log2";
}
} else {
$data[$col] = trim($value);
//Log-Message
$label = getLL('kota_ko_leute_' . $col);
if($action == "submit_neue_person") { //Alle gemachten Angaben loggen
if($value) {
$ll = getLL('kota_ko_leute_'.$col.'_'.$value);
$log_message .= "$label: '".($ll ? $ll : $value)."', ";
}
} else { //Bei Editieren nur die loggen, die geändert wurden
$new = $value;
$old = $person[$col];
if($old == '00:00:00' || $old == '0000-00-00' || $old == '0000-00-00 00:00:00') $old = '';
if( ($old || $new) && $new != $old) {
$ll_old = getLL('kota_ko_leute_'.$col.'_'.$old);
$ll_new = getLL('kota_ko_leute_'.$col.'_'.$new);
$log_message .= $label.": '".($ll_old ? $ll_old : $old)."' --> '".($ll_new ? $ll_new : $new)."', ";
}
}
}
}//foreach($kotaData)
// create log entry for parents
foreach (array('father', 'mother') as $parent) {
if (!isset($data[$parent])) continue;
$val = (int)$data[$parent];
if ($action == 'submit_neue_person') {
$log_message .= "{$col_namen[$parent]}: '{$val}', ";
} else {
if ($person[$parent] != $val) {
$log_message .= "{$col_namen[$parent]}: '{$person[$parent]}' --> '{$val}', ";
}
}
}
//Check for leute_admin_groups to be added
if((!defined('LEUTE_ADMIN_GROUPS_NEW_ONLY') || LEUTE_ADMIN_GROUPS_NEW_ONLY == FALSE)
|| in_array($do_action, array("submit_neue_person", "submit_als_neue_person")))
{
$lag = ko_get_leute_admin_groups($_SESSION["ses_userid"], 'all');
if(is_array($lag) && sizeof($lag) > 0) {
foreach($lag as $gid) {
if(!$gid) continue;
if(FALSE === strstr($data["groups"], $gid)) {
$data["groups"] .= $data["groups"] != "" ? ",".$gid : $gid;
}
}
}
}
//In DB speichern
$data["lastchange"] = date("Y-m-d H:i:s"); //LastChange hinzufügen
//Familien-ID hinzufügen
if(!is_array($allowed_cols["edit"]) || in_array("famid", $allowed_cols["edit"])) {
$data["famid"] = $save_famid;
if($data['famid'] <= 0) $data['kinder'] = '0'; //Set number of children to 0 for persons without a family
}
if($action == "submit_edit_person") {
db_update_data("ko_leute", "WHERE `id` = '$leute_id'", $data);
} else {
//Not needed? as submit_neue_person is handled as submit_edit_person with id of new empty entry...?
$leute_id = db_insert_data("ko_leute", $data);
}
// Create revision entry for checkin
if ($ASYNC_FORM_TAG == 'checkin_add_person' && $do_action == 'submit_neue_person') {
$revisionEntry = array(
'leute_id' => $leute_id,
'reason' => 'checkin',
'crdate' => date('Y-m-d H:i:s'),
'cruser' => $_SESSION['ses_userid'],
);
db_insert_data('ko_leute_revisions', $revisionEntry);
}
// Spouse
ko_leute_set_spouse($leute_id, format_userinput($_POST['input_spouse'], 'uint'));
//Store email checkboxes to define prefered email fields
if(sizeof($LEUTE_EMAIL_FIELDS) > 1) {
foreach($LEUTE_EMAIL_FIELDS as $email_field) {
if(is_array($allowed_cols['edit']) && !in_array($email_field, $allowed_cols['edit'])) continue;
$current = db_select_data('ko_leute_preferred_fields', "WHERE `type` = 'email' AND `lid` = '$leute_id' AND `field` = '$email_field'", '*', '', '', TRUE);
if($_POST['email_chk_'.$email_field]) { //Field selected
if($data[$email_field]) { //Only set checkbox if email address is given
if(!$current) db_insert_data('ko_leute_preferred_fields', array('type' => 'email', 'lid' => $leute_id, 'field' => $email_field));
} else { //Delete checkbox if no email address is given
if($current) db_delete_data('ko_leute_preferred_fields', "WHERE `type` = 'email' AND `lid` = '$leute_id' AND `field` = '$email_field'");
}
} else { //Field not selected
if($current) db_delete_data('ko_leute_preferred_fields', "WHERE `type` = 'email' AND `lid` = '$leute_id' AND `field` = '$email_field'");
}
}
}
//Store mobile checkboxes to define prefered mobile fields
if(sizeof($LEUTE_MOBILE_FIELDS) > 1) {
foreach($LEUTE_MOBILE_FIELDS as $mobile_field) {
if(is_array($allowed_cols['edit']) && !in_array($mobile_field, $allowed_cols['edit'])) continue;
$current = db_select_data('ko_leute_preferred_fields', "WHERE `type` = 'mobile' AND `lid` = '$leute_id' AND `field` = '$mobile_field'", '*', '', '', TRUE);
if($_POST['mobile_chk_'.$mobile_field]) { //Field selected
if($data[$mobile_field]) { //Only set checkbox if mobile number is given
if(!$current) db_insert_data('ko_leute_preferred_fields', array('type' => 'mobile', 'lid' => $leute_id, 'field' => $mobile_field));
} else { //Delete checkbox if no mobile number is given
if($current) db_delete_data('ko_leute_preferred_fields', "WHERE `type` = 'mobile' AND `lid` = '$leute_id' AND `field` = '$mobile_field'");
}
} else { //Field not selected
if($current) db_delete_data('ko_leute_preferred_fields', "WHERE `type` = 'mobile' AND `lid` = '$leute_id' AND `field` = '$mobile_field'");
}
}
}
//In LDAP speichern
if($do_ldap) {
$ldap = ko_ldap_connect();
//Get full person record (if only some columns can be edited only these would be in $data)
ko_get_person_by_id($leute_id, $ldap_person);
if($action == "submit_edit_person" && !$ldap_new_entry) { //Als neue Person speichern, ist zwar edit, muss aber neu angelegt werden.
ko_ldap_add_person($ldap, $ldap_person, $person['id'], TRUE);
} else {
ko_ldap_add_person($ldap, $ldap_person, $leute_id);
}
ko_ldap_close($ldap);
}//if(do_ldap)
//ezmlm: change email in mailinglist address if email has changed
if($action != 'submit_neue_person' && defined("EXPORT2EZMLM") && EXPORT2EZMLM) {
$old_email = $person['email']; $new_email = $_POST['input_email'];
if($old_email != $new_email && check_email($new_email)) { //Check for changed valid email
foreach(explode(",", $data["groups"]) as $group) { //Check this user's groups for one with an ML assigned
$gid = ko_groups_decode($group, "group_id");
if($all_groups[$gid]["ezmlm_list"]) {
//Un- and resubscribe
ko_ezmlm_unsubscribe($all_groups[$gid]["ezmlm_list"], $all_groups[$gid]["ezmlm_moderator"], $old_email);
ko_ezmlm_subscribe($all_groups[$gid]["ezmlm_list"], $all_groups[$gid]["ezmlm_moderator"], $new_email);
}
}
}
}
//Update count for groups this person is/was assigned to
$ag = array_unique(array_merge(explode(',', $person['groups']), explode(',', $data['groups'])));
foreach($ag as $g) {
$g = ko_groups_decode($g, 'group_id');
if($all_groups[$g]['maxcount'] > 0) {
ko_update_group_count($g, $all_groups[$g]['count_role']);
}
}
//Log-Meldung
if($do_action == "submit_neue_person") {
ko_log("new_person", $leute_id . ": " . substr($log_message,0,-2));
$notifier->addInfo(1, $do_action);
} else {
if($log_message != "") {
$name = $person["vorname"]." ".$person["nachname"];
if(!$name) $name = $person["firm"];
ko_log("edit_person", $leute_id . " ($name): " . substr($log_message,0,-2));
//Save changes for versioning
ko_save_leute_changes($leute_id, $person, $datafields);
//Announce changes to selected users
if(sizeof($_POST['sel_announce_changes']) > 0) {
$moderator = ko_get_logged_in_person();
foreach($_POST['sel_announce_changes'] as $lid) {
$lid = (int)$lid;
if(!$lid) continue;
$loggedinPerson = ko_get_logged_in_person($lid);
$text = sprintf(getLL('leute_announce_changes_email_text'), $moderator['vorname'].' '.$moderator['nachname'], $name)."\n\n".str_replace(',', "\n", substr($log_message, 0, -2));
ko_send_mail(
'',
$loggedinPerson['email'],
getLL('leute_announce_changes_email_subject'),
$text
);
}
}//if(POST[sel_announce_changes])
}//if(log_message)
if (!$notifier->hasErrors()) {
$notifier->addInfo(2, $do_action);
}
}
// Update groups assignment history
ko_get_person_by_id($leute_id, $currentPerson);
ko_create_groups_snapshot($currentPerson, NULL, NULL, TRUE);
//Set show case
$_SESSION["show"] = $_SESSION["show_back"] ? $_SESSION["show_back"] : "show_all";
break;
case "mailing":
$_SESSION['show'] = 'leute_mailing';
break;
//Bearbeiten
case "edit_person":
if($action_mode == 'POST') $leute_id = format_userinput($_POST['id'], 'uint');
else if($action_mode == 'GET') $leute_id = format_userinput($_GET['id'], 'uint');
if($access['leute']['ALL'] > 1 || $access['leute'][$leute_id] > 1 || (ko_get_setting('login_edit_person') == 1 && $leute_id == ko_get_logged_in_id())) {} else break;
$_SESSION["show_back"] = $_SESSION["show"];
$_POST['id'] = $leute_id;
$_SESSION["show"] = "edit_person";
break;
case "delete_persons":
if (ko_get_setting('leute_multiple_delete')) {
foreach($_POST["chk"] as $person_id => $status) {
if($status == "on") {
$del_id = format_userinput($person_id, "uint", TRUE);
if(!$del_id) continue;
if($access['leute']['MAX'] < 3) continue;
if(ko_leute_delete_person($del_id)) {
$notifier->addInfo(3, $do_action);
} else {
$notifier->addError(4, $do_action);
}
}
}
}
break;
case 'merge_duplicates':
//TODO: Merge history of both address records?
if($access['leute']['MAX'] < 3) break;
//Find marked persons and test for access level 3 (edit and delete)
$do_ids = array();
foreach($_POST['chk'] as $c_i => $c) {
if(!$c) continue;
$dup_id = format_userinput($c_i, 'uint');
if($dup_id > 0 && ($access['leute']['ALL'] > 2 || $access['leute'][$dup_id] > 2)) $do_ids[] = $dup_id;
}
if(sizeof($do_ids) <= 0) {
$notifier->addError(5, $do_action);
break;
}
//Find duplicate filter and get tested fields
$filters = db_select_data('ko_filter', "WHERE `typ` = 'leute'", '*');
foreach($_SESSION['filter'] as $k => $v) {
if(!is_integer($k)) continue;
if($filters[$v[0]]['name'] == 'duplicates') {
$fields = explode('-', $v[1][1]);
}
}
//Only get addresses with none-empty test field
$where = "WHERE `deleted` = '0' ".ko_get_leute_hidden_sql();
foreach($fields as $field) {
$where .= ' AND `'.$field.'` != \'\' AND `'.$field.'` != \'0000-00-00\'';
}
$all = db_select_data('ko_leute', $where, '*');
//Build test string for all persons
$test = array();
foreach($all as $person) {
$value = array();
foreach($fields as $field) $value[] = strtolower($person[$field]);
$test[$person['id']] = implode('#', $value);
}
unset($all);
//Find dups (only one is left in $dups)
$dups = array_unique(array_diff_assoc($test, array_unique($test)));
if(sizeof($dups) <= 0) break;
//Get ids of all duplicates (not just one for each hit)
$ids = $dups;
foreach($test as $tid => $t) {
if(in_array($t, $dups)) $ids[$tid] = $t;
}
//Group duplicates that contain possible duplicates
$c = 0; $duplicates = array();
$done = array();
foreach($ids as $id => $value) {
if(!in_array($id, $do_ids)) continue; //Only test marked ids
if(in_array($id, $done)) continue; //Don't check IDs which have been added as duplicate of another ID
foreach($test as $tid => $t) {
if(!in_array($tid, $do_ids)) continue; //Only test marked ids
if($t == $value) {
$duplicates[$c][] = $tid;
$done[] = $tid;
}
}
$c++;
}
$showMutations = FALSE;
foreach($duplicates as $ids) {
ko_leute_merge_ids($ids, $addressChanged, $all_datafields);
$showMutations = $showMutations || $addressChanged;
}//foreach(duplicates)
//Show moderations
if($showMutations && $access['leute']['MAX'] > 1) $_SESSION['show'] = 'mutationsliste';
break;
case 'merge_duplicates_no_filter':
//TODO: Merge history of both address records?
if($access['leute']['MAX'] < 3) break;
//Find marked persons and test for access level 3 (edit and delete)
$ids = array();
foreach($_POST['chk'] as $c_i => $c) {
if(!$c) continue;
$dup_id = format_userinput($c_i, 'uint');
if($dup_id > 0 && ($access['leute']['ALL'] > 2 || $access['leute'][$dup_id] > 2)) {
$ids[] = $dup_id;
} else {
$notifier->addError(29, $do_action);
break;
}
}
if(sizeof($ids) != 2 || sizeof($_POST['chk']) != 2) {
$notifier->addError(30, $do_action);
break;
}
ko_leute_merge_ids($ids, $showMutations);
//Show moderations
if($showMutations && $access['leute']['MAX'] > 1) $_SESSION['show'] = 'mutationsliste';
break;
case 'decouple_from_household':
if ($access['leute']['MAX'] < 2) break;
//Find marked persons and test for access level 3 (edit and delete)
$doIds = array();
$checkAccess = TRUE;
if (!is_array($_POST['chk']) || sizeof($_POST['chk']) == 0) {
$doIds = 'APPLY_FILTER';
} else {
foreach($_POST['chk'] as $c_i => $c) {
if(!$c) continue;
$pid = format_userinput($c_i, 'uint');
if($pid > 0 && ($access['leute']['ALL'] > 1 || $access['leute'][$pid] > 1)) $doIds[] = $pid;
$checkAccess = FALSE;
}
if(sizeof($doIds) == 0) {
$notifier->addError(5, $do_action);
break;
}
}
// decouple selected (or all if none were selected) people from housefolds
ko_decouple_from_household($doIds, $checkAccess);
break;
case "multiedit":
/* Leute-Multiedit */
if($_SESSION["show"] == "show_all" || $_SESSION["show"] == "show_my_list") {
if($access['leute']['MAX'] < 2) break;
//Zu bearbeitende Spalten
$columns = explode(",", format_userinput($_POST["id"], "alphanumlist"));
foreach($columns as $column) {
$do_columns[] = $column;
}
if(sizeof($do_columns) < 1) koNotifier::Instance()->addError(4);
//Zu bearbeitende Einträge
$do_ids = array();
foreach($_POST["chk"] as $c_i => $c) {
if($c) {
if(FALSE === ($edit_id = format_userinput($c_i, "uint", TRUE))) {
trigger_error("Not allowed multiedit_id: ".$c_i, E_USER_ERROR);
}
if($access['leute']['ALL'] > 1 || $access['leute'][$edit_id] > 1) $do_ids[] = $edit_id;
}
}
if(sizeof($do_ids) < 1) $notifier->addError(5, $do_action);
//Daten für Formular-Aufruf vorbereiten
if(!$notifier->hasErrors()) {
if(substr($_SESSION["sort_leute"][0], 0, 6) == "MODULE") {
$order = "ORDER BY nachname ASC";
} else {
$order = "ORDER BY ".$_SESSION["sort_leute"][0]." ".$_SESSION["sort_leute_order"][0];
}
$_SESSION["show_back"] = $_SESSION["show"];
$_SESSION["show"] = "multiedit";
}
/* KG-Multiedit */
} else if($_SESSION["show"] == "list_kg") {
if($access['kg']['MAX'] < 3) break;
//Zu bearbeitende Spalten
$columns = explode(",", format_userinput($_POST["id"], "alphanumlist"));
foreach($columns as $column) {
$do_columns[] = $column;
}
if(sizeof($do_columns) < 1) $notifier->addError(4, $do_action);
//Zu bearbeitende Einträge
$do_ids = array();
foreach($_POST["chk"] as $c_i => $c) {
if($c) {
if(FALSE === ($edit_id = format_userinput($c_i, "uint", TRUE))) {
trigger_error("Not allowed multiedit_id: ".$c_i, E_USER_ERROR);
}
$do_ids[] = $edit_id;
}
}
if(sizeof($do_ids) < 1) $notifier->addError(5, $do_action);
//Daten für Formular-Aufruf vorbereiten
$order = 'ORDER BY name ASC'; //Default
if(!$notifier->hasErrors()) {
if(is_string($_SESSION['sort_kg'])) $order = "ORDER BY ".$_SESSION["sort_kg"]." ".$_SESSION["sort_kg_order"];
$_SESSION["show_back"] = $_SESSION["show"];
$_SESSION["show"] = "multiedit_kg";
}
}
$onload_code = "form_set_first_input();".$onload_code;
break;
case "submit_multiedit":
if($_SESSION["show"] == "multiedit") {
kota_submit_multiedit(2);
} else if($_SESSION["show"] == "multiedit_kg") {
if($access['kg']['MAX'] < 3) break;
kota_submit_multiedit(2);
}
if(!$notifier->hasErrors()) $notifier->addInfo(11, $do_action);
$_SESSION["show"] = $_SESSION["show_back"] ? $_SESSION["show_back"] : "show_all";
break;
//Löschen
case "delete_person":
$del_id = format_userinput($_POST["id"], "uint", TRUE);
if(!$del_id) break;
if($access['leute']['MAX'] < 3) break;
$ok = ko_leute_delete_person($del_id);
if($ok) {
$notifier->addInfo(3, $do_action);
} else {
$notifier->addError(4, $do_action);
}
break;
case 'undelete_person':
$del_id = format_userinput($_POST['id'], 'uint', TRUE);
if(!$del_id) break;
if(!($access['leute']['ALL'] > 2 || $access['leute'][$del_id] > 2)) break;
ko_get_person_by_id($del_id, $del_person);
if($del_person['deleted'] != 1) break;
ko_save_leute_changes($del_id, $del_person);
ko_log_diff('undelete_person', $del_person);
db_update_data('ko_leute', "WHERE `id` = '$del_id'", array('deleted' => '0'));
//set group datafields to undeleted
db_update_data('ko_groups_datafields_data', "WHERE `person_id` = '$del_id'", array('deleted' => '0'));
//re-subscribe to ezmlm
if(defined('EXPORT2EZMLM') && EXPORT2EZMLM) {
foreach(explode(',', $del_person['groups']) as $grp) {
$gid = ko_groups_decode($grp, 'group_id');
if($all_groups[$gid]['ezmlm_list']) ko_ezmlm_subscribe($all_groups[$gid]['ezmlm_list'], $all_groups[$gid]['ezmlm_moderator'], $del_person['email']);
}
}
//add person to LDAP
if(ko_do_ldap()) {
$ldap = ko_ldap_connect();
ko_ldap_add_person($ldap, $del_person, $del_id);
ko_ldap_close($ldap);
}
//Update group counts for all assigned groups
foreach(explode(',', $del_person['groups']) as $fullgid) {
$group = ko_groups_decode($fullgid, 'group');
if(!$group['maxcount']) continue;
ko_update_group_count($group['id'], $group['count_role']);
}
$notifier->addInfo(20, $do_action);
break;
//Mutationen
case "submit_mutation":
if($access['leute']['MAX'] < 2) break;
if(!$_POST["aa_id"]) break;
//Initialisierung
$do_ldap = ko_do_ldap();
$mod_aa_id = format_userinput($_POST["aa_id"], "uint");
//Mod- und alte Daten auslesen
ko_get_mod_leute($_mod_p, $mod_aa_id);
$mod_p = $_mod_p[$mod_aa_id];
if($access['leute']['ALL'] < 2 && ($access['leute'][$mod_p['_leute_id']] < 2 || $mod_p['_leute_id'] < 1)) break;
if($mod_p["_leute_id"] == -1) { //Neu:
$new_entry = TRUE;
$old_p = array();
} else {
$new_entry = FALSE;
ko_get_person_by_id($mod_p["_leute_id"], $old_p);
}
$found = FALSE;
foreach($_POST["chk_".$mod_aa_id] as $field => $field_state) {
if ($field_state == "0") continue;
if ($field == 'decouple_from_family') continue;
$data[$field] = format_userinput($_POST["txt_".$mod_aa_id][$field], "text");
$found = TRUE;
//Familien-Daten:
if(in_array($field, $COLS_LEUTE_UND_FAMILIE) && $old_p["famid"] != 0) {
$fam_data[$field] = format_userinput($_POST["txt_".$mod_aa_id][$field], "text");
}
//ezmlm: change email in mailinglist address if email has changed
if($field == "email" && !$new_entry && defined("EXPORT2EZMLM") && EXPORT2EZMLM) {
if($old_p["email"] != $data["email"] && check_email($data[$field])) { //Check for changed valid email
foreach(explode(",", $old_p["groups"]) as $group) { //Check this user's groups for one with an ML assigned
$gid = ko_groups_decode($group, "group_id");
if($all_groups[$gid]["ezmlm_list"]) {
//Un- and resubscribe
ko_ezmlm_unsubscribe($all_groups[$gid]["ezmlm_list"], $all_groups[$gid]["ezmlm_moderator"], $old_p["email"]);
ko_ezmlm_subscribe($all_groups[$gid]["ezmlm_list"], $all_groups[$gid]["ezmlm_moderator"], $data["email"]);
}
}
}
}
}//foreach(chk_id as field)
//mindestens eine markierte CheckBox gefunden
if($found) {
// delete family link if decoupled (and delete empty family)
$doUpdateFamily = false;
if($old_p["famid"] != 0 && $_POST["chk_".$mod_aa_id]['decouple_from_family']) {
$data['famid'] = 0;
$data['kinder'] = 0;
$num = ko_get_personen_by_familie($old_p["famid"], $asdf);
if($num <= 1) {
db_update_data('ko_leute', "WHERE `famid` = '".$old_p["famid"]."'", array('famid' => '0', 'kinder' => '0'));
db_delete_data('ko_familie', "WHERE `famid` = '".$old_p["famid"]."'");
}
else {
$doUpdateFamily = true;
}
}