<?php
if(!defined('R_P')) die("access die");
$ids = implode(',', explode(',', trim($_POST['ids'])));
$field = array('title'=>'分类','filter'=>'过滤属性','editor'=>'编辑','edit_time'=>'修改时间','dateline'=>'添加时间','dview'=>'日浏览数','wview'=>'周浏览数','mview'=>'月浏览数','views'=>'总浏览数');
$field_data = array('id'=>'文档ID','subject'=>'标题');
foreach($field as $val=>$tip){
	if(intval($_POST[$val]) > 0) $field_data[$val] = $tip;
}
$data = array();
foreach($field_data as $key=>&$val){
	$val = qbase::iconvs($val, 'utf-8', $_SET['def_charset']);
}
$data[] = array_values($field_data);
require_once(R_P . "/include/class.excel.php");
$query = "SELECT a.*, c.title FROM `".TABLEPRE."{$mod}_{$channelid}` as a left join ".TABLEPRE."acategory as c on a.cid=c.cid where a.id IN ($ids) ";
$temp = qdb::fetchAll($query);
foreach ($temp as $key=>&$item) {
	$item['filter'] = export_format_filter($item['filter']);
	$item['dateline'] = qbase::formatTime('Y-m-d H:i', $item['dateline']);
	$item['edit_time'] = qbase::formatTime('Y-m-d H:i', $item['edit_time']);
	$t = array();
	foreach($field_data as $f=>$v){
		$t[] = isset($item[$f]) ? (is_int($item[$f]) ? $item[$f] : qbase::iconvs($item[$f], 'utf-8', $_SET['def_charset'])) : '';
	}
	$data[] = $t;
}

$name =  'export-' . qbase::formatTime('Y-m-d', time());
$xls = new excel('utf-8', false, $name);
$xls->addArray($data);
$xls->generateXML($name);

function export_format_filter($filter){
	global $filterData;
	if(empty($filter)) return '';
	$data = array();
	$temp = explode(',', $filter);
	foreach($temp as $val){
		if(!isset($filterData[$val])) continue;
		$data[] = $filterData[$val];
	}
	return implode(',', $data);
}
?>