include_once('../../../common.php');
$sql = " SELECT * from {$write_table} where wr_is_comment = 0 order by wr_id asc";
$result = sql_query($sql);
$cnt = @sql_num_rows($result);
if (!$cnt)
alert("출력할 내역이 없습니다.");
/*================================================================================
php_writeexcel http://www.bettina-attack.de/jonny/view.php/projects/php_writeexcel/
=================================================================================*/
include_once(G5_LIB_PATH.'/Excel/php_writeexcel/class.writeexcel_workbook.inc.php');
include_once(G5_LIB_PATH.'/Excel/php_writeexcel/class.writeexcel_worksheet.inc.php');
$fname = tempnam(G5_DATA_PATH, "tmp-KaKao-Friends-Premium.xls");
$workbook = new writeexcel_workbook($fname);
$worksheet = $workbook->addworksheet();
// Put Excel data
$data = array('번호', '입금자명', '핸드폰번호', '카톡채널', '신청수량', '세금계산서' );
$data = array_map('iconv_euckr', $data);
$col = 0;
foreach($data as $cell) {
$worksheet->write(0, $col++, $cell);
}
$save_it_id = '';
for($i=1; $row=sql_fetch_array($result); $i++)
{
$row = array_map('iconv_euckr', $row);
$wr_data = apms_unpack($row['wr_content']);
$worksheet->write($i, 0, ' '.$i);
$worksheet->write($i, 1, $row['wr_subject']);
$worksheet->write($i, 2, $row['wr_content']);
$worksheet->write($i, 3, $wr_data['kakao']);
$worksheet->write($i, 4, $wr_data['amount']);
$worksheet->write($i, 5, $wr_data['tax']);
}
$workbook->close();
header("Content-Type: application/x-msexcel; name=\"KaKao-Friends-Premium-".date("ymd", time()).".xls\"");
header("Content-Disposition: inline; filename=\"KaKao-Friends-Premium-".date("ymd", time()).".xls\"");
$fh=fopen($fname, "rb");
fpassthru($fh);
unlink($fname);
exit;