<?php
/**
* 后台控制面板
* @author moufer<moufer@163.com>
* @package modoer
* @copyright Moufer Studio(www.modoer.com)
* @version $Id: admincp.php 2 2007-10-11 11:43:54 $
*/

define('IN_ADMIN', TRUE);
define('SCRIPTNAV', 'admincp');

session_start();

require_once './include/common.inc.php';
require_once MUDDER_ROOT.'./include/cache.func.php';
require_once MUDDER_ROOT.'./admin/include/fun_common.php';
require_once MUDDER_ROOT.'./admin/menus.inc.php';

$cpaccess = $admin->access;
//++操作记录

$action = !empty($action) && is_string($action) ? trim($action) : '';

if($cpaccess == 0 ) {
    !$adminlogin && cploginmsg('','admincp.php','login');
    if($adminlogin) {
        if($_seccode['adminlogin'] && ($_DCOOKIE['seccode'] != formhash(strtolower($seccode),'',''))) {
            redirect('验证码错误！请返回修改。');
        }
        $admin_name = trim($admin_name);
        $admin_password = trim($admin_password);
        if($admin_name && $admin_password) {
            if(!$admin->Login($admin_name,$admin_password)) {
                cploginmsg('', 'admincp.php', 'login');
            } else {
                cploginmsg('正在登录，请稍后...', 'admincp.php');
                echo "<meta http-equiv=refresh content=\"0;URL=admincp.php\">";
                exit;
            }
        }
    }

} elseif($cpaccess == 1) {

    if($action == 'logout') {
        $admin->Logout();
        cploginmsg('', 'admincp.php', 'login');
    }

    if(!$admin_password || (md5($admin_password) != $admin->password)) {
        if($admin_password) {
            //+++登录错误日志
        }
        cploginmsg('', 'admincp.php', 'login');
    } else {
        $db->query("UPDATE {$dbpre}adminsessions SET errorcount='-1' WHERE adminid='{$admin->id}'");
        cploginmsg('正在登录，请稍后...', 'admincp.php');
        echo "<meta http-equiv=refresh content=\"0;URL=admincp.php\">";
        exit;
    }

} elseif($cpaccess == 2) {

    cploginmsg('IP无权限登录。');

}

if(empty($action) || isset($frames)) {
	parse_str($_SERVER['QUERY_STRING'], $getarray);
	$extra = $and = '';
	foreach($getarray as $key => $value) {
		if($key == 'action' && in_array($value, array('header', 'menu'))) {
			$extra .= $and.$key.'=home';
		} elseif(!in_array($key, array('sid', 'frames'))) {
			@$extra .= $and.$key.'='.rawurlencode($value);
			$and = '&';
		}
	}
    $extra = $extra && $action ? $extra : 'action=home';
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title>Modoer Administrator's Control Panel</title>
<meta http-equiv="Content-Type" content="text/html; charset=<?=$charset?>">
</head>
<body style="margin: 0px" scroll="no">
<div style="position: absolute;top: 0px;left: 0px; z-index: 2;height: 65px;width: 100%">
<iframe frameborder="0" id="header" name="header" src="admincp.php?action=header" scrolling="no" style="height: 65px; visibility: inherit; width: 100%; z-index: 1;"></iframe>
</div>
<table border="0" cellPadding="0" cellSpacing="0" height="100%" width="100%" style="table-layout: fixed;">
<tr><td width="180" height="65"></td><td></td></tr>
<tr>
<td><iframe frameborder="0" id="menu" name="menu" src="admincp.php?action=menu&tab=$tab" scrolling="yes" style="height: 100%; visibility: inherit; width: 100%; z-index: 1;overflow: auto; "></iframe></td>
<td><iframe frameborder="0" id="main" name="main" src="admincp.php?<?=$extra?>" scrolling="yes" style="height: 100%; visibility: inherit; width: 100%; z-index: 1;overflow: auto;"></iframe></td>
</tr></table>
</body>
</html>
<?
    cpoutput();
}
if($action == 'menu') {

	require_once MUDDER_ROOT.'admin/menu.inc.php';

} elseif($action == 'header') {

	require_once MUDDER_ROOT.'admin/header.inc.php';

} elseif($action == 'logout') {

    $admin->Logout();
    cploginmsg('退出完毕！','./index.php');

} else {

    if($action == 'home') {
        $cpage = 'home';
    } elseif(in_array($action,array('modoer'))) {
        $cpage = 'modoer';
    } elseif(in_array($action,getModulekeys())) {
        $cpage = 'modules';
    } elseif(in_array($action,getPluginkeys())) {
        $cpage = 'plugins';
    }

	if($cpage) {
        cpheader();
		require_once MUDDER_ROOT.'./admin/'.$cpage.'.inc.php';
	} else {
		redirect('权限不足。'.$action,'#');
	}
	if($action != 'menu' && $action != 'header') {
		cpfooter();
	}
}
cpoutput();
?>