<?php session_start();  //Developed by ITechScripts
require 'include/announcements.php'; // ITECHBIDS Configuration File
require 'include/options.php'; // ITECHBIDS Configuration File
require 'include/itechbids.php'; // ITECHBIDS Configuration File
$locheckuser=$_SESSION[username];
$locheckpass=$_SESSION[checkpass];
if((strlen($locheckuser)==0) || (strlen($locheckpass)==0))
{
echo '<meta http-equiv="refresh" content="0; url=index.php">';
exit();
} 
$lochecksql="select * from member_details where user_name='$locheckuser' and password='$locheckpass' and verified='yes' and approved='yes' and payment_status='yes'";
$locheckre=mysql_query($lochecksql);
if(mysql_num_rows($locheckre)==0)
{
echo '<meta http-equiv="refresh" content="0; url=index.php">';
exit();
} 
$auction_query="select * from genaralsettings where set_id=42";
$table=mysql_query($auction_query);
$row=mysql_fetch_array($table);
$bid_permission=$row['set_value'];

   if($postmethod!="dutch_auction")
   {
   $qty="1";
   $_SESSION[qty]=1;
   }


if($_SESSION[mode]=="repost")
{
$productid=$_SESSION[productid];
$edit="select * from auction_details where productid=$productid";
$modifyres=mysql_query($edit);
$modifyrow=mysql_fetch_array($modifyres);
$fea_item="select * from featuredproducts where productid=$productid";
$fea_res=mysql_query($fea_item);
$fea_row=mysql_fetch_array($fea_res);
$_SESSION[item_name]=$modifyrow[producttitle];
$_SESSION[des]=$modifyrow[detailed_descrip];
$_SESSION[postmethod]=$modifyrow[selling_method];
$_SESSION[currency]=$modifyrow[currency];
$_SESSION[min_amt]=$modifyrow[min_bid_amount];
$_SESSION[quick_price] =$modifyrow[quick_buy_price]; 
$_SESSION[rev_price]=$modifyrow[reserve_price];
$_SESSION[bid_inc]=$modifyrow[bidincrement];
$_SESSION[size_of_qty]=$modifyrow[size_of_quantity];
$_SESSION[qty]=$modifyrow[Quantity];
$_SESSION[start_delay]=$modifyrow[start_delay];
$_SESSION[image1]=$modifyrow[picture1];
$_SESSION[image2]=$modifyrow[picture2];
$_SESSION[image3]=$modifyrow[picture3];
$_SESSION[shipping_route]=$modifyrow[shipping_route];
$_SESSION[shipping_amt]=$modifyrow[shipping_cost];
$_SESSION[tax]=$modifyrow[tax];
$_SESSION[repost]=$_modifyrow[no_of_repost];
   $quick=$_SESSION[quick_price];	  
   $size_of_qty=$_SESSION[size_of_qty];
   $start_delay=$_SESSION[start_delay];
   $img1=$_SESSION[image1];
   $img2=$_SESSION[image2];
   $img3=$_SESSION[image3];
   $img4=$_SESSION[image4];
   $img5=$_SESSION[image5];
   $addshop=$_SESSION[addshop];
}

?>
<?
  $flag=$_POST[flag];
  if($flag==1)
{  
   $userid=$_SESSION[userid];   
   $cat_id=$_SESSION[categoryid];
   $producttitle=$_SESSION[item_name];
   $qty=$_SESSION[qty];
   $itemdes=$_SESSION[des];
   $currency=$_SESSION[currency];
   $postmethod=$_SESSION[postmethod];
   $min_amt=$_SESSION[min_amt];  
   $bid_inc=$_SESSION[bid_inc];

   $dur=$_SESSION[dur];
   $rev_price=$_SESSION[rev_price];
   $quick=$_SESSION[quick_price];	  
   $size_of_qty=$_SESSION[size_of_qty];
   $start_delay=$_SESSION[start_delay];
   $img1=$_SESSION[image1];
   $img2=$_SESSION[image2];
   $img3=$_SESSION[image3];
   $img4=$_SESSION[image4];
   $img5=$_SESSION[image5];
   $addshop=$_SESSION[addshop];
   $shipping_route=$_SESSION[shipping_route];
   $shipping_amt=$_SESSION[shipping_amt];
   $tax=$_SESSION[tax];
   //payment
   $payment=$_SESSION[payment];
   $payname=$_SESSION[payname];
   $payid=$_SESSION[payid];
   $repost=$_SESSION[repost];
   $s_repost=$_SESSION[s_repost];
   function addDay($date,$interval) 
{ 
  if (!isset($date)) 
  $date = date("Y-m-d"); 
  $elts = explode("-", $date); 
  $inter=$interval*24*3600; 
  $dcour=mktime(1,0,0,$elts[1],$elts[2],$elts[0]); 
  $dres=$dcour+$inter; 
  $date1=date("Y-m-d",$dres);
  $sec=date("G:i:s");
  $ret_date="$date1"." "."$sec";
  return $ret_date; 
}
   if($_SESSION[mode]!="repost" or $_SESSION[mode]="relist")
   {
   $bidding_start_date=date("Y-m-d");
   $bidding_start_date = addDay($bidding_start_date,$start_delay); 
   $interval =$dur +$start_delay;
   $expire_date = addDay($bidding_start_date,$interval); 
   $Gallery=$_SESSION[Gallery];
   $Border=$_SESSION[Border];
   $Highlight=$_SESSION[Highlight];
   $Privateauc=$_SESSION[Privateauc];

   $Bold=$_SESSION[Bold];
   $Home=$_SESSION[Home];
   $repost=$_SESSION[repost];
   $Insertion_fee=$_SESSION[Insertionfee];
   $addshop=$_SESSION[addshop];
   $mem_plans = member_tp($userid);
$fee_sql="select * from site_fees where admin_id=$mem_plans";
$fee_res=mysql_query($fee_sql);
$fee_row=mysql_fetch_array($fee_res);
if($_SESSION[Gallery])
$gallery_price=$fee_row[gallery_price];
if($_SESSION[Highlight])
$highlight_price=$fee_row[highlight_price];
if($_SESSION[Privateauc])
$private_fee=$fee_row[private_fee];

if($_SESSION[Bold])
$bold_price=$fee_row[bold_price];
if($_SESSION[Home])
$homepage_price=$fee_row[homepage_price];
 $insertion_fee=$fee_row[Insertion_fee];
if($insertionfee=="0.00" || $insertionfee=="0" || $insertionfee==" " )
{
$insertionfee="";
 }
$auction_query1="select * from genaralsettings where set_id=42";
$table1=mysql_query($auction_query1);
$row1=mysql_fetch_array($table1);
$bid_permission1=$row['set_value'];
if($bid_permission1=="no")
{

	$qry="select * from bidincrement";
	$res=mysql_query($qry);
	while($fetch=mysql_fetch_array($res))
	{
		if($min_amt>=$fetch['bid_from'] && $min_amt<=$fetch['bid_to'])
		{
			$bid_inc=$fetch['bid_inc'];
			break;
		}
	}
}

$default_currency="select * from genaralsettings where set_id=55";
$default_res=mysql_query($default_currency);
$default_row=mysql_fetch_array($default_res);
$default_cur=$default_row[set_value];
$itemrepost = $_SESSION[itemrepost];
require 'include/options.php';
if($en_dis[7]=="yes")
     {
$po_status = "unapproved";
}
if($en_dis[7]=="no")
     {
$po_status = "Active";
}
if($itemrepost!="yes"){

if((($highlight_price!="")&&($highlight_price!=0)&&($highlight_price!="0.00"))|| (($private_fee!="")&&($private_fee!=0)&&($private_fee!="0.00")) || (($bold_price!="")&&($bold_price!=0)&&($bold_price!="0.00")) || (($gallery_price!="")&&($gallery_price!=0)&&($gallery_price!="0.00")) || (($homepage_price!="")&&($homepage_price!=0)&&($homepage_price!="0.00")) || (($insertion_fee!="")&&($insertion_fee!=0)&&($insertion_fee!="0.00"))  )
   {
    $sql="insert into auction_details(user_id,category_id,producttitle,quantity,detailed_descrip, currency ,selling_method,min_bid_amount,bidincrement,duration,reserve_price,quick_buy_price,bid_starting_date,picture1,picture2,picture3,picture4,picture5,size_of_quantity,start_delay,expire_date,shipping_route,shipping_cost,status,tax,payment_gateway,payment_name,payment_id,no_of_repost,s_repost,shop)";
    $sql.="values('$userid','$cat_id','$producttitle','$qty','$itemdes','$default_cur','$postmethod','$min_amt','$bid_inc','$dur','$rev_price','$quick','$bidding_start_date','$img1','$img2','$img3','$img4','$img5','$size_of_qty','$start_delay','$expire_date','$shipping_route','$shipping_amt','New','$tax','$payment','$payname','$payid','$repost','$s_repost','$addshop')"; 
  } 
  else 
   {
    $sql="insert into auction_details(user_id,category_id,producttitle,quantity,detailed_descrip, currency ,selling_method,min_bid_amount,bidincrement,duration,reserve_price,quick_buy_price,bid_starting_date,picture1,picture2,picture3,picture4,picture5,size_of_quantity,start_delay,expire_date,shipping_route,shipping_cost,status,tax,payment_gateway,payment_name,payment_id,no_of_repost,s_repost,shop)";
    $sql.="values('$userid','$cat_id','$producttitle','$qty','$itemdes','$default_cur','$postmethod','$min_amt','$bid_inc','$dur','$rev_price','$quick','$bidding_start_date','$img1','$img2','$img3','$img4','$img5','$size_of_qty','$start_delay','$expire_date','$shipping_route','$shipping_amt','$po_status','$tax','$payment','$payname','$payid','$repost','$s_repost','$addshop')"; 
  } }
if($itemrepost=="yes"){
$productid = $_SESSION[itemnorepost];
$sql="update auction_details set producttitle='$producttitle',quantity='$qty',detailed_descrip='$itemdes',currency='$default_cur',min_bid_amount='$min_amt',reserve_price='$rev_price',bidincrement='$bid_inc',quick_buy_price='$quick',bid_starting_date='$bidding_start_date',picture1='$img1',picture2='$img2',picture3='$img3',picture4='$img4',picture5='$img5',size_of_quantity='$size_of_qty',start_delay='$start_delay',expire_date='$expire_date',shipping_route='$shipping_route',shipping_cost='$shipping_amt',status='Active',tax='$tax',payment_gateway='$payment',payment_name='$payname',payment_id='$payid',no_of_repost='$repost',s_repost='$s_repost',shop='$addshop' where productid=$productid";
}   
    $res=mysql_query($sql);  
		
  if($res)
{
$productid=mysql_insert_id();
$user="select * from member_details where user_id=$_SESSION[userid]";
$user_res=mysql_query($user);
$user_row=mysql_fetch_array($user_res);
   
if(!empty($Highlight) || !empty($Privatefee) || !empty($Border) || !empty($Bold) || !empty($Gallery) || !empty($Subtitle) || !empty($Home))
{ 
   $feature_sql="insert into featuredproducts(productid,gallery_feature,home_feature,bold,border,highlight,subtitle_feature,subtitle,privateauc)";
   $feature_sql.="values($productid,'$Gallery','$Home','$Bold','$Border','$Highlight','$Subtitle','$Subtitle_name','$Privateauc')";
   $feature_res=mysql_query($feature_sql);
}   
 if(!empty($Insertion_fee) || !empty($Highlight) || !empty($Privateauc) || !empty($Border) || !empty($Bold) || !empty($Gallery) || !empty($Subtitle) || !empty($Home))
 { 
$fee_sql="select * from site_fees where admin_id=$mem_plans";
$fee_res=mysql_query($fee_sql);
$fee_row=mysql_fetch_array($fee_res);
if($Gallery)
$gallery_price=$fee_row[gallery_price];
if($Highlight)
$highlight_price=$fee_row[highlight_price];
if($Privateauc)
$private_fee=$fee_row[private_fee];

if($Bold)
$bold_price=$fee_row[bold_price];
if($Home)
$homepage_price=$fee_row[homepage_price];
 $insertion_fee=$fee_row[Insertion_fee];

   $feature_sql="insert into auction_fees(productid,gallery_fee,homepage_featureditem_fee,boldlisting_fee,highlighted_fee,insertion_fee,private_fee)";
   $feature_sql.="values('$productid','$gallery_price','$homepage_price','$bold_price','$highlight_price','$insertion_fee','$private_fee')";
   $feature_res=mysql_query($feature_sql);
  
 } 
 


//}

$cat_sql="select * from downcats where category_id=$cat_id";
$res=mysql_query($cat_sql);
$row=mysql_fetch_array($res);
$tablename=$row[tablename];
$file_path=$row[file_path];
  if($tablename)
   { 
     	$tab_sql="select * from $tablename";
        $tab_res=mysql_query($tab_sql);
        $i =2; 
		$j=3;
		$in_sql="insert into $tablename(productid,";
		$in_sql_value="values(' $productid ', ";
 while ($i < mysql_num_fields($tab_res))
{
    $tab_col = mysql_fetch_field($tab_res, $i);
	$dummy=$tab_col->name;
	$in_sql.="$dummy ,";
	//if($i<$j)
   	$in_sql_value.="'$_SESSION[$dummy]',";
   // echo "sesssion"."<br>". $_SESSION[third]."<br>";
	$i++;
	// $j++;
}
$in_sql=rtrim($in_sql,", "); 
$in_sql_value=rtrim($in_sql_value,", "); 
$in_sql.=")".$in_sql_value.")";
$in_res=mysql_query($in_sql);
}
//$sucess=1;
} //if($res)
} //
if($res)
 $sucess=1;
 else
 $fail=1;
 } 
if($sucess==1)
{
$_SESSION[des]="";
$_SESSION[postmethod]="";
$_SESSION[currency]="";
$_SESSION[min_amt]="";
 $_SESSION[quick_price] ="";
$_SESSION[rev_price]="";
$_SESSION[bid_inc]="";
$_SESSION[size_of_qty]="";
$_SESSION[qty]="";
$_SESSION[start_delay]="";
$_SESSION[image1]="";
$_SESSION[image2]="";
$_SESSION[image3]="";
$_SESSION[shipping_route]="";
$_SESSION[shipping_amt]="";
$_SESSION[tax]="";
$_SESSION[mode]="";
$_SESSION[Gallery]="";
$_SESSION[Border]="";
$_SESSION[Highlight]="";
$_SESSION[Privateauc]="";
$_SESSION[itemrepost]="";
$_SESSION[itemnorepost]="";
$_SESSION[Bold]="";
$_SESSION[Home]="";
$_SESSION[repost]="";
$_SESSION[s_repost]="";
$_SESSION[dur] ="";
$_SESSION[categoryid]="";
if($tablename)
  {
  $tab_sql="select * from $tablename";
  $tab_res=mysql_query($tab_sql);
  $i =2;
while ($i < mysql_num_fields($tab_res))
{
    $tab_col = mysql_fetch_field($tab_res, $i);
    if (!$tab_col) 
	{
        echo "";
    }
	else
	{
	  $dummy="$".$tab_col->name;
      $dummy=$_POST[$tab_col->name];
	  $_SESSION[$tab_col->name]="";		
    }
	$i++;
} // while
} // if($tablename)
} // if($sucess==1)
require'themes/preview.tpl';
?>
</table>
<tr><td> <? require 'templates/'.$tfold.'/footer.php'; ?></td></tr>
<script language="JavaScript">
function cancel()
{
var where_to= confirm("Are U Sure U Want to cancel the items?");
if (where_to== true)
 {
 window.location="index.php";
 //document.preview.submit();
 }
}
</script>