2011-10-12 13:03:17 +00:00
|
|
|
<?php
|
|
|
|
class EmailText{
|
2011-10-13 10:12:00 +00:00
|
|
|
private $tmpid;
|
|
|
|
private $db;
|
|
|
|
private $data;
|
|
|
|
protected $tmpinfo;
|
2011-10-12 13:03:17 +00:00
|
|
|
|
2011-10-13 10:12:00 +00:00
|
|
|
function __construct($db,$id,$replace)
|
|
|
|
{
|
|
|
|
$this->db=$db;
|
|
|
|
$this->tmpid=$id;
|
|
|
|
$this->data=$replace;
|
|
|
|
$this->load();
|
2011-10-12 13:03:17 +00:00
|
|
|
}
|
|
|
|
|
2011-10-13 10:12:00 +00:00
|
|
|
protected function getinfo(){
|
2011-10-13 09:09:42 +00:00
|
|
|
|
|
|
|
if(is_numeric($this->tmpid))
|
|
|
|
$sql = "select * from emailtext where id='".$this->tmpid."'";
|
|
|
|
else
|
|
|
|
$sql = "select * from emailtext where template='".$this->tmpid."'";
|
|
|
|
|
|
|
|
$rs = $this->db->query($sql);
|
|
|
|
|
|
|
|
$this->tmpinfo = $rs->fetch();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-10-13 10:12:00 +00:00
|
|
|
public function load($body){
|
2011-10-12 13:03:17 +00:00
|
|
|
|
|
|
|
if(empty($this->tmpid))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}else{
|
2011-10-13 10:12:00 +00:00
|
|
|
if (empty($body))
|
|
|
|
{
|
|
|
|
$this->getinfo();
|
|
|
|
$body=$this->tmpinfo['body'];
|
|
|
|
}
|
2011-10-12 13:03:17 +00:00
|
|
|
|
2011-10-13 10:12:00 +00:00
|
|
|
if(!empty($body))
|
2011-10-12 13:03:17 +00:00
|
|
|
{
|
|
|
|
if(count($this->data)==0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$patterns = array();
|
|
|
|
$replacements = array();
|
|
|
|
foreach($this->data as $k=>$v)
|
|
|
|
{
|
|
|
|
$patterns[]='/{'.$k.'}/i';
|
|
|
|
$replacements[]=$v;
|
|
|
|
}
|
|
|
|
ksort($patterns);
|
|
|
|
ksort($replacements);
|
2011-10-13 10:12:00 +00:00
|
|
|
$this->tmpinfo['body']=preg_replace($patterns, $replacements, $body);
|
|
|
|
return true;
|
2011-10-12 13:03:17 +00:00
|
|
|
}//count($this->data)
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}//empty($this->tmpid)
|
2011-10-13 10:12:00 +00:00
|
|
|
}//function loadtmp
|
|
|
|
public function getBody() {
|
|
|
|
return $this->tmpinfo['body'];
|
|
|
|
}
|
|
|
|
public function getSubject() {
|
|
|
|
return $this->tmpinfo['subject'];
|
|
|
|
}
|
2011-10-12 13:03:17 +00:00
|
|
|
}
|