<?php
include_once("inc/conn.php");		
include_once("inc/function.php");
login_check();
business_check();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>商户中心-<?=$web_name;?></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="keywords" content="<?=$web_keywords;?>" />
<meta name="description" content="<?=$web_description;?>" />
<META http-equiv=X-UA-Compatible content=IE=EmulateIE7>
<link href="style/default.css" rel="stylesheet" type="text/css" />
</head>
<?php include_once("top.php");?>
<DIV class="wrapper">
	<DIV class="page_content">
  		<!--主体右边 Start-->
    	<div class="area260 fl">
			<DIV class="news-title">
				 <H3>商户中心</H3>
			</DIV>
			<ul class="area260-info business-list">
				<LI><A href="businessnotice.php">商户公告</A></LI>
                <LI class="my_nav_on"><A href="businessusers.php">商户汇豆</A></LI>
                <LI><A href="businesscardlog.php">汇豆记录</A></LI>
                <LI><A href="businesscardback.php">查看库存</A></LI>
                <LI><A href="businesspay.php">我要进货</A></LI>
                <LI><A href="businesslog.php">进货记录</A></LI>
			</ul>
			 <DIV class="area260-b h5px"></DIV>
			 <DIV class=blank10></DIV>
		</div>
		<!--主体左边 Start-->
		<div class="area690 fr">
			<DIV class="users-title">
				 <H3>商户汇豆</H3>
			</DIV>
        	<div class="users-content">
        		<?
				switch($_GET["act"]){
				case "saddSms":
					saddSms();
					echo "<script language=javascript>alert('发卡成功！');location.href='businessusers.php';</script>";
					break;
				default:
					addSms();
					break;
				}
				
				function saddSms(){
					global $db,$web_dbtop;
					if(!$_POST["tbSmsReceiver"]){
						echo "<script language=javascript>alert('对不起，请填写收卡人！');history.go(-1);</script>";
						exit;
					}
					if(!$_POST["cardtype"]){
						echo "<script language=javascript>alert('对不起，请选择充值卡类型！');history.go(-1);</script>";
						exit;
					}
					if($_POST["rType"]==1){
						$tbSmsReceiver=intval($_POST["tbSmsReceiver"]);
					}else{
						$tbSmsReceiver=showid("users","id",str_check($_POST["tbSmsReceiver"]));
					}
					$cardtypename=showcardtype(intval($_POST["cardtype"]));
					$sql="SELECT * FROM {$web_dbtop}card where cardtype=".intval($_POST["cardtype"])." and businessid=".showbusinessid(intval($_COOKIE["usersid"]))." and state=0 Order by id desc";
					$query=$db->query($sql);
					if($db->fetch_array($query)) 
						$intnum=$db->num_rows($query);
					if($intnum<$_POST["tbnum"]){
						echo "<script language=javascript>alert('对不起，你的 ".$cardtypename." 库存不足！');history.go(-1);</script>";
						exit;
					}
					$query=$db->query($sql." limit 0,".intval($_POST["tbnum"]));
					while($rs=$db->fetch_array($query)){
						$db->query("update {$web_dbtop}card set state=2,uid=$tbSmsReceiver,utime='".date("Y-m-d H:i:s")."' where id =".$rs["id"]);
						$tbSmsSubject="系统发卡通知";
						$tbSmsContent="您购买的 ".$cardtypename."</br>卡号：".$rs["cardid"]."</br>密码：".$rs["cardpaw"];
						$db->query("INSERT INTO {$web_dbtop}msg (usersid,title,mag,mid,time) VALUES (0,'".$tbSmsSubject."','".$tbSmsContent."',".$tbSmsReceiver.",'".date("Y-m-d H:i:s")."')");
					}
				}
				
				function addSms(){
				?>
				<!--添加短信-->
				<FORM action=?act=saddSms method=post>
					<DIV class=table1>
						<UL class=bg3>
						  <LI class=b1>收卡人类型：</LI>
						  <LI class=b2>ID <INPUT type=radio CHECKED value=1 name=rType> &nbsp;&nbsp; 
						  E-mail <INPUT type=radio value=0 name=rType></LI>
						  <LI class=b1>收卡人：</LI>
						  <LI class=b2><INPUT name=tbSmsReceiver class=input170 value=""></LI>
						  <LI class=b1>发卡类型：</LI>
						  <LI class=b2><? cardtypeselect();?></LI>
						  <LI class=b1>发卡数量：</LI>
						  <LI class=b2><INPUT name=tbnum class=input170 value="1"></LI>
						  <LI class=b1></LI>
						  <LI class=b2><INPUT type=image src="images/an_fs_03.gif" border=0></LI>
						</UL>
					</DIV>
				</FORM>
				<?
				}
				?>
			</div>
			<div class="area690-b h5px"></div>
        	<div class="blank10"></div>
		</div>
		<!--主体左边 End-->
	</DIV>
	<!--Flink End-->
	<div class="blank10"></div>
	<!--Footer Start-->
<?php include_once("footer.php");?>
</DIV>