<?php 
$conf_basedir	= "../../";	//相对主目录的位置
$conf_where		= "admin";	//选择调用相应模块
$directory		= basename(dirname(__FILE__));	//定义当前所在的目录，引入模块公用函数
include_once($conf_basedir."base.inc.php");
error_reporting(7);
ini_set("display_errors",true);

if($do=='lock_img')
  {
  		if($password!='123456')
        {
        echo 3;exit;
        }

        //$arr['dateline'] = time();
        //$arr['admin'] = $_SESSION[$web_auth]["username"];
        $arr['blockid'] = $blockid;
        $arr['flag'] = 1;
		$q = insert_sql("block_lock",$arr);
        
        $mark=$db->Execute($q);
        if($mark)
            {
             echo 1;
            }else
            {
             echo 2;
            }
  }

  //获取小区列表
if($_REQUEST['actiontype'] == 'getblocklist' && $_REQUEST['q']){
	$blocklist = array();

    $blockname = trim(strip_tags(urldecode($_REQUEST['q'])));
	$temp_block = getBlockArrByKeyword($blockname,10);
	if($temp_block && !empty($temp_block)){
		$i = 0;
		foreach($temp_block as $key=>$value ){
			//$blocklist[$i]['label'] = "<p><span>".trim(iconv('GBK', 'UTF-8', $value["blockname"]))."</span><span>".trim(iconv('GBK', 'UTF-8', $value["district"]))."</span><span>".trim(iconv('GBK', 'UTF-8', $value["streetname"]))."</span><span>".trim(iconv('GBK', 'UTF-8', "约".$value["sellcount"]."套"))."</span></p>";
            $blocklist[$i]['label'] = trim(iconv('GBK', 'UTF-8', $value["blockname"]));
			$blocklist[$i]['id']	= $value["id"];
            $blocklist[$i]['blockname']    = trim(iconv('GBK', 'UTF-8', $value["blockname"]));
            $blocklist[$i]['district']    = trim(iconv('GBK', 'UTF-8', $value["district"]));
            $blocklist[$i]['streetname']    = trim(iconv('GBK', 'UTF-8', $value["streetname"]));
            $blocklist[$i]['sellcount']    = trim(iconv('GBK', 'UTF-8', $value["sellcount"]));
            //$blocklist[$i]['url'] = get_block_url($value['id']);
			$i++;
		}
	}else{
		$blocklist[0]['label']  = trim(iconv('GB2312', 'UTF-8', "无相似小区"));
		$blocklist[0]['id']		= "0";
	}

  print_r(json_encode($blocklist));
  exit;
}

if($actiontype == 'getstreet'){

    $district=mb_convert_encoding(urldecode($district),"gb2312","utf-8");
    $sql = "select id,streetname from street where district='$district'";

    $arr[street]=$dbback->GetAssoc($sql);
  
    if(isset($arr[street]) && !empty($arr[street]))
    {
     foreach($arr[street] as $key=>$value)
    {
     $ss.='<option  value="'.$key.'">'.$value.'</option>';
  }
}

  echo $ss;
  exit;
}

 //邮件数据excel统计
if($actiontype == "export_data"){

      $tbl='block';
          //查询条件
        $wherecond = "1=1";

      //查询条件处理开始

    if(!empty($keyword))
    {
    if(!empty($cond_s_2) and $cond_s_2!='none')
      {
         $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')
      {
      $wherecond.= " and esta = '".$esta."'";
      }

    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 ";
      }

     $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 COUNT(*) from $tbl  where ".$wherecond." group by id";
   
    $totalrows = $dbback->GetAll($sql);
    $numrows=count($totalrows);

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

    //获得数据当前页面数据
    $sql = "select * from $tbl where  $wherecond  $ordercond  ";

        $data_info = $dbback->GetAll($sql);
       
        $count_num = count($data_info);
  
    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'] = '无';
        }

    }
    }


		$export_str = '<html><head><meta http-equiv="Content-type" content="text/html;charset=gbk" /><style type="text/css">.td_border{border-bottom:solid 1px #ccc;border-right:solid 1px #ccc;text-align:center;}</style></head>';
		$export_str .= '<body><TABLE style="border-left:solid 1px #ccc;border-top:solid 1px #ccc;" width="100%" cellspacing = "0" cellspadding = "0" align="center" >';
		$export_str .= '<tr><td class="td_border">小区ID</td>';
		$export_str .= '<td class="td_border">小区名称</td>';
		$export_str .= '<td class="td_border">小区别名</td>';
		$export_str .= '<td class="td_border">区属</td>';
        $export_str .= '<td class="td_border">板块</td>';
        $export_str .= '<td class="td_border">地址</td>';
        $export_str .= '<td class="td_border">资料空缺</td>';
        $export_str .= '<td class="td_border">户型图</td>';
        $export_str .= '<td class="td_border">外景图</td>';
        $export_str .= '<td class="td_border">地图标点</td>';
        $export_str .= '<td class="td_border">更新时间</td>';
		$export_str .= '<td class="td_border">添加者</td>';
		if($conf_city=='nj'){
			$export_str .= '<td class="td_border">备注小区地址</td>';
        }
		$export_str .= "</tr>";
		if($count_num >= 1){
			foreach ($data_info as $key=>$value){

                $value['updatetime']=$value['updatetime']?date("Y-m-d H:i",$value['updatetime']):'';
				$export_str .= '<tr>';
                $export_str .= "<td height=200 class='td_border'>".$value['id']."</td>";
				$export_str .= "<td height=200 class='td_border'>".$value['blockname']."</td>";
				$export_str .= "<td height=200 class='td_border'>".$value['alias']."</td>";
				$export_str .= "<td height=200 class='td_border'>".$value['district']."</td>";
				$export_str .= "<td height=200 class='td_border'>".$value['streetname']."</td>";
                $export_str .= "<td height=200 class='td_border'>".$value['address']."</td>";
                $export_str .= "<td height=200 class='td_border'>".$value['lack']."项</td>";
                $export_str .= "<td height=200 class='td_border'>".$value['pic_num']."张</td>";
                $export_str .= "<td height=200 class='td_border'>".$value['pic_num1']."张</td>";
                $export_str .= "<td height=200 class='td_border'>".$value['map_flag']."</td>";
                $export_str .= "<td height=200 class='td_border'>".$value['updatetime']."</td>";
                $export_str .= "<td height=200 class='td_border'>".$value['addname']."</td>";
				if($conf_city=='nj'){
				  $export_str .= "<td height=200 class='td_border'>".$value['b_address']."</td>";
				}
				$export_str .= "</tr>";
			}
		}else{
				$export_str .= "<tr><td colspan='10' align='center' class='td_border'>暂无统计数据</td></tr>";
		}

		$export_str .= "</table></body></table>";
		$filename = "小区列表信息(".date("Y-m-d").").xls";

		header("Content-type:application/vnd.ms-excel");
		header("Content-Disposition: attachment; filename=$filename");
        echo "<script>location.replace('".$referer."');</script>";
		echo $export_str;
		
		exit;
	}





 
?>