<?php 
session_start();
include('includes/php/dbconnection.php');
//////////////////////////delete category//////////////////////////////
if($_REQUEST['catid'])
{

 $delsql="delete from tbl_catogery where id=".$_REQUEST['catid'];
if(mysql_query($delsql))
{

$_SESSION['msg']= "Category Deleted Successfully";
	header("location:catogery.php");
	exit;
}

}
?>
<?php 
/////////////////////////////////////////////////delete platform//////////////////////

if($_REQUEST['platformid'])
{

 $delsql="delete from tbl_platform where id=".$_REQUEST['platformid'];
if(mysql_query($delsql))
{

$_SESSION['msg']= "Platform Deleted Successfully";
	header("location:platform.php");
	exit;
}

}
?>
<?php 
/////////////////////////////////////////////////delete product//////////////////////

if($_REQUEST['product'])
{

 $delsql="delete from products where pro_id=".$_REQUEST['product'];
if(mysql_query($delsql))
{
$delsqlcat="delete from protocat where pro_id=".$_REQUEST['product'];
mysql_query($delsqlcat);
$delsqlplt="delete from protoplatf where pro_id=".$_REQUEST['product'];
mysql_query($delsqlplt);
$_SESSION['msg']= "Product Deleted Successfully";
	header("location:products.php");
	exit;
}

}
?>
<?php 
/////////////////////////////////////////////////delete CMS page//////////////////////

if($_REQUEST['page'])
{

 $delsql="delete from cmspages where page_id=".$_REQUEST['page'];
if(mysql_query($delsql))
{

$_SESSION['msg']= "Page Deleted Successfully";
	header("location:cmspage.php");
	exit;
}

}
?>
<?php
///////////////////////////////////////add CMS pages////////////////////////////////////
if (isset ($_POST['savepage']))
{   
    $parent_id=$_POST['parent_id'];
    $page_type=$_POST['type'];
    $page_name=$_POST['page_name']; 
	 $page_heading=$_POST['page_heading']; 
    $txtSavePage = $_POST['savepage']; 
	$txtData = addslashes($_POST['txtData']); 
	if($_REQUEST['status'])
	{$status=$_REQUEST['status'];}
	else{$status=0;}	
	// "select * from cmspages where type ='".$txtSavePage."'";exit;
 	/*$rsCMS=mysql_query("select * from cmspages where type ='".$txtSavePage."'");
	if ( mysql_num_rows($rsCMS)>0	)
	{		
	$qry="UPDATE `cmspages` SET `body`='".$txtData."'  where type ='".$txtSavePage."'and status='".$status."'";
	}else if($txtSavePage != ""){*/
	
	$result_sortorder = mysql_query("SELECT MAX( sort_order  ) AS sortord FROM  `cmspages` ");
	$row_order = mysql_fetch_array($result_sortorder);
	$order = $row_order["sortord"] + 1 ;
	
	$qry="insert into cmspages set  parent_id='".$parent_id."',page_name='".$page_name."', page_heading='".$page_heading."', txtbody = '".$txtData."' , type ='".$page_type."',sort_order='".$order."', status='".$status."'";

	
	@mysql_query($qry);
	$_SESSION['msg'] = 'New Page Added Successfuly !';
	header('location:cmspage.php');
	exit;
}
?>
<?php
///////////////////////////////////////Update CMS pages////////////////////////////////////
if (isset ($_POST['updatecmspage']))
{   
    $parent_id=$_POST['parent_id'];
    $page_type=$_POST['type'];
    $page_name=$_POST['page_name'];
	 $page_heading=$_POST['page_heading'];  
    $txtSavePage = $_POST['savepage']; 
	$txtData = addslashes($_POST['txtData']); 
	if($_REQUEST['status'])
	{$status=$_REQUEST['status'];}
	else{$status=0;}	

	
	$qry="UPDATE cmspages set page_name='".$page_name."', page_heading='".$page_heading."', txtbody = '".$txtData."' , type ='".$page_type."', status='".$status."', parent_id='".$parent_id."' where page_id='".$_POST['updatecmspage']."'";

	
	@mysql_query($qry);
	$_SESSION['msg'] = 'Page Updated Successfuly !';
	//header('location:cmspage.php');?>
	<script type="text/javascript">
	
	location.replace('cmspage.php');
	</script><?php 
	exit;
}
?>
<?php
///////////////////////////add product/////////////////////////////

if($_REQUEST['addproduct'])
{ 
  if($_POST['status'] != 1) 
	{
		 $status = 0;
	}
	else
	{
		 $status = 1;
	}	
	 $product = $_POST["product"];
	 $platform=$_POST['platform'];
	 $category=$_POST['category'];
	 $price=$_POST['price'];
	 $language=$_POST['language'];
	 $description=$_POST['description'];
	 $reveiw=$_POST['reveiw'];
	 $features=$_POST['features'];
	 $productlink=$_POST['productlink'];
	
	/////////////////////img upload/////////////////////////////////////
	if($_FILES['image']['tmp_name']!="")
	{
		$targetpath="../uploads/productimg/";
		//$prod_img='';
		$image_name=$_FILES['image']['name'];
		if(move_uploaded_file($_FILES['image']['tmp_name'], $targetpath.$image_name)) {
		
		
		$prod_img=$_FILES['image']['name'];
		}
	
			
////////////////////////screenshot 1/////////////////////	
	
	 $targetpath="../uploads/screenshots/";
	
	if($_FILES['screenshot1']['tmp_name']!="")
	{
	    $screenshot1=$_FILES['screenshot1']['name'];
		if(move_uploaded_file($_FILES['screenshot1']['tmp_name'], $targetpath.$screenshot1)) 
		{
		   $scshot1=$_FILES['screenshot1']['name'];
	     }
	
	}
	
/////////////////////screenshot 2 ///////////////////////////////			
	
	if($_FILES['screenshot2']['tmp_name']!="")
	{   $screenshot2=$_FILES['screenshot2']['name'];
		if(move_uploaded_file($_FILES['screenshot2']['tmp_name'], $targetpath.$screenshot2))
	   {
		  $scshot2=$_FILES['screenshot2']['name'];
		
		} 
	}
	
/////////////////////////////screentshot 3//////////////////////	

	if($_FILES['screenshot3']['tmp_name']!="")
	{
		
		$screenshot3=$_FILES['screenshot3']['name'];
		if(move_uploaded_file($_FILES['screenshot3']['tmp_name'], $targetpath.$screenshot3)) {
		  $scshot3=$_FILES['screenshot3']['name'];
		
		} 
	}
	
////////////////////////////screenshot 4//////////////////////////	
	if($_FILES['screenshot4']['tmp_name']!="")
	{   $screenshot4=$_FILES['screenshot4']['name'];
		if(move_uploaded_file($_FILES['screenshot4']['tmp_name'], $targetpath.$screenshot4)) {
		 $scshot4=$_FILES['screenshot4']['name'];
		
		} 
	}
	
/////////////////////////////////screenshot 5//////////////	
	
	if($_FILES['screenshot5']['tmp_name']!="")
	{   $screenshot5=$_FILES['screenshot5']['name'];
		if(move_uploaded_file($_FILES['screenshot5']['tmp_name'], $targetpath.$screenshot5)) {
		 $scshot5=$_FILES['screenshot5']['name'];
		
		} 
	}

/////////////////////product video///////////////
	if($_FILES['video']['tmp_name']!="")
	{
		$targetpath="../uploads/productvideos/";
		$videos=$_FILES['video']['name'];
		
		if(move_uploaded_file($_FILES['video']['tmp_name'], $targetpath.$videos)) {
		$video=$_FILES['video']['name'];
		} 
	}
	
	/////////////up end///////////////////
	
	$result_sortorder = mysql_query("SELECT MAX( sort_order  ) AS sortord FROM  `products` ");
	$row_order = mysql_fetch_array($result_sortorder);
	$order = $row_order["sortord"] + 1 ;
	
	 $query_user="INSERT INTO  `products` set 
	                                    product='".$product."',
	                                    price='".$price."',
	                                    language='".$language."',
	                                    image='".$prod_img."',
                                       	description='".$description."',
	                                    Reveiw='".$reveiw."',
	                                    features='".$features."',
	                                    screnshot1='".$scshot1."',
	                                    screnshot2='".$scshot2."',
	                                    screnshot3='".$scshot3."',
	                                    screnshot4='".$scshot4."',
	                                    screnshot5='".$scshot5."',
										prod_link='".$productlink."',
	                                    video='".$video."',
	                                    sort_order='".$order."',
	                                    status='".$status."'";
	
	mysql_query($query_user) or die('Error, insert query failed');
	$id = mysql_insert_id();
		
		
		 foreach($_POST['category'] as $key_category => $value_category)
		 {
$a="insert into protocat (pro_id, cat_id) VALUES ( '".$id ."', '".$value_category."')";
$b=mysql_query($a);

		  }
		  
		  
		  	 foreach($_POST['platform'] as $key_platform => $value_platform)
		 {
     $c="insert into protoplatf (pro_id, p_id) VALUES ( '".$id ."', '".$value_platform."')";
	 $d=mysql_query($c);
		  }
$_SESSION['msg']="Product Added Successfully";		  
header("location:products.php");
exit;

}

}
?>
<?php
///////////////////////////update product/////////////////////////////

if($_REQUEST['editproduct'])
{
  if($_POST['status'] != 1) 
	{
		 $status = 0;
	}
	else
	{
		 $status = 1;
	}	
	
	
	 $product = $_POST["product"];
	 $platform=$_POST['platform'];
	 $category=$_POST['category'];
	 $price=$_POST['price'];
	 $language=$_POST['language'];
	 $description=$_POST['description'];
	 $reveiw=$_POST['reveiw'];
	 $features=$_POST['features'];
	 $productlink=$_POST['productlink'];
	
	 $productid=$_POST['prodid'];
	
	/////////////////////img upload/////////////////////////////////////
	
if($_FILES['image']['tmp_name']!="")
{
	  $targetpath="../uploads/productimg/";
	  $image_name='';
	  
			if($_POST['imageval']!='')
			{
			$image_name=$_POST['imageval'];
			}
			else
			{
			$image_name=$_FILES['image']['name'];
			}
			
			if(move_uploaded_file($_FILES['image']['tmp_name'], $targetpath.$image_name))
			{
			$prod_img=$image_name;
			}
	
}
		
////////////////////////screenshot 1/////////////////////	
	
	 $targetpath="../uploads/screenshots/";
	 
 if($_FILES['screenshot1']['tmp_name']!="")
{
		
				if($_POST['screenshotval1']!='')
				{
				$screenshot1='_new1'.$_POST['screenshotval1'];
				}
				else
				{
				$screenshot1=$_FILES['screenshot1']['name'];
				} 
				if(move_uploaded_file($_FILES['screenshot1']['tmp_name'], $targetpath.$screenshot1)) 
				{
				$screenshot1add="screnshot1='".$screenshot1."',";
				}
	
}
	   
	
/////////////////////screenshot 2 ///////////////////////////////			
  if($_FILES['screenshot2']['tmp_name']!="")
	{
		
				if($_POST['screenshotval2']!='')
				{
				$screenshot2='_new2'.$_POST['screenshotval2'];
				}
				else
				{
				$screenshot2=$_FILES['screenshot2']['name'];
				} 
				if(move_uploaded_file($_FILES['screenshot2']['tmp_name'], $targetpath.$screenshot2)) 
				{
				$screenshot2add="screnshot2='".$screenshot2."',";
				}
	
}
/////////////////////////////screentshot 3//////////////////////	
  if($_FILES['screenshot3']['tmp_name']!="")
	{
		
				if($_POST['screenshotval3']!='')
				{
				$screenshot3='_new3'.$_POST['screenshotval3'];
				}
				else
				{
				$screenshot3=$_FILES['screenshot3']['name'];
				} 
				if(move_uploaded_file($_FILES['screenshot3']['tmp_name'], $targetpath.$screenshot3)) 
				{
				$screenshot3add="screnshot3='".$screenshot3."',";
				}
	
}
////////////////////////////screenshot 4//////////////////////////
  if($_FILES['screenshot4']['tmp_name']!="")
	{
		
				if($_POST['screenshotval4']!='')
				{
				$screenshot4='_new4'.$_POST['screenshotval4'];
				}
				else
				{
				$screenshot4=$_FILES['screenshot4']['name'];
				} 
				if(move_uploaded_file($_FILES['screenshot4']['tmp_name'], $targetpath.$screenshot4)) 
				{
				$screenshot4add="screnshot4='".$screenshot4."',";
				}
	
}
/////////////////////////////////screenshot 5//////////////
  if($_FILES['screenshot5']['tmp_name']!="")
	{
		
				if($_POST['screenshotval5']!='')
				{
				$screenshot5='_new5'.$_POST['screenshotval5'];
				}
				else
				{
				$screenshot5=$_FILES['screenshot5']['name'];
				} 
				if(move_uploaded_file($_FILES['screenshot5']['tmp_name'], $targetpath.$screenshot5)) 
				{
				$screenshot5add="screnshot5='".$screenshot5."',";
				}
	
}
/////////////////////product video///////////////
 if($_FILES['video']['tmp_name']!="")
	{
		
				if($_POST['videoval']!='')
				{
				$video=$_POST['videoval'].'_new';
				}
				else
				{
				$video=$_FILES['video']['name'];
				} 
				if(move_uploaded_file($_FILES['video']['tmp_name'], $targetpath.$screenshot1)) 
				{
				$videoadd="video='".$video."',";
				}
	
}
	/////////////up end///////////////////
	
	/*$result_sortorder = mysql_query("SELECT MAX( sort_order  ) AS sortord FROM  `products` ");
	$row_order = mysql_fetch_array($result_sortorder);
	$order = $row_order["sortord"] + 1 ;*/
	
	 $query_user="UPDATE `products` set product='".$product."',
										price='".$price."',
										language='".$language."',
										image='".$prod_img."',
										description='".addslashes($description)."',
										Reveiw='".$reveiw."',
										features='".$features."',
										".$screenshot1add
										.$screenshot2add
										.$screenshot3add
										.$screenshot4add
										.$screenshot5add
										."prod_link='".$productlink."',".$videoadd."status='".$status."' where pro_id='".$productid."'";
	
	
	/* $query_user="UPDATE `products` set product='".$product."',
										price='".$price."',
										language='".$language."',
										image='".$prod_img."',
										description='".$description."',
										Reveiw='".$reveiw."',
										features='".$features."',
										screnshot1='".$scshot1."',
										screnshot2='".$scshot2."',
										screnshot3='".$scshot3."',
										screnshot4='".$scshot4."',
										screnshot5='".$scshot5."',
										prod_link='".$productlink."',
										video='".$video."',
									
										status='".$status."' where pro_id='".$productid."'";
	*/

	mysql_query($query_user) or die('Error, insert query failed');
	$id = mysql_insert_id();
if($_POST['category']){		
 $catsql="delete from protocat where pro_id='".$productid."'";

$delcattt=mysql_query($catsql);

}	
		 foreach($_POST['category'] as $key_category => $value_category)
		 {
$a="insert into protocat (pro_id, cat_id) VALUES ( '".$productid."', '".$value_category."')";
$b=mysql_query($a);

		  }
	if($_POST['platform']){		
$catsql="delete from protoplatf where pro_id='".$productid."'";
$deell=mysql_query($catsql);

}	  
		  
		  	 foreach($_POST['platform'] as $key_platform => $value_platform)
		 {
     $c="insert into protoplatf (pro_id, p_id) VALUES ( '".$productid."', '".$value_platform."')";
	 $d=mysql_query($c);
		  }
$_SESSION['msg']="Product Updated Successfully";		  
header("location:products.php");
exit;

}
?>
<?php
///////////////////////////////////////Update fallow US pages////////////////////////////////////
if (isset ($_POST['updatefallowus']))
{  
    $fallowusurl=$_POST['fallowusurl'];
	
	if($_REQUEST['status'])
	{$status=$_REQUEST['status'];}
	else{$status=0;}	

	
	$qry="UPDATE fallow_us set fallowlink='".$fallowusurl."', status='".$status."' where id='".$_POST['updatefallowus']."'";

	//}
	@mysql_query($qry);
	$_SESSION['msg'] = 'Fallow Us URL Updated Successfuly !';
	header('location:fallow_us.php');
	exit;
}
?>