<?php
include_once("includes/global.php");
include_once("includes/admin_global.php");
include_once("includes/admin_class.php");
include_once("includes/insert_function.php");
//===============================================
$action=isset($_GET['action'])?$_GET['action']:"main";
$submit=isset($_POST['submit'])?$_POST['submit']:NULL;
$deid=isset($_GET['deid'])?$_GET['deid']:NULL;
$admin = new admin();

//---------------------登录检查
$admin->is_login($action);

//---------------------清缓存
if(!empty($_POST)||!empty($_GET['deid'])||!empty($_GET['rec']))
	$admin->clear_user_shop_cache();
//---------------------更换语言包
if(!empty($_GET['lang']))
{
	$_SESSION['USER_LANG']=$_GET['lang'];
	$admin->msg("main.php");
}
if(empty($_SESSION['USER_LANG']))
	$_SESSION['USER_LANG']=$config['language'];
include("lang/".$_SESSION['USER_LANG']."/user_admin.php");

//---------------------会员类型。
$right_file='config/user_right_'.$_SESSION['USER_LANG'].'_'.$_SESSION['identity'].'_config.php';
if(isset($_SESSION['identity'])&&file_exists($right_file))
{	//企业会员分类
	@include_once($config['webroot'].'/config/module_company_config.php');
	if($module_company_config['identity'])
	{
		include($right_file);
		$ide=explode('|',$module_company_config['identity']);
		$idekey=$_SESSION['identity'];
		$tpl->assign("identity_name",$ide[$idekey]);
	}
}
//-----------------------用户菜单加载
include("lang/".$_SESSION['USER_LANG']."/admin_menu.inc.php");
//-------------------------------------以下是会员办公室的信息---
include_once("module/company/includes/company_class.php");
$user=new user();
$cominfo=$user->get_user_detail($buid);
$admin->tpl->assign("cominfo",$cominfo);
switch ($action){
	case "admin_subscribe":
	{	
		include_once("includes/plugin_tradealter_class.php");
		$tradealter=new tradealter();
		if(!empty($_POST['addid']))
		{
			if($_POST['keycon']&&$_POST['email'])
			{
				if(!empty($_POST['seditid']))
					$re=$tradealter->up_subscribe($_POST['seditid']);
				else
					$re=$tradealter->up_subscribe();
				msg("main.php?action=admin_subscribe");
			}
		}
		if(!empty($_GET['editid']))
		{	
			$tpl->assign("de",$tradealter->list_subscribe($_GET['editid']));
		}
		if(!empty($_GET['delid']))
		{
			$tradealter->delete_subscribe($_GET['delid']);
		}
		$tpl->assign("subscribe",$tradealter->list_subscribe());
		$page="user_admin/admin_subscribe.htm";
		break;
	}

	case "admin_subuser":
	{	
		if(!empty($_GET['deid']))
			$admin->delete_personal($_GET['deid']);
			
		if(!empty($_POST['action'])&&$_POST['action']=='submit')
		{
			$admin->add_personal();
			msg("main.php?action=admin_subuser&t=1&adduser=$_GET[adduser]");
		}
		if(!empty($_POST['action'])&&$_POST['action']=='update')
		{	
			$admin->update_personal($_POST['uid']);
			msg("main.php?action=admin_subuser&adduser=$_GET[adduser]&t=1");
		}
		
		include_once("lang/".$config['language']."/company_type_config.php");
		$tpl->assign("de",$de=$admin->get_personal_detail($_GET['editid']));
		$tpl->assign("plist",$admin->get_personal_list());
		$tpl->assign("prov",get_province($de['province']));
		
		if(!empty($_GET['adduser']))
		{
			$nohead='true';
			$page="user_admin/admin_add_personal.htm";
			if(empty($_GET['editid']))
				$tpl->assign("de",NULL);
		}
		else
			$page="user_admin/admin_subuser.htm";
		break;
	}
	
	case "admin_personal":
	{	
		if(!empty($_POST['action'])&&$_POST['action']=='update')
		{	
			$admin->update_personal($_POST['uid']);
			$admin->msg("main.php?action=admin_personal");
		}
		include_once("lang/".$config['language']."/company_type_config.php");
		$tpl->assign("de",$de=$admin->get_personal_detail($_GET['editid']));
		$tpl->assign("plist",$admin->get_personal_list());
		$tpl->assign("prov",get_province($de['province']));
		if(!empty($_GET['guid']))
		{
			include_once('uc_client/client.php');
			$tpl->assign("slogin",uc_user_synlogin($_GET['guid']));
		}
		$page="user_admin/admin_personal.htm";
		break;
	}
	
	case "setpassword":
	{
		if(isset($_POST["action"]))
		{
			$admin->resetpass($buid);
		}
		$page="user_admin/admin_resetpass.htm";
		$current="myshop";
		break;
	}
	case "logout":
	{
		global $config;
		include_once("$config[webroot]/config/reg_config.php");
		$config = array_merge($config,$reg_config);
		bsetcookie("USERID",NULL,time(),"/",$config['baseurl']);
		setcookie("USER",NULL,time(),"/",$config['baseurl']);
		//=====================
		unset($_SESSION['IFPAY']);
		msg("$config[weburl]/index.php");
		break;
	}
	case "msg":
	{
		include_once("$config[webroot]/config/usergroup.php");
		$ifpay=$_SESSION['IFPAY'];
		$groupname = $group[$ifpay]['name'];
		$des = $group[$ifpay]['des'];
		$tpl->assign('groupname',$groupname );
		$tpl->assign('des',$des );
		//----------
		include_once("$config[webroot]/config/reg_config.php");
		$config = array_merge($config,$reg_config);
		//---------
		if(!empty($_GET['nohead']))
			$nohead=true;
		$page="user_admin/admin_msg.htm";
		break;
	}
	default:
	{
		$_GET['s']=!empty($_GET['m'])?$_GET['s']:"admin_offer_list";
		$_GET['m']=!empty($_GET['m'])?$_GET['m']:"offer";
		if(!empty($_GET['m']))
		{
			if(file_exists($config['webroot'].'/config/module_'.$_GET['m'].'_config.php'))
			{
				@include($config['webroot'].'/config/module_'.$_GET['m'].'_config.php');
				$mcon='module_'.$_GET['m'].'_config';
				@$config = array_merge($config,$$mcon);
			}
			if(file_exists("$config[webroot]/module/".$_GET['m']."/lang/".$_SESSION['USER_LANG'].".php"))
				include("$config[webroot]/module/".$_GET['m']."/lang/".$_SESSION['USER_LANG'].".php");		//#调用模块语言包
			include("module/".$_GET['m']."/".$_GET['s'].".php");
			$tpl->template_dir=$config['webroot']."/templates/".$config['temp']."/user_admin/";
			break;
		}
		else
		{
			include_once("includes/point_inc.php");
			include_once("module/message/includes/plugin_msg_class.php");
			$msg=new msg();
			$tpl->assign("point",$p=point_ranks($buid));		
			$tpl->assign("mailNum",$msg->getMailNum());
			$tpl->assign("certification",$cominfo['statu']);//工商是否认证
			//--------------------------------------
			$page="user_admin/admin_main.htm";
			break;
		}
	}
}
//==============================================
include_once($config["webroot"]."/config/nav_menu.php");
$tpl->assign("menus",$nav_menu);
$tpl->assign("lang",$lang);
include_once("footer.php");
if(!empty($nohead))
	$tpl->display($page);
else
{
	if(!empty($output))
		$tpl->assign("output",$output);
	else
		$tpl->assign("output",$admin -> tpl -> fetch($page));

	$tpl->template_dir=$config['webroot']."/templates/".$config['temp']."/user_admin/";
	$tpl->display("admin_inc.htm");
}
?>