setPageTitle(WT_I18N::translate('Edit'))
->pageHeader();
// If the fact has a DATE or PLAC, then delete any value of Y
if ($text[0] == 'Y') {
for ($n = 1; $n < count($tag); ++$n) {
if ($glevels[$n] == 2 && ($tag[$n] == 'DATE' || $tag[$n] == 'PLAC') && $text[$n]) {
$text[0] = '';
break;
}
}
}
$newged = "";
if (!empty($_POST['NAME'])) {
$newged .= "\n1 NAME " . $_POST['NAME'];
}
if (!empty($_POST['TYPE'])) {
$newged .= "\n2 TYPE " . $_POST['TYPE'];
}
if (!empty($_POST['NPFX'])) {
$newged .= "\n2 NPFX " . $_POST['NPFX'];
}
if (!empty($_POST['GIVN'])) {
$newged .= "\n2 GIVN " . $_POST['GIVN'];
}
if (!empty($_POST['NICK'])) {
$newged .= "\n2 NICK " . $_POST['NICK'];
}
if (!empty($_POST['SPFX'])) {
$newged .= "\n2 SPFX " . $_POST['SPFX'];
}
if (!empty($_POST['SURN'])) {
$newged .= "\n2 SURN " . $_POST['SURN'];
}
if (!empty($_POST['NSFX'])) {
$newged .= "\n2 NSFX " . $_POST['NSFX'];
}
if (!empty($_POST['ROMN'])) {
$newged .= "\n2 ROMN " . $_POST['ROMN'];
}
if (!empty($_POST['FONE'])) {
$newged .= "\n2 FONE " . $_POST['FONE'];
}
if (!empty($_POST['_HEB'])) {
$newged .= "\n2 _HEB " . $_POST['_HEB'];
}
if (!empty($_POST['_AKA'])) {
$newged .= "\n2 _AKA " . $_POST['_AKA'];
}
if (!empty($_POST['_MARNM'])) {
$newged .= "\n2 _MARNM " . $_POST['_MARNM'];
}
if (isset($_POST['NOTE'])) {
$NOTE = $_POST['NOTE'];
}
if (!empty($NOTE)) {
$tempnote = preg_split('/\r?\n/', trim($NOTE) . "\n"); // make sure only one line ending on the end
$title[] = "0 @$xref@ NOTE " . array_shift($tempnote);
foreach ($tempnote as &$line) {
$line = trim("1 CONT " . $line, ' ');
}
}
$newged = handle_updates($newged);
$newged = substr($newged, 1); // Remove leading newline
$record->updateFact($fact_id, $newged, !$keep_chan);
// For the GEDFact_assistant module
$pid_array = WT_Filter::post('pid_array');
if ($pid_array) {
foreach (explode(', ', $pid_array) as $pid) {
if ($pid != $xref) {
$indi = WT_Individual::getInstance($pid);
if ($indi && $indi->canEdit()) {
$indi->updateFact($fact_id, $newged, !$keep_chan);
}
}
}
}
$controller->addInlineJavascript('closePopupAndReloadParent();');
break;
////////////////////////////////////////////////////////////////////////////////
// Add a new child to an existing family
////////////////////////////////////////////////////////////////////////////////
case 'add_child_to_family':
$xref = WT_Filter::get('xref', WT_REGEX_XREF);
$gender = WT_Filter::get('gender', '[MFU]', 'U');
$family = WT_Family::getInstance($xref);
check_record_access($family);
$controller
->setPageTitle($family->getFullName() . ' - ' . WT_I18N::translate('Add a new child'))
->pageHeader();
print_indi_form('add_child_to_family_action', null, $family, null, 'CHIL', $gender);
break;
case 'add_child_to_family_action':
$xref = WT_Filter::post('xref', WT_REGEX_XREF);
$PEDI = WT_Filter::post('PEDI');
$keep_chan = WT_Filter::postBool('keep_chan');
$glevels = WT_Filter::postArray('glevels', '[0-9]');
$tag = WT_Filter::postArray('tag', WT_REGEX_TAG);
$text = WT_Filter::postArray('text');
$islink = WT_Filter::postArray('islink', '[01]');
if (!WT_Filter::checkCsrf()) {
$gender = WT_Filter::get('gender', '[MFU]', 'U');
Zend_Session::writeClose();
header('Location: ' . WT_SERVER_NAME . WT_SCRIPT_PATH . WT_SCRIPT_NAME . '?action=add_child_to_family&xref=' . $xref . '&gender=' . $gender);
return;
}
$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 (WT_Filter::postBool('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 (WT_Filter::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 = WT_Filter::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 = WT_Filter::post('xref', WT_REGEX_XREF);
$PEDI = WT_Filter::post('PEDI');
$glevels = WT_Filter::postArray('glevels', '[0-9]');
$tag = WT_Filter::postArray('tag', WT_REGEX_TAG);
$text = WT_Filter::postArray('text');
$islink = WT_Filter::postArray('islink', '[01]');
if (!WT_Filter::checkCsrf()) {
Zend_Session::writeClose();
header('Location: ' . WT_SERVER_NAME . WT_SCRIPT_PATH . WT_SCRIPT_NAME . '?action=add_child_to_individual&xref=' . $xref);
return;
}
$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, $family->getXref());
if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FACTS, $matches)) {
foreach ($matches[1] as $match) {
$gedcom .= addNewFact($match);
}
}
if (WT_Filter::postBool('SOUR_INDI')) {
$gedcom = handle_updates($gedcom);
} else {
$gedcom = updateRest($gedcom);
}
$child = WT_GedcomRecord::createRecord($gedcom, WT_GED_ID);
// Link the family to the child
$family->createFact('1 CHIL @' . $child->getXref() . '@', true);
if (WT_Filter::post('goto') == 'new') {
$controller->addInlineJavascript('closePopupAndReloadParent("' . $child->getRawUrl() . '");');
} else {
$controller->addInlineJavascript('closePopupAndReloadParent();');
}
break;
////////////////////////////////////////////////////////////////////////////////
// Add a new parent to an existing individual (creating a one-parent family)
////////////////////////////////////////////////////////////////////////////////
case 'add_parent_to_individual':
$xref = WT_Filter::get('xref', WT_REGEX_XREF);
$gender = WT_Filter::get('gender', '[MF]', 'U');
$individual = WT_Individual::getInstance($xref);
check_record_access($individual);
if ($gender == '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 = WT_Filter::post('xref', WT_REGEX_XREF);
$PEDI = WT_Filter::post('PEDI');
$glevels = WT_Filter::postArray('glevels', '[0-9]');
$tag = WT_Filter::postArray('tag', WT_REGEX_TAG);
$text = WT_Filter::postArray('text');
$islink = WT_Filter::postArray('islink', '[01]');
if (!WT_Filter::checkCsrf()) {
$gender = WT_Filter::get('gender', '[MFU]', 'U');
Zend_Session::writeClose();
header('Location: ' . WT_SERVER_NAME . WT_SCRIPT_PATH . WT_SCRIPT_NAME . '?action=add_parent_to_individual&xref=' . $xref . '&gender=' . $gender);
return;
}
$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();
if (preg_match_all('/([A-Z0-9_]+)/', $QUICK_REQUIRED_FACTS, $matches)) {
foreach ($matches[1] as $match) {
$gedcom .= addNewFact($match);
}
}
if (WT_Filter::postBool('SOUR_INDI')) {
$gedcom = handle_updates($gedcom);
} else {
$gedcom = updateRest($gedcom);
}
$gedcom .= "\n1 FAMS @" . $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);
}
if (WT_Filter::post('goto') == 'new') {
$controller->addInlineJavascript('closePopupAndReloadParent("' . $parent->getRawUrl() . '");');
} else {
$controller->addInlineJavascript('closePopupAndReloadParent();');
}
break;
////////////////////////////////////////////////////////////////////////////////
// Add a new, unlinked individual
////////////////////////////////////////////////////////////////////////////////
case 'add_unlinked_indi':
$controller
->restrictAccess(Auth::isManager())
->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':
$glevels = WT_Filter::postArray('glevels', '[0-9]');
$tag = WT_Filter::postArray('tag', WT_REGEX_TAG);
$text = WT_Filter::postArray('text');
$islink = WT_Filter::postArray('islink', '[01]');
if (!WT_Filter::checkCsrf()) {
Zend_Session::writeClose();
header('Location: ' . WT_SERVER_NAME . WT_SCRIPT_PATH . WT_SCRIPT_NAME . '?action=add_unlinked_indi');
return;
}
$controller
->restrictAccess(Auth::isManager())
->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 (WT_Filter::postBool('SOUR_INDI')) {
$gedrec = handle_updates($gedrec);
} else {
$gedrec = updateRest($gedrec);
}
$new_indi = WT_GedcomRecord::createRecord($gedrec, WT_GED_ID);
if (WT_Filter::post('goto') == 'new') {
$controller->addInlineJavascript('closePopupAndReloadParent("' . $new_indi->getRawUrl() . '");');
} else {
$controller->addInlineJavascript('closePopupAndReloadParent();');
}
break;
////////////////////////////////////////////////////////////////////////////////
// Add a new spouse to an existing individual (creating a new family)
////////////////////////////////////////////////////////////////////////////////
case 'add_spouse_to_individual':
$famtag = WT_Filter::get('famtag', 'HUSB|WIFE');
$xref = WT_Filter::get('xref', WT_REGEX_XREF);
$individual = WT_Individual::getInstance($xref);
check_record_access($individual);
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('add_spouse_to_individual_action', $individual, null, null, $famtag, $sex);
break;
case 'add_spouse_to_individual_action':
$xref = WT_Filter::post('xref'); // Add a spouse to this individual
$sex = WT_Filter::post('SEX', '[MFU]', 'U');
$glevels = WT_Filter::postArray('glevels', '[0-9]');
$tag = WT_Filter::postArray('tag', WT_REGEX_TAG);
$text = WT_Filter::postArray('text');
$islink = WT_Filter::postArray('islink', '[01]');
if (!WT_Filter::checkCsrf()) {
$famtag = WT_Filter::get('famtag', 'HUSB|WIFE');
Zend_Session::writeClose();
header('Location: ' . WT_SERVER_NAME . WT_SCRIPT_PATH . WT_SCRIPT_NAME . '?action=add_spouse_to_individual&xref=' . $xref . '&famtag=' . $famtag);
return;
}
$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 (WT_Filter::postBool('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 (WT_Filter::postBool('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 (WT_Filter::post('goto') == 'new') {
$controller->addInlineJavascript('closePopupAndReloadParent("' . $spouse->getRawUrl() . '");');
} else {
$controller->addInlineJavascript('closePopupAndReloadParent();');
}
break;
////////////////////////////////////////////////////////////////////////////////
// Add a new spouse to an existing family
////////////////////////////////////////////////////////////////////////////////
case 'add_spouse_to_family':
$xref = WT_Filter::get('xref', WT_REGEX_XREF);
$famtag = WT_Filter::get('famtag', 'HUSB|WIFE');
$family = WT_Family::getInstance($xref);
check_record_access($family);
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('add_spouse_to_family_action', null, $family, null, $famtag, $sex);
break;
case 'add_spouse_to_family_action':
$xref = WT_Filter::post('xref', WT_REGEX_XREF);
$glevels = WT_Filter::postArray('glevels', '[0-9]');
$tag = WT_Filter::postArray('tag', WT_REGEX_TAG);
$text = WT_Filter::postArray('text');
$islink = WT_Filter::postArray('islink', '[01]');
$family = WT_Family::getInstance($xref);
check_record_access($family);
if (!WT_Filter::checkCsrf()) {
$famtag = WT_Filter::get('famtag', 'HUSB|WIFE');
Zend_Session::writeClose();
header('Location: ' . WT_SERVER_NAME . WT_SCRIPT_PATH . WT_SCRIPT_NAME . '?action=add_spouse_to_family&xref=' . $xref . '&famtag=' . $famtag);
return;
}
$controller->pageHeader();
// 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 (WT_Filter::postBool('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 (WT_Filter::postBool('SOUR_FAM')) {
$famrec = handle_updates($famrec);
} else {
$famrec = updateRest($famrec);
}
$family->createFact(trim($famrec), true); // trim leading \n
if (WT_Filter::post('goto') == 'new') {
$controller->addInlineJavascript('closePopupAndReloadParent("' . $spouse->getRawUrl() . '");');
} else {
$controller->addInlineJavascript('closePopupAndReloadParent();');
}
break;
////////////////////////////////////////////////////////////////////////////////
// Link an individual to an existing family, as a child
////////////////////////////////////////////////////////////////////////////////
case 'addfamlink':
$xref = WT_Filter::get('xref', WT_REGEX_XREF);
$person = WT_Individual::getInstance($xref);
check_record_access($person);
$controller
->setPageTitle($person->getFullName() . ' - ' . WT_I18N::translate('Link this individual to an existing family as a child'))
->pageHeader();
?>
getPageTitle(); ?>
setPageTitle($person->getFullName() . ' - ' . WT_I18N::translate('Link this individual to an existing family as a child'))
->pageHeader();
// Replace any existing child->family link (we may be changing the PEDI);
$fact_id = null;
foreach ($person->getFacts('FAMC') as $fact) {
if ($family === $fact->getTarget()) {
$fact_id = $fact->getFactId();
break;
}
}
$gedcom = WT_Gedcom_Code_Pedi::createNewFamcPedi($PEDI, $famid);
$person->updateFact($fact_id, $gedcom, true);
// Only set the family->child link if it does not already exist
$edit_fact = null;
foreach ($family->getFacts('CHIL') as $fact) {
if ($person === $fact->getTarget()) {
$edit_fact = $fact;
break;
}
}
if (!$edit_fact) {
$family->createFact('1 CHIL @' . $person->getXref() . '@', true);
}
$controller->addInlineJavascript('closePopupAndReloadParent();');
break;
////////////////////////////////////////////////////////////////////////////////
// Link and individual to an existing individual as a spouse
////////////////////////////////////////////////////////////////////////////////
case 'linkspouse':
$famtag = WT_Filter::get('famtag', 'HUSB|WIFE');
$xref = WT_Filter::get('xref', WT_REGEX_XREF);
$person = WT_Individual::getInstance($xref);
check_record_access($person);
if ($person->getSex() == 'F') {
$controller->setPageTitle($person->getFullName() . ' - ' . WT_I18N::translate('Add a husband using an existing individual'));
$label = WT_I18N::translate('Husband');
} else {
$controller->setPageTitle($person->getFullName() . ' - ' . WT_I18N::translate('Add a wife using an existing individual'));
$label = WT_I18N::translate('Wife');
}
$controller->pageHeader();
init_calendar_popup();
?>
getPageTitle(); ?>
getSex() == 'F') {
$controller->setPageTitle($person->getFullName() . ' - ' . WT_I18N::translate('Add a husband using an existing individual'));
} else {
$controller->setPageTitle($person->getFullName() . ' - ' . WT_I18N::translate('Add a wife using an existing individual'));
}
$controller->pageHeader();
if ($person->getSex() == 'M') {
$gedcom = "0 @new@ FAM\n1 HUSB @" . $person->getXref() . "@\n1 WIFE @" . $spouse->getXref() . "@";
} else {
$gedcom = "0 @new@ FAM\n1 HUSB @" . $spouse->getXref() . "@\n1 WIFE @" . $person->getXref() . "@";
}
splitSOUR();
$gedcom .= addNewFact('MARR');
if (WT_Filter::postBool('SOUR_FAM') || count($tagSOUR) > 0) {
// before adding 2 SOUR it needs to add 1 MARR Y first
if (addNewFact('MARR') == '') {
$gedcom .= "\n1 MARR Y";
}
$gedcom = handle_updates($gedcom);
} else {
// before adding level 2 facts it needs to add 1 MARR Y first
if (addNewFact('MARR') == '') {
$gedcom .= "\n1 MARR Y";
}
$gedcom = updateRest($gedcom);
}
$family = WT_GedcomRecord::createRecord($gedcom, WT_GED_ID);
$person->createFact('1 FAMS @' . $family->getXref() . '@', true);
$spouse->createFact('1 FAMS @' . $family->getXref() . '@', true);
$controller->addInlineJavascript('closePopupAndReloadParent();');
break;
////////////////////////////////////////////////////////////////////////////////
// Create a new source record
////////////////////////////////////////////////////////////////////////////////
case 'addnewsource':
$controller
->setPageTitle(WT_I18N::translate('Create a new source'))
->pageHeader();
?>
setPageTitle(WT_I18N::translate('Edit shared note'))
->pageHeader();
// We have user-supplied data in a replacement string - escape it against backreferences
$note = str_replace(array('\\', '$'), array('\\\\', '\\$'), $note);
$gedrec = preg_replace(
'/^0 @' . $record->getXref() . '@ NOTE.*(\n1 CONT.*)*/',
'0 @' . $record->getXref() . '@ NOTE ' . preg_replace("/\r?\n/", "\n1 CONT ", $note),
$record->getGedcom()
);
$record->updateRecord($gedrec, !$keep_chan);
$controller->addInlineJavascript('closePopupAndReloadParent();');
break;
////////////////////////////////////////////////////////////////////////////////
// Create a new repository
////////////////////////////////////////////////////////////////////////////////
case 'addnewrepository':
$controller
->setPageTitle(WT_I18N::translate('Create a new repository'))
->pageHeader();
echo '
';
echo '
', $controller->getPageTitle(), '
';
echo '';
?>
setPageTitle(WT_I18N::translate('Create a new repository'))
->pageHeader();
$gedrec = "0 @XREF@ REPO";
$REPO_NAME = WT_Filter::post('REPO_NAME');
if ($REPO_NAME) {
$gedrec .= "\n1 NAME " . $REPO_NAME;
$_HEB = WT_Filter::post('_HEB');
if ($_HEB) {
$gedrec .= "\n2 _HEB " . $_HEB;
}
$ROMN = WT_Filter::post('ROMN');
if ($ROMN) {
$gedrec .= "\n2 ROMN " . $ROMN;
}
}
$ADDR = WT_Filter::post('ADDR');
if ($ADDR) {
$gedrec .= "\n1 ADDR " . preg_replace('/\r?\n/', "\n2 CONT ", $ADDR);
}
$PHON = WT_Filter::post('PHON');
if ($PHON) {
$gedrec .= "\n1 PHON " . $PHON;
}
$FAX = WT_Filter::post('FAX');
if ($FAX) {
$gedrec .= "\n1 FAX " . $FAX;
}
$EMAIL = WT_Filter::post('EMAIL');
if ($EMAIL) {
$gedrec .= "\n1 EMAIL " . $EMAIL;
}
$WWW = WT_Filter::post('WWW');
if ($WWW) {
$gedrec .= "\n1 WWW " . $WWW;
}
$record = WT_GedcomRecord::createRecord($gedrec, WT_GED_ID);
$controller->addInlineJavascript('openerpasteid("' . $record->getXref() . '");');
break;
////////////////////////////////////////////////////////////////////////////////
case 'editname':
$xref = WT_Filter::get('xref', WT_REGEX_XREF);
$fact_id = WT_Filter::get('fact_id');
$person = WT_Individual::getInstance($xref);
check_record_access($person);
// Find the fact to edit
$name_fact = null;
foreach ($person->getFacts() as $fact) {
if ($fact->getFactId() == $fact_id && $fact->canEdit()) {
$name_fact = $fact;
}
}
if (!$name_fact) {
$controller
->pageHeader()
->addInlineJavascript('closePopupAndReloadParent();');
return;
}
$controller
->setPageTitle(WT_I18N::translate('Edit name'))
->pageHeader();
print_indi_form('update', $person, null, $name_fact, '', $person->getSex());
break;
////////////////////////////////////////////////////////////////////////////////
case 'addname':
$xref = WT_Filter::get('xref', WT_REGEX_XREF);
$person = WT_Individual::getInstance($xref);
check_record_access($person);
$controller
->setPageTitle(WT_I18N::translate('Add a new name'))
->pageHeader();
print_indi_form('update', $person, null, null, '', $person->getSex());
break;
////////////////////////////////////////////////////////////////////////////////
// Change the order of media objects
////////////////////////////////////////////////////////////////////////////////
case 'reorder_media':
$xref = WT_Filter::get('xref', WT_REGEX_XREF);
$person = WT_Individual::getInstance($xref);
check_record_access($person);
$controller
->setPageTitle(WT_I18N::translate('Re-order media'))
->pageHeader()
->addInlineJavascript('
jQuery("#reorder_media_list").sortable({forceHelperSize: true, forcePlaceholderSize: true, opacity: 0.7, cursor: "move", axis: "y"});
//-- update the order numbers after drag-n-drop sorting is complete
jQuery("#reorder_media_list").bind("sortupdate", function(event, ui) {
jQuery("#"+jQuery(this).attr("id")+" input").each(
function (index, value) {
value.value = index+1;
}
);
});
');
// Get the current sort order
$sort_obje = array();
foreach ($person->getFacts('_WT_OBJE_SORT') as $fact) {
$media = $fact->getTarget();
if ($media && $media->canShow()) {
$sort_obje[] = $media;
}
}
// Add other media objects from the individual and any spouse-families
$record_list = array($person);
foreach ($person->getSpouseFamilies() as $family) {
$record_list[] = $family;
}
foreach ($record_list as $record) {
if ($record->canShow()) {
foreach ($record->getFacts() as $fact) {
if (!$fact->isPendingDeletion()) {
preg_match_all('/(?:^1|\n\d) OBJE @(' . WT_REGEX_XREF . ')@/', $fact->getGedcom(), $matches);
foreach ($matches[1] as $match) {
$media = WT_Media::getInstance($match);
if (!in_array($media, $sort_obje)) {
$sort_obje[] = $media;
}
}
}
}
}
}
?>
setPageTitle(WT_I18N::translate('Re-order media'))
->pageHeader();
// Delete any existing _WT_OBJE_SORT records
$facts = array('0 @' . $person->getXref() . '@ INDI');
foreach ($person->getFacts() as $fact) {
if ($fact->getTag() != '_WT_OBJE_SORT') {
$facts[] = $fact->getGedcom();
}
}
if (is_array($order1)) {
// Add new _WT_OBJE_SORT records
foreach ($order1 as $xref=>$n) {
$facts[] = '1 _WT_OBJE_SORT @' . $xref . '@';
}
}
$person->updateRecord(implode("\n", $facts), !$keep_chan);
$controller->addInlineJavascript('closePopupAndReloadParent();');
break;
////////////////////////////////////////////////////////////////////////////////
// Change the order of children within a family record
////////////////////////////////////////////////////////////////////////////////
case 'reorder_children':
$xref = WT_Filter::post('xref', WT_REGEX_XREF, WT_Filter::get('xref', WT_REGEX_XREF));
$option = WT_Filter::post('option');
$family = WT_Family::getInstance($xref);
check_record_access($family);
$controller
->addInlineJavascript('jQuery("#reorder_list").sortable({forceHelperSize: true, forcePlaceholderSize: true, opacity: 0.7, cursor: "move", axis: "y"});')
->addInlineJavascript('jQuery("#reorder_list").bind("sortupdate", function(event, ui) { jQuery("#"+jQuery(this).attr("id")+" input").each( function (index, value) { value.value = index+1; }); });')
->setPageTitle(WT_I18N::translate('Re-order children'))
->pageHeader();
?>
getPageTitle(); ?>
setPageTitle(WT_I18N::translate('Re-order children'))
->pageHeader();
if (is_array($order)) {
$gedcom = array('0 @' . $family->getXref() . '@ FAM');
$facts = $family->getFacts();
// Move children to the end of the record
foreach ($order as $child=>$num) {
foreach ($facts as $n=>$fact) {
if ($fact->getValue() == '@' . $child . '@') {
$facts[] = $fact;
unset($facts[$n]);
break;
}
}
}
foreach ($facts as $fact) {
$gedcom[] = $fact->getGedcom();
}
$family->updateRecord(implode("\n", $gedcom), !$keep_chan);
}
$controller->addInlineJavascript('closePopupAndReloadParent();');
break;
////////////////////////////////////////////////////////////////////////////////
// Change the members of a family record
////////////////////////////////////////////////////////////////////////////////
case 'changefamily':
$xref = WT_Filter::get('xref', WT_REGEX_XREF);
$family = WT_Family::getInstance($xref);
check_record_access($family);
$controller
->setPageTitle(WT_I18N::translate('Change family members') . ' – ' . $family->getFullName())
->pageHeader();
$father = $family->getHusband();
$mother = $family->getWife();
$children = $family->getChildren();
?>
getPageTitle(); ?>
setPageTitle(WT_I18N::translate('Change family members') . ' – ' . $family->getFullName())
->pageHeader();
// Current family members
$old_father = $family->getHusband();
$old_mother = $family->getWife();
$old_children = $family->getChildren();
// New family members
$new_father = WT_Individual::getInstance($HUSB);
$new_mother = WT_Individual::getInstance($WIFE);
$new_children = array();
if (is_array($CHIL)) {
foreach ($CHIL as $child) {
$new_children[] = WT_Individual::getInstance($child);
}
}
if ($old_father !== $new_father) {
if ($old_father) {
// Remove old FAMS link
foreach ($old_father->getFacts('FAMS') as $fact) {
if ($fact->getTarget() === $family) {
$old_father->deleteFact($fact->getFactId(), !$keep_chan);
}
}
// Remove old HUSB link
foreach ($family->getFacts('HUSB|WIFE') as $fact) {
if ($fact->getTarget() === $old_father) {
$family->deleteFact($fact->getFactId(), !$keep_chan);
}
}
}
if ($new_father) {
// Add new FAMS link
$new_father->createFact('1 FAMS @' . $family->getXref() . '@', !$keep_chan);
// Add new HUSB link
$family->createFact('1 HUSB @' . $new_father->getXref() . '@', !$keep_chan);
}
}
if ($old_mother !== $new_mother) {
if ($old_mother) {
// Remove old FAMS link
foreach ($old_mother->getFacts('FAMS') as $fact) {
if ($fact->getTarget() === $family) {
$old_mother->deleteFact($fact->getFactId(), !$keep_chan);
}
}
// Remove old WIFE link
foreach ($family->getFacts('HUSB|WIFE') as $fact) {
if ($fact->getTarget() === $old_mother) {
$family->deleteFact($fact->getFactId(), !$keep_chan);
}
}
}
if ($new_mother) {
// Add new FAMS link
$new_mother->createFact('1 FAMS @' . $family->getXref() . '@', !$keep_chan);
// Add new WIFE link
$family->createFact('1 WIFE @' . $new_mother->getXref() . '@', !$keep_chan);
}
}
foreach ($old_children as $old_child) {
if ($old_child && !in_array($old_child, $new_children)) {
// Remove old FAMC link
foreach ($old_child->getFacts('FAMC') as $fact) {
if ($fact->getTarget() === $family) {
$old_child->deleteFact($fact->getFactId(), !$keep_chan);
}
}
// Remove old CHIL link
foreach ($family->getFacts('CHIL') as $fact) {
if ($fact->getTarget() === $old_child) {
$family->deleteFact($fact->getFactId(), !$keep_chan);
}
}
}
}
foreach ($new_children as $new_child) {
if ($new_child && !in_array($new_child, $old_children)) {
// Add new FAMC link
$new_child->createFact('1 FAMC @' . $family->getXref() . '@', !$keep_chan);
// Add new CHIL link
$family->createFact('1 CHIL @' . $new_child->getXref() . '@', !$keep_chan);
}
}
$controller->addInlineJavascript('closePopupAndReloadParent();');
break;
////////////////////////////////////////////////////////////////////////////////
// Change the order of FAMS records within an INDI record
////////////////////////////////////////////////////////////////////////////////
case 'reorder_fams':
$xref = WT_Filter::post('xref', WT_REGEX_XREF, WT_Filter::get('xref', WT_REGEX_XREF));
$option = WT_Filter::post('option');
$person = WT_Individual::getInstance($xref);
check_record_access($person);
$controller
->addInlineJavascript('jQuery("#reorder_list").sortable({forceHelperSize: true, forcePlaceholderSize: true, opacity: 0.7, cursor: "move", axis: "y"});')
//-- update the order numbers after drag-n-drop sorting is complete
->addInlineJavascript('jQuery("#reorder_list").bind("sortupdate", function(event, ui) { jQuery("#"+jQuery(this).attr("id")+" input").each( function (index, value) { value.value = index+1; }); });')
->setPageTitle(WT_I18N::translate('Re-order families'))
->pageHeader();
$fams = $person->getSpouseFamilies();
if ($option == 'bymarriage') {
usort($fams, array('WT_Family', 'compareMarrDate'));
}
?>
getPageTitle(); ?>
setPageTitle(WT_I18N::translate('Re-order families'))
->pageHeader();
if (is_array($order)) {
$gedcom = array('0 @' . $person->getXref() . '@ INDI');
$facts = $person->getFacts();
// Move families to the end of the record
foreach ($order as $family=>$num) {
foreach ($facts as $n=>$fact) {
if ($fact->getValue() == '@' . $family . '@') {
$facts[] = $fact;
unset($facts[$n]);
break;
}
}
}
foreach ($facts as $fact) {
$gedcom[] = $fact->getGedcom();
}
$person->updateRecord(implode("\n", $gedcom), !$keep_chan);
}
$controller->addInlineJavascript('closePopupAndReloadParent();');
break;
}
/**
* Show an option to preserve the existing CHAN record when editing.
*
* @param WT_GedcomRecord $record
*
* @return string
*/
function keep_chan(WT_GedcomRecord $record = null) {
global $NO_UPDATE_CHAN;
if (Auth::isAdmin()) {
if ($record) {
$details =
WT_Gedcom_Tag::getLabelValue('DATE', $record->lastChangeTimestamp()) .
WT_Gedcom_Tag::getLabelValue('_WT_USER', WT_Filter::escapeHtml($record->lastChangeUser()));
} else {
$details = '';
}
return
'
' .
WT_Gedcom_Tag::getLabel('CHAN') .
'
' .
'' .
WT_I18N::translate('Do not update the “last change” record') .
help_link('no_update_CHAN') .
$details .
'
';
} else {
return '';
}
}
/**
* Print a form to add an individual or edit an individual’s name
*
* @param string $nextaction
* @param WT_Individual $person
* @param WT_Family $family
* @param WT_Fact $name_fact
* @param string $famtag
* @param string $gender
*/
function print_indi_form($nextaction, WT_Individual $person = null, WT_Family $family = null, WT_Fact $name_fact = null, $famtag = 'CHIL', $gender = 'U') {
global $WT_TREE, $WORD_WRAPPED_NOTES, $NPFX_accept, $SHOW_GEDCOM_RECORD, $bdm, $STANDARD_NAME_FACTS, $ADVANCED_NAME_FACTS;
global $QUICK_REQUIRED_FACTS, $QUICK_REQUIRED_FAMFACTS, $controller;
$SURNAME_TRADITION = $WT_TREE->getPreference('SURNAME_TRADITION');
if ($person) {
$xref = $person->getXref();
} elseif ($family) {
$xref = $family->getXref();
} else {
$xref = 'new';
}
$name_fields = array();
if ($name_fact) {
$name_fact_id = $name_fact->getFactId();
$name_type = $name_fact->getAttribute('TYPE');
$namerec = $name_fact->getGedcom();
// Populate the standard NAME field and subfields
foreach ($STANDARD_NAME_FACTS as $tag) {
if ($tag == 'NAME') {
$name_fields[$tag] = $name_fact->getValue();
} else {
$name_fields[$tag] = $name_fact->getAttribute($tag);
}
}
} else {
$name_fact_id = null;
$name_type = null;
$namerec = null;
// Populate the standard NAME field and subfields
foreach ($STANDARD_NAME_FACTS as $tag) {
$name_fields[$tag] = '';
}
}
$bdm = ''; // used to copy '1 SOUR' to '2 SOUR' for BIRT DEAT MARR
echo '
';
echo '
', $controller->getPageTitle(), '
';
init_calendar_popup();
echo '';
$controller->addInlineJavascript('
SURNAME_TRADITION="'.$SURNAME_TRADITION . '";
gender="'.$gender . '";
famtag="'.$famtag . '";
function trim(str) {
str=str.replace(/\s\s+/g, " ");
return str.replace(/(^\s+)|(\s+$)/g, "");
}
function lang_class(str) {
if (str.match(/[\u0370-\u03FF]/)) return "greek";
if (str.match(/[\u0400-\u04FF]/)) return "cyrillic";
if (str.match(/[\u0590-\u05FF]/)) return "hebrew";
if (str.match(/[\u0600-\u06FF]/)) return "arabic";
return "latin"; // No matched text implies latin :-)
}
// Generate a full name from the name components
function generate_name() {
var npfx = jQuery("#NPFX").val();
var givn = jQuery("#GIVN").val();
var spfx = jQuery("#SPFX").val();
var surn = jQuery("#SURN").val();
var nsfx = jQuery("#NSFX").val();
if (SURNAME_TRADITION == "polish" && (gender == "F" || famtag == "WIFE")) {
surn = surn.replace(/ski$/, "ska");
surn = surn.replace(/cki$/, "cka");
surn = surn.replace(/dzki$/, "dzka");
surn = surn.replace(/żki$/, "żka");
}
// Commas are used in the GIVN and SURN field to separate lists of surnames.
// For example, to differentiate the two Spanish surnames from an English
// double-barred name.
// Commas *may* be used in other fields, and will form part of the NAME.
if (WT_LOCALE=="vi" || WT_LOCALE=="hu") {
// Default format: /SURN/ GIVN
return trim(npfx+" /"+trim(spfx+" "+surn).replace(/ *, */g, " ")+"/ "+givn.replace(/ *, */g, " ")+" "+nsfx);
} else if (WT_LOCALE=="zh") {
// Default format: /SURN/GIVN
return trim(npfx+" /"+trim(spfx+" "+surn).replace(/ *, */g, " ")+"/"+givn.replace(/ *, */g, " ")+" "+nsfx);
} else {
// Default format: GIVN /SURN/
return trim(npfx+" "+givn.replace(/ *, */g, " ")+" /"+trim(spfx+" "+surn).replace(/ *, */g, " ")+"/ "+nsfx);
}
}
// Update the NAME and _MARNM fields from the name components
// and also display the value in read-only "gedcom" format.
function updatewholename() {
// Don’t update the name if the user manually changed it
if (manualChange) {
return;
}
var npfx = jQuery("#NPFX").val();
var givn = jQuery("#GIVN").val();
var spfx = jQuery("#SPFX").val();
var surn = jQuery("#SURN").val();
var nsfx = jQuery("#NSFX").val();
var name = generate_name();
jQuery("#NAME").val(name);
jQuery("#NAME_display").text(name);
// Married names inherit some NSFX values, but not these
nsfx = nsfx.replace(/^(I|II|III|IV|V|VI|Junior|Jr\.?|Senior|Sr\.?)$/i, "");
// Update _MARNM field from _MARNM_SURN field and display it
// Be careful of mixing latin/hebrew/etc. character sets.
var ip = document.getElementsByTagName("input");
var marnm_id = "";
var romn = "";
var heb = "";
for (var i = 0; i < ip.length; i++) {
var val = trim(ip[i].value);
if (ip[i].id.indexOf("_HEB") === 0)
heb = val;
if (ip[i].id.indexOf("ROMN") === 0)
romn = val;
if (ip[i].id.indexOf("_MARNM") === 0) {
if (ip[i].id.indexOf("_MARNM_SURN") === 0) {
var msurn = "";
if (val != "") {
var lc = lang_class(document.getElementById(ip[i].id).value);
if (lang_class(name) === lc)
msurn = trim(npfx + " " + givn + " /" + val + "/ " + nsfx);
else if (lc == "hebrew")
msurn = heb.replace(/\/.*\//, "/" + val + "/");
else if (lang_class(romn) == lc)
msurn = romn.replace(/\/.*\//, "/" + val + "/");
}
document.getElementById(marnm_id).value = msurn;
document.getElementById(marnm_id+"_display").innerHTML = msurn;
} else {
marnm_id = ip[i].id;
}
}
}
}
// Toggle the name editor fields between
//
//
var oldName = "";
// Calls to generate_name() trigger an update - hence need to
// set the manual change to true first. We are probably
// listening to the wrong events on the input fields...
var manualChange = true;
manualChange = generate_name() !== jQuery("#NAME").val();
function convertHidden(eid) {
var input1 = jQuery("#" + eid);
var input2 = jQuery("#" + eid + "_display");
// Note that IE does not allow us to change the type of an input, so we must create a new one.
if (input1.attr("type")=="hidden") {
input1.replaceWith(input1.clone().attr("type", "text"));
input2.hide();
} else {
input1.replaceWith(input1.clone().attr("type", "hidden"));
input2.show();
}
}
/**
* if the user manually changed the NAME field, then update the textual
* HTML representation of it
* If the value changed set manualChange to true so that changing
* the other fields doesn’t change the NAME line
*/
function updateTextName(eid) {
var element = document.getElementById(eid);
if (element) {
if (element.value!=oldName) manualChange = true;
var delement = document.getElementById(eid+"_display");
if (delement) {
delement.innerHTML = element.value;
}
}
}
function checkform() {
var ip=document.getElementsByTagName("input");
for (var i=0; i';
}
/**
* Can we edit a WT_GedcomRecord object
*
* @param WT_GedcomRecord $object
*/
function check_record_access(WT_GedcomRecord $object = null) {
global $controller;
if (!$object || !$object->canShow() || !$object->canEdit()) {
$controller
->pageHeader()
->addInlineJavascript('closePopupAndReloadParent();');
exit;
}
}