<?php
$conf_basedir   = "../../";	//相对主目录的位置
$conf_where = "admin";	//选择调用相应模块
include_once($conf_basedir."base.inc_new.php");
checkAuth('93');    //判断登录和权限

if ($actiontype) doaction($actiontype,$actionid);

$title = "个人用户行为轨迹分析";
$js = "<script src= 'http://esfadmin.house365.com/script/js/list_common.js'></script>
      <script src= 'http://esfadmin.house365.com/script/My97DatePicker/WdatePicker.js'></script>";

$showType = strip_tags($_GET['showType']);
$showType = $showType != '' ? $showType : 'all';

//初始化用户行为轨迹类
$user_behavior = new UserBehavior( $db_user , $dbback_user , $conf_cityflag);

$user_behavior->set_city($conf_city);

//查询条件_1(文本)
$cond_arr_1 = array();
$cond_arr_1["none"] = "*请选择*";
$cond_arr_1["telno"] = "电话号码";
$cond_arr_1["uid"]  = "用户账号";
$cond_arr_1["id"]   = "记录编号";
if( $showType != 'all')
{
    $cond_arr_1["keyword"]   = "小区/关键词";
}

//条件数组
$cond_arr_2 = array();
$cond_arr_2["district"] = "按区属查询";
$cond_arr_2["subway"]  = "按地铁查询";

$empty = array ("none"=>"*请选择*");

if( $showType == 'ask')
{	
	if( $conf_city != 'nj')
	{
		echo '<script>alert("城市问答频道统计暂时未开启");location.href="user_behavior_analysis.php"</script>';
		exit;
	}

    $is_best_arr = $empty + array( 1 => '已解决' , 2 => '未解决' );

    //查询问答一级分类
    $question_type_arr = $empty + q_type_cache(0);

    //查询问答二级分类
    $question_class_arr = $empty + q_type_cache(1);

    $cond_type_search  = tonyForm("select","qa_type",$question_type_arr,$qa_type ,'1','onchange=get_qa_class(this.value)');

    if( $qa_type > 0 )
    {
        $question_type_class_arr = $empty + q_type_cache( 1 , $qa_type );
        $cond_class_search  = tonyForm("select","qa_class",$question_type_class_arr,$qa_class);
    }
    else
    {
        $cond_class_search  = tonyForm("select","qa_class",$empty,$qa_class);
    }

    $cond_is_best_search  = tonyForm("select","is_best",$is_best_arr,$is_best);

    //问题类型
    $qa_type = intval($qa_type);

    if( $qa_type > 0)
    {
        $user_behavior->set_qa_type( $qa_type );
    }

    //问题子型
    $qa_class = intval($qa_class);
    if( $qa_class > 0)
    {
        $user_behavior->set_qa_class( $qa_class );
    }

    //是否有最佳答案
    $is_best = intval($is_best);
    if( $is_best > 0)
    {
        $user_behavior->set_is_best( $is_best );
    }
}

//频道条件
$website_arr = $empty + $user_behavior->get_website_arr();

//位置条件
$position_arr = $empty + $user_behavior->get_position_arr();

//操作类型条件
$opreatetype_arr = $empty + $user_behavior->get_opreatetype_arr();

//设备类型条件
$device_arr = $empty + $user_behavior->get_device_arr();

//各频道条件选择

//地铁线路
$subway_line_arr = $empty + $house['infofrom'];

//地铁站点
$station_arr = $empty ;

//区属
$district_arr = $empty + $uri_district;

//板块
$street_arr = $empty ;

//来源
$infofrom_arr = $empty + $house['infofrom'];

//类型
$infotype_arr = $empty + $house['infotype'];

//租赁方式
$renttype_arr = $empty + $uri_renttype;

//装修
$fitment_arr = $empty + $uri_fitment;

if( $showType == 'school')
{	
	if( !in_array( $conf_city , array('hz','wx')) )
	{
		echo '<script>alert("城市学区频道统计暂时未开启");location.href="user_behavior_analysis.php"</script>';
		exit;
	}

	//学校类型
	$category_arr = $empty + $house['category_sh'];

	//学校级别
	$rank_arr = $empty + $house['rank'];

	$cond_category_search  = tonyForm("select","category_sh",$category_arr,$category_sh);
	$cond_rank_search  = tonyForm("select","rank",$rank_arr,$rank);
}

//排序条件
$orderby_arr = array();
$orderby_arr["none"]  = "*请选择*";
$orderby_arr["datetime"] = "记录时间";

$asc_desc_arr=array();
$asc_desc_arr["none"] ="*请选择*";
$asc_desc_arr["asc"] ="&nbsp;正序排列&nbsp;";//方向
$asc_desc_arr["desc"]="&nbsp;倒序排列&nbsp;";

//默认排序
$orderby = empty($orderby) ?  'datetime' : $orderby;
$asc_desc = empty($asc_desc) ?  'desc' : $asc_desc;

$cond_search_1  = tonyForm("select","cond_key",$cond_arr_1,$cond_key);
$cond_search_2  = tonyForm("select","cond_key2",$cond_arr_2,$cond_key2);
$cond_website_search  = tonyForm("select","website",$website_arr,$website);
$cond_position_search  = tonyForm("select","position",$position_arr,$position);
$cond_operate_search  = tonyForm("select","operate_type",$opreatetype_arr,$operate_type);
$cond_device_search  = tonyForm("select","device",$device_arr,$device);
$orderby_arr_search = tonyForm("select","orderby",$orderby_arr,$orderby);
$asc_desc_arr_search    = tonyForm("select","asc_desc",$asc_desc_arr,$asc_desc);

//各频道查询条件
$cond_district_search  = tonyForm("select","district",$district_arr,$district,'1','onchange=get_street(this)');
if( $district > 0)
{
    $district_street_arr  = $empty + street_cache($uri_district[$district]);
    $cond_street_search  = tonyForm("select","street",$district_street_arr,$street);
}
else
{
    $cond_street_search  = tonyForm("select","street",$empty,$street);
}

$cond_subway_search  = tonyForm("select","subway_line",$district_arr,$subway_line,'1','onchange=get_station(this)');
if( $subway_line > 0)
{
    $line_station_arr  = $empty + subway_cache($line_arr[$subway_line]);
    $cond_station_search  = tonyForm("select","station",$line_station_arr,$station);
}
else
{
    $cond_station_search  = tonyForm("select","station",$empty,$station);
}

$cond_infofrom_search  = tonyForm("select","infofrom",$infofrom_arr,$infofrom);
$cond_infotype_search  = tonyForm("select","infotype",$infotype_arr,$infotype);
$cond_renttype_search  = tonyForm("select","renttype",$renttype_arr,$renttype);
$cond_fitment_search  = tonyForm("select","fitment",$fitment_arr,$fitment);
//顶部查询部分结束

/**组装查询条件**/
//查询时间
$default_day = date('Y-m-d',time() - 86400);
$count_day = isset($_GET['count_day']) ? $_GET['count_day'] : $default_day ;
$count_day2 = isset($_GET['count_day2']) ? $_GET['count_day2'] : $default_day ;
$count_date = date( 'Ymd' , strtotime($count_day) );
$count_date2 = date( 'Ymd' , strtotime($count_day2) );

//查询手机号或者用户编号
$keyword = trim(strip_tags($keyword));
if( !empty($cond_key) && $cond_key != 'none' &&  $keyword != '')
{
    switch ($cond_key)
    {
        case 'telno':
            $user_behavior->set_telno($keyword);
            break;
        case 'uid':
            $user_behavior->set_uid(intval($keyword));
            break;
        case 'id':
            $user_behavior->set_id(intval($keyword));
            break;
        case 'keyword':
            $user_behavior->set_keyword($keyword);
            break;
    }
}

//查询站点
$website = intval($website);
if( $website > 0)
{
    $user_behavior->set_website($website);
}

//查询页面位置
$position = intval($position);
if( $position > 0)
{
    $user_behavior->set_position($position);
}

//查询操作类型
$operate_type = intval($operate_type);
if( $operate_type > 0)
{
    $user_behavior->set_opreatetype($operate_type);
}

//查询设备类型
$device = intval($device);
if( $device > 0)
{
    $user_behavior->set_device($device);
}

//区属查询
$district = intval($district);
if( $district > 0)
{
    $user_behavior->set_district($district);
}

//板块查询
$street = intval($street);
if( $street > 0)
{
    $user_behavior->set_street($street);
}

//来源
$infofrom = intval($infofrom);
if( $infofrom > 0)
{
    $user_behavior->set_infofrom($infofrom);
}

//房源类型
$infotype = intval($infotype);
if( $infotype > 0)
{
    $user_behavior->set_infotype($infotype);
}

//房源租赁方式
$renttype = intval($renttype);
if( $renttype > 0)
{
    $user_behavior->set_renttype($renttype);
}

//装修程度
$fitment = intval($fitment);
if( $fitment > 0)
{
    $user_behavior->set_fitment($fitment);
}

//价格参数
if( intval($price1) > 0 || intval($price2) > 0)
{
    $user_behavior->set_price( $price1 , $price2 );
}

//均价参数
if( intval($averprice1) > 0 || intval($averprice2) > 0)
{
    $user_behavior->set_averprice( $averprice1 ,$averprice2 );
}

//面积参数
if( intval($buildarea1) > 0 || intval($buildarea2) > 0)
{
    $user_behavior->set_buildarea( $buildarea1 , $buildarea2 );
}

//户型参数
if( intval($room1) > 0 || intval($room2) > 0)
{
    $user_behavior->set_room( $room1 , $room2 );
}

//价格参数
if( intval($floor1) > 0 || intval($floor2) > 0)
{
    $user_behavior->set_floor( $floor1 , $floor2 );
}

//学校类型
$category_sh = intval($category_sh);
if( $category_sh > 0)
{
    $user_behavior->set_category($category_sh);
}

//学校级别
$rank = intval($rank);
if( $rank > 0)
{
    $user_behavior->set_rank($rank);
}

//行为轨迹总数
switch ($showType)
{
    case 'all':
        $behavior_num = $user_behavior->get_behavior_logs_count($count_date);
        break;
    case 'sell':
        $behavior_num = $user_behavior->get_behavior_sell_logs_count( $count_date , $count_date2 );
        break;
    case 'rent':
        $behavior_num = $user_behavior->get_behavior_rent_logs_count( $count_date , $count_date2 );
        break;
    case 'block':
        $behavior_num = $user_behavior->get_behavior_block_logs_count( $count_date , $count_date2 );
        break;
    case 'ask':
        $behavior_num = $user_behavior->get_behavior_ask_logs_count( $count_date , $count_date2 );
        break;
	case 'shool':
        $behavior_num = $user_behavior->get_behavior_school_logs_count( $count_date , $count_date2 );
        break;
    default :
        $behavior_num = $user_behavior->get_behavior_logs_count($count_date);
}

//分页参数
$pagesize   = $disp_rows ? intval($disp_rows) : 20;
$page_now   = $page_now ? max(1, intval($page_now)) : 1 ; // 获取当前页数
$offset = ( $page_now - 1 ) * $pagesize;

//行为轨迹内容
switch ($showType)
{
    case 'all':
        $behavior_info = $user_behavior->get_behavior_logs( $count_date , $offset , $pagesize  , $orderby , $asc_desc );
        //用户行为所有编号
        $arr_ids = $user_behavior->array_pluck('node' ,$behavior_info );
        $arr_nodes = $user_behavior->get_node_by_ids($arr_ids);
        break;
    case 'sell':
        $behavior_info = $user_behavior->get_behavior_sell_logs( $count_date , $count_date2 , $offset , $pagesize  , $orderby , $asc_desc );
        break;
    case 'rent':
        $behavior_info = $user_behavior->get_behavior_rent_logs( $count_date , $count_date2 , $offset , $pagesize  , $orderby , $asc_desc );
        break;
    case 'block':
         $behavior_info = $user_behavior->get_behavior_block_logs( $count_date , $count_date2 , $offset , $pagesize  , $orderby , $asc_desc );
        break;
    case 'ask':
        $behavior_info = $user_behavior->get_behavior_ask_logs( $count_date , $count_date2 , $offset , $pagesize  , $orderby , $asc_desc );
         break;
	case 'school':
         $behavior_info = $user_behavior->get_behavior_school_logs( $count_date , $count_date2 , $offset , $pagesize  , $orderby , $asc_desc );
        break;
    default :
        $behavior_info = $user_behavior->get_behavior_logs( $count_date , $offset , $pagesize  , $orderby , $asc_desc );
}

//当前页面数量
$pagenum = count($behavior_info);
$numrows = $behavior_num > 0 ? $behavior_num : 0;

if( $numrows <= 0 || $pagenum <=0)
{
    $pages = 0 ;  //计算总页数
}
else
{
    $pages = ceil( $numrows / $pagesize ); //计算总页数
    $new_pagenavi = new_pagenavi2($page_now,$pages,$numrows);
}

//引用模版文件
include_once(Template("header"));
include_once(Template("user_center/user_behavior_analysis"));
include_once(Template("footer"));
?>