.
*/
/**
* Class CensusAssistantModule
*/
class CensusAssistantModule extends Module {
/** {@inheritdoc} */
public function getTitle() {
return /* I18N: Name of a module */ I18N::translate('Census assistant');
}
/** {@inheritdoc} */
public function getDescription() {
return /* I18N: Description of the “Census assistant” module */ I18N::translate('An alternative way to enter census transcripts and link them to individuals.');
}
/** {@inheritdoc} */
public function modAction($mod_action) {
switch ($mod_action) {
case '_CENS/census_3_find':
// TODO: this file should be a method in this class
require WT_ROOT . WT_MODULES_DIR . $this->getName() . '/_CENS/census_3_find.php';
break;
case 'media_3_find':
self::mediaFind();
break;
case 'media_query_3a':
self::mediaQuery();
break;
default:
echo $mod_action;
http_response_code(404);
}
}
/**
* ...
*/
private static function mediaFind() {
global $WT_TREE;
$controller = new SimpleController;
$filter = Filter::get('filter');
$multiple = Filter::getBool('multiple');
$controller
->setPageTitle(I18N::translate('Find an individual'))
->pageHeader();
echo '';
echo "
";
echo "
";
echo ""; // start column for find text header
echo $controller->getPageTitle();
echo " ";
echo " ";
echo "
";
echo "
";
echo '
', I18N::translate('close'), ' ';
echo "
";
$filter = trim($filter);
$filter_array = explode(' ', preg_replace('/ {2,}/', ' ', $filter));
echo "
";
$myindilist = search_indis_names($filter_array, $WT_TREE);
if ($myindilist) {
echo "";
usort($myindilist, __NAMESPACE__ . '\GedcomRecord::compare');
foreach ($myindilist as $indi) {
$nam = Filter::escapeHtml($indi->getFullName());
echo "getXref() . "' ,
'".$nam . "' ,
'".$indi->getSex() . "' ,
'".$indi->getbirthyear() . "' ,
'".(1901 - $indi->getbirthyear()) . "' ,
'".$indi->getbirthplace() . "'); return false;\">
".$indi->getFullName() . " ";
$born = GedcomTag::getLabel('BIRT');
echo "", $born, " ", $indi->getbirthyear(), " ", $indi->getbirthplace(), " ";
echo " ";
}
echo ' ', I18N::translate('Total individuals: %s', count($myindilist)), ' ';
} else {
echo "";
echo I18N::translate('No results found.');
echo " ";
}
echo "
";
echo '
';
}
/**
* ...
*/
private static function mediaQuery() {
$iid2 = Filter::get('iid', WT_REGEX_XREF);
$controller = new SimpleController;
$controller
->setPageTitle(I18N::translate('Link to an existing media object'))
->pageHeader();
$record = GedcomRecord::getInstance($iid2);
if ($record) {
$headjs = '';
if ($record instanceof Family) {
if ($record->getHusband()) {
$headjs = $record->getHusband()->getXref();
} elseif ($record->getWife()) {
$headjs = $record->getWife()->getXref();
}
}
?>
'Age at first marriage',
'Age' => 'Age at last birthday',
'Assets' => 'Assets = Owned,Rented - Value,Rent - Radio - Farm',
'BIC' => 'Born in County',
'BOE' => 'Born outside England',
'BP' => 'Birthplace - (Chapman format)',
'Birthplace' => 'Birthplace (Full format)',
'Bmth' => 'Month of birth - If born within Census year',
'ChB' => 'Children born alive',
'ChD' => 'Children who have died',
'ChL' => 'Children still living',
'DOB' => 'Date of birth',
'Edu' => 'Education - At School, Can Read, Can Write', // or "Cannot Read, Cannot Write" ??
'EmD' => 'Employed?',
'EmN' => 'Unemployed?',
'EmR' => 'Employer?',
'Employ' => 'Employment',
'Eng?' => 'English spoken?',
'EngL' => 'English spoken?, if not, Native Language',
'FBP' => 'Father’s Birthplace - (Chapman format)',
'Health' => 'Health - 1.Blind, 2.Deaf & Dumb, 3.Idiotic, 4.Insane, 5.Disabled etc',
'Home' => 'Home Ownership - Owned/Rented-Free/Mortgaged-Farm/House-Farm Schedule number',
'Industry' => 'Industry',
'Infirm' => 'Infirmities - 1. Deaf & Dumb, 2. Blind, 3. Lunatic, 4. Imbecile/feeble-minded',
'Lang' => 'If Foreign Born - Native Language',
'MBP' => 'Mother’s Birthplace - (Chapman format)',
'MC' => 'Marital Condition - Married, Single, Unmarried, Widowed or Divorced',
'Mmth' => 'Month of marriage - If married during Census Year',
'MnsE' => 'Months employed during Census Year',
'MnsU' => 'Months unemployed during Census Year',
'N/A' => 'If Foreign Born - Naturalized, Alien',
'NL' => 'If Foreign Born - Native Language',
'Name' => 'Full Name or Married name if married',
'Occupation' => 'Occupation',
'Par' => 'Parentage - Father if foreign born, Mother if foreign born',
'Race' => 'Race or Color - Black, White, Mulatto, Asian, Indian, Chinese etc',
'Relation' => 'Relationship to Head of Household',
'Sex' => 'Male or Female',
'Situ' => 'Situation - Disease, Infirmity, Convict, Pauper etc',
'Ten' => 'Tenure - Owned/Rented, (if owned)Free/Morgaged',
'Vet' => 'War Veteran?',
'WH' => 'Working at Home?',
'War' => 'War or Expedition',
'WksU' => 'Weeks unemployed during Census Year',
'YOI' => 'If Foreign Born - Year of immigration',
'YON' => 'If Foreign Born - Year of naturalization',
'YUS' => 'If Foreign Born - Years in the USA',
'YrsM' => 'Years Married, or Y if married in Census Year',
);
if (preg_match('/(.*)((?:\n.*)*)\n\.start_formatted_area\.\n(.*)((?:\n.*)*)\n.end_formatted_area\.((?:\n.*)*)/', $note->getNote(), $match)) {
// This looks like a census-assistant shared note
$title = Filter::escapeHtml($match[1]);
$preamble = Filter::escapeHtml($match[2]);
$header = Filter::escapeHtml($match[3]);
$data = Filter::escapeHtml($match[4]);
$postamble = Filter::escapeHtml($match[5]);
$fmt_headers = array();
foreach ($headers as $key=>$value) {
$fmt_headers['.b.' . $key] = '' . $key . ' ';
}
// Substitue header labels and format as HTML
$thead = '' . strtr(str_replace('|', ' ', $header), $fmt_headers) . ' ';
// Format data as HTML
$tbody = '';
foreach (explode("\n", $data) as $row) {
$tbody .= '';
foreach (explode('|', $row) as $column) {
$tbody .= '' . $column . ' ';
}
$tbody .= ' ';
}
return
$title . "\n" . // The newline allows the framework to expand the details and turn the first line into a link
'' . $preamble . '
' .
'' .
'' . $thead . ' ' .
'' . $tbody . ' ' .
'
' .
'' . $postamble . '
';
} else {
// Not a census-assistant shared note - apply default formatting
return Filter::formatText($note->getNote(), $WT_TREE);
}
}
/**
* Modify the “add shared note” field, to create a note using the assistant
*
* @param string $element_id
* @param string $xref
* @param string $action
*
* @return string
*/
static function addNoteWithAssistantLink($element_id, $xref, $action) {
global $controller;
// We do not yet support family records
if (!GedcomRecord::getInstance($xref) instanceof Individual) {
return '';
}
// Only modify “add shared note” links on the add/edit actions.
// TODO: does the “edit” action work?
if ($action != 'add' && $action != 'edit') {
return '';
}
// There are lots of “add shared note” links. We only need to modify the 2nd one
static $n = 0;
if (++$n != 2) {
return '';
}
$controller->addInlineJavascript('
var pid_array=jQuery("#pid_array");
function set_pid_array(pa) {
pid_array.val(pa);
}
');
return
' ' .
' ' .
'' .
I18N::translate('Create a new shared note using assistant') .
' ';
}
/**
* Add a selector containing UK/US/FR census dates
*
* @param string $action
* @param string $tag
* @param string $element_id
*
* @return string
*/
public static function censusDateSelector($action, $tag, $element_id) {
global $controller;
if ($action == 'add' && $tag == 'CENS') {
$controller->addInlineJavascript('
function addDate(theCensDate) {
var ddate = theCensDate.split(", ");
document.getElementById("setctry").value = ddate[3];
document.getElementById("setyear").value = ddate[0];
cal_setDateField("' . $element_id . '", parseInt(ddate[0]), parseInt(ddate[1]), parseInt(ddate[2]));
return false;
}
function pasteAsstDate(setcy, setyr) {
document.getElementById(setcy+setyr).selected = true;
addDate(document.getElementById("selcensdate").options[document.getElementById(\'selcensdate\').selectedIndex].value);
return false;
}
');
return '
' . I18N::translate('Census date') . '
UK 1911
UK 1901
UK 1891
UK 1881
UK 1871
UK 1861
UK 1851
UK 1841
US 1940
US 1930
US 1920
US 1910
US 1900
US 1890
US 1880
US 1870
US 1860
US 1850
US 1840
US 1830
US 1820
US 1810
US 1800
US 1790
FR 1951
FR 1946
FR 1941
FR 1936
FR 1931
FR 1926
FR 1921
FR 1916
FR 1911
FR 1906
FR 1901
FR 1896
FR 1891
FR 1886
FR 1881
FR 1876
';
} else {
return '';
}
}
}