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