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


$title = "单日审核报表";
$search_flag = 0;

$ym = date("Y-m");

//获取日期
$last_date = getMonthRange($ym);
$month_date_start = $last_date[0];
$month_date_end = $last_date[1];
$search_ym = date('Y-m',strtotime($month_date_start));

/*设置前台select信息
$lastym = date("Y-m");
$search_ym_arr = array($lastym=>$lastym);
//获取前台select信息
$ym_display = getSelect($search_ym_arr,'search_ym',$search_ym);
 */
//获得数据当前页面数据
$ordersql = $actiontype == 'exportcsv' ? "" : " order by id desc ";
$sql = "SELECT dateline, admin,  SUM(sort0_num) AS sort0_num, SUM(sort1_num) AS sort1_num, SUM(sort2_num) AS sort2_num, SUM(remark_num) AS remark_num FROM admin_house_check_opernum_log WHERE (dateline >= '$month_date_start' AND dateline <= '$month_date_end') GROUP BY dateline ".$ordersql." limit 31";
$data_arr = $dbback->GetAll($sql);

//获取图片入库量和描述入库量
$month_date_start = str_replace("-", "", $month_date_start);
$month_date_end = str_replace("-", "", $month_date_end);
$sql = "SELECT in_sort0_num,in_sort1_num,in_sort2_num FROM admin_pic_total_stat WHERE (dateline >= '$month_date_start' AND dateline <= '$month_date_end') ".$ordersql." limit 31";
$pic_total = $dbback->GetAll($sql);
$sql = "SELECT in_num FROM admin_remark_total_stat WHERE (dateline >= '$month_date_start' AND dateline <= '$month_date_end') ".$ordersql." limit 31";
$remark_total = $dbback->GetAll($sql);

$data_info = array();
if(count($data_arr))
{
	foreach($data_arr as $key=>$data)
	{
		$value = array();
		
		$value['dateline'] = $data['dateline'];
		$value['sort0_num'] = $data['sort0_num'];
		$value['sort1_num'] = $data['sort1_num'];
		$value['sort2_num'] = $data['sort2_num'];
		$value['in_sort0_num'] = $pic_total[$key]['in_sort0_num'];
		$value['in_sort1_num'] = $pic_total[$key]['in_sort1_num'];
		$value['in_sort2_num'] = $pic_total[$key]['in_sort2_num'];
		$value['remark_num'] = $data['remark_num'];
		$value['in_num'] = $remark_total[$key]['in_num'];

		$data_info[] = $value;

		unset($value);
	}
}


//下载报表
if($actiontype == 'exportcsv'){
	$data = $search_month."日期,户型图已审,户型图总量,外景图已审,外景图总量,室内图已审,室内图总量,描述已审,描述总量
	";

	if(is_array($data_info) && !empty($data_info)){
		foreach($data_info as $key=>$val){
			$data .= $val['dateline'].','.$val['sort0_num'].','.$val['in_sort0_num'].','.$val['sort1_num'].','.$val['in_sort1_num'].','.$val['sort2_num'].','.$val['in_sort2_num'].','.$val['remark_num'].','.$val['in_num'].'
			';
		}
	}

	$mime_type = 'text/x-csv';
	header('Content-Type: ' . $mime_type);
    header("Content-Disposition: attachment; filename=房源审核单日报表".$search_ym.".csv");
    $actiontype = '';
    echo $data;
    exit();
}

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