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

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

    $css="<link href='http://esfadmin.house365.com/script/css/autocomplete.css' rel='stylesheet' type='text/css' />";
    $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>
   <script type='text/javascript' src='http://esfadmin.house365.com/script/js/jquery_ui_autocomplete/ui/jquery.ui.core.js'></script>
   <script type='text/javascript' src='http://esfadmin.house365.com/script/js/jquery_ui_autocomplete/ui/jquery.ui.position.js'></script>
   <script type='text/javascript' src='http://esfadmin.house365.com/script/js/jquery_ui_autocomplete/ui/jquery.ui.widget.js'></script>
   <script type='text/javascript' src='http://esfadmin.house365.com/script/js/jquery_ui_autocomplete/ui/jquery.ui.autocomplete.js'></script>";


    $tbl='mobile_broker_shop';
    
    
    //顶部查询部分开始
    $wherecond = "1=1";
    //查询条件_2(文本)
    $cond_arr_2=array();
    $cond_arr_2["none"]     ="*请选择*";
    $cond_arr_2["blockid"]	="小区名称";
    $cond_arr_2["uid"]	="经纪人账号";
    

    $cond_arr_1=array();
    $cond_arr_1["none"] ="*请选择*";
    $cond_arr_1["1"]	="有效";
    $cond_arr_1["2"]	="无效";


    //排序条件
    $orderby_arr=array();
    $orderby_arr["none"] ="*请选择*";
    $orderby_arr["addtime"] ="添加时间";

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


    $cond_search_1	= tonyForm("select","esta",$cond_arr_1,$esta);
    $cond_search_2	= tonyForm("select","cond_s_2",$cond_arr_2,$cond_s_2);
    $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(!empty($keyword))
    {
        if(!empty($cond_s_2) and $cond_s_2!='none')
          {
            if($cond_s_2=='blockid')
              {	
                    $keyword2=$dbback->GetOne("select id from block where blockname='".$keyword."'");
                    $wherecond.= " and ".$cond_s_2." = '".$keyword2."'";
              }else{
                    $keyword2=$dbback->GetOne("select uid from broker where username='".$keyword."'");
                    $wherecond.= " and ".$cond_s_2." = '".$keyword2."'";
              }
          }
    }

    if(!empty($cond_s_1) and $cond_s_1!='none')
      {
         $wherecond.= " and  sort= '".$cond_s_1."'";
      }

    if(!empty($esta) && $esta!='none')
    {
        if($esta==1)
        {
            $wherecond.= " and esta = '1'";
        }else{
            $wherecond.= " and esta = '2'";
        }
    }

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

      //查询条件处理结束

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


    //获得数据总条数
    $sql = "select COUNT(*) from $tbl  where ".$wherecond." group by id";
    $totalrows = $dbback->GetAll($sql);
    $numrows=count($totalrows);
    $yemian=array('id','uid','blockid','type','addtime','astime','esta');
    //获得数据当前页面数据
    $sql = "select * from $tbl where  $wherecond  $ordercond  LIMIT ".$offset.",".$pagesize." ";
	//echo $sql;
    $data_info = $dbback->GetAll($sql);
	if(is_array($data_info)){
		for ($i = 0; $i < count($data_info); $i++) {
			$n=0;
			foreach($data_info[$i] as $key=>$value)
			 {


				 if((empty($value)) && in_array($key,$yemian))
				 {
				 $n++;
				 }

			 }

			//获得经纪人信息
			$q = "select username,telno,agentcode,truename from broker where uid = '".$data_info[$i]['uid']."'";
			$broker = $dbback->GetRow($q);
			$data_info[$i]['truename'] = $broker['truename'];
			$data_info[$i]['username'] = $broker['username'];
			$data_info[$i]['agentshortname'] = $dbback->GetOne("select agentshortname from agency where agentcode='".$broker[agentcode]."'");
			$data_info[$i]['telno'] = $broker['telno'];
			//获得小区信息
			$data_info[$i]['blockname'] = $dbback->GetOne("select blockname from block where id='".$data_info[$i]['blockid']."'");

		}
    }

    $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_pagenavi2($page_now,$pages,$numrows);
    }


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