Added Send Notice Enable feature to global settings.
Reviewed Notice generation cron code.
Added Notice generation debug information.
Other minor changes
* @access public
*/
public $threshold = -1;
+ /**
+ * Reporting Send Enabled
+ *
+ * @var $send_enabled
+ * @access public
+ */
+ public $send_enabled = false;
/**
* Default Website ID
*
$this->connected = false;
$this->threshold = get_option(GLM_SERVERSTATS_PLUGIN_THRESHOLD_OPTION);
+ $this->send_enabled = get_option(GLM_SERVERSTATS_PLUGIN_SEND_OPTION);
+
// Initialize MySQLi
$this->bwdb = mysqli_init();
* @param boolean $forceDisplay Flag to display rather than send
* If this is a development system all messages will only be displayed, not sent.
*
+ * @return integer Number of sites notified
+ *
*/
public function checkEmailNotifications($sendToGlmContact = false, $sendToCustContact = false, $sendAll = false, $site = false, $forceDisplay = false)
{
// For each website retrieved
foreach ($websites as $site) {
-
$mesg = '';
// If theshold is not -1 and at least one of usage or disk % of target equals or exceeds reporting threshold
if ($this->threshold != -1 && ($sendAll || $site['target_percent'] >= $this->threshold || $site['disk_target_percent'] >= $this->threshold)) {
-echo "Threshold = ".$this->threshold."<P>";
$numbReporting++;
$this->sendHtmlEmail($this->glm_billing_contact, 'info@gaslightmedia.com', 'Gaslight Media Server Usage Report', $glmMesg, $forceDisplay);
}
- return;
+ $res = [
+ 'numbSites' => $numbSites,
+ 'numbReporting' => $numbReporting,
+ 'numbReportingWithContactEmail' => $numbReportingWithContactEmail
+ ];
+
+ trigger_error("Usage E-Mail Notifications Summary - Sites: $numbSites, Sites Reporting: $numbReporting, Reporting with Contact E-Mail: $numbReportingWithContactEmail", E_USER_NOTICE );
+
+ return $res;
}
// Other
define('GLM_SERVERSTATS_PLUGIN_THRESHOLD_OPTION', 'glmServerStatsThreshold');
+define('GLM_SERVERSTATS_PLUGIN_SEND_OPTION', 'glmServerStatsSend');
define('GLM_SERVERSTATS_PLUGIN_CONFIG_OPTION', 'glmServerStatsConfigData');
\ No newline at end of file
register_deactivation_hook(__FILE__, 'glmServerStatsPluginDeactivate');
/*
- * Check is we should run the target check E-mail process
+ * Check if we should run the target check E-mail process
*
- * This only runs on the Bandwidth Management Site!
+ * This only runs on the Bandwidth Management Site! (see defines.php)
*
* A WordPress scheduled event is created to run once per hour and call
- * doGlmServerstatsCron(). That checkeds to see if the target checks
+ * doGlmServerstatsCron(). That checks to see if the target checks
* have been run in the current month and if not to run them now.
*
* The target check will look for sites that are near or above their
*/
// Called by WordPress scheduler as set below
-//add_action('glm_serverstats_notify_cron', 'doGlmServerstatsCron');
-function doGlmServerstatsCron() {
+function doGlmServerUsageCron() {
trigger_error('GLM Serverstats Cron Called', E_USER_NOTICE);
+ $enabled = get_option(GLM_SERVERSTATS_PLUGIN_SEND_OPTION);
+ if (!$enabled) {
+ trigger_error('GLM Serverstats E-Mail Notifications not enabled!', E_USER_NOTICE);
+ return;
+ }
+
// Test if already run this month.
$targetCheckMonth = date('m/Y');
$targetCheckLast = get_option(GLM_SERVERSTATS_PLUGIN_CONFIG_OPTION.'_LAST_CHECK');
- // *** FOR TESTING ONLY - Incriment number to enable another test ***
- $targetCheckMonth .= '/43';
+ /* *** FOR TESTING ONLY ***
+ * Adds a suffix to the date to enable another E-Mail check.
+ * This value can be incremented to re-try the E-Mail usage check for additional tests.
+ * If this is left here and not updated, this section will resume running the E-Mail
+ * usage check once per month anyway.
+ */
+ $targetCheckMonth .= '/53';
-trigger_error("BLOCKING TARGET CHECK FOR NOW FOR TEST", E_USER_NOTICE);
- if ( false && $targetCheckMonth != $targetCheckLast) {
+ trigger_error("GLM Serverstats Cron Check: If $targetCheckMonth equals $targetCheckLast this has already been run.", E_USER_NOTICE);
- trigger_error('Running Target Check Process for Month = '.$targetCheckMonth, E_USER_NOTICE);
+ if ( $targetCheckMonth != $targetCheckLast) {
+
+ trigger_error('Running Usage E-Mail Notification Process for Month = '.$targetCheckMonth, E_USER_NOTICE);
update_option(GLM_SERVERSTATS_PLUGIN_CONFIG_OPTION.'_LAST_CHECK', $targetCheckMonth);
}
}
+add_action('glm_serverstats_notify_cron', 'doGlmServerUsageCron');
-// ***** Setup a one minute schedule for TESTING ONLY
+/*
+ * This code sets up a once per minute cron schedule to use for testing.
+ * Normally this would use the "hourly" schedule. This may be commented out if not in use.
+ * To use this schedule for testing, see the commented out code in the next block of code.
+ */
function cron_add_minute( $schedules ) {
// Adds once weekly to the existing schedules.
$schedules['minute'] = array(
return $schedules;
}
-// If this running on the Bandwidth Management site, setup scheduler to call abovie once per hour.
+
+/*
+ * If this running on the Bandwidth Management site (see defines.php), sets scheduler to call
+ * doGlmServerstatsCron
+ * once per .
+ *
+ */
if (apply_filters('glm-serverstats-is-provider', false) || true) {
- // ****** Add a 1 minute schedule option for testing only
+ // Add a 1 minute schedule option for testing only - For testing only
add_filter( 'cron_schedules', 'cron_add_minute' );
// If there's no current cron for doing this, set it now
if (!$cronTimestamp) {
wp_schedule_event( time(), 'hourly', 'glm_serverstats_notify_cron' );
-// for testing wp_schedule_event( time(), 'minute', 'glm_serverstats_notify_cron' );
+ // wp_schedule_event( time(), 'minute', 'glm_serverstats_notify_cron' ); // For testing only
}
$option = $_REQUEST['option'];
}
- // If a threshold value is submitted
+ // If a threshold value is submitted, the form has been submitted
if (isset($_REQUEST['threshold'])) {
+
$this->threshold = $_REQUEST['threshold'] - 0;
update_option(GLM_SERVERSTATS_PLUGIN_THRESHOLD_OPTION, $this->threshold);
+
+ // If a send_enabled is submitted
+ $this->send_enabled = false;
+ if (isset($_REQUEST['send_enabled']) && $_REQUEST['send_enabled'] == 'on') {
+ $this->send_enabled = true;
+ }
+ update_option(GLM_SERVERSTATS_PLUGIN_SEND_OPTION, $this->send_enabled);
+
}
// Check for a selected site or use website in config
'target' => $this->target,
'diskTarget' => $this->disk_target,
'threshold' => $this->threshold,
+ 'send_enabled' => $this->send_enabled,
'websites' => $websites,
'isProvider' => apply_filters('glm-serverstats-is-provider', false),
'site_sort' => $site_sort,
'settings' => $settings
);
+ //echo "<pre>".print_r($templateData,1)."</pre>";
+
// Return status, suggested view, and data to controller
return array(
'view' => 'adminServerStats',
public function model()
{
- // Check input
+ // Check input
$site = filter_input( INPUT_GET, 'selected_site', FILTER_SANITIZE_STRING);
$display = filter_input( INPUT_GET, 'display_only', FILTER_SANITIZE_STRING);
$displayOnly = true;
}
+ // If Display is not requested, must be a real send so check if sending is enabled.
+ $send_enabled = get_option(GLM_SERVERSTATS_PLUGIN_SEND_OPTION);
+ if (!$displayOnly && !$send_enabled) {
+ echo "<h3>Sending of notification E-Mail is dissabled!</h3>";
+ wp_die();
+ };
+
// If we have a Website selected - Do that notice
if (!empty($site)) {
echo "<hr>";
- $this->checkEmailNotifications(true, true, true, $site, $displayOnly);
+ $res = $this->checkEmailNotifications(true, true, true, $site, $displayOnly);
} else {
wp_die();
}
- $this->checkEmailNotifications(true, true, false, false, $displayOnly);
+ $res = $this->checkEmailNotifications(true, true, false, false, $displayOnly);
}
+ echo "
+ <p>
+ ".$res['numbSites']." Total sites<br>
+ ".$res['numbReporting']." Number of Notifications Generated<br>
+ ".$res['numbReportingWithContactEmail']." Number of Notfications for which there is a contact E-Mail address
+ </p>
+ ";
+
// Ajax processing ends here
wp_die();
<div class="cell small-12"><br><h4>Global Settings</h4></div>
<div class="cell small-12 large-3 glm-f6-ui-nowrap"><b>Monthly Reporting Threshold:</b></div>
<div class="cell small-12 large-9">At or above {$threshold|string_format:"%.0f"}% of site's target levels</div>
+ <div class="cell small-12 large-3 glm-f6-ui-nowrap"><b>Send Notices Enabled:</b></div>
+ <div class="cell small-12 large-9">{if !empty($send_enabled)}YES{else}NO{/if}</div>
</div>
</div>
'helpText' => '
Percentage above which target percentage should be highlighted in red and site contacts will receive E-Mail reports.
Set Reporting Threshold to -1% to block all automatic monthly reporting.
- '
+ ',
+ 'errorText' => 'Please enter or select a number between -1 and 1000.'
]}
{include file="ui/f6/number.html"}
+ {* Send Enabled *}
+ {$ui = [
+ 'field' => 'send_enabled',
+ 'value' => {$send_enabled},
+ 'label' => 'Send Notices',
+ 'helpText' => '
+ Turn this on to have monthly notices set to site contacts for sites
+ above the reporting threashold.
+ '
+ ]}
+ {include file="ui/f6/checkbox.html"}
+
{include file="ui/f6/section-end.html"}
{* Submit Button *}
{if !empty($ui.validate)}
<div id="validateMessage{if !empty($ui.validateID)}_{$ui.validateID}{/if}" data-abide-error class="alert callout" style="display: none;">
- <p><i class="fi-alert"></i> {$ui.validateMessage|default:'There are some errors in your formmmmmm.'}</p>
+ <p><i class="fi-alert"></i> {$ui.validateMessage|default:'There are some errors in your form.'}</p>
</div>
<script>