summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--edit_interface.php707
-rw-r--r--family.php4
-rw-r--r--includes/functions/functions_charts.php8
-rw-r--r--includes/functions/functions_edit.php6
-rw-r--r--includes/functions/functions_print.php11
-rw-r--r--js/webtrees-1.5.0.js134
-rw-r--r--library/WT/Controller/Family.php2
-rw-r--r--library/WT/Family.php43
-rw-r--r--library/WT/GedcomRecord.php31
-rw-r--r--library/WT/Individual.php16
-rw-r--r--modules_v3/descendancy/module.php5
-rw-r--r--modules_v3/family_nav/module.php18
-rw-r--r--modules_v3/relatives/module.php20
13 files changed, 527 insertions, 478 deletions
diff --git a/edit_interface.php b/edit_interface.php
index 18f543a26a..c441fce2c6 100644
--- a/edit_interface.php
+++ b/edit_interface.php
@@ -325,7 +325,6 @@ case 'update':
$tag = safe_POST('tag', WT_REGEX_TAG);
$text = safe_POST('text', WT_REGEX_UNSAFE);
$islink = safe_POST('islink');
-var_dump($glevels, $tag, $text, $islink);exit;
$controller
->setPageTitle(WT_I18N::translate('Edit'))
@@ -400,32 +399,255 @@ var_dump($glevels, $tag, $text, $islink);exit;
break;
////////////////////////////////////////////////////////////////////////////////
-case 'addchild':
+// Add a new child to an existing family
+////////////////////////////////////////////////////////////////////////////////
+case 'add_child_to_family':
+ $xref = safe_GET('xref', WT_REGEX_XREF);
$gender = safe_GET('gender', '[MF]', 'U');
- $famid = safe_GET('famid', WT_REGEX_XREF);
- $family = WT_Family::getInstance($famid);
+ $family = WT_Family::getInstance($xref);
check_record_access($family);
$controller
->setPageTitle($family->getFullName() . ' - ' . WT_I18N::translate('Add a new child'))
->pageHeader();
- print_indi_form('addchildaction', null, $family, null, 'CHIL', $gender);
+ print_indi_form('add_child_to_family_action', null, $family, null, 'CHIL', $gender);
+ break;
+
+case 'add_child_to_family_action':
+ $xref = safe_POST('xref', WT_REGEX_XREF);
+ $PEDI = safe_POST('PEDI');
+ $keep_chan = safe_POST_bool('keep_chan');
+
+ $family = WT_Family::getInstance($xref);
+ check_record_access($family);
+
+ $controller->pageHeader();
+
+ splitSOUR();
+ $gedrec ="0 @REF@ INDI";
+ $gedrec.=addNewName();
+ $gedrec.=addNewSex ();
+ if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FACTS, $matches)) {
+ foreach ($matches[1] as $match) {
+ $gedrec.=addNewFact($match);
+ }
+ }
+ $gedrec .= "\n".WT_Gedcom_Code_Pedi::createNewFamcPedi($PEDI, $xref);
+ if (safe_POST_bool('SOUR_INDI')) {
+ $gedrec = handle_updates($gedrec);
+ } else {
+ $gedrec = updateRest($gedrec);
+ }
+
+ // Create the new child
+ $new_child = WT_GedcomRecord::createRecord($gedrec, WT_GED_ID);
+
+ // Insert new child at the right place
+ $done = false;
+ foreach ($family->getFacts('CHIL') as $fact) {
+ $old_child = $fact->getTarget();
+ if ($old_child && WT_Date::Compare($new_child->getEstimatedBirthDate(), $old_child->getEstimatedBirthDate())<0) {
+ // Insert before this child
+ $family->updateFact($fact->getFactId(), '1 CHIL @' . $new_child->getXref() . "@\n" . $fact->getGedcom(), !$keep_chan);
+ $done = true;
+ break;
+ }
+ }
+ if (!$done) {
+ // Append child at end
+ $family->createFact('1 CHIL @' . $new_child->getXref() . '@', !$keep_chan);
+ }
+
+ if (safe_POST('goto')=='new') {
+ $controller->addInlineJavascript('closePopupAndReloadParent("' . $new_child->getRawUrl() . '");');
+ } else {
+ $controller->addInlineJavascript('closePopupAndReloadParent();');
+ }
+ break;
+
+////////////////////////////////////////////////////////////////////////////////
+// Add a new child to an existing individual (creating a one-parent family)
+////////////////////////////////////////////////////////////////////////////////
+case 'add_child_to_individual':
+ $xref = safe_GET('xref', WT_REGEX_XREF);
+
+ $person = WT_Individual::getInstance($xref);
+ check_record_access($person);
+
+ $controller
+ ->setPageTitle($person->getFullName() . ' - ' . WT_I18N::translate('Add a child to create a one-parent family'))
+ ->pageHeader();
+
+ print_indi_form('add_child_to_individual_action', $person, null, null, 'CHIL', $person->getSex());
+ break;
+
+case 'add_child_to_individual_action':
+ $xref = safe_POST('xref', WT_REGEX_XREF);
+ $PEDI = safe_POST('PEDI');
+
+ $person = WT_Individual::getInstance($xref);
+ check_record_access($person);
+
+ $controller->pageHeader();
+
+ // Create a family
+ if ($person->getSex()=='F') {
+ $gedcom = "0 @NEW@ FAM\n1 WIFE @" . $person->getXref() . "@";
+ } else {
+ $gedcom = "0 @NEW@ FAM\n1 HUSB @" . $person->getXref() . "@";
+ }
+ $family = WT_GedcomRecord::createRecord($gedcom, WT_GED_ID);
+
+ // Link the parent to the family
+ $person->createFact('1 FAMS @' . $family->getXref() . '@', true);
+
+ // Create a child
+ splitSOUR(); // separate SOUR record from the rest
+
+ $gedcom = '0 @NEW@ INDI';
+ $gedcom .= addNewName();
+ $gedcom .= addNewSex ();
+ $gedcom .= "\n".WT_Gedcom_Code_Pedi::createNewFamcPedi($PEDI, $newfamxref);
+ if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FACTS, $matches)) {
+ foreach ($matches[1] as $match) {
+ $gedcom.=addNewFact($match);
+ }
+ }
+ if (safe_POST_bool('SOUR_INDI')) {
+ $gedcom=handle_updates($gedcom);
+ } else {
+ $gedcom=updateRest($gedcom);
+ }
+ $gedcom .= "\n1 FAMC @" . $family->getXref() . "@";
+
+ $child = WT_GedcomRecord::createRecord($gedcom, WT_GED_ID);
+
+ // Link the family to the child
+ $family->createFact('1 CHIL @' . $child->getXref() . '@', true);
+
+ $controller->addInlineJavascript('closePopupAndReloadParent();');
+ break;
+
+////////////////////////////////////////////////////////////////////////////////
+// Add a new parent to an existing individual (creating a one-parent family)
+////////////////////////////////////////////////////////////////////////////////
+case 'add_parent_to_individual':
+ $xref = safe_GET('xref', WT_REGEX_XREF);
+ $gender = safe_GET('gender', '[MF]', 'U');
+
+ $individual = WT_Individual::getInstance($xref);
+ check_record_access($individual);
+
+ if ($sex='F') {
+ $controller->setPageTitle(WT_I18N::translate('Add a new mother'));
+ $famtag = 'WIFE';
+ } else {
+ $controller->setPageTitle(WT_I18N::translate('Add a new father'));
+ $famtag = 'HUSB';
+ }
+ $controller->pageHeader();
+
+ print_indi_form('add_parent_to_individual_action', $individual, null, null, $famtag, $gender);
+ break;
+
+case 'add_parent_to_individual_action':
+ $xref = safe_POST('xref', WT_REGEX_XREF);
+ $PEDI = safe_POST('PEDI');
+
+ $person = WT_Individual::getInstance($xref);
+ check_record_access($person);
+
+ $controller->pageHeader();
+
+ // Create a new family
+ $gedcom = "0 @NEW@ FAM\n1 CHIL @" . $person->getXref() . "@";
+ $family = WT_GedcomRecord::createRecord($gedcom, WT_GED_ID);
+
+ // Link the child to the family
+ $person->createFact('1 FAMC @' . $family->getXref() . '@', true);
+
+ // Create a child
+ splitSOUR(); // separate SOUR record from the rest
+
+ $gedcom = '0 @NEW@ INDI';
+ $gedcom .= addNewName();
+ $gedcom .= addNewSex ();
+ $gedcom .= "\n".WT_Gedcom_Code_Pedi::createNewFamcPedi($PEDI, $newfamxref);
+ if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FACTS, $matches)) {
+ foreach ($matches[1] as $match) {
+ $gedcom.=addNewFact($match);
+ }
+ }
+ if (safe_POST_bool('SOUR_INDI')) {
+ $gedcom=handle_updates($gedcom);
+ } else {
+ $gedcom=updateRest($gedcom);
+ }
+ if (safe_POST('SEX')=='F') {
+ $gedcom .= "\n1 WIFE @" . $family->getXref() . "@";
+ } else {
+ $gedcom .= "\n1 HUSB @" . $family->getXref() . "@";
+ }
+
+ $parent = WT_GedcomRecord::createRecord($gedcom, WT_GED_ID);
+
+ // Link the family to the child
+ if ($parent->getSex()=='F') {
+ $family->createFact('1 WIFE @' . $parent->getXref() . '@', true);
+ } else {
+ $family->createFact('1 HUSB @' . $parent->getXref() . '@', true);
+ }
+
+ $controller->addInlineJavascript('closePopupAndReloadParent();');
break;
////////////////////////////////////////////////////////////////////////////////
+// Add a new, unlinked individual
+////////////////////////////////////////////////////////////////////////////////
case 'add_unlinked_indi':
$controller
->requireManagerLogin()
- ->setPageTitle(WT_I18N::translate('Add an unlinked person'))
+ ->setPageTitle(WT_I18N::translate('Create a new individual'))
->pageHeader();
print_indi_form('add_unlinked_indi_action', null, null, null, null, null);
break;
+case 'add_unlinked_indi_action':
+ $controller
+ ->requireManagerLogin()
+ ->pageHeader();
+
+ splitSOUR();
+ $gedrec ="0 @REF@ INDI";
+ $gedrec.=addNewName();
+ $gedrec.=addNewSex ();
+ if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FACTS, $matches)) {
+ foreach ($matches[1] as $match) {
+ $gedrec.=addNewFact($match);
+ }
+ }
+ if (safe_POST_bool('SOUR_INDI')) {
+ $gedrec = handle_updates($gedrec);
+ } else {
+ $gedrec = updateRest($gedrec);
+ }
+
+ $new_indi = WT_GedcomRecord::createRecord($gedrec, WT_GED_ID);
+
+ if (safe_POST('goto')=='new') {
+ $controller->addInlineJavascript('closePopupAndReloadParent("' . $new_indi->getRawUrl() . '");');
+ } else {
+ $controller->addInlineJavascript('closePopupAndReloadParent();');
+ }
+ break;
+
////////////////////////////////////////////////////////////////////////////////
-case 'addspouse':
+// Add a new spouse to an existing individual (creating a new family)
+////////////////////////////////////////////////////////////////////////////////
+case 'add_spouse_to_individual':
$famtag = safe_GET('famtag', '(HUSB|WIFE)');
$xref = safe_GET('xref', WT_REGEX_XREF);
@@ -434,57 +656,147 @@ case 'addspouse':
if ($famtag=='WIFE') {
$controller->setPageTitle(WT_I18N::translate('Add a new wife'));
+ $sex = 'F';
} else {
$controller->setPageTitle(WT_I18N::translate('Add a new husband'));
+ $sex = 'M';
}
$controller->pageHeader();
- print_indi_form('addspouseaction', $individual, null, null, $famtag);
+ print_indi_form('add_spouse_to_individual_action', $individual, null, null, $famtag, $sex);
break;
-////////////////////////////////////////////////////////////////////////////////
-case 'addnewparent':
- $xref = safe_GET('xref', WT_REGEX_XREF);
- $famtag = safe_GET('famtag', '(HUSB|WIFE)');
- $famid = safe_GET('famid', WT_REGEX_XREF);
+case 'add_spouse_to_individual_action':
+ $xref = safe_POST('xref', WT_REGEX_XREF); // Add a spouse to this individual
+ $sex = safe_POST('SEX', '[MFU]');
$person = WT_Individual::getInstance($xref);
- $family = WT_Family::getInstance($famid);
check_record_access($person);
- if ($family) {
- check_record_access($family);
+
+ $controller
+ ->setPageTitle(WT_I18N::translate('Add a new spouse'))
+ ->pageHeader();
+
+ splitSOUR();
+ $indi_gedcom = '0 @REF@ INDI';
+ $indi_gedcom.= addNewName();
+ $indi_gedcom.= addNewSex ();
+ if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FACTS, $matches)) {
+ foreach ($matches[1] as $match) {
+ $indi_gedcom.=addNewFact($match);
+ }
+ }
+ if (safe_POST_bool('SOUR_INDI')) {
+ $indi_gedcom = handle_updates($indi_gedcom);
+ } else {
+ $indi_gedcom = updateRest($indi_gedcom);
}
- if ($person) {
- // Adding a parent to an individual
- $name=$person->getFullName() . ' - ';
+ $fam_gedcom = '';
+ if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FAMFACTS, $matches)) {
+ foreach ($matches[1] as $match) {
+ $fam_gedcom.=addNewFact($match);
+ }
+ }
+ if (safe_POST_bool('SOUR_FAM')) {
+ $fam_gedcom = handle_updates($fam_gedcom);
+ } else {
+ $fam_gedcom = updateRest($fam_gedcom);
+ }
+
+ // Create the new spouse
+ $spouse = WT_GedcomRecord::createRecord($indi_gedcom, WT_GED_ID);
+ // Create a new family
+ if ($sex == 'F') {
+ $family = WT_GedcomRecord::createRecord("0 @NEW@ FAM\n1 WIFE @" . $spouse->getXref() . "@\n1 HUSB @" . $person->getXref() . "@" . $fam_gedcom, WT_GED_ID);
} else {
- // Adding a spouse to a family
- $name='';
+ $family = WT_GedcomRecord::createRecord("0 @NEW@ FAM\n1 HUSB @" . $spouse->getXref() . "@\n1 WIFE @" . $person->getXref() . "@" . $fam_gedcom, WT_GED_ID);
}
+ // Link the spouses to the family
+ $spouse->createFact('1 FAMS @' . $family->getXref() . '@', true);
+ $person->createFact('1 FAMS @' . $family->getXref() . '@', true);
+
+ if (safe_POST('goto')=='new') {
+ $controller->addInlineJavascript('closePopupAndReloadParent("' . $new_spouse->getRawUrl() . '");');
+ } else {
+ $controller->addInlineJavascript('closePopupAndReloadParent();');
+ }
+ break;
+
+////////////////////////////////////////////////////////////////////////////////
+// Add a new spouse to an existing family
+////////////////////////////////////////////////////////////////////////////////
+case 'add_spouse_to_family':
+ $xref = safe_GET('xref', WT_REGEX_XREF);
+ $famtag = safe_GET('famtag', '(HUSB|WIFE)');
+
+ $family = WT_Individual::getInstance($xref);
+ check_record_access($family);
if ($famtag=='WIFE') {
- $controller->setPageTitle($name . WT_I18N::translate('Add a new mother'));
+ $controller->setPageTitle(WT_I18N::translate('Add a new wife'));
+ $sex = 'F';
} else {
- $controller->setPageTitle($name . WT_I18N::translate('Add a new father'));
+ $controller->setPageTitle(WT_I18N::translate('Add a new husband'));
+ $sex = 'M';
}
$controller->pageHeader();
- print_indi_form('addnewparentaction', $person, $family, null, $famtag, $person->getSex());
+ print_indi_form('add_spouse_to_family_action', null, $family, null, $famtag, $sex);
break;
-////////////////////////////////////////////////////////////////////////////////
-case 'addopfchild':
- $xref = safe_GET('xref', WT_REGEX_XREF);
+case 'add_spouse_to_family_action':
+ $xref = safe_POST('xref', WT_REGEX_XREF);
- $person = WT_Individual::getInstance($xref);
- check_record_access($person);
+ $family = WT_Family::getInstance($xref);
+ check_record_access($family);
- $controller
- ->setPageTitle($person->getFullName() . ' - ' . WT_I18N::translate('Add a child to create a one-parent family'))
- ->pageHeader();
+ $controller->pageHeader();
- print_indi_form('addopfchildaction', $person, null, null, 'CHIL', $person->getSex());
+ // Create the new spouse
+ splitSOUR(); // separate SOUR record from the rest
+
+ $gedrec ="0 @REF@ INDI";
+ $gedrec.=addNewName();
+ $gedrec.=addNewSex ();
+ if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FACTS, $matches)) {
+ foreach ($matches[1] as $match) {
+ $gedrec.=addNewFact($match);
+ }
+ }
+
+ if (safe_POST_bool('SOUR_INDI')) {
+ $gedrec = handle_updates($gedrec);
+ } else {
+ $gedrec = updateRest($gedrec);
+ }
+ $gedrec .= "\n1 FAMS @" . $family->getXref() . "@";
+ $spouse = WT_GedcomRecord::createRecord($gedrec, WT_GED_ID);
+
+ // Update the existing family - add marriage, etc
+ if ($family->getFirstFact('HUSB')) {
+ $family->createFact('1 WIFE @' . $spouse->getXref() . '@', true);
+ } else {
+ $family->createFact('1 HUSB @' . $spouse->getXref() . '@', true);
+ }
+ $famrec = '';
+ if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FAMFACTS, $matches)) {
+ foreach ($matches[1] as $match) {
+ $famrec.=addNewFact($match);
+ }
+ }
+ if (safe_POST_bool('SOUR_FAM')) {
+ $famrec = handle_updates($famrec);
+ } else {
+ $famrec = updateRest($famrec);
+ }
+ $family->createFact(trim($famrec), true); // trim leading "\n"
+
+ if (safe_POST('goto')=='new') {
+ $controller->addInlineJavascript('closePopupAndReloadParent("' . $spouse->getRawUrl() . '");');
+ } else {
+ $controller->addInlineJavascript('closePopupAndReloadParent();');
+ }
break;
////////////////////////////////////////////////////////////////////////////////
@@ -1073,150 +1385,6 @@ case 'addrepoaction':
break;
////////////////////////////////////////////////////////////////////////////////
-case 'addchildaction':
- $famid = safe_POST('famid', WT_REGEX_XREF); // Add a child to this family
- $PEDI = safe_POST('PEDI');
- $keep_chan = safe_POST_bool('keep_chan');
-
- $family = WT_Family::getInstance($famid);
- check_record_access($family);
-
- $controller
- ->setPageTitle(WT_I18N::translate('Add child'))
- ->pageHeader();
-
- splitSOUR();
- $gedrec ="0 @REF@ INDI";
- $gedrec.=addNewName();
- $gedrec.=addNewSex ();
- if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FACTS, $matches)) {
- foreach ($matches[1] as $match) {
- $gedrec.=addNewFact($match);
- }
- }
- $gedrec .= "\n".WT_Gedcom_Code_Pedi::createNewFamcPedi($PEDI, $famid);
- if (safe_POST_bool('SOUR_INDI')) {
- $gedrec = handle_updates($gedrec);
- } else {
- $gedrec = updateRest($gedrec);
- }
-
- // Create the new child
- $new_child = WT_GedcomRecord::createRecord($gedrec, WT_GED_ID);
-
- // Insert new child at the right place
- $done = false;
- foreach ($family->getFacts('CHIL') as $fact) {
- $old_child = $fact->getTarget();
- if ($old_child && WT_Date::Compare($new_child->getEstimatedBirthDate(), $old_child->getEstimatedBirthDate())<0) {
- // Insert before this child
- $family->updateFact($fact->getFactId(), '1 CHIL @' . $new_child->getXref() . '@' . $fact->getGedcom(), !$keep_chan);
- $done = true;
- break;
- }
- }
- if (!$done) {
- // Append child at end
- $family->createFact('1 CHIL @' . $new_child->getXref() . '@', !$keep_chan);
- }
-
- if (safe_POST('goto')=='new') {
- $controller->addInlineJavascript('closePopupAndReloadParent("' . $new_child->getRawUrl() . '");');
- } else {
- $controller->addInlineJavascript('closePopupAndReloadParent();');
- }
- break;
-
-////////////////////////////////////////////////////////////////////////////////
-case 'add_unlinked_indi_action':
- $controller
- ->requireManagerLogin()
- ->setPageTitle(WT_I18N::translate('Add an unlinked person'))
- ->pageHeader();
-
- splitSOUR();
- $gedrec ="0 @REF@ INDI";
- $gedrec.=addNewName();
- $gedrec.=addNewSex ();
- if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FACTS, $matches)) {
- foreach ($matches[1] as $match) {
- $gedrec.=addNewFact($match);
- }
- }
- if (safe_POST_bool('SOUR_INDI')) {
- $gedrec = handle_updates($gedrec);
- } else {
- $gedrec = updateRest($gedrec);
- }
-
- $new_indi = WT_GedcomRecord::createRecord($gedrec, WT_GED_ID);
-
- if (safe_POST('goto')=='new') {
- $controller->addInlineJavascript('closePopupAndReloadParent("' . $new_indi->getRawUrl() . '");');
- } else {
- $controller->addInlineJavascript('closePopupAndReloadParent();');
- }
- break;
-
-////////////////////////////////////////////////////////////////////////////////
-case 'addspouseaction':
- $xref = safe_POST('xref', WT_REGEX_XREF); // Add a spouse to this individual
- $sex = safe_POST('SEX', '[MFU]');
-
- $person = WT_Individual::getInstance($xref);
- check_record_access($person);
-
- $controller
- ->setPageTitle(WT_I18N::translate('Add a new spouse'))
- ->pageHeader();
-
- splitSOUR();
- $indi_gedcom = '0 @REF@ INDI';
- $indi_gedcom.= addNewName();
- $indi_gedcom.= addNewSex ();
- if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FACTS, $matches)) {
- foreach ($matches[1] as $match) {
- $indi_gedcom.=addNewFact($match);
- }
- }
- if (safe_POST_bool('SOUR_INDI')) {
- $indi_gedcom = handle_updates($indi_gedcom);
- } else {
- $indi_gedcom = updateRest($indi_gedcom);
- }
-
- $fam_gedcom = '';
- if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FAMFACTS, $matches)) {
- foreach ($matches[1] as $match) {
- $fam_gedcom.=addNewFact($match);
- }
- }
- if (safe_POST_bool('SOUR_FAM')) {
- $fam_gedcom = handle_updates($fam_gedcom);
- } else {
- $fam_gedcom = updateRest($fam_gedcom);
- }
-
- // Create the new spouse
- $spouse = WT_GedcomRecord::createRecord($indi_gedcom, WT_GED_ID);
- // Create a new family
- if ($sex == 'F') {
- $family = WT_GedcomRecord::createRecord("0 @NEW@ FAM\n1 WIFE @" . $spouse->getXref() . "@\n1 HUSB @" . $person->getXref() . "@" . $fam_gedcom, WT_GED_ID);
- } else {
- $family = WT_GedcomRecord::createRecord("0 @NEW@ FAM\n1 HUSB @" . $spouse->getXref() . "@\n1 WIFE @" . $person->getXref() . "@" . $fam_gedcom, WT_GED_ID);
- }
- // Link the spouses to the family
- $spouse->createFact('1 FAMS @' . $family->getXref() . '@', true);
- $person->createFact('1 FAMS @' . $family->getXref() . '@', true);
-
- if (safe_POST('goto')=='new') {
- $controller->addInlineJavascript('closePopupAndReloadParent("' . $new_spouse->getRawUrl() . '");');
- } else {
- $controller->addInlineJavascript('closePopupAndReloadParent();');
- }
- break;
-
-////////////////////////////////////////////////////////////////////////////////
case 'linkspouseaction':
$xref = safe_POST('xref', WT_REGEX_XREF);
$spid = safe_POST('spid', WT_REGEX_XREF);
@@ -1264,140 +1432,6 @@ case 'linkspouseaction':
break;
////////////////////////////////////////////////////////////////////////////////
-case 'addnewparentaction':
- $xref = safe_POST('xref', WT_REGEX_XREF);
- $famid = safe_POST('famid', WT_REGEX_XREF);
- $famtag = safe_POST('famtag', '(HUSB|WIFE)');
-
- $person = WT_Individual::getInstance($xref);
- $family = WT_Family::getInstance($famid);
- check_record_access($person);
- if ($family) {
- check_record_access($family);
- }
-
- $controller
- ->setPageTitle(WT_I18N::translate('Add a new father'))
- ->pageHeader();
-
- splitSOUR(); // separate SOUR record from the rest
-
- $gedrec ="0 @REF@ INDI";
- $gedrec.=addNewName();
- $gedrec.=addNewSex ();
- if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FACTS, $matches)) {
- foreach ($matches[1] as $match) {
- $gedrec.=addNewFact($match);
- }
- }
-
- if (safe_POST_bool('SOUR_INDI')) {
- $gedrec = handle_updates($gedrec);
- } else {
- $gedrec = updateRest($gedrec);
- }
-
- $parent = WT_GedcomRecord::createRecord($gedrec, WT_GED_ID);
- if ($family) {
- // Link to an existing family
- $famrec = '1 ' . $famtag .' @' . $parent . '@';
- if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FAMFACTS, $matches)) {
- foreach ($matches[1] as $match) {
- $famrec.=addNewFact($match);
- }
- }
- if (safe_POST_bool('SOUR_FAM')) {
- $famrec = handle_updates($famrec);
- } else {
- $famrec = updateRest($famrec);
- }
- $family->createFact($famrec, true);
- $parent->createFact('1 FAMS @' . $family->getXref() . '@', true);
- } else {
- // Create a new family
- $famrec = '0 @new@ FAM';
- if ($famtag == 'HUSB') {
- $famrec .= "\n1 HUSB @" . $parent->getXref() . '@';
- $famrec .= "\n1 CHIL @" . $person->getXref() . '@';
- } else {
- $famrec .= "\n1 WIFE @" . $parent->getXref() . '@';
- $famrec .= "\n1 CHIL @" . $person->getXref() . '@';
- }
-
- if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FAMFACTS, $matches)) {
- foreach ($matches[1] as $match) {
- $famrec.=addNewFact($match);
- }
- }
- if (safe_POST_bool('SOUR_FAM')) {
- $famrec = handle_updates($famrec);
- } else {
- $famrec = updateRest($famrec);
- }
-
- $family = WT_GedcomRecord::createRecord($famrec, WT_GED_ID);
- $person->createFact('1 FAMC @' . $family->getXref() . '@', true);
- $parent->createFact('1 FAMS @' . $family->getXref() . '@', true);
- }
-
- if (safe_POST('goto')=='new') {
- $controller->addInlineJavascript('closePopupAndReloadParent("' . $parent->getRawUrl() . '");');
- } else {
- $controller->addInlineJavascript('closePopupAndReloadParent();');
- }
- break;
-
-////////////////////////////////////////////////////////////////////////////////
-case 'addopfchildaction':
- $xref = safe_POST('xref', WT_REGEX_XREF);
- $PEDI = safe_POST('PEDI');
-
- $person = WT_Individual::getInstance($xref);
- check_record_access($person);
-
- $controller
- ->setPageTitle(WT_I18N::translate('Add child'))
- ->pageHeader();
-
- // Create a family
- if ($person->getSex()=='F') {
- $gedcom = "0 @NEW@ FAM\n1 WIFE @" . $person->getXref() . "@";
- } else {
- $gedcom = "0 @NEW@ FAM\n1 HUSB @" . $person->getXref() . "@";
- }
- $family = WT_GedcomRecord::createRecord($gedcom, WT_GED_ID);
-
- // Link the parent to the family
- $person->createFact('1 FAMS @' . $family->getXref() . '@', true);
-
- // Create a child
- splitSOUR(); // separate SOUR record from the rest
-
- $gedcom = '0 @NEW@ INDI';
- $gedcom .= addNewName();
- $gedcom .= addNewSex ();
- $gedcom .= "\n".WT_Gedcom_Code_Pedi::createNewFamcPedi($PEDI, $newfamxref);
- if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FACTS, $matches)) {
- foreach ($matches[1] as $match) {
- $gedcom.=addNewFact($match);
- }
- }
- if (safe_POST_bool('SOUR_INDI')) {
- $gedcom=handle_updates($gedcom);
- } else {
- $gedcom=updateRest($gedcom);
- }
- $gedcom .= "\n1 FAMC @" . $family->getXref() . "@";
-
- $child = WT_GedcomRecord::createRecord($gedcom, WT_GED_ID);
-
- // Link the family to the child
- $family->createFact('1 CHIL @' . $child->getXref() . '@', true);
-
- $controller->addInlineJavascript('closePopupAndReloadParent();');
- break;
-
-////////////////////////////////////////////////////////////////////////////////
case 'editname':
$xref = safe_GET('xref', WT_REGEX_XREF);
$fact_id = safe_GET('fact_id');
@@ -2078,14 +2112,12 @@ function print_indi_form($nextaction, WT_Individual $person=null, WT_Family $fam
if ($person) {
$xref = $person->getXref();
+ } elseif ($family) {
+ $xref = $family->getXref();
} else {
- $xref = null;
- }
- if ($family) {
- $famid = $family->getXref();
- } else {
- $famid = null;
+ $xref = 'new';
}
+
if ($name_fact) {
$name_fact_id = $name_fact->getFactId();
$name_type = $name_fact->getAttribute('TYPE');
@@ -2113,15 +2145,14 @@ function print_indi_form($nextaction, WT_Individual $person=null, WT_Family $fam
echo "<form method=\"post\" name=\"addchildform\" onsubmit=\"return checkform();\">";
echo "<input type=\"hidden\" name=\"action\" value=\"$nextaction\">";
echo "<input type=\"hidden\" name=\"fact_id\" value=\"$name_fact_id\">";
- echo "<input type=\"hidden\" name=\"famid\" value=\"$famid\">";
echo "<input type=\"hidden\" name=\"xref\" value=\"$xref\">";
echo "<input type=\"hidden\" name=\"famtag\" value=\"$famtag\">";
echo "<input type=\"hidden\" name=\"goto\" value=\"\">"; // set by javascript
echo "<table class=\"facts_table\">";
switch ($nextaction) {
- case 'addchildaction':
- case 'addopfchildaction':
+ case 'add_child_to_family_action':
+ case 'add_child_to_individual_action':
// When adding a new child, specify the pedigree
add_simple_tag('0 PEDI');
break;
@@ -2135,16 +2166,15 @@ function print_indi_form($nextaction, WT_Individual $person=null, WT_Family $fam
// Inherit surname from parents, spouse or child
if (!$namerec) {
// We'll need the parent's name to set the child's surname
- $family = WT_Family::getInstance($famid);
if ($family) {
$father = $family->getHusband();
- if ($father->getFirstFact('NAME')) {
+ if ($father && $father->getFirstFact('NAME')) {
$father_name = $father->getFirstFact('NAME')->getValue();
} else {
$father_name='';
}
$mother = $family->getWife();
- if ($mother->getFirstFact('NAME')) {
+ if ($mother && $mother->getFirstFact('NAME')) {
$mother_name = $mother->getFirstFact('NAME')->getValue();
} else {
$mother_name = '';
@@ -2166,14 +2196,14 @@ function print_indi_form($nextaction, WT_Individual $person=null, WT_Family $fam
//Father: Jose /CCCC DDDD/
//Child: Pablo /CCCC AAAA/
switch ($nextaction) {
- case 'addchildaction':
+ case 'add_child_to_family_action':
if (preg_match('/\/(\S+)\s+\S+\//', $mother_name, $matchm) &&
preg_match('/\/(\S+)\s+\S+\//', $father_name, $matchf)) {
$name_fields['SURN']=$matchf[1].' '.$matchm[1];
$name_fields['NAME']='/'.$name_fields['SURN'].'/';
}
break;
- case 'addnewparentaction':
+ case 'add_spouse_to_family_action':
if ($famtag=='HUSB' && preg_match('/\/(\S+)\s+\S+\//', $indi_name, $match)) {
$name_fields['SURN']=$match[1].' ';
$name_fields['NAME']='/'.$name_fields['SURN'].'/';
@@ -2190,14 +2220,14 @@ function print_indi_form($nextaction, WT_Individual $person=null, WT_Family $fam
//Father: Jose /CCCC DDDD/
//Child: Pablo /BBBB DDDD/
switch ($nextaction) {
- case 'addchildaction':
+ case 'add_child_to_family_action':
if (preg_match('/\/\S+\s+(\S+)\//', $mother_name, $matchm) &&
preg_match('/\/\S+\s+(\S+)\//', $father_name, $matchf)) {
$name_fields['SURN']=$matchf[1].' '.$matchm[1];
$name_fields['NAME']='/'.$name_fields['SURN'].'/';
}
break;
- case 'addnewparentaction':
+ case 'add_spouse_to_family_action':
if ($famtag=='HUSB' && preg_match('/\/\S+\s+(\S+)\//', $indi_name, $match)) {
$name_fields['SURN']=' '.$match[1];
$name_fields['NAME']='/'.$name_fields['SURN'].'/';
@@ -2213,7 +2243,7 @@ function print_indi_form($nextaction, WT_Individual $person=null, WT_Family $fam
// Sons get their father's given name plus "sson"
// Daughters get their father's given name plus "sdottir"
switch ($nextaction) {
- case 'addchildaction':
+ case 'add_child_to_family_action':
if ($sextag=='M' && preg_match('/(\S+)\s+\/.*\//', $father_name, $match)) {
$name_fields['SURN']=preg_replace('/s$/', '', $match[1]).'sson';
$name_fields['NAME']='/'.$name_fields['SURN'].'/';
@@ -2223,7 +2253,7 @@ function print_indi_form($nextaction, WT_Individual $person=null, WT_Family $fam
$name_fields['NAME']='/'.$name_fields['SURN'].'/';
}
break;
- case 'addnewparentaction':
+ case 'add_spouse_to_family_action':
if ($famtag=='HUSB' && preg_match('/(\S+)sson\s+\/.*\//i', $indi_name, $match)) {
$name_fields['GIVN']=$match[1];
$name_fields['NAME']=$name_fields['GIVN'].' //';
@@ -2238,14 +2268,14 @@ function print_indi_form($nextaction, WT_Individual $person=null, WT_Family $fam
case 'patrilineal':
// Father gives his surname to his children
switch ($nextaction) {
- case 'addchildaction':
+ case 'add_child_to_family_action':
if (preg_match('/\/((?:[a-z]{2,3} )*)(.*)\//i', $father_name, $match)) {
$name_fields['SURN']=$match[2];
$name_fields['SPFX']=trim($match[1]);
$name_fields['NAME']="/{$match[1]}{$match[2]}/";
}
break;
- case 'addnewparentaction':
+ case 'add_spouse_to_family_action':
if ($famtag=='HUSB' && preg_match('/\/((?:[a-z]{2,3} )*)(.*)\//i', $indi_name, $match)) {
$name_fields['SURN']=$match[2];
$name_fields['SPFX']=trim($match[1]);
@@ -2257,14 +2287,14 @@ function print_indi_form($nextaction, WT_Individual $person=null, WT_Family $fam
case 'matrilineal':
// Mother gives her surname to her children
switch ($nextaction) {
- case 'addchildaction':
+ case 'add_child_to_family_action':
if (preg_match('/\/((?:[a-z]{2,3} )*)(.*)\//i', $mother, $match)) {
$name_fields['SURN']=$match[2];
$name_fields['SPFX']=trim($match[1]);
$name_fields['NAME']="/{$match[1]}{$match[2]}/";
}
break;
- case 'addnewparentaction':
+ case 'add_spouse_to_family_action':
if ($famtag=='WIFE' && preg_match('/\/((?:[a-z]{2,3} )*)(.*)\//i', $indi_name, $match)) {
$name_fields['SURN']=$match[2];
$name_fields['SPFX']=trim($match[1]);
@@ -2278,7 +2308,7 @@ function print_indi_form($nextaction, WT_Individual $person=null, WT_Family $fam
case 'lithuanian':
// Father gives his surname to his wife and children
switch ($nextaction) {
- case 'addspouseaction':
+ case 'add_spouse_to_individual_action':
if ($famtag=='WIFE' && preg_match('/\/(.*)\//', $indi_name, $match)) {
if ($SURNAME_TRADITION=='polish') {
$match[1]=preg_replace(array('/ski$/', '/cki$/', '/dzki$/', '/żki$/'), array('ska', 'cka', 'dzka', 'żka'), $match[1]);
@@ -2288,7 +2318,7 @@ function print_indi_form($nextaction, WT_Individual $person=null, WT_Family $fam
$new_marnm=$match[1];
}
break;
- case 'addchildaction':
+ case 'add_child_to_family_action':
if (preg_match('/\/((?:[a-z]{2,3} )*)(.*)\//i', $father_name, $match)) {
$name_fields['SURN']=$match[2];
if ($SURNAME_TRADITION=='polish' && $sextag=='F') {
@@ -2300,7 +2330,7 @@ function print_indi_form($nextaction, WT_Individual $person=null, WT_Family $fam
$name_fields['NAME']="/{$match[1]}{$match[2]}/";
}
break;
- case 'addnewparentaction':
+ case 'add_spouse_to_family_action':
if ($famtag=='HUSB' && preg_match('/\/((?:[a-z]{2,3} )*)(.*)\//i', $indi_name, $match)) {
if ($SURNAME_TRADITION=='polish' && $sextag=='M') {
$match[2]=preg_replace(array('/ska$/', '/cka$/', '/dzka$/', '/żka$/'), array('ski', 'cki', 'dzki', 'żki'), $match[2]);
@@ -2366,7 +2396,6 @@ function print_indi_form($nextaction, WT_Individual $person=null, WT_Family $fam
if ($SURNAME_TRADITION=='paternal' || $SURNAME_TRADITION=='polish' || $SURNAME_TRADITION=='lithuanian' || (strpos($namerec, '2 _MARNM')!==false)) {
$adv_name_fields['_MARNM']='';
}
- $person = WT_Individual::getInstance($xref);
if (isset($adv_name_fields['TYPE'])) {
unset($adv_name_fields['TYPE']);
}
@@ -2453,7 +2482,7 @@ function print_indi_form($nextaction, WT_Individual $person=null, WT_Family $fam
}
}
//-- if adding a spouse add the option to add a marriage fact to the new family
- if ($nextaction=='addspouseaction' || ($nextaction=='addnewparentaction' && $famid!='new')) {
+ if ($nextaction=='add_spouse_to_individual_action' || $nextaction=='add_spouse_to_family_action') {
$bdm .= "M";
if (preg_match_all('/('.WT_REGEX_TAG.')/', $QUICK_REQUIRED_FAMFACTS, $matches)) {
foreach ($matches[1] as $match) {
@@ -2483,7 +2512,7 @@ function print_indi_form($nextaction, WT_Individual $person=null, WT_Family $fam
}
echo '<p id="save-cancel">';
echo '<input type="submit" class="save" value="', /* I18N: button label */ WT_I18N::translate('save'), '">';
- if (preg_match('/^add(child|spouse|newparent)/', $nextaction)) {
+ if (preg_match('/^add_(child|spouse|parent|unlinked_indi)/', $nextaction)) {
echo '<input type="submit" class="save" value="', /* I18N: button label */ WT_I18N::translate('go to new individual'), '" onclick="document.addchildform.goto.value=\'new\';">';
}
echo '<input type="button" class="cancel" value="', /* I18N: button label */ WT_I18N::translate('close'), '" onclick="window.close();">';
diff --git a/family.php b/family.php
index ee0da25f00..bedc38c693 100644
--- a/family.php
+++ b/family.php
@@ -114,11 +114,11 @@ echo '</script>';
if (WT_USER_CAN_EDIT) {
$husb=$controller->record->getHusband();
if (!$husb) {
- echo '<a href="#" onclick="return addnewparentfamily(\'\', \'HUSB\', \'', $controller->record->getXref(), '\');">', WT_I18N::translate('Add a new father'), '</a><br>';
+ echo '<a href="#" onclick="return add_spouse_to_family(\'\', \'HUSB\', \'', $controller->record->getXref(), '\');">', WT_I18N::translate('Add a new father'), '</a><br>';
}
$wife=$controller->record->getWife();
if (!$wife) {
- echo '<a href="#" onclick="return addnewparentfamily(\'\', \'WIFE\', \'', $controller->record->getXref(), '\');">', WT_I18N::translate('Add a new mother'), '</a><br>';
+ echo '<a href="#" onclick="return add_spouse_to_family(\'\', \'WIFE\', \'', $controller->record->getXref(), '\');">', WT_I18N::translate('Add a new mother'), '</a><br>';
}
}
?>
diff --git a/includes/functions/functions_charts.php b/includes/functions/functions_charts.php
index ab65a302dc..a4fbc50051 100644
--- a/includes/functions/functions_charts.php
+++ b/includes/functions/functions_charts.php
@@ -83,8 +83,8 @@ function print_family_parents(WT_Family $family, $sosa=0, $label='', $parid='',
$husb = new WT_Individual('M', "0 @M@ INDI\n1 SEX M", null, WT_GED_ID);
}
$wife = $family->getWife();
- echo '<a name="', $wife->getXref(), '"></a>';
if ($wife) {
+ echo '<a name="', $wife->getXref(), '"></a>';
} else {
$wife = new WT_Individual('F', "0 @F@ INDI\n1 SEX F", null, WT_GED_ID);
}
@@ -252,9 +252,9 @@ function print_family_children(WT_Family $family, $childid = "", $sosa = 0, $lab
if ($sosa==0 && WT_USER_CAN_EDIT) {
echo '<br>';
- echo "<a href=\"#\" onclick=\"return addnewchild('", $family->getXref(), "','');\">" . WT_I18N::translate('Add a child to this family') . "</a>";
- echo ' <a class="icon-sex_m_15x15" href="#" onclick="return addnewchild(\'', $family->getXref(), '\',\'M\');" title="',WT_I18N::translate('son'), '"></a>';
- echo ' <a class="icon-sex_f_15x15" href="#" onclick="return addnewchild(\'', $family->getXref(), '\',\'F\');" title="',WT_I18N::translate('daughter'), '"></a>';
+ echo "<a href=\"#\" onclick=\"return add_child_to_family('", $family->getXref(), "', 'U');\">" . WT_I18N::translate('Add a child to this family') . "</a>";
+ echo ' <a class="icon-sex_m_15x15" href="#" onclick="return add_child_to_family(\'', $family->getXref(), '\', \'M\');" title="',WT_I18N::translate('son'), '"></a>';
+ echo ' <a class="icon-sex_f_15x15" href="#" onclick="return add_child_to_family(\'', $family->getXref(), '\', \'F\');" title="',WT_I18N::translate('daughter'), '"></a>';
echo '<br><br>';
}
echo '</td>';
diff --git a/includes/functions/functions_edit.php b/includes/functions/functions_edit.php
index 9e15777771..e2df141ce4 100644
--- a/includes/functions/functions_edit.php
+++ b/includes/functions/functions_edit.php
@@ -552,9 +552,9 @@ function add_simple_tag($tag, $upperlevel='', $label='', $extra=null) {
} else if ($fact=="TEMP") {
echo select_edit_control($element_name, WT_Gedcom_Code_Temp::templeNames(), WT_I18N::translate('No Temple - Living Ordinance'), $value);
} else if ($fact=="ADOP") {
- echo edit_field_adop($element_name, $value, '', WT_Individual::getInstance($xref));
+ echo edit_field_adop($element_name, $value);
} else if ($fact=="PEDI") {
- echo edit_field_pedi($element_name, $value, '', WT_Individual::getInstance($xref));
+ echo edit_field_pedi($element_name, $value);
} else if ($fact=='STAT') {
echo select_edit_control($element_name, WT_Gedcom_Code_Stat::statusNames($upperlevel), '', $value);
} else if ($fact=='RELA') {
@@ -670,7 +670,7 @@ function add_simple_tag($tag, $upperlevel='', $label='', $extra=null) {
// NAME TYPE : hide text field and show a selection list
else if ($fact=='TYPE' && $level==0) {
$extra = 'onchange="document.getElementById(\''.$element_id.'\').value=this.value;"';
- echo edit_field_name_type($element_name, $value, $extra, WT_Individual::getInstance($xref));
+ echo edit_field_name_type($element_name, $value, $extra);
echo '<script>';
echo "document.getElementById('", $element_id, "').style.display='none';";
echo '</script>';
diff --git a/includes/functions/functions_print.php b/includes/functions/functions_print.php
index f600716859..6cab122d19 100644
--- a/includes/functions/functions_print.php
+++ b/includes/functions/functions_print.php
@@ -105,10 +105,13 @@ function print_pedigree_person($person, $style=1, $count=0, $personcount="1") {
}
foreach ($person->getSpouseFamilies() as $family) {
$spouse = $family->getSpouse($person);
- $personlinks .= '<li>';
- $personlinks .= '<a href="'.$family->getHtmlUrl().'"><b>'.WT_I18N::translate('Family with spouse').'</b></a><br>';
- $personlinks .= '<a href="'.$spouse->getHtmlUrl().'">' . $spouse->getFullName() . '</a>';
- $personlinks .= '</li><li><ul>';
+ if ($spouse) {
+ $personlinks .= '<li>';
+ $personlinks .= '<a href="'.$family->getHtmlUrl().'"><b>'.WT_I18N::translate('Family with spouse').'</b></a><br>';
+ $personlinks .= '<a href="'.$spouse->getHtmlUrl().'">' . $spouse->getFullName() . '</a>';
+ $personlinks .= '</li>';
+ $personlinks .= '<li><ul>';
+ }
foreach ($family->getChildren() as $child) {
$personlinks .= '<li><a href="'.$child->getHtmlUrl().'">';
$personlinks .= $child->getFullName();
diff --git a/js/webtrees-1.5.0.js b/js/webtrees-1.5.0.js
index 3791f326db..febc5cd4ef 100644
--- a/js/webtrees-1.5.0.js
+++ b/js/webtrees-1.5.0.js
@@ -309,39 +309,36 @@ function edit_interface(params, windowspecs, pastefield) {
var features = windowspecs || edit_window_specs;
var url = 'edit_interface.php?' + jQuery.param(params) + '&ged=' + WT_GEDCOM;
window.open(url, '_blank', features);
+ return false;
}
function edit_record(xref, fact_id) {
- edit_interface({
+ return edit_interface({
"action": "edit",
"xref": xref,
"fact_id": fact_id
});
- return false;
}
function edit_raw(xref) {
- edit_interface({
+ return edit_interface({
"action": "editraw",
"xref": xref
});
- return false;
}
function edit_note(xref) {
- edit_interface({
+ return edit_interface({
"action": "editnote",
"xref": xref
});
- return false;
}
function edit_source(xref) {
- edit_interface({
+ return edit_interface({
"action": "editsource",
"xref": xref,
});
- return false;
}
function add_record(xref, fact_field) {
@@ -350,7 +347,7 @@ function add_record(xref, fact_field) {
if (fact == "OBJE") {
window.open('addmedia.php?action=showmediaform&linkid=' + xref + '&ged=' + WT_GEDCOM, '_blank', edit_window_specs);
} else {
- edit_interface({
+ return edit_interface({
"action": "add",
"xref": xref,
"fact": fact
@@ -364,7 +361,7 @@ function addClipboardRecord(xref, fact) {
var factfield = document.getElementById(fact);
if (factfield) {
var factvalue = factfield.options[factfield.selectedIndex].value;
- edit_interface({
+ return edit_interface({
"action": "paste",
"xref": xref,
"fact": factvalue.substr(10)
@@ -374,118 +371,100 @@ function addClipboardRecord(xref, fact) {
}
function reorder_media(xref) {
- edit_interface({
+ return edit_interface({
"action": "reorder_media",
"xref": xref
}, mord_window_specs);
- return false;
}
function add_new_record(xref, fact) {
- edit_interface({
+ return edit_interface({
"action": "add",
"xref": xref,
"fact": fact
});
- return false;
}
-function addnewchild(famid, gender) {
- edit_interface({
- "action": "addchild",
+// Add a new child to an existing family
+function add_child_to_family(xref, gender) {
+ return edit_interface({
+ "action": "add_child_to_family",
"gender": gender,
- "famid": famid
+ "xref": xref
});
- return false;
}
-function add_unlinked_indi() {
- edit_interface({
- "action": "add_unlinked_indi",
+// Add a new child to an existing individual (creating a one-parent family)
+function add_child_to_individual(xref, gender) {
+ return edit_interface({
+ "action": "add_child_to_individual",
+ "gender": gender,
+ "xref": xref
});
- return false;
}
-function addnewspouse(xref, famtag) {
- edit_interface({
- "action": "addspouse",
+// Add a new parent to an existing individual (creating a one-parent family)
+function add_parent_to_individual(xref, gender) {
+ return edit_interface({
+ "action": "add_parent_to_individual",
+ "xref": xref,
+ "gender": gender
+ });
+}
+
+// Add a new spouse to an existing family
+function add_spouse_to_family(xref, famtag) {
+ return edit_interface({
+ "action": "add_spouse_to_family",
"xref": xref,
"famtag": famtag
});
- return false;
}
-function addopfchild(xref, gender) {
- edit_interface({
- "action": "addopfchild",
- "xref": xref,
- "gender": gender
+function add_unlinked_indi() {
+ return edit_interface({
+ "action": "add_unlinked_indi",
});
- return false;
}
-function addspouse(xref, famtag) {
- edit_interface({
- "action": "addspouse",
- "xref": xref,
- "famtag": famtag,
- "famid": "new"
+// Add a new spouse to an existing individual (creating a new family)
+function add_spouse_to_individual(xref, famtag) {
+ return edit_interface({
+ "action": "add_spouse_to_individual",
+ "xref": xref,
+ "famtag": famtag
});
- return false;
}
function linkspouse(xref, famtag) {
- edit_interface({
+ return edit_interface({
"action": "linkspouse",
"xref": xref,
"famtag": famtag,
"famid": "new"
});
- return false;
}
function add_famc(xref) {
- edit_interface({
+ return edit_interface({
"action": "addfamlink",
"xref": xref,
});
- return false;
}
function edit_name(xref, fact_id) {
- edit_interface({
+ return edit_interface({
"action": "editname",
"xref": xref,
"fact_id": fact_id
});
- return false;
}
function add_name(xref) {
- edit_interface({
+ return edit_interface({
"action": "addname",
"xref": xref
});
- return false;
-}
-
-function addnewparent(xref, famtag) {
- edit_interface({
- "action": "addnewparent",
- "xref": xref,
- "famtag": famtag
- });
- return false;
-}
-
-function addnewparentfamily(xref, famtag, famid) {
- edit_interface({
- "action": "addnewparent",
- "xref": xref,
- "famtag": famtag,
- "famid": famid
- });
- return false;
}
// Delete a fact - and reload the page
@@ -519,19 +498,17 @@ function copy_fact(xref, fact_id) {
}
function reorder_children(xref) {
- edit_interface({
+ return edit_interface({
"action": "reorder_children",
"xref": xref
});
- return false;
}
function reorder_families(xref) {
- edit_interface({
+ return edit_interface({
"action": "reorder_fams",
"xref": xref
});
- return false;
}
function reply(username, subject) {
@@ -545,48 +522,43 @@ function delete_message(id) {
}
function change_family_members(xref) {
- edit_interface({
+ return edit_interface({
"action": "changefamily",
"xref": xref
});
- return false;
}
function addnewsource(field) {
pastefield=field;
- edit_interface({
+ return edit_interface({
"action": "addnewsource",
"xref": "newsour"
}, null, field);
- return false;
}
function addnewrepository(field) {
pastefield=field;
- edit_interface({
+ return edit_interface({
"action": "addnewrepository",
"xref": "newrepo"
}, null, field);
- return false;
}
function addnewnote(field) {
pastefield=field;
- edit_interface({
+ return edit_interface({
"action": "addnewnote",
"noteid": "newnote"
}, null, field);
- return false;
}
function addnewnote_assisted(field, xref) {
pastefield=field;
- edit_interface({
+ return edit_interface({
"action": "addnewnote_assisted",
"noteid": "newnote",
"xref": xref
}, assist_window_specs, field);
- return false;
}
function addmedia_links(field, iid, iname) {
diff --git a/library/WT/Controller/Family.php b/library/WT/Controller/Family.php
index c91b54d24a..5aaac36bc0 100644
--- a/library/WT/Controller/Family.php
+++ b/library/WT/Controller/Family.php
@@ -93,7 +93,7 @@ class WT_Controller_Family extends WT_Controller_GedcomRecord {
// edit_fam / add child
$submenu = new WT_Menu(WT_I18N::translate('Add a child to this family'), '#', 'menu-fam-addchil');
- $submenu->addOnclick("return addnewchild('".$this->record->getXref()."');");
+ $submenu->addOnclick("return add_child_to_family('".$this->record->getXref()."', 'U');");
$menu->addSubmenu($submenu);
// edit_fam / reorder_children
diff --git a/library/WT/Family.php b/library/WT/Family.php
index 5c3ef4fb01..f4685621cf 100644
--- a/library/WT/Family.php
+++ b/library/WT/Family.php
@@ -43,18 +43,12 @@ class WT_Family extends WT_GedcomRecord {
if (preg_match('/^1 HUSB @(.+)@/m', $gedcom.$pending, $match)) {
$this->husb = WT_Individual::getInstance($match[1]);
}
- if (!$this->husb) {
- $this->husb = new WT_Individual('M', '0 @M@ INDI', null, $gedcom_id);
- }
if (preg_match('/^1 WIFE @(.+)@/m', $gedcom.$pending, $match)) {
$this->wife = WT_Individual::getInstance($match[1]);
}
- if (!$this->wife) {
- $this->wife = new WT_Individual('F', '0 @F@ INDI', null, $gedcom_id);
- }
// Make sure husb/wife are the right way round.
- if ($this->husb->getSex()=='F' || $this->wife->getSex()=='M') {
+ if ($this->husb && $this->husb->getSex()=='F' || $this->wife && $this->wife->getSex()=='M') {
list($this->husb, $this->wife) = array($this->wife, $this->husb);
}
}
@@ -132,7 +126,14 @@ class WT_Family extends WT_GedcomRecord {
}
function getSpouses($access_level=WT_USER_ACCESS_LEVEL) {
- return array($this->husb, $this->wife);
+ $spouses=array();
+ if ($this->husb) {
+ $spouses[] = $this->husb;
+ }
+ if ($this->wife) {
+ $spouses[] = $this->wife;
+ }
+ return $spouses;
}
/**
@@ -240,13 +241,35 @@ class WT_Family extends WT_GedcomRecord {
// Get an array of structures containing all the names in the record
public function getAllNames() {
+ global $UNKNOWN_NN, $UNKNOWN_PN;
+
if (is_null($this->_getAllNames)) {
// Check the script used by each name, so we can match cyrillic with cyrillic, greek with greek, etc.
- $husb_names=$this->husb->getAllNames();
+ if ($this->husb) {
+ $husb_names=$this->husb->getAllNames();
+ } else {
+ $husb_names = array(
+ 0 => array(
+ 'type' => 'BIRT',
+ 'sort' => '@N.N.',
+ 'full' => $UNKNOWN_PN, ' ', $UNKNOWN_NN,
+ ),
+ );
+ }
foreach ($husb_names as $n=>$husb_name) {
$husb_names[$n]['script']=utf8_script($husb_name['full']);
}
- $wife_names=$this->wife->getAllNames();
+ if ($this->wife) {
+ $wife_names=$this->wife->getAllNames();
+ } else {
+ $wife_names = array(
+ 0 => array(
+ 'type' => 'BIRT',
+ 'sort' => '@N.N.',
+ 'full' => $UNKNOWN_PN, ' ', $UNKNOWN_NN,
+ ),
+ );
+ }
foreach ($wife_names as $n=>$wife_name) {
$wife_names[$n]['script']=utf8_script($wife_name['full']);
}
diff --git a/library/WT/GedcomRecord.php b/library/WT/GedcomRecord.php
index 3036914196..c779b0c5d6 100644
--- a/library/WT/GedcomRecord.php
+++ b/library/WT/GedcomRecord.php
@@ -62,15 +62,20 @@ class WT_GedcomRecord {
$this->pending = $pending;
$this->gedcom_id = $gedcom_id;
+ $this->parseFacts();
+ }
+
+ // Split the record into facts
+ private function parseFacts() {
// Split the record into facts
- if ($gedcom) {
- $gedcom_facts = preg_split('/\n(?=1)/s', $gedcom);
+ if ($this->gedcom) {
+ $gedcom_facts = preg_split('/\n(?=1)/s', $this->gedcom);
array_shift($gedcom_facts);
} else {
$gedcom_facts = array();
}
- if ($pending) {
- $pending_facts = preg_split('/\n(?=1)/s', $pending);
+ if ($this->pending) {
+ $pending_facts = preg_split('/\n(?=1)/s', $this->pending);
array_shift($pending_facts);
} else {
$pending_facts = array();
@@ -80,7 +85,7 @@ class WT_GedcomRecord {
foreach ($gedcom_facts as $gedcom_fact) {
$fact = new WT_Fact($gedcom_fact, $this, md5($gedcom_fact));
- if ($pending !== null && !in_array($gedcom_fact, $pending_facts)) {
+ if ($this->pending !== null && !in_array($gedcom_fact, $pending_facts)) {
$fact->setIsOld();
}
$this->facts[] = $fact;
@@ -809,14 +814,15 @@ class WT_GedcomRecord {
WT_USER_ID
));
- // Clear the cache
- self::$gedcom_record_cache = null;
- self::$pending_record_cache = null;
+ $this->pending = $new_gedcom;
if (get_user_setting(WT_USER_ID, 'auto_accept')) {
accept_all_changes($this->xref, $this->gedcom_id);
+ $this->gedcom = $new_gedcom;
+ $this->pending = null;
}
}
+ $this->parseFacts();
}
static public function createRecord($gedcom, $gedcom_id) {
@@ -893,14 +899,17 @@ class WT_GedcomRecord {
WT_USER_ID
));
+ // Clear the cache
+ $this->pending = $gedcom;
+
// Accept this pending change
if (get_user_setting(WT_USER_ID, 'auto_accept')) {
accept_all_changes($this->xref, $this->gedcom_id);
+ $this->gedcom = $gedcom;
+ $this->pending = null;
}
- // Clear the cache
- self::$gedcom_record_cache = null;
- self::$pending_record_cache = null;
+ $this->parseFacts();
AddToLog('Update: ' . static::RECORD_TYPE . ' ' . $this->xref, 'edit');
}
diff --git a/library/WT/Individual.php b/library/WT/Individual.php
index 23e420ac17..813b267028 100644
--- a/library/WT/Individual.php
+++ b/library/WT/Individual.php
@@ -858,9 +858,12 @@ class WT_Individual extends WT_GedcomRecord {
$step_families=array();
$families=$this->getSpouseFamilies();
foreach ($families as $family) {
- foreach ($family->getSpouse($this)->getSpouseFamilies() as $step_family) {
- if (!in_array($step_family, $families, true)) {
- $step_families[]=$step_family;
+ $spouse = $family->getSpouse($this);
+ if ($spouse) {
+ foreach ($family->getSpouse($this)->getSpouseFamilies() as $step_family) {
+ if (!in_array($step_family, $families, true)) {
+ $step_families[]=$step_family;
+ }
}
}
}
@@ -922,7 +925,12 @@ class WT_Individual extends WT_GedcomRecord {
// TODO - this function doesn't belong in this class
function getSpouseFamilyLabel(WT_Family $family) {
- return /* I18N: %s is the spouse name */ WT_I18N::translate('Family with %s', $family->getSpouse($this)->getFullName());
+ $spouse = $family->getSpouse($this);
+ if ($spouse) {
+ return /* I18N: %s is the spouse name */ WT_I18N::translate('Family with %s', $spouse->getFullName());
+ } else {
+ return $family->getFullName();
+ }
}
/**
diff --git a/modules_v3/descendancy/module.php b/modules_v3/descendancy/module.php
index 2b4255bb63..8f5f3f59ab 100644
--- a/modules_v3/descendancy/module.php
+++ b/modules_v3/descendancy/module.php
@@ -209,7 +209,10 @@ class descendancy_WT_Module extends WT_Module implements WT_Module_Sidebar {
$out = '';
if ($person && $person->canShow()) {
foreach($person->getSpouseFamilies() as $family) {
- $out .= $this->getFamilyLi($family, $family->getSpouse($person), $generations-1);
+ $spouse = $family->getSpouse($person);
+ if ($spouse) {
+ $out .= $this->getFamilyLi($family, $spouse, $generations-1);
+ }
}
}
if ($out) {
diff --git a/modules_v3/family_nav/module.php b/modules_v3/family_nav/module.php
index 06d80a8ba4..9f306f93cf 100644
--- a/modules_v3/family_nav/module.php
+++ b/modules_v3/family_nav/module.php
@@ -240,19 +240,21 @@ class family_nav_WT_Module extends WT_Module implements WT_Module_Sidebar {
// Spouse Families -------------------------------------- @var $family Family
foreach ($person->getSpouseFamilies() as $family) {
- $spouse = $family->getSpouse($person);
- $children = $family->getChildren();
// Spouse ------------------------------
- $spouselinks .= '<a class="flyout3" href="' . $spouse->getHtmlUrl() . '">';
- $spouselinks .= $spouse->getFullName();
- $spouselinks .= '</a>';
- $spouselinks .= '<br>';
- if ($spouse->getFullName() != '') {
- $persons = 'Yes';
+ $spouse = $family->getSpouse($person);
+ if ($spouse) {
+ $spouselinks .= '<a class="flyout3" href="' . $spouse->getHtmlUrl() . '">';
+ $spouselinks .= $spouse->getFullName();
+ $spouselinks .= '</a>';
+ $spouselinks .= '<br>';
+ if ($spouse->getFullName() != '') {
+ $persons = 'Yes';
+ }
}
// Children ------------------------------ @var $child Person
+ $children = $family->getChildren();
foreach ($children as $child) {
$persons='Yes';
$spouselinks .= '<ul class="clist">';
diff --git a/modules_v3/relatives/module.php b/modules_v3/relatives/module.php
index e260db0148..f05516534b 100644
--- a/modules_v3/relatives/module.php
+++ b/modules_v3/relatives/module.php
@@ -93,7 +93,7 @@ class relatives_WT_Module extends WT_Module implements WT_Module_Tab {
?>
<tr>
<td class="facts_label"><?php echo WT_I18N::translate('Add husband'); ?></td>
- <td class="facts_value"><a href="#" onclick="return addnewspouse('<?php echo $family->getXref(); ?>', 'HUSB');"><?php echo WT_I18N::translate('Add a husband to this family'); ?></a></td>
+ <td class="facts_value"><a href="#" onclick="return add_spouse_to_family('<?php echo $family->getXref(); ?>', 'HUSB');"><?php echo WT_I18N::translate('Add a husband to this family'); ?></a></td>
</tr>
<?php
}
@@ -163,7 +163,7 @@ class relatives_WT_Module extends WT_Module implements WT_Module_Tab {
?>
<tr>
<td class="facts_label"><?php echo WT_I18N::translate('Add wife'); ?></td>
- <td class="facts_value"><a href="#" onclick="return addnewspouse('<?php echo $family->getXref(); ?>', 'WIFE');"><?php echo WT_I18N::translate('Add a wife to this family'); ?></a></td>
+ <td class="facts_value"><a href="#" onclick="return add_spouse_to_family('<?php echo $family->getXref(); ?>', 'WIFE');"><?php echo WT_I18N::translate('Add a wife to this family'); ?></a></td>
</tr>
<?php
}
@@ -208,10 +208,10 @@ class relatives_WT_Module extends WT_Module implements WT_Module_Tab {
<?php } ?>
</td>
<td class="facts_value">
- <a href="#" onclick="return addnewchild('<?php echo $family->getXref(); ?>');"><?php echo $child_u; ?></a>
+ <a href="#" onclick="return add_child_to_family('<?php echo $family->getXref(); ?>');"><?php echo $child_u; ?></a>
<span style='white-space:nowrap;'>
- <a href="#" class="icon-sex_m_15x15" onclick="return addnewchild('<?php echo $family->getXref(); ?>','M');"></a>
- <a href="#" class="icon-sex_f_15x15" onclick="return addnewchild('<?php echo $family->getXref(); ?>','F');"></a>
+ <a href="#" class="icon-sex_m_15x15" onclick="return add_child_to_family('<?php echo $family->getXref(); ?>','M');"></a>
+ <a href="#" class="icon-sex_f_15x15" onclick="return add_child_to_family('<?php echo $family->getXref(); ?>','F');"></a>
</span>
</td>
</tr>
@@ -246,10 +246,10 @@ class relatives_WT_Module extends WT_Module implements WT_Module_Tab {
?>
<table class="facts_table">
<tr>
- <td class="facts_value"><a href="#" onclick="return addnewparent('<?php echo $controller->record->getXref(); ?>', 'HUSB');"><?php echo WT_I18N::translate('Add a new father'); ?></td>
+ <td class="facts_value"><a href="#" onclick="return add_parent_to_individual('<?php echo $controller->record->getXref(); ?>', 'M');"><?php echo WT_I18N::translate('Add a new father'); ?></td>
</tr>
<tr>
- <td class="facts_value"><a href="#" onclick="return addnewparent('<?php echo $controller->record->getXref(); ?>', 'WIFE');"><?php echo WT_I18N::translate('Add a new mother'); ?></a></td>
+ <td class="facts_value"><a href="#" onclick="return add_parent_to_individual('<?php echo $controller->record->getXref(); ?>', 'F');"><?php echo WT_I18N::translate('Add a new mother'); ?></a></td>
</tr>
</table>
<?php
@@ -299,7 +299,7 @@ class relatives_WT_Module extends WT_Module implements WT_Module_Tab {
<?php if ($controller->record->getSex()!="F") { ?>
<tr>
<td class="facts_value">
- <a href="#" onclick="return addspouse('<?php echo $controller->record->getXref(); ?>','WIFE');"><?php echo WT_I18N::translate('Add a new wife'); ?></a>
+ <a href="#" onclick="return add_spouse_to_individual('<?php echo $controller->record->getXref(); ?>','WIFE');"><?php echo WT_I18N::translate('Add a new wife'); ?></a>
</td>
</tr>
<tr>
@@ -311,7 +311,7 @@ class relatives_WT_Module extends WT_Module implements WT_Module_Tab {
if ($controller->record->getSex()!="M") { ?>
<tr>
<td class="facts_value">
- <a href="#" onclick="return addspouse('<?php echo $controller->record->getXref(); ?>','HUSB');"><?php echo WT_I18N::translate('Add a new husband'); ?></a>
+ <a href="#" onclick="return add_spouse_to_individual('<?php echo $controller->record->getXref(); ?>','HUSB');"><?php echo WT_I18N::translate('Add a new husband'); ?></a>
</td>
</tr>
<tr>
@@ -322,7 +322,7 @@ class relatives_WT_Module extends WT_Module implements WT_Module_Tab {
<?php } ?>
<tr>
<td class="facts_value">
- <a href="#" onclick="return addopfchild('<?php echo $controller->record->getXref(); ?>','U');"><?php echo WT_I18N::translate('Add a child to create a one-parent family'); ?></a>
+ <a href="#" onclick="return add_child_to_individual('<?php echo $controller->record->getXref(); ?>','U');"><?php echo WT_I18N::translate('Add a child to create a one-parent family'); ?></a>
</td>
</tr>
</table>