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 81 return Theme::theme()->formatBlock($id, $title, $class, $content); 82 } else { 83 return $content; 84 } 85 } 86 87 /** {@inheritdoc} */ 88 public function loadAjax() { 89 return true; 90 } 91 92 /** {@inheritdoc} */ 93 public function isUserBlock() { 94 return true; 95 } 96 97 /** {@inheritdoc} */ 98 public function isGedcomBlock() { 99 return true; 100 } 101 102 /** {@inheritdoc} */ 103 public function configureBlock($block_id) { 104 if (Filter::postBool('save') && Filter::checkCsrf()) { 105 $this->setBlockSetting($block_id, 'filter', Filter::postBool('filter')); 106 $this->setBlockSetting($block_id, 'onlyBDM', Filter::postBool('onlyBDM')); 107 $this->setBlockSetting($block_id, 'infoStyle', Filter::post('infoStyle', 'list|table', 'table')); 108 $this->setBlockSetting($block_id, 'sortStyle', Filter::post('sortStyle', 'alpha|anniv', 'alpha')); 109 $this->setBlockSetting($block_id, 'block', Filter::postBool('block')); 110 } 111 112 $filter = $this->getBlockSetting($block_id, 'filter', '1'); 113 $onlyBDM = $this->getBlockSetting($block_id, 'onlyBDM', '1'); 114 $infoStyle = $this->getBlockSetting($block_id, 'infoStyle', 'table'); 115 $sortStyle = $this->getBlockSetting($block_id, 'sortStyle', 'alpha'); 116 $block = $this->getBlockSetting($block_id, 'block', '1'); 117 118 echo '<tr><td class="descriptionbox wrap width33">'; 119 echo I18N::translate('Show only events of living individuals?'); 120 echo '</td><td class="optionbox">'; 121 echo edit_field_yes_no('filter', $filter); 122 echo '</td></tr>'; 123 124 echo '<tr><td class="descriptionbox wrap width33">'; 125 echo I18N::translate('Show only births, deaths, and marriages?'); 126 echo '</td><td class="optionbox">'; 127 echo edit_field_yes_no('onlyBDM', $onlyBDM); 128 echo '</td></tr>'; 129 130 echo '<tr><td class="descriptionbox wrap width33">'; 131 echo I18N::translate('Presentation style'); 132 echo '</td><td class="optionbox">'; 133 echo select_edit_control('infoStyle', array('list' => I18N::translate('list'), 'table' => I18N::translate('table')), null, $infoStyle, ''); 134 echo '</td></tr>'; 135 136 echo '<tr><td class="descriptionbox wrap width33">'; 137 echo I18N::translate('Sort order'); 138 echo '</td><td class="optionbox">'; 139 echo select_edit_control('sortStyle', array( 140 /* I18N: An option in a list-box */ 'alpha' => I18N::translate('sort by name'), 141 /* I18N: An option in a list-box */ 'anniv' => I18N::translate('sort by date'), 142 ), null, $sortStyle, ''); 143 echo '</td></tr>'; 144 145 echo '<tr><td class="descriptionbox wrap width33">'; 146 echo /* I18N: label for a yes/no option */ I18N::translate('Add a scrollbar when block contents grow'); 147 echo '</td><td class="optionbox">'; 148 echo edit_field_yes_no('block', $block); 149 echo '</td></tr>'; 150 } 151} 152