<?php
/*
* ===========================================
* 项目: CTB文本论坛
* 版本: 1.41
* 团队: 实易数码
* 小组: CTB文本论坛小组
* 作者: windnets，16hot，险情
* 功能: 模块调用
* ===========================================
* Copyright (c) 2002
* 团队主页: http://www.11cn.org
* 团队信箱: -------------------
* 创建日期: 2002-4-25
* 修改日期: 2003-4-10
* 修改说明: 代码整理
* 版权声明: 免费软件.
* ===========================================
*/

    header("Content-Language: charset=zh-cn");
    header("Content-type: text/html; charset=GB2312");

//=============================================================================
    $mtime1 = explode(" ", microtime());
    $startTime = $mtime1[1] + $mtime1[0];

//+----------------------------------------------------------------------------
    require_once ("./include/config.php");
    require_once ("./include/CtbClass.php");
    require_once ("./include/CommonClass.php");

    //$set[enableZip] == 'Y' ? ob_start('ob_gzhandler') : ob_start();  // added by cx
//+----------------------------------------------------------------------------
    //设置session保存目录
    session_save_path($set[dataPath]."/tmp");
    if(function_exists(session_cache_limiter)) { 
        session_cache_limiter('nocache');
    //    session_cache_limiter('private, must-revalidate');
    }
    session_start();

//+----------------------------------------------------------------------------
    //获取cookie测试登陆
    if($HTTP_COOKIE_VARS[ctb_user_login] and $HTTP_COOKIE_VARS[ctb_user_pass] and $HTTP_COOKIE_VARS[ctb_login_mode] and !$HTTP_SESSION_VARS[sess_ulogin]){
        $common = new CommonClass;
        $common->set = $set;
        $common->loginFromCookie($HTTP_COOKIE_VARS[ctb_user_login],$HTTP_COOKIE_VARS[ctb_user_pass],$HTTP_COOKIE_VARS[ctb_login_mode]);
    }

//+----------------------------------------------------------------------------
    //防止刷新
    $timeStamp = time();
    $cookieTime = $timeStamp+3153600;
    if($set[refreshLimit] == "Y") {
        if ($timeStamp-$HTTP_COOKIE_VARS['lastvisit_fresh'] < $set[refreshLimitTime]) {
            die('请您不要频繁刷新，谢谢合作。防刷新时间<font color=red>'.$set[refreshLimitTime].'</font>秒');
        }
        setCookie('lastvisit_fresh', $timeStamp, $cookieTime);
    }
    //<<
//+----------------------------------------------------------------------------
    //论坛关闭
    if ($set[boardClose] == "Y") {  //以后要加上可以管理员访问
        $common = new CommonClass;
        $common->wrongPage($set[boardCloseShow],$url="index.php",$turn=0);
    }
    //<<
//+----------------------------------------------------------------------------
    //限制访客访问
    $mods = $HTTP_GET_VARS['mods'] ? $HTTP_GET_VARS['mods'] : $HTTP_POST_VARS['mods'];
    $action = $HTTP_GET_VARS['action'] ? $HTTP_GET_VARS['action'] : $HTTP_POST_VARS['action'];
    if ($set[openLimitGuest] == "Y" and !$HTTP_SESSION_VARS['sess_uid'] and ($mods!="member" or ($action!="login" and $action!="logined" and $action!="register" and $action!="writereg"))) {
        $common = new CommonClass;
        require_once $set[dataPath]."/styles/list.php";
        $usingStyleId = $styles["idDefault"];
        if (is_dir($styles[$usingStyleId]["tplPath"])) {  // 防止后台设置错误
            $common->cssPath = "$set[dataPath]/styles/$usingStyleId.css";;
            $common->tplPath = $styles[$usingStyleId]["tplPath"];
            $common->imgPath = $styles[$usingStyleId]["imgPath"];
        } else {
            die("指定风格的模板存放路径不存在，请联系管理员！");
        }
        $common->showMsgLogin($set[openLimitShow], './index.php');
    }
    //<<

//+----------------------------------------------------------------------------
    //获取get变量
    if( is_array($HTTP_GET_VARS) ) {
        foreach($HTTP_GET_VARS as $k=>$v) {
            if( is_array( $HTTP_GET_VARS[$k]) ) {
                foreach($HTTP_GET_VARS[$k] as $k2=>$v2) {
                    $return[$k][$k2] = $v2;
                }
            } else {
                $return[$k] = $v;
            }
        }
    }
            
    // Overwrite GET data with post data
    if( is_array($HTTP_POST_VARS) ) {
        foreach($HTTP_POST_VARS as $k=>$v) {
            if ( is_array($HTTP_POST_VARS[$k]) ) {
                foreach($HTTP_POST_VARS[$k] as $k2 => $v2) {
                    $return[$k][$k2] = $v2;
                }
            } else {
                $return[$k] = $v;
            }
        }
    }
    //获取数组上传变量
    if( is_array($HTTP_POST_FILES) ) {
        foreach($HTTP_POST_FILES as $k=>$v) {
            if ( is_array($HTTP_POST_FILES[$k]) ) {
                foreach($HTTP_POST_FILES[$k] as $k2 => $v2) {
                    $return[$k][$k2] = $v2;
                }
            } else {
                $return[$k] = $v;
            }
        }
    }

//+----------------------------------------------------------------------------
    //模块调用
    if (!file_exists("./mods/".$mods.".php")) {
        $mods = "main";
    }
    require_once ("./mods/".$mods.".php");
    $ctb = new Module;
    $ctb->input = $return;
    $ctb->sess = isset($HTTP_COOKIE_VARS["sess_uname"]) ? $HTTP_COOKIE_VARS : $HTTP_SESSION_VARS;
    $ctb->set = $set;

//+----------------------------------------------------------------------------
    //记录和校验表单时间
    if ($mods == 'topicdisplay' or ($mods == 'post' and (!$action or $action == 'showpoll' or $action == 'showReply')) or ($mods == 'upload' and $action == 'uploadfile') or ($mods == 'usermgs' and $action == 'sentmgs_htm') or ($mods == 'member' and $action == 'register')) {
        $ctb->formTime = $timeStamp;
        $ctb->setSessionPara('sess_formTime', $ctb->formTime);
    } elseif (($mods == 'post' and ($action == 'posted' or $action == 'reply')) or ($mods == 'upload' and $action == 'douploadfile') or ($mods == 'usermgs' and $action == 'sentmgs_act') or ($mods == 'member' and $action == 'writereg')) {
        if (!$ctb->input['formTime'] or $ctb->input['formTime'] != $ctb->sess['sess_formTime']) {
            unset($ctb->input);
            die('invalid submit!');
        } else {
            $ctb->delSessionPara('sess_formTime');
        }
    }

//+----------------------------------------------------------------------------
    //风格
    require_once $set[dataPath]."/styles/list.php";
    $ctb->styles = $styles;
    if (intval($HTTP_GET_VARS["style"]) and isset($styles[intval($HTTP_GET_VARS["style"])])) {
        setCookie('ctb_styleid', intval($HTTP_GET_VARS["style"]), $cookieTime);
        $usingStyleId = intval($HTTP_GET_VARS["style"]);
    } elseif ($HTTP_COOKIE_VARS["ctb_styleid"] and isset($styles[$HTTP_COOKIE_VARS["ctb_styleid"]])) {
        $usingStyleId = $HTTP_COOKIE_VARS["ctb_styleid"];
    } elseif ($_SESSION["sess_ustyle"] and isset($styles[$_SESSION["sess_ustyle"]])) {
        $usingStyleId = $_SESSION["sess_ustyle"];
    } else {
        $usingStyleId = $styles["idDefault"];
    }
    if (is_dir($styles[$usingStyleId]["tplPath"])) {  // 防止后台设置错误
        $ctb->cssPath = "$set[dataPath]/styles/$usingStyleId.css";;
        $ctb->tplPath = $styles[$usingStyleId]["tplPath"];
        $ctb->imgPath = $styles[$usingStyleId]["imgPath"];
    } else {
        die("指定风格的模板存放路径不存在，请联系管理员！");
    }

//+----------------------------------------------------------------------------
    $ctb->execute();

//=============================================================================

?>