<?php 
include_once 'class.database.php';
class ManageIssues{
	public $link;
	function __construct()
	{
		global $prefix;
		$db_connection = new dbConnection();
		$this->link = $db_connection->connect();

		return $this->link;
	}
	function Add($aid , $tyid , $prjid , $iversion , $icode , $ititle , $idesc , $iproirity , $icomplexity , $ineeded_time , $ifile1 , $ifile2 , $ifile3 , $iarchive , $iwho_fullname , $iwho_email , $iwho_tel , $icomments ,$idone ,$idone_date ,$idone_version)
	{
		global $prefix;
		$query = $this->link->prepare("INSERT INTO `".$prefix."issues` (`aid` , `tyid` , `prjid` , `iversion` , `icode` , `ititle` , `idesc` , `iproirity` , `icomplexity` , `ineeded_time` , `ifile1` , `ifile2` , `ifile3` , `iarchive` , `iwho_fullname` , `iwho_email` , `iwho_tel` , `icomments` , `idone` , `idone_date` , `idone_version`, `idate`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,NOW()) ");
		$values = array($aid , $tyid , $prjid , $iversion , $icode , $ititle , $idesc , $iproirity , $icomplexity , $ineeded_time , $ifile1 , $ifile2 , $ifile3 , $iarchive , $iwho_fullname , $iwho_email , $iwho_tel , $icomments ,$idone ,$idone_date ,$idone_version);
		$query->execute($values);
		// print_r ($query->errorInfo());
		$counts= $query->rowCount();

		
		return $counts;
	}

	function Update($tyid , $prjid , $iversion , $icode , $ititle , $idesc , $iproirity , $icomplexity , $ineeded_time , $ifile1 , $ifile2 , $ifile3 , $iarchive , $iwho_fullname , $iwho_email , $iwho_tel , $icomments, $idone ,$idone_date ,$idone_version ,$iid)
	{
		global $prefix;
		$query = $this->link->prepare("UPDATE `".$prefix."issues` SET `tyid`=?, `prjid`=?, `iversion`=?, `icode`=?, `ititle`=?, `idesc`=?, `iproirity`=?, `icomplexity`=?, `ineeded_time`=?, `ifile1`=?, `ifile2`=?, `ifile3`=?, `iarchive`=?, `iwho_fullname`=?, `iwho_email`=?, `iwho_tel`=?, `icomments`=?, `idone`=?, `idone_date`=?, `idone_version`=? WHERE `iid`=? ");
		$values = array($tyid , $prjid , $iversion , $icode , $ititle , $idesc , $iproirity , $icomplexity , $ineeded_time , $ifile1 , $ifile2 , $ifile3 , $iarchive , $iwho_fullname , $iwho_email , $iwho_tel , $icomments, $idone ,$idone_date ,$idone_version ,$iid);
		$query->execute($values);
		// print_r ($query->errorInfo());
		return $query->rowCount();
	}

	function Delifile1($ifile1 ,$iid)
		{
			global $prefix;
			$query = $this->link->prepare("UPDATE `".$prefix."issues` SET `ifile1`=? WHERE `iid`=? ");
			$values = array($ifile1 ,$iid);
			$query->execute($values);
			// print_r ($query->errorInfo());
			return $query->rowCount();
		}

	function Delifile2($ifile2 ,$iid)
		{
			global $prefix;
			$query = $this->link->prepare("UPDATE `".$prefix."issues` SET `ifile2`=? WHERE `iid`=? ");
			$values = array($ifile2 ,$iid);
			$query->execute($values);
			// print_r ($query->errorInfo());
			return $query->rowCount();
		}

	function Delifile3($ifile3 ,$iid)
		{
			global $prefix;
			$query = $this->link->prepare("UPDATE `".$prefix."issues` SET `ifile3`=? WHERE `iid`=? ");
			$values = array($ifile3 ,$iid);
			$query->execute($values);
			// print_r ($query->errorInfo());
			return $query->rowCount();
		}


	function ListIssues($where, $order='ORDER BY iid DESC' ,$limit=NULL)
	{
		global $prefix;
		$query = $this->link->query("SELECT * FROM `".$prefix."issues` INNER JOIN `".$prefix."admins` ON ".$prefix."issues.aid=".$prefix."admins.aid INNER JOIN `".$prefix."projects` ON ".$prefix."issues.prjid=".$prefix."projects.prjid INNER JOIN `".$prefix."issue_types` ON ".$prefix."issues.tyid=".$prefix."issue_types.tyid $where $order $limit");
		// $values = array($where);
		// $query->execute($values);
		// print_r ($query->errorInfo());
		return $query->fetchAll();
	}

		function Getinfo($field,$value)
	{
		global $prefix;
		$query = $this->link->prepare("SELECT * FROM `".$prefix."issues` INNER JOIN `".$prefix."admins` ON ".$prefix."issues.aid=".$prefix."admins.aid INNER JOIN `".$prefix."projects` ON ".$prefix."issues.prjid=".$prefix."projects.prjid INNER JOIN `".$prefix."issue_types` ON ".$prefix."issues.tyid=".$prefix."issue_types.tyid WHERE $field=?");
		$values = array($value);
		$query->execute($values);
		return $query->fetchAll();
	}

	function GetList($query="")
	{
		global $prefix;
		$query = $this->link->query("SELECT * FROM `".$prefix."issues` WHERE idone=0 $query");
		// $values = array($where);
		// $query->execute($values);
		// print_r ($query->errorInfo());
		return $query->fetchAll();
	}

		function GetListAll($query="")
	{
		global $prefix;
		$query = $this->link->query("SELECT * FROM `".$prefix."issues` WHERE $query");
		// $values = array($where);
		// $query->execute($values);
		// print_r ($query->errorInfo());
		return $query->fetchAll();
	}



		function GetFullList()
	{
		global $prefix;
		$query = $this->link->query("SELECT * FROM `".$prefix."issues` ");
		// $values = array($where);
		// $query->execute($values);
		// print_r ($query->errorInfo());
		return $query->fetchAll();
	}

		function GetFullNames()
	{
		global $prefix;
		$query = $this->link->query("SELECT ititle,iid,idone FROM `".$prefix."issues` ");
		// $values = array($where);
		// $query->execute($values);
		// print_r ($query->errorInfo());
		return $query->fetchAll();
	}

	function GetIssueTasks($iid)
	{
		global $prefix;
		$query = $this->link->prepare("SELECT tskid FROM `".$prefix."tasks_issues` WHERE iid=?");
		$values = array($iid);
		$query->execute($values);
		return $query->fetchAll(PDO::FETCH_COLUMN);
	}

	function GetFullIssueTasks($iid)
	{
		global $prefix;
		$query = $this->link->prepare("SELECT tskid FROM `".$prefix."tasks_issues` WHERE iid=?");
		$values = array($iid);
		$query->execute($values);
		return $query->fetchAll();
	}

	function RowCount($where=NULL)
		{
			global $prefix;
			$query = $this->link->query("SELECT * FROM `".$prefix."issues` INNER JOIN `".$prefix."admins` ON ".$prefix."issues.aid=".$prefix."admins.aid INNER JOIN `".$prefix."projects` ON ".$prefix."issues.prjid=".$prefix."projects.prjid INNER JOIN `".$prefix."issue_types` ON ".$prefix."issues.tyid=".$prefix."issue_types.tyid $where");
			// $values = array($where);
			// $query->execute($values);
			// print_r ($query->errorInfo());
			return $query->rowCount();
		}

	function Delete($id)
	{
		global $prefix;
		$query = $this->link->prepare("DELETE FROM `".$prefix."issues` WHERE iid=?");
		$values = array($id);
		$query->execute($values);
		return $query->rowCount();
	}
}
 ?>