<?php
!function_exists("adminmsg") && exit("Forbidden");

$partner = md5($db_siteid.$db_siteownerid);
!$action && $action = 'blooming';
include_once(D_P.'data/bbscache/info_class.php');
include_once(D_P.'data/bbscache/info_group.php');

if ($action == 'blooming') {
	require_once(R_P.'require/posthost.php');
	InitGP(array('step'));
	$_POST['step'] = $step;
	if (empty($_POST['step'])) {

		$_Ginfo = explode(',',$db_appginfo);

		if (!file_exists(D_P.'data/bbscache/info_class.php')) {
			require_once(R_P.'require/posthost.php');
			$verify = md5($db_sitehash.$partner.'getclass');
			$data = PostHost("http://app.phpwind.com/pw_app.php?", "action=getclass&sitehash=$db_sitehash&&verify=$verify&", "POST");
			$backdata = substr($data,strpos($data,'$backdata=')+10);
			if (strpos($backdata,'Not Found') !== false) {
				Showmsg('The Interface is not exist');
			}
			if (strpos($backdata,'}') === false) {
				$backdata = pwutf8Convert($backdata,$db_charset,'gbk');
				Showmsg($backdata);
			}
			$backdatadb = unserialize(stripslashes($backdata));
			UpdateClassCache($backdatadb,1);
		}

	} elseif ($_POST['step'] == '2') {

		InitGP(array('ciddb'),'P');
		foreach ($info_class as $key => $value) {
			$info_class[$key]['ifshow']= '0';
		}
		foreach ($ciddb as $val) {
			$info_class[$val]['ifshow']= '1';
		}
		UpdateClassCache($info_class);

		adminmsg('operate_success');

	} elseif ($_POST['step'] == '3') {

		InitGP(array('groupdb'),'P',2);
		$groupdb = implode(',',$groupdb);
		$db->update("REPLACE INTO pw_config SET " . pwSqlSingle(array('db_name' => 'db_appginfo', 'db_value' => $groupdb)));
		updatecache_c();

		adminmsg('operate_success');

	} elseif ($_POST['step'] == '4') {

		$verify = md5($db_sitehash.$partner.'getclass');
		$data = PostHost("http://app.phpwind.com/pw_app.php?", "action=getclass&sitehash=$db_sitehash&&verify=$verify&", "POST");
		$backdata = substr($data,strpos($data,'$backdata=')+10);
		if (strpos($backdata,'Not Found') !== false) {
			Showmsg('The Interface is not exist');
		}
		if (strpos($backdata,'}') === false) {
			$backdata = pwutf8Convert($backdata,$db_charset,'gbk');
			Showmsg($backdata);
		}
		$backdatadb = unserialize(stripslashes($backdata));
		UpdateClassCache($backdatadb,1);
		adminmsg('operate_success');
	}
}
require PrintHack("admin");exit;

function UpdateClassCache($classdb=array(),$a=0) {
	global $info_class,$db_charset;
	$classcache = "<?php\r\n\$info_class=array(\r\n";

	foreach ($classdb as $key => $class) {
		!$class['ifshow'] && $class['ifshow'] = '0';
		if ($a == 1) {
			$info_class[$class['cid']]['ifshow'] && $class['ifshow'] = '1';
		}
		$class['name'] = str_replace(array('"',"'"),array("&quot;","&#39;"),$class['name']);
		$classcache .= "'$class[cid]'=>".pw_var_export($class).",\r\n\r\n";
	}
	$classcache .= ");\r\n?>";
	if ($a == 1) {
		$classcache = pwutf8Convert($classcache,$db_charset,'gbk');
	}
	writeover(D_P."data/bbscache/info_class.php",$classcache);
}
function pwutf8Convert($str,$to_encoding,$from_encoding) {
	if (strtolower($to_encoding) == strtolower($from_encoding)) {
		return $str;
	} else {
		require_once(R_P.'wap/app_chinese.php');
		$chs = new Chinese($from_encoding,$to_encoding);
		if(is_array($str)){
			foreach($str as $key=> $val){
				$str[$key]=pwutf8Convert($val,$to_encoding,$from_encoding);
			}
		}else{
			return $chs->Convert($str);
		}
		return $str;
	}
}
?>