<?php

/**
 * ErrorController
 * Feel free to change this and customize your own error message
 *
 * @author darkredz
 */
class ErrorController extends DooController {

    public $data;

    function __construct() {
        $this->data['rootUrl'] = Doo::conf()->APP_URL;
        $this->data['rootUrl_JS'] = Doo::conf()->APP_JS_URL;
        $this->data['rootUrl_IMG'] = Doo::conf()->APP_IMG_URL;
        $this->data['rootUrl_CSS'] = Doo::conf()->APP_CSS_URL;
        $this->theme = Doo::conf()->APP_THEME;
    }

    function defaultError() {
        $this->data['title'] = '';
        $this->data['content'] = '<p>ERROR 404 not found</p>';
        $this->render($this->theme.'error', $this->data);
    }

// 未登录提示
    function loginError() {
        $this->data['title'] = '';
        $this->data['content'] = '<p style="color:#ff0000;">请登录后操作!2秒后跳转登陆</p>';
        header('refresh:2;url=' . Doo::conf()->APP_URL . 'login');
        $this->render($this->theme.'error', $this->data);
    }

// 已登录
    function IsloginError() {
        $this->data['title'] = '';
        $this->data['content'] = '<p style="color:#ff0000;">已经登陆无需重复操作!2秒后跳转个人信息页</p>';
        header('refresh:2;url=' . Doo::conf()->APP_URL . 'profile');
        $this->render($this->theme.'error', $this->data);
    }

// 激活邮箱缺少参数
    function ActEmailError() {
        $this->data['title'] = '';
        $this->data['content'] = '<p style="color:#ff0000;">错误!2秒后跳转登陆页</p>';
        header('refresh:2;url=' . Doo::conf()->APP_URL . 'login');
        $this->render($this->theme.'error', $this->data);
    }

// 账户已经激活
    function activeUser() {
        $this->data['title'] = '';
        $this->data['content'] = '<p style="color:#ff0000;">已经激活，无需重复操作!2秒后跳转登陆页</p>';
        header('refresh:2;url=' . Doo::conf()->APP_URL . 'profile');
        $this->render($this->theme.'error', $this->data);
    }

// 激活邮件
    function isact() {
        $this->data['title'] = '';
        $this->data['content'] = '<p style="color:#ff0000;">激活邮件已经发送，请查收!2秒后跳转登陆页</p>';
        header('refresh:2;url=' . Doo::conf()->APP_URL . 'profile');
        $this->render($this->theme.'error', $this->data);
    }

// 邮箱与当前相同
    function userdemail() {
        $this->data['title'] = '';
        $this->data['content'] = '<p style="color:#ff0000;">此邮箱已存在，请更换其他邮箱!2秒后跳转登陆页</p>';
        header('refresh:2;url=' . Doo::conf()->APP_URL . 'nactchm');
        $this->render($this->theme.'error', $this->data);
    }

// 邮箱与当前相同
    function erroremail() {
        $this->data['title'] = '';
        $this->data['content'] = '<p style="color:#ff0000;">邮箱格式不正确!2秒后跳转登陆页</p>';
        header('refresh:2;url=' . Doo::conf()->APP_URL . 'nactchm');
        $this->render($this->theme.'error', $this->data);
    }

// 登陆跳转充值页面
    function loginandforwardtodeposit() {
        $this->data['title'] = '';
        $this->data['content'] = '<p style="color:#ff0000;">即将跳转充值页面...</p>';
        header('refresh:2;url=' . Doo::conf()->APP_URL . 'deposit');
        $this->render($this->theme.'error', $this->data);
    }

// 登陆跳转充值页面
    function logout() {
        $this->data['title'] = '';
        $this->data['content'] = '<p style="color:#ff0000;">登出成功.</p>';
        header('refresh:2;url=' . Doo::conf()->APP_URL . 'login');
        $this->render($this->theme.'error', $this->data);
    }

    /**
     * Prepare sidebar data, random tags and archive list
     */
    private function prepareSidebar() {

        //if tags cache exist, skip retrieving from DB, expires every 5 minutes
        $cacheTagOK = Doo::cache('front')->testPart('sidebarTag', 300);
        if (!$cacheTagOK) {
            echo '<h2>Cache expired. Get Tags from DB!</h2>';
            //get random 10 tags
            Doo::loadModel('Tag');
            $tags = new Tag();
            $this->data['randomTags'] = $tags->limit(10, null, null, array('custom' => 'ORDER BY RAND()'));
        } else {
            $this->data['randomTags'] = array();
        }

        //if archive cache exist, skip retrieving from DB, archive expires when Post added, updated, deleted
        $cacheArchiveOK = Doo::cache('front')->testPart('sidebarArchive', 31536000);
        if (!$cacheArchiveOK) {
            echo '<h2>Cache expired. Get Archives from DB!</h2>';
            //you can pass data to constructor to set the Model properties
            Doo::loadModel('Post');
            $p = new Post(array('status' => 1));
            $this->data['archives'] = $p->getArchiveSummary();
        } else {
            $this->data['archives'] = array();
        }
    }

// 登陆跳转充值页面
    function username() {
        $this->data['title'] = '';
        $this->data['content'] = '<p style="color:#ff0000;">用户名只能包含中文、字母大小写与数字</p>';
        header('refresh:2;url=' . Doo::conf()->APP_URL . 'reg');
        $this->render($this->theme.'error', $this->data);
    }

// 激活用户失败
    function actUserError() {
        $this->data['title'] = '';
        $this->data['content'] = '<p style="color:#ff0000;">激活用户失败</p>';
        header('refresh:2;url=' . Doo::conf()->APP_URL);
        $this->render($this->theme.'error', $this->data);
    }
// 用户已经激活
    function actived() {
        $this->data['title'] = '';
        $this->data['content'] = '<p style="color:#ff0000;">用户已经激活</p>';
        header('refresh:2;url=' . Doo::conf()->APP_URL . 'login');
        $this->render($this->theme.'error', $this->data);
    }
// 重新登录
    function relogin() {
        $this->data['title'] = '';
        $this->data['content'] = '<p style="color:#ff0000;">修改成功，请重新登陆</p>';
        header('refresh:2;url=' . Doo::conf()->APP_URL . 'login');
        $this->render($this->theme.'error', $this->data);
    }

// 重新登录
    function emailerror() {
        $this->data['title'] = '';
        $this->data['content'] = '<p style="color:#ff0000;">发送成功，请按邮件提示进行操作！</p>';
        header('refresh:2;url=' . Doo::conf()->APP_URL . 'profile');
        $this->render($this->theme.'error', $this->data);
    }

// 手机注册验证码过期或出错
    function mobilereg() {
        $this->data['title'] = '';
        $this->data['content'] = '<p style="color:#ff0000;">验证码过期或不一致，请重新获取</p>';
        header('refresh:2;url=' . Doo::conf()->APP_URL . 'login');
        $this->render($this->theme.'error', $this->data);
    }
// 手机注册验证码过期或出错
    function hadmobile() {
        $this->data['title'] = '';
        $this->data['content'] = '<p style="color:#ff0000;">该手机号码已注册</p>';
        header('refresh:2;url=' . Doo::conf()->APP_URL . 'login');
        $this->render($this->theme.'error', $this->data);
    }
// 密码出错
    function mimaerror() {
        $this->data['title'] = '';
        $this->data['content'] = '<p style="color:#ff0000;">请确认密码是否正确</p>';
        header('refresh:2;url=' . Doo::conf()->APP_URL . 'login');
        $this->render($this->theme.'error', $this->data);
    }
// 手机找回密码成功
    function repwdmobile() {
        $this->data['title'] = '';
        $this->data['content'] = '<p style="color:#ff0000;">找回密码成功，请重新登陆</p>';
        header('refresh:2;url=' . Doo::conf()->APP_URL . 'login');
        $this->render($this->theme.'error', $this->data);
    }

// 添加手机
    function addmobile() {
        $this->data['title'] = '';
        $this->data['content'] = '<p style="color:#ff0000;">添加手机成功！2秒后跳转个人页</p>';
        header('refresh:2;url=' . Doo::conf()->APP_URL . 'profile');
        $this->render($this->theme.'error', $this->data);
    }

}

?>