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 AbstractModule 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 global $WT_TREE; 43 44 return Auth::isEditor($WT_TREE) || $this->getFactsWithNotes(); 45 } 46 47 /** {@inheritdoc} */ 48 public function isGrayedOut() { 49 return !$this->getFactsWithNotes(); 50 } 51 52 /** {@inheritdoc} */ 53 public function getTabContent() { 54 global $WT_TREE, $controller; 55 56 ob_start(); 57 echo '<table class="facts_table">'; 58 ?> 59 <tr> 60 <td colspan="2" class="descriptionbox rela"> 61 <input id="checkbox_note2" type="checkbox" <?php echo $WT_TREE->getPreference('SHOW_LEVEL2_NOTES') ? 'checked' : ''; ?> onclick="jQuery('tr.row_note2').toggle();"> 62 <label for="checkbox_note2"><?php echo I18N::translate('Show all notes'); ?></label> 63 </td> 64 </tr> 65 <?php 66 foreach ($this->getFactsWithNotes() as $fact) { 67 if ($fact->getTag() == 'NOTE') { 68 print_main_notes($fact, 1); 69 } else { 70 for ($i = 2; $i < 4; ++$i) { 71 print_main_notes($fact, $i); 72 } 73 } 74 } 75 if (!$this->getFactsWithNotes()) { 76 echo '<tr><td id="no_tab4" colspan="2" class="facts_value">', I18N::translate('There are no notes for this individual.'), '</td></tr>'; 77 } 78 79 // New note link 80 if ($controller->record->canEdit()) { 81 ?> 82 <tr> 83 <td class="facts_label"> 84 <?php echo GedcomTag::getLabel('NOTE'); ?> 85 </td> 86 <td class="facts_value"> 87 <a href="#" onclick="add_new_record('<?php echo $controller->record->getXref(); ?>','NOTE'); return false;"> 88 <?php echo I18N::translate('Add a new note'); ?> 89 </a> 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 </td> 101 </tr> 102 <?php 103 } 104 ?> 105 </table> 106 <?php 107 if (!$WT_TREE->getPreference('SHOW_LEVEL2_NOTES')) { 108 echo '<script>jQuery("tr.row_note2").toggle();</script>'; 109 } 110 111 return '<div id="' . $this->getName() . '_content">' . ob_get_clean() . '</div>'; 112 } 113 114 /** 115 * Get all the facts for an individual which contain notes. 116 * 117 * @return Fact[] 118 */ 119 private function getFactsWithNotes() { 120 global $controller; 121 122 if ($this->facts === null) { 123 $facts = $controller->record->getFacts(); 124 foreach ($controller->record->getSpouseFamilies() as $family) { 125 if ($family->canShow()) { 126 foreach ($family->getFacts() as $fact) { 127 $facts[] = $fact; 128 } 129 } 130 } 131 $this->facts = array(); 132 foreach ($facts as $fact) { 133 if (preg_match('/(?:^1|\n\d) NOTE/', $fact->getGedcom())) { 134 $this->facts[] = $fact; 135 } 136 } 137 sort_facts($this->facts); 138 } 139 140 return $this->facts; 141 } 142 143 /** {@inheritdoc} */ 144 public function canLoadAjax() { 145 return !Auth::isSearchEngine(); // Search engines cannot use AJAX 146 } 147 148 /** {@inheritdoc} */ 149 public function getPreLoadContent() { 150 return ''; 151 } 152} 153