<?php
require '../conn/conn.php';
require '../conn/function.php';

if($C_memberon==0){
    box("会员中心未开放","../","error");
}

$from = $_GET["from"];

if($from==""){
    $from="index.php";
}

$action=$_GET["action"];
$genkey=gen_key(20);
$D_domain=splitx($_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"],"/member",0);

if($action=="reg"){
    $M_login=htmlspecialchars($_POST["M_login"]);
    $M_pwd=$_POST["M_pwd"];
    $M_pwd2=$_POST["M_pwd2"];
    $M_email=htmlspecialchars($_POST["M_email"]);
    $M_qq=htmlspecialchars($_POST["M_qq"]);
    $M_mobile=htmlspecialchars($_POST["M_mobile"]);
    if ($M_pwd!=$M_pwd2){
        box("两次输入密码不一致!","back","error");
    }
    if(($_POST["M_code"]!=$_SESSION["CmsCode"] || $_POST["M_code"]=="" || $_SESSION["CmsCode"]=="") && $C_slide==1){
        die("{\"code\":\"error2\",\"msg\":\"请填写正确的计算结果！\"}");
    } else {
        $_SESSION["CmsCode"]="refresh";
        if ($M_login!="" && $M_pwd!=""){
            if(strpos($C_regr,"email")!==false){
                if (strpos($M_email,"@")===false){
                    box("请输入一个正确格式的邮箱!","back","error");
                }else{
                    if(getrs("select * from sl_member Where M_email='".$M_email."'","M_id")!=""){
                        box("邮箱已被占用!","back","error");
                    }
                }
            }
            if(strpos($C_regr,"mobile")!==false){
                if(getrs("select * from sl_member Where M_mobile='".$M_mobile."'","M_id")!=""){
                    box("手机号已被占用!","back","error");
                }
            }
            if(strpos($C_regr,"qq")!==false){
                if(getrs("select * from sl_member Where M_qq='".$M_qq."'","M_id")!=""){
                    box("QQ已被占用!","back","error");
                }
            }
            if(getrs("select * from sl_member Where M_login='".$M_login."'","M_id")!=""){
                box("用户名已被占用!","back","error");
            }else{
                mysqli_query($conn,"insert into sl_member(M_login,M_pwd,M_email,M_mobile,M_qq,M_head,M_regtime,M_pwdcode,M_openid,M_from,M_shop) values('".$M_login."','".md5($M_pwd)."','".$M_email."','".$M_mobile."','".$M_qq."','head.jpg','".date('Y-m-d H:i:s')."','','',".intval($_SESSION["uid"]).",'".$M_login."')");
                box("注册成功!您可以登录了！","login.php?from=".urlencode($from),"success");
            }
        }else{
            box("请填全信息!","back","error");
        }
    }
}

if($_SESSION["M_login"]!=="" && $_SESSION["M_pwd"]!="" && $_SESSION["M_id"]!="" && $_SESSION["M_pwdcode"]!=""){
    die("<script>window.location.href=\"$from\"</script>");
}
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <title>注册 - <?php echo $C_title?></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
	<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">  
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link href="../media/<?php echo $C_ico?>" rel="shortcut icon" type="image/x-icon" />
    <link rel='stylesheet' type='text/css' href="../css/css/font-awesome.min.css">
	<style type="text/css">
		body{background: #62a8ea}
		.box{max-width: 400px;width: 90%;margin:0 auto;background: #fff;border-radius: 10px;text-align: center;margin-top:10%;padding: 50px;box-shadow: 0 1px 1px rgb(0 0 0 / 5%);}
		.buttons{text-align: center;margin-top: 20px}
	</style>
</head>
<body>
<div class="box">
	<a href="../"><img  src="../media/<?php echo $C_logo?>" style="max-width: 100%"></a>
	<h2 class="h3">会员注册</h2>
	<div style="text-align: left;">
        <?php if($C_regon==1){?>
        <form method="post" class="met-form-validation" action="?action=reg&from=<?php echo urlencode($from)?>">

		<p><input type="text" name="M_login" class="form-control" placeholder="登录账号"></p>
        <?php if(strpos($C_regr,"email")!==false){?>
        <p><input type="text" name="M_email" class="form-control" placeholder="电子邮箱"></p>
        <?php }?>
        <?php if(strpos($C_regr,"mobile")!==false){?>
        <p><input type="text" name="M_mobile" class="form-control" placeholder="手机号码"></p>
        <?php }?>
        <?php if(strpos($C_regr,"qq")!==false){?>
        <p><input type="text" name="M_qq" class="form-control" placeholder="QQ号码"></p>
        <?php }?>
        <p><input type="text" name="M_pwd" class="form-control" placeholder="设置密码"></p>
        <p><input type="text" name="M_pwd2" class="form-control" placeholder="密码确认"></p>

		<?php if($C_slide==1){
            echo "<p>
            ".calculation("M_code")."
            </p>";
        }?>
		<p><button type="submit" class="btn btn-block btn-primary">登录</button></p>
        </form>
        <?php }?>

		<div style="font-size: 12px;color: #AAA;margin-top: 12px;text-align: center;">注册或点击登录代表您同意<a href="../?type=lisence" target="_blank" style="margin-left: 5px;">《用户协议》</a></div>
		<p class="buttons">
            <?php 
            if($C_qqon==1){
                echo "<a href=\"../qq/qqlogin.php?from=".urlencode($from)."\" style=\"width:40px;height:40px;border-radius:100%;text-align:center;background:#0099ff;color:#ffffff;display:inline-block;font-size:20px;padding-top:3px;\"><i class=\"fa fa-qq\"></i></a>";
            }
            if($C_wxon==1){
            	if(isMobile()){
                    echo " <a href=\"".gethttp().$D_domain."/pay/wxpay/login.php?from=".urlencode($from)."&genkey=".$genkey."_".intval($_SESSION["uid"])."\" style=\"width:40px;height:40px;border-radius:100%;text-align:center;background:#009900;color:#ffffff;display:inline-block;font-size:20px;padding-top:3px;vertical-align:top;margin-left:10px;\"><i class=\"fa fa-weixin\"></i></a>";
            	}else{
                    echo " <a href=\"javascript:qrcode();\" style=\"width:40px;height:40px;border-radius:100%;text-align:center;background:#009900;color:#ffffff;display:inline-block;font-size:20px;padding-top:3px;vertical-align:top;margin-left:10px;\"><i class=\"fa fa-weixin\"></i></a>";
            	}
            }
            if($C_dxon==1){
                echo " <a href=\"mobile_login.php?from=".urlencode($from)."\" style=\"width:40px;height:40px;border-radius:100%;text-align:center;background:#ff9900;color:#ffffff;display:inline-block;font-size:25px;padding-top:-10px;vertical-align:top;margin-left:10px;\"><i class=\"fa fa-mobile\"></i></a>";
            }
            ?>
        </p>
        <div id="billImage" style="display: inline-block;margin-bottom: 10px;"></div>
        <p style="font-size: 12px;color: #AAA;text-align: center;">还没有账号? 去 <a href="reg.php?from=<?php echo urlencode($from)?>">注册</a> <a href="forget.php">忘记密码</a> <a href="../">返回首页</a></p>
	</div>
</div>

<script src="../js/qrcode.min.js"></script>
<script type="text/javascript">
function qrcode(){
    $("#buttons").hide();
    var qrcode = new QRCode('billImage', {width: 100,height: 100,colorDark: '#000000',colorLight: '#ffffff',correctLevel: QRCode.CorrectLevel.H});
    qrcode.makeCode("<?php echo gethttp().$D_domain."/pay/wxpay/login.php?genkey=".$genkey."_".intval($_SESSION["uid"])?>");
}
function test(){
$.post("post.php",
    {
      genkey:"<?php echo $genkey."_".intval($_SESSION["uid"])?>",
    },
    function(data){
  if(data==1){
  window.location.href='login.php?from=<?php echo urlencode($from)?>'
  }
    });
}
setInterval("test()",3000); //每3秒钟执行一次test()
</script>
<?php
if(isMobile()){
  $api=$api.'<style>
.tab_bar{position: fixed;bottom: 0px;left: 0px;z-index: 9999;background: #fff;height: 55px;width: 100%;border-top: solid 1px #DDD;padding-top: 5px;font-size: 12px;}
.tab_bar a{color:#333}
.tab_bar .active{color: #ff0000}
.tab_bar img{height: 27px;}
.tab_bar table{width: 100%;}
.tab_bar table tr td{text-align: center;}
.h50{height: 50px;}
</style>

<div class="h50"></div>
<div class="tab_bar">
  <table>
    <tr>
  <td><a class="tab" href="../">
    <img src="https://www.fahuo100.cn/images/tab1.png">
    <div >首页</div>
  </a></td>';

  if($config->course!="false"){
    $api=$api.'<td><a class="tab" href="../?type=course&id=0">
        <img src="https://www.fahuo100.cn/images/tab5.png">
        <div >课程</div>
      </a></td>';
  }

  if($config->news!="false"){
    $api=$api.'<td><a class="tab" href="../?type=news&id=0">
      <img src="https://www.fahuo100.cn/images/tab3.png">
      <div >文章</div>
    </a></td>';
  }

  if($config->product!="false"){
    $api=$api.'<td><a class="tab" href="../?type=product&id=0">
      <img src="https://www.fahuo100.cn/images/tab2.png">
      <div >商品</div>
    </a></td>';
  }

  $api=$api.'<td><a class="tab" href="">
    <img src="https://www.fahuo100.cn/images/tab4_2.png">
    <div class="active">我的</div>
  </a></td>
</tr>
</table>
</div>';
echo $api;
}
?>
</body>
</html>