public function getBlock($block_id, $template = true, $cfg = null) { global $ctype, $SHOW_COUNTER; $count_placement = get_block_setting($block_id, 'count_placement', 'before'); $num = (int) get_block_setting($block_id, 'num', 10); $block = get_block_setting($block_id, 'block', false); if ($cfg) { foreach (array('count_placement', 'num', 'block') as $name) { if (array_key_exists($name, $cfg)) { ${$name} = $cfg[$name]; } } } $id = $this->getName() . $block_id; $class = $this->getName() . '_block'; if ($ctype == 'gedcom' && WT_USER_GEDCOM_ADMIN || $ctype == 'user' && WT_USER_ID) { $title = '<i class="icon-admin" title="' . WT_I18N::translate('Configure') . '" onclick="modalDialog(\'block_edit.php?block_id=' . $block_id . '\', \'' . $this->getTitle() . '\');"></i>'; } else { $title = ''; } $title .= $this->getTitle(); $content = ""; // load the lines from the file $top10 = WT_DB::prepare("SELECT page_parameter, page_count" . " FROM `##hit_counter`" . " WHERE gedcom_id=? AND page_name IN ('individual.php','family.php','source.php','repo.php','note.php','mediaviewer.php')" . " ORDER BY page_count DESC LIMIT " . $num)->execute(array(WT_GED_ID))->FetchAssoc(); if ($block) { $content .= "<table width=\"90%\">"; } else { $content .= "<table>"; } foreach ($top10 as $id => $count) { $record = WT_GedcomRecord::getInstance($id); if ($record && $record->canShow()) { $content .= '<tr valign="top">'; if ($count_placement == 'before') { $content .= '<td dir="ltr" align="right">[' . $count . ']</td>'; } $content .= '<td class="name2" ><a href="' . $record->getHtmlUrl() . '">' . $record->getFullName() . '</a></td>'; if ($count_placement == 'after') { $content .= '<td dir="ltr" align="right">[' . $count . ']</td>'; } $content .= '</tr>'; } } $content .= "</table>"; if ($template) { if ($block) { require WT_THEME_DIR . 'templates/block_small_temp.php'; } else { require WT_THEME_DIR . 'templates/block_main_temp.php'; } } else { return $content; } }
protected function _canShowByType($access_level) { // Hide media objects if they are attached to private records $linked_ids = WT_DB::prepare("SELECT l_from FROM `##link` WHERE l_to=? AND l_file=?")->execute(array($this->xref, $this->gedcom_id))->fetchOneColumn(); foreach ($linked_ids as $linked_id) { $linked_record = WT_GedcomRecord::getInstance($linked_id); if ($linked_record && !$linked_record->canShow($access_level)) { return false; } } // ... otherwise apply default behaviour return parent::_canShowByType($access_level); }
public function modAction($modAction) { global $controller; switch ($modAction) { case 'menu-add-favorite': // Process the "add to user favorites" menu item on indi/fam/etc. pages $record = WT_GedcomRecord::getInstance(WT_Filter::post('xref', WT_REGEX_XREF)); if (WT_USER_ID && $record->canShowName()) { self::addFavorite(array('user_id' => WT_USER_ID, 'gedcom_id' => $record->getGedcomId(), 'gid' => $record->getXref(), 'type' => $record::RECORD_TYPE, 'url' => null, 'note' => null, 'title' => null)); WT_FlashMessages::addMessage(WT_I18N::translate('“%s” has been added to your favorites.', $record->getFullName())); } break; } }
public function __construct() { // Automatically fix broken links if ($this->record && $this->record->canEdit()) { $broken_links = 0; foreach ($this->record->getFacts('HUSB|WIFE|CHIL|FAMS|FAMC|REPO') as $fact) { if (!$fact->isOld() && $fact->getTarget() === null) { $this->record->deleteFact($fact->getFactId(), false); WT_FlashMessages::addMessage(WT_I18N::translate('The link from “%1$s” to “%2$s” has been deleted.', $this->record->getFullName(), $fact->getValue())); $broken_links = true; } } foreach ($this->record->getFacts('NOTE|SOUR|OBJE') as $fact) { // These can be links or inline. Only delete links. if (!$fact->isOld() && $fact->getTarget() === null && preg_match('/^@.*@$/', $fact->getValue())) { $this->record->deleteFact($fact->getFactId(), false); WT_FlashMessages::addMessage(WT_I18N::translate('The link from “%1$s” to “%2$s” has been deleted.', $this->record->getFullName(), $fact->getValue())); $broken_links = true; } } if ($broken_links) { // Reload the updated family $this->record = WT_GedcomRecord::getInstance($this->record->getXref()); } } parent::__construct(); // We want robots to index this page $this->setMetaRobots('index,follow'); // Set a page title if ($this->record) { $this->setCanonicalUrl($this->record->getHtmlUrl()); if ($this->record->canShowName()) { // e.g. "John Doe" or "1881 Census of Wales" $this->setPageTitle($this->record->getFullName()); } else { // e.g. "Individual" or "Source" $record = $this->record; $this->setPageTitle(WT_Gedcom_Tag::getLabel($record::RECORD_TYPE)); } } else { // No such record $this->setPageTitle(WT_I18N::translate('Private')); } }
break; //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// case 'update': // Update a fact $xref = WT_Filter::post('xref', WT_REGEX_XREF); $fact_id = WT_Filter::post('fact_id'); $keep_chan = WT_Filter::postBool('keep_chan'); if (!WT_Filter::checkCsrf()) { $prev_action = WT_Filter::post('prev_action', 'add|edit|addname|editname'); $fact_type = WT_Filter::post('fact_type', WT_REGEX_TAG); Zend_Session::writeClose(); header('Location: ' . WT_SERVER_NAME . WT_SCRIPT_PATH . WT_SCRIPT_NAME . '?action=' . $prev_action . '&xref=' . $xref . '&fact_id=' . $fact_id . '&fact=' . $fact_type); exit; } $record = WT_GedcomRecord::getInstance($xref); check_record_access($record); // Arrays for each GEDCOM line $glevels = WT_Filter::postArray('glevels', '[0-9]'); $tag = WT_Filter::postArray('tag', WT_REGEX_TAG); $text = WT_Filter::postArray('text'); $islink = WT_Filter::postArray('islink', '[01]'); $controller->setPageTitle(WT_I18N::translate('Edit'))->pageHeader(); // If the fact has a DATE or PLAC, then delete any value of Y if ($text[0] == 'Y') { for ($n = 1; $n < count($tag); ++$n) { if ($glevels[$n] == 2 && ($tag[$n] == 'DATE' || $tag[$n] == 'PLAC') && $text[$n]) { $text[0] = ''; break; } }
public static function getFavoritesMenu() { global $REQUIRE_AUTHENTICATION, $controller, $SEARCH_SPIDER; $show_user_favs = WT_USER_ID && array_key_exists('user_favorites', WT_Module::getActiveModules()); $show_gedc_favs = !$REQUIRE_AUTHENTICATION && array_key_exists('gedcom_favorites', WT_Module::getActiveModules()); if ($show_user_favs && !$SEARCH_SPIDER) { if ($show_gedc_favs && !$SEARCH_SPIDER) { $favorites = array_merge(gedcom_favorites_WT_Module::getFavorites(WT_GED_ID), user_favorites_WT_Module::getFavorites(WT_USER_ID)); } else { $favorites = user_favorites_WT_Module::getFavorites(WT_USER_ID); } } else { if ($show_gedc_favs && !$SEARCH_SPIDER) { $favorites = gedcom_favorites_WT_Module::getFavorites(WT_GED_ID); } else { return null; } } // Sort $favorites alphabetically? $menu = new WT_Menu(WT_I18N::translate('Favorites'), '#', 'menu-favorites'); foreach ($favorites as $favorite) { switch ($favorite['type']) { case 'URL': $submenu = new WT_Menu($favorite['title'], $favorite['url']); $menu->addSubMenu($submenu); break; case 'INDI': case 'FAM': case 'SOUR': case 'OBJE': case 'NOTE': $obj = WT_GedcomRecord::getInstance($favorite['gid']); if ($obj && $obj->canShowName()) { $submenu = new WT_Menu($obj->getFullName(), $obj->getHtmlUrl()); $menu->addSubMenu($submenu); } break; } } if ($show_user_favs) { if (isset($controller->record) && $controller->record instanceof WT_GedcomRecord) { $submenu = new WT_Menu(WT_I18N::translate('Add to favorites'), '#'); $submenu->addOnclick("jQuery.post('module.php?mod=user_favorites&mod_action=menu-add-favorite',{xref:'" . $controller->record->getXref() . "'},function(){location.reload();})"); $menu->addSubMenu($submenu); } } return $menu; }
/** * XML </ Relatives> end element handler * * @see RelativesSHandler() */ function RelativesEHandler() { global $list, $repeats, $repeatsStack, $repeatBytes, $parser, $parserStack, $report, $gedrec, $processRepeats, $list_total, $list_private, $generation; $processRepeats--; if ($processRepeats > 0) { return; } // Check if there is any relatives if (count($list) > 0) { // @deprecated //$line = xml_get_current_line_number($parser)-1; $lineoffset = 0; foreach ($repeatsStack as $rep) { $lineoffset += $rep[1]; } //-- read the xml from the file $lines = file($report); while (strpos($lines[$lineoffset + $repeatBytes], "<Relatives") === false && $lineoffset + $repeatBytes > 0) { $lineoffset--; } $lineoffset++; $reportxml = "<tempdoc>\n"; $line_nr = $lineoffset + $repeatBytes; // Relatives Level counter $count = 1; while (0 < $count) { if (strpos($lines[$line_nr], "<Relatives") !== false) { $count++; } elseif (strpos($lines[$line_nr], "</Relatives") !== false) { $count--; } if (0 < $count) { $reportxml .= $lines[$line_nr]; } $line_nr++; } // No need to drag this unset($lines); $reportxml .= "</tempdoc>\n"; // Save original values array_push($parserStack, $parser); $oldgedrec = $gedrec; $list_total = count($list); $list_private = 0; foreach ($list as $key => $value) { if (isset($value->generation)) { $generation = $value->generation; } $tmp = WT_GedcomRecord::getInstance($key); $gedrec = $tmp->privatizeGedcom(WT_USER_ACCESS_LEVEL); //-- start the sax parser $repeat_parser = xml_parser_create(); $parser = $repeat_parser; //-- make sure everything is case sensitive xml_parser_set_option($repeat_parser, XML_OPTION_CASE_FOLDING, false); //-- set the main element handler functions xml_set_element_handler($repeat_parser, "startElement", "endElement"); //-- set the character data handler xml_set_character_data_handler($repeat_parser, "characterData"); if (!xml_parse($repeat_parser, $reportxml, true)) { printf($reportxml . "\nRelativesEHandler XML error: %s at line %d", xml_error_string(xml_get_error_code($repeat_parser)), xml_get_current_line_number($repeat_parser)); exit; } xml_parser_free($repeat_parser); } // Clean up the GLOBAL list array unset($list); $parser = array_pop($parserStack); $gedrec = $oldgedrec; } $temp = array_pop($repeatsStack); $repeats = $temp[0]; $repeatBytes = $temp[1]; }
echo 'colspan="2"'; } echo ' style="text-align: center;">'; echo '<a href="', $place->getURL(), '&action=show" class="formField">', $place->getPlaceName(), '</a>'; echo '</td></tr>'; } echo '</table>'; } echo '</td></tr></table>'; if ($place_id && $action == 'show') { // -- array of names $myindilist = array(); $myfamlist = array(); $positions = WT_DB::prepare("SELECT DISTINCT pl_gid FROM `##placelinks` WHERE pl_p_id=? AND pl_file=?")->execute(array($place_id, WT_GED_ID))->fetchOneColumn(); foreach ($positions as $position) { $record = WT_GedcomRecord::getInstance($position); if ($record && $record->canShow()) { if ($record instanceof WT_Individual) { $myindilist[] = $record; } if ($record instanceof WT_Family) { $myfamlist[] = $record; } } } echo '<br>'; //-- display results $controller->addInlineJavascript('jQuery("#places-tabs").tabs();')->addInlineJavascript('jQuery("#places-tabs").css("visibility", "visible");')->addInlineJavascript('jQuery(".loading-image").css("display", "none");'); echo '<div class="loading-image"> </div>'; echo '<div id="places-tabs"><ul>'; if ($myindilist) {
<p id="save-cancel"> <input type="submit" class="save" value="<?php echo WT_I18N::translate('save'); ?> " onclick="shiftlinks();"> <input type="button" class="cancel" value="<?php echo WT_I18N::translate('close'); ?> " onclick="window.close();"> </p> </form> <?php } elseif ($action == "update" && $paramok) { // Unlink records indicated by radio button ========= if ($exist_links) { foreach (explode(',', $exist_links) as $remLinkId) { $indi = WT_GedcomRecord::getInstance($remLinkId); $indi->removeLinks($mediaid, $update_CHAN != 'no_change'); } } // Add new Links ==================================== if ($more_links) { // array_unique() because parseAddLinks() may includes the gid field, even // when it is also in the list. foreach (array_unique(explode(',', $more_links)) as $addLinkId) { $indi = WT_GedcomRecord::getInstance($addLinkId); $indi->createFact('1 OBJE @' . $mediaid . '@', $update_CHAN != 'no_change'); } } $controller->addInlineJavascript('closePopupAndReloadParent();'); }
// webtrees: Web based Family History software // Copyright (C) 2014 webtrees development team. // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA define('WT_SCRIPT_NAME', 'gedrecord.php'); require './includes/session.php'; $controller = new WT_Controller_Page(); $obj = WT_GedcomRecord::getInstance(WT_Filter::get('pid', WT_REGEX_XREF)); if ($obj instanceof WT_Individual || $obj instanceof WT_Family || $obj instanceof WT_Source || $obj instanceof WT_Repository || $obj instanceof WT_Note || $obj instanceof WT_Media) { Zend_Session::writeClose(); header('Location: ' . WT_SERVER_NAME . WT_SCRIPT_PATH . $obj->getRawUrl()); exit; } elseif (!$obj || !$obj->canShow()) { $controller->pageHeader(); echo '<div class="error">', WT_I18N::translate('This information is private and cannot be shown.'), '</div>'; } else { $controller->pageHeader(); echo '<pre style="white-space:pre-wrap; word-wrap:break-word;">', preg_replace('/@(' . WT_REGEX_XREF . ')@/', '@<a href="gedrecord.php?pid=$1">$1</a>@', WT_Filter::escapeHtml($obj->getGedcom())), '</pre>'; }
static function print_addnewnote_assisted_link($element_id, $xref, $action) { global $controller; // We do not yet support family records if (!WT_GedcomRecord::getInstance($xref) instanceof WT_Individual) { return ''; } // Only modify “add shared note” links on the add/edit actions. // TODO: does the “edit” action work? if ($action != 'add' && $action != 'edit') { return ''; } // There are lots of “add shared note” links. We only need to modify the 2nd one static $n = 0; if (++$n != 2) { return ''; } $controller->addInlineJavascript(' var pid_array=jQuery("#pid_array"); function set_pid_array(pa) { pid_array.val(pa); } '); return '<br>' . '<input type="hidden" name="pid_array" id="pid_array" value="">' . '<a href="#" onclick="return addnewnote_assisted(document.getElementById(\'' . $element_id . '\'), \'' . $xref . '\');">' . WT_I18N::translate('Create a new shared note using assistant') . '</a>'; }
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>'; } }
public function getCartList() { global $WT_SESSION; // Keep track of the INDI from the parent page, otherwise it will // get lost after ajax updates $pid = WT_Filter::get('pid', WT_REGEX_XREF); if (!$WT_SESSION->cart[WT_GED_ID]) { $out = WT_I18N::translate('Your clippings cart is empty.'); } else { $out = '<ul>'; foreach (array_keys($WT_SESSION->cart[WT_GED_ID]) as $xref) { $record = WT_GedcomRecord::getInstance($xref); if ($record && ($record::RECORD_TYPE == 'INDI' || $record::RECORD_TYPE == 'FAM')) { // Just show INDI/FAM in the sidbar switch ($record::RECORD_TYPE) { case 'INDI': $icon = 'icon-indis'; break; case 'FAM': $icon = 'icon-sfamily'; break; } $out .= '<li>'; if (!empty($icon)) { $out .= '<i class="' . $icon . '"></i>'; } $out .= '<a href="' . $record->getHtmlUrl() . '">'; if ($record::RECORD_TYPE == 'INDI') { $out .= $record->getSexImage(); } $out .= ' ' . $record->getFullName() . ' '; if ($record::RECORD_TYPE == 'INDI' && $record->canShow()) { $out .= ' (' . $record->getLifeSpan() . ')'; } $out .= '</a>'; $out .= '<a class="icon-remove remove_cart" href="module.php?mod=' . $this->getName() . '&mod_action=ajax&sb_action=clippings&remove=' . $xref . '&pid=' . $pid . '" title="' . WT_I18N::translate('Remove') . '"></a>'; $out .= '</li>'; } } $out .= '</ul>'; } if ($WT_SESSION->cart[WT_GED_ID]) { $out .= '<br><a href="module.php?mod=' . $this->getName() . '&mod_action=ajax&sb_action=clippings&empty=true&pid=' . $pid . '" class="remove_cart">' . WT_I18N::translate('Empty the clippings cart') . '</a>' . help_link('empty_cart', $this->getName()) . '<br>' . '<a href="module.php?mod=' . $this->getName() . '&mod_action=ajax&sb_action=clippings&download=true&pid=' . $pid . '" class="add_cart">' . WT_I18N::translate('Download') . '</a>'; } $record = WT_Individual::getInstance($pid); if ($record && !array_key_exists($record->getXref(), $WT_SESSION->cart[WT_GED_ID])) { $out .= '<br><a href="module.php?mod=' . $this->getName() . '&mod_action=ajax&sb_action=clippings&add=' . $pid . '&pid=' . $pid . '" class="add_cart"><i class="icon-clippings"></i> ' . WT_I18N::translate('Add %s to the clippings cart', $record->getFullName()) . '</a>'; } return $out; }
public static function createRecord($gedcom, $gedcom_id) { if (preg_match('/^0 @(' . WT_REGEX_XREF . ')@ (' . WT_REGEX_TAG . ')/', $gedcom, $match)) { $xref = $match[1]; $type = $match[2]; } else { throw new Exception('Invalid argument to WT_GedcomRecord::createRecord(' . $gedcom . ')'); } if (strpos("\r", $gedcom) !== false) { // MSDOS line endings will break things in horrible ways throw new Exception('Evil line endings found in WT_GedcomRecord::createRecord(' . $gedcom . ')'); } // webtrees creates XREFs containing digits. Anything else (e.g. “new”) is just a placeholder. if (!preg_match('/\\d/', $xref)) { $xref = get_new_xref($type); $gedcom = preg_replace('/^0 @(' . WT_REGEX_XREF . ')@/', '0 @' . $xref . '@', $gedcom); } // Create a change record, if not already present if (!preg_match('/\\n1 CHAN/', $gedcom)) { $gedcom .= "\n1 CHAN\n2 DATE " . date('d M Y') . "\n3 TIME " . date('H:i:s') . "\n2 _WT_USER " . WT_USER_NAME; } // Create a pending change WT_DB::prepare("INSERT INTO `##change` (gedcom_id, xref, old_gedcom, new_gedcom, user_id) VALUES (?, ?, '', ?, ?)")->execute(array($gedcom_id, $xref, $gedcom, WT_USER_ID)); // Accept this pending change if (Auth::user()->getSetting('auto_accept')) { accept_all_changes($xref, $gedcom_id); } // Clear this record from the cache self::$pending_record_cache = null; Log::addEditLog('Create: ' . $type . ' ' . $xref); // Return the newly created record return WT_GedcomRecord::getInstance($xref); }
public function getBlock($block_id, $template = true, $cfg = null) { global $ctype, $WEBTREES_EMAIL; $changes = WT_DB::prepare("SELECT 1" . " FROM `##change`" . " WHERE status='pending'" . " LIMIT 1")->fetchOne(); $days = get_block_setting($block_id, 'days', 1); $sendmail = get_block_setting($block_id, 'sendmail', true); $block = get_block_setting($block_id, 'block', true); if ($cfg) { foreach (array('days', 'sendmail', 'block') as $name) { if (array_key_exists($name, $cfg)) { ${$name} = $cfg[$name]; } } } if ($changes && $sendmail == 'yes') { // There are pending changes - tell moderators/managers/administrators about them. if (WT_TIMESTAMP - WT_Site::getPreference('LAST_CHANGE_EMAIL') > 60 * 60 * 24 * $days) { // Which users have pending changes? foreach (User::all() as $user) { if ($user->getSetting('contactmethod') !== 'none') { foreach (WT_Tree::getAll() as $tree) { if (exists_pending_change($user, $tree)) { WT_I18N::init($user->getSetting('language')); WT_Mail::systemMessage($tree, $user, WT_I18N::translate('Pending changes'), WT_I18N::translate('There are pending changes for you to moderate.') . WT_Mail::EOL . WT_MAIL::EOL . '<a href="' . WT_SERVER_NAME . WT_SCRIPT_PATH . 'index.php?ged=' . WT_GEDURL . '">' . WT_SERVER_NAME . WT_SCRIPT_PATH . 'index.php?ged=' . WT_GEDURL . '</a>'); WT_I18N::init(WT_LOCALE); } } } } WT_Site::setPreference('LAST_CHANGE_EMAIL', WT_TIMESTAMP); } if (WT_USER_CAN_EDIT) { $id = $this->getName() . $block_id; $class = $this->getName() . '_block'; if ($ctype == 'gedcom' && WT_USER_GEDCOM_ADMIN || $ctype == 'user' && WT_USER_ID) { $title = '<i class="icon-admin" title="' . WT_I18N::translate('Configure') . '" onclick="modalDialog(\'block_edit.php?block_id=' . $block_id . '\', \'' . $this->getTitle() . '\');"></i>'; } else { $title = ''; } $title .= $this->getTitle() . help_link('review_changes', $this->getName()); $content = ''; if (WT_USER_CAN_ACCEPT) { $content .= "<a href=\"#\" onclick=\"window.open('edit_changes.php','_blank', chan_window_specs); return false;\">" . WT_I18N::translate('There are pending changes for you to moderate.') . "</a><br>"; } if ($sendmail == "yes") { $content .= WT_I18N::translate('Last email reminder was sent ') . format_timestamp(WT_Site::getPreference('LAST_CHANGE_EMAIL')) . "<br>"; $content .= WT_I18N::translate('Next email reminder will be sent after ') . format_timestamp(WT_Site::getPreference('LAST_CHANGE_EMAIL') + 60 * 60 * 24 * $days) . "<br><br>"; } $changes = WT_DB::prepare("SELECT xref" . " FROM `##change`" . " WHERE status='pending'" . " AND gedcom_id=?" . " GROUP BY xref")->execute(array(WT_GED_ID))->fetchAll(); foreach ($changes as $change) { $record = WT_GedcomRecord::getInstance($change->xref); if ($record->canShow()) { $content .= '<b>' . $record->getFullName() . '</b>'; $content .= $block ? '<br>' : ' '; $content .= '<a href="' . $record->getHtmlUrl() . '">' . WT_I18N::translate('View the changes') . '</a>'; $content .= '<br>'; } } if ($template) { if ($block) { require WT_THEME_DIR . 'templates/block_small_temp.php'; } else { require WT_THEME_DIR . 'templates/block_main_temp.php'; } } else { return $content; } } } }
public function getTarget() { $xref = trim($this->getValue(), '@'); switch ($this->tag) { case 'FAMC': case 'FAMS': return WT_Family::getInstance($xref, $this->getParent()->getGedcomId()); case 'HUSB': case 'WIFE': case 'CHIL': return WT_Individual::getInstance($xref, $this->getParent()->getGedcomId()); case 'SOUR': return WT_Source::getInstance($xref, $this->getParent()->getGedcomId()); case 'OBJE': return WT_Media::getInstance($xref, $this->getParent()->getGedcomId()); case 'REPO': return WT_Repository::getInstance($xref, $this->getParent()->getGedcomId()); case 'NOTE': return WT_Note::getInstance($xref, $this->getParent()->getGedcomId()); default: return WT_GedcomRecord::getInstance($xref, $this->getParent()->getGedcomId()); } }
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>'; }
function _eventQuery($type, $direction, $facts) { $eventTypes = array('BIRT' => WT_I18N::translate('birth'), 'DEAT' => WT_I18N::translate('death'), 'MARR' => WT_I18N::translate('marriage'), 'ADOP' => WT_I18N::translate('adoption'), 'BURI' => WT_I18N::translate('burial'), 'CENS' => WT_I18N::translate('census added')); $fact_query = "IN ('" . str_replace('|', "','", $facts) . "')"; if ($direction != 'ASC') { $direction = 'DESC'; } $rows = self::_runSQL('' . ' SELECT SQL_CACHE' . ' d_gid AS id,' . ' d_year AS year,' . ' d_fact AS fact,' . ' d_type AS type' . ' FROM' . " `##dates`" . ' WHERE' . " d_file={$this->_ged_id} AND" . " d_gid<>'HEAD' AND" . " d_fact {$fact_query} AND" . ' d_julianday1<>0' . ' ORDER BY' . " d_julianday1 {$direction}, d_type LIMIT 1"); if (!isset($rows[0])) { return ''; } $row = $rows[0]; $record = WT_GedcomRecord::getInstance($row['id']); switch ($type) { default: case 'full': if ($record->canShow()) { $result = $record->format_list('span', false, $record->getFullName()); } else { $result = WT_I18N::translate('This information is private and cannot be shown.'); } break; case 'year': $date = new WT_Date($row['type'] . ' ' . $row['year']); $result = $date->Display(true); break; case 'type': if (isset($eventTypes[$row['fact']])) { $result = $eventTypes[$row['fact']]; } else { $result = WT_Gedcom_Tag::getLabel($row['fact']); } break; case 'name': $result = "<a href=\"" . $record->getHtmlUrl() . "\">" . $record->getFullName() . "</a>"; break; case 'place': $fact = $record->getFirstFact($row['fact']); if ($fact) { $result = format_fact_place($fact, true, true, true); } else { $result = WT_I18N::translate('Private'); } break; } return $result; }
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(); } }
/** * Handles searches entered in the top search box in the themes and * prepares the search to do a general search on individuals, families and sources. */ function TopSearch() { // first set some required variables. Search only in current gedcom, only in individuals. $this->srindi = "yes"; // Enable the default gedcom for search $str = str_replace(array(".", "-", " "), array("_", "_", "_"), WT_GEDCOM); $_REQUEST["{$str}"] = "yes"; // Then see if an ID is typed in. If so, we might want to jump there. if (isset($this->query)) { $record = WT_GedcomRecord::getInstance($this->query); if ($record && $record->canShow()) { header('Location: ' . WT_SERVER_NAME . WT_SCRIPT_PATH . $record->getRawUrl()); exit; } } }
function print_changes_table($change_ids, $sort) { global $controller; $n = 0; $table_id = 'table-chan-' . Uuid::uuid4(); // lists requires a unique ID in case there are multiple lists per page switch ($sort) { case 'name': //name $aaSorting = "[5,'asc'], [4,'desc']"; break; case 'date_asc': //date ascending $aaSorting = "[4,'asc'], [5,'asc']"; break; case 'date_desc': //date descending $aaSorting = "[4,'desc'], [5,'asc']"; break; } $html = ''; $controller->addExternalJavascript(WT_JQUERY_DATATABLES_URL)->addInlineJavascript(' jQuery.fn.dataTableExt.oSort["unicode-asc" ]=function(a,b) {return a.replace(/<[^<]*>/, "").localeCompare(b.replace(/<[^<]*>/, ""))}; jQuery.fn.dataTableExt.oSort["unicode-desc"]=function(a,b) {return b.replace(/<[^<]*>/, "").localeCompare(a.replace(/<[^<]*>/, ""))}; jQuery("#' . $table_id . '").dataTable({ dom: \'t\', paging: false, autoWidth:false, lengthChange: false, filter: false, ' . WT_I18N::datatablesI18N() . ', jQueryUI: true, sorting: [' . $aaSorting . '], columns: [ /* 0-Type */ { sortable: false, class: "center" }, /* 1-Record */ { dataSort: 5 }, /* 2-Change */ { dataSort: 4 }, /* 3-By */ null, /* 4-DATE */ { visible: false }, /* 5-SORTNAME */{ type: "unicode", visible: false } ] }); '); //-- table header $html .= '<table id="' . $table_id . '" class="width100">'; $html .= '<thead><tr>'; $html .= '<th> </th>'; $html .= '<th>' . WT_I18N::translate('Record') . '</th>'; $html .= '<th>' . WT_Gedcom_Tag::getLabel('CHAN') . '</th>'; $html .= '<th>' . WT_Gedcom_Tag::getLabel('_WT_USER') . '</th>'; $html .= '<th>DATE</th>'; //hidden by datatables code $html .= '<th>SORTNAME</th>'; //hidden by datatables code $html .= '</tr></thead><tbody>'; //-- table body foreach ($change_ids as $change_id) { $record = WT_GedcomRecord::getInstance($change_id); if (!$record || !$record->canShow()) { continue; } $html .= '<tr><td>'; switch ($record::RECORD_TYPE) { case 'INDI': $icon = $record->getSexImage('small', '', '', false); break; case 'FAM': $icon = '<i class="icon-button_family"></i>'; break; case 'OBJE': $icon = '<i class="icon-button_media"></i>'; break; case 'NOTE': $icon = '<i class="icon-button_note"></i>'; break; case 'SOUR': $icon = '<i class="icon-button_source"></i>'; break; case 'REPO': $icon = '<i class="icon-button_repository"></i>'; break; default: $icon = ' '; break; } $html .= '<a href="' . $record->getHtmlUrl() . '">' . $icon . '</a>'; $html .= '</td>'; ++$n; //-- Record name(s) $name = $record->getFullName(); $html .= '<td class="wrap">'; $html .= '<a href="' . $record->getHtmlUrl() . '">' . $name . '</a>'; if ($record instanceof WT_Individual) { $addname = $record->getAddName(); if ($addname) { $html .= '<div class="indent"><a href="' . $record->getHtmlUrl() . '">' . $addname . '</a></div>'; } } $html .= "</td>"; //-- Last change date/time $html .= "<td class='wrap'>" . $record->lastChangeTimestamp() . "</td>"; //-- Last change user $html .= "<td class='wrap'>" . $record->lastChangeUser() . "</td>"; //-- change date (sortable) hidden by datatables code $html .= "<td>" . $record->lastChangeTimestamp(true) . "</td>"; //-- names (sortable) hidden by datatables code $html .= "<td>" . $record->getSortName() . "</td></tr>"; } $html .= '</tbody></table>'; return $html; }
static function compareClippings($a, $b) { $a = WT_GedcomRecord::getInstance($a); $b = WT_GedcomRecord::getInstance($b); if ($a && $b) { switch ($a::RECORD_TYPE) { case 'INDI': $t1 = 1; break; case 'FAM': $t1 = 2; break; case 'SOUR': $t1 = 3; break; case 'REPO': $t1 = 4; break; case 'OBJE': $t1 = 5; break; case 'NOTE': $t1 = 6; break; default: $t1 = 7; break; } switch ($b::RECORD_TYPE) { case 'INDI': $t2 = 1; break; case 'FAM': $t2 = 2; break; case 'SOUR': $t2 = 3; break; case 'REPO': $t2 = 4; break; case 'OBJE': $t2 = 5; break; case 'NOTE': $t2 = 6; break; default: $t2 = 7; break; } if ($t1 != $t2) { return $t1 - $t2; } else { return WT_GedcomRecord::compare($a, $b); } } else { return 0; } }
public function getBlock($block_id, $template = true, $cfg = null) { global $ctype, $show_full, $PEDIGREE_FULL_DETAILS, $controller; self::updateSchema(); // make sure the favorites table has been created $action = WT_Filter::get('action'); switch ($action) { case 'deletefav': $favorite_id = WT_Filter::getInteger('favorite_id'); if ($favorite_id) { self::deleteFavorite($favorite_id); } break; case 'addfav': $gid = WT_Filter::get('gid', WT_REGEX_XREF); $favnote = WT_Filter::get('favnote'); $url = WT_Filter::getUrl('url'); $favtitle = WT_Filter::get('favtitle'); if ($gid) { $record = WT_GedcomRecord::getInstance($gid); if ($record && $record->canShow()) { self::addFavorite(array('user_id' => $ctype == 'user' ? WT_USER_ID : null, 'gedcom_id' => WT_GED_ID, 'gid' => $record->getXref(), 'type' => $record::RECORD_TYPE, 'url' => null, 'note' => $favnote, 'title' => $favtitle)); } } elseif ($url) { self::addFavorite(array('user_id' => $ctype == 'user' ? WT_USER_ID : null, 'gedcom_id' => WT_GED_ID, 'gid' => null, 'type' => 'URL', 'url' => $url, 'note' => $favnote, 'title' => $favtitle ? $favtitle : $url)); } break; } $block = get_block_setting($block_id, 'block', false); if ($cfg) { foreach (array('block') as $name) { if (array_key_exists($name, $cfg)) { ${$name} = $cfg[$name]; } } } // Override GEDCOM configuration temporarily if (isset($show_full)) { $saveShowFull = $show_full; } $savePedigreeFullDetails = $PEDIGREE_FULL_DETAILS; $show_full = 1; $PEDIGREE_FULL_DETAILS = 1; $userfavs = $this->getFavorites($ctype == 'user' ? WT_USER_ID : WT_GED_ID); if (!is_array($userfavs)) { $userfavs = array(); } $id = $this->getName() . $block_id; $class = $this->getName() . '_block'; $title = $this->getTitle(); if (WT_USER_ID) { $controller->addExternalJavascript(WT_STATIC_URL . 'js/autocomplete.js')->addInlineJavascript('autocomplete();'); } $content = ''; $style = 2; // 1 means "regular box", 2 means "wide box" if ($userfavs) { foreach ($userfavs as $key => $favorite) { if (isset($favorite['id'])) { $key = $favorite['id']; } $removeFavourite = '<a class="font9" href="index.php?ctype=' . $ctype . '&action=deletefav&favorite_id=' . $key . '" onclick="return confirm(\'' . WT_I18N::translate('Are you sure you want to remove this item from your list of favorites?') . '\');">' . WT_I18N::translate('Remove') . '</a> '; if ($favorite['type'] == 'URL') { $content .= '<div id="boxurl' . $key . '.0" class="person_box">'; if ($ctype == 'user' || WT_USER_GEDCOM_ADMIN) { $content .= $removeFavourite; } $content .= '<a href="' . $favorite['url'] . '"><b>' . $favorite['title'] . '</b></a>'; $content .= '<br>' . $favorite['note']; $content .= '</div>'; } else { $record = WT_GedcomRecord::getInstance($favorite['gid']); if ($record && $record->canShow()) { if ($record instanceof WT_Individual) { $content .= '<div id="box' . $favorite["gid"] . '.0" class="person_box action_header'; switch ($record->getsex()) { case 'M': break; case 'F': $content .= 'F'; break; case 'U': $content .= 'NN'; break; } $content .= '">'; if ($ctype == "user" || WT_USER_GEDCOM_ADMIN) { $content .= $removeFavourite; } ob_start(); print_pedigree_person($record, $style, 1, $key); $content .= ob_get_clean(); $content .= $favorite['note']; $content .= '</div>'; } else { $content .= '<div id="box' . $favorite['gid'] . '.0" class="person_box">'; if ($ctype == 'user' || WT_USER_GEDCOM_ADMIN) { $content .= $removeFavourite; } $content .= $record->format_list('span'); $content .= '<br>' . $favorite['note']; $content .= '</div>'; } } } } } if ($ctype == 'user' || WT_USER_GEDCOM_ADMIN) { $uniqueID = Uuid::uuid4(); // This block can theoretically appear multiple times, so use a unique ID. $content .= '<div class="add_fav_head">'; $content .= '<a href="#" onclick="return expand_layer(\'add_fav' . $uniqueID . '\');">' . WT_I18N::translate('Add a new favorite') . '<i id="add_fav' . $uniqueID . '_img" class="icon-plus"></i></a>'; $content .= '</div>'; $content .= '<div id="add_fav' . $uniqueID . '" style="display: none;">'; $content .= '<form name="addfavform" method="get" action="index.php">'; $content .= '<input type="hidden" name="action" value="addfav">'; $content .= '<input type="hidden" name="ctype" value="' . $ctype . '">'; $content .= '<input type="hidden" name="ged" value="' . WT_GEDCOM . '">'; $content .= '<div class="add_fav_ref">'; $content .= '<input type="radio" name="fav_category" value="record" checked="checked" onclick="jQuery(\'#gid' . $uniqueID . '\').removeAttr(\'disabled\'); jQuery(\'#url, #favtitle\').attr(\'disabled\',\'disabled\').val(\'\');">'; $content .= '<label for="gid' . $uniqueID . '">' . WT_I18N::translate('Enter an individual, family, or source ID') . '</label>'; $content .= '<input class="pedigree_form" data-autocomplete-type="IFSRO" type="text" name="gid" id="gid' . $uniqueID . '" size="5" value="">'; $content .= ' ' . print_findindi_link('gid' . $uniqueID); $content .= ' ' . print_findfamily_link('gid' . $uniqueID); $content .= ' ' . print_findsource_link('gid' . $uniqueID); $content .= ' ' . print_findrepository_link('gid' . $uniqueID); $content .= ' ' . print_findnote_link('gid' . $uniqueID); $content .= ' ' . print_findmedia_link('gid' . $uniqueID); $content .= '</div>'; $content .= '<div class="add_fav_url">'; $content .= '<input type="radio" name="fav_category" value="url" onclick="jQuery(\'#url, #favtitle\').removeAttr(\'disabled\'); jQuery(\'#gid' . $uniqueID . '\').attr(\'disabled\',\'disabled\').val(\'\');">'; $content .= '<input type="text" name="url" id="url" size="20" value="" placeholder="' . WT_Gedcom_Tag::getLabel('URL') . '" disabled="disabled"> '; $content .= '<input type="text" name="favtitle" id="favtitle" size="20" value="" placeholder="' . WT_I18N::translate('Title') . '" disabled="disabled">'; $content .= '<p>' . WT_I18N::translate('Enter an optional note about this favorite') . '</p>'; $content .= '<textarea name="favnote" rows="6" cols="50"></textarea>'; $content .= '</div>'; $content .= '<input type="submit" value="' . WT_I18N::translate('Add') . '">'; $content .= '</form></div>'; } if ($template) { if ($block) { require WT_THEME_DIR . 'templates/block_small_temp.php'; } else { require WT_THEME_DIR . 'templates/block_main_temp.php'; } } else { return $content; } // Restore GEDCOM configuration unset($show_full); if (isset($saveShowFull)) { $show_full = $saveShowFull; } $PEDIGREE_FULL_DETAILS = $savePedigreeFullDetails; }
echo '></td>'; echo '<td>', nl2br(WT_Filter::escapeHtml($fact2->getGedcom()), false), '</td></tr>'; } } echo '</table>'; echo '</td></tr>'; echo '</table>'; echo '<input type="submit" value="', WT_I18N::translate('save'), '">'; echo '</form></div>'; } elseif ($action == 'merge') { echo '<div id="merge3"><h3>', WT_I18N::translate('Merge records'), '</h3>'; if ($GEDCOM == $ged2) { //-- replace all the records that linked to gid2 $ids = fetch_all_links($gid2, WT_GED_ID); foreach ($ids as $id) { $record = WT_GedcomRecord::getInstance($id); if (!$record->isOld()) { echo WT_I18N::translate('Updating linked record'), ' ', $id, '<br>'; $gedcom = str_replace("@{$gid2}@", "@{$gid1}@", $record->getGedcom()); $gedcom = preg_replace('/(\\n1.*@.+@.*(?:(?:\\n[2-9].*)*))((?:\\n1.*(?:\\n[2-9].*)*)*\\1)/', '$2', $gedcom); $record->updateRecord($gedcom, true); } } // Update any linked user-accounts WT_DB::prepare("UPDATE `##user_gedcom_setting`" . " SET setting_value=?" . " WHERE gedcom_id=? AND setting_name='gedcomid' AND setting_value=?")->execute(array($gid2, WT_GED_ID, $gid1)); // Merge hit counters $hits = WT_DB::prepare("SELECT page_name, SUM(page_count)" . " FROM `##hit_counter`" . " WHERE gedcom_id=? AND page_parameter IN (?, ?)" . " GROUP BY page_name")->execute(array(WT_GED_ID, $gid1, $gid2))->fetchAssoc(); foreach ($hits as $page_name => $page_count) { WT_DB::prepare("UPDATE `##hit_counter` SET page_count=?" . " WHERE gedcom_id=? AND page_name=? AND page_parameter=?")->execute(array($page_count, WT_GED_ID, $page_name, $gid1)); } WT_DB::prepare("DELETE FROM `##hit_counter`" . " WHERE gedcom_id=? AND page_parameter=?")->execute(array(WT_GED_ID, $gid2));
// Level 1 links $source->deleteFact($fact->getFactId(), true); } elseif (strpos($fact->getGedcom(), ' @' . $target . '@')) { // Level 2-3 links $source->updateFact($fact->getFactId(), preg_replace(array('/\\n2 OBJE @' . $target . '@(\\n[3-9].*)*/', '/\\n3 OBJE @' . $target . '@(\\n[4-9].*)*/'), '', $fact->getGedcom()), true); } } } } } else { header('HTTP/1.0 406 Not Acceptable'); } break; case 'reject-changes': // Reject all the pending changes for a record $record = WT_GedcomRecord::getInstance(WT_Filter::post('xref', WT_REGEX_XREF)); if ($record && WT_USER_CAN_ACCEPT && $record->canShow() && $record->canEdit()) { WT_FlashMessages::addMessage(WT_I18N::translate('The changes to “%s” have been rejected.', $record->getFullName())); reject_all_changes($record->getXref(), $record->getGedcomId()); } else { header('HTTP/1.0 406 Not Acceptable'); } break; case 'theme': // Change the current theme $theme_dir = WT_Filter::post('theme'); if (WT_Site::getPreference('ALLOW_USER_THEMES') && in_array($theme_dir, get_theme_names())) { $WT_SESSION->theme_dir = $theme_dir; if (Auth::id()) { // Remember our selection Auth::user()->setSetting('theme', $theme_dir);
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; }