/bbs/delete_all.php

https://gitlab.com/dev.essetel/sjnuri · PHP · 164 lines · 109 code · 27 blank · 28 comment · 40 complexity · 2c5536a36a91bc855ab62ef0f4ca8f2c MD5 · raw file

  1. <?php
  2. if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
  3. if(!$is_admin)
  4. alert('접근 권한이 없습니다.', G5_URL);
  5. // 4.11
  6. @include_once($board_skin_path.'/delete_all.head.skin.php');
  7. $count_write = 0;
  8. $count_comment = 0;
  9. $tmp_array = array();
  10. if ($wr_id) // 건별삭제
  11. $tmp_array[0] = $wr_id;
  12. else // 일괄삭제
  13. $tmp_array = (isset($_POST['chk_wr_id']) && is_array($_POST['chk_wr_id'])) ? $_POST['chk_wr_id'] : array();
  14. $chk_count = count($tmp_array);
  15. if($chk_count > (G5_IS_MOBILE ? $board['bo_mobile_page_rows'] : $board['bo_page_rows']))
  16. alert('올바른 방법으로 이용해 주십시오.');
  17. // 사용자 코드 실행
  18. @include_once($board_skin_path.'/delete_all.skin.php');
  19. // 거꾸로 읽는 이유는 답변글부터 삭제가 되어야 하기 때문임
  20. for ($i=$chk_count-1; $i>=0; $i--)
  21. {
  22. $write = sql_fetch(" select * from $write_table where wr_id = '$tmp_array[$i]' ");
  23. if ($is_admin == 'super') // 최고관리자 통과
  24. ;
  25. else if ($is_admin == 'group') // 그룹관리자
  26. {
  27. $mb = get_member($write['mb_id']);
  28. if ($member['mb_id'] == $group['gr_admin']) // 자신이 관리하는 그룹인가?
  29. {
  30. if ($member['mb_level'] >= $mb['mb_level']) // 자신의 레벨이 크거나 같다면 통과
  31. ;
  32. else
  33. continue;
  34. }
  35. else
  36. continue;
  37. }
  38. else if ($is_admin == 'board') // 게시판관리자이면
  39. {
  40. $mb = get_member($write['mb_id']);
  41. if ($member['mb_id'] == $board['bo_admin']) // 자신이 관리하는 게시판인가?
  42. if ($member['mb_level'] >= $mb['mb_level']) // 자신의 레벨이 크거나 같다면 통과
  43. ;
  44. else
  45. continue;
  46. else
  47. continue;
  48. }
  49. else if ($member['mb_id'] && $member['mb_id'] == $write['mb_id']) // 자신의 글이라면
  50. {
  51. ;
  52. }
  53. else if ($wr_password && !$write['mb_id'] && check_password($wr_password, $write['wr_password'])) // 비밀번호가 같다면
  54. {
  55. ;
  56. }
  57. else
  58. continue; // 나머지는 삭제 불가
  59. $len = strlen($write['wr_reply']);
  60. if ($len < 0) $len = 0;
  61. $reply = substr($write['wr_reply'], 0, $len);
  62. // 원글만 구한다.
  63. $sql = " select count(*) as cnt from $write_table
  64. where wr_reply like '$reply%'
  65. and wr_id <> '{$write['wr_id']}'
  66. and wr_num = '{$write['wr_num']}'
  67. and wr_is_comment = 0 ";
  68. $row = sql_fetch($sql);
  69. if ($row['cnt'])
  70. continue;
  71. // 나라오름님 수정 : 원글과 코멘트수가 정상적으로 업데이트 되지 않는 오류를 잡아 주셨습니다.
  72. //$sql = " select wr_id, mb_id, wr_comment from {$write_table} where wr_parent = '{$write[wr_id]}' order by wr_id ";
  73. $sql = " select wr_id, mb_id, wr_is_comment, wr_content from $write_table where wr_parent = '{$write['wr_id']}' order by wr_id ";
  74. $result = sql_query($sql);
  75. while ($row = sql_fetch_array($result))
  76. {
  77. // 원글이라면
  78. if (!$row['wr_is_comment'])
  79. {
  80. // 원글 포인트 삭제
  81. if (!delete_point($row['mb_id'], $bo_table, $row['wr_id'], '쓰기'))
  82. insert_point($row['mb_id'], $board['bo_write_point'] * (-1), "{$board['bo_subject']} {$row['wr_id']} 글 삭제");
  83. // 업로드된 파일이 있다면
  84. $sql2 = " select * from {$g5['board_file_table']} where bo_table = '$bo_table' and wr_id = '{$row['wr_id']}' ";
  85. $result2 = sql_query($sql2);
  86. while ($row2 = sql_fetch_array($result2)) {
  87. // 파일삭제
  88. $delete_file = run_replace('delete_file_path', G5_DATA_PATH.'/file/'.$bo_table.'/'.str_replace('../', '',$row2['bf_file']), $row2);
  89. if( file_exists($delete_file) ){
  90. @unlink($delete_file);
  91. }
  92. // 썸네일삭제
  93. if(preg_match("/\.({$config['cf_image_extension']})$/i", $row2['bf_file'])) {
  94. delete_board_thumbnail($bo_table, $row2['bf_file']);
  95. }
  96. }
  97. // 에디터 썸네일 삭제
  98. delete_editor_thumbnail($row['wr_content']);
  99. // 파일테이블 행 삭제
  100. sql_query(" delete from {$g5['board_file_table']} where bo_table = '$bo_table' and wr_id = '{$row['wr_id']}' ");
  101. $count_write++;
  102. }
  103. else
  104. {
  105. // 코멘트 포인트 삭제
  106. if (!delete_point($row['mb_id'], $bo_table, $row['wr_id'], '댓글'))
  107. insert_point($row['mb_id'], $board['bo_comment_point'] * (-1), "{$board['bo_subject']} {$write['wr_id']}-{$row['wr_id']} 댓글삭제");
  108. $count_comment++;
  109. }
  110. }
  111. // 게시글 삭제
  112. sql_query(" delete from $write_table where wr_parent = '{$write['wr_id']}' ");
  113. // 최근게시물 삭제
  114. sql_query(" delete from {$g5['board_new_table']} where bo_table = '$bo_table' and wr_parent = '{$write['wr_id']}' ");
  115. // 스크랩 삭제
  116. sql_query(" delete from {$g5['scrap_table']} where bo_table = '$bo_table' and wr_id = '{$write['wr_id']}' ");
  117. /*
  118. // 공지사항 삭제
  119. $notice_array = explode(',', trim($board['bo_notice']));
  120. $bo_notice = "";
  121. for ($k=0; $k<count($notice_array); $k++)
  122. if ((int)$write['wr_id'] != (int)$notice_array[$k])
  123. $bo_notice .= $notice_array[$k].',';
  124. $bo_notice = trim($bo_notice);
  125. */
  126. $bo_notice = board_notice($board['bo_notice'], $write['wr_id']);
  127. sql_query(" update {$g5['board_table']} set bo_notice = '$bo_notice' where bo_table = '$bo_table' ");
  128. $board['bo_notice'] = $bo_notice;
  129. }
  130. // 글숫자 감소
  131. if ($count_write > 0 || $count_comment > 0)
  132. 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' ");
  133. // 4.11
  134. @include_once($board_skin_path.'/delete_all.tail.skin.php');
  135. delete_cache_latest($bo_table);
  136. run_event('bbs_delete_all', $tmp_array, $board);
  137. goto_url(short_url_clean(G5_HTTP_BBS_URL.'/board.php?bo_table='.$bo_table.'&amp;page='.$page.$qstr));