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