westdc-zf1/application/models/EmailText.php

68 lines
1.2 KiB
PHP

<?php
class EmailText{
var $tmpid;
var $db;
var $data;
var $tmpinfo;
function __construct()
{
if(empty($this->tmpid))
{
$this->tmpid = 0;
}
}
public function getinfo(){
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();
}
public function loadtmp(){
if(empty($this->tmpid))
{
return false;
}else{
$this->getinfo();
$c = $this->tmpinfo;
if(!empty($c['id']))
{
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);
$newString=preg_replace($patterns, $replacements, $c['body']);
return $newString;
}//count($this->data)
}
else
{
return false;
}
}//empty($this->tmpid)
}//function loadtmp
}