xref: /webtrees/app/Module/OnThisDayModule.php (revision 8c2e82270a639a3acf607b432e54721116dae723)
1*8c2e8227SGreg Roach<?php
2*8c2e8227SGreg Roachnamespace Fisharebest\Webtrees;
3*8c2e8227SGreg Roach
4*8c2e8227SGreg Roach/**
5*8c2e8227SGreg Roach * webtrees: online genealogy
6*8c2e8227SGreg Roach * Copyright (C) 2015 webtrees development team
7*8c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify
8*8c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by
9*8c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or
10*8c2e8227SGreg Roach * (at your option) any later version.
11*8c2e8227SGreg Roach * This program is distributed in the hope that it will be useful,
12*8c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
13*8c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14*8c2e8227SGreg Roach * GNU General Public License for more details.
15*8c2e8227SGreg Roach * You should have received a copy of the GNU General Public License
16*8c2e8227SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
17*8c2e8227SGreg Roach */
18*8c2e8227SGreg Roach
19*8c2e8227SGreg Roach/**
20*8c2e8227SGreg Roach * Class OnThisDayModule
21*8c2e8227SGreg Roach */
22*8c2e8227SGreg Roachclass OnThisDayModule extends Module implements ModuleBlockInterface {
23*8c2e8227SGreg Roach	/** {@inheritdoc} */
24*8c2e8227SGreg Roach	public function getTitle() {
25*8c2e8227SGreg Roach		return /* I18N: Name of a module */ I18N::translate('On this day');
26*8c2e8227SGreg Roach	}
27*8c2e8227SGreg Roach
28*8c2e8227SGreg Roach	/** {@inheritdoc} */
29*8c2e8227SGreg Roach	public function getDescription() {
30*8c2e8227SGreg Roach		return /* I18N: Description of the “On this day” module */ I18N::translate('A list of the anniversaries that occur today.');
31*8c2e8227SGreg Roach	}
32*8c2e8227SGreg Roach
33*8c2e8227SGreg Roach	/** {@inheritdoc} */
34*8c2e8227SGreg Roach	public function getBlock($block_id, $template = true, $cfg = null) {
35*8c2e8227SGreg Roach		global $ctype;
36*8c2e8227SGreg Roach
37*8c2e8227SGreg Roach		$filter    = get_block_setting($block_id, 'filter', '1');
38*8c2e8227SGreg Roach		$onlyBDM   = get_block_setting($block_id, 'onlyBDM', '1');
39*8c2e8227SGreg Roach		$infoStyle = get_block_setting($block_id, 'infoStyle', 'table');
40*8c2e8227SGreg Roach		$sortStyle = get_block_setting($block_id, 'sortStyle', 'alpha');
41*8c2e8227SGreg Roach		$block     = get_block_setting($block_id, 'block', '1');
42*8c2e8227SGreg Roach
43*8c2e8227SGreg Roach		if ($cfg) {
44*8c2e8227SGreg Roach			foreach (array('filter', 'onlyBDM', 'infoStyle', 'sortStyle', 'block') as $name) {
45*8c2e8227SGreg Roach				if (array_key_exists($name, $cfg)) {
46*8c2e8227SGreg Roach					$$name = $cfg[$name];
47*8c2e8227SGreg Roach				}
48*8c2e8227SGreg Roach			}
49*8c2e8227SGreg Roach		}
50*8c2e8227SGreg Roach
51*8c2e8227SGreg Roach		$todayjd = WT_CLIENT_JD;
52*8c2e8227SGreg Roach
53*8c2e8227SGreg Roach		$id    = $this->getName() . $block_id;
54*8c2e8227SGreg Roach		$class = $this->getName() . '_block';
55*8c2e8227SGreg Roach		if ($ctype === 'gedcom' && WT_USER_GEDCOM_ADMIN || $ctype === 'user' && Auth::check()) {
56*8c2e8227SGreg Roach			$title = '<i class="icon-admin" title="' . I18N::translate('Configure') . '" onclick="modalDialog(\'block_edit.php?block_id=' . $block_id . '\', \'' . $this->getTitle() . '\');"></i>';
57*8c2e8227SGreg Roach		} else {
58*8c2e8227SGreg Roach			$title = '';
59*8c2e8227SGreg Roach		}
60*8c2e8227SGreg Roach		$title .= $this->getTitle();
61*8c2e8227SGreg Roach
62*8c2e8227SGreg Roach		$content = '';
63*8c2e8227SGreg Roach		switch ($infoStyle) {
64*8c2e8227SGreg Roach		case 'list':
65*8c2e8227SGreg Roach			// Output style 1:  Old format, no visible tables, much smaller text.  Better suited to right side of page.
66*8c2e8227SGreg Roach			$content .= print_events_list($todayjd, $todayjd, $onlyBDM ? 'BIRT MARR DEAT' : '', $filter, $sortStyle);
67*8c2e8227SGreg Roach			break;
68*8c2e8227SGreg Roach		case 'table':
69*8c2e8227SGreg Roach			// Style 2: New format, tables, big text, etc.  Not too good on right side of page
70*8c2e8227SGreg Roach			ob_start();
71*8c2e8227SGreg Roach			$content .= print_events_table($todayjd, $todayjd, $onlyBDM ? 'BIRT MARR DEAT' : '', $filter, $sortStyle);
72*8c2e8227SGreg Roach			$content .= ob_get_clean();
73*8c2e8227SGreg Roach			break;
74*8c2e8227SGreg Roach		}
75*8c2e8227SGreg Roach
76*8c2e8227SGreg Roach		if ($template) {
77*8c2e8227SGreg Roach			if ($block) {
78*8c2e8227SGreg Roach				$class .= ' small_inner_block';
79*8c2e8227SGreg Roach			}
80*8c2e8227SGreg Roach			return Theme::theme()->formatBlock($id, $title, $class, $content);
81*8c2e8227SGreg Roach		} else {
82*8c2e8227SGreg Roach			return $content;
83*8c2e8227SGreg Roach		}
84*8c2e8227SGreg Roach	}
85*8c2e8227SGreg Roach
86*8c2e8227SGreg Roach	/** {@inheritdoc} */
87*8c2e8227SGreg Roach	public function loadAjax() {
88*8c2e8227SGreg Roach		return true;
89*8c2e8227SGreg Roach	}
90*8c2e8227SGreg Roach
91*8c2e8227SGreg Roach	/** {@inheritdoc} */
92*8c2e8227SGreg Roach	public function isUserBlock() {
93*8c2e8227SGreg Roach		return true;
94*8c2e8227SGreg Roach	}
95*8c2e8227SGreg Roach
96*8c2e8227SGreg Roach	/** {@inheritdoc} */
97*8c2e8227SGreg Roach	public function isGedcomBlock() {
98*8c2e8227SGreg Roach		return true;
99*8c2e8227SGreg Roach	}
100*8c2e8227SGreg Roach
101*8c2e8227SGreg Roach	/** {@inheritdoc} */
102*8c2e8227SGreg Roach	public function configureBlock($block_id) {
103*8c2e8227SGreg Roach		if (Filter::postBool('save') && Filter::checkCsrf()) {
104*8c2e8227SGreg Roach			set_block_setting($block_id, 'filter', Filter::postBool('filter'));
105*8c2e8227SGreg Roach			set_block_setting($block_id, 'onlyBDM', Filter::postBool('onlyBDM'));
106*8c2e8227SGreg Roach			set_block_setting($block_id, 'infoStyle', Filter::post('infoStyle', 'list|table', 'table'));
107*8c2e8227SGreg Roach			set_block_setting($block_id, 'sortStyle', Filter::post('sortStyle', 'alpha|anniv', 'alpha'));
108*8c2e8227SGreg Roach			set_block_setting($block_id, 'block', Filter::postBool('block'));
109*8c2e8227SGreg Roach		}
110*8c2e8227SGreg Roach
111*8c2e8227SGreg Roach		$filter    = get_block_setting($block_id, 'filter', '1');
112*8c2e8227SGreg Roach		$onlyBDM   = get_block_setting($block_id, 'onlyBDM', '1');
113*8c2e8227SGreg Roach		$infoStyle = get_block_setting($block_id, 'infoStyle', 'table');
114*8c2e8227SGreg Roach		$sortStyle = get_block_setting($block_id, 'sortStyle', 'alpha');
115*8c2e8227SGreg Roach		$block     = get_block_setting($block_id, 'block', '1');
116*8c2e8227SGreg Roach
117*8c2e8227SGreg Roach		echo '<tr><td class="descriptionbox wrap width33">';
118*8c2e8227SGreg Roach		echo I18N::translate('Show only events of living individuals?');
119*8c2e8227SGreg Roach		echo '</td><td class="optionbox">';
120*8c2e8227SGreg Roach		echo edit_field_yes_no('filter', $filter);
121*8c2e8227SGreg Roach		echo '</td></tr>';
122*8c2e8227SGreg Roach
123*8c2e8227SGreg Roach		echo '<tr><td class="descriptionbox wrap width33">';
124*8c2e8227SGreg Roach		echo I18N::translate('Show only births, deaths, and marriages?');
125*8c2e8227SGreg Roach		echo '</td><td class="optionbox">';
126*8c2e8227SGreg Roach		echo edit_field_yes_no('onlyBDM', $onlyBDM);
127*8c2e8227SGreg Roach		echo '</td></tr>';
128*8c2e8227SGreg Roach
129*8c2e8227SGreg Roach		echo '<tr><td class="descriptionbox wrap width33">';
130*8c2e8227SGreg Roach		echo I18N::translate('Presentation style');
131*8c2e8227SGreg Roach		echo '</td><td class="optionbox">';
132*8c2e8227SGreg Roach		echo select_edit_control('infoStyle', array('list'=> I18N::translate('list'), 'table'=> I18N::translate('table')), null, $infoStyle, '');
133*8c2e8227SGreg Roach		echo '</td></tr>';
134*8c2e8227SGreg Roach
135*8c2e8227SGreg Roach		echo '<tr><td class="descriptionbox wrap width33">';
136*8c2e8227SGreg Roach		echo I18N::translate('Sort order');
137*8c2e8227SGreg Roach		echo '</td><td class="optionbox">';
138*8c2e8227SGreg Roach		echo select_edit_control('sortStyle', array(
139*8c2e8227SGreg Roach			/* I18N: An option in a list-box */ 'alpha'=> I18N::translate('sort by name'),
140*8c2e8227SGreg Roach			/* I18N: An option in a list-box */ 'anniv'=> I18N::translate('sort by date'),
141*8c2e8227SGreg Roach		), null, $sortStyle, '');
142*8c2e8227SGreg Roach		echo '</td></tr>';
143*8c2e8227SGreg Roach
144*8c2e8227SGreg Roach		echo '<tr><td class="descriptionbox wrap width33">';
145*8c2e8227SGreg Roach		echo /* I18N: label for a yes/no option */ I18N::translate('Add a scrollbar when block contents grow');
146*8c2e8227SGreg Roach		echo '</td><td class="optionbox">';
147*8c2e8227SGreg Roach		echo edit_field_yes_no('block', $block);
148*8c2e8227SGreg Roach		echo '</td></tr>';
149*8c2e8227SGreg Roach	}
150*8c2e8227SGreg Roach}
151