Browse Source

added email stats (how many alerts we send)

import/raw
memespring 17 years ago
parent
commit
570cbdac25
3 changed files with 44 additions and 12 deletions
  1. +1
    -1
      trunk/data/%%AD^AD7^AD71B708%%rss.tpl.php
  2. +9
    -0
      trunk/schema/planningalerts.sql
  3. +34
    -11
      trunk/tools/application_mailer.php

+ 1
- 1
trunk/data/%%AD^AD7^AD71B708%%rss.tpl.php View File

@@ -1,4 +1,4 @@
<?php /* Smarty version 2.6.16, created on 2007-04-09 19:59:18
<?php /* Smarty version 2.6.16, created on 2007-04-21 12:06:10
compiled from rss.tpl */ ?> compiled from rss.tpl */ ?>
<?php echo '<?xml'; ?> <?php echo '<?xml'; ?>
version="1.0" encoding="UTF-8"<?php echo '?>'; ?> version="1.0" encoding="UTF-8"<?php echo '?>'; ?>


+ 9
- 0
trunk/schema/planningalerts.sql View File

@@ -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'), 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'); (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 */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;


+ 34
- 11
trunk/tools/application_mailer.php View File

@@ -13,6 +13,8 @@
//Properties //Properties
var $log = array(); var $log = array();
var $application_count = 0;
var $email_count = 0;


//Run //Run
function run (){ function run (){
@@ -34,8 +36,6 @@
//Loop though users //Loop though users
for ($i=0; $i < sizeof($user_results); $i++){ for ($i=0; $i < sizeof($user_results); $i++){

$this->store_log("Processing user " . $i);
//Find applications for that user //Find applications for that user
$sql = "select council_reference, address, $sql = "select council_reference, address,
@@ -51,13 +51,11 @@


//Send email if we have any //Send email if we have any
if(sizeof($application_results) > 0){ if(sizeof($application_results) > 0){

$this->store_log("Found " . sizeof($application_results) . "applications for this user. w00t!");
//Setup applications array (bit pikey this) //Setup applications array (bit pikey this)
$applications = array(); $applications = array();
for ($ii=0; $ii < sizeof($application_results); $ii++){ for ($ii=0; $ii < sizeof($application_results); $ii++){
print_r($application_results);
$application = new application(); $application = new application();
$application->council_reference = $application_results[$ii][0]; $application->council_reference = $application_results[$ii][0];
$application->address = $application_results[$ii][1]; $application->address = $application_results[$ii][1];
@@ -69,7 +67,9 @@ print_r($application_results);
$application->authority_name = $application_results[$ii][7]; $application->authority_name = $application_results[$ii][7];
array_push($applications, $application); array_push($applications, $application);
}
}

$this->application_count += sizeof($applications);
//Smarty template //Smarty template
$smarty = new Smarty; $smarty = new Smarty;
@@ -87,11 +87,11 @@ print_r($application_results);
//Send the email //Send the email
if($email_text !=""){ 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); 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{ }else{
$this->store_log("BLANK EMAIL TEXT !!! EMAIL NOT SENT"); $this->store_log("BLANK EMAIL TEXT !!! EMAIL NOT SENT");
} }
//Update last sent //Update last sent
$sql = "update user set last_sent = " . $db->quote(mysql_date(time())) . " where user_id = " . $user_results[$i][0]; $sql = "update user set last_sent = " . $db->quote(mysql_date(time())) . " where user_id = " . $user_results[$i][0];
$db->query($sql); $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 the log
send_text_email(LOG_EMAIL, "mailer@" . DOMAIN, "mailer@" . DOMAIN, "Planning mailer log", print_r($this->log, true)); 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);
} }


Loading…
Cancel
Save