1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2016 webtrees development team 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16namespace Fisharebest\Webtrees\Module; 17 18use Fisharebest\Webtrees\Auth; 19use Fisharebest\Webtrees\Database; 20use Fisharebest\Webtrees\Filter; 21use Fisharebest\Webtrees\Functions\FunctionsDb; 22use Fisharebest\Webtrees\Functions\FunctionsEdit; 23use Fisharebest\Webtrees\GedcomRecord; 24use Fisharebest\Webtrees\GedcomTag; 25use Fisharebest\Webtrees\I18N; 26use Fisharebest\Webtrees\Theme; 27use Rhumsaa\Uuid\Uuid; 28 29/** 30 * Class ResearchTaskModule 31 */ 32class ResearchTaskModule extends AbstractModule implements ModuleBlockInterface { 33 const DEFAULT_SHOW_OTHER = '1'; 34 const DEFAULT_SHOW_UNASSIGNED = '1'; 35 const DEFAULT_SHOW_FUTURE = '1'; 36 const DEFAULT_BLOCK = '1'; 37 38 /** {@inheritdoc} */ 39 public function getTitle() { 40 return /* I18N: Name of a module. Tasks that need further research. */ I18N::translate('Research tasks'); 41 } 42 43 /** {@inheritdoc} */ 44 public function getDescription() { 45 return /* I18N: Description of “Research tasks” module */ I18N::translate('A list of tasks and activities that are linked to the family tree.'); 46 } 47 48 /** 49 * Generate the HTML content of this block. 50 * 51 * @param int $block_id 52 * @param bool $template 53 * @param string[] $cfg 54 * 55 * @return string 56 */ 57 public function getBlock($block_id, $template = true, $cfg = array()) { 58 global $ctype, $controller, $WT_TREE; 59 60 $show_other = $this->getBlockSetting($block_id, 'show_other', self::DEFAULT_SHOW_OTHER); 61 $show_unassigned = $this->getBlockSetting($block_id, 'show_unassigned', self::DEFAULT_SHOW_UNASSIGNED); 62 $show_future = $this->getBlockSetting($block_id, 'show_future', self::DEFAULT_SHOW_FUTURE); 63 $block = $this->getBlockSetting($block_id, 'block', self::DEFAULT_BLOCK); 64 65 foreach (array('show_unassigned', 'show_other', 'show_future', 'block') as $name) { 66 if (array_key_exists($name, $cfg)) { 67 $$name = $cfg[$name]; 68 } 69 } 70 71 $id = $this->getName() . $block_id; 72 $class = $this->getName() . '_block'; 73 if ($ctype === 'gedcom' && Auth::isManager($WT_TREE) || $ctype === 'user' && Auth::check()) { 74 $title = '<a class="icon-admin" title="' . I18N::translate('Configure') . '" href="block_edit.php?block_id=' . $block_id . '&ged=' . $WT_TREE->getNameHtml() . '&ctype=' . $ctype . '"></a>'; 75 } else { 76 $title = ''; 77 } 78 $title .= $this->getTitle(); 79 80 $table_id = Uuid::uuid4(); // create a unique ID 81 82 $controller 83 ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL) 84 ->addInlineJavascript(' 85 jQuery("#' . $table_id . '").dataTable({ 86 dom: \'t\', 87 ' . I18N::datatablesI18N() . ', 88 autoWidth: false, 89 paginate: false, 90 lengthChange: false, 91 filter: false, 92 info: true, 93 jQueryUI: true, 94 columns: [ 95 /* 0-DATE */ null, 96 /* 1-Date */ { dataSort: 0 }, 97 /* 2-Record */ null, 98 /* 3-Username */ null, 99 /* 4-Text */ null 100 ] 101 }); 102 jQuery("#' . $table_id . '").css("visibility", "visible"); 103 jQuery(".loading-image").css("display", "none"); 104 '); 105 106 $content = ''; 107 $content .= '<div class="loading-image"> </div>'; 108 $content .= '<table id="' . $table_id . '" style="visibility:hidden;">'; 109 $content .= '<thead><tr>'; 110 $content .= '<th hidden>DATE</th>'; 111 $content .= '<th>' . GedcomTag::getLabel('DATE') . '</th>'; 112 $content .= '<th>' . I18N::translate('Record') . '</th>'; 113 $content .= '<th>' . I18N::translate('Username') . '</th>'; 114 $content .= '<th>' . GedcomTag::getLabel('TEXT') . '</th>'; 115 $content .= '</tr></thead><tbody>'; 116 117 $found = false; 118 $end_jd = $show_future ? 99999999 : WT_CLIENT_JD; 119 120 $xrefs = Database::prepare( 121 "SELECT DISTINCT d_gid FROM `##dates`" . 122 " WHERE d_file = :tree_id AND d_fact = '_TODO' AND d_julianday1 < :jd" 123 )->execute(array( 124 'tree_id' => $WT_TREE->getTreeId(), 125 'jd' => $end_jd, 126 ))->fetchOneColumn(); 127 128 $facts = array(); 129 foreach ($xrefs as $xref) { 130 $record = GedcomRecord::getInstance($xref, $WT_TREE); 131 if ($record->canShow()) { 132 foreach ($record->getFacts('_TODO') as $fact) { 133 $facts[] = $fact; 134 } 135 } 136 } 137 138 foreach ($facts as $fact) { 139 $record = $fact->getParent(); 140 $user_name = $fact->getAttribute('_WT_USER'); 141 if ($user_name === Auth::user()->getUserName() || !$user_name && $show_unassigned || $user_name && $show_other) { 142 $content .= '<tr>'; 143 $content .= '<td hidden>' . $fact->getDate()->julianDay() . '</td>'; 144 $content .= '<td class="wrap">' . $fact->getDate()->display() . '</td>'; 145 $content .= '<td class="wrap"><a href="' . $record->getHtmlUrl() . '">' . $record->getFullName() . '</a></td>'; 146 $content .= '<td class="wrap">' . $user_name . '</td>'; 147 $content .= '<td class="wrap" dir="auto">' . $fact->getValue() . '</td>'; 148 $content .= '</tr>'; 149 $found = true; 150 } 151 } 152 153 $content .= '</tbody></table>'; 154 if (!$found) { 155 $content .= '<p>' . I18N::translate('There are no research tasks in this family tree.') . '</p>'; 156 } 157 158 if ($template) { 159 if ($block) { 160 $class .= ' small_inner_block'; 161 } 162 163 return Theme::theme()->formatBlock($id, $title, $class, $content); 164 } else { 165 return $content; 166 } 167 } 168 169 /** {@inheritdoc} */ 170 public function loadAjax() { 171 return false; 172 } 173 174 /** {@inheritdoc} */ 175 public function isUserBlock() { 176 return true; 177 } 178 179 /** {@inheritdoc} */ 180 public function isGedcomBlock() { 181 return true; 182 } 183 184 /** 185 * An HTML form to edit block settings 186 * 187 * @param int $block_id 188 */ 189 public function configureBlock($block_id) { 190 if (Filter::postBool('save') && Filter::checkCsrf()) { 191 $this->setBlockSetting($block_id, 'show_other', Filter::postBool('show_other')); 192 $this->setBlockSetting($block_id, 'show_unassigned', Filter::postBool('show_unassigned')); 193 $this->setBlockSetting($block_id, 'show_future', Filter::postBool('show_future')); 194 $this->setBlockSetting($block_id, 'block', Filter::postBool('block')); 195 } 196 197 $show_other = $this->getBlockSetting($block_id, 'show_other', self::DEFAULT_SHOW_OTHER); 198 $show_unassigned = $this->getBlockSetting($block_id, 'show_unassigned', self::DEFAULT_SHOW_UNASSIGNED); 199 $show_future = $this->getBlockSetting($block_id, 'show_future', self::DEFAULT_SHOW_FUTURE); 200 $block = $this->getBlockSetting($block_id, 'block', self::DEFAULT_BLOCK); 201 202 ?> 203 <tr> 204 <td colspan="2"> 205 <?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.'); ?> 206 <?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.'); ?> 207 <?php echo I18N::translate('Research tasks are stored using the custom GEDCOM tag “_TODO”. Other genealogy applications may not recognize this tag.'); ?> 208 </td> 209 </tr> 210 <?php 211 212 echo '<tr><td class="descriptionbox wrap width33">'; 213 echo I18N::translate('Show research tasks that are assigned to other users'); 214 echo '</td><td class="optionbox">'; 215 echo FunctionsEdit::editFieldYesNo('show_other', $show_other); 216 echo '</td></tr>'; 217 218 echo '<tr><td class="descriptionbox wrap width33">'; 219 echo I18N::translate('Show research tasks that are not assigned to any user'); 220 echo '</td><td class="optionbox">'; 221 echo FunctionsEdit::editFieldYesNo('show_unassigned', $show_unassigned); 222 echo '</td></tr>'; 223 224 echo '<tr><td class="descriptionbox wrap width33">'; 225 echo I18N::translate('Show research tasks that have a date in the future'); 226 echo '</td><td class="optionbox">'; 227 echo FunctionsEdit::editFieldYesNo('show_future', $show_future); 228 echo '</td></tr>'; 229 230 echo '<tr><td class="descriptionbox wrap width33">'; 231 echo /* I18N: label for a yes/no option */ I18N::translate('Add a scrollbar when block contents grow'); 232 echo '</td><td class="optionbox">'; 233 echo FunctionsEdit::editFieldYesNo('block', $block); 234 echo '</td></tr>'; 235 } 236} 237