<?
include_once("include/global.php");
include_once("include/board_lib.php");


###############################################################################


	// set
		$ba = NULL;
		$q_where = '';


	// Required variables
		$id;
		$mode;


###############################################################################

	if(preg_match("/^ADMIN_/", $mode) || !$mode)		// 관리자메뉴
	{
		$ba[is_admin] = false;
		$ba[view_ba_name] = "<b>관리자메뉴</b> >> <b>공용게시판관리</b>";
		$ba[view_ba_header] = NULL;
		$ba[view_ba_footer] = NULL;
		$ba[view_ba_notice_subject] = NULL;
		$ba[view_ba_notice_memo] = NULL;
	}else		// 사용자 모드
	{
		$ba = board_admin_info($ba_no);		// array
		$ba[is_admin] = board_is_admin();		// true|false

		// [2011-01-05] 메뉴관리
		//$ba[view_ba_name] = '<b>' . $ba[ba_name] . '</b>';
		if (!$_GET['bm_no'])
			$_GET['bm_no'] = $ba[bm_no];

		// [2011-03-10] 메인 스킨 호환성
		if (version_compare(NM_SKIN_MAIN_VER, '2.6.0', '>='))
		{
			$ba[view_ba_name] = '<a href="'.$nmpath.'/board_new.php?bm_no='.$_GET['bm_no'].'"><b><u>' . get_bm_name($_GET['bm_no']) . '</u></b></a> >> <b>' . $ba[ba_name] . '</b>';
			$G_SYS['TITLE_AUTOLINK_SKIP'] = true;
		} else 
		{
			$ba[view_ba_name] = '<b>' . $ba[ba_name] . '</b>';
		}	// if()

		$ba[view_ba_header] = text_view($ba[ba_header], $ba[ba_header_html], "Y");
		$ba[view_ba_footer] = text_view($ba[ba_footer], $ba[ba_footer_html], "Y");

		if ($ba[ba_notice_no] > 0)
		{
			$ba[view_ba_notice_subject] = htmlspecialchars_fix($ba[ba_notice_subject]);
			$ba[view_ba_notice_memo] = text_view($ba[ba_notice_memo], $ba[ba_notice_html], "Y");
		}	// if()
	}	// if()
	$upload_dir = $UPLOAD_DIR[BOARD] . "/" . $ba_no;		// ex) BOARD/1 => /xxxx/upload/BOARD/1/
	$upload_new_dir = $UPLOAD_DIR[BOARD_NEW] . "/" . $ba_no;		// ex) BOARD/1 => /xxxx/upload/BOARD/1/

	$CFG[TITLE] = $ba[view_ba_name];

	$subject_maxlength = 70;
	$body_maxwidth = 600;		// 이미지출력시 본문의 최대폭(pixel)


	// Query String
	include_once("include/querystring.php");
	$_ar_qs_text = array("ba_no", "b_no", "reqPage", "s_kind", "s_word", "s_category", "s_bm_no");
	$_ar_qs_value = array($ba_no, $b_no, $reqPage, $s_kind, $s_word, $s_category, $s_bm_no);

	$cfg_qs = querystring($_ar_qs_text, $_ar_qs_value);		// $cfg_qs = "local_id=busan&reqPage=2"
	$b_qs["DEFAULT"] = $cfg_qs;
	$b_qs["SEARCH"] = querystring_cut($cfg_qs, "b_no", "reqPage", "s_kind", "s_word");
	$b_qs["LIST"] = querystring_cut($cfg_qs, "b_no");
	$b_qs["LIST_PAGE"] = querystring_cut($cfg_qs, "b_no", "reqPage");
	$b_qs["REGISTER"] = querystring_cut($cfg_qs, "b_no", "reqPage", "s_kind", "s_word");
	$b_qs["REPLY"] = $cfg_qs;
	$b_qs["MODIFY"] = $cfg_qs;
	$b_qs["DEL"] = $cfg_qs;
	$b_qs["ADMIN"] = querystring_cut($cfg_qs, "ba_no");
	$b_qs["ADMIN_PAGE"] = querystring_cut($cfg_qs, "ba_no", "reqPage");
	$b_qs["ADMIN_SEARCH"] = querystring_cut($cfg_qs, "ba_no", "reqPage", "s_kind", "s_word");
	$b_qs["ADMIN_MODIFY"] = querystring_cut($cfg_qs, "b_no", "reqPage", "s_kind", "s_word") . "&back_url=" . urlencode($_SERVER[REQUEST_URI]);


################################################################################

		$G_BOARD[S_KIND_ADMIN] = array(
										"ba_name"=>"이름",
										"ba_isuse_link"=>"링크",
										"ba_isuse_file"=>"파일",
										"ba_isuse_comment"=>"덧말",
										"ba_isuse_reply"=>"답변",
										"ba_isuse_rewrite"=>"재게시",
										"ba_isuse_read_log"=>"조회 기록",
										"ba_regdate"=>"생성일자",
										"ba_last_modifydate"=>"수정일자"
										);

	// [2008-03-19] 사용그룹제한 추가
	if (strpos($mode, 'ADMIN_') === false && $ba['ba_mg_no'] != '')		// 사용자모드이고, 사용그룹제한이 지정되었을 때
	{
		// [2011-01-04] 사용그룹제한시에는 로그인여부를 먼저 검사
		auth_limit("user");

		$q = "SELECT mg_name, mg_no FROM ".$TB['MEMBER_GROUP']." WHERE d_no='".$G['DINFO']['d_no']."' AND mg_no IN (".implode(',', db_str_explode('|', $ba['ba_mg_no'])).") ORDER BY mg_name";
		$mg = db_get_rows($q, true);

		$_is_limit = false;
		if ($AUTH['auth_m_level'] < $G['LEVEL']['admin'])		// 도메인 관리자 레벨이상은 제한하지 않음.
		{
			// [2008-09-12] 회원그룹(단일) -> 회원조직(다중)
				$q = "SELECT mg_no FROM ".$TB['MEMBER_GROUP_REL']." WHERE m_no='".$AUTH['auth_m_no']."'";
				$mgr = db_get_rows($q);
				$mgr_cnt = sizeof($mgr);
				$q_mgr = '';
				$_is_limit = true;
				if ($mgr_cnt > 0)
				{
					for ($i=0; $i<$mgr_cnt; $i++)
					{
						if (in_array($mgr[$i]['mg_no'], $mg['mg_no']))
						{
							$_is_limit = false;		// 하나의 조직이라도 접근가능한 경우 허용.
							break;
						}	// if()
					}	// for()
				}	// if()

			// 사용아이디 제한
				if ($_is_limit && $ba['ba_use_id'] != '' && in_array($AUTH['auth_m_id'], db_str_explode('|', $ba['ba_use_id'])))
					$_is_limit = false;

			if ($_is_limit)
				msg("[".$ba['ba_name']."] 게시판에 사용권한이 없습니다.\\n\\n관리자에게 문의하여 주시기 바랍니다.");
		}	// if()

		// [2009-12-09] 회원 조직에 지정된 조직이 삭제되고난 후 에러 메세지 해결
		//$ba['ba_mg_no_view'] = implode(',', $mg['mg_name']);
		$ba['ba_mg_no_view'] = @implode(',', $mg['mg_name']);
		$ba[view_ba_header] .= '
			<div style="background-color:#FEF0DE; width:100%; margin: 5px 0px 5px 0px"><table cellpadding="5" cellspacing="1" border="0" width="100%">
			<tr>
				<td>
					<img src="'.nskindirroot('main').'/img/bul_10.gif"  align=absmiddle> 사용 그룹 : <b>'.$ba['ba_mg_no_view'].'</b>
				</td>
			';
		if ($ba['ba_use_id'] != '')
		{
			$ba[view_ba_header] .= '
					<td>
						<img src="'.nskindirroot('main').'/img/bul_10.gif"  align=absmiddle> 사용 아이디 : <b>'.implode(',', db_str_explode('|', $ba['ba_use_id'])).'</b>
					</td>
				';
		}	// if()
		$ba[view_ba_header] .= '
			</tr>
			</table></div>
			';
	}	// if()


###############################################################################

	switch($mode)
	{
		case "LIST":

			auth_limit($ba[ba_perm_access]);

			// query
				$q_where = " WHERE ba_no='$ba_no' ";


			// search
				if ($s_word == true)		// search mode
				{
					set_q_search($s_word);

					switch($s_kind)
					{
						case "ALL":
							$q_where .= " AND (b_subject like '%" . $s_word . "%' ";
							$q_where .= " OR b_memo like '%" . $s_word . "%' ";
							$q_where .= " OR b_name like '%" . $s_word . "%') ";
							break;

						default:
							$q_where .= " AND " . $s_kind . " like '%" . $s_word . "%' ";
							break;
					}	// switch()

					$null_msg = "검색된 글이 없습니다.";
				}else		// normail mode
				{
					$null_msg = "등록된 글이 없습니다.";
				}	// if()


			// category
				if ($s_category) $q_where .= " AND bca_no ='$s_category' ";


			// set_board_list
				$pageSize = $ba[ba_page];
				$strTrans = "&mode=$mode&" . $b_qs["LIST_PAGE"];
				$subject_url = "&" . $b_qs["LIST"];

				$board = set_board_list($q_where, $pageSize, $strTrans, $subject_url, $subject_maxlength);		// array


			// set admin mode
				if ($ba[is_admin] == true)		// 게시판 관리자일때
				{
					if ($G_SYS[DB] == 'oracle')
					{
						$q = "
							SELECT
								ba.ba_no key, CONCAT(CONCAT(ba.ba_no, '. '), ba.ba_name) value
							FROM
								$TB[BOARD_ADMIN] ba
							WHERE
								ba.ba_no != '$ba_no'
								AND ba.d_no='" . $AUTH['auth_d_no'] ."'
							ORDER BY
								ba.ba_no
							";
					} else
					{
						$q = "
							SELECT
								ba.ba_no 'key', CONCAT(ba.ba_no, '. ', ba.ba_name) 'value'
							FROM
								$TB[BOARD_ADMIN] ba
							WHERE
								ba.ba_no != '$ba_no'
								AND ba.d_no='" . $AUTH['auth_d_no'] ."'
							ORDER BY
								ba.ba_no
							";
					}	// if()
					$target_ba = db_get_rows($q, true);

					$target_ba_select = select_list_value(NULL, $target_ba['value'], $target_ba['key'], "이동할 게시판", 0, 1);
				}	// if()


			// set category
				if ($ba[ba_isuse_category] == "Y")
				{

					$board_category = get_board_category($ba_no, NULL, "N");		// array
					$s_category_cnt = sizeof($board_category['bca_no']);
					$v_s_category = select_list_value($s_category, $board_category['bca_name'], $board_category['bca_no'], "분류", 0, 1);
				}	// if()


			// view


				// body
				$page_view = disPgCount($whlPgCount, $reqPage, $strTrans, 3, 1);

				// search

				$s_kind = select_list_value($s_kind, array_values($G_BOARD[S_KIND]), array_keys($G_BOARD[S_KIND]), NULL, 0, 1);
				$v_s_word = input_value($s_word,1);

				nskinset('board', 'list.html');
				include($NSKIN['view_layout']);

			break;


###############################################################################


		case "READ":
		case "PRINT":

			include_once("include/file.php");

			auth_limit($ba[ba_perm_read]);
			board_refer_plus($ba_no, $b_no);

			$board = board_info($ba_no, $b_no);		// array

			// get
				if($board)
				{
					$board[v_b_name] = get_mailto_url($board[b_email], $board[b_name]);
					$board[v_b_subject] = text_view($board[b_subject]);
					// [2008-06-07] 웹에디터 추가
					//$board[v_b_memo] = text_view($board[b_memo], $board[b_html]);
					$board[v_b_memo] = text_view($board[b_memo], $board[b_html], "Y");

					if($board[b_file])
					{
						if ($AUTH["auth_m_level"] >= $ba[ba_perm_down]) {
							$board[v_b_file_down_url] = file_down_url($board[b_file], $board[b_no], $upload_dir);
							$board[v_b_file_down_target] = "_download";
						}else {
							$board[v_b_file_down_url] = "JavaScript:alert('첨부파일 다운로드 권한이 없습니다.\\n\\n로그인하지 않았을 경우 로그인후 재시도하시기 바랍니다.\\n\\n다음 레벨이상만 다운로드가 가능합니다.\\n\\n=> " . $G[LEVEL_NAME][$ba[ba_perm_down]] . "');";
							$board[v_b_file_down_target] = "_self";
						}	// if()

						#$board[v_b_file_size] = file_size($board[b_file], $board[b_no], $upload_dir);
						$board[v_b_file_size] = filesize_human($board['b_file_size'], 0);;
						$board[v_b_file] = file_view($board[b_file], $board[b_no], $upload_dir, $body_maxwidth);
					}	// if()

					// [2008-06-10] ActiveX 파일 첨부
					$board[v_b_files_down_url] = array();
					if($board[b_files])
					{
						$_ex = explode("||", stripslashes($board[b_files]));
						for ($i=0; $i<sizeof($_ex); $i++)
						{
							if ($_ex[$i])
							{
								$_ex2 = explode("|", $_ex[$i]);
								$_down_url = '';
								if ($AUTH["auth_m_level"] >= $ba[ba_perm_down]) {
									$_down_url = $nmpath."/board_down.php?ba_no=".$ba_no."&b_no=".$board[b_no]."&tmpfile=".$_ex2[1]."&file=".urlencode($_ex2[0]);
									$board[v_b_files_down_url][] = $_down_url;
								}else {
									$board[v_b_files_down_url][] = "JavaScript:alert('첨부파일 다운로드 권한이 없습니다.\\n\\n로그인하지 않았을 경우 로그인후 재시도하시기 바랍니다.\\n\\n다음 레벨이상만 다운로드가 가능합니다.\\n\\n=> " . $G[LEVEL_NAME][$ba[ba_perm_down]] . "');";
								}	// if()
								//$fs = @filesize($UPLOAD_ROOT.'/'.$upload_new_dir.'/'.file_name_fix($_ex2[1], $board[b_no]));
								$board[v_b_files_name][] = $_ex2[0];
								$board[v_b_files_size][] = filesize_human($_ex2[2], 0);

								if ($board[v_b_file] != '')
									$board[v_b_file] .= '<br><br style="line-height:10px">';
								$board[v_b_file] .= file_view($_ex2[1], $board[b_no], $upload_new_dir, $body_maxwidth, "첨부파일 : ", '', $_ex2[0], $_down_url);
							}	// if()
						}	// for()
					}	// if()
				}	// if()


			// set
				// 손님글이거나 본인글이거나 관리자일때만 수정/삭제 가능
				$ba[isview_modify] = ( ($board[m_no] < 1) || ($board[m_no] == $AUTH[auth_m_no]) || ($ba[is_admin] == true) ) ? "Y" : "N";


			// comment
				if ($G_SYS[DB] == 'oracle')
				{
					$q = "SELECT bc.*, m.m_email FROM $TB[BOARD_COMMENT] bc, $TB[MEMBER] m WHERE b_no='$b_no' AND ba_no='$ba_no' AND bc.m_no=m.m_no ORDER BY bc_no";
				} else
				{
					$q = "SELECT bc.*, m.m_email FROM $TB[BOARD_COMMENT] bc LEFT JOIN $TB[MEMBER] m ON (bc.m_no=m.m_no) WHERE b_no='$b_no' AND ba_no='$ba_no' ORDER BY bc_no";
				}	// if()
				//echo $q;
				$bc = db_get_rows($q);

				if($bc)
				{
					for($i=0; $i<sizeof($bc); $i++)
					{
						$bc[$i][v_bc_name] = get_mailto_url($bc[$i][m_email], $bc[$i][bc_name]);
						$bc[$i][v_bc_subject] = text_view($bc[$i][bc_subject]);
						$bc[$i][v_bc_memo] = text_view($bc[$i][bc_memo]);
						$bc[$i][v_bc_regdate] = substr($bc[$i][bc_regdate], 0, 10);

					}	// for()
				}	// if()

				$bc_reg[is_member] = board_is_member($AUTH[auth_m_no]);

				$mode_proc = "CMT_REGISTER_OK";
				$mode_name = "추가";


			// view
				if ($mode == 'PRINT')
				{
					nskinset('board', 'print.html', 'iframe');
				} else
				{
					nskinset('board', 'read.html');
				}	// if()

				include($NSKIN['view_layout']);

			break;


###############################################################################

		// [2010-12-22] 조회기록 추가
		case "READ_LOG":
			require_once('include/pager.php');

			$CFG['TITLE'] .= ' >> <b>조회기록</b>';

			auth_limit($ba[ba_perm_read]);

			$board = board_info($ba_no, $b_no);		// array

			// data
				// search
					$q_where = " br.b_no='".$b_no."' AND br.ba_no='".$ba_no."' AND br.m_no=m.m_no ";
					if ($_GET['s_word'])
					{
						set_q_search($_GET['s_word']);
						$q_where .= " AND (m.m_id LIKE '%" . $_GET['s_word'] . "%' OR m.m_name LIKE '%" . $_GET['s_word'] . "%') ";
						$v_s_word = htmlspecialchars_fix(stripslashes($_GET['s_word']));
					}	// if()

				// sort
					$CFG['READ_LOG_LIST_FIELD'] = array(
							'm.m_id' => '아이디',
							'm.m_name' => '이름',
							'br.br_regdate' => '등록일자'
							);
					#if (!$_GET['s_key2'])
					#	$_GET['s_key2'] = 'ASC';
					$order_set = get_order(array_keys($CFG['READ_LOG_LIST_FIELD']), 'br.br_no', $_GET['s_key'], $_GET['s_key2']);
					$order_img = get_order_img(array_keys($CFG['READ_LOG_LIST_FIELD']), $_GET['s_key'], $_GET['s_key2'], false, 'common_skin');		// array

				// db - pager
					$DEBUG['db_cnt']['start'] = getmicrotime();
					$pager_params['totalItems'] = db_get_one("
						SELECT
							COUNT(*)
						FROM
							" . $TB['BOARD_READ_LOG'] . " br,
							" . $TB['MEMBER'] . " m
						WHERE
							$q_where
						");
					$pager_params['perPage'] = 20;
					$pager_params['delta'] = 2;

					$DEBUG['db_cnt']['exec'] += getmicrotime() - $DEBUG['db_cnt']['start'];

					$pager = &new Pager_Sliding($pager_params);
					$pager_links = $pager->getLinks();
					$pager_limit = get_pager_limit($pager->getCurrentPageID(), $pager_params['perPage']);

				// db - select
					$DEBUG['db_select']['start'] = getmicrotime();
					$sql = "
						SELECT
							m.m_id, m.m_name, br.br_regdate
						FROM
							" . $TB['BOARD_READ_LOG'] . " br,
							" . $TB['MEMBER'] . " m
						WHERE
							$q_where
						ORDER BY
							" . $order_set['query'] . "
						";
					$rows = db_get_rows($sql, $pager_limit['from'], $pager_limit['count'], true);
					$rows_cnt = getarraycount($rows['m_id']);
					$DEBUG['db_select']['exec'] += getmicrotime() - $DEBUG['db_select']['start'];

					for ($i=0; $i<$rows_cnt; $i++)
					{
						//$rows['br_regdate'][$i] = date('y-m-d H:i', strtotime($rows['br_regdate'][$i]));
					}	// for()


			// view
				nskinset('board', 'read_log.html', 'window_open');
				include($NSKIN['view_layout']);

			break;


###############################################################################

		// [2010-12-22] 조회기록 추가
		case "READ_LOG_EXPORT_OK":
			require_once('include/file.php');

			auth_limit($ba[ba_perm_read]);

			$board = board_info($ba_no, $b_no);		// array

			// data
				// search
					$q_where = " br.b_no='".$b_no."' AND br.ba_no='".$ba_no."' AND br.m_no=m.m_no ";

				// db - select
					$DEBUG['db_select']['start'] = getmicrotime();
					$sql = "
						SELECT
							m.m_id, m.m_name, br.br_regdate
						FROM
							" . $TB['BOARD_READ_LOG'] . " br,
							" . $TB['MEMBER'] . " m
						WHERE
							$q_where
						ORDER BY
							br.br_no
						";
					$rows = db_get_rows($sql, true);
					$rows_cnt = getarraycount($rows['m_id']);
					$DEBUG['db_select']['exec'] += getmicrotime() - $DEBUG['db_select']['start'];

					function csv_data_replace($str)
					{
						// htmlspecialchars_fix 로 변경된 문자열 되돌리기
						$trans = array("&quot;" => "\"", "&#039;" => "＇", "&lt;"=>"<", "&gt;"=>">");
						$str = strtr($str, $trans);
						return str_replace('"', '""', $str);
					}	// function()
					$crlf = "\r\n";

					$data = '"아이디","이름","읽은날짜"'.$crlf;
					for ($i=0; $i<$rows_cnt; $i++)
					{
						$data .= '"'.csv_data_replace($rows['m_id'][$i]).'",';
						$data .= '"'.csv_data_replace($rows['m_name'][$i]).'",';
						$data .= '"'.csv_data_replace($rows['br_regdate'][$i]).'"';
						$data .= $crlf;
					}	// for()

					// UTF-8
					if (strtoupper($G_SYS[CHARSET]) == 'UTF-8')
						$data = iconv_fix('UTF-8', $data, 'CP949');

					file_down_headeronly($data, 'NmailBoardReadLog_'.date('Ymd_His').'.csv');

			break;


###############################################################################


		case "REGISTER":

			auth_limit($ba[ba_perm_register]);

			//$board = board_info($ba_no, $b_no);		// array


			// check - mbronly
				if ($ba[ba_mbronly_register]) limit_mbronly($ba[ba_mbronly_register], "글쓰기권한이 없습니다.");


			// get
				$board[is_member] = board_is_member($AUTH[auth_m_no]);


			// set category
				if ($ba[ba_isuse_category] == "Y")
				{

					$board_category = get_board_category($ba_no, NULL, "N");		// array
					$board[bca_cnt] = sizeof($board_category['bca_no']);
					$board[v_bca_no] = select_list_value($_GET['s_category'], $board_category['bca_name'], $board_category['bca_no'], "선택하세요", 0, 1);
				}	// if()


			// default
				$board[v_b_homepage] = input_value("http://",1);
				$board[v_b_link] = input_value("http://",1);


			// view
				$mode_proc = "REGISTER_OK";
				$mode_name = "추가";
				$back_url = urlencode($_SERVER[REQUEST_URI]);


				// body
				$v_back_url = input_value($back_url,1);
				$radio_b_html = radio_value("b_html", NULL, array_values($G[HTML]), array_keys($G[HTML]), 0, 0, 1);
				$radio_b_isuse_reply_mail = radio_value("b_isuse_reply_mail", NULL, array_values($G[ISUSE_REPLY_MAIL]), array_keys($G[ISUSE_REPLY_MAIL]), 0, 0, 1);

				// [2006-07-20] 사용량 체크
				$fsize = get_board_size_sum($G['DINFO']['d_no'], $G['DINFO']['d_quota_board']);

				// [2008-06-10] ActiveX 추가
				$board_max_size = $fsize['quota_b'] - $fsize['sum_b'];
				$board_max_file_size = $UPLOAD_MAX_SIZE;
				$board_max_size_view = filesize_human($board_max_size);
				$board_max_file_size_view = filesize_human($board_max_file_size);

				// [2011-01-10] 히든 프레임을 사용하는 페이지에서만 활성화.
				$G_SYS['NM_HIDDEN_FRAME_ISUSE'] = true;
				nskinset('board', 'register_editor.html');
				include($NSKIN['view_layout']);


				// [2012-10-22] IE 10 fix - ActiveX 미지원하는 Metro 스타일 브라우저에서, ActvieX 가 먼저 로딩될 경우 Text 모드로 전환하는 안내창 보여줌.
				if ($ba[ba_isuse_file] == "Y" && get_activex_use() && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 10') !== false)
				{
					?>
						<script language="JavaScript">
						<!--
							if (get_activex_use_support() == false)
							{
								if (confirm("현재 브라우저에서는 ActiveX를 지원하지 않습니다.\n\n업로드 방식을 Text 모드로 전환하시겠습니까?"))
								{
									//mail_write_draft_save(2);

									var expDate = new Date();
									expDate.setDate(expDate.getDate() + 365);
									document.cookie = 'nm_upmode=T;expires='+expDate.toGMTString();

									location.reload();
								}	// if()
							}	// if()
						//-->
						</script>
					<?
				}	// if()
			break;


###############################################################################


		case "REPLY":

			auth_limit($ba[ba_perm_reply]);

			if($ba[ba_isuse_reply] != "Y") msg("답변기능을 사용할 수 없도록 설정되었습니다.");

			board_reply_limit($ba_no, $b_no);

			$board = board_info($ba_no, $b_no);		// array


			// check - mbronly
				if ($ba[ba_mbronly_reply]) limit_mbronly($ba[ba_mbronly_reply], "답변권한이 없습니다.");


			// get
				if($board)
				{
					//$_tmp = ($board[b_re_level] == 0) ? "[Re] " : NULL;
					//$board[v_b_subject] = input_value($_tmp . text_view($board[b_subject]),1);
					$board[v_b_subject] = input_value(text_view($board[b_subject]),1);

					// [2008-06-07] 웹에디터 추가
					//$board[v_b_memo] = text_view($board[b_memo], "REPLY");

					// [2009-10-12] 웹에디터 사용으로 인한 원본글 표시 문제 보완
					//$board[v_b_memo] = text_view($board[v_b_memo], "REPLY");
					//$board[v_b_memo] = text_view($board[b_memo], $board[b_html], "Y");
					//$board[v_b_memo] = htmlspecialchars($board[v_b_memo]);		// &lt; 에서 &를 한번 더 변환해야함.

					// 선택) 1,2 번 중 원하는 방식만 남기고 나머지는 주석처리(#)하시면 됩니다.

					// 1. 원본글을 보여주지 않기 - 일반적인 웹에디터 게시판 형태
					#$board[v_b_memo] = "";

					// 2. 원본글을 HTML태그를 통해 블럭으로 감싸주기 - 웹메일의 답변과 유사한 형태
					$board[v_b_memo] = '<p></p><p></p><p></p><blockquote style="border-left:#000000 2px solid; padding: 0px 0px 0px 5px; margin:0px 0px 0px 5px">-----Original Message-----<br><b>Writer</b>: '.get_mailto_url($board[b_email], $board[b_name]).'<br><b>Date</b>: '.$board[b_regdate].'<br><b>Subject</b>: '.htmlspecialchars_fix($board[b_subject]).'<br><br>'.$board[b_memo].'</blockquote>';

					// set category
						if ($ba[ba_isuse_category] == "Y")
						{

							$board_category = get_board_category($ba_no, NULL, "N");		// array
							$board[bca_cnt] = sizeof($board_category['bca_no']);
							$board[v_bca_no] = select_list_value($board[bca_no], $board_category['bca_name'], $board_category['bca_no'], "선택하세요", 0, 1);
						}	// if()

				}	// if()
				$board[is_member] = board_is_member($AUTH[auth_m_no]);


			// default
				$ba[v_ba_cm_reply] = number_format($ba[ba_cm_reply]);
				$board[v_b_homepage] = input_value("http://",1);
				$board[v_b_link] = input_value("http://",1);


			// view
				$mode_proc = "REPLY_OK";
				$mode_name = "답변";
				$back_url = urlencode($_SERVER[REQUEST_URI]);



				// body
				$v_back_url = input_value($back_url,1);
				$radio_b_html = radio_value("b_html", $board[b_html], array_values($G[HTML]), array_keys($G[HTML]), 0, 0, 1);
				$radio_b_isuse_reply_mail = radio_value("b_isuse_reply_mail", NULL, array_values($G[ISUSE_REPLY_MAIL]), array_keys($G[ISUSE_REPLY_MAIL]), 0, 0, 1);

				// [2006-07-20] 사용량 체크
				$fsize = get_board_size_sum($G['DINFO']['d_no'], $G['DINFO']['d_quota_board']);

				// [2008-06-10] ActiveX 추가
				$board_max_size = $fsize['quota_b'] - $fsize['sum_b'];
				$board_max_file_size = $UPLOAD_MAX_SIZE;
				$board_max_size_view = filesize_human($board_max_size);
				$board_max_file_size_view = filesize_human($board_max_file_size);

				// [2011-01-10] 히든 프레임을 사용하는 페이지에서만 활성화.
				$G_SYS['NM_HIDDEN_FRAME_ISUSE'] = true;
				nskinset('board', 'register_editor.html');
				include($NSKIN['view_layout']);

			break;


###############################################################################


		case "MODIFY":
		case "DEL":

			include_once("include/file.php");

			$board = board_info($ba_no, $b_no);		// array

			if($mode == "DEL")
			{
				board_reply_del_limit($ba_no, $b_no, $board[b_re_level]);
			}	// if()


			// auth
				// 회원이 작성한글은 회원만 수정/삭제가능.
				if($board[m_no] > 0)
				{
					auth_limit("user");
					if (($board[m_no] != $AUTH[auth_m_no])&&($ba[is_admin] == false))
					{
						msg("본인의 게시물만 수정/삭제할 수 있습니다.");
					}
				}


			// get
				if($board)
				{
					//$board[is_member] = board_is_member($board[m_no], $ba[ba_perm_modify]);
					$board[v_b_name] = input_value($board[b_name],1);
					$board[v_b_email] = input_value($board[b_email],1);
					$board[v_b_homepage] = input_value($board[b_homepage],1);
					$board[v_b_subject] = input_value($board[b_subject],1);

					// [2008-06-07] 웹에디터 추가
					//$board[v_b_memo] = htmlspecialchars_fix($board[b_memo]);
					$board[v_b_memo] = text_view($board[b_memo], $board[b_html], "Y");
					$board[v_b_memo] = htmlspecialchars($board[v_b_memo]);		// &lt; 에서 &를 한번 더 변환해야함.

					$board[v_b_link] = input_value($board[b_link],1);
					$board[v_b_file] = input_value($board[b_file],1);

					// set category
						if ($ba[ba_isuse_category] == "Y")
						{

							$board_category = get_board_category($ba_no, NULL, "N");		// array
							$board[bca_cnt] = sizeof($board_category['bca_no']);
							$board[v_bca_no] = select_list_value($board[bca_no], $board_category['bca_name'], $board_category['bca_no'], "선택하세요", 0, 1);
						}	// if()

				}	// if()
				$board[is_member] = board_is_member($AUTH[auth_m_no], $ba[ba_perm_modify]);


			// default
				if($board[v_b_homepage] == false) $board[v_b_homepage] = input_value("http://",1);
				if($board[v_b_link] == false) $board[v_b_link] = input_value("http://",1);


			// view
				if($mode == "MODIFY")
				{
					$mode_proc = "MODIFY_OK";
					$mode_name = "수정";
				}else if($mode == "DEL")
				{
					$mode_proc = "DEL_OK";
					$mode_name = "삭제";
				}	// if()



				// body

				if($mode == "MODIFY")
				{
					$modify_disabled = "disabled=true";
					$radio_b_html = radio_value("b_html", $board[b_html], array_values($G[HTML]), array_keys($G[HTML]), 0, 0, 1);
					$radio_b_isuse_reply_mail = radio_value("b_isuse_reply_mail", $board[b_isuse_reply_mail], array_values($G[ISUSE_REPLY_MAIL]), array_keys($G[ISUSE_REPLY_MAIL]), 0, 0, 1);

					// [2008-06-10] ActiveX 파일 첨부
					$board[v_b_files_down_url] = array();
					if($board[b_files])
					{
						$_ex = explode("||", stripslashes($board[b_files]));
						for ($i=0; $i<sizeof($_ex); $i++)
						{
							if ($_ex[$i])
							{
								$_ex2 = explode("|", $_ex[$i]);
								$_down_url = '';
								if ($AUTH["auth_m_level"] >= $ba[ba_perm_down]) {
									$_down_url = $nmpath."/board_down.php?ba_no=".$ba_no."&b_no=".$board[b_no]."&tmpfile=".$_ex2[1]."&file=".urlencode($_ex2[0]);
									$board[v_b_files_down_url][] = $_down_url;
								}else {
									$board[v_b_files_down_url][] = "JavaScript:alert('첨부파일 다운로드 권한이 없습니다.\\n\\n로그인하지 않았을 경우 로그인후 재시도하시기 바랍니다.\\n\\n다음 레벨이상만 다운로드가 가능합니다.\\n\\n=> " . $G[LEVEL_NAME][$ba[ba_perm_down]] . "');";
								}	// if()
								//$fs = @filesize($UPLOAD_ROOT.'/'.$upload_new_dir.'/'.file_name_fix($_ex2[1], $board[b_no]));
								$board[v_b_files_name][] = $_ex2[0];
								$board[v_b_files_name_tmp][] = $_ex2[1];
								$board[v_b_files_size][] = filesize_human($_ex2[2], 0);

								// [2009-02-18] 수정화면에서 일반첨부와 다중첨부가 같이 있을 경우 > 태그가 보여지는 오류 수정.
								//if ($board[v_b_file] != '')
								//	$board[v_b_file] .= '<br><br style="line-height:10px">';
								//$board[v_b_file] .= file_view($_ex2[1], $board[b_no], $upload_new_dir, $body_maxwidth, "첨부파일 : ", '', $_ex2[0], $_down_url);
							}	// if()
						}	// for()
					}	// if()

					if($board[b_file])
					{
						$board[v_b_files_down_url][] = file_down_url($board[b_file], $board[b_no], $upload_dir);
						$board[v_b_files_name][] = $board[b_file];
						$board[v_b_files_name_tmp][] = 'OLD_B_FILE';
						$board[v_b_files_size][] = filesize_human($board['b_file_size'], 0);;
					}	// if()

				}	// if()

				// [2006-07-20] 사용량 체크
				$fsize = get_board_size_sum($G['DINFO']['d_no'], $G['DINFO']['d_quota_board']);

				// [2008-06-10] ActiveX 추가
				$board_max_size = $fsize['quota_b'] - $fsize['sum_b'];
				$board_max_file_size = $UPLOAD_MAX_SIZE;
				$board_max_size_view = filesize_human($board_max_size);
				$board_max_file_size_view = filesize_human($board_max_file_size);

				// [2011-01-10] 히든 프레임을 사용하는 페이지에서만 활성화.
				$G_SYS['NM_HIDDEN_FRAME_ISUSE'] = true;
				nskinset('board', 'register_editor.html');
				include($NSKIN['view_layout']);

			break;


###############################################################################


		// [2010-12-24] 재게시 수정
		case "REWRITE":

			include_once("include/file.php");


			if($ba[ba_isuse_rewrite] != "Y") msg("재게시기능을 사용할 수 없도록 설정되었습니다.");

			auth_limit($ba[ba_perm_rewrite]);

			// 재게시 - 기존 게시물의 제목,본문, 첨부파일을 가져와서 새 글을 등록함.  따라서 읽기/다운/쓰기 권한 검사 필요.
			auth_limit($ba[ba_perm_read]);
			auth_limit($ba[ba_perm_down]);
			auth_limit($ba[ba_perm_register]);

			// check - mbronly
				if ($ba[ba_mbronly_register]) limit_mbronly($ba[ba_mbronly_register], "글쓰기권한이 없습니다.");


			$board = board_info($ba_no, $b_no);		// array

			// get
				if($board)
				{
					//$board[is_member] = board_is_member($board[m_no], $ba[ba_perm_modify]);
					#$board[v_b_name] = input_value($board[b_name],1);
					#$board[v_b_email] = input_value($board[b_email],1);
					#$board[v_b_homepage] = input_value($board[b_homepage],1);
					$rewrite_prefix = '[재게시] ';
					if (strpos(trim($board[b_subject]), $rewrite_prefix) !== 0)
						$board[b_subject] = $rewrite_prefix.$board[b_subject];
					$board[v_b_subject] = input_value($board[b_subject],1);

					// [2008-06-07] 웹에디터 추가
					//$board[v_b_memo] = htmlspecialchars_fix($board[b_memo]);
					$board[v_b_memo] = text_view($board[b_memo], $board[b_html], "Y");
					$board[v_b_memo] = htmlspecialchars($board[v_b_memo]);		// &lt; 에서 &를 한번 더 변환해야함.

					$board[v_b_link] = input_value($board[b_link],1);
					$board[v_b_file] = input_value($board[b_file],1);

					// set category
						if ($ba[ba_isuse_category] == "Y")
						{

							$board_category = get_board_category($ba_no, NULL, "N");		// array
							$board[bca_cnt] = sizeof($board_category['bca_no']);
							$board[v_bca_no] = select_list_value($board[bca_no], $board_category['bca_name'], $board_category['bca_no'], "선택하세요", 0, 1);
						}	// if()

				}	// if()
				$board[is_member] = board_is_member($AUTH[auth_m_no], $ba[ba_perm_modify]);


			// default
				if($board[v_b_homepage] == false) $board[v_b_homepage] = input_value("http://",1);
				if($board[v_b_link] == false) $board[v_b_link] = input_value("http://",1);


			// view
				$mode_proc = "REWRITE_OK";
				$mode_name = "재게시";


				// body
				$modify_disabled = "disabled=true";
				$radio_b_html = radio_value("b_html", $board[b_html], array_values($G[HTML]), array_keys($G[HTML]), 0, 0, 1);
				$radio_b_isuse_reply_mail = radio_value("b_isuse_reply_mail", $board[b_isuse_reply_mail], array_values($G[ISUSE_REPLY_MAIL]), array_keys($G[ISUSE_REPLY_MAIL]), 0, 0, 1);


				// [2008-06-10] ActiveX 파일 첨부
				$board[v_b_files_down_url] = array();
				if($board[b_files])
				{
					$b_files_old_new = "";
					$_ex = explode("||", stripslashes($board[b_files]));
					for ($i=0; $i<sizeof($_ex); $i++)
					{
						if ($_ex[$i])
						{
							$_ex2 = explode("|", $_ex[$i]);

							// [2010-12-31]원본 게시물의 첨부파일을 임시디렉토리로 저장함.  글 작성도중 원본 게시물이 삭제/수정될 경우의 에러 예방.
							$file_ori = $UPLOAD_ROOT.'/'.$upload_new_dir.'/'.file_name_fix($_ex2[1], $board[b_no]);
							if (file_exists($file_ori))
							{
								$UPLOAD_ROOT = $UPLOAD_ROOT_NEW;
								mkdir_parent($UPLOAD_DIR[BIGFILE_TMP]);
								// [2011-01-17] 임시 폴더에서는 게시물 번호가 생략되어야 함.  생략하지 않으면 이중으로 붙음.
								//$file_new = $UPLOAD_ROOT.'/'.$UPLOAD_DIR[BIGFILE_TMP].'/'.$_ex2[1].'.'.$ba_no.'.'.$b_no;
								$file_new_name = getmicrotime().'.'.$i;
								$file_new = $UPLOAD_ROOT.'/'.$UPLOAD_DIR[BIGFILE_TMP].'/'.$file_new_name;
								if (!file_exists($file_new))
									copy($file_ori, $file_new);

								$_down_url = '';
								if ($AUTH["auth_m_level"] >= $ba[ba_perm_down]) {
									$_down_url = $nmpath."/board_down.php?ba_no=".$ba_no."&b_no=".$board[b_no]."&tmpfile=".$_ex2[1]."&file=".urlencode($_ex2[0]);
									$board[v_b_files_down_url][] = $_down_url;
								}else {
									$board[v_b_files_down_url][] = "JavaScript:alert('첨부파일 다운로드 권한이 없습니다.\\n\\n로그인하지 않았을 경우 로그인후 재시도하시기 바랍니다.\\n\\n다음 레벨이상만 다운로드가 가능합니다.\\n\\n=> " . $G[LEVEL_NAME][$ba[ba_perm_down]] . "');";
								}	// if()
								//$fs = @filesize($UPLOAD_ROOT.'/'.$upload_new_dir.'/'.file_name_fix($_ex2[1], $board[b_no]));
								$board[v_b_files_name][] = $_ex2[0];
								$board[v_b_files_name_tmp][] = $file_new_name;
								$board[v_b_files_size][] = filesize_human($_ex2[2], 0);

								// [2011-01-17] 변경된 v_b_files_name_tmp 파일명을 갱신해야함.
								if ($b_files_old_new != '')
									$b_files_old_new .= "||";
								$b_files_old_new .= $_ex2[0].'|'.$file_new_name.'|'.$_ex2[2];

								// [2009-02-18] 수정화면에서 일반첨부와 다중첨부가 같이 있을 경우 > 태그가 보여지는 오류 수정.
								//if ($board[v_b_file] != '')
								//	$board[v_b_file] .= '<br><br style="line-height:10px">';
								//$board[v_b_file] .= file_view($_ex2[1], $board[b_no], $upload_new_dir, $body_maxwidth, "첨부파일 : ", '', $_ex2[0], $_down_url);
							}	// if()
						}	// if()
					}	// for()
					$board[b_files] = $b_files_old_new;
				}	// if()

				/*
				if($board[b_file])
				{
					$board[v_b_files_down_url][] = file_down_url($board[b_file], $board[b_no], $upload_dir);
					$board[v_b_files_name][] = $board[b_file];
					$board[v_b_files_name_tmp][] = 'OLD_B_FILE';
					$board[v_b_files_size][] = filesize_human($board['b_file_size'], 0);;
				}	// if()
				*/

				// [2006-07-20] 사용량 체크
				$fsize = get_board_size_sum($G['DINFO']['d_no'], $G['DINFO']['d_quota_board']);

				// [2008-06-10] ActiveX 추가
				$board_max_size = $fsize['quota_b'] - $fsize['sum_b'];
				$board_max_file_size = $UPLOAD_MAX_SIZE;
				$board_max_size_view = filesize_human($board_max_size);
				$board_max_file_size_view = filesize_human($board_max_file_size);

				// [2011-01-10] 히든 프레임을 사용하는 페이지에서만 활성화.
				$G_SYS['NM_HIDDEN_FRAME_ISUSE'] = true;
				nskinset('board', 'register_editor.html');
				include($NSKIN['view_layout']);

			break;


###############################################################################


		case "NOTICE":
		case "NOTICE_MODIFY":


			// auth
				if ($ba[is_admin] == false)
				{
					msg("게시판 관리자 권한이 있어야 공지사항으로 지정할 수 있습니다.");
				}		// if()


			// get
				if ($mode == "NOTICE")
				{
					$board = board_info($ba_no, $b_no);		// array
				} else
				{
					$board[b_subject] = $ba[ba_notice_subject];
					$board[b_memo] = $ba[ba_notice_memo];
					$board[b_html] = $ba[ba_notice_html];
				}	// if()


			// set
				$board[v_b_subject] = input_value($board[b_subject],1);
				$board[v_b_memo] = htmlspecialchars_fix(han_substr($board[b_memo],$G_BOARD[NOTICE_LENGTH]));
				$radio_b_html = radio_value("b_html", $board[b_html], array_values($G[HTML]), array_keys($G[HTML]), 0, 0, 1);


			// view
				nskinset('board', 'notice_form.html');
				include($NSKIN['view_layout']);

			break;


###############################################################################


		case "NOTICE_OK":

			// [2007-05-10] 연결된 게시물이 삭제되었을때 공지사항이 수정/삭제가 안되던 오류 수정.
			//$board = board_info($ba_no, $b_no);		// array
			$board = board_info($ba_no, $b_no, 'N');		// array


			// auth
				if ($ba[is_admin] == false)
				{
					msg("게시판 관리자 권한이 있어야 공지사항으로 지정할 수 있습니다.");
				}		// if()


			// check
				if ($b_subject == '') msg("올바른 URL로 접근하여 주십시오");


			// set
				// query
					to_db_str(&$b_subject, 255);
					if ($G_SYS[DB] == 'oracle')
					{
						to_db_str(&$b_memo, $G_SYS['DB_TEXT'], false);
					} else
					{
						to_db_str(&$b_memo, $G_SYS['DB_MEDIUMTEXT'], false);
					}	// if()


			// proc
				// update
					$q = "
						UPDATE
							$TB[BOARD_ADMIN]
						SET
							ba_notice_no='$b_no',
							ba_notice_subject='$b_subject',
							ba_notice_html='$b_html',
							ba_notice_memo='$b_memo'
						WHERE
							ba_no='$ba_no'
							AND d_no='" . $AUTH['auth_d_no'] ."'
						";
					//echo "<HR>" . $q;
					db_query($q);


			// view
				msg("공지사항으로 지정되었습니다.", 0);
				movepage("board.php?mode=LIST&" . $b_qs["DEFAULT"]);

			break;


###############################################################################


		case "NOTICE_DEL_OK":

			// [2007-05-10] 연결된 게시물이 삭제되었을때 공지사항이 수정/삭제가 안되던 오류 수정.
			//$board = board_info($ba_no, $b_no);		// array
			$board = board_info($ba_no, $b_no, 'N');		// array


			// auth
				if ($ba[is_admin] == false)
				{
					msg("게시판 관리자 권한이 있어야 공지사항을 삭제할 수 있습니다.");
				}		// if()


			// proc
				// update
					$q = "
						UPDATE
							$TB[BOARD_ADMIN]
						SET
							ba_notice_no=NULL,
							ba_notice_subject=NULL,
							ba_notice_html=NULL,
							ba_notice_memo=NULL
						WHERE
							ba_no='$ba_no'
							AND d_no='" . $AUTH['auth_d_no'] ."'
						";
					//echo "<HR>" . $q;
					db_query($q);


			// view
				msg("공지사항이 삭제되었습니다.", 0);
				movepage("board.php?mode=LIST&" . $b_qs["DEFAULT"]);

			break;


###############################################################################


		case "CMT_DEL":

			$bc = board_comment_info($ba_no, $b_no, $bc_no);		// array

			// auth
				// 회원이 작성한글은 회원만 수정/삭제가능.
				if($bc[m_no] > 0) auth_limit("user");


			// comment
				$bc_reg[is_member] = board_is_member($bc[m_no], $ba[ba_perm_cmt_del]);

				$mode_proc = "CMT_DEL_OK";
				$mode_name = "삭제";


			// view


				// body

				nskinset('board', 'cmt_register.html');
				include($NSKIN['view_layout']);

			break;


###############################################################################


		case "REGISTER_OK":
		case "REPLY_OK":

			auth_limit($ba[ba_perm_register]);

			include_once("include/file.php");

			// check
				if($b_subject == '') msg("올바른 URL로 접근하여 주십시오");
				if (!$AUTH[auth_m_id])
				{
					if  ((!$b_name)||(!$b_pwd)) msg("글입력시간이 길어져서 자동로그아웃된 경우에는\\n\\n다시 로그인하셔서 글을 작성하셔야합니다.\\n\\n글추가 페이지를 [새로고침]해보십시오.");
				}	// if()

			board_loop_limit($b_subject);

			if ($mode == "REGISTER_OK")
			{
				// check - mbronly
					if ($ba[ba_mbronly_register]) limit_mbronly($ba[ba_mbronly_register], "글쓰기권한이 없습니다.");
			}elseif ($mode == "REPLY_OK")
			{
				// check - mbronly
					if ($ba[ba_mbronly_reply]) limit_mbronly($ba[ba_mbronly_reply], "답변권한이 없습니다.");

				if($ba[ba_isuse_reply] != "Y") msg("답변기능을 사용할 수 없도록 설정되었습니다.");
				board_reply_limit($ba_no, $b_no);
			}	// if()

			// set
				// query
					to_db_str(&$b_name, 20, "STRIP_TAGS");
					to_db_str(&$b_pwd, 32, false);
					to_db_str(&$b_email, 255, "STRIP_TAGS");
					to_db_str(&$b_homepage, 255, "STRIP_TAGS");
					to_db_str(&$b_subject, 255);
					if ($G_SYS[DB] == 'oracle')
					{
						to_db_str(&$b_memo, $G_SYS['DB_TEXT'], false);
					} else
					{
						to_db_str(&$b_memo, $G_SYS['DB_MEDIUMTEXT'], false);
					}	// if()
					to_db_str(&$b_link, 255, "STRIP_TAGS");
					to_db_str(&$b_file, 255);


				// data
					$ba_no;

					if ($AUTH[auth_m_id])
					{
						$m_no = $AUTH[auth_m_no];
						$b_name = $AUTH[auth_m_name];
						$b_pwd = NULL;
						$b_email = $AUTH[auth_m_email];
						$b_homepage = $AUTH[auth_m_homepage];
						$q_b_pwd = " '$b_pwd' ";
					}else
					{
						$m_no = 0;
						$q_b_pwd = " '" . pwd_enc($b_pwd) . "' ";
					}	// if()

					if (trim($b_homepage) == "http://" ) $b_homepage = "";
					if (trim($b_link) == "http://" ) $b_link = "";


					// [2008-06-10] ActiveX 파일 첨부
					// sample) ["b_files"]=> string(74) "||사본 - test.php|1116556464.14663|19||철원군청.xls|1116556471.03856|13824"
					$b_files_tmp = array();
					$b_file_size = 0;
					if ($_POST['board_upload_type'] == '1')
					{
						if ($_POST['b_files'])
						{
							$b_files_new = '';
							$_ex = explode("||", stripslashes($_POST['b_files']));
							for ($i=0; $i<sizeof($_ex); $i++)
							{
								if ($_ex[$i])
								{
									$_ex2 = explode("|", $_ex[$i]);
									if (dir_parent_limit($_ex2[1]))
										msg("상위 디렉토리로는 접근하실 수 없습니다.");

									$_file = $UPLOAD_ROOT_NEW.'/'.$UPLOAD_DIR[BIGFILE_TMP].'/'.$_ex2[1];
									if (file_exists($_file))
									{
										$_ex2[0] = basename_fix($_ex2[0]);
										$b_files_tmp['file'][] = $_file;
										$b_files_tmp['file_name'][] = $_ex2[0];
										$fs = filesize($_file);
										$b_files_tmp['file_size'][] = $fs;
										$b_file_size += $fs;

										if ($b_files_new != '')
											$b_files_new .= '||';
										$b_files_new .= $_ex2[0].'|'.$_ex2[1].'|'.$fs;
									}	// if()
								}	// if()
							}	// for()
							$_POST['b_files'] = addslashes($b_files_new);
						}	// if()
						$is_upload = false;
						$b_file = '';
						//$b_file_size;
						$b_files = $_POST['b_files'];
					} else
					{
						// [2008-04-15] 업로드 에러 메세지를 정확히 표시함
						$errorMsg = '';
						if ($_FILES['file']['error'] == UPLOAD_ERR_NO_FILE)
						{
							$is_upload = false;
						} else
						{
							// [2008-05-30] 파일 첨부를 사용하지 않을 때 글쓰기시 post_max_size 관련 에러 방지
							if ($ba['ba_isuse_file'] == 'Y')
							{
								$errorMsg = file_upload_error_msg($_FILES['file'], $_FILES['file']['size'], $UPLOAD_MAX_SIZE);
								if ($errorMsg != '')
								{
									$errorMsg = "\\n\\n파일 첨부가 실패하였습니다.\\n\\n원인 : ".$errorMsg;
									$is_upload = false;
								} else
								{
									// 업로드되었을때만 파일이름을 DB에 저장함.
										$b_file = $_FILES[file][name];
										$b_file_size = $_FILES[file][size];

										// [2006-07-20] 사용량 체크
										$fsize = get_board_size_sum($G['DINFO']['d_no'], $G['DINFO']['d_quota_board']);
										if (	($fsize['sum_b'] + $_FILES[file][size]) > $fsize['quota_b'])
											msg("[게시판 첨부 할당량]을 초과하여 파일첨부가 불가능합니다.\\n\\n서버관리자에게 문의하여 주시기 바랍니다.");
									$is_upload = true;
								}	// if()
							} else 
							{
								$is_upload = false;								
							}	// if()
						}	// if()

						if (!$is_upload)
						{
							$b_file = '';
							$b_file_size = 0;
						}	// if()
						$b_files = '';
					}	// if()


				// default
					if ($mode == "REGISTER_OK")
					{
						$b_ref = 0;
						$b_re_step = 0;
						$b_re_level = 0;
					}else if ($mode == "REPLY_OK")
					{
						$board = board_info($ba_no, $b_no);		// array

						$b_ref = $board[b_ref];
						$b_re_step = $board[b_re_step] + 1;
						$b_re_level = $board[b_re_level] + 1;

						// 연관된 답변들의 순서 재정렬
							$q = "UPDATE $TB[BOARD] SET b_re_step=b_re_step+1 WHERE b_ref='$b_ref' AND b_re_step >= '$b_re_step'";
							//echo "<HR>" . $q;
							db_query($q);

					}	// if()

					$now = date('Y-m-d H:i:s');
					$b_reghost = $_SERVER["REMOTE_ADDR"];


			// proc
				// insert
					$q = "INSERT INTO $TB[BOARD] (b_no, ba_no, bca_no, m_no, b_name, b_pwd, b_email, b_homepage, b_isuse_reply_mail, b_subject, b_html, b_memo, b_link, b_file, b_files, b_file_size, b_refer, b_down, b_vote, b_comment, b_ref, b_re_step, b_re_level, b_regdate, b_reghost, b_last_modifydate, b_last_modifyhost) VALUES (".db_sqc_next($TB['BOARD']).", '$ba_no', '$bca_no', '$m_no', '$b_name', " . $q_b_pwd . ", '$b_email', '$b_homepage', '$b_isuse_reply_mail', '$b_subject', '$b_html', '$b_memo', '$b_link', '$b_file', '$b_files', '$b_file_size', 0, 0, 0, 0, '$b_ref', '$b_re_step', '$b_re_level', '$now', '$b_reghost', NULL, NULL)";
					//echo "<HR>" . $q;
					db_query($q);


				// update - b_ref
					$curr_b_no = db_sqc_curr($TB['BOARD']);		// 삽입된 데이타 키

					if ($mode == "REGISTER_OK")
					{
						$q = "UPDATE $TB[BOARD] SET b_ref=b_no WHERE b_no='$curr_b_no' AND ba_no='$ba_no'";
						//echo "<HR>" . $q;
						db_query($q);
					}	// if()


				// [2008-06-10] ActiveX 파일 첨부 - 디비 저장 성공후 실제 디렉토리로 이동
				for ($i=0; $i<sizeof($b_files_tmp['file']); $i++)
				{
					$filename = basename_fix($b_files_tmp['file'][$i]);
					$errorMsg .= file_move($filename, '', $UPLOAD_DIR[BIGFILE_TMP], $filename, $curr_b_no, $upload_new_dir);
				}	// for()


				// [2008-04-15] 업로드 에러 메세지를 정확히 표시함
				if ($is_upload)
				{
					// file upload
						if($_FILES['file'][name])
						{
							// [2006-07-28] 업로드 파일 용량 체크 변경.
							#$errorMsg = file_up($file, $_FILES['file'][name], $_FILES[file][size], $upload_dir, $curr_b_no, "ALL");
							$errorMsg .= file_up_new('file', $_FILES['file'][name], $curr_b_no, $upload_dir, $UPLOAD_MAX_SIZE);
						}	// if()
				}	// if()


			// reply mail
				/*
				if ($mode == "REGISTER_OK") {
					//
				} else if ($mode == "REPLY_OK") {
					if ( ($board[b_isuse_reply_mail] == "Y") && ($board[b_email]) ) {		// parent data
						// mail check
							if (isemail($board[b_email])) {		// 올바른주소인지여부
								if (mail_mx_check($board[b_email])) {		// 운영중인주소인지여부

									// body make
										$rm = array();
										$rm[board_name] = stripslashes($ba[ba_name]);
										$rm[subject] = stripslashes($b_subject);

										$rm[memo] = text_view(stripslashes($b_memo), $b_html);
										//echo "<hr><xmp>" . stripslashes($b_memo) . "</xmp>";
										//echo "<hr><xmp>" . $rm[memo] . "</xmp>";

										$rm[writer] = get_mailto_url($AUTH[auth_m_email], $AUTH[auth_m_name]);
										$rm[regdate] = date("Y-m-d H:i:s");
										$rm[board_list_url] = $G_SYS[HTTP_URL_ROOT] . "/board/board.php?mode=LIST&ba_no=$ba_no";
										$rm[board_read_url] = $G_SYS[HTTP_URL_ROOT] . "/board/board.php?mode=READ&ba_no=$ba_no&b_no=$curr_b_no";

										$body = file_read("../main/header_mail.inc.html");
										$body .= file_read("board_skin/reply_mail.html");
										$body .= file_read("../main/footer_mail.inc.html");
										//echo "<hr><xmp>" . $body . "</xmp>";

										$body = set_text_fetch($body);
										$body = text_fetch("rm", $rm, $body);
										//echo "<hr><xmp>" . $body . "</xmp>";
										//echo "<hr>" . $body;


									// mail send
										require_once('include/mail_send_lib.php');

										$recipients = $board[b_email];		// An array or comma seperated string of recipients.
										$to = $board[b_name] . "<" . $board[b_email] . ">";
										$from = "\"" . $G_SYS[ADMIN_EMAIL_NAME] . "\"<" . $G_SYS[ADMIN_EMAIL] . ">";		// 한글사용시 큰따옴표로 묶어줘야함.  ex) "테스터"<test@test.com>
										$subject = "[답변알림]" . htmlspecialchars_fix($b_subject);
										$body;
										$body_type = "HTML";
										$file = NULL;
										$file_name = NULL;
										$host = $G_SYS[SMTP_ADDR];

										//echo "<hr><xmp>" . $subject . "</xmp>";
										//echo "<hr>" . $body . "";

										mail_smtp($recipients, $to, $from, $subject, $body, $body_type, $file, $file_name, $host);

								}	// if()
							}	// if()

					}	// if()
				}	// if()
				*/

				// [2010-12-23] 임시보관 추가
				if ($_POST['draft_bd_no'] > 0)
					board_draft_del($AUTH['auth_m_no'], $_POST['draft_bd_no']);


			// view
				if ($errorMsg)
					msg($mode_name . "되었습니다." . $errorMsg, 0);
				movepage("board.php?mode=READ&b_no=".$curr_b_no."&" . $b_qs["LIST"]);

			break;


###############################################################################


		// [2010-12-23] 임시보관 추가
		case "DRAFT_OK":

			if (!$AUTH[auth_m_no])
				die("Not Login");

			// 임시보관함에 저장할때 아무 내용이 없을 땐 생략함.
			if (trim($_POST['b_subject']) == '' && trim($_POST['b_memo']) == '')
				die("Data Null");


			// set
				// query
					to_db_str(&$b_subject, 255);
					if ($G_SYS[DB] == 'oracle')
					{
						to_db_str(&$b_memo, $G_SYS['DB_TEXT'], false);
					} else
					{
						to_db_str(&$b_memo, $G_SYS['DB_MEDIUMTEXT'], false);
					}	// if()


					$now = date('Y-m-d H:i:s');
					$bd_reghost = $_SERVER["REMOTE_ADDR"];

			// proc
				if ($_POST['draft_bd_no'] > 0)
				{
					$q = "UPDATE $TB[BOARD_DRAFT] SET b_subject='$b_subject', b_memo='$b_memo' WHERE bd_no='".$_POST['draft_bd_no']."' AND m_no='".$AUTH['auth_m_no']."'";
					//echo "<HR>" . $q;
					db_query($q);

					$curr_bd_no = $_POST['draft_bd_no'];
				} else
				{
					$q = "INSERT INTO $TB[BOARD_DRAFT] (bd_no, m_no, b_subject, b_memo, bd_regdate, bd_reghost) VALUES (".db_sqc_next($TB['BOARD_DRAFT']).", '".$AUTH[auth_m_no]."', '$b_subject', '$b_memo', '$now', '$bd_reghost')";
					//echo "<HR>" . $q;
					db_query($q);

					$curr_bd_no = db_sqc_curr($TB['BOARD_DRAFT']);		// 삽입된 데이타 키
				}	// if()


			// view
				?>
					<script language="JavaScript">
					<!--
						var parent_form = '';
						if (parent.document.forms.register == null && opener.document.forms.register != null)
						{
							parent_form = opener.document.forms.register;
						} else
						{
							parent_form = parent.document.forms.register;
						}
						parent_form.draft_bd_no.value = '<?= $curr_bd_no ?>';

						<? if ($_GET['isauto'] == '1') { ?>
							if (parent.document.all.draft_save_auto_msg)
							{
								parent.document.all.draft_save_auto_msg.style.display = '';
								parent.document.all.draft_save_auto_msg.innerHTML = '&nbsp;자동으로 임시 보관함에 저장되었습니다.  <?= date('H:i') ?>&nbsp;';
							}
						<? } else { ?>
							alert('임시 보관함에 저장되었습니다.\n\n주의) 첨부파일은 저장되지 않습니다.');
						<? }	// if() ?>
					//-->
					</script>
				<?

			break;


###############################################################################


		// [2010-12-23] 임시보관 추가
		case "DRAFT_LIST":
			auth_limit("user");

			require_once('include/pager.php');

			$CFG['TITLE'] .= ' >> <b>임시 보관함</b>';


			// data
				// search
					$q_where = " m_no='".$AUTH['auth_m_no']."' ";
					if ($_GET['s_word'])
					{
						set_q_search($_GET['s_word']);
						$q_where .= " AND (b_subject LIKE '%" . $_GET['s_word'] . "%' OR b_memo LIKE '%" . $_GET['s_word'] . "%') ";
						$v_s_word = htmlspecialchars_fix(stripslashes($_GET['s_word']));
					}	// if()

				// sort
					$CFG['DRAFT_LIST_FIELD'] = array(
							'b_subject' => '제목',
							'bd_regdate' => '등록일자'
							);
					#if (!$_GET['s_key2'])
					#	$_GET['s_key2'] = 'ASC';
					$order_set = get_order(array_keys($CFG['DRAFT_LIST_FIELD']), 'bd_no', $_GET['s_key'], $_GET['s_key2']);
					$order_img = get_order_img(array_keys($CFG['DRAFT_LIST_FIELD']), $_GET['s_key'], $_GET['s_key2'], false, 'common_skin');		// array

				// db - pager
					$DEBUG['db_cnt']['start'] = getmicrotime();
					$pager_params['totalItems'] = db_get_one("
						SELECT
							COUNT(*)
						FROM
							" . $TB['BOARD_DRAFT'] . "
						WHERE
							$q_where
						");
					$pager_params['perPage'] = 15;
					$pager_params['delta'] = 2;

					$DEBUG['db_cnt']['exec'] += getmicrotime() - $DEBUG['db_cnt']['start'];

					$pager = &new Pager_Sliding($pager_params);
					$pager_links = $pager->getLinks();
					$pager_limit = get_pager_limit($pager->getCurrentPageID(), $pager_params['perPage']);

				// db - select
					$DEBUG['db_select']['start'] = getmicrotime();
					$sql = "
						SELECT
							*
						FROM
							" . $TB['BOARD_DRAFT'] . "
						WHERE
							$q_where
						ORDER BY
							" . $order_set['query'] . "
						";
					$rows = db_get_rows($sql, $pager_limit['from'], $pager_limit['count'], true);
					$rows_cnt = getarraycount($rows['bd_no']);
					$DEBUG['db_select']['exec'] += getmicrotime() - $DEBUG['db_select']['start'];

					for ($i=0; $i<$rows_cnt; $i++)
					{
						$rows['bd_regdate'][$i] = date('y-m-d H:i', strtotime($rows['bd_regdate'][$i]));
					}	// for()


			// view
				nskinset('board', 'draft_list.html', 'window_open');
				include($NSKIN['view_layout']);

			break;

###############################################################################


		// [2010-12-23] 임시보관 추가
		case "DRAFT_DEL_OK":
			auth_limit("user");

			for ($i=0; $i<sizeof($_GET['cno']); $i++)
			{
				if (is_numeric($_GET['cno'][$i]))
				{
					$q = "DELETE FROM $TB[BOARD_DRAFT] WHERE bd_no='".$_GET['cno'][$i]."' AND m_no='".$AUTH['auth_m_no']."'";
					//echo "<HR>" . $q;
					db_query($q);
				}	// if()
			}	// for()


			// view
				msg("삭제되었습니다." . $errorMsg, 0);
				movepage("board.php?mode=DRAFT_LIST&" . $b_qs["DEFAULT"]);

			break;


###############################################################################


		case "VOTE_OK":

			//$board = board_info($ba_no, $b_no);		// array


			// check
				$vote_no = $ba_no . "_" . $b_no;

				if ($_COOKIE[ck_vote][$vote_no] == 1) msg("이미 추천하였습니다.");
				SetCookie("ck_vote[$vote_no]", 1, time()+24*3600, "/");		// 쿠키의 배열을 사용해서 각각의 게시물마다 쿠키값을 저장함.


			// proc
				board_vote_plus($ba_no, $b_no);


			// view
				msg("추천되었습니다.", 0);
				movepage("board.php?mode=READ&" . $b_qs["DEFAULT"]);

			break;


###############################################################################


		case "MODIFY_OK":

			include_once("include/file.php");

			$board = board_info($ba_no, $b_no);		// array

			// check
				if($b_subject == '') msg("올바른 URL로 접근하여 주십시오");

			// auth
				// 회원이 작성한글은 회원만 수정가능.
				if($board[m_no] > 0) auth_limit("user");

				$board[is_member] = board_is_member($board[m_no], $ba[ba_perm_modify]);

				if($board[is_member] == true)		// 회원폼에서는 자신의 글일때만 수정가능.  (관리자제외)
				{
					if ($board[m_no] != $AUTH[auth_m_no]) auth_limit($ba[ba_perm_modify]);
				}else		// 회원폼이 아닐때는 비밀번호가 일치할때만 수정가능.
				{
					if (strcmp($board[b_pwd], pwd_enc($b_pwd))) msg("비밀번호가 일치하지 않습니다.");
				}	// if()


			// set
				// query
					to_db_str(&$b_name, 20, "STRIP_TAGS");
					to_db_str(&$b_pwd, 32, false);
					to_db_str(&$b_email, 255, "STRIP_TAGS");
					to_db_str(&$b_homepage, 255, "STRIP_TAGS");
					to_db_str(&$b_subject, 255);
					if ($G_SYS[DB] == 'oracle')
					{
						to_db_str(&$b_memo, $G_SYS['DB_TEXT'], false);
					} else
					{
						to_db_str(&$b_memo, $G_SYS['DB_MEDIUMTEXT'], false);
					}	// if()
					to_db_str(&$b_link, 255, "STRIP_TAGS");
					to_db_str(&$b_file, 255);


				// data
					$q_set = NULL;
					if ($board[is_member] == false)
					{
						$q_set .= " b_name='$b_name', ";
						$q_set .= " b_email='$b_email', ";
						$q_set .= " b_homepage='$b_homepage', ";
					}	// if()

					$b_subject;
					$b_html;
					$b_memo;
					if (trim($b_homepage) == "http://" ) $b_homepage = "";
					if (trim($b_link) == "http://" ) $b_link = "";

					$errorMsg = '';

					// [2008-06-12] 파일삭제
					$board['b_file_ori'] = $board['b_file'];
					$_b_files_del = array();
					if ($_POST['b_files_del'])
					{
						for ($i=0; $i<sizeof($_POST['b_files_del']); $i++)
						{
							if ($_POST['b_files_del'][$i] == 'OLD_B_FILE')
							{
								$fs = @filesize($UPLOAD_ROOT_NEW.'/'.$upload_dir.'/'.file_name_fix($board['b_file'], $board[b_no]));
								$board['b_file_size'] -= $fs;

								$errorMsg .= file_del($board['b_file'], $b_no, $upload_dir);
								$board['b_file'] = '';
							} else
							{
								$fs = @filesize($UPLOAD_ROOT_NEW.'/'.$upload_new_dir.'/'.file_name_fix($_POST['b_files_del'][$i], $board[b_no]));
								$board['b_file_size'] -= $fs;

								$errorMsg .= file_del($_POST['b_files_del'][$i], $b_no, $upload_new_dir);
								$_b_files_del[] = $_POST['b_files_del'][$i];
							}	// if()
						}	// for()
					}	// if()

					// 디비에 저장된 파일저장구조 갱신
					if ($_b_files_del)
					{
						$b_files_new = '';
						$_ex = explode("||", stripslashes($board['b_files']));
						for ($i=0; $i<sizeof($_ex); $i++)
						{
							if ($_ex[$i])
							{
								$_ex2 = explode("|", $_ex[$i]);

								if (!in_array($_ex2[1], $_b_files_del))
								{
									if ($b_files_new != '')
										$b_files_new .= '||';
									$b_files_new .= $_ex2[0].'|'.$_ex2[1].'|'.$_ex2[2];
								}	// if()
							}	// if()
						}	// for()
						$board['b_files'] = $b_files_new;
					}	// if()

					// [2008-06-10] ActiveX 파일 첨부
					// sample) ["b_files"]=> string(74) "||사본 - test.php|1116556464.14663|19||철원군청.xls|1116556471.03856|13824"
					$b_files_tmp = array();
					//$b_file_size = 0;
					if ($_POST['board_upload_type'] == '1')
					{
						if ($_POST['b_files'])
						{
							$b_files_new = '';
							$_ex = explode("||", stripslashes($_POST['b_files']));
							for ($i=0; $i<sizeof($_ex); $i++)
							{
								if ($_ex[$i])
								{
									$_ex2 = explode("|", $_ex[$i]);
									if (dir_parent_limit($_ex2[1]))
										msg("상위 디렉토리로는 접근하실 수 없습니다.");

									$_file = $UPLOAD_ROOT_NEW.'/'.$UPLOAD_DIR[BIGFILE_TMP].'/'.$_ex2[1];
									if (file_exists($_file))
									{
										$_ex2[0] = basename_fix($_ex2[0]);

										$b_files_tmp['file'][] = $_file;
										$b_files_tmp['file_name'][] = $_ex2[0];
										$fs = filesize($_file);
										$b_files_tmp['file_size'][] = $fs;
										// [2009-06-09] 수정시 첨부용량이 제대로 갱신되지 않는 오류 수정
										//$b_file_size += $fs;
										$board['b_file_size'] += $fs;

										if ($b_files_new != '')
											$b_files_new .= '||';
										$b_files_new .= $_ex2[0].'|'.$_ex2[1].'|'.$fs;
									}	// if()
								}	// if()
							}	// for()
							$_POST['b_files'] = addslashes($b_files_new);
						}	// if()
						$is_upload = false;
					} else
					{
						// [2008-04-15] 업로드 에러 메세지를 정확히 표시함
						include_once("include/file.php");
						if ($_FILES['file']['error'] == UPLOAD_ERR_NO_FILE)
						{
							$is_upload = false;
						} else
						{
							// [2008-05-30] 파일 첨부를 사용하지 않을 때 글쓰기시 post_max_size 관련 에러 방지
							if ($ba['ba_isuse_file'] == 'Y')
							{
								$errorMsg = file_upload_error_msg($_FILES['file'], $_FILES['file']['size'], $UPLOAD_MAX_SIZE);
								if ($errorMsg != '')
								{
									$errorMsg = "\\n\\n파일 첨부가 실패하였습니다.\\n\\n원인 : ".$errorMsg;
									$is_upload = false;
								} else
								{
									// 업로드 되었을때 새 파일이름을 저장하고, 기존 파일 유지시 기존 파일이름 저장.
										$b_file = $_FILES[file][name];
										$b_file_size = $_FILES[file][size];
										//$q_set .= " b_file = '".$_FILES[file][name]."', b_file_size = '".$_FILES[file][size]."', ";
										$board['b_file'] = $_FILES[file][name];
										$board['b_file_size'] = $_FILES[file][size];

										// [2006-07-20] 사용량 체크
										$fsize = get_board_size_sum($G['DINFO']['d_no'], $G['DINFO']['d_quota_board']);
										if (	($fsize['sum_b'] + $_FILES[file][size] - $board['b_file_size']) > $fsize['quota_b'])
											msg("[게시판 첨부 할당량]을 초과하여 파일첨부가 불가능합니다.\\n\\n서버관리자에게 문의하여 주시기 바랍니다.");
									$is_upload = true;
								}	// if()
							} else 
							{
								$is_upload = false;								
							}	// if()
						}	// if()
					}	// if()

					if ($_POST['b_files'])
					{
						if ($board['b_files'] != '')
							$board['b_files'] .= '||';
						$board['b_files'] .= $_POST['b_files'];
					}	// if()

					if ((!$board['b_file'] && !$board['b_files']) || $board['b_file_size'] < 0)
						$board['b_file_size'] = 0;

					$q_set .= " b_file = '".addslashes($board['b_file'])."', b_files = '".addslashes($board['b_files'])."', b_file_size = '".$board['b_file_size']."', ";

					$b_last_modifyhost = $_SERVER["REMOTE_ADDR"];

					if ($bca_no) $q_set .= " bca_no = '$bca_no', ";
					if ($b_link) $q_set .= " b_link = '$b_link', ";
					if ($b_isuse_reply_mail) $q_set .= " b_isuse_reply_mail = '$b_isuse_reply_mail', ";
					// [2007-01-29] 불필요하게 중복되는 쿼리 삭제.
					//if ($b_link) $q_set .= " b_link = '$b_link', ";

			// proc
				// update
					$now = date('Y-m-d H:i:s');
					$q = "
						UPDATE
							$TB[BOARD]
						SET
							$q_set
							b_subject='$b_subject',
							b_html='$b_html',
							b_memo='$b_memo',
							b_last_modifydate='$now',
							b_last_modifyhost='".$_SERVER["REMOTE_ADDR"]."'
						WHERE
							b_no='$b_no' AND
							ba_no='$ba_no'";
					//echo "<HR>" . $q;
					db_query($q);

				// [2008-06-10] ActiveX 파일 첨부 - 디비 저장 성공후 실제 디렉토리로 이동
				for ($i=0; $i<sizeof($b_files_tmp['file']); $i++)
				{
					$filename = basename_fix($b_files_tmp['file'][$i]);
					$errorMsg .= file_move($filename, '', $UPLOAD_DIR[BIGFILE_TMP], $filename, $b_no, $upload_new_dir);
				}	// for()

				// [2008-04-15] 업로드 에러 메세지를 정확히 표시함
				if ($is_upload)
				{
					// old file delete
						if ( is_uploaded_file($_FILES['file']['tmp_name']) )
						{
							$errorMsg .= file_del($board['b_file_ori'], $b_no, $upload_dir);		// 새파일이 업로드되었을때 기존파일 삭제
						}	// if()

					// file upload
						if($_FILES['file'][name])
						{
							// [2006-07-28] 업로드 파일 용량 체크 변경.
							#$errorMsg .= file_up($file, $_FILES[file][name], $_FILES[file][size], $upload_dir, $b_no, "ALL");
							$errorMsg .= file_up_new('file', $_FILES['file']['name'], $b_no, $upload_dir, $UPLOAD_MAX_SIZE);
						}	// if()
				}	// if()

				// [2010-12-23] 임시보관 추가
				if ($_POST['draft_bd_no'] > 0)
					board_draft_del($AUTH['auth_m_no'], $_POST['draft_bd_no']);

			// view
				if ($errorMsg)
					msg("수정되었습니다." . $errorMsg, 0);
				movepage("board.php?mode=READ&" . $b_qs["DEFAULT"]);

			break;


###############################################################################


		case "DEL_OK":

			if (is_array($chk_b_no)) $b_no = $chk_b_no;
			if (!is_array($b_no)) $b_no = (array)$b_no;

			$errorMsg = NULL;

			// sort - 답글일 경우 마지막에 달린 글이 가장 뒤에 오도록 조취함.
				if (sizeof($b_no) > 1)
				{
					rsort($b_no, SORT_NUMERIC);
					reset($b_no);
				}	// if()

			for ($i=0; $i<sizeof($b_no); $i++)
			{
				$board = board_info($ba_no, $b_no[$i]);		// array

				board_reply_del_limit($ba_no, $b_no[$i], $board[b_re_level]);

				// auth
					// 회원이 작성한글은 회원만 삭제가능.
					if($board[m_no] > 0) auth_limit("user");

					$board[is_member] = board_is_member($board[m_no], $ba[ba_perm_modify]);		// modify = del

					if($board[is_member] == true)		// 회원폼에서는 자신의 글일때만 삭제가능.  (관리자제외)
					{
						if ($board[m_no] != $AUTH[auth_m_no]) auth_limit($ba[ba_perm_modify]);
					}else		// 회원폼이 아닐때는 비밀번호가 일치할때만 삭제가능.
					{
						if (strcmp($board[b_pwd], pwd_enc($b_pwd))) msg("비밀번호가 일치하지 않습니다.");
					}	// if()


				// proc
					// board delete
						$q = "DELETE FROM $TB[BOARD] WHERE b_no='$b_no[$i]' AND ba_no='$ba_no'";
						//echo "<HR>" . $q;
						db_query($q);


					// board comment delete
						$q = "DELETE FROM $TB[BOARD_COMMENT] WHERE b_no='$b_no[$i]' AND ba_no='$ba_no'";
						//echo "<HR>" . $q;
						db_query($q);


					// [2010-12-22] 조회기록 추가
						$q = "DELETE FROM $TB[BOARD_READ_LOG] WHERE b_no='$b_no[$i]' AND ba_no='$ba_no'";
						//echo "<HR>" . $q;
						db_query($q);


					// file delete
						include_once("include/file.php");

						if ($board[b_file] == true)
						{
							$errorMsg .= file_del($board[b_file], $b_no[$i], $upload_dir);
						}	// if()

						// [2008-06-10] ActiveX 파일 첨부
						if ($board['b_files'])
						{
							$_ex = explode("||", stripslashes($board['b_files']));
							for ($j=0; $j<sizeof($_ex); $j++)
							{
								if ($_ex[$j])
								{
									$_ex2 = explode("|", $_ex[$j]);
									$errorMsg .= file_del($_ex2[1], $b_no[$i], $upload_new_dir);
								}	// if()
							}	// for()
						}	// if()

			}	// for()


			// view
				msg("삭제되었습니다." . $errorMsg, 0);
				movepage("board.php?mode=LIST&" . $b_qs["LIST"]);

			break;


###############################################################################


		// [2010-12-22] 재게시 추가
		case "REWRITE_OK":

			if($ba[ba_isuse_rewrite] != "Y") msg("재게시기능을 사용할 수 없도록 설정되었습니다.");

			auth_limit($ba[ba_perm_rewrite]);

			// 재게시 - 기존 게시물의 제목,본문, 첨부파일을 가져와서 새 글을 등록함.  따라서 읽기/다운/쓰기 권한 검사 필요.
			auth_limit($ba[ba_perm_read]);
			auth_limit($ba[ba_perm_down]);
			auth_limit($ba[ba_perm_register]);

			// check - mbronly
				if ($ba[ba_mbronly_register]) limit_mbronly($ba[ba_mbronly_register], "글쓰기권한이 없습니다.");


			include_once("include/file.php");

			// check
				if($b_subject == '') msg("올바른 URL로 접근하여 주십시오");

			board_loop_limit($b_subject);

			$errorMsg = '';

			// 기존 게시물에 첨부파일이 있을 경우
			if ($_POST['b_files_old'] != '')
			{
				$b_files_old_new = '';
				$_ex = explode("||", stripslashes($_POST['b_files_old']));
				for ($i=0; $i<sizeof($_ex); $i++)
				{
					if ($_ex[$i])
					{
						$_ex2 = explode("|", $_ex[$i]);
						if (dir_parent_limit($_ex2[1]))
							msg("상위 디렉토리로는 접근하실 수 없습니다.");

						// $_file = $UPLOAD_ROOT_NEW.'/'.$UPLOAD_DIR[BIGFILE_TMP].'/'.$_ex2[1].'.'.$ba_no.'.'.$b_no;
						$_file = $UPLOAD_ROOT_NEW.'/'.$UPLOAD_DIR[BIGFILE_TMP].'/'.$_ex2[1];
						if (file_exists($_file))
						{
							$_is_add = true;
							if (is_array($_POST['b_files_del']) && in_array($_ex2[1], $_POST['b_files_del']))		// 삭제에 체크한 경우 제외시킴.
							{
								// [2011-01-17]
								//$errorMsg .= file_del($_ex2[1].'.'.$ba_no, $b_no, $UPLOAD_DIR[BIGFILE_TMP]);
								$errorMsg .= file_del($_ex2[1], '', $UPLOAD_DIR[BIGFILE_TMP]);
								$_is_add = false;
							}	// if()

							if ($_is_add)
							{
								if ($b_files_old_new != '')
									$b_files_old_new .= "||";
								//$b_files_old_new .= $_ex2[0].'|'.$_ex2[1].'.'.$ba_no.'.'.$b_no.'|'.$_ex2[2];
								$b_files_old_new .= $_ex2[0].'|'.$_ex2[1].'|'.$_ex2[2];
							}	// if()
						}	// if()
					}	// if()
				}	// for()

				if ($_POST['b_files'] != '')
				{
					$_POST['b_files'] = addslashes($b_files_old_new)."||".$_POST['b_files'];
				} else
				{
					$_POST['b_files'] = addslashes($b_files_old_new);
				}	// if()
			}	// if()


			// set
				// query
					to_db_str(&$b_name, 20, "STRIP_TAGS");
					to_db_str(&$b_pwd, 32, false);
					to_db_str(&$b_email, 255, "STRIP_TAGS");
					to_db_str(&$b_homepage, 255, "STRIP_TAGS");
					to_db_str(&$b_subject, 255);
					if ($G_SYS[DB] == 'oracle')
					{
						to_db_str(&$b_memo, $G_SYS['DB_TEXT'], false);
					} else
					{
						to_db_str(&$b_memo, $G_SYS['DB_MEDIUMTEXT'], false);
					}	// if()
					to_db_str(&$b_link, 255, "STRIP_TAGS");
					to_db_str(&$b_file, 255);


				// data
					$ba_no;

					if ($AUTH[auth_m_id])
					{
						$m_no = $AUTH[auth_m_no];
						$b_name = $AUTH[auth_m_name];
						$b_pwd = NULL;
						$b_email = $AUTH[auth_m_email];
						$b_homepage = $AUTH[auth_m_homepage];
						$q_b_pwd = " '$b_pwd' ";
					}else
					{
						$m_no = 0;
						$q_b_pwd = " '" . pwd_enc($b_pwd) . "' ";
					}	// if()

					if (trim($b_homepage) == "http://" ) $b_homepage = "";
					if (trim($b_link) == "http://" ) $b_link = "";


					// [2008-06-10] ActiveX 파일 첨부
					// sample) ["b_files"]=> string(74) "||사본 - test.php|1116556464.14663|19||철원군청.xls|1116556471.03856|13824"
					$b_files_tmp = array();
					$b_file_size = 0;
					if ($_POST['board_upload_type'] == '1')
					{
						if ($_POST['b_files'])
						{
							$b_files_new = '';
							$_ex = explode("||", stripslashes($_POST['b_files']));
							for ($i=0; $i<sizeof($_ex); $i++)
							{
								if ($_ex[$i])
								{
									$_ex2 = explode("|", $_ex[$i]);
									if (dir_parent_limit($_ex2[1]))
										msg("상위 디렉토리로는 접근하실 수 없습니다.");

									$_file = $UPLOAD_ROOT_NEW.'/'.$UPLOAD_DIR[BIGFILE_TMP].'/'.$_ex2[1];
									if (file_exists($_file))
									{
										$_ex2[0] = basename_fix($_ex2[0]);
										$b_files_tmp['file'][] = $_file;
										$b_files_tmp['file_name'][] = $_ex2[0];
										$fs = filesize($_file);
										$b_files_tmp['file_size'][] = $fs;
										$b_file_size += $fs;

										if ($b_files_new != '')
											$b_files_new .= '||';
										$b_files_new .= $_ex2[0].'|'.$_ex2[1].'|'.$fs;
									}	// if()
								}	// if()
							}	// for()
							$_POST['b_files'] = addslashes($b_files_new);
						}	// if()
						$is_upload = false;
						$b_file = '';
						//$b_file_size;
						$b_files = $_POST['b_files'];
					} else
					{
						// [2008-04-15] 업로드 에러 메세지를 정확히 표시함
						if ($_FILES['file']['error'] == UPLOAD_ERR_NO_FILE)
						{
							$is_upload = false;
						} else
						{
							// [2008-05-30] 파일 첨부를 사용하지 않을 때 글쓰기시 post_max_size 관련 에러 방지
							if ($ba['ba_isuse_file'] == 'Y')
							{
								$errorMsg = file_upload_error_msg($_FILES['file'], $_FILES['file']['size'], $UPLOAD_MAX_SIZE);
								if ($errorMsg != '')
								{
									$errorMsg = "\\n\\n파일 첨부가 실패하였습니다.\\n\\n원인 : ".$errorMsg;
									$is_upload = false;
								} else
								{
									// 업로드되었을때만 파일이름을 DB에 저장함.
										$b_file = $_FILES[file][name];
										$b_file_size = $_FILES[file][size];

										// [2006-07-20] 사용량 체크
										$fsize = get_board_size_sum($G['DINFO']['d_no'], $G['DINFO']['d_quota_board']);
										if (	($fsize['sum_b'] + $_FILES[file][size]) > $fsize['quota_b'])
											msg("[게시판 첨부 할당량]을 초과하여 파일첨부가 불가능합니다.\\n\\n서버관리자에게 문의하여 주시기 바랍니다.");
									$is_upload = true;
								}	// if()
							} else 
							{
								$is_upload = false;								
							}	// if()
						}	// if()

						if (!$is_upload)
						{
							$b_file = '';
							$b_file_size = 0;
						}	// if()
						$b_files = '';
					}	// if()


				// default
					$b_ref = 0;
					$b_re_step = 0;
					$b_re_level = 0;

					$now = date('Y-m-d H:i:s');
					$b_reghost = $_SERVER["REMOTE_ADDR"];


			// proc
				// insert
					$q = "INSERT INTO $TB[BOARD] (b_no, ba_no, bca_no, m_no, b_name, b_pwd, b_email, b_homepage, b_isuse_reply_mail, b_subject, b_html, b_memo, b_link, b_file, b_files, b_file_size, b_refer, b_down, b_vote, b_comment, b_ref, b_re_step, b_re_level, b_regdate, b_reghost, b_last_modifydate, b_last_modifyhost) VALUES (".db_sqc_next($TB['BOARD']).", '$ba_no', '$bca_no', '$m_no', '$b_name', " . $q_b_pwd . ", '$b_email', '$b_homepage', '$b_isuse_reply_mail', '$b_subject', '$b_html', '$b_memo', '$b_link', '$b_file', '$b_files', '$b_file_size', 0, 0, 0, 0, '$b_ref', '$b_re_step', '$b_re_level', '$now', '$b_reghost', NULL, NULL)";
					//echo "<HR>" . $q;
					db_query($q);


				// update - b_ref
					$curr_b_no = db_sqc_curr($TB['BOARD']);		// 삽입된 데이타 키

					$q = "UPDATE $TB[BOARD] SET b_ref=b_no WHERE b_no='$curr_b_no' AND ba_no='$ba_no'";
					//echo "<HR>" . $q;
					db_query($q);


				// [2008-06-10] ActiveX 파일 첨부 - 디비 저장 성공후 실제 디렉토리로 이동
				for ($i=0; $i<sizeof($b_files_tmp['file']); $i++)
				{
					$filename = basename_fix($b_files_tmp['file'][$i]);
					$errorMsg .= file_move($filename, '', $UPLOAD_DIR[BIGFILE_TMP], $filename, $curr_b_no, $upload_new_dir);
				}	// for()


				// [2008-04-15] 업로드 에러 메세지를 정확히 표시함
				if ($is_upload)
				{
					// file upload
						if($_FILES['file'][name])
						{
							// [2006-07-28] 업로드 파일 용량 체크 변경.
							#$errorMsg = file_up($file, $_FILES['file'][name], $_FILES[file][size], $upload_dir, $curr_b_no, "ALL");
							$errorMsg .= file_up_new('file', $_FILES['file'][name], $curr_b_no, $upload_dir, $UPLOAD_MAX_SIZE);
						}	// if()
				}	// if()


			/*
			$board = board_info($ba_no, $b_no);		// array

			if ($ba[is_admin] == false && $board[m_no] != $AUTH[auth_m_no])
				msg("현재 게시물에 대한 재게시 권한이 없습니다.");

			// 답변 글은 제한함.
				if ($board[b_re_step] > 0)
					msg("답변 게시물은 재게시할 수 없습니다.");

			// 신규 게시물 등록

				// 게시물
					// insert
						$now = date('Y-m-d H:i:s');
						$b_reghost = $_SERVER["REMOTE_ADDR"];

						$_board = array();
						foreach ($board as $key=>$val)
						{
							$_board[$key] = addslashes($val);
						}	// foreach()

						$q = "INSERT INTO $TB[BOARD] (b_no, ba_no, bca_no, m_no, b_name, b_pwd, b_email, b_homepage, b_isuse_reply_mail, b_subject, b_html, b_memo, b_link, b_file, b_files, b_file_size, b_refer, b_down, b_vote, b_comment, b_ref, b_re_step, b_re_level, b_regdate, b_reghost, b_last_modifydate, b_last_modifyhost) VALUES (".db_sqc_next($TB['BOARD']).", '$_board[ba_no]', '$_board[bca_no]', '$_board[m_no]', '$_board[b_name]', '$_board[b_pwd]', '$_board[b_email]', '$_board[b_homepage]', '$_board[b_isuse_reply_mail]', '$_board[b_subject]', '$_board[b_html]', '$_board[b_memo]', '$_board[b_link]', '$_board[b_file]', '$_board[b_files]', '$_board[b_file_size]', 0, 0, 0, 0, 0, 0, 0, '$now', '$b_reghost', NULL, NULL)";
						//echo "<HR>" . $q;
						db_query($q);


					// update - b_ref
						$curr_b_no = db_sqc_curr($TB['BOARD']);		// 삽입된 데이타 키

						$q = "UPDATE $TB[BOARD] SET b_ref=b_no WHERE b_no='$curr_b_no' AND ba_no='$ba_no'";
						//echo "<HR>" . $q;
						db_query($q);


					// 자식글들의 부모글 번호를 갱신함.
						$q = "UPDATE $TB[BOARD] SET b_ref='".$curr_b_no."' WHERE b_ref='".$b_no."' AND b_re_step != 0 AND ba_no='$ba_no'";
						//echo "<HR>" . $q;
						db_query($q);


				// 첨부파일
				include_once("include/file.php");

				if ($board[b_file] == true)
				{
					$errorMsg .= file_move($board[b_file], $board[b_no], $upload_dir, $board[b_file], $curr_b_no, $upload_dir);
				}	// if()

				// [2008-06-10] ActiveX 파일 첨부
				if ($board['b_files'])
				{
					$_ex = explode("||", stripslashes($board['b_files']));
					for ($k=0; $k<sizeof($_ex); $k++)
					{
						if ($_ex[$k])
						{
							$_ex2 = explode("|", $_ex[$k]);
							$errorMsg .= file_move($_ex2[1], $board[b_no], $upload_new_dir, $_ex2[1], $curr_b_no, $upload_new_dir);
						}	// if()
					}	// for()
				}	// if()

			// 기존 게시물 삭제
				// board delete
					$q = "DELETE FROM $TB[BOARD] WHERE b_no='$b_no' AND ba_no='$ba_no'";
					//echo "<HR>" . $q;
					db_query($q);


				// board comment delete
					$q = "DELETE FROM $TB[BOARD_COMMENT] WHERE b_no='$b_no' AND ba_no='$ba_no'";
					//echo "<HR>" . $q;
					db_query($q);


				// [2010-12-22] 조회기록 추가
					$q = "DELETE FROM $TB[BOARD_READ_LOG] WHERE b_no='$b_no' AND ba_no='$ba_no'";
					//echo "<HR>" . $q;
					db_query($q);


				// file delete
					// skip - already move
				*/


			// view
				msg("재게시되었습니다." . $errorMsg, 0);
				movepage("board.php?mode=LIST&" . $b_qs["REGISTER"]);

			break;

###############################################################################


		case "MOVE_OK":

			auth_limit("admin");


			// check
				if (!$target_ba_no) msg("올바른 URL로 접근하여 주시기 바랍니다.");


			// get
				$target_ba = board_admin_info($target_ba_no);		// array
				$target_upload_dir = $UPLOAD_DIR[BOARD] . "/" . $target_ba_no;		// ex) BOARD/1 => /xxxx/upload/BOARD/1/
				$target_upload_new_dir = $UPLOAD_DIR[BOARD_NEW] . "/" . $target_ba_no;		// ex) BOARD/1 => /xxxx/upload/BOARD/1/


			if (is_array($chk_b_no)) $b_no = $chk_b_no;
			if (!is_array($b_no)) $b_no = (array)$b_no;
			$errorMsg = NULL;

			// sort - 답글일 경우 마지막에 달린 글이 가장 뒤에 오도록 조취함.
				if (sizeof($b_no) > 1)
				{
					rsort($b_no, SORT_NUMERIC);
					reset($b_no);
				}	// if()

			for ($i=0; $i<sizeof($b_no); $i++)
			{
				$board = board_info($ba_no, $b_no[$i], "N");		// array

				// reply check
					$q = "SELECT b_no, b_file, b_files FROM $TB[BOARD] WHERE b_ref='$board[b_ref]' AND ba_no='$ba_no'";
					//echo "<HR>" . $q;
					$board_reply = db_get_rows($q, true);


					$board_reply_cnt = sizeof($board_reply[b_no]);

					for ($j=0; $j<$board_reply_cnt; $j++)
					{
						// proc
							// board update
								$q = "
									UPDATE
										$TB[BOARD]
									SET
										ba_no='$target_ba_no'
									WHERE
										b_no='" . $board_reply[b_no][$j] . "' AND
										ba_no='$ba_no'
									";
								//echo "<HR>" . $q;
								db_query($q);



							// board comment update
								$q = "
									UPDATE
										$TB[BOARD_COMMENT]
									SET
										ba_no='$target_ba_no'
									WHERE
										b_no='" . $board_reply[b_no][$j] . "' AND
										ba_no='$ba_no'
									";
								//echo "<HR>" . $q;
								db_query($q);

							// [2010-12-22] 조회기록 추가
								$q = "
									UPDATE
										$TB[BOARD_READ_LOG]
									SET
										ba_no='$target_ba_no'
									WHERE
										b_no='" . $board_reply[b_no][$j] . "' AND
										ba_no='$ba_no'
									";
								//echo "<HR>" . $q;
								db_query($q);


							// file move
								include_once("include/file.php");

								if ($board_reply[b_file][$j] == true)
								{
									$errorMsg .= file_move($board_reply[b_file][$j], $board_reply[b_no][$j], $upload_dir, $board_reply[b_file][$j], $board_reply[b_no][$j], $target_upload_dir);
								}	// if()

								// [2008-06-10] ActiveX 파일 첨부
								if ($board_reply['b_files'][$j])
								{
									$_ex = explode("||", stripslashes($board_reply['b_files'][$j]));
									for ($k=0; $k<sizeof($_ex); $k++)
									{
										if ($_ex[$k])
										{
											$_ex2 = explode("|", $_ex[$k]);
											$errorMsg .= file_move($_ex2[1], $board_reply[b_no][$j], $upload_new_dir, $_ex2[1], $board_reply[b_no][$j], $target_upload_new_dir);
										}	// if()
									}	// for()
								}	// if()
					}	// for()

			}	// for()


			// view
				msg("이동되었습니다." . $errorMsg, 0);
				movepage("board.php?mode=LIST&" . $b_qs["LIST"]);

			break;


###############################################################################


		case "CMT_REGISTER_OK":

			auth_limit($ba[ba_perm_cmt_register]);

			// check
				if (!$bc_memo) msg("올바른 URL로 접근하여 주십시오");
				if (!$AUTH[auth_m_id])
				{
					if  ((!$bc_name)||(!$bc_pwd)) msg("글입력시간이 길어져서 자동로그아웃된 경우에는\\n\\n다시 로그인하셔서 글을 작성하셔야합니다.\\n\\n추가 페이지를 [새로고침]해보십시오.");
				}	// if()


			// set
				// query
					to_db_str(&$bc_name, 20, "STRIP_TAGS");
					to_db_str(&$bc_pwd, 20);
					to_db_str(&$bc_memo, $G_SYS['DB_TEXT']);

				// data
					if ($AUTH[auth_m_id])
					{
						$m_no = $AUTH[auth_m_no];
						$bc_name = $AUTH[auth_m_name];
						$bc_pwd = $AUTH[auth_m_pwd];
						$q_bc_pwd = " '$bc_pwd' ";
					}else
					{
						$m_no = 0;
						// [2010-06-09]
						//$q_bc_pwd = " '$" . pwd_enc($bc_pwd) . "' ";
						$q_bc_pwd = " '" . pwd_enc($bc_pwd) . "' ";
					}	// if()

					$now = date('Y-m-d H:i:s');
					$bc_reghost = $_SERVER["REMOTE_ADDR"];


			// proc
				// insert
					$q = "INSERT INTO $TB[BOARD_COMMENT] (bc_no, ba_no, b_no, m_no, bc_name, bc_pwd, bc_memo, bc_regdate, bc_reghost) VALUES (".db_sqc_next($TB['BOARD_COMMENT']).", '$ba_no', '$b_no', '$m_no', '$bc_name', $q_bc_pwd, '$bc_memo', '$now', '$bc_reghost')";
					//echo "<HR>" . $q;
					db_query($q);


				board_comment_update($ba_no, $b_no);


			// view
				//msg("덧말이 추가되었습니다.", 0);
				movepage("board.php?mode=READ&" . $b_qs["DEFAULT"]);

			break;


###############################################################################


		case "CMT_DEL_OK":

			$bc = board_comment_info($ba_no, $b_no, $bc_no);		// array

			// auth
				// 회원이 작성한글은 회원만 삭제가능.
				if($bc[m_no] > 0) auth_limit("user");

				$bc[is_member] = board_is_member($bc[m_no], $ba[ba_perm_cmt_del]);		// del

				if($bc[is_member] == true)		// 회원폼에서는 자신의 글일때만 삭제가능.  (관리자제외)
				{
					if ($bc[m_no] != $AUTH[auth_m_no]) auth_limit($ba[ba_perm_modify]);
				}else		// 회원폼이 아닐때는 비밀번호가 일치할때만 삭제가능.
				{
					if (strcmp($bc[bc_pwd], pwd_enc($bc_pwd))) msg("비밀번호가 일치하지 않습니다.");
				}	// if()


			// proc
				// delete
					$q = "DELETE FROM $TB[BOARD_COMMENT] WHERE bc_no='$bc_no' AND b_no='$b_no' AND ba_no='$ba_no'";
					//echo "<HR>" . $q;
					db_query($q);


				board_comment_update($ba_no, $b_no);


			// view
				msg("덧말이 삭제되었습니다.", 0);
				movepage("board.php?mode=READ&" . $b_qs["DEFAULT"]);

			break;


###############################################################################


		case "ADMIN_LIST":

			auth_limit("admin");

			$CFG[TITLE] = $CFG[TITLE];

			// search
				$q_where = '';
				if ($s_word == true)		// search mode
				{
					set_q_search($s_word);

					$q_where .= " AND ba." . $s_kind . " like '%" . $s_word . "%' ";
					$null_msg = "검색된 게시판이 없습니다.";
					$count_msg = "검색된 게시판";
				}else		// normal mode
				{
					$null_msg = "등록된 게시판이 없습니다.";
					$count_msg = "등록된 게시판";
				}	// if()

				if (is_numeric($_GET['s_bm_no']))
					$q_where .= " AND ba.bm_no='".$_GET['s_bm_no']."' ";


			// paging
				include_once("include/page.php");

				$q_count = "SELECT count(*) FROM $TB[BOARD_ADMIN] ba WHERE ba.d_no='" . $AUTH['auth_d_no'] ."' $q_where";
				$strTrans = "&mode=$mode&" . $b_qs["ADMIN_PAGE"];
				disPgProc($q_count, 50, $strTrans, "DESC");


			// get
				$q = "SELECT ba.*, bm.bm_name FROM $TB[BOARD_ADMIN] ba, $TB[BOARD_MENU] bm WHERE ba.d_no='" . $AUTH['auth_d_no'] ."' $q_where AND ba.bm_no=bm.bm_no ORDER BY bm.bm_sort, bm.bm_name, ba.ba_sort, ba.ba_name";
				//echo $q;
				$ba_list = db_get_rows($q, $limitOffset, $limitRows);

				if($ba_list)
				{
					for($i=0; $i<sizeof($ba_list); $i++)
					{
						$ba_list[$i][i] = $i;
						//$ba_list[$i][v_ba_no] = $pageMaxNo - $i;
						$ba_list[$i][v_ba_no] = $ba_list[$i][ba_no];
						$ba_list[$i][v_ba_name] = "<a href='".$nmpath."/board.php?mode=LIST&ba_no=" . $ba_list[$i][ba_no] . "'>" . text_view(han_substr($ba_list[$i][ba_name], $subject_maxlength)) . "</a>";
						$ba_list[$i][v_ba_regdate] = substr($ba_list[$i][ba_regdate], 0, 10);
						$ba_list[$i][v_ba_last_modifydate] = substr($ba_list[$i][ba_last_modifydate], 0, 10);


						// [2008-03-19] 사용그룹제한 추가
						if ($ba_list[$i]['ba_mg_no'] != '')
						{
							$q = "SELECT mg_name FROM ".$TB['MEMBER_GROUP']." WHERE d_no='".$G['DINFO']['d_no']."' AND mg_no IN (".implode(',', db_str_explode('|', $ba_list[$i]['ba_mg_no'])).") ORDER BY mg_name";
							$mg = db_get_rows($q, true);
							$ba_list[$i]['ba_mg_no'] = @implode(',', $mg['mg_name']);
						}	// if()
						if ($ba_list[$i]['ba_use_id'] != '')
							$ba_list[$i]['ba_use_id'] = implode(',', db_str_explode('|', $ba_list[$i]['ba_use_id']));
					}	// for()
				}	// if()


			// [2011-01-05] 메뉴관리
				$q = "SELECT bm_no, bm_name FROM ".$TB['BOARD_MENU']." WHERE d_no='" . $AUTH['auth_d_no'] ."' ORDER BY bm_sort, bm_name";
				$_bm = db_get_rows($q, true);
				if (!$_bm)
				{
					msg("게시판이 보여질 메뉴를 먼저 만들어 주십시오.", 0);
					movepage("admin_board_menu.php?bm_name=".urlencode("게시판"));					
				}	// if()
				$select_board_menu = select_list_value ($_GET['s_bm_no'], $_bm['bm_name'], $_bm['bm_no'], '전체 메뉴', 0, 1);



			// view


				// search
				$v_s_kind = select_list_value($s_kind, array_values($G_BOARD[S_KIND_ADMIN]), array_keys($G_BOARD[S_KIND_ADMIN]), NULL, 0, 1);
				$v_s_word = input_value($s_word,1);
				$v_rowCount = number_format($rowCount);

				// body
				$page_view = disPgCount($whlPgCount, $reqPage, $strTrans, 3, 1);
			// skin view
				nskinset('sadmin', 'admin_board_list.html');
				include($NSKIN['view_layout']);

			break;



###############################################################################


		case "ADMIN_REGISTER":

			auth_limit("admin");

			$CFG[TITLE] = $CFG[TITLE] . " >> <b>추가</b>";

			//$board = board_info($ba_no, $b_no);		// array


			// default
				$ba_form[bm_no] = $_GET['s_bm_no'];
				$ba_form[ba_name] = NULL;

				// 마지막 출력순서
				$q_where = "";
				if (is_numeric($_GET['s_bm_no']))
					$q_where .= " AND bm_no='".$_GET['s_bm_no']."' ";
				$q = "SELECT MAX(ba_sort) FROM ".$TB['BOARD_ADMIN']." WHERE d_no='" . $AUTH['auth_d_no'] . "'".$q_where;
				$ba_form[ba_sort] = db_get_one($q)+1;

				$ba_form[ba_isuse_link] = "Y";		//  Y, N
				$ba_form[ba_isuse_file] = "N";		//  Y, N
				$ba_form[ba_isuse_comment] = "Y";		//  Y, N
				$ba_form[ba_isuse_reply] = "Y";		//  Y, N
				$ba_form[ba_isuse_rewrite] = "Y";		//  Y, N
				$ba_form[ba_isuse_read_log] = "Y";		//  Y, N
				$ba_form[ba_page] = 20;
				$ba_form[ba_header_html] = "N";
				$ba_form[ba_header] = NULL;
				$ba_form[ba_footer_html] = "N";
				$ba_form[ba_footer] = NULL;
				$ba_form[ba_inc_header] = "../main/header.inc.html";
				$ba_form[ba_inc_footer] = "../main/footer.inc.html";
				$ba_form[ba_perm_access] = $G['LEVEL']['user'];
				$ba_form[ba_perm_register] = $G['LEVEL']['user'];
				$ba_form[ba_perm_reply] = $G['LEVEL']['user'];
				$ba_form[ba_perm_rewrite] = $G['LEVEL']['user'];
				$ba_form[ba_perm_read_log] = $G['LEVEL']['user'];
				$ba_form[ba_perm_read] = $G['LEVEL']['user'];
				$ba_form[ba_perm_down] = $G['LEVEL']['user'];
				$ba_form[ba_perm_modify] = $G['LEVEL']['admin'];
				$ba_form[ba_perm_cmt_register] = $G['LEVEL']['user'];
				$ba_form[ba_perm_cmt_read] = $G['LEVEL']['user'];
				$ba_form[ba_perm_cmt_del] = $G['LEVEL']['admin'];
				$ba_form[ba_mbronly_register] = NULL;
				$ba_form[ba_mbronly_reply] = NULL;
				$ba_form[ba_regdate] = NULL;
				$ba_form[ba_reghost] = NULL;
				$ba_form[ba_last_modifydate] = NULL;
				$ba_form[ba_last_modifyhost] = NULL;


			// set
				$ba_form = set_admin_form($ba_form);


			// view
				$mode_proc = "ADMIN_REGISTER_OK";
				$mode_name = "추가";
				$back_url = urlencode($_SERVER[REQUEST_URI]);



				// body
				$v_back_url = input_value($back_url,1);

				nskinset('sadmin', 'admin_board_form.html');
				include($NSKIN['view_layout']);

			break;



###############################################################################


		case "ADMIN_REGISTER_OK":

			auth_limit("admin");

			// check
				if(!$ba_name) msg("올바른 URL로 접근하여 주십시오");

			// set
				// query
					to_db_str(&$ba_name, 255, "STRIP_TAGS");
					to_db_str(&$ba_page, 2);
					// [2007-04-26] HTML 태그가 제대로 보이지 않던 문제 수정.
					//to_db_str(&$ba_header, $G_SYS['DB_TEXT']);
					//to_db_str(&$ba_footer, $G_SYS['DB_TEXT']);
					to_db_str(&$ba_header, $G_SYS['DB_TEXT'], false);
					to_db_str(&$ba_footer, $G_SYS['DB_TEXT'], false);
					to_db_str(&$ba_inc_header, 255, "STRIP_TAGS");
					to_db_str(&$ba_inc_footer, 255, "STRIP_TAGS");
					to_db_str(&$ba_mbronly_register, $G_SYS['DB_TEXT']);
					to_db_str(&$ba_mbronly_reply, $G_SYS['DB_TEXT']);


				// mbronly
					$error_msg = NULL;

					$mo1 = set_ba_mbronly($ba_mbronly_register);		// array()
					$ba_mbronly_register = $mo1['true'];
					if ($mo1['false']) $error_msg .= "\\n\\n=> 글쓰기가능 아이디중 비회원 : " . $mo1['false'];

					$mo2 = set_ba_mbronly($ba_mbronly_reply);		// array()
					$ba_mbronly_reply = $mo2['true'];
					if ($mo2['false']) $error_msg .= "\\n\\n=> 답변가능 아이디중 비회원 : " . $mo2['false'];


					// [2008-03-19] 사용그룹제한 추가
					to_db_str(&$ba_use_id, $G_SYS['DB_TEXT']);
					$mo3 = set_ba_mbronly($ba_use_id);		// array()
					$ba_use_id = $mo3['true'];
					if ($mo3['false']) $error_msg .= "\\n\\n=> 사용 아이디중 비회원 : " . $mo3['false'];

					// [2008-09-11] 사용그룹제한시 데이타 구조가 변경됨.
					if ($ba_mg_no != '')
						$ba_mg_no = explode(',', $ba_mg_no);
					$ba_mg_no = db_str_implode('|', $ba_mg_no);
					if ($ba_use_id != '')
						$ba_use_id = db_str_implode('|', explode(',', $ba_use_id));


				// default
					$m_no = $AUTH[auth_m_no];
					$now = date('Y-m-d H:i:s');
					$ba_reghost = $_SERVER["REMOTE_ADDR"];

			// proc
				// insert
					$q = "INSERT INTO $TB[BOARD_ADMIN] (ba_no, ba_name, d_no, bm_no, ba_sort, ba_isuse_link, ba_isuse_file, ba_isuse_comment, ba_isuse_reply, ba_isuse_rewrite, ba_isuse_read_log, ba_isuse_category,ba_page, ba_header_html, ba_header, ba_footer_html, ba_footer, ba_inc_header, ba_inc_footer, ba_perm_access, ba_perm_register, ba_perm_reply, ba_perm_rewrite, ba_perm_read_log, ba_perm_read, ba_perm_down, ba_perm_modify, ba_perm_cmt_register, ba_perm_cmt_read, ba_perm_cmt_del, ba_mbronly_register, ba_mbronly_reply, ba_mg_no, ba_use_id, ba_regdate, ba_reghost, ba_last_modifydate, ba_last_modifyhost) VALUES (".db_sqc_next($TB['BOARD_ADMIN']).", '$ba_name', '" . $AUTH['auth_d_no'] . "', '$bm_no', '$ba_sort', '$ba_isuse_link', '$ba_isuse_file', '$ba_isuse_comment', '$ba_isuse_reply', '$ba_isuse_rewrite', '$ba_isuse_read_log', '$ba_isuse_category', '$ba_page', '$ba_header_html', '$ba_header', '$ba_footer_html', '$ba_footer', '$ba_inc_header', '$ba_inc_footer', '$ba_perm_access', '$ba_perm_register', '$ba_perm_reply', '$ba_perm_rewrite', '$ba_perm_read_log', '$ba_perm_read', '$ba_perm_down', '$ba_perm_modify', '$ba_perm_cmt_register', '$ba_perm_cmt_read', '$ba_perm_cmt_del', '$ba_mbronly_register', '$ba_mbronly_reply', '$ba_mg_no', '$ba_use_id', '$now', '$ba_reghost', NULL, NULL)";
					//echo "<HR>" . $q;
					db_query($q);


			// view
				msg("게시판이 " . $mode_name . "되었습니다.", 0);
				movepage("board.php?mode=ADMIN_LIST&" . $b_qs["ADMIN"]);

			break;


###############################################################################


		case "ADMIN_MODIFY":

			auth_limit("admin");

			$CFG[TITLE] = $CFG[TITLE] . " >> <b>수정</b>";

			$ba_form = board_admin_info($ba_no);		// array

			// set
				//if($back_url) $back_url = urldecode($back_url);
				$ba_form = set_admin_form($ba_form);


			// view
				$mode_proc = "ADMIN_MODIFY_OK";
				$mode_name = "수정";



				// body
				$v_back_url = input_value($back_url,1);

				nskinset('sadmin', 'admin_board_form.html');
				include($NSKIN['view_layout']);

			break;


###############################################################################


		case "ADMIN_MODIFY_OK":

			auth_limit("admin");

			$ba = board_admin_info($ba_no);		// array

			// check
				if(!$ba_name) msg("올바른 URL로 접근하여 주십시오");

			// set
				// query
					to_db_str(&$ba_name, 255, "STRIP_TAGS");
					to_db_str(&$ba_page, 2);
					// [2007-04-26] HTML 태그가 제대로 보이지 않던 문제 수정.
					//to_db_str(&$ba_header, $G_SYS['DB_TEXT']);
					//to_db_str(&$ba_footer, $G_SYS['DB_TEXT']);
					to_db_str(&$ba_header, $G_SYS['DB_TEXT'], false);
					to_db_str(&$ba_footer, $G_SYS['DB_TEXT'], false);
					to_db_str(&$ba_inc_header, 255, "STRIP_TAGS");
					to_db_str(&$ba_inc_footer, 255, "STRIP_TAGS");
					to_db_str(&$ba_cm_register, 20);
					to_db_str(&$ba_cm_reply, 20);
					to_db_str(&$ba_mbronly_register, $G_SYS['DB_TEXT']);
					to_db_str(&$ba_mbronly_reply, $G_SYS['DB_TEXT']);


				// default
					$ba_last_modifyhost = $_SERVER["REMOTE_ADDR"];


				// mbronly
					$error_msg = NULL;

					$mo1 = set_ba_mbronly($ba_mbronly_register);		// array()
					$ba_mbronly_register = $mo1['true'];
					if ($mo1['false']) $error_msg .= "\\n\\n=> 글쓰기가능 아이디중 비회원 : " . $mo1['false'];

					$mo2 = set_ba_mbronly($ba_mbronly_reply);		// array()
					$ba_mbronly_reply = $mo2['true'];
					if ($mo2['false']) $error_msg .= "\\n\\n=> 답변가능 아이디중 비회원 : " . $mo2['false'];

					// [2008-03-19] 사용그룹제한 추가
					to_db_str(&$ba_use_id, $G_SYS['DB_TEXT']);
					$mo3 = set_ba_mbronly($ba_use_id);		// array()
					$ba_use_id = $mo3['true'];
					if ($mo3['false']) $error_msg .= "\\n\\n=> 사용 아이디중 비회원 : " . $mo3['false'];

					// [2008-09-11] 사용그룹제한시 데이타 구조가 변경됨.
					if ($ba_mg_no != '')
						$ba_mg_no = explode(',', $ba_mg_no);
					$ba_mg_no = db_str_implode('|', $ba_mg_no);
					if ($ba_use_id != '')
						$ba_use_id = db_str_implode('|', explode(',', $ba_use_id));


			// proc
				// update
					$now = date('Y-m-d H:i:s');
					$q = "UPDATE $TB[BOARD_ADMIN] SET
								ba_name='$ba_name',
								bm_no='$bm_no',
								ba_sort='$ba_sort',
								ba_isuse_link='$ba_isuse_link',
								ba_isuse_file='$ba_isuse_file',
								ba_isuse_comment='$ba_isuse_comment',
								ba_isuse_reply='$ba_isuse_reply',
								ba_isuse_rewrite='$ba_isuse_rewrite',
								ba_isuse_read_log='$ba_isuse_read_log',
								ba_isuse_category='$ba_isuse_category',
								ba_page='$ba_page',
								ba_header_html='$ba_header_html',
								ba_header='$ba_header',
								ba_footer_html='$ba_footer_html',
								ba_footer='$ba_footer',
								ba_inc_header='$ba_inc_header',
								ba_inc_footer='$ba_inc_footer',
								ba_perm_access='$ba_perm_access',
								ba_perm_register='$ba_perm_register',
								ba_perm_reply='$ba_perm_reply',
								ba_perm_rewrite='$ba_perm_rewrite',
								ba_perm_read_log='$ba_perm_read_log',
								ba_perm_read='$ba_perm_read',
								ba_perm_down='$ba_perm_down',
								ba_perm_modify='$ba_perm_modify',
								ba_perm_cmt_register='$ba_perm_cmt_register',
								ba_perm_cmt_read='$ba_perm_cmt_read',
								ba_perm_cmt_del='$ba_perm_cmt_del',
								ba_mbronly_register='$ba_mbronly_register',
								ba_mbronly_reply='$ba_mbronly_reply',
								ba_mg_no='$ba_mg_no',
								ba_use_id='$ba_use_id',
								ba_last_modifydate='$now',
								ba_last_modifyhost='$ba_last_modifyhost'
							WHERE
								ba_no='$ba_no'
								AND d_no='" . $AUTH['auth_d_no'] ."'
							";
					//echo "<HR>" . $q;
					db_query($q);


			// view
				msg("게시판이 " . $mode_name . "되었습니다." . $error_msg, 0);
				if (!$back_url) $back_url = "board.php?mode=ADMIN_LIST&" . $b_qs["ADMIN"];
				movepage($back_url);

			break;


###############################################################################


		case "ADMIN_DEL":

			auth_limit("admin");

			$CFG[TITLE] = $CFG[TITLE] . " >> <b>삭제</b>";

			$ba_form = board_admin_info($ba_no);		// array


			// set
				//if($back_url) $back_url = urldecode($back_url);
				$ba_form = set_admin_form($ba_form);


			// view
				$mode_proc = "ADMIN_DEL_OK";
				$mode_name = "삭제";



				// body
				nskinset('sadmin', 'admin_board_form.html');
				include($NSKIN['view_layout']);

			break;


###############################################################################


		case "ADMIN_DEL_OK":

			auth_limit("admin");

			$ba_form = board_admin_info($ba_no);		// array

			// proc
				// file delete
					include_once("include/file.php");
					dir_del_all($upload_dir, true);

				// delete
					// [2010-12-22] 조회기록 추가
					$q = "DELETE FROM $TB[BOARD_READ_LOG] WHERE ba_no='$ba_no'";
					//echo "<HR>" . $q;
					db_query($q);

					$q = "DELETE FROM $TB[BOARD_COMMENT] WHERE ba_no='$ba_no'";
					//echo "<HR>" . $q;
					db_query($q);


					$q = "DELETE FROM $TB[BOARD] WHERE ba_no='$ba_no'";
					//echo "<HR>" . $q;
					db_query($q);


					$q = "DELETE FROM $TB[BOARD_ADMIN] WHERE ba_no='$ba_no' AND d_no='" . $AUTH['auth_d_no'] . "'";
					//echo "<HR>" . $q;
					db_query($q);



			// view
				msg("게시판이 " . $mode_name . "되었습니다.", 0);
				movepage("board.php?mode=ADMIN_LIST&" . $b_qs["ADMIN"]);

			break;



###############################################################################

# Test

###############################################################################


		case "REPLY_MAIL_PREVIEW":		// 테스트작업용

			auth_limit("admin");

			// set
				$ba = board_admin_info($ba_no);		// array

				$rm = array();
				$rm[board_name] = $ba[ba_name];
				$rm[subject] = "테스트 답변입니다.";
				$rm[memo] = nl2br("내용입니다...\n\n내용입니다...\n\n내용입니다...내용입니다...내용입니다...내용입니다...내용입니다...\n\n");
				$rm[writer] = get_mailto_url($AUTH[auth_m_email], $AUTH[auth_m_name]);
				$rm[regdate] = date("Y-m-d H:i:s");
				$rm[board_list_url] = "board.php?mode=LIST&ba_no=$ba_no";
				$rm[board_read_url] = "board.php?mode=READ&ba_no=$ba_no&b_no=$b_no";


			// view
				nskinset('board', 'reply_mail.html');
				include($NSKIN['view_layout']);

			break;

	}	// switch()


###############################################################################

	unset_db();

?>
