forked from HuubMons/HuMo-genealogy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
relations.php
3138 lines (2848 loc) · 123 KB
/
relations.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
//=================================================================
// relations.php - checks relationships between person X and person Y
//
// written by Yossi Beck - August 2010 for HuMo-gen
// adjusted for several languages 2011-2015 by Yossi Beck
// extended marital calculator added by Yossi Beck - February 2014
//
// contains the following functions:
// create_rel_array - creates $rel_array with gedcom nr and generation nr of ancestors of person X and Y
// compare_rel_array - compares the $rel_array arrays of X and Y to find common ancestor (can be the persons themselves)
// calculate_rel - if found, determines the nature of the relation (siblings, ancestors, nephews etc.)
// calculate_ancestor - calculates the degree of relations (2nd great-grandfather)
// calculate_descendant - calculates the degree of relations (3rd great-grandson)
// calculate_nephews - calculates the degree of relations (grand-niece)
// calculate_uncles - calculates the degree of relations (4th great-grand-uncle)
// calculate_cousins - calculates the degree of relations (2nd cousin twice removed)
// search_marital - if no direct blood relation found, searches for relation between spouses of person X and Y
// search_bloodrel - searches for blood relationship between X and Y
// display - displays the result of comparison checks
// display_table - displays simple chart showing the found relationship
// unset_var - unsets the vital variables before searching marital relations
// get_person - retrieves person from MySQL database by gedcom nr
// dutch_ancestor - special algorithm to process complicated dutch terminology for distant ancestors
//
// the meaning of the value of the $table variable (for displaying table with lineage if a match is found):
// 1 = parent - child
// 2 = child - parent
// 3 = uncle - nephew
// 4 = nephew - uncle
// 5 = cousin
// 6 = siblings
// 7 = spouses or self
//
// the meaning of the value of the $spouse variable (flagging type of relationship check):
// 0 = checks relation X vs Y
// 1 = checks relation spouse of X versus person Y
// 2 = checks relation person X versus spouse of Y
// 3 = checks relation spouse of X versus spouse of Y
//
// values in the genarray:
// the genarray is an array of the ancestors of a base person (one of the two persons entered in the search or their spouses)
// genarray[][0] = gedcom number of the person
// genarray[][1] = number of generations (counted from base person)
// genarray[][2] = array number of child
//
// meaning of some other global variables:
// $doublespouse - flags situation where searched persons X and Y are both spouses of a third person
// $special_spouseX (and Y) - flags situation where the regular text "spouse of" has to be changed:
// ----- for example: "X is spouse of brother of Y" should become "X is sister-in-law of Y"
// $sexe, $sexe2 - the sexe of persons X and Y
// person, $person2 - gedcom nr of the searched persons X and Y
//============================================================================================
ini_set('max_execution_time', 600);
//global declarations for Joomla
global $foundX_nr, $foundY_nr, $foundX_gen, $foundY_gen, $foundX_match, $foundY_match, $spouse;
global $reltext, $sexe, $sexe2, $special_spouseY, $special_spouseX, $doublespouse, $table;
global $ancestortext, $dutchtext, $selected_language, $spantext;
global $famsX, $famsY, $famX, $famY, $famspouseX, $famspouseY, $rel_arrayX, $rel_arrayY, $spousenameX, $spousenameY;
global $rel_arrayspouseX, $rel_arrayspouseY;
global $person, $person2, $searchDb, $searchDb2;
global $bloodreltext, $name1, $name2, $gednr, $gednr2;
global $fampath;
// *** Only needed for dutch relation names ***
global $hoog, $opper, $aarts, $voor, $edel, $stam, $oud, $rest;
include_once("header.php"); // returns CMS_ROOTPATH constant
include_once(CMS_ROOTPATH."menu.php");
require_once(CMS_ROOTPATH."include/person_cls.php");
include_once(CMS_ROOTPATH."include/marriage_cls.php");
include_once(CMS_ROOTPATH."include/language_date.php");
include_once(CMS_ROOTPATH."include/date_place.php");
if(CMS_SPECIFIC == "Joomla") {
$fampath = "index.php?option=com_humo-gen&task=family&"; // path to family.php for joomla (used some 20 times in this code
}
else {
$fampath = CMS_ROOTPATH."family.php?";
}
function create_rel_array ($gednr) {
// creates array of ancestors of person with gedcom nr. $gednr
global $dbh, $db_functions;
$family_id=$gednr;
$ancestor_id2[] = $family_id;
$ancestor_number2[] = 1;
$marriage_number2[] = 0;
$generation = 1;
$genarray_count = 0;
// *** Loop ancestor report ***
while (isset($ancestor_id2[0])){
unset($ancestor_id);
$ancestor_id=$ancestor_id2;
unset($ancestor_id2);
unset($ancestor_number);
$ancestor_number=$ancestor_number2;
unset($ancestor_number2);
unset($marriage_number);
$marriage_number=$marriage_number2;
unset($marriage_number2);
// *** Loop per generation ***
$kwcount=count($ancestor_id);
for ($i=0; $i<$kwcount; $i++) {
if ($ancestor_id[$i]!='0'){
$person_manDb=$db_functions->get_person($ancestor_id[$i]);
$man_cls = New person_cls;
$man_cls->construct($person_manDb);
$man_privacy=$man_cls->privacy;
if (strtolower($person_manDb->pers_sexe)=='m' AND $ancestor_number[$i]>1){
@$familyDb=$db_functions->get_family($marriage_number[$i]);
// *** Use privacy filter of woman ***
$person_womanDb=$db_functions->get_person($familyDb->fam_woman);
$woman_cls = New person_cls;
$woman_cls->construct($person_womanDb);
$woman_privacy=$woman_cls->privacy;
// *** Use class for marriage ***
$marriage_cls = New marriage_cls;
$marriage_cls->construct($familyDb, $man_privacy, $woman_privacy);
$family_privacy=$marriage_cls->privacy;
}
//*** Show person data ***
$genarray[$genarray_count][0]= $ancestor_id[$i];
$genarray[$genarray_count][1]= $generation-1;
$genarray_count++; // increase by one
// *** Check for parents ***
if ($person_manDb->pers_famc){
@$familyDb = $db_functions->get_family($person_manDb->pers_famc);
if ($familyDb->fam_man){
$ancestor_id2[] = $familyDb->fam_man;
$ancestor_number2[]=(2*$ancestor_number[$i]);
$marriage_number2[]=$person_manDb->pers_famc;
$genarray[][2]= $genarray_count-1;
// save array nr of child in parent array so we can build up ancestral line later
}
if ($familyDb->fam_woman){
$ancestor_id2[]= $familyDb->fam_woman;
$ancestor_number2[]=(2*$ancestor_number[$i]+1);
$marriage_number2[]=$person_manDb->pers_famc;
$genarray[][2]= $genarray_count-1;
// save array nr of child in parent array so we can build up ancestral line later
}
}
}
} // loop per generation
$generation++;
} // loop ancestors
return @$genarray;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function compare_rel_array($arrX, $arrY, $spouce_flag) {
global $foundX_nr, $foundY_nr, $foundX_gen, $foundY_gen, $foundX_match, $foundY_match, $spouse;
foreach($arrX as $keyx=>$valx) {
foreach($arrY as $keyy=>$valy) {
if($arrX[$keyx][0]==$arrY[$keyy][0]) {
$foundX_match=$keyx; // saves the array nr of common ancestor in ancestor array of X
$foundY_match=$keyy; // saves the array nr of common ancestor in ancestor array of Y
if(isset($arrX[$keyx][2])) { $foundX_nr=$arrX[$keyx][2]; } // saves the array nr of the child leading to X
if(isset($arrY[$keyy][2])) { $foundY_nr=$arrY[$keyy][2]; } // saves the array nr of the child leading to Y
if(isset($arrX[$keyx][1])) { $foundX_gen=$arrX[$keyx][1]; }// saves the nr of generations common ancestor is removed from X
if(isset($arrY[$keyy][1])) { $foundY_gen=$arrY[$keyy][1]; }// saves the nr of generations common ancestor is removed from Y
$spouse=$spouce_flag; // saves global variable flagging if we're comparing X - Y or spouse combination
return;
}
}
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function calculate_rel ($arr_x, $arr_y, $genX, $genY) {
// calculates the relationship found: "X is 2nd cousin once removed of Y"
global $reltext, $sexe, $sexe2, $spouse, $special_spouseY, $special_spouseX, $doublespouse, $table, $language;
global $selected_language;
$doublespouse=0;
if ( $arr_x == 0 AND $arr_y == 0 ) { // self
$reltext = __(' identical to ');
if($spouse==1 OR $spouse==2) { $reltext = " "; }
if($spouse==3) {$doublespouse=1; }
// it's the spouse itself so text should be "X is spouse of Y", not "X is spouse of is identical to Y" !!
$table=7;
}
elseif ( $arr_x == 0 AND $arr_y > 0 ) { // x is ancestor of y
$table=1;
calculate_ancestor ($genY);
}
elseif ( $arr_y == 0 AND $arr_x > 0 ) { // x is descendant of y
$table=2;
calculate_descendant ($genX);
}
elseif ( $genX == 1 AND $genY == 1 ) { // x is brother of y
/*
elder brother's wife 嫂
younger brother's wife 弟妇
elder sister's husband 姊夫
younger sister's husband 妹夫
*/
$table=6;
if($sexe=='m') {
$reltext = __('brother of ');
if($selected_language=="cn") {
if($sexe2=="m") { $reltext = '兄弟是'; } // "A's brother is B"
else { $reltext = '姊妹是';} // "A's sister is B"
}
if($spouse==1) {
$reltext = __('sister-in-law of '); $special_spouseX=1; //comparing spouse of X with Y
if($selected_language=="cn") {
if($sexe2=="m") { $reltext = '大爷(小叔)是'; } // "A's brother-in-law is B" (husband's brother)
else { $reltext = '大姑(小姑)是';} // "A's sister-in-law is B" (husband's sister)
}
}
if($spouse==2 OR $spouse==3) {
$reltext = __('brother-in-law of '); $special_spouseY=1;
//comparing X with spouse of Y or comparing 2 spouses
//$special_spouseX flags not to enter "spouse of" for X in display function
//$special_spouseY flags not to enter "spouse of" for Y in display function
if($selected_language=="cn" AND $spouse==2) {
if($sexe2=="m") { $reltext = '姊夫(妹夫)是'; } // "A's brother-in-law is B" (sister's husband)
else { $reltext = '嫂(弟妇)是';} // "A's sister-in-law is B" (brother's wife)
}
if($selected_language=="cn" AND $spouse==3) {
if($sexe2=="m") { $reltext = '大姑丈(小姑丈)是'; } // "A's brother-in-law is B" (husband's sister's husband)
else { $reltext = '大嫂(小嫂)是';} // "A's sister-in-law is B" (husband's brother's wife)
}
}
}
else {
$reltext = __('sister of ');
if($selected_language=="cn") {
if($sexe2=="m") { $reltext = '兄弟是'; } // "A's brother is B"
else { $reltext = '姊妹是';} // "A's sister is B"
}
if($spouse==1) {
$reltext = __('brother-in-law of ');
$special_spouseX=1; //comparing spouse of X with Y
if($selected_language=="cn") {
if($sexe2=="m") { $reltext = '大舅(小舅)是'; } // "A's brother-in-law is B" (wife's brother)
else { $reltext = '大姨子(小姨)是';} // "A's sister-in-law is B" (wife's sister)
}
}
if($spouse== 2 OR $spouse==3) {
$reltext = __('sister-in-law of ');
$special_spouseY=1; //comparing X with spouse of Y or comparing 2 spouses
//$special_spouseX flags not to enter "spouse of" for X in display function
//$special_spouseY flags not to enter "spouse of" for Y in display function
if($selected_language=="cn" AND $spouse==2) {
if($sexe2=="m") { $reltext = '姊夫(妹夫)是'; } // "A's brother-in-law is B" (sister's husband)
else { $reltext = '嫂(弟妇)是';} // "A's sister-in-law is B" (brother's wife)
}
if($selected_language=="cn" AND $spouse==3) {
if($sexe2=="m") { $reltext = '姐夫(妹夫)是'; } // "A's brother-in-law is B" (wife's sister's husband)
else { $reltext = '表嫂(表嫂)是';} // "A's sister-in-law is B" (wife's brother's wife)
}
}
}
}
elseif ( $genX == 1 AND $genY > 1 ) { // x is uncle, great-uncle etc of y
$table=3;
calculate_uncles ($genY);
}
elseif ( $genX > 1 AND $genY == 1 ) { // x is nephew, great-nephew etc of y
$table=4;
calculate_nephews ($genX);
}
else { // x and y are cousins of any number (2nd, 3rd etc) and any distance removed (once removed, twice removed etc)
$table=5;
calculate_cousins ($genX, $genY);
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function spanish_degrees ($pers, $text) {
global $spantext, $language;
if ($pers == 2) { $spantext = $text; }
if ($pers == 3) { $spantext = 'bis'.$text; }
if ($pers == 4) { $spantext = 'tris'.$text; }
if ($pers == 5) { $spantext = 'tetra'.$text; }
if ($pers == 6) { $spantext = 'penta'.$text; }
if ($pers == 7) { $spantext = 'hexa'.$text; }
if ($pers == 8) { $spantext = 'hepta'.$text; }
if ($pers == 9) { $spantext = 'octa'.$text; }
if ($pers == 10) { $spantext = 'nona'.$text; }
if ($pers == 11) { $spantext = 'deca'.$text; }
if ($pers == 12) { $spantext = 'undeca'.$text; }
if ($pers == 13) { $spantext = 'dodeca'.$text; }
if ($pers == 14) { $spantext = 'trideca'.$text; }
if ($pers == 15) { $spantext = 'tetradeca'.$text; }
if ($pers == 16) { $spantext = 'pentadeca'.$text; }
if ($pers == 17) { $spantext = 'hexadeca'.$text; }
if ($pers == 18) { $spantext = 'heptadeca'.$text; }
if ($pers == 19) { $spantext = 'octadeca'.$text; }
if ($pers == 20) { $spantext = 'nonadeca'.$text; }
if ($pers == 21) { $spantext = 'icosa'.$text; }
if ($pers == 22) { $spantext = 'unicosa'.$text; }
if ($pers == 23) { $spantext = 'doicosa'.$text; }
if ($pers == 24) { $spantext = 'tricosa'.$text; }
if ($pers == 25) { $spantext = 'tetricosa'.$text; }
if ($pers == 26) { $spantext = 'penticosa'.$text; }
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function calculate_ancestor($pers) {
global $db_functions, $reltext, $sexe, $sexe2, $spouse, $special_spouseY, $language, $ancestortext, $dutchtext, $selected_language, $spantext, $generY, $foundY_nr, $rel_arrayY;
global $rel_arrayspouseY;
$anscestortext='';
if($sexe=='m') {
$parent = __('father');
}
else {
$parent = __('mother');
}
if($selected_language=="cn") {
// chinese instead of A is father of B we say: A's son is B
// therefore we need sex of B instead of A and use son/daughter instead of father/mother
if($sexe2=='m') {
$parent = '儿子'; // son
}
else {
$parent = '女儿'; //daughter
}
}
if ($pers == 1) {
if($spouse==2 OR $spouse==3) {
$special_spouseY=1; // prevents "spouse of Y" in output
if($parent==__('father')) { $parent=__('father-in-law'); }
else { $parent=__('mother-in-law');}
if($selected_language=="cn") {
if($sexe2=="m") { $parent = '女婿'; } // son-in-law
else { $parent = '儿媳'; } // daughter-in-law
}
}
$reltext = $parent.__(' of ');
if($selected_language=="cn") {
$reltext = $parent.'是';
}
}
else {
if($selected_language=="nl") {
dutch_ancestors($pers);
$reltext= $ancestortext.$parent.__(' of ');
if ($pers >4 ) {
$gennr=$pers-2;
$dutchtext = "(".$ancestortext.$parent." = ".$gennr.__('th').__('great-grand').$parent.")";
}
}
elseif($selected_language=="es") {
if($parent==__('father')) { $grparent='abuelo'; $spanishnumber="o"; }
else {$grparent='abuela'; $spanishnumber="a";}
$gennr=$pers-1;
$degree=$gennr.$spanishnumber." ".$grparent;
if ($pers == 2) { $reltext = $grparent.__(' of '); }
elseif($pers >2 AND $pers <27) {
spanish_degrees($pers,$grparent); // sets spanish "bis", "tris" etc prefix
$reltext = $spantext." (".$degree.")".__(' of ');
}
else { $reltext = $degree.__(' of '); }
}
elseif($selected_language=="he") {
if($parent==__('father')) { $grparent=__('grand'); $grgrparent=__('great-grand'); }
else {$grparent=__('grand'); $grgrparent=__('great-grand'); }
$gennr=$pers-2;
if ($pers == 2) { $reltext = $grparent.__(' of '); }
elseif ($pers > 2) {
$degree='';
if($pers >3) {
$degree=' דרגה ';
$degree.=$gennr;
}
$reltext = $grgrparent.$degree.__(' of ');
}
}
elseif($selected_language=="fi") {
if ($pers == 2) { $reltext = __('grand').$parent.__(' of '); }
$gennr=$pers-1;
if ($pers > 2) { $reltext = $gennr.'. '.__('grand').$parent.__(' of '); }
}
elseif($selected_language=="no") {
if ($pers == 2) { $reltext = __('grand').$parent.__(' of '); }
if ($pers == 3) { $reltext = __('great-grand').$parent.__(' of '); }
if ($pers == 4) { $reltext = 'tippolde'.$parent.__(' of '); }
if ($pers == 5) { $reltext = 'tipp-tippolde'.$parent.__(' of '); }
$gennr=$pers-3;
if ($pers > 5) { $reltext = $gennr."x ".'tippolde'.$parent.__(' of '); }
}
// Swedish needs to know if grandparent is related through mother or father - different names there
// also for great-grandparent and 2nd great-grandparent!!!
elseif($selected_language=="sv"){
if($spouse=="2" OR $spouse=="3") { // right person is spouse of Y, not Y
$relarr = $rel_arrayspouseY;
}
else {
$relarr = $rel_arrayY;
}
if ($pers > 1) {
// grandfather
$arrnum=0; reset($ancsarr);
$count=$foundY_nr;
while($count!=0) {
$parnumber=$count;
$ancsarr[$arrnum]=$parnumber; $arrnum++;
$count=$relarr[$count][2];
}
$persidDb=$db_functions->get_person($relarr[$parnumber][0]);
$parsexe = $persidDb->pers_sexe;
if($parsexe=='M') { $se_grandpar = 'far'.$parent; $direct_par = 'far';}
else { $se_grandpar = 'mor'.$parent; $direct_par = 'mor';}
}
if ($pers > 2) {
// great-grandfather
$persidDb2=$db_functions->get_person($relarr[$ancsarr[$arrnum-2]][0]);
$parsexe2 = $persidDb2->pers_sexe;
if($parsexe2=="M") {
if($parsexe=="M") $se_gr_grandpar = 'farfars '.$parent;
else $se_gr_grandpar = 'morfars '.$parent;
}
else {
if($parsexe=="M") $se_gr_grandpar = 'farmors '.$parent;
else $se_gr_grandpar = 'mormors '.$parent;
}
}
if ($pers > 3) {
// 2nd great-grandfather
$persidDb3=$db_functions->get_person($relarr[$ancsarr[$arrnum-3]][0]);
$parsexe3 = $persidDb3->pers_sexe;
if($parsexe3=="M") {
if($parsexe2=="M") {
if($parsexe=="M") $se_2ndgr_grandpar = 'farfars far'.$parent;
else $se_2ndgr_grandpar = 'morfars far'.$parent;
}
else {
if($parsexe=="M") $se_2ndgr_grandpar = 'farmors far'.$parent;
else $se_2ndgr_grandpar = 'mormors far'.$parent;
}
}
else {
if($parsexe2=="M") {
if($parsexe=="M") $se_2ndgr_grandpar = 'farfars mor'.$parent;
else $se_2ndgr_grandpar = 'morfars mor'.$parent;
}
else {
if($parsexe=="M") $se_2ndgr_grandpar = 'farmors mor'.$parent;
else $se_2ndgr_grandpar = 'mormors mor'.$parent;
}
}
}
if ($pers == 2) { $reltext = $se_grandpar.__(' of '); }
if ($pers == 3) { $reltext = $se_gr_grandpar.__(' of '); }
if ($pers == 4) { $reltext = $se_2ndgr_grandpar.__(' of '); }
$gennr=$pers;
if ($pers > 4) { $reltext = $gennr.':e generations ana på '.$direct_par.'s sida'.__(' of '); }
}
elseif($selected_language=="cn") {
if(($sexe2=='m' AND $spouse!=2 AND $spouse!=3) OR ($sexe2=='f' AND ($spouse==2 OR $spouse==3))) {
//if($sexe2=="m") { // kwan gives: grandson, great-grandson etc 曾內孫仔 孫子 ???
if ($pers == 2) { $reltext = '孙子'; }
if ($pers == 3) { $reltext = '曾孙'; }
if ($pers == 4) { $reltext = '玄孙'; }
if ($pers > 4) { $reltext = 'notext'; } // in Chinese don't display text after 2nd great grandson
}
else { // granddaughter etc (kwan gives: 曾孫女 曾內孫女 玄孫 ???)
if ($pers == 2) { $reltext = '孙女'; }
if ($pers == 3) { $reltext = '曾孙女'; }
if ($pers == 4) { $reltext = '玄孙女'; }
if ($pers > 4) { $reltext = 'notext'; } // in Chinese don't display text after 2nd great granddaughter
}
$reltext .= '是';
}
else { // *** Other languages ***
if ($pers == 2) { $reltext = __('grand').$parent.__(' of '); }
if ($pers == 3) { $reltext = __('great-grand').$parent.__(' of '); }
if ($pers == 4) { $reltext = __('2nd').' '.__('great-grand').$parent.__(' of '); }
if ($pers == 5) { $reltext = __('3rd').' '.__('great-grand').$parent.__(' of '); }
$gennr=$pers-2;
if ($pers > 5) { $reltext = $gennr.__('th').' '.__('great-grand').$parent.__(' of '); }
}
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function dutch_ancestors($gennr) {
global $ancestortext;
global $hoog, $opper, $aarts, $voor, $edel, $stam, $oud, $rest;
if ($gennr > 512){
$text = " Neanthertaler ancestor of "; // ;-)
}
else {
if ($gennr > 256) {
$hoog="hoog-";
$gennr-=256;
dutch_ancestors($gennr);
}
elseif ($gennr > 128) {
$opper="opper-";
$gennr-=128;
dutch_ancestors($gennr);
}
elseif ($gennr > 64) {
$aarts="aarts-";
$gennr-=64;
dutch_ancestors($gennr);
}
elseif ($gennr > 32) {
$voor="voor-";
$gennr-=32;
dutch_ancestors($gennr);
}
elseif ($gennr > 16) {
$edel="edel-";
$gennr-=16;
dutch_ancestors($gennr);
}
elseif ($gennr > 8) {
$stam="stam-";
$gennr-=8;
dutch_ancestors($gennr);
}
elseif ($gennr > 4) {
$oud="oud";
$gennr-=4;
dutch_ancestors($gennr);
}
else {
if ($gennr==4) { $rest='betovergroot'; }
if ($gennr==3) { $rest='overgroot'; }
if ($gennr==2) { $rest='groot'; }
if ($gennr==1) { $rest=''; }
}
}
$ancestortext= $hoog.$opper.$aarts.$voor.$edel.$stam.$oud.$rest;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function calculate_descendant($pers) {
global $db_functions, $reltext, $sexe, $sexe2, $spouse, $special_spouseX, $language, $selected_language, $spantext, $foundX_nr, $rel_arrayX, $rel_arrayspouseX;
if($sexe=='m') {
$child = __('son');
}
else {
$child = __('daughter');
}
if($selected_language=="cn") {
// chinese instead of A is son of B we say: A's father is B
// therefore we need sex of B instead of A and use father/mother instead of son/daughter
if($sexe2=='m') {
$child = '父亲'; // father
}
else {
$child = '母亲'; // mother
}
}
if ($pers == 1) {
if($spouse==1) {
if($child==__('son')) { $child=__('daughter-in-law'); }
else { $child=__('son-in-law');}
$special_spouseX=1;
if($selected_language=="cn") { // A's father/mother-in-law is B (instead of A is son/daughter-in-law of B)
if($sexe2=="m") {
if($sexe=="f") { $child = '公公'; } // father-in-law called by daughter-in-law
else { $child = '岳父'; } // father-in-law called by son-in-law
}
else {
if($sexe=="f") { $child = '婆婆'; } // mother-in-law called by daughter-in-law
else { $child = '岳母'; } // mother-in-law called by son-in-law
}
}
}
$reltext = $child.__(' of ');
if($selected_language=="cn") {
$reltext = $child.'是';
}
}
elseif($selected_language=="es") {
if($child == __('son')) { $grchild='nieto'; $spanishnumber="o"; }
else {$grchild='nieta'; $spanishnumber="a";}
$gennr=$pers-1;
$degree=$gennr.$spanishnumber." ".$grchild;
if ($pers == 2) { $reltext = $grchild.__(' of '); }
elseif($pers >2 AND $pers <27) {
spanish_degrees($pers,$grchild); // sets spanish "bis", "tris" etc prefix
$reltext = $spantext." (".$degree.")".__(' of ');
}
else { $reltext = $degree.__(' of '); }
}
elseif($selected_language=="he") {
if($child==__('son')) { $grchild='נכד '; $grgrchild='נין '; }
else {$grchild='נכדה '; $grgrchild='נינה '; }
$gennr=$pers-2;
if ($pers == 2) { $reltext = $grchild.__(' of '); }
elseif ($pers > 2) {
$degree='';
if($pers >3) { $degree='דרגה '.$gennr; }
$reltext = $grgrchild.$degree.__(' of ');
}
}
elseif($selected_language=="fi") {
if ($pers == 2) { $reltext = __('grandchild').__(' of '); }
$gennr=$pers-1;
if ($pers > 2) { $reltext = $gennr.'. '.__('grandchild').__(' of '); }
}
elseif($selected_language=="no") {
$child = 'barnet'; // barn
if ($pers == 2) { $reltext = 'barnebarnet '.__(' of '); } // barnebarn
if ($pers == 3) { $reltext = __('great-grand').$child.__(' of '); } // olde + barn
if ($pers == 4) { $reltext = 'tippolde'.$child.__(' of '); } // tippolde + barn
if ($pers == 5) { $reltext = 'tipp-tippolde'.$child.__(' of '); } // tipp-tippolde + barn
$gennr=$pers-3;
if ($pers > 5) { $reltext = $gennr.'x tipp-tippolde'.$child.__(' of '); }
}
// Swedish needs to know if grandchild is related through son or daughter - different names there
// also for great-grandchild and 2nd great-grandchild!!!
elseif($selected_language=="sv"){
if($spouse=="1" OR $spouse=="3") { // right person is spouse of Y, not Y
$relarr = $rel_arrayspouseX;
}
else {
$relarr = $rel_arrayX;
}
if ($pers > 1) {
// grandchild
$arrnum=0; reset($ancsarr);
$count=$foundX_nr;
while($count!=0) {
$parnumber=$count;
$ancsarr[$arrnum]=$parnumber; $arrnum++;
//$count=$rel_arrayX[$count][2];
$count=$relarr[$count][2];
}
$persidDb=$db_functions->get_person($relarr[$foundX_nr][0]);
$parsexe = $persidDb->pers_sexe;
if($parsexe=='M') { $se_grandch = 'son'.$child; $direct_ch = 'son';}
else { $se_grandch = 'dotter'.$child; $direct_ch = 'dotter';}
}
if ($pers > 2) {
// great-grandchild
$persidDb2=$db_functions->get_person($relarr[$ancsarr[1]][0]);
$parsexe2 = $persidDb2->pers_sexe;
if($parsexe2=="M") {
if($parsexe=="M") $se_gr_grandch = 'sonsons '.$child;
else $se_gr_grandch = 'dottersons '.$child;
}
else {
if($parsexe=="M") $se_gr_grandch = 'sondotters '.$child;
else $se_gr_grandch = 'dotterdotters '.$child;
}
}
if ($pers > 3) {
// 2nd great-grandchild
$persidDb3=$db_functions->get_person($relarr[$ancsarr[2]][0]);
$parsexe3 = $persidDb3->pers_sexe;
if($parsexe3=="M") {
if($parsexe2=="M") {
if($parsexe=="M") $se_2ndgr_grandch = 'sonsons son'.$child;
else $se_2ndgr_grandch = 'dottersons son'.$child;
}
else {
if($parsexe=="M") $se_2ndgr_grandch = 'sondotters son'.$child;
else $se_2ndgr_grandch = 'dotterdotters son'.$child;
}
}
else {
if($parsexe2=="M") {
if($parsexe=="M") $se_2ndgr_grandch = 'sonsons dotter'.$child;
else $se_2ndgr_grandch = 'dottersons dotter'.$child;
}
else {
if($parsexe=="M") $se_2ndgr_grandch = 'sondotters dotter'.$child;
else $se_2ndgr_grandch = 'dotterdotters dotter'.$child;
}
}
}
if ($pers == 2) { $reltext = $se_grandch.__(' of '); }
if ($pers == 3) { $reltext = $se_gr_grandch.__(' of '); }
if ($pers == 4) { $reltext = $se_2ndgr_grandch.__(' of '); }
$gennr=$pers;
if ($pers > 4) { $reltext = $gennr.':e generations barn'.__(' of '); }
}
elseif($selected_language=="cn") { // instead of A is grandson of B we say: A's granfather is B
if(($sexe2=='m' AND $spouse!=2 AND $spouse!=3) OR ($sexe2=='f' AND ($spouse==2 OR $spouse==3))) {
//if($sexe2=="m") { // grandfather, great-grandfather etc
if ($pers == 2) { $reltext = '祖父'; }
if ($pers == 3) { $reltext = '曾祖父'; }
if ($pers == 4) { $reltext = '高祖父'; }
if ($pers > 4) { $reltext = 'notext'; } // in Chinese don't display text after 2nd great grandfather
}
else { // grandmother etc
if ($pers == 2) { $reltext = '祖母'; }
if ($pers == 3) { $reltext = '曾祖母'; }
if ($pers == 4) { $reltext = '高祖母'; }
if ($pers > 4) { $reltext = 'notext'; } // in Chinese don't display text after 2nd great grandmother
}
$reltext .= '是';
}
else {
if ($pers == 2) { $reltext = __('grand').$child.__(' of '); }
if ($pers == 3) { $reltext = __('great-grand').$child.__(' of '); }
if ($pers == 4) { $reltext = __('2nd').' '.__('great-grand').$child.__(' of '); }
if ($pers == 5) { $reltext = __('3rd').' '.__('great-grand').$child.__(' of '); }
$gennr=$pers-2;
if ($pers > 5) { $reltext = $gennr.__('th').' '.__('great-grand').$child.__(' of '); }
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function calculate_nephews($generX) { // handed generations x is removed from common ancestor
global $db_functions, $reltext, $sexe, $sexe2, $language, $spantext, $selected_language, $reltext_nor, $reltext_nor2, $foundX_nr, $rel_arrayX, $rel_arrayspouseX, $spouse;
if($selected_language=="es"){
if($sexe=="m") { $neph=__('nephew'); $span_postfix="o "; $grson='nieto'; }
else { $neph=__('niece'); $span_postfix="a "; $grson='nieta'; }
//$gendiff = abs($generX - $generY); // FOUT
$gendiff = abs($generX - $generY) - 1;
$gennr=$gendiff-1;
$degree=$grson." ".$gennr.$span_postfix;
if($gendiff ==1) { $reltext=$neph.__(' of ');}
elseif($gendiff > 1 AND $gendiff < 27) {
spanish_degrees($gendiff,$grson);
$reltext=$neph." ".$spantext.__(' of ');
}
else { $reltext=$neph." ".$degree; }
}
elseif ($selected_language=="he"){
if($sexe=='m') { $nephniece = __('nephew'); }
else { $nephniece = __('niece'); }
$gendiff = abs($generX - $generY);
$gennr=$gendiff-1;
if($gendiff ==1) { $reltext=$nephniece.__(' of ');}
elseif($gendiff > 1 ) {
if($gendiff >2) { $degree='דרגה '.$gennr; }
$reltext=$nephniece.$degree.__(' of ');
}
}
elseif ($selected_language=="fi"){
if($sexe=='m') {
$nephniece = __('nephew');
}
else {
$nephniece = __('niece');
}
if ($generX == 2) { $reltext = $nephniece.__(' of '); }
if ($generX == 3) { $reltext = __('grand').$nephniece.__(' of '); }
$gennr=$generX-2;
if ($generX > 3) { $reltext = $gennr.'. '.__('grand').$nephniece.__(' of '); }
}
elseif ($selected_language=="no"){
if($sexe=='m') { $nephniece = __('nephew'); }
else { $nephniece = __('niece'); }
$reltext_nor=''; $reltext_nor2='';
if ($generX > 3) {
$reltext_nor = "s ".substr('søskenet',0,-2); // for: A er oldebarnet av Bs søsken
$reltext_nor2 = 'søskenet'.
__(' of '); // for: A er oldebarnet av søskenet av mannen til B
}
if ($generX == 2) { $reltext = $nephniece.__(' of '); }
if ($generX == 3) { $reltext = 'grand'.$nephniece.__(' of '); }
if ($generX == 4) { $reltext = __('great-grand').' barnet'.__(' of '); }
if ($generX == 5) { $reltext = 'tippolde barnet'.__(' of '); }
if ($generX == 6) { $reltext = 'tipp-tippolde barnet'.__(' of '); }
$gennr=$generX-4;
if ($generX > 6) { $reltext = $gennr.'x tippolde barnet'.__(' of '); }
}
elseif ($selected_language=="nl"){
if($sexe=='m') {
$nephniece = __('nephew');
}
else {
$nephniece = __('niece');
}
// in Dutch we use the __('3rd [COUSIN]') variables, that work for nephews as well
if ($generX == 2) { $reltext = $nephniece.__(' of '); }
if ($generX == 3) { $reltext = __('2nd [COUSIN]').$nephniece.__(' of '); }
if ($generX == 4) { $reltext = __('3rd [COUSIN]').$nephniece.__(' of '); }
if ($generX == 5) { $reltext = __('2nd').' '.__('3rd [COUSIN]').$nephniece.__(' of '); }
if ($generX == 6) { $reltext = __('3rd').' '.__('3rd [COUSIN]').$nephniece.__(' of '); }
$gennr=$generX-3;
if ($generX > 6) { $reltext = $gennr.__('th ').__('3rd [COUSIN]').$nephniece.__(' of '); }
}
elseif ($selected_language=="sv"){
// Swedish needs to know if nephew/niece is related through brother or sister - different names there
// also for grandnephew!!!
if($spouse=="1" OR $spouse=="3") { // right person is spouse of Y, not Y
$relarr = $rel_arrayspouseX;
}
else {
$relarr = $rel_arrayX;
}
if($sexe=='m') {
$nephniece = "son";
}
else {
$nephniece = "dotter";
}
if ($generX >1) {
// niece/nephew
$arrnum=0; reset($ancsarr);
$count=$foundX_nr;
while($count!=0) {
$parnumber=$count;
$ancsarr[$arrnum]=$parnumber; $arrnum++;
$count=$relarr[$count][2];
}
$persidDb=$db_functions->get_person($relarr[$parnumber][0]);
$parsexe = $persidDb->pers_sexe;
if($parsexe=='M') { $se_nephniece = 'bror'.$nephniece; }
else { $se_nephniece = 'syster'.$nephniece; }
}
if ($generX == 3) {
// grandniece/nephew
$persidDb2=$db_functions->get_person($relarr[$ancsarr[$arrnum-2]][0]);
$parsexe2 = $persidDb2->pers_sexe;
if($parsexe2=="M") {
if($parsexe=="M") $se_gr_nephniece = 'brors son'.$nephniece;
else $se_gr_nephniece = 'brors dotter'.$nephniece;
}
else {
if($parsexe=="M") $se_gr_nephniece = 'systers son'.$nephniece;
else $se_gr_nephniece = 'systers dotter'.$nephniece;
}
}
if ($generX == 2) { $reltext = $se_nephniece.__(' of '); }
if ($generX == 3) { $reltext = $se_gr_nephniece.__(' of '); }
$gennr=$generX-1;
if ($generX > 3) {
$persidDb=$db_functions->get_person($rel_arrayX[$foundX_nr][0]);
$parsexe = $persidDb->pers_sexe;
if($parsexe=='M') { $se_sib = "bror"; }
else { $se_sib = "syster"; }
$reltext = $se_sib.'s '.$gennr.':e generations barn'.__(' of ');
}
}
elseif ($selected_language=="cn"){
// Used: http://www.kwanfamily.info/culture/familytitles_table.php
if($spouse=="1") { // left person is spouse of X, not X
$relarrX = $rel_arrayspouseX;
}
else {
$relarrX = $rel_arrayX;
}
$arrnumX=0; if(isset($ancsarrX)) reset($ancsarrX);
$count=$foundX_nr;
while($count!=0) {
$parnumberX=$count;
$ancsarrX[$arrnumX]=$parnumberX; $arrnumX++;
$count=$relarrX[$count][2];
}
$persidDbX=$db_functions->get_person($relarrX[$parnumberX][0]);
$parsexeX = $persidDbX->pers_sexe;
if($parsexeX=='M') { // uncle/aunt from father's side
if(($sexe2=="m" AND $spouse!=2 AND $spouse!=3) OR ($sexe2=="f" AND ($spouse==2 OR $spouse==3))) {
$reltext = '伯父(叔父)是'; // uncle - brother of father
}
else {
$reltext = '姑母是'; // aunt - sister of father
}
}
else { // uncle/aunt from mother's side
if(($sexe2=="m" AND $spouse!=2 AND $spouse!=3) OR ($sexe2=="f" AND ($spouse==2 OR $spouse==3))) {
$reltext = '舅父是'; // uncle - brother of mother
}
else {
$reltext = '姨母(姨)是'; // aunt - sister of mother
}
}
/*
if(($sexe2=='m' AND $spouse!=2 AND $spouse!=3) OR ($sexe2=='f' AND ($spouse==2 OR $spouse==3))) {
$nephniece = '叔伯是'; // A's uncle is B
}
else {
$nephniece = '婶娘是'; // A's aunt is B
}
*/
if ($generX == 2) { }
if ($generX > 2) { $reltext = "notext"; } // suppress text - "granduncle" etc is not (yet) supported in Chinese
}
else {
if($sexe=='m') {
$nephniece = __('nephew');
}
else {
$nephniece = __('niece');
}
if ($generX == 2) { $reltext = $nephniece.__(' of '); }
if ($generX == 3) { $reltext = __('grand').$nephniece.__(' of '); }
if ($generX == 4) { $reltext = __('great-grand').$nephniece.__(' of '); }
if ($generX == 5) { $reltext = __('2nd').' '.__('great-grand').$nephniece.__(' of '); }
if ($generX == 6) { $reltext = __('3rd').' '.__('great-grand').$nephniece.__(' of '); }
$gennr=$generX-3;
if ($generX > 6) { $reltext = $gennr.__('th ').__('great-grand').$nephniece.__(' of '); }
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function calculate_uncles($generY) { // handed generations y is removed from common ancestor
global $db_functions, $reltext, $sexe, $sexe2, $language, $ancestortext, $dutchtext, $selected_language, $spantext, $rel_arrayspouseY, $spouse;
global $foundY_nr, $rel_arrayY, $fampath; // only for Finnish paragraph
global $reltext_nor, $reltext_nor2; // for Norwegian
global $rel_arrayspouseX, $rel_arrayX, $foundX_nr; // for Chinese
$ancestortext='';
if($sexe=='m') {
$uncleaunt = __('uncle');
if($selected_language=="cn"){ // A's nephew/niece is B
// Used: http://www.kwanfamily.info/culture/familytitles_table.php
// Other translations (not used): dongshan: nephew: 侄子是 niece 侄女是
if($spouse=="2" OR $spouse=="3") { // right person is spouse of Y, not Y
$relarrY = $rel_arrayspouseY;
}
else {
$relarrY = $rel_arrayY;
}
$arrnumY=0; if(isset($ancsarrY)) reset($ancsarrY);
$count=$foundY_nr;
while($count!=0) {
$parnumberY=$count;
$ancsarrY[$arrnumY]=$parnumberY; $arrnumY++;
$count=$relarrY[$count][2];
}
$persidDbY=$db_functions->get_person($relarrY[$parnumberY][0]);
$parsexeY = $persidDbY->pers_sexe;
if($parsexeY=="M") { // is child of brother
if(($sexe2=='m' AND $spouse!=2 AND $spouse!=3) OR ($sexe2=='f' AND ($spouse==2 OR $spouse==3))) {
$uncleaunt = '姪子是';
}
else {
$uncleaunt = '姪女是';
}
}
else { // is child of sister - term depends also on sex of A
if(($sexe2=='m' AND $spouse!=2 AND $spouse!=3) OR ($sexe2=='f' AND ($spouse==2 OR $spouse==3))) {
if($sexe=="m") $uncleaunt = '外甥是'; // son of sister (A is male)
else $uncleaunt = '姨甥是'; // son of sister (A is female)
}
else {
if($sexe=="m") $uncleaunt = '外甥女是'; // daughter of sister (A is male)
else $uncleaunt = '姨甥女是'; // daughter of sister (A is female)
}
}
}
// Finnish needs to know if uncle is related through mother or father - different names there
if($selected_language=="fi"){
$count=$foundY_nr;
while($count!=0) {
$parnumber=$count;
$count=$rel_arrayY[$count][2];
}
$persidDb=$db_functions->get_person($rel_arrayY[$parnumber][0]);
$parsexe = $persidDb->pers_sexe;
if($parsexe=='M') { $uncleaunt = 'setä'; }
else { $uncleaunt = 'eno'; }
}