<?
include_once('baseModelPMS.php');

class newsModel extends baseModelPMS {


	/* ********************************************************************************
	Select list of news items
	******************************************************************************** */

	function getlist_news(){

		$listdata=array();

		$sql="Select * from news_details order by news_date DESC";
		$listdata=$this->getextendedrows($sql);
		return $listdata;
	}


	/* ********************************************************************************
	Select a specific news item
	******************************************************************************** */

	function getdata_news($newspkey){

		$data=array();

		$sql="Select * from news_details where news_pkey='".$newspkey."'";
		$data=$this->getextendedrow($sql);
		return $data;
	}


	/* FUNCTIONS TO INSERT RECORDS */


	/* ********************************************************************************
	Insert/Create a news item
	> 
	******************************************************************************** */

	function insertdata_news($news_pkey, $news_date, $news_time, $news_expirydate, $news_title, $news_text, $news_relatedurl) {

		// convert params..
		$news_pkey=md5(microtime());
		if ($news_date=="") { 
			$realdate=gettimestamp(); 
		} else { 
			if ($news_time!="") {
				$realdate=converttounixfull($news_date." ".$news_time.":00");
			} else {
				$realdate=converttounix($news_date); 
			}
		}
		$realexpiry = "";
		if ($news_expirydate!="") $realexpiry = converttounix($news_expirydate);

		// upload file (currently no caption or desc)..
		//$imagepkey = image_uploadimage($_FILES['news_picture']['name'],$_FILES['news_picture']['tmp_name'],"","");

		// update news..
		$sa = $this->add_data("News Item [Add]", "news_details", "news_pkey, news_date, news_expirydate, news_title, news_text, news_relatedurl",
				"'".$news_pkey."','".$realdate.
				"','".$realexpiry."','".$news_title.
				"','".$news_text."','".$news_relatedurl."'");

		// return result..
		if ($sa==1) {
			return $news_pkey;
		} else {
			return false;
		}
	}


	/* FUNCTIONS TO UPDATE RECORDS */


	/* ********************************************************************************
	Update/Override an existing news item
	> 
	******************************************************************************** */

	function updatedata_news($news_pkey, $news_date, $news_time, $news_expirydate, $news_title, $news_text, $news_relatedurl) {

		// convert params..
		if ($news_date=="") { 
			$realdate=gettimestamp(); 
		} else { 
			if ($news_time!="") {
				$realdate=converttounixfull($news_date." ".$news_time.":00");
			} else {
				$realdate=converttounix($news_date); 
			}
		}
		$realexpiry = "";
		if ($news_expirydate!="") $realexpiry = converttounix($news_expirydate);

		// upload file (currently no caption or desc)..
		//$imagepkey = image_uploadimage($_FILES['news_picture']['name'],$_FILES['news_picture']['tmp_name'],"","");

		$sa = $this->update_data("News Item [Edit]", "news_details", 
			"news_date = '".$realdate.
			"', news_expirydate = '".$realexpiry.
			"', news_title = '".$news_title.
			"', news_text = '".$news_text.
			"', news_relatedurl = '".$news_relatedurl."'",
			"where news_pkey = '".$news_pkey."'");

		// return result..
		if ($sa==1) {
			return $news_pkey;
		} else {
			return false;
		}
	}


	/* FUNCTIONS TO DELETE RECORDS */


	/* ********************************************************************************
	Delete an existing news item
	> 
	******************************************************************************** */

	function deletedata_news($news_pkey) {

		// delete news..
		$sa = $this->delete_data("News Item [Delete]", "news_details", "where news_pkey = '".$news_pkey."'");

		// return result..
		if ($sa==1) {
			return $news_pkey;
		} else {
			return false;
		}
	}

}
?>
