db = $db; $this->project_status = array( 0 => "计划未提交", 1 => "计划未审核", 2 => "跟踪专家审核", 3 => "跟踪专家通过", 4 => "数据委员会通过" ); } //获取汇交状态 public function getStatus($code){ $status = $this->project_status; if(isset($status[$code])) { return $status[$code]; } } //改变状态 public function ChangeStatus($p,$s){ $sql = "UPDATE ".$this->tbl_heiheproject." SET status=? WHERE id=?"; $sth = $this->db->prepare($sql); $rs = $sth->execute(array($s,$p)); return $rs; } //专家激活 public function expertActive($pid,$code,$email) { if(empty($pid)) { return 1; } if(!is_numeric($pid)) { return 1; } if(!preg_match("/[A-Za-z0-9]/",$code)) { return 1; } if(strlen($code) != 12) { return 1; } $validation = $this->makeValidation($email); if($code != $validation) { return 5; } $experts = $this->expertRead($pid); if(!is_array($experts)) { return 10; } $matched = false; $match_expert = ""; foreach($experts as $k=>$v) { if($v['validation'] == $code) { $matched = true; $match_expert = $v; unset($experts[$k]); break; } } if($matched != true) { return 15; } if(isset($match_expert['activated'])) { if(strtotime($match_expert['activated']) < time()) { return 20; } } $match_expert['activated'] = date("Y-m-d H:i:s",time()); $experts[] = $match_expert; $experts = json_encode($experts); $this->expertUpdate($pid,$experts); return 200; } public function expertActiveError($level){ $errors = array( 1 => "参数错误", 5 => "您的验证码不正确", 10 => "此项目尚未邀请任何专家", 15 => "您没有被邀请,请联系数据中心进行核实", 20 => "您的邀请已经激活", 50 => "服务器错误,请刷新页面重试", 200 => "激活成功", ); if(isset($errors[$level])) return $errors[$level]; else return "发生意外错误,请重试"; } //邀请一个专家 /* $data = array( "name"=>'', //专家姓名 "email"=>'', //专家email "created"=>'', //邀请时间 "validation"=>'', //验证码 "activated"=>'' //激活时间 ) */ public function expertAdd($pid,$data){ if(!is_array($data)) { return 0; } $experts = $this->expertRead($pid); if(!is_array($experts)) { $experts = array($data); }else{ foreach($experts as $k=>$v) { if($v['email'] == $data['email']) { return -1; } } $experts[] = $data; } $experts = json_encode($experts,JSON_NUMERIC_CHECK); return $this->expertUpdate($pid,$experts); } //移除一个专家 public function expertRemove($pid,$email){ if(empty($pid) || empty($email)) { return 0; } $experts = $this->expertRead($pid); if(!is_array($experts)) { return -1; }else{ foreach($experts as $k=>$v) { if(isset($v['email']) && $v['email'] == $email) { unset($experts[$k]); } } } $experts = json_encode($experts); return $this->expertUpdate($pid,$experts); } //更新专家 public function expertUpdate($pid,$obj){ $sql = "UPDATE ".$this->tbl_heiheproject." SET expert='$obj' WHERE id=$pid"; $rs = $this->db->exec($sql); return $rs; } //读取已有的专家 public function expertRead($pid){ if(!is_numeric($pid)) { return NULL; } $sql = "SELECT expert FROM ".$this->tbl_heiheproject." WHERE id=$pid"; $rs = $this->db->query($sql); $row = $rs->fetch(); $expert = $row['expert']; if(empty($expert)) { return NULL; } $expert = json_decode($expert,true); if(count($expert)<1) { return 0; }else{ return $expert; } } //邀请码 public function makeValidation($email){ return substr(md5($email),5,12); } //生成邀请连接 public function makeInviteLink($pid,$code) { $http_base = "http://".$_SERVER ['HTTP_HOST']; $url = $http_base."/heihe/projects/invite/".$code.'/pid/'.$pid; return $url; }//生成邀请连接 //从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; } } } }