여러 게시판 글 삭제시 total_count 질문입니다~~

여러 게시판 글 삭제시 total_count 질문입니다~~

QA

여러 게시판 글 삭제시 total_count 질문입니다~~

본문

일단, 

내글, 내댓글을 보여주는 파일을 만들었습니다 

article_member.php 와 reply_member.php  

이렇게 두개 파일로 만들었는데요, 게시물 가져오는건 아주 잘 됩니다.

 

그런데, 삭제부분을 구현하는데 있어서

조금 문제가 있어서 조언을 구하려고 합니다.

 

article_member.php와 reply_member.php에서

삭제기능을 담당하는 articel_reply_delete.php 라는 파일을 만들었는데요

베이스는 new_delete.php입니다.

 

그런데, A게시판의 게시글과 B게시판의 게시글을 체크 한 뒤

선택 삭제를 하게 되면

bo_count_write 값이 이상하게 들어갑니다;

 

count_write++ 값때문인것 같아서

게시글 마이너스 해주는 쿼리를 for문 밖에 작성하게 되면.. 

A게시판만 카운트가 마이너스 됩니다-_-;

 

저걸 도대체 어디다 넣어줘야 할까요 ㅠ

 


<?php
// articel_reply_delete.php
include_once('./_common.php');
//print_r2($_POST); exit;
if ($mb_id == $member['mb_id'])
    alert("최고관리자만 접근이 가능합니다.");
$board = array();
$save_bo_table = array();
for($i=0;$i<count($_POST['chk_bn_id']);$i++)
{
    // 실제 번호를 넘김
    $k = $_POST['chk_bn_id'][$i];
    $bo_table = $_POST['bo_table'][$k];
    $wr_id    = $_POST['wr_id'][$k];
    $save_bo_table[] = $bo_table;
    $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']);
                }
                */
                // 업로드된 파일이 있다면 파일삭제
                $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']);
                    // 썸네일삭제
                    if(preg_match("/\.({$config['cf_image_extension']})$/i", $row2['bf_file'])) {
                        delete_board_thumbnail($bo_table, $row2['bf_file']);
                    }
                }
                // 게시글 삭제
                $sql_delete = " delete from $write_table where wr_parent = '{$write['wr_id']}' ";
                sql_query($sql_delete);
                // 에디터 썸네일 삭제
                delete_editor_thumbnail($row['wr_content']);
                // 파일테이블 행 삭제
                sql_query(" delete from {$g5['board_file_table']} where bo_table = '$bo_table' and wr_id = '{$row['wr_id']}' ");
                // 2018-02-06 게시물 삭제시 member table에 mb_article 디스카운트
                if(!$gr_id = 'shop') {
                    sql_query("UPDATE $g5[member_table] SET mb_article=mb_article-1 WHERE mb_id='$member[mb_id]'");
                }
                $count_write++;
            }
            else
            {
                // 2018-02-27 원글 id 구하기
                $sql_d = "SELECT mb_id FROM {$write_table} WHERE wr_is_comment = 0 AND wr_id = $write[wr_parent]";
                $row_d = sql_fetch($sql_d);
                // 댓글 포인트 삭제
                if ($row_d['mb_id'] != $write['mb_id']) {
                    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(",", trim($board['bo_notice']));
        $bo_notice = "";
        $lf = '';
        for ($k=0; $k<count($notice_array); $k++) {
            if ((int)$write['wr_id'] != (int)$notice_array[$k])
                $bo_notice .= $nl.$notice_array[$k];
            if($bo_notice)
                $lf = ',';
        }
        $bo_notice = trim($bo_notice);
        sql_query(" update {$g5['board_table']} set bo_notice = '$bo_notice' where bo_table = '$bo_table' ");
        
        // 서로 다른 게시판을 삭제할때 게시판 한군대만 카운트 되는 문제.
        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);
        // 2018-02-27 원글 id 구하기
        $sql_d = "SELECT mb_id FROM {$write_table} WHERE wr_is_comment = 0 AND wr_id = $write[wr_parent]";
        $row_d = sql_fetch($sql_d);
        $comment_id = $wr_id;
        $len = strlen($write['wr_comment_reply']);
        if ($len < 0) $len = 0;
        $comment_reply = substr($write['wr_comment_reply'], 0, $len);
        // 2018-02-27 만약 원글과 댓글 아이디가 다르다면 댓글 포인트 차감
        if ($row_d['mb_id'] != $write['mb_id']) {
            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' ");
    }
}

$save_bo_table = array_unique($save_bo_table);
foreach ($save_bo_table as $key=>$value) {
    delete_cache_latest($value);
}
//goto_url($_SERVER['HTTP_REFERER']);
?>

이 질문에 댓글 쓰기 :

답변 1

12라인 위에 아래를 추가해 보세요
//추가 ------------------- 
$count_comment=$count_write=0;
//------------------------

012
    $k = $_POST['chk_bn_id'][$i];
013
    $bo_table = $_POST['bo_table'][$k];
014
    $wr_id    = $_POST['wr_id'][$k];
015
    $save_bo_table[] = $bo_table;
016
    $write_table = $g5['write_prefix'].$bo_table;
 

답변을 작성하시기 전에 로그인 해주세요.
전체 219
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT