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

		return $this->link;
	}
	function Add($aid ,$prjcode ,$prjtitle ,$prjdesc ,$prjlogo ,$prjcomments)
	{
		global $prefix;
		$query = $this->link->prepare("INSERT INTO `".$prefix."projects` (`aid`, `prjcode`, `prjtitle`, `prjdesc`, `prjlogo`, `prjcomments`, `prjdate`) VALUES (?,?,?,?,?,?,NOW()) ");
		$values = array($aid ,$prjcode ,$prjtitle ,$prjdesc ,$prjlogo ,$prjcomments);
		$query->execute($values);
		// print_r ($query->errorInfo());
		$counts= $query->rowCount();

		
		return $counts;
	}

	function Update($prjcode ,$prjtitle ,$prjdesc ,$prjlogo ,$prjcomments,$prjid)
	{
		global $prefix;
		$query = $this->link->prepare("UPDATE `".$prefix."projects` SET `prjcode`=?, `prjtitle`=?, `prjdesc`=?, `prjlogo`=?, `prjcomments`=? WHERE `prjid`=? ");
		$values = array($prjcode ,$prjtitle ,$prjdesc ,$prjlogo ,$prjcomments,$prjid);
		$query->execute($values);
		// print_r ($query->errorInfo());
		return $query->rowCount();
	}

	function ListProjects($where, $order='ORDER BY prjid DESC' ,$limit=NULL)
	{
		global $prefix;
		$query = $this->link->query("SELECT * FROM `".$prefix."projects` INNER JOIN `".$prefix."admins` ON ".$prefix."projects.aid=".$prefix."admins.aid $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."projects` INNER JOIN `".$prefix."admins` ON ".$prefix."projects.aid=".$prefix."admins.aid WHERE $field=?");
		$values = array($value);
		$query->execute($values);
		return $query->fetchAll();
	}

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

	

	function RowCount($where=NULL)
		{
			global $prefix;
			$query = $this->link->query("SELECT * FROM `".$prefix."projects` INNER JOIN `".$prefix."admins` ON ".$prefix."projects.aid=".$prefix."admins.aid $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."projects` WHERE prjid=?");
		$values = array($id);
		$query->execute($values);
		return $query->rowCount();
	}
}
 ?>