18c2e8227SGreg Roach<?php 2*0e62c4b8SGreg 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 */ 188c2e8227SGreg Roach 19*0e62c4b8SGreg Roachuse Fisharebest\Webtrees\Auth; 20*0e62c4b8SGreg Roachuse Fisharebest\Webtrees\Filter; 21*0e62c4b8SGreg Roachuse Fisharebest\Webtrees\GedcomTag; 22*0e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N; 23*0e62c4b8SGreg Roachuse Fisharebest\Webtrees\Theme; 248c2e8227SGreg Roachuse Rhumsaa\Uuid\Uuid; 258c2e8227SGreg Roach 268c2e8227SGreg Roach/** 278c2e8227SGreg Roach * Class ResearchTaskModule 288c2e8227SGreg Roach */ 29e2a378d3SGreg Roachclass ResearchTaskModule extends AbstractModule implements ModuleBlockInterface { 308c2e8227SGreg Roach /** {@inheritdoc} */ 318c2e8227SGreg Roach public function getTitle() { 328c2e8227SGreg Roach return /* I18N: Name of a module. Tasks that need further research. */ I18N::translate('Research tasks'); 338c2e8227SGreg Roach } 348c2e8227SGreg Roach 358c2e8227SGreg Roach /** {@inheritdoc} */ 368c2e8227SGreg Roach public function getDescription() { 378c2e8227SGreg Roach return /* I18N: Description of “Research tasks” module */ I18N::translate('A list of tasks and activities that are linked to the family tree.'); 388c2e8227SGreg Roach } 398c2e8227SGreg Roach 408c2e8227SGreg Roach /** {@inheritdoc} */ 418c2e8227SGreg Roach public function getBlock($block_id, $template = true, $cfg = null) { 424b9ff166SGreg Roach global $ctype, $controller, $WT_TREE; 438c2e8227SGreg Roach 44e2a378d3SGreg Roach $show_other = $this->getBlockSetting($block_id, 'show_other', '1'); 45e2a378d3SGreg Roach $show_unassigned = $this->getBlockSetting($block_id, 'show_unassigned', '1'); 46e2a378d3SGreg Roach $show_future = $this->getBlockSetting($block_id, 'show_future', '1'); 47e2a378d3SGreg Roach $block = $this->getBlockSetting($block_id, 'block', '1'); 488c2e8227SGreg Roach 498c2e8227SGreg Roach if ($cfg) { 508c2e8227SGreg Roach foreach (array('show_unassigned', 'show_other', 'show_future', 'block') as $name) { 518c2e8227SGreg Roach if (array_key_exists($name, $cfg)) { 528c2e8227SGreg Roach $$name = $cfg[$name]; 538c2e8227SGreg Roach } 548c2e8227SGreg Roach } 558c2e8227SGreg Roach } 568c2e8227SGreg Roach 578c2e8227SGreg Roach $id = $this->getName() . $block_id; 588c2e8227SGreg Roach $class = $this->getName() . '_block'; 594b9ff166SGreg Roach if ($ctype === 'gedcom' && Auth::isManager($WT_TREE) || $ctype === 'user' && Auth::check()) { 609353052eSGreg Roach $title = '<a class="icon-admin" title="' . I18N::translate('Configure') . '" href="block_edit.php?block_id=' . $block_id . '&ged=' . $WT_TREE->getNameHtml() . '&ctype=' . $ctype . '"></a>'; 618c2e8227SGreg Roach } else { 628c2e8227SGreg Roach $title = ''; 638c2e8227SGreg Roach } 648c2e8227SGreg Roach $title .= $this->getTitle(); 658c2e8227SGreg Roach 668c2e8227SGreg Roach $table_id = Uuid::uuid4(); // create a unique ID 678c2e8227SGreg Roach 688c2e8227SGreg Roach $controller 698c2e8227SGreg Roach ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL) 708c2e8227SGreg Roach ->addInlineJavascript(' 718c2e8227SGreg Roach jQuery("#' . $table_id . '").dataTable({ 728c2e8227SGreg Roach dom: \'t\', 738c2e8227SGreg Roach ' . I18N::datatablesI18N() . ', 748c2e8227SGreg Roach autoWidth: false, 758c2e8227SGreg Roach paginate: false, 768c2e8227SGreg Roach lengthChange: false, 778c2e8227SGreg Roach filter: false, 788c2e8227SGreg Roach info: true, 798c2e8227SGreg Roach jQueryUI: true, 808c2e8227SGreg Roach columns: [ 818c2e8227SGreg Roach /* 0-DATE */ { visible: false }, 828c2e8227SGreg Roach /* 1-Date */ { dataSort: 0 }, 838c2e8227SGreg Roach /* 1-Record */ null, 848c2e8227SGreg Roach /* 2-Username */ null, 858c2e8227SGreg Roach /* 3-Text */ null 868c2e8227SGreg Roach ] 878c2e8227SGreg Roach }); 888c2e8227SGreg Roach jQuery("#' . $table_id . '").css("visibility", "visible"); 898c2e8227SGreg Roach jQuery(".loading-image").css("display", "none"); 908c2e8227SGreg Roach '); 918c2e8227SGreg Roach 928c2e8227SGreg Roach $content = ''; 938c2e8227SGreg Roach $content .= '<div class="loading-image"> </div>'; 948c2e8227SGreg Roach $content .= '<table id="' . $table_id . '" style="visibility:hidden;">'; 958c2e8227SGreg Roach $content .= '<thead><tr>'; 968c2e8227SGreg Roach $content .= '<th>DATE</th>'; //hidden by datables code 97764a01d9SGreg Roach $content .= '<th>' . GedcomTag::getLabel('DATE') . '</th>'; 988c2e8227SGreg Roach $content .= '<th>' . I18N::translate('Record') . '</th>'; 998c2e8227SGreg Roach if ($show_unassigned || $show_other) { 1008c2e8227SGreg Roach $content .= '<th>' . I18N::translate('Username') . '</th>'; 1018c2e8227SGreg Roach } 102764a01d9SGreg Roach $content .= '<th>' . GedcomTag::getLabel('TEXT') . '</th>'; 1038c2e8227SGreg Roach $content .= '</tr></thead><tbody>'; 1048c2e8227SGreg Roach 1058c2e8227SGreg Roach $found = false; 1068c2e8227SGreg Roach $end_jd = $show_future ? 99999999 : WT_CLIENT_JD; 10724ec66ceSGreg Roach foreach (get_calendar_events(0, $end_jd, '_TODO', $WT_TREE) as $fact) { 1088c2e8227SGreg Roach $record = $fact->getParent(); 1098c2e8227SGreg Roach $user_name = $fact->getAttribute('_WT_USER'); 1108c2e8227SGreg Roach if ($user_name === Auth::user()->getUserName() || !$user_name && $show_unassigned || $user_name && $show_other) { 1118c2e8227SGreg Roach $content .= '<tr>'; 1128c2e8227SGreg Roach //-- Event date (sortable) 1138c2e8227SGreg Roach $content .= '<td>'; //hidden by datables code 1148c2e8227SGreg Roach $content .= $fact->getDate()->julianDay(); 1158c2e8227SGreg Roach $content .= '</td>'; 1168c2e8227SGreg Roach $content .= '<td class="wrap">' . $fact->getDate()->display() . '</td>'; 1178c2e8227SGreg Roach $content .= '<td class="wrap"><a href="' . $record->getHtmlUrl() . '">' . $record->getFullName() . '</a></td>'; 1188c2e8227SGreg Roach if ($show_unassigned || $show_other) { 1198c2e8227SGreg Roach $content .= '<td class="wrap">' . $user_name . '</td>'; 1208c2e8227SGreg Roach } 1218c2e8227SGreg Roach $text = $fact->getValue(); 1228c2e8227SGreg Roach $content .= '<td class="wrap">' . $text . '</td>'; 1238c2e8227SGreg Roach $content .= '</tr>'; 1248c2e8227SGreg Roach $found = true; 1258c2e8227SGreg Roach } 1268c2e8227SGreg Roach } 1278c2e8227SGreg Roach 1288c2e8227SGreg Roach $content .= '</tbody></table>'; 1298c2e8227SGreg Roach if (!$found) { 1308c2e8227SGreg Roach $content .= '<p>' . I18N::translate('There are no research tasks in this family tree.') . '</p>'; 1318c2e8227SGreg Roach } 1328c2e8227SGreg Roach 1338c2e8227SGreg Roach if ($template) { 1348c2e8227SGreg Roach if ($block) { 1358c2e8227SGreg Roach $class .= ' small_inner_block'; 1368c2e8227SGreg Roach } 137cbc1590aSGreg Roach 1388c2e8227SGreg Roach return Theme::theme()->formatBlock($id, $title, $class, $content); 1398c2e8227SGreg Roach } else { 1408c2e8227SGreg Roach return $content; 1418c2e8227SGreg Roach } 1428c2e8227SGreg Roach } 1438c2e8227SGreg Roach 1448c2e8227SGreg Roach /** {@inheritdoc} */ 1458c2e8227SGreg Roach public function loadAjax() { 1468c2e8227SGreg Roach return false; 1478c2e8227SGreg Roach } 1488c2e8227SGreg Roach 1498c2e8227SGreg Roach /** {@inheritdoc} */ 1508c2e8227SGreg Roach public function isUserBlock() { 1518c2e8227SGreg Roach return true; 1528c2e8227SGreg Roach } 1538c2e8227SGreg Roach 1548c2e8227SGreg Roach /** {@inheritdoc} */ 1558c2e8227SGreg Roach public function isGedcomBlock() { 1568c2e8227SGreg Roach return true; 1578c2e8227SGreg Roach } 1588c2e8227SGreg Roach 1598c2e8227SGreg Roach /** {@inheritdoc} */ 1608c2e8227SGreg Roach public function configureBlock($block_id) { 1618c2e8227SGreg Roach if (Filter::postBool('save') && Filter::checkCsrf()) { 162e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'show_other', Filter::postBool('show_other')); 163e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'show_unassigned', Filter::postBool('show_unassigned')); 164e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'show_future', Filter::postBool('show_future')); 165e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'block', Filter::postBool('block')); 1668c2e8227SGreg Roach } 1678c2e8227SGreg Roach 168e2a378d3SGreg Roach $show_other = $this->getBlockSetting($block_id, 'show_other', '1'); 169e2a378d3SGreg Roach $show_unassigned = $this->getBlockSetting($block_id, 'show_unassigned', '1'); 170e2a378d3SGreg Roach $show_future = $this->getBlockSetting($block_id, 'show_future', '1'); 171e2a378d3SGreg Roach $block = $this->getBlockSetting($block_id, 'block', '1'); 1728c2e8227SGreg Roach 1738c2e8227SGreg Roach ?> 1748c2e8227SGreg Roach <tr> 1758c2e8227SGreg Roach <td colspan="2"> 1768c2e8227SGreg Roach <?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.'); ?> 1778c2e8227SGreg Roach <?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.'); ?> 1788c2e8227SGreg Roach <?php echo I18N::translate('Research tasks are stored using the custom GEDCOM tag “_TODO”. Other genealogy applications may not recognize this tag.'); ?> 1798c2e8227SGreg Roach </td> 1808c2e8227SGreg Roach </tr> 1818c2e8227SGreg Roach <?php 1828c2e8227SGreg Roach 1838c2e8227SGreg Roach echo '<tr><td class="descriptionbox wrap width33">'; 1848c2e8227SGreg Roach echo I18N::translate('Show research tasks that are assigned to other users'); 1858c2e8227SGreg Roach echo '</td><td class="optionbox">'; 1868c2e8227SGreg Roach echo edit_field_yes_no('show_other', $show_other); 1878c2e8227SGreg Roach echo '</td></tr>'; 1888c2e8227SGreg Roach 1898c2e8227SGreg Roach echo '<tr><td class="descriptionbox wrap width33">'; 1908c2e8227SGreg Roach echo I18N::translate('Show research tasks that are not assigned to any user'); 1918c2e8227SGreg Roach echo '</td><td class="optionbox">'; 1928c2e8227SGreg Roach echo edit_field_yes_no('show_unassigned', $show_unassigned); 1938c2e8227SGreg Roach echo '</td></tr>'; 1948c2e8227SGreg Roach 1958c2e8227SGreg Roach echo '<tr><td class="descriptionbox wrap width33">'; 1968c2e8227SGreg Roach echo I18N::translate('Show research tasks that have a date in the future'); 1978c2e8227SGreg Roach echo '</td><td class="optionbox">'; 1988c2e8227SGreg Roach echo edit_field_yes_no('show_future', $show_future); 1998c2e8227SGreg Roach echo '</td></tr>'; 2008c2e8227SGreg Roach 2018c2e8227SGreg Roach echo '<tr><td class="descriptionbox wrap width33">'; 2028c2e8227SGreg Roach echo /* I18N: label for a yes/no option */ I18N::translate('Add a scrollbar when block contents grow'); 2038c2e8227SGreg Roach echo '</td><td class="optionbox">'; 2048c2e8227SGreg Roach echo edit_field_yes_no('block', $block); 2058c2e8227SGreg Roach echo '</td></tr>'; 2068c2e8227SGreg Roach } 2078c2e8227SGreg Roach} 208