<?php
/*
 * 사이드메뉴 플러그인 설치
 */
include_once './_common.php';
include_once './index.php';

if (!defined('_GNUBOARD_')) {
    exit;
}
if ($w == 'u') {
    $sql = "select * from ask_plugin_config where pc_id = '{$plugin['id']}'";
    $result = sql_fetch($sql);
    $data = unserialize($result['pc_config']);
}

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);

//컨텐츠 슬라이더 테이블 존재 검사
function ask_dbtable_exist() {
    //슬라이드 테이블
    $sql = "show tables like 'ask_plugin_sidemenu'";
    $result = sql_fetch($sql);
    $sql = "CREATE TABLE `ask_plugin_sidemenu` (
  `as_idx` int(11) NOT NULL AUTO_INCREMENT,
  `as_status` int(11) NOT NULL COMMENT '사용/중지',
  `as_gr_id` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  `as_me_code` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`as_idx`),
  KEY `as_gr_id` (`as_gr_id`)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='사이드메뉴 매칭 플러그인';";
    if (!$result) {
        sql_query($sql);
    }
}

ask_dbtable_exist();
?>
<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']; ?> 플러그인 설정</h1>
                </div>
                <div class="panel-body">
                    <?php
                    if ($w == 'u' && $mode) {
                        $refresh = "refresh=1";
                    }
                    ?>
                    <form class="setup_form" action="./setup_update.php?<?php echo $refresh ?>"  onsubmit="return form_submit(this);" method="post" enctype="multipart/form-data" autocomplete="off" >
                        <input type="hidden" name="pc_id" value="<?php echo $plugin['id'] ?>"/>
                        <input type="hidden" name="pc_name" value="<?php echo $plugin['name'] ?>"/>
                        <div class="text text-default">
                            사이드 메뉴 플러그인은 그누보드 관리자 메뉴에서 설정한 1차 메뉴 및 그 하위 메뉴를 그누보드 그룹메뉴와 연계해서 그룹메인 및 게시판, 일반페이지에 왼쪽 메뉴를 생성해 줍니다.
                        </div>
                        <div class="responsetable write-table">
                            <div class="tb-body">
                                <div class="tb-row">
                                    <div class="tb-cell tb-text"><label for="pc_use">사용여부<strong class="sound-only">필수</strong></label></div>
                                    <div class="tb-cell">
                                        <?php
                                        if ($data['pc_use'] == '1') {
                                            $pc_use = "checked";
                                        } else {
                                            $pc_unuse = "checked";
                                        }
                                        ?>
                                        <label><input type="radio" name="pc_use" value="1" <?php echo $pc_use ?> class="plugin-start">사용하기</label>
                                        <label><input type="radio" name="pc_use" value="0" <?php echo $pc_unuse ?> class="plugin-stop">사용중지</label>
                                    </div>
                                </div>
                                <div class="tb-row">
                                    <div class="tb-cell show-for-medium">

                                    </div>
                                    <div class="tb-cell clearfix">
                                        <div class="button-group">
                                            <button type="submit" class="button submit"><i class="fa fa-check"></i> 확인</button>
                                            <button type="button" class="button alert cancel"><i class="fa fa-ban"></i> 취소</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!--responsetable-->
                    </form>
                </div>
                <div class="panel-footer">
                    &middot; 항목을 빠짐없이 입력해주세요.
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    function form_submit(f) {
        //console.log(f);
        var form_radio = $('input[name=pc_use]:checked').val();
        if (form_radio === undefined) {
            alert('사용여부를 선택하세요');
            return false;
        }

<?php if ($w == 'u' && $mode == 'start') { ?>
            $('.plugin-start').attr('checked', true);
<?php } ?>
<?php if ($w == 'u' && $mode == 'stop') { ?>
            $('.plugin-stop').attr('checked', true);
<?php } ?>
        return true;
    }
    $(function () {
<?php if ($w == 'u' && $mode) { ?>
            $('.setup_form').submit();
<?php } ?>
        $('.cancel').click(function () {
            if (confirm('취소하시겠습니까?')) {
                location.href = history.go(-1);
            } else {
                return false;
            }
        });

    });
</script>
<?php
include_once G5_PLUGIN_PATH . "/asktheme/_admin/tail.php";

