xref: /webtrees/app/Module/CensusAssistantModule.php (revision 3a7bc14ad32e31ba049b6906a4e881a1685c8926)
18c2e8227SGreg Roach<?php
28c2e8227SGreg Roach/**
38c2e8227SGreg Roach * webtrees: online genealogy
4369c0ce6SGreg 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
18*3a7bc14aSDavid Druryuse Fisharebest\Webtrees\Census\Census;
19ad51e0bbSGreg Roachuse Fisharebest\Webtrees\Census\CensusInterface;
200e62c4b8SGreg Roachuse Fisharebest\Webtrees\Controller\SimpleController;
210e62c4b8SGreg Roachuse Fisharebest\Webtrees\Family;
220e62c4b8SGreg Roachuse Fisharebest\Webtrees\Filter;
23ad51e0bbSGreg Roachuse Fisharebest\Webtrees\Functions\Functions;
243d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsDb;
250e62c4b8SGreg Roachuse Fisharebest\Webtrees\GedcomRecord;
260e62c4b8SGreg Roachuse Fisharebest\Webtrees\GedcomTag;
270e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N;
2899f222b3SGreg Roachuse Fisharebest\Webtrees\Individual;
29ad51e0bbSGreg Roachuse Fisharebest\Webtrees\Menu;
300e62c4b8SGreg Roachuse Fisharebest\Webtrees\Note;
318c2e8227SGreg Roach
328c2e8227SGreg Roach/**
338c2e8227SGreg Roach * Class CensusAssistantModule
348c2e8227SGreg Roach */
3515834aaeSGreg Roachclass CensusAssistantModule extends AbstractModule {
368c2e8227SGreg Roach	/** {@inheritdoc} */
378c2e8227SGreg Roach	public function getTitle() {
388c2e8227SGreg Roach		return /* I18N: Name of a module */ I18N::translate('Census assistant');
398c2e8227SGreg Roach	}
408c2e8227SGreg Roach
418c2e8227SGreg Roach	/** {@inheritdoc} */
428c2e8227SGreg Roach	public function getDescription() {
438c2e8227SGreg Roach		return /* I18N: Description of the “Census assistant” module */ I18N::translate('An alternative way to enter census transcripts and link them to individuals.');
448c2e8227SGreg Roach	}
458c2e8227SGreg Roach
4676692c8bSGreg Roach	/**
4776692c8bSGreg Roach	 * This is a general purpose hook, allowing modules to respond to routes
4876692c8bSGreg Roach	 * of the form module.php?mod=FOO&mod_action=BAR
4976692c8bSGreg Roach	 *
5076692c8bSGreg Roach	 * @param string $mod_action
5176692c8bSGreg Roach	 */
528c2e8227SGreg Roach	public function modAction($mod_action) {
538c2e8227SGreg Roach		switch ($mod_action) {
5440990b78SGreg Roach		case 'census_find':
5540990b78SGreg Roach			self::censusFind();
568c2e8227SGreg Roach			break;
5740990b78SGreg Roach		case 'media_find':
58764a01d9SGreg Roach			self::mediaFind();
598c2e8227SGreg Roach			break;
608c2e8227SGreg Roach		case 'media_query_3a':
61764a01d9SGreg Roach			self::mediaQuery();
628c2e8227SGreg Roach			break;
638c2e8227SGreg Roach		default:
648c2e8227SGreg Roach			http_response_code(404);
658c2e8227SGreg Roach		}
668c2e8227SGreg Roach	}
678c2e8227SGreg Roach
688c2e8227SGreg Roach	/**
6976692c8bSGreg Roach	 * Find an individual.
708c2e8227SGreg Roach	 */
7140990b78SGreg Roach	private static function censusFind() {
7240990b78SGreg Roach		global $WT_TREE;
7340990b78SGreg Roach
7440990b78SGreg Roach		$controller = new SimpleController;
7540990b78SGreg Roach		$filter     = Filter::get('filter');
7640990b78SGreg Roach		$action     = Filter::get('action');
77ad51e0bbSGreg Roach		$census     = Filter::get('census');
78ad51e0bbSGreg Roach		$census     = new $census;
7940990b78SGreg Roach
8040990b78SGreg Roach		$controller
81ad51e0bbSGreg Roach			->restrictAccess($census instanceof CensusInterface)
8240990b78SGreg Roach			->setPageTitle(I18N::translate('Find an individual'))
8340990b78SGreg Roach			->pageHeader();
8440990b78SGreg Roach
85ad51e0bbSGreg Roach		echo '<table class="list_table width90" border="0">';
86a86dd8b1SGreg Roach		echo '<tr><td style="padding: 10px;" class="facts_label03 width90">';
8740990b78SGreg Roach		echo I18N::translate('Find an individual');
88ad51e0bbSGreg Roach		echo '</td>';
89ad51e0bbSGreg Roach		echo '</table>';
90ad51e0bbSGreg Roach		echo '<br>';
9140990b78SGreg Roach
92ad51e0bbSGreg Roach		if ($action == 'filter') {
9340990b78SGreg Roach			$filter       = trim($filter);
9440990b78SGreg Roach			$filter_array = explode(' ', preg_replace('/ {2,}/', ' ', $filter));
9540990b78SGreg Roach
9640990b78SGreg Roach			// Output Individual for GEDFact Assistant ======================
97ad51e0bbSGreg Roach			echo '<table class="list_table width90">';
983d7a8a4cSGreg Roach			$myindilist = FunctionsDb::searchIndividualNames($filter_array, array($WT_TREE));
9940990b78SGreg Roach			if ($myindilist) {
100ad51e0bbSGreg Roach				echo '<tr><td class="list_value_wrap"><ul>';
10140990b78SGreg Roach				usort($myindilist, '\Fisharebest\Webtrees\GedcomRecord::compare');
10240990b78SGreg Roach				foreach ($myindilist as $indi) {
103ad51e0bbSGreg Roach					echo '<li>';
1040b18a98dSGreg Roach					echo '<a href="#" onclick="window.opener.appendCensusRow(\'' . Filter::escapeJs(self::censusTableRow($census, $indi, null)) . '\'); window.close();">';
105ad51e0bbSGreg Roach					echo '<b>' . $indi->getFullName() . '</b>';
106ad51e0bbSGreg Roach					echo '</a>';
107ad51e0bbSGreg Roach					echo $indi->formatFirstMajorFact(WT_EVENTS_BIRT, 1);
108ad51e0bbSGreg Roach					echo $indi->formatFirstMajorFact(WT_EVENTS_DEAT, 1);
109ad51e0bbSGreg Roach					echo '<hr>';
110ad51e0bbSGreg Roach					echo '</li>';
11140990b78SGreg Roach				}
11240990b78SGreg Roach				echo '</ul></td></tr>';
11340990b78SGreg Roach			} else {
114ad51e0bbSGreg Roach				echo '<tr><td class="list_value_wrap">';
11540990b78SGreg Roach				echo I18N::translate('No results found.');
116ad51e0bbSGreg Roach				echo '</td></tr>';
11740990b78SGreg Roach			}
118ad51e0bbSGreg Roach			echo '<tr><td>';
11940990b78SGreg Roach			echo '<button onclick="window.close();">', I18N::translate('close'), '</button>';
120ad51e0bbSGreg Roach			echo '</td></tr>';
121ad51e0bbSGreg Roach			echo '</table>';
122ad51e0bbSGreg Roach		}
12340990b78SGreg Roach	}
12440990b78SGreg Roach
12540990b78SGreg Roach	/**
12676692c8bSGreg Roach	 * Find a media object.
12740990b78SGreg Roach	 */
128764a01d9SGreg Roach	private static function mediaFind() {
1298c2e8227SGreg Roach		global $WT_TREE;
1308c2e8227SGreg Roach
1318c2e8227SGreg Roach		$controller = new SimpleController;
1328c2e8227SGreg Roach		$filter     = Filter::get('filter');
1338c2e8227SGreg Roach		$multiple   = Filter::getBool('multiple');
1348c2e8227SGreg Roach
1358c2e8227SGreg Roach		$controller
1368c2e8227SGreg Roach			->setPageTitle(I18N::translate('Find an individual'))
1378c2e8227SGreg Roach			->pageHeader();
1388c2e8227SGreg Roach
1398c2e8227SGreg Roach		?>
14099f222b3SGreg Roach		<script>
1418c2e8227SGreg Roach		function pasterow(id, name, gend, yob, age, bpl) {
1428c2e8227SGreg Roach			window.opener.opener.insertRowToTable(id, name, '', gend, '', yob, age, 'Y', '', bpl);
1438c2e8227SGreg Roach		}
1448c2e8227SGreg Roach
1458c2e8227SGreg Roach		function pasteid(id, name, thumb) {
1468c2e8227SGreg Roach			if (thumb) {
1478c2e8227SGreg Roach				window.opener.paste_id(id, name, thumb);
14899f222b3SGreg Roach				<?php if (!$multiple) { echo "window.close();"; } ?>
1498c2e8227SGreg Roach			} else {
1508c2e8227SGreg Roach			// GEDFact_assistant ========================
1518c2e8227SGreg Roach			if (window.opener.document.getElementById('addlinkQueue')) {
1528c2e8227SGreg Roach				window.opener.insertRowToTable(id, name);
1538c2e8227SGreg Roach			}
1548c2e8227SGreg Roach			window.opener.paste_id(id);
1558c2e8227SGreg Roach			if (window.opener.pastename) {
1568c2e8227SGreg Roach				window.opener.pastename(name);
1578c2e8227SGreg Roach			}
15899f222b3SGreg Roach			<?php if (!$multiple) { echo "window.close();"; } ?>
1598c2e8227SGreg Roach			}
1608c2e8227SGreg Roach		}
1618c2e8227SGreg Roach		function checknames(frm) {
1628c2e8227SGreg Roach			if (document.forms[0].subclick) {
1638c2e8227SGreg Roach				button = document.forms[0].subclick.value;
1648c2e8227SGreg Roach			} else {
1658c2e8227SGreg Roach				button = "";
1668c2e8227SGreg Roach			}
167ad51e0bbSGreg Roach			if (frm.filter.value.length < 2 && button !== "all") {
16877e70a22SGreg Roach				alert("<?php echo I18N::translate('Please enter more than one character.'); ?>");
1698c2e8227SGreg Roach				frm.filter.focus();
1708c2e8227SGreg Roach				return false;
1718c2e8227SGreg Roach			}
1728c2e8227SGreg Roach			if (button=="all") {
1738c2e8227SGreg Roach				frm.filter.value = "";
1748c2e8227SGreg Roach			}
1758c2e8227SGreg Roach			return true;
1768c2e8227SGreg Roach		}
17799f222b3SGreg Roach		</script>
1788c2e8227SGreg Roach
17999f222b3SGreg Roach		<?php
180a86dd8b1SGreg Roach		echo '<div>';
1814c621133SGreg Roach		echo '<table class="list_table width90" border="0">';
182a86dd8b1SGreg Roach		echo '<tr><td style="padding: 10px;" class="facts_label03 width90">'; // start column for find text header
1838c2e8227SGreg Roach		echo $controller->getPageTitle();
1844c621133SGreg Roach		echo '</td>';
1854c621133SGreg Roach		echo '</tr>';
1864c621133SGreg Roach		echo '</table>';
1874c621133SGreg Roach		echo '<br>';
1888c2e8227SGreg Roach		echo '<button onclick="window.close();">', I18N::translate('close'), '</button>';
1894c621133SGreg Roach		echo '<br>';
1908c2e8227SGreg Roach
1918c2e8227SGreg Roach		$filter       = trim($filter);
1928c2e8227SGreg Roach		$filter_array = explode(' ', preg_replace('/ {2,}/', ' ', $filter));
1934c621133SGreg Roach		echo '<table class="tabs_table width90"><tr>';
1943d7a8a4cSGreg Roach		$myindilist = FunctionsDb::searchIndividualNames($filter_array, array($WT_TREE));
1958c2e8227SGreg Roach		if ($myindilist) {
1964c621133SGreg Roach			echo '<td class="list_value_wrap"><ul>';
1970e62c4b8SGreg Roach			usort($myindilist, '\Fisharebest\Webtrees\GedcomRecord::compare');
1988c2e8227SGreg Roach			foreach ($myindilist as $indi) {
1998c2e8227SGreg Roach				$nam = Filter::escapeHtml($indi->getFullName());
2008c2e8227SGreg Roach				echo "<li><a href=\"#\" onclick=\"pasterow(
2018c2e8227SGreg Roach					'" . $indi->getXref() . "' ,
2028c2e8227SGreg Roach					'" . $nam . "' ,
2038c2e8227SGreg Roach					'" . $indi->getSex() . "' ,
2047820e4d7SGreg Roach					'" . $indi->getBirthYear() . "' ,
2057820e4d7SGreg Roach					'" . (1901 - $indi->getBirthYear()) . "' ,
2067820e4d7SGreg Roach					'" . $indi->getBirthPlace() . "'); return false;\">
2078c2e8227SGreg Roach					<b>" . $indi->getFullName() . "</b>&nbsp;&nbsp;&nbsp;";
2088c2e8227SGreg Roach
209764a01d9SGreg Roach				$born = GedcomTag::getLabel('BIRT');
2107820e4d7SGreg Roach				echo "</span><br><span class=\"list_item\">", $born, " ", $indi->getBirthYear(), "&nbsp;&nbsp;&nbsp;", $indi->getBirthPlace(), "</span></a></li>";
2118c2e8227SGreg Roach				echo "<hr>";
2128c2e8227SGreg Roach			}
2138c2e8227SGreg Roach			echo '</ul></td></tr><tr><td class="list_label">', I18N::translate('Total individuals: %s', count($myindilist)), '</tr></td>';
2148c2e8227SGreg Roach		} else {
2158c2e8227SGreg Roach			echo "<td class=\"list_value_wrap\">";
2168c2e8227SGreg Roach			echo I18N::translate('No results found.');
2178c2e8227SGreg Roach			echo "</td></tr>";
2188c2e8227SGreg Roach		}
2198c2e8227SGreg Roach		echo "</table>";
2208c2e8227SGreg Roach		echo '</div>';
2218c2e8227SGreg Roach	}
2228c2e8227SGreg Roach
2238c2e8227SGreg Roach	/**
22476692c8bSGreg Roach	 * Search for a media object.
2258c2e8227SGreg Roach	 */
226764a01d9SGreg Roach	private static function mediaQuery() {
22724ec66ceSGreg Roach		global $WT_TREE;
22824ec66ceSGreg Roach
2298c2e8227SGreg Roach		$iid2 = Filter::get('iid', WT_REGEX_XREF);
2308c2e8227SGreg Roach
2318c2e8227SGreg Roach		$controller = new SimpleController;
2328c2e8227SGreg Roach		$controller
2338c2e8227SGreg Roach			->setPageTitle(I18N::translate('Link to an existing media object'))
2348c2e8227SGreg Roach			->pageHeader();
2358c2e8227SGreg Roach
23624ec66ceSGreg Roach		$record = GedcomRecord::getInstance($iid2, $WT_TREE);
2378c2e8227SGreg Roach		if ($record) {
2388c2e8227SGreg Roach			$headjs = '';
2398c2e8227SGreg Roach			if ($record instanceof Family) {
2408c2e8227SGreg Roach				if ($record->getHusband()) {
2418c2e8227SGreg Roach					$headjs = $record->getHusband()->getXref();
2428c2e8227SGreg Roach				} elseif ($record->getWife()) {
2438c2e8227SGreg Roach					$headjs = $record->getWife()->getXref();
2448c2e8227SGreg Roach				}
2458c2e8227SGreg Roach			}
2468c2e8227SGreg Roach			?>
2478c2e8227SGreg Roach			<script>
2488c2e8227SGreg Roach				function insertId() {
2498c2e8227SGreg Roach					if (window.opener.document.getElementById('addlinkQueue')) {
2508c2e8227SGreg Roach						// alert('Please move this alert window and examine the contents of the pop-up window, then click OK')
2517820e4d7SGreg Roach						window.opener.insertRowToTable('<?php echo $record->getXref(); ?>', '<?php echo htmlspecialchars($record->getFullName()); ?>', '<?php echo $headjs; ?>');
2528c2e8227SGreg Roach						window.close();
2538c2e8227SGreg Roach					}
2548c2e8227SGreg Roach				}
2558c2e8227SGreg Roach			</script>
2568c2e8227SGreg Roach			<?php
2578c2e8227SGreg Roach		} else {
2588c2e8227SGreg Roach			?>
2598c2e8227SGreg Roach			<script>
2608c2e8227SGreg Roach				function insertId() {
26177e70a22SGreg Roach					window.opener.alert('<?php echo $iid2; ?> - <?php echo I18N::translate('Not a valid individual, family, or source ID'); ?>');
2628c2e8227SGreg Roach					window.close();
2638c2e8227SGreg Roach				}
2648c2e8227SGreg Roach			</script>
2658c2e8227SGreg Roach			<?php
2668c2e8227SGreg Roach		}
2678c2e8227SGreg Roach		?>
2688c2e8227SGreg Roach		<script>window.onLoad = insertId();</script>
2698c2e8227SGreg Roach		<?php
2708c2e8227SGreg Roach	}
2718c2e8227SGreg Roach
2728c2e8227SGreg Roach	/**
2738c2e8227SGreg Roach	 * Convert custom markup into HTML
2748c2e8227SGreg Roach	 *
2758c2e8227SGreg Roach	 * @param Note $note
2768c2e8227SGreg Roach	 *
2778c2e8227SGreg Roach	 * @return string
2788c2e8227SGreg Roach	 */
2798c2e8227SGreg Roach	public static function formatCensusNote(Note $note) {
2808c2e8227SGreg Roach		global $WT_TREE;
2818c2e8227SGreg Roach
282*3a7bc14aSDavid Drury
283*3a7bc14aSDavid Drury		$headers = array();
284*3a7bc14aSDavid Drury		foreach (Census::allCensusPlaces() as $allCensusesOfPlace) {
285*3a7bc14aSDavid Drury			foreach ($allCensusesOfPlace->allCensusDates() as $census) {
286*3a7bc14aSDavid Drury				foreach ($census->columns() as $column) {
287*3a7bc14aSDavid Drury					if ($column->abbreviation()) {
288*3a7bc14aSDavid Drury						$headers[$column->abbreviation()] = $column->title();
289*3a7bc14aSDavid Drury					}
290*3a7bc14aSDavid Drury				}
291*3a7bc14aSDavid Drury			}
292*3a7bc14aSDavid Drury		}
2938c2e8227SGreg Roach
2948c2e8227SGreg Roach		if (preg_match('/(.*)((?:\n.*)*)\n\.start_formatted_area\.\n(.*)((?:\n.*)*)\n.end_formatted_area\.((?:\n.*)*)/', $note->getNote(), $match)) {
2958c2e8227SGreg Roach			// This looks like a census-assistant shared note
2968c2e8227SGreg Roach			$title     = Filter::escapeHtml($match[1]);
2978c2e8227SGreg Roach			$preamble  = Filter::escapeHtml($match[2]);
2988c2e8227SGreg Roach			$header    = Filter::escapeHtml($match[3]);
2998c2e8227SGreg Roach			$data      = Filter::escapeHtml($match[4]);
3008c2e8227SGreg Roach			$postamble = Filter::escapeHtml($match[5]);
3018c2e8227SGreg Roach
3028c2e8227SGreg Roach			$fmt_headers = array();
3038c2e8227SGreg Roach			foreach ($headers as $key => $value) {
304ad51e0bbSGreg Roach				$fmt_headers[$key] = '<span title="' . Filter::escapeHtml($value) . '">' . $key . '</span>';
3058c2e8227SGreg Roach			}
3068c2e8227SGreg Roach
3078c2e8227SGreg Roach			// Substitue header labels and format as HTML
3088c2e8227SGreg Roach			$thead = '<tr><th>' . strtr(str_replace('|', '</th><th>', $header), $fmt_headers) . '</th></tr>';
309ad51e0bbSGreg Roach			$thead = str_replace('.b.', '', $thead);
3108c2e8227SGreg Roach
3118c2e8227SGreg Roach			// Format data as HTML
3128c2e8227SGreg Roach			$tbody = '';
3138c2e8227SGreg Roach			foreach (explode("\n", $data) as $row) {
3148c2e8227SGreg Roach				$tbody .= '<tr>';
3158c2e8227SGreg Roach				foreach (explode('|', $row) as $column) {
3168c2e8227SGreg Roach					$tbody .= '<td>' . $column . '</td>';
3178c2e8227SGreg Roach				}
3188c2e8227SGreg Roach				$tbody .= '</tr>';
3198c2e8227SGreg Roach			}
3208c2e8227SGreg Roach
3218c2e8227SGreg Roach			return
3228c2e8227SGreg Roach				$title . "\n" . // The newline allows the framework to expand the details and turn the first line into a link
3238c2e8227SGreg Roach				'<p>' . $preamble . '</p>' .
3248c2e8227SGreg Roach				'<table class="table-census-assistant">' .
3258c2e8227SGreg Roach				'<thead>' . $thead . '</thead>' .
3268c2e8227SGreg Roach				'<tbody>' . $tbody . '</tbody>' .
3278c2e8227SGreg Roach				'</table>' .
3288c2e8227SGreg Roach				'<p>' . $postamble . '</p>';
3298c2e8227SGreg Roach		} else {
3308c2e8227SGreg Roach			// Not a census-assistant shared note - apply default formatting
3318c2e8227SGreg Roach			return Filter::formatText($note->getNote(), $WT_TREE);
3328c2e8227SGreg Roach		}
3338c2e8227SGreg Roach	}
33499f222b3SGreg Roach
33599f222b3SGreg Roach	/**
336ad51e0bbSGreg Roach	 * Generate an HTML row of data for the census header
33799f222b3SGreg Roach	 *
33852bc9faeSGreg Roach	 * Add prefix cell (store XREF and drag/drop)
33952bc9faeSGreg Roach	 * Add suffix cell (delete button)
34052bc9faeSGreg Roach	 *
341ad51e0bbSGreg Roach	 * @param CensusInterface $census
34299f222b3SGreg Roach	 *
343ad51e0bbSGreg Roach	 * @return string
34499f222b3SGreg Roach	 */
345ad51e0bbSGreg Roach	public static function censusTableHeader(CensusInterface $census) {
34652bc9faeSGreg Roach		$html = '';
347ad51e0bbSGreg Roach		foreach ($census->columns() as $column) {
348ad51e0bbSGreg Roach			$html .= '<th title="' . $column->title() . '">' . $column->abbreviation() . '</th>';
34999f222b3SGreg Roach		}
35099f222b3SGreg Roach
35152bc9faeSGreg Roach		return '<tr><th hidden></th>' . $html . '<th></th></th></tr>';
352ad51e0bbSGreg Roach	}
35399f222b3SGreg Roach
354ad51e0bbSGreg Roach	/**
355ad51e0bbSGreg Roach	 * Generate an HTML row of data for the census
356ad51e0bbSGreg Roach	 *
35752bc9faeSGreg Roach	 * Add prefix cell (store XREF and drag/drop)
35852bc9faeSGreg Roach	 * Add suffix cell (delete button)
35952bc9faeSGreg Roach	 *
360ad51e0bbSGreg Roach	 * @param CensusInterface $census
361ad51e0bbSGreg Roach	 *
362ad51e0bbSGreg Roach	 * @return string
363ad51e0bbSGreg Roach	 */
364ad51e0bbSGreg Roach	public static function censusTableEmptyRow(CensusInterface $census) {
36552bc9faeSGreg 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>';
366ad51e0bbSGreg Roach	}
36799f222b3SGreg Roach
368ad51e0bbSGreg Roach	/**
369ad51e0bbSGreg Roach	 * Generate an HTML row of data for the census
370ad51e0bbSGreg Roach	 *
37152bc9faeSGreg Roach	 * Add prefix cell (store XREF and drag/drop)
37252bc9faeSGreg Roach	 * Add suffix cell (delete button)
37352bc9faeSGreg Roach	 *
374ad51e0bbSGreg Roach	 * @param CensusInterface $census
375ad51e0bbSGreg Roach	 * @param Individual      $individual
376ad51e0bbSGreg Roach	 * @param Individual|null $head
377ad51e0bbSGreg Roach	 *
378ad51e0bbSGreg Roach	 * @return string
379ad51e0bbSGreg Roach	 */
380ad51e0bbSGreg Roach	public static function censusTableRow(CensusInterface $census, Individual $individual, Individual $head = null) {
38152bc9faeSGreg Roach		$html = '';
382ad51e0bbSGreg Roach		foreach ($census->columns() as $column) {
383ad51e0bbSGreg Roach			$html .= '<td><input type="text" value="' . $column->generate($individual, $head) . '"></td>';
384ad51e0bbSGreg Roach		}
385ad51e0bbSGreg Roach
38652bc9faeSGreg Roach		return '<tr><td hidden>' . $individual->getXref() . '</td>' . $html . '<td><a class="icon-remove" href="#" title="' . I18N::translate('Remove') . '"></a></td></tr>';
387ad51e0bbSGreg Roach	}
388ad51e0bbSGreg Roach
389ad51e0bbSGreg Roach	/**
390ad51e0bbSGreg Roach	 * Create a family on the census navigator.
391ad51e0bbSGreg Roach	 *
392ad51e0bbSGreg Roach	 * @param CensusInterface $census
393ad51e0bbSGreg Roach	 * @param Family          $family
394ad51e0bbSGreg Roach	 * @param Individual      $head
395ad51e0bbSGreg Roach	 *
396ad51e0bbSGreg Roach	 * @return string
397ad51e0bbSGreg Roach	 */
398ad51e0bbSGreg Roach	public static function censusNavigatorFamily(CensusInterface $census, Family $family, Individual $head) {
399ad51e0bbSGreg Roach		$headImg2  = '<i class="icon-button_head" title="' . I18N::translate('Click to choose individual as head of family.') . '"></i>';
400ad51e0bbSGreg Roach
401ad51e0bbSGreg Roach		foreach ($family->getSpouses() as $spouse) {
402ad51e0bbSGreg Roach			$menu  = new Menu(Functions::getCloseRelationshipName($head, $spouse));
403ad51e0bbSGreg Roach			foreach ($spouse->getChildFamilies() as $grandparents) {
404ad51e0bbSGreg Roach				foreach ($grandparents->getSpouses() as $grandparent) {
405ad51e0bbSGreg Roach					$submenu = new Menu(
406ad51e0bbSGreg Roach						Functions::getCloseRelationshipName($head, $grandparent) . ' - ' . $grandparent->getFullName(),
407ad51e0bbSGreg Roach						'#',
408ad51e0bbSGreg Roach						'',
4090b18a98dSGreg Roach						array('onclick' => 'return appendCensusRow("' . Filter::escapeJs(self::censusTableRow($census, $grandparent, $head)) . '");')
410ad51e0bbSGreg Roach					);
411ad51e0bbSGreg Roach					$submenu->addClass('submenuitem', '');
412ad51e0bbSGreg Roach					$menu->addSubmenu($submenu);
413ad51e0bbSGreg Roach					$menu->addClass('', 'submenu');
41499f222b3SGreg Roach				}
41599f222b3SGreg Roach			}
41699f222b3SGreg Roach
417ad51e0bbSGreg Roach			?>
418ad51e0bbSGreg Roach			<tr>
419ad51e0bbSGreg Roach				<td class="optionbox">
420ad51e0bbSGreg Roach					<?php echo $menu->getMenu(); ?>
421ad51e0bbSGreg Roach				</td>
422ad51e0bbSGreg Roach				<td class="facts_value nowrap">
4230b18a98dSGreg Roach					<a href="#" onclick="return appendCensusRow('<?php echo Filter::escapeJs(self::censusTableRow($census, $spouse, $head)); ?>');">
424ad51e0bbSGreg Roach						<?php echo $spouse->getFullName(); ?>
425ad51e0bbSGreg Roach					</a>
426ad51e0bbSGreg Roach				</td>
427a86dd8b1SGreg Roach				<td class="facts_value">
428ad51e0bbSGreg 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); ?>">
429ad51e0bbSGreg Roach						<?php echo $headImg2; ?>
430ad51e0bbSGreg Roach					</a>
431ad51e0bbSGreg Roach				</td>
432ad51e0bbSGreg Roach			</tr>
433ad51e0bbSGreg Roach			<?php
43499f222b3SGreg Roach		}
435ad51e0bbSGreg Roach
436ad51e0bbSGreg Roach		foreach ($family->getChildren() as $child) {
437ad51e0bbSGreg Roach			$menu  = new Menu(Functions::getCloseRelationshipName($head, $child));
438ad51e0bbSGreg Roach			foreach ($child->getSpouseFamilies() as $spouse_family) {
439ad51e0bbSGreg Roach				foreach ($spouse_family->getSpouses() as $spouse_family_spouse) {
440ad51e0bbSGreg Roach					if ($spouse_family_spouse != $child) {
441ad51e0bbSGreg Roach						$submenu = new Menu(
442ad51e0bbSGreg Roach							Functions::getCloseRelationshipName($head, $spouse_family_spouse) . ' - ' . $spouse_family_spouse->getFullName(),
443ad51e0bbSGreg Roach							'#',
444ad51e0bbSGreg Roach							'',
4450b18a98dSGreg Roach							array('onclick' => 'return appendCensusRow("' . Filter::escapeJs(self::censusTableRow($census, $spouse_family_spouse, $head)) . '");')
446ad51e0bbSGreg Roach						);
447ad51e0bbSGreg Roach						$submenu->addClass('submenuitem', '');
448ad51e0bbSGreg Roach						$menu->addSubmenu($submenu);
449ad51e0bbSGreg Roach						$menu->addClass('', 'submenu');
450ad51e0bbSGreg Roach					}
451ad51e0bbSGreg Roach				}
452ad51e0bbSGreg Roach				foreach ($spouse_family->getChildren() as $spouse_family_child) {
453ad51e0bbSGreg Roach					$submenu = new Menu(
454ad51e0bbSGreg Roach						Functions::getCloseRelationshipName($head, $spouse_family_child) . ' - ' . $spouse_family_child->getFullName(),
455ad51e0bbSGreg Roach						'#',
456ad51e0bbSGreg Roach						'',
4570b18a98dSGreg Roach						array('onclick' => 'return appendCensusRow("' . Filter::escapeJs(self::censusTableRow($census, $spouse_family_child, $head)) . '");')
458ad51e0bbSGreg Roach					);
459ad51e0bbSGreg Roach					$submenu->addClass('submenuitem', '');
460ad51e0bbSGreg Roach					$menu->addSubmenu($submenu);
461ad51e0bbSGreg Roach					$menu->addClass('', 'submenu');
46299f222b3SGreg Roach				}
46399f222b3SGreg Roach			}
46499f222b3SGreg Roach
465ad51e0bbSGreg Roach			?>
466ad51e0bbSGreg Roach			<tr>
467ad51e0bbSGreg Roach				<td class="optionbox">
468ad51e0bbSGreg Roach					<?php echo $menu->getMenu(); ?>
469ad51e0bbSGreg Roach				</td>
470ad51e0bbSGreg Roach				<td class="facts_value">
4710b18a98dSGreg Roach					<a href="#" onclick="return appendCensusRow('<?php echo Filter::escapeJs(self::censusTableRow($census, $child, $head)); ?>');">
472ad51e0bbSGreg Roach						<?php echo $child->getFullName(); ?>
473ad51e0bbSGreg Roach					</a>
474ad51e0bbSGreg Roach				</td>
475ad51e0bbSGreg Roach				<td class="facts_value">
476ad51e0bbSGreg 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); ?>">
477ad51e0bbSGreg Roach						<?php echo $headImg2; ?>
478ad51e0bbSGreg Roach					</a>
479ad51e0bbSGreg Roach				</td>
480ad51e0bbSGreg Roach			</tr>
481ad51e0bbSGreg Roach			<?php
48299f222b3SGreg Roach		}
483ad51e0bbSGreg Roach		echo '<tr><td><br></td></tr>';
48499f222b3SGreg Roach	}
4858c2e8227SGreg Roach}
486