<?php
define('ROOT',dirname(dirname(__FILE__)));
include(ROOT.'/../include/config.php');
include(ROOT.'/../include/global.func.php');
include_once(__DIR__.'/../../include/db_mysql.php');
include(ROOT.'/../include/jtemplate.php');
include(ROOT.'/include/fundcalc.inc.php');
include(ROOT.'/include/jj_tools.php');

$g_db = new db;
$ret = $g_db->connect($g_DBIP,$g_DBUser,$g_DBPwd,"funds");
if(!$ret)
	exit;

//显示类型：默认是网站显示，如果showtype=client是给客户端但没有头部
$showtype = isset($_REQUEST['showtype']) ? $_REQUEST['showtype'] : '';
//判断是不是收费用户
$sfyh=isset($_REQUEST['sfyh']) ? $_REQUEST['sfyh'] : '';
	
$g_tpl = new JTemplate(ROOT.'/templates/');

//判断用户是否已经登录
$uid = 0;$username='';
if( GetCookies( $aryCookies ) )
{
	$uid 	= $aryCookies['uid'];//必须是数字
	$username = $aryCookies['username'];
}
//判断是否客户端登录
if( $showtype=='client' )
	$g_tpl->set("default_header",false);
else	
	$g_tpl->set("default_header",true);
$g_tpl->set("showtype",$showtype);

if( $sfyh=='yes' )
	$g_tpl->set("sfyh",true);
else	
	$g_tpl->set("sfyh",false);

//判断是否是收费用户
if(GetProductAuth(2,$uid))
	$jjdsyh=1;
elseif(GetProductAuth(3,$uid))
	$jjdsyh=1;
elseif(GetProductAuth(4,$uid))
	$jjdsyh=1;
elseif(GetProductAuth(5,$uid))
	$jjdsyh=1;
else
	$jjdsyh=0;

$g_tpl->set("jjdsyh",$jjdsyh);		
//查询某个选基条件
$planid = isset($_REQUEST['planid']) ? intval($_REQUEST['planid']) : 0;
$aryPlan = array();
if( $planid>0 )
{
	$aryPlans = GetUserPlan($planid,'','');
	if( $aryPlans[$planid]['open']==0 && $uid != $aryPlans[$planid]['userid'] )
		$aryPlans = array();
	else	
		$aryPlan = $aryPlans[$planid];
}

//基金公司列表
$aryJJGS = array_values(GetAllJJGS());
//代销基金列表
$aryDXBank1 = GetDXBank(1);
//定投列表
$aryDXBank2 = GetDXBank(2);

//我的方案
$aryMyPlan = array();
if( $uid>0 )
	$aryMyPlan = GetUserPlan('',$uid,'','planid');
//易天富方案
$aryYTFPlan = GetUserPlan('','27899',1,'planid');
//新鲜出炉方案
$aryNewPlan = GetUserPlan('','',1,'plantime');
//最受支持方案
$arySupportPlan = GetUserPlan('','',1,'topsupportplan');
	
$g_tpl->set('aryPlan',$aryPlan);
$g_tpl->set('aryMyPlan',$aryMyPlan);
$g_tpl->set('aryYTFPlan',$aryYTFPlan);
$g_tpl->set('aryNewPlan',$aryNewPlan);
$g_tpl->set('arySupportPlan',$arySupportPlan);
$g_tpl->set('aryJJGS',$aryJJGS);
$g_tpl->set('aryDXBank1',$aryDXBank1);
$g_tpl->set('aryDXBank2',$aryDXBank2);

CreateHeaderFooter($g_tpl,'智能选基 ',true,true);
echo $g_tpl->fetch("xjpt_znxj.tpl.php");


function GetDXBank($banktype=1/*1代销2定投*/)
{
global $g_db;
	
	$sql="SELECT orgname, uid FROM pub002 WHERE f003 =2 AND uid IN (SELECT DISTINCT f003 FROM fund03 WHERE f002 =12) order by uid";
	//$sql = "select bankid,bankname from dx_banks where typeid=".$banktype." order by bankid";
	$res = $g_db->query($sql);
	$aryDXBank=array();
	while( $row = $g_db->fetch_array($res) )
	{
		$aryDXBank[] = GetGB($row['orgname']);
	}	
	return $aryDXBank;
}

?>
