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


if($C_regon==0){
    die("<script>alert(\"管理员未开启注册！\");history.back();</script>");
}

$from = $_GET["from"];
$action=$_GET["action"];

if($action=="reg"){
    $M_login=$_POST["M_login"];
    $M_pwd=$_POST["M_pwd"];
    $M_pwd2=$_POST["M_pwd2"];
    $M_email=removexss($_POST["M_email"]);
    $M_qq=removexss($_POST["M_qq"]);
    $M_mobile=removexss($_POST["M_mobile"]);
    if ($M_pwd!=$M_pwd2){
        box("两次输入密码不一致!","back","error");
    }
    if(xcode($_POST["M_code"],'DECODE',$_SESSION["CmsCode"],0)!=$_SESSION["CmsCode"] || $_POST["M_code"]=="" || $_SESSION["CmsCode"]==""){
        box("请重新拖动滑块进行验证！", "back", "error");
    } 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(getrs("select * from sl_member Where M_login='".$M_login."'","M_id")!=""){
                box("用户名已被占用!","back","error");
            }else{
                mysqli_query($conn,member("reg",$_POST));
                box("注册成功!您可以登录了！","login.php?from=".urlencode($from),"success");
            }
        }else{
            box("请填全信息!","back","error");
        }
    }
}

if($_SESSION["M_login"]!=="" && $_SESSION["M_pwd"]!="" && $_SESSION["M_id"]!=""){
    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}
        .form-control{border:none;border-bottom: solid 1px #DDD;border-radius: 0px;-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,0);
    box-shadow: inset 0 1px 1px rgba(0,0,0,0);
    -webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;}
        p{margin-top: 30px}
    </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;">
        <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>
        <p><input type="text" name="M_email" class="form-control" placeholder="电子邮箱"></p>
        <p><input type="text" name="M_pwd" class="form-control" placeholder="设置密码"></p>
        <p><input type="text" name="M_pwd2" class="form-control" placeholder="密码确认"></p>
        <p><iframe id="slide" src="../conn/code_1.php?name=M_code" scrolling="no" frameborder="0" width="100%" height="40"></iframe></p>
        <p><button type="submit" class="btn btn-block btn-primary">登录</button></p>
        </form>
        <p style="font-size: 12px;color: #AAA;text-align: center;">已有账号? 去 <a href="login.php?from=<?php echo urlencode($from)?>">登录</a> <a href="forget.php">忘记密码</a> <a href="../">返回首页</a></p>
    </div>
</div>
</body>
</html>