重写专家邀请确认部分

This commit is contained in:
Li Jianxuan 2013-01-05 09:20:36 +00:00
parent 15f85d7950
commit 4358904f5d
2 changed files with 124 additions and 19 deletions

View File

@ -1017,29 +1017,17 @@ class HeiheController extends DataController
return true;
}
$sql = "SELECT * FROM $projectTable WHERE id=$pid";
$sth = $this->db->query($sql);
$row = $sth->fetch();
$level = $heihe->expertActive($pid,$invite);
if(empty($row['expert_name']))
if($level>100)
{
$this->view->error = "此项目尚未邀请跟踪专家";
$this->view->error = "数据中心对您的邀请已经确认!感谢您的支持";
return true;
}else{
$this->view->error = $heihe->expertActiveError($level);
return true;
}
$names = $this->getArray($row['expert_name']);
$emails = $this->getArray($row['expert_email']);
$validations = $this->getArray($row['expert_validation']);
$created = $this->getArray($row['expert_created']);
if(!in_array($validations))
{
$this->view->error = "您不在被邀请的专家名单内";
return true;
}
}//专家邀请链接

View File

@ -53,4 +53,121 @@ class Heihe
}
//专家激活
public function expertActive($pid,$code)
{
try{
$sql = "SELECT * FROM ".$this->tbl_heiheproject." WHERE id=$pid";
$sth = $this->db->query($sql);
$row = $sth->fetch();
//没有邀请专家
if(empty($row['expert_name']))
{
return 1;
}
$validations = $this->getArray($row['expert_validation']);
$status = $this->getArray($row['expert_activated']);
if(!in_array($code,$validations))
{
return 2;
}
$key = $this->getKey($validations,$code);
if(!empty($status))
{
if(isset($status[$key]))
{
return 3;
}
$time = array($code,date("Y-m-d H:i:s",time()));
$time = array($this->mkArray($time));
$new_status = array_splice($status,$key,0,$time);
$new_status = $this->mkArray($new_status);
$sql = "UPDATE ".$this->tbl_heiheproject." SET expert_activated=?";
$sth = $this->db->prepare($sql);
if($sth->execute(array($new_status)))
{
return 200;
}
}else{
$time = date("Y-m-d H:i:s",time());
$new_status = "{{".$code.",".$time."}}";
$sql = "UPDATE ".$this->tbl_heiheproject." SET expert_activated=?";
$sth = $this->db->prepare($sql);
if($sth->execute(array($new_status)))
{
return 200;
}
}
}catch(Execaption $e){
return 50;
}
}
public function expertActiveError($level){
$errors = array(
1 => "该汇交计划还没有邀请专家",
2 => "您没有被邀请,请联系数据中心进行核实",
3 => "您的邀请已经激活",
50 => "服务器错误,请刷新页面重试",
200 => "在已存在的激活时间中插入了新数据",
300 => "新激活时间写入"
);
}
//从pgsql读取数组并拆分为php数组
public function getArray($str){
if(strlen($str)>3)
{
return explode(",",substr($str,1,-1));
}else{
return NULL;
}
}
//将php数组组装成pgsql中的数组
public 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)."}";
}
}
//从数组中获得键名
public function getKey($array,$needle)
{
foreach($array as $k=>$v)
{
if($v == $needle)
{
return $k;
}
}
}
}