<?php
/*
 *  사이드메뉴 등록
 */
include_once './_common.php';
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);
//수정모드일때
if ($w == 'u' && $idx) {
    $sql = "select * from ask_plugin_sidemenu where as_idx = '{$idx}'";
    $data = sql_fetch($sql);
    if (!$data) {
        alert('데이터가 없습니다.', './sidemenu_menu.php');
    }
}
?>
<div id="container">
    <div class="ask-row grid">
        <div class="col-2-12">
            <?php include_once './sidemenu_menu.php'; ?>
        </div>
        <div class="col-10-12">
            <div class="panel panel-default">
                <div class="panel-header">
                    <h1><?php echo $plugin['name'], $plugin['version']; ?> 등록하기</h1>
                </div>
                <div class="panel-body">
                    <form class="add_sidemenu" action="./sidemenu_add_update.php"  onsubmit="return form_submit(this);" method="post" enctype="multipart/form-data" autocomplete="off" >
                        <?php
                        if ($w == 'u' && $idx) {
                            echo "<input type='hidden' name='w' value='u'>";
                            echo "<input type='hidden' name='as_idx' value='{$data['as_idx']}'>";
                        }
                        ?>
                        <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"><label for="as_status">사이드메뉴 사용여부<strong class="sound-only">필수</strong></label></div>
                                    <div class="tb-cell">
                                        <?php
                                        if ($data['as_status'] == '1') {
                                            $as_use = "checked";
                                        } elseif ($data['as_status'] == '0') {
                                            $as_unuse = "checked";
                                        }
                                        ?>
                                        <label><input type="radio" name="as_status" value="1" <?php echo $as_use ?> class="sidemenu-start">사용하기</label>
                                        <label><input type="radio" name="as_status" value="0" <?php echo $as_unuse ?> class="sidemenu-stop">중지하기</label>
                                    </div>
                                </div>


                                <div class="tb-row">
                                    <div class="tb-cell"><label for="as_gr_id">그룹선택<strong class="sound-only">필수</strong></label></div>
                                    <div class="tb-cell">
                                        <?php
                                        if ($w == 'u' && $idx) {
                                            $select_data = $data['as_gr_id'];
                                        }
                                        echo get_group_select('as_gr_id', $select_data, 'class="input"');
                                        ?>

                                    </div>
                                </div>
                                <div class="tb-row">
                                    <div class="tb-cell"><label for="as_me_code">연결할 메뉴선택<strong class="sound-only">필수</strong></label></div>
                                    <div class="tb-cell">
                                        <?php
                                        if ($w == 'u' && $idx) {
                                            $select_data = $data['as_me_code'];
                                        }
                                        echo ask_get_menu_select('as_me_code', $select_data, 'class="input"');
                                        ?>
                                    </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">
                    &middot; 그룹 메인 페이지 및 게시판, 내용관리, 일반페이지에 사이드메뉴를 연결해 줄수 있습니다.<br/>
                    &middot; 일반페이지에 사이드메뉴 추가시 페이지 상단에 <span class='label label-info'>&lt;?php $gr_id ='그룹아이디'?&gt;</span> 코드를 넣어주시면 출력됩니다.
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $('.cancel').click(function () {
            if (confirm('취소하시겠습니까?')) {
                location.href = history.go(-1);
            } else {
                return false;
            }
        });

    });
    function validateURL(textval) {
        var urlregex = /^(https?|http):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/;
        return urlregex.test(textval);
    }
    function form_submit(f) {
        //console.log(f);
        var use_sidemenu = $('input[name=as_status]:checked').val();
        if (use_sidemenu === undefined) {
            alert('사이드메뉴 사용여부를 선택하세요');
            return false;
        }
        if ($('[name=as_gr_id]').val() == "") {
            alert("그룹을 선택하세요.");
            return false;
        }
        if ($('[name=as_me_id]').val() == "") {
            alert("연결할 메뉴를 선택하세요.");
            return false;
        }


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

