<?php
$conct  = new connectionCreat();
$conct->connectToDB();
$conct->selectDB();
function product($id) 
{
	$sql	= mysql_query(" SELECT `name` FROM `tbl_product` where `id`='$id' ")or die(mysql_error());
	$data	= mysql_fetch_array($sql);
	return $data['name'];
}
function product_code($id) 
{
	$sql	= mysql_query(" SELECT `p_code` FROM `tbl_product` where `id`='$id' ")or die(mysql_error());
	$data	= mysql_fetch_array($sql);
	return $data['p_code'];
}
function client($id) 
{
	$sql	= mysql_query(" SELECT `name` FROM `tbl_clients` where `id`='$id' ")or die(mysql_error());
	$data	= mysql_fetch_array($sql);
	return $data['name'];
}
function state($id) 
{
	$sql	= mysql_query(" SELECT `state_name` FROM `state` where `id`='$id' ")or die(mysql_error());
	$data	= mysql_fetch_array($sql);
	return $data['state_name'];
}
function state_id($id) 
{
	$sql	= mysql_query(" SELECT `id` FROM `state` where `state_name`='$id' ")or die(mysql_error());
	$data	= mysql_fetch_array($sql);
	return $data['id'];
}
function town_name($id) 
{
	$sql	= mysql_query(" SELECT `town_name` FROM `tbl_town` where `id`='$id' ")or die(mysql_error());
	$data	= mysql_fetch_array($sql);
	return $data['town_name'];
}
function distributor_name($id) 
{
	$sql	= mysql_query(" SELECT `name` FROM `tbl_distributor` where `id`='$id' ")or die(mysql_error());
	$data	= mysql_fetch_array($sql);
	return $data['name'];
}
function encryptIt( $q ) 
{
    $cryptKey  = 'QxLUF1bgIAdeQYZ';
    $qEncoded      = base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), $q, MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ) );
    return( $qEncoded );
}

function decryptIt( $q ) {
    $cryptKey  = 'QxLUF1bgIAdeQYZ';
    $qDecoded      = rtrim( mcrypt_decrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), base64_decode( $q ), MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ), "\0");
    return( $qDecoded );
}
class actionDo
{
	//function user login admin
	function login($username,$password,$ipaddress)
	{
	    $password      = encryptIt($password);
		$login_user1    = mysql_query("Select * From `tbl_admin` where `username` = '$username' ");
        $show_user1     = mysql_fetch_array($login_user1);
		if(mysql_num_rows($login_user1) > 0)
		{
			
			$login_user = mysql_query("Select * From `tbl_admin` where `username` = '$username' and `password`='$password'");
            $show_user  = mysql_fetch_array($login_user);
    		if(mysql_num_rows($login_user) > 0)
    		{
    			
    			$_SESSION['post']      =      $show_user['post'];
    			$_SESSION['userid']    =      $show_user['id'];
    			$_SESSION['name']      =      $show_user['name'];
    			$_SESSION['userid']    =      $show_user['id'];
    			$_SESSION['consult']   =      $show_user['consult_porson'];
    			$ipaddress             =      $_SERVER["REMOTE_ADDR"];
    			$sql_update            =      mysql_query("UPDATE `tbl_admin` SET `last_visit`=NOW(),`ip`='$ipaddress' WHERE username='$username' AND password='$password'")or die(mysql_error());
    			$sql                   =      mysql_query("insert into `user_login_detail` SET `ip`='$ipaddress', `uid`= '".$_SESSION['userid']."', `last_login`=NOW()")or die(mysql_error());
    			header('location:../home.php');
    			
    		}
    		else
    		{
    		  
    		  header("location:../index.php");
    			
    		}
			
		}
		else
		{
		  
		  header("location:../index.php");
			
		}
	}
	//end function
	//Client Logo
	function client_logo($small_img,$logo_name,$home_image,$home_desc,$lux_lamp_image,$lux_lamp_content,$lux_title,$logo_title,$logo_alt,$web_keywords,$web_meta_desc)
	{
		if(!empty($small_img) && empty($home_image) && empty($lux_lamp_image))
		{
	      mysql_query("Update `client_logo` set `small_logo_image` = '$small_img',`website_title`='$logo_name',`home_desc`='$home_desc',`lux_lamp_content`='$lux_lamp_content',`lux_title`='$lux_title',`logo_title`='$logo_title',`logo_alt`='$logo_alt',`web_keywords`='$web_keywords',`web_meta_desc`='$web_meta_desc' where `id` = '1'") or die('Cannot add Logo' . mysql_error());
	      $_SESSION['client_msg'] = 'Logo Update Sucessfully!!';
		}
		
		else if(!empty($small_img) && !empty($home_image) && empty($lux_lamp_image))
		{
	      mysql_query("Update `client_logo` set `small_logo_image` = '$small_img',`home_image`='$home_image',`website_title`='$logo_name',`home_desc`='$home_desc',`lux_lamp_content`='$lux_lamp_content',`lux_title`='$lux_title',`logo_title`='$logo_title',`logo_alt`='$logo_alt',`web_keywords`='$web_keywords',`web_meta_desc`='$web_meta_desc' where `id` = '1'") or die('Cannot add Logo' . mysql_error());
	      $_SESSION['client_msg'] = 'Logo Update Sucessfully!!';
		}
		
		else if(!empty($small_img) && !empty($home_image) && !empty($lux_lamp_image))
		{
	      mysql_query("Update `client_logo` set `small_logo_image` = '$small_img',`home_image`='$home_image',`lux_lamp_image`='$lux_lamp_image',`website_title`='$logo_name',`home_desc`='$home_desc',`lux_lamp_content`='$lux_lamp_content',`lux_title`='$lux_title',`logo_title`='$logo_title',`logo_alt`='$logo_alt',`web_keywords`='$web_keywords',`web_meta_desc`='$web_meta_desc' where `id` = '1'") or die('Cannot add Logo' . mysql_error());
	      $_SESSION['client_msg'] = 'Logo Update Sucessfully!!';
		}
		
		else if(!empty($small_img) && empty($home_image) && !empty($lux_lamp_image))
		{
	      mysql_query("Update `client_logo` set `website_title`='$logo_name',`lux_lamp_image`='$lux_lamp_image',`home_desc`='$home_desc',`lux_lamp_content`='$lux_lamp_content',`lux_title`='$lux_title',`logo_title`='$logo_title',`logo_alt`='$logo_alt',`web_keywords`='$web_keywords',`web_meta_desc`='$web_meta_desc' where `id` = '1'") or die('Cannot add Logo' . mysql_error());
	      $_SESSION['client_msg'] = 'Logo Update Sucessfully!!';
		}
		
		else if(empty($small_img) && !empty($home_image) && !empty($lux_lamp_image))
		{
	      mysql_query("Update `client_logo` set `website_title`='$logo_name',`home_image`='$home_image',`lux_lamp_image`='$lux_lamp_image',`home_desc`='$home_desc',`lux_lamp_content`='$lux_lamp_content',`lux_title`='$lux_title',`logo_title`='$logo_title',`logo_alt`='$logo_alt',`web_keywords`='$web_keywords',`web_meta_desc`='$web_meta_desc' where `id` = '1'") or die('Cannot add Logo' . mysql_error());
	      $_SESSION['client_msg'] = 'Logo Update Sucessfully!!';
		}
		
		else if(empty($small_img) && !empty($home_image) && empty($lux_lamp_image))
		{
	      mysql_query("Update `client_logo` set `website_title`='$logo_name',`home_image`='$home_image',`home_desc`='$home_desc',`lux_lamp_content`='$lux_lamp_content',`lux_title`='$lux_title',`logo_title`='$logo_title',`logo_alt`='$logo_alt',`web_keywords`='$web_keywords',`web_meta_desc`='$web_meta_desc' where `id` = '1'") or die('Cannot add Logo' . mysql_error());
	      $_SESSION['client_msg'] = 'Logo Update Sucessfully!!';
		}
		
		else if(empty($small_img) && empty($home_image) && !empty($lux_lamp_image))
		{
	      mysql_query("Update `client_logo` set `website_title`='$logo_name',`lux_lamp_image`='$lux_lamp_image',`home_desc`='$home_desc',`lux_lamp_content`='$lux_lamp_content',`lux_title`='$lux_title',`logo_title`='$logo_title',`logo_alt`='$logo_alt',`web_keywords`='$web_keywords',`web_meta_desc`='$web_meta_desc' where `id` = '1'") or die('Cannot add Logo' . mysql_error());
	      $_SESSION['client_msg'] = 'Logo Update Sucessfully!!';
		}
			
		else
		{
			 mysql_query("Update `client_logo` set `website_title`='$logo_name',`home_desc`='$home_desc',`lux_lamp_content`='$lux_lamp_content',`lux_title`='$lux_title',`logo_title`='$logo_title',`logo_alt`='$logo_alt',`web_keywords`='$web_keywords',`web_meta_desc`='$web_meta_desc' where `id` = '1'") or die('Cannot add Logo' . mysql_error());
			 $_SESSION['client_msg'] = 'Logo Update Sucessfully!!';
		}		
	   header('location:home.php?page=home_setting');
	}
	function logo_modify()
	{
		//$logo_modify = 
		//return $logo_modify;
	}
	function show_client_logo()
	{
		$list_logo = mysql_query("Select * from `client_logo` order by id desc");
		return $list_logo;
	}
	//End CLient Logo
	 function category($name,$image)
	 {
		 $sql = mysql_query("select * from `tbl_category` where `name` = '$name'");
		 if(mysql_num_rows($sql)>0)
		 {
			 $_SESSION['msg1']   = 'Category Already Exist!!!!';
		 }
		 else
		 {
			 
		   $_SESSION['msg']   = 'Category Addes Sucessfully!!!!';	 
		    mysql_query("INSERT INTO `tbl_category` set `name` = '$name',`image`='$image'");
		 }
		 header("location:home.php?page=category");
		 
	 }
     function category_modify($name,$image,$id)
	 {
		 if($image == '')
		 {
			  $_SESSION['msg']   = 'Category Update Sucessfully!!!!';	 
			mysql_query("Update `tbl_category` set `name` = '$name' where `id`='$id'");

		 }
		 else
		 {
			 move_uploaded_file($_FILES['image']['tmp_name'],"cate_image/".$image);
			$_SESSION['msg']   = 'Category Update Sucessfully!!!!';	 
			mysql_query("Update `tbl_category` set `name` = '$name',`image`='$image' where `id`='$id'");
		 }
		header("location:home.php?page=category");
		
	 }
	 function list_category()
	 {
		$category = mysql_query("select * from `tbl_category` order by `name` asc");
		return  $category;
	 }
	 function modify_list($modify_id)
	 {
		$category1 = mysql_query("select * from `tbl_category` where `id`='$modify_id'");
		return  $category1; 
	 }
	function publish_category($publish_id,$value)
	{ 
		if($value == 'yes')
		{
		 
		  mysql_query("UPDATE `tbl_category` SET `publish`='0' WHERE `id`='$publish_id'");
		}
		else
		{
		
		  mysql_query("UPDATE `tbl_category` SET `publish`='1' WHERE `id`='$publish_id'"); 
		}
		header("location:home.php?page=category");
	}

	function delete_category($id)
	{
		$slider = mysql_query("select * from `tbl_category`  where `id`='$id'") or die(mysql_error());
		$row = mysql_fetch_array($slider);
		if(file_exists('cate_image/'.$row['image']))
		{
			mysql_query("DELETE FROM `tbl_category` where `id`='$id'") or die(mysql_error());
			$path = 'cate_image';
			$image_name = $row['image'];
		    unlink($path.'/'.$image_name);
		}
		header("location:home.php?page=category");
	}

	 
	// Add Menu
	function menu($pagename,$pagetitle,$details,$image)
	{
	   mysql_query("INSERT INTO `tbl_menu` set `image`='$image',`page_name`='$pagename',`content_information`='$details',`page_title`='$pagetitle'") or die(mysql_error());
	    $_SESSION['page_msg'] = 'Menu Added Sucessfully!!';
		header("location:home.php?page=page");
	}
	function list_menu()
	{
		$menu_list = mysql_query("SELECT * FROM `tbl_menu` order by `id` desc");
		return $menu_list;
	}
	function list_menu_header()
	{
		$menu_list = mysql_query("SELECT * FROM `tbl_menu` where `publish`='1' and header_show = '1' order by `id` asc");
		return $menu_list;
	}
	function list_menu_footer()
	{
		$menu_list = mysql_query("SELECT * FROM `tbl_menu` where `publish`='1' and footer_show = '1' order by `id` desc");
		return $menu_list;
	}
	function modify_menu($id)
	{
		$modify_menu = mysql_query("SELECT * FROM `tbl_menu` WHERE `id` = '$id'");
		return $modify_menu;
	}
	function menu_modify1($pagename,$pagetitle,$details,$image,$id)
	{
		if($image == '')
		{
		  mysql_query("update `tbl_menu` set `page_name`='$pagename',`content_information`='$details',`page_title`='$pagetitle' where `id`='$id'") or die(mysql_error());	
		}
		else
		{
		   move_uploaded_file($_FILES['image']['tmp_name'],'page_image/'.$image);
		   mysql_query("update `tbl_menu` set `page_name`='$pagename',`content_information`='$details',`page_title`='$pagetitle' where `id`='$id'") or die(mysql_error());
		}
		$_SESSION['page_msg'] = 'Menu Update Sucessfully!!';
		header("location:home.php?page=page");		
	}
	function publish_menu($publish_id,$value)
	{ 
		if($value == 'yes')
		{
		 
		  mysql_query("UPDATE `tbl_menu` SET `publish`='0' WHERE `id`='$publish_id'");
		}
		else
		{
		
		  mysql_query("UPDATE `tbl_menu` SET `publish`='1' WHERE `id`='$publish_id'"); 
		}
		header("location:home.php?page=page");
	}
	function delete_menu($id)
	{
		mysql_query("Delete From `tbl_menu` WHERE `id`='$id'");
	    $_SESSION['msg'] = 'Menu Delete Sucessfully!!';
		header("location:home.php?page=page");
	}
	function publish_header($header_id,$value)
	{
		if($value == 'yes1')
		{
		 
		  mysql_query("UPDATE `tbl_menu` SET `header_show`='0' WHERE `id`='$header_id'");
		}
		else
		{
		
		  mysql_query("UPDATE `tbl_menu` SET `header_show`='1' WHERE `id`='$header_id'"); 
		}
		header("location:home.php?page=page");
		
	}
	function publish_footer($footer_id,$value)
	{
		if($value == 'yes2')
		{
		 
		  mysql_query("UPDATE `tbl_menu` SET `footer_show`='0' WHERE `id`='$footer_id'");
		}
		else
		{
		
		  mysql_query("UPDATE `tbl_menu` SET `footer_show`='1' WHERE `id`='$footer_id'"); 
		}
		header("location:home.php?page=page");
		
	}
	//End Add Menu
	function sub_menu($maincontent_id,$subpage_name,$subpage_title,$subpage_information)
	{
		mysql_query("INSERT INTO `tbl_sub_pages` set `maincontent_id`='$maincontent_id',`subpage_name`='$subpage_name', `subpage_information`='$subpage_information',`subpage_title`='$subpage_title'")or die(mysql_error());
		$_SESSION['subpage_msg'] = 'Sub Menu Added Sucessfully!!';
		header("location:home.php?page=subpage");				    
	}
	function list_sub_menu()
	{
		$show_modify = mysql_query("Select * from `tbl_sub_pages` order by `id` desc") or die(mysql_error());
	    return $show_modify;
	}
	function modifyshow_sub_menu($id)
	{
		$show_modify = mysql_query("Select * from `tbl_sub_pages` where `id`='$id'") or die(mysql_error());
	    return $show_modify;
	}
	function publish_subpage($publish_id,$value)
	{
		if($value == 'yes')
		{
		 
		  mysql_query("UPDATE `tbl_sub_pages` SET `publish`='0' WHERE `id`='$publish_id'");
		}
		else
		{
		
		  mysql_query("UPDATE `tbl_sub_pages` SET `publish`='1' WHERE `id`='$publish_id'"); 
		}
		header("location:home.php?page=subpage");
		
	}
	function header_subpage($header_id,$value)
	{
		if($value == 'yes1')
		{
		 
		  mysql_query("UPDATE `tbl_sub_pages` SET `header_show`='0' WHERE `id`='$header_id'");
		}
		else
		{
		
		  mysql_query("UPDATE `tbl_sub_pages` SET `header_show`='1' WHERE `id`='$header_id'"); 
		}
		header("location:home.php?page=subpage");
		
	}
	function footer_subpage($footer_id,$value)
	{
		if($value == 'yes2')
		{
		 
		  mysql_query("UPDATE `tbl_sub_pages` SET `footer_show`='0' WHERE `id`='$footer_id'");
		}
		else
		{
		
		  mysql_query("UPDATE `tbl_sub_pages` SET `footer_show`='1' WHERE `id`='$footer_id'"); 
		}
		header("location:home.php?page=subpage");
	}
	function modify_sub_menu($maincontent_id,$subpage_name,$subpage_title,$subpage_information,$id)
	{ 
	   
		mysql_query("update `tbl_sub_pages` set `maincontent_id`='$maincontent_id', `subpage_name`='$subpage_name',`subpage_information`='$subpage_information',`subpage_title`='$subpage_title' where `id`='$id'") or die(mysql_error());   
	   
		$_SESSION['subpage_msg'] = 'Sub Menu Update Sucessfully!!';
		header("location:home.php?page=subpage");	
		
	}
	function delete_sub_menu($id)
	{
		mysql_query("Delete From `tbl_sub_pages` where `id`='$id'") or die(mysql_error());
	    $_SESSION['msg'] = 'Delete Sub Menu Added Sucessfully!!';
		header("location:home.php?page=subpage");
	}
	function check_submenu($menu_id)
	{
	  $show_sub_menu  =  mysql_query("Select * from `tbl_sub_pages` where `maincontent_id`='$menu_id' and `header_show`=1") or die(mysql_error());	
	  return $show_sub_menu;
	}
	//about us section

	
	//about us section
	
	function show_pages($menu_id)
	{
		$show_pages  = mysql_query("select * from `tbl_menu` where `id` = '$menu_id'");
		return $show_pages;
	}
	function show_sub_pages($sub_menu_id)
	{
		$show_sub_pages  = mysql_query("select * from `tbl_sub_pages` where `id` = '$sub_menu_id'");
		return $show_sub_pages;
	}
	//add folio
	function folio($img_name,$img,$description,$category)
	{
		
	   
	}
	function folio_list()
	{
		$folio_list = mysql_query("Select * from `tbl_folio` order by `id` desc");
		return $folio_list;
	}
	function show_folio($id)
	{
		$folio_modify = mysql_query("select * from `tbl_folio` where `id`='$id'");
		return $folio_modify;
	}
	function update_folio($img_name,$img,$description,$category,$id)
	{
		
	}
	function publish_folio($id,$status)
	{ 
		if($status == 'yes')
		{
		
		  mysql_query("UPDATE `tbl_folio` SET `publish`='0' WHERE id='$id'") or die(mysql_error());
		}
		else
		{
		  mysql_query("UPDATE `tbl_folio` SET `publish`='1' WHERE id='$id'") or die(mysql_error());	
		}
		header("location:home.php?page=add_folio");
	}
	function delete_folio($id)
	{
		$slider = mysql_query("select * from `tbl_folio` where `id`='$id'") or die(mysql_error());
		$row = mysql_fetch_array($slider);
		if(file_exists('sliderimage/'.$row['image']))
		{
			mysql_query("DELETE FROM `tbl_folio` where `id`='$id'") or die(mysql_error());
			$path = 'sliderimage';
			$image_name = $row['image'];
		    unlink($path.'/'.$image_name);
		}
	}
	//end folio
  function company_address($cname,$person,$num2,$email,$address)
	{
	 mysql_query("UPDATE `company_address` SET `company_name`='$cname',`person`='".mysql_real_escape_string($person)."',`mobile`='$num2',`email`='$email',`address`='$address' WHERE 1");
	 $_SESSION['msg'] = 'Comany Address Update Sucessfully!';
	 header('location:home.php?page=company_address');
		
	}
	function company_address_list()
	{
	 $company_address_list = mysql_query("Select * from `company_address` WHERE 1 ");
	 return $company_address_list;
	}
	function contact($name,$email,$subject,$message)
	{
		$currentdate = date('Y-m-d');
		mysql_query("INSERT INTO `contact_us` set `name`='$name', `email`='$email', `subject`='$subject', `message`='$message', `date`='$currentdate'");
	    $_SESSION['msg'] = 'Thank You! We Will Contact You Soon.';

	}
	function conatct_list()
	{
		$conatct_list = mysql_query('select * from contact_us order by date desc');
		return $conatct_list;
		
	}
	function delete_conatct_list($conatc_id)
	{
	  mysql_query("Delete from contact_us where `id`= '$conatc_id'");
		
	}
	
	
}

function email($to,$from,$subject,$txt1)
{	
	$headers = "From: " . strip_tags($from) . "\r\n";
	$headers .= "Reply-To: ". strip_tags($to) . "\r\n";
	$headers .= "MIME-Version: 1.0\r\n";
	$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";								
	mail($to,$subject,$txt1,$headers);		
}
?>