浏览代码

added email stats (how many alerts we send)

master
memespring 17 年前
父节点
当前提交
35c82b186b
共有 3 个文件被更改,包括 44 次插入12 次删除
  1. +1
    -1
      data/%%AD^AD7^AD71B708%%rss.tpl.php
  2. +9
    -0
      schema/planningalerts.sql
  3. +34
    -11
      tools/application_mailer.php

+ 1
- 1
data/%%AD^AD7^AD71B708%%rss.tpl.php 查看文件

@@ -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 */ ?>
<?php echo '<?xml'; ?>
version="1.0" encoding="UTF-8"<?php echo '?>'; ?>


+ 9
- 0
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 */;


+ 34
- 11
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);
}


正在加载...
取消
保存