18c2e8227SGreg Roach<?php 28c2e8227SGreg Roach/** 38c2e8227SGreg Roach * webtrees: online genealogy 48c2e8227SGreg Roach * Copyright (C) 2015 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*4c00bbb9SGreg Roachuse Fisharebest\Webtrees\Census\Census; 19*4c00bbb9SGreg Roachuse Fisharebest\Webtrees\Census\CensusOfDenmark; 20*4c00bbb9SGreg Roachuse Fisharebest\Webtrees\Census\CensusOfEngland; 21*4c00bbb9SGreg Roachuse Fisharebest\Webtrees\Census\CensusOfFrance; 22*4c00bbb9SGreg Roachuse Fisharebest\Webtrees\Census\CensusOfScotland; 23*4c00bbb9SGreg Roachuse Fisharebest\Webtrees\Census\CensusOfUnitedStates; 24*4c00bbb9SGreg Roachuse Fisharebest\Webtrees\Census\CensusOfWales; 250e62c4b8SGreg Roachuse Fisharebest\Webtrees\Controller\SimpleController; 26*4c00bbb9SGreg Roachuse Fisharebest\Webtrees\Date; 270e62c4b8SGreg Roachuse Fisharebest\Webtrees\Family; 280e62c4b8SGreg Roachuse Fisharebest\Webtrees\Filter; 293d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsDb; 300e62c4b8SGreg Roachuse Fisharebest\Webtrees\GedcomRecord; 310e62c4b8SGreg Roachuse Fisharebest\Webtrees\GedcomTag; 320e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N; 330e62c4b8SGreg Roachuse Fisharebest\Webtrees\Individual; 340e62c4b8SGreg Roachuse Fisharebest\Webtrees\Note; 358c2e8227SGreg Roach 368c2e8227SGreg Roach/** 378c2e8227SGreg Roach * Class CensusAssistantModule 388c2e8227SGreg Roach */ 3915834aaeSGreg Roachclass CensusAssistantModule extends AbstractModule { 408c2e8227SGreg Roach /** {@inheritdoc} */ 418c2e8227SGreg Roach public function getTitle() { 428c2e8227SGreg Roach return /* I18N: Name of a module */ I18N::translate('Census assistant'); 438c2e8227SGreg Roach } 448c2e8227SGreg Roach 458c2e8227SGreg Roach /** {@inheritdoc} */ 468c2e8227SGreg Roach public function getDescription() { 478c2e8227SGreg Roach return /* I18N: Description of the “Census assistant” module */ I18N::translate('An alternative way to enter census transcripts and link them to individuals.'); 488c2e8227SGreg Roach } 498c2e8227SGreg Roach 5076692c8bSGreg Roach /** 5176692c8bSGreg Roach * This is a general purpose hook, allowing modules to respond to routes 5276692c8bSGreg Roach * of the form module.php?mod=FOO&mod_action=BAR 5376692c8bSGreg Roach * 5476692c8bSGreg Roach * @param string $mod_action 5576692c8bSGreg Roach */ 568c2e8227SGreg Roach public function modAction($mod_action) { 578c2e8227SGreg Roach switch ($mod_action) { 5840990b78SGreg Roach case 'census_find': 5940990b78SGreg Roach self::censusFind(); 608c2e8227SGreg Roach break; 6140990b78SGreg Roach case 'media_find': 62764a01d9SGreg Roach self::mediaFind(); 638c2e8227SGreg Roach break; 648c2e8227SGreg Roach case 'media_query_3a': 65764a01d9SGreg Roach self::mediaQuery(); 668c2e8227SGreg Roach break; 678c2e8227SGreg Roach default: 688c2e8227SGreg Roach http_response_code(404); 698c2e8227SGreg Roach } 708c2e8227SGreg Roach } 718c2e8227SGreg Roach 728c2e8227SGreg Roach /** 7376692c8bSGreg Roach * Find an individual. 748c2e8227SGreg Roach */ 7540990b78SGreg Roach private static function censusFind() { 7640990b78SGreg Roach global $WT_TREE; 7740990b78SGreg Roach 7840990b78SGreg Roach $controller = new SimpleController; 7940990b78SGreg Roach 8040990b78SGreg Roach $filter = Filter::get('filter'); 8140990b78SGreg Roach $action = Filter::get('action'); 8240990b78SGreg Roach $callback = Filter::get('callback'); 8340990b78SGreg Roach $multiple = Filter::getBool('multiple'); 8440990b78SGreg Roach 8540990b78SGreg Roach $controller 8640990b78SGreg Roach ->setPageTitle(I18N::translate('Find an individual')) 8740990b78SGreg Roach ->pageHeader(); 8840990b78SGreg Roach 8940990b78SGreg Roach ?> 9040990b78SGreg Roach <script> 9140990b78SGreg Roach function pasterow(id, nam, mnam, label, gend, cond, dom, dob, dod, occu, age, birthpl, fbirthpl, mbirthpl, chilBLD) { 9240990b78SGreg Roach window.opener.insertRowToTable(id, nam, mnam, label, gend, cond, dom, dob, dod, occu, age, birthpl, fbirthpl, mbirthpl, chilBLD); 9340990b78SGreg Roach <?php if (!$multiple) echo "window.close();"; ?> 9440990b78SGreg Roach } 9540990b78SGreg Roach 9640990b78SGreg Roach function pasteid(id, name, thumb) { 9740990b78SGreg Roach if (thumb) { 9840990b78SGreg Roach window.opener.<?php echo $callback; ?>(id, name, thumb); 9940990b78SGreg Roach <?php if (!$multiple) echo "window.close();"; ?> 10040990b78SGreg Roach } else { 10140990b78SGreg Roach // GEDFact_assistant ======================== 10240990b78SGreg Roach if (window.opener.document.getElementById('addlinkQueue')) { 10340990b78SGreg Roach window.opener.insertRowToTable(id, name); 10440990b78SGreg Roach } 10540990b78SGreg Roach window.opener.<?php echo $callback; ?>(id); 10640990b78SGreg Roach if (window.opener.pastename) { 10740990b78SGreg Roach window.opener.pastename(name); 10840990b78SGreg Roach } 10940990b78SGreg Roach <?php if (!$multiple) echo "window.close();"; ?> 11040990b78SGreg Roach } 11140990b78SGreg Roach } 11240990b78SGreg Roach </script> 11340990b78SGreg Roach <?php 11440990b78SGreg Roach 11540990b78SGreg Roach echo "<div align=\"center\">"; 11640990b78SGreg Roach echo "<table class=\"list_table width90\" border=\"0\">"; 11740990b78SGreg Roach echo "<tr><td style=\"padding: 10px;\" valign=\"top\" class=\"facts_label03 width90\">"; 11840990b78SGreg Roach echo I18N::translate('Find an individual'); 11940990b78SGreg Roach echo "</td>"; 12040990b78SGreg Roach echo "</table>"; 12140990b78SGreg Roach echo "<br>"; 12240990b78SGreg Roach 12340990b78SGreg Roach if ($action == "filter") { 12440990b78SGreg Roach $filter = trim($filter); 12540990b78SGreg Roach $filter_array = explode(' ', preg_replace('/ {2,}/', ' ', $filter)); 12640990b78SGreg Roach 12740990b78SGreg Roach // Output Individual for GEDFact Assistant ====================== 12840990b78SGreg Roach echo "<table class=\"tabs_table width90\">"; 1293d7a8a4cSGreg Roach $myindilist = FunctionsDb::searchIndividualNames($filter_array, array($WT_TREE)); 13040990b78SGreg Roach if ($myindilist) { 13140990b78SGreg Roach echo "<tr><td class=\"list_value_wrap\"><ul>"; 13240990b78SGreg Roach usort($myindilist, '\Fisharebest\Webtrees\GedcomRecord::compare'); 13340990b78SGreg Roach foreach ($myindilist as $indi) { 13440990b78SGreg Roach $nam = $indi->getAllNames(); 13540990b78SGreg Roach $wholename = rtrim($nam[0]['givn'], '*') . " " . $nam[0]['surname']; 13640990b78SGreg Roach $fulln = rtrim($nam[0]['givn'], '*') . " " . $nam[0]['surname']; 13740990b78SGreg Roach $fulln = str_replace('"', '\'', $fulln); // Replace double quotes 13840990b78SGreg Roach $fulln = str_replace("@N.N.", "(" . I18N::translate('unknown') . ")", $fulln); 13940990b78SGreg Roach $fulln = str_replace("@P.N.", "(" . I18N::translate('unknown') . ")", $fulln); 14040990b78SGreg Roach $givn = rtrim($nam[0]['givn'], '*'); 14140990b78SGreg Roach $surn = $nam[0]['surname']; 14240990b78SGreg Roach if (isset($nam[1])) { 14340990b78SGreg Roach $fulmn = rtrim($nam[1]['givn'], '*') . " " . $nam[1]['surname']; 14440990b78SGreg Roach $fulmn = str_replace('"', '\'', $fulmn); // Replace double quotes 14540990b78SGreg Roach $fulmn = str_replace("@N.N.", "(" . I18N::translate('unknown') . ")", $fulmn); 14640990b78SGreg Roach $fulmn = str_replace("@P.N.", "(" . I18N::translate('unknown') . ")", $fulmn); 14740990b78SGreg Roach $marn = $nam[1]['surname']; 14840990b78SGreg Roach } else { 14940990b78SGreg Roach $fulmn = $fulln; 15040990b78SGreg Roach } 15140990b78SGreg Roach 15240990b78SGreg Roach //-- Build Indi Parents Family to get FBP and MBP ----------- 15340990b78SGreg Roach foreach ($indi->getChildFamilies() as $family) { 15440990b78SGreg Roach $father = $family->getHusband(); 15540990b78SGreg Roach $mother = $family->getWife(); 15640990b78SGreg Roach if (!is_null($father)) { 15740990b78SGreg Roach $FBP = $father->getBirthPlace(); 15840990b78SGreg Roach } 15940990b78SGreg Roach if (!is_null($mother)) { 16040990b78SGreg Roach $MBP = $mother->getBirthPlace(); 16140990b78SGreg Roach } 16240990b78SGreg Roach } 16340990b78SGreg Roach if (!isset($FBP)) { $FBP = "UNK, UNK, UNK, UNK"; } 16440990b78SGreg Roach if (!isset($MBP)) { $MBP = "UNK, UNK, UNK, UNK"; } 16540990b78SGreg Roach 16640990b78SGreg Roach //-- Build Indi Spouse Family to get marriage Date ---------- 16740990b78SGreg Roach foreach ($indi->getSpouseFamilies() as $family) { 16840990b78SGreg Roach $marrdate = $family->getMarriageDate(); 16940990b78SGreg Roach $marrdate = ($marrdate->minimumJulianDay() + $marrdate->maximumJulianDay()) / 2; // Julian 17040990b78SGreg Roach $children = $family->getChildren(); 17140990b78SGreg Roach } 17240990b78SGreg Roach if (!isset($marrdate)) { $marrdate = ""; } 17340990b78SGreg Roach 17440990b78SGreg Roach //-- Get Children’s Name, DOB, DOD -------------------------- 17540990b78SGreg Roach $chBLDarray = array(); 17640990b78SGreg Roach if (isset($children)) { 17740990b78SGreg Roach foreach ($children as $key => $child) { 17840990b78SGreg Roach $chnam = $child->getAllNames(); 17940990b78SGreg Roach $chfulln = rtrim($chnam[0]['givn'], '*') . " " . $chnam[0]['surname']; 18040990b78SGreg Roach $chfulln = str_replace('"', "", $chfulln); // Must remove quotes completely here 18140990b78SGreg Roach $chfulln = str_replace("@N.N.", "(" . I18N::translate('unknown') . ")", $chfulln); 18240990b78SGreg Roach $chfulln = str_replace("@P.N.", "(" . I18N::translate('unknown') . ")", $chfulln); // Child’s Full Name 18340990b78SGreg Roach $chdob = ($child->getBirthDate()->minimumJulianDay() + $child->getBirthDate()->maximumJulianDay()) / 2; // Child’s Date of Birth (Julian) 18440990b78SGreg Roach if (!isset($chdob)) { $chdob = ""; } 18540990b78SGreg Roach $chdod = ($child->getDeathDate()->minimumJulianDay() + $child->getDeathDate()->maximumJulianDay()) / 2; // Child’s Date of Death (Julian) 18640990b78SGreg Roach if (!isset($chdod)) { $chdod = ""; } 18740990b78SGreg Roach $chBLD = ($chfulln . ", " . $chdob . ", " . $chdod); 18840990b78SGreg Roach array_push($chBLDarray, $chBLD); 18940990b78SGreg Roach } 19040990b78SGreg Roach } 19140990b78SGreg Roach if ($chBLDarray && $indi->getSex() == "F") { 19240990b78SGreg Roach $chBLDarray = implode("::", $chBLDarray); 19340990b78SGreg Roach } else { 19440990b78SGreg Roach $chBLDarray = ''; 19540990b78SGreg Roach } 19640990b78SGreg Roach 19740990b78SGreg Roach echo "<li>"; 19840990b78SGreg Roach echo "<a href=\"#\" onclick=\"window.opener.insertRowToTable("; 19940990b78SGreg Roach echo "'" . $indi->getXref() . "', "; // id - Indi Id 20040990b78SGreg Roach echo "'" . addslashes(strip_tags($fulln)) . "', "; // nam - Name 20140990b78SGreg Roach echo "'" . addslashes(strip_tags($fulmn)) . "', "; // mnam - Married Name 20240990b78SGreg Roach echo "'-', "; // label - Relation to Head of Household 20340990b78SGreg Roach echo "'" . $indi->getSex() . "', "; // gend - Sex 20440990b78SGreg Roach echo "'S', "; // cond - Marital Condition 20540990b78SGreg Roach echo "'" . $marrdate . "', "; // dom - Date of Marriage 20640990b78SGreg Roach echo "'" . (($indi->getBirthDate()->minimumJulianDay() + $indi->getBirthDate()->maximumJulianDay()) / 2) . "' ,"; // dob - Date of Birth 20740990b78SGreg Roach echo "'" . (1901 - $indi->getbirthyear()) . "' ,"; // ~age~ - Census Date minus YOB (Preliminary) 20840990b78SGreg Roach echo "'" . (($indi->getDeathDate()->minimumJulianDay() + $indi->getDeathDate()->maximumJulianDay()) / 2) . "' ,"; // dod - Date of Death 20940990b78SGreg Roach echo "'', "; // occu - Occupation 21040990b78SGreg Roach echo "'" . Filter::escapeHtml($indi->getbirthplace()) . "', "; // birthpl - Birthplace 21140990b78SGreg Roach echo "'" . $FBP . "', "; // fbirthpl - Father’s Birthplace 21240990b78SGreg Roach echo "'" . $MBP . "', "; // mbirthpl - Mother’s Birthplace 21340990b78SGreg Roach echo "'" . $chBLDarray . "'"; // chilBLD - Array of Children (name, birthdate, deathdate) 21440990b78SGreg Roach echo ");"; 21540990b78SGreg Roach echo "return false;\">"; 21640990b78SGreg Roach echo "<b>" . $indi->getFullName() . "</b> "; // Name Link 21740990b78SGreg Roach echo "</span><br><span class=\"list_item\">", GedcomTag::getLabel('BIRT', $indi), " ", $indi->getbirthyear(), " ", $indi->getbirthplace(), "</span>"; 21840990b78SGreg Roach echo "</a>"; 21940990b78SGreg Roach echo "</li>"; 22040990b78SGreg Roach echo "<hr>"; 22140990b78SGreg Roach } 22240990b78SGreg Roach echo '</ul></td></tr>'; 22340990b78SGreg Roach } else { 22440990b78SGreg Roach echo "<tr><td class=\"list_value_wrap\">"; 22540990b78SGreg Roach echo I18N::translate('No results found.'); 22640990b78SGreg Roach echo "</td></tr>"; 22740990b78SGreg Roach } 22840990b78SGreg Roach echo "</table>"; 22940990b78SGreg Roach } 23040990b78SGreg Roach echo '<button onclick="window.close();">', I18N::translate('close'), '</button>'; 23140990b78SGreg Roach echo "</div>"; // Close div that centers table 23240990b78SGreg Roach } 23340990b78SGreg Roach 23440990b78SGreg Roach /** 23576692c8bSGreg Roach * Find a media object. 23640990b78SGreg Roach */ 237764a01d9SGreg Roach private static function mediaFind() { 2388c2e8227SGreg Roach global $WT_TREE; 2398c2e8227SGreg Roach 2408c2e8227SGreg Roach $controller = new SimpleController; 2418c2e8227SGreg Roach $filter = Filter::get('filter'); 2428c2e8227SGreg Roach $multiple = Filter::getBool('multiple'); 2438c2e8227SGreg Roach 2448c2e8227SGreg Roach $controller 2458c2e8227SGreg Roach ->setPageTitle(I18N::translate('Find an individual')) 2468c2e8227SGreg Roach ->pageHeader(); 2478c2e8227SGreg Roach 2488c2e8227SGreg Roach echo '<script>'; 2498c2e8227SGreg Roach ?> 2508c2e8227SGreg Roach 2518c2e8227SGreg Roach function pasterow(id, name, gend, yob, age, bpl) { 2528c2e8227SGreg Roach window.opener.opener.insertRowToTable(id, name, '', gend, '', yob, age, 'Y', '', bpl); 2538c2e8227SGreg Roach } 2548c2e8227SGreg Roach 2558c2e8227SGreg Roach function pasteid(id, name, thumb) { 2568c2e8227SGreg Roach if (thumb) { 2578c2e8227SGreg Roach window.opener.paste_id(id, name, thumb); 2588c2e8227SGreg Roach <?php if (!$multiple) echo "window.close();"; ?> 2598c2e8227SGreg Roach } else { 2608c2e8227SGreg Roach // GEDFact_assistant ======================== 2618c2e8227SGreg Roach if (window.opener.document.getElementById('addlinkQueue')) { 2628c2e8227SGreg Roach window.opener.insertRowToTable(id, name); 2638c2e8227SGreg Roach } 2648c2e8227SGreg Roach window.opener.paste_id(id); 2658c2e8227SGreg Roach if (window.opener.pastename) { 2668c2e8227SGreg Roach window.opener.pastename(name); 2678c2e8227SGreg Roach } 2688c2e8227SGreg Roach <?php if (!$multiple) echo "window.close();"; ?> 2698c2e8227SGreg Roach } 2708c2e8227SGreg Roach } 2718c2e8227SGreg Roach function checknames(frm) { 2728c2e8227SGreg Roach if (document.forms[0].subclick) { 2738c2e8227SGreg Roach button = document.forms[0].subclick.value; 2748c2e8227SGreg Roach } else { 2758c2e8227SGreg Roach button = ""; 2768c2e8227SGreg Roach } 2778c2e8227SGreg Roach if (frm.filter.value.length<2&button!="all") { 27877e70a22SGreg Roach alert("<?php echo I18N::translate('Please enter more than one character.'); ?>"); 2798c2e8227SGreg Roach frm.filter.focus(); 2808c2e8227SGreg Roach return false; 2818c2e8227SGreg Roach } 2828c2e8227SGreg Roach if (button=="all") { 2838c2e8227SGreg Roach frm.filter.value = ""; 2848c2e8227SGreg Roach } 2858c2e8227SGreg Roach return true; 2868c2e8227SGreg Roach } 2878c2e8227SGreg Roach <?php 2888c2e8227SGreg Roach echo '</script>'; 2898c2e8227SGreg Roach 2908c2e8227SGreg Roach echo "<div align=\"center\">"; 2918c2e8227SGreg Roach echo "<table class=\"list_table width90\" border=\"0\">"; 2928c2e8227SGreg Roach echo "<tr><td style=\"padding: 10px;\" valign=\"top\" class=\"facts_label03 width90\">"; // start column for find text header 2938c2e8227SGreg Roach echo $controller->getPageTitle(); 2948c2e8227SGreg Roach echo "</td>"; 2958c2e8227SGreg Roach echo "</tr>"; 2968c2e8227SGreg Roach echo "</table>"; 2978c2e8227SGreg Roach echo "<br>"; 2988c2e8227SGreg Roach echo '<button onclick="window.close();">', I18N::translate('close'), '</button>'; 2998c2e8227SGreg Roach echo "<br>"; 3008c2e8227SGreg Roach 3018c2e8227SGreg Roach $filter = trim($filter); 3028c2e8227SGreg Roach $filter_array = explode(' ', preg_replace('/ {2,}/', ' ', $filter)); 3038c2e8227SGreg Roach echo "<table class=\"tabs_table width90\"><tr>"; 3043d7a8a4cSGreg Roach $myindilist = FunctionsDb::searchIndividualNames($filter_array, array($WT_TREE)); 3058c2e8227SGreg Roach if ($myindilist) { 3068c2e8227SGreg Roach echo "<td class=\"list_value_wrap\"><ul>"; 3070e62c4b8SGreg Roach usort($myindilist, '\Fisharebest\Webtrees\GedcomRecord::compare'); 3088c2e8227SGreg Roach foreach ($myindilist as $indi) { 3098c2e8227SGreg Roach $nam = Filter::escapeHtml($indi->getFullName()); 3108c2e8227SGreg Roach echo "<li><a href=\"#\" onclick=\"pasterow( 3118c2e8227SGreg Roach '" . $indi->getXref() . "' , 3128c2e8227SGreg Roach '" . $nam . "' , 3138c2e8227SGreg Roach '" . $indi->getSex() . "' , 3148c2e8227SGreg Roach '" . $indi->getbirthyear() . "' , 3158c2e8227SGreg Roach '" . (1901 - $indi->getbirthyear()) . "' , 3168c2e8227SGreg Roach '" . $indi->getbirthplace() . "'); return false;\"> 3178c2e8227SGreg Roach <b>" . $indi->getFullName() . "</b> "; 3188c2e8227SGreg Roach 319764a01d9SGreg Roach $born = GedcomTag::getLabel('BIRT'); 3208c2e8227SGreg Roach echo "</span><br><span class=\"list_item\">", $born, " ", $indi->getbirthyear(), " ", $indi->getbirthplace(), "</span></a></li>"; 3218c2e8227SGreg Roach echo "<hr>"; 3228c2e8227SGreg Roach } 3238c2e8227SGreg Roach echo '</ul></td></tr><tr><td class="list_label">', I18N::translate('Total individuals: %s', count($myindilist)), '</tr></td>'; 3248c2e8227SGreg Roach } else { 3258c2e8227SGreg Roach echo "<td class=\"list_value_wrap\">"; 3268c2e8227SGreg Roach echo I18N::translate('No results found.'); 3278c2e8227SGreg Roach echo "</td></tr>"; 3288c2e8227SGreg Roach } 3298c2e8227SGreg Roach echo "</table>"; 3308c2e8227SGreg Roach echo '</div>'; 3318c2e8227SGreg Roach } 3328c2e8227SGreg Roach 3338c2e8227SGreg Roach /** 33476692c8bSGreg Roach * Search for a media object. 3358c2e8227SGreg Roach */ 336764a01d9SGreg Roach private static function mediaQuery() { 33724ec66ceSGreg Roach global $WT_TREE; 33824ec66ceSGreg Roach 3398c2e8227SGreg Roach $iid2 = Filter::get('iid', WT_REGEX_XREF); 3408c2e8227SGreg Roach 3418c2e8227SGreg Roach $controller = new SimpleController; 3428c2e8227SGreg Roach $controller 3438c2e8227SGreg Roach ->setPageTitle(I18N::translate('Link to an existing media object')) 3448c2e8227SGreg Roach ->pageHeader(); 3458c2e8227SGreg Roach 34624ec66ceSGreg Roach $record = GedcomRecord::getInstance($iid2, $WT_TREE); 3478c2e8227SGreg Roach if ($record) { 3488c2e8227SGreg Roach $headjs = ''; 3498c2e8227SGreg Roach if ($record instanceof Family) { 3508c2e8227SGreg Roach if ($record->getHusband()) { 3518c2e8227SGreg Roach $headjs = $record->getHusband()->getXref(); 3528c2e8227SGreg Roach } elseif ($record->getWife()) { 3538c2e8227SGreg Roach $headjs = $record->getWife()->getXref(); 3548c2e8227SGreg Roach } 3558c2e8227SGreg Roach } 3568c2e8227SGreg Roach ?> 3578c2e8227SGreg Roach <script> 3588c2e8227SGreg Roach function insertId() { 3598c2e8227SGreg Roach if (window.opener.document.getElementById('addlinkQueue')) { 3608c2e8227SGreg Roach // alert('Please move this alert window and examine the contents of the pop-up window, then click OK') 3618c2e8227SGreg Roach window.opener.insertRowToTable('<?php echo $record->getXref(); ?>', '<?php echo htmlSpecialChars($record->getFullName()); ?>', '<?php echo $headjs; ?>'); 3628c2e8227SGreg Roach window.close(); 3638c2e8227SGreg Roach } 3648c2e8227SGreg Roach } 3658c2e8227SGreg Roach </script> 3668c2e8227SGreg Roach <?php 3678c2e8227SGreg Roach 3688c2e8227SGreg Roach } else { 3698c2e8227SGreg Roach ?> 3708c2e8227SGreg Roach <script> 3718c2e8227SGreg Roach function insertId() { 37277e70a22SGreg Roach window.opener.alert('<?php echo $iid2; ?> - <?php echo I18N::translate('Not a valid individual, family, or source ID'); ?>'); 3738c2e8227SGreg Roach window.close(); 3748c2e8227SGreg Roach } 3758c2e8227SGreg Roach </script> 3768c2e8227SGreg Roach <?php 3778c2e8227SGreg Roach } 3788c2e8227SGreg Roach ?> 3798c2e8227SGreg Roach <script>window.onLoad = insertId();</script> 3808c2e8227SGreg Roach <?php 3818c2e8227SGreg Roach } 3828c2e8227SGreg Roach 3838c2e8227SGreg Roach /** 3848c2e8227SGreg Roach * Convert custom markup into HTML 3858c2e8227SGreg Roach * 3868c2e8227SGreg Roach * @param Note $note 3878c2e8227SGreg Roach * 3888c2e8227SGreg Roach * @return string 3898c2e8227SGreg Roach */ 3908c2e8227SGreg Roach public static function formatCensusNote(Note $note) { 3918c2e8227SGreg Roach global $WT_TREE; 3928c2e8227SGreg Roach 3938c2e8227SGreg Roach $headers = array( 3948c2e8227SGreg Roach 'AgM' => 'Age at first marriage', 3958c2e8227SGreg Roach 'Age' => 'Age at last birthday', 3968c2e8227SGreg Roach 'Assets' => 'Assets = Owned,Rented - Value,Rent - Radio - Farm', 3978c2e8227SGreg Roach 'BIC' => 'Born in County', 3988c2e8227SGreg Roach 'BOE' => 'Born outside England', 3998c2e8227SGreg Roach 'BP' => 'Birthplace - (Chapman format)', 4008c2e8227SGreg Roach 'Birthplace' => 'Birthplace (Full format)', 4018c2e8227SGreg Roach 'Bmth' => 'Month of birth - If born within Census year', 4028c2e8227SGreg Roach 'ChB' => 'Children born alive', 4038c2e8227SGreg Roach 'ChD' => 'Children who have died', 4048c2e8227SGreg Roach 'ChL' => 'Children still living', 4058c2e8227SGreg Roach 'DOB' => 'Date of birth', 4068c2e8227SGreg Roach 'Edu' => 'Education - At School, Can Read, Can Write', // or "Cannot Read, Cannot Write" ?? 4078c2e8227SGreg Roach 'EmD' => 'Employed?', 4088c2e8227SGreg Roach 'EmN' => 'Unemployed?', 4098c2e8227SGreg Roach 'EmR' => 'Employer?', 4108c2e8227SGreg Roach 'Employ' => 'Employment', 4118c2e8227SGreg Roach 'Eng?' => 'English spoken?', 4128c2e8227SGreg Roach 'EngL' => 'English spoken?, if not, Native Language', 4138c2e8227SGreg Roach 'FBP' => 'Father’s Birthplace - (Chapman format)', 4148c2e8227SGreg Roach 'Health' => 'Health - 1.Blind, 2.Deaf & Dumb, 3.Idiotic, 4.Insane, 5.Disabled etc', 4158c2e8227SGreg Roach 'Home' => 'Home Ownership - Owned/Rented-Free/Mortgaged-Farm/House-Farm Schedule number', 4168c2e8227SGreg Roach 'Industry' => 'Industry', 4178c2e8227SGreg Roach 'Infirm' => 'Infirmities - 1. Deaf & Dumb, 2. Blind, 3. Lunatic, 4. Imbecile/feeble-minded', 4188c2e8227SGreg Roach 'Lang' => 'If Foreign Born - Native Language', 4198c2e8227SGreg Roach 'MBP' => 'Mother’s Birthplace - (Chapman format)', 4208c2e8227SGreg Roach 'MC' => 'Marital Condition - Married, Single, Unmarried, Widowed or Divorced', 4218c2e8227SGreg Roach 'Mmth' => 'Month of marriage - If married during Census Year', 4228c2e8227SGreg Roach 'MnsE' => 'Months employed during Census Year', 4238c2e8227SGreg Roach 'MnsU' => 'Months unemployed during Census Year', 4248c2e8227SGreg Roach 'N/A' => 'If Foreign Born - Naturalized, Alien', 4258c2e8227SGreg Roach 'NL' => 'If Foreign Born - Native Language', 4268c2e8227SGreg Roach 'Name' => 'Full Name or Married name if married', 4278c2e8227SGreg Roach 'Occupation' => 'Occupation', 4288c2e8227SGreg Roach 'Par' => 'Parentage - Father if foreign born, Mother if foreign born', 4298c2e8227SGreg Roach 'Race' => 'Race or Color - Black, White, Mulatto, Asian, Indian, Chinese etc', 4308c2e8227SGreg Roach 'Relation' => 'Relationship to Head of Household', 4318c2e8227SGreg Roach 'Sex' => 'Male or Female', 4328c2e8227SGreg Roach 'Situ' => 'Situation - Disease, Infirmity, Convict, Pauper etc', 4338c2e8227SGreg Roach 'Ten' => 'Tenure - Owned/Rented, (if owned)Free/Morgaged', 4348c2e8227SGreg Roach 'Vet' => 'War Veteran?', 4358c2e8227SGreg Roach 'WH' => 'Working at Home?', 4368c2e8227SGreg Roach 'War' => 'War or Expedition', 4378c2e8227SGreg Roach 'WksU' => 'Weeks unemployed during Census Year', 4388c2e8227SGreg Roach 'YOI' => 'If Foreign Born - Year of immigration', 4398c2e8227SGreg Roach 'YON' => 'If Foreign Born - Year of naturalization', 4408c2e8227SGreg Roach 'YUS' => 'If Foreign Born - Years in the USA', 4418c2e8227SGreg Roach 'YrsM' => 'Years Married, or Y if married in Census Year', 4428c2e8227SGreg Roach ); 4438c2e8227SGreg Roach 4448c2e8227SGreg Roach if (preg_match('/(.*)((?:\n.*)*)\n\.start_formatted_area\.\n(.*)((?:\n.*)*)\n.end_formatted_area\.((?:\n.*)*)/', $note->getNote(), $match)) { 4458c2e8227SGreg Roach // This looks like a census-assistant shared note 4468c2e8227SGreg Roach $title = Filter::escapeHtml($match[1]); 4478c2e8227SGreg Roach $preamble = Filter::escapeHtml($match[2]); 4488c2e8227SGreg Roach $header = Filter::escapeHtml($match[3]); 4498c2e8227SGreg Roach $data = Filter::escapeHtml($match[4]); 4508c2e8227SGreg Roach $postamble = Filter::escapeHtml($match[5]); 4518c2e8227SGreg Roach 4528c2e8227SGreg Roach $fmt_headers = array(); 4538c2e8227SGreg Roach foreach ($headers as $key => $value) { 4548c2e8227SGreg Roach $fmt_headers['.b.' . $key] = '<span title="' . Filter::escapeHtml($value) . '">' . $key . '</span>'; 4558c2e8227SGreg Roach } 4568c2e8227SGreg Roach 4578c2e8227SGreg Roach // Substitue header labels and format as HTML 4588c2e8227SGreg Roach $thead = '<tr><th>' . strtr(str_replace('|', '</th><th>', $header), $fmt_headers) . '</th></tr>'; 4598c2e8227SGreg Roach 4608c2e8227SGreg Roach // Format data as HTML 4618c2e8227SGreg Roach $tbody = ''; 4628c2e8227SGreg Roach foreach (explode("\n", $data) as $row) { 4638c2e8227SGreg Roach $tbody .= '<tr>'; 4648c2e8227SGreg Roach foreach (explode('|', $row) as $column) { 4658c2e8227SGreg Roach $tbody .= '<td>' . $column . '</td>'; 4668c2e8227SGreg Roach } 4678c2e8227SGreg Roach $tbody .= '</tr>'; 4688c2e8227SGreg Roach } 4698c2e8227SGreg Roach 4708c2e8227SGreg Roach return 4718c2e8227SGreg Roach $title . "\n" . // The newline allows the framework to expand the details and turn the first line into a link 4728c2e8227SGreg Roach '<p>' . $preamble . '</p>' . 4738c2e8227SGreg Roach '<table class="table-census-assistant">' . 4748c2e8227SGreg Roach '<thead>' . $thead . '</thead>' . 4758c2e8227SGreg Roach '<tbody>' . $tbody . '</tbody>' . 4768c2e8227SGreg Roach '</table>' . 4778c2e8227SGreg Roach '<p>' . $postamble . '</p>'; 4788c2e8227SGreg Roach } else { 4798c2e8227SGreg Roach // Not a census-assistant shared note - apply default formatting 4808c2e8227SGreg Roach return Filter::formatText($note->getNote(), $WT_TREE); 4818c2e8227SGreg Roach } 4828c2e8227SGreg Roach } 4838c2e8227SGreg Roach 4848c2e8227SGreg Roach /** 4858c2e8227SGreg Roach * Modify the “add shared note” field, to create a note using the assistant 4868c2e8227SGreg Roach * 4878c2e8227SGreg Roach * @param string $element_id 4888c2e8227SGreg Roach * @param string $xref 4898c2e8227SGreg Roach * @param string $action 4908c2e8227SGreg Roach * 4918c2e8227SGreg Roach * @return string 4928c2e8227SGreg Roach */ 493ffd703eaSGreg Roach public static function addNoteWithAssistantLink($element_id, $xref, $action) { 49424ec66ceSGreg Roach global $controller, $WT_TREE; 4958c2e8227SGreg Roach 4968c2e8227SGreg Roach // We do not yet support family records 49724ec66ceSGreg Roach if (!GedcomRecord::getInstance($xref, $WT_TREE) instanceof Individual) { 4988c2e8227SGreg Roach return ''; 4998c2e8227SGreg Roach } 5008c2e8227SGreg Roach 5018c2e8227SGreg Roach // Only modify “add shared note” links on the add/edit actions. 5028c2e8227SGreg Roach // TODO: does the “edit” action work? 5038c2e8227SGreg Roach if ($action != 'add' && $action != 'edit') { 5048c2e8227SGreg Roach return ''; 5058c2e8227SGreg Roach } 5068c2e8227SGreg Roach 5078c2e8227SGreg Roach $controller->addInlineJavascript(' 5088c2e8227SGreg Roach var pid_array=jQuery("#pid_array"); 5098c2e8227SGreg Roach function set_pid_array(pa) { 5108c2e8227SGreg Roach pid_array.val(pa); 5118c2e8227SGreg Roach } 5128c2e8227SGreg Roach '); 5138c2e8227SGreg Roach 5148c2e8227SGreg Roach return 5158c2e8227SGreg Roach '<br>' . 5168c2e8227SGreg Roach '<input type="hidden" name="pid_array" id="pid_array" value="">' . 5178c2e8227SGreg Roach '<a href="#" onclick="return addnewnote_assisted(document.getElementById(\'' . $element_id . '\'), \'' . $xref . '\');">' . 5188c2e8227SGreg Roach I18N::translate('Create a new shared note using assistant') . 5198c2e8227SGreg Roach '</a>'; 5208c2e8227SGreg Roach } 5218c2e8227SGreg Roach 5228c2e8227SGreg Roach /** 5238c2e8227SGreg Roach * Add a selector containing UK/US/FR census dates 5248c2e8227SGreg Roach * 5258c2e8227SGreg Roach * @param string $action 5268c2e8227SGreg Roach * @param string $tag 5278c2e8227SGreg Roach * @param string $element_id 5288c2e8227SGreg Roach * 5298c2e8227SGreg Roach * @return string 5308c2e8227SGreg Roach */ 5318c2e8227SGreg Roach public static function censusDateSelector($action, $tag, $element_id) { 5328c2e8227SGreg Roach global $controller; 5338c2e8227SGreg Roach 5348c2e8227SGreg Roach if ($action == 'add' && $tag == 'CENS') { 535*4c00bbb9SGreg Roach // Show more likely census details at the top of the list. 536*4c00bbb9SGreg Roach switch (WT_LOCALE) { 537*4c00bbb9SGreg Roach case 'en-AU': 538*4c00bbb9SGreg Roach case 'en-GB': 539*4c00bbb9SGreg Roach $census_places = array(new CensusOfEngland, new CensusOfWales, new CensusOfScotland); 540*4c00bbb9SGreg Roach break; 541*4c00bbb9SGreg Roach case 'en-US': 542*4c00bbb9SGreg Roach $census_places = array(new CensusOfUnitedStates); 543*4c00bbb9SGreg Roach break; 544*4c00bbb9SGreg Roach case 'fr': 545*4c00bbb9SGreg Roach case 'fr-CA': 546*4c00bbb9SGreg Roach $census_places = array(new CensusOfFrance); 547*4c00bbb9SGreg Roach break; 548*4c00bbb9SGreg Roach case 'da': 549*4c00bbb9SGreg Roach $census_places = array(new CensusOfDenmark); 550*4c00bbb9SGreg Roach break; 551*4c00bbb9SGreg Roach default: 552*4c00bbb9SGreg Roach $census_places = array(); 553*4c00bbb9SGreg Roach break; 5548c2e8227SGreg Roach } 555*4c00bbb9SGreg Roach foreach (Census::allCensusPlaces() as $census_place) { 556*4c00bbb9SGreg Roach if (!in_array($census_place, $census_places)) { 557*4c00bbb9SGreg Roach $census_places[] = $census_place; 558*4c00bbb9SGreg Roach } 559*4c00bbb9SGreg Roach } 560*4c00bbb9SGreg Roach 561*4c00bbb9SGreg Roach $controller->addInlineJavascript(' 562*4c00bbb9SGreg Roach function selectCensus(el) { 563*4c00bbb9SGreg Roach var option = jQuery(":selected", el); 564*4c00bbb9SGreg Roach jQuery("input.DATE", jQuery(el).closest("table")).val(option.val()); 565*4c00bbb9SGreg Roach jQuery("input.PLAC", jQuery(el).closest("table")).val(option.data("place")); 566*4c00bbb9SGreg Roach jQuery("#setctry").val(option.data("place")); 567*4c00bbb9SGreg Roach jQuery("#setyear").val(option.data("year")); 5688c2e8227SGreg Roach } 5698c2e8227SGreg Roach '); 5708c2e8227SGreg Roach 571*4c00bbb9SGreg Roach $options = '<option value="">' . I18N::translate('Census date') . '</option>'; 5728c2e8227SGreg Roach 573*4c00bbb9SGreg Roach foreach ($census_places as $census_place) { 574*4c00bbb9SGreg Roach $options .= '<option value=""></option>'; 575*4c00bbb9SGreg Roach foreach ($census_place->allCensusDates() as $census) { 576*4c00bbb9SGreg Roach $date = new Date($census->censusDate()); 577*4c00bbb9SGreg Roach $year = $date->minimumDate()->format('%Y'); 578*4c00bbb9SGreg Roach $options .= '<option value="' . $census->censusDate() . '" data-year="' . $year . '" data-place="' . $census->censusPlace() . '">' . $census->censusPlace() . ' ' . $year . '</option>'; 579*4c00bbb9SGreg Roach } 580*4c00bbb9SGreg Roach } 581*4c00bbb9SGreg Roach 582*4c00bbb9SGreg Roach return 583*4c00bbb9SGreg Roach '<input type="hidden" id="setctry" name="setctry" value="">' . 584*4c00bbb9SGreg Roach '<input type="hidden" id="setyear" name="setyear" value="">' . 585*4c00bbb9SGreg Roach '<select onchange="selectCensus(this);">' . $options . '</select>'; 5868c2e8227SGreg Roach } else { 5878c2e8227SGreg Roach return ''; 5888c2e8227SGreg Roach } 5898c2e8227SGreg Roach } 5908c2e8227SGreg Roach} 591