2012-11-09 09:58:33 +00:00
|
|
|
<?php
|
|
|
|
class Admin_HeiheController extends Zend_Controller_Action
|
|
|
|
{
|
|
|
|
function preDispatch()
|
|
|
|
{
|
|
|
|
$this->db=Zend_Registry::get('db');
|
|
|
|
$this->view->config = Zend_Registry::get('config');
|
|
|
|
}
|
|
|
|
|
|
|
|
function postDispatch()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function indexAction()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* projectsAction() 数据汇交计划
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function projectAction()
|
|
|
|
{
|
|
|
|
$this->view->input_NameDefaultVal = "专家姓名";
|
|
|
|
$this->view->input_EmailDefaultVal = "专家email";
|
|
|
|
$projectTable = "heiheproject";
|
|
|
|
|
|
|
|
$ac = $this->_getParam('ac');
|
|
|
|
|
|
|
|
if(empty($ac) || $ac == "index")
|
|
|
|
{
|
|
|
|
$this->_helper->viewRenderer('project');
|
|
|
|
|
|
|
|
//Search Link
|
|
|
|
$this->view->searchLink = "/admin/heihe/project/ac/index/";
|
|
|
|
|
|
|
|
$q = $this->_getParam('q');
|
|
|
|
|
|
|
|
$wheresql = array();
|
|
|
|
|
|
|
|
if(!empty($q))
|
|
|
|
{
|
|
|
|
$wheresql[] = " (title LIKE '%$q%' OR
|
|
|
|
code LIKE '%$q%' OR
|
|
|
|
name LIKE '%$q%' OR
|
|
|
|
email LIKE '%$q%')";
|
|
|
|
$this->view->searchKeyword = $q;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(count($wheresql)>0)
|
|
|
|
{
|
|
|
|
$wheresql = join(" AND ",$wheresql);
|
|
|
|
}else{
|
|
|
|
$wheresql = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!empty($wheresql))
|
|
|
|
{
|
|
|
|
$wheresql = " WHERE ".$wheresql;
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "SELECT * FROM $projectTable $wheresql
|
|
|
|
ORDER BY id ASC";
|
|
|
|
$sth = $this->db->query($sql);
|
|
|
|
$rows = $sth->fetchAll();
|
|
|
|
|
|
|
|
foreach ($rows as $k=>$v)
|
|
|
|
{
|
|
|
|
$rows[$k]['status'] = $this->replacestatus($v['status']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->view->Count = count($rows);
|
|
|
|
|
|
|
|
$paginator = Zend_Paginator::factory($rows);
|
|
|
|
$paginator->setCurrentPageNumber($this->_getParam('page'));
|
|
|
|
$paginator->setItemCountPerPage(15);
|
|
|
|
$paginator->setView($this->view);
|
|
|
|
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
|
|
|
|
$this->view->paginator=$paginator;
|
|
|
|
|
|
|
|
}//ac == index
|
|
|
|
|
|
|
|
//邀请专家
|
|
|
|
if($ac == "invite")
|
|
|
|
{
|
|
|
|
$this->_helper->layout->disableLayout();
|
|
|
|
$this->_helper->viewRenderer->setNoRender();
|
|
|
|
|
|
|
|
$pid = $this->_getParam('id');
|
|
|
|
$name = $this->_getParam('name');
|
|
|
|
$email = $this->_getParam('email');
|
|
|
|
|
|
|
|
if(!is_numeric($pid))
|
|
|
|
{
|
|
|
|
$this->jsonexit(array("error"=>"参数错误"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(empty($name) || $name == $this->view->input_NameDefaultVal)
|
|
|
|
{
|
|
|
|
$this->jsonexit(array("error"=>"请输入专家姓名"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(empty($email) || $email == $this->view->input_EmailDefaultVal)
|
|
|
|
{
|
|
|
|
$this->jsonexit(array("error"=>"请输入专家Email"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "SELECT * FROM $projectTable WHERE id=$pid";
|
|
|
|
$sth = $this->db->query($sql);
|
|
|
|
$row = $sth->fetch();
|
|
|
|
|
|
|
|
$expert_name = $this->getArray($row['expert_name']);
|
|
|
|
$expert_email = $this->getArray($row['expert_email']);
|
2012-11-12 07:10:31 +00:00
|
|
|
$expert_validation = $this->getArray($row['expert_validation']);
|
|
|
|
$expert_created = $this->getArray($row['expert_created']);
|
2012-11-09 09:58:33 +00:00
|
|
|
|
|
|
|
$name_list = array();
|
|
|
|
$email_list = array();
|
2012-11-12 07:10:31 +00:00
|
|
|
$validation_list = array();
|
|
|
|
$created_list = array();
|
2012-11-09 09:58:33 +00:00
|
|
|
|
|
|
|
if(is_array($expert_name) && count($expert_name)>0)
|
|
|
|
{
|
|
|
|
if(in_array($name,$expert_name))
|
|
|
|
{
|
|
|
|
$this->jsonexit(array("error"=>"该专家的姓名已经存在"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(is_array($expert_email) && count($expert_email)>0)
|
|
|
|
{
|
|
|
|
if(in_array($email,$expert_email))
|
|
|
|
{
|
|
|
|
$this->jsonexit(array("error"=>"该专家的Email已经存在"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$expert_name[] = $name;
|
|
|
|
$expert_email[] = $email;
|
2012-11-12 07:10:31 +00:00
|
|
|
$code = substr(md5($email),5,12);
|
|
|
|
$expert_validation[] = $code;
|
|
|
|
$expert_created[] = date("Y-m-d H:i:s",time());
|
|
|
|
|
2012-11-09 09:58:33 +00:00
|
|
|
|
|
|
|
$name_list = $this->mkArray($expert_name);
|
|
|
|
$email_list = $this->mkArray($expert_email);
|
2012-11-12 07:10:31 +00:00
|
|
|
$validation_list = $this->mkArray($expert_validation);
|
|
|
|
$created_list = $this->mkArray($expert_created);
|
|
|
|
|
|
|
|
$update = array(
|
|
|
|
"expert_name"=>$name_list,
|
|
|
|
"expert_email"=>$email_list,
|
|
|
|
"expert_validation"=>$validation_list,
|
|
|
|
"expert_created"=>$created_list
|
|
|
|
);
|
2012-11-09 09:58:33 +00:00
|
|
|
$where = "id=$pid";
|
|
|
|
|
|
|
|
if($this->db->update($projectTable,$update,$where))
|
|
|
|
{
|
2012-11-12 07:10:31 +00:00
|
|
|
$this->sendMailToExpert($pid,$name,$email,$code);
|
2012-11-09 09:58:33 +00:00
|
|
|
$this->jsonexit(array("msg"=>"专家邀请成功!","invited"=>1));
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
$this->jsonexit(array("error"=>"邀请失败,请重试"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}// 邀请专家
|
|
|
|
|
|
|
|
if($ac == "showexpert")
|
|
|
|
{
|
|
|
|
$del = $this->_getParam('del');
|
|
|
|
|
|
|
|
if(isset($del))
|
|
|
|
{
|
|
|
|
|
|
|
|
$this->_helper->layout->disableLayout();
|
|
|
|
$this->_helper->viewRenderer->setNoRender();
|
|
|
|
}else{
|
|
|
|
$this->_helper->layout->setLayout('layout-iframe');
|
|
|
|
$this->_helper->viewRenderer('project-showexpert');
|
|
|
|
}
|
|
|
|
|
|
|
|
$pid = $this->_getParam('id');
|
|
|
|
|
|
|
|
if(empty($pid) || !is_numeric($pid))
|
|
|
|
{
|
|
|
|
$this->view->error = "参数错误";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->view->pid = $pid;
|
|
|
|
|
|
|
|
$sql = "SELECT * FROM $projectTable WHERE id=$pid";
|
|
|
|
$sth = $this->db->query($sql);
|
|
|
|
$row = $sth->fetch();
|
|
|
|
|
|
|
|
if(empty($row['expert_name']))
|
|
|
|
{
|
|
|
|
$this->view->error = "此项目还没有添加跟踪专家";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$names = $this->getArray($row['expert_name']);
|
|
|
|
$emails = $this->getArray($row['expert_email']);
|
2012-11-12 07:10:31 +00:00
|
|
|
$validations = $this->getArray($row['expert_validation']);
|
|
|
|
$created = $this->getArray($row['expert_created']);
|
2012-11-09 09:58:33 +00:00
|
|
|
|
|
|
|
$experts = array();
|
|
|
|
|
|
|
|
foreach($names as $k=>$v)
|
|
|
|
{
|
2012-11-12 07:10:31 +00:00
|
|
|
$experts[$k] = array(
|
|
|
|
"name"=>$names[$k],
|
|
|
|
"email"=>$emails[$k],
|
|
|
|
"validation"=>$validations[$k],
|
|
|
|
"created"=>$created[$k],
|
|
|
|
"url"=>$this->makeInviteLink($pid,$validations[$k])
|
|
|
|
);
|
2012-11-09 09:58:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->view->experts = $experts;
|
|
|
|
|
|
|
|
$del = $this->_getParam('del');
|
|
|
|
|
|
|
|
if(isset($del))
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!is_numeric($del))
|
|
|
|
{
|
|
|
|
$this->jsonexit(array("error"=>"参数错误"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
unset($names[$del]);
|
|
|
|
unset($emails[$del]);
|
2012-11-12 07:10:31 +00:00
|
|
|
unset($validations[$del]);
|
|
|
|
unset($created[$del]);
|
2012-11-09 09:58:33 +00:00
|
|
|
|
|
|
|
$update = array(
|
|
|
|
"expert_name"=>$this->mkArray($names),
|
2012-11-12 07:10:31 +00:00
|
|
|
"expert_email"=>$this->mkArray($emails),
|
|
|
|
"expert_validation"=>$this->mkArray($validations),
|
|
|
|
"expert_created"=>$this->mkArray($created),
|
2012-11-09 09:58:33 +00:00
|
|
|
);
|
|
|
|
$where = "id=$pid";
|
|
|
|
|
|
|
|
if($this->db->update($projectTable,$update,$where))
|
|
|
|
{
|
|
|
|
$this->jsonexit(array("deleted"=>1));
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
$this->jsonexit(array("error"=>"邀请失败,请重试"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}//ac == showexpert 查看跟踪专家
|
|
|
|
|
|
|
|
if($ac == "unsubmit")
|
|
|
|
{
|
|
|
|
|
|
|
|
}//ac == unsubmit 未提交
|
|
|
|
|
|
|
|
if($ac == "submit")
|
|
|
|
{
|
|
|
|
|
|
|
|
}//ac == submit 已提交
|
|
|
|
|
|
|
|
}//projectsAction()
|
|
|
|
|
|
|
|
function replacestatus($status)
|
|
|
|
{
|
|
|
|
if($status == 0)
|
|
|
|
{
|
|
|
|
return "计划未提交";
|
|
|
|
}
|
|
|
|
if($status == 1)
|
|
|
|
{
|
|
|
|
return "计划未审核";
|
|
|
|
}
|
|
|
|
if($status == 2)
|
|
|
|
{
|
|
|
|
return "跟踪专家审核";
|
|
|
|
}
|
|
|
|
if($status == 3)
|
|
|
|
{
|
|
|
|
return "跟踪专家通过";
|
|
|
|
}
|
|
|
|
if($status == 4)
|
|
|
|
{
|
|
|
|
return "数据委员会通过";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//从pgsql读取数组并拆分为php数组
|
|
|
|
function getArray($str){
|
|
|
|
if(strlen($str)>3)
|
|
|
|
{
|
|
|
|
return explode(",",substr($str,1,-1));
|
|
|
|
}else{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//将php数组组装成pgsql中的数组
|
|
|
|
function mkArray($array){
|
|
|
|
if(!is_array($array))
|
|
|
|
{
|
|
|
|
return "{".$array."}";
|
|
|
|
}
|
|
|
|
if(count($array)==1)
|
|
|
|
{
|
|
|
|
$key = max(array_keys($array));
|
|
|
|
return "{".$array[$key]."}";
|
|
|
|
}
|
|
|
|
if(count($array)>1)
|
|
|
|
{
|
|
|
|
return "{".join(",",$array)."}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//发送邀请专家的邮件
|
2012-11-12 07:10:31 +00:00
|
|
|
function sendMailToExpert($pid,$name,$email,$code)
|
2012-11-09 09:58:33 +00:00
|
|
|
{
|
2012-11-12 07:10:31 +00:00
|
|
|
$url = $this->makeInviteLink($pid,$code);
|
|
|
|
|
2012-11-09 09:58:33 +00:00
|
|
|
include_once("EmailText.php");
|
2012-11-12 07:10:31 +00:00
|
|
|
$mailtp=new EmailText($this->db,"expert-invite",array(
|
2012-11-09 09:58:33 +00:00
|
|
|
'name' => $name,
|
|
|
|
'url' => $url,
|
|
|
|
));
|
|
|
|
//Email test code
|
|
|
|
|
2012-11-12 07:10:31 +00:00
|
|
|
/*
|
2012-11-09 09:58:33 +00:00
|
|
|
$mail_config = array(
|
|
|
|
'ssl' => 'ssl',
|
|
|
|
'port' => 465,
|
|
|
|
'auth' => 'login',
|
2012-11-12 07:10:31 +00:00
|
|
|
'username' => 'la5c@qq.com',
|
|
|
|
'password' => ''
|
2012-11-09 09:58:33 +00:00
|
|
|
);
|
2012-11-12 07:10:31 +00:00
|
|
|
$transport = new Zend_Mail_Transport_Smtp('smtp.qq.com', $mail_config);
|
2012-11-09 09:58:33 +00:00
|
|
|
Zend_Mail::setDefaultTransport($transport);
|
|
|
|
|
|
|
|
$mail=new Zend_Mail();
|
2012-11-12 07:10:31 +00:00
|
|
|
$mail->setBodyText($mailtp->getBody());
|
|
|
|
$mail->setFrom('la5c@qq.com','Jack');
|
2012-11-09 09:58:33 +00:00
|
|
|
$mail->addTo($email);
|
2012-11-12 07:10:31 +00:00
|
|
|
$mail->setSubject($mailtp->getSubject());
|
2012-11-09 09:58:33 +00:00
|
|
|
$mail->send();
|
2012-11-12 07:10:31 +00:00
|
|
|
*/
|
2012-11-09 09:58:33 +00:00
|
|
|
|
|
|
|
$mail=new WestdcMailer($this->view->config->smtp);
|
|
|
|
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
|
|
|
|
$mail->setBodyText($mailtp->getBody());
|
|
|
|
$mail->setSubject($mailtp->getSubject());
|
2012-11-12 07:10:31 +00:00
|
|
|
$mail->addTo($email);
|
2012-11-09 09:58:33 +00:00
|
|
|
$mail->send();
|
2012-11-12 07:10:31 +00:00
|
|
|
}//发送邀请邮件
|
|
|
|
|
|
|
|
//生成邀请连接
|
|
|
|
function makeInviteLink($pid,$code)
|
|
|
|
{
|
|
|
|
$http_base = "http://".$_SERVER ['HTTP_HOST'];
|
|
|
|
$url = $http_base."/heihe/projects/invite/".$code.'/pid/'.$pid;
|
|
|
|
return $url;
|
|
|
|
}//生成邀请连接
|
2012-11-09 09:58:33 +00:00
|
|
|
|
|
|
|
public function jsonexit($data){
|
|
|
|
$this->getResponse()
|
|
|
|
->setHeader('Content-Type', 'application/json')
|
|
|
|
->appendBody(json_encode($data,JSON_NUMERIC_CHECK));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|