전체게시물에 선택삭제 기능넣기

This commit is contained in:
gnuboard
2013-11-25 12:57:47 +09:00
parent 526e250898
commit e93e829fb6
2 changed files with 195 additions and 0 deletions

130
bbs/new_delete.php Normal file
View File

@ -0,0 +1,130 @@
<?php
include_once('./_common.php');
//print_r2($_POST); exit;
if ($is_admin != 'super')
alert("최고관리자만 접근이 가능합니다.");
$board = array();
for($i=0;$i<count($_POST['chk_bn_id']);$i++)
{
list($bo_table, $wr_id) = explode(",", $_POST['chk_bn_id'][$i]);
$write_table = $g5['write_prefix'].$bo_table;
if ($board['bo_table'] != $bo_table)
$board = sql_fetch(" select bo_subject, bo_write_point, bo_comment_point, bo_notice from {$g5['board_table']} where bo_table = '$bo_table' ");
$sql = " select * from $write_table where wr_id = '$wr_id' ";
$write = sql_fetch($sql);
if (!$write) continue;
// 원글 삭제
if ($write['wr_is_comment']==0)
{
$len = strlen($write['wr_reply']);
if ($len < 0) $len = 0;
$reply = substr($write['wr_reply'], 0, $len);
// 나라오름님 수정 : 원글과 코멘트수가 정상적으로 업데이트 되지 않는 오류를 잡아 주셨습니다.
$sql = " select wr_id, mb_id, wr_is_comment from $write_table where wr_parent = '{$write['wr_id']}' order by wr_id ";
$result = sql_query($sql);
while ($row = sql_fetch_array($result))
{
// 원글이라면
if (!$row['wr_is_comment'])
{
if (!delete_point($row['mb_id'], $bo_table, $row['wr_id'], '쓰기'))
insert_point($row['mb_id'], $board['bo_write_point'] * (-1), "{$board['bo_subject']} $row[wr_id] 글삭제");
// 업로드된 파일이 있다면 파일삭제
$sql2 = " select * from {$g5['board_file_table']} where bo_table = '$bo_table' and wr_id = '{$row['wr_id']}' ";
$result2 = sql_query($sql2);
while ($row2 = sql_fetch_array($result2))
@unlink(G5_DATA_PATH.'/file/'.$bo_table.'/'.$row2['bf_file']);
// 파일테이블 행 삭제
sql_query(" delete from {$g5['board_file_table']} where bo_table = '$bo_table' and wr_id = '{$row['wr_id']}' ");
$count_write++;
}
else
{
// 코멘트 포인트 삭제
if (!delete_point($row['mb_id'], $bo_table, $row['wr_id'], '코멘트'))
insert_point($row['mb_id'], $board['bo_comment_point'] * (-1), "{$board['bo_subject']} {$write['wr_id']}-{$row['wr_id']} 코멘트삭제");
$count_comment++;
}
}
if ($pressed == '선택내용삭제') {
// 게시글 내용만 삭제
sql_query(" update $write_table set wr_subject = '{$g5['time_ymdhis']} - 본인 요청으로 인한 삭제 (냉무) ☆', wr_content = '', wr_name='본인요청삭제☆' where wr_id = '{$write['wr_id']}' ");
} else {
// 게시글 삭제
sql_query(" delete from $write_table where wr_parent = '{$write['wr_id']}' ");
}
// 최근게시물 삭제
sql_query(" delete from {$g5['board_new_table']} where bo_table = '$bo_table' and wr_parent = '{$write['wr_id']}' ");
// 스크랩 삭제
sql_query(" delete from {$g5['scrap_table']} where bo_table = '$bo_table' and wr_id = '{$write['wr_id']}' ");
// 공지사항 삭제
$notice_array = explode("\n", trim($board['bo_notice']));
$bo_notice = "";
for ($k=0; $k<count($notice_array); $k++)
if ((int)$write['wr_id'] != (int)$notice_array[$k])
$bo_notice .= $notice_array[$k] . "\n";
$bo_notice = trim($bo_notice);
sql_query(" update {$g5['board_table']} set bo_notice = '$bo_notice' where bo_table = '$bo_table' ");
if ($pressed == '선택삭제') {
// 글숫자 감소
if ($count_write > 0 || $count_comment > 0) {
sql_query(" update {$g5['board_table']} set bo_count_write = bo_count_write - '$count_write', bo_count_comment = bo_count_comment - '$count_comment' where bo_table = '$bo_table' ");
}
}
}
else // 코멘트 삭제
{
//--------------------------------------------------------------------
// 코멘트 삭제시 답변 코멘트 까지 삭제되지는 않음
//--------------------------------------------------------------------
//print_r2($write);
$comment_id = $wr_id;
$len = strlen($write['wr_comment_reply']);
if ($len < 0) $len = 0;
$comment_reply = substr($write['wr_comment_reply'], 0, $len);
// 코멘트 삭제
if (!delete_point($write['mb_id'], $bo_table, $comment_id, '코멘트')) {
insert_point($write['mb_id'], $board['bo_comment_point'] * (-1), "{$board['bo_subject']} {$write[wr_parent]}-{$comment_id} 코멘트삭제");
}
// 코멘트 삭제
sql_query(" delete from $write_table where wr_id = '$comment_id' ");
// 코멘트가 삭제되므로 해당 게시물에 대한 최근 시간을 다시 얻는다.
$sql = " select max(wr_datetime) as wr_last from $write_table where wr_parent = '{$write['wr_parent']}' ";
$row = sql_fetch($sql);
// 원글의 코멘트 숫자를 감소
sql_query(" update $write_table set wr_comment = wr_comment - 1, wr_last = '$row[wr_last]' where wr_id = '{$write['wr_parent']}' ");
// 코멘트 숫자 감소
sql_query(" update {$g5['board_table']} set bo_count_comment = bo_count_comment - 1 where bo_table = '$bo_table' ");
// 새글 삭제
sql_query(" delete from {$g5['board_new_table']} where bo_table = '$bo_table' and wr_id = '$comment_id' ");
}
}
goto_url("new.php?sfl=$sfl&stx=$stx&page=$page");
?>

View File

@ -33,10 +33,26 @@ if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
<!-- } 전체게시물 검색 끝 -->
<!-- 전체게시물 목록 시작 { -->
<form name="fnewlist" method="post" action="#" onsubmit="return fnew_submit(this);">
<input type="hidden" name="sw" value="move">
<input type="hidden" name="view" value="<?php echo $view; ?>">
<input type="hidden" name="sfl" value="<?php echo $sfl; ?>">
<input type="hidden" name="stx" value="<?php echo $stx; ?>">
<input type="hidden" name="srows" value="<?php echo $srows; ?>">
<input type="hidden" name="bo_table" value="<?php echo $bo_table; ?>">
<input type="hidden" name="page" value="<?php echo $page; ?>">
<input type="hidden" name="pressed" value="">
<div class="tbl_head01 tbl_wrap">
<table>
<thead>
<tr>
<?php if ($is_admin) { ?>
<th scope="col">
<label for="all_chk" class="sir_sr">목록 전체</label>
<input type="checkbox" id="all_chk">
</th>
<?php } ?>
<th scope="col">그룹</th>
<th scope="col">게시판</th>
<th scope="col">제목</th>
@ -48,11 +64,18 @@ if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
<?php
for ($i=0; $i<count($list); $i++)
{
$num = $total_count - ($page - 1) * $config['cf_page_rows'] - $i;
$gr_subject = cut_str($list[$i]['gr_subject'], 20);
$bo_subject = cut_str($list[$i]['bo_subject'], 20);
$wr_subject = get_text(cut_str($list[$i]['wr_subject'], 80));
?>
<tr>
<?php if ($is_admin) { ?>
<td class="sir_set_chk">
<label for="chk_bn_id_<?php echo $i; ?>" class="sir_sr"><?php echo $num?>번</label>
<input type="checkbox" name="chk_bn_id[]" value="<?php echo $list[$i]['bo_table'].','.$list[$i]['wr_id']; ?>">
</td>
<?php } ?>
<td class="td_group"><a href="./new.php?gr_id=<?php echo $list[$i]['gr_id'] ?>"><?php echo $gr_subject ?></a></td>
<td class="td_board"><a href="./board.php?bo_table=<?php echo $list[$i]['bo_table'] ?>"><?php echo $bo_subject ?></a></td>
<td><a href="<?php echo $list[$i]['href'] ?>"><?php echo $list[$i]['comment'] ?><?php echo $wr_subject ?></a></td>
@ -68,5 +91,47 @@ if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
</table>
</div>
<?php if ($is_admin) { ?>
<div class="sir_bw02 sir_bw">
<input type="submit" onclick="document.pressed=this.value" value="선택삭제" class="sir_b01_adm">
<input type="submit" onclick="document.pressed=this.value" value="선택내용삭제" class="sir_b01_adm">
</div>
<?}?>
</form>
<?php if ($is_admin) { ?>
<script>
$(function(){
$('#all_chk').click(function(){
$('[name="chk_bn_id[]"]').attr('checked', this.checked);
});
});
function fnew_submit(f)
{
f.pressed.value = document.pressed;
var cnt = 0;
for (var i=0; i<f.length; i++) {
if (f.elements[i].name == "chk_bn_id[]" && f.elements[i].checked)
cnt++;
}
if (!cnt) {
alert(document.pressed+"할 게시물을 하나 이상 선택하세요.");
return false;
}
if (!confirm("선택한 게시물을 정말 "+document.pressed+" 하시겠습니까?\n\n한번 삭제한 자료는 복구할 수 없습니다")) {
return false;
}
f.action = "./new_delete.php";
return true;
}
</script>
<?php } ?>
<?php echo $write_pages ?>
<!-- } 전체게시물 목록 끝 -->