<?php 
    require "Run.php"; 
	require "include/code.fun.php";
	$gro = $_GET['cid'];
   
	//初始化验证码
	$code = codeRight('1');
	$code2 = codeRight('2');
	
    
	echo head('网站注册');
	echo '<div class="title">注册站长</div>';
if($_GET['action'] == 'reg'){
   if(sys_config('zj_on')=='YES'){
	if($_SESSION['check'] != $_POST['check'] || $_SESSION['check'] == NULL)
			{
				ehtml('验证码错误!请重新输入');
				exit();
			}
//验证注册信息是否完整
    if($_POST['name'] == "" or $_POST['pass'] == "" or $_POST['nc'] == "" or $_POST['qsid']==''){
    die('用户名、密码、昵称、起始ID均不能为空！');
	  }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(YZ($_POST['qsid'])!=6)
	   die('起始ID只能是数字');
	  }
	 if($_POST['qsid']<0){
	   die('起始ID不能小于0'); 
		 }
//验证邮箱信息
 if (!preg_match('/(.+?)\@(.+?)\.(.+?)/',$_POST['email'])) 
 {
    ehtml('请填写正确的邮箱格式！');
	exit;
 }  

//验证用户名位数

if($_POST['urlname'] < sys_config('zj_limit')){
	die('您好，用户名最低为'.sys_config('zj_limit').'位，请重新填写');
}
   
//验证域名是否重复
   $labsurl=$_POST['urlname'].'.'.sys_config('zj_url');

	function urlcf($labsurl){
		$sql="SELECT url FROM urlzf WHERE url='{$labsurl}'";
		$logininfo=mysql_query($sql);
		if($logininfo && mysql_num_rows($logininfo)>0){
		$back=1;
		}else{
			$back=0;
			}
		 return $back;
	  }
	function cssdr($wid/*网站的id*/){
		
		$sql="SELECT cssid,csscn,csscontent,color,site,mr,ver FROM css WHERE site='1000' ORDER BY cssid DESC";  
		
		$result=mysql_query($sql);
		
		if($result && mysql_num_rows($result)>0){
		
		while(list($cssid,$csscn,$csscontent,$color,$site,$if,$drver) = mysql_fetch_row($result)){
		
		$sql = "INSERT INTO css(csscn,csscontent,site,color,mr,ver) VALUES ('{$csscn}', '{$csscontent}', '{$wid}','{$color}','{$if}','{$drver}')";
		
		mysql_query($sql);
			}
		}
	}
	function configdr($wid){
       $sql = "INSERT INTO config(user,wap_top,wap_bottom,index_top,index_bottom,stop,stopTip,ver,suofang,seotitle,keywords,sitecon) VALUES ( '{$wid}', '', '', '[topbar]', '', 'NO', '','2','YES','','免费WAP自助建站,WAP免费自助建站,手机上的IT技术网','免费WAP自助建站，国内知名的手机上的IT技术网')";
       $wapinfo = mysql_query($sql);
        if($wapinfo && mysql_affected_rows()>0){
        }else{
        die('个人网站配置出错，请重试或者联系超级管理员！');
       }
	}
	function urldr($url,$wapid){//注册网站域名转向
	    $sql = "INSERT INTO urlzf(siteid,url,ps,zhuanfa,go_url) VALUES ('{$wapid}','{$url}', 'system','NO','NULL')";
        $url = mysql_query($sql);	
	    if($url && mysql_affected_rows()>0){
	    }else{
	   die('系统内部错误，域名信息没有成功提交给系统，注册失败');
	   }
	}
if(urlcf($labsurl)==0){
 
//注册会员；
       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 = time();
	$data=$_POST['name'].$_POST['nc'].$_POST['pass'].$D;
	$sid  = M_D_5($data);
	//添加用户记录至数据库
	$mysql = new MySql;
	$info['stitle']    =    $_POST['stitle'];;
	$info['name']      =    $_POST['name'];
	$info['pass']      =    MD5($_POST['pass']);
	$info['nc']        =    $_POST['nc'];
	$info['head']      =    'http://".HTTP_HOST."/style/nohead.jpg';
	$info['qianm']     =    '还木有签名哦';
	$info['email']     =    $_POST['email'];
	$info['vip']       =    '0';
	$info['admin']     =    '0';
	$info['sex']       =    $_POST['sex'];
	$info['sid']       =    $sid;
	$info['site']      =    'YES';
	$info['xid']       =    $xid;
	$info['qsid']      =    '1000';
	$info['site_u']    =    $_POST['urlname'];
	$info['crevalue']  =    '100';
	$info['time']      =    time();
	$info['site_reg']  =    '0';
	$info['site_vip']  =    '0';
	$info['site_stop'] =    '0';
	if($mysql->sqlinsert($info,'user')){
	//搜索用户记录
	$sql="SELECT id,name,site_u,time FROM user WHERE name='{$_POST['name']}' AND site_u='{$_POST['urlname']}'";
	$userjl = mysql_query($sql);
    if($userjl && mysql_num_rows($userjl)>0){
	list($wid,$wname,$wsite_u,$wtime) = mysql_fetch_row($userjl);
	//修改用户记录的所属网站值
	mysql_query("UPDATE user SET site_u='{$wid}' WHERE id='{$wid}'");
	}
	//导入域名数据到数据库
	urldr($labsurl,$wid);
	//创建配置文件	
    configdr($wid); 
	//导入默认CSS
    cssdr($wid);
    echo '<font color="red"><u><b>恭喜你！注册成功！</b></u></font><br>';
    echo "用户名:".$_POST['name']."<br>";
	echo "密码:".$_POST['pass']."<br>";
	echo "昵称:".$_POST['nc']."<br>";
	echo "请妥善保管";	
	echo "<a href=\"http://".$labsurl."\">进入我的网站并登陆</a><br>";
	}else{
	echo "注册失败!请重试或者联系网站管理员！";
	}
	    echo "<div class=\"mylink\"><a href=\"index.php?cid=".$_GET['cid']."&sid=".$sid_info."\">注册完成返回</a></div>";
	    mysql_close($link);
		}else{
		   echo '<div class="tip">您好，您要注册的URL已经被注册喽，快去试一试别的吧！</div>';
				}
		}else{
		    echo '<div class="tip">您好，子站注册功能已经关闭！</div>';
		}
      
    }else{
    echo'
    <div class="content">
    <form name="f" action="wapsitereg.php?action=reg&" method="post">
    您的域名[最低'.sys_config('zj_limit').'位字符]:<br>
    <input type="text" name="urlname" value=""/>.'.sys_config('zj_url').'<br>
	用户名*:<br>
    <input type="text" name="name" value="admin"/><br>
    网站名称*:<br><input type="text" name="stitle" value="">
    <br>昵称*:<br><input type="text" name="nc" value="admin">
    <br>密码*:<br><input type="text" name="pass" value="">
    <br>起始ID*:<br><input type="text" name="qsid" value="1000">
    <br>邮箱(很重要取回密码用)*:<br>
    <input type="text" name="email" value="@qq.com"><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>
    <input type="submit" name="g" value="提 交 注 册"/></form>
    </div><div class="mylink"><a href="login.php?">返回登录</a>-<a href="index.php?">返回首页</a></div>';
   }
   echo footer(1);
?>