그누보드 [G5] 게시판 엑셀다운로드
페이지 정보
본문
게시글을 엑셀로 다운로드 받는 방법입니다.
1. 그누보드5 / skin / board / basic / _common.php 생성
<?php
include_once('../../../common.php');
// 테마 폴더 스킨폴더 이용할때 아래꺼 사용
//include_once('../../../../../common.php');
?>
2. 그누보드5 / skin / board / basic / list.skin.php 적절한 위치에 아래 코드 추가
<?php if ($is_admin) { ?>
<div style="float:left">
<a href='<?php echo $board_skin_url; ?>/excel.php?bo_table=<?php echo $bo_table; ?>' class="btn_admin btn2" target='_blank'><i class="fa fa-user-circle" aria-hidden="true"></i> Excel (전체받기)</a>
</div>
<div style="float:left; padding-left:20px;">
<form action="<?php echo $board_skin_url; ?>/excel.php" method="post">
<?php include_once(G5_PLUGIN_PATH.'/jquery-ui/datepicker.php'); ?>
<script>
$(function(){
// 시작날짜와 끝나는 날짜를 함께 선택해서 사용할때
var dates = $( "#datepicker_from, #datepicker_to" ).datepicker({
//defaultDate: "+1w", // 기본선택일이 1 week 이후가 선택되는 옵션
changeMonth: true,
dateFormat: "yy-mm-dd", // 년월일 표시방법 yy-mm-dd 또는 yymmdd
numberOfMonths: 2, // 한눈에 보이는 월달력수
onSelect: function( selectedDate ) {
var option = this.id == "datepicker_from" ? "minDate" : "maxDate",
instance = $( this ).data( "datepicker" ),
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not( this ).datepicker( "option", option, date );
}
});
});
</script>
<input type="hidden" name="bo_table" value="<?php echo $bo_table; ?>">
<input type="text" name="date1" class="frm_input" style="width:72px; height:35px;" readonly id="datepicker_from"> ~
<input type="text" name="date2" class="frm_input" style="width:72px; height:35px;" readonly id="datepicker_to">
<input type="submit" class="frm_input" style="width:72px; height:35px;" value="엑셀받기">
</form>
</div>
<div style="clear: both;"></div>
<?php } ?>
3. 그누보드5 / skin / board / basic / excel.php 파일 생성
<?php
include_once "_common.php";
if (!$is_admin) {
alert("관리자만 접근 가능합니다.");
exit;
}
$bo_table = $_REQUEST['bo_table'];
$excel_down = $g5['write_prefix'] . $bo_table; //엑셀 다운로드 테이블
$wr_id = $_REQUEST['wr_id'];
//$hp_filename = "파일명";
$hp_filename = $bo_table."_".date('Y_md h_m');
//@sql_query("SET CHARACTER SET utf8"); // 한글깨지면 주석해지
if ($ms =="excel"){
$g5['title'] = "엑셀 문서 다운로드";
header( "Content-type: application/vnd.ms-excel" );
header( "Content-Disposition: attachment; filename={$hp_filename}.xls" );
//header( "Content-Description: PHP4 Generated Data" );
} else if ($ms =="power"){
$g5['title'] = "파워포인트 문서 다운로드";
header( "Content-type: application/vnd.ms-powerpoint" );
header( "Content-Disposition: attachment; filename={$hp_filename}.ppt" );
// header( "Content-Description: PHP4 Generated Data" );
} else if ($ms =="word"){
$g5['title'] = "워드 문서 다운로드";
header( "Content-type: application/vnd.ms-word" );
header( "Content-Disposition: attachment; filename={$hp_filename}.doc" );
//header( "Content-Description: PHP4 Generated Data" );
} else if ($ms =="memo"){
$g5['title'] = "메모 문서 다운로드";
header( "Content-type: application/vnd.ms-notepad" );
header( "Content-Disposition: attachment; filename={$hp_filename}.txt" );
} else {
header( "Content-type: application/vnd.ms-excel" );
header( "Content-Disposition: attachment; filename={$hp_filename}.xls" );
}
header( "Content-Description: PHP4 Generated Data" );
$date1 = $_POST['date1']." 00:00:00";
$date2 = $_POST['date2']." 23:59:59";
$search = " where 1 ";
if ($_POST['date1'] && !$_POST['date2']) {
$search = " and wr_datetime > '{$date1}' ";
} elseif (!$_POST['date1'] && $_POST['date2']) {
$search = " and wr_datetime < '{$date2}' ";
} elseif ($_POST['date1'] && $_POST['date2']) {
$search = " and wr_datetime > '{$date1}' && wr_datetime < '{$date2}' ";
}
// 원글 + 코멘트 다운로드
$temp=sql_fetch_array(sql_query("select count(*) from {$excel_down} "));
$sql="select * from {$excel_down} {$search} order by wr_datetime desc";
$qry=sql_query($sql);
// 원글만 다운로드 (코멘트 제외) , 2013-10-21 추가
//$temp=sql_fetch_array(sql_query("select count(*) from {$excel_down} and wr_is_comment = '0' and wr_content = '{$wr_id}' "));
//$sql="select * from {$excel_down} {$search} and wr_is_comment = '0' and wr_content = '{$wr_id}' order by wr_datetime desc";
//$qry=sql_query($sql);
$number=$temp[0];
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.txt {
mso-style-parent:style0;
mso-number-format:"\@";
border:.5pt solid windowtext;
}
</style>
</head>
<body>
<table>
<tr>
<td class='txt'>아이디</td>
<td class='txt'>이름</td>
<td class='txt'>이메일</td>
<td class='txt'>홈페이지</td>
<td class='txt'>작성일</td>
<td class='txt'>분류</td>
<td class='txt'>제목</td>
<td class='txt'>내용</td>
<td class='txt'>필드1</td>
<td class='txt'>필드2</td>
<td class='txt'>필드3</td>
<td class='txt'>필드4</td>
<td class='txt'>필드5</td>
<td class='txt'>필드6</td>
<td class='txt'>필드7</td>
<td class='txt'>필드8</td>
<td class='txt'>필드9</td>
<td class='txt'>필드10</td>
</tr>
<?php
while($row=sql_fetch_array($qry)) {
echo "
<tr>
<td class='txt'>{$row['mb_id']}</td>
<td class='txt'>{$row['wr_name']}</td>
<td class='txt'>{$row['wr_email']}</td>
<td class='txt'>{$row['wr_homepage']}</td>
<td class='txt'>{$row['wr_datetime']}</td>
<td class='txt'>{$row['ca_name']}</td>
<td class='txt'>{$row['wr_subject']}</td>
<td class='txt'>".get_text(strip_tags($row['wr_content']))."</td>
<td class='txt'>{$row['wr_1']}</td>
<td class='txt'>{$row['wr_2']}</td>
<td class='txt'>{$row['wr_3']}</td>
<td class='txt'>{$row['wr_4']}</td>
<td class='txt'>{$row['wr_5']}</td>
<td class='txt'>{$row['wr_6']}</td>
<td class='txt'>{$row['wr_7']}</td>
<td class='txt'>{$row['wr_8']}</td>
<td class='txt'>{$row['wr_9']}</td>
<td class='txt'>{$row['wr_10']}</td>
</tr>
";
$number--;
}
?>
</table>
</body>
</html>
참고자료
https://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=qna_function&wr_id=249834
1. 그누보드5 / skin / board / basic / _common.php 생성
<?php
include_once('../../../common.php');
// 테마 폴더 스킨폴더 이용할때 아래꺼 사용
//include_once('../../../../../common.php');
?>
2. 그누보드5 / skin / board / basic / list.skin.php 적절한 위치에 아래 코드 추가
<?php if ($is_admin) { ?>
<div style="float:left">
<a href='<?php echo $board_skin_url; ?>/excel.php?bo_table=<?php echo $bo_table; ?>' class="btn_admin btn2" target='_blank'><i class="fa fa-user-circle" aria-hidden="true"></i> Excel (전체받기)</a>
</div>
<div style="float:left; padding-left:20px;">
<form action="<?php echo $board_skin_url; ?>/excel.php" method="post">
<?php include_once(G5_PLUGIN_PATH.'/jquery-ui/datepicker.php'); ?>
<script>
$(function(){
// 시작날짜와 끝나는 날짜를 함께 선택해서 사용할때
var dates = $( "#datepicker_from, #datepicker_to" ).datepicker({
//defaultDate: "+1w", // 기본선택일이 1 week 이후가 선택되는 옵션
changeMonth: true,
dateFormat: "yy-mm-dd", // 년월일 표시방법 yy-mm-dd 또는 yymmdd
numberOfMonths: 2, // 한눈에 보이는 월달력수
onSelect: function( selectedDate ) {
var option = this.id == "datepicker_from" ? "minDate" : "maxDate",
instance = $( this ).data( "datepicker" ),
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not( this ).datepicker( "option", option, date );
}
});
});
</script>
<input type="hidden" name="bo_table" value="<?php echo $bo_table; ?>">
<input type="text" name="date1" class="frm_input" style="width:72px; height:35px;" readonly id="datepicker_from"> ~
<input type="text" name="date2" class="frm_input" style="width:72px; height:35px;" readonly id="datepicker_to">
<input type="submit" class="frm_input" style="width:72px; height:35px;" value="엑셀받기">
</form>
</div>
<div style="clear: both;"></div>
<?php } ?>
3. 그누보드5 / skin / board / basic / excel.php 파일 생성
<?php
include_once "_common.php";
if (!$is_admin) {
alert("관리자만 접근 가능합니다.");
exit;
}
$bo_table = $_REQUEST['bo_table'];
$excel_down = $g5['write_prefix'] . $bo_table; //엑셀 다운로드 테이블
$wr_id = $_REQUEST['wr_id'];
//$hp_filename = "파일명";
$hp_filename = $bo_table."_".date('Y_md h_m');
//@sql_query("SET CHARACTER SET utf8"); // 한글깨지면 주석해지
if ($ms =="excel"){
$g5['title'] = "엑셀 문서 다운로드";
header( "Content-type: application/vnd.ms-excel" );
header( "Content-Disposition: attachment; filename={$hp_filename}.xls" );
//header( "Content-Description: PHP4 Generated Data" );
} else if ($ms =="power"){
$g5['title'] = "파워포인트 문서 다운로드";
header( "Content-type: application/vnd.ms-powerpoint" );
header( "Content-Disposition: attachment; filename={$hp_filename}.ppt" );
// header( "Content-Description: PHP4 Generated Data" );
} else if ($ms =="word"){
$g5['title'] = "워드 문서 다운로드";
header( "Content-type: application/vnd.ms-word" );
header( "Content-Disposition: attachment; filename={$hp_filename}.doc" );
//header( "Content-Description: PHP4 Generated Data" );
} else if ($ms =="memo"){
$g5['title'] = "메모 문서 다운로드";
header( "Content-type: application/vnd.ms-notepad" );
header( "Content-Disposition: attachment; filename={$hp_filename}.txt" );
} else {
header( "Content-type: application/vnd.ms-excel" );
header( "Content-Disposition: attachment; filename={$hp_filename}.xls" );
}
header( "Content-Description: PHP4 Generated Data" );
$date1 = $_POST['date1']." 00:00:00";
$date2 = $_POST['date2']." 23:59:59";
$search = " where 1 ";
if ($_POST['date1'] && !$_POST['date2']) {
$search = " and wr_datetime > '{$date1}' ";
} elseif (!$_POST['date1'] && $_POST['date2']) {
$search = " and wr_datetime < '{$date2}' ";
} elseif ($_POST['date1'] && $_POST['date2']) {
$search = " and wr_datetime > '{$date1}' && wr_datetime < '{$date2}' ";
}
// 원글 + 코멘트 다운로드
$temp=sql_fetch_array(sql_query("select count(*) from {$excel_down} "));
$sql="select * from {$excel_down} {$search} order by wr_datetime desc";
$qry=sql_query($sql);
// 원글만 다운로드 (코멘트 제외) , 2013-10-21 추가
//$temp=sql_fetch_array(sql_query("select count(*) from {$excel_down} and wr_is_comment = '0' and wr_content = '{$wr_id}' "));
//$sql="select * from {$excel_down} {$search} and wr_is_comment = '0' and wr_content = '{$wr_id}' order by wr_datetime desc";
//$qry=sql_query($sql);
$number=$temp[0];
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.txt {
mso-style-parent:style0;
mso-number-format:"\@";
border:.5pt solid windowtext;
}
</style>
</head>
<body>
<table>
<tr>
<td class='txt'>아이디</td>
<td class='txt'>이름</td>
<td class='txt'>이메일</td>
<td class='txt'>홈페이지</td>
<td class='txt'>작성일</td>
<td class='txt'>분류</td>
<td class='txt'>제목</td>
<td class='txt'>내용</td>
<td class='txt'>필드1</td>
<td class='txt'>필드2</td>
<td class='txt'>필드3</td>
<td class='txt'>필드4</td>
<td class='txt'>필드5</td>
<td class='txt'>필드6</td>
<td class='txt'>필드7</td>
<td class='txt'>필드8</td>
<td class='txt'>필드9</td>
<td class='txt'>필드10</td>
</tr>
<?php
while($row=sql_fetch_array($qry)) {
echo "
<tr>
<td class='txt'>{$row['mb_id']}</td>
<td class='txt'>{$row['wr_name']}</td>
<td class='txt'>{$row['wr_email']}</td>
<td class='txt'>{$row['wr_homepage']}</td>
<td class='txt'>{$row['wr_datetime']}</td>
<td class='txt'>{$row['ca_name']}</td>
<td class='txt'>{$row['wr_subject']}</td>
<td class='txt'>".get_text(strip_tags($row['wr_content']))."</td>
<td class='txt'>{$row['wr_1']}</td>
<td class='txt'>{$row['wr_2']}</td>
<td class='txt'>{$row['wr_3']}</td>
<td class='txt'>{$row['wr_4']}</td>
<td class='txt'>{$row['wr_5']}</td>
<td class='txt'>{$row['wr_6']}</td>
<td class='txt'>{$row['wr_7']}</td>
<td class='txt'>{$row['wr_8']}</td>
<td class='txt'>{$row['wr_9']}</td>
<td class='txt'>{$row['wr_10']}</td>
</tr>
";
$number--;
}
?>
</table>
</body>
</html>
참고자료
https://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=qna_function&wr_id=249834
댓글목록
등록된 댓글이 없습니다.