2011-10-11 10:06:51 +00:00
|
|
|
<?php
|
|
|
|
class Admin_SysController extends Zend_Controller_Action
|
|
|
|
{
|
|
|
|
function preDispatch()
|
|
|
|
{
|
|
|
|
$this->db=Zend_Registry::get('db');
|
|
|
|
$this->view->config = Zend_Registry::get('config');
|
|
|
|
$this->messenger=$this->_helper->getHelper('FlashMessenger');
|
|
|
|
$this->view->messages = $this->messenger->getMessages();
|
2011-10-12 08:33:46 +00:00
|
|
|
//$this->_helper->layout->setLayout('administry');//新UI
|
2011-10-11 10:06:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function postDispatch()
|
|
|
|
{
|
|
|
|
$this->view->messages = $this->messenger->getMessages();
|
|
|
|
}
|
|
|
|
|
|
|
|
function indexAction()
|
|
|
|
{
|
|
|
|
//$this->_helper->viewRenderer('');
|
|
|
|
//$this->messenger->addMessage('');
|
|
|
|
//$this->_redirect('');
|
|
|
|
}//indexAction 首页
|
|
|
|
|
|
|
|
function emailtextAction(){
|
|
|
|
|
|
|
|
$ac = $this->_request->getParam('ac');
|
|
|
|
$submit = $this->_request->getParam('submit');
|
|
|
|
$id = $this->_request->getParam('id');
|
|
|
|
|
2011-10-12 08:33:46 +00:00
|
|
|
if($ac=='add' && empty($submit))
|
|
|
|
{
|
|
|
|
$this->_helper->viewRenderer('emailtextadd');
|
|
|
|
}
|
2011-10-11 10:06:51 +00:00
|
|
|
|
|
|
|
if($ac=='add' && !empty($submit))
|
|
|
|
{
|
|
|
|
$title = $this->_request->getParam('title');
|
2011-10-12 13:45:45 +00:00
|
|
|
$template = $this->_request->getParam('template');
|
2011-10-11 10:06:51 +00:00
|
|
|
$body = $this->_request->getParam('body');
|
|
|
|
|
|
|
|
if(empty($title)) $title=='未命名模板';
|
|
|
|
|
2011-10-12 13:45:45 +00:00
|
|
|
$sql = "insert into emailtext (subject,template,body) values ('$title','$template','$body')";
|
2011-10-11 10:06:51 +00:00
|
|
|
|
|
|
|
try{
|
|
|
|
if($this->db->exec($sql)>0)
|
|
|
|
{
|
|
|
|
$this->messenger->addMessage('模板添加成功');
|
|
|
|
$this->_redirect('/admin/sys/emailtext');
|
|
|
|
}
|
|
|
|
}catch(Exception $e){
|
|
|
|
$this->messenger->addMessage('模板添加失败:'.$e->getMessage());
|
|
|
|
$this->_redirect('/admin/sys/emailtext');
|
|
|
|
}
|
|
|
|
}//创建新模板
|
|
|
|
|
|
|
|
else if($ac=='edit'&& !empty($id))
|
|
|
|
{
|
|
|
|
if(!empty($submit))
|
|
|
|
{
|
|
|
|
$title = $this->_request->getParam('title');
|
2011-10-12 13:45:45 +00:00
|
|
|
$template = $this->_request->getParam('template');
|
2011-10-11 10:06:51 +00:00
|
|
|
$body = $this->_request->getParam('body');
|
|
|
|
|
2011-10-12 13:45:45 +00:00
|
|
|
$sql = "update emailtext set subject='$title',template='$template',body='$body',ts_changed=now() where id='$id'";
|
2011-10-11 10:06:51 +00:00
|
|
|
|
|
|
|
try{
|
|
|
|
if($this->db->exec($sql)>0)
|
|
|
|
{
|
|
|
|
$this->messenger->addMessage('模板编辑成功');
|
|
|
|
$this->_redirect('/admin/sys/emailtext');
|
|
|
|
}
|
|
|
|
}catch(Exception $e){
|
|
|
|
$this->messenger->addMessage('模板编辑失败:'.$e->getMessage());
|
|
|
|
$this->_redirect('/admin/sys/emailtext');
|
|
|
|
}
|
2011-10-12 08:33:46 +00:00
|
|
|
}else{
|
2011-10-11 10:06:51 +00:00
|
|
|
$sql = "select * from emailtext where id='$id'";
|
|
|
|
$rs = $this->db->query($sql);
|
|
|
|
$rows = $rs->fetch();
|
|
|
|
$this->view->info = $rows;
|
2011-10-12 08:33:46 +00:00
|
|
|
$this->_helper->viewRenderer('emailtextedit');
|
|
|
|
}
|
|
|
|
|
|
|
|
}//模板编辑
|
|
|
|
|
|
|
|
else if($ac=='test'&& !empty($id))
|
|
|
|
{
|
|
|
|
if(!empty($submit))
|
|
|
|
{
|
|
|
|
try{
|
2011-10-12 13:45:45 +00:00
|
|
|
$subject = $this->_request->getParam('subject');
|
|
|
|
$email = $this->_request->getParam('email');
|
|
|
|
$body = $this->_request->getParam('body');
|
|
|
|
$body=str_replace("[username]",$this->_request->getParam('user'),$body);
|
|
|
|
if(empty($subject) || empty($email))
|
2011-10-12 08:33:46 +00:00
|
|
|
{
|
|
|
|
$this->messenger->addMessage('请填写测试邮件发送信息');
|
|
|
|
$this->_redirect('/admin/sys/emailtext/ac/test/id/'.$id);
|
|
|
|
}
|
|
|
|
$mail=new WestdcMailer($this->view->config->smtp);
|
|
|
|
|
|
|
|
$mail->setBodyText($body);
|
|
|
|
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
|
|
|
|
$mail->addTo($email);
|
|
|
|
$mail->setSubject($subject);
|
|
|
|
|
|
|
|
if($mail->send()){
|
|
|
|
$this->messenger->addMessage('测试邮件发送成功');
|
|
|
|
$this->_redirect('/admin/sys/emailtext/ac/test/id/'.$id);
|
|
|
|
}else{
|
|
|
|
$this->messenger->addMessage('测试邮件发送失败');
|
|
|
|
$this->_redirect('/admin/sys/emailtext/ac/test/id/'.$id);
|
|
|
|
}
|
|
|
|
}catch(Exception $e){
|
|
|
|
$this->messenger->addMessage('测试邮件发送失败'.$e->getMessage());
|
|
|
|
$this->_redirect('/admin/sys/emailtext/ac/test/id/'.$id);
|
2011-10-12 13:45:45 +00:00
|
|
|
}
|
2011-10-12 08:33:46 +00:00
|
|
|
}
|
|
|
|
else
|
2011-10-12 13:45:45 +00:00
|
|
|
{
|
|
|
|
$sql = "select * from emailtext where id='$id'";
|
|
|
|
$rs = $this->db->query($sql);
|
|
|
|
$rows = $rs->fetch();
|
|
|
|
$this->view->info = $rows;
|
2011-10-12 08:33:46 +00:00
|
|
|
$this->_helper->viewRenderer('emailtexttest');
|
|
|
|
}
|
|
|
|
|
|
|
|
}//模板测试
|
2011-10-11 10:06:51 +00:00
|
|
|
|
|
|
|
else
|
|
|
|
{
|
2011-10-12 13:45:45 +00:00
|
|
|
$sql = "select id,subject,template,ts_created,ts_changed from emailtext";
|
2011-10-11 10:06:51 +00:00
|
|
|
$rs = $this->db->query($sql);
|
|
|
|
$rows = $rs->fetchAll();
|
|
|
|
|
|
|
|
$paginator = Zend_Paginator::factory($rows);
|
|
|
|
$paginator->setCurrentPageNumber($this->_getParam('page'));
|
|
|
|
$paginator->setItemCountPerPage($this->view->config->page->max);
|
|
|
|
$paginator->setView($this->view);
|
|
|
|
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
|
|
|
|
$this->view->paginator=$paginator;
|
|
|
|
}//邮件模板管理首页
|
|
|
|
|
|
|
|
}//emailtextAction 邮件模板管理
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|