1<?php 2namespace Fisharebest\Webtrees\Module; 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 19use Fisharebest\Webtrees\Auth; 20use Fisharebest\Webtrees\Filter; 21use Fisharebest\Webtrees\Functions\FunctionsDb; 22use Fisharebest\Webtrees\Functions\FunctionsEdit; 23use Fisharebest\Webtrees\GedcomTag; 24use Fisharebest\Webtrees\I18N; 25use Fisharebest\Webtrees\Theme; 26use Rhumsaa\Uuid\Uuid; 27 28/** 29 * Class ResearchTaskModule 30 */ 31class ResearchTaskModule extends AbstractModule implements ModuleBlockInterface { 32 /** {@inheritdoc} */ 33 public function getTitle() { 34 return /* I18N: Name of a module. Tasks that need further research. */ I18N::translate('Research tasks'); 35 } 36 37 /** {@inheritdoc} */ 38 public function getDescription() { 39 return /* I18N: Description of “Research tasks” module */ I18N::translate('A list of tasks and activities that are linked to the family tree.'); 40 } 41 42 /** {@inheritdoc} */ 43 public function getBlock($block_id, $template = true, $cfg = null) { 44 global $ctype, $controller, $WT_TREE; 45 46 $show_other = $this->getBlockSetting($block_id, 'show_other', '1'); 47 $show_unassigned = $this->getBlockSetting($block_id, 'show_unassigned', '1'); 48 $show_future = $this->getBlockSetting($block_id, 'show_future', '1'); 49 $block = $this->getBlockSetting($block_id, 'block', '1'); 50 51 if ($cfg) { 52 foreach (array('show_unassigned', 'show_other', 'show_future', 'block') as $name) { 53 if (array_key_exists($name, $cfg)) { 54 $$name = $cfg[$name]; 55 } 56 } 57 } 58 59 $id = $this->getName() . $block_id; 60 $class = $this->getName() . '_block'; 61 if ($ctype === 'gedcom' && Auth::isManager($WT_TREE) || $ctype === 'user' && Auth::check()) { 62 $title = '<a class="icon-admin" title="' . I18N::translate('Configure') . '" href="block_edit.php?block_id=' . $block_id . '&ged=' . $WT_TREE->getNameHtml() . '&ctype=' . $ctype . '"></a>'; 63 } else { 64 $title = ''; 65 } 66 $title .= $this->getTitle(); 67 68 $table_id = Uuid::uuid4(); // create a unique ID 69 70 $controller 71 ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL) 72 ->addInlineJavascript(' 73 jQuery("#' . $table_id . '").dataTable({ 74 dom: \'t\', 75 ' . I18N::datatablesI18N() . ', 76 autoWidth: false, 77 paginate: false, 78 lengthChange: false, 79 filter: false, 80 info: true, 81 jQueryUI: true, 82 columns: [ 83 /* 0-DATE */ { visible: false }, 84 /* 1-Date */ { dataSort: 0 }, 85 /* 1-Record */ null, 86 /* 2-Username */ null, 87 /* 3-Text */ null 88 ] 89 }); 90 jQuery("#' . $table_id . '").css("visibility", "visible"); 91 jQuery(".loading-image").css("display", "none"); 92 '); 93 94 $content = ''; 95 $content .= '<div class="loading-image"> </div>'; 96 $content .= '<table id="' . $table_id . '" style="visibility:hidden;">'; 97 $content .= '<thead><tr>'; 98 $content .= '<th>DATE</th>'; //hidden by datables code 99 $content .= '<th>' . GedcomTag::getLabel('DATE') . '</th>'; 100 $content .= '<th>' . I18N::translate('Record') . '</th>'; 101 if ($show_unassigned || $show_other) { 102 $content .= '<th>' . I18N::translate('Username') . '</th>'; 103 } 104 $content .= '<th>' . GedcomTag::getLabel('TEXT') . '</th>'; 105 $content .= '</tr></thead><tbody>'; 106 107 $found = false; 108 $end_jd = $show_future ? 99999999 : WT_CLIENT_JD; 109 foreach (FunctionsDb::getCalendarEvents(0, $end_jd, '_TODO', $WT_TREE) as $fact) { 110 $record = $fact->getParent(); 111 $user_name = $fact->getAttribute('_WT_USER'); 112 if ($user_name === Auth::user()->getUserName() || !$user_name && $show_unassigned || $user_name && $show_other) { 113 $content .= '<tr>'; 114 //-- Event date (sortable) 115 $content .= '<td>'; //hidden by datables code 116 $content .= $fact->getDate()->julianDay(); 117 $content .= '</td>'; 118 $content .= '<td class="wrap">' . $fact->getDate()->display() . '</td>'; 119 $content .= '<td class="wrap"><a href="' . $record->getHtmlUrl() . '">' . $record->getFullName() . '</a></td>'; 120 if ($show_unassigned || $show_other) { 121 $content .= '<td class="wrap">' . $user_name . '</td>'; 122 } 123 $text = $fact->getValue(); 124 $content .= '<td class="wrap">' . $text . '</td>'; 125 $content .= '</tr>'; 126 $found = true; 127 } 128 } 129 130 $content .= '</tbody></table>'; 131 if (!$found) { 132 $content .= '<p>' . I18N::translate('There are no research tasks in this family tree.') . '</p>'; 133 } 134 135 if ($template) { 136 if ($block) { 137 $class .= ' small_inner_block'; 138 } 139 140 return Theme::theme()->formatBlock($id, $title, $class, $content); 141 } else { 142 return $content; 143 } 144 } 145 146 /** {@inheritdoc} */ 147 public function loadAjax() { 148 return false; 149 } 150 151 /** {@inheritdoc} */ 152 public function isUserBlock() { 153 return true; 154 } 155 156 /** {@inheritdoc} */ 157 public function isGedcomBlock() { 158 return true; 159 } 160 161 /** {@inheritdoc} */ 162 public function configureBlock($block_id) { 163 if (Filter::postBool('save') && Filter::checkCsrf()) { 164 $this->setBlockSetting($block_id, 'show_other', Filter::postBool('show_other')); 165 $this->setBlockSetting($block_id, 'show_unassigned', Filter::postBool('show_unassigned')); 166 $this->setBlockSetting($block_id, 'show_future', Filter::postBool('show_future')); 167 $this->setBlockSetting($block_id, 'block', Filter::postBool('block')); 168 } 169 170 $show_other = $this->getBlockSetting($block_id, 'show_other', '1'); 171 $show_unassigned = $this->getBlockSetting($block_id, 'show_unassigned', '1'); 172 $show_future = $this->getBlockSetting($block_id, 'show_future', '1'); 173 $block = $this->getBlockSetting($block_id, 'block', '1'); 174 175 ?> 176 <tr> 177 <td colspan="2"> 178 <?php echo I18N::translate('Research tasks are special events, added to individuals in your family tree, which identify the need for further research. You can use them as a reminder to check facts against more reliable sources, to obtain documents or photographs, to resolve conflicting information, etc.'); ?> 179 <?php echo I18N::translate('To create new research tasks, you must first add “research task” to the list of facts and events in the family tree’s preferences.'); ?> 180 <?php echo I18N::translate('Research tasks are stored using the custom GEDCOM tag “_TODO”. Other genealogy applications may not recognize this tag.'); ?> 181 </td> 182 </tr> 183 <?php 184 185 echo '<tr><td class="descriptionbox wrap width33">'; 186 echo I18N::translate('Show research tasks that are assigned to other users'); 187 echo '</td><td class="optionbox">'; 188 echo FunctionsEdit::editFieldYesNo('show_other', $show_other); 189 echo '</td></tr>'; 190 191 echo '<tr><td class="descriptionbox wrap width33">'; 192 echo I18N::translate('Show research tasks that are not assigned to any user'); 193 echo '</td><td class="optionbox">'; 194 echo FunctionsEdit::editFieldYesNo('show_unassigned', $show_unassigned); 195 echo '</td></tr>'; 196 197 echo '<tr><td class="descriptionbox wrap width33">'; 198 echo I18N::translate('Show research tasks that have a date in the future'); 199 echo '</td><td class="optionbox">'; 200 echo FunctionsEdit::editFieldYesNo('show_future', $show_future); 201 echo '</td></tr>'; 202 203 echo '<tr><td class="descriptionbox wrap width33">'; 204 echo /* I18N: label for a yes/no option */ I18N::translate('Add a scrollbar when block contents grow'); 205 echo '</td><td class="optionbox">'; 206 echo FunctionsEdit::editFieldYesNo('block', $block); 207 echo '</td></tr>'; 208 } 209} 210