xref: /webtrees/app/Module/CensusAssistantModule.php (revision 369c0ce6d43eee62858778711fa4744ed347814a)
18c2e8227SGreg Roach<?php
28c2e8227SGreg Roach/**
38c2e8227SGreg Roach * webtrees: online genealogy
4*369c0ce6SGreg Roach * Copyright (C) 2016 webtrees development team
58c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify
68c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by
78c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or
88c2e8227SGreg Roach * (at your option) any later version.
98c2e8227SGreg Roach * This program is distributed in the hope that it will be useful,
108c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
118c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
128c2e8227SGreg Roach * GNU General Public License for more details.
138c2e8227SGreg Roach * You should have received a copy of the GNU General Public License
148c2e8227SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
158c2e8227SGreg Roach */
1676692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module;
1776692c8bSGreg Roach
18ad51e0bbSGreg Roachuse Fisharebest\Webtrees\Census\CensusInterface;
190e62c4b8SGreg Roachuse Fisharebest\Webtrees\Controller\SimpleController;
200e62c4b8SGreg Roachuse Fisharebest\Webtrees\Family;
210e62c4b8SGreg Roachuse Fisharebest\Webtrees\Filter;
22ad51e0bbSGreg Roachuse Fisharebest\Webtrees\Functions\Functions;
233d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsDb;
240e62c4b8SGreg Roachuse Fisharebest\Webtrees\GedcomRecord;
250e62c4b8SGreg Roachuse Fisharebest\Webtrees\GedcomTag;
260e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N;
2799f222b3SGreg Roachuse Fisharebest\Webtrees\Individual;
28ad51e0bbSGreg Roachuse Fisharebest\Webtrees\Menu;
290e62c4b8SGreg Roachuse Fisharebest\Webtrees\Note;
308c2e8227SGreg Roach
318c2e8227SGreg Roach/**
328c2e8227SGreg Roach * Class CensusAssistantModule
338c2e8227SGreg Roach */
3415834aaeSGreg Roachclass CensusAssistantModule extends AbstractModule {
358c2e8227SGreg Roach	/** {@inheritdoc} */
368c2e8227SGreg Roach	public function getTitle() {
378c2e8227SGreg Roach		return /* I18N: Name of a module */ I18N::translate('Census assistant');
388c2e8227SGreg Roach	}
398c2e8227SGreg Roach
408c2e8227SGreg Roach	/** {@inheritdoc} */
418c2e8227SGreg Roach	public function getDescription() {
428c2e8227SGreg Roach		return /* I18N: Description of the “Census assistant” module */ I18N::translate('An alternative way to enter census transcripts and link them to individuals.');
438c2e8227SGreg Roach	}
448c2e8227SGreg Roach
4576692c8bSGreg Roach	/**
4676692c8bSGreg Roach	 * This is a general purpose hook, allowing modules to respond to routes
4776692c8bSGreg Roach	 * of the form module.php?mod=FOO&mod_action=BAR
4876692c8bSGreg Roach	 *
4976692c8bSGreg Roach	 * @param string $mod_action
5076692c8bSGreg Roach	 */
518c2e8227SGreg Roach	public function modAction($mod_action) {
528c2e8227SGreg Roach		switch ($mod_action) {
5340990b78SGreg Roach		case 'census_find':
5440990b78SGreg Roach			self::censusFind();
558c2e8227SGreg Roach			break;
5640990b78SGreg Roach		case 'media_find':
57764a01d9SGreg Roach			self::mediaFind();
588c2e8227SGreg Roach			break;
598c2e8227SGreg Roach		case 'media_query_3a':
60764a01d9SGreg Roach			self::mediaQuery();
618c2e8227SGreg Roach			break;
628c2e8227SGreg Roach		default:
638c2e8227SGreg Roach			http_response_code(404);
648c2e8227SGreg Roach		}
658c2e8227SGreg Roach	}
668c2e8227SGreg Roach
678c2e8227SGreg Roach	/**
6876692c8bSGreg Roach	 * Find an individual.
698c2e8227SGreg Roach	 */
7040990b78SGreg Roach	private static function censusFind() {
7140990b78SGreg Roach		global $WT_TREE;
7240990b78SGreg Roach
7340990b78SGreg Roach		$controller = new SimpleController;
7440990b78SGreg Roach		$filter     = Filter::get('filter');
7540990b78SGreg Roach		$action     = Filter::get('action');
76ad51e0bbSGreg Roach		$census     = Filter::get('census');
77ad51e0bbSGreg Roach		$census     = new $census;
7840990b78SGreg Roach
7940990b78SGreg Roach		$controller
80ad51e0bbSGreg Roach			->restrictAccess($census instanceof CensusInterface)
8140990b78SGreg Roach			->setPageTitle(I18N::translate('Find an individual'))
8240990b78SGreg Roach			->pageHeader();
8340990b78SGreg Roach
84ad51e0bbSGreg Roach		echo '<table class="list_table width90" border="0">';
85ad51e0bbSGreg Roach		echo '<tr><td style="padding: 10px;" valign="top" class="facts_label03 width90">';
8640990b78SGreg Roach		echo I18N::translate('Find an individual');
87ad51e0bbSGreg Roach		echo '</td>';
88ad51e0bbSGreg Roach		echo '</table>';
89ad51e0bbSGreg Roach		echo '<br>';
9040990b78SGreg Roach
91ad51e0bbSGreg Roach		if ($action == 'filter') {
9240990b78SGreg Roach			$filter       = trim($filter);
9340990b78SGreg Roach			$filter_array = explode(' ', preg_replace('/ {2,}/', ' ', $filter));
9440990b78SGreg Roach
9540990b78SGreg Roach			// Output Individual for GEDFact Assistant ======================
96ad51e0bbSGreg Roach			echo '<table class="list_table width90">';
973d7a8a4cSGreg Roach			$myindilist = FunctionsDb::searchIndividualNames($filter_array, array($WT_TREE));
9840990b78SGreg Roach			if ($myindilist) {
99ad51e0bbSGreg Roach				echo '<tr><td class="list_value_wrap"><ul>';
10040990b78SGreg Roach				usort($myindilist, '\Fisharebest\Webtrees\GedcomRecord::compare');
10140990b78SGreg Roach				foreach ($myindilist as $indi) {
102ad51e0bbSGreg Roach					echo '<li>';
1030b18a98dSGreg Roach					echo '<a href="#" onclick="window.opener.appendCensusRow(\'' . Filter::escapeJs(self::censusTableRow($census, $indi, null)) . '\'); window.close();">';
104ad51e0bbSGreg Roach					echo '<b>' . $indi->getFullName() . '</b>';
105ad51e0bbSGreg Roach					echo '</a>';
106ad51e0bbSGreg Roach					echo $indi->formatFirstMajorFact(WT_EVENTS_BIRT, 1);
107ad51e0bbSGreg Roach					echo $indi->formatFirstMajorFact(WT_EVENTS_DEAT, 1);
108ad51e0bbSGreg Roach					echo '<hr>';
109ad51e0bbSGreg Roach					echo '</li>';
11040990b78SGreg Roach				}
11140990b78SGreg Roach				echo '</ul></td></tr>';
11240990b78SGreg Roach			} else {
113ad51e0bbSGreg Roach				echo '<tr><td class="list_value_wrap">';
11440990b78SGreg Roach				echo I18N::translate('No results found.');
115ad51e0bbSGreg Roach				echo '</td></tr>';
11640990b78SGreg Roach			}
117ad51e0bbSGreg Roach			echo '<tr><td>';
11840990b78SGreg Roach			echo '<button onclick="window.close();">', I18N::translate('close'), '</button>';
119ad51e0bbSGreg Roach			echo '</td></tr>';
120ad51e0bbSGreg Roach			echo '</table>';
121ad51e0bbSGreg Roach		}
12240990b78SGreg Roach	}
12340990b78SGreg Roach
12440990b78SGreg Roach	/**
12576692c8bSGreg Roach	 * Find a media object.
12640990b78SGreg Roach	 */
127764a01d9SGreg Roach	private static function mediaFind() {
1288c2e8227SGreg Roach		global $WT_TREE;
1298c2e8227SGreg Roach
1308c2e8227SGreg Roach		$controller = new SimpleController;
1318c2e8227SGreg Roach		$filter     = Filter::get('filter');
1328c2e8227SGreg Roach		$multiple   = Filter::getBool('multiple');
1338c2e8227SGreg Roach
1348c2e8227SGreg Roach		$controller
1358c2e8227SGreg Roach			->setPageTitle(I18N::translate('Find an individual'))
1368c2e8227SGreg Roach			->pageHeader();
1378c2e8227SGreg Roach
1388c2e8227SGreg Roach		?>
13999f222b3SGreg Roach		<script>
1408c2e8227SGreg Roach		function pasterow(id, name, gend, yob, age, bpl) {
1418c2e8227SGreg Roach			window.opener.opener.insertRowToTable(id, name, '', gend, '', yob, age, 'Y', '', bpl);
1428c2e8227SGreg Roach		}
1438c2e8227SGreg Roach
1448c2e8227SGreg Roach		function pasteid(id, name, thumb) {
1458c2e8227SGreg Roach			if (thumb) {
1468c2e8227SGreg Roach				window.opener.paste_id(id, name, thumb);
14799f222b3SGreg Roach				<?php if (!$multiple) { echo "window.close();"; } ?>
1488c2e8227SGreg Roach			} else {
1498c2e8227SGreg Roach			// GEDFact_assistant ========================
1508c2e8227SGreg Roach			if (window.opener.document.getElementById('addlinkQueue')) {
1518c2e8227SGreg Roach				window.opener.insertRowToTable(id, name);
1528c2e8227SGreg Roach			}
1538c2e8227SGreg Roach			window.opener.paste_id(id);
1548c2e8227SGreg Roach			if (window.opener.pastename) {
1558c2e8227SGreg Roach				window.opener.pastename(name);
1568c2e8227SGreg Roach			}
15799f222b3SGreg Roach			<?php if (!$multiple) { echo "window.close();"; } ?>
1588c2e8227SGreg Roach			}
1598c2e8227SGreg Roach		}
1608c2e8227SGreg Roach		function checknames(frm) {
1618c2e8227SGreg Roach			if (document.forms[0].subclick) {
1628c2e8227SGreg Roach				button = document.forms[0].subclick.value;
1638c2e8227SGreg Roach			} else {
1648c2e8227SGreg Roach				button = "";
1658c2e8227SGreg Roach			}
166ad51e0bbSGreg Roach			if (frm.filter.value.length < 2 && button !== "all") {
16777e70a22SGreg Roach				alert("<?php echo I18N::translate('Please enter more than one character.'); ?>");
1688c2e8227SGreg Roach				frm.filter.focus();
1698c2e8227SGreg Roach				return false;
1708c2e8227SGreg Roach			}
1718c2e8227SGreg Roach			if (button=="all") {
1728c2e8227SGreg Roach				frm.filter.value = "";
1738c2e8227SGreg Roach			}
1748c2e8227SGreg Roach			return true;
1758c2e8227SGreg Roach		}
17699f222b3SGreg Roach		</script>
1778c2e8227SGreg Roach
17899f222b3SGreg Roach		<?php
1798c2e8227SGreg Roach		echo "<div align=\"center\">";
1808c2e8227SGreg Roach		echo "<table class=\"list_table width90\" border=\"0\">";
1818c2e8227SGreg Roach		echo "<tr><td style=\"padding: 10px;\" valign=\"top\" class=\"facts_label03 width90\">"; // start column for find text header
1828c2e8227SGreg Roach		echo $controller->getPageTitle();
1838c2e8227SGreg Roach		echo "</td>";
1848c2e8227SGreg Roach		echo "</tr>";
1858c2e8227SGreg Roach		echo "</table>";
1868c2e8227SGreg Roach		echo "<br>";
1878c2e8227SGreg Roach		echo '<button onclick="window.close();">', I18N::translate('close'), '</button>';
1888c2e8227SGreg Roach		echo "<br>";
1898c2e8227SGreg Roach
1908c2e8227SGreg Roach		$filter       = trim($filter);
1918c2e8227SGreg Roach		$filter_array = explode(' ', preg_replace('/ {2,}/', ' ', $filter));
1928c2e8227SGreg Roach		echo "<table class=\"tabs_table width90\"><tr>";
1933d7a8a4cSGreg Roach		$myindilist = FunctionsDb::searchIndividualNames($filter_array, array($WT_TREE));
1948c2e8227SGreg Roach		if ($myindilist) {
1958c2e8227SGreg Roach			echo "<td class=\"list_value_wrap\"><ul>";
1960e62c4b8SGreg Roach			usort($myindilist, '\Fisharebest\Webtrees\GedcomRecord::compare');
1978c2e8227SGreg Roach			foreach ($myindilist as $indi) {
1988c2e8227SGreg Roach				$nam = Filter::escapeHtml($indi->getFullName());
1998c2e8227SGreg Roach				echo "<li><a href=\"#\" onclick=\"pasterow(
2008c2e8227SGreg Roach					'" . $indi->getXref() . "' ,
2018c2e8227SGreg Roach					'" . $nam . "' ,
2028c2e8227SGreg Roach					'" . $indi->getSex() . "' ,
2038c2e8227SGreg Roach					'" . $indi->getbirthyear() . "' ,
2048c2e8227SGreg Roach					'" . (1901 - $indi->getbirthyear()) . "' ,
2058c2e8227SGreg Roach					'" . $indi->getbirthplace() . "'); return false;\">
2068c2e8227SGreg Roach					<b>" . $indi->getFullName() . "</b>&nbsp;&nbsp;&nbsp;";
2078c2e8227SGreg Roach
208764a01d9SGreg Roach				$born = GedcomTag::getLabel('BIRT');
2098c2e8227SGreg Roach				echo "</span><br><span class=\"list_item\">", $born, " ", $indi->getbirthyear(), "&nbsp;&nbsp;&nbsp;", $indi->getbirthplace(), "</span></a></li>";
2108c2e8227SGreg Roach				echo "<hr>";
2118c2e8227SGreg Roach			}
2128c2e8227SGreg Roach			echo '</ul></td></tr><tr><td class="list_label">', I18N::translate('Total individuals: %s', count($myindilist)), '</tr></td>';
2138c2e8227SGreg Roach		} else {
2148c2e8227SGreg Roach			echo "<td class=\"list_value_wrap\">";
2158c2e8227SGreg Roach			echo I18N::translate('No results found.');
2168c2e8227SGreg Roach			echo "</td></tr>";
2178c2e8227SGreg Roach		}
2188c2e8227SGreg Roach		echo "</table>";
2198c2e8227SGreg Roach		echo '</div>';
2208c2e8227SGreg Roach	}
2218c2e8227SGreg Roach
2228c2e8227SGreg Roach	/**
22376692c8bSGreg Roach	 * Search for a media object.
2248c2e8227SGreg Roach	 */
225764a01d9SGreg Roach	private static function mediaQuery() {
22624ec66ceSGreg Roach		global $WT_TREE;
22724ec66ceSGreg Roach
2288c2e8227SGreg Roach		$iid2 = Filter::get('iid', WT_REGEX_XREF);
2298c2e8227SGreg Roach
2308c2e8227SGreg Roach		$controller = new SimpleController;
2318c2e8227SGreg Roach		$controller
2328c2e8227SGreg Roach			->setPageTitle(I18N::translate('Link to an existing media object'))
2338c2e8227SGreg Roach			->pageHeader();
2348c2e8227SGreg Roach
23524ec66ceSGreg Roach		$record = GedcomRecord::getInstance($iid2, $WT_TREE);
2368c2e8227SGreg Roach		if ($record) {
2378c2e8227SGreg Roach			$headjs = '';
2388c2e8227SGreg Roach			if ($record instanceof Family) {
2398c2e8227SGreg Roach				if ($record->getHusband()) {
2408c2e8227SGreg Roach					$headjs = $record->getHusband()->getXref();
2418c2e8227SGreg Roach				} elseif ($record->getWife()) {
2428c2e8227SGreg Roach					$headjs = $record->getWife()->getXref();
2438c2e8227SGreg Roach				}
2448c2e8227SGreg Roach			}
2458c2e8227SGreg Roach			?>
2468c2e8227SGreg Roach			<script>
2478c2e8227SGreg Roach				function insertId() {
2488c2e8227SGreg Roach					if (window.opener.document.getElementById('addlinkQueue')) {
2498c2e8227SGreg Roach						// alert('Please move this alert window and examine the contents of the pop-up window, then click OK')
2508c2e8227SGreg Roach						window.opener.insertRowToTable('<?php echo $record->getXref(); ?>', '<?php echo htmlSpecialChars($record->getFullName()); ?>', '<?php echo $headjs; ?>');
2518c2e8227SGreg Roach						window.close();
2528c2e8227SGreg Roach					}
2538c2e8227SGreg Roach				}
2548c2e8227SGreg Roach			</script>
2558c2e8227SGreg Roach			<?php
2568c2e8227SGreg Roach		} else {
2578c2e8227SGreg Roach			?>
2588c2e8227SGreg Roach			<script>
2598c2e8227SGreg Roach				function insertId() {
26077e70a22SGreg Roach					window.opener.alert('<?php echo $iid2; ?> - <?php echo I18N::translate('Not a valid individual, family, or source ID'); ?>');
2618c2e8227SGreg Roach					window.close();
2628c2e8227SGreg Roach				}
2638c2e8227SGreg Roach			</script>
2648c2e8227SGreg Roach			<?php
2658c2e8227SGreg Roach		}
2668c2e8227SGreg Roach		?>
2678c2e8227SGreg Roach		<script>window.onLoad = insertId();</script>
2688c2e8227SGreg Roach		<?php
2698c2e8227SGreg Roach	}
2708c2e8227SGreg Roach
2718c2e8227SGreg Roach	/**
2728c2e8227SGreg Roach	 * Convert custom markup into HTML
2738c2e8227SGreg Roach	 *
2748c2e8227SGreg Roach	 * @param Note $note
2758c2e8227SGreg Roach	 *
2768c2e8227SGreg Roach	 * @return string
2778c2e8227SGreg Roach	 */
2788c2e8227SGreg Roach	public static function formatCensusNote(Note $note) {
2798c2e8227SGreg Roach		global $WT_TREE;
2808c2e8227SGreg Roach
2818c2e8227SGreg Roach		$headers = array(
2828c2e8227SGreg Roach			'AgM'        => 'Age at first marriage',
2838c2e8227SGreg Roach			'Age'        => 'Age at last birthday',
2848c2e8227SGreg Roach			'Assets'     => 'Assets = Owned,Rented - Value,Rent - Radio - Farm',
2858c2e8227SGreg Roach			'BIC'        => 'Born in County',
2868c2e8227SGreg Roach			'BOE'        => 'Born outside England',
2878c2e8227SGreg Roach			'BP'         => 'Birthplace - (Chapman format)',
2888c2e8227SGreg Roach			'Birthplace' => 'Birthplace (Full format)',
2898c2e8227SGreg Roach			'Bmth'       => 'Month of birth - If born within Census year',
2908c2e8227SGreg Roach			'ChB'        => 'Children born alive',
2918c2e8227SGreg Roach			'ChD'        => 'Children who have died',
2928c2e8227SGreg Roach			'ChL'        => 'Children still living',
2938c2e8227SGreg Roach			'DOB'        => 'Date of birth',
2948c2e8227SGreg Roach			'Edu'        => 'Education - At School, Can Read, Can Write', // or "Cannot Read, Cannot Write" ??
2958c2e8227SGreg Roach			'EmD'        => 'Employed?',
2968c2e8227SGreg Roach			'EmN'        => 'Unemployed?',
2978c2e8227SGreg Roach			'EmR'        => 'Employer?',
2988c2e8227SGreg Roach			'Employ'     => 'Employment',
2998c2e8227SGreg Roach			'Eng?'       => 'English spoken?',
3008c2e8227SGreg Roach			'EngL'       => 'English spoken?, if not, Native Language',
3018c2e8227SGreg Roach			'FBP'        => 'Father’s Birthplace - (Chapman format)',
3028c2e8227SGreg Roach			'Health'     => 'Health - 1.Blind, 2.Deaf & Dumb, 3.Idiotic, 4.Insane, 5.Disabled etc',
3038c2e8227SGreg Roach			'Home'       => 'Home Ownership - Owned/Rented-Free/Mortgaged-Farm/House-Farm Schedule number',
3048c2e8227SGreg Roach			'Industry'   => 'Industry',
3058c2e8227SGreg Roach			'Infirm'     => 'Infirmities - 1. Deaf & Dumb, 2. Blind, 3. Lunatic, 4. Imbecile/feeble-minded',
3068c2e8227SGreg Roach			'Lang'       => 'If Foreign Born - Native Language',
3078c2e8227SGreg Roach			'MBP'        => 'Mother’s Birthplace - (Chapman format)',
3088c2e8227SGreg Roach			'MC'         => 'Marital Condition - Married, Single, Unmarried, Widowed or Divorced',
3098c2e8227SGreg Roach			'Mmth'       => 'Month of marriage - If married during Census Year',
3108c2e8227SGreg Roach			'MnsE'       => 'Months employed during Census Year',
3118c2e8227SGreg Roach			'MnsU'       => 'Months unemployed during Census Year',
3128c2e8227SGreg Roach			'N/A'        => 'If Foreign Born - Naturalized, Alien',
3138c2e8227SGreg Roach			'NL'         => 'If Foreign Born - Native Language',
3148c2e8227SGreg Roach			'Name'       => 'Full Name or Married name if married',
3158c2e8227SGreg Roach			'Occupation' => 'Occupation',
3168c2e8227SGreg Roach			'Par'        => 'Parentage - Father if foreign born, Mother if foreign born',
3178c2e8227SGreg Roach			'Race'       => 'Race or Color - Black, White, Mulatto, Asian, Indian, Chinese etc',
3188c2e8227SGreg Roach			'Relation'   => 'Relationship to Head of Household',
3198c2e8227SGreg Roach			'Sex'        => 'Male or Female',
3208c2e8227SGreg Roach			'Situ'       => 'Situation - Disease, Infirmity, Convict, Pauper etc',
3218c2e8227SGreg Roach			'Ten'        => 'Tenure - Owned/Rented, (if owned)Free/Morgaged',
3228c2e8227SGreg Roach			'Vet'        => 'War Veteran?',
3238c2e8227SGreg Roach			'WH'         => 'Working at Home?',
3248c2e8227SGreg Roach			'War'        => 'War or Expedition',
3258c2e8227SGreg Roach			'WksU'       => 'Weeks unemployed during Census Year',
3268c2e8227SGreg Roach			'YOI'        => 'If Foreign Born - Year of immigration',
3278c2e8227SGreg Roach			'YON'        => 'If Foreign Born - Year of naturalization',
3288c2e8227SGreg Roach			'YUS'        => 'If Foreign Born - Years in the USA',
3298c2e8227SGreg Roach			'YrsM'       => 'Years Married, or Y if married in Census Year',
3308c2e8227SGreg Roach		);
3318c2e8227SGreg Roach
3328c2e8227SGreg Roach		if (preg_match('/(.*)((?:\n.*)*)\n\.start_formatted_area\.\n(.*)((?:\n.*)*)\n.end_formatted_area\.((?:\n.*)*)/', $note->getNote(), $match)) {
3338c2e8227SGreg Roach			// This looks like a census-assistant shared note
3348c2e8227SGreg Roach			$title     = Filter::escapeHtml($match[1]);
3358c2e8227SGreg Roach			$preamble  = Filter::escapeHtml($match[2]);
3368c2e8227SGreg Roach			$header    = Filter::escapeHtml($match[3]);
3378c2e8227SGreg Roach			$data      = Filter::escapeHtml($match[4]);
3388c2e8227SGreg Roach			$postamble = Filter::escapeHtml($match[5]);
3398c2e8227SGreg Roach
3408c2e8227SGreg Roach			$fmt_headers = array();
3418c2e8227SGreg Roach			foreach ($headers as $key => $value) {
342ad51e0bbSGreg Roach				$fmt_headers[$key] = '<span title="' . Filter::escapeHtml($value) . '">' . $key . '</span>';
3438c2e8227SGreg Roach			}
3448c2e8227SGreg Roach
3458c2e8227SGreg Roach			// Substitue header labels and format as HTML
3468c2e8227SGreg Roach			$thead = '<tr><th>' . strtr(str_replace('|', '</th><th>', $header), $fmt_headers) . '</th></tr>';
347ad51e0bbSGreg Roach			$thead = str_replace('.b.', '', $thead);
3488c2e8227SGreg Roach
3498c2e8227SGreg Roach			// Format data as HTML
3508c2e8227SGreg Roach			$tbody = '';
3518c2e8227SGreg Roach			foreach (explode("\n", $data) as $row) {
3528c2e8227SGreg Roach				$tbody .= '<tr>';
3538c2e8227SGreg Roach				foreach (explode('|', $row) as $column) {
3548c2e8227SGreg Roach					$tbody .= '<td>' . $column . '</td>';
3558c2e8227SGreg Roach				}
3568c2e8227SGreg Roach				$tbody .= '</tr>';
3578c2e8227SGreg Roach			}
3588c2e8227SGreg Roach
3598c2e8227SGreg Roach			return
3608c2e8227SGreg Roach				$title . "\n" . // The newline allows the framework to expand the details and turn the first line into a link
3618c2e8227SGreg Roach				'<p>' . $preamble . '</p>' .
3628c2e8227SGreg Roach				'<table class="table-census-assistant">' .
3638c2e8227SGreg Roach				'<thead>' . $thead . '</thead>' .
3648c2e8227SGreg Roach				'<tbody>' . $tbody . '</tbody>' .
3658c2e8227SGreg Roach				'</table>' .
3668c2e8227SGreg Roach				'<p>' . $postamble . '</p>';
3678c2e8227SGreg Roach		} else {
3688c2e8227SGreg Roach			// Not a census-assistant shared note - apply default formatting
3698c2e8227SGreg Roach			return Filter::formatText($note->getNote(), $WT_TREE);
3708c2e8227SGreg Roach		}
3718c2e8227SGreg Roach	}
37299f222b3SGreg Roach
37399f222b3SGreg Roach	/**
374ad51e0bbSGreg Roach	 * Generate an HTML row of data for the census header
37599f222b3SGreg Roach	 *
37652bc9faeSGreg Roach	 * Add prefix cell (store XREF and drag/drop)
37752bc9faeSGreg Roach	 * Add suffix cell (delete button)
37852bc9faeSGreg Roach	 *
379ad51e0bbSGreg Roach	 * @param CensusInterface $census
38099f222b3SGreg Roach	 *
381ad51e0bbSGreg Roach	 * @return string
38299f222b3SGreg Roach	 */
383ad51e0bbSGreg Roach	public static function censusTableHeader(CensusInterface $census) {
38452bc9faeSGreg Roach		$html = '';
385ad51e0bbSGreg Roach		foreach ($census->columns() as $column) {
386ad51e0bbSGreg Roach			$html .= '<th title="' . $column->title() . '">' . $column->abbreviation() . '</th>';
38799f222b3SGreg Roach		}
38899f222b3SGreg Roach
38952bc9faeSGreg Roach		return '<tr><th hidden></th>' . $html . '<th></th></th></tr>';
390ad51e0bbSGreg Roach	}
39199f222b3SGreg Roach
392ad51e0bbSGreg Roach	/**
393ad51e0bbSGreg Roach	 * Generate an HTML row of data for the census
394ad51e0bbSGreg Roach	 *
39552bc9faeSGreg Roach	 * Add prefix cell (store XREF and drag/drop)
39652bc9faeSGreg Roach	 * Add suffix cell (delete button)
39752bc9faeSGreg Roach	 *
398ad51e0bbSGreg Roach	 * @param CensusInterface $census
399ad51e0bbSGreg Roach	 *
400ad51e0bbSGreg Roach	 * @return string
401ad51e0bbSGreg Roach	 */
402ad51e0bbSGreg Roach	public static function censusTableEmptyRow(CensusInterface $census) {
40352bc9faeSGreg Roach		return '<tr><td hidden></td>' . str_repeat('<td><input type="text"></td>', count($census->columns())) . '<td><a class="icon-remove" href="#" title="' . I18N::translate('Remove') . '"></a></td></tr>';
404ad51e0bbSGreg Roach	}
40599f222b3SGreg Roach
406ad51e0bbSGreg Roach	/**
407ad51e0bbSGreg Roach	 * Generate an HTML row of data for the census
408ad51e0bbSGreg Roach	 *
40952bc9faeSGreg Roach	 * Add prefix cell (store XREF and drag/drop)
41052bc9faeSGreg Roach	 * Add suffix cell (delete button)
41152bc9faeSGreg Roach	 *
412ad51e0bbSGreg Roach	 * @param CensusInterface $census
413ad51e0bbSGreg Roach	 * @param Individual      $individual
414ad51e0bbSGreg Roach	 * @param Individual|null $head
415ad51e0bbSGreg Roach	 *
416ad51e0bbSGreg Roach	 * @return string
417ad51e0bbSGreg Roach	 */
418ad51e0bbSGreg Roach	public static function censusTableRow(CensusInterface $census, Individual $individual, Individual $head = null) {
41952bc9faeSGreg Roach		$html = '';
420ad51e0bbSGreg Roach		foreach ($census->columns() as $column) {
421ad51e0bbSGreg Roach			$html .= '<td><input type="text" value="' . $column->generate($individual, $head) . '"></td>';
422ad51e0bbSGreg Roach		}
423ad51e0bbSGreg Roach
42452bc9faeSGreg Roach		return '<tr><td hidden>' . $individual->getXref() . '</td>' . $html . '<td><a class="icon-remove" href="#" title="' . I18N::translate('Remove') . '"></a></td></tr>';
425ad51e0bbSGreg Roach	}
426ad51e0bbSGreg Roach
427ad51e0bbSGreg Roach	/**
428ad51e0bbSGreg Roach	 * Create a family on the census navigator.
429ad51e0bbSGreg Roach	 *
430ad51e0bbSGreg Roach	 * @param CensusInterface $census
431ad51e0bbSGreg Roach	 * @param Family          $family
432ad51e0bbSGreg Roach	 * @param Individual      $head
433ad51e0bbSGreg Roach	 *
434ad51e0bbSGreg Roach	 * @return string
435ad51e0bbSGreg Roach	 */
436ad51e0bbSGreg Roach	public static function censusNavigatorFamily(CensusInterface $census, Family $family, Individual $head) {
437ad51e0bbSGreg Roach		$headImg2  = '<i class="icon-button_head" title="' . I18N::translate('Click to choose individual as head of family.') . '"></i>';
438ad51e0bbSGreg Roach
439ad51e0bbSGreg Roach		foreach ($family->getSpouses() as $spouse) {
440ad51e0bbSGreg Roach			$menu  = new Menu(Functions::getCloseRelationshipName($head, $spouse));
441ad51e0bbSGreg Roach			foreach ($spouse->getChildFamilies() as $grandparents) {
442ad51e0bbSGreg Roach				foreach ($grandparents->getSpouses() as $grandparent) {
443ad51e0bbSGreg Roach					$submenu = new Menu(
444ad51e0bbSGreg Roach						Functions::getCloseRelationshipName($head, $grandparent) . ' - ' . $grandparent->getFullName(),
445ad51e0bbSGreg Roach						'#',
446ad51e0bbSGreg Roach						'',
4470b18a98dSGreg Roach						array('onclick' => 'return appendCensusRow("' . Filter::escapeJs(self::censusTableRow($census, $grandparent, $head)) . '");')
448ad51e0bbSGreg Roach					);
449ad51e0bbSGreg Roach					$submenu->addClass('submenuitem', '');
450ad51e0bbSGreg Roach					$menu->addSubmenu($submenu);
451ad51e0bbSGreg Roach					$menu->addClass('', 'submenu');
45299f222b3SGreg Roach				}
45399f222b3SGreg Roach			}
45499f222b3SGreg Roach
455ad51e0bbSGreg Roach			?>
456ad51e0bbSGreg Roach			<tr>
457ad51e0bbSGreg Roach				<td class="optionbox">
458ad51e0bbSGreg Roach					<?php echo $menu->getMenu(); ?>
459ad51e0bbSGreg Roach				</td>
460ad51e0bbSGreg Roach				<td class="facts_value nowrap">
4610b18a98dSGreg Roach					<a href="#" onclick="return appendCensusRow('<?php echo Filter::escapeJs(self::censusTableRow($census, $spouse, $head)); ?>');">
462ad51e0bbSGreg Roach						<?php echo $spouse->getFullName(); ?>
463ad51e0bbSGreg Roach					</a>
464ad51e0bbSGreg Roach				</td>
465ad51e0bbSGreg Roach				<td align="left" class="facts_value">
466ad51e0bbSGreg Roach					<a href="edit_interface.php?action=addnewnote_assisted&amp;noteid=newnote&amp;xref=<?php echo $spouse->getXref(); ?>&amp;gedcom=<?php echo $spouse->getTree()->getNameUrl(); ?>&amp;census=<?php echo get_class($census); ?>">
467ad51e0bbSGreg Roach						<?php echo $headImg2; ?>
468ad51e0bbSGreg Roach					</a>
469ad51e0bbSGreg Roach				</td>
470ad51e0bbSGreg Roach			</tr>
471ad51e0bbSGreg Roach			<?php
47299f222b3SGreg Roach		}
473ad51e0bbSGreg Roach
474ad51e0bbSGreg Roach		foreach ($family->getChildren() as $child) {
475ad51e0bbSGreg Roach			$menu  = new Menu(Functions::getCloseRelationshipName($head, $child));
476ad51e0bbSGreg Roach			foreach ($child->getSpouseFamilies() as $spouse_family) {
477ad51e0bbSGreg Roach				foreach ($spouse_family->getSpouses() as $spouse_family_spouse) {
478ad51e0bbSGreg Roach					if ($spouse_family_spouse != $child) {
479ad51e0bbSGreg Roach						$submenu = new Menu(
480ad51e0bbSGreg Roach							Functions::getCloseRelationshipName($head, $spouse_family_spouse) . ' - ' . $spouse_family_spouse->getFullName(),
481ad51e0bbSGreg Roach							'#',
482ad51e0bbSGreg Roach							'',
4830b18a98dSGreg Roach							array('onclick' => 'return appendCensusRow("' . Filter::escapeJs(self::censusTableRow($census, $spouse_family_spouse, $head)) . '");')
484ad51e0bbSGreg Roach						);
485ad51e0bbSGreg Roach						$submenu->addClass('submenuitem', '');
486ad51e0bbSGreg Roach						$menu->addSubmenu($submenu);
487ad51e0bbSGreg Roach						$menu->addClass('', 'submenu');
488ad51e0bbSGreg Roach					}
489ad51e0bbSGreg Roach				}
490ad51e0bbSGreg Roach				foreach ($spouse_family->getChildren() as $spouse_family_child) {
491ad51e0bbSGreg Roach					$submenu = new Menu(
492ad51e0bbSGreg Roach						Functions::getCloseRelationshipName($head, $spouse_family_child) . ' - ' . $spouse_family_child->getFullName(),
493ad51e0bbSGreg Roach						'#',
494ad51e0bbSGreg Roach						'',
4950b18a98dSGreg Roach						array('onclick' => 'return appendCensusRow("' . Filter::escapeJs(self::censusTableRow($census, $spouse_family_child, $head)) . '");')
496ad51e0bbSGreg Roach					);
497ad51e0bbSGreg Roach					$submenu->addClass('submenuitem', '');
498ad51e0bbSGreg Roach					$menu->addSubmenu($submenu);
499ad51e0bbSGreg Roach					$menu->addClass('', 'submenu');
50099f222b3SGreg Roach				}
50199f222b3SGreg Roach			}
50299f222b3SGreg Roach
503ad51e0bbSGreg Roach			?>
504ad51e0bbSGreg Roach			<tr>
505ad51e0bbSGreg Roach				<td class="optionbox">
506ad51e0bbSGreg Roach					<?php echo $menu->getMenu(); ?>
507ad51e0bbSGreg Roach				</td>
508ad51e0bbSGreg Roach				<td class="facts_value">
5090b18a98dSGreg Roach					<a href="#" onclick="return appendCensusRow('<?php echo Filter::escapeJs(self::censusTableRow($census, $child, $head)); ?>');">
510ad51e0bbSGreg Roach						<?php echo $child->getFullName(); ?>
511ad51e0bbSGreg Roach					</a>
512ad51e0bbSGreg Roach				</td>
513ad51e0bbSGreg Roach				<td class="facts_value">
514ad51e0bbSGreg Roach					<a href="edit_interface.php?action=addnewnote_assisted&amp;noteid=newnote&amp;xref=<?php echo $child->getXref(); ?>&amp;gedcom=<?php echo $child->getTree()->getNameUrl(); ?>&amp;census=<?php echo get_class($census); ?>">
515ad51e0bbSGreg Roach						<?php echo $headImg2; ?>
516ad51e0bbSGreg Roach					</a>
517ad51e0bbSGreg Roach				</td>
518ad51e0bbSGreg Roach			</tr>
519ad51e0bbSGreg Roach			<?php
52099f222b3SGreg Roach		}
521ad51e0bbSGreg Roach		echo '<tr><td><br></td></tr>';
52299f222b3SGreg Roach	}
5238c2e8227SGreg Roach}
524