<?php session_start();
require_once("../config/config.php");
//require_once("../config/commonsetting.php");
$myformId=SESS_MASTER;

$userids = secureSuperGlobalPOST($_REQUEST[SESS_MASTER.'userid']);
$myIp= ipCheck() ;
$dateceated=date("Y-m-d G:i:s");
$createdby='0';
$user_id=$_SESSION[ADD_TAG.'_UserId_vendor'];
// $olga="DELETE FROM product_master WHERE created_by='$user_id' AND created_type='vendor'"; 
// $stmts = $conn->prepare($olga);
// $stmts->execute();
$handle = fopen($_FILES[SESS_MASTER.'upload_data']['tmp_name'], "r");
$headers = fgetcsv($handle, 1000, ",");
$data = fgetcsv($handle, 1000, ",");
$num = count($data);
if($num<=250){
while (($data = fgetcsv($handle, 1000, ","))!== FALSE) 
{
try{
$coupon_code=addslashes($data[0]);
$company_name=addslashes($data[1]);
$short_title=addslashes($data[2]);
$full_title=addslashes($data[3]);
$link=addslashes($data[4]);
$category=addslashes($data[5]);
$type=addslashes($data[6]);
$exp_date=addslashes($data[7]);
$from_site=addslashes($data[8]);
$coupon_country_name=addslashes($data[9]);
$brand_store=addslashes($data[10]);
$image=addslashes($data[11]);
$trending=rand(0,1);
if($coupon_code!='' && $company_name!='' && $short_title!='' && $full_title!=''&& $link!='' && $category!='' && $type!='' && $exp_date!='' && $from_site!='' && $coupon_country_name!=''){
$olgaquery="INSERT INTO coupon SET company_name='$company_name', short_title ='$short_title', full_title='$full_title',link='$link',category='$category',exp_date='$exp_date',coupon_country_name='$coupon_country_name',brand_store='$brand_store'
,trending='$trending',from_site='$from_site',created_by='$user_id',created_type='vendor',coupon_code='$coupon_code',image='$image'"; 
$stmt = $conn->prepare($olgaquery);
if($stmt->execute()){
$last_insert_id = $conn->lastInsertId();
$status='success';
$_SESSION["uploaded"] = $status ;
header("location:../merchant-id/3");
}
}else{
$olga="DELETE FROM coupon WHERE created_by='$user_id' AND created_type='vendor'"; 
$stmts = $conn->prepare($olga);
$stmts->execute();
$status='failed';
unset($_SESSION["uploaded"]);
$_SESSION["uploaded"] = $status ;
break;
header("location:../merchant-tab/".$userids);
}
}
// show error
catch(PDOException $exception){
die('ERROR: ' . $exception->getMessage());
}
}
echo '<br>';
}else{
$status='failed';
}
$_SESSION["uploaded"] = $status ;
header("location:../merchant-tab/".$userids);
fclose($handle);