<?php
/*
 *  탭 최신글 등록하기
 */
include_once './_common.php';
set_session("ask_delete_token", $token = uniqid(time()));
include_once './index.php';

if (!defined('_GNUBOARD_')) {
    exit;
}

include_once G5_PLUGIN_PATH . "/asktheme/_admin/head.php";
add_stylesheet('<link rel="stylesheet" href="' . G5_PLUGIN_URL . '/asktheme/plugin/' . $plugin['id'] . '/plugin_style.css">', 0);
add_javascript('<script src="' . G5_PLUGIN_URL . '/asktheme/plugin/' . $plugin['id'] . '/jquery.taginput.min.js"></script>');
//수정모드일때
if ($w == 'u' && $idx) {
    $sql = "select * from ask_plugin_indexgroup_child where aic_idx = '{$idx}'";
    $data = sql_fetch($sql);
    if (!$data) {
        alert('데이터가 없습니다.', './indexgroup_list.php');
        exit;
    }
}
?>

<div id="container">
    <div class="row">
        <div class="small-12 medium-12 large-12 columns">
            <div class="panel panel-default">
                <div class="panel-header">
                    <h1><?php echo $plugin['name'], $plugin['version']; ?> 2단계 탭최신글 등록하기</h1>
                </div>
                <div class="panel-body">
                    <form class="add_latest" action="./indexgroup_child_tab_add_update.php"  onsubmit="return form_submit(this);" method="post" enctype="multipart/form-data" autocomplete="off" >
                        <?php
                        if ($parent_idx) {
                            echo "<input type='hidden' name='parent_idx' value='{$parent_idx}'>";
                        }
                        if ($w == 'u' && $idx) {
                            echo "<input type='hidden' name='w' value='u'>";
                            echo "<input type='hidden' name='aic_idx' value='{$data['aic_idx']}'>";
                            echo "<input type='hidden' name='parent_idx' value='{$data['aic_parent_idx']}'>";
                        }
                        ?>
                        <input type="hidden" name="pc_id" value="<?php echo $plugin['id'] ?>"/>
                        <input type="hidden" name="pc_name" value="<?php echo $plugin['name'] ?>"/>
                        <input type='hidden' name='aic_tab' value='1'>
                        <input type="hidden" name="popup" value="<?php echo $popup?>/">

                        <div class="responsetable write-table">
                            <div class="tb-body">
                                <div class="tb-row">
                                    <div class="tb-cell"><label for="aic_status">사용여부<strong class="sound-only">필수</strong></label></div>
                                    <div class="tb-cell">
                                        <?php
                                        if ($data['aic_status'] == '1') {
                                            $aic_use = "checked";
                                        } elseif ($data['aic_status'] == '0') {
                                            $aic_unuse = "checked";
                                        }
                                        ?>
                                        <label><input type="radio" name="aic_status" value="1" <?php echo $aic_use ?> class="indexgroup-start">사용하기</label>
                                        <label><input type="radio" name="aic_status" value="0" <?php echo $aic_unuse ?> class="indexgroup-stop">중지하기</label>
                                    </div>
                                </div>
                                <div class="tb-row">
                                    <div class="tb-cell"><label for="aic_bo_table">게시판<strong class="sound-only">필수</strong></label></div>
                                    <div class="tb-cell">
                                        <select name="aic_bo_table_load" class="input">
                                            <option value="">---- 게시판 선택 ----</option>
                                            <?php
                                            echo ask_group_board_select();
                                            ?>
                                        </select>
                                        <br/><br/>
                                        <input type="text" name="aic_bo_table" id="table_tags" class="input" size="60" rows="5"  value="<?php echo $data['aic_bo_table'] ?>"  placeholder="게시판을 입력하세요">
                                        <br/>
                                        <div class="text text-default">
                                            &middot; 탭최신글은 여러개의 게시판을 탭으로 묶어 페이지에 출력해주게 됩니다.<br/>
                                            &middot; 2개~3개 정도의 게시판을 등록하세요. 
                                        </div>
                                    </div>
                                </div>
                                <div class="tb-row">
                                    <div class="tb-cell"><label for="aic_type">스킨<strong class="sound-only">필수</strong></label></div>
                                    <div class="tb-cell">
                                        <?php
                                        if ($w == 'u') {
                                            $latest = ask_skin_select('latest', 'aic_type', 'aic_type', $data['aic_type']);
                                        } else {
                                            $latest = ask_skin_select('latest', 'aic_type', 'aic_type');
                                        }

                                        echo $latest;
                                        ?>
                                        <div class="alert alert-danger">
                                            PC, Mobile에 맞는 스킨을 선택하세요. <br/>
                                            모바일 Swipe 스킨을 PC용으로 설정하지 마세요. IE에서 동작하지 않습니다.
                                        </div>
                                    </div>
                                </div>

                                <div class="tb-row">
                                    <div class="tb-cell"><label for="aic_row">줄수</label></div>
                                    <div class="tb-cell">
                                        <input type="text" name="aic_rows" value="<?php echo $data['aic_rows'] ?>" size="10" class="input" placeholder="최신글 뽑을 줄수">
                                    </div>
                                </div>
                                <div class="tb-row">
                                    <div class="tb-cell"><label for="">정렬</label></div>
                                    <div class="tb-cell">
                                        <input type="text" name="aic_sort" value="<?php echo $data['aic_sort'] ?>" size="10" class="input" placeholder="정렬용 숫자, 작은숫자가 먼저출력됨" />
                                    </div>
                                </div>
                                <div class="tb-row">
                                    <div class="tb-cell">

                                    </div>
                                    <div class="tb-cell">
                                        <div class="button-group float-left">
                                            <button type="submit" class="button primary submit"><i class="fa fa-check"></i> 확인</button>
                                            <?php if ($w == u && $idx) { ?>
                                                <a href='./indexgroup_add.php?w=u&idx=<?php echo $data['aic_parent_idx'] ?>' class="button"><i class="fa fa-link"></i> 상위 설정으로..</a>
                                            <?php } ?>
                                        </div>
                                        <?php if ($w == u && $idx) { ?>
                                            <div class="button-group float-right">
                                                <a href='./indexgroup_delete.php?idx=<?php echo $data['aic_idx'] ?>&type=child&amp;token=<?php echo $token?>' class="button danger delete"><i class="fa fa-trash"></i> 삭제</a>
                                                <a href='./indexgroup_child_tab_add.php?parent_idx=<?php echo $data['aic_parent_idx'] ?>' class="button"><i class="fa fa-plus"></i> 탭최신글 추가등록</a>
                                            </div>
                                        <?php } ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!--responsetable-->
                    </form>
                </div>
                <div class="panel-footer">
                    mobile_로 시작하는 스킨은 모바일용입니다.
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $('#table_tags').tagsInput({
            'height': '50px',
            'width': '100%',
            'delimiter': [','], // Or a string with a single delimiter. Ex: ';'
            'removeWithBackspace': true,
            'minChars': 1,
            'maxChars': 20, // if not provided there is no limit
            'placeholderColor': '#666666'
        });
        $('.delete').click(function () {
            if (confirm('등록된 최신글 설정을 삭제하시겠습니까?')) {
                return true;
            } else {
                return false;
            }
        });
        $('select[name=aic_bo_table_load]').change(function () {
            var tag_val = $(this).val() + "(" + $('option:selected', this).text() + ")";
            if ($('#table_tags').tagExist(tag_val)) {
                $('#table_tags').removeTag(tag_val);
            }else{
                $('#table_tags').addTag(tag_val);
            }
        });
    });
    function form_submit(f) {
        //console.log(f);
        var use_status = $('input[name=aic_status]:checked').val();
        if (use_status === undefined) {
            alert('최신글 사용여부를 선택하세요');
            return false;
        }

        if ($('input[name=aic_bo_table]').val() == "") {
            alert('게시판을 선택하세요.');
            return false;
        }
        if ($('select[name=aic_type]').val() == "") {
            alert('스킨을 선택하세요.');
            return false;
        }

        if ($('input[name=aic_rows]').val() == '') {
            alert('줄수를 입력하세요.');
            return false;
        }
        if ($('input[name=aic_sort]').val() == '') {
            alert('정렬용 숫자를 입력하세요. 낮은 숫자가 먼저 출력됩니다.');
            return false;
        }
        return true;
    }
</script>
<?php
include_once G5_PLUGIN_PATH . "/asktheme/_admin/tail.php";

