<?
ob_start();
session_start();
if($_SESSION['uname']=='' || $_SESSION['pwd']=='')
		{
			header("location:login.php");
		}
 include("../include/db.inc.php");
 include("../include/bit_functions.inc.php");
 include("../include/pager.php"); 
   $db1=new db;
   $db1->open();
    mysql_query("SET NAMES 'utf8'");
   
  $uid=$_SESSION['id'];
   
    if(isset($_POST['send']) && is_array($_POST['user_id']))
   { 
   
   
   
   			$s="select * from discount_mail where uid='".$_SESSION['id']."'";
			if(mysql_num_rows(mysql_query($s))==0)
			{
  
						 extract($_POST);
						 $code=substr(md5(time()),0,10);
						
						foreach($user_id as $userid)
							{
							$sql="insert into discount_mail set uid='$userid',code='$code',discount='$discount',date=now()";
							$res=mysql_query($sql);
							$all_mail=get_fieldval(id,email,user,$userid);
											
						 $body="<html><title>DISCOUNT</title><body>
								<center>
								<div style='width:500px'>
								
								<div style='height:20px; padding:10px; color:#FFFFFF; background-color:#5CB115; font-size:20px;font-family: 'lucida grande', tahoma, verdana, 
								arial, sans-serif' align='left'>Welcome <?=_TITLE1_?></div><div style='height:5px; background-color:#FFAE0D'></div><div style='padding:10px; 
								border:1px solid #CCCCCC; font-size:12px; color:#333333;font-family: 'lucida grande', tahoma, verdana, arial, sans-serif' 
								align='left'>Buy Any Bidpack With Greenfair And Enter the code for get more discount ".$discount." % <br>".$code."<br>
									<br>Thanks!<br>Greenfair Team</div>
								</div>
								</center>
								</body>
								</html>"; 
								$headers ="From:". _ADMIN_MAIL_. "<"._ADMIN_MAIL_."> \r\n";
								$headers .= "Reply-To:". _ADMIN_MAIL_. "<"._ADMIN_MAIL_ ."> \r\n";
								$headers .= "Content-Transfer-Encoding: 8bit\n";
								$headers .= "MIME-Version: 1.0\n";
								$headers .= "Content-type: text/html; charset=utf-8\n";
								 $subject ="Welcome For '".$discount."' % Discount ON Your Bids!"; 
								
								 mail($all_mail,$subject,$body,$headers);
								
					
							
							}
								header("location:bid_discount.php?uid='$uid'");
		
		
		       }
		
		
				
	}
	
		       
   
$uname_sql = "select id,uname from user where email!='' and confirm='1' and deactive='0' and blocked='0'";
$uname = mysql_query($uname_sql);


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Money Auctions | Admin Controls</title>
<link href="index.css" rel="stylesheet" type="text/css" />
<link href="../css/stylesheet.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#ffffff">
<div class="admin_wrapper"> 
<div class="logo_show"><? include("minorlogout.php");?></div>
<div style="float:left; width:200px">
<div class="topg_links_show"><? include("left.php");	?></div>
<div class="top_links_show"><? include("belowleft1.php");	?></div></div>
<div style="float:left; width:800px"> 
<div class="maximum"> 
    <!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::center starts:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
    <div style="margin-top:5px">
      <table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%" style="border-collapse:collapse; border-color:#404193; margin-top:40px">
        <tr height="417">
          <!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::left starts:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
          <!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::left ends:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
          <td width="81%" bgcolor="#FFFFFF" valign="top"><br />
              <table width="73%" border=0 cellpadding=0 cellspacing=0 align="center">
                <tr>
                  <td><img border='0' src="border_img/circle_01.gif" width=36 height=35 alt="" /></td>
                  <td width="626" height="34" valign="top" ><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="16%" ><strong><font color="#003366">Bid Discount</font></strong></td>
                        <td width="79%" background="border_img/circle_02.gif">&nbsp;</td>
                      </tr>
                  </table></td>
                  <td><img border='0' src="border_img/circle_03.gif" width=35 height=35 alt="" /></td>
                </tr>
                <tr>
                  <td width="36" background="border_img/circle_04.gif">&nbsp;</td>
                  <td align="left" valign="top"><form action="" method="post" enctype="multipart/form-data" name="addnewfrm" onsubmit="return valform(this)">
                      <table width="100%" border="0" cellspacing="1" cellpadding="1" bgcolor="#003366" >
                        <tr bgcolor="#E6E4E3">
                          <td width="19%" height="20">User Name</td>
                          <td><div style="margin-top:5px;">
                              <div style=" padding-left:7px;">
                                <div >
                                  <ul class="checklist cl1">
									<?
									  $i = 0;
									  
									  while($username = mysql_fetch_array($uname)){?>
									<li class="alt<?=($i%2)?"1":"2"?>">
                                      <label for="username<?=$i;?>">
                                      <input id="username<?=$i;?>" type="checkbox" name="user_id[]" value="<?=$username['id'];?>"/>
                                      <?=$username['uname'];?>
                                      </label>
                                    </li>
										<?
										   $i++;
										  }
											?>
                                  </ul>
                                </div>
                              </div>
                          </div></td>
                        </tr>
                        <tr bgcolor="#FFFFFF">
                          <td height="20">Discount Percentage</td>
                          <td><select name="discount" >
                              <option value="0">--Discount Percentage--</option>
                              <option value="1">1%</option>
                              <option value="3">3%</option>
                              <option value="5">5%</option>
                              <option value="10">10%</option>
                              <option value="20">20%</option>
                              <option value="25">25%</option>
                              <option value="30">30%</option>
                              <option value="40">40%</option>
                              <option value="50">50%</option>
                          </select></td>
                        </tr>
                        <tr bgcolor="#E6E4E3">
                          <td height="25">&nbsp;</td>
                          <td><input name="send" type="submit" class="inputsubmit" value="SEND" />
						  <input  type="button" name="back" class="inputsubmit" value="BACK TO LIST" onClick="window.location.href='bid_disc.php'"/></td>
                        </tr>
                      </table>
                  </form></td>
                  <td width="35" background="border_img/circle_06.gif">&nbsp;</td>
                </tr>
                <tr>
                  <td><img border='0' src="border_img/circle_07.gif" width=36 height=34 alt="" /></td>
                  <td height="34" background="border_img/circle_08.gif">&nbsp;</td>
                  <td><img border='0' src="border_img/circle_09.gif" width=35 height=34 alt="" /></td>
                </tr>
            </table></td>
        </tr>
      </table>
    </div>
    <!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::center ends:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
</div></div>
<div class="bottom_links_show"><? include("footer.php");	?></div>
</div>
<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::footer ends:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
</body>
</html>