Beispiel #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;
}
/**
* import record into database
*
* this function will parse the given gedcom record and add it to the database
* @param string $gedrec the raw gedcom record to parse
* @param boolean $update whether or not this is an updated record that has been accepted
*/
function import_record($gedrec, $update)
{
    global $xtype, $TBLPREFIX, $GEDCOM_FILE, $FILE, $pgv_lang, $USE_RIN;
    global $place_id, $WORD_WRAPPED_NOTES, $GEDCOMS, $MAX_IDS, $fpnewged, $GEDCOM, $GENERATE_UIDS;
    global $gBitDb, $gGedcom;
    $FILE = $gGedcom->mGedcomName;
    // Escaped @ signs (only if importing from file)
    if (!$update) {
        $gedrec = str_replace('@@', '@', $gedrec);
    }
    // Standardise gedcom format
    $gedrec = reformat_record_import($gedrec);
    // import different types of records
    if (preg_match('/^0 @(' . PGV_REGEX_XREF . ')@ (' . PGV_REGEX_TAG . ')/', $gedrec, $match) > 0) {
        list(, $gid, $type) = $match;
        // check for a _UID, if the record doesn't have one, add one
        if ($GENERATE_UIDS && !strpos($gedrec, "\n1 _UID ")) {
            $gedrec .= "\n1 _UID " . uuid();
        }
    } elseif (preg_match('/0 (' . PGV_REGEX_TAG . ')/', $gedrec, $match)) {
        $gid = $match[1];
        $type = $match[1];
    } else {
        echo $pgv_lang['invalid_gedformat'], '<br /><pre>', $gedrec, '</pre>';
        return;
    }
    // keep track of the max id for each type as they are imported
    if (!isset($MAX_IDS)) {
        $MAX_IDS = array();
    }
    if (preg_match('/(\\d+)/', $gid, $match)) {
        $idnum = (int) $match[1];
    } else {
        $idnum = 0;
    }
    if (isset($MAX_IDS[$type])) {
        $MAX_IDS[$type] = max($MAX_IDS[$type], $idnum);
    } else {
        $MAX_IDS[$type] = $idnum;
    }
    $newrec = update_media($gid, $gedrec, $update);
    if ($newrec != $gedrec) {
        $gedrec = $newrec;
        // make sure we have the correct media id
        if (preg_match('/0 @(' . PGV_REGEX_XREF . ')@ (' . PGV_REGEX_TAG . ')/', $gedrec, $match)) {
            list(, $gid, $type) = $match;
        } else {
            echo $pgv_lang['invalid_gedformat'], '<br /><pre>', $gedrec, '</pre>';
            return;
        }
    }
    switch ($type) {
        case 'INDI':
            $record = new Person($gedrec);
            break;
        case 'FAM':
            $record = new Family($gedrec);
            break;
        case 'SOUR':
            $record = new Source($gedrec);
            break;
        case 'REPO':
            $record = new Repository($gedrec);
            break;
        case 'OBJE':
            $record = new Media($gedrec);
            break;
        default:
            $record = new GedcomRecord($gedrec);
            $type = $record->getType();
            break;
    }
    // Just in case the admin has blocked themself from seeing names!
    $record->disp = true;
    $record->dispname = true;
    // Update the cross-reference/index tables.
    $ged_id = $gGedcom->mGEDCOMId;
    $xref = $gid;
    update_places($xref, $ged_id, $gedrec);
    update_dates($xref, $ged_id, $gedrec);
    update_links($xref, $ged_id, $gedrec);
    update_rlinks($xref, $ged_id, $gedrec);
    update_names($xref, $ged_id, $record);
    switch ($type) {
        case 'INDI':
            if ($USE_RIN && preg_match('/\\n1 RIN (.+)/', $gedrec, $match)) {
                $rin = $match[1];
            } else {
                $rin = $xref;
            }
            $param = array($xref, $ged_id, $rin, is_dead($gedrec, '', true), $record->getSex(), $gedrec);
            $gBitDb->query("INSERT INTO {$TBLPREFIX}individuals (i_id, i_file, i_rin, i_isdead, i_sex, i_gedcom) VALUES (?,?,?,?,?,?)", $param);
            break;
        case 'FAM':
            if (preg_match('/\\n1 HUSB @(' . PGV_REGEX_XREF . ')@/', $gedrec, $match)) {
                $husb = $match[1];
            } else {
                $husb = '';
            }
            if (preg_match('/\\n1 WIFE @(' . PGV_REGEX_XREF . ')@/', $gedrec, $match)) {
                $wife = $match[1];
            } else {
                $wife = '';
            }
            if ($nchi = preg_match_all('/\\n1 CHIL @(' . PGV_REGEX_XREF . ')@/', $gedrec, $match)) {
                $chil = implode(';', $match[1]) . ';';
            } else {
                $chil = '';
            }
            if (preg_match('/\\n1 NCHI (\\d+)/', $gedrec, $match)) {
                $nchi = max($nchi, $match[1]);
            }
            $param = array($xref, $ged_id, $husb, $wife, $chil, $gedrec, $nchi);
            $gBitDb->query("INSERT INTO {$TBLPREFIX}families (f_id, f_file, f_husb, f_wife, f_chil, f_gedcom, f_numchil) VALUES (?,?,?,?,?,?,?)", $param);
            break;
        case 'SOUR':
            if (preg_match('/\\n1 TITL (.+)/', $gedrec, $match)) {
                $name = $match[1];
            } elseif (preg_match('/\\n1 ABBR (.+)/', $gedrec, $match)) {
                $name = $match[1];
            } else {
                $name = $gid;
            }
            if (strpos($gedrec, "\n1 _DBID")) {
                $_dbid = 'Y';
            } else {
                $_dbid = null;
            }
            $gBitDb->query("INSERT INTO {$TBLPREFIX}sources (s_id, s_file, s_name, s_gedcom, s_dbid) VALUES (?,?,?,?,?)", array($xref, $ged_id, $name, $gedrec, $_dbid));
            break;
        case 'OBJE':
            // OBJE records are imported by update_media function
            break;
        case 'HEAD':
            if (!strpos($gedrec, "\n1 DATE ")) {
                $gedrec .= "\n1 DATE " . date('j M Y');
            }
            // no break
        // no break
        default:
            if (substr($type, 0, 1) != '_') {
                $gBitDb->query("INSERT INTO {$TBLPREFIX}other (o_id, o_file, o_type, o_gedcom) VALUES (?,?,?,?)", array($xref, $ged_id, $type, $gedrec));
            }
            break;
    }
    // if this is not an update then write it to the new gedcom file
    if (!$update && !empty($fpnewged)) {
        fwrite($fpnewged, reformat_record_export($gedrec));
    }
    $xtype = $type;
    // Pass value back to uploadgedcom.php
}
Beispiel #3
0
 /**
  * Return whether or not this person is already dead
  * @return boolean true if dead, false if alive
  */
 function isDead()
 {
     if ($this->isdead == -1) {
         $this->isdead = is_dead($this->gedrec);
     }
     return $this->isdead;
 }