示例#1
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
}
示例#2
0
/**
* @todo add info
* @param array $attrs an array of key value pairs for the attributes
* @see PGVRFactsEHandler()
*/
function PGVRFactsSHandler($attrs)
{
    global $repeats, $repeatsStack, $gedrec, $parser, $parserStack, $repeatBytes, $processRepeats, $vars;
    $processRepeats++;
    if ($processRepeats > 1) {
        return;
    }
    $families = 1;
    if (isset($attrs["families"])) {
        $families = $attrs["families"];
    }
    array_push($repeatsStack, array($repeats, $repeatBytes));
    $repeats = array();
    $repeatBytes = xml_get_current_line_number($parser);
    $id = "";
    $gmatch = array();
    $gt = preg_match("/0 @(.+)@/", $gedrec, $gmatch);
    if ($gt > 0) {
        $id = $gmatch[1];
    }
    $tag = "";
    if (isset($attrs["ignore"])) {
        $tag .= $attrs["ignore"];
    }
    $match = array();
    $ct = preg_match("/\\\$(.+)/", $tag, $match);
    if ($ct > 0) {
        $tag = $vars[$match[1]]["id"];
    }
    if (empty($attrs["diff"]) && !empty($id)) {
        $record = GedcomRecord::getInstance($id);
        $facts = $record->getFacts(explode(",", $tag));
        if (!is_array($facts)) {
            $facts = array($facts);
        }
        sort_facts($facts);
        $repeats = array();
        foreach ($facts as $event) {
            if (strpos($tag . ",", $event->getTag()) === false) {
                $repeats[] = $event->getGedComRecord();
            }
        }
    } else {
        global $nonfacts;
        $nonfacts = preg_split("/[\\s,;:]/", $tag);
        $record = new GedcomRecord($gedrec);
        switch ($record->getType()) {
            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 'NOTE':
                $record = new Note($gedrec);
                break;
        }
        $oldrecord = GedcomRecord::getInstance($record->getXref());
        $oldrecord->diffMerge($record);
        $facts = $oldrecord->getFacts();
        foreach ($facts as $fact) {
            if (strstr($fact->getGedcomRecord(), "PGV_NEW") !== false) {
                $repeats[] = $fact->getGedcomRecord();
            }
        }
    }
}