<?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);
?>
<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="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 tb-text"><label for="pc_rows">출력수<strong class="sound-only">필수</strong></label></div>
                                    <div class="tb-cell"><input type="text" name="pc_rows" id="pc_rows" value="<?php echo $data['pc_rows'] ?>" class="input" maxlength="5" placeholder="출력할 회원 수를 입력"></div>
                                </div>
                                <div class="tb-row">
                                    <div class="tb-cell show-for-medium">

                                    </div>
                                    <div class="tb-cell clearfix">
                                        <div class="button-group float-left">
                                            <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 class="button-group float-right">
                                            <a href="<?php echo G5_PLUGIN_URL ?>/asktheme/_admin/plugin/plugin_admin.php" class="button"><i class="fa fa-list"></i> 목록으로</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!--responsetable-->
                    </form>
                </div>
                <div class="panel-footer">
                    &middot; <a href='<?php echo G5_ADMIN_URL ?>/contentlist.php'> 내용관리<i class='fa fa-link'></i></a>에 [[point_chart]]를 입력하면 회원 포인트 순위가 출력됩니다.<br/>
                    &middot; 플러그인 폴더에 point_chart.skin.php를 편집하세요.<br/>
                    &middot; <a href='http://www.asktheme.net/#n090' target="_blank">도움말<i class='fa fa-link'></i></a>
                </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;
        }
        var form_rows = parseInt($('#pc_rows').val());
        if (isNaN(form_rows)) {
            alert('출력할 회원수를 숫자로 입력하세요.');
            return false;
        }
        if (form_rows <= 0) {
            alert('1 이상 숫자를 입력하세요');
            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";

