<?php include('../../config/setup.php');?>
<?php
error_reporting(E_ALL & ~E_NOTICE);
error_reporting(E_ERROR | E_PARSE);
if(isset($_POST['Add_new_product']))
{
  
 
// $Add_pro_game_support= array_filter( $_POST['Add_pro_game_support']);
// $support_image=array_values(array_filter($_FILES['support_image']['name']));
// $prod_price=array_values(array_filter($_POST['prod_price']));
// $shell_price=array_values( array_filter($_POST['shell_price']));
//  $tempname = array_values(array_filter($_FILES["support_image"]["tmp_name"]));
//  $i=0;
//   foreach($support_image as $val){  
// $addsugcatephoto=$val;
// echo $addsubphoto="../../../photos/Product/".$addsugcatephoto;
// // move_uploaded_file($tempname[$i],$addsubphoto);

// $offer_per = (100 * ($prod_price[$i] - $shell_price[$i]) / $prod_price[$i] );
// $maincate=date('Y-m-d');
// echo $p_p_d="insert into product_price_master(Product_id,Product_type,Product_price,Shelling_price,Offer_Percent,product_stock,product_tax,Product_price_Add_on,Product_status)
// values('$pid','".$Add_pro_game_support[$i]."','".$prod_price[$i]."','".$shell_price[$i]."','$offer_per','".$_POST['Add_pro_stocks']."','".$_POST['Add_pro_tax']."','$maincate','".$_POST['Add_pro_status']."')";

// $i++;


//   }
 

//     foreach( $Add_pro_game_support as $code) {
//       echo $code ;
//       $addsugcatephoto=$support_image[$i];
//       $addsubphoto="../../../photos/Product/".$addsugcatephoto;
//       move_uploaded_file($_FILES["upload_images"]["tmp_name"][$key],$addsubphoto);

      
        
     
//     }

  
$subcate=date('Y-m-d');

$desc=str_replace("'"," ",$_POST['Editor1']);
$addprophoto=$_FILES['Add_product_master_image']['name'];
$addprphoto="../../../img/Product/".$addprophoto;
move_uploaded_file($_FILES["Add_product_master_image"]["tmp_name"],$addprphoto);
  
  $pm="insert into product_master(Product_Name,sub_cate,product_brand,Main_Category,product_publisher,product_developer,Product_image,Product_description,product_video_link,Product_offer,product_display_cate,product_display,Product_Active_Status,Product_add_on,Releasing_on,refundpolicy,product_ttype,pro_list,pro_list2,delivry,product_tax)
values('".$_POST['Add_pro_name']."','".$_POST['Add_product_sub']."','".$_POST['Add_pro_brand']."','".$_POST['Add_product_maincate']."','".$_POST['Add_pro_Publisher']."','".$_POST['Add_pro_Developer']."','$addprophoto','$desc','".$_POST['Add_pro_video_link']."','".$_POST['Add_pro_offer']."','".$_POST['Add_pro_dispaly_cate']."','".$_POST['Add_pro_dispaly']."','".$_POST['Add_pro_status']."','$subcate','".$_POST['Add_pro_rel_date']."','".$_POST['return']."','".$_POST['pm_type']."','".$_POST['p_list']."','".$_POST['p_list2']."','".$_POST['delivry']."','".$_POST['Add_pro_tax']."')";

$addmaincate=mysqli_query($config,$pm);	

 
 $pid= mysqli_insert_id($config);
$pttype=$_POST['pm_type'];


$i=0;
$color=$_POST['color'];
$length=$_POST['length'];
$weight=$_POST['weight'];
$texture=$_POST['texture'];
$prod_price=$_POST['Add_pro_price'];
$shell_price=$_POST['Add_pro_shelling_price'];
$p_img=$_FILES['support_image']['name'];
$p_tmp=$_FILES["support_image"]["tmp_name"];
  foreach($color as $val){  
$addsugcatephoto=$p_img[$i];
    $addsubphoto="../../../photos/Product/".$addsugcatephoto;
     move_uploaded_file($p_tmp[$i],$addsubphoto);

 $taxadd=$_POST['Add_pro_tax'];
 $sellprice=$shell_price[$i];
 
$offer_per = (100 * ($prod_price[$i] -  $sellprice) / $prod_price[$i] );
$maincate=date('Y-m-d');

    $p_p_d="insert into product_price_master(Product_id,P_image,Product_type,	Product_length,Product_price,Shelling_price,Offer_Percent,product_stock,product_tax,Product_price_Add_on,Product_status,p_weight,p_texture)
values('$pid','$addsugcatephoto','$val','".$length[$i]."','".$prod_price[$i]."','".$sellprice."','$offer_per','".$_POST['Add_pro_stocks']."','".$_POST['Add_pro_tax']."','$maincate','".$_POST['Add_pro_status']."','".$weight[$i]."','".$texture[$i]."')";
 $addprotype=mysqli_query($config,$p_p_d);
$i++;


  
}

 //$oid=count($_POST['Add_pro_game_support']);
//   for($aa=0;$aa<$oid;$aa++) {
 
 
//  $offer_per = (100 * ($_POST['Add_pro_price'] - $_POST['Add_pro_shelling_price']) / $_POST['Add_pro_price'] );
// $maincate=date('Y-m-d');
// $addprotype=mysqli_query($config,"insert into product_price_master(Product_id,Product_type,Product_price,Shelling_price,Offer_Percent,product_stock,product_tax,Product_price_Add_on,Product_status)
//  values('$pid','".$_POST['Add_pro_game_support'][$aa]."','".$_POST['Add_pro_price']."','".$_POST['Add_pro_shelling_price']."','$offer_per','".$_POST['Add_pro_stocks']."','".$_POST['Add_pro_tax']."','$maincate','".$_POST['Add_pro_status']."')");	


//   }

 $c=count($_POST['Add_pro_type']);
  for($cc=0;$cc<$c;$cc++) {
 
 
 $maincate=date('Y-m-d');
$addprotype=mysqli_query($config,"insert into product_plateform(product_id,plateform,plateform_status)
 values('$pid','".$_POST['Add_pro_type'][$cc]."','".$_POST['Add_pro_status']."')");	


  }

$product_subcate=$_POST['Add_pro_sub_gener'];

foreach($product_subcate as $data){
mysqli_query($config,"insert into product_game_sub_cate(product_id,sub_main_cate)
  values('$pid','$data')");	

}



//  $d=$_POST['Add_pro_game_support'];
//   $d1=$_POST['Add_pro_game_support1'];
//  $da1= implode("",$d1);
//   $da1;
 
//   foreach($d1 as $d){
//     $addprotype1=mysqli_query($config,"insert into product_game_support3(product_id,support_Name)  values('$pid','". $d."')");
//   }

  // for($dd=0;$dd<$d;$dd++) {
 
 
//  $maincate=date('Y-m-d');
// $addprotype=mysqli_query($config,"insert into product_game_support(product_id,support_Name,support_status)
//  values('$pid','". $da1."','".$_POST['Add_pro_status']."')");	
//  $maincate=date('Y-m-d');
//  for($dd=0;$dd<$d1;$dd++) {
// echo $addprotype1=mysqli_query($config,"insert into product_game_support1(product_id,support_Name)
//  values('$pid','". $d1[$dd]."')");	


//    } 
 
//   $e=count($_POST['Add_game_rate']);
//   for($ee=0;$ee<$e;$ee++) {
 
 
//  $maincate=date('Y-m-d');
// $addprotype=mysqli_query($config,"insert into product_game_age_rating(product_id,game_rating,game_rating_status)
//  values('$pid','".$_POST['Add_game_rate'][$ee]."','".$_POST['Add_pro_status']."')");	


//   }

//     $f=count($_POST['Add_pro_sub_gener']);
//     $su=$_POST['Add_pro_sub_gener'];
//     $sa= implode(" ",$su);
     
  // for($ff=0;$ff<$f;$ff++) {
 
 
//  $maincate=date('Y-m-d');
// $addprotype=mysqli_query($config,"insert into product_game_sub_cate(product_id,subcate_Name,sub_cate_status,sub_main_cate)
//  values('$pid','".$sa."','".$_POST['Add_pro_status']."','".$_POST['Add_product_maincate']."')");	


  







$a1=count($pid);
$b=count($_FILES['upload_images']['name']);
 
 for($a11=0;$a11 < $a1; $a11++)
 {
  foreach($_FILES['upload_images']['name'] as $key=>$val){  
 
     
$addsugcatephoto=$_FILES['upload_images']['name'][$key];
$addsubphoto="../../../img/Product/".$addsugcatephoto;
move_uploaded_file($_FILES["upload_images"]["tmp_name"][$key],$addsubphoto);
  
 
		$insert_sql =mysqli_query($config,"INSERT INTO product_image_master(Product_image,Product_id,Product_image_status) 
			VALUES('$addsugcatephoto','".$pid."',1)");
	
	
	
	




 }
 }


echo "<script>window.location.href='../product_master.php?msg=100';</script>";	 

 }
?>




