Example #1
0
/**
 * is the person alive in the given year
 * @param string $indirec	the persons raw gedcom record
 * @param int $year			the year to check if they are alive in
 * @return int			return 0 if the person is alive, negative number if they died earlier, positive number if they will be born in the future
 */
function check_alive($indirec, $year)
{
    global $MAX_ALIVE_AGE;
    if (is_dead($indirec, $year)) {
        return -1;
    }
    // Died before year?
    $deathrec = get_sub_record(1, "1 DEAT", $indirec);
    if (preg_match("/\\d DATE (.*)/", $deathrec, $match)) {
        $ddate = new GedcomDate($match[1]);
        $dyear = $ddate->gregorianYear();
        if ($year > $dyear) {
            return -1;
        }
    }
    // Born after year?
    $birthrec = get_sub_record(1, "1 BIRT", $indirec);
    if (preg_match("/\\d DATE (.*)/", $birthrec, $match)) {
        $bdate = new GedcomDate($match[1]);
        $byear = $bdate->gregorianYear();
        if ($year < $byear) {
            return 1;
        }
    }
    // Born before year and died after year
    if (isset($byear) && isset($dyear) && $year >= $byear && $year <= $dyear) {
        return 0;
    }
    // If no death record than check all dates;
    $years = array();
    $subrecs = get_all_subrecords($indirec, "CHAN", true, true, false);
    foreach ($subrecs as $ind => $subrec) {
        if (preg_match("/\\d DATE (.*)/", $subrec, $match)) {
            $date = new GedcomDate($match[1]);
            $datey = $date->gregorianYear();
            if ($datey) {
                $years[] = $datey;
            }
        }
    }
    // Events both before and after year
    if (count($years) > 1 && $year >= $years[0] && $year <= $years[count($years) - 1]) {
        return 0;
    }
    foreach ($years as $ind => $year1) {
        if ($year1 - $year > $MAX_ALIVE_AGE) {
            return -1;
        }
    }
    return 0;
}
Example #2
0
function get_first_tag($level, $tag, $gedrec, $num = 1)
{
    $temp = get_sub_record($level, $level . " " . $tag, $gedrec, $num) . "\n";
    $length = strpos($temp, "\n");
    if ($length === false) {
        $length = strlen($temp);
    }
    return substr($temp, 2, $length - 2);
}
Example #3
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;
}
Example #4
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);
}
Example #5
0
/**
 * print fact PLACe TEMPle STATus
 *
 * @param WT_Fact $event       gedcom fact record
 * @param bool    $anchor      to print a link to placelist
 * @param bool    $sub_records to print place subrecords
 * @param bool    $lds         to print LDS TEMPle and STATus
 *
 * @return string HTML
 */
function format_fact_place(WT_Fact $event, $anchor = false, $sub_records = false, $lds = false)
{
    global $SEARCH_SPIDER;
    if ($anchor) {
        // Show the full place name, for facts/events tab
        if ($SEARCH_SPIDER) {
            $html = $event->getPlace()->getFullName();
        } else {
            $html = '<a href="' . $event->getPlace()->getURL() . '">' . $event->getPlace()->getFullName() . '</a>';
        }
    } else {
        // Abbreviate the place name, for chart boxes
        return ' - ' . $event->getPlace()->getShortName();
    }
    if ($sub_records) {
        $placerec = get_sub_record(2, '2 PLAC', $event->getGedcom());
        if (!empty($placerec)) {
            if (preg_match_all('/\\n3 (?:_HEB|ROMN) (.+)/', $placerec, $matches)) {
                foreach ($matches[1] as $match) {
                    $wt_place = new WT_Place($match, WT_GED_ID);
                    $html .= ' - ' . $wt_place->getFullName();
                }
            }
            $map_lati = "";
            $cts = preg_match('/\\d LATI (.*)/', $placerec, $match);
            if ($cts > 0) {
                $map_lati = $match[1];
                $html .= '<br><span class="label">' . WT_Gedcom_Tag::getLabel('LATI') . ': </span>' . $map_lati;
            }
            $map_long = '';
            $cts = preg_match('/\\d LONG (.*)/', $placerec, $match);
            if ($cts > 0) {
                $map_long = $match[1];
                $html .= ' <span class="label">' . WT_Gedcom_Tag::getLabel('LONG') . ': </span>' . $map_long;
            }
            if ($map_lati && $map_long) {
                $map_lati = trim(strtr($map_lati, "NSEW,�", " - -. "));
                // S5,6789 ==> -5.6789
                $map_long = trim(strtr($map_long, "NSEW,�", " - -. "));
                // E3.456� ==> 3.456
                $html .= ' <a rel="nofollow" href="https://maps.google.com/maps?q=' . $map_lati . ',' . $map_long . '" class="icon-googlemaps" title="' . WT_I18N::translate('Google Mapsâ„¢') . '"></a>';
                $html .= ' <a rel="nofollow" href="https://www.bing.com/maps/?lvl=15&cp=' . $map_lati . '~' . $map_long . '" class="icon-bing" title="' . WT_I18N::translate('Bing Mapsâ„¢') . '"></a>';
                $html .= ' <a rel="nofollow" href="https://www.openstreetmap.org/#map=15/' . $map_lati . '/' . $map_long . '" class="icon-osm" title="' . WT_I18N::translate('OpenStreetMapâ„¢') . '"></a>';
            }
            if (preg_match('/\\d NOTE (.*)/', $placerec, $match)) {
                $html .= '<br>' . print_fact_notes($placerec, 3);
            }
        }
    }
    if ($lds) {
        if (preg_match('/2 TEMP (.*)/', $event->getGedcom(), $match)) {
            $html .= '<br>' . WT_I18N::translate('LDS temple') . ': ' . WT_Gedcom_Code_Temp::templeName($match[1]);
        }
        if (preg_match('/2 STAT (.*)/', $event->getGedcom(), $match)) {
            $html .= '<br>' . WT_I18N::translate('Status') . ': ' . WT_Gedcom_Code_Stat::statusName($match[1]);
            if (preg_match('/3 DATE (.*)/', $event->getGedcom(), $match)) {
                $date = new WT_Date($match[1]);
                $html .= ', ' . WT_Gedcom_Tag::getLabel('STAT:DATE') . ': ' . $date->Display(false);
            }
        }
    }
    return $html;
}
Example #6
0
    private function adminPlaces()
    {
        require WT_ROOT . 'includes/functions/functions_edit.php';
        $action = WT_Filter::get('action');
        $parent = WT_Filter::get('parent');
        $inactive = WT_Filter::getBool('inactive');
        $deleteRecord = WT_Filter::get('deleteRecord');
        if (!isset($parent)) {
            $parent = 0;
        }
        $controller = new WT_Controller_Page();
        $controller->restrictAccess(Auth::isAdmin());
        if ($action == 'ExportFile' && Auth::isAdmin()) {
            Zend_Session::writeClose();
            $tmp = $this->placeIdToHierarchy($parent);
            $maxLevel = $this->getHighestLevel();
            if ($maxLevel > 8) {
                $maxLevel = 8;
            }
            $tmp[0] = 'places';
            $outputFileName = preg_replace('/[:;\\/\\\\(\\)\\{\\}\\[\\] $]/', '_', implode('-', $tmp)) . '.csv';
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename="' . $outputFileName . '"');
            echo '"', WT_I18N::translate('Level'), '";"', WT_I18N::translate('Country'), '";';
            if ($maxLevel > 0) {
                echo '"', WT_I18N::translate('State'), '";';
            }
            if ($maxLevel > 1) {
                echo '"', WT_I18N::translate('County'), '";';
            }
            if ($maxLevel > 2) {
                echo '"', WT_I18N::translate('City'), '";';
            }
            if ($maxLevel > 3) {
                echo '"', WT_I18N::translate('Place'), '";';
            }
            if ($maxLevel > 4) {
                echo '"', WT_I18N::translate('Place'), '";';
            }
            if ($maxLevel > 5) {
                echo '"', WT_I18N::translate('Place'), '";';
            }
            if ($maxLevel > 6) {
                echo '"', WT_I18N::translate('Place'), '";';
            }
            if ($maxLevel > 7) {
                echo '"', WT_I18N::translate('Place'), '";';
            }
            echo '"', WT_I18N::translate('Longitude'), '";"', WT_I18N::translate('Latitude'), '";';
            echo '"', WT_I18N::translate('Zoom level'), '";"', WT_I18N::translate('Icon'), '";', WT_EOL;
            $this->outputLevel($parent);
            exit;
        }
        $controller->setPageTitle(WT_I18N::translate('Google Mapsâ„¢'))->pageHeader();
        ?>
		<table id="gm_config">
			<tr>
				<th>
					<a href="module.php?mod=googlemap&amp;mod_action=admin_config">
						<?php 
        echo WT_I18N::translate('Google Mapsâ„¢ preferences');
        ?>
					</a>
				</th>
				<th>
					<a class="current" href="module.php?mod=googlemap&amp;mod_action=admin_places">
						<?php 
        echo WT_I18N::translate('Geographic data');
        ?>
					</a>
				</th>
				<th>
					<a href="module.php?mod=googlemap&amp;mod_action=admin_placecheck">
						<?php 
        echo WT_I18N::translate('Place check');
        ?>
					</a>
				</th>
			</tr>
		</table>
		<?php 
        if ($action == 'ImportGedcom') {
            $placelist = array();
            $j = 0;
            $gedcom_records = WT_DB::prepare("SELECT i_gedcom FROM `##individuals` WHERE i_file=? UNION ALL SELECT f_gedcom FROM `##families` WHERE f_file=?")->execute(array(WT_GED_ID, WT_GED_ID))->fetchOneColumn();
            foreach ($gedcom_records as $gedrec) {
                $i = 1;
                $placerec = get_sub_record(2, '2 PLAC', $gedrec, $i);
                while (!empty($placerec)) {
                    if (preg_match("/2 PLAC (.+)/", $placerec, $match)) {
                        $placelist[$j] = array();
                        $placelist[$j]['place'] = trim($match[1]);
                        if (preg_match("/4 LATI (.*)/", $placerec, $match)) {
                            $placelist[$j]['lati'] = trim($match[1]);
                            if ($placelist[$j]['lati'][0] != 'N' && $placelist[$j]['lati'][0] != 'S') {
                                if ($placelist[$j]['lati'] < 0) {
                                    $placelist[$j]['lati'][0] = 'S';
                                } else {
                                    $placelist[$j]['lati'] = 'N' . $placelist[$j]['lati'];
                                }
                            }
                        } else {
                            $placelist[$j]['lati'] = NULL;
                        }
                        if (preg_match("/4 LONG (.*)/", $placerec, $match)) {
                            $placelist[$j]['long'] = trim($match[1]);
                            if ($placelist[$j]['long'][0] != 'E' && $placelist[$j]['long'][0] != 'W') {
                                if ($placelist[$j]['long'] < 0) {
                                    $placelist[$j]['long'][0] = 'W';
                                } else {
                                    $placelist[$j]['long'] = 'E' . $placelist[$j]['long'];
                                }
                            }
                        } else {
                            $placelist[$j]['long'] = NULL;
                        }
                        $j = $j + 1;
                    }
                    $i = $i + 1;
                    $placerec = get_sub_record(2, '2 PLAC', $gedrec, $i);
                }
            }
            asort($placelist);
            $prevPlace = '';
            $prevLati = '';
            $prevLong = '';
            $placelistUniq = array();
            $j = 0;
            foreach ($placelist as $k => $place) {
                if ($place['place'] != $prevPlace) {
                    $placelistUniq[$j] = array();
                    $placelistUniq[$j]['place'] = $place['place'];
                    $placelistUniq[$j]['lati'] = $place['lati'];
                    $placelistUniq[$j]['long'] = $place['long'];
                    $j = $j + 1;
                } elseif ($place['place'] == $prevPlace && ($place['lati'] != $prevLati || $place['long'] != $prevLong)) {
                    if ($placelistUniq[$j - 1]['lati'] == 0 || $placelistUniq[$j - 1]['long'] == 0) {
                        $placelistUniq[$j - 1]['lati'] = $place['lati'];
                        $placelistUniq[$j - 1]['long'] = $place['long'];
                    } elseif ($place['lati'] != '0' || $place['long'] != '0') {
                        echo 'Difference: previous value = ', $prevPlace, ', ', $prevLati, ', ', $prevLong, ' current = ', $place['place'], ', ', $place['lati'], ', ', $place['long'], '<br>';
                    }
                }
                $prevPlace = $place['place'];
                $prevLati = $place['lati'];
                $prevLong = $place['long'];
            }
            $highestIndex = $this->getHighestIndex();
            $default_zoom_level = array(4, 7, 10, 12);
            foreach ($placelistUniq as $k => $place) {
                $parent = preg_split('/ *, */', $place['place']);
                $parent = array_reverse($parent);
                $parent_id = 0;
                for ($i = 0; $i < count($parent); $i++) {
                    if (!isset($default_zoom_level[$i])) {
                        $default_zoom_level[$i] = $default_zoom_level[$i - 1];
                    }
                    $escparent = $parent[$i];
                    if ($escparent == '') {
                        $escparent = 'Unknown';
                    }
                    $row = WT_DB::prepare("SELECT pl_id, pl_long, pl_lati, pl_zoom FROM `##placelocation` WHERE pl_level=? AND pl_parent_id=? AND pl_place LIKE ?")->execute(array($i, $parent_id, $escparent))->fetchOneRow();
                    if ($i < count($parent) - 1) {
                        // Create higher-level places, if necessary
                        if (empty($row)) {
                            $highestIndex++;
                            WT_DB::prepare("INSERT INTO `##placelocation` (pl_id, pl_parent_id, pl_level, pl_place, pl_zoom) VALUES (?, ?, ?, ?, ?)")->execute(array($highestIndex, $parent_id, $i, $escparent, $default_zoom_level[$i]));
                            echo WT_Filter::escapeHtml($escparent), '<br>';
                            $parent_id = $highestIndex;
                        } else {
                            $parent_id = $row->pl_id;
                        }
                    } else {
                        // Create lowest-level place, if necessary
                        if (empty($row->pl_id)) {
                            $highestIndex++;
                            WT_DB::prepare("INSERT INTO `##placelocation` (pl_id, pl_parent_id, pl_level, pl_place, pl_long, pl_lati, pl_zoom) VALUES (?, ?, ?, ?, ?, ?, ?)")->execute(array($highestIndex, $parent_id, $i, $escparent, $place['long'], $place['lati'], $default_zoom_level[$i]));
                            echo WT_Filter::escapeHtml($escparent), '<br>';
                        } else {
                            if (empty($row->pl_long) && empty($row->pl_lati) && $place['lati'] != '0' && $place['long'] != '0') {
                                WT_DB::prepare("UPDATE `##placelocation` SET pl_lati=?, pl_long=? WHERE pl_id=?")->execute(array($place['lati'], $place['long'], $row->pl_id));
                                echo WT_Filter::escapeHtml($escparent), '<br>';
                            }
                        }
                    }
                }
            }
            $parent = 0;
        }
        if ($action == 'ImportFile') {
            $placefiles = array();
            $this->findFiles(WT_MODULES_DIR . 'googlemap/extra');
            sort($placefiles);
            ?>
		<form method="post" enctype="multipart/form-data" id="importfile" name="importfile" action="module.php?mod=googlemap&amp;mod_action=admin_places&amp;action=ImportFile2">
			<table class="gm_plac_edit">
				<tr>
					<th><?php 
            echo WT_I18N::translate('File containing places (CSV)');
            ?>
</th>
					<td><input type="file" name="placesfile" size="50"></td>
				</tr>
				<?php 
            if (count($placefiles) > 0) {
                ?>
				<tr>
					<th><?php 
                echo WT_I18N::translate('Server file containing places (CSV)'), help_link('PLIF_LOCALFILE', 'googlemap');
                ?>
</th>
					<td>
						<select name="localfile">
							<option></option>
							<?php 
                foreach ($placefiles as $p => $placefile) {
                    ?>
							<option value="<?php 
                    echo WT_Filter::escapeHtml($placefile);
                    ?>
"><?php 
                    if (substr($placefile, 0, 1) == "/") {
                        echo substr($placefile, 1);
                    } else {
                        echo $placefile;
                    }
                    ?>
</option>
							<?php 
                }
                ?>
						</select>
					</td>
				</tr>
				<?php 
            }
            ?>
				<tr>
					<th><?php 
            echo WT_I18N::translate('Delete all existing geographic data before importing the file.');
            ?>
</th>
					<td><input type="checkbox" name="cleardatabase"></td>
				</tr>
				<tr>
					<th><?php 
            echo WT_I18N::translate('Do not create new locations, just import coordinates for existing locations.');
            ?>
</th>
					<td><input type="checkbox" name="updateonly"></td>
				</tr>
				<tr>
					<th><?php 
            echo WT_I18N::translate('Overwrite existing coordinates.');
            ?>
</th>
					<td><input type="checkbox" name="overwritedata"></td>
				</tr>
			</table>
			<input id="savebutton" type="submit" value="<?php 
            echo WT_I18N::translate('Continue adding');
            ?>
"><br>
		</form>
		<?php 
            exit;
        }
        if ($action == 'ImportFile2') {
            $country_names = array();
            foreach (WT_Stats::iso3166() as $key => $value) {
                $country_names[$key] = WT_I18N::translate($key);
            }
            if (isset($_POST['cleardatabase'])) {
                WT_DB::exec("DELETE FROM `##placelocation` WHERE 1=1");
            }
            if (!empty($_FILES['placesfile']['tmp_name'])) {
                $lines = file($_FILES['placesfile']['tmp_name']);
            } elseif (!empty($_REQUEST['localfile'])) {
                $lines = file(WT_MODULES_DIR . 'googlemap/extra' . $_REQUEST['localfile']);
            }
            // Strip BYTE-ORDER-MARK, if present
            if (!empty($lines[0]) && substr($lines[0], 0, 3) == WT_UTF8_BOM) {
                $lines[0] = substr($lines[0], 3);
            }
            asort($lines);
            $highestIndex = $this->getHighestIndex();
            $placelist = array();
            $j = 0;
            $maxLevel = 0;
            foreach ($lines as $p => $placerec) {
                $fieldrec = explode(';', $placerec);
                if ($fieldrec[0] > $maxLevel) {
                    $maxLevel = $fieldrec[0];
                }
            }
            $fields = count($fieldrec);
            $set_icon = true;
            if (!is_dir(WT_MODULES_DIR . 'googlemap/places/flags/')) {
                $set_icon = false;
            }
            foreach ($lines as $p => $placerec) {
                $fieldrec = explode(';', $placerec);
                if (is_numeric($fieldrec[0]) && $fieldrec[0] <= $maxLevel) {
                    $placelist[$j] = array();
                    $placelist[$j]['place'] = '';
                    for ($ii = $fields - 4; $ii > 1; $ii--) {
                        if ($fieldrec[0] > $ii - 2) {
                            $placelist[$j]['place'] .= $fieldrec[$ii] . ',';
                        }
                    }
                    foreach ($country_names as $countrycode => $countryname) {
                        if ($countrycode == strtoupper($fieldrec[1])) {
                            $fieldrec[1] = $countryname;
                            break;
                        }
                    }
                    $placelist[$j]['place'] .= $fieldrec[1];
                    $placelist[$j]['long'] = $fieldrec[$fields - 4];
                    $placelist[$j]['lati'] = $fieldrec[$fields - 3];
                    $placelist[$j]['zoom'] = $fieldrec[$fields - 2];
                    if ($set_icon) {
                        $placelist[$j]['icon'] = trim($fieldrec[$fields - 1]);
                    } else {
                        $placelist[$j]['icon'] = '';
                    }
                    $j = $j + 1;
                }
            }
            $prevPlace = '';
            $prevLati = '';
            $prevLong = '';
            $placelistUniq = array();
            $j = 0;
            foreach ($placelist as $k => $place) {
                if ($place['place'] != $prevPlace) {
                    $placelistUniq[$j] = array();
                    $placelistUniq[$j]['place'] = $place['place'];
                    $placelistUniq[$j]['lati'] = $place['lati'];
                    $placelistUniq[$j]['long'] = $place['long'];
                    $placelistUniq[$j]['zoom'] = $place['zoom'];
                    $placelistUniq[$j]['icon'] = $place['icon'];
                    $j = $j + 1;
                } elseif ($place['place'] == $prevPlace && ($place['lati'] != $prevLati || $place['long'] != $prevLong)) {
                    if ($placelistUniq[$j - 1]['lati'] == 0 || $placelistUniq[$j - 1]['long'] == 0) {
                        $placelistUniq[$j - 1]['lati'] = $place['lati'];
                        $placelistUniq[$j - 1]['long'] = $place['long'];
                        $placelistUniq[$j - 1]['zoom'] = $place['zoom'];
                        $placelistUniq[$j - 1]['icon'] = $place['icon'];
                    } elseif ($place['lati'] != '0' || $place['long'] != '0') {
                        echo 'Difference: previous value = ', $prevPlace, ', ', $prevLati, ', ', $prevLong, ' current = ', $place['place'], ', ', $place['lati'], ', ', $place['long'], '<br>';
                    }
                }
                $prevPlace = $place['place'];
                $prevLati = $place['lati'];
                $prevLong = $place['long'];
            }
            $default_zoom_level = array();
            $default_zoom_level[0] = 4;
            $default_zoom_level[1] = 7;
            $default_zoom_level[2] = 10;
            $default_zoom_level[3] = 12;
            foreach ($placelistUniq as $k => $place) {
                $parent = explode(',', $place['place']);
                $parent = array_reverse($parent);
                $parent_id = 0;
                for ($i = 0; $i < count($parent); $i++) {
                    $escparent = $parent[$i];
                    if ($escparent == '') {
                        $escparent = 'Unknown';
                    }
                    $row = WT_DB::prepare("SELECT pl_id, pl_long, pl_lati, pl_zoom, pl_icon FROM `##placelocation` WHERE pl_level=? AND pl_parent_id=? AND pl_place LIKE ? ORDER BY pl_place")->execute(array($i, $parent_id, $escparent))->fetchOneRow();
                    if (empty($row)) {
                        // this name does not yet exist: create entry
                        if (!isset($_POST['updateonly'])) {
                            $highestIndex = $highestIndex + 1;
                            if ($i + 1 == count($parent)) {
                                $zoomlevel = $place['zoom'];
                            } elseif (isset($default_zoom_level[$i])) {
                                $zoomlevel = $default_zoom_level[$i];
                            } else {
                                $zoomlevel = $this->getSetting('GM_MAX_ZOOM');
                            }
                            if ($place['lati'] == '0' || $place['long'] == '0' || $i + 1 < count($parent)) {
                                WT_DB::prepare("INSERT INTO `##placelocation` (pl_id, pl_parent_id, pl_level, pl_place, pl_zoom, pl_icon) VALUES (?, ?, ?, ?, ?, ?)")->execute(array($highestIndex, $parent_id, $i, $escparent, $zoomlevel, $place['icon']));
                            } else {
                                //delete leading zero
                                $pl_lati = str_replace(array('N', 'S', ','), array('', '-', '.'), $place['lati']);
                                $pl_long = str_replace(array('E', 'W', ','), array('', '-', '.'), $place['long']);
                                if ($pl_lati >= 0) {
                                    $place['lati'] = 'N' . abs($pl_lati);
                                } elseif ($pl_lati < 0) {
                                    $place['lati'] = 'S' . abs($pl_lati);
                                }
                                if ($pl_long >= 0) {
                                    $place['long'] = 'E' . abs($pl_long);
                                } elseif ($pl_long < 0) {
                                    $place['long'] = 'W' . abs($pl_long);
                                }
                                WT_DB::prepare("INSERT INTO `##placelocation` (pl_id, pl_parent_id, pl_level, pl_place, pl_long, pl_lati, pl_zoom, pl_icon) VALUES (?, ?, ?, ?, ?, ?, ?, ?)")->execute(array($highestIndex, $parent_id, $i, $escparent, $place['long'], $place['lati'], $zoomlevel, $place['icon']));
                            }
                            $parent_id = $highestIndex;
                        }
                    } else {
                        $parent_id = $row->pl_id;
                        if (isset($_POST['overwritedata']) && $i + 1 == count($parent)) {
                            WT_DB::prepare("UPDATE `##placelocation` SET pl_lati=?, pl_long=?, pl_zoom=?, pl_icon=? WHERE pl_id=?")->execute(array($place['lati'], $place['long'], $place['zoom'], $place['icon'], $parent_id));
                        } else {
                            if (($row->pl_long == '0' || $row->pl_long == null) && ($row->pl_lati == '0' || $row->pl_lati == null)) {
                                WT_DB::prepare("UPDATE `##placelocation` SET pl_lati=?, pl_long=? WHERE pl_id=?")->execute(array($place['lati'], $place['long'], $parent_id));
                            }
                            if (empty($row->pl_icon) && !empty($place['icon'])) {
                                WT_DB::prepare("UPDATE `##placelocation` SET pl_icon=? WHERE pl_id=?")->execute(array($place['icon'], $parent_id));
                            }
                        }
                    }
                }
            }
            $parent = 0;
        }
        if ($action == 'DeleteRecord') {
            $exists = WT_DB::prepare("SELECT 1 FROM `##placelocation` WHERE pl_parent_id=?")->execute(array($deleteRecord))->fetchOne();
            if (!$exists) {
                WT_DB::prepare("DELETE FROM `##placelocation` WHERE pl_id=?")->execute(array($deleteRecord));
            } else {
                echo '<table class="facts_table"><tr><td>', WT_I18N::translate('Location not removed: this location contains sub-locations'), '</td></tr></table>';
            }
        }
        ?>
		<script>
		function updateList(inactive) {
			window.location.href='<?php 
        if (strstr($_SERVER['REQUEST_URI'], '&inactive', true)) {
            $uri = strstr($_SERVER['REQUEST_URI'], '&inactive', true);
        } else {
            $uri = $_SERVER['REQUEST_URI'];
        }
        echo $uri, '&inactive=';
        ?>
'+inactive;
		}

		function edit_place_location(placeid) {
			window.open('module.php?mod=googlemap&mod_action=places_edit&action=update&placeid='+placeid, '_blank', gmap_window_specs);
			return false;
		}

		function add_place_location(placeid) {
			window.open('module.php?mod=googlemap&mod_action=places_edit&action=add&placeid='+placeid, '_blank', gmap_window_specs);
			return false;
		}

		function delete_place(placeid) {
			var answer=confirm('<?php 
        echo WT_I18N::translate('Remove this location?');
        ?>
');
			if (answer == true) {
				window.location = '<?php 
        echo $_SERVER['REQUEST_URI'];
        ?>
&action=DeleteRecord&deleteRecord=' + placeid;
			}
		}
		</script>
		<?php 
        echo '<div id="gm_breadcrumb">';
        $where_am_i = $this->placeIdToHierarchy($parent);
        foreach (array_reverse($where_am_i, true) as $id => $place) {
            if ($id == $parent) {
                if ($place != 'Unknown') {
                    echo WT_Filter::escapeHtml($place);
                } else {
                    echo WT_I18N::translate('unknown');
                }
            } else {
                echo '<a href="module.php?mod=googlemap&mod_action=admin_places&parent=', $id, '&inactive=', $inactive, '">';
                if ($place != 'Unknown') {
                    echo WT_Filter::escapeHtml($place), '</a>';
                } else {
                    echo WT_I18N::translate('unknown'), '</a>';
                }
            }
            echo ' - ';
        }
        echo '<a href="module.php?mod=googlemap&mod_action=admin_places&parent=0&inactive=', $inactive, '">', WT_I18N::translate('Top level'), '</a></div>';
        echo '<form name="active" method="post" action="module.php?mod=googlemap&mod_action=admin_places&parent=', $parent, '&inactive=', $inactive, '"><div id="gm_active">';
        echo '<label for="inactive">', WT_I18N::translate('Show inactive places'), '</label>';
        echo '<input type="checkbox" name="inactive" id="inactive"';
        if ($inactive) {
            echo ' checked="checked"';
        }
        echo ' onclick="updateList(this.checked)"';
        echo '>', help_link('PLE_ACTIVE', 'googlemap'), '</div></form>';
        $placelist = $this->getPlaceListLocation($parent, $inactive);
        echo '<div class="gm_plac_edit">';
        echo '<table class="gm_plac_edit"><tr>';
        echo '<th>', WT_Gedcom_Tag::getLabel('PLAC'), '</th>';
        echo '<th>', WT_Gedcom_Tag::getLabel('LATI'), '</th>';
        echo '<th>', WT_Gedcom_Tag::getLabel('LONG'), '</th>';
        echo '<th>', WT_I18N::translate('Zoom level'), '</th>';
        echo '<th>', WT_I18N::translate('Icon'), '</th>';
        echo '<th>';
        echo WT_I18N::translate('Edit'), '</th><th>', WT_I18N::translate('Delete'), '</th></tr>';
        if (count($placelist) == 0) {
            echo '<tr><td colspan="7" class="accepted">', WT_I18N::translate('No places found'), '</td></tr>';
        }
        foreach ($placelist as $place) {
            echo '<tr><td><a href="module.php?mod=googlemap&mod_action=admin_places&parent=', $place['place_id'], '&inactive=', $inactive, '">';
            if ($place['place'] != 'Unknown') {
                echo WT_Filter::escapeHtml($place['place']), '</a></td>';
            } else {
                echo WT_I18N::translate('unknown'), '</a></td>';
            }
            echo '<td>', $place['lati'], '</td>';
            echo '<td>', $place['long'], '</td>';
            echo '<td>', $place['zoom'], '</td>';
            echo '<td>';
            if ($place['icon'] == NULL || $place['icon'] == '') {
                if ($place['lati'] == NULL || $place['long'] == NULL || $place['lati'] == '0' && $place['long'] == '0') {
                    echo '<img src="', WT_STATIC_URL, WT_MODULES_DIR, 'googlemap/images/mm_20_yellow.png">';
                } else {
                    echo '<img src="', WT_STATIC_URL, WT_MODULES_DIR, 'googlemap/images/mm_20_red.png">';
                }
            } else {
                echo '<img src="', WT_STATIC_URL, WT_MODULES_DIR, 'googlemap/', $place['icon'], '" width="25" height="15">';
            }
            echo '</td>';
            echo '<td class="narrow"><a href="#" onclick="edit_place_location(', $place['place_id'], ');return false;" class="icon-edit" title="', WT_I18N::translate('Edit'), '"></a></td>';
            $noRows = WT_DB::prepare("SELECT COUNT(pl_id) FROM `##placelocation` WHERE pl_parent_id=?")->execute(array($place['place_id']))->fetchOne();
            if ($noRows == 0) {
                ?>
				<td><a href="#" onclick="delete_place(<?php 
                echo $place['place_id'];
                ?>
);return false;" class="icon-delete" title="<?php 
                echo WT_I18N::translate('Remove');
                ?>
"></a></td>
		<?php 
            } else {
                ?>
				<td><i class="icon-delete-grey"></i></td>
		<?php 
            }
            ?>
			</tr>
			<?php 
        }
        ?>
		</table>
		</div>

		<table id="gm_manage">
			<tr>
				<td>
					<?php 
        echo WT_I18N::translate('Add  a new geographic location');
        ?>
				</td>
				<td>
					<form action="?" onsubmit="add_place_location(this.parent_id.options[this.parent_id.selectedIndex].value); return false;">
						<?php 
        echo select_edit_control('parent_id', $where_am_i, WT_I18N::translate('Top level'), $parent);
        ?>
						<input type="submit" value="<?php 
        echo WT_I18N::translate('Add');
        ?>
">
					</form>
				</td>
			</tr>
			<tr>
				<td>
					<?php 
        echo WT_I18N::translate('Import all places from a family tree');
        ?>
				</td>
				<td>
					<form action="module.php" method="get">
						<input type="hidden" name="mod" value="googlemap">
						<input type="hidden" name="mod_action" value="admin_places">
						<input type="hidden" name="action" value="ImportGedcom">
						<?php 
        echo select_edit_control('ged', WT_Tree::getNameList(), null, WT_GEDCOM);
        ?>
						<input type="submit" value="<?php 
        echo WT_I18N::translate('Import');
        ?>
">
					</form>
				</td>
			</tr>
			<tr>
				<td>
					<?php 
        echo WT_I18N::translate('Upload geographic data');
        ?>
				</td>
				<td>
					<form action="module.php" method="get">
						<input type="hidden" name="mod" value="googlemap">
						<input type="hidden" name="mod_action" value="admin_places">
						<input type="hidden" name="action" value="ImportFile">
						<input type="submit" value="<?php 
        echo WT_I18N::translate('Upload');
        ?>
">
					</form>
				</td>
			</tr>
			<tr>
				<td>
					<?php 
        echo WT_I18N::translate('Download geographic data');
        ?>
				</td>
				<td>
					<form action="module.php" method="get">
						<input type="hidden" name="mod" value="googlemap">
						<input type="hidden" name="mod_action" value="admin_places">
						<input type="hidden" name="action" value="ExportFile">
						<?php 
        echo select_edit_control('parent', $where_am_i, WT_I18N::translate('All'), WT_GED_ID);
        ?>
						<input type="submit" value="<?php 
        echo WT_I18N::translate('Download');
        ?>
">
					</form>
				</td>
			</tr>
		</table>
		<?php 
    }
Example #7
0
/**
* prints a form to add an individual or edit an individual's name
*
* @param string $nextaction the next action the edit_interface.php file should take after the form is submitted
* @param string $famid the family that the new person should be added to
* @param string $namerec the name subrecord when editing a name
* @param string $famtag how the new person is added to the family
*/
function print_indi_form($nextaction, $famid, $linenum = "", $namerec = "", $famtag = "CHIL", $sextag = "")
{
    global $pgv_lang, $factarray, $pid, $PGV_IMAGE_DIR, $PGV_IMAGES, $WORD_WRAPPED_NOTES;
    global $NPFX_accept, $SPFX_accept, $NSFX_accept, $FILE_FORM_accept, $GEDCOM, $NAME_REVERSE;
    global $bdm, $TEXT_DIRECTION, $STANDARD_NAME_FACTS, $REVERSED_NAME_FACTS, $ADVANCED_NAME_FACTS, $ADVANCED_PLAC_FACTS, $SURNAME_TRADITION;
    global $QUICK_REQUIRED_FACTS, $QUICK_REQUIRED_FAMFACTS;
    $bdm = "";
    // used to copy '1 SOUR' to '2 SOUR' for BIRT DEAT MARR
    init_calendar_popup();
    echo "<form method=\"post\" name=\"addchildform\" onsubmit=\"return checkform();\">\n";
    echo "<input type=\"hidden\" name=\"action\" value=\"{$nextaction}\" />\n";
    echo "<input type=\"hidden\" name=\"linenum\" value=\"{$linenum}\" />\n";
    echo "<input type=\"hidden\" name=\"famid\" value=\"{$famid}\" />\n";
    echo "<input type=\"hidden\" name=\"pid\" value=\"{$pid}\" />\n";
    echo "<input type=\"hidden\" name=\"famtag\" value=\"{$famtag}\" />\n";
    echo "<input type=\"submit\" value=\"" . $pgv_lang["save"] . "\" />\n";
    echo "<input type=\"hidden\" name=\"goto\" value=\"\" />\n";
    if (preg_match('/^add(child|spouse|newparent|newrepository)/', $nextaction)) {
        echo "<input type=\"submit\" value=\"{$pgv_lang['saveandgo']}\" onclick=\"document.addchildform.goto.value='new';\"/>\n";
    }
    echo "<table class=\"facts_table\">";
    // When adding a new child, specify the pedigree
    if ($nextaction == 'addchildaction') {
        add_simple_tag("0 PEDI");
    }
    // Populate the standard NAME field and subfields
    $name_fields = array();
    if (!$NAME_REVERSE) {
        foreach ($STANDARD_NAME_FACTS as $tag) {
            $name_fields[$tag] = get_gedcom_value($tag, 0, $namerec);
        }
    } else {
        foreach ($REVERSED_NAME_FACTS as $tag) {
            $name_fields[$tag] = get_gedcom_value($tag, 0, $namerec);
        }
    }
    $new_marnm = '';
    // Inherit surname from parents, spouse or child
    if (empty($namerec)) {
        // We'll need the parent's name to set the child's surname
        if (isset($pgv_changes[$famid . "_" . $GEDCOM])) {
            $famrec = find_updated_record($famid);
        } else {
            $famrec = find_family_record($famid);
        }
        $parents = find_parents_in_record($famrec);
        $father_name = get_gedcom_value('NAME', 0, find_person_record($parents['HUSB']));
        $mother_name = get_gedcom_value('NAME', 0, find_person_record($parents['WIFE']));
        // We'll need the spouse/child's name to set the spouse/parent's surname
        if (isset($pgv_changes[$pid . "_" . $GEDCOM])) {
            $prec = find_updated_record($pid);
        } else {
            $prec = find_person_record($pid);
        }
        $indi_name = get_gedcom_value('NAME', 0, $prec);
        // Different cultures do surnames differently
        switch ($SURNAME_TRADITION) {
            case 'spanish':
                //Mother: Maria /AAAA BBBB/
                //Father: Jose  /CCCC DDDD/
                //Child:  Pablo /CCCC AAAA/
                switch ($nextaction) {
                    case 'addchildaction':
                        if (preg_match('/\\/(\\S+)\\s+\\S+\\//', $mother_name, $matchm) && preg_match('/\\/(\\S+)\\s+\\S+\\//', $father_name, $matchf)) {
                            $name_fields['SURN'] = $matchf[1] . ' ' . $matchm[1];
                            $name_fields['NAME'] = '/' . $name_fields['SURN'] . '/';
                        }
                        break;
                    case 'addnewparentaction':
                        if ($famtag == 'HUSB' && preg_match('/\\/(\\S+)\\s+\\S+\\//', $indi_name, $match)) {
                            $name_fields['SURN'] = $match[1] . ' ';
                            $name_fields['NAME'] = '/' . $name_fields['SURN'] . '/';
                        }
                        if ($famtag == 'WIFE' && preg_match('/\\/\\S+\\s+(\\S+)\\//', $indi_name, $match)) {
                            $name_fields['SURN'] = $match[1] . ' ';
                            $name_fields['NAME'] = '/' . $name_fields['SURN'] . '/';
                        }
                        break;
                }
                break;
            case 'portuguese':
                //Mother: Maria /AAAA BBBB/
                //Father: Jose  /CCCC DDDD/
                //Child:  Pablo /BBBB DDDD/
                switch ($nextaction) {
                    case 'addchildaction':
                        if (preg_match('/\\/\\S+\\s+(\\S+)\\//', $mother_name, $matchm) && preg_match('/\\/\\S+\\s+(\\S+)\\//', $father_name, $matchf)) {
                            $name_fields['SURN'] = $matchf[1] . ' ' . $matchm[1];
                            $name_fields['NAME'] = '/' . $name_fields['SURN'] . '/';
                        }
                        break;
                    case 'addnewparentaction':
                        if ($famtag == 'HUSB' && preg_match('/\\/\\S+\\s+(\\S+)\\//', $indi_name, $match)) {
                            $name_fields['SURN'] = ' ' . $match[1];
                            $name_fields['NAME'] = '/' . $name_fields['SURN'] . '/';
                        }
                        if ($famtag == 'WIFE' && preg_match('/\\/(\\S+)\\s+\\S+\\//', $indi_name, $match)) {
                            $name_fields['SURN'] = ' ' . $match[1];
                            $name_fields['NAME'] = '/' . $name_fields['SURN'] . '/';
                        }
                        break;
                }
                break;
            case 'icelandic':
                // Sons get their father's given name plus "sson"
                // Daughters get their father's given name plus "sdottir"
                switch ($nextaction) {
                    case 'addchildaction':
                        if ($sextag == 'M' && preg_match('/(\\S+)\\s+\\/.*\\//', $father_name, $match)) {
                            $name_fields['SURN'] = preg_replace('/s$/', '', $match[1]) . 'sson';
                            $name_fields['NAME'] = '/' . $name_fields['SURN'] . '/';
                        }
                        if ($sextag == 'F' && preg_match('/(\\S+)\\s+\\/.*\\//', $father_name, $match)) {
                            $name_fields['SURN'] = preg_replace('/s$/', '', $match[1]) . 'sdottir';
                            $name_fields['NAME'] = '/' . $name_fields['SURN'] . '/';
                        }
                        break;
                    case 'addnewparentaction':
                        if ($famtag == 'HUSB' && preg_match('/(\\S+)sson\\s+\\/.*\\//i', $indi_name, $match)) {
                            $name_fields['GIVN'] = $match[1];
                            $name_fields['NAME'] = $name_fields['GIVN'] . ' //';
                        }
                        if ($famtag == 'WIFE' && preg_match('/(\\S+)sdottir\\s+\\/.*\\//i', $indi_name, $match)) {
                            $name_fields['GIVN'] = $match[1];
                            $name_fields['NAME'] = $name_fields['GIVN'] . ' //';
                        }
                        break;
                }
                break;
            case 'paternal':
            case 'polish':
                // Father gives his surname to his wife and children
                switch ($nextaction) {
                    case 'addspouseaction':
                        if ($famtag == 'WIFE' && preg_match('/\\/(.*)\\//', $indi_name, $match)) {
                            if ($SURNAME_TRADITION == 'polish') {
                                $match[1] = preg_replace(array('/ski$/', '/cki$/', '/dzki$/'), array('ska', 'cka', 'dzka'), $match[1]);
                            }
                            $new_marnm = $match[1];
                        }
                        break;
                    case 'addchildaction':
                        if (preg_match('/\\/((?:[a-z]{2,3}\\s+)*)(.*)\\//i', $father_name, $match)) {
                            if ($SURNAME_TRADITION == 'polish' && $sextag == 'F') {
                                $match[2] = preg_replace(array('/ski$/', '/cki$/', '/dzki$/'), array('ska', 'cka', 'dzka'), $match[2]);
                            }
                            $name_fields['SPFX'] = trim($match[1]);
                            $name_fields['SURN'] = $match[2];
                            $name_fields['NAME'] = "/{$match[1]}{$match[2]}/";
                        }
                        break;
                    case 'addnewparentaction':
                        if ($famtag == 'HUSB' && preg_match('/\\/((?:[a-z]{2,3}\\s+)*)(.*)\\//i', $indi_name, $match)) {
                            if ($SURNAME_TRADITION == 'polish' && $sextag == 'M') {
                                $match[2] = preg_replace(array('/ska$/', '/cka$/', '/dzka$/'), array('ski', 'cki', 'dzki'), $match[2]);
                            }
                            $name_fields['SPFX'] = trim($match[1]);
                            $name_fields['SURN'] = $match[2];
                            $name_fields['NAME'] = "/{$match[1]}{$match[2]}/";
                        }
                        break;
                }
                break;
        }
    }
    // Make sure there are two slashes in the name
    if (!preg_match('/\\//', $name_fields['NAME'])) {
        $name_fields['NAME'] .= ' /';
    }
    if (!preg_match('/\\/.*\\//', $name_fields['NAME'])) {
        $name_fields['NAME'] .= '/';
    }
    // Populate any missing 2 XXXX fields from the 1 NAME field
    $npfx_accept = implode('|', $NPFX_accept);
    if (preg_match("/((({$npfx_accept})\\.? +)*)([^\n\\/\"]*)(\"(.*)\")? *\\/(([a-z]{2,3} +)*)(.*)\\/ *(.*)/i", $name_fields['NAME'], $name_bits)) {
        if (empty($name_fields['NPFX'])) {
            $name_fields['NPFX'] = $name_bits[1];
        }
        if (!$NAME_REVERSE && empty($name_fields['GIVN'])) {
            $name_fields['GIVN'] = $name_bits[4];
        }
        if (empty($name_fields['SPFX']) && empty($name_fields['SURN'])) {
            $name_fields['SPFX'] = trim($name_bits[7]);
            $name_fields['SURN'] = $name_bits[9];
        }
        if (empty($name_fields['NSFX'])) {
            $name_fields['NSFX'] = $name_bits[10];
        }
        if ($NAME_REVERSE && empty($name_fields['GIVN'])) {
            $name_fields['GIVN'] = $name_bits[4];
        }
        // Don't automatically create an empty NICK - it is an "advanced" field.
        if (empty($name_fields['NICK']) && !empty($name_bits[6]) && !preg_match('/^2 NICK/m', $namerec)) {
            $name_fields['NICK'] = $name_bits[6];
        }
    }
    // Edit the standard name fields
    foreach ($name_fields as $tag => $value) {
        add_simple_tag("0 {$tag} {$value}");
    }
    // Get the advanced name fields
    $adv_name_fields = array();
    if (preg_match_all('/(' . PGV_REGEX_TAG . ')/', $ADVANCED_NAME_FACTS, $match)) {
        foreach ($match[1] as $tag) {
            $adv_name_fields[$tag] = '';
        }
    }
    // This is a custom tag, but PGV uses it extensively.
    if ($SURNAME_TRADITION == 'paternal' || $SURNAME_TRADITION == 'polish' || preg_match('/2 _MARNM/', $namerec)) {
        $adv_name_fields['_MARNM'] = '';
    }
    foreach ($adv_name_fields as $tag => $dummy) {
        // Edit existing tags
        if (preg_match_all("/2 {$tag} (.+)/", $namerec, $match)) {
            foreach ($match[1] as $value) {
                if ($tag == '_MARNM') {
                    $mnsct = preg_match('/\\/(.+)\\//', $value, $match2);
                    $marnm_surn = "";
                    if ($mnsct > 0) {
                        $marnm_surn = $match2[1];
                    }
                    add_simple_tag("2 _MARNM " . $value);
                    add_simple_tag("2 _MARNM_SURN " . $marnm_surn);
                } else {
                    add_simple_tag("2 {$tag} {$value}", "", fact_label("NAME:{$tag}"));
                }
            }
        }
        // Allow a new row to be entered if there was no row provided
        if (count($match[1]) == 0 && empty($name_fields[$tag]) || $tag != '_HEB' && $tag != 'NICK') {
            if ($tag == '_MARNM') {
                add_simple_tag("0 _MARNM");
                add_simple_tag("0 _MARNM_SURN {$new_marnm}");
            } else {
                add_simple_tag("0 {$tag}", "", fact_label("NAME:{$tag}"));
            }
        }
    }
    // Handle any other NAME subfields that aren't included above (SOUR, NOTE, _CUSTOM, etc)
    if ($namerec != "" && $namerec != "NEW") {
        $gedlines = split("\n", $namerec);
        // -- find the number of lines in the record
        $fields = explode(' ', $gedlines[0]);
        $glevel = $fields[0];
        $level = $glevel;
        $type = trim($fields[1]);
        $level1type = $type;
        $tags = array();
        $i = 0;
        do {
            if (!isset($name_fields[$type]) && !isset($adv_name_fields[$type])) {
                $text = "";
                for ($j = 2; $j < count($fields); $j++) {
                    if ($j > 2) {
                        $text .= " ";
                    }
                    $text .= $fields[$j];
                }
                $iscont = false;
                while ($i + 1 < count($gedlines) && preg_match("/" . ($level + 1) . " (CON[CT])\\s?(.*)/", $gedlines[$i + 1], $cmatch) > 0) {
                    $iscont = true;
                    if ($cmatch[1] == "CONT") {
                        $text .= "\n";
                    }
                    if ($WORD_WRAPPED_NOTES) {
                        $text .= " ";
                    }
                    $text .= $cmatch[2];
                    $i++;
                }
                add_simple_tag($level . " " . $type . " " . $text);
            }
            $tags[] = $type;
            $i++;
            if (isset($gedlines[$i])) {
                $fields = explode(' ', $gedlines[$i]);
                $level = $fields[0];
                if (isset($fields[1])) {
                    $type = $fields[1];
                }
            }
        } while ($level > $glevel && $i < count($gedlines));
    }
    // If we are adding a new individual, add the basic details
    if ($nextaction != 'update') {
        echo '</table><br/><table class="facts_table">';
        // 1 SEX
        if ($famtag == "HUSB" || $sextag == "M") {
            add_simple_tag("0 SEX M");
        } elseif ($famtag == "WIFE" || $sextag == "F") {
            add_simple_tag("0 SEX F");
        } else {
            add_simple_tag("0 SEX");
        }
        $bdm = "BD";
        if (preg_match_all('/(' . PGV_REGEX_TAG . ')/', $QUICK_REQUIRED_FACTS, $matches)) {
            foreach ($matches[1] as $match) {
                if (!in_array($match, explode('|', PGV_EVENTS_DEAT))) {
                    addSimpleTags($match);
                }
            }
        }
        //-- if adding a spouse add the option to add a marriage fact to the new family
        if ($nextaction == 'addspouseaction' || $nextaction == 'addnewparentaction' && $famid != 'new') {
            $bdm .= "M";
            if (preg_match_all('/(' . PGV_REGEX_TAG . ')/', $QUICK_REQUIRED_FAMFACTS, $matches)) {
                foreach ($matches[1] as $match) {
                    addSimpleTags($match);
                }
            }
        }
        if (preg_match_all('/(' . PGV_REGEX_TAG . ')/', $QUICK_REQUIRED_FACTS, $matches)) {
            foreach ($matches[1] as $match) {
                if (in_array($match, explode('|', PGV_EVENTS_DEAT))) {
                    addSimpleTags($match);
                }
            }
        }
    }
    if (PGV_USER_IS_ADMIN) {
        echo "<tr><td class=\"descriptionbox " . $TEXT_DIRECTION . " wrap width25\">";
        print_help_link("no_update_CHAN_help", "qm");
        echo $pgv_lang["admin_override"] . "</td><td class=\"optionbox wrap\">\n";
        echo "<input type=\"checkbox\" name=\"preserve_last_changed\" />\n";
        echo $pgv_lang["no_update_CHAN"] . "<br />\n";
        if (isset($famrec)) {
            $event = new Event(get_sub_record(1, "1 CHAN", $famrec));
            echo format_fact_date($event, false, true);
        }
        echo "</td></tr>\n";
    }
    echo "</table>\n";
    if ($nextaction == 'update') {
        // GEDCOM 5.5.1 spec says NAME doesn't get a OBJE
        print_add_layer('SOUR');
        print_add_layer('NOTE');
        print_add_layer('SHARED_NOTE');
    } else {
        print_add_layer('SOUR', 1);
        print_add_layer('NOTE', 1);
        print_add_layer('SHARED_NOTE', 1);
        print_add_layer('OBJE', 1);
    }
    echo "<input type=\"submit\" value=\"" . $pgv_lang["save"] . "\" />\n";
    if (preg_match('/^add(child|spouse|newparent|source)/', $nextaction)) {
        echo "<input type=\"submit\" value=\"{$pgv_lang['saveandgo']}\" onclick=\"document.addchildform.goto.value='new';\"/>\n";
    }
    echo "</form>\n";
    ?>
	<script type="text/javascript">
	<!--
	function trim(str) {
		// Commas are used in the GIVN and SURN field to separate lists of surnames.
		// For example, to differentiate the two Spanish surnames from an English
		// double-barred name.
		// Commas *may* be used in the NAME field, and will form part of the displayed
		// name.  This is not encouraged, as it may confuse some logic that assumes
		// "list" format names are always "surn, givn".
		str=str.replace(/,/g," ");

		str=str.replace(/\s\s+/g," ");
		return str.replace(/(^\s+)|(\s+$)/g,'');
	}

	function lang_class(str) {
		if (str.match(/[\u0370-\u03FF]/)) return "greek";
		if (str.match(/[\u0400-\u04FF]/)) return "cyrillic";
		if (str.match(/[\u0590-\u05FF]/)) return "hebrew";
		if (str.match(/[\u0600-\u06FF]/)) return "arabic";
		return "latin"; // No matched text implies latin :-)
	}

	// Generate a full name from the name components
	function generate_name() {
		var frm =document.forms[0];
		var npfx=frm.NPFX.value;
		var givn=frm.GIVN.value;
		var spfx=frm.SPFX.value;
		var surn=frm.SURN.value;
		var nsfx=frm.NSFX.value;
		return trim(npfx+" "+givn+" /"+trim(spfx+" "+surn.replace(/ *, */, " "))+"/ "+nsfx);
	}

	// Update the NAME and _MARNM fields from the name components
	// and also display the value in read-only "gedcom" format.
	function updatewholename() {
		// don't update the name if the user manually changed it
		if (manualChange) return;
		// Update NAME field from components and display it
		var frm =document.forms[0];
		var npfx=frm.NPFX.value;
		var givn=frm.GIVN.value;
		var spfx=frm.SPFX.value;
		var surn=frm.SURN.value;
		var nsfx=frm.NSFX.value;
		document.getElementById('NAME').value=generate_name();
		document.getElementById('NAME_display').innerHTML=frm.NAME.value;
		// Married names inherit some NSFX values, but not these
		nsfx=nsfx.replace(/^(I|II|III|IV|V|VI|Junior|Jr\.?|Senior|Sr\.?)$/i, '');
		// Update _MARNM field from _MARNM_SURN field and display it
		// Be careful of mixing latin/hebrew/etc. character sets.
		var ip=document.getElementsByTagName('input');
		var marnm_id='';
		var romn='';
		var heb='';
		for (var i=0; i<ip.length; i++) {
			var val=ip[i].value;
			if (ip[i].id.indexOf("_HEB")==0)
				heb=val;
			if (ip[i].id.indexOf("ROMN")==0)
				romn=val;
			if (ip[i].id.indexOf("_MARNM")==0) {
				if (ip[i].id.indexOf("_MARNM_SURN")==0) {
					var msurn='';
					if (val!='') {
						var lc=lang_class(document.getElementById(ip[i].id).value);
						if (lang_class(frm.NAME.value)==lc)
							msurn=trim(npfx+" "+givn+" /"+val+"/ "+nsfx);
						else if (lc=="hebrew")
							msurn=heb.replace(/\/.*\//, '/'+val+'/');
						else if (lang_class(romn)==lc)
							msurn=romn.replace(/\/.*\//, '/'+val+'/');
					}
					document.getElementById(marnm_id).value=msurn;
					document.getElementById(marnm_id+"_display").innerHTML=msurn;
				} else {
					marnm_id=ip[i].id;
				}
			}
		}
	}

	/**
	* convert a hidden field to a text box
	*/
	var oldName = "";
	var manualChange = false;
	function convertHidden(eid) {
		var element = document.getElementById(eid);
		if (element) {
			if (element.type=="hidden") {
				// IE doesn't allow changing the "type" of an input field so we'll cludge it ( silly :P)
				if (IE) {
					var newInput = document.createElement('input');
					newInput.setAttribute("type", "text");
					newInput.setAttribute("name", element.Name);
					newInput.setAttribute("id", element.id);
					newInput.setAttribute("value", element.value);
					newInput.setAttribute("onchange", element.onchange);
					var parent = element.parentNode;
					parent.replaceChild(newInput, element);
					element = newInput;
				}
				else {
					element.type="text";
				}
				element.size="40";
				oldName = element.value;
				manualChange = true;
				var delement = document.getElementById(eid+"_display");
				if (delement) {
					delement.style.display='none';
					// force FF ui to update the display
					if (delement.innerHTML != oldName) {
						oldName = delement.innerHTML;
						element.value = oldName;
					}
				}
			}
			else {
				manualChange = false;
				// IE doesn't allow changing the "type" of an input field so we'll cludge it ( silly :P)
				if (IE) {
					var newInput = document.createElement('input');
					newInput.setAttribute("type", "hidden");
					newInput.setAttribute("name", element.Name);
					newInput.setAttribute("id", element.id);
					newInput.setAttribute("value", element.value);
					newInput.setAttribute("onchange", element.onchange);
					var parent = element.parentNode;
					parent.replaceChild(newInput, element);
					element = newInput;
				}
				else {
					element.type="hidden";
				}
				var delement = document.getElementById(eid+"_display");
				if (delement) {
					delement.style.display='inline';
				}
			}
		}
	}

	/**
	* if the user manually changed the NAME field, then update the textual
	* HTML representation of it
	* If the value changed set manualChange to true so that changing
	* the other fields doesn't change the NAME line
	*/
	function updateTextName(eid) {
		var element = document.getElementById(eid);
		if (element) {
			if (element.value!=oldName) manualChange = true;
			var delement = document.getElementById(eid+"_display");
			if (delement) {
				delement.innerHTML = element.value;
			}
		}
	}

	function checkform() {
		var ip=document.getElementsByTagName('input');
		for (var i=0; i<ip.length; i++) {
			// ADD slashes to _HEB and _AKA names
			if (ip[i].id.indexOf('_AKA')==0 || ip[i].id.indexOf('_HEB')==0 || ip[i].id.indexOf('ROMN')==0)
				if (ip[i].value.indexOf('/')<0 && ip[i].value!='')
					ip[i].value=ip[i].value.replace(/([^\s]+)\s*$/, "/$1/");
			// Blank out temporary _MARNM_SURN and empty name fields
			if (ip[i].id.indexOf("_MARNM_SURN")==0 || ip[i].value=='//')
					ip[i].value='';
			// Convert "xxx yyy" and "xxx y yyy" surnames to "xxx,yyy"
			if ('<?php 
    echo $SURNAME_TRADITION;
    ?>
'=='spanish' || '<?php 
    echo $SURNAME_TRADITION;
    ?>
'=='portuguese')
				if (ip[i].id.indexOf("SURN")==0) ip[i].value=document.forms[0].SURN.value.replace(/^\s*([^\s,]{2,})\s+([iIyY] +)?([^\s,]{2,})\s*$/, "$1,$3");;
		}
		return true;
	}

	// If the name isn't initially formed from the components in a standard way,
	// then don't automatically update it.
	if (document.getElementById("NAME").value!=generate_name() && document.getElementById("NAME").value!="//") convertHidden("NAME");
	//-->
	</script>
	<?php 
}
Example #8
0
function print_descendency($pid, $count)
{
    global $show_spouse, $dgenerations, $bwidth, $bheight, $bhalfheight;
    global $TEXT_DIRECTION, $PGV_IMAGE_DIR, $PGV_IMAGES, $generations, $box_width, $view, $show_full, $pgv_lang;
    if ($count >= $dgenerations) {
        return 0;
    }
    print "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n";
    print "<tr>";
    print "<td width=\"" . ($bwidth - 2) . "\">\n";
    $numkids = 0;
    $famids = find_sfamily_ids($pid);
    if (count($famids) > 0) {
        $firstkids = 0;
        foreach ($famids as $indexval => $famid) {
            $famrec = find_family_record($famid, PGV_GED_ID);
            $ct = preg_match_all("/1 CHIL @(.*)@/", $famrec, $match, PREG_SET_ORDER);
            if ($ct > 0) {
                print "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n";
                for ($i = 0; $i < $ct; $i++) {
                    $rowspan = 2;
                    if ($i > 0 && $i < $ct - 1) {
                        $rowspan = 1;
                    }
                    $chil = trim($match[$i][1]);
                    print "<tr><td rowspan=\"{$rowspan}\" width=\"{$bwidth}\" style=\"padding-top: 2px;\">\n";
                    if ($count < $dgenerations - 1) {
                        $kids = print_descendency($chil, $count + 1);
                        if ($i == 0) {
                            $firstkids = $kids;
                        }
                        $numkids += $kids;
                    } else {
                        print_pedigree_person($chil);
                        $numkids++;
                    }
                    print "</td>\n";
                    $twidth = 7;
                    if ($ct == 1) {
                        $twidth += 3;
                    }
                    print "<td rowspan=\"{$rowspan}\"><img src=\"" . $PGV_IMAGE_DIR . "/" . $PGV_IMAGES["hline"]["other"] . "\" width=\"{$twidth}\" height=\"3\" alt=\"\" /></td>\n";
                    if ($ct > 1) {
                        if ($i == 0) {
                            print "<td height=\"" . ($bhalfheight + 3) . "\"><img src=\"" . $PGV_IMAGE_DIR . "/" . $PGV_IMAGES["spacer"]["other"] . "\" width=\"3\" alt=\"\" /></td></tr>\n";
                            print "<tr><td height=\"" . ($bhalfheight + 3) . "\" style=\"background: url('" . $PGV_IMAGE_DIR . "/" . $PGV_IMAGES["vline"]["other"] . "');\"><img src=\"" . $PGV_IMAGE_DIR . "/" . $PGV_IMAGES["spacer"]["other"] . "\" width=\"3\" alt=\"\" /></td>\n";
                        } else {
                            if ($i == $ct - 1) {
                                print "<td height=\"" . ($bhalfheight + 4) . "\" style=\"background: url('" . $PGV_IMAGE_DIR . "/" . $PGV_IMAGES["vline"]["other"] . "');\"><img src=\"" . $PGV_IMAGE_DIR . "/" . $PGV_IMAGES["spacer"]["other"] . "\" width=\"3\" alt=\"\" /></td></tr>\n";
                                print "<tr><td height=\"" . ($bhalfheight + 4) . "\"><img src=\"" . $PGV_IMAGE_DIR . "/" . $PGV_IMAGES["spacer"]["other"] . "\" width=\"3\" alt=\"\" /></td>\n";
                            } else {
                                print "<td style=\"background: url('" . $PGV_IMAGE_DIR . "/" . $PGV_IMAGES["vline"]["other"] . "');\"><img src=\"" . $PGV_IMAGE_DIR . "/" . $PGV_IMAGES["spacer"]["other"] . "\" width=\"3\" alt=\"\" /></td>\n";
                            }
                        }
                    }
                    print "</tr>\n";
                }
                print "</table>\n";
            }
        }
        print "</td>\n";
        print "<td width=\"{$bwidth}\">\n";
    }
    // NOTE: If statement OK
    if ($numkids == 0) {
        $numkids = 1;
        $tbwidth = $bwidth + 16;
        for ($j = $count; $j < $dgenerations; $j++) {
            print "</td>\n<td width=\"{$bwidth}\">\n";
        }
    }
    //-- add offset divs to make things line up better
    if ($show_spouse) {
        foreach ($famids as $indexval => $famid) {
            $famrec = find_family_record($famid, PGV_GED_ID);
            if (!empty($famrec)) {
                $marrec = get_sub_record(1, "1 MARR", $famrec);
                if (!empty($marrec)) {
                    print "<br />";
                }
                print "<div style=\"height: " . $bheight . "px; width: " . $bwidth . "px;\"><br /></div>\n";
            }
        }
    }
    print_pedigree_person($pid);
    // NOTE: If statement OK
    if ($show_spouse) {
        foreach ($famids as $indexval => $famid) {
            $famrec = find_family_record($famid, PGV_GED_ID);
            if (!empty($famrec)) {
                $parents = find_parents_in_record($famrec);
                $marrec = get_sub_record(1, "1 MARR", $famrec);
                if (!empty($marrec)) {
                    print "<br />";
                    $marriage = new Event($marrec);
                    $marriage->print_simple_fact();
                }
                if ($parents["HUSB"] != $pid) {
                    print_pedigree_person($parents["HUSB"]);
                } else {
                    print_pedigree_person($parents["WIFE"]);
                }
            }
        }
    }
    // NOTE: If statement OK
    if ($count == 0) {
        $indirec = find_person_record($pid, PGV_GED_ID);
        // NOTE: If statement OK
        if (displayDetailsById($pid, 'INDI') || showLivingNameById($pid)) {
            // -- print left arrow for decendants so that we can move down the tree
            $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;
            // NOTE: For statement OK
            for ($f = 0; $f < count($cfamids); $f++) {
                $famrec = find_family_record($cfamids[$f], PGV_GED_ID);
                if ($famrec) {
                    $num += preg_match_all("/1\\s*CHIL\\s*@(.*)@/", $famrec, $smatch, PREG_SET_ORDER);
                }
            }
            // NOTE: If statement OK
            if ($famids || $num > 1) {
                print "\n\t\t<div class=\"center\" id=\"childarrow.{$pid}\" dir=\"" . $TEXT_DIRECTION . "\"";
                print " style=\"position:absolute; width:" . $bwidth . "px; \">";
                if ($view != "preview") {
                    print "<a href=\"javascript: " . $pgv_lang["show"] . "\" onclick=\"return togglechildrenbox('{$pid}');\" onmouseover=\"swap_image('larrow.{$pid}',3);\" onmouseout=\"swap_image('larrow.{$pid}',3);\">";
                    print "<img id=\"larrow.{$pid}\" src=\"" . $PGV_IMAGE_DIR . "/" . $PGV_IMAGES["darrow"]["other"] . "\" border=\"0\" alt=\"\" />";
                    print "</a>";
                }
                print "\n\t\t<div id=\"childbox.{$pid}\" dir=\"" . $TEXT_DIRECTION . "\" style=\"width:" . $bwidth . "px; height:" . $bheight . "px; visibility: hidden;\">";
                print "\n\t\t\t<table class=\"person_box\"><tr><td>";
                for ($f = 0; $f < count($famids); $f++) {
                    $famrec = find_family_record(trim($famids[$f]), PGV_GED_ID);
                    if ($famrec) {
                        $parents = find_parents($famids[$f]);
                        if ($parents) {
                            if ($pid != $parents["HUSB"]) {
                                $spid = $parents["HUSB"];
                            } else {
                                $spid = $parents["WIFE"];
                            }
                            $spouse = Person::getInstance($spid);
                            if ($spouse) {
                                $name = $spouse->getFullName();
                                print "\n\t\t\t\t<a href=\"" . encode_url("familybook.php?pid={$spid}&show_spouse={$show_spouse}&show_full={$show_full}&generations={$generations}&box_width={$box_width}") . "\"><span class=\"";
                                if (hasRTLText($name)) {
                                    print "name2";
                                } else {
                                    print "name1";
                                }
                                print "\">";
                                print PrintReady($name);
                                print "<br /></span></a>";
                            }
                        }
                        $num = preg_match_all("/1\\s*CHIL\\s*@(.*)@/", $famrec, $smatch, PREG_SET_ORDER);
                        for ($i = 0; $i < $num; $i++) {
                            //-- add the following line to stop a bad PHP bug
                            if ($i >= $num) {
                                break;
                            }
                            $cid = $smatch[$i][1];
                            $child = Person::getInstance($cid);
                            $name = $child->getFullName();
                            print "\n\t\t\t\t&nbsp;&nbsp;<a href=\"" . encode_url("familybook.php?pid={$cid}&show_spouse={$show_spouse}&show_full={$show_full}&generations={$generations}&box_width={$box_width}") . "\"><span class=\"";
                            if (hasRTLText($name)) {
                                print "name2";
                            } else {
                                print "name1";
                            }
                            print "\">&lt; ";
                            print PrintReady($name);
                            print "<br /></span></a>";
                        }
                    }
                }
                //-- print the siblings
                for ($f = 0; $f < count($cfamids); $f++) {
                    $famrec = find_family_record($cfamids[$f], PGV_GED_ID);
                    if ($famrec) {
                        $parents = find_parents($cfamids[$f]);
                        if ($parents) {
                            print "<span class=\"name1\"><br />" . $pgv_lang["parents"] . "<br /></span>";
                            if (!empty($parents["HUSB"])) {
                                $spid = $parents["HUSB"];
                                $spouse = Person::getInstance($spid);
                                $name = $spouse->getFullName();
                                print "\n\t\t\t\t&nbsp;&nbsp;<a href=\"" . encode_url("familybook.php?pid={$spid}&show_spouse={$show_spouse}&show_full={$show_full}&generations={$generations}&box_width={$box_width}") . "\"><span class=\"";
                                if (hasRTLText($name)) {
                                    print "name2";
                                } else {
                                    print "name1";
                                }
                                print "\">";
                                print PrintReady($name);
                                print "<br /></span></a>";
                            }
                            if (!empty($parents["WIFE"])) {
                                $spid = $parents["WIFE"];
                                $spouse = Person::getInstance($spid);
                                $name = $spouse->getFullName();
                                print "\n\t\t\t\t&nbsp;&nbsp;<a href=\"" . encode_url("familybook.php?pid={$spid}&show_spouse={$show_spouse}&show_full={$show_full}&generations={$generations}&box_width={$box_width}") . "\"><span class=\"";
                                if (hasRTLText($name)) {
                                    print "name2";
                                } else {
                                    print "name1";
                                }
                                print "\">";
                                print PrintReady($name);
                                print "<br /></span></a>";
                            }
                        }
                        $num = preg_match_all("/1\\s*CHIL\\s*@(.*)@/", $famrec, $smatch, PREG_SET_ORDER);
                        if ($num > 2) {
                            print "<span class=\"name1\"><br />" . $pgv_lang["siblings"] . "<br /></span>";
                        }
                        if ($num == 2) {
                            print "<span class=\"name1\"><br />" . $pgv_lang["sibling"] . "<br /></span>";
                        }
                        for ($i = 0; $i < $num; $i++) {
                            //-- add the following line to stop a bad PHP bug
                            if ($i >= $num) {
                                break;
                            }
                            $cid = $smatch[$i][1];
                            if ($cid != $pid) {
                                $child = Person::getInstance($cid);
                                $name = $child->getFullName();
                                print "\n\t\t\t\t&nbsp;&nbsp;<a href=\"familybook.php?pid={$cid}&amp;show_spouse={$show_spouse}&amp;show_full={$show_full}&amp;generations={$generations}&amp;box_width={$box_width}\"><span class=\"";
                                if (hasRTLText($name)) {
                                    print "name2";
                                } else {
                                    print "name1";
                                }
                                print "\"> ";
                                print PrintReady($name);
                                print "<br /></span></a>";
                            }
                        }
                    }
                }
                print "\n\t\t\t</td></tr></table>";
                print "\n\t\t</div>";
                print "\n\t\t</div>";
            }
        }
    }
    print "</td></tr>\n";
    print "</table>\n";
    return $numkids;
}
Example #9
0
				</tr></table>
			</div>
		</td>
	</tr>
	<?php 
    if (PGV_USER_IS_ADMIN) {
        echo "<tr><td class=\"descriptionbox ", $TEXT_DIRECTION, " wrap width25\">";
        print_help_link("no_update_CHAN_help", "qm", "no_update_CHAN");
        echo $pgv_lang["admin_override"], "</td><td class=\"optionbox wrap\">\n";
        if ($NO_UPDATE_CHAN) {
            echo "<input type=\"checkbox\" checked=\"checked\" name=\"preserve_last_changed\" />\n";
        } else {
            echo "<input type=\"checkbox\" name=\"preserve_last_changed\" />\n";
        }
        echo $pgv_lang["no_update_CHAN"], "<br />\n";
        $event = new Event(get_sub_record(1, "1 CHAN", ""));
        echo format_fact_date($event, false, true);
        echo "</td></tr>\n";
    }
    ?>
</table>
<br />
<input type="submit" value="<?php 
    echo $pgv_lang["label_add_remote_link"];
    ?>
" id="btnSubmit" name="btnSubmit" />
</form>
<?php 
    echo PGV_JS_START, 'swapComponents("', $controller->form_location, '");', PGV_JS_END;
}
// autoclose window when update successful
Example #10
0
/**
* returns FAM:SOUR:PAGE matching filter
* @return Array of string
*/
function autocomplete_FAM_SOUR_PAGE($FILTER, $OPTION)
{
    $rows = get_autocomplete_FAM_SOUR_PAGE($FILTER, $OPTION);
    $data = array();
    foreach ($rows as $row) {
        $family = Family::getInstance($row);
        if ($family->canDisplayDetails()) {
            // a single FAM may have multiple level 1 and level 2 sources
            for ($level = 1; $level <= 2; $level++) {
                $i = 1;
                do {
                    $srec = get_sub_record("SOUR @{$OPTION}@", $level, $family->gedrec, $i++);
                    $page = get_gedcom_value("PAGE", $level + 1, $srec);
                    if (stripos($page, $FILTER) !== false || empty($FILTER)) {
                        $data[] = $page;
                    }
                } while ($srec);
            }
        }
    }
    return $data;
}
 /**
  * Creates a GrampsXML for a media, if that media exists in the given GEDCOM record
  * @param $mediaRec - The GEDCOM record of the media
  * @param $mediaID - The id of the media
  * @param $level - The level on which the media can be found, the default is 1
  * @return GrampsXML for the recrord
  */
 function create_media($mediaRec, $mediaID, $level = 1)
 {
     global $file, $eRoot;
     if (!isset($this->dom)) {
         $this->dom = new DomDocument("1.0", "UTF-8");
         $this->dom->formatOutput = true;
         $eRoot = $this->dom->createElementNS("http://gramps-project.org/xml/1.1.0/", "database");
         $eRoot = $this->dom->appendChild($eRoot);
     }
     $object = $this->dom->createElement("object");
     /*primary object elements and attributes*/
     $object->setAttribute("id", $mediaID);
     $object->setAttribute("handle", $mediaID);
     $object->setAttribute("change", time());
     /*elements and attributes of the object element*/
     /*File elements*/
     $file_ = get_gedcom_value("FILE", 1, $mediaRec);
     $fileNode = $this->dom->createElement("file");
     /*Source*/
     $src = $this->dom->createAttribute("src");
     $srcData = $this->dom->createTextNode($file_);
     $srcData = $src->appendChild($srcData);
     $src = $fileNode->appendChild($src);
     /*MIME*/
     $mime_ = get_gedcom_value("FORM", 1, $mediaRec);
     $mime = $this->dom->createAttribute("mime");
     if (empty($mime_)) {
         $path = pathinfo($file_);
         if (!isset($path["extension"])) {
             $mime_ = "unknown_file_extension";
         } else {
             $mime_ = $path["extension"];
         }
     }
     $mimeData = $this->dom->createTextNode($mime_);
     $mimeData = $mime->appendChild($mimeData);
     $mime = $fileNode->appendChild($mime);
     /*DESCRIPTION*/
     $description_ = get_gedcom_value("TITL", 1, $mediaRec);
     $description = $this->dom->createAttribute("description");
     $descriptionData = $this->dom->createTextNode($description_);
     $descriptionData = $description->appendChild($descriptionData);
     $description = $fileNode->appendChild($description);
     /*fileNode elements*/
     $fileNode = $object->appendChild($fileNode);
     $fileNode = $this->dom->createElement("file");
     if (($note = get_sub_record(1, "1 NOTE", $mediaRec)) != null) {
         $this->create_note($object, $note, 1);
     }
     $num = 1;
     while (($nameSource = get_sub_record($level, $level . " SOUR", $mediaRec, $num)) != null) {
         $this->create_sourceref($object, $nameSource, 1);
         $num++;
     }
     $eRoot->appendChild($object);
     return $this->dom->saveXML();
 }
 /**
  * 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;
     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) {
                 /*
                  * 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) {
                     $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);
     }
 }
Example #13
0
 function _statsPlaces($what = 'ALL', $fact = false, $parent = 0, $country = false)
 {
     global $TBLPREFIX, $gBitDb;
     if ($fact) {
         if ($what == 'INDI') {
             $rows = $gBitDb->query("SELECT i_gedcom AS ged FROM {$TBLPREFIX}individuals WHERE i_file=?", array($this->_ged_id));
         } else {
             if ($what == 'FAM') {
                 $rows = $gBitDb->query("SELECT f_gedcom AS ged FROM {$TBLPREFIX}families WHERE f_file=?", array($this->_ged_id));
             }
         }
         $placelist = array();
         while ($row = $roes->fetchRow()) {
             $factrec = trim(get_sub_record(1, "1 {$fact}", $row[ged], 1));
             if (!empty($factrec) && preg_match("/2 PLAC (.+)/", $factrec, $match)) {
                 if ($country) {
                     $place = getPlaceCountry(trim($match[1]));
                 } else {
                     $place = trim($match[1]);
                 }
                 if (!isset($placelist[$place])) {
                     $placelist[$place] = 1;
                 } else {
                     $placelist[$place]++;
                 }
             }
         }
         return $placelist;
     } else {
         if ($parent > 0) {
             if ($what == 'INDI') {
                 $join = " JOIN {$TBLPREFIX}individuals ON pl_file = i_file AND pl_gid = i_id";
             } else {
                 if ($what == 'FAM') {
                     $join = " JOIN {$TBLPREFIX}families ON pl_file = f_file AND pl_gid = f_id";
                 } else {
                     $join = "";
                 }
             }
             $rows = self::_runSQL('' . ' SELECT' . ' p_place AS place,' . ' COUNT(*)' . ' FROM' . " {$TBLPREFIX}places" . " JOIN {$TBLPREFIX}placelinks ON pl_file=p_file AND p_id=pl_p_id" . $join . ' WHERE' . " p_id={$parent} AND" . " p_file={$this->_ged_id}" . ' GROUP BY place');
             if (!isset($rows[0])) {
                 return '';
             }
             return $rows;
         } else {
             if ($what == 'INDI') {
                 $join = " JOIN {$TBLPREFIX}individuals ON pl_file = i_file AND pl_gid = i_id";
             } else {
                 if ($what == 'FAM') {
                     $join = " JOIN {$TBLPREFIX}families ON pl_file = f_file AND pl_gid = f_id";
                 } else {
                     $join = "";
                 }
             }
             $rows = self::_runSQL('' . ' SELECT' . ' p_place AS country,' . ' COUNT(*) AS tot' . ' FROM' . " {$TBLPREFIX}places" . " JOIN {$TBLPREFIX}placelinks ON pl_file=p_file AND p_id=pl_p_id" . $join . ' WHERE' . " p_file={$this->_ged_id}" . " AND p_parent_id='0'" . ' GROUP BY country ORDER BY tot DESC, country ASC');
             if (!isset($rows[0])) {
                 return '';
             }
             return $rows;
         }
     }
 }
Example #14
0
/**
* parse out specific subrecords (NOTE, _PRIM, _THUM) from a given OBJE record
*
* @author Joseph King
* @param string $objrec the OBJE record to retrieve the subrecords from
* @param int $objlevel the level of the OBJE record
* @param string $m_media that media id of the OBJE record
* @return string containing NOTE, _PRIM, and _THUM subrecords parsed from the passed object record
*/
function subrecord_createobjectref($objrec, $objlevel, $m_media)
{
    //- level of subrecords is object record level + 1
    $level = $objlevel + 1;
    //- get and concatenate NOTE subrecords
    $n = 1;
    $nt = "";
    $note = "";
    do {
        $nt = get_sub_record($level, $level . " NOTE", $objrec, $n);
        if ($nt != "") {
            $note = $note . trim($nt) . "\n";
        }
        $n++;
    } while ($nt != "");
    //- get and concatenate PRIM subrecords
    $n = 1;
    $pm = "";
    $prim = "";
    do {
        $pm = get_sub_record($level, $level . " _PRIM", $objrec, $n);
        if ($pm != "") {
            $prim = $prim . trim($pm) . "\n";
        }
        $n++;
    } while ($pm != "");
    //- get and concatenate THUM subrecords
    $n = 1;
    $tm = "";
    $thum = "";
    do {
        $tm = get_sub_record($level, $level . " _THUM", $objrec, $n);
        if ($tm != "") {
            //- call image cropping function ($tm contains thum data)
            $thum = $thum . trim($tm) . "\n";
        }
        $n++;
    } while ($tm != "");
    //- add object reference
    $objmed = addslashes($objlevel . ' OBJE @' . $m_media . "@\n" . $note . $prim . $thum);
    //- return the object media reference
    return $objmed;
}
Example #15
0
/**
* returns FAM:SOUR:PAGE matching filter
* @return Array of string
*/
function autocomplete_FAM_SOUR_PAGE($FILTER, $OPTION)
{
    global $TBLPREFIX, $gBitDb;
    $sql = "SELECT 'FAM' AS type, f_id AS xref, f_file AS ged_id, f_gedcom AS gedrec, f_husb, f_wife, f_chil, f_numchil FROM {$TBLPREFIX}families WHERE f_gedcom LIKE ? AND f_file=?";
    $rows = $gBitDb->query($sql, array("% SOUR @{$OPTION}@% PAGE %{$FILTER}%", PGV_GED_ID), PGV_AUTOCOMPLETE_LIMIT);
    $data = array();
    while ($row = $rows->fetchRows()) {
        $family = Family::getInstance($row);
        if ($family->canDisplayDetails()) {
            // a single FAM may have multiple level 1 and level 2 sources
            for ($level = 1; $level <= 2; $level++) {
                $i = 1;
                do {
                    $srec = get_sub_record("SOUR @{$OPTION}@", $level, $family->gedrec, $i++);
                    $page = get_gedcom_value("PAGE", $level + 1, $srec);
                    if (stripos($page, $FILTER) !== false || empty($FILTER)) {
                        $data[] = $page;
                    }
                } while ($srec);
            }
        }
    }
    return $data;
}
Example #16
0
/**
 * get gedcom tag value
 *
 * @param string $tag    The tag to find, use : to delineate subtags
 * @param int    $level  The gedcom line level of the first tag to find, setting level to 0 will cause it to use 1+ the level of the incoming record
 * @param string $gedrec The gedcom record to get the value from
 *
 * @return string the value of a gedcom tag from the given gedcom record
 */
function get_gedcom_value($tag, $level, $gedrec)
{
    if (empty($gedrec)) {
        return '';
    }
    $tags = explode(':', $tag);
    $origlevel = $level;
    if ($level == 0) {
        $level = $gedrec[0] + 1;
    }
    $subrec = $gedrec;
    foreach ($tags as $t) {
        $lastsubrec = $subrec;
        $subrec = get_sub_record($level, "{$level} {$t}", $subrec);
        if (empty($subrec) && $origlevel == 0) {
            $level--;
            $subrec = get_sub_record($level, "{$level} {$t}", $lastsubrec);
        }
        if (empty($subrec)) {
            if ($t == "TITL") {
                $subrec = get_sub_record($level, "{$level} ABBR", $lastsubrec);
                if (!empty($subrec)) {
                    $t = "ABBR";
                }
            }
            if (empty($subrec)) {
                if ($level > 0) {
                    $level--;
                }
                $subrec = get_sub_record($level, "@ {$t}", $gedrec);
                if (empty($subrec)) {
                    return;
                }
            }
        }
        $level++;
    }
    $level--;
    $ct = preg_match("/{$level} {$t}(.*)/", $subrec, $match);
    if ($ct == 0) {
        $ct = preg_match("/{$level} @.+@ (.+)/", $subrec, $match);
    }
    if ($ct == 0) {
        $ct = preg_match("/@ {$t} (.+)/", $subrec, $match);
    }
    if ($ct > 0) {
        $value = trim($match[1]);
        if ($t == 'NOTE' && preg_match('/^@(.+)@$/', $value, $match)) {
            $note = WT_Note::getInstance($match[1]);
            if ($note) {
                $value = $note->getNote();
            } else {
                //-- set the value to the id without the @
                $value = $match[1];
            }
        }
        if ($level != 0 || $t != "NOTE") {
            $value .= get_cont($level + 1, $subrec);
        }
        return $value;
    }
    return "";
}
Example #17
0
/**
 * print the children table for a family
 *
 * @param string $famid family gedcom ID
 * @param string $childid optional child ID
 * @param int $sosa optional child sosa number
 * @param string $label optional indi label (descendancy booklet)
 */
function print_family_children($famid, $childid = "", $sosa = 0, $label = "", $personcount = "1")
{
    global $pgv_lang, $factarray, $pbwidth, $pbheight, $view, $show_famlink, $show_cousins;
    global $PGV_IMAGE_DIR, $PGV_IMAGES, $show_changes, $pgv_changes, $GEDCOM, $SHOW_ID_NUMBERS, $TEXT_DIRECTION;
    $family = Family::getInstance($famid);
    $children = $family->getChildrenIds();
    print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"2\"><tr>";
    if ($sosa > 0) {
        print "<td></td>";
    }
    print "<td><span class=\"subheaders\">" . $pgv_lang["children"] . "</span></td>";
    if ($sosa > 0) {
        print "<td></td><td></td>";
    }
    print "</tr>\n";
    $newchildren = array();
    $oldchildren = array();
    if (PGV_USER_CAN_EDIT) {
        if (isset($_REQUEST['show_changes']) && $_REQUEST['show_changes'] == 'yes' && isset($pgv_changes[$famid . "_" . $GEDCOM])) {
            $newrec = find_updated_record($famid);
            $ct = preg_match_all("/1 CHIL @(.*)@/", $newrec, $match, PREG_SET_ORDER);
            if ($ct > 0) {
                $oldchil = array();
                for ($i = 0; $i < $ct; $i++) {
                    if (!in_array($match[$i][1], $children)) {
                        $newchildren[] = $match[$i][1];
                    } else {
                        $oldchil[] = $match[$i][1];
                    }
                }
                foreach ($children as $indexval => $chil) {
                    if (!in_array($chil, $oldchil)) {
                        $oldchildren[] = $chil;
                    }
                }
                //-- if there are no old or new children then the children were reordered
                if (count($newchildren) == 0 && count($oldchildren) == 0) {
                    $children = array();
                    for ($i = 0; $i < $ct; $i++) {
                        $children[] = $match[$i][1];
                    }
                }
            }
        }
    }
    $nchi = 1;
    if (count($children) > 0 || count($newchildren) > 0 || count($oldchildren) > 0) {
        foreach ($children as $indexval => $chil) {
            if (!in_array($chil, $oldchildren)) {
                print "<tr>\n";
                if ($sosa != 0) {
                    if ($chil == $childid) {
                        print_sosa_number($sosa, $childid);
                    } else {
                        if (empty($label)) {
                            print_sosa_number("");
                        } else {
                            print_sosa_number($label . $nchi++ . ".");
                        }
                    }
                }
                print "<td valign=\"middle\" >";
                print_pedigree_person($chil, 1, $show_famlink, 8, $personcount);
                $personcount++;
                print "</td>";
                if ($sosa != 0) {
                    // loop for all families where current child is a spouse
                    $famids = find_sfamily_ids($chil);
                    $maxfam = count($famids) - 1;
                    for ($f = 0; $f <= $maxfam; $f++) {
                        $famid = $famids[$f];
                        if (!$famid) {
                            continue;
                        }
                        $parents = find_parents($famid);
                        if (!$parents) {
                            continue;
                        }
                        if ($parents["HUSB"] == $chil) {
                            $spouse = $parents["WIFE"];
                        } else {
                            $spouse = $parents["HUSB"];
                        }
                        // multiple marriages
                        if ($f > 0) {
                            print "</tr>\n<tr><td>&nbsp;</td>";
                            print "<td valign=\"top\"";
                            if ($TEXT_DIRECTION == "rtl") {
                                print " align=\"left\">";
                            } else {
                                print " align=\"right\">";
                            }
                            //if ($f==$maxfam) print "<img height=\"50%\"";
                            //else print "<img height=\"100%\"";
                            if ($f == $maxfam) {
                                print "<img height=\"" . ($pbheight / 2 - 3) . "px\"";
                            } else {
                                print "<img height=\"" . $pbheight . "px\"";
                            }
                            print " width=\"3\" src=\"" . $PGV_IMAGE_DIR . "/" . $PGV_IMAGES["vline"]["other"] . "\" alt=\"\" />";
                            print "</td>";
                        }
                        print "<td class=\"details1\" valign=\"middle\" align=\"center\">";
                        $divrec = "";
                        if (showFact("MARR", $famid)) {
                            // marriage date
                            $famrec = find_family_record($famid);
                            $ct = preg_match("/2 DATE.*(\\d\\d\\d\\d)/", get_sub_record(1, "1 MARR", $famrec), $match);
                            if ($ct > 0) {
                                print "<span class=\"date\">" . trim($match[1]) . "</span>";
                            }
                            // divorce date
                            $divrec = get_sub_record(1, "1 DIV", $famrec);
                            $ct = preg_match("/2 DATE.*(\\d\\d\\d\\d)/", $divrec, $match);
                            if ($ct > 0) {
                                print "-<span class=\"date\">" . trim($match[1]) . "</span>";
                            }
                        }
                        print "<br /><img width=\"100%\" height=\"3\" src=\"" . $PGV_IMAGE_DIR . "/" . $PGV_IMAGES["hline"]["other"] . "\" alt=\"\" />";
                        // family link
                        if ($famid) {
                            print "<br />";
                            print "<a class=\"details1\" href=\"family.php?famid={$famid}\">";
                            if ($SHOW_ID_NUMBERS) {
                                print getLRM() . "&nbsp;({$famid})&nbsp;" . getLRM();
                            }
                            print "</a>";
                        }
                        print "</td>\n";
                        // spouse information
                        print "<td style=\"vertical-align: center;";
                        if (!empty($divrec) and $view != "preview") {
                            print " filter:alpha(opacity=40);-moz-opacity:0.4\">";
                        } else {
                            print "\">";
                        }
                        print_pedigree_person($spouse, 1, $show_famlink, 9, $personcount);
                        $personcount++;
                        print "</td>\n";
                        // cousins
                        if ($show_cousins) {
                            print_cousins($famid, $personcount);
                            $personcount++;
                        }
                    }
                }
                print "</tr>\n";
            }
        }
        foreach ($newchildren as $indexval => $chil) {
            print "<tr >";
            print "<td valign=\"top\" class=\"facts_valueblue\" style=\"width: " . $pbwidth . "px; height: " . $pbheight . "px;\">\n";
            print_pedigree_person($chil, 1, $show_famlink, 0, $personcount);
            $personcount++;
            print "</td></tr>\n";
        }
        foreach ($oldchildren as $indexval => $chil) {
            print "<tr >";
            print "<td valign=\"top\" class=\"facts_valuered\" style=\"width: " . $pbwidth . "px; height: " . $pbheight . "px;\">\n";
            print_pedigree_person($chil, 1, $show_famlink, 0, $personcount);
            $personcount++;
            print "</td></tr>\n";
        }
        // message 'no children' except for sosa
    } else {
        if ($sosa < 1) {
            print "<tr><td></td><td valign=\"top\" >";
            $nchi = "";
            if (isset($pgv_changes[$famid . "_" . $GEDCOM])) {
                $famrec = find_updated_record($famid);
            } else {
                $famrec = find_family_record($famid);
            }
            $ct = preg_match("/1 NCHI (\\w+)/", $famrec, $match);
            if ($ct > 0) {
                $nchi = $match[1];
            } else {
                $famrec = find_family_record($famid);
                $ct = preg_match("/1 NCHI (\\w+)/", $famrec, $match);
                if ($ct > 0) {
                    $nchi = $match[1];
                }
            }
            if ($nchi == "0") {
                print "<img src=\"images/small/childless.gif\" alt=\"" . $pgv_lang["childless_family"] . "\" title=\"" . $pgv_lang["childless_family"] . "\" /> " . $pgv_lang["childless_family"];
            } else {
                print $pgv_lang["no_children"];
            }
            print "</td></tr>";
        } else {
            print "<tr>\n";
            print_sosa_number($sosa, $childid);
            print "<td valign=\"top\">";
            print_pedigree_person($childid, 1, $show_famlink, 0, $personcount);
            $personcount++;
            print "</td></tr>\n";
        }
    }
    print "</table><br />";
    if ($view != "preview" && $sosa == 0 && PGV_USER_CAN_EDIT) {
        print_help_link("add_child_help", "qm", "add_child_to_family");
        print "<a href=\"javascript:;\" onclick=\"return addnewchild('{$famid}','');\">" . $pgv_lang["add_child_to_family"] . "</a>";
        print "<span style='white-space:nowrap;'>";
        print " <a href=\"javascript:;\" onclick=\"return addnewchild('{$famid}','M');\">[" . Person::sexImage('M', 'small', $pgv_lang['son']) . "]</a>";
        print " <a href=\"javascript:;\" onclick=\"return addnewchild('{$famid}','F');\">[" . Person::sexImage('F', 'small', $pgv_lang['daughter']) . "]</a>";
        print "</span>";
    }
}
 /**
  * Creates the SourceRef element and appends it to the Parent Element.  If the actual Source has not
  * 	been previously created, this will retrieve the record for that, and create that also.
  *
  * @param DOMElement $eParent - the parent DOMElement to which the created Note Element is appended
  * @param string $sourcerefRec - the record containing the reference to a Source
  * @param int $level - The GEDCOM line level where the SOUR tag may be found
  */
 function create_sourceref($eParent, $sourcerefRec, $level)
 {
     if (($sourceID = get_gedcom_value("SOUR", $level, $sourcerefRec)) != null) {
         if (id_in_cart($sourceID)) {
             $eSourceRef = $this->dom->createElement("sourceref");
             $eSourceRef = $eParent->appendChild($eSourceRef);
             if (($sourceHlink = $this->query_dom("./sources/source[@id = \"{$sourceID}\"]/@handle")) == null) {
                 $this->create_source($sourceID, find_source_record($sourceID));
             }
             $eSourceRef->setAttribute("hlink", $this->query_dom("./sources/source[@id = \"{$sourceID}\"]/@handle"));
             if (($page = get_gedcom_value("SOUR:PAGE", $level, $sourcerefRec)) != null) {
                 $eSPage = $this->dom->createElement("spage");
                 $etSPage = $this->dom->createTextNode($page);
                 $etSPage = $eSPage->appendChild($etSPage);
                 $eSPage = $eSourceRef->appendChild($eSPage);
             }
             if (($comments = get_gedcom_value("SOUR:NOTE", $level, $sourcerefRec)) != null) {
                 $eSComments = $this->dom->createElement("scomments");
                 $etSComments = $this->dom->createTextNode($comments);
                 $etSComments = $eSComments->appendChild($etSComments);
                 $eSComments = $eSourceRef->appendChild($eSComments);
             }
             if (($text = get_gedcom_value("SOUR:TEXT", $level, $sourcerefRec)) != null) {
                 $num = 1;
                 while (($cont = get_gedcom_value("SOUR:TEXT:CONT", $level, $sourcerefRec, $num)) != null) {
                     $text .= $cont;
                     $num++;
                 }
                 $eSText = $this->dom->createElement("stext");
                 $etSText = $this->dom->createTextNode($text);
                 $etSText = $eSText->appendChild($etSText);
                 $eSText = $eSourceRef->appendChild($eSText);
             }
             if (($dateRec = get_sub_record(1, $level + 1 . " DATE", $sourcerefRec)) != null) {
                 $this->create_date($eSourceRef, $dateRec, $level + 1);
             }
         }
     }
 }
Example #19
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;
}
 /**
  * Creates the Source and appends it to the Sources Element
  *
  * @param string $sourceID - the ID of the source to be created
  * @param string $sourceRec - the entire GEDCOM record containing the Source
  * @param int $level - the level the source is on in the GEDCOM record
  * @param int $done - whether the method is called from the GrampsExport($done=1) or a sub-class
  */
 function create_source($sourceID, $sourceRec, $level = 1, $done = 1)
 {
     $eSource = $this->dom->createElement("source");
     $eSource->setAttribute("id", $sourceID);
     $eSource->setAttribute("handle", $this->generateHandle());
     $eSource->setAttribute("change", time());
     if (($title = get_gedcom_value("TITL", $level, $sourceRec)) != null) {
         $eSTitle = $this->dom->createElement("stitle");
         $etSTitle = $this->dom->createTextNode($title);
         $etSTitle = $eSTitle->appendChild($etSTitle);
         $eSTitle = $eSource->appendChild($eSTitle);
     }
     if (($author = get_gedcom_value("AUTH", $level, $sourceRec)) != null) {
         $eSAuthor = $this->dom->createElement("sauthor");
         $etSAuthor = $this->dom->createTextNode($author);
         $etSAuthor = $eSAuthor->appendChild($etSAuthor);
         $eSAuthor = $eSource->appendChild($eSAuthor);
     }
     if (($pubInfo = get_gedcom_value("PUBL", $level, $sourceRec)) != null) {
         $eSPubInfo = $this->dom->createElement("spubinfo");
         $etSPubInfo = $this->dom->createTextNode($pubInfo);
         $etSPubInfo = $eSPubInfo->appendChild($etSPubInfo);
         $eSPubInfo = $eSource->appendChild($eSPubInfo);
     }
     if (($abbrev = get_gedcom_value("ABBR", $level, $sourceRec)) != null) {
         $eSAbbrev = $this->dom->createElement("sabbrev");
         $etSAbbrev = $this->dom->createTextNode($abbrev);
         $etSAbbrev = $eSAbbrev->appendChild($etSAbbrev);
         $eSAbbrev = $eSource->appendChild($eSAbbrev);
     }
     if (($note = get_sub_record($level, $level . " NOTE", $sourceRec)) != null) {
         $this->create_note($eSource, $note, $level);
     }
     $num = 1;
     while (($nameSource = get_sub_record(1, "1 OBJE", $sourceRec, $num)) != null) {
         $this->create_mediaref($this->eSources, $nameSource, 1, $done);
         $num++;
     }
     $eSource = $this->eSources->appendChild($eSource);
 }
Example #21
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 
        }
    }
Example #22
0
     } else {
         $prev_tags[$fact] = 1;
     }
     $subrec = get_sub_record(1, "1 {$fact}", $gedrec1, $prev_tags[$fact]);
     $facts1[] = array("fact" => $fact, "subrec" => trim($subrec));
 }
 $prev_tags = array();
 $ct = preg_match_all("/\n1 (\\w+)/", $gedrec2, $match, PREG_SET_ORDER);
 for ($i = 0; $i < $ct; $i++) {
     $fact = trim($match[$i][1]);
     if (isset($prev_tags[$fact])) {
         $prev_tags[$fact]++;
     } else {
         $prev_tags[$fact] = 1;
     }
     $subrec = get_sub_record(1, "1 {$fact}", $gedrec2, $prev_tags[$fact]);
     $facts2[] = array("fact" => $fact, "subrec" => trim($subrec));
 }
 if ($action == "select") {
     print "<h2>" . $pgv_lang["merge_step2"] . "</h2>\n";
     print "<form method=\"post\" action=\"edit_merge.php\">\n";
     print $pgv_lang["merge_facts_same"] . "<br />\n";
     print "<input type=\"hidden\" name=\"gid1\" value=\"{$gid1}\">\n";
     print "<input type=\"hidden\" name=\"gid2\" value=\"{$gid2}\">\n";
     print "<input type=\"hidden\" name=\"ged\" value=\"{$GEDCOM}\">\n";
     print "<input type=\"hidden\" name=\"ged2\" value=\"{$ged2}\">\n";
     print "<input type=\"hidden\" name=\"action\" value=\"merge\">\n";
     $equal_count = 0;
     $skip1 = array();
     $skip2 = array();
     print "<table border=\"1\">\n";
Example #23
0
 if (!empty($xref1)) {
     $gedrec = find_updated_record($xref1);
     if (!$gedrec) {
         $gedrec = find_gedcom_record($xref1);
         if ($gedrec) {
             preg_match("/0 @(.*)@ (.*)/", $gedrec, $match);
             $type = trim($match[2]);
             if (!displayDetailsById($xref1, $type)) {
                 //-- do not have full access to this record, so privatize it
                 $gedrec = privatize_gedcom($gedrec);
             } else {
                 if ($view == 'version' || $view == 'change') {
                     $chan = get_gedcom_value('CHAN', 1, $gedrec);
                     if (empty($chan)) {
                         $head = find_gedcom_record("HEAD");
                         $head_date = get_sub_record(1, "1 DATE", $head);
                         $lines = explode("\n", $head_date);
                         $head_date = "";
                         foreach ($lines as $line) {
                             $num = $line[0];
                             $head_date .= $num + 1 . substr($line, 1) . "\n";
                         }
                         $chan = "1 CHAN\n" . $head_date;
                     }
                     $gedrec = '0 @' . $xref1 . '@ ' . $type . "\n" . $chan;
                 }
             }
             if (!empty($gedrec)) {
                 $gedrecords = $gedrecords . "\n" . trim($gedrec);
             }
         }
Example #24
0
function print_gedcom_stats($block = true, $config = '', $side, $index)
{
    global $PGV_BLOCKS, $pgv_lang, $ALLOW_CHANGE_GEDCOM, $ctype, $COMMON_NAMES_THRESHOLD, $PGV_IMAGE_DIR, $PGV_IMAGES, $MULTI_MEDIA;
    global $top10_block_present;
    if (empty($config)) {
        $config = $PGV_BLOCKS['print_gedcom_stats']['config'];
    }
    if (!isset($config['stat_indi'])) {
        $config = $PGV_BLOCKS['print_gedcom_stats']['config'];
    }
    if (!isset($config['stat_first_death'])) {
        $config['stat_first_death'] = $PGV_BLOCKS['print_gedcom_stats']['config']['stat_first_death'];
    }
    if (!isset($config['stat_last_death'])) {
        $config['stat_last_death'] = $PGV_BLOCKS['print_gedcom_stats']['config']['stat_last_death'];
    }
    if (!isset($config['stat_media'])) {
        $config['stat_media'] = $PGV_BLOCKS['print_gedcom_stats']['config']['stat_media'];
    }
    if (!isset($config['stat_link'])) {
        $config['stat_link'] = $PGV_BLOCKS['print_gedcom_stats']['config']['stat_link'];
    }
    $id = 'gedcom_stats';
    $title = print_help_link('index_stats_help', 'qm', '', false, true);
    if ($PGV_BLOCKS['print_gedcom_stats']['canconfig']) {
        if ($ctype == 'gedcom' && PGV_USER_GEDCOM_ADMIN || $ctype == 'user' && PGV_USER_ID) {
            if ($ctype == 'gedcom') {
                $name = PGV_GEDCOM;
            } else {
                $name = PGV_USER_NAME;
            }
            $title .= "<a href=\"javascript: configure block\" onclick=\"window.open('" . encode_url("index_edit.php?name={$name}&ctype={$ctype}&action=configure&side={$side}&index={$index}") . "', '_blank', 'top=50,left=50,width=700,height=400,scrollbars=1,resizable=1'); return false;\">";
            $title .= "<img class=\"adminicon\" src=\"{$PGV_IMAGE_DIR}/" . $PGV_IMAGES['admin']['small'] . "\" width=\"15\" height=\"15\" border=\"0\" alt=\"" . $pgv_lang['config_block'] . "\" /></a>";
        }
    }
    $title .= $pgv_lang['gedcom_stats'];
    $stats = new stats(PGV_GEDCOM);
    $content = "<b><a href=\"index.php?ctype=gedcom\">" . PrintReady(strip_tags(get_gedcom_setting(PGV_GED_ID, 'title'))) . "</a></b><br />";
    $head = find_other_record('HEAD', PGV_GED_ID);
    $ct = preg_match('/1 SOUR (.*)/', $head, $match);
    if ($ct > 0) {
        $softrec = get_sub_record(1, '1 SOUR', $head);
        $tt = preg_match('/2 NAME (.*)/', $softrec, $tmatch);
        if ($tt > 0) {
            $software = printReady(trim($tmatch[1]));
        } else {
            $software = trim($match[1]);
        }
        if (!empty($software)) {
            $text = str_replace(array('#SOFTWARE#', '#CREATED_SOFTWARE#'), $software, $pgv_lang['gedcom_created_using']);
            $tt = preg_match('/2 VERS (.*)/', $softrec, $tmatch);
            if ($tt > 0) {
                $version = printReady(trim($tmatch[1]));
            } else {
                $version = '';
            }
            $text = str_replace(array('#VERSION#', '#CREATED_VERSION#'), $version, $text);
            $content .= $text;
        }
    }
    if (preg_match('/1 DATE (.+)/', $head, $match)) {
        if (empty($software)) {
            $content .= str_replace(array('#DATE#', '#CREATED_DATE#'), $stats->gedcomDate(), $pgv_lang['gedcom_created_on']);
        } else {
            $content .= str_replace(array('#DATE#', '#CREATED_DATE#'), $stats->gedcomDate(), $pgv_lang['gedcom_created_on2']);
        }
    }
    $content .= '<br /><table><tr><td valign="top" class="width20"><table cellspacing="1" cellpadding="0">';
    if ($config['stat_indi'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_individuals'] . '</td><td class="facts_value"><div dir="rtl"><a href="' . encode_url("indilist.php?surname_sublist=no&ged=" . PGV_GEDCOM) . '">' . $stats->totalIndividuals() . '</a></div></td></tr>';
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_males'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->totalSexMales() . '<br />' . $stats->totalSexMalesPercentage() . '%</div></td></tr>';
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_females'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->totalSexFemales() . '<br />' . $stats->totalSexFemalesPercentage() . '%</div></td></tr>';
    }
    if ($config['stat_surname'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_surnames'] . '</td><td class="facts_value"><div dir="rtl"><a href="' . encode_url("indilist.php?show_all=yes&surname_sublist=yes&ged=" . PGV_GEDCOM) . '">' . $stats->totalSurnames() . '</a></div></td></tr>';
    }
    if ($config['stat_fam'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_families'] . '</td><td class="facts_value"><div dir="rtl"><a href="famlist.php">' . $stats->totalFamilies() . '</a></div></td></tr>';
    }
    if ($config['stat_sour'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_sources'] . '</td><td class="facts_value"><div dir="rtl"><a href="sourcelist.php">' . $stats->totalSources() . '</a></div></td></tr>';
    }
    if ($config['stat_media'] == 'yes' && $MULTI_MEDIA == true) {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_media'] . '</td><td class="facts_value"><div dir="rtl"><a href="medialist.php">' . $stats->totalMedia() . '</a></div></td></tr>';
    }
    if ($config['stat_other'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_other'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->totalOtherRecords() . '</div></td></tr>';
    }
    if ($config['stat_events'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_events'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->totalEvents() . '</div></td></tr>';
    }
    if ($config['stat_users'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_users'] . '</td><td class="facts_value"><div dir="rtl">';
        if (PGV_USER_GEDCOM_ADMIN) {
            $content .= '<a href="useradmin.php">' . $stats->totalUsers() . '</a>';
        } else {
            $content .= $stats->totalUsers();
        }
        $content .= '</div>
</td>
</tr>';
    }
    if (!$block) {
        $content .= '</table></td><td><br /></td><td valign="top"><table cellspacing="1" cellpadding="1" border="0">';
    }
    if ($config['stat_first_birth'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_earliest_birth'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->firstBirthYear() . '</div></td>';
        if (!$block) {
            $content .= '<td class="facts_value">' . $stats->firstBirth() . '</td>';
        }
        $content .= '</tr>';
    }
    if ($config['stat_last_birth'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_latest_birth'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->lastBirthYear() . '</div></td>';
        if (!$block) {
            $content .= '<td class="facts_value">' . $stats->lastBirth() . '</td>';
        }
        $content .= '</tr>';
    }
    if ($config['stat_first_death'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_earliest_death'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->firstDeathYear() . '</div></td>';
        if (!$block) {
            $content .= '<td class="facts_value">' . $stats->firstDeath() . '</td>';
        }
        $content .= '</tr>';
    }
    if ($config['stat_last_death'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_latest_death'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->lastDeathYear() . '</div>
</td>';
        if (!$block) {
            $content .= '<td class="facts_value">' . $stats->lastDeath() . '</td>';
        }
        $content .= '</tr>';
    }
    if ($config['stat_long_life'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_longest_life'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->LongestLifeAge() . '</div></td>';
        if (!$block) {
            $content .= '<td class="facts_value">' . $stats->LongestLife() . '</td>';
        }
        $content .= '</tr>';
    }
    if ($config['stat_avg_life'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_avg_age_at_death'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->averageLifespan() . '</div></td>';
        if (!$block) {
            $content .= '<td class="facts_value">' . $pgv_lang['stat_males'] . ':&nbsp;' . $stats->averageLifespanMale();
            $content .= '&nbsp;&nbsp;&nbsp;' . $pgv_lang['stat_females'] . ':&nbsp;' . $stats->averageLifespanFemale() . '</td>';
        }
        $content .= '</tr>';
    }
    if ($config['stat_most_chil'] == 'yes' && !$block) {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_most_children'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->largestFamilySize() . '</div></td>';
        if (!$block) {
            $content .= '<td class="facts_value">' . $stats->largestFamily() . '</td>';
        }
        $content .= '</tr>';
    }
    if ($config['stat_avg_chil'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_average_children'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->averageChildren() . '</div></td>';
        if (!$block) {
            $content .= '<td class="facts_value">&nbsp;</td>';
        }
        $content .= '</tr>';
    }
    $content .= '</table></td></tr></table>';
    if ($config['stat_link'] == 'yes') {
        $content .= '<a href="statistics.php"><b>' . $pgv_lang['stat_link'] . '</b></a><br />';
    }
    // NOTE: Print the most common surnames
    if ($config['show_common_surnames'] == 'yes') {
        $surnames = get_common_surnames($COMMON_NAMES_THRESHOLD);
        if (count($surnames) > 0) {
            $content .= '<br />';
            $content .= print_help_link('index_common_names_help', 'qm', '', false, true);
            $content .= '<b>' . $pgv_lang['common_surnames'] . '</b><br />';
            $i = 0;
            foreach ($surnames as $indexval => $surname) {
                if (stristr($surname['name'], '@N.N') === false) {
                    if ($i > 0) {
                        $content .= ', ';
                    }
                    $content .= '<a href="' . encode_url("indilist.php?ged=" . PGV_GEDCOM . "&surname=" . $surname['name']) . '">' . PrintReady($surname['name']) . '</a>';
                    $i++;
                }
            }
        }
    }
    global $THEME_DIR;
    if ($block) {
        require $THEME_DIR . 'templates/block_small_temp.php';
    } else {
        require $THEME_DIR . 'templates/block_main_temp.php';
    }
}
Example #25
0
 function init()
 {
     global $PRIV_HIDE, $PRIV_PUBLIC, $ENABLE_CLIPPINGS_CART, $SCRIPT_NAME, $pgv_lang, $SERVER_URL, $CONTACT_EMAIL, $HOME_SITE_TEXT, $HOME_SITE_URL, $MEDIA_DIRECTORY;
     global $GEDCOM, $CHARACTER_SET, $cart;
     if (!isset($ENABLE_CLIPPINGS_CART)) {
         $ENABLE_CLIPPINGS_CART = $PRIV_HIDE;
     }
     if ($ENABLE_CLIPPINGS_CART === true) {
         $ENABLE_CLIPPING_CART = $PRIV_PUBLIC;
     }
     if ($ENABLE_CLIPPINGS_CART < PGV_USER_ACCESS_LEVEL) {
         header("Location: index.php");
         exit;
     }
     if (!isset($_SESSION['exportConvPath'])) {
         $_SESSION['exportConvPath'] = $MEDIA_DIRECTORY;
     }
     if (!isset($_SESSION['exportConvSlashes'])) {
         $_SESSION['exportConvSlashes'] = 'forward';
     }
     $this->action = safe_GET("action");
     $this->id = safe_GET('id');
     $remove = safe_GET('remove', "", "no");
     $convert = safe_GET('convert', "", "no");
     $this->Zip = safe_GET('Zip');
     $this->IncludeMedia = safe_GET('IncludeMedia');
     $this->conv_path = safe_GET('conv_path', PGV_REGEX_NOSCRIPT, $_SESSION['exportConvPath']);
     $this->conv_slashes = safe_GET('conv_slashes', array('forward', 'backward'), $_SESSION['exportConvSlashes']);
     $this->privatize_export = safe_GET('privatize_export', array('none', 'visitor', 'user', 'gedadmin', 'admin'));
     $this->filetype = safe_GET('filetype');
     $this->level1 = safe_GET('level1');
     $this->level2 = safe_GET('level2');
     $this->level3 = safe_GET('level3');
     if (empty($this->filetype)) {
         $this->filetype = "gedcom";
     }
     $others = safe_GET('others');
     $item = safe_GET('item');
     if (!isset($cart)) {
         $cart = $_SESSION['cart'];
     }
     $this->type = safe_GET('type');
     $this->conv_path = stripLRMRLM($this->conv_path);
     $_SESSION['exportConvPath'] = $this->conv_path;
     // remember this for the next Download
     $_SESSION['exportConvSlashes'] = $this->conv_slashes;
     if ($this->action == 'add') {
         if (empty($this->type) && !empty($this->id)) {
             $this->type = "";
             $obj = GedcomRecord::getInstance($this->id);
             if (is_null($obj)) {
                 $this->id = "";
                 $this->action = "";
             } else {
                 $this->type = strtolower($obj->getType());
             }
         } else {
             if (empty($this->id)) {
                 $this->action = "";
             }
         }
         if (!empty($this->id) && $this->type != 'fam' && $this->type != 'indi' && $this->type != 'sour') {
             $this->action = 'add1';
         }
     }
     if ($this->action == 'add1') {
         $clipping = array();
         $clipping['type'] = $this->type;
         $clipping['id'] = $this->id;
         $clipping['gedcom'] = $GEDCOM;
         $ret = $this->add_clipping($clipping);
         if ($ret) {
             if ($this->type == 'sour') {
                 if ($others == 'linked') {
                     foreach (fetch_linked_indi($this->id, 'SOUR', PGV_GED_ID) as $indi) {
                         if ($indi->canDisplayName()) {
                             $this->add_clipping(array('type' => 'indi', 'id' => $indi->getXref()));
                         }
                     }
                     foreach (fetch_linked_fam($this->id, 'SOUR', PGV_GED_ID) as $fam) {
                         if ($fam->canDisplayName()) {
                             $this->add_clipping(array('type' => 'fam', 'id' => $fam->getXref()));
                         }
                     }
                 }
             }
             if ($this->type == 'fam') {
                 if ($others == 'parents') {
                     $parents = find_parents($this->id);
                     if (!empty($parents["HUSB"])) {
                         $clipping = array();
                         $clipping['type'] = "indi";
                         $clipping['id'] = $parents["HUSB"];
                         $ret = $this->add_clipping($clipping);
                     }
                     if (!empty($parents["WIFE"])) {
                         $clipping = array();
                         $clipping['type'] = "indi";
                         $clipping['id'] = $parents["WIFE"];
                         $ret = $this->add_clipping($clipping);
                     }
                 } else {
                     if ($others == "members") {
                         $this->add_family_members($this->id);
                     } else {
                         if ($others == "descendants") {
                             $this->add_family_descendancy($this->id);
                         }
                     }
                 }
             } else {
                 if ($this->type == 'indi') {
                     if ($others == 'parents') {
                         $famids = find_family_ids($this->id);
                         foreach ($famids as $indexval => $famid) {
                             $clipping = array();
                             $clipping['type'] = "fam";
                             $clipping['id'] = $famid;
                             $ret = $this->add_clipping($clipping);
                             if ($ret) {
                                 $this->add_family_members($famid);
                             }
                         }
                     } else {
                         if ($others == 'ancestors') {
                             $this->add_ancestors_to_cart($this->id, $this->level1);
                         } else {
                             if ($others == 'ancestorsfamilies') {
                                 $this->add_ancestors_to_cart_families($this->id, $this->level2);
                             } else {
                                 if ($others == 'members') {
                                     $famids = find_sfamily_ids($this->id);
                                     foreach ($famids as $indexval => $famid) {
                                         $clipping = array();
                                         $clipping['type'] = "fam";
                                         $clipping['id'] = $famid;
                                         $ret = $this->add_clipping($clipping);
                                         if ($ret) {
                                             $this->add_family_members($famid);
                                         }
                                     }
                                 } else {
                                     if ($others == 'descendants') {
                                         $famids = find_sfamily_ids($this->id);
                                         foreach ($famids as $indexval => $famid) {
                                             $clipping = array();
                                             $clipping['type'] = "fam";
                                             $clipping['id'] = $famid;
                                             $ret = $this->add_clipping($clipping);
                                             if ($ret) {
                                                 $this->add_family_descendancy($famid, $this->level3);
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     } else {
         if ($this->action == 'remove') {
             $ct = count($cart);
             for ($i = $item + 1; $i < $ct; $i++) {
                 $cart[$i - 1] = $cart[$i];
             }
             unset($cart[$ct - 1]);
         } else {
             if ($this->action == 'empty') {
                 $cart = array();
                 $_SESSION["cart"] = $cart;
             } else {
                 if ($this->action == 'download') {
                     usort($cart, "same_group");
                     if ($this->filetype == "gedcom") {
                         $path = substr($SCRIPT_NAME, 0, strrpos($SCRIPT_NAME, "/"));
                         if (empty($path)) {
                             $path = "/";
                         }
                         if ($path[strlen($path) - 1] != "/") {
                             $path .= "/";
                         }
                         if ($SERVER_URL[strlen($SERVER_URL) - 1] == "/") {
                             $dSERVER_URL = substr($SERVER_URL, 0, strlen($SERVER_URL) - 1);
                         } else {
                             $dSERVER_URL = $SERVER_URL;
                         }
                         $media = array();
                         $mediacount = 0;
                         $ct = count($cart);
                         $filetext = "0 HEAD\n1 SOUR " . PGV_PHPGEDVIEW . "\n2 NAME " . PGV_PHPGEDVIEW . "\n2 VERS " . PGV_VERSION_TEXT . "\n1 DEST DISKETTE\n1 DATE " . date("j M Y") . "\n2 TIME " . date("H:i:s") . "\n";
                         $filetext .= "1 GEDC\n2 VERS 5.5\n2 FORM LINEAGE-LINKED\n1 CHAR {$CHARACTER_SET}\n";
                         $head = find_gedcom_record("HEAD");
                         $placeform = trim(get_sub_record(1, "1 PLAC", $head));
                         if (!empty($placeform)) {
                             $filetext .= $placeform . "\n";
                         } else {
                             $filetext .= "1 PLAC\n2 FORM " . "City, County, State/Province, Country" . "\n";
                         }
                         if ($convert == "yes") {
                             $filetext = preg_replace("/UTF-8/", "ANSI", $filetext);
                             $filetext = utf8_decode($filetext);
                         }
                         $tempUserID = '#ExPoRt#';
                         if ($this->privatize_export != 'none') {
                             // Create a temporary userid
                             $export_user_id = createTempUser($tempUserID, $this->privatize_export, $GEDCOM);
                             // Create a temporary userid
                             // Temporarily become this user
                             $_SESSION["org_user"] = $_SESSION["pgv_user"];
                             $_SESSION["pgv_user"] = $tempUserID;
                         }
                         for ($i = 0; $i < $ct; $i++) {
                             $clipping = $cart[$i];
                             if ($clipping['gedcom'] == $GEDCOM) {
                                 $record = find_gedcom_record($clipping['id']);
                                 $savedRecord = $record;
                                 // Save this for the "does this file exist" check
                                 if ($clipping['type'] == 'obje') {
                                     $record = convert_media_path($record, $this->conv_path, $this->conv_slashes);
                                 }
                                 $record = privatize_gedcom($record);
                                 $record = remove_custom_tags($record, $remove);
                                 if ($convert == "yes") {
                                     $record = utf8_decode($record);
                                 }
                                 switch ($clipping['type']) {
                                     case 'indi':
                                         $ft = preg_match_all("/1 FAMC @(.*)@/", $record, $match, PREG_SET_ORDER);
                                         for ($k = 0; $k < $ft; $k++) {
                                             if (!id_in_cart($match[$k][1])) {
                                                 $record = preg_replace("/1 FAMC @" . $match[$k][1] . "@.*/", "", $record);
                                             }
                                         }
                                         $ft = preg_match_all("/1 FAMS @(.*)@/", $record, $match, PREG_SET_ORDER);
                                         for ($k = 0; $k < $ft; $k++) {
                                             if (!id_in_cart($match[$k][1])) {
                                                 $record = preg_replace("/1 FAMS @" . $match[$k][1] . "@.*/", "", $record);
                                             }
                                         }
                                         $ft = preg_match_all("/\\d FILE (.*)/", $savedRecord, $match, PREG_SET_ORDER);
                                         for ($k = 0; $k < $ft; $k++) {
                                             $filename = $MEDIA_DIRECTORY . extract_filename(trim($match[$k][1]));
                                             if (file_exists($filename)) {
                                                 $media[$mediacount] = array(PCLZIP_ATT_FILE_NAME => $filename);
                                                 $mediacount++;
                                             }
                                             //								$record = preg_replace("|(\d FILE )" . addslashes($match[$k][1]) . "|", "$1" . $filename, $record);
                                         }
                                         $filetext .= trim($record) . "\n";
                                         $filetext .= "1 SOUR @SPGV1@\n";
                                         $filetext .= "2 PAGE " . $dSERVER_URL . "/individual.php?pid=" . $clipping['id'] . "\n";
                                         $filetext .= "2 DATA\n";
                                         $filetext .= "3 TEXT " . $pgv_lang["indi_downloaded_from"] . "\n";
                                         $filetext .= "4 CONT " . $dSERVER_URL . "/individual.php?pid=" . $clipping['id'] . "\n";
                                         break;
                                     case 'fam':
                                         $ft = preg_match_all("/1 CHIL @(.*)@/", $record, $match, PREG_SET_ORDER);
                                         for ($k = 0; $k < $ft; $k++) {
                                             if (!id_in_cart($match[$k][1])) {
                                                 /* if the child is not in the list delete the record of it */
                                                 $record = preg_replace("/1 CHIL @" . $match[$k][1] . "@.*/", "", $record);
                                             }
                                         }
                                         $ft = preg_match_all("/1 HUSB @(.*)@/", $record, $match, PREG_SET_ORDER);
                                         for ($k = 0; $k < $ft; $k++) {
                                             if (!id_in_cart($match[$k][1])) {
                                                 /* if the husband is not in the list delete the record of him */
                                                 $record = preg_replace("/1 HUSB @" . $match[$k][1] . "@.*/", "", $record);
                                             }
                                         }
                                         $ft = preg_match_all("/1 WIFE @(.*)@/", $record, $match, PREG_SET_ORDER);
                                         for ($k = 0; $k < $ft; $k++) {
                                             if (!id_in_cart($match[$k][1])) {
                                                 /* if the wife is not in the list delete the record of her */
                                                 $record = preg_replace("/1 WIFE @" . $match[$k][1] . "@.*/", "", $record);
                                             }
                                         }
                                         $ft = preg_match_all("/\\d FILE (.*)/", $savedRecord, $match, PREG_SET_ORDER);
                                         for ($k = 0; $k < $ft; $k++) {
                                             $filename = $MEDIA_DIRECTORY . extract_filename(trim($match[$k][1]));
                                             if (file_exists($filename)) {
                                                 $media[$mediacount] = array(PCLZIP_ATT_FILE_NAME => $filename);
                                                 $mediacount++;
                                             }
                                             //								$record = preg_replace("|(\d FILE )" . addslashes($match[$k][1]) . "|", "$1" . $filename, $record);
                                         }
                                         $filetext .= trim($record) . "\n";
                                         $filetext .= "1 SOUR @SPGV1@\n";
                                         $filetext .= "2 PAGE " . $dSERVER_URL . $path . "family.php?famid=" . $clipping['id'] . "\n";
                                         $filetext .= "2 DATA\n";
                                         $filetext .= "3 TEXT " . $pgv_lang["family_downloaded_from"] . "\n";
                                         $filetext .= "4 CONT " . $dSERVER_URL . "/family.php?famid=" . $clipping['id'] . "\n";
                                         break;
                                     case 'source':
                                         $ft = preg_match_all("/\\d FILE (.*)/", $savedRecord, $match, PREG_SET_ORDER);
                                         for ($k = 0; $k < $ft; $k++) {
                                             $filename = $MEDIA_DIRECTORY . extract_filename(trim($match[$k][1]));
                                             if (file_exists($filename)) {
                                                 $media[$mediacount] = array(PCLZIP_ATT_FILE_NAME => $filename);
                                                 $mediacount++;
                                             }
                                             //								$record = preg_replace("|(\d FILE )" . addslashes($match[$k][1]) . "|", "$1" . $filename, $record);
                                         }
                                         $filetext .= trim($record) . "\n";
                                         $filetext .= "1 NOTE " . $pgv_lang["source_downloaded_from"] . "\n";
                                         $filetext .= "2 CONT " . $dSERVER_URL . "/source.php?sid=" . $clipping['id'] . "\n";
                                         break;
                                     default:
                                         $ft = preg_match_all("/\\d FILE (.*)/", $savedRecord, $match, PREG_SET_ORDER);
                                         for ($k = 0; $k < $ft; $k++) {
                                             $filename = $MEDIA_DIRECTORY . extract_filename(trim($match[$k][1]));
                                             if (file_exists($filename)) {
                                                 $media[$mediacount] = array(PCLZIP_ATT_FILE_NAME => $filename);
                                                 $mediacount++;
                                             }
                                             //								$record = preg_replace("|(\d FILE )" . addslashes($match[$k][1]) . "|", "$1" . $filename, $record);
                                         }
                                         $filetext .= trim($record) . "\n";
                                         break;
                                 }
                             }
                         }
                         if ($this->privatize_export != 'none') {
                             $_SESSION["pgv_user"] = $_SESSION["org_user"];
                             delete_user($export_user_id);
                             AddToLog("deleted dummy user -> {$tempUserID} <-");
                         }
                         if ($this->IncludeMedia == "yes") {
                             $this->media_list = $media;
                         }
                         $filetext .= "0 @SPGV1@ SOUR\n";
                         if ($user_id = get_user_id($CONTACT_EMAIL)) {
                             $filetext .= "1 AUTH " . getUserFullName($user_id) . "\n";
                         }
                         $filetext .= "1 TITL " . $HOME_SITE_TEXT . "\n";
                         $filetext .= "1 ABBR " . $HOME_SITE_TEXT . "\n";
                         $filetext .= "1 PUBL " . $HOME_SITE_URL . "\n";
                         $filetext .= "0 TRLR\n";
                         //-- make sure the preferred line endings are used
                         $filetext = preg_replace("/[\r\n]+/", PGV_EOL, $filetext);
                         $this->download_data = $filetext;
                         $this->download_clipping();
                     } else {
                         if ($this->filetype == "gramps") {
                             // Sort the clippings cart because the export works better when the cart is sorted
                             usort($cart, "same_group");
                             require_once "includes/classes/class_geclippings.php";
                             $gramps_Exp = new GEClippings();
                             $gramps_Exp->begin_xml();
                             $ct = count($cart);
                             usort($cart, "same_group");
                             for ($i = 0; $i < $ct; $i++) {
                                 $clipping = $cart[$i];
                                 switch ($clipping['type']) {
                                     case 'indi':
                                         $rec = find_person_record($clipping['id']);
                                         $rec = remove_custom_tags($rec, $remove);
                                         if ($this->privatize_export != 'none') {
                                             $rec = privatize_gedcom($rec);
                                         }
                                         $gramps_Exp->create_person($rec, $clipping['id']);
                                         break;
                                     case 'fam':
                                         $rec = find_family_record($clipping['id']);
                                         $rec = remove_custom_tags($rec, $remove);
                                         if ($this->privatize_export != 'none') {
                                             $rec = privatize_gedcom($rec);
                                         }
                                         $gramps_Exp->create_family($rec, $clipping['id']);
                                         break;
                                     case 'source':
                                         $rec = find_source_record($clipping['id']);
                                         $rec = remove_custom_tags($rec, $remove);
                                         if ($this->privatize_export != 'none') {
                                             $rec = privatize_gedcom($rec);
                                         }
                                         $gramps_Exp->create_source($rec, $clipping['id']);
                                         break;
                                 }
                             }
                             $this->download_data = $gramps_Exp->dom->saveXML();
                             if ($convert) {
                                 $this->download_data = utf8_decode($this->download_data);
                             }
                             $this->media_list = $gramps_Exp->get_all_media();
                             $this->download_clipping();
                         }
                     }
                 }
             }
         }
     }
 }
Example #26
0
 /**
  * parse marriage record
  */
 function _parseMarriageRecord()
 {
     $this->marriage = new Event(trim(get_sub_record(1, "1 MARR", $this->gedrec)), -1);
     $this->marriage->setParentObject($this);
 }
function print_main_notes(WT_Fact $fact, $level)
{
    global $WT_TREE, $SHOW_FACT_ICONS;
    $factrec = $fact->getGedcom();
    $fact_id = $fact->getFactId();
    $parent = $fact->getParent();
    $pid = $parent->getXref();
    if ($fact->isNew()) {
        $styleadd = ' new';
        $can_edit = $level == 1 && $fact->canEdit();
    } elseif ($fact->isOld()) {
        $styleadd = ' old';
        $can_edit = false;
    } else {
        $styleadd = '';
        $can_edit = $level == 1 && $fact->canEdit();
    }
    $ct = preg_match_all("/{$level} NOTE (.*)/", $factrec, $match, PREG_SET_ORDER);
    for ($j = 0; $j < $ct; $j++) {
        // Note object, or inline note?
        if (preg_match("/{$level} NOTE @(.*)@/", $match[$j][0], $nmatch)) {
            $note = WT_Note::getInstance($nmatch[1]);
            if ($note && !$note->canShow()) {
                continue;
            }
        } else {
            $note = null;
        }
        if ($level >= 2) {
            echo '<tr class="row_note2"><td class="descriptionbox rela ', $styleadd, ' width20">';
        } else {
            echo '<tr><td class="descriptionbox ', $styleadd, ' width20">';
        }
        if ($can_edit) {
            echo '<a onclick="return edit_record(\'', $pid, '\', \'', $fact_id, '\');" href="#" title="', WT_I18N::translate('Edit'), '">';
            if ($level < 2) {
                if ($SHOW_FACT_ICONS) {
                    echo '<i class="icon-note"></i> ';
                }
                if ($note) {
                    echo WT_Gedcom_Tag::getLabel('SHARED_NOTE');
                } else {
                    echo WT_Gedcom_Tag::getLabel('NOTE');
                }
                echo '</a>';
                echo '<div class="editfacts">';
                echo "<div class=\"editlink\"><a class=\"editicon\" onclick=\"return edit_record('{$pid}', '{$fact_id}');\" href=\"#\" title=\"" . WT_I18N::translate('Edit') . "\"><span class=\"link_text\">" . WT_I18N::translate('Edit') . "</span></a></div>";
                echo '<div class="copylink"><a class="copyicon" href="#" onclick="return copy_fact(\'', $pid, '\', \'', $fact_id, '\');" title="' . WT_I18N::translate('Copy') . '"><span class="link_text">' . WT_I18N::translate('Copy') . '</span></a></div>';
                echo "<div class=\"deletelink\"><a class=\"deleteicon\" onclick=\"return delete_fact('" . WT_I18N::translate('Are you sure you want to delete this fact?') . "', '{$pid}', '{$fact_id}');\" href=\"#\" title=\"" . WT_I18N::translate('Delete') . "\"><span class=\"link_text\">" . WT_I18N::translate('Delete') . "</span></a></div>";
                if ($note) {
                    echo '<a class="icon-note" href="', $note->getHtmlUrl(), '" title="' . WT_I18N::translate('View') . '"><span class="link_text">' . WT_I18N::translate('View') . '</span></a>';
                }
                echo '</div>';
            }
        } else {
            if ($level < 2) {
                if ($SHOW_FACT_ICONS) {
                    echo '<i class="icon-note"></i> ';
                }
                if ($note) {
                    echo WT_Gedcom_Tag::getLabel('SHARED_NOTE');
                } else {
                    echo WT_Gedcom_Tag::getLabel('NOTE');
                }
            }
            $factlines = explode("\n", $factrec);
            // 1 BIRT Y\n2 NOTE ...
            $factwords = explode(" ", $factlines[0]);
            // 1 BIRT Y
            $factname = $factwords[1];
            // BIRT
            $parent = WT_GedcomRecord::getInstance($pid);
            if ($factname == 'EVEN' || $factname == 'FACT') {
                // Add ' EVEN' to provide sensible output for an event with an empty TYPE record
                $ct = preg_match("/2 TYPE (.*)/", $factrec, $ematch);
                if ($ct > 0) {
                    $factname = trim($ematch[1]);
                    echo $factname;
                } else {
                    echo WT_Gedcom_Tag::getLabel($factname, $parent);
                }
            } else {
                if ($factname != 'NOTE') {
                    // Note is already printed
                    echo WT_Gedcom_Tag::getLabel($factname, $parent);
                    if ($note) {
                        echo '<div class="editfacts"><a class="icon-note" href="', $note->getHtmlUrl(), '" title="' . WT_I18N::translate('View') . '"><span class="link_text">' . WT_I18N::translate('View') . '</span></a></div>';
                    }
                }
            }
        }
        echo '</td>';
        if ($note) {
            // Note objects
            if (array_key_exists('GEDFact_assistant', WT_Module::getActiveModules())) {
                // If Census assistant installed, allow it to format the note
                $text = GEDFact_assistant_WT_Module::formatCensusNote($note);
            } else {
                $text = WT_Filter::formatText($note->getNote(), $WT_TREE);
            }
        } else {
            // Inline notes
            $nrec = get_sub_record($level, "{$level} NOTE", $factrec, $j + 1);
            $text = $match[$j][1] . get_cont($level + 1, $nrec);
            $text = WT_Filter::formatText($text, $WT_TREE);
        }
        echo '<td class="optionbox', $styleadd, ' wrap">';
        echo $text;
        if (!empty($noterec)) {
            echo print_fact_sources($noterec, 1);
        }
        // 2 RESN tags.  Note, there can be more than one, such as "privacy" and "locked"
        if (preg_match_all("/\n2 RESN (.+)/", $factrec, $matches)) {
            foreach ($matches[1] as $match) {
                echo '<br><span class="label">', WT_Gedcom_Tag::getLabel('RESN'), ':</span> <span class="field">';
                switch ($match) {
                    case 'none':
                        // Note: "2 RESN none" is not valid gedcom, and the GUI will not let you add it.
                        // However, webtrees privacy rules will interpret it as "show an otherwise private fact to public".
                        echo '<i class="icon-resn-none"></i> ', WT_I18N::translate('Show to visitors');
                        break;
                    case 'privacy':
                        echo '<i class="icon-resn-privacy"></i> ', WT_I18N::translate('Show to members');
                        break;
                    case 'confidential':
                        echo '<i class="icon-resn-confidential"></i> ', WT_I18N::translate('Show to managers');
                        break;
                    case 'locked':
                        echo '<i class="icon-resn-locked"></i> ', WT_I18N::translate('Only managers can edit');
                        break;
                    default:
                        echo $match;
                        break;
                }
                echo '</span>';
            }
        }
        echo '</td></tr>';
    }
}
 if (!empty($subrec)) {
     $ct = preg_match("/1 PHON (.*)/", $subrec, $match);
     if ($ct > 0) {
         $PHON = trim($match[1]);
     }
     $PHON .= get_cont(2, $subrec);
 }
 $EMAIL = "";
 $ct = preg_match("/1 (_?EMAIL) (.*)/", $gedrec, $match);
 if ($ct > 0) {
     $EMAIL = trim($match[2]);
     $subrec = get_sub_record(1, "1 " . $match[1], $gedrec);
     $EMAIL .= get_cont(2, $subrec);
 }
 $FAX = "";
 $subrec = get_sub_record(1, "1 FAX", $gedrec);
 if (!empty($subrec)) {
     $ct = preg_match("/1 FAX (.*)/", $subrec, $match);
     if ($ct > 0) {
         $FAX = trim($match[1]);
     }
     $FAX .= get_cont(2, $subrec);
 }
 $indifacts = array();
 $person = Person::getInstance($pid);
 $facts = $person->getIndiFacts();
 $repeat_tags = array();
 foreach ($facts as $event) {
     $fact = $event->getTag();
     if ($fact == "EVEN" || $fact == "FACT") {
         $fact = $event->getType();
Example #29
0
     // Insert the 1 FILE xxx record into the arrays used by function handle_updates()
     $glevels = array_merge(array("1"), $glevels);
     $tag = array_merge(array("FILE"), $tag);
     $islink = array_merge(array(0), $islink);
     $text = array_merge(array($folder . $filename), $text);
     if (!empty($pid)) {
         if (!isset($pgv_changes[$pid . "_" . $GEDCOM])) {
             $gedrec = find_gedcom_record($pid);
         } else {
             $gedrec = find_updated_record($pid);
         }
     }
     $newrec = "0 @{$pid}@ OBJE\n";
     $newrec = handle_updates($newrec);
     if (!$update_CHAN) {
         $newrec .= get_sub_record(1, "1 CHAN", $gedrec);
     }
     //print("[".$newrec."]");
     //-- look for the old record media in the file
     //-- if the old media record does not exist that means it was
     //-- generated at import and we need to append it
     if (replace_gedrec($pid, $newrec, $update_CHAN)) {
         AddToChangeLog("Media ID " . $pid . " successfully updated.");
     }
     if ($pid && $linktoid != "") {
         $link = linkMedia($pid, $linktoid, $level);
         if ($link) {
             AddToChangeLog("Media ID " . $pid . " successfully added to {$linktoid}.");
         }
     }
 }
Example #30
0
     break;
     //------------------------------------------------------------------------------
 //------------------------------------------------------------------------------
 case 'reorder_update':
     if (PGV_DEBUG) {
         phpinfo(INFO_VARIABLES);
     }
     if (isset($_REQUEST['order'])) {
         $order = $_REQUEST['order'];
     }
     asort($order);
     reset($order);
     $newgedrec = $gedrec;
     foreach ($order as $child => $num) {
         // move each child subrecord to the bottom, in the order specified
         $subrec = get_sub_record(1, "1 CHIL @" . $child . "@", $gedrec);
         $subrec = trim($subrec, "\n");
         if (PGV_DEBUG) {
             echo "<pre>[", $subrec, "]</pre>";
         }
         $newgedrec = str_replace($subrec, "", $newgedrec);
         $newgedrec .= "\n" . $subrec . "\n";
     }
     if (PGV_DEBUG) {
         echo "<pre>{$newgedrec}</pre>";
     }
     $success = replace_gedrec($pid, $newgedrec, $update_CHAN);
     if ($success) {
         echo "<br /><br />", $pgv_lang["update_successful"];
     }
     break;