18c2e8227SGreg Roach<?php 20e62c4b8SGreg Roachnamespace Fisharebest\Webtrees\Module; 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 */ 180e62c4b8SGreg Roachuse Fisharebest\Webtrees\Auth; 190e62c4b8SGreg Roachuse Fisharebest\Webtrees\Database; 200e62c4b8SGreg Roachuse Fisharebest\Webtrees\Filter; 21*3d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsDate; 22*3d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsEdit; 230e62c4b8SGreg Roachuse Fisharebest\Webtrees\GedcomRecord; 240e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N; 250e62c4b8SGreg Roachuse Fisharebest\Webtrees\Mail; 260e62c4b8SGreg Roachuse Fisharebest\Webtrees\Site; 270e62c4b8SGreg Roachuse Fisharebest\Webtrees\Theme; 280e62c4b8SGreg Roachuse Fisharebest\Webtrees\Tree; 290e62c4b8SGreg Roachuse Fisharebest\Webtrees\User; 308c2e8227SGreg Roach 318c2e8227SGreg Roach/** 328c2e8227SGreg Roach * Class ReviewChangesModule 338c2e8227SGreg Roach */ 34e2a378d3SGreg Roachclass ReviewChangesModule extends AbstractModule implements ModuleBlockInterface { 358c2e8227SGreg Roach /** {@inheritdoc} */ 368c2e8227SGreg Roach public function getTitle() { 378c2e8227SGreg Roach return /* I18N: Name of a module */ I18N::translate('Pending changes'); 388c2e8227SGreg Roach } 398c2e8227SGreg Roach 408c2e8227SGreg Roach /** {@inheritdoc} */ 418c2e8227SGreg Roach public function getDescription() { 428c2e8227SGreg Roach return /* I18N: Description of the “Pending changes” module */ I18N::translate('A list of changes that need moderator approval, and email notifications.'); 438c2e8227SGreg Roach } 448c2e8227SGreg Roach 458c2e8227SGreg Roach /** {@inheritdoc} */ 468c2e8227SGreg Roach public function getBlock($block_id, $template = true, $cfg = null) { 478c2e8227SGreg Roach global $ctype, $WT_TREE; 488c2e8227SGreg Roach 49e2a378d3SGreg Roach $sendmail = $this->getBlockSetting($block_id, 'sendmail', '1'); 50e2a378d3SGreg Roach $days = $this->getBlockSetting($block_id, 'days', '1'); 51e2a378d3SGreg Roach $block = $this->getBlockSetting($block_id, 'block', '1'); 528c2e8227SGreg Roach 538c2e8227SGreg Roach if ($cfg) { 548c2e8227SGreg Roach foreach (array('days', 'sendmail', 'block') as $name) { 558c2e8227SGreg Roach if (array_key_exists($name, $cfg)) { 568c2e8227SGreg Roach $$name = $cfg[$name]; 578c2e8227SGreg Roach } 588c2e8227SGreg Roach } 598c2e8227SGreg Roach } 608c2e8227SGreg Roach 618c2e8227SGreg Roach $changes = Database::prepare( 628c2e8227SGreg Roach "SELECT 1" . 638c2e8227SGreg Roach " FROM `##change`" . 648c2e8227SGreg Roach " WHERE status='pending'" . 658c2e8227SGreg Roach " LIMIT 1" 668c2e8227SGreg Roach )->fetchOne(); 678c2e8227SGreg Roach 688c2e8227SGreg Roach if ($changes && $sendmail == 'yes') { 698c2e8227SGreg Roach // There are pending changes - tell moderators/managers/administrators about them. 708c2e8227SGreg Roach if (WT_TIMESTAMP - Site::getPreference('LAST_CHANGE_EMAIL') > (60 * 60 * 24 * $days)) { 718c2e8227SGreg Roach // Which users have pending changes? 728c2e8227SGreg Roach foreach (User::all() as $user) { 738c2e8227SGreg Roach if ($user->getPreference('contactmethod') !== 'none') { 748c2e8227SGreg Roach foreach (Tree::getAll() as $tree) { 758c2e8227SGreg Roach if ($tree->hasPendingEdit() && Auth::isManager($tree, $user)) { 768c2e8227SGreg Roach I18N::init($user->getPreference('language')); 778c2e8227SGreg Roach Mail::systemMessage( 788c2e8227SGreg Roach $tree, 798c2e8227SGreg Roach $user, 808c2e8227SGreg Roach I18N::translate('Pending changes'), 818c2e8227SGreg Roach I18N::translate('There are pending changes for you to moderate.') . 828c2e8227SGreg Roach Mail::EOL . Mail::EOL . 834b9ff166SGreg Roach '<a href="' . WT_BASE_URL . 'index.php?ged=' . $WT_TREE->getNameUrl() . '">' . WT_BASE_URL . 'index.php?ged=' . $WT_TREE->getNameUrl() . '</a>' 848c2e8227SGreg Roach ); 858c2e8227SGreg Roach I18N::init(WT_LOCALE); 868c2e8227SGreg Roach } 878c2e8227SGreg Roach } 888c2e8227SGreg Roach } 898c2e8227SGreg Roach } 908c2e8227SGreg Roach Site::setPreference('LAST_CHANGE_EMAIL', WT_TIMESTAMP); 918c2e8227SGreg Roach } 928c2e8227SGreg Roach } 938c2e8227SGreg Roach if (Auth::isEditor($WT_TREE) && $WT_TREE->hasPendingEdit()) { 948c2e8227SGreg Roach $id = $this->getName() . $block_id; 958c2e8227SGreg Roach $class = $this->getName() . '_block'; 968c2e8227SGreg Roach if ($ctype === 'user' || Auth::isManager($WT_TREE)) { 979353052eSGreg Roach $title = '<a class="icon-admin" title="' . I18N::translate('Configure') . '" href="block_edit.php?block_id=' . $block_id . '&ged=' . $WT_TREE->getNameHtml() . '&ctype=' . $ctype . '"></a>'; 988c2e8227SGreg Roach } else { 998c2e8227SGreg Roach $title = ''; 1008c2e8227SGreg Roach } 1018c2e8227SGreg Roach $title .= $this->getTitle(); 1028c2e8227SGreg Roach 1038c2e8227SGreg Roach $content = ''; 1048c2e8227SGreg Roach if (Auth::isModerator($WT_TREE)) { 1058c2e8227SGreg Roach $content .= "<a href=\"#\" onclick=\"window.open('edit_changes.php','_blank', chan_window_specs); return false;\">" . I18N::translate('There are pending changes for you to moderate.') . "</a><br>"; 1068c2e8227SGreg Roach } 1078c2e8227SGreg Roach if ($sendmail == "yes") { 108*3d7a8a4cSGreg Roach $content .= I18N::translate('Last email reminder was sent ') . FunctionsDate::formatTimestamp(Site::getPreference('LAST_CHANGE_EMAIL')) . "<br>"; 109*3d7a8a4cSGreg Roach $content .= I18N::translate('Next email reminder will be sent after ') . FunctionsDate::formatTimestamp(Site::getPreference('LAST_CHANGE_EMAIL') + (60 * 60 * 24 * $days)) . "<br><br>"; 1108c2e8227SGreg Roach } 1118c2e8227SGreg Roach $content .= '<ul>'; 1128c2e8227SGreg Roach $changes = Database::prepare( 1138c2e8227SGreg Roach "SELECT xref" . 1148c2e8227SGreg Roach " FROM `##change`" . 1158c2e8227SGreg Roach " WHERE status='pending'" . 1168c2e8227SGreg Roach " AND gedcom_id=?" . 1178c2e8227SGreg Roach " GROUP BY xref" 11824ec66ceSGreg Roach )->execute(array($WT_TREE->getTreeId()))->fetchAll(); 1198c2e8227SGreg Roach foreach ($changes as $change) { 12024ec66ceSGreg Roach $record = GedcomRecord::getInstance($change->xref, $WT_TREE); 1218c2e8227SGreg Roach if ($record->canShow()) { 1228c2e8227SGreg Roach $content .= '<li><a href="' . $record->getHtmlUrl() . '">' . $record->getFullName() . '</a></li>'; 1238c2e8227SGreg Roach } 1248c2e8227SGreg Roach } 1258c2e8227SGreg Roach $content .= '</ul>'; 1268c2e8227SGreg Roach 1278c2e8227SGreg Roach if ($template) { 1288c2e8227SGreg Roach if ($block) { 1298c2e8227SGreg Roach $class .= ' small_inner_block'; 1308c2e8227SGreg Roach } 131cbc1590aSGreg Roach 1328c2e8227SGreg Roach return Theme::theme()->formatBlock($id, $title, $class, $content); 1338c2e8227SGreg Roach } else { 1348c2e8227SGreg Roach return $content; 1358c2e8227SGreg Roach } 1368c2e8227SGreg Roach } 1378c2e8227SGreg Roach } 1388c2e8227SGreg Roach 1398c2e8227SGreg Roach /** {@inheritdoc} */ 1408c2e8227SGreg Roach public function loadAjax() { 1418c2e8227SGreg Roach return false; 1428c2e8227SGreg Roach } 1438c2e8227SGreg Roach 1448c2e8227SGreg Roach /** {@inheritdoc} */ 1458c2e8227SGreg Roach public function isUserBlock() { 1468c2e8227SGreg Roach return true; 1478c2e8227SGreg Roach } 1488c2e8227SGreg Roach 1498c2e8227SGreg Roach /** {@inheritdoc} */ 1508c2e8227SGreg Roach public function isGedcomBlock() { 1518c2e8227SGreg Roach return true; 1528c2e8227SGreg Roach } 1538c2e8227SGreg Roach 1548c2e8227SGreg Roach /** {@inheritdoc} */ 1558c2e8227SGreg Roach public function configureBlock($block_id) { 1568c2e8227SGreg Roach if (Filter::postBool('save') && Filter::checkCsrf()) { 157e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'days', Filter::postInteger('num', 1, 180, 1)); 158e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'sendmail', Filter::postBool('sendmail')); 159e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'block', Filter::postBool('block')); 1608c2e8227SGreg Roach } 1618c2e8227SGreg Roach 162e2a378d3SGreg Roach $sendmail = $this->getBlockSetting($block_id, 'sendmail', '1'); 163e2a378d3SGreg Roach $days = $this->getBlockSetting($block_id, 'days', '1'); 164e2a378d3SGreg Roach $block = $this->getBlockSetting($block_id, 'block', '1'); 1658c2e8227SGreg Roach 1668c2e8227SGreg Roach ?> 1678c2e8227SGreg Roach <tr> 1688c2e8227SGreg Roach <td colspan="2"> 1698c2e8227SGreg Roach <?php echo I18N::translate('This block will show editors a list of records with pending changes that need to be approved by a moderator. It also generates daily emails to moderators whenever pending changes exist.'); ?> 1708c2e8227SGreg Roach </td> 1718c2e8227SGreg Roach </tr> 1728c2e8227SGreg Roach 1738c2e8227SGreg Roach <?php 1748c2e8227SGreg Roach echo '<tr><td class="descriptionbox wrap width33">'; 1758c2e8227SGreg Roach echo I18N::translate('Send out reminder emails?'); 1768c2e8227SGreg Roach echo '</td><td class="optionbox">'; 177*3d7a8a4cSGreg Roach echo FunctionsEdit::editFieldYesNo('sendmail', $sendmail); 1788c2e8227SGreg Roach echo '<br>'; 1798c2e8227SGreg Roach echo I18N::translate('Reminder email frequency (days)') . " <input type='text' name='days' value='" . $days . "' size='2'>"; 1808c2e8227SGreg Roach echo '</td></tr>'; 1818c2e8227SGreg Roach 1828c2e8227SGreg Roach echo '<tr><td class="descriptionbox wrap width33">'; 1838c2e8227SGreg Roach echo /* I18N: label for a yes/no option */ I18N::translate('Add a scrollbar when block contents grow'); 1848c2e8227SGreg Roach echo '</td><td class="optionbox">'; 185*3d7a8a4cSGreg Roach echo FunctionsEdit::editFieldYesNo('block', $block); 1868c2e8227SGreg Roach echo '</td></tr>'; 1878c2e8227SGreg Roach } 1888c2e8227SGreg Roach} 189