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