<?
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
* Class		:	product
* Version :	1.0
* Date    :	04 October 2009
* Author  :	Darwish A. Khalil
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/

// Class Definition
class product
{
	var $ProductID;					// Auto increment (Primary Key)
	var $Title;							// Product Name/Title
	var $Description;				// Small description about product to be displayed as to describe this product on the home page
	var $GenericInfo;				// Product's Generic Information/Introduction
	var $Roadmap;						// Product's Roadmap
	var $PictureName;				// Name of the product's picture
	var $DisplayOrder = 1;	// The order of this product on products list
	var $ShowOnHomePage = 0;// To specify whether this product is to be shown on home page or not

	/*
	 * Class constructor
	 */
  function product($ProductID = -1)
  {
  	if ((!empty($ProductID)) && ($ProductID != -1))
  	{
  		$this->ProductID = $ProductID;
			$this->getInfo();
		}
	}

	/*
	 * Retrieves product information
	 */
	function getInfo()
	{
		$query = "
							Select * From product
					 	  Where ProductID = $this->ProductID
					 	 ";

		$result = mysql_query($query);
		$row = mysql_fetch_object($result);

    // Set class data members
    $this->Title 					= stripslashes($row->Title);
    $this->Description 		= stripslashes($row->Description);
    $this->GenericInfo 		= stripslashes($row->GenericInfo);
    $this->Roadmap 				= stripslashes($row->Roadmap);
    $this->PictureName 		= $row->PictureName;
    $this->DisplayOrder 	= $row->DisplayOrder;
    $this->ShowOnHomePage = $row->ShowOnHomePage;
  }

	/*
   * Retrieves a list of all products to be shown on the home page ordered by Display Order
   */
	function getHomePageList()
	{
		global $language;

		$query  =
							"
								Select ProductID From product
								Where Enabled = 1 And Deleted = 0 And ShowOnHomePage = 1 And Language = '$language'
								Order By DisplayOrder
							";
		// echo $query;
		$result = mysql_query($query);
		return $result;
	}

	/*
   * Retrieves the count of products
   */
	function getTotal()
	{
		global $language;

		$query =
						"
							Select COUNT(*) From product
							Where Enabled = 1 And Deleted = 0 And Language = '$language'
						";

		// Keyword ---------------------------------------------------------------------
		if($Criteria['Keyword'] != '')
		{
			$query .= "And ( ";
			$query .= "(Title Like '%" . $Criteria['Keyword'] . "%') OR ";
			$query .= "(Description Like '%" . $Criteria['Keyword'] . "%') ";
			$query .= ") ";
		}
	  // echo $query;
   	$result = mysql_result(mysql_query($query), 0, 0);
    return $result;
	}

	/*
   * Retrieves a list of all products
   */
	function getList($Start = -1, $Num = -1, $SortField = "Title", $SortType = "ASC")
	{
		global $language;

		$query  =
							"
								Select * From product
								Where Enabled = 1 And Deleted = 0 And Language = '$language' ";

		// Keyword ---------------------------------------------------------------------
		if($Criteria['Keyword'] != '')
		{
			$query .= "And ( ";
			$query .= "(Title Like '%" . $Criteria['Keyword'] . "%') OR ";
			$query .= "(Description Like '%" . $Criteria['Keyword'] . "%') ";
			$query .= ") ";
		}

		// Order By
		$query .= "Order By $SortField $SortType ";

		// Limit Results
		if (($Start!=-1) && ($Num!=-1)) {
     $query .= "Limit $Start,$Num";
    }
		// echo $query;
		$result = mysql_query($query);
		return $result;
	}

	/*
	 * Retrieves a list of all products having a certain keyword in GenericInfo Or Roadmap
   */
	function search($Keyword = '', $Type = "GenericInfo")
	{
		global $language;

		$Field = ($Type == "GenericInfo") ? "GenericInfo" : "Roadmap";

		$query  =
							"
								Select * From product
								Where Enabled = 1 And Deleted = 0 And Language = '$language'
								And $Field Like '%$Keyword%'
							";

		// Order By
		$query .= "Order By Title ";
		// echo $query;
		$result = mysql_query($query);
		return $result;
	}


	/*
	 * Checks if a certain product exists or not
	 */
  function isExist()
  {
  	global $language;

    $query =
    				"
    					Select ProductID From product
    					Where Enabled = 1 And Deleted = 0 And Language = '$language' And ProductID = $this->ProductID
    				";
    $result = mysql_query($query);
    if (mysql_num_rows($result)>0) {
			return true;
		}
		return false;
	}

	/*
   * Retrieves a list of all updates related to a certain product
   */
	function getUpdatesList()
	{
		global $language;

		$query  =
							"
								Select ReleaseID, VersionNumber, FileName From product_update
								Where Enabled = 1 And Deleted = 0 And Language = '$language' And ProductID = $this->ProductID
								Order By VersionNumber DESC
							";
		// echo $query;
		$result = mysql_query($query);
		return $result;
	}

}
?>