<?php
/**
*
*  Copyright (c) 2003-08  PHPWind.net. All rights reserved.
*  Support : http://www.phpwind.net
*  This software is the proprietary information of PHPWind.com.
*
*/
error_reporting(E_ERROR | E_PARSE);
set_magic_quotes_runtime(0);

define('R_P',getdirname(__FILE__));
define('D_P',R_P);

require_once(R_P.'admin/admincp.php');
//print_r($rightset);exit;
if (!$adminjob) {
	require_once(R_P.'admin/index.php');
} elseif($adminjob=='notice'){
	require_once(R_P.'admin/notice.php');
} elseif ($adminjob=='admin') {
	if ($ceversion) {
		require_once(R_P.'admin/c_update.php');
	}
	if (pwFilemtime(D_P.'data/bbscache/admin_cache.php')<PwStrtoTime(get_date($timestamp,'Y-m-d'))) {
		require_once(R_P.'admin/table.php');
		list($tabledb) = N_getTabledb();
		$pw_size = $o_size = 0;
		$query = $db->query('SHOW TABLE STATUS');
		while ($rt = $db->fetch_array($query)) {
			if (in_array($rt['Name'],$tabledb)) {
				$pw_size += $rt['Data_length']+$rt['Index_length']+0;
			} else {
				$o_size  += $rt['Data_length']+$rt['Index_length']+0;
			}
		}
		$o_size		 = number_format($o_size/(1024*1024),2);
		$pw_size	 = number_format($pw_size/(1024*1024),2);
		$dbversion	 = $db->server_info();
		$max_upload  = ini_get('file_uploads') ? ini_get('upload_max_filesize') : 'Disabled';
		$max_ex_time = intval(ini_get('max_execution_time')).' seconds';
		if ($sendmail_path = ini_get('sendmail_path')) {
			$sys_mail = 'Unix Sendmail ( Path: '.$sendmail_path.')';
		} elseif ($SMTP = ini_get('SMTP')) {
			$sys_mail = 'SMTP ( Server: '.$SMTP.')';
		} else {
			$sys_mail = 'Disabled';
		}
		@extract($db->get_one('SELECT totalmember,yposts FROM pw_bbsinfo WHERE id=1'));
		@extract($db->get_one('SELECT SUM(topic) AS threads,SUM(article) AS posts FROM pw_forumdata'));
		$hits = $db->get_value('SELECT SUM(hits) FROM pw_threads');
		writeover(D_P.'data/bbscache/admin_cache.php',"<?php die;?>$pw_size|$o_size|$dbversion|$max_upload|$max_ex_time|$sys_mail|$totalmember|$threads|$posts|$hits|$yposts");
	} else {
		list($pw_size,$o_size,$dbversion,$max_upload,$max_ex_time,$sys_mail,$totalmember,$threads,$posts,$hits, $yposts) = explode('|',substr(readover(D_P.'data/bbscache/admin_cache.php'),12));
	}
	$altertime	= gmdate('Y-m-d H:i',$timestamp+$db_timedf*3600);
	$systemtime	= $db_cvtime==0 ? $altertime : gmdate('Y-m-d H:i',time()+$db_timedf*3600);
	$sysversion = PHP_VERSION;
	$sysos      = str_replace('PHP/'.$sysversion,'',GetServer('SERVER_SOFTWARE'));
	$ifcookie   = isset($_COOKIE) ? 'SUCCESS' : 'FAIL';
	$warnid = $mid = $u = 0;
	if ($admin_gid=='3' || CkInArray($admin_name,$manager)) {
		$u = 1;
		if (pwWritable(D_P.'data/sql_config.php')) {
			$warnid += 1;
		}
		if (is_dir('data')) {
			$warnid += 2;
		}
		if (ini_get('register_globals')) {
			$warnid += 4;
		}
		if (file_exists('admin.php')) {
			$warnid += 8;
		}
		if (!$db_ifsafecv || strpos($db_safegroup,',3,')===false || strpos($db_safegroup,',4,')===false || strpos($db_safegroup,',5,')===false) {
			$warnid += 16;
		}
		if ($pw_size > 500) {
			$warnid += 32;
		} elseif ($pw_size > 300) {
			$warnid += 64;
		}
	}
	$content = $sltlv = '';
	@extract($db->get_one('SELECT mid,content FROM pw_memo WHERE isuser=0 AND username='.pwEscape($admin_name)));
	$content && $content = str_replace('<br />',"\n",$content);
	if ($rightset['level']) {
		foreach ($ltitle as $key => $value) {
			$sltlv .= '<option value="'.$key.'">'.$value.'</option>';
		}
	}
	include_once(D_P.'data/bbscache/forumcache.php');
	if (If_manager) {
		list(,$hideforum) = GetHiddenForum();
		$forumcache .= $hideforum;
	} elseif ($rightset['setforum']) {
		if ($admin_gid=='5') {
			list(,$forumcache) = GetAllowForum($admin_name);
		}
	} else {
		$forumcache = '';
	}
	if ($db_adminrecord == '1') {
		$bbscrecordfile = D_P."data/bbscache/adminrecord.php";
		$recorddb = readlog($bbscrecordfile);
		$recorddb = array_reverse($recorddb);
		for($i=0; $i<=4; $i++){
			$detail=explode("|",$recorddb[$i]);
			if($detail[1] && $detail[3] && $detail[4] && $detail[6]){
				$winddate=get_date($detail[4]);
				$detail[6]=htmlspecialchars($detail[6]);
				$adlogfor.="
	<tr class=\"tr3 tac\">
	<td><a href='$admin_file?adminjob=setuser&action=search&schname=$detail[1]&schname_s=1'>$detail[1]</a></td>
	<td>$detail[3]</td>
	<td class='smalltxt'>$winddate</td>
	<td>$detail[6]</td>
	</tr>";
			}
		}
	}
	require_once PrintEot('admin');afooter();
} elseif ($adminjob=='hackcenter' && $rightset['hackcenter']==1) {//old
	require_once(R_P.'admin/hackcenter.php');
} elseif ($adminjob=='hack' && $rightset['hackcenter']==1) {//old
	if (!$db_hackdb[$hackset] || !is_dir(R_P."hack/$hackset") || !file_exists(R_P."hack/$hackset/admin.php")) {
		adminmsg('hack_error');
	}
	define('H_P',R_P."hack/$hackset/");
	$basename="$admin_file?adminjob=hack&hackset=$hackset";
	require_once Pcv(H_P.'admin.php');
} elseif ($adminjob == 'mode' && $admintype && $rightset[$admintype] == 1) {
	list($m,$adminjob) = explode('_',$admintype);
	if (!isset($db_modes[$m]) || !is_dir(R_P."mode/$m") || !file_exists(R_P."mode/$m/admin/{$adminjob}.php")) {
		adminmsg('mode_admin_error');
	}
	define('M_P',R_P."mode/$m/");
	$basename = "$admin_file?adminjob=mode&admintype=$admintype";
	require_once Pcv(M_P."admin/{$adminjob}.php");
} elseif ($adminjob=='content' && ($rightset['tpccheck'] && $type=='tpc' || $rightset['postcheck'] && $type=='post' || (int)$rightset['superdel']['message']==1 && $type=='message')) {//old
	require_once(R_P.'admin/content.php');
} elseif ((If_manager && in_array($adminjob,array('rightset','manager','code','ystats','diyoption','optimize','modepage'))) || (!is_array($rightset[$adminjob]) && (int)$rightset[$adminjob]==1) || ($admintype && is_array($rightset[$adminjob]) && (int)$rightset[$adminjob][$admintype]==1)) {
	$basename = $admin_file.'?adminjob='.$adminjob;
	require_once(R_P.'admin/'.$adminjob.'.php');
} elseif ($adminjob=='updatememo') {
	list($mmid,$mcontent) = $db->get_one("SELECT mid,content FROM pw_memo WHERE isuser='0' AND username=".pwEscape($admin_name),MYSQL_NUM);
	$mmid = (int)$mmid;
	$content = Char_cv($_POST['content']);
	if (!$mmid) {
		$pwSQL = pwSqlSingle(array(
			'username'	=> $admin_name,
			'postdate'	=> $timestamp,
			'content'	=> $content,
			'isuser'	=> '0'
		));
		$db->update('INSERT INTO pw_memo SET '.$pwSQL);
	} elseif ($mmid==(int)$_POST['mid'] && $mcontent!=$content) {
		$pwSQL = pwSqlSingle(array(
			'postdate'	=> $timestamp,
			'content'	=> $content
		));
		$db->update("UPDATE pw_memo SET $pwSQL WHERE mid=".pwEscape($mmid));
	}
	ObHeader($admin_file.'?adminjob=admin');
} else {
	adminmsg('undefine_action');
}
function getdirname($path=null){
	if (!empty($path)) {
		if (strpos($path,'\\')!==false) {
			return substr($path,0,strrpos($path,'\\')).'/';
		} elseif (strpos($path,'/')!==false) {
			return substr($path,0,strrpos($path,'/')).'/';
		}
	}
	return './';
}
?>