<?php
$cate_id = "mnu_board_list"; //현재 메뉴 ID 필수!!!
include_once "{$_SERVER['DOCUMENT_ROOT']}/common.inc.php";
include_once _ADM_INC_PATH_ ."/auth_check.php";

$brdObj = new Board($_REQUEST['board_id']);
$binfo = $brdObj->board_info;

$smnu_txt = "추가";
if( $binfo['board_id'] ){
  $smnu_txt = "수정";
}

//권한 그룹
$sgrp = array(
  "M" => "회원",
  "A" => "관리자",
);

//소속 리스트
$custObj = new Cust();
$where = new DB_where("and");
$where->add("cust_status = ?",1);
$where->add("cust_active = ?",1);
$cust_list = $custObj->getCustSelect("cust_id", "cust_name", $where);

include _ADM_INC_PATH_ ."/header.html";
?>

        <div id="cmd_bar" class="mb-2">
          <div class="h4"><i class="bi bi-files-alt"></i> 게시판 <?=$smnu_txt?></div>
          <div class="text-right">
          </div>
        </div>

        <form method="post" name="frm_board_put" id="frm_board_put" class="fadmin" autocomplete="off" action="###" onsubmit="return false">
          <div class="fld-block">
            <label for="board_id">게시판 코드 </label>
            <div>
              <input type="text" name="board_id" id="board_id" value="<?=$binfo['board_id']?>" class="form-control inline" <?=($binfo['board_id'])?"readonly":""?>>
              <small class="text-info"><?=cUtil\Mlang::getText("게시판의 유일한 코드로 등록합니다.")?></small>
            </div>
          </div>
          <div class="fld-block">
            <label for="board_name">게시판명 </label>
            <div>
              <input type="text" name="board_name" id="board_name" value="<?=$binfo['board_name']?>" class="form-control inline">
            </div>
          </div>
          <div class="fld-block">
            <label for="board_admin">게시판 관리자 ID </label>
            <div>
              <input type="text" name="board_admin" id="board_admin" value="<?=$binfo['board_admin']?>" class="form-control inline">
              <small class="text-info"><?=cUtil\Mlang::getText("게시판 관리권한이 있는 회원의 ID를 입력합니다.")?></small>
            </div>
          </div>
          <div class="fld-block">
            <label for="board_cate">분류 </label>
            <div>
              <input type="text" name="board_cate" id="board_cate" value="<?=$binfo['board_cate']?>" class="form-control inline">
              <small class="text-info"><?=cUtil\Mlang::getText("게시판내 필요한 분류를 '|' 로 구분하여 입력하세요.")?></small>
            </div>
          </div>
          <div class="fld-block">
            <label for="mem_type">게시판 소속 </label>
            <div>
              <select name="mem_type" id="mem_type" data-defval="<?=$binfo['mem_type']?>" class="form-control form-select">
                <?=getSelectOptions($cust_list,"- 전체 -")?>
              </select>
              <small class="text-info"><?=cUtil\Mlang::getText("게시판의 소속을 선택합니다.")?></small>
            </div>
          </div>
          <div class="fld-block">
            <label for="mem_type">권한 </label>
            <div class="row">
              <div class="col-auto text-right">
                <label for="read_level">읽기권한
                  <div class="form-inline">
                    <select name="read_level" id="read_level" data-defval="<?=$binfo['read_level']?>" class="form-control form-select">
                      <?=getSelectOptions($sgrp,"- 전체가능 -")?>
                    </select>
                  </div>
                </label>
              </div>
              <div class="col-auto text-right">
                <label for="write_level">쓰기권한
                  <div class="form-inline">
                    <select name="write_level" id="write_level" data-defval="<?=$binfo['write_level']?>" class="form-control form-select">
                      <?=getSelectOptions($sgrp,"- 전체가능 -")?>
                    </select>
                  </div>
                </label>
              </div>
            </div>
          </div>
          <div class="fld-block">
            <label for="ness_title">필수항목</label>
            <div class="row">
              <label class="col-4 col-sm-3 col-lg-2 col-xl mb-0 border-left"><input type="checkbox" value="Y" name="ness_title"    id="ness_title"    data-defval="<?=$binfo['ness_title']?>">    제목</label>
              <label class="col-4 col-sm-3 col-lg-2 col-xl mb-0 border-left"><input type="checkbox" value="Y" name="ness_contents" id="ness_contents" data-defval="<?=$binfo['ness_contents']?>"> 내용</label>
              <label class="col-4 col-sm-3 col-lg-2 col-xl mb-0 border-left"><input type="checkbox" value="Y" name="ness_name"     id="ness_name"     data-defval="<?=$binfo['ness_name']?>">     이름</label>
              <label class="col-4 col-sm-3 col-lg-2 col-xl mb-0 border-left"><input type="checkbox" value="Y" name="ness_passwd"   id="ness_passwd"   data-defval="<?=$binfo['ness_passwd']?>">   비밀번호</label>
              <label class="col-4 col-sm-3 col-lg-2 col-xl mb-0 border-left"><input type="checkbox" value="Y" name="ness_homepage" id="ness_homepage" data-defval="<?=$binfo['ness_homepage']?>"> 홈페이지</label>
              <label class="col-4 col-sm-3 col-lg-2 col-xl mb-0 border-left"><input type="checkbox" value="Y" name="ness_mail"     id="ness_mail"     data-defval="<?=$binfo['ness_mail']?>">     메일</label>
              <label class="col-4 col-sm-3 col-lg-2 col-xl mb-0 border-left"><input type="checkbox" value="Y" name="ness_image"    id="ness_image"    data-defval="<?=$binfo['ness_image']?>">    이미지</label>
              <label class="col-4 col-sm-3 col-lg-2 col-xl mb-0 border-left"><input type="checkbox" value="Y" name="ness_file"     id="ness_file"     data-defval="<?=$binfo['ness_file']?>">     파일</label>
            </div>
          </div>
          <div class="fld-block">
            <label for="use_opinion">옵션항목 </label>
            <div class="row">
              <label class="col-auto text-right"><input type="checkbox" value="Y" name="use_opinion"   id="use_opinion"   data-defval="<?=$binfo['use_opinion']?>">   의견글 사용</label>
              <label class="col-auto text-right"><input type="checkbox" value="Y" name="use_spamproof" id="use_spamproof" data-defval="<?=$binfo['use_spamproof']?>"> 스팸방지 사용</label>
              <label class="col-auto text-right"><input type="checkbox" value="Y" name="use_realname"  id="use_realname"  data-defval="<?=$binfo['use_realname']?>">  실명제 사용</label>
            </div>
          </div>
          <div class="fld-block">
            <label for="use_webeditor">내용 작성 방식 </label>
            <div>
              <select name="use_webeditor" id="use_webeditor" data-defval="<?=$binfo['use_webeditor']?>" class="form-control form-select">
                <?=getSelectOptions($GLOBALS['_varsBoardEditor'])?>
              </select>
            </div>
          </div>
          <div class="fld-block">
            <label for="line_num">페이지당 라인수 </label>
            <div>
              <input type="text" name="line_num" id="line_num" value="<?=$binfo['line_num']?:$GLOBALS['_varsBaseCode']['line_num']?>" class="form-control inline">
              <small class="text-info"><?=cUtil\Mlang::getText("한 페이지에 나타날 게시물 수를 입력하세요.")?></small>
            </div>
          </div>
          <div class="fld-block">
            <label for="page_num">페이지 표시수 </label>
            <div>
              <input type="text" name="page_num" id="page_num" value="<?=$binfo['page_num']?:$GLOBALS['_varsBaseCode']['page_num']?>" class="form-control inline">
              <small class="text-info"><?=cUtil\Mlang::getText("리스트 화면에 표시될 페이지 숫자를 입력하세요.")?></small>
            </div>
          </div>
          <div class="fld-block">
            <label for="new_num">최신글 기준 일수 </label>
            <div>
              <input type="text" name="new_num" id="new_num" value="<?=$binfo['new_num']?>" class="form-control inline">
              <small class="text-info"><?=cUtil\Mlang::getText("최신글이 표시될 기준 일수")?></small>
            </div>
          </div>
          <div class="fld-block">
            <label for="hot_num">인기글 기준 조회수 </label>
            <div>
              <input type="text" name="hot_num" id="hot_num" value="<?=$binfo['hot_num']?>" class="form-control inline">
              <small class="text-info"><?=cUtil\Mlang::getText("인기글이 표시될 기준 조회수")?></small>
            </div>
          </div>
          <div class="fld-block">
            <label for="skin_name">게시판 스킨 </label>
            <div>
              <input type="text" name="skin_name" id="skin_name" value="<?=$binfo['skin_name']?>" class="form-control inline">
              <small class="text-info"><?=cUtil\Mlang::getText("인기글이 표시될 기준 조회수")?></small>
            </div>
          </div>

          <div class="text-center mt-4">
            <?php if( $binfo['board_id'] ){?>
            <button type="button" id="btnDelBoard" class="btn btn-danger px-5">게시판 삭제</button>
            <?php }?>
            <a href="./board_list.php" class="btn btn-success px-5">리스트</a>
            <button type="submit" id="btnPutBoard" class="btn btn-primary px-5">게시판 <?=$smnu_txt?></button>
          </div>

          <?=hidden_input('board_oid', $binfo['board_id'])?>
        </form>

<?php
include _ADM_INC_PATH_ ."/footer.html";
?>
<script>
  jQuery("#btnPutBoard, #btnDelBoard").on("click",function(){
    let formdata = new FormData(document.forms['frm_board_put']);
    let bmesg;

    switch( jQuery(this).attr("id") ){
      case "btnPutBoard" :
        formdata.append("mode","putBoard");
        bmesg = "<?=cUtil\Mlang::getText("등록 되었습니다.")?>";
        putContent(formdata, bmesg);
      break;
      case "btnDelBoard" :
        kuls_confirm("게시판 삭제","정말 삭제하시겠습니까?",function(){
          formdata.append("mode","delBoard");
          bmesg = "<?=cUtil\Mlang::getText("삭제 되었습니다.")?>";
          putContent(formdata, bmesg);
        },function(){return false;});
      break;
      default : return;
    }

  });

  const putContent = function(formdata, bmesg){
    ajax_form({
      url: "./board.ajax.php",
      type: "POST",
      data: formdata,
      success: function (data) {
        if (!data.code) {
          kuls_alert(data.mesg);
          return;
        }
        kuls_alert(bmesg, function(){
          location.href = "./board_list.php";
        });
      },
      error: function (request, status, error) {
        kuls_alert(error.message);
      }
    });
  }

  /*
if( jQuery("#board_put").length ){
  var V_board_write = new Vue({
    data : vue_data,
    mounted: function(){
      var that = this;
      that.getBoard(that.nid);
    },
    computed:{},
    methods:{
      movePage: function(url){
        common_page_move(url);
      },
      getBoard: function(){
        var that = this;
        var post_data = new FormData();
        post_data.append("mode","getBoard");
        post_data.append("nid",that.fmd.nid);
        exec_ajax_common("./board.ajax.php",post_data,"json",function(resp){
          if( resp.code ){
            if( that.fmd.nid && that.fmd.nid != 0 ){
              for( var a in resp.data ){
                that.fmd[a] = resp.data[a];
              }
            }
          }else{
            palert(resp.mesg);
            history.go(-1);
          }
        });
      },
      putBoard: function(){
        var that = this;
        if( that.formCheck() ) return;

        var post_data = new FormData(jQuery("#frm_board_put").get(0));
        post_data.append("mode","putBoard");
        exec_ajax_common("./board.ajax.php",post_data,"json",function(resp){
          if( resp.code ){
            if( that.fmd.nid ){
              palert("수정되었습니다.");
            }else{
              palert("게시판이 추가되었습니다.");
            }
            common_page_move("./board_list.php");
          }else{
            palert(resp.mesg);
          }
        });
      },
      delBoard: function(){
        var that = this;
        if( that.fmd.nid ){
          pconfirm("포함된 게시물 및 의견글등 모두 삭제됩니다.\n정말 삭제하시겠습니까?",function(){
            var post_data = new FormData(jQuery("#frm_board_put").get(0));
            post_data.append("mode","delBoard");
            exec_ajax_common("./board.ajax.php",post_data,"json",function(resp){
              if( resp.code ){
                palert("삭제 되었습니다.");
                common_page_move("./board_list.php");
              }else{
                palert(resp.mesg);
              }
            });
          });
        }else{
          alert('잘못된 접근입니다.');
        }
      },
      formCheck: function(){
        var that = this;
        that.fmd = objtrim(that.fmd);
        if( !that.fmd.board_id ){
          palert("게시판 코드를 입력하지 않았습니다.");
          return true;
        }
        if( !that.fmd.board_name ){
          palert("게시판명을 입력하지 않았습니다.");
          return true;
        }
        if( !that.fmd.use_webeditor ){
          palert("내용 작성방식을 선택하지 않았습니다.");
          return true;
        }
        if( !that.fmd.line_num ){
          palert("페이지당 라인수를 입력하지 않았습니다.");
          return true;
        }
        if( !that.fmd.page_num ){
          palert("페이지 표시수를 입력하지 않았습니다.");
          return true;
        }
        if( !that.fmd.new_num ){
          palert("최신글 기준 일수를 입력하지 않았습니다.");
          return true;
        }
        if( !that.fmd.hot_num ){
          palert("인기글 기준 조회수를 입력하지 않았습니다.");
          return true;
        }
      },
    },
  }).$mount("#board_put");
}*/
</script>
<?php
/*
require_once _INCLUDE_PATH_."/vendor/tinymce5/tinymce_inc.php";
echo $fileupload_script;
*/