xref: /webtrees/app/Module/OnThisDayModule.php (revision 4b9ff166b3342695f2a94855b7a33368e6d55c35)
18c2e8227SGreg Roach<?php
28c2e8227SGreg Roachnamespace Fisharebest\Webtrees;
38c2e8227SGreg Roach
48c2e8227SGreg Roach/**
58c2e8227SGreg Roach * webtrees: online genealogy
68c2e8227SGreg Roach * Copyright (C) 2015 webtrees development team
78c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify
88c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by
98c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or
108c2e8227SGreg Roach * (at your option) any later version.
118c2e8227SGreg Roach * This program is distributed in the hope that it will be useful,
128c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
138c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
148c2e8227SGreg Roach * GNU General Public License for more details.
158c2e8227SGreg Roach * You should have received a copy of the GNU General Public License
168c2e8227SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
178c2e8227SGreg Roach */
188c2e8227SGreg Roach
198c2e8227SGreg Roach/**
208c2e8227SGreg Roach * Class OnThisDayModule
218c2e8227SGreg Roach */
228c2e8227SGreg Roachclass OnThisDayModule extends Module implements ModuleBlockInterface {
238c2e8227SGreg Roach	/** {@inheritdoc} */
248c2e8227SGreg Roach	public function getTitle() {
258c2e8227SGreg Roach		return /* I18N: Name of a module */ I18N::translate('On this day');
268c2e8227SGreg Roach	}
278c2e8227SGreg Roach
288c2e8227SGreg Roach	/** {@inheritdoc} */
298c2e8227SGreg Roach	public function getDescription() {
308c2e8227SGreg Roach		return /* I18N: Description of the “On this day” module */ I18N::translate('A list of the anniversaries that occur today.');
318c2e8227SGreg Roach	}
328c2e8227SGreg Roach
338c2e8227SGreg Roach	/** {@inheritdoc} */
348c2e8227SGreg Roach	public function getBlock($block_id, $template = true, $cfg = null) {
35*4b9ff166SGreg Roach		global $ctype, $WT_TREE;
368c2e8227SGreg Roach
378c2e8227SGreg Roach		$filter    = get_block_setting($block_id, 'filter', '1');
388c2e8227SGreg Roach		$onlyBDM   = get_block_setting($block_id, 'onlyBDM', '1');
398c2e8227SGreg Roach		$infoStyle = get_block_setting($block_id, 'infoStyle', 'table');
408c2e8227SGreg Roach		$sortStyle = get_block_setting($block_id, 'sortStyle', 'alpha');
418c2e8227SGreg Roach		$block     = get_block_setting($block_id, 'block', '1');
428c2e8227SGreg Roach
438c2e8227SGreg Roach		if ($cfg) {
448c2e8227SGreg Roach			foreach (array('filter', 'onlyBDM', 'infoStyle', 'sortStyle', 'block') as $name) {
458c2e8227SGreg Roach				if (array_key_exists($name, $cfg)) {
468c2e8227SGreg Roach					$$name = $cfg[$name];
478c2e8227SGreg Roach				}
488c2e8227SGreg Roach			}
498c2e8227SGreg Roach		}
508c2e8227SGreg Roach
518c2e8227SGreg Roach		$todayjd = WT_CLIENT_JD;
528c2e8227SGreg Roach
538c2e8227SGreg Roach		$id    = $this->getName() . $block_id;
548c2e8227SGreg Roach		$class = $this->getName() . '_block';
55*4b9ff166SGreg Roach		if ($ctype === 'gedcom' && Auth::isManager($WT_TREE) || $ctype === 'user' && Auth::check()) {
568c2e8227SGreg Roach			$title = '<i class="icon-admin" title="' . I18N::translate('Configure') . '" onclick="modalDialog(\'block_edit.php?block_id=' . $block_id . '\', \'' . $this->getTitle() . '\');"></i>';
578c2e8227SGreg Roach		} else {
588c2e8227SGreg Roach			$title = '';
598c2e8227SGreg Roach		}
608c2e8227SGreg Roach		$title .= $this->getTitle();
618c2e8227SGreg Roach
628c2e8227SGreg Roach		$content = '';
638c2e8227SGreg Roach		switch ($infoStyle) {
648c2e8227SGreg Roach		case 'list':
658c2e8227SGreg Roach			// Output style 1:  Old format, no visible tables, much smaller text.  Better suited to right side of page.
668c2e8227SGreg Roach			$content .= print_events_list($todayjd, $todayjd, $onlyBDM ? 'BIRT MARR DEAT' : '', $filter, $sortStyle);
678c2e8227SGreg Roach			break;
688c2e8227SGreg Roach		case 'table':
698c2e8227SGreg Roach			// Style 2: New format, tables, big text, etc.  Not too good on right side of page
708c2e8227SGreg Roach			ob_start();
718c2e8227SGreg Roach			$content .= print_events_table($todayjd, $todayjd, $onlyBDM ? 'BIRT MARR DEAT' : '', $filter, $sortStyle);
728c2e8227SGreg Roach			$content .= ob_get_clean();
738c2e8227SGreg Roach			break;
748c2e8227SGreg Roach		}
758c2e8227SGreg Roach
768c2e8227SGreg Roach		if ($template) {
778c2e8227SGreg Roach			if ($block) {
788c2e8227SGreg Roach				$class .= ' small_inner_block';
798c2e8227SGreg Roach			}
808c2e8227SGreg Roach			return Theme::theme()->formatBlock($id, $title, $class, $content);
818c2e8227SGreg Roach		} else {
828c2e8227SGreg Roach			return $content;
838c2e8227SGreg Roach		}
848c2e8227SGreg Roach	}
858c2e8227SGreg Roach
868c2e8227SGreg Roach	/** {@inheritdoc} */
878c2e8227SGreg Roach	public function loadAjax() {
888c2e8227SGreg Roach		return true;
898c2e8227SGreg Roach	}
908c2e8227SGreg Roach
918c2e8227SGreg Roach	/** {@inheritdoc} */
928c2e8227SGreg Roach	public function isUserBlock() {
938c2e8227SGreg Roach		return true;
948c2e8227SGreg Roach	}
958c2e8227SGreg Roach
968c2e8227SGreg Roach	/** {@inheritdoc} */
978c2e8227SGreg Roach	public function isGedcomBlock() {
988c2e8227SGreg Roach		return true;
998c2e8227SGreg Roach	}
1008c2e8227SGreg Roach
1018c2e8227SGreg Roach	/** {@inheritdoc} */
1028c2e8227SGreg Roach	public function configureBlock($block_id) {
1038c2e8227SGreg Roach		if (Filter::postBool('save') && Filter::checkCsrf()) {
1048c2e8227SGreg Roach			set_block_setting($block_id, 'filter', Filter::postBool('filter'));
1058c2e8227SGreg Roach			set_block_setting($block_id, 'onlyBDM', Filter::postBool('onlyBDM'));
1068c2e8227SGreg Roach			set_block_setting($block_id, 'infoStyle', Filter::post('infoStyle', 'list|table', 'table'));
1078c2e8227SGreg Roach			set_block_setting($block_id, 'sortStyle', Filter::post('sortStyle', 'alpha|anniv', 'alpha'));
1088c2e8227SGreg Roach			set_block_setting($block_id, 'block', Filter::postBool('block'));
1098c2e8227SGreg Roach		}
1108c2e8227SGreg Roach
1118c2e8227SGreg Roach		$filter    = get_block_setting($block_id, 'filter', '1');
1128c2e8227SGreg Roach		$onlyBDM   = get_block_setting($block_id, 'onlyBDM', '1');
1138c2e8227SGreg Roach		$infoStyle = get_block_setting($block_id, 'infoStyle', 'table');
1148c2e8227SGreg Roach		$sortStyle = get_block_setting($block_id, 'sortStyle', 'alpha');
1158c2e8227SGreg Roach		$block     = get_block_setting($block_id, 'block', '1');
1168c2e8227SGreg Roach
1178c2e8227SGreg Roach		echo '<tr><td class="descriptionbox wrap width33">';
1188c2e8227SGreg Roach		echo I18N::translate('Show only events of living individuals?');
1198c2e8227SGreg Roach		echo '</td><td class="optionbox">';
1208c2e8227SGreg Roach		echo edit_field_yes_no('filter', $filter);
1218c2e8227SGreg Roach		echo '</td></tr>';
1228c2e8227SGreg Roach
1238c2e8227SGreg Roach		echo '<tr><td class="descriptionbox wrap width33">';
1248c2e8227SGreg Roach		echo I18N::translate('Show only births, deaths, and marriages?');
1258c2e8227SGreg Roach		echo '</td><td class="optionbox">';
1268c2e8227SGreg Roach		echo edit_field_yes_no('onlyBDM', $onlyBDM);
1278c2e8227SGreg Roach		echo '</td></tr>';
1288c2e8227SGreg Roach
1298c2e8227SGreg Roach		echo '<tr><td class="descriptionbox wrap width33">';
1308c2e8227SGreg Roach		echo I18N::translate('Presentation style');
1318c2e8227SGreg Roach		echo '</td><td class="optionbox">';
1328c2e8227SGreg Roach		echo select_edit_control('infoStyle', array('list'=> I18N::translate('list'), 'table'=> I18N::translate('table')), null, $infoStyle, '');
1338c2e8227SGreg Roach		echo '</td></tr>';
1348c2e8227SGreg Roach
1358c2e8227SGreg Roach		echo '<tr><td class="descriptionbox wrap width33">';
1368c2e8227SGreg Roach		echo I18N::translate('Sort order');
1378c2e8227SGreg Roach		echo '</td><td class="optionbox">';
1388c2e8227SGreg Roach		echo select_edit_control('sortStyle', array(
1398c2e8227SGreg Roach			/* I18N: An option in a list-box */ 'alpha'=> I18N::translate('sort by name'),
1408c2e8227SGreg Roach			/* I18N: An option in a list-box */ 'anniv'=> I18N::translate('sort by date'),
1418c2e8227SGreg Roach		), null, $sortStyle, '');
1428c2e8227SGreg Roach		echo '</td></tr>';
1438c2e8227SGreg Roach
1448c2e8227SGreg Roach		echo '<tr><td class="descriptionbox wrap width33">';
1458c2e8227SGreg Roach		echo /* I18N: label for a yes/no option */ I18N::translate('Add a scrollbar when block contents grow');
1468c2e8227SGreg Roach		echo '</td><td class="optionbox">';
1478c2e8227SGreg Roach		echo edit_field_yes_no('block', $block);
1488c2e8227SGreg Roach		echo '</td></tr>';
1498c2e8227SGreg Roach	}
1508c2e8227SGreg Roach}
151