Esempio n. 1
0
 /**
  * Create a new record from GEDCOM data.
  *
  * @param string $gedcom
  *
  * @throws \Exception
  *
  * @return GedcomRecord
  */
 public function createRecord($gedcom)
 {
     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 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 GedcomRecord::createRecord(' . $gedcom . ')');
     }
     // webtrees creates XREFs containing digits.  Anything else (e.g. “new”) is just a placeholder.
     if (!preg_match('/\\d/', $xref)) {
         $xref = $this->getNewXref($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 " . Auth::user()->getUserName();
     }
     // Create a pending change
     Database::prepare("INSERT INTO `##change` (gedcom_id, xref, old_gedcom, new_gedcom, user_id) VALUES (?, ?, '', ?, ?)")->execute(array($this->tree_id, $xref, $gedcom, Auth::id()));
     Log::addEditLog('Create: ' . $type . ' ' . $xref);
     // Accept this pending change
     if (Auth::user()->getPreference('auto_accept')) {
         FunctionsImport::acceptAllChanges($xref, $this->tree_id);
     }
     // Return the newly created record.  Note that since GedcomRecord
     // has a cache of pending changes, we cannot use it to create a
     // record with a newly created pending change.
     return GedcomRecord::getInstance($xref, $this, $gedcom);
 }
Esempio n. 2
0
use Fisharebest\Webtrees\Functions\FunctionsEdit;
use Fisharebest\Webtrees\Functions\FunctionsImport;
define('WT_SCRIPT_NAME', 'action.php');
require './includes/session.php';
header('Content-type: text/html; charset=UTF-8');
if (!Filter::checkCsrf()) {
    http_response_code(406);
    return;
}
switch (Filter::post('action')) {
    case 'accept-changes':
        // Accept all the pending changes for a record
        $record = GedcomRecord::getInstance(Filter::post('xref', WT_REGEX_XREF), $WT_TREE);
        if ($record && Auth::isModerator($record->getTree()) && $record->canShow() && $record->canEdit()) {
            FlashMessages::addMessage(I18N::translate('The changes to “%s” have been accepted.', $record->getFullName()));
            FunctionsImport::acceptAllChanges($record->getXref(), $record->getTree()->getTreeId());
        } else {
            http_response_code(406);
        }
        break;
    case 'copy-fact':
        // Copy a fact to the clipboard
        $xref = Filter::post('xref', WT_REGEX_XREF);
        $fact_id = Filter::post('fact_id');
        $record = GedcomRecord::getInstance($xref, $WT_TREE);
        if ($record && $record->canEdit()) {
            foreach ($record->getFacts() as $fact) {
                if ($fact->getFactId() == $fact_id) {
                    switch ($fact->getTag()) {
                        case 'NOTE':
                        case 'SOUR':
Esempio n. 3
0
 /**
  * Delete this record
  */
 public function deleteRecord()
 {
     // Create a pending change
     if (!$this->isPendingDeletion()) {
         Database::prepare("INSERT INTO `##change` (gedcom_id, xref, old_gedcom, new_gedcom, user_id) VALUES (?, ?, ?, '', ?)")->execute(array($this->tree->getTreeId(), $this->xref, $this->getGedcom(), Auth::id()));
     }
     // Auto-accept this pending change
     if (Auth::user()->getPreference('auto_accept')) {
         FunctionsImport::acceptAllChanges($this->xref, $this->tree->getTreeId());
     }
     // Clear the cache
     self::$gedcom_record_cache = null;
     self::$pending_record_cache = null;
     Log::addEditLog('Delete: ' . static::RECORD_TYPE . ' ' . $this->xref);
 }