338 lines
11 KiB
PHP
338 lines
11 KiB
PHP
<?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))
|
|
{
|
|
$this->_helper->viewRenderer('emailtextadd');
|
|
}
|
|
|
|
if($ac=='add' && !empty($submit))
|
|
{
|
|
$title = $this->_request->getParam('title');
|
|
$template = $this->_request->getParam('template');
|
|
$body = $this->_request->getParam('body');
|
|
|
|
if(empty($title)) $title=='未命名模板';
|
|
|
|
$sql = "insert into emailtext (subject,template,body) values ('$title','$template','$body')";
|
|
|
|
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');
|
|
$template = $this->_request->getParam('template');
|
|
$body = $this->_request->getParam('body');
|
|
|
|
$sql = "update emailtext set subject='$title',template='$template',body='$body',ts_changed=now() 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{
|
|
$sql = "select * from emailtext where id='$id'";
|
|
$rs = $this->db->query($sql);
|
|
$rows = $rs->fetch();
|
|
$this->view->info = $rows;
|
|
$this->_helper->viewRenderer('emailtextedit');
|
|
}
|
|
|
|
}//模板编辑
|
|
|
|
else if($ac=='test'&& !empty($id))
|
|
{
|
|
if(!empty($submit))
|
|
{
|
|
try{
|
|
$subject = $this->_request->getParam('subject');
|
|
$email = $this->_request->getParam('email');
|
|
$body = $this->_request->getParam('body');
|
|
|
|
if(empty($subject) || empty($email))
|
|
{
|
|
$this->messenger->addMessage('请填写测试邮件发送信息');
|
|
$this->_redirect('/admin/sys/emailtext/ac/test/id/'.$id);
|
|
}
|
|
|
|
$mailtp=new EmailText($this->db,$this->_request->getParam('id'),array('user' => $this->_request->getParam('user')));
|
|
$body = $mailtp->getBody();
|
|
if($body === false)
|
|
{
|
|
$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);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$sql = "select * from emailtext where id='$id'";
|
|
$rs = $this->db->query($sql);
|
|
$rows = $rs->fetch();
|
|
$this->view->info = $rows;
|
|
$this->_helper->viewRenderer('emailtexttest');
|
|
}
|
|
|
|
}//模板测试
|
|
|
|
else if($ac=='help')
|
|
{
|
|
$this->_helper->viewRenderer('emailtexthelp');
|
|
}
|
|
|
|
else
|
|
{
|
|
try{
|
|
$sql = "select id,subject,template,ts_created,ts_changed 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;
|
|
}catch (Exception $e){
|
|
echo $e->getMessage();
|
|
}
|
|
}//邮件模板管理首页
|
|
|
|
}//emailtextAction 邮件模板管理
|
|
|
|
function seekspaceAction()
|
|
{
|
|
set_time_limit(0);
|
|
$submit = $this->_request->getParam('submit');
|
|
if (!empty($submit))
|
|
{
|
|
$sql="select item_id from knl_article order by id desc";
|
|
$row=$this->db->fetchRow($sql);
|
|
try {
|
|
$this->db->beginTransaction();
|
|
$sql="insert into knl_article (item_id) select item_id from knl_dcvalue where dc_type_id=66 and text_value='Article' and item_id>".$row['item_id'];
|
|
$this->db->query($sql);
|
|
$sql="update knl_article k set title=t.text_value from (select text_value,item_id from knl_dcvalue where dc_type_id=64) as t where k.item_id=t.item_id and k.item_id>".$row['item_id'];
|
|
$this->db->query($sql);
|
|
$sql="update knl_article k set url=t.text_value from (select text_value,item_id from knl_dcvalue where dc_type_id=25) as t where k.item_id=t.item_id and k.item_id>".$row['item_id'];
|
|
$this->db->query($sql);
|
|
$sql="update knl_article k set publisher=t.text_value from (select text_value,item_id from knl_dcvalue where dc_type_id=39) as t where k.item_id=t.item_id and k.item_id>".$row['item_id'];
|
|
$this->db->query($sql);
|
|
$sql="update knl_article k set ts_issued=t.text_value from (select text_value,item_id from knl_dcvalue where dc_type_id=15) as t where k.item_id=t.item_id and k.item_id>".$row['item_id'];
|
|
$this->db->query($sql);
|
|
$sql="update knl_article k set ts_created=cast(t.text_value as timestamp without time zone) from (select text_value,item_id from knl_dcvalue where dc_type_id=12) as t where k.item_id=t.item_id and k.item_id>".$row['item_id'];
|
|
$this->db->query($sql);
|
|
$sql="update knl_article k set keywords[t.place]=t.text_value from (select text_value,item_id,place from knl_dcvalue where dc_type_id=57) as t where k.item_id=t.item_id and k.item_id>".$row['item_id'];
|
|
$this->db->query($sql);
|
|
$sql="insert into knl_keyword (keyword,item_id,place) select text_value,item_id,place from knl_dcvalue where dc_type_id=57 and item_id>".$row['item_id'];
|
|
$this->db->query($sql);
|
|
$sql="insert into knl_author (author,item_id,place) select text_value,item_id,place from knl_dcvalue where dc_type_id=3 and item_id>".$row['item_id'];
|
|
$this->db->query($sql);
|
|
$this->db->query("delete from knl_keyword where item_id not in (select item_id from knl_article)");
|
|
$this->db->query("delete from knl_author where item_id not in (select item_id from knl_article)");
|
|
$this->db->commit();
|
|
} catch(Exception $e) {
|
|
$this->db->rollBack();
|
|
$this->view->msg=$e->getMessage();
|
|
}
|
|
$this->view->msg='与文献平台同步成功!';
|
|
}
|
|
$sql="select (select count(*) from knl_article) as westdccount,(select count(*) from knl_dcvalue where dc_type_id=66 and text_value='Article') as seekcount";
|
|
$this->view->count=$this->db->fetchRow($sql);
|
|
}
|
|
|
|
function getmsgAction(){
|
|
$this->_helper->layout()->disableLayout();
|
|
$this->_helper->viewRenderer->setNoRender();
|
|
$msg = array();
|
|
$auth = Zend_Auth::getInstance();
|
|
if($auth->hasIdentity())
|
|
{
|
|
$user = $auth->getIdentity();
|
|
$userid = $user->id;
|
|
if($user->usertype == "administrator")
|
|
{
|
|
include_once("message.php");
|
|
$rs = message::getNew($this->db,$userid,"admin");
|
|
echo Zend_Json::encode($rs);
|
|
exit();
|
|
}else{
|
|
$msg['error'] = "您没有权限";
|
|
echo Zend_Json::encode($msg);
|
|
exit();
|
|
}
|
|
}else{
|
|
$msg['error'] = "您没有权限";
|
|
echo Zend_Json::encode($msg);
|
|
exit();
|
|
}
|
|
}
|
|
|
|
function messageAction(){
|
|
$do = $this->_request->getParam('do');
|
|
$id = $this->_request->getParam('id');
|
|
|
|
if($do=='read' && !empty($id))
|
|
{
|
|
$this->_helper->viewRenderer('messageview');
|
|
$auth = Zend_Auth::getInstance();
|
|
if($auth->hasIdentity())
|
|
{
|
|
$user = $auth->getIdentity();
|
|
$userid = $user->id;
|
|
if($user->usertype == "administrator")
|
|
{
|
|
include_once("message.php");
|
|
$rs = message::getOne($this->db,$userid,$id);
|
|
$this->view->info = $rs['info'];
|
|
}
|
|
}
|
|
}
|
|
|
|
//读取所有消息
|
|
else if($do=="listall")
|
|
{
|
|
$sql = "SELECT * FROM messages m
|
|
LEFT JOIN messages_logs ml ON m.id=ml.mid
|
|
ORDER BY m.sendtime DESC";
|
|
$result = $this->db->query($sql);
|
|
$rows = $result->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;
|
|
}
|
|
|
|
//标记为已读
|
|
else if($do=="close" && !empty($id))
|
|
{
|
|
$auth = Zend_Auth::getInstance();
|
|
if($auth->hasIdentity())
|
|
{
|
|
$user = $auth->getIdentity();
|
|
$userid = $user->id;
|
|
include_once("message.php");
|
|
$rs = message::read($this->db,$userid,$id);
|
|
$this->_redirect('/admin/sys/message');
|
|
}
|
|
|
|
}
|
|
|
|
//标记为已处理(不再推送给其他管理员)
|
|
else if($do=="over" && !empty($id))
|
|
{
|
|
$auth = Zend_Auth::getInstance();
|
|
if($auth->hasIdentity())
|
|
{
|
|
$user = $auth->getIdentity();
|
|
$userid = $user->id;
|
|
if($user->usertype == "administrator")
|
|
{
|
|
include_once("message.php");
|
|
$rs = message::over($this->db,$id);
|
|
if($rs){
|
|
echo "操作成功!";exit();
|
|
}else{
|
|
echo "操作失败!";exit();
|
|
}
|
|
}else{
|
|
echo "非法操作!";exit();
|
|
}
|
|
}else{
|
|
echo "非法操作!";exit();
|
|
}
|
|
}
|
|
|
|
//拉取新消息
|
|
else
|
|
{
|
|
$auth = Zend_Auth::getInstance();
|
|
if($auth->hasIdentity())
|
|
{
|
|
$user = $auth->getIdentity();
|
|
$userid = $user->id;
|
|
if($user->usertype == "administrator")
|
|
{
|
|
include_once("message.php");
|
|
$rs = message::getNew($this->db,$userid,"admin");
|
|
$this->view->totle = $rs['count'];
|
|
$paginator = Zend_Paginator::factory($rs['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;
|
|
}
|
|
}
|
|
}//end
|
|
|
|
}//getmessageAction() 获取站内消息
|
|
}
|
|
|