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