<?php
class Managememnt{
	
	public function Get_Data($Table_Name, $Sort_Col)
	{
		if($Sort_Col != '')
		{
			$Query	=	"Select * from $Table_Name ORDER BY `$Sort_Col` ASC";
		}else{
			$Query	=	"Select * from $Table_Name";
		}
		$Exe_Query	=	mysql_query($Query);
		if(mysql_query($Query))
		{
			return $Exe_Query;
		}else return false;
	}
	

		
	public function Insert_Data($Arr)
	{
		extract($Arr);
		$SQL	=	"INSERT INTO `portfolio` (`name`, `description`) 
					 VALUES ('$port_name', '$desc')";
		
		if(mysql_query($SQL))
			return true;
		else
			return false;
	}
	
	public function Get_Data_Admin($Admin_ID)
	{
		$SQL	=	"SELECT * FROM `portfolio` where id  = '$Admin_ID'";
		if(mysql_query($SQL))
		{
			$Exe_Query	=	mysql_query($SQL);
			return $Exe_Query;
		}else{
			return "Error: " . mysql_error($SQL);
		}

	}
	
	public function Update_Data($Arr, $Rec_ID)
	{
		extract($Arr);
		$SQL	=	"UPDATE `portfolio` SET `name` = '$port_name', `description` = '$desc' WHERE `id` = '$Rec_ID'";
		
		if(mysql_query($SQL))
		{
			return true;
		}else{
			return "Error:" . mysql_error($SQL); 
		}		
	}
	
	public function Delete_Admin_Rec($Table_Name, $Primary_Col, $Admin_ID)
	{
		$SQL	=	"DELETE FROM `$Table_Name` WHERE `$Primary_Col` = '$Admin_ID'";
		if(mysql_query($SQL))
		{
			return true;
		}else{
			return "Error:".mysql_error($SQL);
		}
	}
	
	public function Insert_Data_Content($Arr)
	{
		 	 	 	 	 	 	 	 		
		extract($Arr);
//	echo "===========".$Parent_Select."+============<br />";
		$Sort_Order = $this->Sort_ID_Parent($Parent_Select);
//		echo $Sort_Order;
//		exit;
		$SQL	=	"INSERT INTO `CMS_Pages` 
					(`parent_id`, `page_name`, `keywords`, `meta_desc`, `page_heading`, `txtbody`, `type`, `sort_order`, `status`) 
					 VALUES ('$Parent_Select', '$Page_Title', '$Key_Words', '$Meta_Desc', '$Page_Heading', '$Content_Data', '$Page_Type', '$Sort_Order', '$Page_Status')";
		
//		echo $SQL;
//		exit;
		if(mysql_query($SQL))
			return true;
		else
			return false;
	}
	
	public function Sort_ID_Parent($parent_id)
	{
		if($parent_id	==	"")
		{
			$Sql	=	"Select max(`sort_order`) as sort from  `CMS_Pages` where `parent_id` = '0'";
			$Exr_query	=	mysql_query($Sql);
		}else{
			$Sql	=	"Select max(`sort_order`) as sort from  `CMS_Pages` where `parent_id` = '$parent_id'";
			$Exr_query	=	mysql_query($Sql);			
		}
			$row	=	mysql_fetch_array($Exr_query);
			$Sorted_ID	=	$row['sort'] + 1 ;
			return  $Sorted_ID;	
	}	
	
	public function Get_Data_All($Table_Name, $Field_Name, $Admin_ID)
	{
		$SQL	=	"SELECT * FROM `$Table_Name` where $Field_Name = '$Admin_ID'";
		if(mysql_query($SQL))
		{
			$Exe_Query	=	mysql_query($SQL);
			return $Exe_Query;
		}else{
			return false;
		}
			
	}
	
	public function Content_Update($Arr, $Rec_ID, $parent_id)
	{
		extract($Arr);


		if($parent_id == $Parent_Select)
		{
			$SQL	=	"UPDATE `CMS_Pages` SET `parent_id` = '$Parent_Select', `page_name` = '$Page_Title', `keywords` = '$Key_Words', `meta_desc` = '$Meta_Desc', `page_heading` =  '$Page_Heading', `txtbody` = '$Content_Data', `type` = '$Page_Type' , `status` =  '$Page_Status' WHERE `page_id` = '$Rec_ID'";								 		
		}else if(($parent_id == "0") && ($Parent_Select == "") ){
			$SQL	=	"UPDATE `CMS_Pages` SET `parent_id` = '$Parent_Select', `page_name` = '$Page_Title', `keywords` = '$Key_Words', `meta_desc` = '$Meta_Desc', `page_heading` =  '$Page_Heading', `txtbody` = '$Content_Data', `type` = '$Page_Type' , `status` =  '$Page_Status' WHERE `page_id` = '$Rec_ID'";								 					
		}else{
		$Sort_Order = $this->Sort_ID_Parent($Parent_Select);
		$SQL	=	"UPDATE `CMS_Pages` SET `parent_id` = '$Parent_Select', `page_name` = '$Page_Title', `keywords` = '$Key_Words', `meta_desc` = '$Meta_Desc', `page_heading` =  '$Page_Heading', `txtbody` = '$Content_Data', `type` = '$Page_Type' , `sort_order` = '$Sort_Order', `status` =  '$Page_Status' WHERE `page_id` = '$Rec_ID'";	
		}
				
		if(mysql_query($SQL))
		{
			return true;
		}else{
			return "Error:" . mysql_error($SQL); 
		}	
		
	}
	
	public function Enable($val)
	{
		if($val == '1')
		return "Enable";
		else return "Disable";	
	}
}
?>