<?php
require_once(dirname(__FILE__)."/admin_inc.php");
/*******************************************************************************************
' Software name: DJCMS Content Management System
' Version:3.0
' Web: http://www.djcms.net
' Author: 心情(qq:1130731)
' Copyright (C) 2009-2010 DJCMS官方 版权所有
' 法律申明：DJCMS程序所有代码100%原创、未引入任何网上代码,对一切抄袭行为、坚决严肃追究法律责任
'*******************************************************************************************/
$action = getForm("action", "get");
switch ($action) {
	case "login" : login();break;
	case "check" : checkLogin();break;
	case "logout" : clearPower();break;
	case "notice" : notice();break;
	default : main();break;
}

function getCurrVersion() {
	global $updateUrl;
	$xml = new DOMDocument(); 
    // 加载Xml文件 
    $xml->load("imgs/version.xml");
	$CurrVersion = $xml->getElementsByTagName("version")->item(0)->nodeValue;
	echo "<script type=\"text/javascript\">var DJCMSVERSION='".$CurrVersion."',BACKMSG='False';function backcall(){window.setTimeout(function (){checkNewVersionCallBack({responseText:BACKMSG})},1000)}</script>\n<script language=\"javascript\" src=\"".$updateUrl."/djcmsver2.5.js?t=".microtime()."\" charset=\"gbk\"></script>\n<script type=\"text/javascript\">backcall();</script>";
}

function notice(){
	checkPower();
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>后台管理中心-DjCms</title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<link href="imgs/admin.css" rel="stylesheet" type="text/css" />
<script src="../js/common.js" type="text/javascript"></script>
<script src="imgs/main.js" type="text/javascript"></script>
<script src="imgs/drag.js" type="text/javascript"></script>
</head>
<body>
<div class="container" id="cpcontainer">
<script type="text/JavaScript">if(parent.$('admincpnav')) parent.$('admincpnav').innerHTML='后台首页';</script>

    <table class="tb">
    	<tr class="thead"><td colspan="4">升级信息</td></tr>
    	<tr><td colspan="4"><div style="float:left">当前使用版本：<script language="javascript" src="imgs/version.js"></script>&nbsp;&nbsp;</div><?php if (getcookie("m_level")==0){ ?><div id="update"><font color='red'>请稍等，正在检测新版本...</font></div><?php }else{?>暂无升级信息<?php }?></td></tr>
        <tr class="thead"><td colspan="4">站点信息</td></tr>
        <tr>
            <td width="135">服务器类型：</td><td width="391"><?=PHP_OS?>(IP:<?php
																  $netscapeftp = gethostbynamel($_SERVER['SERVER_NAME']); 
                                                                   echo $netscapeftp[0]; 
																  ?>)</td>
            <td width="138">脚本解释引擎：</td><td width="499"><?php echo $_SERVER["SERVER_SOFTWARE"];?></td>
        </tr>
        <tr>
            <td>站点物理路径：</td><td><?=DJ_ROOT?></td>
            <td>服务器名：</td><td><?=$_SERVER['SERVER_NAME']?></td>
        </tr>
        <tr>
            <td>PHP版本：</td><td><?php echo @phpversion(); ?></td>
            <td>其它必须函数检测：</td><td><?php
          $needfunc = array('dir','phpinfo');
          $n = 0;
          foreach ($needfunc as $k) {
          	  if (!function_exists($k)) {
          		  echo "<font color='red'>[{$k}×]</font> ";
          		  $n++;
          	  }
          }
          if ($n == 0) {
          	  echo "符合要求";
          } else {
          	  echo "被禁用的函数可能导致部份功能无法使用！";
          }
       ?></td>
        </tr>
		<tr>
            <td>是否安全模式：</td><td><?php echo ((boolean) ini_get('safe_mode') ? 'On' : 'Off')?></td>
            <td>Register_Globals：</td><td><?php echo ini_get("register_globals") ? 'On' : 'Off'?></td>
        </tr>
			<tr>
            <td>Magic_Quotes_Gpc ：</td><td><?php echo ini_get("magic_quotes_gpc") ? 'On' : 'Off'?></td>
            <td>是否允许打开远程连接：</td><td><?php echo ini_get("allow_url_fopen") ? '支持' : '不支持'?></td>
        </tr>
        <tr>
            <td>最后更新人气：</td>
			<td><script language="javascript" src="imgs/last_clear_lock.js?<?=microtime()?>"></script>
				<script language="javascript">
				var x=window.HitLastUpdateTime,d=new Date();
					if(!x){
						document.write('从未更新');
						(new Image()).src='admin_ajax.php?action=cleartophit&do=d';
					}else{
						var ld=new Date(x),ad=parseInt((d.getTime()-ld.getTime()) / 84000000);
						document.write(ld.toLocaleString());
						if(ld.toLocaleDateString()!=d.toLocaleDateString()){
							(new Image()).src='admin_ajax.php?action=cleartophit&do=d'+(ld.getDay()==0 || ad>7 ? 'w' : '')+(d.getDate()==0 || ad>30 ? 'm' : '');
						}
					}
				</script></td>
            <td></td><td></td>
        </tr>
    </table>
   
    <h4 class="mt20">最新消息</h4>
    <ul class="news pub_ulist"></ul>
</div>
<?php
    if (getcookie("m_level") == 0) getCurrVersion();
	viewFoot();
}

function checkLogin(){
	$agent = getAgent() ; $errFlag = false ;$errStr = "<br>";
	if (isOutSubmit()){  $errFlag = true ; $errStr .= "非法外部提交被禁止<br>";}
	$username = getForm("input_name","post") ; $pwd = getForm("input_pwd","post") ; $ip = getIp() ; $bRem=getForm("input_rem","post")=="true";
	if (empty($username) || empty($pwd)){ $errFlag = true ;$errStr .= "用户名或密码为空<br>";}
	$row = DB::fetch_first("select * from ".DB::table('manager')." where m_username='".$username."'");
	if (!is_array($row)) {
	   $errFlag = true;
	   $errStr .= "用户名或密码不正确<br>";
	} else {
		if (intval($row['m_state']) == 0) {
		    $errFlag = true ; 
		    $errStr .= "<br>管理员被锁定<br>";
		}
		if (strlen($row['m_pwd']) > 15) $pwd = md5($pwd); else $pwd = $pwd;
		if (trim($row['m_pwd']) != $pwd) $errFlag = true ; $errStr .= "用户名或密码不正确a<br>";
		if (!$errFlag) {
			$random = md5(mt_rand()*99999999);
			$feedarr = array(
			'm_logintime' => time(),
			'm_loginip' => $ip,
			'm_random' => $random
			);
			DB::update('manager', $feedarr, array('m_username' => $username));
			if ($bRem) {
				dsetcookie("m_username", $row['m_username'], 31536000);
				dsetcookie("m_id", $row['m_id'], 31536000);
				dsetcookie("m_level", $row['m_level'], 31536000);
				dsetcookie("check".$username, md5($agent.$ip.$random), 31536000);
			} else {
				dsetcookie("m_username", $row['m_username'], 86400);
				dsetcookie("m_id", $row['m_id'], 86400);
				dsetcookie("m_level", $row['m_level'], 86400);
				dsetcookie("check".$username, md5($agent.$ip.$random), 86400);
			}
			if (intval($row['m_level']) == 0) {
				if (selfManageDir() == "admin/") alertMsg("您的后台目录名为admin,具有很大安全隐患,请尽快更改后台目录名以保证安全!建议:目录名设为6位以上,尽量复杂一些!","index.php");
			}
			echo "<script>top.location.href='index.php';</script>";exit;
		}
	}
	echoErr("登陆错误","自定义错误",$errStr);
}

function login() {
if (getcookie("m_username") != "") {
	die("<script>top.location.href='index.php';</script>");exit;
}
?>
<html>
<head>
<title>后台登陆中心</title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<meta name="robots" content="noindex,nofollow" />
<style>
html,body,div,form,fieldset,input{margin:0;padding:0}
body{text-align:center;background-color:#001e3b;overflow:hidden;text-align:center}
.wrap{width:1003px;margin:0 auto;clear:both;background:url(imgs/login_01.jpg) no-repeat center top;text-align:center}
img,fieldset	{border:none}
input{background-color:transparent;border:none;cursor:pointer;font-size:14px;padding-top:4px;color:#88D2EB;font-weight:600}
#lay01{height:80px}
#lay02{background-image:url(imgs/login_02.jpg);height:90px}
#lay03{background-image:url(imgs/login_03.jpg);height:126px}
#lay04{background-image:url(imgs/login_04.jpg);height:123px}
	#layform{width:645px;height:123px;margin:0 auto;position:relative;}
		#input_name	{left:196px;position:absolute;top:40px;width:166px;height:26px;}
		#input_pwd	{left:196px;position:absolute;top:91px;width:166px;height:26px}
		#input_remdiv {left:420px;position:absolute;top:100px;color:#FFF;font-size:14px;}
		#input_sub	{left:423px;position:absolute;top:56px;width:153px;height:39px;background:url(imgs/login_btn.png) no-repeat;text-indent:-20em}
#lay05{background-image:url(imgs/login_05.jpg);height:78px}
#lay06{background-image:url(imgs/login_06.jpg);height:87px}
#lay07{background-image:url(imgs/login_07.jpg);height:77px}
</style>
</head>
<body>
<div class="wrap" id="lay01"></div>
<div class="wrap" id="lay02"></div>
<div class="wrap" id="lay03"></div>
<div class="wrap" id="lay04">
	<div id="layform">
		<form method="post" action="?action=check" name="formsearch">
		<fieldset>
			<input name="input_name" type="text" id="input_name" tabindex="1" />
			<input name="input_pwd" type="password" id="input_pwd" tabindex="2" />
			<div id="input_remdiv">
				<input name="input_rem" type="checkbox" id="input_rem" value="true" tabindex="3" /><label for="input_rem">记住登陆</label>
			</div>
			<input name="input_sub" type="submit" id="input_sub" value="登录" tabindex="4" />
		</fieldset>
		</form>
	</div>
</div>
<div class="wrap" id="lay05"></div>
<div class="wrap" id="lay06"></div>
<div class="wrap" id="lay07"></div>
<script src="imgs/admin.js" type="text/javascript"></script>
<script type="text/javascript">focusLogin();</script>
</body>
</html>
<?php
}

function main(){
	checkPower();
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>后台管理中心-DjCMS</title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<meta name="robots" content="noindex,nofollow" />
<link rel="stylesheet" href="imgs/admin.css" type="text/css" media="all" />
<script src="../js/common.js" type="text/javascript"></script>
<script src="imgs/admin.js" type="text/javascript"></script>
<script src="imgs/main.js" type="text/javascript"></script>
<script src="imgs/drag.js" type="text/javascript"></script>
<style type="text/css">
#gMenuMap{text-align:left;}
#gMenuMap a{color:#666;}
.fm3,.fm4{background:url(imgs/34.gif) no-repeat;width:7px;display:block;cursor:pointer}
.fm4{background-position:-6px 0}
.menutd2{background:#DEECF6 url(imgs/leftbg.png) repeat-y -171px 0}
</style>
</head>
<body style="margin: 0px" scroll="no">
<table cellpadding="0" cellspacing="0" width="100%" height="100%">
  <tr>
    <td colspan="3" height="90"><div class="header">
        <div class="logo" onclick="window.open('../');" style="cursor:pointer;">后台管理中心-MaxCMS</div>
        <div class="pannel">
          <p>您好<em><?php echo getcookie("m_username")?></em><?php if (intval(getcookie("m_level"))==0) { ?>(系统管理员)<?php }else{ ?>(网站编辑)<?php }?>&nbsp;&nbsp;&nbsp;&nbsp;<em><span onclick="clearCache()" style="cursor:pointer"><font color="#FF0000">[更新缓存]</font></span></em><span id="upcacheresult" style="color:#FF0000"></span>&nbsp;&nbsp;<a href="admin_update.php" target="main"><font color="red">[在线升级]</font></a> [<a href="index.php?action=logout" target="_top">退出</a>] [<a href="../" target="_blank">网站首页</a>]&nbsp;&nbsp;<a href="javascript:void(0);" onclick="view('gMenuMap');selfLabelWindefault('gMenuMap');"><img width="72"  height="18"  src="imgs/btn_map.gif" title="系统功能地图"  style="margin-bottom:-4px;"  /></a></p>
         </div>
        <div class="navbg"></div>
        <div class="nav">
          <!--上部菜单 changeMenu(左侧菜单id号后部分，右侧默认打开的url)-->
          <ul id="topmenu">
            <?php
				$bigMenuArray = getBigMenuInfo(getcookie("m_level"));
				$bigMenuNum = count($bigMenuArray);
	            for ($i = 0;$i < $bigMenuNum;$i++) {
				if ($i == 0) $bigMenuFlagStr = "'".$bigMenuArray[$i][1]."'"; else $bigMenuFlagStr = $bigMenuFlagStr.","."'".$bigMenuArray[$i][1]."'";
			?>
            <li><em><a href="#" id="header_<?=$bigMenuArray[$i][1]?>" onClick="changeMenu('<?=$bigMenuArray[$i][1]?>', '<?=$bigMenuArray[$i][2]?>');"><?=$bigMenuArray[$i][0]?></a></em></li>
            
            <?php
				}
			?>
          </ul>
          <!--当前所在位置导航 js动态插入-->
          <div class="iamhere">
            <p id="admincpnav"></p>
          </div>
          <div class="navbd"></div>
        </div>
      </div></td>
  </tr>
  <tr>
    <td class="menutd" id="menutd" valign="top" width="171"><div id="leftmenu" class="menu" style="width:171px">
        <!--左菜单 ul id号为menu_XXXX形式，XXXX与上部导航菜单传递参数、JS中topMenus数组一至，li a中的链接与上部导航菜单传递参数一至-->
        <?php
			$smallMenuArray = getSmallMenuInfo(getcookie("m_level"));
			for ($i = 0;$i < $bigMenuNum;$i++) {
				$bigMenuFlag = $bigMenuArray[$i][1];
		?>
        <ul id="menu_<?=$bigMenuFlag?>" style="display: none">
        <?php
				$sSmallMenuArr = explode("|",$smallMenuArray[$i]);
				$sSmallMenuArrLen = count($sSmallMenuArr);
				for ($k = 0;$k < $sSmallMenuArrLen;$k++) {
					if (empty($sSmallMenuArr[$k])) {
                    	echo "<li class='menuspace'><a></a></li>";
					} else {
						$sSmallMenuArr2 = explode(",",$sSmallMenuArr[$k]);
		?>
          <li><a href="<?=$sSmallMenuArr2[1]?>" target="main"><?=$sSmallMenuArr2[0]?></a></li>
        <?php
		 			}
           }
		?>
        </ul>
        <?php
          }
		?>
     </div>
		<div class="footer">
		  <p>Powered by <a href="http://www.djcms.net" target="_blank">djcms</a> 3.0</p>
		</div>
	  </td>
	<td class="menutd2" valign="middle" width="9"><span id="fm" class="fm3" onclick="tooglemenutd(this)" title="点此伸缩左侧菜单栏"> </span></td>
	<td valign="top" class="maincontent"><iframe src="?action=notice" name="main" width="100%" height="100%" frameborder="0"scrolling="yes" style="overflow: visible;"></iframe></td>
 </tr>
</table>
<div id="gMenuMap" class="popdiv" style="width:900px;top:100px;z-index:1000; display:none;">
</div>
<script type="text/JavaScript">
	var dc=$('menutd');
	var topMenus = new Array(<?=$bigMenuFlagStr?>);//大菜单参数数组
	var menu_key = initMenu('leftmenu');//初始化
	changeMenu(menu_key ? menu_key : 'index');
	//初始化左侧菜单高度
	var tt=0
	$("leftmenu").style.height=document.body.clientHeight-90-7-33+"px";
	var  resizeTimer = null;
	function doResize(){
	  $("leftmenu").style.height=document.body.clientHeight-90-7-33+"px";;resizeTimer=null
	}
	window.onresize = function(){
	   if(resizeTimer==null){
			resizeTimer = setTimeout("doResize()",300);
		}
	}
	function MarkMenuMap(){
		var hrefs, s;
		s = '<div class="poptitie"><img src="../pic/btn_close.gif" onClick="hide(\'gMenuMap\');" />后台功能地图</div><table width="100%" border="0" cellspacing="0" cellpadding="0" class="tb2"  ><tr>';
		s += '<td width="10" valign="top"><h4>&nbsp;</h4></td>';
		for(var i=0;i<topMenus.length;i++){
			s += '<td valign="top" width="150"><ul class="cmblock"><li><h4>' + $('header_' + topMenus[i]).innerHTML + '</h4></li>';
			hrefs = $('menu_' + topMenus[i]).getElementsByTagName('a');
			for(var j = 0; j < hrefs.length; j++) {
				s += hrefs[j].innerHTML!='' ? '<li><a href="'+hrefs[j].href+'" onclick="hide(\'gMenuMap\');changeMenu(\'' + topMenus[i] + '\',\''+hrefs[j].href+'\')" target="' + hrefs[j].target + '">' + hrefs[j].innerHTML + '</a></li>' : '';
			}
			s += '<li>&nbsp;</li></ul></td>';
		}
		s += '</tr></table>';
		return s;
	}
	function getClientWidth(){
		return document.body.clientWidth;
	}
	function selfLabelWindefault(divid){
		$(divid).style.left=(getClientWidth()-$(divid).offsetWidth)/2+"px";
		$(divid).style.top=(getScroll()+100)+"px";
	}
	$('gMenuMap').innerHTML=MarkMenuMap();
	function tooglemenutd(){
		dc.style.display = dc.style.display != 'none' ? 'none' : '';
		$('fm').className = dc.style.display != 'none' ? 'fm3' : 'fm4';
		setCookie('MENUON',dc.style.display != 'none' ? '' : '1',365*24);
	}
	if(getCookie('MENUON')=='1'){
		dc.style.display = 'none';
		$('fm').className = 'fm4';
	}
</script>

</body>
</html>
<?php
}
?>
