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

// Class Definition
class productFAQ
{
	var $FAQID;						// Auto increment (Primary Key)
	var $Question;				// Question
	var $Answer;					// Answer
	var $PublishedDate;		// Published date
	var $ProductID;				// Question's related product id
	var $ProductName;			// Question's related product name
	var $ReleaseID;				// Question's related release id
	var $ProductRelease;  // Question's related release
	var $DisplayOrder = 1;// The order of this question on FAQ list

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

	/*
	 * Retrieves FAQ information
	 */
	function getInfo()
	{
		$query = "
							Select q.Question, q.Answer, q.PublishedDate, q.ProductID, q.DisplayOrder,
							p.Title ProductName, r.VersionNumber ProductRelease
							From product_faq q
							Inner Join product p On q.ProductID = p.ProductID
							Left Join product_update r On q.ReleaseID = r.ReleaseID
							Where FAQID = $this->FAQID
					 	 ";
		// echo $query;
		$result = mysql_query($query);
		$row = mysql_fetch_object($result);

    // Set class data members
    $this->Question 			= stripslashes($row->Question);
    $this->Answer 				= stripslashes($row->Answer);
    $this->PublishedDate 	= $row->PublishedDate;
    $this->ProductID 			= $row->ProductID;
    $this->ProductName 		= $row->ProductName;
    $this->ReleaseID 			= $row->ReleaseID;
    $this->ProductRelease = $row->ProductRelease;
    $this->DisplayOrder 	= $row->DisplayOrder;
  }

	/*
   * Retrieves the count of questions available according to the given search criteria
   */
	function getTotal($Criteria)
	{
		global $language;

		$query  = "Select COUNT(*) From product_faq ";
		$query .= "Where Deleted = 0 And Enabled = 1 And Language = '$language' And ProductID = $this->ProductID ";

		// Keyword ----------------------------------------------------------------
		if($Criteria['Keyword'] != '')
		{
			$query .= "And ( ";
			$query .= "(Question Like '%" . $Criteria['Keyword'] . "%') OR ";
			$query .= "(Answer Like '%" . $Criteria['Keyword'] . "%') ";
			$query .= ") ";
		}
		// ReleaseID --------------------------------------------------------------
		if( (!empty($Criteria['ReleaseID'])) && ($Criteria['ReleaseID'] != -1) )  {
			$query .= "And (ReleaseID = '" . $Criteria['ReleaseID'] . "') ";
		}

	  // echo $query;
   	$result = mysql_result(mysql_query($query), 0, 0);

    return $result;
	}

	/*
	 * Retrieve a list of questions regarding a certain search criteria
	 */
	function getList($Criteria = '', $SortField = "DisplayOrder", $SortType = "ASC", $Start = -1, $Num = -1)
	{
		global $language;

		$query  =
							"
								Select q.FAQID, q.Question, q.Answer, q.PublishedDate, q.DisplayOrder, r.VersionNumber ProductRelease
								From product_faq q
								Left Join product_update r On q.ReleaseID = r.ReleaseID
								Where q.Deleted = 0 And q.Enabled = 1 And q.Language = '$language' And q.ProductID = $this->ProductID ";

		// Keyword ----------------------------------------------------------------
		if($Criteria['Keyword'] != '')
		{
			$query .= "And ( ";
			$query .= "(Question Like '%" . $Criteria['Keyword'] . "%') OR ";
			$query .= "(Answer Like '%" . $Criteria['Keyword'] . "%') ";
			$query .= ") ";
		}
		// ReleaseID --------------------------------------------------------------
		if( ($Criteria['ReleaseID'] != '') && ($Criteria['ReleaseID'] != -1) )  {
			$query .= "And (q.ReleaseID = '" . $Criteria['ReleaseID'] . "') ";
		}

		// 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;
	}
}
?>