<?php session_start();  //Developed by ITechScripts
   error_reporting(0);
require 'include/announcements.php'; // ITECHBIDS Configuration File
require 'include/itechbids.php'; // Server compatibility Patch
   $buyer_id=$_GET[buyer_id];
   $buyer_name=$_GET[buyer_name];
   $flag=$_GET[flag];
   $productid=$_GET[productid];
   
   $send_sql="select * from auction_details where productid=$productid";
   $send_res=mysql_query($send_sql);
   $send_rec=mysql_fetch_array($send_res);
if($flag==1)
{
$buyer_id=$_GET[buyer_id];
$buyer_name=$_GET[buyer_name];
$productid=$_GET[productid];

$user_sql="select * from member_details where user_id=$buyer_id";
$user_recordset=mysql_query($user_sql);
$user_record=mysql_fetch_array($user_recordset);
$mailto=$user_record['email'];
$send_sql="select * from auction_details where productid=$productid";
$send_res=mysql_query($send_sql);
$send_rec=mysql_fetch_array($send_res);
$subject=$send_rec['producttitle'];
$message=$_GET[message];
$from=$_SESSION[username];
$admin="select * from genaralsettings where set_id=3";
$admin_res=mysql_query($admin);
$admin_rec=mysql_fetch_array($admin_res);
$update_sql1="update site_bids set user_pos='Yes' where user_id=$buyer_id and productid=$productid";
mysql_query($update_sql1);
$update_alert="update user_alert set alert_type='P' where productid=$productid and seller_id=$_SESSION[userid] and buyer_id=$buyer_id ";
mysql_query($update_alert);
$status=1;
$myquery="insert into trader_list (seller,buyer) values ('$from','$buyer_name')";
mysql_query($myquery);
}
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ". $from."\r\n";
 /* if(mail($mailto,$subject,$message,$headers))
				$status = 1; 
			else
				 $status = 2;   */
	
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ". $from."\r\n";
$mailto=$admin_rec[admin_email];

$tax=$send_rec[tax];
$ship_cost=$send_rec['shipping_cost'];
$total_quantity=$send_rec['Quantity'];
$query="select * from site_bids where((productid=$send_rec[productid]) and (user_id=$_REQUEST[buyer_id])) order by bidding_amount DESC";
$table=mysql_query($query);
if($row=mysql_fetch_array($table))
{
$single_price=$row['bidding_amount'];
$quantity=$row['quantity'];
  if($total_quantity>=$quantity)
  {
    $total_quantity=$total_quantity-$quantity;
  }
  else
  {
    $quantity=$total_quantity;
    $total_quantity=0;
  }
$update_query="update auction_details set quantity='$total_quantity' where productid='$send_rec[productid]'";
mysql_query($update_query);

  $total_price=$quantity * $single_price;
  $total_price= $total_price + $ship_cost + (($tax/100)*$total_price);
}


if($send_rec['payment_gateway']!=0)
{
//fetch site name
$query="select * from genaralsettings where set_id = 1";
$table=mysql_query($query);
if($row=mysql_fetch_array($table))
$site_name = $row['set_value'];

 $productid =$send_rec[productid];
 $var="<br><a href='$sitename/postpay.php?id=$productid&pm=$total_price&quantity=$quantity'>Pay Now</a>";
}
$message . "$var";
//mail($mailto,$subject,$message,$headers); 
   require 'themes/sendmail.php'; // Server compatibility Patch
?>
