コード例 #1
0
 /**
  * get edit menu
  */
 public function getEditMenu()
 {
     if (!$this->record || $this->record->isPendingDeletion()) {
         return null;
     }
     // edit menu
     $menu = new Menu(I18N::translate('Edit'), '#', 'menu-record');
     // edit raw
     if (Auth::isAdmin() || Auth::isEditor($this->record->getTree()) && $this->record->getTree()->getPreference('SHOW_GEDCOM_RECORD')) {
         $menu->addSubmenu(new Menu(I18N::translate('Edit raw GEDCOM'), '#', 'menu-record-editraw', array('onclick' => 'return edit_raw("' . $this->record->getXref() . '");')));
     }
     // delete
     if (Auth::isEditor($this->record->getTree())) {
         $menu->addSubmenu(new Menu(I18N::translate('Delete'), '#', 'menu-record-del', array('onclick' => 'return delete_record("' . I18N::translate('Are you sure you want to delete “%s”?', Filter::escapeJs(Filter::unescapeHtml($this->record->getFullName()))) . '", "' . $this->record->getXref() . '");')));
     }
     // add to favorites
     if (Module::getModuleByName('user_favorites')) {
         $menu->addSubmenu(new Menu(I18N::translate('Add to favorites'), '#', 'menu-record-addfav', array('onclick' => 'jQuery.post("module.php?mod=user_favorites&mod_action=menu-add-favorite" ,{xref:"' . $this->record->getXref() . '"},function(){location.reload();})')));
     }
     // Get the link for the first submenu and set it as the link for the main menu
     if ($menu->getSubmenus()) {
         $submenus = $menu->getSubmenus();
         $menu->setLink($submenus[0]->getLink());
         $menu->setAttrs($submenus[0]->getAttrs());
     }
     return $menu;
 }
コード例 #2
0
 /**
  * Startup activity
  */
 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->isPendingDeletion() && $fact->getTarget() === null) {
                 $this->record->deleteFact($fact->getFactId(), false);
                 FlashMessages::addMessage(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->isPendingDeletion() && $fact->getTarget() === null && preg_match('/^@.*@$/', $fact->getValue())) {
                 $this->record->deleteFact($fact->getFactId(), false);
                 FlashMessages::addMessage(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 = GedcomRecord::getInstance($this->record->getXref(), $this->record->getTree());
         }
     }
     parent::__construct();
     // We want robots to index this page
     $this->setMetaRobots('index,follow');
     // Set a page title
     if ($this->record) {
         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(GedcomTag::getLabel($record::RECORD_TYPE));
         }
     } else {
         // No such record
         $this->setPageTitle(I18N::translate('Private'));
     }
 }
コード例 #3
0
 /**
  * get edit menu
  */
 public function getEditMenu()
 {
     if (!$this->record || $this->record->isPendingDeletion()) {
         return null;
     }
     // edit menu
     $menu = new Menu(I18N::translate('Edit'), '#', 'menu-record');
     // edit raw
     if (Auth::isAdmin() || Auth::isEditor($this->record->getTree()) && $this->record->getTree()->getPreference('SHOW_GEDCOM_RECORD')) {
         $menu->addSubmenu(new Menu(I18N::translate('Edit the raw GEDCOM'), '#', 'menu-record-editraw', array('onclick' => 'return edit_raw("' . $this->record->getXref() . '");')));
     }
     // delete
     if (Auth::isEditor($this->record->getTree())) {
         $menu->addSubmenu(new Menu(I18N::translate('Delete'), '#', 'menu-record-del', array('onclick' => 'return delete_record("' . I18N::translate('Are you sure you want to delete “%s”?', Filter::escapeJs(Filter::unescapeHtml($this->record->getFullName()))) . '", "' . $this->record->getXref() . '");')));
     }
     return $menu;
 }
コード例 #4
0
ファイル: FunctionsPrint.php プロジェクト: jflash/webtrees
 /**
  * Print fact DATE/TIME
  *
  * @param Fact $event event containing the date/age
  * @param GedcomRecord $record the person (or couple) whose ages should be printed
  * @param bool $anchor option to print a link to calendar
  * @param bool $time option to print TIME value
  *
  * @return string
  */
 public static function formatFactDate(Fact $event, GedcomRecord $record, $anchor, $time)
 {
     global $pid;
     $factrec = $event->getGedcom();
     $html = '';
     // Recorded age
     if (preg_match('/\\n2 AGE (.+)/', $factrec, $match)) {
         $fact_age = $match[1];
     } else {
         $fact_age = '';
     }
     if (preg_match('/\\n2 HUSB\\n3 AGE (.+)/', $factrec, $match)) {
         $husb_age = $match[1];
     } else {
         $husb_age = '';
     }
     if (preg_match('/\\n2 WIFE\\n3 AGE (.+)/', $factrec, $match)) {
         $wife_age = $match[1];
     } else {
         $wife_age = '';
     }
     // Calculated age
     if (preg_match('/\\n2 DATE (.+)/', $factrec, $match)) {
         $date = new Date($match[1]);
         $html .= ' ' . $date->display($anchor);
         // time
         if ($time && preg_match('/\\n3 TIME (.+)/', $factrec, $match)) {
             $html .= ' – <span class="date">' . $match[1] . '</span>';
         }
         $fact = $event->getTag();
         if ($record instanceof Individual) {
             if ($fact === 'BIRT' && $record->getTree()->getPreference('SHOW_PARENTS_AGE')) {
                 // age of parents at child birth
                 $html .= self::formatParentsAges($record, $date);
             } elseif ($fact !== 'CHAN' && $fact !== '_TODO') {
                 // age at event
                 $birth_date = $record->getBirthDate();
                 // Can't use getDeathDate(), as this also gives BURI/CREM events, which
                 // wouldn't give the correct "days after death" result for people with
                 // no DEAT.
                 $death_event = $record->getFirstFact('DEAT');
                 if ($death_event) {
                     $death_date = $death_event->getDate();
                 } else {
                     $death_date = new Date('');
                 }
                 $ageText = '';
                 if (Date::compare($date, $death_date) <= 0 || !$record->isDead() || $fact == 'DEAT') {
                     // Before death, print age
                     $age = Date::getAgeGedcom($birth_date, $date);
                     // Only show calculated age if it differs from recorded age
                     if ($age != '') {
                         if ($fact_age != '' && $fact_age != $age || $fact_age == '' && $husb_age == '' && $wife_age == '' || $husb_age != '' && $record->getSex() == 'M' && $husb_age != $age || $wife_age != '' && $record->getSex() == 'F' && $wife_age != $age) {
                             if ($age != "0d") {
                                 $ageText = '(' . I18N::translate('Age') . ' ' . FunctionsDate::getAgeAtEvent($age, false) . ')';
                             }
                         }
                     }
                 }
                 if ($fact != 'DEAT' && Date::compare($date, $death_date) >= 0) {
                     // After death, print time since death
                     $age = FunctionsDate::getAgeAtEvent(Date::getAgeGedcom($death_date, $date), true);
                     if ($age != '') {
                         if (Date::getAgeGedcom($death_date, $date) == "0d") {
                             $ageText = '(' . I18N::translate('on the date of death') . ')';
                         } else {
                             $ageText = '(' . $age . ' ' . I18N::translate('after death') . ')';
                             // Family events which occur after death are probably errors
                             if ($event->getParent() instanceof Family) {
                                 $ageText .= '<i class="icon-warning"></i>';
                             }
                         }
                     }
                 }
                 if ($ageText) {
                     $html .= ' <span class="age">' . $ageText . '</span>';
                 }
             }
         } elseif ($record instanceof Family) {
             $indi = Individual::getInstance($pid, $record->getTree());
             if ($indi) {
                 $birth_date = $indi->getBirthDate();
                 $death_date = $indi->getDeathDate();
                 $ageText = '';
                 if (Date::compare($date, $death_date) <= 0) {
                     $age = Date::getAgeGedcom($birth_date, $date);
                     // Only show calculated age if it differs from recorded age
                     if ($age != '' && $age > 0) {
                         if ($fact_age != '' && $fact_age != $age || $fact_age == '' && $husb_age == '' && $wife_age == '' || $husb_age != '' && $indi->getSex() == 'M' && $husb_age != $age || $wife_age != '' && $indi->getSex() == 'F' && $wife_age != $age) {
                             $ageText = '(' . I18N::translate('Age') . ' ' . FunctionsDate::getAgeAtEvent($age, false) . ')';
                         }
                     }
                 }
                 if ($ageText) {
                     $html .= ' <span class="age">' . $ageText . '</span>';
                 }
             }
         }
     } else {
         // 1 DEAT Y with no DATE => print YES
         // 1 BIRT 2 SOUR @S1@ => print YES
         // 1 DEAT N is not allowed
         // It is not proper GEDCOM form to use a N(o) value with an event tag to infer that it did not happen.
         $factdetail = explode(' ', trim($factrec));
         if (isset($factdetail) && (count($factdetail) == 3 && strtoupper($factdetail[2]) == 'Y') || count($factdetail) == 4 && $factdetail[2] == 'SOUR') {
             $html .= I18N::translate('yes');
         }
     }
     // print gedcom ages
     foreach (array(GedcomTag::getLabel('AGE') => $fact_age, GedcomTag::getLabel('HUSB') => $husb_age, GedcomTag::getLabel('WIFE') => $wife_age) as $label => $age) {
         if ($age != '') {
             $html .= ' <span class="label">' . $label . ':</span> <span class="age">' . FunctionsDate::getAgeAtEvent($age, false) . '</span>';
         }
     }
     return $html;
 }
コード例 #5
0
ファイル: FunctionsImport.php プロジェクト: tronsmit/webtrees
 /**
  * Accept all pending changes for a specified record.
  *
  * @param GedcomRecord $record
  */
 public static function rejectAllChanges(GedcomRecord $record)
 {
     Database::prepare("UPDATE `##change`" . " SET status = 'rejected'" . " WHERE status = 'pending' AND xref = :xref AND gedcom_id = :tree_id")->execute(array('xref' => $record->getXref(), 'tree_id' => $record->getTree()->getTreeId()));
 }
コード例 #6
0
 /**
  * Create a form to edit a Fact object.
  *
  * @param GedcomRecord $record
  * @param Fact $fact
  *
  * @return string
  */
 public static function createEditForm(GedcomRecord $record, Fact $fact)
 {
     global $tags, $WT_TREE;
     $pid = $record->getXref();
     $tags = array();
     $gedlines = explode("\n", $fact->getGedcom());
     $linenum = 0;
     $fields = explode(' ', $gedlines[$linenum]);
     $glevel = $fields[0];
     $level = $glevel;
     $type = $fact->getTag();
     $parent = $fact->getParent();
     $level0type = $parent::RECORD_TYPE;
     $level1type = $type;
     $i = $linenum;
     $inSource = false;
     $levelSource = 0;
     $add_date = true;
     // List of tags we would expect at the next level
     // NB add_missing_subtags() already takes care of the simple cases
     // where a level 1 tag is missing a level 2 tag. Here we only need to
     // handle the more complicated cases.
     $expected_subtags = array('SOUR' => array('PAGE', 'DATA'), 'DATA' => array('TEXT'), 'PLAC' => array('MAP'), 'MAP' => array('LATI', 'LONG'));
     if ($record->getTree()->getPreference('FULL_SOURCES')) {
         $expected_subtags['SOUR'][] = 'QUAY';
         $expected_subtags['DATA'][] = 'DATE';
     }
     if (preg_match_all('/(' . WT_REGEX_TAG . ')/', $record->getTree()->getPreference('ADVANCED_PLAC_FACTS'), $match)) {
         $expected_subtags['PLAC'] = array_merge($match[1], $expected_subtags['PLAC']);
     }
     $stack = array(0 => $level0type);
     // Loop on existing tags :
     while (true) {
         // Keep track of our hierarchy, e.g. 1=>BIRT, 2=>PLAC, 3=>FONE
         $stack[(int) $level] = $type;
         // Merge them together, e.g. BIRT:PLAC:FONE
         $label = implode(':', array_slice($stack, 1, $level));
         $text = '';
         for ($j = 2; $j < count($fields); $j++) {
             if ($j > 2) {
                 $text .= ' ';
             }
             $text .= $fields[$j];
         }
         $text = rtrim($text);
         while ($i + 1 < count($gedlines) && preg_match("/" . ($level + 1) . ' CONT ?(.*)/', $gedlines[$i + 1], $cmatch) > 0) {
             $text .= "\n" . $cmatch[1];
             $i++;
         }
         if ($type === 'SOUR') {
             $inSource = true;
             $levelSource = $level;
         } elseif ($levelSource >= $level) {
             $inSource = false;
         }
         if ($type !== 'DATA' && $type !== 'CONT') {
             $tags[] = $type;
             $person = Individual::getInstance($pid, $WT_TREE);
             $subrecord = $level . ' ' . $type . ' ' . $text;
             if ($inSource && $type === 'DATE') {
                 self::addSimpleTag($subrecord, '', GedcomTag::getLabel($label, $person));
             } elseif (!$inSource && $type === 'DATE') {
                 self::addSimpleTag($subrecord, $level1type, GedcomTag::getLabel($label, $person));
                 if ($level === '2') {
                     // We already have a date - no need to add one.
                     $add_date = false;
                 }
             } elseif ($type === 'STAT') {
                 self::addSimpleTag($subrecord, $level1type, GedcomTag::getLabel($label, $person));
             } elseif ($level0type === 'REPO') {
                 $repo = Repository::getInstance($pid, $WT_TREE);
                 self::addSimpleTag($subrecord, $level0type, GedcomTag::getLabel($label, $repo));
             } else {
                 self::addSimpleTag($subrecord, $level0type, GedcomTag::getLabel($label, $person));
             }
         }
         // Get a list of tags present at the next level
         $subtags = array();
         for ($ii = $i + 1; isset($gedlines[$ii]) && preg_match('/^\\s*(\\d+)\\s+(\\S+)/', $gedlines[$ii], $mm) && $mm[1] > $level; ++$ii) {
             if ($mm[1] == $level + 1) {
                 $subtags[] = $mm[2];
             }
         }
         // Insert missing tags
         if (!empty($expected_subtags[$type])) {
             foreach ($expected_subtags[$type] as $subtag) {
                 if (!in_array($subtag, $subtags)) {
                     if (!$inSource || $subtag !== 'DATA') {
                         self::addSimpleTag($level + 1 . ' ' . $subtag, '', GedcomTag::getLabel($label . ':' . $subtag));
                     }
                     if (!empty($expected_subtags[$subtag])) {
                         foreach ($expected_subtags[$subtag] as $subsubtag) {
                             self::addSimpleTag($level + 2 . ' ' . $subsubtag, '', GedcomTag::getLabel($label . ':' . $subtag . ':' . $subsubtag));
                         }
                     }
                 }
             }
         }
         // Awkward special cases
         if ($level == 2 && $type === 'DATE' && in_array($level1type, Config::dateAndTime()) && !in_array('TIME', $subtags)) {
             self::addSimpleTag('3 TIME');
             // TIME is NOT a valid 5.5.1 tag
         }
         if ($level == 2 && $type === 'STAT' && GedcomCodeTemp::isTagLDS($level1type) && !in_array('DATE', $subtags)) {
             self::addSimpleTag('3 DATE', '', GedcomTag::getLabel('STAT:DATE'));
         }
         $i++;
         if (isset($gedlines[$i])) {
             $fields = explode(' ', $gedlines[$i]);
             $level = $fields[0];
             if (isset($fields[1])) {
                 $type = trim($fields[1]);
             } else {
                 $level = 0;
             }
         } else {
             $level = 0;
         }
         if ($level <= $glevel) {
             break;
         }
     }
     if ($level1type !== '_PRIM') {
         self::insertMissingSubtags($level1type, $add_date);
     }
     return $level1type;
 }
コード例 #7
0
 /**
  * Inserts a clipping into the clipping cart
  *
  * @param GedcomRecord $record
  */
 public function addClipping(GedcomRecord $record)
 {
     if ($record->canShowName()) {
         $this->cart[$record->getTree()->getTreeId()][$record->getXref()] = true;
         // Add directly linked records
         preg_match_all('/\\n\\d (?:OBJE|NOTE|SOUR|REPO) @(' . WT_REGEX_XREF . ')@/', $record->getGedcom(), $matches);
         foreach ($matches[1] as $match) {
             $this->cart[$record->getTree()->getTreeId()][$match] = true;
         }
     }
 }