<?php
require_once 'include/contain.class.php';
if (isset($_COOKIE['login_auth'])) {
    list($User_uid, $User_username) = explode("\t", uc_authcode($_COOKIE['login_auth'], 'DECODE'));
    $tem_url_return = $lang[system][url_return][index];
    $state = $lang[system][login]['success'];
    $style->display('login/status.html');
} else {
    if ($_GET['m'] == 'user' and $_GET['a'] == 'reg') {
        $_admincp_power[allowreg] = mysql_fetch_array(mysql_query("SELECT * FROM " . $table . "admincp_power
WHERE name='allowreg'"));
        if ($_admincp_power[allowreg][power] == 'yes') {
            if ($_POST['password'] == $_POST['password2']) {
                $uid = uc_user_register($_POST['username'], $_POST['password'], $_POST['email']);
                if ($uid > 0) {
                    $get = mysql_query("SELECT * FROM " . $table . "members 
WHERE `uid`='" . $uid . "'", $con);
                    $unum = mysql_num_rows($get);
                    $_admincp_power[maxqq] = mysql_fetch_array(mysql_query("SELECT * FROM " . $table . "admincp_power
WHERE name='initialmaxqq'"));
                    $_admincp_power[group] = mysql_fetch_array(mysql_query("SELECT * FROM " . $table . "admincp_power
WHERE name='initialgroup'"));
                    $_admincp_power[integral] = mysql_fetch_array(mysql_query("SELECT * FROM " . $table . "admincp_power
WHERE name='initialintegral'"));
                    $_initialmaxqq = $_admincp_power[maxqq][power];
                    $_initialintegral = $_admincp_power[integral][power];
                    $_initialgroup = $_admincp_power[group][power];
                    if ($unum == 0) {
                        $in = mysql_query("INSERT INTO " . $table . "members (uid,user,largest,`group`,integral,noticeqq,`status`) VALUES ('" . $uid . "','" . $_POST['username'] . "','" . $_initialmaxqq . "','$_initialgroup','$_initialintegral','0','1')", $con);
                        echo mysql_error();
                    } else {
                        $in = mysql_query("DELETE FROM {$table}members
WHERE uid='$uid'", $con);
                        $in = mysql_query("INSERT INTO " . $table . "members (uid,user,largest,`group`,integral,noticeqq,`status`) VALUES ('" . $uid . "','" . $_POST['username'] . "','" . $_initialmaxqq . "','$_initialgroup','$_initialintegral','0','1')", $con);
                        echo mysql_error();
                    }
                    setcookie('login_auth', uc_authcode($uid . "\t" . $_POST['username'], 'ENCODE') , $_POST['cookietime']);
                    $ucsynlogin = uc_user_synlogin($uid);
                    $tem_url_return = $lang[system][url_return][index];
                    $state = $lang[system][reg]['success'];
                } elseif ($uid == - 1) {
                    $tem_url_return = $lang[system][url_return][reg];
                    $state = $lang[system][reg]['error'];
                } elseif ($uid == - 2) {
                    $tem_url_return = $lang[system][url_return][reg];
                    $state = $lang[system][reg]['worderror'];
                } elseif ($uid == - 3) {
                    $tem_url_return = $lang[system][url_return][reg];
                    $state = $lang[system][reg]['alreadyin'];
                } elseif ($uid == - 4) {
                    $tem_url_return = $lang[system][url_return][reg];
                    $state = $lang[system][reg]['emailerror'];
                } elseif ($uid == - 5) {
                    $tem_url_return = $lang[system][url_return][reg];
                    $state = $lang[system][reg]['emailnotallow'];
                } elseif ($uid == - 6) {
                    $tem_url_return = $lang[system][url_return][reg];
                    $state = $lang[system][reg]['emailalreadyin'];
                } else {
                    $tem_url_return = $lang[system][url_return][reg];
                    $state = $lang[system][reg]['false'];
                }
                $style->display('login/status.html');
            } else {
                $tem_url_return = $lang[system][url_return][reg];
                $state = $lang[system][reg]['passworderror'];
                $style->display('login/status.html');
            }
        }
        else{
            $tem_url_return = $lang[system][url_return][index];
            $state = $lang[system][reg]['noallowreg'];
            $style->display('login/status.html');
        }
    } else if (!empty($_GET['token'])) {
        /*if(!empty($_GET['bind'])){
            //header("location:http://open.denglu.cc/transfer/qzone"."?appid=".DL_APPID."&uid=1");
            exit();
        }*/
        $api = new Denglu(DL_APPID, DL_APIKEY, 'utf-8');
        try {
            $userInfo = $api->getUserInfoByToken($_GET['token']);
            $state = print_r($userInfo);
            $style->display('login/status.html');
        }
        catch(DengluException $e) { //获取异常后的处理办法(请自定义)
            $tem_url_return = $lang[system][url_return][login];
            $state = '错误编号:' . $e->geterrorCode(); //返回错误编号
            $state.= '<br>错误信息:' . $e->geterrorDescription(); //返回错误信息
            $style->display('login/status.html');
        }
    } else {
        $style->display('registra.html');
    }
}
