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) { 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; } } } }