Esempio n. 1
0
/**
 * print ancestors on a fan chart
 *
 * @param array $treeid ancestry pid
 * @param int $fanw fan width in px (default=640)
 * @param int $fandeg fan size in deg (default=270)
 */
function print_fan_chart($treeid, $fanw = 640, $fandeg = 270)
{
    global $PEDIGREE_GENERATIONS, $fan_width, $fan_style;
    global $name, $pgv_lang, $SHOW_ID_NUMBERS, $view, $TEXT_DIRECTION;
    global $stylesheet, $print_stylesheet;
    global $PGV_IMAGE_DIR, $PGV_IMAGES, $LINK_ICONS, $GEDCOM;
    // check for GD 2.x library
    if (!defined("IMG_ARC_PIE")) {
        print "<span class=\"error\">" . $pgv_lang["gd_library"] . "</span>";
        print " <a href=\"" . $pgv_lang["gd_helplink"] . "\"><img src=\"" . $PGV_IMAGE_DIR . "/" . $PGV_IMAGES["help"]["small"] . "\" class=\"icon\" alt=\"\" /></a><br /><br />";
        return false;
    }
    if (!function_exists("ImageTtfBbox")) {
        print "<span class=\"error\">" . $pgv_lang["gd_freetype"] . "</span>";
        print " <a href=\"" . $pgv_lang["gd_helplink"] . "\"><img src=\"" . $PGV_IMAGE_DIR . "/" . $PGV_IMAGES["help"]["small"] . "\" class=\"icon\" alt=\"\" /></a><br /><br />";
        return false;
    }
    // parse CSS file
    include "includes/cssparser.inc.php";
    $css = new cssparser(false);
    if ($view == "preview") {
        $css->Parse($print_stylesheet);
    } else {
        $css->Parse($stylesheet);
    }
    // check for fontfile
    $fontfile = $css->Get(".fan_chart", "font-family");
    $fontsize = $css->Get(".fan_chart", "font-size");
    $fontfile = str_replace("url(", "", $fontfile);
    $fontfile = str_replace(")", "", $fontfile);
    if (!file_exists($fontfile)) {
        if (!empty($fontfile)) {
            print "<span class=\"error\">" . $pgv_lang["fontfile_error"] . " : {$fontfile}</span>";
        }
        $fontfile = "./includes/fonts/DejaVuSans.ttf";
    }
    if ($fontfile[0] != '/') {
        $fontfile = dirname(__FILE__) . "/" . $fontfile;
    }
    if (!file_exists($fontfile)) {
        print "<span class=\"error\">" . $pgv_lang["fontfile_error"] . " : {$fontfile}</span>";
        return false;
    }
    if (intval($fontsize) < 2) {
        $fontsize = 7;
    }
    $treesize = count($treeid);
    if ($treesize < 1) {
        return;
    }
    // generations count
    $gen = log($treesize) / log(2) - 1;
    $sosa = $treesize - 1;
    // fan size
    if ($fandeg == 0) {
        $fandeg = 360;
    }
    $fandeg = min($fandeg, 360);
    $fandeg = max($fandeg, 90);
    $cx = $fanw / 2 - 1;
    // center x
    $cy = $cx;
    // center y
    $rx = $fanw - 1;
    $rw = $fanw / ($gen + 1);
    $fanh = $fanw;
    // fan height
    if ($fandeg == 180) {
        $fanh = round($fanh * ($gen + 1) / ($gen * 2));
    }
    if ($fandeg == 270) {
        $fanh = round($fanh * 0.86);
    }
    $scale = $fanw / 640;
    // image init
    $image = ImageCreate($fanw, $fanh);
    $black = ImageColorAllocate($image, 0, 0, 0);
    $white = ImageColorAllocate($image, 0xff, 0xff, 0xff);
    ImageFilledRectangle($image, 0, 0, $fanw, $fanh, $white);
    ImageColorTransparent($image, $white);
    $rgb = $css->Get(".fan_chart", "color");
    if (empty($rgb)) {
        $rgb = "#000000";
    }
    $color = ImageColorAllocate($image, hexdec(substr($rgb, 1, 2)), hexdec(substr($rgb, 3, 2)), hexdec(substr($rgb, 5, 2)));
    $rgb = $css->Get(".fan_chart", "background-color");
    if (empty($rgb)) {
        $rgb = "#EEEEEE";
    }
    $bgcolor = ImageColorAllocate($image, hexdec(substr($rgb, 1, 2)), hexdec(substr($rgb, 3, 2)), hexdec(substr($rgb, 5, 2)));
    $rgb = $css->Get(".fan_chart_box", "background-color");
    if (empty($rgb)) {
        $rgb = "#D0D0AC";
    }
    $bgcolorM = ImageColorAllocate($image, hexdec(substr($rgb, 1, 2)), hexdec(substr($rgb, 3, 2)), hexdec(substr($rgb, 5, 2)));
    $rgb = $css->Get(".fan_chart_boxF", "background-color");
    if (empty($rgb)) {
        $rgb = "#D0ACD0";
    }
    $bgcolorF = ImageColorAllocate($image, hexdec(substr($rgb, 1, 2)), hexdec(substr($rgb, 3, 2)), hexdec(substr($rgb, 5, 2)));
    // imagemap
    $imagemap = "<map id=\"fanmap\" name=\"fanmap\">";
    // loop to create fan cells
    while ($gen >= 0) {
        // clean current generation area
        $deg2 = 360 + ($fandeg - 180) / 2;
        $deg1 = $deg2 - $fandeg;
        ImageFilledArc($image, $cx, $cy, $rx, $rx, $deg1, $deg2, $bgcolor, IMG_ARC_PIE);
        $rx -= 3;
        // calculate new angle
        $p2 = pow(2, $gen);
        $angle = $fandeg / $p2;
        $deg2 = 360 + ($fandeg - 180) / 2;
        $deg1 = $deg2 - $angle;
        // special case for rootid cell
        if ($gen == 0) {
            $deg1 = 90;
            $deg2 = 360 + $deg1;
        }
        // draw each cell
        while ($sosa >= $p2) {
            $pid = $treeid[$sosa];
            if (!empty($pid)) {
                $indirec = find_person_record($pid);
                if (!$indirec) {
                    $indirec = find_updated_record($pid);
                }
                if ($sosa % 2) {
                    $bg = $bgcolorF;
                } else {
                    $bg = $bgcolorM;
                }
                if ($sosa == 1) {
                    $bg = $bgcolor;
                    // sex unknown
                    if (preg_match("/1 SEX F/", $indirec) > 0) {
                        $bg = $bgcolorF;
                    } else {
                        if (preg_match("/1 SEX M/", $indirec) > 0) {
                            $bg = $bgcolorM;
                        }
                    }
                }
                ImageFilledArc($image, $cx, $cy, $rx, $rx, $deg1, $deg2, $bg, IMG_ARC_PIE);
                $person = Person::getInstance($pid);
                $name = $person->getFullName();
                $addname = $person->getAddName();
                //$name = str_replace(array('<span class="starredname">', '</span>'), '', $name);
                //$addname = str_replace(array('<span class="starredname">', '</span>'), '', $addname);
                //$name = str_replace(array('<span class="starredname">', '</span>'), array('<u>', '</u>'), $name); //@@
                //$addname = str_replace(array('<span class="starredname">', '</span>'), array('<u>', '</u>'), $addname); //@@
                // ToDo - print starred names underlined - 1985154
                // Todo - print Arabic letters combined - 1360209
                $text = reverseText($name) . "\n";
                if (!empty($addname)) {
                    $text .= reverseText($addname) . "\n";
                }
                if (displayDetailsById($pid)) {
                    $birthrec = get_sub_record(1, "1 BIRT", $indirec);
                    $ct = preg_match("/2 DATE.*(\\d\\d\\d\\d)/", $birthrec, $match);
                    if ($ct > 0) {
                        $text .= trim($match[1]);
                    }
                    $deathrec = get_sub_record(1, "1 DEAT", $indirec);
                    $ct = preg_match("/2 DATE.*(\\d\\d\\d\\d)/", $deathrec, $match);
                    if ($ct > 0) {
                        $text .= "-" . trim($match[1]);
                    }
                }
                $text = unhtmlentitiesrtl($text);
                $text = strip_tags($text);
                //Do we still need?
                // split and center text by lines
                $wmax = floor($angle * 7 / $fontsize * $scale);
                $wmax = min($wmax, 35 * $scale);
                if ($gen == 0) {
                    $wmax = min($wmax, 17 * $scale);
                }
                $text = split_align_text($text, $wmax);
                // text angle
                $tangle = 270 - ($deg1 + $angle / 2);
                if ($gen == 0) {
                    $tangle = 0;
                }
                // calculate text position
                $bbox = ImageTtfBbox((double) $fontsize, 0, $fontfile, $text);
                $textwidth = $bbox[4];
                $deg = $deg1 + 0.44;
                if ($deg2 - $deg1 > 40) {
                    $deg = $deg1 + ($deg2 - $deg1) / 11;
                }
                if ($deg2 - $deg1 > 80) {
                    $deg = $deg1 + ($deg2 - $deg1) / 7;
                }
                if ($deg2 - $deg1 > 140) {
                    $deg = $deg1 + ($deg2 - $deg1) / 4;
                }
                if ($gen == 0) {
                    $deg = 180;
                }
                $rad = deg2rad($deg);
                $mr = ($rx - $rw / 4) / 2;
                if ($gen > 0 and $deg2 - $deg1 > 80) {
                    $mr = $rx / 2;
                }
                $tx = $cx + $mr * cos($rad);
                $ty = $cy - $mr * -sin($rad);
                if ($sosa == 1) {
                    $ty -= $mr / 2;
                }
                // print text
                ImageTtfText($image, (double) $fontsize, $tangle, $tx, $ty, $color, $fontfile, $text);
                $imagemap .= "<area shape=\"poly\" coords=\"";
                // plot upper points
                $mr = $rx / 2;
                $deg = $deg1;
                while ($deg <= $deg2) {
                    $rad = deg2rad($deg);
                    $tx = round($cx + $mr * cos($rad));
                    $ty = round($cy - $mr * -sin($rad));
                    $imagemap .= "{$tx}, {$ty}, ";
                    $deg += ($deg2 - $deg1) / 6;
                }
                // plot lower points
                $mr = ($rx - $rw) / 2;
                $deg = $deg2;
                while ($deg >= $deg1) {
                    $rad = deg2rad($deg);
                    $tx = round($cx + $mr * cos($rad));
                    $ty = round($cy - $mr * -sin($rad));
                    $imagemap .= "{$tx}, {$ty}, ";
                    $deg -= ($deg2 - $deg1) / 6;
                }
                // join first point
                $mr = $rx / 2;
                $deg = $deg1;
                $rad = deg2rad($deg);
                $tx = round($cx + $mr * cos($rad));
                $ty = round($cy - $mr * -sin($rad));
                $imagemap .= "{$tx}, {$ty}";
                // add action url
                $tempURL = "javascript://" . htmlspecialchars(strip_tags($name));
                if ($SHOW_ID_NUMBERS) {
                    $tempURL .= " (" . $pid . ")";
                }
                $imagemap .= "\" href=\"{$tempURL}\" ";
                $tempURL = "fanchart.php?rootid={$pid}&PEDIGREE_GENERATIONS={$PEDIGREE_GENERATIONS}&fan_width={$fan_width}&fan_style={$fan_style}";
                if (!empty($view)) {
                    $tempURL .= "&view={$view}";
                }
                $count = 0;
                $lbwidth = 200;
                print "<div id=\"I" . $pid . "." . $count . "links\" style=\"position:absolute; >";
                print "left:" . $tx . "px; top:" . $ty . "px; width: " . $lbwidth . "px; visibility:hidden; z-index:'100';\">";
                print "<table class=\"person_box\"><tr><td class=\"details1\">";
                print "<a href=\"individual.php?pid={$pid}\" class=\"name1\">" . PrintReady($name);
                if (!empty($addname)) {
                    print "<br />" . PrintReady($addname);
                }
                print "</a>";
                print "<br /><a href=\"pedigree.php?rootid={$pid}\" >" . $pgv_lang["index_header"] . "</a>";
                print "<br /><a href=\"descendancy.php?pid={$pid}\" >" . $pgv_lang["descend_chart"] . "</a>";
                if (PGV_USER_GEDCOM_ID) {
                    print "<br /><a href=\"" . encode_url("relationship.php?pid1=" . PGV_USER_GEDCOM_ID . "&pid2={$pid}&ged={$GEDCOM}") . "\" onmouseover=\"clear_family_box_timeout('" . $pid . "." . $count . "');\" onmouseout=\"family_box_timeout('" . $pid . "." . $count . "');\">" . $pgv_lang["relationship_to_me"] . "</a>";
                }
                print "<br /><a href=\"ancestry.php?rootid={$pid}\" onmouseover=\"clear_family_box_timeout('" . $pid . "." . $count . "');\" onmouseout=\"family_box_timeout('" . $pid . "." . $count . "');\">" . $pgv_lang["ancestry_chart"] . "</a>";
                print "<br /><a href=\"compact.php?rootid={$pid}\" onmouseover=\"clear_family_box_timeout('" . $pid . "." . $count . "');\" onmouseout=\"family_box_timeout('" . $pid . "." . $count . "');\">" . $pgv_lang["compact_chart"] . "</a>";
                print "<br /><a href=\"" . encode_url($tempURL) . "\" onmouseover=\"clear_family_box_timeout('" . $pid . "." . $count . "');\" onmouseout=\"family_box_timeout('" . $pid . "." . $count . "');\">" . $pgv_lang["fan_chart"] . "</a>";
                print "<br /><a href=\"hourglass.php?pid={$pid}\" onmouseover=\"clear_family_box_timeout('" . $pid . "." . $count . "');\" onmouseout=\"family_box_timeout('" . $pid . "." . $count . "');\">" . $pgv_lang["hourglass_chart"] . "</a>";
                if ($sosa >= 1) {
                    $famids = find_sfamily_ids($pid);
                    //-- make sure there is more than 1 child in the family with parents
                    $cfamids = find_family_ids($pid);
                    $num = 0;
                    for ($f = 0; $f < count($cfamids); $f++) {
                        $famrec = find_family_record($cfamids[$f]);
                        if ($famrec) {
                            $num += preg_match_all("/1\\s*CHIL\\s*@(.*)@/", $famrec, $smatch, PREG_SET_ORDER);
                        }
                    }
                    if ($famids || $num > 1) {
                        //-- spouse(s) and children
                        for ($f = 0; $f < count($famids); $f++) {
                            $famrec = find_family_record(trim($famids[$f]));
                            if ($famrec) {
                                $parents = find_parents($famids[$f]);
                                if ($parents) {
                                    if ($pid != $parents["HUSB"]) {
                                        $spid = $parents["HUSB"];
                                    } else {
                                        $spid = $parents["WIFE"];
                                    }
                                    $person = Person::getInstance($spid);
                                    if ($person) {
                                        echo '<br /><a href="', $person->getLinkUrl(), '" class="name1">', $person->getFullName(), '</a>';
                                    }
                                }
                                $num = preg_match_all("/1\\s*CHIL\\s*@(.*)@/", $famrec, $smatch, PREG_SET_ORDER);
                                for ($i = 0; $i < $num; $i++) {
                                    $person = Person::getInstance($smatch[$i][1]);
                                    if ($person) {
                                        echo '<br />&nbsp;&nbsp;<a href="', $person->getLinkUrl(), '" class="name1">&lt; ', $person->getFullName(), '</a>';
                                    }
                                }
                            }
                        }
                        //-- siblings
                        for ($f = 0; $f < count($cfamids); $f++) {
                            $famrec = find_family_record($cfamids[$f]);
                            if ($famrec) {
                                $num = preg_match_all("/1\\s*CHIL\\s*@(.*)@/", $famrec, $smatch, PREG_SET_ORDER);
                                if ($num > 2) {
                                    print "<br /><span class=\"name1\">" . $pgv_lang["siblings"] . "</span>";
                                }
                                if ($num == 2) {
                                    print "<br /><span class=\"name1\">" . $pgv_lang["sibling"] . "</span>";
                                }
                                for ($i = 0; $i < $num; $i++) {
                                    $cpid = $smatch[$i][1];
                                    if ($cpid != $pid) {
                                        $person = Person::getInstance($cpid);
                                        if ($person) {
                                            echo '<br />&nbsp;&nbsp;<a href="', $person->getLinkUrl(), '" class="name1"> ', $person->getFullName(), '</a>';
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                print "</td></tr></table>";
                print "</div>";
                $imagemap .= " onclick=\"show_family_box('" . $pid . "." . $count . "', 'relatives'); return false;\"";
                $imagemap .= " onmouseout=\"family_box_timeout('" . $pid . "." . $count . "'); return false;\"";
                $imagemap .= " alt=\"" . PrintReady(strip_tags($name)) . "\" title=\"" . PrintReady(strip_tags($name)) . "\" />";
            }
            $deg1 -= $angle;
            $deg2 -= $angle;
            $sosa--;
        }
        $rx -= $rw;
        $gen--;
    }
    $imagemap .= "</map>";
    echo $imagemap;
    // PGV banner ;-)
    ImageStringUp($image, 1, $fanw - 10, $fanh / 3, PGV_PHPGEDVIEW_URL, $color);
    // here we cannot send image to browser ('header already sent')
    // and we dont want to use a tmp file
    // step 1. save image data in a session variable
    ob_start();
    ImagePng($image);
    $image_data = ob_get_contents();
    ob_end_clean();
    $image_data = serialize($image_data);
    unset($_SESSION['image_data']);
    $_SESSION['image_data'] = $image_data;
    // step 2. call imageflush.php to read this session variable and display image
    // note: arg "image_name=" is to avoid image miscaching
    $image_name = "V" . time();
    unset($_SESSION[$image_name]);
    // statisticsplot.php uses this to hold a file name to send to browser
    $image_title = preg_replace("~<.*>~", "", $name) . " " . $pgv_lang["fan_chart"];
    echo "<p align=\"center\" >";
    echo "<img src=\"imageflush.php?image_type=png&amp;image_name={$image_name}&amp;height={$fanh}&amp;width={$fanw}\" width=\"{$fanw}\" height=\"{$fanh}\" border=\"0\" alt=\"{$image_title}\" title=\"{$image_title}\" usemap=\"#fanmap\" />";
    echo "</p>";
    ImageDestroy($image);
}
Esempio n. 2
0
/**
 * get a quick-glance view of current LDS ordinances
 * @param string $indirec
 * @return string
 */
function get_lds_glance($indirec)
{
    $text = "";
    $ord = get_sub_record(1, "1 BAPL", $indirec);
    if ($ord) {
        $text .= "B";
    } else {
        $text .= "_";
    }
    $ord = get_sub_record(1, "1 ENDL", $indirec);
    if ($ord) {
        $text .= "E";
    } else {
        $text .= "_";
    }
    $found = false;
    $ct = preg_match_all("/1 FAMS @(.*)@/", $indirec, $match, PREG_SET_ORDER);
    for ($i = 0; $i < $ct; $i++) {
        $famrec = find_family_record($match[$i][1]);
        if ($famrec) {
            $ord = get_sub_record(1, "1 SLGS", $famrec);
            if ($ord) {
                $found = true;
                break;
            }
        }
    }
    if ($found) {
        $text .= "S";
    } else {
        $text .= "_";
    }
    $ord = get_sub_record(1, "1 SLGC", $indirec);
    if ($ord) {
        $text .= "P";
    } else {
        $text .= "_";
    }
    return $text;
}
Esempio n. 3
0
    /**
     * print parents informations
     * @param Family family
     * @param Array people
     * @param String family type
     * @return html table rows
     */
    function printParentsRows(&$family, &$people, $type)
    {
        global $personcount, $pgv_changes, $pgv_lang, $factarray;
        global $PGV_IMAGE_DIR, $PGV_IMAGES;
        global $lang_short_cut, $LANGUAGE;
        $elderdate = "";
        //-- new father/husband
        $styleadd = "";
        if (isset($people["newhusb"])) {
            $styleadd = "red";
            ?>
			<tr>
				<td class="facts_labelblue"><?php 
            print $people["newhusb"]->getLabel();
            ?>
</td>
				<td class="<?php 
            print $this->getPersonStyle($people["newhusb"]);
            ?>
">
					<?php 
            print_pedigree_person($people["newhusb"]->getXref(), 2, !$this->isPrintPreview(), 0, $personcount++);
            ?>
				</td>
			</tr>
			<?php 
            $elderdate = $people["newhusb"]->getBirthDate();
        }
        //-- father/husband
        if (isset($people["husb"])) {
            ?>
			<tr>
				<td class="facts_label<?php 
            print $styleadd;
            ?>
"><?php 
            print $people["husb"]->getLabel();
            ?>
</td>
				<td class="<?php 
            print $this->getPersonStyle($people["husb"]);
            ?>
">
					<?php 
            print_pedigree_person($people["husb"]->getXref(), 2, !$this->isPrintPreview(), 0, $personcount++);
            ?>
				</td>
			</tr>
			<?php 
            $elderdate = $people["husb"]->getBirthDate();
        }
        //-- missing father
        if ($type == "parents" && !isset($people["husb"]) && !isset($people["newhusb"])) {
            if (!$this->isPrintPreview() && PGV_USER_CAN_EDIT && $this->indi->canDisplayDetails()) {
                ?>
				<tr>
					<td class="facts_label"><?php 
                print $pgv_lang["add_father"];
                ?>
</td>
					<td class="facts_value"><?php 
                print_help_link("edit_add_parent_help", "qm");
                ?>
 <a href="javascript <?php 
                print $pgv_lang["add_father"];
                ?>
" onclick="return addnewparentfamily('<?php 
                print $this->pid;
                ?>
', 'HUSB', '<?php 
                print $family->getXref();
                ?>
');"><?php 
                print $pgv_lang["add_father"];
                ?>
</a></td>
				</tr>
				<?php 
            }
        }
        //-- missing husband
        if ($type == "spouse" && $this->indi->equals($people["wife"]) && !isset($people["husb"]) && !isset($people["newhusb"])) {
            if (!$this->isPrintPreview() && PGV_USER_CAN_EDIT && $this->indi->canDisplayDetails()) {
                ?>
				<tr>
					<td class="facts_label"><?php 
                print $pgv_lang["add_husb"];
                ?>
</td>
					<td class="facts_value"><a href="javascript:;" onclick="return addnewspouse('<?php 
                print $family->getXref();
                ?>
', 'HUSB');"><?php 
                print $pgv_lang["add_husb_to_family"];
                ?>
</a></td>
				</tr>
				<?php 
            }
        }
        //-- new mother/wife
        $styleadd = "";
        if (isset($people["newwife"])) {
            $styleadd = "red";
            ?>
			<tr>
				<td class="facts_labelblue"><?php 
            print $people["newwife"]->getLabel($elderdate);
            ?>
</td>
				<td class="<?php 
            print $this->getPersonStyle($people["newwife"]);
            ?>
">
					<?php 
            print_pedigree_person($people["newwife"]->getXref(), 2, !$this->isPrintPreview(), 0, $personcount++);
            ?>
				</td>
			</tr>
			<?php 
        }
        //-- mother/wife
        if (isset($people["wife"])) {
            ?>
			<tr>
				<td class="facts_label<?php 
            print $styleadd;
            ?>
"><?php 
            print $people["wife"]->getLabel($elderdate);
            ?>
</td>
				<td class="<?php 
            print $this->getPersonStyle($people["wife"]);
            ?>
">
					<?php 
            print_pedigree_person($people["wife"]->getXref(), 2, !$this->isPrintPreview(), 0, $personcount++);
            ?>
				</td>
			</tr>
			<?php 
        }
        //-- missing mother
        if ($type == "parents" && !isset($people["wife"]) && !isset($people["newwife"])) {
            if (!$this->isPrintPreview() && PGV_USER_CAN_EDIT && $this->indi->canDisplayDetails()) {
                ?>
				<tr>
					<td class="facts_label"><?php 
                print $pgv_lang["add_mother"];
                ?>
</td>
					<td class="facts_value"><?php 
                print_help_link("edit_add_parent_help", "qm");
                ?>
 <a href="javascript:;" onclick="return addnewparentfamily('<?php 
                print $this->pid;
                ?>
', 'WIFE', '<?php 
                print $family->getXref();
                ?>
');"><?php 
                print $pgv_lang["add_mother"];
                ?>
</a></td>
				</tr>
				<?php 
            }
        }
        //-- missing wife
        if ($type == "spouse" && $this->indi->equals($people["husb"]) && !isset($people["wife"]) && !isset($people["newwife"])) {
            if (!$this->isPrintPreview() && PGV_USER_CAN_EDIT && $this->indi->canDisplayDetails()) {
                ?>
				<tr>
					<td class="facts_label"><?php 
                print $pgv_lang["add_wife"];
                ?>
</td>
					<td class="facts_value"><a href="javascript:;" onclick="return addnewspouse('<?php 
                print $family->getXref();
                ?>
', 'WIFE');"><?php 
                print $pgv_lang["add_wife_to_family"];
                ?>
</a></td>
				</tr>
				<?php 
            }
        }
        //-- marriage row
        if ($family->getMarriageRecord() != "" || PGV_USER_CAN_EDIT) {
            $styleadd = "";
            $date = $family->getMarriageDate();
            $place = $family->getMarriagePlace();
            $famid = $family->getXref();
            if (!$date && $this->show_changes && isset($pgv_changes[$famid . "_" . $GEDCOM])) {
                $famrec = find_updated_record($famid);
                $marrrec = get_sub_record(1, "1 MARR", $famrec);
                if ($marrrec != $family->getMarriageRecord()) {
                    $date = new GedcomDate(get_gedcom_value("MARR:DATE", 1, $marrrec, '', false));
                    $place = get_gedcom_value("MARR:PLAC", 1, $marrrec, '', false);
                    $styleadd = "blue";
                }
            }
            ?>
			<tr>
				<td class="facts_label"><br />
				</td>
				<td class="facts_value<?php 
            print $styleadd;
            ?>
">
					<?php 
            //echo "<span class=\"details_label\">".$factarray["NCHI"].": </span>".$family->getNumberOfChildren()."<br />";
            ?>
					<?php 
            if ($date && $date->isOK() || $place) {
                $marr_type = "MARR_" . strtoupper($family->getMarriageType());
                if (isset($factarray[$marr_type])) {
                    echo "<span class=\"details_label\">" . $factarray[$marr_type] . ": </span>";
                } else {
                    echo "<span class=\"details_label\">" . $factarray["MARR"] . ": </span>" . $family->getMarriageType();
                }
                if ($date) {
                    echo $date->Display(false);
                    if (!empty($place)) {
                        echo ' -- ';
                    }
                }
                if (!empty($place)) {
                    echo $place;
                }
            } else {
                if (get_sub_record(1, "1 _NMR", find_family_record($famid))) {
                    // Allow special processing for different languages
                    $func = "fact_NMR_localisation_{$lang_short_cut[$LANGUAGE]}";
                    if (function_exists($func)) {
                        // Localise the _NMR facts
                        $func("_NMR", $famid);
                    }
                    echo $factarray["_NMR"];
                } else {
                    if (get_sub_record(1, "1 _NMAR", find_family_record($famid))) {
                        // Allow special processing for different languages
                        $func = "fact_NMR_localisation_{$lang_short_cut[$LANGUAGE]}";
                        if (function_exists($func)) {
                            // Localise the _NMR facts
                            $func("_NMAR", $famid);
                        }
                        echo $factarray["_NMAR"];
                    } else {
                        if ($family->getMarriageRecord() == "" && PGV_USER_CAN_EDIT) {
                            print "<a href=\"#\" onclick=\"return add_new_record('" . $famid . "', 'MARR');\">" . $pgv_lang['add_marriage'] . "</a>";
                        } else {
                            $factdetail = explode(' ', trim($family->getMarriageRecord()));
                            if ($family->getMarriageType()) {
                                $marr_type = "MARR_" . strtoupper($family->getMarriageType());
                            } else {
                                $marr_type = "MARR";
                            }
                            if (isset($factarray[$marr_type])) {
                                if (isset($factdetail)) {
                                    if (count($factdetail) == 3) {
                                        if (strtoupper($factdetail[2]) == "Y") {
                                            echo "<span class=\"details_label\">" . $factarray[$marr_type] . ": </span>" . $pgv_lang["yes"];
                                        } else {
                                            if (strtoupper($factdetail[2]) == "N") {
                                                echo "<span class=\"details_label\">" . $factarray[$marr_type] . ": </span>" . $pgv_lang["no"];
                                            }
                                        }
                                    }
                                }
                            } else {
                                echo "<span class=\"details_label\">" . $factarray["MARR"] . ": </span>" . $family->getMarriageType();
                            }
                        }
                    }
                }
            }
            ?>
				</td>
			</tr>
			<?php 
        }
    }
Esempio n. 4
0
 function add_ancestors_to_cart_families($pid, $level = "")
 {
     global $cart;
     $famids = find_family_ids($pid);
     if (count($famids) > 0) {
         foreach ($famids as $indexval => $famid) {
             if ($level == "" || $level > 0) {
                 if ($level != "") {
                     $level = $level - 1;
                 }
                 $clipping = array();
                 $clipping['type'] = "fam";
                 $clipping['id'] = $famid;
                 $ret = $this->add_clipping($clipping);
                 if ($ret) {
                     $parents = find_parents($famid);
                     if (!empty($parents["HUSB"])) {
                         $clipping = array();
                         $clipping['type'] = "indi";
                         $clipping['id'] = $parents["HUSB"];
                         $ret = $this->add_clipping($clipping);
                         $this->add_ancestors_to_cart_families($parents["HUSB"], $level);
                     }
                     if (!empty($parents["WIFE"])) {
                         $clipping = array();
                         $clipping['type'] = "indi";
                         $clipping['id'] = $parents["WIFE"];
                         $ret = $this->add_clipping($clipping);
                         $this->add_ancestors_to_cart_families($parents["WIFE"], $level);
                     }
                     $famrec = find_family_record($famid);
                     if ($famrec) {
                         $num = preg_match_all("/1\\s*CHIL\\s*@(.*)@/", $famrec, $smatch, PREG_SET_ORDER);
                         for ($i = 0; $i < $num; $i++) {
                             $clipping = array();
                             $clipping['type'] = "indi";
                             $clipping['id'] = $smatch[$i][1];
                             $this->add_clipping($clipping);
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 5
0
/**
 * Get relationship between two individuals in the gedcom
 *
 * function to calculate the relationship between two people it uses hueristics based on the
 * individuals birthdate to try and calculate the shortest path between the two individuals
 * it uses a node cache to help speed up calculations when using relationship privacy
 * this cache is indexed using the string "$pid1-$pid2"
 * @param string $pid1 the ID of the first person to compute the relationship from
 * @param string $pid2 the ID of the second person to compute the relatiohip to
 * @param bool $followspouse whether to add spouses to the path
 * @param int $maxlenght the maximim length of path
 * @param bool $ignore_cache enable or disable the relationship cache
 * @param int $path_to_find which path in the relationship to find, 0 is the shortest path, 1 is the next shortest path, etc
 */
function get_relationship($pid1, $pid2, $followspouse = true, $maxlength = 0, $ignore_cache = false, $path_to_find = 0)
{
    global $TIME_LIMIT, $start_time, $pgv_lang, $NODE_CACHE, $NODE_CACHE_LENGTH, $USE_RELATIONSHIP_PRIVACY, $pgv_changes, $GEDCOM;
    $pid1 = strtoupper($pid1);
    $pid2 = strtoupper($pid2);
    if (isset($pgv_changes[$pid2 . "_" . $GEDCOM]) && PGV_USER_CAN_EDIT) {
        $indirec = find_updated_record($pid2);
    } else {
        $indirec = find_person_record($pid2);
    }
    //-- check the cache
    if ($USE_RELATIONSHIP_PRIVACY && !$ignore_cache) {
        if (isset($NODE_CACHE["{$pid1}-{$pid2}"])) {
            if ($NODE_CACHE["{$pid1}-{$pid2}"] == "NOT FOUND") {
                return false;
            }
            if ($maxlength == 0 || count($NODE_CACHE["{$pid1}-{$pid2}"]["path"]) - 1 <= $maxlength) {
                return $NODE_CACHE["{$pid1}-{$pid2}"];
            } else {
                return false;
            }
        }
        //-- check the cache for person 2's children
        $famids = array();
        $ct = preg_match_all("/1\\sFAMS\\s@(.*)@/", $indirec, $match, PREG_SET_ORDER);
        for ($i = 0; $i < $ct; $i++) {
            $famids[$i] = $match[$i][1];
        }
        foreach ($famids as $indexval => $fam) {
            if (isset($pgv_changes[$fam . "_" . $GEDCOM]) && PGV_USER_CAN_EDIT) {
                $famrec = find_updated_record($fam);
            } else {
                $famrec = find_family_record($fam);
            }
            $ct = preg_match_all("/1 CHIL @(.*)@/", $famrec, $match, PREG_SET_ORDER);
            for ($i = 0; $i < $ct; $i++) {
                $child = $match[$i][1];
                if (!empty($child)) {
                    if (isset($NODE_CACHE["{$pid1}-{$child}"])) {
                        if ($maxlength == 0 || count($NODE_CACHE["{$pid1}-{$child}"]["path"]) + 1 <= $maxlength) {
                            $node1 = $NODE_CACHE["{$pid1}-{$child}"];
                            if ($node1 != "NOT FOUND") {
                                $node1["path"][] = $pid2;
                                $node1["pid"] = $pid2;
                                $ct = preg_match("/1 SEX F/", $indirec, $match);
                                if ($ct > 0) {
                                    $node1["relations"][] = "mother";
                                } else {
                                    $node1["relations"][] = "father";
                                }
                            }
                            $NODE_CACHE["{$pid1}-{$pid2}"] = $node1;
                            if ($node1 == "NOT FOUND") {
                                return false;
                            }
                            return $node1;
                        } else {
                            return false;
                        }
                    }
                }
            }
        }
        if (!empty($NODE_CACHE_LENGTH) && $maxlength > 0) {
            if ($NODE_CACHE_LENGTH >= $maxlength) {
                return false;
            }
        }
    }
    //-- end cache checking
    //-- get the birth year of p2 for calculating heuristics
    $birthrec = get_sub_record(1, "1 BIRT", $indirec);
    $byear2 = -1;
    if ($birthrec !== false) {
        $dct = preg_match("/2 DATE .*(\\d\\d\\d\\d)/", $birthrec, $match);
        if ($dct > 0) {
            $byear2 = $match[1];
        }
    }
    if ($byear2 == -1) {
        $numfams = preg_match_all("/1\\s*FAMS\\s*@(.*)@/", $indirec, $fmatch, PREG_SET_ORDER);
        for ($j = 0; $j < $numfams; $j++) {
            // Get the family record
            if (isset($pgv_changes[$fmatch[$j][1] . "_" . $GEDCOM]) && PGV_USER_CAN_EDIT) {
                $famrec = find_updated_record($fmatch[$j][1]);
            } else {
                $famrec = find_family_record($fmatch[$j][1]);
            }
            // Get the set of children
            $ct = preg_match_all("/1 CHIL @(.*)@/", $famrec, $cmatch, PREG_SET_ORDER);
            for ($i = 0; $i < $ct; $i++) {
                // Get each child's record
                if (isset($pgv_changes[$cmatch[$i][1] . "_" . $GEDCOM]) && PGV_USER_CAN_EDIT) {
                    $childrec = find_updated_record($cmatch[$i][1]);
                } else {
                    $childrec = find_person_record($cmatch[$i][1]);
                }
                $birthrec = get_sub_record(1, "1 BIRT", $childrec);
                if ($birthrec !== false) {
                    $dct = preg_match("/2 DATE .*(\\d\\d\\d\\d)/", $birthrec, $bmatch);
                    if ($dct > 0) {
                        $byear2 = $bmatch[1] - 25;
                    }
                    if ($byear2 > 2100) {
                        $byear2 -= 3760;
                    }
                    // Crude conversion from jewish to gregorian
                }
            }
        }
    }
    //-- end of approximating birth year
    //-- current path nodes
    $p1nodes = array();
    //-- ids visited
    $visited = array();
    //-- set up first node for person1
    $node1 = array();
    $node1["path"] = array();
    $node1["path"][] = $pid1;
    $node1["length"] = 0;
    $node1["pid"] = $pid1;
    $node1["relations"] = array();
    $node1["relations"][] = "self";
    $p1nodes[] = $node1;
    $visited[$pid1] = true;
    $found = false;
    $count = 0;
    while (!$found) {
        //-- the following 2 lines ensure that the user can abort a long relationship calculation
        //-- refer to http://www.php.net/manual/en/features.connection-handling.php for more
        //-- information about why these lines are included
        if (headers_sent()) {
            print " ";
            if ($count % 100 == 0) {
                flush();
            }
        }
        $count++;
        $end_time = microtime(true);
        $exectime = $end_time - $start_time;
        if ($TIME_LIMIT > 1 && $exectime > $TIME_LIMIT - 1) {
            print "<span class=\"error\">" . $pgv_lang["timeout_error"] . "</span>\n";
            return false;
        }
        if (count($p1nodes) == 0) {
            if ($maxlength != 0) {
                if (!isset($NODE_CACHE_LENGTH)) {
                    $NODE_CACHE_LENGTH = $maxlength;
                } else {
                    if ($NODE_CACHE_LENGTH < $maxlength) {
                        $NODE_CACHE_LENGTH = $maxlength;
                    }
                }
            }
            if (headers_sent()) {
                print "\n<!-- Relationship {$pid1}-{$pid2} NOT FOUND | Visited " . count($visited) . " nodes | Required {$count} iterations.<br />\n";
                print_execution_stats();
                print "-->\n";
            }
            $NODE_CACHE["{$pid1}-{$pid2}"] = "NOT FOUND";
            return false;
        }
        //-- search the node list for the shortest path length
        $shortest = -1;
        foreach ($p1nodes as $index => $node) {
            if ($shortest == -1) {
                $shortest = $index;
            } else {
                $node1 = $p1nodes[$shortest];
                if ($node1["length"] > $node["length"]) {
                    $shortest = $index;
                }
            }
        }
        if ($shortest == -1) {
            return false;
        }
        $node = $p1nodes[$shortest];
        if ($maxlength == 0 || count($node["path"]) <= $maxlength) {
            if ($node["pid"] == $pid2) {
            } else {
                //-- hueristic values
                $fatherh = 1;
                $motherh = 1;
                $siblingh = 2;
                $spouseh = 2;
                $childh = 3;
                //-- generate heuristic values based of the birthdates of the current node and p2
                if (isset($pgv_changes[$node["pid"] . "_" . $GEDCOM]) && PGV_USER_CAN_EDIT) {
                    $indirec = find_updated_record($node["pid"]);
                } else {
                    $indirec = find_person_record($node["pid"]);
                }
                $byear1 = -1;
                $birthrec = get_sub_record(1, "1 BIRT", $indirec);
                if ($birthrec !== false) {
                    $dct = preg_match("/2 DATE .*(\\d\\d\\d\\d)/", $birthrec, $match);
                    if ($dct > 0) {
                        $byear1 = $match[1];
                    }
                    if ($byear1 > 2100) {
                        $byear1 -= 3760;
                    }
                    // Crude conversion from jewish to gregorian
                }
                if ($byear1 != -1 && $byear2 != -1) {
                    $yeardiff = $byear1 - $byear2;
                    if ($yeardiff < -140) {
                        $fatherh = 20;
                        $motherh = 20;
                        $siblingh = 15;
                        $spouseh = 15;
                        $childh = 1;
                    } else {
                        if ($yeardiff < -100) {
                            $fatherh = 15;
                            $motherh = 15;
                            $siblingh = 10;
                            $spouseh = 10;
                            $childh = 1;
                        } else {
                            if ($yeardiff < -60) {
                                $fatherh = 10;
                                $motherh = 10;
                                $siblingh = 5;
                                $spouseh = 5;
                                $childh = 1;
                            } else {
                                if ($yeardiff < -20) {
                                    $fatherh = 5;
                                    $motherh = 5;
                                    $siblingh = 3;
                                    $spouseh = 3;
                                    $childh = 1;
                                } else {
                                    if ($yeardiff < 20) {
                                        $fatherh = 3;
                                        $motherh = 3;
                                        $siblingh = 1;
                                        $spouseh = 1;
                                        $childh = 5;
                                    } else {
                                        if ($yeardiff < 60) {
                                            $fatherh = 1;
                                            $motherh = 1;
                                            $siblingh = 5;
                                            $spouseh = 2;
                                            $childh = 10;
                                        } else {
                                            if ($yeardiff < 100) {
                                                $fatherh = 1;
                                                $motherh = 1;
                                                $siblingh = 10;
                                                $spouseh = 3;
                                                $childh = 15;
                                            } else {
                                                $fatherh = 1;
                                                $motherh = 1;
                                                $siblingh = 15;
                                                $spouseh = 4;
                                                $childh = 20;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                //-- check all parents and siblings of this node
                $famids = array();
                $ct = preg_match_all("/1\\sFAMC\\s@(.*)@/", $indirec, $match, PREG_SET_ORDER);
                for ($i = 0; $i < $ct; $i++) {
                    if (!isset($visited[$match[$i][1]])) {
                        $famids[$i] = $match[$i][1];
                    }
                }
                foreach ($famids as $indexval => $fam) {
                    $visited[$fam] = true;
                    if (isset($pgv_changes[$fam . "_" . $GEDCOM]) && PGV_USER_CAN_EDIT) {
                        $famrec = find_updated_record($fam);
                    } else {
                        $famrec = find_family_record($fam);
                    }
                    $parents = find_parents_in_record($famrec);
                    if (!empty($parents["HUSB"]) && !isset($visited[$parents["HUSB"]])) {
                        $node1 = $node;
                        $node1["length"] += $fatherh;
                        $node1["path"][] = $parents["HUSB"];
                        $node1["pid"] = $parents["HUSB"];
                        $node1["relations"][] = "father";
                        $p1nodes[] = $node1;
                        if ($node1["pid"] == $pid2) {
                            if ($path_to_find > 0) {
                                $path_to_find--;
                            } else {
                                $found = true;
                                $resnode = $node1;
                            }
                        } else {
                            $visited[$parents["HUSB"]] = true;
                        }
                        if ($USE_RELATIONSHIP_PRIVACY) {
                            $NODE_CACHE["{$pid1}-" . $node1["pid"]] = $node1;
                        }
                    }
                    if (!empty($parents["WIFE"]) && !isset($visited[$parents["WIFE"]])) {
                        $node1 = $node;
                        $node1["length"] += $motherh;
                        $node1["path"][] = $parents["WIFE"];
                        $node1["pid"] = $parents["WIFE"];
                        $node1["relations"][] = "mother";
                        $p1nodes[] = $node1;
                        if ($node1["pid"] == $pid2) {
                            if ($path_to_find > 0) {
                                $path_to_find--;
                            } else {
                                $found = true;
                                $resnode = $node1;
                            }
                        } else {
                            $visited[$parents["WIFE"]] = true;
                        }
                        if ($USE_RELATIONSHIP_PRIVACY) {
                            $NODE_CACHE["{$pid1}-" . $node1["pid"]] = $node1;
                        }
                    }
                    $ct = preg_match_all("/1 CHIL @(.*)@/", $famrec, $match, PREG_SET_ORDER);
                    for ($i = 0; $i < $ct; $i++) {
                        $child = $match[$i][1];
                        if (!empty($child) && !isset($visited[$child])) {
                            $node1 = $node;
                            $node1["length"] += $siblingh;
                            $node1["path"][] = $child;
                            $node1["pid"] = $child;
                            $node1["relations"][] = "sibling";
                            $p1nodes[] = $node1;
                            if ($node1["pid"] == $pid2) {
                                if ($path_to_find > 0) {
                                    $path_to_find--;
                                } else {
                                    $found = true;
                                    $resnode = $node1;
                                }
                            } else {
                                $visited[$child] = true;
                            }
                            if ($USE_RELATIONSHIP_PRIVACY) {
                                $NODE_CACHE["{$pid1}-" . $node1["pid"]] = $node1;
                            }
                        }
                    }
                }
                //-- check all spouses and children of this node
                $famids = array();
                $ct = preg_match_all("/1\\sFAMS\\s@(.*)@/", $indirec, $match, PREG_SET_ORDER);
                for ($i = 0; $i < $ct; $i++) {
                    $famids[$i] = $match[$i][1];
                }
                foreach ($famids as $indexval => $fam) {
                    $visited[$fam] = true;
                    if (isset($pgv_changes[$fam . "_" . $GEDCOM]) && PGV_USER_CAN_EDIT) {
                        $famrec = find_updated_record($fam);
                    } else {
                        $famrec = find_family_record($fam);
                    }
                    if ($followspouse) {
                        $parents = find_parents_in_record($famrec);
                        if (!empty($parents["HUSB"]) && (!in_arrayr($parents["HUSB"], $node1) || !isset($visited[$parents["HUSB"]]))) {
                            $node1 = $node;
                            $node1["length"] += $spouseh;
                            $node1["path"][] = $parents["HUSB"];
                            $node1["pid"] = $parents["HUSB"];
                            $node1["relations"][] = "spouse";
                            $p1nodes[] = $node1;
                            if ($node1["pid"] == $pid2) {
                                if ($path_to_find > 0) {
                                    $path_to_find--;
                                } else {
                                    $found = true;
                                    $resnode = $node1;
                                }
                            } else {
                                $visited[$parents["HUSB"]] = true;
                            }
                            if ($USE_RELATIONSHIP_PRIVACY) {
                                $NODE_CACHE["{$pid1}-" . $node1["pid"]] = $node1;
                            }
                        }
                        if (!empty($parents["WIFE"]) && (!in_arrayr($parents["WIFE"], $node1) || !isset($visited[$parents["WIFE"]]))) {
                            $node1 = $node;
                            $node1["length"] += $spouseh;
                            $node1["path"][] = $parents["WIFE"];
                            $node1["pid"] = $parents["WIFE"];
                            $node1["relations"][] = "spouse";
                            $p1nodes[] = $node1;
                            if ($node1["pid"] == $pid2) {
                                if ($path_to_find > 0) {
                                    $path_to_find--;
                                } else {
                                    $found = true;
                                    $resnode = $node1;
                                }
                            } else {
                                $visited[$parents["WIFE"]] = true;
                            }
                            if ($USE_RELATIONSHIP_PRIVACY) {
                                $NODE_CACHE["{$pid1}-" . $node1["pid"]] = $node1;
                            }
                        }
                    }
                    $ct = preg_match_all("/1 CHIL @(.*)@/", $famrec, $match, PREG_SET_ORDER);
                    for ($i = 0; $i < $ct; $i++) {
                        $child = $match[$i][1];
                        if (!empty($child) && !isset($visited[$child])) {
                            $node1 = $node;
                            $node1["length"] += $childh;
                            $node1["path"][] = $child;
                            $node1["pid"] = $child;
                            $node1["relations"][] = "child";
                            $p1nodes[] = $node1;
                            if ($node1["pid"] == $pid2) {
                                if ($path_to_find > 0) {
                                    $path_to_find--;
                                } else {
                                    $found = true;
                                    $resnode = $node1;
                                }
                            } else {
                                $visited[$child] = true;
                            }
                            if ($USE_RELATIONSHIP_PRIVACY) {
                                $NODE_CACHE["{$pid1}-" . $node1["pid"]] = $node1;
                            }
                        }
                    }
                }
            }
        }
        unset($p1nodes[$shortest]);
    }
    //-- end while loop
    if (headers_sent()) {
        print "\n<!-- Relationship {$pid1}-{$pid2} | Visited " . count($visited) . " nodes | Required {$count} iterations.<br />\n";
        print_execution_stats();
        print "-->\n";
    }
    return $resnode;
}
Esempio n. 6
0
/**
* Delete a person and update all records that link to that person
* @param string $pid the id of the person to delete
* @param string $gedrec the gedcom record of the person to delete
* @return boolean true or false based on the successful completion of the deletion
*/
function delete_family($pid, $gedrec = '')
{
    // NOTE: $pgv_changes isn't a global.  Making it global appears to cause problems.
    global $GEDCOM, $pgv_lang;
    if (empty($gedrec)) {
        $gedrec = find_family_record($pid);
    }
    if (!empty($gedrec)) {
        $success = true;
        $ct = preg_match_all("/1 (\\w+) @(.*)@/", $gedrec, $match, PREG_SET_ORDER);
        for ($i = 0; $i < $ct; $i++) {
            $type = $match[$i][1];
            $id = $match[$i][2];
            if (PGV_DEBUG) {
                echo $type . " " . $id . " ";
            }
            if (!isset($pgv_changes[$id . "_" . $GEDCOM])) {
                $indirec = find_gedcom_record($id);
            } else {
                $indirec = find_updated_record($id);
            }
            if (!empty($indirec)) {
                $lines = explode("\n", $indirec);
                $newindirec = "";
                $lastlevel = -1;
                foreach ($lines as $indexval => $line) {
                    $lct = preg_match("/^(\\d+)/", $line, $levelmatch);
                    if ($lct > 0) {
                        $level = $levelmatch[1];
                    } else {
                        $level = 1;
                    }
                    //-- make sure we don't add any sublevel records
                    if ($level <= $lastlevel) {
                        $lastlevel = -1;
                    }
                    if (preg_match("/@{$pid}@/", $line) == 0 && $lastlevel == -1) {
                        $newindirec .= $line . "\n";
                    } else {
                        $lastlevel = $level;
                    }
                }
                $success = $success && replace_gedrec($id, $newindirec);
            }
        }
        if ($success) {
            $success = $success && delete_gedrec($pid);
        }
        return $success;
    }
    return false;
}
Esempio n. 7
0
/**
 * print cousins list
 *
 * @param string $famid family ID
 */
function print_cousins($famid, $personcount = "1")
{
    global $show_full, $bheight, $bwidth;
    global $PGV_IMAGE_DIR, $PGV_IMAGES, $pgv_lang, $TEXT_DIRECTION;
    $family = Family::getInstance($famid);
    $fchildren = $family->getChildrenIds();
    $kids = count($fchildren);
    $save_show_full = $show_full;
    if ($save_show_full) {
        $bheight /= 4;
        $bwidth -= 40;
    }
    $show_full = false;
    print "<td valign=\"middle\" height=\"100%\">";
    if ($kids) {
        print "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" ><tr valign=\"middle\">";
        if ($kids > 1) {
            print "<td rowspan=\"" . $kids . "\" valign=\"middle\" align=\"right\"><img width=\"3px\" height=\"" . ($bheight + 5) * ($kids - 1) . "px\" src=\"" . $PGV_IMAGE_DIR . "/" . $PGV_IMAGES["vline"]["other"] . "\" alt=\"\" /></td>";
        }
        $ctkids = count($fchildren);
        $i = 1;
        foreach ($fchildren as $indexval => $fchil) {
            print "<td><img width=\"10px\" height=\"3px\" style=\"padding-";
            if ($TEXT_DIRECTION == "ltr") {
                print "right";
            } else {
                print "left";
            }
            print ": 2px;\" src=\"" . $PGV_IMAGE_DIR . "/" . $PGV_IMAGES["hline"]["other"] . "\" alt=\"\" /></td><td>";
            print_pedigree_person($fchil, 1, false, 0, $personcount);
            $personcount++;
            print "</td></tr>";
            if ($i < $ctkids) {
                print "<tr>";
                $i++;
            }
        }
        print "</table>";
    } else {
        $famrec = find_family_record($famid);
        $ct = preg_match("/1 NCHI (\\w+)/", $famrec, $match);
        if ($ct > 0) {
            $nchi = $match[1];
        } else {
            $nchi = "";
        }
        if ($nchi == "0") {
            print "&nbsp;<img src=\"images/small/childless.gif\" alt=\"" . $pgv_lang["childless_family"] . "\" title=\"" . $pgv_lang["childless_family"] . "\" />";
        }
    }
    $show_full = $save_show_full;
    if ($save_show_full) {
        $bheight *= 4;
        $bwidth += 40;
    }
    print "</td>\n";
}
Esempio n. 8
0
function print_family_book($pid, $descent)
{
    global $generations, $dgenerations, $pgv_lang, $firstrun;
    if ($descent == 0) {
        return;
    }
    $famids = find_sfamily_ids($pid);
    if (count($famids) > 0 || empty($firstrun)) {
        $firstrun = true;
        $pid = check_rootid($pid);
        $person = Person::getInstance($pid);
        $name = $person->getFullName();
        print "\n\t<h2 style=\"text-align: center\">" . $pgv_lang["family_of"] . PrintReady($name) . "</h2>";
        print "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tr>\n";
        //-- descendancy
        print "<td valign=\"middle\">\n";
        $dgenerations = $generations;
        // $dgenerations = max_descendency_generations($pid, 0);
        print_descendency($pid, 1);
        print "</td>\n";
        //-- pedigree
        print "<td valign=\"middle\">\n";
        print_person_pedigree($pid, 1);
        print "</td>\n";
        print "</tr></table>\n";
        print "<br /><br />\n";
        print "<hr style=\"page-break-after:always;\"/>\n";
        print "<br /><br />\n";
        foreach ($famids as $indexval => $famid) {
            $famrec = find_family_record($famid, PGV_GED_ID);
            $ct = preg_match_all("/1 CHIL @(.*)@/", $famrec, $match, PREG_SET_ORDER);
            for ($i = 0; $i < $ct; $i++) {
                $chil = trim($match[$i][1]);
                if (showLivingNameById($chil) || displayDetailsById($chil)) {
                    print_family_book($chil, $descent - 1);
                }
            }
        }
    }
}
        ?>
<div id="tab<?php 
        echo $i;
        ?>
" style="display: none;">
<table class="<?php 
        echo $TEXT_DIRECTION;
        ?>
 width80">
<?php 
        $famreqdfacts = preg_split("/[,; ]/", $QUICK_REQUIRED_FAMFACTS);
        $parents = find_parents($cfams[$j - 1]);
        $famid = $cfams[$j - 1];
        $family = Family::getInstance($famid);
        if (!isset($pgv_changes[$famid . "_" . PGV_GEDCOM])) {
            $famrec = find_family_record($famid, PGV_GED_ID);
        } else {
            $famrec = find_updated_record($famid, PGV_GED_ID);
        }
        if ($family) {
            $subrecords = $family->getFacts(array("HUSB", "WIFE", "CHIL"));
        } else {
            $subrecords = array();
        }
        $famfacts = array();
        foreach ($subrecords as $ind => $eventObj) {
            $fact = $eventObj->getTag();
            $event = $eventObj->getDetail();
            if ($fact == "EVEN" || $fact == "FACT") {
                $fact = $eventObj->getValue("TYPE");
            }
Esempio n. 10
0
 function init()
 {
     global $Dbwidth, $bwidth, $pbwidth, $pbheight, $bheight, $GEDCOM, $pgv_lang, $CONTACT_EMAIL, $show_famlink, $pgv_changes;
     $bwidth = $Dbwidth;
     $pbwidth = $bwidth + 12;
     $pbheight = $bheight + 14;
     $show_famlink = $this->view != 'preview';
     $this->famid = safe_GET_xref('famid');
     $this->family = Family::getInstance($this->famid);
     if (empty($this->famrec)) {
         $ct = preg_match("/(\\w+):(.+)/", $this->famid, $match);
         if ($ct > 0) {
             $servid = trim($match[1]);
             $remoteid = trim($match[2]);
             include_once 'includes/classes/class_serviceclient.php';
             $service = ServiceClient::getInstance($servid);
             if (!is_null($service)) {
                 $newrec = $service->mergeGedcomRecord($remoteid, "0 @" . $this->famid . "@ FAM\n1 RFN " . $this->famid, false);
                 $this->famrec = $newrec;
             }
         }
         //-- if no record was found create a default empty one
         if (isset($pgv_changes[$this->famid . "_" . $GEDCOM])) {
             $this->famrec = "0 @" . $this->famid . "@ FAM\n";
             $this->family = new Family($this->famrec);
         } else {
             if (empty($this->family)) {
                 return false;
             }
         }
     }
     $this->famrec = $this->family->getGedcomRecord();
     $this->display = displayDetailsById($this->famid, 'FAM');
     //-- if the user can edit and there are changes then get the new changes
     if ($this->show_changes && PGV_USER_CAN_EDIT && isset($pgv_changes[$this->famid . "_" . $GEDCOM])) {
         $newrec = find_updated_record($this->famid);
         if (empty($newrec)) {
             $newrec = find_family_record($this->famid);
         }
         $this->difffam = new Family($newrec);
         $this->difffam->setChanged(true);
         $this->family->diffMerge($this->difffam);
         //$this->famrec = $newrec;
         //$this->family = new Family($this->famrec);
     }
     $this->parents = array('HUSB' => $this->family->getHusbId(), 'WIFE' => $this->family->getWifeId());
     //-- check if we can display both parents
     if ($this->display == false) {
         $this->showLivingHusb = showLivingNameById($this->parents['HUSB']);
         $this->showLivingWife = showLivingNameById($this->parents['WIFE']);
     }
     //-- add favorites action
     if ($this->action == 'addfav' && !empty($_REQUEST['gid']) && PGV_USER_NAME) {
         $_REQUEST['gid'] = strtoupper($_REQUEST['gid']);
         $indirec = find_family_record($_REQUEST['gid']);
         if ($indirec) {
             $favorite = array('username' => PGV_USER_NAME, 'gid' => $_REQUEST['gid'], 'type' => 'FAM', 'file' => $GEDCOM, 'url' => '', 'note' => '', 'title' => '');
             addFavorite($favorite);
         }
     }
     if (PGV_USER_CAN_ACCEPT) {
         if ($this->action == 'accept') {
             if (accept_changes($_REQUEST['famid'] . '_' . $GEDCOM)) {
                 $this->show_changes = false;
                 $this->accept_success = true;
                 //-- check if we just deleted the record and redirect to index
                 $famrec = find_family_record($_REQUEST['famid']);
                 if (empty($famrec)) {
                     header("Location: index.php?ctype=gedcom");
                     exit;
                 }
                 $this->family = new Family($famrec);
                 $this->parents = find_parents($_REQUEST['famid']);
             }
         }
         if ($this->action == 'undo') {
             $this->family->undoChange();
             $this->parents = find_parents($_REQUEST['famid']);
         }
     }
     //-- make sure we have the true id from the record
     $ct = preg_match("/0 @(.*)@/", $this->famrec, $match);
     if ($ct > 0) {
         $this->famid = trim($match[1]);
     }
     if ($this->showLivingHusb == false && $this->showLivingWife == false) {
         print_header($pgv_lang['private'] . " " . $pgv_lang['family_info']);
         print_privacy_error($CONTACT_EMAIL);
         print_footer();
         exit;
     }
     $this->title = $this->family->getFullName();
     if (empty($this->parents['HUSB']) || empty($this->parents['WIFE'])) {
         $this->link_relation = 0;
     } else {
         $this->link_relation = 1;
     }
 }
Esempio n. 11
0
}
//-- setup the arrays
$newvars = array();
foreach ($vars as $name => $var) {
    $var = clean_input($var);
    $newvars[$name]["id"] = $var;
    if (!empty($type[$name]) && ($type[$name] == "INDI" || $type[$name] == "FAM" || $type[$name] == "SOUR")) {
        $gedcom = find_gedcom_record($var);
        if (empty($gedcom)) {
            $action = "setup";
        }
        if ($type[$name] == "FAM") {
            if (preg_match("/0 @.*@ INDI/", $gedcom) > 0) {
                $fams = find_sfamily_ids($var);
                if (!empty($fams[0])) {
                    $gedcom = find_family_record($fams[0]);
                    if (!empty($gedcom)) {
                        $vars[$name] = $fams[0];
                    } else {
                        $action = "setup";
                    }
                }
            }
        }
        $newvars[$name]["gedcom"] = $gedcom;
    }
}
$vars = $newvars;
foreach ($varnames as $indexval => $name) {
    if (!isset($vars[$name])) {
        $vars[$name]["id"] = "";
Esempio n. 12
0
 /**
  * Creates the lds_ord element and appends the correct information depending
  * on the type of lds_ord (Endowment, Sealing, Baptism). If there is a sealing,
  * the function will search if the family is in the clippings cart and if the
  * family is created or not. If the family is not created yet, it will be created
  * and added to the DOMDocument
  *
  * @param $indirec - The full INDI GEDCOM record of the person the lds_ord is being created
  * @param $eventName - the name of the LDS event (Baptism, Sealing, Endowment, etc...)
  * @param $eventABV - the event abbreviation in the GEDCOM (ie. SLGC, BAPL, ENDL)
  * @param $eParent - The parent element the lds event is attached to
  */
 function create_lds_event($indirec, $eventName, $eventABV, $eParent)
 {
     global $ePerson, $TEMPLE_CODES, $clipping;
     require_once "includes/classes/class_person.php";
     if (($hasldsevent = get_sub_record(1, "1 " . $eventABV, $indirec)) != null) {
         // Create <lds_ord> and attaches the type attribute
         $eLdsEvent = $this->dom->createElement("lds_ord");
         $eLdsEvent->setAttribute("type", $eventName);
         if (($dateRec = get_sub_record(1, "2 DATE", $hasldsevent)) != null) {
             $this->create_date($eLdsEvent, $dateRec, 2);
         }
         // Create <temple>, this element is common with all lds ords
         if (($temple = get_gedcom_value($eventABV . ":TEMP", 1, $indirec)) != null) {
             $eTemple = $this->dom->createElement("temple");
             $eTemple->setAttribute("val", $temple);
             $eTemple = $eLdsEvent->appendChild($eTemple);
         }
         if (($place = get_gedcom_value($eventABV . ":PLAC", 1, $indirec)) != null) {
             $hlink = $this->query_dom("./places/placeobj[@title=\"{$place}\"]/@handle");
             if ($hlink == null) {
                 $hlink = $this->generateHandle();
                 $this->create_placeobj($place, $hlink);
                 $this->create_place($eLdsEvent, $hlink);
             } else {
                 $this->create_place($eLdsEvent, $hlink);
             }
         }
         // Check to see if the STAT of the ordinance is set and add it to the
         // <lds_ord> element
         if (($stat = get_gedcom_value($eventABV . ":STAT", 1, $indirec)) != null) {
             $eStatus = $this->dom->createElement("status");
             $stat = get_gedcom_value($eventABV . ":STAT", 1, $indirec);
             $eStatus->setAttribute("val", isset($stat));
             $eStatus = $eLdsEvent->appendChild($eStatus);
         }
         // If the event is a sealing
         if ($eventABV == "SLGC") {
             // Create an instance of person and look for their family record
             $person = Person::getInstance($clipping["id"]);
             $famId = $person->getChildFamilyIds();
             $famrec = find_family_record($famId[0]);
             $fid = $famId[0];
             $handle = $this->query_dom("./families/family[@id=\"{$fid}\"]/@handle");
             if ($handle == null && id_in_cart($fid)) {
                 /*
                  * If the family does not exist and their ID is in the clippings cart,
                  * you must create the family before you can query them in the dom to get
                  * their hlink. The hlink is generated when the person element is created.
                  * This causes overhead creating objects that are never added to the XML file
                  * perhaps there is some other way this can be done reducing the overhead?
                  *
                  */
                 $this->create_family($famrec, $famId[0]);
                 $handle = $this->query_dom("./families/family[@id=\"{$fid}\"]/@handle");
                 $eFam = $this->dom->createElement("sealed_to");
                 $eFam->setAttribute("hlink", $handle);
                 $eFam = $eLdsEvent->appendChild($eFam);
                 $person = null;
             } else {
                 if ($handle != null && id_in_cart($fid)) {
                     $eFam = $this->dom->createElement("sealed_to");
                     $eFam->setAttribute("hlink", $handle);
                     $eFam = $eLdsEvent->appendChild($eFam);
                     $person = null;
                 }
             }
         }
         if (($note = get_sub_record(1, "2 NOTE", $hasldsevent)) != null) {
             $this->create_note($eLdsEvent, $note, 2);
         }
         $num = 1;
         while (($sourcerefRec = get_sub_record(2, "2 SOUR", $hasldsevent, $num)) != null) {
             $this->create_sourceref($eLdsEvent, $sourcerefRec, 2);
             $num++;
         }
         $eLdsEvent = $eParent->appendChild($eLdsEvent);
     }
 }
Esempio n. 13
0
        ?>
<div id="tab<?php 
        echo $i;
        ?>
" style="display: none;">
<table class="<?php 
        echo $TEXT_DIRECTION;
        ?>
 width80">
<?php 
        $famreqdfacts = preg_split("/[,; ]/", $QUICK_REQUIRED_FAMFACTS);
        $parents = find_parents($cfams[$j - 1]);
        $famid = $cfams[$j - 1];
        $family = Family::getInstance($famid);
        if (!isset($pgv_changes[$famid . "_" . $GEDCOM])) {
            $famrec = find_family_record($famid);
        } else {
            $famrec = find_updated_record($famid);
        }
        if ($family) {
            $subrecords = $family->getFacts(array("HUSB", "WIFE", "CHIL"));
        } else {
            $subrecords = array();
        }
        $famfacts = array();
        foreach ($subrecords as $ind => $eventObj) {
            $fact = $eventObj->getTag();
            $event = $eventObj->getDetail();
            if ($fact == "EVEN" || $fact == "FACT") {
                $fact = $eventObj->getValue("TYPE");
            }
Esempio n. 14
0
 /**
  * Compairs familys and then returns true if the have 50% or more chance of being the same family.
  * Other wise it returns false.
  */
 function CompairForUpdateFamily($family1, $family2)
 {
     // Values used to calculate the Percent of likley hood that the family is the same.
     $ChanceSameFamily = 0.0;
     $CountFamily1 = 0.0;
     $CountFamily2 = 0.0;
     $ChanceSame = 0.0;
     $firstTimeChildren = true;
     $famrec1 = find_family_record($family1);
     $ct = preg_match("/(\\w+):(.+)/", $family2, $match);
     if ($ct > 0) {
         $servid = trim($match[1]);
         $remoteid = trim($match[2]);
         $famrec2 = $this->getRemoteRecord($remoteid);
     } else {
         return false;
     }
     $family1 = Family::getInstance($family1);
     if (is_null($family1)) {
         return false;
     }
     $family2 = new Family($famrec2);
     if (!is_null($family1)) {
         // Creat the fathers if their is some
         $father1 = $family1->getHusband();
         $CountFamily1 += 1.0;
         $mother1 = $family1->getWife();
         $CountFamily1 += 1.0;
     }
     $father2 = $family2->getHusband();
     $CountFamily2 += 1.0;
     if (empty($father1)) {
         unset($father1);
         $CountFamily1 -= 1.0;
     }
     if (empty($father2)) {
         unset($father2);
         $CountFamily2 -= 1.0;
     }
     // Creat the mothers if their is some
     $mother2 = $family2->getWife();
     $CountFamily2 += 1.0;
     if (empty($mother1)) {
         unset($mother1);
         $CountFamily1 -= 1.0;
     }
     if (empty($mother2)) {
         unset($mother2);
         $CountFamily2 -= 1.0;
     }
     // Creat an array of Children
     $children1 = $family1->getChildren();
     $children2 = $family2->getChildren();
     // finds the probablity that they are the same family Bassed of both sites information
     $CountFamily1 += count($children1);
     $CountFamily2 += count($children2);
     foreach ($children1 as $childID1 => $Person1) {
         if (!empty($Person1)) {
             foreach ($children2 as $childID2 => $Person2) {
                 if (!empty($Person2)) {
                     if ($this->ComparePeople($Person1, $Person2)) {
                         $ChanceSameFamily += 1.0;
                         //print "<br />".$Person1->getXref()." equals ".$Person2->getXref();
                         break;
                     }
                 }
             }
         }
     }
     if (empty($father1)) {
     } elseif (empty($father2)) {
     } else {
         if ($this->ComparePeople($father1, $father2)) {
             $ChanceSameFamily += 1.0;
         }
     }
     if (empty($mother1)) {
     } elseif (empty($mother2)) {
     } else {
         if ($this->ComparePeople($mother1, $mother2)) {
             $ChanceSameFamily += 1.0;
         }
     }
     if ($CountFamily1 != 0 && $CountFamily2 != 0) {
         $ChanceSame = ($ChanceSameFamily / $CountFamily1 + $ChanceSameFamily / $CountFamily2) / 2;
         //print "<br />chancesame=".$ChanceSameFamily." count1=".$CountFamily1." count2=".$CountFamily2." ".$family1->getXref()." compared to ".$family2->getXref()." is ".$ChanceSame;
     } else {
         return false;
     }
     if ($ChanceSame < 0.5) {
         // If the probabilty is less then 0.5 or 50% then the current family is stored here to be added later
         return false;
     } else {
         return true;
     }
 }
Esempio n. 15
0
 /**
  * add events where pid is an ASSOciate
  *
  * @return records added to indifacts array
  *
  */
 function add_asso_facts()
 {
     global $factarray, $pgv_lang;
     $associates = array_merge(fetch_linked_indi($this->getXref(), 'ASSO', $this->ged_id), fetch_linked_fam($this->getXref(), 'ASSO', $this->ged_id));
     foreach ($associates as $associate) {
         foreach ($associate->getFacts() as $event) {
             $srec = $event->getGedcomRecord();
             $arec = get_sub_record(2, "2 ASSO @" . $this->getXref() . "@", $srec);
             if ($arec) {
                 $fact = $event->getTag();
                 $label = $event->getLabel();
                 $sdate = get_sub_record(2, "2 DATE", $srec);
                 // relationship ?
                 $rrec = get_sub_record(3, "3 RELA", $arec);
                 $rela = trim(substr($rrec, 7));
                 if (empty($rela)) {
                     $rela = "ASSO";
                 }
                 // add an event record
                 $factrec = "1 EVEN\n2 TYPE " . $label . "<br/>[ <span class=\"details_label\">";
                 if (isset($pgv_lang[strtolower($rela)])) {
                     $factrec .= $pgv_lang[strtolower($rela)] . "</span> ]";
                 } else {
                     if (isset($factarray[$rela])) {
                         $factrec .= $factarray[$rela] . "</span> ]";
                     }
                 }
                 $factrec .= "\n" . $sdate . "\n" . get_sub_record(2, '2 PLAC', $srec);
                 if (!$event->canShow()) {
                     $factrec .= "\n2 RESN privacy";
                 }
                 if ($associate->getType() == 'FAM') {
                     $famrec = find_family_record($associate->getXref());
                     if ($famrec) {
                         $parents = find_parents_in_record($famrec);
                         if ($parents["HUSB"]) {
                             $factrec .= "\n2 ASSO @" . $parents["HUSB"] . "@";
                         }
                         //\n3 RELA ".$factarray[$fact];
                         if ($parents["WIFE"]) {
                             $factrec .= "\n2 ASSO @" . $parents["WIFE"] . "@";
                         }
                         //\n3 RELA ".$factarray[$fact];
                     }
                 } else {
                     if ($fact == 'BIRT') {
                         $sex = $associate->getSex();
                         if ($sex == "M") {
                             $rela_b = "twin_brother";
                         } else {
                             if ($sex == "F") {
                                 $rela_b = "twin_sister";
                             } else {
                                 $rela_b = "twin";
                             }
                         }
                         $factrec .= "\n2 ASSO @" . $associate->getXref() . "@\n3 RELA " . $rela_b;
                     } else {
                         if ($fact == 'CHR') {
                             $sex = $associate->getSex();
                             if ($sex == "M") {
                                 $rela_chr = "godson";
                             } else {
                                 if ($sex == "F") {
                                     $rela_chr = "goddaughter";
                                 } else {
                                     $rela_chr = "godchild";
                                 }
                             }
                             $factrec .= "\n2 ASSO @" . $associate->getXref() . "@\n3 RELA " . $rela_chr;
                         } else {
                             $factrec .= "\n2 ASSO @" . $associate->getXref() . "@\n3 RELA " . $fact;
                         }
                     }
                 }
                 //$factrec .= "\n3 NOTE ".$rela;
                 $factrec .= "\n2 ASSO @" . $this->getXref() . "@\n3 RELA *" . $rela;
                 // check if this fact already exists in the list
                 $found = false;
                 if ($sdate) {
                     foreach ($this->indifacts as $k => $v) {
                         if (strpos($v->getGedcomRecord(), $sdate) && strpos($v->getGedcomRecord(), "2 ASSO @" . $this->getXref() . "@")) {
                             $found = true;
                             break;
                         }
                     }
                 }
                 if (!$found) {
                     $this->indifacts[] = new Event($factrec, 0);
                 }
             }
         }
     }
 }