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

// Class Definition
class news
{
	var $NewsID;					// Auto increment (Primary Key)
	var $Title;						// News Title
	var $Description;			// News Description
	var $PictureName;			// News Picture
	var $NewsDate;				// News Date (text)
	var $URL;							// URL of the news either to external links or internal ones
	var $Target='_blank';	// Used to specify the target of the URL if external (_blank) or internal (_self)
	var $NewsTypeID;			// News Type (1 = Event / 2 = IT Security News)

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

	/*
	 * Retrieves news information
	 */
	function getInfo()
	{
		$query = "
							Select * From news
					 	  Where NewsID = $this->NewsID
					 	 ";
		// echo $query;
		$result = mysql_query($query);
		$row = mysql_fetch_object($result);

    // Set class data members
    $this->Title 				= $row->Title;
    $this->Description 	= $row->Description;
    $this->PictureName 	= $row->PictureName;
    $this->NewsDate 		= $row->NewsDate;
    $this->URL 					= $row->URL;
    $this->Target 			= $row->Target;
    $this->NewsTypeID 	= $row->NewsTypeID;
  }

	/*
   * Retrieves the count of Events (NewsTypeID = 1) or IT Security News (NewsTypeID = 2)
   */
	function getTotal($NewsTypeID = 1)
	{
		global $language;

		$query =
						"
							Select COUNT(*) From news
							Where Enabled = 1 And Deleted = 0 And Language = '$language' And NewsTypeID = $NewsTypeID
						";
	  // echo $query;
   	$result = mysql_result(mysql_query($query), 0, 0);
    return $result;
	}

	/*
   * Retrieves a list of Events (NewsTypeID = 1) or IT Security News (NewsTypeID = 2)
   */
	function getList($NewsTypeID = 1, $SortField = "NewsID", $SortType = "DESC", $Start = -1, $Num = -1)
	{
		global $language;

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

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

}
?>
