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

	$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='admin_pic_entry';
    //查询条件
    if($config_GrowthCredit == 1){
        $wherecond = "";
    }else {
        $wherecond = "sort=0 ";
    }
    
	//查询条件_2(文本)
	$cond_arr_2=array();
	$cond_arr_2["none"]			="*请选择*";
	$cond_arr_2["blockid"]	    ="小区编号";

	$cond_arr_1=array();
	$cond_arr_1["none"]	="*请选择*";
	$cond_arr_1["2"]	="户型图";
        if($config_GrowthCredit == 1){
            $cond_arr_1["1"]	="外景图";
        }
	

  //  $picArr = array('小区正门'=>51,'外立面'=>52,'小区环境'=>53,'内部设施'=>54,'周边设施'=>55);
	//排序条件
    $orderby_arr=array();
    $orderby_arr["none"] ="*请选择*";
    $orderby_arr["dateline"] ="入库时间";
    $orderby_arr["num"] ="入库数量";

	$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","cond_s_1",$cond_arr_1,$cond_s_1);
    $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 ($action == 'xiala') {

		$q = urldecode($_REQUEST[q]);
		$str = "SELECT * FROM block WHERE blockname LIKE '%" . $q . "%' ORDER BY id DESC LIMIT 50";
		$rs = $db->Execute($str);
		if ($rs->RecordCount() == 0) {
			$ss.="<span onselect=\"this.text.value ='$blockname';$('bi_blockid').value=$id\">请重新输入小区关键字！未找到相关的小区！</span>";
			echo $ss;
			exit;
		}

		while ($row = $rs->FetchRow()) {
			
			$blockname = $row[blockname];
			$id = $row[id];
			$ss.="<span onselect=\"this.text.value ='$blockname';$('bi_blockid').value=$id\">" . csubstr($blockname, 28) . "</span>";
		}
		echo $ss;
		exit;
	}

    //查询条件

     //2014-2-14 xue 外景图、户型图筛选 
     if($config_GrowthCredit == 1){
          if(!empty($cond_s_1) and $cond_s_1!='none'){ 
              if($cond_s_1==2){
                 $cond_s_1 =0;        
                 $wherecond.= "sort= '".$cond_s_1."'";
              }elseif($cond_s_1==1){
                 //  $cond_s_1 = "51,52,53,54,55";
                 $wherecond.=  "sort= '".$cond_s_1."'"; 
              }        
          }else{
              $wherecond .= " sort in ('1','0')";
          } 
         
     }
     
   

      if(!empty($keyword))
      {
          if(!empty($cond_s_2) and $cond_s_2!='none')
          {
              $wherecond.= " and ".$cond_s_2." like '%".$keyword."%'";
          }
       }

    if(!empty($keyword1))
      {
         $wherecond.= " and blockname = '".$keyword1."'";
      }

    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	= $display_rows ? intval($display_rows) : 20;
    $page_now	= $page_now ? max(1, intval($page_now)) : 1 ; // 获取当前页数
    $offset		= ( $page_now - 1 ) * $pagesize;
    //删除7天之前的数据
    $todaytime=strtotime("today")-7*3600*24;
    //var_dump($todaytime);exit;
    $sql = "select COUNT(*) from $tbl where dateline<".$todaytime."";
    $array_yes = $dbback->GetAll($sql);
    if(isset($array_yes) && !empty($array_yes))
    {
    $q ="delete from $tbl where dateline<".$todaytime."";
    $db->Execute($q);
    }
   
    //获得数据总条数
    $sql = "select COUNT(*) from $tbl  where ".$wherecond." group by blockid";
  
    $totalrows = $dbback->GetAll($sql);
    $numrows=count($totalrows);
    //获得数据当前页面数据
    $sql = "select *,count(*) as num from $tbl where  $wherecond group by blockid $ordercond  LIMIT ".$offset.",".$pagesize." ";
    $data_info = $dbback->GetAll($sql);
  
    for ($i = 0; $i < count($data_info); $i++) {
       $bi_type =  $data_info[$i]["sort"] == "0" ?  "bi_type=0" : "bi_type in (51,52,53,54,55)";          
        
        //获得小区图库数量
        $q = "select count(*) as num from block_img where ".$bi_type." and bi_blockid='" . $data_info[$i]["blockid"] . "'";
      
        $blockimg = $dbback->GetRow($q);

        $data_info[$i]['sort0_num'] = $blockimg['num'];
        //检查是否被锁定
       
        //$q = "select count(*) as num from block_lock where blockid='" . $data_info[$i]["blockid"] . "'";
         //户型图、外景图锁定(放到block表中判断) xue 2014-2-14
        if($config_GrowthCredit == 1){
             if($data_info[$i]["flag"]==1){
               //经纪人成长体系来图
               $q = "select lock_outside as flag from block where id='" . $data_info[$i]["blockid"] . "'";
            }else{
               $q = "select lock_layout as flag from block where id='" . $data_info[$i]["blockid"] . "'";
            }
            //  $q = "select count(*) as num from block_lock where blockid='" . $data_info[$i]["blockid"] . "'";
            $array_lock= $dbback->GetRow($q);
            $data_info[$i]['lock'] =$array_lock['flag'];
            
        }else{
              //检查是否被锁定
             $q = "select count(*) as num from block_lock where blockid='" . $data_info[$i]["blockid"] . "'";
             $array_lock= $db->GetRow($q);
             $data_info[$i]['lock'] =$array_lock['num'];
            
        }

       
        
        //if(isset($data_info[$i+1]['blockid']) && !empty($data_info[$i+1]['blockid']))
        //{
        //$data_info[$i]['id_next'] = $data_info[$i+1]['blockid'];
        //}
        //$array_id[$data_info[$i]['id']]=$data_info[$i+1]['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_pagenavi($page_now,$pages,$numrows);
    }

    //读取权限组
 //    $q = "select id,groupname from broker_group ";
    // $broker_group = $db->GetAssoc($q);

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