<?php
    $conf_basedir	= "../../";	//相对主目录的位置
    $conf_where		= "admin";	//选择调用相应模块
    $directory		= basename(dirname(__FILE__));	//定义当前所在的目录，引入模块公用函数
    include_once($conf_basedir."base.inc.php");
    checkAuth('23');	//判断登录和权限


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

    $js = "<script type='text/javascript' src='http://esfadmin.house365.com/script/js/showpic.js'></script>
    <script type='text/javascript' src='http://esfadmin.house365.com/script/js/public.js'></script>";
    $tbl='broker';
    //查询条件
    $wherecond = "1=1 ";
    //查询条件1
    $cond_arr_1 = array();
	$cond_arr_1["none"]		="* 请选择 *";
	$cond_arr_1["logintime"]	="登陆时间";

	//查询条件_2(文本)
	$cond_arr_2=array();
	$cond_arr_2["none"]			="*请选择*";
	$cond_arr_2["username"]	    ="登录名";
	$cond_arr_2["truename"]	    ="真实姓名";
	$cond_arr_2["uid"]	        ="帐号编号";
	$cond_arr_2["agentcode"]	="公司编号";
	$cond_arr_2["agentname"]	="公司名称";
	$cond_arr_2["expiredate"]	="到期时间";
	$cond_arr_2["idno"]			="身份证";

	$valid_flag_arr=array();
	$valid_flag_arr[1]="有效帐号";
	$valid_flag_arr[0]="无效帐号";
 
        
      
	//排序条件
    
	$orderby_arr=array();
	$orderby_arr["username"]	="登录名";
	$orderby_arr["uid"]	        ="帐号编号";
	$orderby_arr["expiredate"]	="到期时间";


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

    $thismonth = date("n");
    $prevmonth = $thismonth == 1 ? 12 : $thismonth - 1;
    $house['month'] = array($prevmonth=>$prevmonth,$thismonth=>$thismonth);

    $thisyear = date("Y");
    if($thismonth == 1)
    {
        $prevyear = $thisyear - 1;
        $house['year'] = array($prevyear=>$prevyear, $thisyear=>$thisyear);
    }
    else
    {
        $house['year'] = array($thisyear=>$thisyear);
    }

    for($i=1;$i<=31;$i++)
    {
        $house['day'][$i] = $i;
    }

    $cond_y1 = intval($cond_y1);
    $cond_y2 = intval($cond_y2);
    $cond_m1 = intval($cond_m1);
    $cond_m2 = intval($cond_m2);
    $cond_d1 = intval($cond_d1);
    $cond_d2 = intval($cond_d2);
    $cond_y1 = $cond_y1 >0 ? $cond_y1 : date("Y");
    $cond_y2 = $cond_y2 >0 ? $cond_y2 : date("Y");
    $cond_m1 = $cond_m1 >0 ? $cond_m1 : date("n");
    $cond_m2 = $cond_m2 >0 ? $cond_m2 : date("n");
    $cond_d1 = $cond_d1 >0 ? $cond_d1 : date("j");
    $cond_d2 = $cond_d2 >0 ? $cond_d2 : date("j");

    $empty[""] = "*请选择*";
    //客户经理组
    $master_array=$db->GetAssoc("select authname ,truename from home_auth where department='05' and valid_flag=1");
    if(empty($master_array)) $master_array = array();
    $master_array=$empty+$master_array;
    
    //区属
     $district = array_merge($empty,$conf_house['district']);
   // print_r($GLOBALS);

    $cond_search_y1	= tonyForm("select","cond_y1",$house['year'],$cond_y1);
    $cond_search_y2	= tonyForm("select","cond_y2",$house['year'],$cond_y2);
    $cond_search_m1	= tonyForm("select","cond_m1",$house['month'],$cond_m1);
    $cond_search_m2	= tonyForm("select","cond_m2",$house['month'],$cond_m2);
    $cond_search_d1	= tonyForm("select","cond_d1",$house['day'],$cond_d1);
    $cond_search_d2	= tonyForm("select","cond_d2",$house['day'],$cond_d2);


    $cond_search_1	= tonyForm("select","cond_s_1",$cond_arr_1,$cond_s_1);
    $cond_search_2	= tonyForm("select","cond_s_2",$cond_arr_2,$cond_s_2);
    $valid_flag_arr_search	= tonyForm("select","valid_flag_arr_s",$valid_flag_arr,$valid_flag_arr_s);
    $orderby_arr_search	= tonyForm("select","orderby_arr_s",$orderby_arr,$orderby_arr_s);
    $asc_desc_arr_search	= tonyForm("select","asc_desc_arr_s",$asc_desc_arr,$asc_desc_arr_s);
    //顶部查询部分结束

    //查询条件
    if($cond_s_1=='logintime')
    {
    $time1 = $cond_y1.'-'.$cond_m1.'-'.$cond_d1;
    $time2 =$cond_y2.'-'.$cond_m2.'-'.$cond_d2;
    $wherecond.= " and (regdate >= '".$time1."' and regdate <= '".$time2."') ";
    }
    if(!empty($keyword))
    {
    if(!empty($cond_s_2))
      {
         $wherecond.= " and ".$cond_s_2." like '%".$keyword."%'";
      }
    }

    if($cond_s_3 !='')
      {
         $wherecond.= " and valid_flag = '".$cond_s_3."'";
      }

    if(!empty($master) and $master!='*请选择*')
      {
         $wherecond.= " and master = '".$master."'";
      }
         
    if(!empty($dist))
      {
         $wherecond.= " and dist = '".$dist."'";
      }

    if(!empty($orderby_arr_s))
      {
         $ordercond= " order by ".$orderby_arr_s." ".$asc_desc_arr_s."";
      }else{
         $ordercond=" ORDER BY id DESC ";
      }


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

    //获得数据总条数
    $sql = "select COUNT(*) from $tbl left join broker_group on groupid=broker_group.id where ".$wherecond;
    $numrows = $dbback->GetOne($sql);

    //获得数据当前页面数据
    $sql = "select $tbl.*,groupname from $tbl left join broker_group on groupid=broker_group.id where  $wherecond $ordercond LIMIT ".$offset.",".$pagesize." ";
    $data_info = $dbback->GetAll($sql);

    for ($i = 0; $i < count($data_info); $i++) {

        //公司名称
        $q = "select agentshortname,agentcode from agency where agentcode='" . $data_info[$i]["agentcode"] . "'";
        $agentinfo = $db->GetRow($q);
        $data_info[$i]['agentshortname'] = csubstr($agentinfo['agentshortname'], 10);
        $data_info[$i]['agentcode']=$agentinfo['agentcode'];

        //读取是否通过头像审核

    }

    $pagenum = count($data_info);//当前页面数量
    $numrows = $numrows >0 ? $numrows : 0;
    $time = time();
    if( $numrows <= 0 || $pagenum <=0){
        $pages = 0 ;  //计算总页数
    }else{
        $pages = ceil($numrows/$pagesize) ;  //计算总页数
        $new_pagenavi = new_pagenavi($page_now,$pages,$numrows);
    }
  
    //读取权限组
     $q = "select id,groupname from broker_group ";
     $broker_group = $db->GetAssoc($q);

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