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