<?php
include_once("config.php"); 
   class Datas {
      
		var $prd_post = array();
		var $photo = array();
		var $tablename;
		var $data_id;
		var $fields;
	    var $vals;
		var $field_id;
		var $event_id;
		var $update_id;
		var $add_date;
		var $upd_date;
		var $event_content;
		var $event_name;
		var $event_status;
		var $temp_desc;
		var $event_day;
		var $event_mon;
		var $event_year;
		var $event_stat;
		var $rlimit;
		var $qry;
		var $obj;
		var $obj_dat;
		var $evt_content;
		var $title;
		var $stat;
		var $msg;
		var $event_category;
		var $category;
		var $blk;
		var $topic_search;
		var $topic_category;
		var $conditions;
		var $order; 
		var $start;
		var $items;
		var $sel_field;
		var $sel_obj;
		var $sql;
		var $sel_qry;
		var $ord;
		var $news_title;
		var $name;
		var $news_description;
		var $news_updatedates;
		var $news_adddates;
		
		var $preview_title;
		var $preview_description;
		var $preview_content;
		var $preview_updatedates;
		var $preview_adddates;
		
		var $reviews_title;
		var $reviews_description;
		var $reviews_content;
		var $reviews_updatedates;
		var $reviews_adddates;
		
		var $db_stat;
		var $stat_id;
		var $field_stat;
		var $stat_qry;
		var $value='';
		var $fn;
		var $passurlvalue;
		var $tab2;
		var $f_stat;
		var $f_id;
		
#-----------------------------------------------------	
	function gettabcount($table)
	{	
		$this->tablename=$table;
		$sql = "select * from ".$this->tablename;
		//echo $sql; exit;
		$result = mysql_query($sql);			
		$this->rowCount = mysql_num_rows($result);	
		return $this->rowCount;
		//exit;
	}
	function getvalues($table)
	{	
		$this->tablename=$table;
		$sql = "select * from ".$this->tablename;
		//echo $sql; exit;
		$result = mysql_query($sql);	
				
		
		return $result;
		//exit;
	}
	function getvalues_nam($table,$type)
	{	
		$this->tablename=$table;
		$sql = "select * from ".$this->tablename." where type='".$type."'";
		//echo $sql; exit;
		$result = mysql_query($sql);	
				
		if($result)
		return $result;
		else
		return 0;
		//exit;
	}
	function gettabcount_condition($table,$conditions)
	{	
		        $this->conditions=$conditions;
			    $this->tablename=$table;
				$this->totalrows=0;
				$sql="select * from ".$this->tablename.$conditions;
				$trs=mysql_query($sql);
				if($trs){
				$this->totalrows = mysql_num_rows($trs);
				}
				return($this->totalrows);
	}
	

	function saveData($table,$fields,$vals)
	{
		 
		 
		 $this->tablename=$table;
		 $this->fields=$fields;
		 $this->vals=$vals;
		 $sql= "insert into ".$this->tablename."(".$fields.") values(".$vals.")";
		
		//print $sql;exit;
		mysql_query($sql)or die(mysql_error());
		$this->data_id = mysql_insert_id();
	}
	
	 function updateData($table,$vals,$id,$field_id)
	{
	
		$this->tablename=$table;
		$this->field_id=$field_id;
		$this->data_id=$id;
		$this->vals=$vals;
		$sql = "update ".$this->tablename." set ".$this->vals." where ".$this->field_id."='".$this->data_id."'";
		//echo $sql;
		//exit;
		mysql_query($sql)or die(mysql_error());
		//$this->sql=$sql;
		//return $this->sql;
	}
	
	function saveDatacategory($table,$fields,$vals)
	{
		 
		 
		 $this->tablename=$table;
		 $this->fields=$fields;
		 $this->vals=$vals;
		 
		 $sql= mysql_query("insert into ".$this->tablename."(".$fields.") values(".$vals.")");
		
		//print $sql;exit;
		if($sql){
		return $sql;
		}else{
		return 0;
		}
	}
	
	 function updateDatacategory($table,$vals,$id,$field_id)
	{
	
		$this->tablename=$table;
		$this->field_id=$field_id;
		$this->data_id=$id;
		$this->vals=$vals;
		$sql = mysql_query("update ".$this->tablename." set ".$this->vals." where ".$this->field_id."='".$this->data_id."'");
		if($sql){
		return $sql;
		}else{
		return 0;
		}
	}
	
	
		
	
		function removeData($table,$id,$field_id)
		{
			$this->field_id=$field_id;
		    $this->data_id=$id;
			$this->tablename=$table;
			//----------------------------------------------------------------------------------//
			$sq="delete from ".$this->tablename." where ".$this->field_id."='".$this->data_id."'";
			//echo $sq;
			//exit;
			mysql_query($sq);
		}
		function removeData_cat($table,$id,$field_id)
		{
			$this->field_id=$field_id;
		    $this->data_id=$id;
			$this->tablename=$table;
			//------------------------------------------------------------------------------------//
			if($this->fgl_id!=''){
			$sq="delete from ".$this->tab3." where ".$this->fgal_id."='".$this->fgl_id."'";
			mysql_query($sq);
			}
			//----------------------------------------------------------------------------------//
			$sq="delete from ".$this->tab2." where ".$this->f_id."='".$this->data_id."'";
			mysql_query($sq);
			//----------------------------------------------------------------------------------//
			$sq="delete from ".$this->tablename." where ".$this->field_id."='".$this->data_id."'";
			mysql_query($sq);
		}
function getData_org()
		{
			
			
			$sql="select * from  ".$this->tablename.$this->condition;
			//echo $sql;
			$rs = mysql_query($sql);
			$obj=mysql_fetch_object($rs);
			$this->obj=$obj;
			return $this->obj;

		}
function getData_orgcat()
		{
			
			
		    $sql="select * from  ".$this->tablename.$this->condition;
			//echo $sql;
			$rs = mysql_query($sql);
			return $rs;

		}
	  function getData_orgdat()
		{
			
			
		$sql="select * from  ".$this->tablename.$this->condition;
			$rs = mysql_query($sql);
			return $rs;

		}
		
		function getData($table,$id,$field_id)
		{
			$this->field_id=$field_id;
		    $this->data_id=$id;
			$this->tablename=$table;
			
			$sql="select * from  ".$this->tablename." where ".$this->field_id."='".$this->data_id."'";
			//echo $sql;
			$rs = mysql_query($sql);
			$obj=mysql_fetch_object($rs);
			$this->obj=$obj;
			return $this->obj;

		}

		

		function getRowcount()
		{	
			$sql = "select * from kerz_events where event_id='{$this->event_id}' and event_status='1' order by event_id desc";
			$result = mysql_query($sql);			
			$this->rowCount = mysql_num_rows($result);	
		}
		
		
		function getDataListings($table,$status,$order,$start,$items)
		{
			
				$sql="select * from ".$table." order by ".$order." desc limit ".$start.",".$items;
				$trs=mysql_query($sql);
				$this->totalrows = mysql_num_rows($trs);
				$limit="";
				if($this->rlimit>0)
				{
				$limit=" limit $this->start,$this->rlimit";
				}
				$sql .= $limit;
				//echo $sql;
				$rs=mysql_query($sql);
				return $rs;
		}
		
	function getDataListings_active($table,$status,$order,$start,$items)
		{
			
				$sql="select * from ".$table." where  ".$status." = 1 order by ".$order." desc limit ".$start.",".$items;
				$trs=mysql_query($sql);
				$this->totalrows = mysql_num_rows($trs);
				$limit="";
				if($this->rlimit>0)
				{
				$limit=" limit $this->start,$this->rlimit";
				}
				$sql .= $limit;
				//echo $sql;
				$rs=mysql_query($sql);
				return $rs;
		}	
		
		function getDataListings_condition($table,$status,$order,$start,$items,$conditions)
		{
				$this->order=$order;
		        $this->conditions=$conditions;
			    $this->tablename=$table;
				$this->start=$start;
				
				$this->items=$items;
				$sql="select * from ".$this->tablename.$conditions.$order." limit ".$this->start.",".$this->items;
				$trs=mysql_query($sql);
				if($trs)
				$this->totalrows = mysql_num_rows($trs);
				$limit="";
				if($this->rlimit>0)
				{
				$limit=" limit $this->start,$this->rlimit";
				}
				$sql .= $limit;
				//echo $sql;
				
				$rs=mysql_query($sql);
				/*if(mysql_num_rows($rs) == 0)
				{    
					$this->start=$start - $items;
					$sql="select * from ".$this->tablename.$conditions.$order." limit ".$this->start.",".$this->items;
					$trs=mysql_query($sql);
					$this->totalrows = mysql_num_rows($trs);
					$limit="";
					if($this->rlimit>0)
					{
					$limit=" limit $this->start,$this->rlimit";
					}
					$sql .= $limit;
					$rs=mysql_query($sql);
				}*/
				
				return $rs;
		}
		function select_query($table,$fields){
		
			    $this->tablename=$table;
				$this->fields=$fields;
				$sql="select distinct(".$this->fields.") from ".$this->tablename;
				$trs=mysql_query($sql);
				return $trs;
		}
		function changeStat($table,$id,$field_id,$field_stat)
		{
		
			$this->tablename=$table;
			$this->field_id=$field_id;
			$this->field_stat=$field_stat;
			$this->data_id=$id;
			//-------------------------------------------//
			$this->stat_qry=mysql_query("select event_status from kerz_events where event_id='".$this->data_id."'");
			$value=mysql_fetch_object($this->stat_qry);
			if($value->event_status==0)
			$this->vals=1;
			if($value->event_status==1)
			$this->vals=0;
			//-------------------------------------------------------------//
			$sql = "update ".$this->tablename." set event_status='".$this->vals."' where ".$this->field_id."='".$this->data_id."'";
			
			mysql_query($sql)or die(mysql_error());
			//$this->sql=$sql;
			//return $this->sql;
		}
		
		function changeStatus_com($table,$id,$field_id,$field_stat)
		{
		
			$this->tablename=$table;
			$this->field_id=$field_id;
			$this->field_stat=$field_stat;
			$this->data_id=$id;
			//-------------------------------------------//
			$this->stat_qry=mysql_query("select ".$this->field_stat." from ".$table." where ".$field_id."='".$this->data_id."'");
			$value=mysql_fetch_object($this->stat_qry);
			return $value;
		}
		function changeStatus_field()
		{
			$sql = "update ".$this->tablename." set ".$this->field_stat."='".$this->vals."' where ".$this->field_id."='".$this->data_id."'";
			
			mysql_query($sql)or die(mysql_error());
			}
		function changeStat_gallery($table,$id,$field_id,$field_stat)
		{
		
			$this->tablename=$table;
			$this->field_id=$field_id;
			$this->field_stat=$field_stat;
			$this->data_id=$id;
			//-------------------------------------------//
			$this->stat_qry=mysql_query("select ".$this->field_stat." from ".$this->tablename." where ".$this->field_id."=".$this->data_id."");
			$value=mysql_fetch_object($this->stat_qry);
			if($value->video_status==0)
			$this->vals=1;
			if($value->video_status==1)
			$this->vals=0;
			//-------------------------------------------------------------//
			 $sql = "update ".$this->tablename." set ".$this->field_stat."='".$this->vals."' where ".$this->field_id."='".$this->data_id."'";
			mysql_query($sql)or die(mysql_error());
			 $sql = "update ".$this->tab2." set ".$this->f_stat."='".$this->vals."' where ".$this->f_id."='".$this->data_id."'";
			mysql_query($sql)or die(mysql_error());
			//$this->sql=$sql;
			//return $this->sql;
		}
		function changeStat_gallery_gal($table,$id,$field_id,$field_stat)
		{
		
			$this->tablename=$table;
			$this->field_id=$field_id;
			$this->field_stat=$field_stat;
			$this->data_id=$id;
			//-------------------------------------------//
			$this->stat_qry=mysql_query("select ".$this->field_stat." from ".$this->tablename." where ".$this->field_id."=".$this->data_id."");
			$value=mysql_fetch_object($this->stat_qry);
			if($value->gallery_status==0)
			$this->vals=1;
			if($value->gallery_status==1)
			$this->vals=0;
			//-------------------------------------------------------------//
			 $sql = "update ".$this->tablename." set ".$this->field_stat."='".$this->vals."' where ".$this->field_id."='".$this->data_id."'";
			mysql_query($sql)or die(mysql_error());
			//$this->sql=$sql;
			//return $this->sql;
		}
		
		
		function changeStat_video($table,$id,$field_id,$field_stat)
		{
		
			$this->tablename=$table;
			$this->field_id=$field_id;
			$this->field_stat=$field_stat;
			$this->data_id=$id;
			//-------------------------------------------//
			$this->stat_qry=mysql_query("select video_status from kerz_video where id='".$this->data_id."'");
			$value=mysql_fetch_object($this->stat_qry);
			if($value->video_status==0)
			$this->vals=1;
			if($value->video_status==1)
			$this->vals=0;
			//-------------------------------------------------------------//
			$sql = "update ".$this->tablename." set video_status='".$this->vals."' where ".$this->field_id."='".$this->data_id."'";
			mysql_query($sql)or die(mysql_error());
			//$this->sql=$sql;
			//return $this->sql;
		}
		
		
		
		function changeStat_profile($table,$id,$field_id,$field_stat)
		{
		
			$this->tablename=$table;
			$this->field_id=$field_id;
			$this->field_stat=$field_stat;
			$this->data_id=$id;
			//-------------------------------------------//
			$this->stat_qry=mysql_query("select profile_status from kerz_profile where profile_id='".$this->data_id."'");
			$value=mysql_fetch_object($this->stat_qry);
			if($value->profile_status==0)
			$this->vals=1;
			if($value->profile_status==1)
			$this->vals=0;
			//-------------------------------------------------------------//
			$sql = "update ".$this->tablename." set profile_status='".$this->vals."' where ".$this->field_id."='".$this->data_id."'";
			mysql_query($sql)or die(mysql_error());
			//$this->sql=$sql;
			//return $this->sql;
		}
		
		
		function changeStat_review($table,$id,$field_id,$field_stat)
		{
		
			$this->tablename=$table;
			$this->field_id=$field_id;
			$this->field_stat=$field_stat;
			$this->data_id=$id;
			//-------------------------------------------//
			$this->stat_qry=mysql_query("select review_status from kerz_reviews where review_id 	='".$this->data_id."'");
			$value=mysql_fetch_object($this->stat_qry);
			if($value->review_status==0)
			$this->vals=1;
			if($value->review_status==1)
			$this->vals=0;
			//-------------------------------------------------------------//
			$sql = "update ".$this->tablename." set review_status='".$this->vals."' where ".$this->field_id."='".$this->data_id."'";
			mysql_query($sql)or die(mysql_error());
			//$this->sql=$sql;
			//return $this->sql;
		}
		
		function changeStat_news($table,$id,$field_id,$field_stat)
		{
		
			$this->tablename=$table;
			$this->field_id=$field_id;
			$this->field_stat=$field_stat;
			$this->data_id=$id;
			//-------------------------------------------//
			$this->stat_qry=mysql_query("select news_status  from kerz_news where news_id  	='".$this->data_id."'");
			$value=mysql_fetch_object($this->stat_qry);
			if($value->news_status==0)
			$this->vals=1;
			if($value->news_statusc==1)
			$this->vals=0;
			//-------------------------------------------------------------//
			$sql = "update ".$this->tablename." set news_status ='".$this->vals."' where ".$this->field_id."='".$this->data_id."'";
			mysql_query($sql)or die(mysql_error());
			//$this->sql=$sql;
			//return $this->sql;
		}
		function changeStat_newfaces($table,$id,$field_id,$field_stat)
		{
		
			$this->tablename=$table;
			$this->field_id=$field_id;
			$this->field_stat=$field_stat;
			$this->data_id=$id;
			//-------------------------------------------//
			$this->stat_qry=mysql_query("select newfaces_status  from kerz_newfaces where newfaces_id  	='".$id."'");
			$value=mysql_fetch_object($this->stat_qry);
			if($value->newfaces_status==0)
			  $this->vals=1;
			if($value->newfaces_status==1)
			$this->vals=0;
			
			//echo "this val = " .  $this->vals;
			//-------------------------------------------------------------//
			$sql = "update ".$this->tablename." set newfaces_status ='".$this->vals."' where ".$this->field_id."='".$this->data_id."'";
			mysql_query($sql)or die(mysql_error());
		
			//$this->sql=$sql;
			//return $this->sql;
		}
		function changeStat_preview($table,$id,$field_id,$field_stat)
		{
		
			$this->tablename=$table;
			$this->field_id=$field_id;
			$this->field_stat=$field_stat;
			$this->data_id=$id;
			//-------------------------------------------//
			$this->stat_qry=mysql_query("select preview_status  from kerz_previews where preview_id ='".$this->data_id."'");
			$value=mysql_fetch_object($this->stat_qry);
			if($value->preview_status==0)
			$this->vals=1;
			if($value->preview_status==1)
			$this->vals=0;
			//-------------------------------------------------------------//
			$sql = "update ".$this->tablename." set preview_status ='".$this->vals."' where ".$this->field_id."='".$this->data_id."'";
			mysql_query($sql)or die(mysql_error());
			//$this->sql=$sql;
			//return $this->sql;
		}
		
		
		
		function changeStat_newreleases($table,$id,$field_id,$field_stat)
		{
		
			$this->tablename=$table;
			$this->field_id=$field_id;
			$this->field_stat=$field_stat;
			$this->data_id=$id;
			//-------------------------------------------//
			$this->stat_qry=mysql_query("select article_status from kerz_articles where article_id='".$id."'");
			$value=mysql_fetch_object($this->stat_qry);
			if($value->article_status==0)
			  $this->vals=1;
			if($value->article_status==1)
			$this->vals=0;
			
			//echo "this val = " .  $this->vals;
			//-------------------------------------------------------------//
			$sql = "update ".$this->tablename." set article_status ='".$this->vals."' where ".$this->field_id."='".$this->data_id."'";
			mysql_query($sql)or die(mysql_error());
		
			//$this->sql=$sql;
			//return $this->sql;
		}
		function changeStat_behindtheframe($table,$id,$field_id,$field_stat)
		{
		
			$this->tablename=$table;
			$this->field_id=$field_id;
			$this->field_stat=$field_stat;
			$this->data_id=$id;
			//-------------------------------------------//
			$this->stat_qry=mysql_query("select behindtheframe_status from kerz_behindtheframe where behindtheframe_id='".$id."'");
			$value=mysql_fetch_object($this->stat_qry);
			if($value->behindtheframe_status==0)
			  $this->vals=1;
			if($value->behindtheframe_status==1)
			$this->vals=0;
			
			//echo "this val = " .  $this->vals;
			//-------------------------------------------------------------//
			$sql = "update ".$this->tablename." set behindtheframe_status ='".$this->vals."' where ".$this->field_id."='".$this->data_id."'";
			mysql_query($sql)or die(mysql_error());
		
			//$this->sql=$sql;
			//return $this->sql;
		}
		
   }
   function redirect($page) {

  if(headers_sent()) {

    echo "<script language=\"Javascript\">window.location.href='$page';</script>";

    exit;

  } else {

    //header("Location:$page");
	echo "<script>location.href='$page'</script>";
	exit;
  }

}
?>