-
Notifications
You must be signed in to change notification settings - Fork 1
/
edit_interface.php
2595 lines (2442 loc) · 102 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.
*
* Genmod: Genealogy Viewer
* Copyright (C) 2005 - 2012 Genmod Development Team
*
* 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
*
* @package Genmod
* @subpackage Edit
* @version $Id: edit_interface.php 29 2022-07-17 13:18:20Z Boudewijn $
*/
/**
* Inclusion of the configuration file
*/
require("config.php");
// Force to show changes
$show_changes = true;
/** * Inclusion of the country names
*/
require(SystemConfig::$GM_BASE_DIRECTORY."languages/countries.en.php");
if (file_exists(SystemConfig::$GM_BASE_DIRECTORY."languages/countries.".$lang_short_cut[$LANGUAGE].".php")) require(SystemConfig::$GM_BASE_DIRECTORY."languages/countries.".$lang_short_cut[$LANGUAGE].".php");
asort($countries);
if ($_SESSION["cookie_login"]) {
if (LOGIN_URL == "") header("Location: login.php?type=simple&gedid=".GedcomConfig::$GEDCOMID."&url=edit_interface.php".urlencode("?".$QUERY_STRING));
else header("Location: ".LOGIN_URL."?type=simple&gedid=".GedcomConfig::$GEDCOMID."&url=edit_interface.php".urlencode("?".$QUERY_STRING));
exit;
}
// Remove slashes
if (isset($text)){
foreach ($text as $l => $line){
$text[$l] = stripslashes($line);
}
}
if (!isset($action)) $action="";
if (!isset($linenum)) $linenum="";
if (isset($pid)) $pid = strtoupper($pid);
$uploaded_files = array();
if (!isset($aa_attempt)) $aa_attempt = false;
$can_auto_accept = true;
$assorela = EditFunctions::GetAssoRela();
PrintSimpleHeader("Edit Interface ".GM_VERSION);
// Debug info
//print "Action: ".$action."<br />Pid: ".$pid;
?>
<script type="text/javascript">
<!--
function openerpasteid(id) {
window.opener.paste_id(id);
window.close();
}
var pastefield;
function paste_id(value) {
pastefield.value = value;
if (pastefield.type != 'hidden') pastefield.focus();
}
function paste_char(value,lang,mag) {
pastefield.value += value;
language_filter = lang;
magnify = mag;
}
// This reload function is empty, as it may be called from edit_close from a 2nd or third edit level.
function reload() {
}
function edit_close() {
window.opener.location.reload();
window.close();
}
//-->
</script>
<?php
// Submitter records must be found first on add/edit
if ($action == "submitter") {
SwitchGedcom($gedfile);
$subm = EditFunctions::FindSubmitter($gedfile);
if (is_object($subm) && !$subm->isempty) {
$pid = $subm->xref;
$pid_type = $subm->datatype;
}
else $pid_type="SUBM";
}
if ($action == "update_submitter") {
SwitchGedcom($gedfile);
}
//-- check if user has access to the gedcom record
$disp = false;
$success = false;
$factdisp = true;
$factedit = true;
$object = "";
if (!empty($pid)) {
// NOTE: Remove any illegal characters from the ID
$pid = CleanInput($pid);
if ((strtolower($pid) != "newsour") && (strtolower($pid) != "newrepo") && (strtolower($pid) != "newmedia") && (strtolower($pid) != "newgnote")&& (strtolower($pid) != "newsubmitter")) {
// NOTE: Do not take the changed record here since non-approved changes should not yet appear
$object =& ConstructObject($pid, $pid_type, GedcomConfig::$GEDCOMID);
if ($object->isdeleted) $disp = false; // We cannot edit a deleted record!
if ($object->ischanged) $gedrec = $object->changedgedrec;
else $gedrec = $object->gedrec;
if (!$object->isempty) {
$disp = $object->disp;
//-- if the record is for an INDI then check for display privileges for that indi
if ($pid_type == "INDI" || $pid_type == "FAM") {
//-- if disp is true, also check for resn access
if ($object->hiddenfacts) $factdisp = false;
if (!$object->canedit) $factedit = false;
if ($factdisp || $factedit) {
foreach ($object->facts as $key => $factobj) {
if ($factobj->fact != "CHAN") {
if (!$factobj->disp) $factdisp = false;
if (!$factobj->canedit) $factedit = false;
}
}
}
}
//-- for FAM check for display privileges on both parents
if ($pid_type == "FAM") {
$disp = true;
//-- check if we can display both parents
if (is_object($object->wife) && !$object->wife->disp) $disp = false;
if ($disp) {
if (is_object($object->husb) && !$object->husb->disp) $disp = false;
}
}
else {
$disp = true;
}
}
else {
$disp = true;
}
}
else {
$gedrec = "";
$disp = true;
}
}
else if (!empty($famid)) {
$famid = CleanInput($famid);
if ($famid != "new") {
$object =& ConstructObject($famid, $pid_type, GedcomConfig::$GEDCOMID);
if ($object->isdeleted) $disp = false; // We cannot edit a deleted record!
if ($object->ischanged) $gedrec = $object->changedgedrec;
else $gedrec = $object->gedrec;
if (!$object->isempty) {
$disp = $object->disp;
//-- if the record is for an INDI then check for display privileges for that indi
if ($pid_type == "INDI" || $pid_type == "FAM") {
//-- if disp is true, also check for resn access
if ($object->hiddenfacts) $factdisp = false;
if (!$object->canedit) $factedit = false;
if ($factdisp || $factedit) {
foreach ($object->facts as $key => $factobj) {
if ($factobj->fact != "CHAN") {
if (!$factobj->disp) $factdisp = false;
if (!$factobj->canedit) $factedit = false;
}
}
}
}
//-- for FAM check for display privileges on both parents
if ($pid_type=="FAM") {
//-- check if we can display both parents
if (is_object($object->wife) && !$object->wife->disp) $disp = false;
if ($disp) {
if (is_object($object->husb) && !$object->husb->disp) $disp = false;
}
}
else {
$disp=true;
}
}
else {
$disp = true;
}
}
}
else {
if (($action!="addchild")&&($action!="addchildaction")&&($action!="submitter")) {
EditFunctions::PrintFailMessage("The \$pid variable was empty. Unable to perform $action");
PrintSimpleFooter();
exit;
// exit added, what's the following line for?
$disp = true;
}
else {
$disp = true;
}
}
if ($action == "edit" || $action == "editraw") {
// Get the fact record
if ($action == "edit") {
if ($change_type == "edit_general_note") {
$recs = explode("\r\n", trim($gedrec));
$gedrec = $recs[0]."\r\n";
for ($i=1;$i<count($recs);$i++) {
$ct = preg_match("/\d\s(\w+)/", $recs[$i], $match);
if (in_array($match[1], array("CONC", "CONT", "NOTE"))) $gedrec .= $recs[$i]."\r\n";
}
$oldrec = $gedrec;
}
else $oldrec = GetSubRecord(1, "1 $fact", $gedrec, $count);
}
else {
// We make an exception for the admin!
if ($object->hiddenfacts && !$gm_user->userIsAdmin()) $disp = false;
$oldrec = $gedrec;
}
// Check links from the fact to hidden sources, media, etc. is not needed: done in hiddenfacts
}
if (!$gm_user->userCanEdit() || !$disp || !GedcomConfig::$ALLOW_EDIT_GEDCOM || (!$gm_user->userCanEditGedlines() && $action == "editraw")) {
print "<div class=\"EditMessageFail\">";
print GM_LANG_access_denied;
//-- display messages as to why the editing access was denied
if (!$gm_user->userCanEdit()) print "<br />".GM_LANG_user_cannot_edit;
else if (!GedcomConfig::$ALLOW_EDIT_GEDCOM) print "<br />".GM_LANG_gedcom_editing_disabled;
else if (!$disp) {
EditFunctions::PrintFailMessage(GM_LANG_privacy_prevented_editing.(!empty($pid) ? "<br />".GM_LANG_privacy_not_granted." pid $pid." : "").(!empty($famid) ? "<br />".GM_LANG_privacy_not_granted." famid $famid." : ""));
}
print "</div>";
print "<div class=\"CloseWindow\"><a href=\"javascript: ".GM_LANG_close_window."\" onclick=\"window.close();\">".GM_LANG_close_window."</a></div>\n";
PrintSimpleFooter();
exit;
}
// Page header
print "<div class=\"NavBlockHeader EditHeader\">";
if (!isset($pid_type)) {
if (is_object($object)) $pid_type = $object->datatype;
else $pid_type="";
}
if (!empty($pid_type) && is_object($object)) {
print $object->name."<br />";
}
if (strstr($action,"addchild")) {
if (empty($famid)) {
PrintHelpLink("edit_add_unlinked_person_help", "qm");
print GM_LANG_add_unlinked_person."\n";
}
else {
PrintHelpLink("edit_add_child_help", "qm");
print GM_LANG_add_child."\n";
}
}
else if (strstr($action,"addspouse")) {
PrintHelpLink("edit_add_spouse_help", "qm");
print constant("GM_LANG_add_".strtolower($famtag))."\n";
}
else if (strstr($action,"addnewparent")) {
PrintHelpLink("edit_add_parent_help", "qm");
if ($famtag == "WIFE") print GM_LANG_add_mother."\n";
else print GM_LANG_add_father."\n";
}
else {
if (defined("GM_FACT_".$pid_type)) print constant("GM_FACT_".$pid_type)."\n";
}
print "</div>";
switch ($action) {
// NOTE: Edit/add submitter
// NOTE: Done for Genmod 2.0
case "submitter":
if (empty($pid)) {
$pid = "newsubmitter";
$gedrec = "";
}
else {
// As the whole level 0 record is rewritten, we can only do one change at the time
if ($object->ischanged) {
EditFunctions::PrintFailMessage(GM_LANG_approve_first.": ".$pid);
PrintSimpleFooter();
exit;
}
}
$change_id = EditFunctions::GetNewXref("CHANGE");
print "<form method=\"post\" action=\"edit_interface.php\" enctype=\"multipart/form-data\">\n";
print "<input type=\"hidden\" name=\"action\" value=\"update_submitter\" />\n";
print "<input type=\"hidden\" name=\"pid\" value=\"".$pid."\" />\n";
print "<input type=\"hidden\" name=\"gedfile\" value=\"".$gedfile."\" />\n";
print "<input type=\"hidden\" name=\"fact\" value=\"SUBM\" />\n";
print "<input type=\"hidden\" name=\"change_type\" value=\"submitter_record\" />\n";
print "<input type=\"hidden\" name=\"pid_type\" value=\"SUBM\" />\n";
print "<table class=\"NavBlockTable EditTable\">";
EditFunctions::SubmitterRecord(0, $gedrec);
EditFunctions::AddAutoAcceptLink();
print "<tr><td class=\"NavBlockFooter\" colspan=\"2\"><input type=\"submit\" value=\"".GM_LANG_save."\" /></td></tr>\n";
print "</table>";
print "</form>\n";
$disp = true;
break;
// NOTE: Delete
// NOTE: deleteperson
// NOTE: Done for Genmod 2.0
case "deleteperson":
if (!$factedit) {
EditFunctions::PrintFailMessage(GM_LANG_privacy_prevented_editing.(!empty($pid) ? "<br />".GM_LANG_privacy_not_granted." pid $pid." : "").(!empty($famid) ? "<br />".GM_LANG_privacy_not_granted." famid $famid." : ""));
}
else {
// TODO: Notify user if record has already been deleted
// TODO: Add checking
if (!empty($gedrec)) {
$change_id = EditFunctions::GetNewXref("CHANGE");
$success = false;
// Save the fams for later, to check on empty families
$fams = $object->fams;
foreach($object->famc as $key => $famc) {
$fams[] = $famc["famid"];
}
// Delete all links to this person
$success = EditFunctions::DeleteLinks($pid, "INDI", $change_id, $change_type, GedcomConfig::$GEDCOMID);
// Remove resulting empty fams
foreach($fams as $key=>$fam) {
if ($success) $success = $success && EditFunctions::DeleteFamIfEmpty($fam, $change_id, $change_type, GedcomConfig::$GEDCOMID);
}
// Delete the person
if ($success) $success = $success && EditFunctions::DeleteGedrec($pid, $change_id, "delete_indi", "INDI");
if ($success) EditFunctions::PrintSuccessMessage(GM_LANG_gedrec_deleted);
}
}
break;
// NOTE: deletefamily
// NOTE: Done for Genmod 2.0
case "deletefamily":
if (!$factedit) {
EditFunctions::PrintFailMessage(GM_LANG_privacy_prevented_editing.(!empty($pid) ? "<br />".GM_LANG_privacy_not_granted." pid $pid." : "").(!empty($famid) ? "<br />".GM_LANG_privacy_not_granted." famid $famid." : ""));
}
else {
if (!empty($gedrec)) {
$change_id = EditFunctions::GetNewXref("CHANGE");
$success = false;
$success = EditFunctions::DeleteLinks($famid, "FAM", $change_id, $change_type, GedcomConfig::$GEDCOMID);
if ($success) {
$success = $success && EditFunctions::DeleteGedrec($famid, $change_id, $change_type, "FAM");
}
if ($success) EditFunctions::PrintSuccessMessage(GM_LANG_gedrec_deleted);
}
}
break;
// NOTE: deletesource
// NOTE: Done for Genmod 2.0
case "deletesource":
if (!empty($gedrec)) {
$change_id = EditFunctions::GetNewXref("CHANGE");
$success = false;
$success = EditFunctions::DeleteLinks($pid, "SOUR", $change_id, $change_type, GedcomConfig::$GEDCOMID);
if ($success) {
$success = $success && EditFunctions::DeleteGedrec($pid, $change_id, $change_type, "SOUR");
}
if ($success) EditFunctions::PrintSuccessMessage(GM_LANG_gedrec_deleted);
}
break;
// NOTE: deleterepo
// NOTE: Done for Genmod 2.0
case "deleterepo":
if (!empty($gedrec)) {
$change_id = EditFunctions::GetNewXref("CHANGE");
$success = false;
$success = EditFunctions::DeleteLinks($pid, "REPO", $change_id, $change_type, GedcomConfig::$GEDCOMID);
if ($success) {
$success = $success && EditFunctions::DeleteGedrec($pid, $change_id, $change_type, "REPO");
}
if ($success) EditFunctions::PrintSuccessMessage(GM_LANG_gedrec_deleted);
}
break;
// NOTE: Done for Genmod 2.0
case "deletegnote":
if (!empty($gedrec)) {
$change_id = EditFunctions::GetNewXref("CHANGE");
$success = false;
$success = EditFunctions::DeleteLinks($pid, "NOTE", $change_id, $change_type, GedcomConfig::$GEDCOMID);
if ($success) {
$success = $success && EditFunctions::DeleteGedrec($pid, $change_id, $change_type, "NOTE");
}
if ($success) EditFunctions::PrintSuccessMessage(GM_LANG_gedrec_deleted);
}
break;
// NOTE: Done for Genmod 2.0
case "deletemedia":
if (!$factedit) {
EditFunctions::PrintFailMessage(GM_LANG_privacy_prevented_editing.(!empty($pid) ? "<br />".GM_LANG_privacy_not_granted." pid $pid." : ""));
}
else {
if (!empty($gedrec)) {
$change_id = EditFunctions::GetNewXref("CHANGE");
$success = false;
$success = EditFunctions::DeleteLinks($pid, "OBJE", $change_id, $change_type, GedcomConfig::$GEDCOMID);
if ($success) {
$success = $success && EditFunctions::DeleteGedrec($pid, $change_id, $change_type, "OBJE");
}
if ($success) EditFunctions::PrintSuccessMessage(GM_LANG_gedrec_deleted);
}
}
break;
// NOTE: delete
// NOTE: Done for Genmod 2.0
case "delete":
$change_id = EditFunctions::GetNewXref("CHANGE");
$success = false;
// Before using getsubrec, we must get the privatised gedrec. Otherwise the counter is not correct.
$gedrecpriv = implode("\r\n", GetAllSubrecords($gedrec, "", false, false));
$oldrec = GetSubRecord(1, "1 $fact", $gedrecpriv, $count);
$success = EditFunctions::ReplaceGedrec($pid, $oldrec, "", $fact, $change_id, $change_type, "", $pid_type);
if ($success) EditFunctions::PrintSuccessMessage(GM_LANG_gedrec_deleted);
break;
// NOTE: Reorder media
// NOTE: Done for Genmod 2.0
case "reorder_media":
?>
<form name="reorder_form" method="post" action="edit_interface.php">
<input type="hidden" name="action" value="reorder_media_update" />
<input type="hidden" name="pid" value="<?php print $pid; ?>" />
<input type="hidden" name="pid_type" value="<?php print $pid_type; ?>" />
<input type="hidden" name="change_type" value="<?php print $change_type; ?>" />
<table class="NavBlockTable EditTable">
<tr><td class="NavBlockColumnHeader EditTableColumnHeader" colspan="2">
<?php PrintHelpLink("reorder_media_help", "qm", "reorder_media"); ?>
<?php print GM_LANG_reorder_media; ?>
</td></tr>
<?php
$mfacts = $object->SelectFacts(array("OBJE"));
$okfacts = array();
foreach ($mfacts as $key => $factobj) {
if ($factobj->linktype == "MediaItem" && $factobj->linkxref != "" && $factobj->style != "ChangeOld") {
$okfacts[] = $factobj;
}
}
$ct = count($okfacts);
if ($ct > 0) {
$i=1;
foreach($okfacts as $key => $factobj) {
print "<tr>\n<td class=\"NavBlockField\">\n";
print "<select name=\"order[$i]\">\n";
for($j=1; $j<=$ct; $j++) {
print "<option value=\"".($j)."\"";
if ($j == $i) print " selected=\"selected\"";
print ">".($j)."</option>\n";
}
print "</select>\n";
print "</td><td class=\"NavBlockLabel\">";
$media =& MediaItem::GetInstance($factobj->linkxref, "", $factobj->gedcomid);
print $media->name;
print "</td>\n</tr>\n";
$i++;
}
}
?>
<tr><td class="NavBlockFooter" colspan="2">
<input type="submit" value="<?php print GM_LANG_save; ?>" />
</td></tr>
</table>
</form>
<?php
break;
// NOTE: Done for Genmod 2.0
case "reorder_media_update":
if (EditFunctions::CheckReorder($order)) {
$change_id = EditFunctions::GetNewXref("CHANGE");
$success = true;
$lines = count($order);
$f = array();
for ($i = 1; $i <= $lines; $i++) {
$t = getsubrecord(1,"1 OBJE", $gedrec, $i);
$f[$i] = $t;
}
foreach($order as $oldord => $neword) {
if ($neword != $oldord) {
$success = $success && (EditFunctions::ReplaceGedrec($pid, $f[$neword], $f[$oldord], "OBJE", $change_id, $change_type, "", $pid_type));
}
}
if ($success) EditFunctions::PrintSuccessMessage();
}
else {
EditFunctions::PrintFailMessage(GM_LANG_invalid_order);
$success = false;
}
break;
// NOTE: Reorder children
// NOTE: Done for Genmod 2.0
case "reorder_children":
?>
<form name="reorder_form" method="post" action="edit_interface.php">
<input type="hidden" name="action" value="reorder_update" />
<input type="hidden" name="pid" value="<?php print $pid; ?>" />
<input type="hidden" name="pid_type" value="<?php print $pid_type; ?>" />
<input type="hidden" name="change_type" value="<?php print $change_type; ?>" />
<input type="hidden" name="option" value="bybirth" />
<table class="NavBlockTable EditTable">
<tr><td class="NavBlockColumnHeader EditTableColumnHeader" colspan="2">
<?php PrintHelpLink("reorder_children_help", "qm", "reorder_children"); ?>
<?php print GM_LANG_reorder_children; ?>
</td></tr>
<?php
$children = $object->children;
// Filter out the deleted children
$keys = array();
$index = 1;
foreach($children as $key => $child) {
if ($child->isdeleted) unset ($children[$key]);
else {
$keys[$child->xref] = $index;
$index++;
}
}
if (!empty($option) && $option == "bybirth") {
uasort($children, "IndiBirthSort");
}
$ct = count($children);
$i = 1;
foreach($children as $pid => $child) {
print "<tr>\n<td class=\"NavBlockField\">\n";
print "<select name=\"order[".$keys[$child->xref]."]\">\n";
for($j = 1; $j <= $ct; $j++) {
print "<option value=\"".$j."\"";
if ($j == $i) print " selected=\"selected\"";
print ">".($j)."</option>\n";
}
print "</select>\n";
print "</td><td class=\"NavBlockLabel\">";
print $child->name;
print "<br />";
PersonFunctions::PrintFirstMajorFact($child);
print "</td>\n</tr>\n";
$i++;
}
?>
<tr><td class="NavBlockFooter" colspan="2">
<input type="submit" value="<?php print GM_LANG_save; ?>" />
<input type="button" value="<?php print GM_LANG_sort_by_birth; ?>" onclick="document.reorder_form.action.value='reorder_children'; document.reorder_form.submit();" />
</td></tr>
</table>
</form>
<?php
break;
// NOTE: reorder_update
// NOTE: Done for Genmod 2.0
case "reorder_update":
if (EditFunctions::CheckReorder($order)) {
$change_id = EditFunctions::GetNewXref("CHANGE");
$success = true;
$lines = count($order);
$f = array();
for ($i = 1; $i <= $lines; $i++) {
$t = getsubrecord(1,"1 CHIL", $gedrec, $i);
$f[$i] = $t;
}
foreach($order as $oldord => $neword) {
if ($neword != $oldord) {
$success = $success && (EditFunctions::ReplaceGedrec($pid, $f[$neword], $f[$oldord], "CHIL", $change_id, $change_type, "", $pid_type));
}
}
if ($success) EditFunctions::PrintSuccessMessage();
}
else {
EditFunctions::PrintFailMessage(GM_LANG_invalid_order);
$success = false;
}
break;
// NOTE: reorder_fams
// NOTE: Done for Genmod 2.0
case "reorder_fams":
?>
<form name="reorder_form" method="post" action="edit_interface.php">
<input type="hidden" name="action" value="reorder_fams_update" />
<input type="hidden" name="pid" value="<?php print $pid; ?>" />
<input type="hidden" name="change_type" value="<?php print $change_type; ?>" />
<input type="hidden" name="pid_type" value="<?php print $pid_type; ?>" />
<input type="hidden" name="option" value="bymarriage" />
<table class="NavBlockTable EditTable">
<tr><td class="NavBlockColumnHeader EditTableColumnHeader" colspan="2">
<?php PrintHelpLink("reorder_families_help", "qm", "reorder_families"); ?>
<?php print GM_LANG_reorder_families; ?>
</td></tr>
<?php
print "<tr><td class=\"NavBlockLabel\">".GM_LANG_order."</td><td class=\"NavBlockLabel\">".GM_LANG_family."</td></tr>";
$fams = $object->spousefamilies;
// Filter out the deleted children
$keys = array();
$index = 1;
foreach($fams as $key => $family) {
if ($family->isdeleted) unset ($fams[$key]);
else {
$keys[$family->xref] = $index;
$index++;
}
}
if (!empty($option) && $option == "bymarriage") {
$sortby = "MARR";
uasort($fams, "CompareDate");
}
$i=1;
$ct = count($fams);
foreach($fams as $famid => $family) {
print "<tr>\n<td class=\"NavBlockField\">\n";
print "<select name=\"order[".$keys[$family->xref]."]\">\n";
for($j = 1; $j <= $ct; $j++) {
print "<option value=\"".($j)."\"";
if ($j == $i) print " selected=\"selected\"";
print ">".($j)."</option>\n";
}
print "</select>\n";
print "</td><td class=\"NavBlockLabel\">";
print $family->name;
print "<br />";
FactFunctions::PrintSimpleFact($family->marr_fact, false, false);
print "</td>\n</tr>\n";
$i++;
}
?>
<tr><td class="NavBlockFooter" colspan = "2">
<input type="submit" value="<?php print GM_LANG_save; ?>" />
<input type="button" value="<?php print GM_LANG_sort_by_marriage; ?>" onclick="document.reorder_form.action.value='reorder_fams'; document.reorder_form.submit();" />
</td></tr>
</table>
</form>
<?php
break;
// NOTE: reorder_fams_update
// NOTE: Done for Genmod 2.0
case "reorder_fams_update":
if (EditFunctions::CheckReorder($order)) {
$change_id = EditFunctions::GetNewXref("CHANGE");
$success = true;
$lines = count($order);
$f = array();
for ($i = 1; $i <= $lines; $i++) {
$t = getsubrecord(1,"1 FAMS", $gedrec, $i);
$f[$i] = $t;
}
foreach($order as $oldord => $neword) {
if ($neword != $oldord) {
$success = $success && (EditFunctions::ReplaceGedrec($pid, $f[$neword], $f[$oldord], "FAMS", $change_id, $change_type, "", $pid_type));
}
}
if ($success) EditFunctions::PrintSuccessMessage();
}
else {
EditFunctions::PrintFailMessage(GM_LANG_invalid_order);
$success = false;
}
break;
// NOTE relation_fams
// NOTE: Done for Genmod 2.0
case "relation_fams":
?>
<form name="reorder_form" method="post" action="edit_interface.php">
<input type="hidden" name="action" value="relation_fams_update" />
<input type="hidden" name="pid" value="<?php print $pid; ?>" />
<input type="hidden" name="pid_type" value="<?php print $pid_type; ?>" />
<input type="hidden" name="change_type" value="<?php print $change_type; ?>" />
<table class="NavBlockTable EditTable">
<tr><td class="NavBlockColumnHeader EditTableColumnHeader" colspan="3">
<?php PrintHelpLink("relation_families_help", "qm", "relation_families"); ?>
<?php print GM_LANG_relation_families; ?>
</td></tr>
<?php
print "<tr><td class=\"NavBlockLabel\">".GM_FACT_PEDI."</td><td class=\"NavBlockLabel\">".GM_LANG_family."</td><td class=\"NavBlockLabel\">".GM_LANG_primary."</td></tr>";
$families = $object->childfamilies;
foreach($families as $key => $family) {
if ($family->isdeleted) unset($families[$key]);
}
$hasprimary = false;
foreach($families as $famid => $fam) {
print "<tr>\n<td class=\"NavBlockField\">\n";
EditFunctions::PrintPedi("pedi_".$fam->xref, "", $fam->pedigreetype);
print "</td><td class=\"NavBlockField\">";
print $fam->name;
print "<br />";
FactFunctions::PrintSimpleFact($fam->marr_fact, false, false);
print "</td>\n<td class=\"NavBlockField\">";
print "<input type=\"radio\" name=\"select_prim\" value=\"".$fam->xref."\" ";
if ($fam->showprimary) {
print "checked=\"checked\" ";
$hasprimary = true;
}
print "/></td></tr>\n";
}
print "<tr><td colspan=\"2\" class=\"NavBlockLabel\">".GM_LANG_no_primary."</td><td class=\"NavBlockField\">";
print "<input type=\"radio\" name=\"select_prim\" value=\"noprim\" ";
if (!$hasprimary) print "checked=\"checked\" ";
print "/></td></tr>\n";
?>
<tr><td class="NavBlockFooter" colspan = "3">
<input type="submit" value="<?php print GM_LANG_save; ?>" />
</td></tr>
</table>
</form>
<?php
break;
// NOTE: relation_fams_update
// NOTE: Done for Genmod 2.0
case "relation_fams_update":
$change_id = EditFunctions::GetNewXref("CHANGE");
$families = $object->childfamilies;
foreach($families as $key => $family) {
if ($family->isdeleted) unset($families[$key]);
}
// Check for more than 1 birth relation
$nobirths = 0;
foreach($families as $famid => $fam) {
$k = "pedi_".$fam->xref;
if ($$k == "birth") $nobirths++;
}
if ($nobirths <= 1) {
$success = true;
foreach($families as $famid => $fam) {
$update = false;
$rec = GetSubRecord(1, "1 FAMC @".$fam->xref."@", $gedrec, 1);
$k = "pedi_".$fam->xref;
if ($$k == "birth") $$k = "";
if ($$k != $fam->pedigreetype) {
if ($fam->pedigreetype == "") {
$recnew = trim($rec)."\r\n"."2 PEDI ".$$k;
}
else {
$repl = "2 PEDI ".$fam->pedigreetype;
if (!empty($$k)) $for = "2 PEDI ".$$k;
else $for = "";
$recnew = preg_replace("/$repl/", "$for", $rec);
}
$update = true;
}
else $recnew = $rec;
if ($fam->xref != $select_prim) {
if ($fam->showprimary) {
$recnew = preg_replace("/2 _PRIMARY Y/", "", $recnew);
$update = true;
}
}
else if (!$fam->showprimary) {
$recnew = trim($recnew)."\r\n2 _PRIMARY Y";
$update = true;
}
if ($update) $success = $success && EditFunctions::ReplaceGedrec($pid, $rec, $recnew, "FAMC", $change_id, $change_type, "", "INDI");
}
if ($success) EditFunctions::PrintSuccessMessage();
}
else {
EditFunctions::PrintFailMessage(GM_LANG_invalid_birthfams);
$success = false;
}
break;
// NOTE: changefamily
// NOTE: Done for Genmod 2.0
case "changefamily":
$father = $object->husb;
$mother = $object->wife;
$children = $object->children;
if (count($children)>0) {
if (is_object($father)) {
if ($father->sex == "F") $father->setFamLabel($famid, GM_LANG_mother);
else $father->setFamLabel($famid, GM_LANG_father);
}
if (is_object($mother)) {
if ($mother->sex == "M") $mother->setFamLabel($famid, GM_LANG_father);
else $mother->setFamLabel($famid, GM_LANG_mother);
}
foreach ($children as $i => $child) {
if (is_object($children[$i])) {
if ($children[$i]->sex == "M") $children[$i]->setFamLabel($famid, GM_LANG_son);
else if ($children[$i]->sex == "F") $children[$i]->setFamLabel($famid, GM_LANG_daughter);
else $children[$i]->setFamLabel($famid, GM_LANG_child);
}
}
}
else {
if (is_object($father)) {
if ($father->sex == "F") $father->setFamLabel($famid, GM_LANG_wife);
else if ($father->sex == "M") $father->setFamLabel($famid, GM_LANG_husband);
else $father->setFamLabel($famidGM_LANG_spouse);
}
if (is_object($mother)) {
if ($mother->sex == "F") $mother->setFamLabel($famid, GM_LANG_wife);
else if ($mother->sex == "M") $mother->setFamLabel($famid, GM_LANG_husband);
else $father->setFamLabel($famid, GM_LANG_spouse);
}
}
?>
<script type="text/javascript">
<!--
var nameElement = null;
var remElement = null;
var pediElement = null;
function pastename(name) {
if (nameElement) {
nameElement.innerHTML = Urldecode(name);
}
if (remElement) {
remElement.style.display = 'block';
}
if (pediElement) {
pediElement.style.display = 'block';
}
}
//-->
</script>
<form name="changefamform" method="post" action="edit_interface.php">
<input type="hidden" name="action" value="changefamily_update" />
<input type="hidden" name="famid" value="<?php print $famid;?>" />
<input type="hidden" name="pid_type" value="<?php print $pid_type; ?>" />
<input type="hidden" name="change_type" value="<?php print $change_type;?>" />
<table class="NavBlockTable EditTable">
<tr><td colspan="4" class="NavBlockColumnHeader EditTableColumnHeader"><?php PrintHelpLink("change_family_instr","qm","change_family_members"); ?><?php print GM_LANG_change_family_members; ?></td></tr>
<tr>
<td class="NavBlockLabel"><?php print GM_LANG_family_role; ?></td>
<td class="NavBlockLabel"><?php print GM_LANG_name; ?></td>
<td class="NavBlockLabel"><?php print GM_FACT_PEDI; ?></td>
<td class="NavBlockLabel"><?php print GM_LANG_action; ?></td>
</tr>
<tr>
<?php
if (is_object($father)) {
?>
<td class="NavBlockField"><?php print $father->label[$famid]; ?><input type="hidden" name="HUSB" value="<?php print $father->xref;?>" /></td>
<td id="HUSBName" class="NavBlockField"><?php print PrintReady($father->name); ?><br /><?php PersonFunctions::PrintFirstMajorFact($father); ?></td><td class="NavBlockField"> </td>
<?php
}
else {
?>
<td class="NavBlockField"><?php print GM_LANG_father; ?><input type="hidden" name="HUSB" value="" /></td>
<td id="HUSBName" class="NavBlockField"></td><td class="NavBlockField"> </td>
<?php
}
?>
<td class="NavBlockField">
<a href="#" id="husbrem" style="display: <?php print !is_object($father) ? 'none':'block'; ?>;" onclick="document.changefamform.HUSB.value=''; document.getElementById('HUSBName').innerHTML=''; this.style.display='none'; return false;"><?php print GM_LANG_remove; ?></a>
<a href="#" onclick="nameElement = document.getElementById('HUSBName'); remElement = document.getElementById('husbrem'); return findIndi(document.changefamform.HUSB);"><?php print GM_LANG_change; ?></a><br />
</td>
</tr>
<tr>
<?php
if (is_object($mother)) {
?>
<td class="NavBlockField"><?php print $mother->label[$famid]; ?><input type="hidden" name="WIFE" value="<?php print $mother->xref;?>" /></td>
<td id="WIFEName" class="NavBlockField"><?php print PrintReady($mother->name); ?><br /><?php PersonFunctions::PrintFirstMajorFact($mother); ?></td><td class="NavBlockField"> </td>
<?php
}
else {
?>
<td class="NavBlockField"><?php print GM_LANG_mother; ?><input type="hidden" name="WIFE" value="" /></td>
<td id="WIFEName" class="NavBlockField"></td><td class="NavBlockField"> </td>
<?php
}
?>
<td class="NavBlockField">
<a href="#" id="wiferem" style="display: <?php print !is_object($mother) ? 'none':'block'; ?>;" onclick="document.changefamform.WIFE.value=''; document.getElementById('WIFEName').innerHTML=''; this.style.display='none'; return false;"><?php print GM_LANG_remove; ?></a>
<a href="#" onclick="nameElement = document.getElementById('WIFEName'); remElement = document.getElementById('wiferem'); return findIndi(document.changefamform.WIFE);"><?php print GM_LANG_change; ?></a><br />
</td>
</tr>
<?php
$i=0;
foreach($children as $key=>$child) {
if (!is_null($child)) {
$pedi = $child->childfamilies[$famid]->pedigreetype;
?>
<tr>
<td class="NavBlockField"><?php print $child->label[$famid]; ?><input type="hidden" name="CHIL<?php print $i; ?>" value="<?php print $child->xref;?>" /></td>
<td id="CHILName<?php print $i; ?>" class="NavBlockField"><?php print PrintReady($child->name); ?><br /><?php PersonFunctions::PrintFirstMajorFact($child); ?></td>
<td id="CHILPedi<?php print $i; ?>" class="NavBlockField"><?php EditFunctions::PrintPedi("CHILPedisel".$i, "", $pedi); ?></td>
<td class="NavBlockField <?php print $TEXT_DIRECTION; ?>">
<a href="#" id="childrem<?php print $i; ?>" style="display:block;" onclick="document.changefamform.CHIL<?php print $i; ?>.value=''; document.getElementById('CHILName<?php print $i; ?>').innerHTML=''; this.style.display='none'; return false;"><?php print GM_LANG_remove; ?></a>
<a href="#" onclick="nameElement = document.getElementById('CHILName<?php print $i; ?>'); remElement = document.getElementById('childrem<?php print $i; ?>'); return findIndi(document.changefamform.CHIL<?php print $i; ?>);"><?php print GM_LANG_change; ?></a><br />
</td>
</tr>
<?php
$i++;
}
}
$pedi = "";
?>
<tr>
<td class="NavBlockField"><?php print GM_LANG_add_child; ?><input type="hidden" name="CHIL<?php print $i; ?>" value="" /></td>
<td id="CHILName<?php print $i; ?>" class="NavBlockField"></td>
<td id="CHILPedi<?php print $i; ?>" class="NavBlockField"><div id="CHILHide<?php print $i; ?>" style="display: none;"><?php EditFunctions::PrintPedi("CHILPedisel".$i, "", $pedi); ?></div></td>
<td class="NavBlockField">
<a href="#" id="childrem<?php print $i; ?>" style="display: none;" onclick="document.changefamform.CHIL<?php print $i; ?>.value=''; document.getElementById('CHILName<?php print $i; ?>').innerHTML=''; this.style.display='none'; return false;"><?php print GM_LANG_remove; ?></a>
<a href="#" onclick="pediElement = document.getElementById('CHILHide<?php print $i; ?>'); nameElement = document.getElementById('CHILName<?php print $i; ?>'); remElement = document.getElementById('childrem<?php print $i; ?>'); return findIndi(document.changefamform.CHIL<?php print $i; ?>);"><?php print GM_LANG_change; ?></a><br />
</td>
</tr>
<tr>
<td class="NavBlockFooter" colspan="4">
<input type="submit" value="<?php print GM_LANG_save; ?>" /> <input type="button" value="<?php print GM_LANG_cancel; ?>" onclick="window.close();" />
</td>
</tr>
</table>
</form>
<?php
break;
// NOTE: changefamily_update
// NOTE: Done for Genmod 2.0
case "changefamily_update":
$change_id = EditFunctions::GetNewXref("CHANGE");
$father = $object->husb;
$mother = $object->wife;
$children = $object->children;
$updated = false;
$success = true;
//-- action: replace existing father link
if (!empty($HUSB) && is_object($father) && $father->xref != $HUSB) {
// Replace the father link in the fam record
$oldrec = GetSubRecord(1, "1 HUSB @$father->xref@", $gedrec);
$newrec = preg_replace("/1 HUSB @$father->xref@/", "1 HUSB @$HUSB@\r\n", $oldrec);
if (trim($oldrec) != trim($newrec)) EditFunctions::ReplaceGedrec($famid, $oldrec, $newrec, "HUSB", $change_id, $change_type, "", "FAM");
// Remove the fam link from the old father record
if ($father->ischanged) $frec = $father->changedgedrec;
else $frec = $father->gedrec;
foreach ($father->spousefamilies as $key => $fam) {
if ($fam->xref == $famid) {
$oldfath = GetSubrecord(1, "1 FAMS @$famid@", $frec, 1);
$success = $success && EditFunctions::ReplaceGedrec($father->xref, $oldfath, "", "FAMS", $change_id, $change_type, "", "INDI");
break;
}
}
// Add the fam link to the new father
$newhusb =& Person::GetInstance($HUSB);
$found = false;
foreach ($newhusb->spousefamilies as $key => $fam) {
if ($fam->xref == $famid) $found = true;
break;
}
if (!$found) {
$newrec = "1 FAMS @$famid@\r\n";
$success = $success && EditFunctions::ReplaceGedrec($HUSB, "", $newrec, "FAMS", $change_id, $change_type, "", "INDI");
}
$updated = true;
}
//-- action: remove the father link
if (empty($HUSB) && is_object($father)) {
// Remove the father link from the fam
$oldfam = GetSubrecord(1, "1 HUSB @$father->xref", $gedrec, 1);
$success = $success && EditFunctions::ReplaceGedrec($famid, $oldfam, "", "HUSB", $change_id, $change_type, "", "FAM");
$updated = true;
// Remove the fam link from the old father record
if ($father->ischanged) $frec = $father->changedgedrec;
else $frec = $father->gedrec;
foreach ($father->spousefamilies as $key => $fam) {
if ($fam->xref == $famid) {
$oldfath = GetSubrecord(1, "1 FAMS @$famid@", $frec, 1);
$success = $success && EditFunctions::ReplaceGedrec($father->xref, $oldfath, "", "FAMS", $change_id, $change_type, "", "INDI");
break;