<?php
	 include $_SERVER['DOCUMENT_ROOT'].'/common/lib/comm.php';
	 include $_SERVER['DOCUMENT_ROOT'].ADMIN_PATH.'/common/auth_chk.php';

	if($cd_board == "01"){$mp="50";}else if($cd_board == "02"){$mp="51";}else if($cd_board == "03"){$mp="52";}else{$mp="53";};

	if($cd_board<>"01" && $cd_board <> "03" && $cd_board <> "02" && $cd_board <> "04"){
		AlertRedirect("잘못된 요청입니다.",ADMIN_PATH."/index.php");
	}
	if($cd_seq =="" || $cd_seq ==null){
		AlertRedirect("잘못된 요청입니다.",ADMIN_PATH."/index.php");
	}
	/*조회수 */
	$hitsql="update board_master 
			set 
				no_hit= no_hit+1
			WHERE  cd_seq =$cd_seq";

	$result  = mysql_query($hitsql,$connect);

	$sql ="SELECT 
			cd_seq , cd_board ,cd_user ,cd_userid , nm_title , nm_name, ds_top, ds_main, ds_kind
			,no_hit, ds_open, nm_content, nm_file, nm_updir, nm_reply, dt_insert, ds_delind ,nm_etc1, nm_etc2, nm_etc3, nm_etc4, nm_etc5
		FROM board_master
		WHERE 
			cd_board='$cd_board' AND cd_seq='$cd_seq' AND ds_delind='N'";

	$col=mysql_fetch_array(mysql_query($sql));
		
	if (!empty($col[cd_seq])){ //일반회원
		
		$cd_seq = $col[cd_seq];
		$cd_board = $col[cd_board];
		$cd_user = $col[cd_user];
		$cd_userid = $col[cd_userid];
		$nm_title = $col[nm_title];
		$no_hit = $col[no_hit];
		$ds_open = $col[ds_open];
		$nm_content = $col[nm_content];
		$nm_file = $col[nm_file];
		$nm_updir = $col[nm_updir];
		$nm_reply = $col[nm_reply];
		$dt_insert = $col[dt_insert];
		$ds_delind = $col[ds_delind];
		$ds_top = $col[ds_top];
		$ds_main = $col[ds_main];
		$ds_kind = $col[ds_kind];
		$nm_name = $col[nm_name];
		$nm_etc1 = $col[nm_etc1];
		$nm_etc2 = $col[nm_etc2];
		$nm_etc3 = $col[nm_etc3];
		$nm_etc4 = $col[nm_etc4];
		$nm_etc5 = $col[nm_etc5];

		//if($_SESSION[cd_userid] != $cd_userid){
		//	AlertBack("게시물을 수정할 권한이 없습니다.");
		//}
	
		$mode="Update";

	}else{
		AlertBack("게시물을 가져오지 못하였습니다.");
	}
	$PageNo = $PageNo;
	
	//이전글
	$presql ="SELECT 
				cd_seq , cd_board ,cd_userid , nm_title , 
				no_hit, ds_open, nm_content, nm_file, nm_updir, dt_insert, ds_delind
			FROM board_master
			WHERE 
				cd_board='$cd_board'  AND ds_delind='N'
				AND cd_seq < (SELECT cd_seq FROM board_master WHERE cd_board='$cd_board'  AND ds_delind='N' AND cd_seq = $cd_seq)
			ORDER BY cd_seq DESC LIMIT 1";

	$preCol=mysql_fetch_array(mysql_query($presql));

	//다음글
	$nextSql ="SELECT 
				cd_seq , cd_board ,cd_userid , nm_title , 
				no_hit, ds_open, nm_content, nm_file, nm_updir, dt_insert, ds_delind
			FROM board_master
			WHERE 
				cd_board='$cd_board'  AND ds_delind='N'
				AND cd_seq > (SELECT cd_seq FROM board_master WHERE cd_board='$cd_board'  AND ds_delind='N' AND cd_seq = $cd_seq)
			ORDER BY cd_seq DESC LIMIT 1";

	$nextCol=mysql_fetch_array(mysql_query($nextSql));
?>
<? include("../inc/inc_top.php") ?>
<? include("../inc/inc_header.php") ?>
<script type="text/javascript" src="/common/smarteditor/js/HuskyEZCreator.js" charset="utf-8"></script>

<section id="contents">
  <h2>커뮤니티</h2>
  
    <h3><em>▶</em> 1:1문의</h3>
<form id="frmProc" name="frmProc" method="post">
	<div class="tbl_wrap">
		<table class="tbl_list2">
			<colgroup>
				<col width="7%">
				<col width="32%">
				
				<col width="*">
			</colgroup>
			<tr>
				<th>제목</th>
				<td><?=$nm_title?>&nbsp;[등록일:<?=$dt_insert?> &nbsp;조회수:<?=$no_hit?>]</td>
			</tr>
<? 
	if($cd_board == "02"){
?>
			<tr>
				<th>작성자</th>
				<td><?=$cd_userid?></td>
			</tr>
<? 
	}
?>
<? 
	if($cd_board == "04"){
?>
			<tr>
				<th>문의유형</th>
				<td><?=$nm_etc1?></td>
			</tr>
			<tr>
				<th>이름</th>
				<td><?=$nm_name?></td>
			</tr>
			<tr>
				<th>연락처</th>
				<td><?=$nm_etc2?></td>
			</tr>
			<tr>
				<th>이메일</th>
				<td><?=$nm_etc3?></td>
			</tr>
<? 
	}
?>
			<tr>
				<th>내용</th>
				<td  class="text_height pd"><?=$nm_content?></td>
			</tr>
<? 
	if($cd_board == "01"){
?>
			<tr>
				<th>파일</th>
				<td><? if($nm_file!=""){?><a href="/common/lib/download.php?nm_file=<?=urlencode($nm_file)?>&type=board&cd_board=<?=$cd_board?>"><?=$nm_file?></a><?}else{?>첨부파일없음<?}?></td>
			</tr>
<? 
	}
?>
		</table>
	</div>
  
<? 
if($_SESSION[admin_cd_userid] && $cd_board == "02"){
?>
	<h3><em>▶</em> 답변하기</h3>
	<div class="tbl_wrap">
		<table class="tbl_list2">
			<colgroup>
				<col width="7%">
				<col width="32%">
				
				<col width="*">
			</colgroup>
			<!--tr>
				<th>제목</th>
				<td><input type="text" class="inp_txt" style="width:90%;"></td>
			</tr-->
            <tr>
				<th>작성자</th>
				<td>관리자</td>
			</tr>
			<tr>
				<th>내용</th>
				<td class="pd"><textarea cols="70" rows="10" style="height:230px;" name="nm_reply" id="nm_reply"><?=$nm_reply?></textarea></td>
			</tr>
			
		</table>
	</div>
<? 
}
?>

<div class="btn_right">
<? 
if($_SESSION[admin_cd_userid]){
?>
	<a href="#" class="rnd_btn ty2 gray" onclick="fnList('<?=$cd_board?>');return false;">취소</a>
<? 
	if($cd_board == "02"){
?>
	<a href="#" class="rnd_btn ty2 black" id="btn_write">답변</a>
<? 
	}else if($cd_board == "04"){
?>
<? 
	}else{
?>
	<a href="#" class="rnd_btn ty2 black" id="btn_write" onclick="fnProc('Update');return false;">수정</a>
	<a href="#" class="rnd_btn ty2 black" id="btn_write" onclick="fnProc('Delete');return false;">삭제</a>
<? 
	}
?>
<? 
}
?>
</div>

	<input type="hidden" name="mode" id="mode" value="Update"/>
	<input type="hidden" name="cd_board" id="cd_board" value="<?=$cd_board?>"/>
	<input type="hidden" name="cd_userid" id="cd_userid" value="<?=$cd_userid?>"/>
	<input type="hidden" name="cd_seq" id="cd_seq" value="<?=$cd_seq?>"/>
	<input type="hidden" name="PageNo" id="PageNo" value="<?=$PageNo?>"/>
</form>

<? 
if($_SESSION[admin_cd_userid] && $cd_board == "02"){
?>
<script language="javascript" type="text/javascript">
	$(document).ready(function() {

		$("#btn_write").bind("click",function(){
			oEditors.getById["nm_reply"].exec("UPDATE_CONTENTS_FIELD", []); 
			
			var fieldlist = [["nm_reply","답변"]];

			if (!fnCheckForm(fieldlist)){
				return false;
			}else{
				var c = confirm("처리하시겠습니까?");
				if(c){
					$("#frmProc").attr("action","./board_proc.php");
					$("#mode").val("ReplyInquiry");
					$("#frmProc").submit();
				}else{
					return false;
				}
			}
		});
	});

</script>
<script type="text/javascript">
 var oEditors = [];
	 nhn.husky.EZCreator.createInIFrame({
	oAppRef: oEditors,
	elPlaceHolder: "nm_reply",
	sSkinURI: "/common/smarteditor/SmartEditor2Skin.html",	
	htParams : {
		bUseToolbar : true,				
		bUseVerticalResizer : true,		
		bUseModeChanger : true,			
		fOnBeforeUnload : function(){}
	}, //boolean
	fOnAppLoad : function(){},
	fCreator: "createSEditor2"		

 });	
function pasteHTML(fcode,objKey){
	var sHTML = '<span style="color:#FF0000;"><img src="'+fcode+'"></span>'; 
	oEditors.getById[objKey].exec("PASTE_HTML", [sHTML]); 
}

function delHTML(source){
	oEditors.getById[source].exec("SET_CONTENTS", [""]); 
}
function copyHTML(source,dest) {
	var sHTML = getHTML(source);
	oEditors.getById[dest].exec("PASTE_HTML", [sHTML]);
}
function getHTML(source){
	return oEditors.getById[source].getIR();
}		
</script>
<? 
}
?>

<script language="javascript" type="text/javascript">
	
	function fnList(param){
		location.replace("./bbs_list.php?cd_board="+param);
	}

	function fnProc(param){
		
		if(param=="Update"){
			$("#frmProc").attr("action","./bbs_write.php");
			$("#mode").val("Update");
			$("#frmProc").submit();
		}
		else if(param=="Reply"){
			$("#frmProc").attr("action","./bbs_write.php");
			$("#mode").val("Reply");
			$("#frmProc").submit();
		}
		else{
			$("#frmProc").attr("action","./board_proc.php");
			$("#mode").val("Delete");

			var c=confirm("선택하신 글을 정말로 삭제하시겠습니까?");
			if(c){
				$("#frmProc").submit();
			}
		}	
	}

	$("#content_view_area img").each(function() {
		var imgObj = new Image();
		var content_width = $("#content_view_area").width();
		imgObj.src = $(this).attr("src");
		if(imgObj.width > content_width) {
			$(this).width(content_width);
		}
	});

</script>
</body>
</html>
