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

	if (($actiontype!='addsort1' && isset($actiontype)) or $actiontype1=='del') 
    {  
        if($actiontype1=='del') $actiontype='del';
        doact($actiontype,$actionid);
    }elseif(isset($actiontype) && !empty($actionid)){
       $id2 = explode(",,", $actionid);
       $aa = explode(",", $id2[0]);
        foreach ($aa as $k => $v) {
          $q = "update $tbl set bi_type=$changetype where id=$v";
          $db->Execute($q);
        }
        if(!isset($type))
        {
      echo "<script>alert('修改成功！');location.href='/module/block/block_pic_manage.php?blockid=".$blockid."'</script>";
      }else{
      echo "<script>alert('修改成功！');location.href='/module/block/block_pic_manage.php?blockid=".$blockid."&type=".$type."'</script>";
      }
    }

    $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>";
    
    
    
    //顶部查询部分开始
    $wherecond = "bi_blockid=".$blockid;
  
	//查询条件_2(文本)
	$cond_arr_2=array();
	$cond_arr_2["none"]			="*请选择*";

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

	$cond_arr_1=array();

	$cond_arr_1["none"]	="未分类图片";
    $cond_arr_1["0"]	="户型图";
    $cond_arr_1["51"]	="小区正门";
    $cond_arr_1["52"]	="外立面";
    $cond_arr_1["53"]	="小区环境";
    $cond_arr_1["54"]	="内部设施";
    $cond_arr_1["55"]	="周边配套";
    $cond_arr_1["56"]	="小区评测";



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

    //顶部查询部分结束


    //查询条件处理开始

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


      //查询条件处理结束

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

    //小区确定
    if($blockid > 0){

        $q = "select blockname,b_img,sd_mark,b_img2 from block where id = '".$blockid."'";
        $binfo = $db->GetRow($q);
        $bname = $binfo['blockname'];
        $bimg = $binfo['b_img'];
        $bimg2 = $binfo['b_img2'];
        $bsd_mark = $binfo['sd_mark'];
    }

    //默认显示无分类图片
    if(!isset($type))
    {
      $wherecond.= " and bi_type not in ('0','51','52','53','54','55','56') ";
     }else{
      $wherecond.= " and bi_type=".$type;
    } 

    //获得数据总条数
    $sql = "select count(*) as count_num from $tbl a left join block b on a.bi_blockid=b.id where ".$wherecond."";
    $totalrows = $dbback->GetAll($sql);
    $numrows=$totalrows[0]['count_num'];

    //获得各类图片数量
    $sql = "select bi_type,count(*) as count_num from $tbl  where bi_blockid=".$blockid." group by bi_type";
    $type_num_array = $dbback->GetAll($sql);
  if(isset($type_num_array) && !empty($type_num_array)){
    foreach($type_num_array as $value)
    {
        if($value['bi_type']==0 or $value['bi_type']==51 or $value['bi_type']==52 or $value['bi_type']==53 or $value['bi_type']==54 or $value['bi_type']==55 or $value['bi_type']==56)
        {
              $type_num[$value['bi_type']]=$value['count_num'];
        }else{
              $type_num[999]+=$value['count_num'];
        }
  
    }}

    //获得数据当前页面数据
    $sql = "select a.*,b.blockname,b.id as bid from $tbl a left join block b on a.bi_blockid=b.id where  $wherecond  order by id desc  LIMIT ".$offset.",".$pagesize." ";
 
    $data_info = $dbback->GetAll($sql);

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

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