<?php
include_once('../../common.php');

$mod_type = isset($_POST['mod_type']) ? $_POST['mod_type'] : '';



if($mod_type == 1) { //환경설정
    $co_color = isset($_POST['co_color']) ? $_POST['co_color'] : '';
    $co_header = isset($_POST['co_header']) ? $_POST['co_header'] : '';
    $co_layout = isset($_POST['co_layout']) ? $_POST['co_layout'] : '';
    $co_font = isset($_POST['co_font']) ? $_POST['co_font'] : '';
    $co_sub_width = isset($_POST['co_sub_width']) ? $_POST['co_sub_width'] : '';
    $co_main_width = isset($_POST['co_main_width']) ? $_POST['co_main_width'] : '';
    $co_tb_width = isset($_POST['co_tb_width']) ? $_POST['co_tb_width'] : '';
}

if($mod_type == 2) { //모듈설정
    $set_title = isset($_POST['set_title']) ? $_POST['set_title'] : '';
    $set_layout = isset($_POST['set_layout']) ? $_POST['set_layout'] : '';
    $set_id = isset($_POST['set_id']) ? $_POST['set_id'] : '';
    $set_type = isset($_POST['set_type']) ? $_POST['set_type'] : '';
    $theme_name = isset($_POST['theme_name']) ? $_POST['theme_name'] : '';
}

if($mod_type == "del") { //모듈삭제
    $set_layout = isset($_POST['set_layout']) ? $_POST['set_layout'] : '';
    $set_id = isset($_POST['set_id']) ? $_POST['set_id'] : '';
    $theme_name = isset($_POST['theme_name']) ? $_POST['theme_name'] : '';
}

?>


   
    <?php if($mod_type == 1) { ?>
        <?php
    
            if($is_admin) {
            $sql = " update rb_config set co_layout = '{$co_layout}', co_color = '{$co_color}', co_header = '{$co_header}', co_font = '{$co_font}', co_sub_width = '{$co_sub_width}', co_main_width = '{$co_main_width}', co_tb_width = '{$co_tb_width}', co_datetime = '".G5_TIME_YMDHIS."', co_ip = '{$_SERVER['REMOTE_ADDR']}' ";
            sql_query($sql);
            }

            $data = array(
                'co_color' => $co_color,
                'co_header' => $co_header,
                'co_layout' => $co_layout,
                'co_font' => $co_font,
                'co_sub_width' => $co_sub_width,
                'co_main_width' => $co_main_width,
                'co_tb_width' => $co_tb_width,
                'status' => 'ok',
            );
            echo json_encode($data);
        ?>
    <?php } ?>
    
    <?php if($mod_type == 2) { ?>
    <h2 class="font-B"><?php if($set_title) { ?><span><?php echo $set_title ?></span> 모듈설정<?php } else { ?>모듈추가<?php } ?></h2>
        
    <h6 class="font-R rb_config_sub_txt">
    공식 배포되는 스킨 외에 커스텀 된 스킨의 경우<br>
    갯수, 간격, 스와이프, 출력항목 등이 작동하지 않을 수 있습니다.
    </h6>

        <?php if($set_layout == "") { ?>

        <div class="rb_config_sec">
           <div class="no_data">
            변경할 모듈을 선택해주세요.
            </div>
        </div>

        <?php } else { ?>
        
            <?php if($set_layout && $set_id && $theme_name) { ?>
            
                <?php
                $rb_module = sql_fetch(" select * from rb_module where md_theme = '{$theme_name}' and md_id = '{$set_id}' and md_layout = '{$set_layout}' ");
                $rb_module_is = sql_fetch(" select COUNT(*) as cnt from rb_module where md_theme = '{$theme_name}' and md_id = '{$set_id}' and md_layout = '{$set_layout}' ");

                $md_id = isset($rb_module['md_id']) ? $rb_module['md_id'] : '';
                $md_theme = isset($rb_module['md_theme']) ? $rb_module['md_theme'] : '';
                $md_type = isset($rb_module['md_type']) ? $rb_module['md_type'] : '';
                $md_title = isset($rb_module['md_title']) ? $rb_module['md_title'] : '';
                $md_module = isset($rb_module['md_module']) ? $rb_module['md_module'] : '';
                $md_skin = isset($rb_module['md_skin']) ? $rb_module['md_skin'] : '';
                $md_bo_table = isset($rb_module['md_bo_table']) ? $rb_module['md_bo_table'] : '';
                $md_sca = isset($rb_module['md_sca']) ? $rb_module['md_sca'] : '';
                $md_widget = isset($rb_module['md_widget']) ? $rb_module['md_widget'] : '';
                $md_banner = isset($rb_module['md_banner']) ? $rb_module['md_banner'] : '';
                $md_cnt = isset($rb_module['md_cnt']) ? $rb_module['md_cnt'] : '';
                $md_col = isset($rb_module['md_col']) ? $rb_module['md_col'] : '';
                $md_row = isset($rb_module['md_row']) ? $rb_module['md_row'] : '';
                $md_col_mo = isset($rb_module['md_col_mo']) ? $rb_module['md_col_mo'] : '';
                $md_row_mo = isset($rb_module['md_row_mo']) ? $rb_module['md_row_mo'] : '';
                $md_width = isset($rb_module['md_width']) ? $rb_module['md_width'] : '';
                $md_height = isset($rb_module['md_height']) ? $rb_module['md_height'] : '';
                $md_subject_is = isset($rb_module['md_subject_is']) ? $rb_module['md_subject_is'] : '';
                $md_thumb_is = isset($rb_module['md_thumb_is']) ? $rb_module['md_thumb_is'] : '';
                $md_nick_is = isset($rb_module['md_nick_is']) ? $rb_module['md_nick_is'] : '';
                $md_date_is = isset($rb_module['md_date_is']) ? $rb_module['md_date_is'] : '';
                $md_content_is = isset($rb_module['md_content_is']) ? $rb_module['md_content_is'] : '';
                $md_icon_is = isset($rb_module['md_icon_is']) ? $rb_module['md_icon_is'] : '';
                $md_comment_is = isset($rb_module['md_comment_is']) ? $rb_module['md_comment_is'] : '';
                $md_ca_is = isset($rb_module['md_ca_is']) ? $rb_module['md_ca_is'] : '';
                $md_gap = isset($rb_module['md_gap']) ? $rb_module['md_gap'] : '';
                $md_gap_mo = isset($rb_module['md_gap_mo']) ? $rb_module['md_gap_mo'] : '';
                $md_swiper_is = isset($rb_module['md_swiper_is']) ? $rb_module['md_swiper_is'] : '';
                $md_auto_is = isset($rb_module['md_auto_is']) ? $rb_module['md_auto_is'] : '';
                $md_auto_time = isset($rb_module['md_auto_time']) ? $rb_module['md_auto_time'] : '';
                $md_order = isset($rb_module['md_order']) ? $rb_module['md_order'] : '';
                ?>
            
            <?php } else { ?>
               
               
                
            <?php } ?>


            <ul class="rb_config_sec">
                <h6 class="font-B">모듈 타이틀 설정</h6>
                <div class="config_wrap">
                    <ul>
                        <input type="text" name="md_title" class="input w100" value="<?php echo $md_title ?>" placeholder="타이틀을 입력하세요." autocomplete="off">
                        <input type="hidden" name="md_layout" value="<?php echo $set_layout ?>">
                        <input type="hidden" name="md_theme" value="<?php echo $theme_name ?>">
                        <input type="hidden" name="md_id" value="<?php echo $md_id ?>">
                    </ul>
                </div>
            </ul>
            
            

            <ul class="rb_config_sec">
                <h6 class="font-B">출력 설정</h6>
                <div class="config_wrap">
                    <ul>
                        <select class="select w100" name="md_type" id="md_type">
                            <option value="">출력타입을 선택하세요.</option>
                            <option value="latest" <?php if($md_type == "latest") { ?>selected<?php } ?>>최신글</option>
                            <option value="widget" <?php if($md_type == "widget") { ?>selected<?php } ?>>위젯</option>
                            <option value="banner" <?php if($md_type == "banner") { ?>selected<?php } ?>>배너</option>
                        </select>
                    </ul>
                      

                    <ul class="mt-5 selected_widget selected_select">
                        <select class="select w100" name="md_widget">
                            <option value="">출력할 위젯을 선택하세요.</option>
                            <?php echo rb_widget_select('rb.widget', $md_widget); ?>
                        </select>
                        
                        <h6 class="font-R rb_config_sub_txt">
                            신규 위젯 추가는 빌더가이드를 참고해주세요.<br>
                            해당 파일의 경로를 참고하셔서 코드를 직접 수정해주세요.
                        </h6>
                        
                    </ul>
                    
                    <ul class="mt-5 selected_banner selected_select">
                        <select class="select w100" name="md_banner">
                            <option value="">출력할 배너를 선택하세요.</option>
                            <?php echo rb_banner_list($md_banner); ?>
                        </select>
                        
                        <h6 class="font-R rb_config_sub_txt">
                            메인배너는 위젯에서 추가할 수 있습니다.<br>
                            배너를 먼저 등록해주셔야 합니다.
                        </h6>
                    </ul>


                    <ul class="mt-5 selected_latest selected_select" id="board_send">
                        <select class="select w100" name="md_bo_table">
                            <option value="">연결할 게시판을 선택하세요.</option>
                            <?php echo rb_board_list($md_bo_table); ?>
                        </select>
                    </ul>

                    <div id="res_cates">

                        <ul class="mt-5 selected_latest selected_select">
                            <select class="select w100" name="md_sca">
                                <option value="">전체 카테고리</option>
                                <?php echo rb_sca_list($md_bo_table, $md_sca); ?>
                            </select>
                        </ul>

                    </div>
                    
                    <ul class="mt-5 selected_latest selected_select">
                        <select class="select w100" name="md_skin">
                            <option value="">출력 스킨을 선택하세요.</option>
                            <?php echo rb_skin_select('latest', $md_skin); ?>
                        </select>
                    </ul>

                    <script>
                        
                        $('#board_send').change(function() {
                            scaAjax();
                        });
                        
                        // 해당게시판의 카테고리를 얻는다
                        function scaAjax() {
                            
                            var md_bo_table = $('select[name="md_bo_table"]').val();
                            var mod_type = 'ca_name';
                            
                            $.ajax({
                                url: '<?php echo G5_URL ?>/rb/rb.lib/ajax.res.php',
                                method: 'POST', // POST 방식으로 전송
                                dataType: 'html',
                                data: { 
                                    "md_bo_table":md_bo_table,
                                    "mod_type":mod_type,
                                },
                                success: function(response) {
                                    $("#res_cates").html(response); //성공
                                },
                                error: function(xhr, status, error) {
                                    console.error('처리에 문제가 있습니다. 잠시 후 이용해주세요.');
                                }
                
                            });
                        }
                        
                        $(document).ready(function() {
                            
                            var md_type = $('select[name="md_type"]').val();
                            $('.selected_select').hide();
                            $('.selected_all').hide();
                            
                            if(md_type == "latest") {
                                $('.selected_latest').show();
                                $('.selected_all').show();
                            } else if(md_type == "widget") {
                                $('.selected_widget').show();
                                $('.selected_all').show();
                            } else if(md_type == "banner") {
                                $('.selected_banner').show();
                                $('.selected_all').show();
                            } else { 
                                $('.selected_select').hide();
                                $('.selected_all').hide();
                            }

                            $('#md_type').change(function() {
                                var selectedValue = $(this).val();
                                $('.selected_select').hide();
                                $('.selected_all').hide();
                                if (selectedValue !== "none") {
                                    $('.selected_' + selectedValue).show();
                                    $('.selected_all').show();
                                }
                            });
                        });
                    </script>
                   
                    <?php if($md_skin) { ?>
                    <ul class="skin_path_url mt-5">
                        <li class="skin_path_url_img"><img src="<?php echo G5_URL ?>/rb/rb.config/image/icon_fd.svg"></li>
                        <li class="skin_path_url_txt">
                        <?php echo str_replace('theme','/theme/rb.basic/skin/latest',$md_skin); ?>/
                        </li>
                        <div class="cb"></div>
                    </ul>
                    <?php } ?>
                    
                    <?php if($md_widget) { ?>
                    <ul class="skin_path_url mt-5">
                        <li class="skin_path_url_img"><img src="<?php echo G5_URL ?>/rb/rb.config/image/icon_fd.svg"></li>
                        <li class="skin_path_url_txt">
                        <?php echo str_replace('rb.widget','/rb/rb.widget',$md_widget); ?>/
                        </li>
                        <div class="cb"></div>
                    </ul>
                    <?php } ?>
                    
                </div>
            </ul>
            
            
            <ul class="rb_config_sec selected_latest selected_select">
                <h6 class="font-B">출력갯수 설정</h6>
                <h6 class="font-R rb_config_sub_txt">
                    열(가로)X행(세로) 출력갯수를 설정할 수 있습니다.
                </h6>
                <div class="config_wrap">
                    <ul class="rows_inp_lr">
                        <li class="rows_inp_l">
                            <input type="number" name="md_cnt" class="input w60 h40 text-center" value="<?php echo $md_cnt ?>" placeholder="갯수" autocomplete="off" autocomplete="off">　<span>개</span>
                        </li>
                        <li class="rows_inp_r">
                            <input type="number" name="md_col" class="input w30 h40 text-center" value="<?php echo $md_col ?>" placeholder="열" autocomplete="off">　<span>X</span>　
                            <input type="number" name="md_row" class="input w30 h40 text-center" value="<?php echo $md_row ?>" placeholder="행" autocomplete="off">
                        </li>
                        <div class="cb"></div>
                    </ul>
                    <ul class="rows_inp_lr mt-10">
                        <li class="rows_inp_l rows_inp_l_span">
                            <span class="font-B">모바일 버전</span><br>
                            1024px 이하
                        </li>
                        <li class="rows_inp_r">
                            <input type="number" name="md_col_mo" class="input w30 h40 text-center" value="<?php echo $md_col_mo ?>" placeholder="열" autocomplete="off">　<span>X</span>　
                            <input type="number" name="md_row_mo" class="input w30 h40 text-center" value="<?php echo $md_row_mo ?>" placeholder="행" autocomplete="off">
                        </li>
                        <div class="cb"></div>
                    </ul>
                </div>
            </ul>
            
            <ul class="rb_config_sec selected_latest selected_select">
                <h6 class="font-B">간격 설정</h6>
                <h6 class="font-R rb_config_sub_txt">
                    게시물간의 간격(여백)을 설정할 수 있습니다.
                </h6>
                <div class="config_wrap">
                    <ul class="rows_inp_lr mt-10">
                        <li class="rows_inp_l rows_inp_l_span">
                            <span class="font-B">PC 버전</span><br>
                            1024px 이상
                        </li>
                        <li class="rows_inp_r">
                            <input type="number" name="md_gap" class="input w40 h40 text-center" value="<?php echo $md_gap ?>" placeholder="간격(px)" autocomplete="off">　<span>px (PC)</span>
                        </li>
                        <div class="cb"></div>
                    </ul>
                    <ul class="rows_inp_lr mt-10">
                        <li class="rows_inp_l rows_inp_l_span">
                            <span class="font-B">모바일 버전</span><br>
                            1024px 이하
                        </li>
                        <li class="rows_inp_r">
                            <input type="number" name="md_gap_mo" class="input w40 h40 text-center" value="<?php echo $md_gap_mo ?>" placeholder="간격(px)" autocomplete="off">　<span>px (Mobile)</span>
                        </li>
                        <div class="cb"></div>
                    </ul>
                    
                </div>
            </ul>
            
            <ul class="rb_config_sec selected_latest selected_select">
                <h6 class="font-B">스와이프 설정</h6>
                <h6 class="font-R rb_config_sub_txt">
                    행X열 보다 출력갯수가 많을 경우<br>
                    스와이프 처리 유무를 설정할 수 있습니다.
                </h6>
                <div class="config_wrap">
                    <input type="radio" name="md_swiper_is" id="md_swiper_is_0" class="magic-radio" value="0" <?php if($md_swiper_is == 0) { ?>checked<?php } ?>><label for="md_swiper_is_0">사용안함</label>　
                    <input type="radio" name="md_swiper_is" id="md_swiper_is_1" class="magic-radio" value="1" <?php if($md_swiper_is == 1) { ?>checked<?php } ?>><label for="md_swiper_is_1">사용</label>
                </div>
            </ul>
            
            <ul class="rb_config_sec selected_latest selected_select">
                <h6 class="font-B">자동롤링 설정</h6>
                <h6 class="font-R rb_config_sub_txt">
                    행X열 보다 출력갯수가 많을 경우<br>
                    자동롤링 유무를 설정할 수 있습니다.
                </h6>
                <div class="config_wrap">
                    <input type="checkbox" name="md_auto_is" id="md_auto_is" class="magic-checkbox" value="1" <?php if($md_auto_is == 1) { ?>checked<?php } ?>><label for="md_auto_is">자동롤링 사용</label>　
                    <input type="number" name="md_auto_time" class="input w30 h40 text-center" value="<?php echo $md_auto_time ?>" placeholder="밀리초" autocomplete="off">　<span>3000=3초</span>
                </div>
            </ul>
            
            <ul class="rb_config_sec selected_all">
                <h6 class="font-B">사이즈 설정</h6>
                <h6 class="font-R rb_config_sub_txt">
                    모듈의 가로, 세로 사이즈를 설정할 수 있습니다.<br>
                    숫자로만 입력해주세요.
                </h6>
                <div class="config_wrap">
                    <ul>
                        <input type="number" name="md_width" class="input w50 h40 text-center" value="<?php echo $md_width ?>" placeholder="숫자만 입력 (%)" autocomplete="off">　<span>% (가로사이즈)</span>
                    </ul>
                    <ul class="mt-5">
                        <input type="text" name="md_height" class="input w50 h40 text-center" value="auto" placeholder="auto" readonly autocomplete="off">　<span>% (세로사이즈)</span>
                    </ul>
                </div>
            </ul>
            
            <ul class="rb_config_sec selected_latest selected_select">
                <h6 class="font-B">출력항목 설정</h6>
                <h6 class="font-R rb_config_sub_txt">
                    선택하신 항목이 출력됩니다.
                </h6>
                <div class="config_wrap">
                    <ul>
                        <input type="checkbox" name="md_subject_is" id="md_subject_is" class="magic-checkbox" value="1" <?php if($md_subject_is == 1) { ?>checked<?php } ?>><label for="md_subject_is">제목</label>　
                        <input type="checkbox" name="md_thumb_is" id="md_thumb_is" class="magic-checkbox" value="1" <?php if($md_thumb_is == 1) { ?>checked<?php } ?>><label for="md_thumb_is">썸네일</label>　
                        <input type="checkbox" name="md_nick_is" id="md_nick_is" class="magic-checkbox" value="1" <?php if($md_nick_is == 1) { ?>checked<?php } ?>><label for="md_nick_is">닉네임</label>　
                        <input type="checkbox" name="md_date_is" id="md_date_is" class="magic-checkbox" value="1" <?php if($md_date_is == 1) { ?>checked<?php } ?>><label for="md_date_is">작성일</label>　
                        <input type="checkbox" name="md_ca_is" id="md_ca_is" class="magic-checkbox" value="1" <?php if($md_ca_is == 1) { ?>checked<?php } ?>><label for="md_ca_is">카테고리</label>　
                        <input type="checkbox" name="md_comment_is" id="md_comment_is" class="magic-checkbox" value="1" <?php if($md_comment_is == 1) { ?>checked<?php } ?>><label for="md_comment_is">댓글</label>　
                        <input type="checkbox" name="md_content_is" id="md_content_is" class="magic-checkbox" value="1" <?php if($md_content_is == 1) { ?>checked<?php } ?>><label for="md_content_is">본문내용</label>　
                        <input type="checkbox" name="md_icon_is" id="md_icon_is" class="magic-checkbox" value="1" <?php if($md_icon_is == 1) { ?>checked<?php } ?>><label for="md_icon_is">아이콘</label>　
                    </ul>
                </div>
            </ul>
            
            
            <ul class="rb_config_sec">
                <button type="button" class="rb_config_save font-B" onclick="executeAjax_module()">저장하기</button>
                <button type="button" class="rb_config_close font-B" onclick="toggleSideOptions_close()">취소</button>
                <div class="cb"></div>
            </ul>
        
        <?php } ?>
        
    <?php } ?>
    
    
    <?php if($mod_type == "del") { ?>
    <h2 class="font-B"><span><?php echo $set_title ?></span> 모듈삭제</h2>
    <input type="hidden" name="md_layout" value="<?php echo $set_layout ?>">
    <input type="hidden" name="md_theme" value="<?php echo $theme_name ?>">
    <input type="hidden" name="md_id" value="<?php echo $set_id ?>">
                        
        <ul class="rb_config_sec">
           <div class="no_data">
            모듈을 삭제합니다.<br>
            삭제하신 모듈은 복구할 수 없습니다.
            </div>
        </ul>
        
        <ul class="rb_config_sec">
            <button type="button" class="rb_config_save font-B" onclick="executeAjax_module_del()">삭제하기</button>
            <button type="button" class="rb_config_close font-B" onclick="toggleSideOptions_close()">취소</button>
            <div class="cb"></div>
        </ul>
    <?php } ?>
    
    


