<?php
/*
 *  컨텐츠 슬라이더 관리자
 */
include_once './_common.php';
include_once './index.php';

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


$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_cslider_parent'";
    $result = sql_fetch($sql);
    $sql = "CREATE TABLE `ask_plugin_cslider_parent` (
  `acp_idx` int(11) NOT NULL AUTO_INCREMENT,
  `acp_status` int(11) NOT NULL COMMENT '사용/중지',
  `acp_area` varchar(100) NOT NULL,
  `acp_bg` varchar(50) NOT NULL,
  PRIMARY KEY (`acp_idx`),
  UNIQUE KEY `acp_area` (`acp_area`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='컨텐츠슬라이더 위치 및 배경지정';";
    if (!$result) {
        sql_query($sql);
    }

    //페이지 테이블
    $sql = "show tables like 'ask_plugin_cslider'";
    $result = sql_fetch($sql);
    $sql = "CREATE TABLE `ask_plugin_cslider` (
  `ac_idx` int(11) NOT NULL AUTO_INCREMENT,
  `ac_parent_idx` int(11) NOT NULL COMMENT '부모idx',
  `ac_status` int(11) NOT NULL COMMENT '사용여부',
  `ac_subject` varchar(255) NOT NULL COMMENT '제목',
  `ac_content` varchar(255) NOT NULL COMMENT '텍스트',
  `ac_image` mediumblob NOT NULL COMMENT '이미지',
  `ac_image_name` varchar(255) NOT NULL COMMENT '등록된이미지명',
  `ac_link` varchar(255) NOT NULL COMMENT '링크',
  `ac_mime` varchar(50) NOT NULL COMMENT 'Mime Type',
  `ac_sort` int(11) NOT NULL COMMENT '정렬용',
  PRIMARY KEY (`ac_idx`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='컨텐츠슬라이더';";
    if (!$result) {
        sql_query($sql);
    } else {
        sql_query("ALTER TABLE `ask_plugin_cslider` ADD `ac_image_name` VARCHAR(255) NOT NULL COMMENT '등록된이미지명' AFTER `ac_image`");
    }
}

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="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">
                                        <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">
                </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";

