<?php

/*
=====================================================================

  프로젝트 이름 : 피리 카페 심플

  만든사람 : 피리 PIREE ( tosports@naver.com )

  홈페이지 : https://piree.kr/nett_dev

  작성날짜 : 2024년 04월 21일 일요일 오전 12시 15분 / 흐림, 12.1, 쾌적, 15, 13, 45%, 12.2mm, 50%, 2.9ms / 좋음, 10, 9

  저 작 권 : Copyright ⓒ 2024 피리 piree.kr All right reserved
              그누보드 외에 추가된 소스는~
              만든사람의 허락없이 무단으로 사용할수 없습니다.
              사용하고자 할 경우 만든사람의 허락을 받아야 합니다.
              http://.piree.kr 에 문의해 주세요.

=====================================================================
 피리 카페 심플 > 프로그램 > 피리 카페 관리 > 내 카페 > 게시판 > 게시판 관련 라이브러리 파일
=====================================================================

*/

  IF (!defined('_GNUBOARD_'))                      EXIT;

  function cafe_article_count_reload($piree_cafe_n, $cafe_member_id='', $board_cate_n_a, $func_calculation_c='plus', $func_count_write=0, $func_count_comment=0)
  {

    global $g5;
    global $piree;
    global $board_cate_list_a;

    SWITCH ( $func_calculation_c )
    {
        CASE 'plus' :           $save_calculation_n = '+';          BREAK;
        CASE 'minus' :          $save_calculation_n = '-';          BREAK;
        DEFAULT :               $save_calculation_n = '+';          BREAK;
    }

    $sql_select_cafe  = "SELECT COUNT(*) FROM `". $piree['cafe_article'] ."` ";
    $sql_select_cafe .= "WHERE `wr_pi_piree_cafe_n` = '". $piree_cafe_n ."'";

    $sql_select_article = $sql_select_cafe ." AND `wr_is_comment` = '0'";

    $sql_select_comment = $sql_select_cafe ." AND `wr_is_comment` = '1'";

    IF ( count($board_cate_n_a) > 0 )
    {

      FOREACH ( $board_cate_n_a AS $loop_cate_n=>$val_out)
      {

        IF ( $loop_cate_n > 0 )
        {

          IF ( $board_cate_list_a[$loop_cate_n]['bca_depth_n'] == 2 )
          {

            $loop_cate_1dep_n = $board_cate_list_a[$loop_cate_n]['bca_1_n'];

            $board_cate_1_a[$loop_cate_1dep_n] = $loop_cate_1dep_n;

          }

          $sql_select = $sql_select_article ." AND `wr_pi_board_cate_n` = '". $loop_cate_n ."'";
          $artilce_this_t = (int)sql_efv($sql_select);

// $artilce_this_t ." <<================== ARTICLE > COUNT > 10 > ARTILCE_THIS_T <br>\n";

// $sql_select ." <<================== ARTICLE > COUNT > 11 > SQL_SELECT <br>\n";

// "<br>\n";

          $sql_select = $sql_select_comment ." AND `wr_pi_board_cate_n` = '". $loop_cate_n ."'";
          $comment_this_t = (int)sql_efv($sql_select);

// $artilce_this_t ." <<================== ARTICLE > COUNT > 20 > ARTILCE_THIS_T <br>\n";

// $sql_select ." <<================== ARTICLE > COUNT > 21 > SQL_SELECT <br>\n";

// "<br>\n";

          $sql_update  = "UPDATE `". $piree['cafe_board'] ."` SET ";
          $sql_update .= "`bca_count_write`   = '". $artilce_this_t ."', ";
          $sql_update .= "`bca_count_comment` = '". $comment_this_t ."' ";
          $sql_update .= "WHERE `bca_cafe_n` = '". $piree_cafe_n ."' AND `bca_cate_n` = '". $loop_cate_n ."'";

// $sql_update ." <<================== ARTICLE > COUNT > 32 > SQL_UPDATE <br>\n";

// "<br>\n";
// "<br>\n";

          IF ( !sql_query($sql_update) )
          {
            alert("[ ". $board_cate_list_a[$loop_cate_n]['bca_cate_s'] ." - 2 ]의 게시글, 댓글 수를 새로고침하지 못했습니다.");
          }

        }

      }

      IF ( count($board_cate_1_a) > 0 )
      {

        FOREACH ( $board_cate_1_a AS $loop_cate_1_n=>$val_in)
        {

          IF ( $loop_cate_1_n > 0 )
          {

            $sql_select = $sql_select_article ." AND (`wr_pi_board_cate_n` BETWEEN '". $loop_cate_1_n ."' AND '". ($loop_cate_1_n+99) ."')";
            $artilce_this_t = (int)sql_efv($sql_select);

// $artilce_this_t ." <<================== ARTICLE > COUNT > 40 > ARTILCE_THIS_T <br>\n";

// $sql_select ." <<================== ARTICLE > COUNT > 41 > SQL_SELECT <br>\n";

// "<br>\n";

            $sql_select = $sql_select_comment ." AND (`wr_pi_board_cate_n` BETWEEN '". $loop_cate_1_n ."' AND '". ($loop_cate_1_n+99) ."')";
            $comment_this_t = (int)sql_efv($sql_select);

// $artilce_this_t ." <<================== ARTICLE > COUNT > 50 > ARTILCE_THIS_T <br>\n";

// $sql_select ." <<================== ARTICLE > COUNT > 51 > SQL_SELECT <br>\n";

// "<br>\n";

            $sql_update  = "UPDATE `". $piree['cafe_board'] ."` SET ";
            $sql_update .= "`bca_count_write`   = '". $artilce_this_t ."', ";
            $sql_update .= "`bca_count_comment` = '". $comment_this_t ."' ";
            $sql_update .= "WHERE `bca_cafe_n` = '". $piree_cafe_n ."' AND `bca_cate_n` = '". $loop_cate_1_n ."'";

// $sql_update ." <<================== ARTICLE > COUNT > 62 > SQL_UPDATE <br>\n";

// "<br>\n";
// "<br>\n";

            IF ( !sql_query($sql_update) )
            {
              alert("[ ". $board_cate_list_a[$loop_cate_1_n]['bca_cate_s'] ." - 2 ]의 게시글, 댓글 수를 새로고침하지 못했습니다.");
            }

          }

        }

      }

    }

      $sql_select = $sql_select_cafe ." AND `wr_is_comment` = '0'";
      $cafe_cate_artilce_t = (int)sql_efv($sql_select);

// $artilce_this_t ." <<================== ARTICLE > COUNT > 70 > ARTILCE_THIS_T <br>\n";

// $sql_select ." <<================== ARTICLE > COUNT > 71 > SQL_SELECT <br>\n";

// "<br>\n";

      $sql_select = $sql_select_cafe ." AND `wr_is_comment` = '1'";
      $cafe_cate_comment_t = (int)sql_efv($sql_select);

// $artilce_this_t ." <<================== ARTICLE > COUNT > 80 > ARTILCE_THIS_T <br>\n";

// $sql_select ." <<================== ARTICLE > COUNT > 81 > SQL_SELECT <br>\n";

// "<br>\n";

      $sql_update  = "UPDATE `". $piree['cafe_board'] ."` SET ";
      $sql_update .= "`bca_count_write`   = '". $cafe_cate_artilce_t ."', ";
      $sql_update .= "`bca_count_comment` = '". $cafe_cate_comment_t ."' ";
      $sql_update .= "WHERE `bca_cafe_n` = '". $piree_cafe_n ."' AND `bca_cate_n` = '0'";

// $sql_update ." <<================== ARTICLE > COUNT > 92 > SQL_UPDATE <br>\n";

// "<br>\n";
// "<br>\n";

      IF ( !sql_query($sql_update) )
      {
        alert("[ ". $piree_cafe_name_s ." ]\\n\\n카페 전체 게시글의 게시글, 댓글 수를 새로고침하지 못했습니다.");
      }

      $sql_update  = "UPDATE `". $piree['cafe'] ."` SET ";
      $sql_update .= "`cafe_article_t` = '". $cafe_cate_artilce_t ."', ";
      $sql_update .= "`cafe_comment_t` = '". $cafe_cate_comment_t ."' ";
      $sql_update .= "WHERE `cafe_row_n` = '". $piree_cafe_n ."'";

// $sql_update ." <<================== ARTICLE > COUNT > 92 > SQL_UPDATE <br>\n";

// "<br>\n";
// "<br>\n";

      IF ( !sql_query($sql_update) )
      {
        alert("[ ". $piree_cafe_name_s ." ]\\n\\n카페 정보의 게시글, 댓글 수를 새로고침하지 못했습니다.");
      }

/*

      $sql_select = $sql_select_cafe ." AND `wr_is_comment` = '0'";
      $cafe_cate_artilce_t = (int)sql_efv($sql_select);

      $sql_select = $sql_select_cafe ." AND `wr_is_comment` = '1'";
      $cafe_cate_comment_t = (int)sql_efv($sql_select);

      $sql_update  = "UPDATE `". $piree['cafe_board'] ."` SET ";
      $sql_update .= "`bca_count_write`   = '". $cafe_cate_artilce_t ."', ";
      $sql_update .= "`bca_count_comment` = '". $cafe_cate_comment_t ."' ";
      $sql_update .= "WHERE `bca_cafe_n` = '". $piree_cafe_n ."' AND `bca_cate_n` = '0'";

      IF ( !sql_query($sql_update) )
      {
        alert("[ ". $piree_cafe_name_s ." ] 카페의 게시글, 댓글 수를 새로고침하지 못했습니다.");
      }

      $sql_update  = "UPDATE `". $piree['cafe_board'] ."` SET ";
      $sql_update .= "`bca_count_write` = `bca_count_write` ". $save_calculation_n ." '". $func_count_write ."', ";
      $sql_update .= "`bca_count_comment` = `bca_count_comment` ". $save_calculation_n ." '". $func_count_comment ."' ";
      $sql_update .= "WHERE `bca_cafe_n` = '". $piree_cafe_n ."' AND `bca_cate_n` = '0'";

// $sql_select ." <<============ A > A > 1 > 71 > SQL_SELECT <br>\n";

// "<br>\n";

      IF ( !sql_query($sql_update) )
      {
        alert("[ ". $piree_cafe_name_s ." ] 카페의 게시글, 댓글 수를 새로고침하지 못했습니다.");
      }

*/

// $func_count_write ." <<================== ARTICLE > COUNT > 100 > FUNC_COUNT_WRITE <br>\n";

// $func_count_comment ." <<================== ARTICLE > COUNT > 101 > FUNC_COUNT_COMMENT <br>\n";

// "<br>\n";

    IF ( $func_count_write > 0 || $func_count_comment > 0 )
    {

       $sql_update  = "UPDATE `". $g5['board_table'] ."` SET ";
       $sql_update .= "`bo_count_write` = `bo_count_write` ". $save_calculation_n ." '". $func_count_write ."', ";
       $sql_update .= "`bo_count_comment` = `bo_count_comment` ". $save_calculation_n ." '". $func_count_comment ."' ";
       $sql_update .= "WHERE `bo_table` = '". $piree['cafe_board_code'] ."'";
       sql_query($sql_update);

// $sql_update ." <<================== ARTICLE > COUNT > 111 > SQL_UPDATE <br>\n";

// "<br>\n";

    }

    IF ( $cafe_member_id )
    {

      global $cafe_member_a;

      IF ( $cafe_member_id == $cafe_member_a['mem_id'] )
      {

        $sql_select_cafe  = "SELECT COUNT(*) FROM `". $piree['cafe_article'] ."` ";
        $sql_select_cafe .= "WHERE `wr_pi_piree_cafe_n` = '". $piree_cafe_n ."' AND `mb_id` = '". $cafe_member_id ."'";

        $sql_select = $sql_select_cafe ." AND `wr_is_comment` = '0'";
        $cafe_member_artilce_t = (int)sql_efv($sql_select);

// $artilce_this_t ." <<================== ARTICLE > COUNT > 70 > ARTILCE_THIS_T <br>\n";

// $sql_select ." <<================== ARTICLE > COUNT > 71 > SQL_SELECT <br>\n";

// "<br>\n";

        $sql_select = $sql_select_cafe ." AND `wr_is_comment` = '1'";
        $cafe_member_comment_t = (int)sql_efv($sql_select);
        $cafe_member_comment_t = (int)sql_efv($sql_select);

// $artilce_this_t ." <<================== ARTICLE > COUNT > 80 > ARTILCE_THIS_T <br>\n";

// $sql_select ." <<================== ARTICLE > COUNT > 81 > SQL_SELECT <br>\n";

// "<br>\n";

        $sql_update  = "UPDATE `". $piree['cafe_member'] ."` SET ";
        $sql_update .= "`cfml_article_t` = '". $cafe_member_artilce_t ."', ";
        $sql_update .= "`cfml_comment_t` = '". $cafe_member_comment_t ."' ";
        $sql_update .= "WHERE `cfml_cafe_n` = '". $piree_cafe_n ."' AND `cfml_mem_id` = '". $cafe_member_id ."'";

// $sql_update ." <<================== ARTICLE > COUNT > 92 > SQL_UPDATE <br>\n";

// "<br>\n";
// "<br>\n";

        IF ( !sql_query($sql_update) )
        {
          alert("[ ". $piree_cafe_name_s ." ]\\n\\n카페 회원의 게시글, 댓글 수를 새로고침하지 못했습니다.");
        }

      }

    }

  }

?>