westdc-zf1/application/admin/controllers/SysController.php

125 lines
3.4 KiB
PHP
Raw Normal View History

<?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();
$this->_helper->layout->setLayout('administry');//新UI
}
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');
if($ac=='add' && !empty($submit))
{
$title = $this->_request->getParam('title');
$description = $this->_request->getParam('description');
$body = $this->_request->getParam('body');
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity())
{
$user = $auth->getIdentity();
$userid = $user->id;
}
if(empty($title)) $title=='未命名模板';
$sql = "insert into emailtext (title,description,content,userid,ts_create) values ('$title','$description','$body','$userid','".time()."')";
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');
$description = $this->_request->getParam('description');
$body = $this->_request->getParam('body');
$sql = "update emailtext set title='$title',description='$description',content='$body' where id='$id'";
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=='test'&& !empty($id))
{
if(!empty($submit))
{
$this->_helper->viewRenderer('emailtext_test');
}
}//模板测试
else
{
$sql = "select * from emailtext where id='$id'";
$rs = $this->db->query($sql);
$rows = $rs->fetch();
$this->view->info = $rows;
$this->_helper->viewRenderer('emailtext_edit');
}//模板列表
}
else
{
$sql = "select id,title,userid,ts_create,description,usetimes from emailtext";
$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 邮件模板管理
}