<?php
define('LANG_PATH', 'langs/');
setLanguage();

QUnit_Global::includeClass('QCore_Login');

QUnit_Global::includeClass('Affiliate_PZone_Views_MainPage');
class Affiliate_PZone_Views_Login extends Affiliate_PZone_Views_MainPage
{

    public $qcore_login;

    function Affiliate_PZone_Views_Login() {
        $this->qcore_login = QUnit_Global::newObj('QCore_Login');
        $this->qcore_login->user_type = USERTYPE_USER;
        parent::__construct();
    }

    //------------------------------------------------------------------------

    function process()
    {

        if($GLOBALS['Auth']->logged) {
            header("LOCATION: affiliates/index.php");
            exit;   //must be...
        }

        if(!empty($_REQUEST['action']))
        {
            switch($_REQUEST['action'])
            {
                case 'login':
                    if($this->qcore_login->processLogin())
                        $this->assign('login_status', true);
                break;
            }
        }

        //重新捕获消息
        $GLOBALS['errorMessages'] = $this->qcore_login->errorMessages;

        $this->showLogin();

        $this->assign('p_title', L_G_AFFLOGINFORM);

        $this->assignData();
        $this->addContent('header');
        $this->addContent('login');
        $this->addContent('footer');
    }

    //--------------------------------------------------------------------------

    function showLogin()
    {
        $_POST['action'] = 'login';

/*        $accounts_data = QUnit_Global::newobj('QCore_RecordSet');
        $accounts_data->setTemplateRS(QCore_Bl_Accounts::getAccountsAsArray());

        $this->assign('a_accounts_data', $accounts_data);*/

        $list_data = QUnit_Global::newobj('QCore_RecordSet');
        $list_data->setTemplateRS(QCore_Settings::getAvailableLangs());

        $this->assign('a_list_data', $list_data);

        switch($this->qcore_login->user_type) {
            case USERTYPE_USER:
                $caption = L_G_AFFILIATELOGIN;
                break;
            case USERTYPE_ADMIN:
                $caption = L_G_MERCHANTLOGIN;
                break;
            case USERTYPE_SUPERADMIN:
                $caption = L_G_SUPERADMINLOGIN;
                break;
            default:
                $caption = L_G_LOGIN;
                break;
        }
        $this->assign('a_caption', $caption);

        $displayAccountId = true;
        if($accountId = $GLOBALS['Auth']->getAccountID()) {
            $this->assign('accountId', $accountId);
            $displayAccountId = false;
        }

        $this->assign('displayAccountId', $displayAccountId);
    }

}
?>
