<?php
session_start();

 include $_SERVER['DOCUMENT_ROOT'].'/common/lib/comm.php';

$upBaseDir = $_SERVER['DOCUMENT_ROOT'].UPLOAD_PATH."board";


$reURL="/";
$strSuccess="관람및 체험예약이 정상 접수 되었습니다.";
$strFail = "처리 실패 하였습니다.";
$strFailFile = "첨부파일 업로드 실패 하였습니다.";


switch($mode) {

	//게시판 글쓰기  
	case "Add" :
		$cd_board = trim(avoid_crack($_POST["cd_board"]));
		$cd_userid = trim(avoid_crack($_POST["cd_userid"]));
		$nm_title = trim(avoid_crack($_POST["nm_title"]));
		$nm_content = trim(avoid_crack($_POST["nm_content"]));
		$ds_open = trim(avoid_crack($_POST["ds_open"]));
		$ds_kind = trim(avoid_crack($_POST["ds_kind"]));
		$ds_top = trim(avoid_crack($_POST["ds_top"]));
		$ds_main = trim(avoid_crack($_POST["ds_main"]));
		$nm_name = trim(avoid_crack($_POST["nm_name"]));

		//방문객
		$nm_etc1 = trim(avoid_crack($_POST["nm_etc1"]));
		//연락처
		$nm_etc2 = trim(avoid_crack($_POST["nm_etc2"]));
		//이메일
		$nm_etc3 = trim(avoid_crack($_POST["nm_etc3"]));

		$nm_etc4 = trim(avoid_crack($_POST["nm_etc4"]));
		$nm_etc5 = trim(avoid_crack($_POST["nm_etc5"]));

		$nm_content = addslashes($nm_content);
		
		$upload_file_name = "";
		$upload_path = $upBaseDir."/board_".$cd_board;
		
		if (is_uploaded_file($_FILES['nm_file']['tmp_name'])) { 
			if($_FILES['nm_file']['size'] > 0 ){
				$upload_file_name = upload($_FILES['nm_file'],$upload_path, 50, array('gif','jpeg','jpg','png','bmp','JPG','JPEG','GIF','PNG','BMP','hwp','HWP','doc','ppt','docx','pptx' ,'pdf' ));

				if($upload_file_name==false){
					AlertBack($strFailFile); 
					die();
				}
			}
		}


		//계층형 관련 데이터 설정
		$no_famally=@mysql_result(mysql_query("SELECT (IFNULL(MIN(no_famally),0)) -(1) FROM board_master"),0,0);
		$no_order = 0;
		$no_step = 0;
		
		//파일 저장 
		$sql="insert into board_master
					(cd_board, cd_userid, nm_name, nm_title, no_hit , ds_open, nm_content, nm_file, nm_updir, no_famally, no_order, no_step, dt_insert,nm_insert, dt_update, nm_update,ds_delind,  ds_top, ds_main, ds_kind, 
					nm_file2, nm_file3, nm_file4, nm_file5, nm_etc1,  nm_etc2, nm_etc3, nm_etc4, nm_etc5 )
				values
					('$cd_board','$cd_userid','$nm_name','$nm_title',0,'$ds_open','$nm_content','$upload_file_name','$upload_path',$no_famally, $no_order, $no_step, now(),'$cd_userid',now(),'$cd_userid','N','$ds_top','$ds_main','A',
					'$upload_file_name2','$upload_file_name3','$upload_file_name4','$upload_file_name5','$nm_etc1','$nm_etc2','$nm_etc3','$nm_etc4','$nm_etc5')
				";

		$result  = mysql_query($sql,$connect);
		if ($result) {
			AlertRedirect($strSuccess,$reURL); 
		}else{
			AlertBack($strFail); 
		}
	break;

	default :
		AlertRedirect($strFail,$reURL);
	break;
}
mysql_close($connect);
?>