1*3b3db8adSGreg Roach<?php 2*3b3db8adSGreg Roach 3*3b3db8adSGreg Roach/** 4*3b3db8adSGreg Roach * webtrees: online genealogy 5*3b3db8adSGreg Roach * Copyright (C) 2019 webtrees development team 6*3b3db8adSGreg Roach * This program is free software: you can redistribute it and/or modify 7*3b3db8adSGreg Roach * it under the terms of the GNU General Public License as published by 8*3b3db8adSGreg Roach * the Free Software Foundation, either version 3 of the License, or 9*3b3db8adSGreg Roach * (at your option) any later version. 10*3b3db8adSGreg Roach * This program is distributed in the hope that it will be useful, 11*3b3db8adSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12*3b3db8adSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*3b3db8adSGreg Roach * GNU General Public License for more details. 14*3b3db8adSGreg Roach * You should have received a copy of the GNU General Public License 15*3b3db8adSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 16*3b3db8adSGreg Roach */ 17*3b3db8adSGreg Roach 18*3b3db8adSGreg Roachdeclare(strict_types=1); 19*3b3db8adSGreg Roach 20*3b3db8adSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 21*3b3db8adSGreg Roach 22*3b3db8adSGreg Roachuse Fisharebest\Webtrees\Auth; 23*3b3db8adSGreg Roachuse Fisharebest\Webtrees\GedcomRecord; 24*3b3db8adSGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 25*3b3db8adSGreg Roachuse Fisharebest\Webtrees\I18N; 26*3b3db8adSGreg Roachuse Fisharebest\Webtrees\Tree; 27*3b3db8adSGreg Roachuse Psr\Http\Message\ResponseInterface; 28*3b3db8adSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 29*3b3db8adSGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 30*3b3db8adSGreg Roach 31*3b3db8adSGreg Roachuse function assert; 32*3b3db8adSGreg Roachuse function redirect; 33*3b3db8adSGreg Roach 34*3b3db8adSGreg Roach/** 35*3b3db8adSGreg Roach * Edit the raw GEDCOM of a fact. 36*3b3db8adSGreg Roach */ 37*3b3db8adSGreg Roachclass EditRawFactPage implements RequestHandlerInterface 38*3b3db8adSGreg Roach{ 39*3b3db8adSGreg Roach use ViewResponseTrait; 40*3b3db8adSGreg Roach 41*3b3db8adSGreg Roach /** 42*3b3db8adSGreg Roach * @param ServerRequestInterface $request 43*3b3db8adSGreg Roach * 44*3b3db8adSGreg Roach * @return ResponseInterface 45*3b3db8adSGreg Roach */ 46*3b3db8adSGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 47*3b3db8adSGreg Roach { 48*3b3db8adSGreg Roach $tree = $request->getAttribute('tree'); 49*3b3db8adSGreg Roach assert($tree instanceof Tree); 50*3b3db8adSGreg Roach 51*3b3db8adSGreg Roach $xref = $request->getAttribute('xref'); 52*3b3db8adSGreg Roach $record = GedcomRecord::getInstance($xref, $tree); 53*3b3db8adSGreg Roach 54*3b3db8adSGreg Roach Auth::checkRecordAccess($record, true); 55*3b3db8adSGreg Roach 56*3b3db8adSGreg Roach $fact_id = $request->getAttribute('fact_id'); 57*3b3db8adSGreg Roach 58*3b3db8adSGreg Roach $title = I18N::translate('Edit the raw GEDCOM') . ' - ' . $record->fullName(); 59*3b3db8adSGreg Roach 60*3b3db8adSGreg Roach foreach ($record->facts() as $fact) { 61*3b3db8adSGreg Roach if (!$fact->isPendingDeletion() && $fact->id() === $fact_id) { 62*3b3db8adSGreg Roach return $this->viewResponse('edit/raw-gedcom-fact', [ 63*3b3db8adSGreg Roach 'fact' => $fact, 64*3b3db8adSGreg Roach 'title' => $title, 65*3b3db8adSGreg Roach ]); 66*3b3db8adSGreg Roach } 67*3b3db8adSGreg Roach } 68*3b3db8adSGreg Roach 69*3b3db8adSGreg Roach return redirect($record->url()); 70*3b3db8adSGreg Roach } 71*3b3db8adSGreg Roach} 72