Files
Gnuboard5/adm/sms_admin/num_book_file_download.php
T
thisgunandClaude Opus 4.7 a6fbbe6ad2 [security] 엑셀/CSV 다운로드 출력값 안전 처리
lib/common.lib.php 에 csv_safe_cell() 헬퍼 추가 (function_exists
가드 포함). 셀 값이 = + - @ TAB CR 로 시작하면 작은따옴표를 prefix
하여 스프레드시트가 수식으로 해석하지 못하도록 변환.

다음 출력 지점에서 사용자 입력 컬럼에 적용:
- adm/shop_admin/orderprintresult.php (CSV + XLS 두 분기)
- adm/shop_admin/orderdeliveryexcel.php
- adm/member_list_exel_export.php
- adm/sms_admin/num_book_file_download.php

호출부는 function_exists('csv_safe_cell') ? ... : 원본 폴백 형태로
감싸서 lib 미업데이트 환경에서도 fatal error 없이 동작하도록 함.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 07:30:21 +00:00

69 lines
2.4 KiB
PHP

<?php
$sub_menu = "900900";
include_once("./_common.php");
$bg_no = isset($_REQUEST['bg_no']) ? clean_xss_tags($_REQUEST['bg_no'], 1, 1) : '';
$no_hp = isset($_REQUEST['no_hp']) ? clean_xss_tags($_REQUEST['no_hp'], 1, 1) : '';
auth_check_menu($auth, $sub_menu, "r");
if ($bg_no != 'all' && $bg_no < 1)
alert_just('다운로드 할 휴대폰번호 그룹을 선택해주세요.');
if ($bg_no == 'all') $sql_bg = ""; else $sql_bg = "and bg_no='$bg_no'";
if ($no_hp) $sql_hp = ""; else $sql_hp = "and bk_hp<>''";
$sql = "select count(*) as cnt from {$g5['sms5_book_table']} where 1 $sql_bg $sql_hp order by bk_name";
$total = sql_fetch($sql);
if (!$total['cnt']) alert_just('데이터가 없습니다.');
$qry = sql_query("select * from {$g5['sms5_book_table']} where 1 $sql_bg $sql_hp order by bk_name");
if(! function_exists('column_char')) {
function column_char($i) {
return chr( 65 + $i );
}
}
include_once(G5_LIB_PATH.'/PHPExcel.php');
$excel = new PHPExcel();
$headers = array('이름', '전화번호');
$widths = array(18, 25);
$header_bgcolor = 'FFABCDEF';
$last_char = column_char(count($headers) - 1);
$rows = array();
$col = 0;
for($i=1; $res=sql_fetch_array($qry); $i++)
{
//$res = array_map('iconv_euckr', $res);
$hp = get_hp($res['bk_hp'], $hyphen);
if ($no_hp && $res['bk_hp'] != '' && !$hp) continue;
$rows[] = array(function_exists('csv_safe_cell') ? csv_safe_cell($res['bk_name']) : $res['bk_name'], ' '.$hp);
}
$data = array_merge(array($headers), $rows);
$excel->setActiveSheetIndex(0)->getStyle( "A1:{$last_char}1" )->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB($header_bgcolor);
$excel->setActiveSheetIndex(0)->getStyle( "A:$last_char" )->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER)->setWrapText(true);
foreach($widths as $i => $w) $excel->setActiveSheetIndex(0)->getColumnDimension( column_char($i) )->setWidth($w);
$excel->getActiveSheet()->fromArray($data,NULL,'A1');
$filename = "휴대폰번호목록-".date("ymd", time()).".xls";
if( is_ie() ) $filename = utf2euc($filename);
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=".$filename);
header("Cache-Control: max-age=0");
$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel5');
$writer->save('php://output');
exit;