forked from fisharebest/webtrees
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_interface.php
2850 lines (2574 loc) · 99.6 KB
/
edit_interface.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
// PopUp Window to provide editing features.
//
// webtrees: Web based Family History software
// Copyright (C) 2013 webtrees development team.
//
// Derived from PhpGedView
// Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved.
//
// This program 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.
//
// This program 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.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
define('WT_SCRIPT_NAME', 'edit_interface.php');
require './includes/session.php';
require WT_ROOT.'includes/functions/functions_edit.php';
$action = WT_Filter::post('action', null, WT_Filter::get('action'));
$controller=new WT_Controller_Simple();
$controller
->requireEditorLogin()
->addExternalJavascript(WT_STATIC_URL.'js/autocomplete.js')
->addInlineJavascript('
var locale_date_format="' . preg_replace('/[^DMY]/', '', str_replace(array('J', 'F'), array('D', 'M'), strtoupper($DATE_FORMAT))). '";
function openerpasteid(id) {
if (window.opener.paste_id) {
window.opener.paste_id(id);
}
window.close();
}
function paste_id(value) {
pastefield.value = value;
}
function paste_char(value) {
if (document.selection) {
// IE
pastefield.focus();
sel = document.selection.createRange();
sel.text = value;
} else if (pastefield.selectionStart || pastefield.selectionStart == 0) {
// Mozilla/Chrome/Safari
pastefield.value =
pastefield.value.substring(0, pastefield.selectionStart) +
value +
pastefield.value.substring(pastefield.selectionEnd, pastefield.value.length);
pastefield.selectionStart = pastefield.selectionEnd = pastefield.selectionStart + value.length;
} else {
// Fallback? - just append
pastefield.value += value;
}
if (pastefield.id=="NPFX" || pastefield.id=="GIVN" || pastefield.id=="SPFX" || pastefield.id=="SURN" || pastefield.id=="NSFX") {
updatewholename();
}
}
');
switch ($action) {
////////////////////////////////////////////////////////////////////////////////
case 'editraw':
$xref = WT_Filter::get('xref', WT_REGEX_XREF);
$record = WT_GedcomRecord::getInstance($xref);
check_record_access($record);
$controller
->setPageTitle($record->getFullName() . ' - ' . WT_I18N::translate('Edit raw GEDCOM'))
->pageHeader()
->addInlineJavascript('jQuery("#raw-gedcom-list").sortable({opacity: 0.7, cursor: "move", axis: "y"});');
?>
<div id="edit_interface-page">
<h4>
<?php echo $controller->getPageTitle(); ?>
<?php echo help_link('edit_edit_raw'); ?>
</h4>
<pre> <?php echo '0 @' . $record->getXref() . '@ ' . $record::RECORD_TYPE; ?></pre>
<form method="post" action="edit_interface.php">
<input type="hidden" name="ged" value="<?php echo WT_Filter::escapeHtml(WT_GEDCOM); ?>">
<input type="hidden" name="action" value="updateraw">
<input type="hidden" name="xref" value="<?php echo $xref; ?>">
<ul id="raw-gedcom-list">
<?php foreach ($record->getFacts() as $fact) { ?>
<?php if (!$fact->isOld()) { ?>
<li>
<div style="cursor:move;">
<?php echo $fact->summary(); ?>
</div>
<input type="hidden" name="fact_id[]" value="<?php echo $fact->getFactId(); ?>">
<textarea name="fact[]" dir="ltr" rows="<?php echo preg_match_all('/\n/', $fact->getGedcom(), $dummy_parameter_for_php53); ?>" style="width:100%;"><?php echo WT_Filter::escapeHtml($fact->getGedcom()); ?></textarea>
</li>
<?php } ?>
<?php } ?>
<li>
<div style="cursor:move;">
<b><i><?php echo WT_I18N::translate('Add a fact'); ?><i></b>
</div>
<input type="hidden" name="fact_id[]" value="">
<textarea name="fact[]" dir="ltr" rows="2" style="width:100%;"></textarea>
</li>
</ul>
<p id="save-cancel">
<input type="submit" class="save" value="<?php echo WT_I18N::translate('save'); ?>">
<input type="button" class="cancel" value="<?php echo WT_I18N::translate('close'); ?>" onclick="window.close();">
</p>
</form>
</div>
<?php
break;
////////////////////////////////////////////////////////////////////////////////
case 'updateraw':
$xref = WT_Filter::post('xref', WT_REGEX_XREF);
$facts = WT_Filter::postArray('fact');
$fact_ids = WT_Filter::postArray('fact_id');
$record = WT_GedcomRecord::getInstance($xref);
check_record_access($record);
$controller
->setPageTitle($record->getFullName() . ' - ' . WT_I18N::translate('Edit raw GEDCOM'))
->pageHeader();
$gedcom = '0 @' . $record->getXref() . '@ ' . $record::RECORD_TYPE;
// Retain any private facts
foreach ($record->getFacts(null, false, WT_PRIV_HIDE) as $fact) {
if (!in_array($fact->getFactId(), $fact_ids)) {
$gedcom .= "\n" . $fact->getGedcom();
}
}
// Append the new facts
foreach ($facts as $fact) {
$gedcom .= "\n" . $fact;
}
// Cleanup the client’s bad editing?
$gedcom = preg_replace('/[\r\n]+/', "\n", $gedcom); // Empty lines
$gedcom = trim($gedcom); // Leading/trailing spaces
$record->updateRecord($gedcom, false);
$controller->addInlineJavascript('closePopupAndReloadParent();');
break;
////////////////////////////////////////////////////////////////////////////////
case 'editrawfact':
$xref = WT_Filter::get('xref', WT_REGEX_XREF);
$fact_id = WT_Filter::get('fact_id');
$record = WT_GedcomRecord::getInstance($xref);
check_record_access($record);
// Find the fact to edit
$edit_fact = null;
foreach ($record->getFacts() as $fact) {
if ($fact->getFactId() == $fact_id && $fact->canEdit()) {
$edit_fact = $fact;
break;
}
}
if (!$edit_fact) {
$controller
->pageHeader()
->addInlineJavascript('closePopupAndReloadParent();');
exit;
}
$controller
->setPageTitle($record->getFullName() . ' - ' . WT_I18N::translate('Edit raw GEDCOM'))
->pageHeader();
?>
<div id="edit_interface-page">
<h4>
<?php echo $controller->getPageTitle(); ?>
<?php echo help_link('edit_edit_raw'); ?>
<?php print_specialchar_link('gedcom'); ?>
</h4>
<form method="post" action="edit_interface.php">
<input type="hidden" name="ged" value="<?php echo WT_Filter::escapeHtml(WT_GEDCOM); ?>">
<input type="hidden" name="action" value="updaterawfact">
<input type="hidden" name="xref" value="<?php echo $xref; ?>">
<input type="hidden" name="fact_id" value="<?php echo $fact_id; ?>">
<textarea name="gedcom" id="gedcom" dir="ltr"><?php echo WT_Filter::escapeHtml($edit_fact->getGedcom()); ?></textarea>
<table class="facts_table">
<?php echo keep_chan($record); ?>
</table>
<p id="save-cancel">
<input type="submit" class="save" value="<?php echo WT_I18N::translate('save'); ?>">
<input type="button" class="cancel" value="<?php echo WT_I18N::translate('close'); ?>" onclick="window.close();">
</p>
</form>
</div>
<?php
break;
////////////////////////////////////////////////////////////////////////////////
case 'updaterawfact':
$xref = WT_Filter::post('xref', WT_REGEX_XREF);
$fact_id = WT_Filter::post('fact_id');
$gedcom = WT_Filter::post('gedcom');
$keep_chan = WT_Filter::postBool('keep_chan');
$record = WT_GedcomRecord::getInstance($xref);
check_record_access($record);
// Find the fact to edit
$edit_fact = null;
foreach ($record->getFacts() as $fact) {
if ($fact->getFactId() == $fact_id && $fact->canEdit()) {
$edit_fact = $fact;
break;
}
}
if (!$edit_fact) {
$controller
->pageHeader()
->addInlineJavascript('closePopupAndReloadParent();');
exit;
}
$controller
->setPageTitle($record->getFullName() . ' - ' . WT_I18N::translate('Edit raw GEDCOM'))
->pageHeader();
// Cleanup the client’s bad editing?
$gedcom = preg_replace('/[\r\n]+/', "\n", $gedcom); // Empty lines
$gedcom = trim($gedcom); // Leading/trailing spaces
$record->updateFact($fact_id, $gedcom, !$keep_chan);
$controller->addInlineJavascript('closePopupAndReloadParent();');
break;
////////////////////////////////////////////////////////////////////////////////
case 'edit':
$xref = WT_Filter::get('xref', WT_REGEX_XREF);
$fact_id = WT_Filter::get('fact_id');
$record = WT_GedcomRecord::getInstance($xref);
check_record_access($record);
// Find the fact to edit
$edit_fact = null;
foreach ($record->getFacts() as $fact) {
if ($fact->getFactId() == $fact_id && $fact->canEdit()) {
$edit_fact = $fact;
break;
}
}
if (!$edit_fact) {
$controller
->pageHeader()
->addInlineJavascript('closePopupAndReloadParent();');
exit;
}
$controller
->setPageTitle($record->getFullName() . ' - ' . WT_I18N::translate('Edit'))
->pageHeader();
echo '<div id="edit_interface-page">';
echo '<h4>', $controller->getPageTitle(), '</h4>';
init_calendar_popup();
echo '<form name="editform" method="post" action="edit_interface.php" enctype="multipart/form-data">';
echo '<input type="hidden" name="ged" value="', WT_Filter::escapeHtml(WT_GEDCOM), '">';
echo '<input type="hidden" name="action" value="update">';
echo '<input type="hidden" name="fact_id" value="', $fact_id, '">';
echo '<input type="hidden" name="xref" value="', $xref, '">';
echo '<table class="facts_table">';
create_edit_form($record, $edit_fact);
echo keep_chan($record);
echo '</table>';
$level1type = $edit_fact->getTag();
switch ($record::RECORD_TYPE) {
case 'OBJE':
case 'NOTE':
// OBJE and NOTE facts are all special, and none can take lower-level links
break;
case 'SOUR':
case 'REPO':
// SOUR and REPO facts may only take a NOTE
if ($level1type!='NOTE') {
print_add_layer('NOTE');
}
break;
case 'FAM':
case 'INDI':
// FAM and INDI records have real facts. They can take NOTE/SOUR/OBJE/etc.
if ($level1type!='SEX') {
if ($level1type!='SOUR' && $level1type!='REPO') {
print_add_layer('SOUR');
}
if ($level1type!='OBJE' && $level1type!='REPO') {
print_add_layer('OBJE');
}
if ($level1type!='NOTE') {
print_add_layer('NOTE');
}
// Shared Note addition ------------
if ($level1type!='SHARED_NOTE' && $level1type!='NOTE') {
print_add_layer('SHARED_NOTE');
}
if ($level1type!='ASSO' && $level1type!='REPO' && $level1type!='NOTE') {
print_add_layer('ASSO');
}
// allow to add godfather and godmother for CHR fact or best man and bridesmaid for MARR fact in one window
if ($level1type=='CHR' || $level1type=='MARR') {
print_add_layer('ASSO2');
}
// RESN can be added to all level 1 tags
print_add_layer('RESN');
}
break;
}
if (WT_USER_IS_ADMIN || $SHOW_GEDCOM_RECORD) {
echo
'<br><br><a href="edit_interface.php?action=editrawfact&xref=', $xref, '&fact_id=', $fact_id, '&ged=', WT_GEDURL, '">',
WT_I18N::translate('Edit raw GEDCOM'),
'</a>';
}
?>
<p id="save-cancel">
<input type="submit" class="save" value="<?php echo WT_I18N::translate('save'); ?>">
<input type="button" class="cancel" value="<?php echo WT_I18N::translate('close'); ?>" onclick="window.close();">
</p>
</form>
</div>
<?php
break;
////////////////////////////////////////////////////////////////////////////////
case 'add':
$xref = WT_Filter::get('xref', WT_REGEX_XREF);
$fact = WT_Filter::get('fact', WT_REGEX_TAG);
$record = WT_GedcomRecord::getInstance($xref);
check_record_access($record);
$controller
->setPageTitle($record->getFullName() . ' - ' . WT_Gedcom_Tag::getLabel($fact, $record))
->pageHeader();
$level0type = $record::RECORD_TYPE;
echo '<div id="edit_interface-page">';
echo '<h4>', $controller->getPageTitle(), '</h4>';
init_calendar_popup();
echo '<form name="addform" method="post" action="edit_interface.php" enctype="multipart/form-data">';
echo '<input type="hidden" name="ged" value="', WT_Filter::escapeHtml(WT_GEDCOM), '">';
echo '<input type="hidden" name="action" value="update">';
echo '<input type="hidden" name="xref" value="', $xref, '">';
echo '<table class="facts_table">';
create_add_form($fact);
echo keep_chan($record);
echo '</table>';
// Genealogical facts (e.g. for INDI and FAM records) can have 2 SOUR/NOTE/OBJE/ASSO/RESN ...
if ($level0type=='INDI' || $level0type=='FAM') {
// ... but not facts which are simply links to other records
if ($fact!='OBJE' && $fact!='SHARED_NOTE' && $fact!='OBJE' && $fact!='REPO' && $fact!='SOUR' && $fact!='ASSO') {
print_add_layer('SOUR');
print_add_layer('OBJE');
// Don’t add notes to notes!
if ($fact!='NOTE') {
print_add_layer('NOTE');
print_add_layer('SHARED_NOTE');
}
print_add_layer('ASSO');
// allow to add godfather and godmother for CHR fact or best man and bridesmaid for MARR fact in one window
if ($fact=='CHR' || $fact=='MARR') {
print_add_layer('ASSO2');
}
print_add_layer('RESN');
}
}
?>
<p id="save-cancel">
<input type="submit" class="save" value="<?php echo WT_I18N::translate('save'); ?>">
<input type="button" class="cancel" value="<?php echo WT_I18N::translate('close'); ?>" onclick="window.close();">
</p>
</form>
</div>
<?php
break;
////////////////////////////////////////////////////////////////////////////////
case 'update':
// Update a fact
$xref = WT_Filter::post('xref', WT_REGEX_XREF);
$fact_id = WT_Filter::post('fact_id');
$keep_chan = WT_Filter::postBool('keep_chan');
$record = WT_GedcomRecord::getInstance($xref);
check_record_access($record);
// Arrays for each GEDCOM line
$glevels = WT_Filter::postArray('glevels', '[0-9]');
$tag = WT_Filter::postArray('tag', WT_REGEX_TAG);
$text = WT_Filter::postArray('text');
$islink = WT_Filter::postArray('islink', '[01]');
$controller
->setPageTitle(WT_I18N::translate('Edit'))
->pageHeader();
// If the fact has a DATE or PLAC, then delete any value of Y
if ($text[0]=='Y') {
for ($n=1; $n<count($tag); ++$n) {
if ($glevels[$n]==2 && ($tag[$n]=='DATE' || $tag[$n]=='PLAC') && $text[$n]) {
$text[0]='';
break;
}
}
}
//-- check for photo update
if (count($_FILES)>0) {
$folder = WT_Filter::post('folder');
$uploaded_files = array();
if (substr($folder, 0, 1) == "/") $folder = substr($folder, 1);
if (substr($folder, -1, 1) != "/") $folder .= "/";
foreach ($_FILES as $upload) {
if (!empty($upload['tmp_name'])) {
if (!move_uploaded_file($upload['tmp_name'], $MEDIA_DIRECTORY.$folder.basename($upload['name']))) {
$error .= "<br>".WT_I18N::translate('There was an error uploading your file.')."<br>".file_upload_error_text($upload['error']);
$uploaded_files[] = "";
} else {
$filename = $MEDIA_DIRECTORY.$folder.basename($upload['name']);
$uploaded_files[] = $MEDIA_DIRECTORY.$folder.basename($upload['name']);
if (!is_dir($MEDIA_DIRECTORY."thumbs/".$folder)) mkdir($MEDIA_DIRECTORY."thumbs/".$folder);
$thumbnail = $MEDIA_DIRECTORY."thumbs/".$folder.basename($upload['name']);
generate_thumbnail($filename, $thumbnail);
if (!empty($error)) {
echo "<span class=\"error\">", $error, "</span>";
}
}
} else {
$uploaded_files[] = "";
}
}
}
$newged = "";
if (!empty($_POST['NAME'])) $newged .= "\n1 NAME " . $_POST['NAME'];
if (!empty($_POST['TYPE'])) $newged .= "\n2 TYPE " . $_POST['TYPE'];
if (!empty($_POST['NPFX'])) $newged .= "\n2 NPFX " . $_POST['NPFX'];
if (!empty($_POST['GIVN'])) $newged .= "\n2 GIVN " . $_POST['GIVN'];
if (!empty($_POST['NICK'])) $newged .= "\n2 NICK " . $_POST['NICK'];
if (!empty($_POST['SPFX'])) $newged .= "\n2 SPFX " . $_POST['SPFX'];
if (!empty($_POST['SURN'])) $newged .= "\n2 SURN " . $_POST['SURN'];
if (!empty($_POST['NSFX'])) $newged .= "\n2 NSFX " . $_POST['NSFX'];
if (!empty($_POST['ROMN'])) $newged .= "\n2 ROMN " . $_POST['ROMN'];
if (!empty($_POST['FONE'])) $newged .= "\n2 FONE " . $_POST['FONE'];
if (!empty($_POST['_HEB'])) $newged .= "\n2 _HEB " . $_POST['_HEB'];
if (!empty($_POST['_AKA'])) $newged .= "\n2 _AKA " . $_POST['_AKA'];
if (!empty($_POST['_MARNM'])) $newged .= "\n2 _MARNM " . $_POST['_MARNM'];
if (isset($_POST['NOTE'])) $NOTE = $_POST['NOTE'];
if (!empty($NOTE)) {
$tempnote = preg_split('/\r?\n/', trim($NOTE) . "\n"); // make sure only one line ending on the end
$title[] = "0 @$xref@ NOTE " . array_shift($tempnote);
foreach($tempnote as &$line) {
$line = trim("1 CONT " . $line,' ');
}
}
$newged = handle_updates($newged);
$newged = substr($newged, 1); // Remove leading newline
$record->updateFact($fact_id, $newged, !$keep_chan);
// For the GEDFact_assistant module
$pid_array = WT_Filter::post('pid_array');
if ($pid_array) {
foreach (explode(', ', $pid_array) as $pid) {
if ($pid != $xref) {
$indi = WT_Individual::getInstance($pid);
if ($indi && $indi->canEdit()) {
$indi->updateFact($fact_id, $newged, !$keep_chan);
}
}
}
}
$controller->addInlineJavascript('closePopupAndReloadParent();');
break;
////////////////////////////////////////////////////////////////////////////////
// Add a new child to an existing family
////////////////////////////////////////////////////////////////////////////////
case 'add_child_to_family':
$xref = WT_Filter::get('xref', WT_REGEX_XREF);
$gender = WT_Filter::get('gender', '[MFU]', 'U');
$family = WT_Family::getInstance($xref);
check_record_access($family);
$controller
->setPageTitle($family->getFullName() . ' - ' . WT_I18N::translate('Add a new child'))
->pageHeader();
print_indi_form('add_child_to_family_action', null, $family, null, 'CHIL', $gender);
break;
case 'add_child_to_family_action':
$xref = WT_Filter::post('xref', WT_REGEX_XREF);
$PEDI = WT_Filter::post('PEDI');
$keep_chan = WT_Filter::postBool('keep_chan');
$glevels = WT_Filter::postArray('glevels', '[0-9]');
$tag = WT_Filter::postArray('tag', WT_REGEX_TAG);
$text = WT_Filter::postArray('text');
$islink = WT_Filter::postArray('islink', '[01]');
$family = WT_Family::getInstance($xref);
check_record_access($family);
$controller->pageHeader();
splitSOUR();
$gedrec ="0 @REF@ INDI";
$gedrec.=addNewName();
$gedrec.=addNewSex ();
if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FACTS, $matches)) {
foreach ($matches[1] as $match) {
$gedrec.=addNewFact($match);
}
}
$gedrec .= "\n".WT_Gedcom_Code_Pedi::createNewFamcPedi($PEDI, $xref);
if (WT_Filter::postBool('SOUR_INDI')) {
$gedrec = handle_updates($gedrec);
} else {
$gedrec = updateRest($gedrec);
}
// Create the new child
$new_child = WT_GedcomRecord::createRecord($gedrec, WT_GED_ID);
// Insert new child at the right place
$done = false;
foreach ($family->getFacts('CHIL') as $fact) {
$old_child = $fact->getTarget();
if ($old_child && WT_Date::Compare($new_child->getEstimatedBirthDate(), $old_child->getEstimatedBirthDate())<0) {
// Insert before this child
$family->updateFact($fact->getFactId(), '1 CHIL @' . $new_child->getXref() . "@\n" . $fact->getGedcom(), !$keep_chan);
$done = true;
break;
}
}
if (!$done) {
// Append child at end
$family->createFact('1 CHIL @' . $new_child->getXref() . '@', !$keep_chan);
}
if (WT_Filter::post('goto')=='new') {
$controller->addInlineJavascript('closePopupAndReloadParent("' . $new_child->getRawUrl() . '");');
} else {
$controller->addInlineJavascript('closePopupAndReloadParent();');
}
break;
////////////////////////////////////////////////////////////////////////////////
// Add a new child to an existing individual (creating a one-parent family)
////////////////////////////////////////////////////////////////////////////////
case 'add_child_to_individual':
$xref = WT_Filter::get('xref', WT_REGEX_XREF);
$person = WT_Individual::getInstance($xref);
check_record_access($person);
$controller
->setPageTitle($person->getFullName() . ' - ' . WT_I18N::translate('Add a child to create a one-parent family'))
->pageHeader();
print_indi_form('add_child_to_individual_action', $person, null, null, 'CHIL', $person->getSex());
break;
case 'add_child_to_individual_action':
$xref = WT_Filter::post('xref', WT_REGEX_XREF);
$PEDI = WT_Filter::post('PEDI');
$glevels = WT_Filter::postArray('glevels', '[0-9]');
$tag = WT_Filter::postArray('tag', WT_REGEX_TAG);
$text = WT_Filter::postArray('text');
$islink = WT_Filter::postArray('islink', '[01]');
$person = WT_Individual::getInstance($xref);
check_record_access($person);
$controller->pageHeader();
// Create a family
if ($person->getSex()=='F') {
$gedcom = "0 @NEW@ FAM\n1 WIFE @" . $person->getXref() . "@";
} else {
$gedcom = "0 @NEW@ FAM\n1 HUSB @" . $person->getXref() . "@";
}
$family = WT_GedcomRecord::createRecord($gedcom, WT_GED_ID);
// Link the parent to the family
$person->createFact('1 FAMS @' . $family->getXref() . '@', true);
// Create a child
splitSOUR(); // separate SOUR record from the rest
$gedcom = '0 @NEW@ INDI';
$gedcom .= addNewName();
$gedcom .= addNewSex ();
$gedcom .= "\n".WT_Gedcom_Code_Pedi::createNewFamcPedi($PEDI, $family->getXref());
if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FACTS, $matches)) {
foreach ($matches[1] as $match) {
$gedcom.=addNewFact($match);
}
}
if (WT_Filter::postBool('SOUR_INDI')) {
$gedcom=handle_updates($gedcom);
} else {
$gedcom=updateRest($gedcom);
}
$child = WT_GedcomRecord::createRecord($gedcom, WT_GED_ID);
// Link the family to the child
$family->createFact('1 CHIL @' . $child->getXref() . '@', true);
if (WT_Filter::post('goto')=='new') {
$controller->addInlineJavascript('closePopupAndReloadParent("' . $child->getRawUrl() . '");');
} else {
$controller->addInlineJavascript('closePopupAndReloadParent();');
}
break;
////////////////////////////////////////////////////////////////////////////////
// Add a new parent to an existing individual (creating a one-parent family)
////////////////////////////////////////////////////////////////////////////////
case 'add_parent_to_individual':
$xref = WT_Filter::get('xref', WT_REGEX_XREF);
$gender = WT_Filter::get('gender', '[MF]', 'U');
$individual = WT_Individual::getInstance($xref);
check_record_access($individual);
if ($gender=='F') {
$controller->setPageTitle(WT_I18N::translate('Add a new mother'));
$famtag = 'WIFE';
} else {
$controller->setPageTitle(WT_I18N::translate('Add a new father'));
$famtag = 'HUSB';
}
$controller->pageHeader();
print_indi_form('add_parent_to_individual_action', $individual, null, null, $famtag, $gender);
break;
case 'add_parent_to_individual_action':
$xref = WT_Filter::post('xref', WT_REGEX_XREF);
$PEDI = WT_Filter::post('PEDI');
$glevels = WT_Filter::postArray('glevels', '[0-9]');
$tag = WT_Filter::postArray('tag', WT_REGEX_TAG);
$text = WT_Filter::postArray('text');
$islink = WT_Filter::postArray('islink', '[01]');
$person = WT_Individual::getInstance($xref);
check_record_access($person);
$controller->pageHeader();
// Create a new family
$gedcom = "0 @NEW@ FAM\n1 CHIL @" . $person->getXref() . "@";
$family = WT_GedcomRecord::createRecord($gedcom, WT_GED_ID);
// Link the child to the family
$person->createFact('1 FAMC @' . $family->getXref() . '@', true);
// Create a child
splitSOUR(); // separate SOUR record from the rest
$gedcom = '0 @NEW@ INDI';
$gedcom .= addNewName();
$gedcom .= addNewSex ();
if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FACTS, $matches)) {
foreach ($matches[1] as $match) {
$gedcom.=addNewFact($match);
}
}
if (WT_Filter::postBool('SOUR_INDI')) {
$gedcom=handle_updates($gedcom);
} else {
$gedcom=updateRest($gedcom);
}
$gedcom .= "\n1 FAMS @" . $family->getXref() . "@";
$parent = WT_GedcomRecord::createRecord($gedcom, WT_GED_ID);
// Link the family to the child
if ($parent->getSex()=='F') {
$family->createFact('1 WIFE @' . $parent->getXref() . '@', true);
} else {
$family->createFact('1 HUSB @' . $parent->getXref() . '@', true);
}
if (WT_Filter::post('goto')=='new') {
$controller->addInlineJavascript('closePopupAndReloadParent("' . $parent->getRawUrl() . '");');
} else {
$controller->addInlineJavascript('closePopupAndReloadParent();');
}
break;
////////////////////////////////////////////////////////////////////////////////
// Add a new, unlinked individual
////////////////////////////////////////////////////////////////////////////////
case 'add_unlinked_indi':
$controller
->requireManagerLogin()
->setPageTitle(WT_I18N::translate('Create a new individual'))
->pageHeader();
print_indi_form('add_unlinked_indi_action', null, null, null, null, null);
break;
case 'add_unlinked_indi_action':
$glevels = WT_Filter::postArray('glevels', '[0-9]');
$tag = WT_Filter::postArray('tag', WT_REGEX_TAG);
$text = WT_Filter::postArray('text');
$islink = WT_Filter::postArray('islink', '[01]');
$controller
->requireManagerLogin()
->pageHeader();
splitSOUR();
$gedrec ="0 @REF@ INDI";
$gedrec.=addNewName();
$gedrec.=addNewSex ();
if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FACTS, $matches)) {
foreach ($matches[1] as $match) {
$gedrec.=addNewFact($match);
}
}
if (WT_Filter::postBool('SOUR_INDI')) {
$gedrec = handle_updates($gedrec);
} else {
$gedrec = updateRest($gedrec);
}
$new_indi = WT_GedcomRecord::createRecord($gedrec, WT_GED_ID);
if (WT_Filter::post('goto')=='new') {
$controller->addInlineJavascript('closePopupAndReloadParent("' . $new_indi->getRawUrl() . '");');
} else {
$controller->addInlineJavascript('closePopupAndReloadParent();');
}
break;
////////////////////////////////////////////////////////////////////////////////
// Add a new spouse to an existing individual (creating a new family)
////////////////////////////////////////////////////////////////////////////////
case 'add_spouse_to_individual':
$famtag = WT_Filter::get('famtag', 'HUSB|WIFE');
$xref = WT_Filter::get('xref', WT_REGEX_XREF);
$individual = WT_Individual::getInstance($xref);
check_record_access($individual);
if ($famtag=='WIFE') {
$controller->setPageTitle(WT_I18N::translate('Add a new wife'));
$sex = 'F';
} else {
$controller->setPageTitle(WT_I18N::translate('Add a new husband'));
$sex = 'M';
}
$controller->pageHeader();
print_indi_form('add_spouse_to_individual_action', $individual, null, null, $famtag, $sex);
break;
case 'add_spouse_to_individual_action':
$xref = WT_Filter::post('xref'); // Add a spouse to this individual
$sex = WT_Filter::post('SEX', '[MFU]', 'U');
$glevels = WT_Filter::postArray('glevels', '[0-9]');
$tag = WT_Filter::postArray('tag', WT_REGEX_TAG);
$text = WT_Filter::postArray('text');
$islink = WT_Filter::postArray('islink', '[01]');
$person = WT_Individual::getInstance($xref);
check_record_access($person);
$controller
->setPageTitle(WT_I18N::translate('Add a new spouse'))
->pageHeader();
splitSOUR();
$indi_gedcom = '0 @REF@ INDI';
$indi_gedcom.= addNewName();
$indi_gedcom.= addNewSex ();
if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FACTS, $matches)) {
foreach ($matches[1] as $match) {
$indi_gedcom.=addNewFact($match);
}
}
if (WT_Filter::postBool('SOUR_INDI')) {
$indi_gedcom = handle_updates($indi_gedcom);
} else {
$indi_gedcom = updateRest($indi_gedcom);
}
$fam_gedcom = '';
if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FAMFACTS, $matches)) {
foreach ($matches[1] as $match) {
$fam_gedcom.=addNewFact($match);
}
}
if (WT_Filter::postBool('SOUR_FAM')) {
$fam_gedcom = handle_updates($fam_gedcom);
} else {
$fam_gedcom = updateRest($fam_gedcom);
}
// Create the new spouse
$spouse = WT_GedcomRecord::createRecord($indi_gedcom, WT_GED_ID);
// Create a new family
if ($sex == 'F') {
$family = WT_GedcomRecord::createRecord("0 @NEW@ FAM\n1 WIFE @" . $spouse->getXref() . "@\n1 HUSB @" . $person->getXref() . "@" . $fam_gedcom, WT_GED_ID);
} else {
$family = WT_GedcomRecord::createRecord("0 @NEW@ FAM\n1 HUSB @" . $spouse->getXref() . "@\n1 WIFE @" . $person->getXref() . "@" . $fam_gedcom, WT_GED_ID);
}
// Link the spouses to the family
$spouse->createFact('1 FAMS @' . $family->getXref() . '@', true);
$person->createFact('1 FAMS @' . $family->getXref() . '@', true);
if (WT_Filter::post('goto')=='new') {
$controller->addInlineJavascript('closePopupAndReloadParent("' . $spouse->getRawUrl() . '");');
} else {
$controller->addInlineJavascript('closePopupAndReloadParent();');
}
break;
////////////////////////////////////////////////////////////////////////////////
// Add a new spouse to an existing family
////////////////////////////////////////////////////////////////////////////////
case 'add_spouse_to_family':
$xref = WT_Filter::get('xref', WT_REGEX_XREF);
$famtag = WT_Filter::get('famtag', 'HUSB|WIFE');
$family = WT_Family::getInstance($xref);
check_record_access($family);
if ($famtag=='WIFE') {
$controller->setPageTitle(WT_I18N::translate('Add a new wife'));
$sex = 'F';
} else {
$controller->setPageTitle(WT_I18N::translate('Add a new husband'));
$sex = 'M';
}
$controller->pageHeader();
print_indi_form('add_spouse_to_family_action', null, $family, null, $famtag, $sex);
break;
case 'add_spouse_to_family_action':
$xref = WT_Filter::post('xref', WT_REGEX_XREF);
$glevels = WT_Filter::postArray('glevels', '[0-9]');
$tag = WT_Filter::postArray('tag', WT_REGEX_TAG);
$text = WT_Filter::postArray('text');
$islink = WT_Filter::postArray('islink', '[01]');
$family = WT_Family::getInstance($xref);
check_record_access($family);
$controller->pageHeader();
// Create the new spouse
splitSOUR(); // separate SOUR record from the rest
$gedrec ="0 @REF@ INDI";
$gedrec.=addNewName();
$gedrec.=addNewSex ();
if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FACTS, $matches)) {
foreach ($matches[1] as $match) {
$gedrec.=addNewFact($match);
}
}
if (WT_Filter::postBool('SOUR_INDI')) {
$gedrec = handle_updates($gedrec);
} else {
$gedrec = updateRest($gedrec);
}
$gedrec .= "\n1 FAMS @" . $family->getXref() . "@";
$spouse = WT_GedcomRecord::createRecord($gedrec, WT_GED_ID);
// Update the existing family - add marriage, etc
if ($family->getFirstFact('HUSB')) {
$family->createFact('1 WIFE @' . $spouse->getXref() . '@', true);
} else {
$family->createFact('1 HUSB @' . $spouse->getXref() . '@', true);
}
$famrec = '';
if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FAMFACTS, $matches)) {
foreach ($matches[1] as $match) {
$famrec.=addNewFact($match);
}
}
if (WT_Filter::postBool('SOUR_FAM')) {
$famrec = handle_updates($famrec);
} else {
$famrec = updateRest($famrec);
}
$family->createFact(trim($famrec), true); // trim leading \n
if (WT_Filter::post('goto')=='new') {
$controller->addInlineJavascript('closePopupAndReloadParent("' . $spouse->getRawUrl() . '");');
} else {
$controller->addInlineJavascript('closePopupAndReloadParent();');
}
break;
////////////////////////////////////////////////////////////////////////////////
// Link an individual to an existing family, as a child
////////////////////////////////////////////////////////////////////////////////
case 'addfamlink':
$xref = WT_Filter::get('xref', WT_REGEX_XREF);
$person = WT_Individual::getInstance($xref);
check_record_access($person);
$controller
->setPageTitle($person->getFullName() . ' - ' . WT_I18N::translate('Link this individual to an existing family as a child'))
->pageHeader();
?>
<div id="edit_interface-page">
<h4><?php echo $controller->getPageTitle(); ?></h4>
<form method="post" name="addchildform" action="edit_interface.php">
<input type="hidden" name="ged" value="<?php echo WT_Filter::escapeHtml(WT_GEDCOM); ?>">
<input type="hidden" name="action" value="linkfamaction">
<input type="hidden" name="xref" value="<?php echo $person->getXref(); ?>">
<table class="facts_table">
<tr>
<td class="facts_label">
<?php echo WT_I18N::translate('Family'); ?>
</td>
<td class="facts_value">
<input type="text" id="famid" name="famid" size="8">
<?php echo print_findfamily_link('famid'); ?>
</td>
</tr>
<tr>
<td class="facts_label">
<?php echo WT_Gedcom_Tag::getLabel('PEDI'); ?>
</td>
<td class="facts_value">
<?php echo edit_field_pedi('PEDI', '', '', $person); ?>
<?php echo help_link('PEDI'); ?>
</td>
</tr>
<?php echo keep_chan($person); ?>
</table>
<p id="save-cancel">
<input type="submit" class="save" value="<?php echo WT_I18N::translate('save'); ?>">
<input type="button" class="cancel" value="<?php echo WT_I18N::translate('close'); ?>" onclick="window.close();">
</p>
</form>
</div>
<?php
break;
case 'linkfamaction':
$xref = WT_Filter::post('xref', WT_REGEX_XREF);
$famid = WT_Filter::post('famid', WT_REGEX_XREF);
$PEDI = WT_Filter::post('PEDI');
$person = WT_Individual::getInstance($xref);
$family = WT_Family::getInstance($famid);
check_record_access($person);
check_record_access($family);
$controller
->setPageTitle($person->getFullName() . ' - ' . WT_I18N::translate('Link this individual to an existing family as a child'))
->pageHeader();
// Replace any existing child->family link (we may be changing the PEDI);
$fact_id = null;
foreach ($person->getFacts('FAMC') as $fact) {
if ($family === $fact->getTarget()) {
$fact_id = $fact->getFactId();