<?php
if($_POST){
  InitGP(array('S'),'P');
  $pass=md5($S['password2']);
  include_once(ONEZ_ROOT.'/uc_client/client.php');
  if(DB()->rows('users',"username='$S[username]'")>0)jump('error','此用户名已经被注册');
  $uid = uc_user_register($S['username'], $S['password2'], $S['email']);
  if($uid <= 0) {
    if($uid == -1) {
      jump('error','用户名不合法');
    } elseif($uid == -2) {
      jump('error','包含要允许注册的词语');
    } elseif($uid == -3) {
      jump('error','用户名已经存在');
    } elseif($uid == -4) {
      jump('error','Email 格式有误');
    } elseif($uid == -5) {
      jump('error','Email 不允许注册');
    } elseif($uid == -6) {
      jump('error','该 Email 已经被注册');
    } else {
      jump('error','未知错误');
    }
  }
  
  DB()->insert("users",array(
    'uid'=>$uid,
    'username'=>$S['username'],
    'password'=>$pass,
    'email'=>$S['email'],
    'infotime'=>$time,
    'infoip'=>$onlineip,
    'thistime'=>$time,
    'thisip'=>$onlineip,
  ));
		
  $U=DB()->one("users","uid,ismaster","uid='$uid'");
  !$U && jump('error','用户名或密码不正确');
  $uid=$U['uid'];
  $cookie=StrCode("$uid\t$S[username]\t$U[ismaster]","ENCODE");
  _cookie('users',$cookie);
  !$S['jumpurl'] && $S['jumpurl']='?';
  jump('notice','注册成功',$S['jumpurl']);
}
theme_header();
$ot->borderA('#content2','box2');
$ot->addhead('新用户注册');
$ot->addinput('用户名','username','','text',1,"");
$ot->addinput('登录密码','password1','','password',1,"");
$ot->addinput('确认登录密码','password2','','password',1,"",array('to'=>'S[password1]'));
$ot->addinput('电子信箱','email','','text',1,"Email");
$ot->addinput('','jumpurl',$_GET['jumpurl'],'hidden',1,"");
$ot->setform('立即注册');
$ot->borderB(1);
$ot->flush();
theme_footer();
?>