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

207 lines
5.5 KiB
PHP

<?php
class Admin_ReviewController 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();
}
function postDispatch()
{
$this->view->messages = $this->messenger->getMessages();
}
function indexAction()
{
}//indexAction
function acceptAction()
{
}//acceptAction 待评审的元数据
function expertsAction()
{
$search = $this->_request->getParam('search');
$keyword= $this->_request->getParam('keyword');
$submit = $this->_request->getParam('submit');
$edit = $this->_request->getParam('edit');
$del = $this->_request->getParam('del');
$add = $this->_request->getParam('add');
if($add)
{
if(!empty($submit))
{
foreach($_POST as $k=>$v)
{
$$k=$v;
}
$speciality = $_POST['speciality'];
$chars = array(
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
"w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G",
"H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
"S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2",
"3", "4", "5", "6", "7", "8", "9"
);
$charsLen = count($chars) - 1;
shuffle($chars);
$output = "";
for ($i=0; $i<8; $i++)
{
$output .= $chars[mt_rand(0, $charsLen)];
}
$password=$output;
$testsql="select id from users where username='$username' or email='$email'";
$re=$this->db->query($testsql);
$test=$re->fetch();
if(!empty($test['id']))
{
$this->messenger->addMessage('用户名或邮箱重复');
$this->_redirect("/admin/review/experts");
}
else
{
$data = array(
'username' => $username,
'realname' => $realname,
'email' => $email,
'unit' => $unit,
'address' => $address,
'phone' => $phone,
'project' => $project,
'password' => md5($password)
);
if($this->db->insert('users',$data))
{
$mail=new WestdcMailer($this->view->config->smtp);
$body="尊敬的西部数据中心用户:
您已经成功注册,请妥善保管您的账号信息
用户名:$username
密码: $password
感谢您的注册
西部数据中心服务组";
$body.="";
$mail->setBodyText($body);
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
$mail->addTo($email);
$mail->setSubject('欢迎注册成为西部数据中心用户');
$mail->send();
$sql="select id from users where username='{$data['username']}'";
$re=$this->db->query($sql);
$row = $re->fetch();
$sql="insert into mdexperts (id,speciality) values ('{$row['id']}','$speciality')";
if($this->db->exec($sql)>0)
{
$this->messenger->addMessage('成功添加评审专家');
$this->_redirect("/admin/review/experts");
}
}
}
}
else
{
$this->_helper->viewRenderer('expertsadd');
}
}
if($del>0)
{
$sql="delete from mdexperts where id='$del'";
if($this->db->exec($sql)>0)
{
$this->messenger->addMessage('删除成功!');
$this->_redirect('/admin/review/experts');
}
}
if($edit>0)
{
if(!empty($submit))
{
$speciality = $this->_request->getParam('speciality');
$sql = "update mdexperts set speciality='$speciality',ts_modified='".date("Y-m-d H:i:s",time())."' where id='$edit'";
if($this->db->exec($sql)>0)
{
$this->messenger->addMessage('编辑成功!');
$this->_redirect('/admin/review/experts');
}
}
else
{
$sql = "select m.*,m.id as mid,u.* from mdexperts m left join users u on u.id=m.id
where m.id='$edit'";
$re = $this->db->query($sql);
$row = $re->fetch();
$this->view->infos = $row;
$this->view->id=$edit;
$this->_helper->viewRenderer('expertsedit');
}
}//编辑
if($search)
{
$sql = "select m.*,m.id as mid,u.* from mdexperts m left join users u on u.id=m.id
where u.realname like '%$keyword%' or m.speciality like '%$keyword%' or u.unit like '%$keyword%'";
$re = $this->db->query($sql);
$rows = $re->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
{
$sql="select m.*,m.id as mid,u.* from mdexperts m left join users u on u.id=m.id";
$re = $this->db->query($sql);
$rows = $re->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.phtml');
$this->view->paginator=$paginator;
}//列表
}//expertsAction 专家库
}