1<?php 2namespace Fisharebest\Webtrees; 3 4/** 5 * webtrees: online genealogy 6 * Copyright (C) 2015 webtrees development team 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19/** 20 * Class NotesTabModule 21 */ 22class NotesTabModule extends Module implements ModuleTabInterface { 23 private $facts; 24 25 /** {@inheritdoc} */ 26 public function getTitle() { 27 return /* I18N: Name of a module */ I18N::translate('Notes'); 28 } 29 30 /** {@inheritdoc} */ 31 public function getDescription() { 32 return /* I18N: Description of the “Notes” module */ I18N::translate('A tab showing the notes attached to an individual.'); 33 } 34 35 /** {@inheritdoc} */ 36 public function defaultTabOrder() { 37 return 40; 38 } 39 40 /** {@inheritdoc} */ 41 public function hasTabContent() { 42 return WT_USER_CAN_EDIT || $this->getFactsWithNotes(); 43 } 44 45 /** {@inheritdoc} */ 46 public function isGrayedOut() { 47 return !$this->getFactsWithNotes(); 48 } 49 50 /** {@inheritdoc} */ 51 public function getTabContent() { 52 global $WT_TREE, $controller; 53 54 ob_start(); 55 echo '<table class="facts_table">'; 56 ?> 57 <tr> 58 <td colspan="2" class="descriptionbox rela"> 59 <input id="checkbox_note2" type="checkbox" <?php echo $WT_TREE->getPreference('SHOW_LEVEL2_NOTES') ? 'checked' : ''; ?> onclick="jQuery('tr.row_note2').toggle();"> 60 <label for="checkbox_note2"><?php echo I18N::translate('Show all notes'); ?></label> 61 <?php echo help_link('show_fact_sources'); ?> 62 </td> 63 </tr> 64 <?php 65 foreach ($this->getFactsWithNotes() as $fact) { 66 if ($fact->getTag() == 'NOTE') { 67 print_main_notes($fact, 1); 68 } else { 69 for ($i = 2; $i < 4; ++$i) { 70 print_main_notes($fact, $i); 71 } 72 } 73 } 74 if (!$this->getFactsWithNotes()) { 75 echo '<tr><td id="no_tab4" colspan="2" class="facts_value">', I18N::translate('There are no notes for this individual.'), '</td></tr>'; 76 } 77 78 // New note link 79 if ($controller->record->canEdit()) { 80 ?> 81 <tr> 82 <td class="facts_label"> 83 <?php echo GedcomTag::getLabel('NOTE'); ?> 84 </td> 85 <td class="facts_value"> 86 <a href="#" onclick="add_new_record('<?php echo $controller->record->getXref(); ?>','NOTE'); return false;"> 87 <?php echo I18N::translate('Add a new note'); ?> 88 </a> 89 <?php echo help_link('add_note'); ?> 90 </td> 91 </tr> 92 <tr> 93 <td class="facts_label"> 94 <?php echo GedcomTag::getLabel('SHARED_NOTE'); ?> 95 </td> 96 <td class="facts_value"> 97 <a href="#" onclick="add_new_record('<?php echo $controller->record->getXref(); ?>','SHARED_NOTE'); return false;"> 98 <?php echo I18N::translate('Add a new shared note'); ?> 99 </a> 100 <?php echo help_link('add_shared_note'); ?> 101 </td> 102 </tr> 103 <?php 104 } 105 ?> 106 </table> 107 <?php 108 if (!$WT_TREE->getPreference('SHOW_LEVEL2_NOTES')) { 109 echo '<script>jQuery("tr.row_note2").toggle();</script>'; 110 } 111 112 return '<div id="' . $this->getName() . '_content">' . ob_get_clean() . '</div>'; 113 } 114 115 /** 116 * Get all the facts for an individual which contain notes. 117 * 118 * @return Fact[] 119 */ 120 private function getFactsWithNotes() { 121 global $controller; 122 123 if ($this->facts === null) { 124 $facts = $controller->record->getFacts(); 125 foreach ($controller->record->getSpouseFamilies() as $family) { 126 if ($family->canShow()) { 127 foreach ($family->getFacts() as $fact) { 128 $facts[] = $fact; 129 } 130 } 131 } 132 $this->facts = array(); 133 foreach ($facts as $fact) { 134 if (preg_match('/(?:^1|\n\d) NOTE/', $fact->getGedcom())) { 135 $this->facts[] = $fact; 136 } 137 } 138 sort_facts($this->facts); 139 } 140 141 return $this->facts; 142 } 143 144 /** {@inheritdoc} */ 145 public function canLoadAjax() { 146 return !Auth::isSearchEngine(); // Search engines cannot use AJAX 147 } 148 149 /** {@inheritdoc} */ 150 public function getPreLoadContent() { 151 return ''; 152 } 153} 154