Completed
Push — develop ( 0b4c01...246b92 )
by Greg
23:51 queued 09:58
created
edit_interface.php 1 patch
Switch Indentation   +475 added lines, -475 removed lines patch added patch discarded remove patch
@@ -30,48 +30,48 @@  discard block
 block discarded – undo
30 30
 $controller = new PageController;
31 31
 
32 32
 switch ($action) {
33
-case 'edit':
34
-	//////////////////////////////////////////////////////////////////////////////
35
-	// Edit a fact
36
-	//////////////////////////////////////////////////////////////////////////////
37
-	$tree    = $controller->tree();
38
-	$xref    = Filter::get('xref', WT_REGEX_XREF);
39
-	$fact_id = Filter::get('fact_id');
40
-
41
-	$record = GedcomRecord::getInstance($xref, $tree);
42
-	check_record_access($record);
43
-
44
-	// Find the fact to edit
45
-	$edit_fact = null;
46
-	foreach ($record->getFacts() as $fact) {
47
-		if ($fact->getFactId() === $fact_id && $fact->canEdit()) {
48
-			$edit_fact = $fact;
33
+	case 'edit':
34
+		//////////////////////////////////////////////////////////////////////////////
35
+		// Edit a fact
36
+		//////////////////////////////////////////////////////////////////////////////
37
+		$tree    = $controller->tree();
38
+		$xref    = Filter::get('xref', WT_REGEX_XREF);
39
+		$fact_id = Filter::get('fact_id');
40
+
41
+		$record = GedcomRecord::getInstance($xref, $tree);
42
+		check_record_access($record);
43
+
44
+		// Find the fact to edit
45
+		$edit_fact = null;
46
+		foreach ($record->getFacts() as $fact) {
47
+			if ($fact->getFactId() === $fact_id && $fact->canEdit()) {
48
+				$edit_fact = $fact;
49
+				break;
50
+			}
51
+		}
52
+		if (!$edit_fact) {
53
+			header('Location: ' . $record->url());
49 54
 			break;
50 55
 		}
51
-	}
52
-	if (!$edit_fact) {
53
-		header('Location: ' . $record->url());
54
-		break;
55
-	}
56 56
 
57
-	$controller
58
-		->setPageTitle($record->getFullName() . ' - ' . GedcomTag::getLabel($edit_fact->getTag()))
59
-		->pageHeader();
60
-
61
-	echo '<h2>', $controller->getPageTitle(), '</h2>';
62
-	FunctionsPrint::initializeCalendarPopup();
63
-	echo '<form name="editform" method="post" enctype="multipart/form-data">';
64
-	echo '<input type="hidden" name="ged" value="', e($tree->getName()), '">';
65
-	echo '<input type="hidden" name="action" value="update">';
66
-	echo '<input type="hidden" name="fact_id" value="', $fact_id, '">';
67
-	echo '<input type="hidden" name="xref" value="', $xref, '">';
68
-	echo '<input type="hidden" name="prev_action" value="edit">';
69
-	echo Filter::getCsrf();
70
-	FunctionsEdit::createEditForm($edit_fact);
71
-	echo keep_chan($record);
72
-
73
-	$level1type = $edit_fact->getTag();
74
-	switch ($record::RECORD_TYPE) {
57
+		$controller
58
+			->setPageTitle($record->getFullName() . ' - ' . GedcomTag::getLabel($edit_fact->getTag()))
59
+			->pageHeader();
60
+
61
+		echo '<h2>', $controller->getPageTitle(), '</h2>';
62
+		FunctionsPrint::initializeCalendarPopup();
63
+		echo '<form name="editform" method="post" enctype="multipart/form-data">';
64
+		echo '<input type="hidden" name="ged" value="', e($tree->getName()), '">';
65
+		echo '<input type="hidden" name="action" value="update">';
66
+		echo '<input type="hidden" name="fact_id" value="', $fact_id, '">';
67
+		echo '<input type="hidden" name="xref" value="', $xref, '">';
68
+		echo '<input type="hidden" name="prev_action" value="edit">';
69
+		echo Filter::getCsrf();
70
+		FunctionsEdit::createEditForm($edit_fact);
71
+		echo keep_chan($record);
72
+
73
+		$level1type = $edit_fact->getTag();
74
+		switch ($record::RECORD_TYPE) {
75 75
 		case 'REPO':
76 76
 			// REPO:NAME facts may take a NOTE (but the REPO record may not).
77 77
 			if ($level1type === 'NAME') {
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 		default:
138 138
 			// Other types of record do not have these lower-level records
139 139
 			break;
140
-	}
140
+		}
141 141
 
142 142
 	?>
143 143
 	<div class="row form-group">
@@ -166,517 +166,517 @@  discard block
 block discarded – undo
166 166
 	echo view('modals/ajax');
167 167
 	break;
168 168
 
169
-case 'add':
170
-	//////////////////////////////////////////////////////////////////////////////
171
-	// Add a new fact
172
-	//////////////////////////////////////////////////////////////////////////////
173
-	$tree = $controller->tree();
174
-	$xref = Filter::get('xref', WT_REGEX_XREF);
175
-	$fact = Filter::get('fact', WT_REGEX_TAG);
176
-
177
-	$record = GedcomRecord::getInstance($xref, $tree);
178
-	check_record_access($record);
179
-
180
-	$controller
181
-		->setPageTitle($record->getFullName() . ' - ' . GedcomTag::getLabel($fact, $record))
182
-		->pageHeader();
183
-
184
-	$level0type = $record::RECORD_TYPE;
185
-
186
-	echo '<h2>', $controller->getPageTitle(), '</h2>';
187
-
188
-	FunctionsPrint::initializeCalendarPopup();
189
-	echo '<form name="addform" method="post" enctype="multipart/form-data">';
190
-	echo '<input type="hidden" name="ged" value="', e($tree->getName()), '">';
191
-	echo '<input type="hidden" name="action" value="update">';
192
-	echo '<input type="hidden" name="xref" value="', $xref, '">';
193
-	echo '<input type="hidden" name="prev_action" value="add">';
194
-	echo '<input type="hidden" name="fact_type" value="' . $fact . '">';
195
-	echo Filter::getCsrf();
196
-	FunctionsEdit::createAddForm($tree, $fact);
197
-	echo keep_chan($record);
198
-
199
-	// Genealogical facts (e.g. for INDI and FAM records) can have 2 SOUR/NOTE/OBJE/ASSO/RESN ...
200
-	if ($level0type === 'INDI' || $level0type === 'FAM') {
201
-		// ... but not facts which are simply links to other records
202
-		if ($fact !== 'OBJE' && $fact !== 'NOTE' && $fact !== 'SHARED_NOTE' && $fact !== 'REPO' && $fact !== 'SOUR' && $fact !== 'SUBM' && $fact !== 'ASSO' && $fact !== 'ALIA' && $fact !== 'SEX') {
203
-			echo view('cards/add-source-citation', [
204
-				'level'          => 2,
205
-				'full_citations' => $tree->getPreference('FULL_SOURCES'),
206
-				'tree'           => $tree,
207
-			]);
208
-			if ($tree->getPreference('MEDIA_UPLOAD') >= Auth::accessLevel($tree)) {
209
-				echo view('cards/add-media-object', [
210
-					'level' => 2,
211
-					'tree' => $tree,
169
+	case 'add':
170
+		//////////////////////////////////////////////////////////////////////////////
171
+		// Add a new fact
172
+		//////////////////////////////////////////////////////////////////////////////
173
+		$tree = $controller->tree();
174
+		$xref = Filter::get('xref', WT_REGEX_XREF);
175
+		$fact = Filter::get('fact', WT_REGEX_TAG);
176
+
177
+		$record = GedcomRecord::getInstance($xref, $tree);
178
+		check_record_access($record);
179
+
180
+		$controller
181
+			->setPageTitle($record->getFullName() . ' - ' . GedcomTag::getLabel($fact, $record))
182
+			->pageHeader();
183
+
184
+		$level0type = $record::RECORD_TYPE;
185
+
186
+		echo '<h2>', $controller->getPageTitle(), '</h2>';
187
+
188
+		FunctionsPrint::initializeCalendarPopup();
189
+		echo '<form name="addform" method="post" enctype="multipart/form-data">';
190
+		echo '<input type="hidden" name="ged" value="', e($tree->getName()), '">';
191
+		echo '<input type="hidden" name="action" value="update">';
192
+		echo '<input type="hidden" name="xref" value="', $xref, '">';
193
+		echo '<input type="hidden" name="prev_action" value="add">';
194
+		echo '<input type="hidden" name="fact_type" value="' . $fact . '">';
195
+		echo Filter::getCsrf();
196
+		FunctionsEdit::createAddForm($tree, $fact);
197
+		echo keep_chan($record);
198
+
199
+		// Genealogical facts (e.g. for INDI and FAM records) can have 2 SOUR/NOTE/OBJE/ASSO/RESN ...
200
+		if ($level0type === 'INDI' || $level0type === 'FAM') {
201
+			// ... but not facts which are simply links to other records
202
+			if ($fact !== 'OBJE' && $fact !== 'NOTE' && $fact !== 'SHARED_NOTE' && $fact !== 'REPO' && $fact !== 'SOUR' && $fact !== 'SUBM' && $fact !== 'ASSO' && $fact !== 'ALIA' && $fact !== 'SEX') {
203
+				echo view('cards/add-source-citation', [
204
+					'level'          => 2,
205
+					'full_citations' => $tree->getPreference('FULL_SOURCES'),
206
+					'tree'           => $tree,
212 207
 				]);
213
-			}
214
-			// Don’t add notes to notes!
215
-			if ($fact !== 'NOTE') {
216
-				echo view('cards/add-note', [
217
-					'level' => 2,
218
-					'tree' => $tree,
219
-				]);
220
-				echo view('cards/add-shared-note', [
208
+				if ($tree->getPreference('MEDIA_UPLOAD') >= Auth::accessLevel($tree)) {
209
+					echo view('cards/add-media-object', [
210
+						'level' => 2,
211
+						'tree' => $tree,
212
+					]);
213
+				}
214
+				// Don’t add notes to notes!
215
+				if ($fact !== 'NOTE') {
216
+					echo view('cards/add-note', [
217
+						'level' => 2,
218
+						'tree' => $tree,
219
+					]);
220
+					echo view('cards/add-shared-note', [
221
+						'level' => 2,
222
+						'tree' => $tree,
223
+					]);
224
+				}
225
+				echo view('cards/add-associate', [
226
+					'id'    => Uuid::uuid4()->toString(),
221 227
 					'level' => 2,
222 228
 					'tree' => $tree,
223 229
 				]);
224
-			}
225
-			echo view('cards/add-associate', [
226
-				'id'    => Uuid::uuid4()->toString(),
227
-				'level' => 2,
228
-				'tree' => $tree,
229
-			]);
230
-			// allow to add godfather and godmother for CHR fact or best man and bridesmaid  for MARR fact in one window
231
-			if (in_array($fact, Config::twoAssociates())) {
232
-				echo view('cards/add-associate', [
233
-					'id'    => Uuid::uuid4()->toString(),
230
+				// allow to add godfather and godmother for CHR fact or best man and bridesmaid  for MARR fact in one window
231
+				if (in_array($fact, Config::twoAssociates())) {
232
+					echo view('cards/add-associate', [
233
+						'id'    => Uuid::uuid4()->toString(),
234
+						'level' => 2,
235
+						'tree' => $tree,
236
+					]);
237
+				}
238
+				echo view('cards/add-restriction', [
234 239
 					'level' => 2,
235 240
 					'tree' => $tree,
236 241
 				]);
237 242
 			}
238
-			echo view('cards/add-restriction', [
239
-				'level' => 2,
240
-				'tree' => $tree,
241
-			]);
242 243
 		}
243
-	}
244
-	?>
244
+		?>
245 245
 	<div class="row form-group">
246 246
 		<div class="col-sm-9 offset-sm-3">
247 247
 			<button class="btn btn-primary" type="submit">
248 248
 				<?= FontAwesome::decorativeIcon('save') ?>
249
-				<?= /* I18N: A button label. */
250
-				I18N::translate('save') ?>
249
+					<?= /* I18N: A button label. */
250
+					I18N::translate('save') ?>
251 251
 			</button>
252 252
 			<a class="btn btn-secondary" href="<?= e($record->url()) ?>">
253 253
 				<?= FontAwesome::decorativeIcon('cancel') ?>
254
-				<?= /* I18N: A button label. */
255
-				I18N::translate('cancel') ?>
254
+					<?= /* I18N: A button label. */
255
+					I18N::translate('cancel') ?>
256 256
 			</a>
257 257
 		</div>
258 258
 	</div>
259 259
 	</form>
260 260
 	<?php
261
-	echo view('modals/on-screen-keyboard');
262
-	echo view('modals/ajax');
261
+		echo view('modals/on-screen-keyboard');
262
+		echo view('modals/ajax');
263 263
 
264
-	break;
264
+		break;
265 265
 
266
-case 'update':
267
-	//////////////////////////////////////////////////////////////////////////////
268
-	// Save a new/updated fact
269
-	//////////////////////////////////////////////////////////////////////////////
270
-	$tree      = $controller->tree();
271
-	$xref      = Filter::post('xref', WT_REGEX_XREF);
272
-	$fact_id   = Filter::post('fact_id');
273
-	$keep_chan = Filter::postBool('keep_chan');
274
-
275
-	$record = GedcomRecord::getInstance($xref, $tree);
276
-	check_record_access($record);
277
-
278
-	// Arrays for each GEDCOM line
279
-	$glevels = Filter::postArray('glevels', '[0-9]');
280
-	$tag     = Filter::postArray('tag', WT_REGEX_TAG);
281
-	$text    = Filter::postArray('text');
282
-	$islink  = Filter::postArray('islink', '[01]');
283
-
284
-	// If the fact has a DATE or PLAC, then delete any value of Y
285
-	if ($text[0] === 'Y') {
286
-		foreach ($tag as $n => $value) {
287
-			if ($glevels[$n] == 2 && ($value === 'DATE' || $value === 'PLAC') && $text[$n] !== '') {
288
-				$text[0] = '';
289
-				break;
266
+	case 'update':
267
+		//////////////////////////////////////////////////////////////////////////////
268
+		// Save a new/updated fact
269
+		//////////////////////////////////////////////////////////////////////////////
270
+		$tree      = $controller->tree();
271
+		$xref      = Filter::post('xref', WT_REGEX_XREF);
272
+		$fact_id   = Filter::post('fact_id');
273
+		$keep_chan = Filter::postBool('keep_chan');
274
+
275
+		$record = GedcomRecord::getInstance($xref, $tree);
276
+		check_record_access($record);
277
+
278
+		// Arrays for each GEDCOM line
279
+		$glevels = Filter::postArray('glevels', '[0-9]');
280
+		$tag     = Filter::postArray('tag', WT_REGEX_TAG);
281
+		$text    = Filter::postArray('text');
282
+		$islink  = Filter::postArray('islink', '[01]');
283
+
284
+		// If the fact has a DATE or PLAC, then delete any value of Y
285
+		if ($text[0] === 'Y') {
286
+			foreach ($tag as $n => $value) {
287
+				if ($glevels[$n] == 2 && ($value === 'DATE' || $value === 'PLAC') && $text[$n] !== '') {
288
+					$text[0] = '';
289
+					break;
290
+				}
290 291
 			}
291 292
 		}
292
-	}
293 293
 
294
-	$newged = '';
295
-	if (!empty($_POST['NAME'])) {
296
-		$newged .= "\n1 NAME " . $_POST['NAME'];
297
-		$name_facts = ['TYPE', 'NPFX', 'GIVN', 'NICK', 'SPFX', 'SURN', 'NSFX'];
298
-		foreach ($name_facts as $name_fact) {
299
-			if (!empty($_POST[$name_fact])) {
300
-				$newged .= "\n2 " . $name_fact . ' ' . $_POST[$name_fact];
294
+		$newged = '';
295
+		if (!empty($_POST['NAME'])) {
296
+			$newged .= "\n1 NAME " . $_POST['NAME'];
297
+			$name_facts = ['TYPE', 'NPFX', 'GIVN', 'NICK', 'SPFX', 'SURN', 'NSFX'];
298
+			foreach ($name_facts as $name_fact) {
299
+				if (!empty($_POST[$name_fact])) {
300
+					$newged .= "\n2 " . $name_fact . ' ' . $_POST[$name_fact];
301
+				}
301 302
 			}
302 303
 		}
303
-	}
304 304
 
305
-	if (isset($_POST['NOTE'])) {
306
-		$NOTE = $_POST['NOTE'];
307
-	}
308
-	if (!empty($NOTE)) {
309
-		$tempnote = preg_split('/\r?\n/', trim($NOTE) . "\n"); // make sure only one line ending on the end
310
-		$title[]  = '0 @' . $xref . '@ NOTE ' . array_shift($tempnote);
311
-		foreach ($tempnote as &$line) {
312
-			$line = trim('1 CONT ' . $line, ' ');
305
+		if (isset($_POST['NOTE'])) {
306
+			$NOTE = $_POST['NOTE'];
307
+		}
308
+		if (!empty($NOTE)) {
309
+			$tempnote = preg_split('/\r?\n/', trim($NOTE) . "\n"); // make sure only one line ending on the end
310
+			$title[]  = '0 @' . $xref . '@ NOTE ' . array_shift($tempnote);
311
+			foreach ($tempnote as &$line) {
312
+				$line = trim('1 CONT ' . $line, ' ');
313
+			}
313 314
 		}
314
-	}
315 315
 
316
-	$newged = FunctionsEdit::handleUpdates($newged);
316
+		$newged = FunctionsEdit::handleUpdates($newged);
317 317
 
318
-	// Add new names after existing names
319
-	if (!empty($_POST['NAME'])) {
320
-		preg_match_all('/[_0-9A-Z]+/', $tree->getPreference('ADVANCED_NAME_FACTS'), $match);
321
-		$name_facts = array_unique(array_merge(['_MARNM'], $match[0]));
322
-		foreach ($name_facts as $name_fact) {
323
-			// Ignore advanced facts that duplicate standard facts.
324
-			if (!in_array($name_fact, ['TYPE', 'NPFX', 'GIVN', 'NICK', 'SPFX', 'SURN', 'NSFX']) && !empty($_POST[$name_fact])) {
325
-				$newged .= "\n2 " . $name_fact . ' ' . $_POST[$name_fact];
318
+		// Add new names after existing names
319
+		if (!empty($_POST['NAME'])) {
320
+			preg_match_all('/[_0-9A-Z]+/', $tree->getPreference('ADVANCED_NAME_FACTS'), $match);
321
+			$name_facts = array_unique(array_merge(['_MARNM'], $match[0]));
322
+			foreach ($name_facts as $name_fact) {
323
+				// Ignore advanced facts that duplicate standard facts.
324
+				if (!in_array($name_fact, ['TYPE', 'NPFX', 'GIVN', 'NICK', 'SPFX', 'SURN', 'NSFX']) && !empty($_POST[$name_fact])) {
325
+					$newged .= "\n2 " . $name_fact . ' ' . $_POST[$name_fact];
326
+				}
326 327
 			}
327 328
 		}
328
-	}
329 329
 
330
-	$newged = substr($newged, 1); // Remove leading newline
330
+		$newged = substr($newged, 1); // Remove leading newline
331 331
 
332
-	/** @var CensusAssistantModule $census_assistant */
333
-	$census_assistant = Module::getModuleByName('GEDFact_assistant');
334
-	if ($census_assistant !== null && $record instanceof Individual) {
335
-		$newged = $census_assistant->updateCensusAssistant($record, $fact_id, $newged, $keep_chan);
336
-	}
332
+		/** @var CensusAssistantModule $census_assistant */
333
+		$census_assistant = Module::getModuleByName('GEDFact_assistant');
334
+		if ($census_assistant !== null && $record instanceof Individual) {
335
+			$newged = $census_assistant->updateCensusAssistant($record, $fact_id, $newged, $keep_chan);
336
+		}
337 337
 
338
-	$record->updateFact($fact_id, $newged, !$keep_chan);
338
+		$record->updateFact($fact_id, $newged, !$keep_chan);
339 339
 
340
-	// For the GEDFact_assistant module
341
-	$pid_array = Filter::post('pid_array');
342
-	if ($pid_array) {
343
-		foreach (explode(',', $pid_array) as $pid) {
344
-			if ($pid !== $xref) {
345
-				$indi = Individual::getInstance($pid, $tree);
346
-				if ($indi && $indi->canEdit()) {
347
-					$indi->updateFact($fact_id, $newged, !$keep_chan);
340
+		// For the GEDFact_assistant module
341
+		$pid_array = Filter::post('pid_array');
342
+		if ($pid_array) {
343
+			foreach (explode(',', $pid_array) as $pid) {
344
+				if ($pid !== $xref) {
345
+					$indi = Individual::getInstance($pid, $tree);
346
+					if ($indi && $indi->canEdit()) {
347
+						$indi->updateFact($fact_id, $newged, !$keep_chan);
348
+					}
348 349
 				}
349 350
 			}
350 351
 		}
351
-	}
352 352
 
353
-	header('Location: ' . $record->url());
354
-	break;
353
+		header('Location: ' . $record->url());
354
+		break;
355 355
 
356
-case 'add_child_to_family_action':
357
-	//////////////////////////////////////////////////////////////////////////////
358
-	// Add a child to an existing family
359
-	//////////////////////////////////////////////////////////////////////////////
360
-	$tree      = $controller->tree();
361
-	$xref      = Filter::post('xref', WT_REGEX_XREF);
362
-	$PEDI      = Filter::post('PEDI');
363
-	$keep_chan = Filter::postBool('keep_chan');
364
-	$glevels   = Filter::postArray('glevels', '[0-9]');
365
-	$tag       = Filter::postArray('tag', WT_REGEX_TAG);
366
-	$text      = Filter::postArray('text');
367
-	$islink    = Filter::postArray('islink', '[01]');
368
-
369
-	$family = Family::getInstance($xref, $tree);
370
-	check_record_access($family);
371
-
372
-	FunctionsEdit::splitSource();
373
-	$gedrec = '0 @REF@ INDI';
374
-	$gedrec .= FunctionsEdit::addNewName($tree);
375
-	$gedrec .= FunctionsEdit::addNewSex();
376
-	if (preg_match_all('/([A-Z0-9_]+)/', $tree->getPreference('QUICK_REQUIRED_FACTS'), $matches)) {
377
-		foreach ($matches[1] as $match) {
378
-			$gedrec .= FunctionsEdit::addNewFact($tree, $match);
356
+	case 'add_child_to_family_action':
357
+		//////////////////////////////////////////////////////////////////////////////
358
+		// Add a child to an existing family
359
+		//////////////////////////////////////////////////////////////////////////////
360
+		$tree      = $controller->tree();
361
+		$xref      = Filter::post('xref', WT_REGEX_XREF);
362
+		$PEDI      = Filter::post('PEDI');
363
+		$keep_chan = Filter::postBool('keep_chan');
364
+		$glevels   = Filter::postArray('glevels', '[0-9]');
365
+		$tag       = Filter::postArray('tag', WT_REGEX_TAG);
366
+		$text      = Filter::postArray('text');
367
+		$islink    = Filter::postArray('islink', '[01]');
368
+
369
+		$family = Family::getInstance($xref, $tree);
370
+		check_record_access($family);
371
+
372
+		FunctionsEdit::splitSource();
373
+		$gedrec = '0 @REF@ INDI';
374
+		$gedrec .= FunctionsEdit::addNewName($tree);
375
+		$gedrec .= FunctionsEdit::addNewSex();
376
+		if (preg_match_all('/([A-Z0-9_]+)/', $tree->getPreference('QUICK_REQUIRED_FACTS'), $matches)) {
377
+			foreach ($matches[1] as $match) {
378
+				$gedrec .= FunctionsEdit::addNewFact($tree, $match);
379
+			}
380
+		}
381
+		$gedrec .= "\n" . GedcomCodePedi::createNewFamcPedi($PEDI, $xref);
382
+		if (Filter::postBool('SOUR_INDI')) {
383
+			$gedrec = FunctionsEdit::handleUpdates($gedrec);
384
+		} else {
385
+			$gedrec = FunctionsEdit::updateRest($gedrec);
379 386
 		}
380
-	}
381
-	$gedrec .= "\n" . GedcomCodePedi::createNewFamcPedi($PEDI, $xref);
382
-	if (Filter::postBool('SOUR_INDI')) {
383
-		$gedrec = FunctionsEdit::handleUpdates($gedrec);
384
-	} else {
385
-		$gedrec = FunctionsEdit::updateRest($gedrec);
386
-	}
387 387
 
388
-	// Create the new child
389
-	$new_child = $family->getTree()->createRecord($gedrec);
390
-
391
-	// Insert new child at the right place
392
-	$done = false;
393
-	foreach ($family->getFacts('CHIL') as $fact) {
394
-		$old_child = $fact->getTarget();
395
-		if ($old_child && Date::compare($new_child->getEstimatedBirthDate(), $old_child->getEstimatedBirthDate()) < 0) {
396
-			// Insert before this child
397
-			$family->updateFact($fact->getFactId(), '1 CHIL @' . $new_child->getXref() . "@\n" . $fact->getGedcom(), !$keep_chan);
398
-			$done = true;
399
-			break;
388
+		// Create the new child
389
+		$new_child = $family->getTree()->createRecord($gedrec);
390
+
391
+		// Insert new child at the right place
392
+		$done = false;
393
+		foreach ($family->getFacts('CHIL') as $fact) {
394
+			$old_child = $fact->getTarget();
395
+			if ($old_child && Date::compare($new_child->getEstimatedBirthDate(), $old_child->getEstimatedBirthDate()) < 0) {
396
+				// Insert before this child
397
+				$family->updateFact($fact->getFactId(), '1 CHIL @' . $new_child->getXref() . "@\n" . $fact->getGedcom(), !$keep_chan);
398
+				$done = true;
399
+				break;
400
+			}
401
+		}
402
+		if (!$done) {
403
+			// Append child at end
404
+			$family->createFact('1 CHIL @' . $new_child->getXref() . '@', !$keep_chan);
400 405
 		}
401
-	}
402
-	if (!$done) {
403
-		// Append child at end
404
-		$family->createFact('1 CHIL @' . $new_child->getXref() . '@', !$keep_chan);
405
-	}
406 406
 
407
-	if (Filter::post('goto') === 'new') {
408
-		header('Location: ' . $new_child->url());
409
-	} else {
410
-		header('Location: ' . $family->url());
411
-	}
412
-	break;
407
+		if (Filter::post('goto') === 'new') {
408
+			header('Location: ' . $new_child->url());
409
+		} else {
410
+			header('Location: ' . $family->url());
411
+		}
412
+		break;
413 413
 
414
-case 'add_child_to_individual_action':
415
-	//////////////////////////////////////////////////////////////////////////////
416
-	// Add a child to an existing individual (creating a one-parent family)
417
-	//////////////////////////////////////////////////////////////////////////////
418
-	$tree      = $controller->tree();
419
-	$xref    = Filter::post('xref', WT_REGEX_XREF);
420
-	$PEDI    = Filter::post('PEDI');
421
-	$glevels = Filter::postArray('glevels', '[0-9]');
422
-	$tag     = Filter::postArray('tag', WT_REGEX_TAG);
423
-	$text    = Filter::postArray('text');
424
-	$islink  = Filter::postArray('islink', '[01]');
425
-
426
-	$person = Individual::getInstance($xref, $tree);
427
-	check_record_access($person);
428
-
429
-	// Create a family
430
-	if ($person->getSex() === 'F') {
431
-		$gedcom = "0 @NEW@ FAM\n1 WIFE @" . $person->getXref() . '@';
432
-	} else {
433
-		$gedcom = "0 @NEW@ FAM\n1 HUSB @" . $person->getXref() . '@';
434
-	}
435
-	$family = $tree->createRecord($gedcom);
414
+	case 'add_child_to_individual_action':
415
+		//////////////////////////////////////////////////////////////////////////////
416
+		// Add a child to an existing individual (creating a one-parent family)
417
+		//////////////////////////////////////////////////////////////////////////////
418
+		$tree      = $controller->tree();
419
+		$xref    = Filter::post('xref', WT_REGEX_XREF);
420
+		$PEDI    = Filter::post('PEDI');
421
+		$glevels = Filter::postArray('glevels', '[0-9]');
422
+		$tag     = Filter::postArray('tag', WT_REGEX_TAG);
423
+		$text    = Filter::postArray('text');
424
+		$islink  = Filter::postArray('islink', '[01]');
425
+
426
+		$person = Individual::getInstance($xref, $tree);
427
+		check_record_access($person);
428
+
429
+		// Create a family
430
+		if ($person->getSex() === 'F') {
431
+			$gedcom = "0 @NEW@ FAM\n1 WIFE @" . $person->getXref() . '@';
432
+		} else {
433
+			$gedcom = "0 @NEW@ FAM\n1 HUSB @" . $person->getXref() . '@';
434
+		}
435
+		$family = $tree->createRecord($gedcom);
436 436
 
437
-	// Link the parent to the family
438
-	$person->createFact('1 FAMS @' . $family->getXref() . '@', true);
437
+		// Link the parent to the family
438
+		$person->createFact('1 FAMS @' . $family->getXref() . '@', true);
439 439
 
440
-	// Create a child
441
-	FunctionsEdit::splitSource(); // separate SOUR record from the rest
440
+		// Create a child
441
+		FunctionsEdit::splitSource(); // separate SOUR record from the rest
442 442
 
443
-	$gedcom = '0 @NEW@ INDI';
444
-	$gedcom .= FunctionsEdit::addNewName($tree);
445
-	$gedcom .= FunctionsEdit::addNewSex();
446
-	$gedcom .= "\n" . GedcomCodePedi::createNewFamcPedi($PEDI, $family->getXref());
447
-	if (preg_match_all('/([A-Z0-9_]+)/', $tree->getPreference('QUICK_REQUIRED_FACTS'), $matches)) {
448
-		foreach ($matches[1] as $match) {
449
-			$gedcom .= FunctionsEdit::addNewFact($tree, $match);
443
+		$gedcom = '0 @NEW@ INDI';
444
+		$gedcom .= FunctionsEdit::addNewName($tree);
445
+		$gedcom .= FunctionsEdit::addNewSex();
446
+		$gedcom .= "\n" . GedcomCodePedi::createNewFamcPedi($PEDI, $family->getXref());
447
+		if (preg_match_all('/([A-Z0-9_]+)/', $tree->getPreference('QUICK_REQUIRED_FACTS'), $matches)) {
448
+			foreach ($matches[1] as $match) {
449
+				$gedcom .= FunctionsEdit::addNewFact($tree, $match);
450
+			}
451
+		}
452
+		if (Filter::postBool('SOUR_INDI')) {
453
+			$gedcom = FunctionsEdit::handleUpdates($gedcom);
454
+		} else {
455
+			$gedcom = FunctionsEdit::updateRest($gedcom);
450 456
 		}
451
-	}
452
-	if (Filter::postBool('SOUR_INDI')) {
453
-		$gedcom = FunctionsEdit::handleUpdates($gedcom);
454
-	} else {
455
-		$gedcom = FunctionsEdit::updateRest($gedcom);
456
-	}
457 457
 
458
-	$child = $tree->createRecord($gedcom);
458
+		$child = $tree->createRecord($gedcom);
459 459
 
460
-	// Link the family to the child
461
-	$family->createFact('1 CHIL @' . $child->getXref() . '@', true);
460
+		// Link the family to the child
461
+		$family->createFact('1 CHIL @' . $child->getXref() . '@', true);
462 462
 
463
-	if (Filter::post('goto') === 'new') {
464
-		header('Location: ' . $child->url());
465
-	} else {
466
-		header('Location: ' . $person->url());
467
-	}
468
-	break;
463
+		if (Filter::post('goto') === 'new') {
464
+			header('Location: ' . $child->url());
465
+		} else {
466
+			header('Location: ' . $person->url());
467
+		}
468
+		break;
469 469
 
470
-case 'add_parent_to_individual_action':
471
-	//////////////////////////////////////////////////////////////////////////////
472
-	// Add a new parent to an existing individual (creating a one-parent family)
473
-	//////////////////////////////////////////////////////////////////////////////
474
-	$tree    = $controller->tree();
475
-	$xref    = Filter::post('xref', WT_REGEX_XREF);
476
-	$PEDI    = Filter::post('PEDI');
477
-	$glevels = Filter::postArray('glevels', '[0-9]');
478
-	$tag     = Filter::postArray('tag', WT_REGEX_TAG);
479
-	$text    = Filter::postArray('text');
480
-	$islink  = Filter::postArray('islink', '[01]');
481
-
482
-	$person = Individual::getInstance($xref, $tree);
483
-	check_record_access($person);
484
-
485
-	// Create a new family
486
-	$gedcom = "0 @NEW@ FAM\n1 CHIL @" . $person->getXref() . '@';
487
-	$family = $tree->createRecord($gedcom);
488
-
489
-	// Link the child to the family
490
-	$person->createFact('1 FAMC @' . $family->getXref() . '@', true);
491
-
492
-	// Create a child
493
-	FunctionsEdit::splitSource(); // separate SOUR record from the rest
494
-
495
-	$gedcom = '0 @NEW@ INDI';
496
-	$gedcom .= FunctionsEdit::addNewName($tree);
497
-	$gedcom .= FunctionsEdit::addNewSex();
498
-	if (preg_match_all('/([A-Z0-9_]+)/', $tree->getPreference('QUICK_REQUIRED_FACTS'), $matches)) {
499
-		foreach ($matches[1] as $match) {
500
-			$gedcom .= FunctionsEdit::addNewFact($tree, $match);
470
+	case 'add_parent_to_individual_action':
471
+		//////////////////////////////////////////////////////////////////////////////
472
+		// Add a new parent to an existing individual (creating a one-parent family)
473
+		//////////////////////////////////////////////////////////////////////////////
474
+		$tree    = $controller->tree();
475
+		$xref    = Filter::post('xref', WT_REGEX_XREF);
476
+		$PEDI    = Filter::post('PEDI');
477
+		$glevels = Filter::postArray('glevels', '[0-9]');
478
+		$tag     = Filter::postArray('tag', WT_REGEX_TAG);
479
+		$text    = Filter::postArray('text');
480
+		$islink  = Filter::postArray('islink', '[01]');
481
+
482
+		$person = Individual::getInstance($xref, $tree);
483
+		check_record_access($person);
484
+
485
+		// Create a new family
486
+		$gedcom = "0 @NEW@ FAM\n1 CHIL @" . $person->getXref() . '@';
487
+		$family = $tree->createRecord($gedcom);
488
+
489
+		// Link the child to the family
490
+		$person->createFact('1 FAMC @' . $family->getXref() . '@', true);
491
+
492
+		// Create a child
493
+		FunctionsEdit::splitSource(); // separate SOUR record from the rest
494
+
495
+		$gedcom = '0 @NEW@ INDI';
496
+		$gedcom .= FunctionsEdit::addNewName($tree);
497
+		$gedcom .= FunctionsEdit::addNewSex();
498
+		if (preg_match_all('/([A-Z0-9_]+)/', $tree->getPreference('QUICK_REQUIRED_FACTS'), $matches)) {
499
+			foreach ($matches[1] as $match) {
500
+				$gedcom .= FunctionsEdit::addNewFact($tree, $match);
501
+			}
501 502
 		}
502
-	}
503
-	if (Filter::postBool('SOUR_INDI')) {
504
-		$gedcom = FunctionsEdit::handleUpdates($gedcom);
505
-	} else {
506
-		$gedcom = FunctionsEdit::updateRest($gedcom);
507
-	}
508
-	$gedcom .= "\n1 FAMS @" . $family->getXref() . '@';
503
+		if (Filter::postBool('SOUR_INDI')) {
504
+			$gedcom = FunctionsEdit::handleUpdates($gedcom);
505
+		} else {
506
+			$gedcom = FunctionsEdit::updateRest($gedcom);
507
+		}
508
+		$gedcom .= "\n1 FAMS @" . $family->getXref() . '@';
509 509
 
510
-	$parent = $tree->createRecord($gedcom);
510
+		$parent = $tree->createRecord($gedcom);
511 511
 
512
-	// Link the family to the child
513
-	if ($parent->getSex() === 'F') {
514
-		$family->createFact('1 WIFE @' . $parent->getXref() . '@', true);
515
-	} else {
516
-		$family->createFact('1 HUSB @' . $parent->getXref() . '@', true);
517
-	}
512
+		// Link the family to the child
513
+		if ($parent->getSex() === 'F') {
514
+			$family->createFact('1 WIFE @' . $parent->getXref() . '@', true);
515
+		} else {
516
+			$family->createFact('1 HUSB @' . $parent->getXref() . '@', true);
517
+		}
518 518
 
519
-	if (Filter::post('goto') === 'new') {
520
-		header('Location: ' . $parent->url());
521
-	} else {
522
-		header('Location: ' . $person->url());
523
-	}
524
-	break;
519
+		if (Filter::post('goto') === 'new') {
520
+			header('Location: ' . $parent->url());
521
+		} else {
522
+			header('Location: ' . $person->url());
523
+		}
524
+		break;
525 525
 
526
-case 'add_unlinked_indi_action':
527
-	//////////////////////////////////////////////////////////////////////////////
528
-	// Add a new, unlinked individual
529
-	//////////////////////////////////////////////////////////////////////////////
530
-	$tree    = $controller->tree();
531
-	$glevels = Filter::postArray('glevels', '[0-9]');
532
-	$tag     = Filter::postArray('tag', WT_REGEX_TAG);
533
-	$text    = Filter::postArray('text');
534
-	$islink  = Filter::postArray('islink', '[01]');
535
-
536
-	FunctionsEdit::splitSource();
537
-	$gedrec = '0 @REF@ INDI';
538
-	$gedrec .= FunctionsEdit::addNewName($tree);
539
-	$gedrec .= FunctionsEdit::addNewSex();
540
-	if (preg_match_all('/([A-Z0-9_]+)/', $tree->getPreference('QUICK_REQUIRED_FACTS'), $matches)) {
541
-		foreach ($matches[1] as $match) {
542
-			$gedrec .= FunctionsEdit::addNewFact($tree, $match);
526
+	case 'add_unlinked_indi_action':
527
+		//////////////////////////////////////////////////////////////////////////////
528
+		// Add a new, unlinked individual
529
+		//////////////////////////////////////////////////////////////////////////////
530
+		$tree    = $controller->tree();
531
+		$glevels = Filter::postArray('glevels', '[0-9]');
532
+		$tag     = Filter::postArray('tag', WT_REGEX_TAG);
533
+		$text    = Filter::postArray('text');
534
+		$islink  = Filter::postArray('islink', '[01]');
535
+
536
+		FunctionsEdit::splitSource();
537
+		$gedrec = '0 @REF@ INDI';
538
+		$gedrec .= FunctionsEdit::addNewName($tree);
539
+		$gedrec .= FunctionsEdit::addNewSex();
540
+		if (preg_match_all('/([A-Z0-9_]+)/', $tree->getPreference('QUICK_REQUIRED_FACTS'), $matches)) {
541
+			foreach ($matches[1] as $match) {
542
+				$gedrec .= FunctionsEdit::addNewFact($tree, $match);
543
+			}
544
+		}
545
+		if (Filter::postBool('SOUR_INDI')) {
546
+			$gedrec = FunctionsEdit::handleUpdates($gedrec);
547
+		} else {
548
+			$gedrec = FunctionsEdit::updateRest($gedrec);
543 549
 		}
544
-	}
545
-	if (Filter::postBool('SOUR_INDI')) {
546
-		$gedrec = FunctionsEdit::handleUpdates($gedrec);
547
-	} else {
548
-		$gedrec = FunctionsEdit::updateRest($gedrec);
549
-	}
550 550
 
551
-	$new_indi = $tree->createRecord($gedrec);
551
+		$new_indi = $tree->createRecord($gedrec);
552 552
 
553
-	if (Filter::post('goto') === 'new') {
554
-		header('Location: ' . $new_indi->url());
555
-	} else {
556
-		header('Location: ' . route('admin-trees'));
557
-	}
558
-	break;
553
+		if (Filter::post('goto') === 'new') {
554
+			header('Location: ' . $new_indi->url());
555
+		} else {
556
+			header('Location: ' . route('admin-trees'));
557
+		}
558
+		break;
559 559
 
560
-case 'add_spouse_to_individual_action':
561
-	//////////////////////////////////////////////////////////////////////////////
562
-	// Add a spouse to an existing individual (creating a new family)
563
-	//////////////////////////////////////////////////////////////////////////////
564
-	$tree    = $controller->tree();
565
-	$xref    = Filter::post('xref'); // Add a spouse to this individual
566
-	$sex     = Filter::post('SEX', '[MFU]', 'U');
567
-	$glevels = Filter::postArray('glevels', '[0-9]');
568
-	$tag     = Filter::postArray('tag', WT_REGEX_TAG);
569
-	$text    = Filter::postArray('text');
570
-	$islink  = Filter::postArray('islink', '[01]');
571
-
572
-	$person = Individual::getInstance($xref, $tree);
573
-	check_record_access($person);
574
-
575
-	FunctionsEdit::splitSource();
576
-	$indi_gedcom = '0 @REF@ INDI';
577
-	$indi_gedcom .= FunctionsEdit::addNewName($tree);
578
-	$indi_gedcom .= FunctionsEdit::addNewSex();
579
-	if (preg_match_all('/([A-Z0-9_]+)/', $tree->getPreference('QUICK_REQUIRED_FACTS'), $matches)) {
580
-		foreach ($matches[1] as $match) {
581
-			$indi_gedcom .= FunctionsEdit::addNewFact($tree, $match);
560
+	case 'add_spouse_to_individual_action':
561
+		//////////////////////////////////////////////////////////////////////////////
562
+		// Add a spouse to an existing individual (creating a new family)
563
+		//////////////////////////////////////////////////////////////////////////////
564
+		$tree    = $controller->tree();
565
+		$xref    = Filter::post('xref'); // Add a spouse to this individual
566
+		$sex     = Filter::post('SEX', '[MFU]', 'U');
567
+		$glevels = Filter::postArray('glevels', '[0-9]');
568
+		$tag     = Filter::postArray('tag', WT_REGEX_TAG);
569
+		$text    = Filter::postArray('text');
570
+		$islink  = Filter::postArray('islink', '[01]');
571
+
572
+		$person = Individual::getInstance($xref, $tree);
573
+		check_record_access($person);
574
+
575
+		FunctionsEdit::splitSource();
576
+		$indi_gedcom = '0 @REF@ INDI';
577
+		$indi_gedcom .= FunctionsEdit::addNewName($tree);
578
+		$indi_gedcom .= FunctionsEdit::addNewSex();
579
+		if (preg_match_all('/([A-Z0-9_]+)/', $tree->getPreference('QUICK_REQUIRED_FACTS'), $matches)) {
580
+			foreach ($matches[1] as $match) {
581
+				$indi_gedcom .= FunctionsEdit::addNewFact($tree, $match);
582
+			}
583
+		}
584
+		if (Filter::postBool('SOUR_INDI')) {
585
+			$indi_gedcom = FunctionsEdit::handleUpdates($indi_gedcom);
586
+		} else {
587
+			$indi_gedcom = FunctionsEdit::updateRest($indi_gedcom);
582 588
 		}
583
-	}
584
-	if (Filter::postBool('SOUR_INDI')) {
585
-		$indi_gedcom = FunctionsEdit::handleUpdates($indi_gedcom);
586
-	} else {
587
-		$indi_gedcom = FunctionsEdit::updateRest($indi_gedcom);
588
-	}
589 589
 
590
-	$fam_gedcom = '';
591
-	if (preg_match_all('/([A-Z0-9_]+)/', $tree->getPreference('QUICK_REQUIRED_FAMFACTS'), $matches)) {
592
-		foreach ($matches[1] as $match) {
593
-			$fam_gedcom .= FunctionsEdit::addNewFact($tree, $match);
590
+		$fam_gedcom = '';
591
+		if (preg_match_all('/([A-Z0-9_]+)/', $tree->getPreference('QUICK_REQUIRED_FAMFACTS'), $matches)) {
592
+			foreach ($matches[1] as $match) {
593
+				$fam_gedcom .= FunctionsEdit::addNewFact($tree, $match);
594
+			}
595
+		}
596
+		if (Filter::postBool('SOUR_FAM')) {
597
+			$fam_gedcom = FunctionsEdit::handleUpdates($fam_gedcom);
598
+		} else {
599
+			$fam_gedcom = FunctionsEdit::updateRest($fam_gedcom);
594 600
 		}
595
-	}
596
-	if (Filter::postBool('SOUR_FAM')) {
597
-		$fam_gedcom = FunctionsEdit::handleUpdates($fam_gedcom);
598
-	} else {
599
-		$fam_gedcom = FunctionsEdit::updateRest($fam_gedcom);
600
-	}
601 601
 
602
-	// Create the new spouse
603
-	$spouse = $tree->createRecord($indi_gedcom);
604
-	// Create a new family
605
-	if ($sex === 'F') {
606
-		$family = $tree->createRecord("0 @NEW@ FAM\n1 WIFE @" . $spouse->getXref() . "@\n1 HUSB @" . $person->getXref() . '@' . $fam_gedcom);
607
-	} else {
608
-		$family = $tree->createRecord("0 @NEW@ FAM\n1 HUSB @" . $spouse->getXref() . "@\n1 WIFE @" . $person->getXref() . '@' . $fam_gedcom);
609
-	}
610
-	// Link the spouses to the family
611
-	$spouse->createFact('1 FAMS @' . $family->getXref() . '@', true);
612
-	$person->createFact('1 FAMS @' . $family->getXref() . '@', true);
602
+		// Create the new spouse
603
+		$spouse = $tree->createRecord($indi_gedcom);
604
+		// Create a new family
605
+		if ($sex === 'F') {
606
+			$family = $tree->createRecord("0 @NEW@ FAM\n1 WIFE @" . $spouse->getXref() . "@\n1 HUSB @" . $person->getXref() . '@' . $fam_gedcom);
607
+		} else {
608
+			$family = $tree->createRecord("0 @NEW@ FAM\n1 HUSB @" . $spouse->getXref() . "@\n1 WIFE @" . $person->getXref() . '@' . $fam_gedcom);
609
+		}
610
+		// Link the spouses to the family
611
+		$spouse->createFact('1 FAMS @' . $family->getXref() . '@', true);
612
+		$person->createFact('1 FAMS @' . $family->getXref() . '@', true);
613 613
 
614
-	if (Filter::post('goto') === 'new') {
615
-		header('Location: ' . $spouse->url());
616
-	} else {
617
-		header('Location: ' . $person->url());
618
-	}
619
-	break;
614
+		if (Filter::post('goto') === 'new') {
615
+			header('Location: ' . $spouse->url());
616
+		} else {
617
+			header('Location: ' . $person->url());
618
+		}
619
+		break;
620 620
 
621
-case 'add_spouse_to_family_action':
622
-	//////////////////////////////////////////////////////////////////////////////
623
-	// Add a spouse to an existing family
624
-	//////////////////////////////////////////////////////////////////////////////
625
-	$tree    = $controller->tree();
626
-	$xref    = Filter::post('xref', WT_REGEX_XREF);
627
-	$glevels = Filter::postArray('glevels', '[0-9]');
628
-	$tag     = Filter::postArray('tag', WT_REGEX_TAG);
629
-	$text    = Filter::postArray('text');
630
-	$islink  = Filter::postArray('islink', '[01]');
631
-
632
-	$family = Family::getInstance($xref, $tree);
633
-	check_record_access($family);
634
-
635
-	// Create the new spouse
636
-	FunctionsEdit::splitSource(); // separate SOUR record from the rest
637
-
638
-	$gedrec = '0 @REF@ INDI';
639
-	$gedrec .= FunctionsEdit::addNewName($tree);
640
-	$gedrec .= FunctionsEdit::addNewSex();
641
-	if (preg_match_all('/([A-Z0-9_]+)/', $tree->getPreference('QUICK_REQUIRED_FACTS'), $matches)) {
642
-		foreach ($matches[1] as $match) {
643
-			$gedrec .= FunctionsEdit::addNewFact($tree, $match);
621
+	case 'add_spouse_to_family_action':
622
+		//////////////////////////////////////////////////////////////////////////////
623
+		// Add a spouse to an existing family
624
+		//////////////////////////////////////////////////////////////////////////////
625
+		$tree    = $controller->tree();
626
+		$xref    = Filter::post('xref', WT_REGEX_XREF);
627
+		$glevels = Filter::postArray('glevels', '[0-9]');
628
+		$tag     = Filter::postArray('tag', WT_REGEX_TAG);
629
+		$text    = Filter::postArray('text');
630
+		$islink  = Filter::postArray('islink', '[01]');
631
+
632
+		$family = Family::getInstance($xref, $tree);
633
+		check_record_access($family);
634
+
635
+		// Create the new spouse
636
+		FunctionsEdit::splitSource(); // separate SOUR record from the rest
637
+
638
+		$gedrec = '0 @REF@ INDI';
639
+		$gedrec .= FunctionsEdit::addNewName($tree);
640
+		$gedrec .= FunctionsEdit::addNewSex();
641
+		if (preg_match_all('/([A-Z0-9_]+)/', $tree->getPreference('QUICK_REQUIRED_FACTS'), $matches)) {
642
+			foreach ($matches[1] as $match) {
643
+				$gedrec .= FunctionsEdit::addNewFact($tree, $match);
644
+			}
644 645
 		}
645
-	}
646 646
 
647
-	if (Filter::postBool('SOUR_INDI')) {
648
-		$gedrec = FunctionsEdit::handleUpdates($gedrec);
649
-	} else {
650
-		$gedrec = FunctionsEdit::updateRest($gedrec);
651
-	}
652
-	$gedrec .= "\n1 FAMS @" . $family->getXref() . '@';
653
-	$spouse = $tree->createRecord($gedrec);
647
+		if (Filter::postBool('SOUR_INDI')) {
648
+			$gedrec = FunctionsEdit::handleUpdates($gedrec);
649
+		} else {
650
+			$gedrec = FunctionsEdit::updateRest($gedrec);
651
+		}
652
+		$gedrec .= "\n1 FAMS @" . $family->getXref() . '@';
653
+		$spouse = $tree->createRecord($gedrec);
654 654
 
655
-	// Update the existing family - add marriage, etc
656
-	if ($family->getFirstFact('HUSB')) {
657
-		$family->createFact('1 WIFE @' . $spouse->getXref() . '@', true);
658
-	} else {
659
-		$family->createFact('1 HUSB @' . $spouse->getXref() . '@', true);
660
-	}
661
-	$famrec = '';
662
-	if (preg_match_all('/([A-Z0-9_]+)/', $tree->getPreference('QUICK_REQUIRED_FAMFACTS'), $matches)) {
663
-		foreach ($matches[1] as $match) {
664
-			$famrec .= FunctionsEdit::addNewFact($tree, $match);
655
+		// Update the existing family - add marriage, etc
656
+		if ($family->getFirstFact('HUSB')) {
657
+			$family->createFact('1 WIFE @' . $spouse->getXref() . '@', true);
658
+		} else {
659
+			$family->createFact('1 HUSB @' . $spouse->getXref() . '@', true);
665 660
 		}
666
-	}
667
-	if (Filter::postBool('SOUR_FAM')) {
668
-		$famrec = FunctionsEdit::handleUpdates($famrec);
669
-	} else {
670
-		$famrec = FunctionsEdit::updateRest($famrec);
671
-	}
672
-	$family->createFact(trim($famrec), true); // trim leading \n
661
+		$famrec = '';
662
+		if (preg_match_all('/([A-Z0-9_]+)/', $tree->getPreference('QUICK_REQUIRED_FAMFACTS'), $matches)) {
663
+			foreach ($matches[1] as $match) {
664
+				$famrec .= FunctionsEdit::addNewFact($tree, $match);
665
+			}
666
+		}
667
+		if (Filter::postBool('SOUR_FAM')) {
668
+			$famrec = FunctionsEdit::handleUpdates($famrec);
669
+		} else {
670
+			$famrec = FunctionsEdit::updateRest($famrec);
671
+		}
672
+		$family->createFact(trim($famrec), true); // trim leading \n
673 673
 
674
-	if (Filter::post('goto') === 'new') {
675
-		header('Location: ' . $spouse->url());
676
-	} else {
677
-		header('Location: ' . $family->url());
678
-	}
679
-	break;
674
+		if (Filter::post('goto') === 'new') {
675
+			header('Location: ' . $spouse->url());
676
+		} else {
677
+			header('Location: ' . $family->url());
678
+		}
679
+		break;
680 680
 }
681 681
 
682 682
 /**
Please login to merge, or discard this patch.