18c2e8227SGreg Roach<?php 28c2e8227SGreg Roach/** 38c2e8227SGreg Roach * webtrees: online genealogy 4369c0ce6SGreg Roach * Copyright (C) 2016 webtrees development team 58c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify 68c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by 78c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or 88c2e8227SGreg Roach * (at your option) any later version. 98c2e8227SGreg Roach * This program is distributed in the hope that it will be useful, 108c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 118c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 128c2e8227SGreg Roach * GNU General Public License for more details. 138c2e8227SGreg Roach * You should have received a copy of the GNU General Public License 148c2e8227SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 158c2e8227SGreg Roach */ 1676692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module; 178c2e8227SGreg Roach 180e62c4b8SGreg Roachuse Fisharebest\Webtrees\Auth; 1964b9f5b2SGreg Roachuse Fisharebest\Webtrees\Database; 200e62c4b8SGreg Roachuse Fisharebest\Webtrees\Filter; 213d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsEdit; 2264b9f5b2SGreg Roachuse Fisharebest\Webtrees\GedcomRecord; 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 { 3264b9f5b2SGreg Roach const DEFAULT_SHOW_OTHER = '1'; 3364b9f5b2SGreg Roach const DEFAULT_SHOW_UNASSIGNED = '1'; 3464b9f5b2SGreg Roach const DEFAULT_SHOW_FUTURE = '1'; 3564b9f5b2SGreg Roach const DEFAULT_BLOCK = '1'; 3664b9f5b2SGreg Roach 378c2e8227SGreg Roach /** {@inheritdoc} */ 388c2e8227SGreg Roach public function getTitle() { 398c2e8227SGreg Roach return /* I18N: Name of a module. Tasks that need further research. */ I18N::translate('Research tasks'); 408c2e8227SGreg Roach } 418c2e8227SGreg Roach 428c2e8227SGreg Roach /** {@inheritdoc} */ 438c2e8227SGreg Roach public function getDescription() { 448c2e8227SGreg Roach return /* I18N: Description of “Research tasks” module */ I18N::translate('A list of tasks and activities that are linked to the family tree.'); 458c2e8227SGreg Roach } 468c2e8227SGreg Roach 4776692c8bSGreg Roach /** 4876692c8bSGreg Roach * Generate the HTML content of this block. 4976692c8bSGreg Roach * 5076692c8bSGreg Roach * @param int $block_id 5176692c8bSGreg Roach * @param bool $template 52727f238cSGreg Roach * @param string[] $cfg 5376692c8bSGreg Roach * 5476692c8bSGreg Roach * @return string 5576692c8bSGreg Roach */ 5676692c8bSGreg Roach public function getBlock($block_id, $template = true, $cfg = array()) { 574b9ff166SGreg Roach global $ctype, $controller, $WT_TREE; 588c2e8227SGreg Roach 5964b9f5b2SGreg Roach $show_other = $this->getBlockSetting($block_id, 'show_other', self::DEFAULT_SHOW_OTHER); 6064b9f5b2SGreg Roach $show_unassigned = $this->getBlockSetting($block_id, 'show_unassigned', self::DEFAULT_SHOW_UNASSIGNED); 6164b9f5b2SGreg Roach $show_future = $this->getBlockSetting($block_id, 'show_future', self::DEFAULT_SHOW_FUTURE); 6264b9f5b2SGreg Roach $block = $this->getBlockSetting($block_id, 'block', self::DEFAULT_BLOCK); 638c2e8227SGreg Roach 648c2e8227SGreg Roach foreach (array('show_unassigned', 'show_other', 'show_future', 'block') as $name) { 658c2e8227SGreg Roach if (array_key_exists($name, $cfg)) { 668c2e8227SGreg Roach $$name = $cfg[$name]; 678c2e8227SGreg Roach } 688c2e8227SGreg Roach } 698c2e8227SGreg Roach 708c2e8227SGreg Roach $id = $this->getName() . $block_id; 718c2e8227SGreg Roach $class = $this->getName() . '_block'; 724b9ff166SGreg Roach if ($ctype === 'gedcom' && Auth::isManager($WT_TREE) || $ctype === 'user' && Auth::check()) { 73*6d1c8039SGreg Roach $title = '<a class="icon-admin" title="' . I18N::translate('Preferences') . '" href="block_edit.php?block_id=' . $block_id . '&ged=' . $WT_TREE->getNameHtml() . '&ctype=' . $ctype . '"></a>'; 748c2e8227SGreg Roach } else { 758c2e8227SGreg Roach $title = ''; 768c2e8227SGreg Roach } 778c2e8227SGreg Roach $title .= $this->getTitle(); 788c2e8227SGreg Roach 798c2e8227SGreg Roach $table_id = Uuid::uuid4(); // create a unique ID 808c2e8227SGreg Roach 818c2e8227SGreg Roach $controller 828c2e8227SGreg Roach ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL) 838c2e8227SGreg Roach ->addInlineJavascript(' 848c2e8227SGreg Roach jQuery("#' . $table_id . '").dataTable({ 858c2e8227SGreg Roach dom: \'t\', 868c2e8227SGreg Roach ' . I18N::datatablesI18N() . ', 878c2e8227SGreg Roach autoWidth: false, 888c2e8227SGreg Roach paginate: false, 898c2e8227SGreg Roach lengthChange: false, 908c2e8227SGreg Roach filter: false, 918c2e8227SGreg Roach info: true, 928c2e8227SGreg Roach jQueryUI: true, 938c2e8227SGreg Roach columns: [ 9464b9f5b2SGreg Roach /* 0-DATE */ null, 958c2e8227SGreg Roach /* 1-Date */ { dataSort: 0 }, 9664b9f5b2SGreg Roach /* 2-Record */ null, 9764b9f5b2SGreg Roach /* 3-Username */ null, 9864b9f5b2SGreg Roach /* 4-Text */ null 998c2e8227SGreg Roach ] 1008c2e8227SGreg Roach }); 1018c2e8227SGreg Roach jQuery("#' . $table_id . '").css("visibility", "visible"); 1028c2e8227SGreg Roach jQuery(".loading-image").css("display", "none"); 1038c2e8227SGreg Roach '); 1048c2e8227SGreg Roach 1058c2e8227SGreg Roach $content = ''; 1068c2e8227SGreg Roach $content .= '<div class="loading-image"> </div>'; 1078c2e8227SGreg Roach $content .= '<table id="' . $table_id . '" style="visibility:hidden;">'; 1088c2e8227SGreg Roach $content .= '<thead><tr>'; 10964b9f5b2SGreg Roach $content .= '<th hidden>DATE</th>'; 110764a01d9SGreg Roach $content .= '<th>' . GedcomTag::getLabel('DATE') . '</th>'; 1118c2e8227SGreg Roach $content .= '<th>' . I18N::translate('Record') . '</th>'; 1128c2e8227SGreg Roach $content .= '<th>' . I18N::translate('Username') . '</th>'; 113764a01d9SGreg Roach $content .= '<th>' . GedcomTag::getLabel('TEXT') . '</th>'; 1148c2e8227SGreg Roach $content .= '</tr></thead><tbody>'; 1158c2e8227SGreg Roach 1168c2e8227SGreg Roach $found = false; 1178c2e8227SGreg Roach $end_jd = $show_future ? 99999999 : WT_CLIENT_JD; 11864b9f5b2SGreg Roach 11964b9f5b2SGreg Roach $xrefs = Database::prepare( 120c19940adSGreg Roach "SELECT DISTINCT d_gid FROM `##dates`" . 121c19940adSGreg Roach " WHERE d_file = :tree_id AND d_fact = '_TODO' AND d_julianday1 < :jd" 12264b9f5b2SGreg Roach )->execute(array( 123c19940adSGreg Roach 'tree_id' => $WT_TREE->getTreeId(), 12464b9f5b2SGreg Roach 'jd' => $end_jd, 12564b9f5b2SGreg Roach ))->fetchOneColumn(); 12664b9f5b2SGreg Roach 12764b9f5b2SGreg Roach $facts = array(); 12864b9f5b2SGreg Roach foreach ($xrefs as $xref) { 12964b9f5b2SGreg Roach $record = GedcomRecord::getInstance($xref, $WT_TREE); 13064b9f5b2SGreg Roach if ($record->canShow()) { 13164b9f5b2SGreg Roach foreach ($record->getFacts('_TODO') as $fact) { 13264b9f5b2SGreg Roach $facts[] = $fact; 13364b9f5b2SGreg Roach } 13464b9f5b2SGreg Roach } 13564b9f5b2SGreg Roach } 13664b9f5b2SGreg Roach 13764b9f5b2SGreg Roach foreach ($facts as $fact) { 1388c2e8227SGreg Roach $record = $fact->getParent(); 1398c2e8227SGreg Roach $user_name = $fact->getAttribute('_WT_USER'); 1408c2e8227SGreg Roach if ($user_name === Auth::user()->getUserName() || !$user_name && $show_unassigned || $user_name && $show_other) { 1418c2e8227SGreg Roach $content .= '<tr>'; 14264b9f5b2SGreg Roach $content .= '<td hidden>' . $fact->getDate()->julianDay() . '</td>'; 1438c2e8227SGreg Roach $content .= '<td class="wrap">' . $fact->getDate()->display() . '</td>'; 1448c2e8227SGreg Roach $content .= '<td class="wrap"><a href="' . $record->getHtmlUrl() . '">' . $record->getFullName() . '</a></td>'; 1458c2e8227SGreg Roach $content .= '<td class="wrap">' . $user_name . '</td>'; 146f9ba92dfSGreg Roach $content .= '<td class="wrap" dir="auto">' . $fact->getValue() . '</td>'; 1478c2e8227SGreg Roach $content .= '</tr>'; 1488c2e8227SGreg Roach $found = true; 1498c2e8227SGreg Roach } 1508c2e8227SGreg Roach } 1518c2e8227SGreg Roach 1528c2e8227SGreg Roach $content .= '</tbody></table>'; 1538c2e8227SGreg Roach if (!$found) { 1548c2e8227SGreg Roach $content .= '<p>' . I18N::translate('There are no research tasks in this family tree.') . '</p>'; 1558c2e8227SGreg Roach } 1568c2e8227SGreg Roach 1578c2e8227SGreg Roach if ($template) { 1588c2e8227SGreg Roach if ($block) { 1598c2e8227SGreg Roach $class .= ' small_inner_block'; 1608c2e8227SGreg Roach } 161cbc1590aSGreg Roach 1628c2e8227SGreg Roach return Theme::theme()->formatBlock($id, $title, $class, $content); 1638c2e8227SGreg Roach } else { 1648c2e8227SGreg Roach return $content; 1658c2e8227SGreg Roach } 1668c2e8227SGreg Roach } 1678c2e8227SGreg Roach 1688c2e8227SGreg Roach /** {@inheritdoc} */ 1698c2e8227SGreg Roach public function loadAjax() { 1708c2e8227SGreg Roach return false; 1718c2e8227SGreg Roach } 1728c2e8227SGreg Roach 1738c2e8227SGreg Roach /** {@inheritdoc} */ 1748c2e8227SGreg Roach public function isUserBlock() { 1758c2e8227SGreg Roach return true; 1768c2e8227SGreg Roach } 1778c2e8227SGreg Roach 1788c2e8227SGreg Roach /** {@inheritdoc} */ 1798c2e8227SGreg Roach public function isGedcomBlock() { 1808c2e8227SGreg Roach return true; 1818c2e8227SGreg Roach } 1828c2e8227SGreg Roach 18376692c8bSGreg Roach /** 18476692c8bSGreg Roach * An HTML form to edit block settings 18576692c8bSGreg Roach * 18676692c8bSGreg Roach * @param int $block_id 18776692c8bSGreg Roach */ 1888c2e8227SGreg Roach public function configureBlock($block_id) { 1898c2e8227SGreg Roach if (Filter::postBool('save') && Filter::checkCsrf()) { 190e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'show_other', Filter::postBool('show_other')); 191e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'show_unassigned', Filter::postBool('show_unassigned')); 192e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'show_future', Filter::postBool('show_future')); 193e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'block', Filter::postBool('block')); 1948c2e8227SGreg Roach } 1958c2e8227SGreg Roach 19664b9f5b2SGreg Roach $show_other = $this->getBlockSetting($block_id, 'show_other', self::DEFAULT_SHOW_OTHER); 19764b9f5b2SGreg Roach $show_unassigned = $this->getBlockSetting($block_id, 'show_unassigned', self::DEFAULT_SHOW_UNASSIGNED); 19864b9f5b2SGreg Roach $show_future = $this->getBlockSetting($block_id, 'show_future', self::DEFAULT_SHOW_FUTURE); 19964b9f5b2SGreg Roach $block = $this->getBlockSetting($block_id, 'block', self::DEFAULT_BLOCK); 2008c2e8227SGreg Roach 2018c2e8227SGreg Roach ?> 2028c2e8227SGreg Roach <tr> 2038c2e8227SGreg Roach <td colspan="2"> 2048c2e8227SGreg 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.'); ?> 2058c2e8227SGreg 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.'); ?> 2068c2e8227SGreg Roach <?php echo I18N::translate('Research tasks are stored using the custom GEDCOM tag “_TODO”. Other genealogy applications may not recognize this tag.'); ?> 2078c2e8227SGreg Roach </td> 2088c2e8227SGreg Roach </tr> 2098c2e8227SGreg Roach <?php 2108c2e8227SGreg Roach 2118c2e8227SGreg Roach echo '<tr><td class="descriptionbox wrap width33">'; 2128c2e8227SGreg Roach echo I18N::translate('Show research tasks that are assigned to other users'); 2138c2e8227SGreg Roach echo '</td><td class="optionbox">'; 2143d7a8a4cSGreg Roach echo FunctionsEdit::editFieldYesNo('show_other', $show_other); 2158c2e8227SGreg Roach echo '</td></tr>'; 2168c2e8227SGreg Roach 2178c2e8227SGreg Roach echo '<tr><td class="descriptionbox wrap width33">'; 2188c2e8227SGreg Roach echo I18N::translate('Show research tasks that are not assigned to any user'); 2198c2e8227SGreg Roach echo '</td><td class="optionbox">'; 2203d7a8a4cSGreg Roach echo FunctionsEdit::editFieldYesNo('show_unassigned', $show_unassigned); 2218c2e8227SGreg Roach echo '</td></tr>'; 2228c2e8227SGreg Roach 2238c2e8227SGreg Roach echo '<tr><td class="descriptionbox wrap width33">'; 2248c2e8227SGreg Roach echo I18N::translate('Show research tasks that have a date in the future'); 2258c2e8227SGreg Roach echo '</td><td class="optionbox">'; 2263d7a8a4cSGreg Roach echo FunctionsEdit::editFieldYesNo('show_future', $show_future); 2278c2e8227SGreg Roach echo '</td></tr>'; 2288c2e8227SGreg Roach 2298c2e8227SGreg Roach echo '<tr><td class="descriptionbox wrap width33">'; 2308c2e8227SGreg Roach echo /* I18N: label for a yes/no option */ I18N::translate('Add a scrollbar when block contents grow'); 2318c2e8227SGreg Roach echo '</td><td class="optionbox">'; 2323d7a8a4cSGreg Roach echo FunctionsEdit::editFieldYesNo('block', $block); 2338c2e8227SGreg Roach echo '</td></tr>'; 2348c2e8227SGreg Roach } 2358c2e8227SGreg Roach} 236