db_conn=pg_connect($dsn); } public function __destruct() { pg_close($this->db_conn); } /*statusUpdate -- will update the status of a vendor in the FLS DB ** vend -> the vendor name ** status -> add - will add the vendor, delete - will delete the vendor */ public function statusUpdate($vendor, $status) { $sql = ''; $sha1 = ''; $res = ''; //check if vendor and status are not empty if($vendor != '' && $status != '') { $sha1 = sha1($vendor); //create sha1 for signer if($status == 'add') { if (false == $this->checkVendor($vendor) ) { $sql = "INSERT INTO data (signer_name, sha1) VALUES('". $vendor ."','". $sha1 ."');"; //fileLog::log($sql); $res = pg_query($this->db_conn, $sql); if(pg_affected_rows($res) != 0) { $this->lastMessage = 'Signer successfully added to FLS database.'; return true; }else{ $this->lastMessage = 'Error adding signer to FLS database.'; return false; } }else{ $this->lastMessage = 'Signer is already added to the FLS database.'; return true; //if signer is in FLS we need to return true as it is not an error } }else if($status == 'delete'){ if (true == $this->checkVendor($vendor)){ $sql = "DELETE FROM data WHERE signer_name = '". $vendor ."';"; $res = pg_query($this->db_conn, $sql); if(pg_affected_rows($res) != 0) { $this->lastMessage = 'Signer successfully removed from FLS database.'; return true; }else{ $this->lastMessage = pg_result_error($res); return false; } }else{ $this->lastMessage = 'Signer does not exist in the FLS database.'; return true;//if signer does not exist in FLS we return true as it is not an error } } }else{ $this->lastMessage = 'Invalid signer name or status.'; return false; } } //returns the last error message public function lastError() { $msg = $this->lastMessage; $this->lastMessage = ''; return $msg; } /*checkVendor - check if a vendor exists or not in the FLS DB *vend - vendor name *return true if exists, false - if not */ private function checkVendor($vend) { $sql = ''; $res = ''; $row = ''; $sql = "SELECT COUNT(*) FROM data WHERE signer_name = '". $vend ."';"; $res = pg_query($this->db_conn, $sql); while($row=pg_fetch_assoc($res)) { if ($row['count'] == 1) return true; } return false; } } ?>