<?
include_once("./_dmshop.php");

// 폼 체크
if (!$_POST['form_check']) {

    alert("요청하신 서비스를 찾을 수 없습니다.\\n\\n확인하신 후 다시 이용하시기 바랍니다.");

}

if ($dmshop_user['datetime'] != $_POST['form_check']) {

    alert("요청하신 서비스를 찾을 수 없습니다.\\n\\n확인하신 후 다시 이용하시기 바랍니다.");

}

if (!$_POST['bbs_id']) {

    alert("게시판 아이디가 입력되지 않았습니다.");

}

if ($_POST['bbs_id'] == 'file' || $_POST['bbs_id'] == 'reply' || $_POST['bbs_id'] == 'good' || $_POST['bbs_id'] == 'down') {

    alert("사용할 수 없는 게시판 아이디입니다.");

}

// br 태그제거
if ($_POST['bbs_write_text'] == '<br>' || $_POST['bbs_write_text'] == '<br />') { $_POST['bbs_write_text'] = ""; }
if ($_POST['bbs_text_top'] == '<br>' || $_POST['bbs_text_top'] == '<br />') { $_POST['bbs_text_top'] = ""; }
if ($_POST['bbs_text_bottom'] == '<br>' || $_POST['bbs_text_bottom'] == '<br />') { $_POST['bbs_text_bottom'] = ""; }

// insert
if ($_POST['m'] == '') {

    // 게시판
    $dmshop_board = shop_board($_POST['bbs_id']);

    if ($dmshop_board['bbs_id']) {

        alert("이미 존재하는 게시판 아이디입니다.");

    }

    // 일괄적용
    if ($_POST['check_all']) {

        $sql_common = "";
        $sql_common .= " set bbs_skin = '".$_POST['bbs_skin']."', ";
        $sql_common .= ", bbs_order = '".$_POST['bbs_order']."', ";
        $sql_common .= ", bbs_sub_len = '".$_POST['bbs_sub_len']."', ";
        $sql_common .= ", bbs_new_time = '".$_POST['bbs_new_time']."', ";
        $sql_common .= ", bbs_hit_time = '".$_POST['bbs_hit_time']."', ";
        $sql_common .= ", bbs_rows = '".$_POST['bbs_rows']."', ";
        $sql_common .= ", bbs_gallery = '".$_POST['bbs_gallery']."', ";
        $sql_common .= ", bbs_thumb_width = '".$_POST['bbs_thumb_width']."', ";
        $sql_common .= ", bbs_thumb_height = '".$_POST['bbs_thumb_height']."', ";
        $sql_common .= ", bbs_view_image = '".$_POST['bbs_view_image']."', ";
        $sql_common .= ", bbs_view_list = '".$_POST['bbs_view_list']."', ";
        $sql_common .= ", bbs_name = '".$_POST['bbs_name']."', ";
        $sql_common .= ", bbs_privacy = '".$_POST['bbs_privacy']."', ";
        $sql_common .= ", bbs_reply_write = '".$_POST['bbs_reply_write']."', ";
        $sql_common .= ", bbs_secret = '".$_POST['bbs_secret']."' ";

        // 업데이트
        sql_query(" update $shop[board_table] $sql_common ");

    }

    // 일괄적용 2
    if ($_POST['check_all2']) {

        $sql_common = "";
        $sql_common .= " set bbs_list_level = '".$_POST['bbs_list_level']."' ";
        $sql_common .= ", bbs_read_level = '".$_POST['bbs_read_level']."' ";
        $sql_common .= ", bbs_write_level = '".$_POST['bbs_write_level']."' ";
        $sql_common .= ", bbs_answer_level = '".$_POST['bbs_answer_level']."' ";
        $sql_common .= ", bbs_reply_level = '".$_POST['bbs_reply_level']."' ";
        $sql_common .= ", bbs_download_level = '".$_POST['bbs_download_level']."' ";
        $sql_common .= ", bbs_file_limit = '".$_POST['bbs_file_limit']."' ";
        $sql_common .= ", bbs_file_size = '".$_POST['bbs_file_size']."' ";
        $sql_common .= ", bbs_write_cash = '".$_POST['bbs_write_cash']."' ";
        $sql_common .= ", bbs_reply_cash = '".$_POST['bbs_reply_cash']."' ";
        $sql_common .= ", bbs_write_text = '".$_POST['bbs_write_text']."' ";

        // 업데이트
        sql_query(" update $shop[board_table] $sql_common ");

    }

    // 개별적용
    $sql_common = "";
    $sql_common .= " set bbs_id = '".$_POST['bbs_id']."' ";
    $sql_common .= ", bbs_title = '".$_POST['bbs_title']."' ";
    $sql_common .= ", bbs_position = '".$_POST['bbs_position']."' ";
    $sql_common .= ", bbs_view = '".$_POST['bbs_view']."' ";
    $sql_common .= ", bbs_category = '".$_POST['bbs_category']."' ";
    $sql_common .= ", bbs_category_use = '".$_POST['bbs_category_use']."' ";
    $sql_common .= ", bbs_skin = '".$_POST['bbs_skin']."' ";
    $sql_common .= ", bbs_order = '".$_POST['bbs_order']."' ";
    $sql_common .= ", bbs_sub_len = '".$_POST['bbs_sub_len']."' ";
    $sql_common .= ", bbs_new_time = '".$_POST['bbs_new_time']."' ";
    $sql_common .= ", bbs_hit_time = '".$_POST['bbs_hit_time']."' ";
    $sql_common .= ", bbs_rows = '".$_POST['bbs_rows']."' ";
    $sql_common .= ", bbs_gallery = '".$_POST['bbs_gallery']."' ";
    $sql_common .= ", bbs_thumb_width = '".$_POST['bbs_thumb_width']."' ";
    $sql_common .= ", bbs_thumb_height = '".$_POST['bbs_thumb_height']."' ";
    $sql_common .= ", bbs_view_image = '".$_POST['bbs_view_image']."' ";
    $sql_common .= ", bbs_view_list = '".$_POST['bbs_view_list']."' ";
    $sql_common .= ", bbs_name = '".$_POST['bbs_name']."' ";
    $sql_common .= ", bbs_privacy = '".$_POST['bbs_privacy']."' ";
    $sql_common .= ", bbs_reply_write = '".$_POST['bbs_reply_write']."' ";
    $sql_common .= ", bbs_secret = '".$_POST['bbs_secret']."' ";
    $sql_common .= ", bbs_list_level = '".$_POST['bbs_list_level']."' ";
    $sql_common .= ", bbs_read_level = '".$_POST['bbs_read_level']."' ";
    $sql_common .= ", bbs_write_level = '".$_POST['bbs_write_level']."' ";
    $sql_common .= ", bbs_answer_level = '".$_POST['bbs_answer_level']."' ";
    $sql_common .= ", bbs_reply_level = '".$_POST['bbs_reply_level']."' ";
    $sql_common .= ", bbs_download_level = '".$_POST['bbs_download_level']."' ";
    $sql_common .= ", bbs_file_limit = '".$_POST['bbs_file_limit']."' ";
    $sql_common .= ", bbs_file_size = '".$_POST['bbs_file_size']."' ";
    $sql_common .= ", bbs_write_cash = '".$_POST['bbs_write_cash']."' ";
    $sql_common .= ", bbs_reply_cash = '".$_POST['bbs_reply_cash']."' ";
    $sql_common .= ", bbs_write_text = '".$_POST['bbs_write_text']."' ";
    $sql_common .= ", bbs_text_top = '".$_POST['bbs_text_top']."' ";
    $sql_common .= ", bbs_text_bottom = '".$_POST['bbs_text_bottom']."' ";
    $sql_common .= ", bbs_include_top = '".$_POST['bbs_include_top']."' ";
    $sql_common .= ", bbs_include_bottom = '".$_POST['bbs_include_bottom']."' ";
    $sql_common .= ", datetime = '".$shop['time_ymdhis']."' ";

    // 등록
    sql_query(" insert into $shop[board_table] $sql_common ");

    // 파일경로
    $dir = $shop['path']."/data/article/".$_POST['bbs_id'];

    // 게시판 폴더 생성
    @mkdir("$dir", 0707);
    @chmod("$dir", 0707);

/*--------------------------------
    ## 게시판 생성 ##
--------------------------------*/

$sql = " CREATE TABLE {$shop['article_table']}{$_POST['bbs_id']} (
  `id` int(11) NOT NULL auto_increment,
  `ar_id` int(11) NOT NULL default '0' COMMENT '원본아이디',
  `ar_count` int(11) NOT NULL default '0' COMMENT '답변수',
  `user_id` varchar(50) NOT NULL COMMENT '회원아이디',
  `ar_name` varchar(50) NOT NULL COMMENT '작성자',
  `ar_email` varchar(255) NOT NULL COMMENT '이메일',
  `ar_homepage` varchar(255) NOT NULL COMMENT '홈페이지',
  `ar_password` varchar(50) NOT NULL COMMENT '패스워드',
  `ar_notice` tinyint(4) NOT NULL default '0' COMMENT '공지사항',
  `ar_secret` tinyint(4) NOT NULL default '0' COMMENT '비밀글',
  `ar_category` varchar(255) NOT NULL COMMENT '분류',
  `ar_title` varchar(255) NOT NULL COMMENT '제목',
  `ar_content` longtext NOT NULL COMMENT '내용',
  `ar_ip` varchar(20) NOT NULL COMMENT '아이피',
  `ar_hit` int(11) NOT NULL default '0' COMMENT '조회수',
  `ar_reply` int(11) NOT NULL default '0' COMMENT '댓글수',
  `datetime` datetime NOT NULL default '0000-00-00 00:00:00' COMMENT '작성일',
  PRIMARY KEY (`id`),
  KEY `index_notice` (`ar_notice`),
  KEY `index_list` (`datetime`),
  KEY `index_reply` (`ar_id`,`id`),
  KEY `index_user` (`user_id`,`datetime`)
) DEFAULT CHARSET=utf8 ";
sql_query($sql, false);

}

// update
else if ($_POST['m'] == 'u') {

    // 게시판
    $dmshop_board = shop_board($_POST['bbs_id']);

    if (!$dmshop_board['bbs_id']) {

        alert("게시판이 삭제되었거나 존재하지 않습니다.");

    }

    // 일괄적용
    if ($_POST['check_all']) {

        $sql_common = "";
        $sql_common .= " set bbs_skin = '".$_POST['bbs_skin']."' ";
        $sql_common .= ", bbs_order = '".$_POST['bbs_order']."' ";
        $sql_common .= ", bbs_sub_len = '".$_POST['bbs_sub_len']."' ";
        $sql_common .= ", bbs_new_time = '".$_POST['bbs_new_time']."' ";
        $sql_common .= ", bbs_hit_time = '".$_POST['bbs_hit_time']."' ";
        $sql_common .= ", bbs_rows = '".$_POST['bbs_rows']."' ";
        $sql_common .= ", bbs_gallery = '".$_POST['bbs_gallery']."' ";
        $sql_common .= ", bbs_thumb_width = '".$_POST['bbs_thumb_width']."' ";
        $sql_common .= ", bbs_thumb_height = '".$_POST['bbs_thumb_height']."' ";
        $sql_common .= ", bbs_view_image = '".$_POST['bbs_view_image']."' ";
        $sql_common .= ", bbs_view_list = '".$_POST['bbs_view_list']."' ";
        $sql_common .= ", bbs_name = '".$_POST['bbs_name']."' ";
        $sql_common .= ", bbs_privacy = '".$_POST['bbs_privacy']."' ";
        $sql_common .= ", bbs_reply_write = '".$_POST['bbs_reply_write']."' ";
        $sql_common .= ", bbs_secret = '".$_POST['bbs_secret']."' ";

        // update
        sql_query(" update $shop[board_table] $sql_common ");

    }

    // 일괄적용 2
    if ($_POST['check_all2']) {

        $sql_common = "";
        $sql_common .= " set bbs_list_level = '".$_POST['bbs_list_level']."' ";
        $sql_common .= ", bbs_read_level = '".$_POST['bbs_read_level']."' ";
        $sql_common .= ", bbs_write_level = '".$_POST['bbs_write_level']."' ";
        $sql_common .= ", bbs_answer_level = '".$_POST['bbs_answer_level']."' ";
        $sql_common .= ", bbs_reply_level = '".$_POST['bbs_reply_level']."' ";
        $sql_common .= ", bbs_download_level = '".$_POST['bbs_download_level']."' ";
        $sql_common .= ", bbs_file_limit = '".$_POST['bbs_file_limit']."' ";
        $sql_common .= ", bbs_file_size = '".$_POST['bbs_file_size']."' ";
        $sql_common .= ", bbs_write_cash = '".$_POST['bbs_write_cash']."' ";
        $sql_common .= ", bbs_reply_cash = '".$_POST['bbs_reply_cash']."' ";
        $sql_common .= ", bbs_write_text = '".$_POST['bbs_write_text']."' ";

        // update
        sql_query(" update $shop[board_table] $sql_common ");

    }

    // 개별적용
    $sql_common = "";
    $sql_common .= " set bbs_title = '".$_POST['bbs_title']."' ";
    $sql_common .= ", bbs_position = '".$_POST['bbs_position']."' ";
    $sql_common .= ", bbs_view = '".$_POST['bbs_view']."' ";
    $sql_common .= ", bbs_category = '".$_POST['bbs_category']."' ";
    $sql_common .= ", bbs_category_use = '".$_POST['bbs_category_use']."' ";
    $sql_common .= ", bbs_skin = '".$_POST['bbs_skin']."' ";
    $sql_common .= ", bbs_order = '".$_POST['bbs_order']."' ";
    $sql_common .= ", bbs_sub_len = '".$_POST['bbs_sub_len']."' ";
    $sql_common .= ", bbs_new_time = '".$_POST['bbs_new_time']."' ";
    $sql_common .= ", bbs_hit_time = '".$_POST['bbs_hit_time']."' ";
    $sql_common .= ", bbs_rows = '".$_POST['bbs_rows']."' ";
    $sql_common .= ", bbs_gallery = '".$_POST['bbs_gallery']."' ";
    $sql_common .= ", bbs_thumb_width = '".$_POST['bbs_thumb_width']."' ";
    $sql_common .= ", bbs_thumb_height = '".$_POST['bbs_thumb_height']."' ";
    $sql_common .= ", bbs_view_image = '".$_POST['bbs_view_image']."' ";
    $sql_common .= ", bbs_view_list = '".$_POST['bbs_view_list']."' ";
    $sql_common .= ", bbs_name = '".$_POST['bbs_name']."' ";
    $sql_common .= ", bbs_privacy = '".$_POST['bbs_privacy']."' ";
    $sql_common .= ", bbs_reply_write = '".$_POST['bbs_reply_write']."' ";
    $sql_common .= ", bbs_secret = '".$_POST['bbs_secret']."' ";
    $sql_common .= ", bbs_list_level = '".$_POST['bbs_list_level']."' ";
    $sql_common .= ", bbs_read_level = '".$_POST['bbs_read_level']."' ";
    $sql_common .= ", bbs_write_level = '".$_POST['bbs_write_level']."' ";
    $sql_common .= ", bbs_answer_level = '".$_POST['bbs_answer_level']."' ";
    $sql_common .= ", bbs_reply_level = '".$_POST['bbs_reply_level']."' ";
    $sql_common .= ", bbs_download_level = '".$_POST['bbs_download_level']."' ";
    $sql_common .= ", bbs_file_limit = '".$_POST['bbs_file_limit']."' ";
    $sql_common .= ", bbs_file_size = '".$_POST['bbs_file_size']."' ";
    $sql_common .= ", bbs_write_cash = '".$_POST['bbs_write_cash']."' ";
    $sql_common .= ", bbs_reply_cash = '".$_POST['bbs_reply_cash']."' ";
    $sql_common .= ", bbs_write_text = '".$_POST['bbs_write_text']."' ";
    $sql_common .= ", bbs_text_top = '".$_POST['bbs_text_top']."' ";
    $sql_common .= ", bbs_text_bottom = '".$_POST['bbs_text_bottom']."' ";
    $sql_common .= ", bbs_include_top = '".$_POST['bbs_include_top']."' ";
    $sql_common .= ", bbs_include_bottom = '".$_POST['bbs_include_bottom']."' ";

    // update
    sql_query(" update $shop[board_table] $sql_common where bbs_id = '".$_POST['bbs_id']."' ");

    // 가로메뉴 업데이트
    sql_query(" update $shop[design_wmlist_table] set title = '".$_POST['bbs_title']."' where menu_type = 'board' and menu_id = '".$_POST['bbs_id']."' ");

    // 세로메뉴 업데이트
    sql_query(" update $shop[design_hmlist_table] set title = '".$_POST['bbs_title']."' where menu_type = 'board' and menu_id = '".$_POST['bbs_id']."' ");

}

// delete
else if ($_POST['m'] == 'd') {

    // 첨부파일 삭제
    $result = sql_query(" select datetime, upload_file from $shop[design_file_table] where upload_mode in ('board_top_".$_POST['bbs_id']."','board_bottom_".$_POST['bbs_id']."') ");
    for ($i=0; $file=sql_fetch_array($result); $i++) {

        // 원본
        $file_path = $shop['path']."/data/design/".shop_data_path("u", $file['datetime'])."/".$file['upload_file'];

        // 첨부파일 삭제
        @unlink($file_path);

    }

    // 파일 삭제
    sql_query(" delete from $shop[design_file_table] where upload_mode in ('board_top_".$_POST['bbs_id']."','board_bottom_".$_POST['bbs_id']."') ");

    // 게시판 삭제
    sql_query(" delete from $shop[board_table] where bbs_id = '".$_POST['bbs_id']."' ");

    // 게시판 drop
    sql_query(" drop table {$shop['article_table']}{$_POST['bbs_id']} ", false);

    // 게시판 폴더 삭제
    shop_delete("{$shop['path']}/data/article/{$_POST['bbs_id']}");

    // 파일 삭제
    sql_query(" delete from $shop[article_file_table] where INSTR(upload_mode, 'af_".$_POST['bbs_id']."_') ");

    // 댓글 삭제
    sql_query(" delete from $shop[article_reply_table] where bbs_id = '".$_POST['bbs_id']."' ");

    // 가로메뉴 삭제
    sql_query(" delete from $shop[design_wmlist_table] where menu_type = 'board' and menu_id = '".$_POST['bbs_id']."' ");

    // 세로메뉴 삭제
    sql_query(" delete from $shop[design_hmlist_table] where menu_type = 'board' and menu_id = '".$_POST['bbs_id']."' ");

       // 메인중앙 게시판 초기화
    sql_query(" update $shop[display_box_list_table] set board = '0' where board = '".$_POST['bbs_id']."' ");

    // 디자인TOP 게시판 초기화
    sql_query(" update $shop[design_top_table] set top_article = '' where top_article = '".$_POST['bbs_id']."' ");

    // 디자인MENU 게시판 초기화
    sql_query(" update $shop[design_menu_table] set menu_article = '' where menu_article = '".$_POST['bbs_id']."' ");

} else {

    alert("게시판이 삭제되었거나 존재하지 않습니다.");

}

// insert, update
if ($_POST['m'] == '' || $_POST['m'] == 'u') {

    // 파일경로
    $dir = $shop['path']."/data/design/".shop_data_path("", "");

    @mkdir("$dir", 0707);
    @chmod("$dir", 0707);

    // 상단
    $upload_name = "top";
    $upload_mode = "board_top_".$bbs_id;
    include("./upload_board_file.php");

    // 하단
    $upload_name = "bottom";
    $upload_mode = "board_bottom_".$bbs_id;
    include("./upload_board_file.php");

}

// 신규 등록
if ($_POST['m'] == '') {

    shop_url("./board_list.php");

}

if ($url) {

    $urlencode = urldecode($url);

} else {

    $urlencode = urldecode($_SERVER[REQUEST_URI]);

}

shop_url($urlencode);
?>