From 760f1a679e3aa9be28735323c13ec4fb8dff80f8 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Mon, 22 Jul 2013 10:58:39 +0200 Subject: [PATCH] Allow admin to disable notification system This addresses #497 and allows the admins to disable notifications through the admin panel. Might be used by those relying on clients using the API instead. Once merged it will fix #497. --- cronjobs/findblock.php | 22 ++++++----- cronjobs/notifications.php | 6 +++ .../pages/account/notifications.inc.php | 37 +++++++++++-------- public/include/pages/admin/settings.inc.php | 1 + public/include/smarty_globals.inc.php | 1 + .../mmcFE/admin/settings/default.tpl | 10 +++++ public/templates/mmcFE/global/navigation.tpl | 2 +- 7 files changed, 52 insertions(+), 27 deletions(-) diff --git a/cronjobs/findblock.php b/cronjobs/findblock.php index 0336deea..d55b7f64 100755 --- a/cronjobs/findblock.php +++ b/cronjobs/findblock.php @@ -115,16 +115,18 @@ if (empty($aAllBlocks)) { . $share->share_type ); - // Notify users - $aAccounts = $notification->getNotificationAccountIdByType('new_block'); - if (is_array($aAccounts)) { - foreach ($aAccounts as $aData) { - $aMailData['height'] = $aBlock['height']; - $aMailData['subject'] = 'New Block'; - $aMailData['email'] = $user->getUserEmail($user->getUserName($aData['account_id'])); - $aMailData['shares'] = $iRoundShares; - if (!$notification->sendNotification($aData['account_id'], 'new_block', $aMailData)) - $log->logError('Failed to notify user of new found block: ' . $user->getUserName($aData['account_id'])); + if ($setting->getValue('disable_notification') != 1) { + // Notify users + $aAccounts = $notification->getNotificationAccountIdByType('new_block'); + if (is_array($aAccounts)) { + foreach ($aAccounts as $aData) { + $aMailData['height'] = $aBlock['height']; + $aMailData['subject'] = 'New Block'; + $aMailData['email'] = $user->getUserEmail($user->getUserName($aData['account_id'])); + $aMailData['shares'] = $iRoundShares; + if (!$notification->sendNotification($aData['account_id'], 'new_block', $aMailData)) + $log->logError('Failed to notify user of new found block: ' . $user->getUserName($aData['account_id'])); + } } } } diff --git a/cronjobs/notifications.php b/cronjobs/notifications.php index effcf002..c3f2f29c 100755 --- a/cronjobs/notifications.php +++ b/cronjobs/notifications.php @@ -22,6 +22,12 @@ limitations under the License. // Include all settings and classes require_once('shared.inc.php'); +if ($setting->getValue('disable_notifications') == 1) { + $monitoring->setStatus($cron_name . "_active", "yesno", 0); + $monitoring->setStatus($cron_name . "_message", "message", "Cron disabled by admin"); + $monitoring->setStatus($cron_name . "_status", "okerror", 0); + exit(0); +} $log->logDebug(" IDLE Worker Notifications ..."); // Find all IDLE workers diff --git a/public/include/pages/account/notifications.inc.php b/public/include/pages/account/notifications.inc.php index 3f013ed0..a4b5aab0 100644 --- a/public/include/pages/account/notifications.inc.php +++ b/public/include/pages/account/notifications.inc.php @@ -3,23 +3,28 @@ // Make sure we are called from index.php if (!defined('SECURITY')) die('Hacking attempt'); if ($user->isAuthenticated()) { - if (@$_REQUEST['do'] == 'save') { - if ($notification->updateSettings($_SESSION['USERDATA']['id'], $_REQUEST['data'])) { - $_SESSION['POPUP'][] = array('CONTENT' => 'Updated notification settings'); - } else { - $_SESSION['POPUP'][] = array('CONTENT' => 'Failed to update settings', 'TYPE' => 'errormsg'); + if ($setting->getValue('disable_notifications') == 1) { + $_SESSION['POPUP'][] = array('CONTENT' => 'Notification system disabled by admin.', 'TYPE' => 'info'); + $smarty->assign('CONTENT', '../../global/empty.tpl'); + } else { + if (@$_REQUEST['do'] == 'save') { + if ($notification->updateSettings($_SESSION['USERDATA']['id'], $_REQUEST['data'])) { + $_SESSION['POPUP'][] = array('CONTENT' => 'Updated notification settings'); + } else { + $_SESSION['POPUP'][] = array('CONTENT' => 'Failed to update settings', 'TYPE' => 'errormsg'); + } } + + // Fetch notifications + $aNotifications = $notification->getNofifications($_SESSION['USERDATA']['id']); + if (!$aNotifications) $_SESSION['POPUP'][] = array('CONTENT' => 'Could not find any notifications', 'TYPE' => 'errormsg'); + + // Fetch user notification settings + $aSettings = $notification->getNotificationSettings($_SESSION['USERDATA']['id']); + + $smarty->assign('NOTIFICATIONS', $aNotifications); + $smarty->assign('SETTINGS', $aSettings); + $smarty->assign('CONTENT', 'default.tpl'); } - - // Fetch notifications - $aNotifications = $notification->getNofifications($_SESSION['USERDATA']['id']); - if (!$aNotifications) $_SESSION['POPUP'][] = array('CONTENT' => 'Could not find any notifications', 'TYPE' => 'errormsg'); - - // Fetch user notification settings - $aSettings = $notification->getNotificationSettings($_SESSION['USERDATA']['id']); - - $smarty->assign('NOTIFICATIONS', $aNotifications); - $smarty->assign('SETTINGS', $aSettings); - $smarty->assign('CONTENT', 'default.tpl'); } ?> diff --git a/public/include/pages/admin/settings.inc.php b/public/include/pages/admin/settings.inc.php index 5999b00d..1b761244 100644 --- a/public/include/pages/admin/settings.inc.php +++ b/public/include/pages/admin/settings.inc.php @@ -22,6 +22,7 @@ $smarty->assign("LOCKREGISTRATION", $setting->getValue('lock_registration')); $smarty->assign("DISABLEINVITATIONS", $setting->getValue('disable_invitations')); $smarty->assign("DISABLEAP", $setting->getValue('disable_ap')); $smarty->assign("DISABLEMP", $setting->getValue('disable_mp')); +$smarty->assign("DISABLENOTIFICATIONS", $setting->getValue('disable_notifications')); // Tempalte specifics $smarty->assign("CONTENT", "default.tpl"); diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index 053f1697..221e5a8e 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -51,6 +51,7 @@ $aGlobal = array( 'website' => $config['website'], 'accounts' => $config['accounts'], 'disable_invitations' => $setting->getValue('disable_invitations'), + 'disable_notifications' => $setting->getValue('disable_notifications'), 'price' => array( 'currency' => $config['price']['currency'] ), 'targetdiff' => $config['difficulty'], 'currency' => $config['currency'], diff --git a/public/templates/mmcFE/admin/settings/default.tpl b/public/templates/mmcFE/admin/settings/default.tpl index 117dd8cd..81d109fa 100644 --- a/public/templates/mmcFE/admin/settings/default.tpl +++ b/public/templates/mmcFE/admin/settings/default.tpl @@ -60,6 +60,16 @@ + + Disable Notifications + + + + + diff --git a/public/templates/mmcFE/global/navigation.tpl b/public/templates/mmcFE/global/navigation.tpl index 14a002ef..a18b6a94 100644 --- a/public/templates/mmcFE/global/navigation.tpl +++ b/public/templates/mmcFE/global/navigation.tpl @@ -6,7 +6,7 @@
  • Edit Account
  • My Workers
  • Transactions
  • -
  • Notifications
  • + {if !$GLOBAL.config.disable_notifications}
  • Notifications
  • {/if} {if !$GLOBAL.config.disable_invitations}
  • Invitations
  • {/if}