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 Roachuse Fisharebest\ExtCalendar\JewishCalendar; 208c2e8227SGreg Roachuse Rhumsaa\Uuid\Uuid; 218c2e8227SGreg Roach 228c2e8227SGreg Roach/** 238c2e8227SGreg Roach * Class YahrzeitModule 248c2e8227SGreg Roach */ 258c2e8227SGreg Roachclass YahrzeitModule extends Module implements ModuleBlockInterface { 268c2e8227SGreg Roach /** {@inheritdoc} */ 278c2e8227SGreg Roach public function getTitle() { 288c2e8227SGreg Roach return /* I18N: Name of a module. Yahrzeiten (the plural of Yahrzeit) are special anniversaries of deaths in the Hebrew faith/calendar. */ I18N::translate('Yahrzeiten'); 298c2e8227SGreg Roach } 308c2e8227SGreg Roach 318c2e8227SGreg Roach /** {@inheritdoc} */ 328c2e8227SGreg Roach public function getDescription() { 338c2e8227SGreg Roach return /* I18N: Description of the “Yahrzeiten” module. A “Hebrew death” is a death where the date is recorded in the Hebrew calendar. */ I18N::translate('A list of the Hebrew death anniversaries that will occur in the near future.'); 348c2e8227SGreg Roach } 358c2e8227SGreg Roach 368c2e8227SGreg Roach /** {@inheritdoc} */ 378c2e8227SGreg Roach public function getBlock($block_id, $template = true, $cfg = null) { 384b9ff166SGreg Roach global $ctype, $controller, $WT_TREE; 398c2e8227SGreg Roach 408c2e8227SGreg Roach $days = get_block_setting($block_id, 'days', '7'); 418c2e8227SGreg Roach $infoStyle = get_block_setting($block_id, 'infoStyle', 'table'); 428c2e8227SGreg Roach $calendar = get_block_setting($block_id, 'calendar', 'jewish'); 438c2e8227SGreg Roach $block = get_block_setting($block_id, 'block', '1'); 448c2e8227SGreg Roach 458c2e8227SGreg Roach if ($cfg) { 468c2e8227SGreg Roach foreach (array('days', 'infoStyle', 'block') as $name) { 478c2e8227SGreg Roach if (array_key_exists($name, $cfg)) { 488c2e8227SGreg Roach $$name = $cfg[$name]; 498c2e8227SGreg Roach } 508c2e8227SGreg Roach } 518c2e8227SGreg Roach } 528c2e8227SGreg Roach 538c2e8227SGreg Roach $startjd = WT_CLIENT_JD; 548c2e8227SGreg Roach $endjd = WT_CLIENT_JD + $days - 1; 558c2e8227SGreg Roach 568c2e8227SGreg Roach $id = $this->getName() . $block_id; 578c2e8227SGreg Roach $class = $this->getName() . '_block'; 584b9ff166SGreg Roach if ($ctype === 'gedcom' && Auth::isManager($WT_TREE) || $ctype === 'user' && Auth::check()) { 598c2e8227SGreg Roach $title = '<i class="icon-admin" title="' . I18N::translate('Configure') . '" onclick="modalDialog(\'block_edit.php?block_id=' . $block_id . '\', \'' . $this->getTitle() . '\');"></i>'; 608c2e8227SGreg Roach } else { 618c2e8227SGreg Roach $title = ''; 628c2e8227SGreg Roach } 638c2e8227SGreg Roach $title .= $this->getTitle(); 648c2e8227SGreg Roach 658c2e8227SGreg Roach $content = ''; 668c2e8227SGreg Roach // The standard anniversary rules cover most of the Yahrzeit rules, we just 678c2e8227SGreg Roach // need to handle a few special cases. 688c2e8227SGreg Roach // Fetch normal anniversaries... 698c2e8227SGreg Roach $yahrzeits = array(); 708c2e8227SGreg Roach for ($jd = $startjd - 1; $jd <= $endjd + $days; ++$jd) { 71*24ec66ceSGreg Roach foreach (get_anniversary_events($jd, 'DEAT _YART', $WT_TREE) as $fact) { 728c2e8227SGreg Roach // Exact hebrew dates only 738c2e8227SGreg Roach $date = $fact->getDate(); 748c2e8227SGreg Roach if ($date->minimumDate() instanceof JewishDate && $date->minimumJulianDay() === $date->maximumJulianDay()) { 758c2e8227SGreg Roach $fact->jd = $jd; 768c2e8227SGreg Roach $yahrzeits[] = $fact; 778c2e8227SGreg Roach } 788c2e8227SGreg Roach } 798c2e8227SGreg Roach } 808c2e8227SGreg Roach 818c2e8227SGreg Roach // ...then adjust dates 828c2e8227SGreg Roach $jewish_calendar = new JewishCalendar; 838c2e8227SGreg Roach 848c2e8227SGreg Roach foreach ($yahrzeits as $yahrzeit) { 858c2e8227SGreg Roach if ($yahrzeit->getTag() === 'DEAT') { 868c2e8227SGreg Roach $today = new JewishDate($yahrzeit->jd); 878a22d202SGreg Roach $hd = $yahrzeit->getDate()->minimumDate(); 888c2e8227SGreg Roach $hd1 = new JewishDate($hd); 898c2e8227SGreg Roach $hd1->y += 1; 908c2e8227SGreg Roach $hd1->setJdFromYmd(); 918c2e8227SGreg Roach // Special rules. See http://www.hebcal.com/help/anniv.html 928c2e8227SGreg Roach // Everything else is taken care of by our standard anniversary rules. 938c2e8227SGreg Roach if ($hd->d == 30 && $hd->m == 2 && $hd->y != 0 && $hd1->daysInMonth() < 30) { 948c2e8227SGreg Roach // 30 CSH - Last day in CSH 958c2e8227SGreg Roach $yahrzeit->jd = $jewish_calendar->ymdToJd($today->y, 3, 1) - 1; 968c2e8227SGreg Roach } elseif ($hd->d == 30 && $hd->m == 3 && $hd->y != 0 && $hd1->daysInMonth() < 30) { 978c2e8227SGreg Roach // 30 KSL - Last day in KSL 988c2e8227SGreg Roach $yahrzeit->jd = $jewish_calendar->ymdToJd($today->y, 4, 1) - 1; 998c2e8227SGreg Roach } elseif ($hd->d == 30 && $hd->m == 6 && $hd->y != 0 && $today->daysInMonth() < 30 && !$today->isLeapYear()) { 1008c2e8227SGreg Roach // 30 ADR - Last day in SHV 1018c2e8227SGreg Roach $yahrzeit->jd = $jewish_calendar->ymdToJd($today->y, 6, 1) - 1; 1028c2e8227SGreg Roach } 1038c2e8227SGreg Roach } 1048c2e8227SGreg Roach } 1058c2e8227SGreg Roach 1068c2e8227SGreg Roach switch ($infoStyle) { 1078c2e8227SGreg Roach case 'list': 1088c2e8227SGreg Roach foreach ($yahrzeits as $yahrzeit) { 1098c2e8227SGreg Roach if ($yahrzeit->jd >= $startjd && $yahrzeit->jd < $startjd + $days) { 1108c2e8227SGreg Roach $ind = $yahrzeit->getParent(); 1118c2e8227SGreg Roach $content .= "<a href=\"" . $ind->getHtmlUrl() . "\" class=\"list_item name2\">" . $ind->getFullName() . "</a>" . $ind->getSexImage(); 1128c2e8227SGreg Roach $content .= "<div class=\"indent\">"; 1138c2e8227SGreg Roach $content .= $yahrzeit->getDate()->display(true); 1148c2e8227SGreg Roach $content .= ', ' . I18N::translate('%s year anniversary', $yahrzeit->anniv); 1158c2e8227SGreg Roach $content .= "</div>"; 1168c2e8227SGreg Roach } 1178c2e8227SGreg Roach } 1188c2e8227SGreg Roach break; 1198c2e8227SGreg Roach case 'table': 1208c2e8227SGreg Roach default: 1218c2e8227SGreg Roach $table_id = Uuid::uuid4(); // table requires a unique ID 1228c2e8227SGreg Roach $controller 1238c2e8227SGreg Roach ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL) 1248c2e8227SGreg Roach ->addInlineJavascript(' 1258c2e8227SGreg Roach jQuery("#'.$table_id . '").dataTable({ 1268c2e8227SGreg Roach dom: \'t\', 1278c2e8227SGreg Roach ' . I18N::datatablesI18N() . ', 1288c2e8227SGreg Roach autoWidth: false, 1298c2e8227SGreg Roach paginate: false, 1308c2e8227SGreg Roach lengthChange: false, 1318c2e8227SGreg Roach filter: false, 1328c2e8227SGreg Roach info: true, 1338c2e8227SGreg Roach jQueryUI: true, 1348c2e8227SGreg Roach sorting: [[5,"asc"]], 1358c2e8227SGreg Roach columns: [ 1368c2e8227SGreg Roach /* 0-name */ { dataSort: 1 }, 1378c2e8227SGreg Roach /* 1-NAME */ { visible: false }, 1388c2e8227SGreg Roach /* 2-date */ { dataSort: 3 }, 1398c2e8227SGreg Roach /* 3-DATE */ { visible: false }, 1408c2e8227SGreg Roach /* 4-Aniv */ { class: "center"}, 1418c2e8227SGreg Roach /* 5-yart */ { dataSort: 6 }, 1428c2e8227SGreg Roach /* 6-YART */ { visible: false } 1438c2e8227SGreg Roach ] 1448c2e8227SGreg Roach }); 1458c2e8227SGreg Roach jQuery("#'.$table_id . '").css("visibility", "visible"); 1468c2e8227SGreg Roach jQuery(".loading-image").css("display", "none"); 1478c2e8227SGreg Roach '); 1488c2e8227SGreg Roach $content = ''; 1498c2e8227SGreg Roach $content .= '<div class="loading-image"> </div>'; 1508c2e8227SGreg Roach $content .= '<table id="' . $table_id . '" class="width100" style="visibility:hidden;">'; 1518c2e8227SGreg Roach $content .= '<thead><tr>'; 152764a01d9SGreg Roach $content .= '<th>' . GedcomTag::getLabel('NAME') . '</th>'; 153764a01d9SGreg Roach $content .= '<th>' . GedcomTag::getLabel('NAME') . '</th>'; 154764a01d9SGreg Roach $content .= '<th>' . GedcomTag::getLabel('DEAT') . '</th>'; 1558c2e8227SGreg Roach $content .= '<th>DEAT</th>'; 1568c2e8227SGreg Roach $content .= '<th><i class="icon-reminder" title="' . I18N::translate('Anniversary') . '"></i></th>'; 157764a01d9SGreg Roach $content .= '<th>' . GedcomTag::getLabel('_YART') . '</th>'; 1588c2e8227SGreg Roach $content .= '<th>_YART</th>'; 1598c2e8227SGreg Roach $content .= '</tr></thead><tbody>'; 1608c2e8227SGreg Roach 1618c2e8227SGreg Roach foreach ($yahrzeits as $yahrzeit) { 1628c2e8227SGreg Roach if ($yahrzeit->jd >= $startjd && $yahrzeit->jd < $startjd + $days) { 1638c2e8227SGreg Roach $content .= '<tr>'; 1648c2e8227SGreg Roach $ind = $yahrzeit->getParent(); 1658c2e8227SGreg Roach // Individual name(s) 1668c2e8227SGreg Roach $name = $ind->getFullName(); 1678c2e8227SGreg Roach $url = $ind->getHtmlUrl(); 1688c2e8227SGreg Roach $content .= '<td>'; 1698c2e8227SGreg Roach $content .= '<a href="' . $url . '">' . $name . '</a>'; 1708c2e8227SGreg Roach $content .= $ind->getSexImage(); 1718c2e8227SGreg Roach $addname = $ind->getAddName(); 1728c2e8227SGreg Roach if ($addname) { 1738c2e8227SGreg Roach $content .= '<br><a href="' . $url . '">' . $addname . '</a>'; 1748c2e8227SGreg Roach } 1758c2e8227SGreg Roach $content .= '</td>'; 1768c2e8227SGreg Roach $content .= '<td>' . $ind->getSortName() . '</td>'; 1778c2e8227SGreg Roach 1788c2e8227SGreg Roach // death/yahrzeit event date 1798c2e8227SGreg Roach $content .= '<td>' . $yahrzeit->getDate()->display() . '</td>'; 1808c2e8227SGreg Roach $content .= '<td>' . $yahrzeit->getDate()->julianDay() . '</td>'; // sortable date 1818c2e8227SGreg Roach 1828c2e8227SGreg Roach // Anniversary 1838c2e8227SGreg Roach $content .= '<td>' . $yahrzeit->anniv . '</td>'; 1848c2e8227SGreg Roach 1858c2e8227SGreg Roach // upcomming yahrzeit dates 1868c2e8227SGreg Roach switch ($calendar) { 1878c2e8227SGreg Roach case 'gregorian': 1888c2e8227SGreg Roach $today = new GregorianDate($yahrzeit->jd); 1898c2e8227SGreg Roach break; 1908c2e8227SGreg Roach case 'jewish': 1918c2e8227SGreg Roach default: 1928c2e8227SGreg Roach $today = new JewishDate($yahrzeit->jd); 1938c2e8227SGreg Roach break; 1948c2e8227SGreg Roach } 1958c2e8227SGreg Roach $td = new Date($today->format('%@ %A %O %E')); 1968c2e8227SGreg Roach $content .= '<td>' . $td->display() . '</td>'; 1978c2e8227SGreg Roach $content .= '<td>' . $td->julianDay() . '</td>'; // sortable date 1988c2e8227SGreg Roach 1998c2e8227SGreg Roach $content .= '</tr>'; 2008c2e8227SGreg Roach } 2018c2e8227SGreg Roach } 2028c2e8227SGreg Roach $content .= '</tbody></table>'; 2038c2e8227SGreg Roach 2048c2e8227SGreg Roach break; 2058c2e8227SGreg Roach } 2068c2e8227SGreg Roach 2078c2e8227SGreg Roach if ($template) { 2088c2e8227SGreg Roach if ($block) { 2098c2e8227SGreg Roach $class .= ' small_inner_block'; 2108c2e8227SGreg Roach } 2118c2e8227SGreg Roach return Theme::theme()->formatBlock($id, $title, $class, $content); 2128c2e8227SGreg Roach } else { 2138c2e8227SGreg Roach return $content; 2148c2e8227SGreg Roach } 2158c2e8227SGreg Roach } 2168c2e8227SGreg Roach 2178c2e8227SGreg Roach /** {@inheritdoc} */ 2188c2e8227SGreg Roach public function loadAjax() { 2198c2e8227SGreg Roach return true; 2208c2e8227SGreg Roach } 2218c2e8227SGreg Roach 2228c2e8227SGreg Roach /** {@inheritdoc} */ 2238c2e8227SGreg Roach public function isUserBlock() { 2248c2e8227SGreg Roach return true; 2258c2e8227SGreg Roach } 2268c2e8227SGreg Roach 2278c2e8227SGreg Roach /** {@inheritdoc} */ 2288c2e8227SGreg Roach public function isGedcomBlock() { 2298c2e8227SGreg Roach return true; 2308c2e8227SGreg Roach } 2318c2e8227SGreg Roach 2328c2e8227SGreg Roach /** {@inheritdoc} */ 2338c2e8227SGreg Roach public function configureBlock($block_id) { 2348c2e8227SGreg Roach if (Filter::postBool('save') && Filter::checkCsrf()) { 2358c2e8227SGreg Roach set_block_setting($block_id, 'days', Filter::postInteger('days', 1, 30, 7)); 2368c2e8227SGreg Roach set_block_setting($block_id, 'infoStyle', Filter::post('infoStyle', 'list|table', 'table')); 2378c2e8227SGreg Roach set_block_setting($block_id, 'calendar', Filter::post('calendar', 'jewish|gregorian', 'jewish')); 2388c2e8227SGreg Roach set_block_setting($block_id, 'block', Filter::postBool('block')); 2398c2e8227SGreg Roach } 2408c2e8227SGreg Roach 2418c2e8227SGreg Roach $days = get_block_setting($block_id, 'days', '7'); 2428c2e8227SGreg Roach $infoStyle = get_block_setting($block_id, 'infoStyle', 'table'); 2438c2e8227SGreg Roach $calendar = get_block_setting($block_id, 'calendar', 'jewish'); 2448c2e8227SGreg Roach $block = get_block_setting($block_id, 'block', '1'); 2458c2e8227SGreg Roach 2468c2e8227SGreg Roach echo '<tr><td class="descriptionbox wrap width33">'; 2478c2e8227SGreg Roach echo I18N::translate('Number of days to show'); 2488c2e8227SGreg Roach echo '</td><td class="optionbox">'; 2498c2e8227SGreg Roach echo '<input type="text" name="days" size="2" value="' . $days . '">'; 2508c2e8227SGreg Roach echo ' <em>', I18N::plural('maximum %d day', 'maximum %d days', 30, 30), '</em>'; 2518c2e8227SGreg Roach echo '</td></tr>'; 2528c2e8227SGreg Roach 2538c2e8227SGreg Roach echo '<tr><td class="descriptionbox wrap width33">'; 2548c2e8227SGreg Roach echo I18N::translate('Presentation style'); 2558c2e8227SGreg Roach echo '</td><td class="optionbox">'; 2568c2e8227SGreg Roach echo select_edit_control('infoStyle', array('list'=> I18N::translate('list'), 'table'=> I18N::translate('table')), null, $infoStyle, ''); 2578c2e8227SGreg Roach echo '</td></tr>'; 2588c2e8227SGreg Roach 2598c2e8227SGreg Roach echo '<tr><td class="descriptionbox wrap width33">'; 2608c2e8227SGreg Roach echo I18N::translate('Calendar'); 2618c2e8227SGreg Roach echo '</td><td class="optionbox">'; 2628c2e8227SGreg Roach echo select_edit_control('calendar', array( 2638c2e8227SGreg Roach 'jewish' => JewishDate::calendarName(), 2648c2e8227SGreg Roach 'gregorian'=> GregorianDate::calendarName(), 2658c2e8227SGreg Roach ), null, $calendar, ''); 2668c2e8227SGreg Roach echo '</td></tr>'; 2678c2e8227SGreg Roach 2688c2e8227SGreg Roach echo '<tr><td class="descriptionbox wrap width33">'; 2698c2e8227SGreg Roach echo /* I18N: label for a yes/no option */ I18N::translate('Add a scrollbar when block contents grow'); 2708c2e8227SGreg Roach echo '</td><td class="optionbox">'; 2718c2e8227SGreg Roach echo edit_field_yes_no('block', $block); 2728c2e8227SGreg Roach echo '</td></tr>'; 2738c2e8227SGreg Roach } 2748c2e8227SGreg Roach} 275