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

// Class Definition
class newsletter
{
	var $NewsletterID;		// Auto increment (Primary Key)
	var $Title;						// Newsletter Title
	var $FileName;				// Newsletter PDF Document Filename
	var $DataEntryDate;		// Newsletter Published Date

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

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

    // Set class data members
    $this->Title 		= $row->Title;
    $this->FileName = $row->FileName;
    $this->DataEntryDate = $row->DataEntryDate;
  }

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

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

	/*
   * Retrieves a list of newsletters
   */
	function getList($SortField = "DataEntryDate", $SortType = "DESC", $Start = -1, $Num = -1)
	{
		global $language;

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

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