xref: /webtrees/app/Module/CensusAssistantModule.php (revision e00e91f6df22dda5b318106dd1564d8a7c061007)
18c2e8227SGreg Roach<?php
28c2e8227SGreg Roachnamespace Fisharebest\Webtrees;
38c2e8227SGreg Roach
48c2e8227SGreg Roach/**
58c2e8227SGreg Roach * webtrees: online genealogy
68c2e8227SGreg Roach * Copyright (C) 2015 webtrees development team
78c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify
88c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by
98c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or
108c2e8227SGreg Roach * (at your option) any later version.
118c2e8227SGreg Roach * This program is distributed in the hope that it will be useful,
128c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
138c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
148c2e8227SGreg Roach * GNU General Public License for more details.
158c2e8227SGreg Roach * You should have received a copy of the GNU General Public License
168c2e8227SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
178c2e8227SGreg Roach */
188c2e8227SGreg Roach
198c2e8227SGreg Roach/**
208c2e8227SGreg Roach * Class CensusAssistantModule
218c2e8227SGreg Roach */
228c2e8227SGreg Roachclass CensusAssistantModule extends Module {
238c2e8227SGreg Roach	/** {@inheritdoc} */
248c2e8227SGreg Roach	public function getTitle() {
258c2e8227SGreg Roach		return /* I18N: Name of a module */ I18N::translate('Census assistant');
268c2e8227SGreg Roach	}
278c2e8227SGreg Roach
288c2e8227SGreg Roach	/** {@inheritdoc} */
298c2e8227SGreg Roach	public function getDescription() {
308c2e8227SGreg Roach		return /* I18N: Description of the “Census assistant” module */ I18N::translate('An alternative way to enter census transcripts and link them to individuals.');
318c2e8227SGreg Roach	}
328c2e8227SGreg Roach
338c2e8227SGreg Roach	/** {@inheritdoc} */
348c2e8227SGreg Roach	public function modAction($mod_action) {
358c2e8227SGreg Roach		switch ($mod_action) {
368c2e8227SGreg Roach		case '_CENS/census_3_find':
378c2e8227SGreg Roach			// TODO: this file should be a method in this class
388c2e8227SGreg Roach			require WT_ROOT . WT_MODULES_DIR . $this->getName() . '/_CENS/census_3_find.php';
398c2e8227SGreg Roach			break;
408c2e8227SGreg Roach		case 'media_3_find':
41764a01d9SGreg Roach			self::mediaFind();
428c2e8227SGreg Roach			break;
438c2e8227SGreg Roach		case 'media_query_3a':
44764a01d9SGreg Roach			self::mediaQuery();
458c2e8227SGreg Roach			break;
468c2e8227SGreg Roach		default:
478c2e8227SGreg Roach			echo $mod_action;
488c2e8227SGreg Roach			http_response_code(404);
498c2e8227SGreg Roach		}
508c2e8227SGreg Roach	}
518c2e8227SGreg Roach
528c2e8227SGreg Roach	/**
538c2e8227SGreg Roach	 * ...
548c2e8227SGreg Roach	 */
55764a01d9SGreg Roach	private static function mediaFind() {
568c2e8227SGreg Roach		global $WT_TREE;
578c2e8227SGreg Roach
588c2e8227SGreg Roach		$controller = new SimpleController;
598c2e8227SGreg Roach		$filter     = Filter::get('filter');
608c2e8227SGreg Roach		$multiple   = Filter::getBool('multiple');
618c2e8227SGreg Roach
628c2e8227SGreg Roach		$controller
638c2e8227SGreg Roach			->setPageTitle(I18N::translate('Find an individual'))
648c2e8227SGreg Roach			->pageHeader();
658c2e8227SGreg Roach
668c2e8227SGreg Roach		echo '<script>';
678c2e8227SGreg Roach		?>
688c2e8227SGreg Roach
698c2e8227SGreg Roach			function pasterow(id, name, gend, yob, age, bpl) {
708c2e8227SGreg Roach				window.opener.opener.insertRowToTable(id, name, '', gend, '', yob, age, 'Y', '', bpl);
718c2e8227SGreg Roach			}
728c2e8227SGreg Roach
738c2e8227SGreg Roach			function pasteid(id, name, thumb) {
748c2e8227SGreg Roach				if (thumb) {
758c2e8227SGreg Roach					window.opener.paste_id(id, name, thumb);
768c2e8227SGreg Roach					<?php if (!$multiple) echo "window.close();"; ?>
778c2e8227SGreg Roach				} else {
788c2e8227SGreg Roach					// GEDFact_assistant ========================
798c2e8227SGreg Roach					if (window.opener.document.getElementById('addlinkQueue')) {
808c2e8227SGreg Roach						window.opener.insertRowToTable(id, name);
818c2e8227SGreg Roach					}
828c2e8227SGreg Roach					window.opener.paste_id(id);
838c2e8227SGreg Roach					if (window.opener.pastename) {
848c2e8227SGreg Roach						window.opener.pastename(name);
858c2e8227SGreg Roach					}
868c2e8227SGreg Roach					<?php if (!$multiple) echo "window.close();"; ?>
878c2e8227SGreg Roach				}
888c2e8227SGreg Roach			}
898c2e8227SGreg Roach			function checknames(frm) {
908c2e8227SGreg Roach				if (document.forms[0].subclick) {
918c2e8227SGreg Roach					button = document.forms[0].subclick.value;
928c2e8227SGreg Roach				} else {
938c2e8227SGreg Roach					button = "";
948c2e8227SGreg Roach				}
958c2e8227SGreg Roach				if (frm.filter.value.length<2&button!="all") {
9677e70a22SGreg Roach					alert("<?php echo I18N::translate('Please enter more than one character.'); ?>");
978c2e8227SGreg Roach					frm.filter.focus();
988c2e8227SGreg Roach					return false;
998c2e8227SGreg Roach				}
1008c2e8227SGreg Roach				if (button=="all") {
1018c2e8227SGreg Roach					frm.filter.value = "";
1028c2e8227SGreg Roach				}
1038c2e8227SGreg Roach				return true;
1048c2e8227SGreg Roach			}
1058c2e8227SGreg Roach		<?php
1068c2e8227SGreg Roach		echo '</script>';
1078c2e8227SGreg Roach
1088c2e8227SGreg Roach		echo "<div align=\"center\">";
1098c2e8227SGreg Roach		echo "<table class=\"list_table width90\" border=\"0\">";
1108c2e8227SGreg Roach		echo "<tr><td style=\"padding: 10px;\" valign=\"top\" class=\"facts_label03 width90\">"; // start column for find text header
1118c2e8227SGreg Roach		echo $controller->getPageTitle();
1128c2e8227SGreg Roach		echo "</td>";
1138c2e8227SGreg Roach		echo "</tr>";
1148c2e8227SGreg Roach		echo "</table>";
1158c2e8227SGreg Roach		echo "<br>";
1168c2e8227SGreg Roach		echo '<button onclick="window.close();">', I18N::translate('close'), '</button>';
1178c2e8227SGreg Roach		echo "<br>";
1188c2e8227SGreg Roach
1198c2e8227SGreg Roach		$filter = trim($filter);
1208c2e8227SGreg Roach		$filter_array = explode(' ', preg_replace('/ {2,}/', ' ', $filter));
1218c2e8227SGreg Roach		echo "<table class=\"tabs_table width90\"><tr>";
122*e00e91f6SGreg Roach		$myindilist = search_indis_names($filter_array, array($WT_TREE));
1238c2e8227SGreg Roach		if ($myindilist) {
1248c2e8227SGreg Roach			echo "<td class=\"list_value_wrap\"><ul>";
1258c2e8227SGreg Roach			usort($myindilist, __NAMESPACE__ . '\GedcomRecord::compare');
1268c2e8227SGreg Roach			foreach ($myindilist as $indi) {
1278c2e8227SGreg Roach				$nam = Filter::escapeHtml($indi->getFullName());
1288c2e8227SGreg Roach				echo "<li><a href=\"#\" onclick=\"pasterow(
1298c2e8227SGreg Roach					'".$indi->getXref() . "' ,
1308c2e8227SGreg Roach					'".$nam . "' ,
1318c2e8227SGreg Roach					'".$indi->getSex() . "' ,
1328c2e8227SGreg Roach					'".$indi->getbirthyear() . "' ,
1338c2e8227SGreg Roach					'".(1901 - $indi->getbirthyear()) . "' ,
1348c2e8227SGreg Roach					'".$indi->getbirthplace() . "'); return false;\">
1358c2e8227SGreg Roach					<b>".$indi->getFullName() . "</b>&nbsp;&nbsp;&nbsp;";
1368c2e8227SGreg Roach
137764a01d9SGreg Roach				$born = GedcomTag::getLabel('BIRT');
1388c2e8227SGreg Roach				echo "</span><br><span class=\"list_item\">", $born, " ", $indi->getbirthyear(), "&nbsp;&nbsp;&nbsp;", $indi->getbirthplace(), "</span></a></li>";
1398c2e8227SGreg Roach			echo "<hr>";
1408c2e8227SGreg Roach			}
1418c2e8227SGreg Roach			echo '</ul></td></tr><tr><td class="list_label">', I18N::translate('Total individuals: %s', count($myindilist)), '</tr></td>';
1428c2e8227SGreg Roach		} else {
1438c2e8227SGreg Roach			echo "<td class=\"list_value_wrap\">";
1448c2e8227SGreg Roach			echo I18N::translate('No results found.');
1458c2e8227SGreg Roach			echo "</td></tr>";
1468c2e8227SGreg Roach		}
1478c2e8227SGreg Roach		echo "</table>";
1488c2e8227SGreg Roach		echo '</div>';
1498c2e8227SGreg Roach	}
1508c2e8227SGreg Roach
1518c2e8227SGreg Roach	/**
1528c2e8227SGreg Roach	 * ...
1538c2e8227SGreg Roach	 */
154764a01d9SGreg Roach	private static function mediaQuery() {
15524ec66ceSGreg Roach		global $WT_TREE;
15624ec66ceSGreg Roach
1578c2e8227SGreg Roach		$iid2 = Filter::get('iid', WT_REGEX_XREF);
1588c2e8227SGreg Roach
1598c2e8227SGreg Roach		$controller = new SimpleController;
1608c2e8227SGreg Roach		$controller
1618c2e8227SGreg Roach			->setPageTitle(I18N::translate('Link to an existing media object'))
1628c2e8227SGreg Roach			->pageHeader();
1638c2e8227SGreg Roach
16424ec66ceSGreg Roach		$record = GedcomRecord::getInstance($iid2, $WT_TREE);
1658c2e8227SGreg Roach		if ($record) {
1668c2e8227SGreg Roach			$headjs = '';
1678c2e8227SGreg Roach			if ($record instanceof Family) {
1688c2e8227SGreg Roach				if ($record->getHusband()) {
1698c2e8227SGreg Roach					$headjs = $record->getHusband()->getXref();
1708c2e8227SGreg Roach				} elseif ($record->getWife()) {
1718c2e8227SGreg Roach					$headjs = $record->getWife()->getXref();
1728c2e8227SGreg Roach				}
1738c2e8227SGreg Roach			}
1748c2e8227SGreg Roach			?>
1758c2e8227SGreg Roach			<script>
1768c2e8227SGreg Roach			function insertId() {
1778c2e8227SGreg Roach				if (window.opener.document.getElementById('addlinkQueue')) {
1788c2e8227SGreg Roach					// alert('Please move this alert window and examine the contents of the pop-up window, then click OK')
1798c2e8227SGreg Roach					window.opener.insertRowToTable('<?php echo $record->getXref(); ?>', '<?php echo htmlSpecialChars($record->getFullName()); ?>', '<?php echo $headjs; ?>');
1808c2e8227SGreg Roach					window.close();
1818c2e8227SGreg Roach				}
1828c2e8227SGreg Roach			}
1838c2e8227SGreg Roach			</script>
1848c2e8227SGreg Roach			<?php
1858c2e8227SGreg Roach
1868c2e8227SGreg Roach		} else {
1878c2e8227SGreg Roach			?>
1888c2e8227SGreg Roach			<script>
1898c2e8227SGreg Roach			function insertId() {
19077e70a22SGreg Roach				window.opener.alert('<?php echo $iid2; ?> - <?php echo I18N::translate('Not a valid individual, family, or source ID'); ?>');
1918c2e8227SGreg Roach				window.close();
1928c2e8227SGreg Roach			}
1938c2e8227SGreg Roach			</script>
1948c2e8227SGreg Roach			<?php
1958c2e8227SGreg Roach		}
1968c2e8227SGreg Roach		?>
1978c2e8227SGreg Roach		<script>window.onLoad = insertId();</script>
1988c2e8227SGreg Roach		<?php
1998c2e8227SGreg Roach	}
2008c2e8227SGreg Roach
2018c2e8227SGreg Roach	/**
2028c2e8227SGreg Roach	 * Convert custom markup into HTML
2038c2e8227SGreg Roach	 *
2048c2e8227SGreg Roach	 * @param Note $note
2058c2e8227SGreg Roach	 *
2068c2e8227SGreg Roach	 * @return string
2078c2e8227SGreg Roach	 */
2088c2e8227SGreg Roach	public static function formatCensusNote(Note $note) {
2098c2e8227SGreg Roach		global $WT_TREE;
2108c2e8227SGreg Roach
2118c2e8227SGreg Roach		$headers = array(
2128c2e8227SGreg Roach			'AgM'        => 'Age at first marriage',
2138c2e8227SGreg Roach			'Age'        => 'Age at last birthday',
2148c2e8227SGreg Roach			'Assets'     => 'Assets = Owned,Rented - Value,Rent - Radio - Farm',
2158c2e8227SGreg Roach			'BIC'        => 'Born in County',
2168c2e8227SGreg Roach			'BOE'        => 'Born outside England',
2178c2e8227SGreg Roach			'BP'         => 'Birthplace - (Chapman format)',
2188c2e8227SGreg Roach			'Birthplace' => 'Birthplace (Full format)',
2198c2e8227SGreg Roach			'Bmth'       => 'Month of birth - If born within Census year',
2208c2e8227SGreg Roach			'ChB'        => 'Children born alive',
2218c2e8227SGreg Roach			'ChD'        => 'Children who have died',
2228c2e8227SGreg Roach			'ChL'        => 'Children still living',
2238c2e8227SGreg Roach			'DOB'        => 'Date of birth',
2248c2e8227SGreg Roach			'Edu'        => 'Education - At School, Can Read, Can Write', // or "Cannot Read, Cannot Write" ??
2258c2e8227SGreg Roach			'EmD'        => 'Employed?',
2268c2e8227SGreg Roach			'EmN'        => 'Unemployed?',
2278c2e8227SGreg Roach			'EmR'        => 'Employer?',
2288c2e8227SGreg Roach			'Employ'     => 'Employment',
2298c2e8227SGreg Roach			'Eng?'       => 'English spoken?',
2308c2e8227SGreg Roach			'EngL'       => 'English spoken?, if not, Native Language',
2318c2e8227SGreg Roach			'FBP'        => 'Father’s Birthplace - (Chapman format)',
2328c2e8227SGreg Roach			'Health'     => 'Health - 1.Blind, 2.Deaf & Dumb, 3.Idiotic, 4.Insane, 5.Disabled etc',
2338c2e8227SGreg Roach			'Home'       => 'Home Ownership - Owned/Rented-Free/Mortgaged-Farm/House-Farm Schedule number',
2348c2e8227SGreg Roach			'Industry'   => 'Industry',
2358c2e8227SGreg Roach			'Infirm'     => 'Infirmities - 1. Deaf & Dumb, 2. Blind, 3. Lunatic, 4. Imbecile/feeble-minded',
2368c2e8227SGreg Roach			'Lang'       => 'If Foreign Born - Native Language',
2378c2e8227SGreg Roach			'MBP'        => 'Mother’s Birthplace - (Chapman format)',
2388c2e8227SGreg Roach			'MC'         => 'Marital Condition - Married, Single, Unmarried, Widowed or Divorced',
2398c2e8227SGreg Roach			'Mmth'       => 'Month of marriage - If married during Census Year',
2408c2e8227SGreg Roach			'MnsE'       => 'Months employed during Census Year',
2418c2e8227SGreg Roach			'MnsU'       => 'Months unemployed during Census Year',
2428c2e8227SGreg Roach			'N/A'        => 'If Foreign Born - Naturalized, Alien',
2438c2e8227SGreg Roach			'NL'         => 'If Foreign Born - Native Language',
2448c2e8227SGreg Roach			'Name'       => 'Full Name or Married name if married',
2458c2e8227SGreg Roach			'Occupation' => 'Occupation',
2468c2e8227SGreg Roach			'Par'        => 'Parentage - Father if foreign born, Mother if foreign born',
2478c2e8227SGreg Roach			'Race'       => 'Race or Color - Black, White, Mulatto, Asian, Indian, Chinese etc',
2488c2e8227SGreg Roach			'Relation'   => 'Relationship to Head of Household',
2498c2e8227SGreg Roach			'Sex'        => 'Male or Female',
2508c2e8227SGreg Roach			'Situ'       => 'Situation - Disease, Infirmity, Convict, Pauper etc',
2518c2e8227SGreg Roach			'Ten'        => 'Tenure - Owned/Rented, (if owned)Free/Morgaged',
2528c2e8227SGreg Roach			'Vet'        => 'War Veteran?',
2538c2e8227SGreg Roach			'WH'         => 'Working at Home?',
2548c2e8227SGreg Roach			'War'        => 'War or Expedition',
2558c2e8227SGreg Roach			'WksU'       => 'Weeks unemployed during Census Year',
2568c2e8227SGreg Roach			'YOI'        => 'If Foreign Born - Year of immigration',
2578c2e8227SGreg Roach			'YON'        => 'If Foreign Born - Year of naturalization',
2588c2e8227SGreg Roach			'YUS'        => 'If Foreign Born - Years in the USA',
2598c2e8227SGreg Roach			'YrsM'       => 'Years Married, or Y if married in Census Year',
2608c2e8227SGreg Roach		);
2618c2e8227SGreg Roach
2628c2e8227SGreg Roach		if (preg_match('/(.*)((?:\n.*)*)\n\.start_formatted_area\.\n(.*)((?:\n.*)*)\n.end_formatted_area\.((?:\n.*)*)/', $note->getNote(), $match)) {
2638c2e8227SGreg Roach			// This looks like a census-assistant shared note
2648c2e8227SGreg Roach			$title     = Filter::escapeHtml($match[1]);
2658c2e8227SGreg Roach			$preamble  = Filter::escapeHtml($match[2]);
2668c2e8227SGreg Roach			$header    = Filter::escapeHtml($match[3]);
2678c2e8227SGreg Roach			$data      = Filter::escapeHtml($match[4]);
2688c2e8227SGreg Roach			$postamble = Filter::escapeHtml($match[5]);
2698c2e8227SGreg Roach
2708c2e8227SGreg Roach			$fmt_headers = array();
2718c2e8227SGreg Roach			foreach ($headers as $key=>$value) {
2728c2e8227SGreg Roach				$fmt_headers['.b.' . $key] = '<span title="' . Filter::escapeHtml($value) . '">' . $key . '</span>';
2738c2e8227SGreg Roach			}
2748c2e8227SGreg Roach
2758c2e8227SGreg Roach			// Substitue header labels and format as HTML
2768c2e8227SGreg Roach			$thead = '<tr><th>' . strtr(str_replace('|', '</th><th>', $header), $fmt_headers) . '</th></tr>';
2778c2e8227SGreg Roach
2788c2e8227SGreg Roach			// Format data as HTML
2798c2e8227SGreg Roach			$tbody = '';
2808c2e8227SGreg Roach			foreach (explode("\n", $data) as $row) {
2818c2e8227SGreg Roach				$tbody .= '<tr>';
2828c2e8227SGreg Roach				foreach (explode('|', $row) as $column) {
2838c2e8227SGreg Roach					$tbody .= '<td>' . $column . '</td>';
2848c2e8227SGreg Roach				}
2858c2e8227SGreg Roach				$tbody .= '</tr>';
2868c2e8227SGreg Roach			}
2878c2e8227SGreg Roach
2888c2e8227SGreg Roach			return
2898c2e8227SGreg Roach				$title . "\n" . // The newline allows the framework to expand the details and turn the first line into a link
2908c2e8227SGreg Roach				'<p>' . $preamble . '</p>' .
2918c2e8227SGreg Roach				'<table class="table-census-assistant">' .
2928c2e8227SGreg Roach				'<thead>' . $thead . '</thead>' .
2938c2e8227SGreg Roach				'<tbody>' . $tbody . '</tbody>' .
2948c2e8227SGreg Roach				'</table>' .
2958c2e8227SGreg Roach				'<p>' . $postamble . '</p>';
2968c2e8227SGreg Roach		} else {
2978c2e8227SGreg Roach			// Not a census-assistant shared note - apply default formatting
2988c2e8227SGreg Roach			return Filter::formatText($note->getNote(), $WT_TREE);
2998c2e8227SGreg Roach		}
3008c2e8227SGreg Roach	}
3018c2e8227SGreg Roach
3028c2e8227SGreg Roach	/**
3038c2e8227SGreg Roach	 * Modify the “add shared note” field, to create a note using the assistant
3048c2e8227SGreg Roach	 *
3058c2e8227SGreg Roach	 * @param string $element_id
3068c2e8227SGreg Roach	 * @param string $xref
3078c2e8227SGreg Roach	 * @param string $action
3088c2e8227SGreg Roach	 *
3098c2e8227SGreg Roach	 * @return string
3108c2e8227SGreg Roach	 */
311764a01d9SGreg Roach	static function addNoteWithAssistantLink($element_id, $xref, $action) {
31224ec66ceSGreg Roach		global $controller, $WT_TREE;
3138c2e8227SGreg Roach
3148c2e8227SGreg Roach		// We do not yet support family records
31524ec66ceSGreg Roach		if (!GedcomRecord::getInstance($xref, $WT_TREE) instanceof Individual) {
3168c2e8227SGreg Roach			return '';
3178c2e8227SGreg Roach		}
3188c2e8227SGreg Roach
3198c2e8227SGreg Roach		// Only modify “add shared note” links on the add/edit actions.
3208c2e8227SGreg Roach		// TODO: does the “edit” action work?
3218c2e8227SGreg Roach		if ($action != 'add' && $action != 'edit') {
3228c2e8227SGreg Roach			return '';
3238c2e8227SGreg Roach		}
3248c2e8227SGreg Roach
3258c2e8227SGreg Roach		// There are lots of “add shared note” links.  We only need to modify the 2nd one
3268c2e8227SGreg Roach		static $n = 0;
3278c2e8227SGreg Roach		if (++$n != 2) {
3288c2e8227SGreg Roach			return '';
3298c2e8227SGreg Roach		}
3308c2e8227SGreg Roach
3318c2e8227SGreg Roach		$controller->addInlineJavascript('
3328c2e8227SGreg Roach			var pid_array=jQuery("#pid_array");
3338c2e8227SGreg Roach			function set_pid_array(pa) {
3348c2e8227SGreg Roach				pid_array.val(pa);
3358c2e8227SGreg Roach			}
3368c2e8227SGreg Roach		');
3378c2e8227SGreg Roach
3388c2e8227SGreg Roach		return
3398c2e8227SGreg Roach			'<br>' .
3408c2e8227SGreg Roach			'<input type="hidden" name="pid_array" id="pid_array" value="">' .
3418c2e8227SGreg Roach			'<a href="#" onclick="return addnewnote_assisted(document.getElementById(\'' . $element_id . '\'), \'' . $xref . '\');">' .
3428c2e8227SGreg Roach			I18N::translate('Create a new shared note using assistant') .
3438c2e8227SGreg Roach			'</a>';
3448c2e8227SGreg Roach	}
3458c2e8227SGreg Roach
3468c2e8227SGreg Roach	/**
3478c2e8227SGreg Roach	 * Add a selector containing UK/US/FR census dates
3488c2e8227SGreg Roach	 *
3498c2e8227SGreg Roach	 * @param string $action
3508c2e8227SGreg Roach	 * @param string $tag
3518c2e8227SGreg Roach	 * @param string $element_id
3528c2e8227SGreg Roach	 *
3538c2e8227SGreg Roach	 * @return string
3548c2e8227SGreg Roach	 */
3558c2e8227SGreg Roach	public static function censusDateSelector($action, $tag, $element_id) {
3568c2e8227SGreg Roach		global $controller;
3578c2e8227SGreg Roach
3588c2e8227SGreg Roach		if ($action == 'add' && $tag == 'CENS') {
3598c2e8227SGreg Roach			$controller->addInlineJavascript('
3608c2e8227SGreg Roach				function addDate(theCensDate) {
3618c2e8227SGreg Roach					var ddate = theCensDate.split(", ");
3628c2e8227SGreg Roach					document.getElementById("setctry").value = ddate[3];
3638c2e8227SGreg Roach					document.getElementById("setyear").value = ddate[0];
3648c2e8227SGreg Roach					cal_setDateField("' . $element_id . '", parseInt(ddate[0]), parseInt(ddate[1]), parseInt(ddate[2]));
3658c2e8227SGreg Roach					return false;
3668c2e8227SGreg Roach				}
3678c2e8227SGreg Roach				function pasteAsstDate(setcy, setyr) {
3688c2e8227SGreg Roach					document.getElementById(setcy+setyr).selected = true;
3698c2e8227SGreg Roach					addDate(document.getElementById("selcensdate").options[document.getElementById(\'selcensdate\').selectedIndex].value);
3708c2e8227SGreg Roach					return false;
3718c2e8227SGreg Roach				}
3728c2e8227SGreg Roach			');
3738c2e8227SGreg Roach
3748c2e8227SGreg Roach			return '
3758c2e8227SGreg Roach				<select id="selcensdate" name="selcensdate" onchange = "if (this.options[this.selectedIndex].value!=\'\') {
3768c2e8227SGreg Roach										addDate(this.options[this.selectedIndex].value);
3778c2e8227SGreg Roach									}">
3788c2e8227SGreg Roach					<option id="defdate" value="" selected>' . I18N::translate('Census date') . '</option>
3798c2e8227SGreg Roach					<option value=""></option>
3808c2e8227SGreg Roach					<option id="UK1911" class="UK"  value="1911, 3, 02, UK">UK 1911</option>
3818c2e8227SGreg Roach					<option id="UK1901" class="UK"  value="1901, 2, 31, UK">UK 1901</option>
3828c2e8227SGreg Roach					<option id="UK1891" class="UK"  value="1891, 3, 05, UK">UK 1891</option>
3838c2e8227SGreg Roach					<option id="UK1881" class="UK"  value="1881, 3, 03, UK">UK 1881</option>
3848c2e8227SGreg Roach					<option id="UK1871" class="UK"  value="1871, 3, 02, UK">UK 1871</option>
3858c2e8227SGreg Roach					<option id="UK1861" class="UK"  value="1861, 3, 07, UK">UK 1861</option>
3868c2e8227SGreg Roach					<option id="UK1851" class="UK"  value="1851, 2, 30, UK">UK 1851</option>
3878c2e8227SGreg Roach					<option id="UK1841" class="UK"  value="1841, 5, 06, UK">UK 1841</option>
3888c2e8227SGreg Roach					<option value=""></option>
3898c2e8227SGreg Roach					<option id="USA1940" class="USA" value="1940, 3, 01, USA">US 1940</option>
3908c2e8227SGreg Roach					<option id="USA1930" class="USA" value="1930, 3, 01, USA">US 1930</option>
3918c2e8227SGreg Roach					<option id="USA1920" class="USA" value="1920, 0, 01, USA">US 1920</option>
3928c2e8227SGreg Roach					<option id="USA1910" class="USA" value="1910, 3, 15, USA">US 1910</option>
3938c2e8227SGreg Roach					<option id="USA1900" class="USA" value="1900, 5, 01, USA">US 1900</option>
3948c2e8227SGreg Roach					<option id="USA1890" class="USA" value="1890, 5, 01, USA">US 1890</option>
3958c2e8227SGreg Roach					<option id="USA1880" class="USA" value="1880, 5, 01, USA">US 1880</option>
3968c2e8227SGreg Roach					<option id="USA1870" class="USA" value="1870, 5, 01, USA">US 1870</option>
3978c2e8227SGreg Roach					<option id="USA1860" class="USA" value="1860, 5, 01, USA">US 1860</option>
3988c2e8227SGreg Roach					<option id="USA1850" class="USA" value="1850, 5, 01, USA">US 1850</option>
3998c2e8227SGreg Roach					<option id="USA1840" class="USA" value="1840, 5, 01, USA">US 1840</option>
4008c2e8227SGreg Roach					<option id="USA1830" class="USA" value="1830, 5, 01, USA">US 1830</option>
4018c2e8227SGreg Roach					<option id="USA1820" class="USA" value="1820, 7, 07, USA">US 1820</option>
4028c2e8227SGreg Roach					<option id="USA1810" class="USA" value="1810, 7, 06, USA">US 1810</option>
4038c2e8227SGreg Roach					<option id="USA1800" class="USA" value="1800, 7, 04, USA">US 1800</option>
4048c2e8227SGreg Roach					<option id="USA1790" class="USA" value="1790, 7, 02, USA">US 1790</option>
4058c2e8227SGreg Roach					<option value=""></option>
4068c2e8227SGreg Roach					<option id="FR1951" class="FR" value="1951, 0, 01, FR">FR 1951</option>
4078c2e8227SGreg Roach					<option id="FR1946" class="FR" value="1946, 0, 01, FR">FR 1946</option>
4088c2e8227SGreg Roach					<option id="FR1941" class="FR" value="1941, 0, 01, FR">FR 1941</option>
4098c2e8227SGreg Roach					<option id="FR1936" class="FR" value="1936, 0, 01, FR">FR 1936</option>
4108c2e8227SGreg Roach					<option id="FR1931" class="FR" value="1931, 0, 01, FR">FR 1931</option>
4118c2e8227SGreg Roach					<option id="FR1926" class="FR" value="1926, 0, 01, FR">FR 1926</option>
4128c2e8227SGreg Roach					<option id="FR1921" class="FR" value="1921, 0, 01, FR">FR 1921</option>
4138c2e8227SGreg Roach					<option id="FR1916" class="FR" value="1916, 0, 01, FR">FR 1916</option>
4148c2e8227SGreg Roach					<option id="FR1911" class="FR" value="1911, 0, 01, FR">FR 1911</option>
4158c2e8227SGreg Roach					<option id="FR1906" class="FR" value="1906, 0, 01, FR">FR 1906</option>
4168c2e8227SGreg Roach					<option id="FR1901" class="FR" value="1901, 0, 01, FR">FR 1901</option>
4178c2e8227SGreg Roach					<option id="FR1896" class="FR" value="1896, 0, 01, FR">FR 1896</option>
4188c2e8227SGreg Roach					<option id="FR1891" class="FR" value="1891, 0, 01, FR">FR 1891</option>
4198c2e8227SGreg Roach					<option id="FR1886" class="FR" value="1886, 0, 01, FR">FR 1886</option>
4208c2e8227SGreg Roach					<option id="FR1881" class="FR" value="1881, 0, 01, FR">FR 1881</option>
4218c2e8227SGreg Roach					<option id="FR1876" class="FR" value="1876, 0, 01, FR">FR 1876</option>
4228c2e8227SGreg Roach					<option value=""></option>
4238c2e8227SGreg Roach				</select>
4248c2e8227SGreg Roach
4258c2e8227SGreg Roach				<input type="hidden" id="setctry" name="setctry" value="">
4268c2e8227SGreg Roach				<input type="hidden" id="setyear" name="setyear" value="">
4278c2e8227SGreg Roach			';
4288c2e8227SGreg Roach		} else {
4298c2e8227SGreg Roach			return '';
4308c2e8227SGreg Roach		}
4318c2e8227SGreg Roach	}
4328c2e8227SGreg Roach}
433