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 19/** 20 * Class UpcomingAnniversariesModule 21 */ 22class UpcomingAnniversariesModule extends Module implements ModuleBlockInterface { 23 /** {@inheritdoc} */ 24 public function getTitle() { 25 return /* I18N: Name of a module */ I18N::translate('Upcoming events'); 26 } 27 28 /** {@inheritdoc} */ 29 public function getDescription() { 30 return /* I18N: Description of the “Upcoming events” module */ I18N::translate('A list of the anniversaries that will occur in the near future.'); 31 } 32 33 /** {@inheritdoc} */ 34 public function getBlock($block_id, $template = true, $cfg = null) { 35 global $ctype, $WT_TREE; 36 37 $days = get_block_setting($block_id, 'days', '7'); 38 $filter = get_block_setting($block_id, 'filter', '1'); 39 $onlyBDM = get_block_setting($block_id, 'onlyBDM', '0'); 40 $infoStyle = get_block_setting($block_id, 'infoStyle', 'table'); 41 $sortStyle = get_block_setting($block_id, 'sortStyle', 'alpha'); 42 $block = get_block_setting($block_id, 'block', '1'); 43 44 if ($cfg) { 45 foreach (array('days', 'filter', 'onlyBDM', 'infoStyle', 'sortStyle', 'block') as $name) { 46 if (array_key_exists($name, $cfg)) { 47 $$name = $cfg[$name]; 48 } 49 } 50 } 51 52 $startjd = WT_CLIENT_JD + 1; 53 $endjd = WT_CLIENT_JD + $days; 54 55 $id = $this->getName() . $block_id; 56 $class = $this->getName() . '_block'; 57 if ($ctype === 'gedcom' && Auth::isManager($WT_TREE) || $ctype === 'user' && Auth::check()) { 58 $title = '<i class="icon-admin" title="' . I18N::translate('Configure') . '" onclick="modalDialog(\'block_edit.php?block_id=' . $block_id . '\', \'' . $this->getTitle() . '\');"></i>'; 59 } else { 60 $title = ''; 61 } 62 $title .= $this->getTitle(); 63 64 $content = ''; 65 switch ($infoStyle) { 66 case 'list': 67 // Output style 1: Old format, no visible tables, much smaller text. Better suited to right side of page. 68 $content .= print_events_list($startjd, $endjd, $onlyBDM ? 'BIRT MARR DEAT' : '', $filter, $sortStyle); 69 break; 70 case 'table': 71 // Style 2: New format, tables, big text, etc. Not too good on right side of page 72 ob_start(); 73 $content .= print_events_table($startjd, $endjd, $onlyBDM ? 'BIRT MARR DEAT' : '', $filter, $sortStyle); 74 $content .= ob_get_clean(); 75 break; 76 } 77 78 if ($template) { 79 if ($block) { 80 $class .= ' small_inner_block'; 81 } 82 return Theme::theme()->formatBlock($id, $title, $class, $content); 83 } else { 84 return $content; 85 } 86 } 87 88 /** {@inheritdoc} */ 89 public function loadAjax() { 90 return true; 91 } 92 93 /** {@inheritdoc} */ 94 public function isUserBlock() { 95 return true; 96 } 97 98 /** {@inheritdoc} */ 99 public function isGedcomBlock() { 100 return true; 101 } 102 103 /** {@inheritdoc} */ 104 public function configureBlock($block_id) { 105 if (Filter::postBool('save') && Filter::checkCsrf()) { 106 set_block_setting($block_id, 'days', Filter::postInteger('days', 1, 30, 7)); 107 set_block_setting($block_id, 'filter', Filter::postBool('filter')); 108 set_block_setting($block_id, 'onlyBDM', Filter::postBool('onlyBDM')); 109 set_block_setting($block_id, 'infoStyle', Filter::post('infoStyle', 'list|table', 'table')); 110 set_block_setting($block_id, 'sortStyle', Filter::post('sortStyle', 'alpha|anniv', 'alpha')); 111 set_block_setting($block_id, 'block', Filter::postBool('block')); 112 } 113 114 $days = get_block_setting($block_id, 'days', '7'); 115 $filter = get_block_setting($block_id, 'filter', '1'); 116 $onlyBDM = get_block_setting($block_id, 'onlyBDM', '0'); 117 $infoStyle = get_block_setting($block_id, 'infoStyle', 'table'); 118 $sortStyle = get_block_setting($block_id, 'sortStyle', 'alpha'); 119 $block = get_block_setting($block_id, 'block', '1'); 120 121 echo '<tr><td class="descriptionbox wrap width33">'; 122 echo I18N::translate('Number of days to show'); 123 echo '</td><td class="optionbox">'; 124 echo '<input type="text" name="days" size="2" value="', $days, '">'; 125 echo ' <em>', I18N::plural('maximum %d day', 'maximum %d days', 30, 30), '</em>'; 126 echo '</td></tr>'; 127 128 echo '<tr><td class="descriptionbox wrap width33">'; 129 echo I18N::translate('Show only events of living individuals?'); 130 echo '</td><td class="optionbox">'; 131 echo edit_field_yes_no('filter', $filter); 132 echo '</td></tr>'; 133 134 echo '<tr><td class="descriptionbox wrap width33">'; 135 echo I18N::translate('Show only births, deaths, and marriages?'); 136 echo '</td><td class="optionbox">'; 137 echo edit_field_yes_no('onlyBDM', $onlyBDM); 138 echo '</td></tr>'; 139 140 echo '<tr><td class="descriptionbox wrap width33">'; 141 echo I18N::translate('Presentation style'); 142 echo '</td><td class="optionbox">'; 143 echo select_edit_control('infoStyle', array('list'=> I18N::translate('list'), 'table'=> I18N::translate('table')), null, $infoStyle, ''); 144 echo '</td></tr>'; 145 146 echo '<tr><td class="descriptionbox wrap width33">'; 147 echo I18N::translate('Sort order'); 148 echo '</td><td class="optionbox">'; 149 echo select_edit_control('sortStyle', array( 150 /* I18N: An option in a list-box */ 'alpha'=> I18N::translate('sort by name'), 151 /* I18N: An option in a list-box */ 'anniv'=> I18N::translate('sort by date'), 152 ), null, $sortStyle, ''); 153 echo '</td></tr>'; 154 155 echo '<tr><td class="descriptionbox wrap width33">'; 156 echo /* I18N: label for a yes/no option */ I18N::translate('Add a scrollbar when block contents grow'); 157 echo '</td><td class="optionbox">'; 158 echo edit_field_yes_no('block', $block); 159 echo '</td></tr>'; 160 } 161} 162