Exemplo n.º 1
0
function get_note_list($ged_id)
{
    $rows = WT_DB::prepare("SELECT o_id AS xref, o_file AS gedcom_id, o_gedcom AS gedcom FROM `##other` WHERE o_type='NOTE' AND o_file=?")->execute(array($ged_id))->fetchAll();
    $list = array();
    foreach ($rows as $row) {
        $list[] = WT_Note::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
    }
    usort($list, array('WT_GedcomRecord', 'compare'));
    return $list;
}
Exemplo n.º 2
0
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>';
    }
}
Exemplo n.º 3
0
 public function __construct()
 {
     $xref = WT_Filter::get('nid', WT_REGEX_XREF);
     $this->record = WT_Note::getInstance($xref);
     parent::__construct();
 }
Exemplo n.º 4
0
/**
 * Print all of the notes in this fact record
 *
 * @param string $factrec  the factrecord to print the notes from
 * @param int    $level    The level of the factrecord
 * @param bool   $textOnly Don't print the "Note: " introduction
 *
 * @return string HTML
 */
function print_fact_notes($factrec, $level, $textOnly = false)
{
    $data = "";
    $previous_spos = 0;
    $nlevel = $level + 1;
    $ct = preg_match_all("/{$level} NOTE (.*)/", $factrec, $match, PREG_SET_ORDER);
    for ($j = 0; $j < $ct; $j++) {
        $spos1 = strpos($factrec, $match[$j][0], $previous_spos);
        $spos2 = strpos($factrec . "\n{$level}", "\n{$level}", $spos1 + 1);
        if (!$spos2) {
            $spos2 = strlen($factrec);
        }
        $previous_spos = $spos2;
        $nrec = substr($factrec, $spos1, $spos2 - $spos1);
        if (!isset($match[$j][1])) {
            $match[$j][1] = "";
        }
        if (!preg_match("/@(.*)@/", $match[$j][1], $nmatch)) {
            $data .= print_note_record($match[$j][1], $nlevel, $nrec, $textOnly);
        } else {
            $note = WT_Note::getInstance($nmatch[1]);
            if ($note) {
                if ($note->canShow()) {
                    $noterec = $note->getGedcom();
                    $nt = preg_match("/0 @{$nmatch['1']}@ NOTE (.*)/", $noterec, $n1match);
                    $data .= print_note_record($nt > 0 ? $n1match[1] : "", 1, $noterec, $textOnly);
                    if (!$textOnly) {
                        if (strpos($noterec, "1 SOUR") !== false) {
                            require_once WT_ROOT . 'includes/functions/functions_print_facts.php';
                            $data .= print_fact_sources($noterec, 1);
                        }
                    }
                }
            } else {
                $data = '<div class="fact_NOTE"><span class="label">' . WT_I18N::translate('Note') . '</span>: <span class="field error">' . $nmatch[1] . '</span></div>';
            }
        }
        if (!$textOnly) {
            if (strpos($factrec, "{$nlevel} SOUR") !== false) {
                $data .= "<div class=\"indent\">";
                $data .= print_fact_sources($nrec, $nlevel);
                $data .= "</div>";
            }
        }
    }
    return $data;
}
Exemplo n.º 5
0
/**
 * add a new tag input field
 *
 * called for each fact to be edited on a form.
 * Fact level=0 means a new empty form : data are POSTed by name
 * else data are POSTed using arrays :
 * glevels[] : tag level
 *  islink[] : tag is a link
 *     tag[] : tag name
 *    text[] : tag value
 *
 * @param string        $tag        fact record to edit (eg 2 DATE xxxxx)
 * @param string        $upperlevel optional upper level tag (eg BIRT)
 * @param string        $label      An optional label to echo instead of the default
 * @param string        $extra      optional text to display after the input field
 * @param WT_Individual $person     For male/female translations
 *
 * @return string
 */
function add_simple_tag($tag, $upperlevel = '', $label = '', $extra = null, WT_Individual $person = null)
{
    global $tags, $emptyfacts, $main_fact, $FILE_FORM_accept, $xref, $bdm, $action;
    global $QUICK_REQUIRED_FACTS, $QUICK_REQUIRED_FAMFACTS, $PREFER_LEVEL2_SOURCES;
    $subnamefacts = array("NPFX", "GIVN", "SPFX", "SURN", "NSFX", "_MARNM_SURN");
    preg_match('/^(?:(\\d+) (' . WT_REGEX_TAG . ') ?(.*))/', $tag, $match);
    list(, $level, $fact, $value) = $match;
    // element name : used to POST data
    if ($level == 0) {
        if ($upperlevel) {
            $element_name = $upperlevel . '_' . $fact;
        } else {
            $element_name = $fact;
        }
        // ex: OCCU
    } else {
        $element_name = "text[]";
    }
    if ($level == 1) {
        $main_fact = $fact;
    }
    // element id : used by javascript functions
    if ($level == 0) {
        $element_id = $fact;
    } else {
        $element_id = $fact . Uuid::uuid4();
    }
    if ($upperlevel) {
        $element_id = $upperlevel . '_' . $fact . Uuid::uuid4();
    }
    // field value
    $islink = substr($value, 0, 1) === '@' && substr($value, 0, 2) != '@#';
    if ($islink) {
        $value = trim(trim(substr($tag, strlen($fact) + 3)), " @\r");
    } else {
        $value = trim(substr($tag, strlen($fact) + 3));
    }
    if ($fact == 'REPO' || $fact == 'SOUR' || $fact == 'OBJE' || $fact == 'FAMC') {
        $islink = true;
    }
    if ($fact == 'SHARED_NOTE_EDIT' || $fact == 'SHARED_NOTE') {
        $islink = 1;
        $fact = "NOTE";
    }
    // label
    echo "<tr id=\"", $element_id, "_tr\" ";
    if ($fact == "MAP" || ($fact == "LATI" || $fact == "LONG") && $value == '') {
        echo " style=\"display:none;\"";
    }
    echo " >";
    if (in_array($fact, $subnamefacts) || $fact == "LATI" || $fact == "LONG") {
        echo "<td class=\"optionbox wrap width25\">";
    } else {
        echo "<td class=\"descriptionbox wrap width25\">";
    }
    if (WT_DEBUG) {
        echo $element_name, "<br>";
    }
    // tag name
    if ($label) {
        echo $label;
    } elseif ($upperlevel) {
        echo WT_Gedcom_Tag::getLabel($upperlevel . ':' . $fact);
    } else {
        echo WT_Gedcom_Tag::getLabel($fact);
    }
    // help link
    // If using GEDFact-assistant window
    if ($action == "addnewnote_assisted") {
        // Do not print on GEDFact Assistant window
    } else {
        // Not all facts have help text.
        switch ($fact) {
            case 'FORM':
                if ($upperlevel != 'OBJE') {
                    echo help_link($fact);
                }
                break;
            case 'NOTE':
                if ($islink) {
                    echo help_link('edit_add_SHARED_NOTE');
                } else {
                    echo help_link($fact);
                }
                break;
            case 'NAME':
                if ($upperlevel != 'REPO') {
                    echo help_link($fact);
                }
                break;
            case 'ASSO':
            case '_ASSO':
                // Some apps (including webtrees) use "2 _ASSO", since "2 ASSO" is not strictly valid GEDCOM
                if ($level == 1) {
                    echo help_link('ASSO_1');
                } else {
                    echo help_link('ASSO_2');
                }
                break;
            case 'ADDR':
            case 'AGNC':
            case 'CAUS':
            case 'DATE':
            case 'EMAI':
            case 'EMAIL':
            case 'EMAL':
            case '_EMAIL':
            case 'FAX':
            case 'OBJE':
            case 'PAGE':
            case 'PEDI':
            case 'PHON':
            case 'PLAC':
            case 'RELA':
            case 'RESN':
            case 'ROMN':
            case 'SEX':
            case 'SOUR':
            case 'STAT':
            case 'SURN':
            case 'TEMP':
            case 'TEXT':
            case 'TIME':
            case 'URL':
            case '_HEB':
            case '_PRIM':
                echo help_link($fact);
                break;
        }
    }
    // tag level
    if ($level > 0) {
        if ($fact == 'TEXT' && $level > 1) {
            echo "<input type=\"hidden\" name=\"glevels[]\" value=\"", $level - 1, "\">";
            echo "<input type=\"hidden\" name=\"islink[]\" value=\"0\">";
            echo "<input type=\"hidden\" name=\"tag[]\" value=\"DATA\">";
            //-- leave data text[] value empty because the following TEXT line will
            //--- cause the DATA to be added
            echo "<input type=\"hidden\" name=\"text[]\" value=\"\">";
        }
        echo "<input type=\"hidden\" name=\"glevels[]\" value=\"", $level, "\">";
        echo "<input type=\"hidden\" name=\"islink[]\" value=\"", $islink, "\">";
        echo "<input type=\"hidden\" name=\"tag[]\" value=\"", $fact, "\">";
    }
    echo "</td>";
    // value
    echo "<td class=\"optionbox wrap\">";
    if (WT_DEBUG) {
        echo $tag, "<br>";
    }
    // retrieve linked NOTE
    if ($fact == "NOTE" && $islink) {
        $note1 = WT_Note::getInstance($value);
        if ($note1) {
            $noterec = $note1->getGedcom();
            preg_match("/{$value}/i", $noterec, $notematch);
            $value = $notematch[0];
        }
    }
    if (in_array($fact, $emptyfacts) && ($value == '' || $value == 'Y' || $value == 'y')) {
        echo "<input type=\"hidden\" id=\"", $element_id, "\" name=\"", $element_name, "\" value=\"", $value, "\">";
        if ($level <= 1) {
            echo '<input type="checkbox" ';
            if ($value) {
                echo ' checked="checked"';
            }
            echo " onclick=\"if (this.checked) ", $element_id, ".value='Y'; else ", $element_id, ".value='';\">";
            echo WT_I18N::translate('yes');
        }
    } else {
        if ($fact == "TEMP") {
            echo select_edit_control($element_name, WT_Gedcom_Code_Temp::templeNames(), WT_I18N::translate('No temple - living ordinance'), $value);
        } else {
            if ($fact == "ADOP") {
                echo edit_field_adop($element_name, $value, '', $person);
            } else {
                if ($fact == "PEDI") {
                    echo edit_field_pedi($element_name, $value, '', $person);
                } else {
                    if ($fact == 'STAT') {
                        echo select_edit_control($element_name, WT_Gedcom_Code_Stat::statusNames($upperlevel), '', $value);
                    } else {
                        if ($fact == 'RELA') {
                            echo edit_field_rela($element_name, strtolower($value));
                        } else {
                            if ($fact == 'QUAY') {
                                echo select_edit_control($element_name, WT_Gedcom_Code_Quay::getValues(), '', $value);
                            } else {
                                if ($fact == '_WT_USER') {
                                    echo edit_field_username($element_name, $value);
                                } else {
                                    if ($fact == 'RESN') {
                                        echo edit_field_resn($element_name, $value);
                                    } else {
                                        if ($fact == '_PRIM') {
                                            echo '<select id="', $element_id, '" name="', $element_name, '" >';
                                            echo '<option value=""></option>';
                                            echo '<option value="Y"';
                                            if ($value == 'Y') {
                                                echo ' selected="selected"';
                                            }
                                            echo '>', WT_I18N::translate('yes'), '</option>';
                                            echo '<option value="N"';
                                            if ($value == 'N') {
                                                echo ' selected="selected"';
                                            }
                                            echo '>', WT_I18N::translate('no'), '</option>';
                                            echo '</select>';
                                        } else {
                                            if ($fact == 'SEX') {
                                                echo '<select id="', $element_id, '" name="', $element_name, '"><option value="M"';
                                                if ($value == 'M') {
                                                    echo ' selected="selected"';
                                                }
                                                echo '>', WT_I18N::translate('Male'), '</option><option value="F"';
                                                if ($value == 'F') {
                                                    echo ' selected="selected"';
                                                }
                                                echo '>', WT_I18N::translate('Female'), '</option><option value="U"';
                                                if ($value == 'U' || empty($value)) {
                                                    echo ' selected="selected"';
                                                }
                                                echo '>', WT_I18N::translate_c('unknown gender', 'Unknown'), '</option></select>';
                                            } else {
                                                if ($fact == 'TYPE' && $level == '3') {
                                                    //-- Build the selector for the Media 'TYPE' Fact
                                                    echo '<select name="text[]"><option selected="selected" value="" ></option>';
                                                    $selectedValue = strtolower($value);
                                                    if (!array_key_exists($selectedValue, WT_Gedcom_Tag::getFileFormTypes())) {
                                                        echo '<option selected="selected" value="', WT_Filter::escapeHtml($value), '" >', WT_Filter::escapeHtml($value), '</option>';
                                                    }
                                                    foreach (WT_Gedcom_Tag::getFileFormTypes() as $typeName => $typeValue) {
                                                        echo '<option value="', $typeName, '"';
                                                        if ($selectedValue == $typeName) {
                                                            echo ' selected="selected"';
                                                        }
                                                        echo '>', $typeValue, '</option>';
                                                    }
                                                    echo '</select>';
                                                } else {
                                                    if ($fact == 'NAME' && $upperlevel != 'REPO' || $fact == '_MARNM') {
                                                        // Populated in javascript from sub-tags
                                                        echo "<input type=\"hidden\" id=\"", $element_id, "\" name=\"", $element_name, "\" onchange=\"updateTextName('", $element_id, "');\" value=\"", WT_Filter::escapeHtml($value), "\" class=\"", $fact, "\">";
                                                        echo '<span id="', $element_id, '_display" dir="auto">', WT_Filter::escapeHtml($value), '</span>';
                                                        echo ' <a href="#edit_name" onclick="convertHidden(\'', $element_id, '\'); return false;" class="icon-edit_indi" title="' . WT_I18N::translate('Edit name') . '"></a>';
                                                    } else {
                                                        // textarea
                                                        if ($fact == 'TEXT' || $fact == 'ADDR' || $fact == 'NOTE' && !$islink) {
                                                            echo "<textarea id=\"", $element_id, "\" name=\"", $element_name, "\" dir=\"auto\">", WT_Filter::escapeHtml($value), "</textarea><br>";
                                                        } else {
                                                            // text
                                                            // If using GEDFact-assistant window
                                                            if ($action == "addnewnote_assisted") {
                                                                echo "<input type=\"text\" id=\"", $element_id, "\" name=\"", $element_name, "\" value=\"", WT_Filter::escapeHtml($value), "\" style=\"width:4.1em;\" dir=\"ltr\"";
                                                            } else {
                                                                echo "<input type=\"text\" id=\"", $element_id, "\" name=\"", $element_name, "\" value=\"", WT_Filter::escapeHtml($value), "\" dir=\"ltr\"";
                                                            }
                                                            echo " class=\"{$fact}\"";
                                                            if (in_array($fact, $subnamefacts)) {
                                                                echo " onblur=\"updatewholename();\" onkeyup=\"updatewholename();\"";
                                                            }
                                                            // Extra markup for specific fact types
                                                            switch ($fact) {
                                                                case 'DATE':
                                                                    echo " onblur=\"valid_date(this);\" onmouseout=\"valid_date(this);\"";
                                                                    break;
                                                                case 'GIVN':
                                                                    echo ' autofocus data-autocomplete-type="GIVN"';
                                                                    break;
                                                                case 'LATI':
                                                                    echo " onblur=\"valid_lati_long(this, 'N', 'S');\" onmouseout=\"valid_lati_long(this, 'N', 'S');\"";
                                                                    break;
                                                                case 'LONG':
                                                                    echo " onblur=\"valid_lati_long(this, 'E', 'W');\" onmouseout=\"valid_lati_long(this, 'E', 'W');\"";
                                                                    break;
                                                                case 'NOTE':
                                                                    // Shared notes.  Inline notes are handled elsewhere.
                                                                    echo ' data-autocomplete-type="NOTE"';
                                                                    break;
                                                                case 'OBJE':
                                                                    echo ' data-autocomplete-type="OBJE"';
                                                                    break;
                                                                case 'PLAC':
                                                                    echo ' data-autocomplete-type="PLAC"';
                                                                    break;
                                                                case 'REPO':
                                                                    echo ' data-autocomplete-type="REPO"';
                                                                    break;
                                                                case 'SOUR':
                                                                    echo ' data-autocomplete-type="SOUR"';
                                                                    break;
                                                                case 'SURN':
                                                                case '_MARNM_SURN':
                                                                    echo ' data-autocomplete-type="SURN"';
                                                                    break;
                                                            }
                                                            echo '>';
                                                        }
                                                        $tmp_array = array('TYPE', 'TIME', 'NOTE', 'SOUR', 'REPO', 'OBJE', 'ASSO', '_ASSO', 'AGE');
                                                        // split PLAC
                                                        if ($fact == 'PLAC') {
                                                            echo "<div id=\"", $element_id, "_pop\" style=\"display: inline;\">";
                                                            echo print_specialchar_link($element_id), ' ', print_findplace_link($element_id);
                                                            echo '<span  onclick="jQuery(\'tr[id^=', $upperlevel, '_LATI],tr[id^=', $upperlevel, '_LONG],tr[id^=LATI],tr[id^=LONG]\').toggle(\'fast\'); return false;" class="icon-target" title="', WT_Gedcom_Tag::getLabel('LATI'), ' / ', WT_Gedcom_Tag::getLabel('LONG'), '"></span>';
                                                            echo '</div>';
                                                            if (array_key_exists('places_assistant', WT_Module::getActiveModules())) {
                                                                places_assistant_WT_Module::setup_place_subfields($element_id);
                                                                places_assistant_WT_Module::print_place_subfields($element_id);
                                                            }
                                                        } elseif (!in_array($fact, $tmp_array)) {
                                                            echo print_specialchar_link($element_id);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // MARRiage TYPE : hide text field and show a selection list
    if ($fact == 'TYPE' && $level == 2 && $tags[0] == 'MARR') {
        echo '<script>';
        echo "document.getElementById('", $element_id, "').style.display='none'";
        echo '</script>';
        echo "<select id=\"", $element_id, "_sel\" onchange=\"document.getElementById('", $element_id, "').value=this.value;\" >";
        foreach (array("Unknown", "Civil", "Religious", "Partners") as $key) {
            if ($key == "Unknown") {
                echo "<option value=\"\"";
            } else {
                echo "<option value=\"", $key, "\"";
            }
            $a = strtolower($key);
            $b = strtolower($value);
            if (@strpos($a, $b) !== false || @strpos($b, $a) !== false) {
                echo ' selected="selected"';
            }
            $tmp = "MARR_" . strtoupper($key);
            echo ">", WT_Gedcom_Tag::getLabel($tmp), "</option>";
        }
        echo "</select>";
    } else {
        if ($fact == 'TYPE' && $level == 0) {
            $onchange = 'onchange="document.getElementById(\'' . $element_id . '\').value=this.value;"';
            echo edit_field_name_type($element_name, $value, $onchange, $person);
            echo '<script>';
            echo "document.getElementById('", $element_id, "').style.display='none';";
            echo '</script>';
        }
    }
    // popup links
    switch ($fact) {
        case 'DATE':
            echo print_calendar_popup($element_id);
            // Allow the GEDFact_assistant module to show a census-date selector
            if (array_key_exists('GEDFact_assistant', WT_Module::getActiveModules())) {
                echo GEDFact_assistant_WT_Module::censusDateSelector($action, $upperlevel, $element_id);
            }
            break;
        case 'FAMC':
        case 'FAMS':
            echo print_findfamily_link($element_id);
            break;
        case 'ASSO':
        case '_ASSO':
            echo print_findindi_link($element_id, $element_id . '_description');
            break;
        case 'FILE':
            print_findmedia_link($element_id, "0file");
            break;
        case 'SOUR':
            echo print_findsource_link($element_id, $element_id . '_description'), ' ', print_addnewsource_link($element_id);
            //-- checkboxes to apply '1 SOUR' to BIRT/MARR/DEAT as '2 SOUR'
            if ($level == 1) {
                echo '<br>';
                if ($PREFER_LEVEL2_SOURCES === '0') {
                    $level1_checked = '';
                    $level2_checked = '';
                } else {
                    if ($PREFER_LEVEL2_SOURCES === '1' || $PREFER_LEVEL2_SOURCES === true) {
                        $level1_checked = '';
                        $level2_checked = ' checked="checked"';
                    } else {
                        $level1_checked = ' checked="checked"';
                        $level2_checked = '';
                    }
                }
                if (strpos($bdm, 'B') !== false) {
                    echo '&nbsp;<input type="checkbox" name="SOUR_INDI" ', $level1_checked, ' value="1">';
                    echo WT_I18N::translate('Individual');
                    if (preg_match_all('/(' . WT_REGEX_TAG . ')/', $QUICK_REQUIRED_FACTS, $matches)) {
                        foreach ($matches[1] as $match) {
                            if (!in_array($match, explode('|', WT_EVENTS_DEAT))) {
                                echo '&nbsp;<input type="checkbox" name="SOUR_', $match, '"', $level2_checked, ' value="1">';
                                echo WT_Gedcom_Tag::getLabel($match);
                            }
                        }
                    }
                }
                if (strpos($bdm, 'D') !== false) {
                    if (preg_match_all('/(' . WT_REGEX_TAG . ')/', $QUICK_REQUIRED_FACTS, $matches)) {
                        foreach ($matches[1] as $match) {
                            if (in_array($match, explode('|', WT_EVENTS_DEAT))) {
                                echo '&nbsp;<input type="checkbox" name="SOUR_', $match, '"', $level2_checked, ' value="1">';
                                echo WT_Gedcom_Tag::getLabel($match);
                            }
                        }
                    }
                }
                if (strpos($bdm, 'M') !== false) {
                    echo '&nbsp;<input type="checkbox" name="SOUR_FAM" ', $level1_checked, ' value="1">';
                    echo WT_I18N::translate('Family');
                    if (preg_match_all('/(' . WT_REGEX_TAG . ')/', $QUICK_REQUIRED_FAMFACTS, $matches)) {
                        foreach ($matches[1] as $match) {
                            echo '&nbsp;<input type="checkbox" name="SOUR_', $match, '"', $level2_checked, ' value="1">';
                            echo WT_Gedcom_Tag::getLabel($match);
                        }
                    }
                }
            }
            break;
        case 'REPO':
            echo print_findrepository_link($element_id), ' ', print_addnewrepository_link($element_id);
            break;
        case 'NOTE':
            // Shared Notes Icons ========================================
            if ($islink) {
                // Print regular Shared Note icons ---------------------------
                echo ' ', print_findnote_link($element_id, $element_id . '_description'), ' ', print_addnewnote_link($element_id);
                if ($value) {
                    echo ' ', print_editnote_link($value);
                }
                // Allow the GEDFact_assistant module to create a formatted shared note.
                if (array_key_exists('GEDFact_assistant', WT_Module::getActiveModules())) {
                    echo GEDFact_assistant_WT_Module::print_addnewnote_assisted_link($element_id, $xref, $action);
                }
            }
            break;
        case 'OBJE':
            echo print_findmedia_link($element_id, '1media');
            if (!$value) {
                echo ' ', print_addnewmedia_link($element_id);
                $value = 'new';
            }
            break;
    }
    echo '<div id="' . $element_id . '_description">';
    // current value
    if ($fact == 'DATE') {
        $date = new WT_Date($value);
        echo $date->Display(false);
    }
    if ($value && $value != 'new' && $islink) {
        switch ($fact) {
            case 'ASSO':
            case '_ASSO':
                $tmp = WT_Individual::getInstance($value);
                if ($tmp) {
                    echo ' ', $tmp->getFullname();
                }
                break;
            case 'SOUR':
                $tmp = WT_Source::getInstance($value);
                if ($tmp) {
                    echo ' ', $tmp->getFullname();
                }
                break;
            case 'NOTE':
                $tmp = WT_Note::getInstance($value);
                if ($tmp) {
                    echo ' ', $tmp->getFullname();
                }
                break;
            case 'OBJE':
                $tmp = WT_Media::getInstance($value);
                if ($tmp) {
                    echo ' ', $tmp->getFullname();
                }
                break;
            case 'REPO':
                $tmp = WT_Repository::getInstance($value);
                if ($tmp) {
                    echo ' ', $tmp->getFullname();
                }
                break;
        }
    }
    // pastable values
    if ($fact == 'FORM' && $upperlevel == 'OBJE') {
        print_autopaste_link($element_id, $FILE_FORM_accept);
    }
    echo '</div>', $extra, '</td></tr>';
    return $element_id;
}
Exemplo n.º 6
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 "";
}
Exemplo n.º 7
0
" onclick="window.close();">
			</p>
		</form>
	</div>
	<?php 
        break;
    case 'editnoteaction':
        $xref = WT_Filter::post('xref', WT_REGEX_XREF);
        $keep_chan = WT_Filter::postBool('keep_chan');
        $note = WT_Filter::post('NOTE');
        if (!WT_Filter::checkCsrf()) {
            Zend_Session::writeClose();
            header('Location: ' . WT_SERVER_NAME . WT_SCRIPT_PATH . WT_SCRIPT_NAME . '?action=editnote&xref=' . $xref);
            exit;
        }
        $record = WT_Note::getInstance($xref);
        check_record_access($record);
        $controller->setPageTitle(WT_I18N::translate('Edit shared note'))->pageHeader();
        // We have user-supplied data in a replacement string - escape it against backreferences
        $note = str_replace(array('\\', '$'), array('\\\\', '\\$'), $note);
        $gedrec = preg_replace('/^0 @' . $record->getXref() . '@ NOTE.*(\\n1 CONT.*)*/', '0 @' . $record->getXref() . '@ NOTE ' . preg_replace("/\r?\n/", "\n1 CONT ", $note), $record->getGedcom());
        $record->updateRecord($gedrec, !$keep_chan);
        $controller->addInlineJavascript('closePopupAndReloadParent();');
        break;
        ////////////////////////////////////////////////////////////////////////////////
        // Create a new repository
        ////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////
    // Create a new repository
    ////////////////////////////////////////////////////////////////////////////////
    case 'addnewrepository':
Exemplo n.º 8
0
 public static function formatCensusNote(WT_Note $note)
 {
     global $WT_TREE;
     $headers = array('AgM' => 'Age at first marriage', 'Age' => 'Age at last birthday', 'Assets' => 'Assets = Owned,Rented - Value,Rent - Radio - Farm', 'BIC' => 'Born in County', 'BOE' => 'Born outside England', 'BP' => 'Birthplace - (Chapman format)', 'Birthplace' => 'Birthplace (Full format)', 'Bmth' => 'Month of birth - If born within Census year', 'ChB' => 'Children born alive', 'ChD' => 'Children who have died', 'ChL' => 'Children still living', 'DOB' => 'Date of birth', 'Edu' => 'Education - At School, Can Read, Can Write', 'EmD' => 'Employed?', 'EmN' => 'Unemployed?', 'EmR' => 'Employer?', 'Employ' => 'Employment', 'Eng?' => 'English spoken?', 'EngL' => 'English spoken?, if not, Native Language', 'FBP' => 'Father’s Birthplace - (Chapman format)', 'Health' => 'Health - 1.Blind, 2.Deaf & Dumb, 3.Idiotic, 4.Insane, 5.Disabled etc', 'Home' => 'Home Ownership - Owned/Rented-Free/Mortgaged-Farm/House-Farm Schedule number', 'Industry' => 'Industry', 'Infirm' => 'Infirmities - 1. Deaf & Dumb, 2. Blind, 3. Lunatic, 4. Imbecile/feeble-minded', 'Lang' => 'If Foreign Born - Native Language', 'MBP' => 'Mother’s Birthplace - (Chapman format)', 'MC' => 'Marital Condition - Married, Single, Unmarried, Widowed or Divorced', 'Mmth' => 'Month of marriage - If married during Census Year', 'MnsE' => 'Months employed during Census Year', 'MnsU' => 'Months unemployed during Census Year', 'N/A' => 'If Foreign Born - Naturalized, Alien', 'NL' => 'If Foreign Born - Native Language', 'Name' => 'Full Name or Married name if married', 'Occupation' => 'Occupation', 'Par' => 'Parentage - Father if foreign born, Mother if foreign born', 'Race' => 'Race or Color - Black, White, Mulatto, Asian, Indian, Chinese etc', 'Relation' => 'Relationship to Head of Household', 'Sex' => 'Male or Female', 'Situ' => 'Situation - Disease, Infirmity, Convict, Pauper etc', 'Ten' => 'Tenure - Owned/Rented, (if owned)Free/Morgaged', 'Vet' => 'War Veteran?', 'WH' => 'Working at Home?', 'War' => 'War or Expedition', 'WksU' => 'Weeks unemployed during Census Year', 'YOI' => 'If Foreign Born - Year of immigration', 'YON' => 'If Foreign Born - Year of naturalization', 'YUS' => 'If Foreign Born - Years in the USA', 'YrsM' => 'Years Married, or Y if married in Census Year');
     if (preg_match('/(.*)((?:\\n.*)*)\\n\\.start_formatted_area\\.\\n(.*)((?:\\n.*)*)\\n.end_formatted_area\\.((?:\\n.*)*)/', $note->getNote(), $match)) {
         // This looks like a census-assistant shared note
         $title = WT_Filter::escapeHtml($match[1]);
         $preamble = WT_Filter::escapeHtml($match[2]);
         $header = WT_Filter::escapeHtml($match[3]);
         $data = WT_Filter::escapeHtml($match[4]);
         $postamble = WT_Filter::escapeHtml($match[5]);
         $fmt_headers = array();
         foreach ($headers as $key => $value) {
             $fmt_headers['.b.' . $key] = '<span title="' . WT_Filter::escapeHtml($value) . '">' . $key . '</span>';
         }
         // Substitue header labels and format as HTML
         $thead = '<tr><th>' . strtr(str_replace('|', '</th><th>', $header), $fmt_headers) . '</th></tr>';
         // Format data as HTML
         $tbody = '';
         foreach (explode("\n", $data) as $row) {
             $tbody .= '<tr>';
             foreach (explode('|', $row) as $column) {
                 $tbody .= '<td>' . $column . '</td>';
             }
             $tbody .= '</tr>';
         }
         return $title . "\n" . '<p>' . $preamble . '</p>' . '<table class="table-census-assistant">' . '<thead>' . $thead . '</thead>' . '<tbody>' . $tbody . '</tbody>' . '</table>' . '<p>' . $postamble . '</p>';
     } else {
         // Not a census-assistant shared note - apply default formatting
         return WT_Filter::formatText($note->getNote(), $WT_TREE);
     }
 }
Exemplo n.º 9
0
 public function getNotes()
 {
     $notes = array();
     preg_match_all('/\\n2 NOTE ?(.*(?:\\n3.*)*)/', $this->getGedcom(), $matches);
     foreach ($matches[1] as $match) {
         $note = preg_replace("/\n3 CONT ?/", "\n", $match);
         if (preg_match('/@(' . WT_REGEX_XREF . ')@/', $note, $nmatch)) {
             $note = WT_Note::getInstance($nmatch[1], $this->getParent()->getGedcomId());
             if ($note && $note->canShow()) {
                 // A note object
                 $notes[] = $note;
             }
         } else {
             // An inline note
             $notes[] = $note;
         }
     }
     return $notes;
 }
Exemplo n.º 10
0
 public function linkedRepositories($link)
 {
     $rows = WT_DB::prepare("SELECT o_id AS xref, o_file AS gedcom_id, o_gedcom AS gedcom" . " FROM `##other`" . " JOIN `##link` ON (o_file=l_file AND o_id=l_from)" . " LEFT JOIN `##name` ON (o_file=n_file AND o_id=n_id AND n_num=0)" . " WHERE o_file=? AND o_type='REPO' AND l_type=? AND l_to=?" . " ORDER BY n_sort COLLATE '" . WT_I18N::$collation . "'")->execute(array($this->gedcom_id, $link, $this->xref))->fetchAll();
     $list = array();
     foreach ($rows as $row) {
         $record = WT_Note::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
         if ($record->canShowName()) {
             $list[] = $record;
         }
     }
     return $list;
 }
Exemplo n.º 11
0
        if ($linkto == "repository") {
            echo WT_I18N::translate('Repository'), "</td>";
            echo '<td  class="optionbox wrap">';
            if ($linktoid == "") {
                echo '<input class="pedigree_form" type="text" name="linktoid" id="linktorid" size="3" value="', $linktoid, '">';
            } else {
                $record = WT_Repository::getInstance($linktoid);
                echo $record->format_list('span', false, $record->getFullName());
            }
        }
        if ($linkto == "note") {
            echo WT_I18N::translate('Shared note'), "</td>";
            echo '<td  class="optionbox wrap">';
            if ($linktoid == "") {
                echo '<input class="pedigree_form" type="text" name="linktoid" id="linktonid" size="3" value="', $linktoid, '">';
            } else {
                $record = WT_Note::getInstance($linktoid);
                echo $record->format_list('span', false, $record->getFullName());
            }
        }
        echo '</td></tr>';
        echo '<tr><td class="topbottombar" colspan="2"><input type="submit" value="', WT_I18N::translate('Set link'), '"></td></tr>';
        echo '</table>';
        echo '</form>';
    } elseif ($action == "update" && $paramok) {
        $record = WT_GedcomRecord::getInstance($linktoid);
        $record->createFact('1 OBJE @' . $mediaid . '@', true);
        $controller->addInlineJavascript('closePopupAndReloadParent();');
    }
    echo '<button onclick="closePopupAndReloadParent();">', WT_I18N::translate('close'), '</button>';
}
Exemplo n.º 12
0
 static function getLatestRecord($xref, $type)
 {
     switch ($type) {
         case 'INDI':
             return WT_Individual::getInstance($xref)->getGedcom();
         case 'FAM':
             return WT_Family::getInstance($xref)->getGedcom();
         case 'SOUR':
             return WT_Source::getInstance($xref)->getGedcom();
         case 'REPO':
             return WT_Repository::getInstance($xref)->getGedcom();
         case 'OBJE':
             return WT_Media::getInstance($xref)->getGedcom();
         case 'NOTE':
             return WT_Note::getInstance($xref)->getGedcom();
         default:
             return WT_GedcomRecord::getInstance($xref)->getGedcom();
     }
 }
Exemplo n.º 13
0
     foreach ($rows as $row) {
         $family = WT_Family::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
         if ($family->canShowName()) {
             $marriage_year = $family->getMarriageYear();
             if ($marriage_year) {
                 $data[] = array('value' => $family->getXref(), 'label' => $family->getFullName() . ', <i>' . $marriage_year . '</i>');
             } else {
                 $data[] = array('value' => $family->getXref(), 'label' => $family->getFullName());
             }
         }
     }
     // Fetch all data, regardless of privacy
     $rows = get_NOTE_rows($term);
     // Filter for privacy
     foreach ($rows as $row) {
         $note = WT_Note::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
         if ($note->canShowName()) {
             $data[] = array('value' => $note->getXref(), 'label' => $note->getFullName());
         }
     }
     echo json_encode($data);
     exit;
 case 'IFS':
     $data = array();
     // Fetch all data, regardless of privacy
     $rows = get_INDI_rows($term);
     // Filter for privacy
     foreach ($rows as $row) {
         $person = WT_Individual::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
         if ($person->canShowName()) {
             $data[] = array('value' => $person->getXref(), 'label' => str_replace(array('@N.N.', '@P.N.'), array($UNKNOWN_NN, $UNKNOWN_PN), $row->n_full) . ', <i>' . $person->getLifeSpan() . '</i>');
Exemplo n.º 14
0
 private function generate_file($ged_id, $rec_type, $volume)
 {
     // Check the cache
     $timestamp = get_module_setting($this->getName(), 'sitemap-' . $ged_id . '-' . $rec_type . '-' . $volume . '.timestamp');
     if ($timestamp > WT_TIMESTAMP - self::CACHE_LIFE && !WT_USER_ID) {
         $data = get_module_setting($this->getName(), 'sitemap-' . $ged_id . '-' . $rec_type . '-' . $volume . '.xml');
     } else {
         $tree = WT_Tree::get($ged_id);
         $data = '<url><loc>' . WT_SERVER_NAME . WT_SCRIPT_PATH . 'index.php?ctype=gedcom&amp;ged=' . $tree->tree_name_url . '</loc></url>' . PHP_EOL;
         $records = array();
         switch ($rec_type) {
             case 'i':
                 $rows = WT_DB::prepare("SELECT i_id AS xref, i_file AS gedcom_id, i_gedcom AS gedcom" . " FROM `##individuals`" . " WHERE i_file=?" . " ORDER BY i_id" . " LIMIT " . self::RECORDS_PER_VOLUME . " OFFSET " . $volume * self::RECORDS_PER_VOLUME)->execute(array($ged_id))->fetchAll();
                 foreach ($rows as $row) {
                     $records[] = WT_Individual::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
                 }
                 break;
             case 's':
                 $rows = WT_DB::prepare("SELECT s_id AS xref, s_file AS gedcom_id, s_gedcom AS gedcom" . " FROM `##sources`" . " WHERE s_file=?" . " ORDER BY s_id" . " LIMIT " . self::RECORDS_PER_VOLUME . " OFFSET " . $volume * self::RECORDS_PER_VOLUME)->execute(array($ged_id))->fetchAll();
                 foreach ($rows as $row) {
                     $records[] = WT_Source::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
                 }
                 break;
             case 'r':
                 $rows = WT_DB::prepare("SELECT o_id AS xref, o_file AS gedcom_id, o_gedcom AS gedcom" . " FROM `##other`" . " WHERE o_file=? AND o_type='REPO'" . " ORDER BY o_id" . " LIMIT " . self::RECORDS_PER_VOLUME . " OFFSET " . $volume * self::RECORDS_PER_VOLUME)->execute(array($ged_id))->fetchAll();
                 foreach ($rows as $row) {
                     $records[] = WT_Repository::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
                 }
                 break;
             case 'n':
                 $rows = WT_DB::prepare("SELECT o_id AS xref, o_file AS gedcom_id, o_gedcom AS gedcom" . " FROM `##other`" . " WHERE o_file=? AND o_type='NOTE'" . " ORDER BY o_id" . " LIMIT " . self::RECORDS_PER_VOLUME . " OFFSET " . $volume * self::RECORDS_PER_VOLUME)->execute(array($ged_id))->fetchAll();
                 foreach ($rows as $row) {
                     $records[] = WT_Note::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
                 }
                 break;
             case 'm':
                 $rows = WT_DB::prepare("SELECT m_id AS xref, m_file AS gedcom_id, m_gedcom AS gedcom" . " FROM `##media`" . " WHERE m_file=?" . " ORDER BY m_id" . " LIMIT " . self::RECORDS_PER_VOLUME . " OFFSET " . $volume * self::RECORDS_PER_VOLUME)->execute(array($ged_id))->fetchAll();
                 foreach ($rows as $row) {
                     $records[] = WT_Media::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
                 }
                 break;
         }
         foreach ($records as $record) {
             if ($record->canShowName()) {
                 $data .= '<url>';
                 $data .= '<loc>' . WT_SERVER_NAME . WT_SCRIPT_PATH . $record->getHtmlUrl() . '</loc>';
                 $chan = $record->getFirstFact('CHAN');
                 if ($chan) {
                     $date = $chan->getDate();
                     if ($date->isOK()) {
                         $data .= '<lastmod>' . $date->minDate()->Format('%Y-%m-%d') . '</lastmod>';
                     }
                 }
                 $data .= '</url>' . PHP_EOL;
             }
         }
         $data = '<' . '?xml version="1.0" encoding="UTF-8" ?' . '>' . PHP_EOL . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">' . PHP_EOL . $data . '</urlset>' . PHP_EOL;
         // Cache this data - but only for visitors, as we don’t want
         // visitors to see data created by logged-in users.
         if (!WT_USER_ID) {
             set_module_setting($this->getName(), 'sitemap-' . $ged_id . '-' . $rec_type . '-' . $volume . '.xml', $data);
             set_module_setting($this->getName(), 'sitemap-' . $ged_id . '-' . $rec_type . '-' . $volume . '.timestamp', WT_TIMESTAMP);
         }
     }
     header('Content-Type: application/xml');
     header('Content-Length: ' . strlen($data));
     echo $data;
 }
Exemplo n.º 15
0
function export_gedcom($gedcom, $gedout, $exportOptions)
{
    global $GEDCOM;
    // Temporarily switch to the specified GEDCOM
    $oldGEDCOM = $GEDCOM;
    $GEDCOM = $gedcom;
    $ged_id = get_id_from_gedcom($gedcom);
    switch ($exportOptions['privatize']) {
        case 'gedadmin':
            $access_level = WT_PRIV_NONE;
            break;
        case 'user':
            $access_level = WT_PRIV_USER;
            break;
        case 'visitor':
            $access_level = WT_PRIV_PUBLIC;
            break;
        case 'none':
            $access_level = WT_PRIV_HIDE;
            break;
    }
    $head = gedcom_header($gedcom);
    if ($exportOptions['toANSI'] == 'yes') {
        $head = str_replace('UTF-8', 'ANSI', $head);
        $head = utf8_decode($head);
    }
    $head = reformat_record_export($head);
    fwrite($gedout, $head);
    // Buffer the output.  Lots of small fwrite() calls can be very slow when writing large gedcoms.
    $buffer = '';
    // Generate the OBJE/SOUR/REPO/NOTE records first, as their privacy calcualations involve
    // database queries, and we wish to avoid large gaps between queries due to MySQL connection timeouts.
    $tmp_gedcom = '';
    $rows = WT_DB::prepare("SELECT 'OBJE' AS type, m_id AS xref, m_file AS gedcom_id, m_gedcom AS gedcom" . " FROM `##media` WHERE m_file=? ORDER BY m_id")->execute(array($ged_id))->fetchAll();
    foreach ($rows as $row) {
        $rec = WT_Media::getInstance($row->xref, $row->gedcom_id, $row->gedcom)->privatizeGedcom($access_level);
        $rec = convert_media_path($rec, $exportOptions['path']);
        if ($exportOptions['toANSI'] == 'yes') {
            $rec = utf8_decode($rec);
        }
        $tmp_gedcom .= reformat_record_export($rec);
    }
    $rows = WT_DB::prepare("SELECT s_id AS xref, s_file AS gedcom_id, s_gedcom AS gedcom" . " FROM `##sources` WHERE s_file=? ORDER BY s_id")->execute(array($ged_id))->fetchAll();
    foreach ($rows as $row) {
        $rec = WT_Source::getInstance($row->xref, $row->gedcom_id, $row->gedcom)->privatizeGedcom($access_level);
        if ($exportOptions['toANSI'] == 'yes') {
            $rec = utf8_decode($rec);
        }
        $tmp_gedcom .= reformat_record_export($rec);
    }
    $rows = WT_DB::prepare("SELECT o_type AS type, o_id AS xref, o_file AS gedcom_id, o_gedcom AS gedcom" . " FROM `##other` WHERE o_file=? AND o_type!='HEAD' AND o_type!='TRLR' ORDER BY o_id")->execute(array($ged_id))->fetchAll();
    foreach ($rows as $row) {
        switch ($row->type) {
            case 'NOTE':
                $record = WT_Note::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
                break;
            case 'REPO':
                $record = WT_Repository::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
                break;
            default:
                $record = WT_GedcomRecord::getInstance($row->xref, $row->gedcom_id, $row->gedcom);
                break;
        }
        $rec = $record->privatizeGedcom($access_level);
        if ($exportOptions['toANSI'] == 'yes') {
            $rec = utf8_decode($rec);
        }
        $tmp_gedcom .= reformat_record_export($rec);
    }
    $rows = WT_DB::prepare("SELECT i_id AS xref, i_file AS gedcom_id, i_gedcom AS gedcom" . " FROM `##individuals` WHERE i_file=? ORDER BY i_id")->execute(array($ged_id))->fetchAll();
    foreach ($rows as $row) {
        $rec = WT_Individual::getInstance($row->xref, $row->gedcom_id, $row->gedcom)->privatizeGedcom($access_level);
        if ($exportOptions['toANSI'] == 'yes') {
            $rec = utf8_decode($rec);
        }
        $buffer .= reformat_record_export($rec);
        if (strlen($buffer) > 65536) {
            fwrite($gedout, $buffer);
            $buffer = '';
        }
    }
    $rows = WT_DB::prepare("SELECT f_id AS xref, f_file AS gedcom_id, f_gedcom AS gedcom" . " FROM `##families` WHERE f_file=? ORDER BY f_id")->execute(array($ged_id))->fetchAll();
    foreach ($rows as $row) {
        $rec = WT_Family::getInstance($row->xref, $row->gedcom_id, $row->gedcom)->privatizeGedcom($access_level);
        if ($exportOptions['toANSI'] == 'yes') {
            $rec = utf8_decode($rec);
        }
        $buffer .= reformat_record_export($rec);
        if (strlen($buffer) > 65536) {
            fwrite($gedout, $buffer);
            $buffer = '';
        }
    }
    fwrite($gedout, $buffer);
    fwrite($gedout, $tmp_gedcom);
    fwrite($gedout, '0 TRLR' . WT_EOL);
    $GEDCOM = $oldGEDCOM;
}