/** * creates the form for editing the fact within the given gedcom record at the * given line number * @param string $gedrec the level 0 gedcom record * @param int $linenum the line number of the fact to edit within $gedrec * @param string $level0type the type of the level 0 gedcom record */ function create_edit_form($gedrec, $linenum, $level0type) { global $WORD_WRAPPED_NOTES, $pgv_lang, $factarray; global $pid, $tags, $ADVANCED_PLAC_FACTS, $date_and_time, $templefacts; global $lang_short_cut, $LANGUAGE, $FULL_SOURCES, $TEXT_DIRECTION; // global $TEXT_DIRECTION, $TBLPREFIX, $DBHOST, $DBUSER, $DBPASS, $DBNAME, $SERVER_URL; $tags = array(); $gedlines = split("\n", $gedrec); // -- find the number of lines in the record if (!isset($gedlines[$linenum])) { echo "<span class=\"error\">" . $pgv_lang["edit_concurrency_msg1"] . "<br /><br />"; echo $pgv_lang["edit_concurrency_reload"] . "</span>"; return; } $fields = explode(' ', $gedlines[$linenum]); $glevel = $fields[0]; $level = $glevel; if ($level != 1 && eregi("/@.*/@", trim($fields[1]))) { echo "<span class=\"error\">" . $pgv_lang["edit_concurrency_msg1"] . "<br /><br />"; echo $pgv_lang["edit_concurrency_reload"] . "</span>"; return; } $type = trim($fields[1]); $level1type = $type; // GEDFact_assistant ================================================ if ($type == "CENS" && file_exists('modules/GEDFact_assistant/_CENS/census_query_2a.php')) { include 'modules/GEDFact_assistant/_CENS/census_query_2a.php'; } // ================================================================== if (count($fields) > 2) { $ct = preg_match("/@.*@/", $fields[2]); $levellink = $ct > 0; } else { $levellink = false; } $i = $linenum; $inSource = false; $levelSource = 0; $add_date = true; // List of tags we would expect at the next level // NB add_missing_subtags() already takes care of the simple cases // where a level 1 tag is missing a level 2 tag. Here we only need to // handle the more complicated cases. $expected_subtags = array('SOUR' => array('PAGE', 'DATA'), 'DATA' => array('TEXT'), 'PLAC' => array('MAP'), 'MAP' => array('LATI', 'LONG')); if ($FULL_SOURCES) { $expected_subtags['SOUR'][] = 'QUAY'; $expected_subtags['DATA'][] = 'DATE'; } if (preg_match_all('/(' . PGV_REGEX_TAG . ')/', $ADVANCED_PLAC_FACTS, $match)) { $expected_subtags['PLAC'] = array_merge($match[1], $expected_subtags['PLAC']); } $stack = array(0 => $level0type); // Loop on existing tags : while (true) { // Keep track of our hierarchy, e.g. 1=>BIRT, 2=>PLAC, 3=>FONE $stack[(int) $level] = $type; // Merge them together, e.g. BIRT:PLAC:FONE $label = implode(':', array_slice($stack, 1, $level)); $text = ""; for ($j = 2; $j < count($fields); $j++) { if ($j > 2) { $text .= " "; } $text .= $fields[$j]; } $text = rtrim($text); while ($i + 1 < count($gedlines) && preg_match("/" . ($level + 1) . " CONT ?(.*)/", $gedlines[$i + 1], $cmatch) > 0) { $text .= "\n" . $cmatch[1]; $i++; } // Shared Note ------------- //if (eregi("@N.*@", $type)) { // $type="note"; //} if ($type == "SOUR") { $inSource = true; $levelSource = $level; } elseif ($levelSource >= $level) { $inSource = false; } if ($type != "DATA" && $type != "CONT") { $tags[] = $type; if ($type == 'DATE') { // Allow the user to edit the date in his/her own natural language $conversion_function = "gedcom_to_edit_date_{$lang_short_cut[$LANGUAGE]}"; if (function_exists($conversion_function)) { $text = $conversion_function($text); } else { $text = default_gedcom_to_edit_date($text); } } if ($type == "_AKAN" || $type == "_AKA" || $type == "ALIA") { // Allow special processing for different languages $func = "fact_AKA_localisation_{$lang_short_cut[$LANGUAGE]}"; if (function_exists($func)) { // Localise the AKA fact $func($type, $pid); } } $subrecord = $level . " " . $type . " " . $text; if ($inSource && $type == "DATE") { add_simple_tag($subrecord, "", fact_label($label)); } elseif (!$inSource && $type == "DATE") { add_simple_tag($subrecord, $level1type, fact_label($label)); $add_date = false; } else { add_simple_tag($subrecord, $level0type, fact_label($label)); } } // Get a list of tags present at the next level $subtags = array(); for ($ii = $i + 1; isset($gedlines[$ii]) && preg_match('/^\\s*(\\d+)\\s+(\\S+)/', $gedlines[$ii], $mm) && $mm[1] > $level; ++$ii) { if ($mm[1] == $level + 1) { $subtags[] = $mm[2]; } } // Insert missing tags if (!empty($expected_subtags[$type])) { foreach ($expected_subtags[$type] as $subtag) { if (!in_array($subtag, $subtags)) { if (!$inSource || $subtag != "DATA") { add_simple_tag($level + 1 . ' ' . $subtag, '', fact_label("{$label}:{$subtag}")); } if (!empty($expected_subtags[$subtag])) { foreach ($expected_subtags[$subtag] as $subsubtag) { add_simple_tag($level + 2 . ' ' . $subsubtag, '', fact_label("{$label}:{$subtag}:{$subsubtag}")); } } } } } // Awkward special cases if ($level == 2 && $type == 'DATE' && in_array($level1type, $date_and_time) && !in_array('TIME', $subtags)) { add_simple_tag("3 TIME"); // TIME is NOT a valid 5.5.1 tag } if ($level == 2 && $type == 'STAT' && in_array($level1type, $templefacts) && !in_array('DATE', $subtags)) { add_simple_tag("3 DATE", "", $factarray['STAT:DATE']); } $i++; if (isset($gedlines[$i])) { $fields = explode(' ', $gedlines[$i]); $level = $fields[0]; if (isset($fields[1])) { $type = trim($fields[1]); } else { $level = 0; } } else { $level = 0; } if ($level <= $glevel) { break; } } insert_missing_subtags($level1type, $add_date); return $level1type; }
function create_edit_form(WT_GedcomRecord $record, WT_Fact $fact) { global $ADVANCED_PLAC_FACTS, $date_and_time, $FULL_SOURCES, $tags; $pid = $record->getXref(); $tags = array(); $gedlines = explode("\n", $fact->getGedcom()); $linenum = 0; $fields = explode(' ', $gedlines[$linenum]); $glevel = $fields[0]; $level = $glevel; $type = $fact->getTag(); $parent = $fact->getParent(); $level0type = $parent::RECORD_TYPE; $level1type = $type; $i = $linenum; $inSource = false; $levelSource = 0; $add_date = true; // List of tags we would expect at the next level // NB add_missing_subtags() already takes care of the simple cases // where a level 1 tag is missing a level 2 tag. Here we only need to // handle the more complicated cases. $expected_subtags = array('SOUR' => array('PAGE', 'DATA'), 'DATA' => array('TEXT'), 'PLAC' => array('MAP'), 'MAP' => array('LATI', 'LONG')); if ($FULL_SOURCES) { $expected_subtags['SOUR'][] = 'QUAY'; $expected_subtags['DATA'][] = 'DATE'; } if (preg_match_all('/(' . WT_REGEX_TAG . ')/', $ADVANCED_PLAC_FACTS, $match)) { $expected_subtags['PLAC'] = array_merge($match[1], $expected_subtags['PLAC']); } $stack = array(0 => $level0type); // Loop on existing tags : while (true) { // Keep track of our hierarchy, e.g. 1=>BIRT, 2=>PLAC, 3=>FONE $stack[(int) $level] = $type; // Merge them together, e.g. BIRT:PLAC:FONE $label = implode(':', array_slice($stack, 1, $level)); $text = ''; for ($j = 2; $j < count($fields); $j++) { if ($j > 2) { $text .= ' '; } $text .= $fields[$j]; } $text = rtrim($text); while ($i + 1 < count($gedlines) && preg_match("/" . ($level + 1) . " CONT ?(.*)/", $gedlines[$i + 1], $cmatch) > 0) { $text .= "\n" . $cmatch[1]; $i++; } if ($type == "SOUR") { $inSource = true; $levelSource = $level; } elseif ($levelSource >= $level) { $inSource = false; } if ($type != "DATA" && $type != "CONT") { $tags[] = $type; $person = WT_Individual::getInstance($pid); $subrecord = $level . ' ' . $type . ' ' . $text; if ($inSource && $type == "DATE") { add_simple_tag($subrecord, '', WT_Gedcom_Tag::getLabel($label, $person)); } elseif (!$inSource && $type == "DATE") { add_simple_tag($subrecord, $level1type, WT_Gedcom_Tag::getLabel($label, $person)); $add_date = false; } elseif ($type == 'STAT') { add_simple_tag($subrecord, $level1type, WT_Gedcom_Tag::getLabel($label, $person)); } elseif ($level0type == 'REPO') { $repo = WT_Repository::getInstance($pid); add_simple_tag($subrecord, $level0type, WT_Gedcom_Tag::getLabel($label, $repo)); } else { add_simple_tag($subrecord, $level0type, WT_Gedcom_Tag::getLabel($label, $person)); } } // Get a list of tags present at the next level $subtags = array(); for ($ii = $i + 1; isset($gedlines[$ii]) && preg_match('/^\\s*(\\d+)\\s+(\\S+)/', $gedlines[$ii], $mm) && $mm[1] > $level; ++$ii) { if ($mm[1] == $level + 1) { $subtags[] = $mm[2]; } } // Insert missing tags if (!empty($expected_subtags[$type])) { foreach ($expected_subtags[$type] as $subtag) { if (!in_array($subtag, $subtags)) { if (!$inSource || $subtag != "DATA") { add_simple_tag($level + 1 . ' ' . $subtag, '', WT_Gedcom_Tag::getLabel("{$label}:{$subtag}")); } if (!empty($expected_subtags[$subtag])) { foreach ($expected_subtags[$subtag] as $subsubtag) { add_simple_tag($level + 2 . ' ' . $subsubtag, '', WT_Gedcom_Tag::getLabel("{$label}:{$subtag}:{$subsubtag}")); } } } } } // Awkward special cases if ($level == 2 && $type == 'DATE' && in_array($level1type, $date_and_time) && !in_array('TIME', $subtags)) { add_simple_tag("3 TIME"); // TIME is NOT a valid 5.5.1 tag } if ($level == 2 && $type == 'STAT' && WT_Gedcom_Code_Temp::isTagLDS($level1type) && !in_array('DATE', $subtags)) { add_simple_tag("3 DATE", '', WT_Gedcom_Tag::getLabel('STAT:DATE')); } $i++; if (isset($gedlines[$i])) { $fields = explode(' ', $gedlines[$i]); $level = $fields[0]; if (isset($fields[1])) { $type = trim($fields[1]); } else { $level = 0; } } else { $level = 0; } if ($level <= $glevel) { break; } } if ($level1type != '_PRIM') { insert_missing_subtags($level1type, $add_date); } return $level1type; }