<?php session_start();	include_once("conn/conn.php");
if ($_GET[name]!="" and $_GET[pass]!=""){				//激活注册用户
	//$self=$_SERVER['HTTP_REFERER'];
	$u=$_SERVER['HTTP_HOST'];
	$r=$_SERVER['PHP_SELF'];
	$l=$_SERVER['QUERY_STRING'];
	$url="http://"."$u"."$r"."?"."$l";
	$querys=mysql_query("select * from tb_voter where tb_voter_activation='$url'");
	if (mysql_num_rows($querys)>0){
		$queryes=mysql_query("update tb_voter set tb_voter_type='1' where tb_voter_activation='$url' ");
		echo "<script>alert('用户激活成功！');window.location.href='index.php';</script>";
	}else{
		echo "<script>alert('用户激活失败！');window.location.href='register.php';</script>";
	}
}

if ($submit=="提交注册信息"){					//处理注册用户提交的数据
	//$self=$_SERVER['HTTP_REFERER'];
	$u=$_SERVER['HTTP_HOST'];
	$r=$_SERVER['PHP_SELF'];
	$l="name=".md5($_POST[tb_voter_name])."&&"."pass=".md5($_POST[tb_voter_pass]);
	$url="http://"."$u"."$r"."?"."$l";

	$tb_voter_name=trim($_POST[tb_voter_name]);
	$tb_voter_pass=md5($_POST[tb_voter_pass]);
	$tb_voter_mail=trim($_POST[tb_voter_mail]);
	$tb_voter_tel=trim($_POST[tb_voter_tel]);
	$tb_voter_address=trim($_POST[tb_voter_address]);
	$tb_voter_activation=$url;
	$tb_voter_ip=getenv("REMOTE_ADDR");
	$tb_voter_type="0";
	$query=mysql_query("insert into tb_voter(tb_voter_name,tb_voter_pass,tb_voter_mail,tb_voter_tel,tb_voter_address,tb_voter_activation,tb_voter_ip,tb_voter_type) values('$tb_voter_name','$tb_voter_pass','$tb_voter_mail','$tb_voter_tel','$tb_voter_address','$tb_voter_activation','$tb_voter_ip','$tb_voter_type')",$conn);
	if($query==true){ 
		session_register("tb_voter_name");
		session_register("tb_voter_mail");
		session_register("tb_voter_activation");	

		//发送邮件，用于激活注册码
		$subject="激活码的获取";
		$mailbody="欢迎您参与投票，您的激活码是："."<a href='$url'>$url</a>"."<br>"."请在IE中输入上述地址，激活您的用户！";
		$envelope["from"]="spcn@www.spcn.com";
		$part1["type"] = TYPEMULTIPART;
		$part1["subtype"] = "mixed";
		$part2["type"] = TYPETEXT;
		$part2["subtype"] = "plain";
		$part2["encoding"] = ENCBINARY;
		$part2["contents.data"] = "$mailbody\n\n\n\t";
		$body[1] = $part1;
		$body[2] = $part2;
		$message=imap_mail_compose($envelope, $body);
		$to="$tb_voter_mail";
		list($msgheader,$msgbody)=split("\r\n\r\n",$message,2);
		$sendes=@imap_mail($to,$subject,$msgbody,$msgheader);
	if($sendes==true){
		echo "<script>alert('注册成功，请到您的邮箱中获取激活码！');window.location.href='index.php';</script>";
}else{
  		echo "<script language='javascript'>alert('您输入的邮箱地址不正确!');history.back();</script>"; 
}
	}else{
  		echo "<script language='javascript'>alert('对不起,注册失败!');history.back();</script>"; 
  	exit;
	}
}
?>