18c2e8227SGreg Roach<?php 20e62c4b8SGreg Roachnamespace Fisharebest\Webtrees\Module; 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 */ 180e62c4b8SGreg Roachuse Fisharebest\Webtrees\Auth; 190e62c4b8SGreg Roachuse Fisharebest\Webtrees\Fact; 20*3d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\Functions; 21*3d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsPrintFacts; 220e62c4b8SGreg Roachuse Fisharebest\Webtrees\GedcomTag; 230e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N; 248c2e8227SGreg Roach 258c2e8227SGreg Roach/** 268c2e8227SGreg Roach * Class SourcesTabModule 278c2e8227SGreg Roach */ 28e2a378d3SGreg Roachclass SourcesTabModule extends AbstractModule implements ModuleTabInterface { 298c2e8227SGreg Roach private $facts; 308c2e8227SGreg Roach 318c2e8227SGreg Roach /** {@inheritdoc} */ 328c2e8227SGreg Roach public function getTitle() { 338c2e8227SGreg Roach return /* I18N: Name of a module */ I18N::translate('Sources'); 348c2e8227SGreg Roach } 358c2e8227SGreg Roach 368c2e8227SGreg Roach /** {@inheritdoc} */ 378c2e8227SGreg Roach public function getDescription() { 388c2e8227SGreg Roach return /* I18N: Description of the “Sources” module */ I18N::translate('A tab showing the sources linked to an individual.'); 398c2e8227SGreg Roach } 408c2e8227SGreg Roach 418c2e8227SGreg Roach /** {@inheritdoc} */ 428c2e8227SGreg Roach public function defaultTabOrder() { 438c2e8227SGreg Roach return 30; 448c2e8227SGreg Roach } 458c2e8227SGreg Roach 468c2e8227SGreg Roach /** {@inheritdoc} */ 478c2e8227SGreg Roach public function hasTabContent() { 484b9ff166SGreg Roach global $WT_TREE; 494b9ff166SGreg Roach 504b9ff166SGreg Roach return Auth::isEditor($WT_TREE) || $this->getFactsWithSources(); 518c2e8227SGreg Roach } 528c2e8227SGreg Roach 538c2e8227SGreg Roach /** {@inheritdoc} */ 548c2e8227SGreg Roach public function isGrayedOut() { 558c2e8227SGreg Roach return !$this->getFactsWithSources(); 568c2e8227SGreg Roach } 578c2e8227SGreg Roach 588c2e8227SGreg Roach /** {@inheritdoc} */ 598c2e8227SGreg Roach public function getTabContent() { 608c2e8227SGreg Roach global $controller, $WT_TREE; 618c2e8227SGreg Roach 628c2e8227SGreg Roach ob_start(); 638c2e8227SGreg Roach ?> 648c2e8227SGreg Roach <table class="facts_table"> 658c2e8227SGreg Roach <tr> 668c2e8227SGreg Roach <td colspan="2" class="descriptionbox rela"> 678c2e8227SGreg Roach <input id="checkbox_sour2" type="checkbox" <?php echo $WT_TREE->getPreference('SHOW_LEVEL2_NOTES') ? 'checked' : ''; ?> onclick="jQuery('tr.row_sour2').toggle();"> 686fd6cde8SGreg Roach <label for="checkbox_sour2"><?php echo I18N::translate('Show all sources'); ?></label> 698c2e8227SGreg Roach </td> 708c2e8227SGreg Roach </tr> 718c2e8227SGreg Roach <?php 728c2e8227SGreg Roach foreach ($this->getFactsWithSources() as $fact) { 738c2e8227SGreg Roach if ($fact->getTag() == 'SOUR') { 74*3d7a8a4cSGreg Roach FunctionsPrintFacts::printMainSources($fact, 1); 758c2e8227SGreg Roach } else { 76*3d7a8a4cSGreg Roach FunctionsPrintFacts::printMainSources($fact, 2); 778c2e8227SGreg Roach } 788c2e8227SGreg Roach } 798c2e8227SGreg Roach if (!$this->getFactsWithSources()) { 808c2e8227SGreg Roach echo '<tr><td id="no_tab4" colspan="2" class="facts_value">', I18N::translate('There are no source citations for this individual.'), '</td></tr>'; 818c2e8227SGreg Roach } 828c2e8227SGreg Roach 838c2e8227SGreg Roach // New Source Link 848c2e8227SGreg Roach if ($controller->record->canEdit()) { 858c2e8227SGreg Roach ?> 868c2e8227SGreg Roach <tr> 878c2e8227SGreg Roach <td class="facts_label"> 88764a01d9SGreg Roach <?php echo GedcomTag::getLabel('SOUR'); ?> 898c2e8227SGreg Roach </td> 908c2e8227SGreg Roach <td class="facts_value"> 918c2e8227SGreg Roach <a href="#" onclick="add_new_record('<?php echo $controller->record->getXref(); ?>','SOUR'); return false;"> 928c2e8227SGreg Roach <?php echo I18N::translate('Add a new source citation'); ?> 938c2e8227SGreg Roach </a> 948c2e8227SGreg Roach </td> 958c2e8227SGreg Roach </tr> 968c2e8227SGreg Roach <?php 978c2e8227SGreg Roach } 988c2e8227SGreg Roach ?> 998c2e8227SGreg Roach </table> 1008c2e8227SGreg Roach <?php 1018c2e8227SGreg Roach if (!$WT_TREE->getPreference('SHOW_LEVEL2_NOTES')) { 1028c2e8227SGreg Roach echo '<script>jQuery("tr.row_sour2").toggle();</script>'; 1038c2e8227SGreg Roach } 1048c2e8227SGreg Roach 1058c2e8227SGreg Roach return '<div id="' . $this->getName() . '_content">' . ob_get_clean() . '</div>'; 1068c2e8227SGreg Roach } 1078c2e8227SGreg Roach 1088c2e8227SGreg Roach /** 1098c2e8227SGreg Roach * Get all the facts for an individual which contain sources. 1108c2e8227SGreg Roach * 1118c2e8227SGreg Roach * @return Fact[] 1128c2e8227SGreg Roach */ 1138c2e8227SGreg Roach private function getFactsWithSources() { 1148c2e8227SGreg Roach global $controller; 1158c2e8227SGreg Roach 1168c2e8227SGreg Roach if ($this->facts === null) { 1178c2e8227SGreg Roach $facts = $controller->record->getFacts(); 1188c2e8227SGreg Roach foreach ($controller->record->getSpouseFamilies() as $family) { 1198c2e8227SGreg Roach if ($family->canShow()) { 1208c2e8227SGreg Roach foreach ($family->getFacts() as $fact) { 1218c2e8227SGreg Roach $facts[] = $fact; 1228c2e8227SGreg Roach } 1238c2e8227SGreg Roach } 1248c2e8227SGreg Roach } 1258c2e8227SGreg Roach $this->facts = array(); 1268c2e8227SGreg Roach foreach ($facts as $fact) { 1278c2e8227SGreg Roach if (preg_match('/(?:^1|\n\d) SOUR/', $fact->getGedcom())) { 1288c2e8227SGreg Roach $this->facts[] = $fact; 1298c2e8227SGreg Roach } 1308c2e8227SGreg Roach } 131*3d7a8a4cSGreg Roach Functions::sortFacts($this->facts); 1328c2e8227SGreg Roach } 1338c2e8227SGreg Roach 1348c2e8227SGreg Roach return $this->facts; 1358c2e8227SGreg Roach } 1368c2e8227SGreg Roach 1378c2e8227SGreg Roach /** {@inheritdoc} */ 1388c2e8227SGreg Roach public function canLoadAjax() { 1398c2e8227SGreg Roach return !Auth::isSearchEngine(); // Search engines cannot use AJAX 1408c2e8227SGreg Roach } 1418c2e8227SGreg Roach 1428c2e8227SGreg Roach /** {@inheritdoc} */ 1438c2e8227SGreg Roach public function getPreLoadContent() { 1448c2e8227SGreg Roach return ''; 1458c2e8227SGreg Roach } 1468c2e8227SGreg Roach} 147