<?php
    $conf_basedir	= "../../";	//相对主目录的位置
    $conf_where		= "admin";	//选择调用相应模块
    $directory		= basename(dirname(__FILE__));	//定义当前所在的目录，引入模块公用函数
    include_once($conf_basedir."base.inc.php");
    checkAuth('32');	//判断登录和权限
	
	$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='block';
    
    
    //顶部查询部分开始
    $wherecond = "1=1";
	//查询条件_2(文本)
	$cond_arr_2=array();
	$cond_arr_2["none"]			="*请选择*";

    $cond_arr_2["blockname"]	    ="小区名称";
    $cond_arr_2["alias"]	    ="小区别名";
    $cond_arr_2["id"]	    ="小区编号";
    $cond_arr_2["address"]	    ="小区地址";

	$cond_arr_1=array();
    $cond_arr_1["2"]	="正式小区";
	$cond_arr_1["4"]	="待审核小区";
    $cond_arr_1["1"]	="临时小区";
    $cond_arr_1["3"]	="新房小区";

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

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

    $cond_district_1	= tonyForm("select","cond_s_3",$conf_house['district'],$cond_s_3);
    $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=='id')
          {
           $wherecond.= " and ".$cond_s_2." = '".$keyword."'";
          }else{
           $wherecond.= " and ".$cond_s_2." like '%".$keyword."%'";
          }
        
      }
    }

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

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

    if($nofee && $nofee!='none')
      {
      $wherecond.= " and nofee = '".$nofee."'";
      }

    if($district && $district!='none')
      {
      $wherecond.= " and district = '".$district."'";
      }

    if($street_id && $street_id!='none')
      {
      $wherecond.= " and streetid = '".$street_id."'";
      }

    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('blockname','district','streetid','address','bi_spell','b_property_type','total_room','area','b_area','b_developers','b_parking','b_green','plot_ratio','b_property_company','b_property_fees','turn_time','b_bus','b_metro','b_introduction','b_other','b_map_x','b_map_y','streetview','feature');
    //获得数据当前页面数据
    $sql = "select * from $tbl where  $wherecond  $ordercond  LIMIT ".$offset.",".$pagesize." ";
    $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++;
             }

         }
		//地铁站点
        $sarr_2 = $dbback->GetAll("select tb.id, t.bid, t.station, t.line from traffic_block tb left join traffic t on tb.bid = t.bid where tb.type = '2' and tb.blockid = '".$data_info[$i]['id']."'");
        if(!$sarr_2)
        {
          $n++;
        }
        //公交站点
        $sarr_1 = $dbback->GetAll("select tb.id, t.bid, t.station, t.line from traffic_block tb left join traffic t on tb.bid = t.bid where tb.type = '1' and tb.blockid = '".$data_info[$i]['id']."'");
        if(!$sarr_1)
        {
          $n++;
        }


        //获得区属
        $q = "select streetname from street where id='" . $data_info[$i]["streetid"] . "'";
        $street = $db->GetRow($q);
        $data_info[$i]['streetname'] = $street['streetname'];
        $data_info[$i]['lack'] = $n;

        //获得各类图片数量
        $sql = "select count(*) as count_num from block_img  where bi_blockid=".$data_info[$i]['id']." and bi_type=0 ";
        //户型图
        $num_array = $dbback->GetRow($sql);

        $sql = "select count(*) as count_num from block_img  where bi_blockid=".$data_info[$i]['id']." and bi_type in ('51','52','53','54','55') ";
        //其他图片
        $num_array1 = $dbback->GetRow($sql);

        $data_info[$i]['pic_num'] = $num_array['count_num'];
        $data_info[$i]['pic_num1'] = $num_array1['count_num'];
       // var_dump($data_info[$i]);exit;
        if($data_info[$i]['b_map_x']>0 && $data_info[$i]['b_map_y']>0)
        {
         $data_info[$i]['map_flag'] = '有';
        }else{
         $data_info[$i]['map_flag'] = '无';
        }
    }
    }

    $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);
    }

    $action = $_REQUEST[actiontype];
    $id = $_REQUEST[actionid];
    if ($action == 'realdel' && $id != "") {

    $q = "delete from $tbl where id=" . intval($id);
    if ($db->Execute($q)) {
		//同步删除图库列表
		$q = "delete from block_img_num where blockid = " . intval($id);
		$db->Execute($q);
        echo "<script>alert('删除成功！');location.href='block_manage.php'</script>";
        die();
    }
}
	$house['street'] = $dbback->GetAssoc("select id,streetname from street");

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