게시판 카테고리 중복 체크 가능하게 하기 > 그누보드5 팁자료실

매출이 오르면 내리는 수수료! 지금 수수료센터에서 전자결제(PG)수수료 비교견적 신청해 보세요!

그누보드5 팁자료실

게시판 카테고리 중복 체크 가능하게 하기 정보

게시판 카테고리 중복 체크 가능하게 하기

본문

기존에 팁에 올라왔던게 있었는데

리스트에서는 어떻게 처리할지 고민하다가 제가 해결한 방법 올립니다.

 

ca_name 방식으로 불러오는것이 아닌 sca로 불러오도록 하였습니다.

 

991938377_1574728917.7518.jpg

 

 

1. 해당 게시판 스킨의 write.skin.php 파일 카테고리 부분을 아래와 같이 변경


<tr>
<th>카테고리</th>
<td>
<?php
    $arr = explode("|",$board['bo_category_list']);
    foreach($arr as $str) { ?>
        <input type="checkbox" name="chk_ca_name[]" value="<?php echo $str; ?>"> <?php echo $str; ?>
    <?php } ?>
      <script>
        var f = document.fwrite;
        var str=",<?php echo $write[ca_name]?>,";
        for (var i=0; i<f.length; i++) {
            if (f.elements[i].name == "chk_ca_name[]") {
                if (str.indexOf(','+f.elements[i].value+',')>=0) {
                    f.elements[i].checked = true;
                }
            }
        }
    </script>
</td>
</tr>

 

 

2. write_update.head.skin.php 파일 생성


<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
$ca_name='';
foreach($_POST[chk_ca_name] as $var) {
 $ca_name.=",$var";
}
if (strlen($ca_name)) $ca_name=substr($ca_name,1);
?>

 

 

3. bbs/list.php에서 아래부분(11번째줄쯤)을


    if ($sca=='')
        $category_option .= ' id="bo_cate_on"'; 

 

아래와 같이 변경 (&& stx==''추가)


    if ($sca=='' && $stx=='') 
        $category_option .= ' id="bo_cate_on"';

 

 

 

4. bbs/list.php에서 아래부분(17~27번째줄쯤)을


for ($i=0; $i<count($categories); $i++) {
            $category = trim($categories[$i]);
            if ($category=='') continue;
            $category_option .= '<li><a href="'.($category_href."&sca=".urlencode($category)).'"';
            $category_msg = '';
            if ($category==$sca) { // 현재 선택된 카테고리라면
                $category_option .= ' id="bo_cate_on"';
                $category_msg = '<span class="sound_only">열린 분류 </span>';
            }
            $category_option .= '>'.$category_msg.$category.'</a></li>';
        }

 

아래 소스로 교체해주세요. 


 if ($bo_table == "게시판아이디") {

        for ($i=0; $i<count($categories); $i++) {
                $category = trim($categories[$i]);
                if ($category=='') continue;
                $category_option .= '<li><a href="'.($category_href."&sfl=ca_name%2C1&&stx=".urlencode($category)).'&sop=or"'; 
                $category_msg = '';
                if ($category==$stx) {
                    $category_option .= ' id="bo_cate_on"';
                    $category_msg = '<span class="sound_only">열린 분류</span>';
                }
                $category_option .= '>'.$category_msg.$category.'</a></li>';
        }
      } else {
          /* original */
          for ($i=0; $i<count($categories); $i++) {
            $category = trim($categories[$i]);
            if ($category=='') continue;
            $category_option .= '<li><a href="'.($category_href."&sca=".urlencode($category)).'"';
            $category_msg = '';
            if ($category==$sca) { // 현재 선택된 카테고리라면
                $category_option .= ' id="bo_cate_on"';
                $category_msg = '<span class="sound_only">열린 분류 </span>';
            }
            $category_option .= '>'.$category_msg.$category.'</a></li>';
        }
           /* original */
      }

 

 

 

5. bbs/write_update.php 에서

if($board['bo_use_category']) { } 위아래를 if ($bo_table !== "게시판아이디") { }로 감싸주세요.

 


if ($bo_table !== "게시판아이디") {  //추가
 
        /* original */
        if($board['bo_use_category']) {
       
            $ca_name = trim($_POST['ca_name']);
            if(!$ca_name) {
                $msg[] = '<strong>분류</strong>를 선택하세요.';
            } else {
                $categories = array_map('trim', explode("|", $board['bo_category_list'].($is_admin ? '|공지' : '')));
                if(!empty($categories) && !in_array($ca_name, $categories))
                    $msg[] = '분류를 올바르게 입력하세요.';
       
                if(empty($categories))
                    $ca_name = '';
            }
       
        } else {
            $ca_name = '';
       
        }
       /* original */
   
}  //추가

 

해당게시판에서만 분류 선택을 안하더라도 경고창 안뜨게 했습니다.

체크박스로 바꾸니 값이 없는것처럼 받아들여서 일단은 해당 스킨에서는 분류가 필수값이 아니도록 설정했는데 일반 회원들이 글을 쓰게 하는 게시판의 경우에는 조금 더 손을 보셔야할것 같습니다.

추천
6

댓글 12개

검색까지 생각하면
lib/common.lib.php도 수정해야 합니다.
// 검색 구문을 얻는다.
function get_sql_search($search_ca_name, $search_field, $search_text, $search_operator='and')
{
    global $g5;

    $str = "";
    if ($search_ca_name)
        $str = " ca_name like '%{$search_ca_name}%'  ";

완전한 방법은 아닙니다.
2개 이상의 카테고리 지정 방식은 set이나 bit 방식으로 하는 것을 추천합니다.
lib/common.lib.php에서

// 검색 구문을 얻는다.
function get_sql_search($search_ca_name, $search_field, $search_text, $search_operator='and')
{
    global $g5;
    global $bo_table;

    $str = "";
    if ($search_ca_name)
        $str = " ca_name = '$search_ca_name' ";
 
    if($search_ca_name && $bo_table == 'gallery') // bo_table 값에 쓰실 게시판주소bo_table값작성
    {
        $str = " ca_name LIKE '%$search_ca_name%' ";
    }

다 했고 글쓰기 까지 되고, 글 보기까지 잘 되는데요 카테고리를 누르면 

Not Found

The requested URL /loan_area&sfl=ca_name,1&&stx=ì¸ì²œ&sop=or was not found on this server. 이 오류가 뜹니다 

@그누초보다 저도 그 에러 났는데요. 원인은 설정화면에서 URL 줄이기 체크하셔서 그럽니다. 해제 하시면 잘 될거에요^^

write_update.head.skin.php 

 

<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
$ca_name='';
foreach($_POST[chk_ca_name] as $var) {
 $ca_name.=",$var";
}
if (strlen($ca_name)) $ca_name=substr($ca_name,1);
?>
 

 

위 부분에 오류가 났습니다.

 

ChatGPT 답변을 받아서 처리하니 정상 작동하였습니다.

 

if (!defined('_GNUBOARD_')) exit; // Prevent direct access

$ca_name = ''; // Initialize the category name string

// Concatenate each selected category name with a comma
if (isset($_POST['chk_ca_name']) && is_array($_POST['chk_ca_name'])) {
    foreach($_POST['chk_ca_name'] as $var) {
        $ca_name .= ",$var";
    }
}

// Remove the leading comma if any categories were selected
if (strlen($ca_name)) {
    $ca_name = substr($ca_name, 1);
}
 

 

write.skin.php.     chatGPT 수정분 

 

<?php
// Assuming $board['bo_category_list'] and $write['ca_name'] are properly defined earlier

// Explode the category list
$categories = explode("|", $board['bo_category_list']);

// Generate the checkboxes
foreach ($categories as $category) { ?>
    <div class="bo_w_ico write_div">
        <input type="checkbox" name="chk_ca_name[]" value="<?php echo htmlspecialchars($category, ENT_QUOTES, 'UTF-8'); ?>"> <?php echo htmlspecialchars($category, ENT_QUOTES, 'UTF-8'); ?>
    </div>
<?php } ?>

<script>
    // Get the form reference
    var f = document.forms['fwrite'];
    // Get the selected categories as a comma-separated string
    var selectedCategories = ",<?php echo htmlspecialchars($write['ca_name'], ENT_QUOTES, 'UTF-8'); ?>,";

    // Loop through the form elements
    for (var i = 0; i < f.elements.length; i++) {
        // Check if the element is a checkbox with the name 'chk_ca_name[]'
        if (f.elements[i].name == "chk_ca_name[]") {
            // Check if the checkbox value is in the selected categories string
            if (selectedCategories.indexOf(',' + f.elements[i].value + ',') >= 0) {
                f.elements[i].checked = true;
            }
        }
    }
</script>
 

전체 2,454 |RSS
그누보드5 팁자료실 내용 검색

회원로그인

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