<?php session_start();  //Developed by ITechScripts
require 'include/announcements.php'; // ITECHBIDS Configuration File
require 'include/itechbids.php';
require 'payments/api.php';
$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();
} 
$userid=$_SESSION['user_id'];
$couponname = $_POST['payamount'];
$couponname = trim($couponname);
if($couponname!=""){
$c_sql="select * from coupons where c_name='$couponname'";
$c_res=mysql_query($c_sql);
$c_count=mysql_num_rows($c_res);
if($c_count==0)
{
$c_error=1;
}
if($c_count>0)
{
$c_row=mysql_fetch_array($c_res);
$c_stats = $c_row['status'];
if($c_stats=='expired')
{
$c_error=2;
}
if($c_stats!='expired'){
$c_error="no";

$sqlC="select * from coupons where c_name='$couponname'";
$resultC=mysql_query($sqlC);
$rowC=mysql_fetch_array($resultC);
$famount=$rowC['amount'];
$sql = "update member_details set bid_num=bid_num+'$famount' where user_id='$userid'";
$result = mysql_query($sql);
$sqld = "delete from coupons where c_name='$couponname'";
$resultd = mysql_query($sqld);
}}}
require 'themes/addcoupon.tpl';
?>
<?
  require 'templates/'.$tfold.'/footer.php';
?>
</td></tr>
</table>	