<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | PHP version 5                                                        |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 The PHP Group                                |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available through the world-wide-web at the following url:           |
// | http://www.php.net/license/3_0.txt.                                  |
// | If you did not receive a copy of the PHP license and are unable to   |
// | obtain it through the world-wide-web, please send a note to          |
// | license@php.net so we can mail you a copy immediately.               |
// +----------------------------------------------------------------------+
// | Authors: Original Author <author@example.com>                        |
// |          Your Name <you@example.com>                                 |
// +----------------------------------------------------------------------+
//
// $Id:$

require "Run.php";
if (user('site_reg', 'id', WAPID) == 'no') {
     ehtml('非常抱歉，本站的会员注册功能已经被网站管理员暂时关闭');
    exit;
}
$gro = $_GET['cid'];
echo head('注册会员', $css);
echo '<div class="title">注册本站会员</div>';
if ($_GET['action'] == 'reg') {
	if($_SESSION['check'] != $_POST['check'] || $_SESSION['check'] == NULL)
			{
				ehtml('验证码错误!请重新输入');
				exit();
			}
    //验证注册信息是否完整
    if ($_POST['name'] == "" or $_POST['pass'] == "" or $_POST['nc'] == "") {
        die('用户名、密码、昵称均不能为空！');
    } else {
        if (YZ($_POST['name']) == 4 || YZ($_POST['name']) == 6 || YZ($_POST['name']) == 7) {
        } else {
            die('用户名只能是英文或数字');
        }
        if (YZ($_POST['pass']) == 4 || YZ($_POST['pass']) == 6 || YZ($_POST['pass']) == 7) {
        } else {
            die('密码只能是英文或数字');
        }
        //验证邮箱信息
        if (preg_match('/(.+?)\@(.+?)\.(.+?)/', $_POST['email'])) {
        } else {
            die('请填写正确的邮箱格式！');
        }
        $sql = "SELECT name FROM user WHERE name='{$_POST['name']}' AND site_u='{$wapid}'";
        $logininfo = mysql_query($sql);
        if ($logininfo && mysql_num_rows($logininfo) > 0) {
            die("哎呦，用户名已经被注册了，再换一个吧！");
        }
    }
    //验证用户名是否重复
    function M_D_5($data) {
        $data1 = md5($data);
        $data2 = md5($data1);
        $data3 = md5($data2);
        $data4 = md5($data3);
        $pass_word = strtoupper($data4);
        return $pass_word;
    }
    $D = date('YmdHis');
    $data = $_POST['name'] . $_POST['nc'] . $_POST['pass'] . $D;
    $sid = M_D_5($data);
    $xid = user('qsid', 'id', WAPID) + 1;
    if ($_POST['code'] == $code2) {
        $mysql = new D('user');
        $info['stitle'] = 'NULL';
        $info['name'] = $_POST['name'];
        $info['pass'] = MD5($_POST['pass']);
        $info['nc'] = $_POST['nc'];
        $info['head'] = '/style/nohead.jpg';
        $info['qianm'] = '还木有签名哦';
        $info['email'] = $_POST['email'];
        $info['vip'] = '0';
        $info['admin'] = '0';
        $info['sex'] = $_POST['sex'];
        $info['sid'] = $sid;
        $info['site'] = 'NO';
        $info['xid'] = $xid;
        $info['qsid'] = '1000';
        $info['site_u'] = WAPID;
        $info['crevalue'] = '100';
        $info['time'] = time();
        $info['site_reg'] = '0';
        $info['site_vip'] = '0';
        $info['site_stop'] = '0';
        if ($mysql->insert($info)) {
            mysql_query("UPDATE user SET qsid='{$xid}' WHERE id='".WAPID."'");
            echo "太好了！注册成功!<br>";
            echo "用户名:" . $_POST['name'] . " <br>";
            echo "密码:" . $_POST['pass'] . "<br />";
            echo "昵称:" . $_POST['nc'] . "<br>";
            echo "请妥善保管<br>";
            /*注册成功 发生短信*/
            if (getMessCfg('send') == 'yes') {
                $title = getMessCfg('title');
                $content = getMessCfg('content');
                $user_id = user2('id', $xid, WAPID);
                SendMessage($title, $content, $user_id, NULL, 'system');
            }
            /*Message send end*/
        } else {
            echo "注册失败!请重试或者联系网站管理员！";
        }
    } else {
        echo '<div class="tip">验证码错误咯</div>';
    }
    echo "<a href=\"http://" . HTTP_HOST . "/index.php?cid=" . $_GET['cid'] . "&sid=" . $sid_info . "\">注册完成|<a href=\"http://" . HTTP_HOST . "/login.php?\">前去登录</a>";
} else {
    echo '<div class="content">
<form  action="reg.php?action=reg" method="post">
用户名*:<br>
<input type="text" name="name" value="">
<br>昵称*:<br><input type="text" name="nc" value="">
<br>密码*:<br><input type="text" name="pass" value="">
<br>邮箱(很重要取回密码用)*:<br>
<input type="text" name="email" value=""><br>
性别*:
<select name="sex">
<option value="gg">男</option>
<option value="mm">女</option>

</select>
<br>请输入验证码<br><img src="/include/check.php"><br>
<input value="" name="check" type="text"><br>
<a href="#">[√我同意本站协议]</a>
<br>
<input type="submit" name="g" value="提 交 注 册"><br>
</form>
</div><div class="mylink"><a href="http://' . HTTP_HOST . '/login.php?">返回登录</a>-<a href="index.php?">返回首页</a></div>';
}
echo footer(1);