;";
$websiteResult = $this->bwdb->query($sql);
if (!$websiteResult) {
- trigger_error("Get website settings failed: " . mysqli_error($bwdb) );
+ trigger_error("Get website settings failed: " . mysqli_error($this->bwdb) );
}
$website = mysqli_fetch_assoc($websiteResult);
if (!$website){
;";
$websiteResult = $this->bwdb->query($sql);
if (!$websiteResult) {
- trigger_error("Website ID query failed: " . mysqli_error($bwdb) );
+ trigger_error("Website ID query failed: " . mysqli_error($this->bwdb) );
}
$row = mysqli_fetch_assoc($websiteResult);
if (!$row){
return ($this->connected && (strpos(GLM_SERVERSTATS_SITE_BASE_URL, '192.168.44.80') !== false || strpos(GLM_SERVERSTATS_SITE_BASE_URL, 'www.gaslightmedia.com') !== false));
}
+
+ /*
+ * Check if a site needs notifications sent based on set limits
+ *
+ * @param boolean $glmContact Send message to GLM contact
+ * @param boolean $custContact Send message to customer contact
+ * @param boolean $forceDisplay Force display of formatted message even if target not exceeded
+ * @param boolean $forceSend Force sending of message even if target not exceeded
+ *
+ * @return string If forse
+ */
+ public function checkForEmailNotifications($glmContact = true, $custContact = true, $forceDisplay = false, $forceSend = false)
+ {
+ $returnMsg = '';
+
+ $stats = $this->getStatsAndCheckTargetExceeded();
+
+ // If traffic had exceeded target
+ if ($stats['trafficDiff']['exceeded'] || $forceDisplay || $forceSend) {
+
+ $month = date('M Y', strtotime('now -1 month'));
+
+ // If GLM contact provided
+ if (trim($this->glm_contact) != '' && $glmContact) {
+
+ // If stats were exceeded then use this message
+ if ($stats['trafficDiff']['exceeded']) {
+
+ $mesg = '
+ <p>Gaslight Media:</p>
+ <p>A Website has exceeded the agreed target traffic for '.$month.'.</p>
+ <table>
+ <tr><th align="left">Website:</th><td>'.$this->website.'</td>
+ <tr><th align="left">Target:</th><td>'.sprintf('%.3f', $this->target).' Gigabytes</td></tr>
+ <tr><th align="left">Last Month:</th><td>'.sprintf('%.3f', $stats['lastMonth']['data_total']).' Gigabytes</td></tr>
+ <tr style="color: red;"><th align="left" style="padding-right: 1em;">Percent of Target:</th><td>'.sprintf('%.0f', $stats['trafficDiff']['percent']).'%</td></tr>
+ </table>
+ <p>Sincerely,</p>
+ <p>Gaslight Media</p>
+ ';
+
+ } else {
+
+ $mesg = '
+ <p>Gaslight Media:</p>
+ <p>Website traffic total for '.$month.'.</p>
+ <table>
+ <tr><th align="left">Website:</th><td>'.$this->website.'</td>
+ <tr><th align="left">Target:</th><td>'.sprintf('%.3f', $this->target).' Gigabytes</td></tr>
+ <tr><th align="left">Last Month:</th><td>'.sprintf('%.3f', $stats['lastMonth']['data_total']).' Gigabytes</td></tr>
+ <tr><th align="left" style="padding-right: 1em;">Percent of Target:</th><td>'.sprintf('%.0f', $stats['trafficDiff']['percent']).'%</td></tr>
+ </table>
+ <p>Sincerely,</p>
+ <p>Gaslight Media</p>
+ ';
+
+ }
+ $this->sendHtmlEmail($this->glm_contact, 'info@gaslightmedia.com', 'Gaslight Media Server Usage Report', $mesg, $forceDisplay);
+
+ }
+
+ // If customer contact provided
+ if (trim($this->cust_contact) != '' && $custContact) {
+
+ // If stats were exceeded then use this message
+ if ($stats['trafficDiff']['exceeded']) {
+
+ $mesg = '
+ <p>Dear Gaslight Media Website Owner:</p>
+ <p>Congradulations, your Website has exceeded the traffic target for '.$month.'.</p>
+ <table>
+ <tr><th align="left">Website:</th><td>'.$this->website.'</td>
+ <tr><th align="left">Target:</th><td>'.sprintf('%.3f', $this->target).' Gigabytes</td></tr>
+ <tr><th align="left">Last Month:</th><td>'.sprintf('%.3f', $stats['lastMonth']['data_total']).' Gigabytes</td></tr>
+ <tr style="color: red;"><th align="left" style="padding-right: 1em; color: red;">Percent of Target:</th><td>'.sprintf('%.0f', $stats['trafficDiff']['percent']).'%</td></tr>
+ </table>
+ <p>
+ This is good because it means your Website is getting more traffic!
+ </p>
+ <p>
+ Unlike other hosting providers, Gaslight Media doesn\'t automatically increase your monthly hosting fees simply because your Website exceeded the
+ agreed-upon service level for one month. Instead, we see this as an oportunity to look at your current and future needs first. If
+ you\'re likely to continue exceeding this traffic target, we can talk about a change in your hosting ageement to make sure you continue to
+ serve your Website users effectively.
+ </p>
+ <p>
+ Please contact us if you have any questions about this or other concerns. Otherwise, we\'ll contact you soon to talk about the
+ good performance of your Website and discuss plans for the future.
+ </p>
+ <p>Sincerely,</p>
+ <p>
+ Gaslight Media<br>
+ 120 E. Lake Street<br>
+ Petoskey, MI 49770<br>
+ 231-487-0692
+ </p>
+ ';
+
+ // Otherwise use this message when stats are not exceeded
+ } else {
+
+ $mesg = '
+ <p>Dear Gaslight Media Website Owner:</p>
+ <p>This is a review of your Website traffic for '.$month.'.</p>
+ <table>
+ <tr><th align="left">Website:</th><td>'.$this->website.'</td>
+ <tr><th align="left">Target:</th><td>'.sprintf('%.3f', $this->target).' Gigabytes</td></tr>
+ <tr><th align="left">Last Month:</th><td>'.sprintf('%.3f', $stats['lastMonth']['data_total']).' Gigabytes</td></tr>
+ <tr><th align="left" style="padding-right: 1em;">Percent of Target:</th><td>'.sprintf('%.0f', $stats['trafficDiff']['percent']).'%</td></tr>
+ </table>
+ <p>
+ Please contact us if you have any questions about this or other concerns.
+ </p>
+ <p>Sincerely,</p>
+ <p>
+ Gaslight Media<br>
+ 120 E. Lake Street<br>
+ Petoskey, MI 49770<br>
+ 231-487-0692
+ </p>
+ ';
+
+ }
+
+ $this->sendHtmlEmail($this->cust_contact, 'info@gaslightmedia.com', 'Gaslight Media Server Usage Report', $mesg, $forceDisplay);
+
+ }
+
+ } // If traffic stats exceeded
+
+ }
+
+ // Ajax processing ends here
+
+
+ /**
+ * sendHtmlEmail
+ *
+ * Create html email and send using wp_mail.
+ *
+ * @param string $to To email address
+ * @param string $from From E-Mail address
+ * @param string $subject Subject line for the email
+ * @param string $htmlMessage Html message for the email
+ * @param boolean $forceDisplay Force display of message rather than send
+ *
+ * @access public
+ * @return void
+ */
+ public function sendHtmlEmail( $to, $from, $subject, $msg, $forceDisplay = false )
+ {
+
+ // Display rather than send if requested or on a development system
+ if (GLM_SERVERSTATS_PLUGIN_HOST == 'DEVELOPMENT' || $forceDisplay) {
+ $msg = "
+ <H2>Server Usage E-Mail - Test Mode</h2>
+ From: $from<br>
+ To: $to<br>
+ Reply-To: $from<br>
+ Subject: $subject<br>
+
+ $msg
+ <hr>
+ <p> </p>
+ ";
+ echo $msg;
+ return;
+ }
+
+ // Send the message
+ $header = [
+ 'Content-type: text/html;charset=utf-8',
+ "From: $from",
+ "Reply-To: $from"
+ ];
+ wp_mail( $to, $subject, $msg, $header );
+
+ }
+
+
+
+
}
*/
public function model()
{
-
- trigger_error('GLM Usage: Cron triggered Usage Target Check', E_USER_NOTICE);
-
- $stats = $this->getStatsAndCheckTargetExceeded();
-
- // If traffic had exceeded target
- if ($stats['trafficDiff']['exceeded']) {
-
- $month = date('M Y', strtotime('now -1 month'));
-
- // If GLM contact provided
- if (trim($this->glm_contact) != '') {
-
- $mesg = '
- <p>Gaslight Media:</p>
- <p>A Website has exceeded the agreed target traffic for '.$month.'.</p>
- <table>
- <tr><th align="left">Website:</th><td>'.$this->website.'</td>
- <tr><th align="left">Target:</th><td>'.sprintf('%.3f', $this->target).' Gigabytes</td></tr>
- <tr><th align="left">Over Target:</th><td>'.sprintf('%.3f', $stats['trafficDiff']['traffic']).' Gigabytes</td></tr>
- <tr><th align="left" style="padding-right: 1em;">Percent Over:</th><td>'.sprintf('%.0f', $stats['trafficDiff']['percent']).'%</td></tr>
- </table>
- <p>Sincerely,</p>
- <p>Gaslight Media</p>
- ';
-
- $this->sendHtmlEmail($this->glm_contact, 'info@gaslightmedia.com', 'Gaslight Media Server Usage Report', $mesg);
- }
-
- // If customer contact provided
- if (trim($this->cust_contact) != '') {
-
- $mesg = '
- <p>Dear Gaslight Media Website Owner:</p>
- <p>Congradulations, your Website has exceeded the traffic target for '.$month.'.</p>
- <table>
- <tr><th align="left">Website:</th><td>'.$this->website.'</td>
- <tr><th align="left">Target:</th><td>'.sprintf('%.3f', $this->target).' Gigabytes</td></tr>
- <tr><th align="left">Over Target:</th><td>'.sprintf('%.3f', $stats['trafficDiff']['traffic']).' Gigabytes</td></tr>
- <tr><th align="left" style="padding-right: 1em;">Percent Over:</th><td>'.sprintf('%.0f', $stats['trafficDiff']['percent']).'%</td></tr>
- </table>
- <p>
- This is good because it means your Website is getting more traffic!
- </p>
- <p>
- Unlike other hosting providers, Gaslight Media doesn\'t automatically increase your monthly hosting fees simply because your Website exceeded the
- agreed-upon service level for one month. Instead, we see this as an oportunity to look at your current and future needs first. If
- you\'re likely to continue exceeding this traffic target, we can talk about a change in your hosting ageement to make sure you continue to
- serve your Website users effectively.
- </p>
- <p>
- Please contact us if you have any questions about this or other concerns. Otherwise, we\'ll contact you soon to talk about the
- good performance of your Website and discuss plans for the future.
- </p>
- <p>Sincerely,</p>
- <p>
- Gaslight Media<br>
- 120 E. Lake Street<br>
- Petoskey, MI 49770<br>
- 231-487-0692
- </p>
- ';
-
- $this->sendHtmlEmail($this->cust_contact, 'info@gaslightmedia.com', 'Gaslight Media Server Usage Report', $mesg);
- }
-
- }
+ $request = filter_input_array(
+ INPUT_GET,
+ array(
+ 'glmContact' => FILTER_VALIDATE_BOOLEAN,
+ 'custContact' => FILTER_VALIDATE_BOOLEAN,
+ 'forceDisplay' => FILTER_VALIDATE_BOOLEAN,
+ 'forceSend' => FILTER_VALIDATE_BOOLEAN
+ )
+ );
+
+ $this->checkForEmailNotifications($request['glmContact'], $request['custContact'], $request['forceDisplay'], $request['forceSend']);
// Ajax processing ends here
wp_die();
}
- /**
- * sendHtmlEmail
- *
- * Create html email and send using wp_mail.
- *
- * @param string $to To email address
- * @param string $from From E-Mail address
- * @param string $subject Subject line for the email
- * @param string $htmlMessage Html message for the email
- *
- * @access public
- * @return void
- */
- public function sendHtmlEmail( $to, $from, $subject, $msg )
- {
-
- if (GLM_SERVERSTATS_PLUGIN_HOST == 'DEVELOPMENT') {
- echo "
- <H2>Server Usage E-Mail - Development Mode</h2>
- From: $from<br>
- To: $to<br>
- Reply-To: $from<br>
- Subject: $subject<br>
-
- $msg
- <hr>
- <p> </p>
- ";
- return;
- }
-
- $header = [
- 'Content-type: text/html;charset=utf-8',
- "From: $from",
- "Reply-To: $from"
- ];
-
- wp_mail( $to, $subject, $msg, $header );
-
- }
-
}