<?php
$sub_menu = "300200";
include_once("./_common.php");

auth_check($auth[$sub_menu], "w");

$token = get_token();

if ($is_admin != "super" && $w == "")
    alert("최고관리자만 접근 가능합니다.");

$html_title = "게시판그룹";
if ($w == "") {
    $gr_id_attr = "required";
    $gr[gr_use_access] = 0;
    $html_title .= " 생성";
} else if ($w == "u") {
    $gr_id_attr = "readonly style='background-color:#dddddd'";
    $gr = sql_fetch(" select * from $g4[group_table] where gr_id = '$gr_id' ");
    $html_title .= " 수정";
} else
    alert("제대로 된 값이 넘어오지 않았습니다.");

$g4[title] = $html_title;
include_once("./admin.head.php");
?>
<div class='row'>
    <div class='col-sm-12'>
        <?php echo subtitle($html_title)?>

        <form name=fboardgroup method=post onsubmit="return fboardgroup_check(this);" autocomplete="off" class='form-horizontal' role='form'>
            <input type='hidden' name='w'     value='<?php echo $w ?>'>
            <input type='hidden' name='sfl'   value='<?php echo $sfl ?>'>
            <input type='hidden' name='stx'   value='<?php echo $stx ?>'>
            <input type='hidden' name='sst'   value='<?php echo $sst ?>'>
            <input type='hidden' name='sod'   value='<?php echo $sod ?>'>
            <input type='hidden' name='page'  value='<?php echo $page ?>'>
            <input type='hidden' name='token' value='<?php echo $token ?>'>
            <div class="form-group">
                <label class="control-label col-sm-2">
                    그룹 ID
                </label>
                <div class='col-sm-10'>
                    <input type='text' class='form-control' name='gr_id' size='11' maxlength='10' <?php echo $gr_id_attr ?> alphanumericunderline itemname='그룹 아이디' value='<?php echo $group[gr_id] ?>'> 영문자, 숫자, _ 만 가능 (공백없이)
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-2">
                    그룹 제목
                </label>
                <div class='col-sm-8'>
                    <input type='text' class='form-control' name='gr_subject' size='40' required itemname='그룹 제목' value='<?php echo get_text($group[gr_subject]) ?>'>
                </div>
                <div class='col-sm-2'>
                    <?php
                    if ($w == 'u')
                        echo "<input type='button' class='btn btn-primary' value='게시판생성' onclick=\"location.href='./board_form.php?gr_id=$gr_id';\">";
                    ?>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-2">
                    그룹 관리자
                </label>
                <div class='col-sm-10'>
                    <?php
                    if ($is_admin == "super")
                    //echo get_member_id_select("gr_admin", 9, $row[gr_admin]);
                        echo "<input type='text' class='form-control' name='gr_admin' value='$gr[gr_admin]' maxlength=20>";
                    else
                        echo "<input type=hidden name='gr_admin' value='$gr[gr_admin]' size=40>$gr[gr_admin]";
                    ?>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-2">
                    접근회원사용
                </label>
                <div class='col-sm-10'>
                    <input type=checkbox name=gr_use_access value='1' <?php echo $gr[gr_use_access] ? 'checked' : ''; ?>>사용 
                    <?php echo help("사용에 체크하시면 이 그룹에 속한 게시판은 접근가능한 회원만 접근이 가능합니다.") ?>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-2">
                    접근회원수
                </label>
                <div class='col-sm-10'>
                    <?php
                        // 접근회원수
                        $sql1 = " select count(*) as cnt from $g4[group_member_table] where gr_id = '$gr_id' ";
                        $row1 = sql_fetch($sql1);
                        echo "<a href='./boardgroupmember_list.php?gr_id=$gr_id'>$row1[cnt]</a>";
                    ?>
                </div>
            </div>
            <?php for ($i = 1; $i <= 10; $i++) { ?>
                <div class="form-group">
                    <div class="col-sm-2">
                        <input type=text class='form-control' name='gr_<?php echo $i ?>_subj' value='<?php echo get_text($group["gr_{$i}_subj"]) ?>' title='여분필드 <?php echo $i ?> 제목' style='text-align:right;font-weight:bold;' size=15>
                    </div>
                    <div class='col-sm-10'>
                        <input type='text' class='form-control' name=gr_<?php echo $i ?> value='<?php echo $gr["gr_$i"] ?>' title='여분필드 <?php echo $i ?> 설정값'>
                    </div>
                </div>
            <?php } ?>
            
            <div class='form-action col-sm-offset-2'>
                <button type='submit' class='btn btn-primary'>확인</button>
                <input type='button' class='btn btn-default pull-right' value='목록' onclick="document.location.href = './boardgroup_list.php?<?php echo $qstr ?>';">
            </div>
                
        </form>
    </div>
</div>
<script type='text/javascript'>
    if (document.fboardgroup.w.value == '')
        document.fboardgroup.gr_id.focus();
    else
        document.fboardgroup.gr_subject.focus();

    function fboardgroup_check(f)
    {
        f.action = "./boardgroup_form_update.php";
        return true;
    }
</script>

<?
include_once ("./admin.tail.php");
?>
