From 35c82b186bd376182ad09efe02979abaacef076c Mon Sep 17 00:00:00 2001 From: memespring Date: Sat, 21 Apr 2007 11:32:32 +0000 Subject: [PATCH] added email stats (how many alerts we send) --- data/%%AD^AD7^AD71B708%%rss.tpl.php | 2 +- schema/planningalerts.sql | 9 ++++++ tools/application_mailer.php | 45 ++++++++++++++++++++++------- 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/data/%%AD^AD7^AD71B708%%rss.tpl.php b/data/%%AD^AD7^AD71B708%%rss.tpl.php index 9b18bcf..534ca0f 100644 --- a/data/%%AD^AD7^AD71B708%%rss.tpl.php +++ b/data/%%AD^AD7^AD71B708%%rss.tpl.php @@ -1,4 +1,4 @@ - version="1.0" encoding="UTF-8"'; ?> diff --git a/schema/planningalerts.sql b/schema/planningalerts.sql index b2203f5..0b2e538 100644 --- a/schema/planningalerts.sql +++ b/schema/planningalerts.sql @@ -266,6 +266,15 @@ CREATE TABLE `planning`.`user` ( INSERT INTO `planning`.`user` VALUES (51,'richard@memespring.co.uk','sw98jx',0,'2007-01-07 10:16:08',530045,174349,532145,176449,'d8a8495e75bece822921',1,'l'), (52,'richard@memespring.co.uk','sw98jx',0,'2007-01-06 11:04:37',530045,174349,532145,176449,'c4a175ffa33297125bf9',0,'l'); +CREATE TABLE `planning`.`stats` ( + `key` varchar(25) NOT NULL, + `value` int(11) NOT NULL, + PRIMARY KEY (`key`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; +INSERT INTO `planning`.`stats` (`key`,`value`) VALUES + ('applications_sent',4), + ('emails_sent',4); + /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; diff --git a/tools/application_mailer.php b/tools/application_mailer.php index 8f82e27..e9802b4 100644 --- a/tools/application_mailer.php +++ b/tools/application_mailer.php @@ -13,6 +13,8 @@ //Properties var $log = array(); + var $application_count = 0; + var $email_count = 0; //Run function run (){ @@ -34,8 +36,6 @@ //Loop though users for ($i=0; $i < sizeof($user_results); $i++){ - - $this->store_log("Processing user " . $i); //Find applications for that user $sql = "select council_reference, address, @@ -51,13 +51,11 @@ //Send email if we have any if(sizeof($application_results) > 0){ - - $this->store_log("Found " . sizeof($application_results) . "applications for this user. w00t!"); //Setup applications array (bit pikey this) $applications = array(); for ($ii=0; $ii < sizeof($application_results); $ii++){ -print_r($application_results); + $application = new application(); $application->council_reference = $application_results[$ii][0]; $application->address = $application_results[$ii][1]; @@ -69,7 +67,9 @@ print_r($application_results); $application->authority_name = $application_results[$ii][7]; array_push($applications, $application); - } + } + + $this->application_count += sizeof($applications); //Smarty template $smarty = new Smarty; @@ -87,11 +87,11 @@ print_r($application_results); //Send the email if($email_text !=""){ send_text_email($user_results[$i][1], EMAIL_FROM_NAME, EMAIL_FROM_ADDRESS, "Planning applications near " . strtoupper($user_results[$i][2]), $email_text); - $this->store_log("sent applications to " . $user_results[$i][1]); + $this->email_count +=1; }else{ $this->store_log("BLANK EMAIL TEXT !!! EMAIL NOT SENT"); } - + //Update last sent $sql = "update user set last_sent = " . $db->quote(mysql_date(time())) . " where user_id = " . $user_results[$i][0]; $db->query($sql); @@ -101,11 +101,34 @@ print_r($application_results); } } - + + $this->store_log("Sent " . $this->application_count . " applications to " . $this->email_count . " people!"); + + //update the number of apps sent + $sql = "select `key`, `value` from stats"; + $stats_results = $db->getAll($sql); + $new_application_total = 0; + $new_email_total = 0; + for ($i=0; $i < sizeof($stats_results); $i++){ + if($stats_results[$i][0] == 'applications_sent'){ + $new_application_total = $stats_results[$i][1] + $this->application_count; + $new_email_total = $stats_results[$i][1] + $this->email_count; + } + } + + //add stats to email + $this->store_log("Total applications ever sent: " . $new_application_total); + $this->store_log("Total emails ever sent: " . $new_email_total); + + //update stats in DB + $sql = "update stats set `value` = " . $new_application_total . " where `key` = 'applications_sent'"; + $db->query($sql); + + $sql = "update stats set `value` = " . $new_email_total . " where `key` = 'emails_sent'"; + $db->query($sql); + //Send the log send_text_email(LOG_EMAIL, "mailer@" . DOMAIN, "mailer@" . DOMAIN, "Planning mailer log", print_r($this->log, true)); - - $this->store_log("Debug email sent to " . LOG_EMAIL); }