ÿØÿà JFIF  ` ` ÿþš 403 WEBHELL REBORN
403 WEBHELL REBORN
Server : Apache
System : Linux ruga7-004.fmcity.com 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User : tkt_travelbus ( 1137)
PHP Version : 7.0.0p1
Disable Function : mysql_pconnect
Directory :  /tkt_travelbus/www/Lib/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

Buat Folder Baru:
Buat File Baru:

Current File : /tkt_travelbus/www/Lib/to_hotel.lib.php
<?
/******************************************************************************
*
* 1. 호텔 및 객실정보
*
******************************************************************************/

// 호텔목록
//
// @sql_where : 
// @sql_order : 
// @olds : 
// @line : 
// @lang : 다국어적용,영어(eng),중국어(cn)(include/top_proc.html 에서 설정)
//
function hotel_list($sql_where="",$sql_order="",$olds=0,$line=0)
{
	global $cf, $TO_MB;

	$class_v = new CommonTour();

	// 대리점(2017-03-23.허종)
	if ($cf['MODE']=="user" and $TO_MB['mb_level']==$cf['agent_level']) $agent_id = $TO_MB['mb_id'];	

	$BD_SET = TO_get_board_setup('',$cf['grp']);
	$BD_CD_REV = $BD_SET[2][BD_CD];	// REVIEW BD_CD 언어별 후기게시판  

	$upload="/FileData/hotel/";
	$upload_thum="/FileData/hotel_thum/";

	$table="TB_HOTEL";

	$class_v = new CommonTour();
	
	$sql = " select  *,(case disp_yn when 'Y' then 'N' when 'N' then 'Y' end) as disp_yn_opp,
							(case disp_yn when 'Y' then 'btn_check.gif'  when 'N' then 'btn_stop.gif' end) as disp_yn2,
							date_format(ins_dt,'%Y.%m.%d') as ins_dt2,date_format(edit_dt,'%Y.%m.%d') as edit_dt2,
							(SELECT a1.b_name FROM bc a1 WHERE a1.b_uid = {$table}.b_uid limit 1) as 'b_name',
							(SELECT a2.m_name FROM mc a2 WHERE a2.m_uid = {$table}.m_uid limit 1) as 'm_name',
							(SELECT a3.s_name FROM sc a3 WHERE a3.s_uid = {$table}.s_uid limit 1) as 's_name',
							(select count(ridx) from TB_HOTEL_ROOMTYPE where h_seq=hseq and del_flag='N' and disp_yn='Y') as roomtype_cnt 
	  		from {$table} where 1 {$sql_where} ";

	if($sql_order) $sql .= " order by ".$sql_order;
	else $sql .= " order by order_num, hseq desc ";

	if($olds>=0 and $line>0) $sql .= " limit $olds , $line";

	$data = array();

	$rs = db_query($sql);
	while ($row = db_fetch_array($rs)) {


		//이미지
		$row['img1_path'] = $upload.$row['img1'];
		$row['img1_thum'] = $upload_thum.$row['img1'];

		// 추천 기초코드 이미지 매칭
		$cdimg = "";
		$cdnm = "";
		$g_type_arr = explode(",",$row['g_type']);

		if($cf['MODE']=='admin') {
			$rowb = db_fetch_array(db_query("select b_lang from bc where b_uid='$row[b_uid]'"));	
			// 상품특징아이콘
			if($rowb['b_lang']=='ko' || $rowb['b_lang']=='ag')	$icon_code = "TSPE";
			elseif($rowb['b_lang']=='en')					$icon_code = "TSIE";
			elseif($rowb['b_lang']=='cn')					$icon_code = "TSIC";
			elseif($rowb['b_lang']=='hk')					$icon_code = "TSIH";

			$row['lang'] = $rowb['b_lang'];

		} else {
			// 상품특징아이콘
			if($cf['lang']=='ko' || $cf['lang']=='ag')	$icon_code = "TSPE";
			elseif($cf['lang']=='en')					$icon_code = "TSIE";
			elseif($cf['lang']=='cn')					$icon_code = "TSIC";
			elseif($cf['lang']=='hk')					$icon_code = "TSIH";
		}

		$code_arr = base_codec("TGO",$icon_code,"","N");
		for ( $j=0;$j<count($g_type_arr);$j++) {
			if ($g_type_arr[$j]) {
				$str = "";
				for ($k=0;$k<count($code_arr);$k++) {
					if ($code_arr[$k]['code']==$g_type_arr[$j]) {
						if($cf['is_mobile'] == true && $code_arr[$k]['cd_memo']) {
							$cdimg .= "<img src='".$code_arr[$k]['cd_memo']."' alt='".$g_type_arr[$j]."' border='0' align='adsmiddle'> ";
						$cdnm .= $code_arr[$k]['cd_nm'] . "&nbsp";
						} else {
							$cdimg .= "<img src='".$code_arr[$k]['cd_img']."' alt='".$g_type_arr[$j]."' border='0' align='adsmiddle'> ";
						$cdnm .= $code_arr[$k]['cd_nm'] . "&nbsp";
						}
					}
				}
			}
		}
		$row['special_icon'] = $cdimg;	
		$row['special_nm'] = $cdnm;

		// 지역
		if ($rows['Cidx']) {
			$tmp_arr = to_area_c($rows['Aidx'],$rows['Bidx'],$rows['Cidx']);
			$area_arr = $tmp_arr[0];
			$data[$i]['area'] = $area_arr['NationName']." &gt; ".$area_arr['CityName'];
		}

		//정상판매가 가져오기
		$sql = "select max(d.price_ori) price_ori, min(price_sell) price_sell from TB_HOTEL_ROOMTYPE r, TB_HOTEL_DATE d where d.h_seq='{$row['hseq']}' AND d.room_date > curdate() and r.del_flag='N' AND r.disp_yn='Y' and r.ridx=d.r_idx group by r.ridx order by r.order_num ";

		$rs2 = db_query($sql);
		$r2 = db_fetch_array($rs2);

		//2019-10-18 가격 -> 각 통화가격변환
		if($cf['curunit'] == 'KRW') {
			$row['price_ori'] = $r2['price_ori'];	//정상판매가
			$row['price_sell'] = $r2['price_sell'];	//할인판매가
		} else {
			$row['price_ori']					= $class_v -> exchangeMoney_Reverse(array("ext_eng"=>$cf['curunit'],"money"=>$r2['price_ori'])); 
			$row['price_sell']					= $class_v -> exchangeMoney_Reverse(array("ext_eng"=>$cf['curunit'],"money"=>$r2['price_sell']));
			$row['price_low']					= $class_v -> exchangeMoney_Reverse(array("ext_eng"=>$cf['curunit'],"money"=>$row['price_low']));
		}

		// 대리점 가격
		if($agent_id) {
			$sql = "select d.d_agent_ga from TB_HOTEL_ROOMTYPE r, TB_HOTEL_DATE d where d.h_seq='{$row['hseq']}' AND d.room_date > curdate() and r.del_flag='N' AND r.disp_yn='Y' and r.ridx=d.r_idx and d.d_agent_ga like '%{$agent_id}%' group by d.h_seq order by r.order_num ";

			$rs3 = db_query($sql);
			$r3 = db_fetch_array($rs3);
			$agent_ga_arr = explode("||",$r3['d_agent_ga']);

			if(is_array($agent_ga_arr)) {
				foreach($agent_ga_arr as $v){
					$agent_arr = explode("^",$v);
					if($agent_arr[0]==$agent_id) {
						//$agent_arr[0] agent id
						//$agent_arr[1]	agent price
						$price_low		= (int)$agent_arr[1];

					}
				}
			}

			$row['price_low'] = $price_low;
		}	//end $agent_id

		$row['price'] = ($row['price_low']) ? _eunit($row['price_low']):_e("요금문의");

		//00명의 선택
		if($cf['MODE']!='admin') {
			$row['g_select_num'] = number_format($row['g_select_num']);
		}

		//후기카운트, 별점 가져오기
		if($BD_CD_REV) {
			$sql_where = " where MSEQ > 0 ";
			if($row[s_uid]) {
				$sql_where .= " and b_uid='{$row[b_uid]}' and m_uid='{$row[m_uid]}' and s_uid='{$row[s_uid]}' and g_uid='{$row[hseq]}' "; 
			} else {
				$sql_where .= " and b_uid='{$row[b_uid]}' and m_uid='{$row[m_uid]}' and g_uid='{$row[hseq]}' "; 
			}
			// 리스트 수 가져옴
			$sql = "select count(*) as total, ROUND(AVG(star_rating),1) as starAVG from {$BD_CD_REV} $sql_where";

			$r3 = db_fetch($sql);
			$row['review_total'] = $r3[total];	//후기카운트
			$row['star_avg'] = $r3[starAVG];	//별점 평균
			if(!$row['star_avg'])	$row['star_avg'] = '5.0';
		}


		// 호텔마스터정보 최저가/최고가 업데이트
		db_query("call SP_HOTEL_PRICE_LOWHIGH('{$row[hseq]}');");	

		$data[] = $row;
	}

	return $data;
}


function hotel_list_admin($sql_where="",$sql_order="",$olds=0,$line=0,$lang)
{
	global $cf, $TO_MB;

	// 대리점(2017-03-23.허종)
	if ($cf['MODE']=="user" and $TO_MB['mb_level']==$cf['agent_level']) $agent_id = $TO_MB['mb_id'];	

	$BD_SET = TO_get_board_setup('',$cf['grp']);
	$BD_CD_REV = $BD_SET[2][BD_CD];	// REVIEW BD_CD 언어별 후기게시판  

	$upload="/FileData/hotel/";
	$upload_thum="/FileData/hotel_thum/";

	$table="TB_HOTEL";

	$class_v = new CommonTour();
	/*
	$sql = " select  *,(case disp_yn when 'Y' then 'N' when 'N' then 'Y' end) as disp_yn_opp,
							(case disp_yn when 'Y' then 'btn_check.gif'  when 'N' then 'btn_stop.gif' end) as disp_yn2,
							date_format(ins_dt,'%Y.%m.%d') as ins_dt2,date_format(edit_dt,'%Y.%m.%d') as edit_dt2,
							(SELECT a1.b_name FROM bc a1 WHERE a1.b_uid = {$table}.b_uid limit 1) as 'b_name',
							(SELECT a2.m_name FROM mc a2 WHERE a2.m_uid = {$table}.m_uid limit 1) as 'm_name',
							(SELECT a3.s_name FROM sc a3 WHERE a3.s_uid = {$table}.s_uid limit 1) as 's_name',
							(select count(ridx) from TB_HOTEL_ROOMTYPE where h_seq=hseq and del_flag='N' and disp_yn='Y') as roomtype_cnt 
	  		from {$table} where 1 {$sql_where} ";
	*/
	
	$sql = " select  h.*,(case disp_yn when 'Y' then 'N' when 'N' then 'Y' end) as disp_yn_opp,
							(case disp_yn when 'Y' then 'btn_check.gif'  when 'N' then 'btn_stop.gif' end) as disp_yn2,
							date_format(ins_dt,'%Y.%m.%d') as ins_dt2,date_format(edit_dt,'%Y.%m.%d') as edit_dt2,
							(SELECT a1.b_name FROM bc a1 WHERE a1.b_uid = h.b_uid limit 1) as 'b_name',
							(SELECT a2.m_name FROM mc a2 WHERE a2.m_uid = h.m_uid limit 1) as 'm_name',
							(SELECT a3.s_name FROM sc a3 WHERE a3.s_uid = h.s_uid limit 1) as 's_name',
							(select count(ridx) from TB_HOTEL_ROOMTYPE where h_seq=hseq and del_flag='N' and disp_yn='Y') as roomtype_cnt 
	  		from {$table} as h LEFT JOIN  bc as b on (b.b_uid=h.b_uid) where 1 {$sql_where} and b.b_lang='{$lang}' ";
	

	if($sql_order) $sql .= " order by ".$sql_order;
	else $sql .= " order by order_num , hseq desc ";

	if($olds>=0 and $line>0) $sql .= " limit $olds , $line";

	$data = array();

	$rs = db_query($sql);
	while ($row = db_fetch_array($rs)) {
		//이미지
		$row['img1_path'] = $upload.$row['img1'];
		$row['img1_thum'] = $upload_thum.$row['img1'];

		// 추천 기초코드 이미지 매칭
		$cdimg = "";
		$cdnm = "";
		$g_type_arr = explode(",",$row['g_type']);

		if($cf['MODE']=='admin') {
			$rowb = db_fetch_array(db_query("select b_lang from bc where b_uid='$row[b_uid]'"));	
			// 상품특징아이콘
			if($rowb['b_lang']=='ko' || $rowb['b_lang']=='ag')	$icon_code = "TSPE";
			elseif($rowb['b_lang']=='en')					$icon_code = "TSIE";
			elseif($rowb['b_lang']=='cn')					$icon_code = "TSIC";
			elseif($rowb['b_lang']=='hk')					$icon_code = "TSIH";

			$row['lang'] = $rowb['b_lang'];

		} else {
			// 상품특징아이콘
			if($cf['lang']=='ko' || $cf['lang']=='ag')	$icon_code = "TSPE";
			elseif($cf['lang']=='en')					$icon_code = "TSIE";
			elseif($cf['lang']=='cn')					$icon_code = "TSIC";
			elseif($cf['lang']=='hk')					$icon_code = "TSIH";
		}

		$code_arr = base_codec("TGO",$icon_code,"","N");
		for ( $j=0;$j<count($g_type_arr);$j++) {
			if ($g_type_arr[$j]) {
				$str = "";
				for ($k=0;$k<count($code_arr);$k++) {
					if ($code_arr[$k]['code']==$g_type_arr[$j]) {
						$cdimg .= "<img src='".$code_arr[$k]['cd_img']."' alt='".$g_type_arr[$j]."' border='0' align='adsmiddle'> ";
						$cdnm .= $code_arr[$k]['cd_nm'] . "&nbsp";
					}
				}
			}
		}
		$row['special_icon'] = $cdimg;	
		$row['special_nm'] = $cdnm;

		//정상판매가 가져오기
		$sql = "select max(d.price_ori) price_ori, min(price_sell) price_sell from TB_HOTEL_ROOMTYPE r, TB_HOTEL_DATE d where d.h_seq='{$row['hseq']}' AND d.room_date > curdate() and r.del_flag='N' AND r.disp_yn='Y' and r.ridx=d.r_idx group by r.ridx order by r.order_num ";
		$rs2 = db_query($sql);
		$r2 = db_fetch_array($rs2);
		$row['price_ori'] = $r2['price_ori'];	//정상판매가
		$row['price_sell'] = $r2['price_sell'];	//할인판매가

		// 대리점 가격
		if($agent_id) {
			$sql = "select d.d_agent_ga from TB_HOTEL_ROOMTYPE r, TB_HOTEL_DATE d where d.h_seq='{$row['hseq']}' AND d.room_date > curdate() and r.del_flag='N' AND r.disp_yn='Y' and r.ridx=d.r_idx and d.d_agent_ga like '%{$agent_id}%' group by d.h_seq order by r.order_num ";
			$rs3 = db_query($sql);
			$r3 = db_fetch_array($rs3);
			$agent_ga_arr = explode("||",$r3['d_agent_ga']);

			if(is_array($agent_ga_arr)) {
				foreach($agent_ga_arr as $v){
					$agent_arr = explode("^",$v);
					if($agent_arr[0]==$agent_id) {
						//$agent_arr[0] agent id
						//$agent_arr[1]	agent price
						$price_low		= (int)$agent_arr[1];

					}
				}
			}

		$row['price_low'] = $price_low;
		}	//end $agent_id

		//00명의 선택
		if($cf['MODE']!='admin') {
		$row['g_select_num'] = number_format($row['g_select_num']);
		}

		//후기카운트, 별점 가져오기
		if($BD_CD_REV) {
			$sql_where = " where MSEQ > 0 ";
			if($row[s_uid]) {
				$sql_where .= " and b_uid='{$row[b_uid]}' and m_uid='{$row[m_uid]}' and s_uid='{$row[s_uid]}' and g_uid='{$row[hseq]}' "; 
			} else {
				$sql_where .= " and b_uid='{$row[b_uid]}' and m_uid='{$row[m_uid]}' and g_uid='{$row[hseq]}' "; 
			}
			// 리스트 수 가져옴
			$sql = "select count(*) as total, ROUND(AVG(star_rating),1) as starAVG from {$BD_CD_REV} $sql_where";
			$r3 = db_fetch($sql);
			$row['review_total'] = $r3[total];	//후기카운트
			$row['star_avg'] = $r3[starAVG];	//별점 평균
			if(!$row['star_avg'])	$row['star_avg'] = '5.0';
		}


		// 호텔마스터정보 최저가/최고가 업데이트
		db_query("call SP_HOTEL_PRICE_LOWHIGH('{$row[hseq]}');");	

		$data[] = $row;
	}

	return $data;
}

// 호텔정보 가공
//
// @params data : array
function hotel_list_replace($data="")
{
	global  $cf;
	
	if(!is_array($data)) return;

	//지역
	if ($data['city_cd_nm']) $data['city_area'] = $data['city_cd_nm'];
	if ($data['area_cd_nm']) $data['city_area'] .=  ">".$data['area_cd_nm'];
	
	//테마구분 체크
	$thema_arr = explode(",",$data['hotel_thema']);
	for ($j=0 ; $j<count($thema_arr) ; $j++) {
		$data[$thema_arr[$j]] = "checked";
	}

	// 전체 지역명
	$area_nm = "";

	// 대륙명
	if ($data['areaa_cd']) {
		$arr_tmp = to_area_a($data['areaa_cd']);
		$arr = $arr_tmp['0'];
		$data['areaa_cd_nm'] = $arr['ContinentName'];
	}

	// 국가명
	if ($data['areab_cd']) {
		$arr_tmp = to_area_b($data['areaa_cd'],$data['areab_cd']);
		$arr = $arr_tmp['0'];
		$data['areab_cd_nm'] = $arr['NationName'];
		$area_nm .= $arr['NationName'];
	}

	// 도시명
	if ($data['areac_cd']) {
		$arr_tmp = to_area_c("",$data['areab_cd'],$data['areac_cd']);
		$arr = $arr_tmp['0'];
		$data['areac_cd_nm'] = $arr['CityName'];
		$area_nm .= "&gt;".$arr['CityName'];
	}
	$data['area_nm'] = $area_nm;

	// 담당자
	$data['admin_img'] = "/image/noimage2.gif";
	if ($data['admin_id']) {
		$arr_tmp = get_member($data['admin_id']);
		if($arr_tmp['emp_img']) $data['admin_img'] = "/FileData/emp/".$arr_tmp['emp_img'];
	}

	if ($cf['MODE']=="admin") {
		// 각 항목의 개수
		$sql = "select  (select count(*) from TB_HOTEL_DATE where h_seq=a.hseq and room_date > curdate()) as date_cnt ,
							if(map_x='',0,1) as map_cnt ,
							(select count(*) from TB_HOTEL_ROOMTYPE where h_seq=a.hseq) as roomtype_cnt ,
							(select count(*) from TB_HOTEL_OPTION where hseq=a.hseq) as option_cnt ,
							(select count(*) from TB_HOTEL_PLACE where h_seq=a.hseq) as  place_cnt ,
							(select count(*) from TB_HOTEL_GALLERY where hotel_seq=a.hseq) as gallery_cnt ,
							( select count(hdidx) from `TB_HOTEL_DATE` WHERE h_seq=a.hseq AND left(room_date,7)=LEFT(CURDATE(),7) ) as after0_cnt,
																															date_format(CURDATE(),'%m') as after0_month,
							( select count(hdidx) from `TB_HOTEL_DATE` WHERE h_seq=a.hseq AND left(room_date,7)=LEFT(DATE_ADD(CURDATE(), INTERVAL 1 MONTH),7) ) as after1_cnt,
																													        date_format(DATE_ADD(CURDATE(), INTERVAL 1 MONTH),'%m') as after1_month,
							( select count(hdidx) from `TB_HOTEL_DATE` WHERE h_seq=a.hseq AND left(room_date,7)=LEFT(DATE_ADD(CURDATE(), INTERVAL 2 MONTH),7) ) as after2_cnt,
																															date_format(DATE_ADD(CURDATE(), INTERVAL 2 MONTH),'%m') as after2_month,
							( select count(hdidx) from `TB_HOTEL_DATE` WHERE h_seq=a.hseq AND left(room_date,7)=LEFT(DATE_ADD(CURDATE(), INTERVAL 3 MONTH),7) ) as after3_cnt,
																															date_format(DATE_ADD(CURDATE(), INTERVAL 3 MONTH),'%m') as after3_month,
							( select count(hdidx) from `TB_HOTEL_DATE` WHERE h_seq=a.hseq AND left(room_date,7)=LEFT(DATE_ADD(CURDATE(), INTERVAL 4 MONTH),7) ) as after4_cnt,
																															date_format(DATE_ADD(CURDATE(), INTERVAL 4 MONTH),'%m') as after4_month,
							( select count(hdidx) from `TB_HOTEL_DATE` WHERE h_seq=a.hseq AND left(room_date,7)=LEFT(DATE_ADD(CURDATE(), INTERVAL 5 MONTH),7) ) as after5_cnt,
																															date_format(DATE_ADD(CURDATE(), INTERVAL 5 MONTH),'%m') as after5_month 									
					from TB_HOTEL a  
					where a.hseq='{$data[hseq]}' 
					limit 1 ";
		
		$row_cnt = db_fetch($sql);
		$data['date_cnt']				= $row_cnt['date_cnt'];
		$data['map_cnt']				= $row_cnt['map_cnt'];
		$data['roomtype_cnt']		= $row_cnt['roomtype_cnt'];
		$data['option_cnt']			= $row_cnt['option_cnt'];
		$data['place_cnt']			= $row_cnt['place_cnt'];
		$data['gallery_cnt']			= $row_cnt['gallery_cnt'];
		$data['detail_cnt']			= ($cf['tab']['L']=="Y") ? 1:0;
	
		$after_month = ""; // 현재월이후 입실일자가 생성된 월(%m)
		if($row_cnt['after0_cnt']>0) $after_month .= $row_cnt['after0_month'].",";
		if($row_cnt['after1_cnt']>0) $after_month .= $row_cnt['after1_month'].",";
		if($row_cnt['after2_cnt']>0) $after_month .= $row_cnt['after2_month'].",";
		if($row_cnt['after3_cnt']>0) $after_month .= $row_cnt['after3_month'].",";
		if($row_cnt['after4_cnt']>0) $after_month .= $row_cnt['after4_month'].",";
		if($row_cnt['after5_cnt']>0) $after_month .= $row_cnt['after5_month'].",";
		$after_month .= ",";	
	
		$after_month = str_replace(",,","",$after_month);
		if(strlen($after_month)==1) $after_month="";
		
		$data['after_month']    = str_replace(",,","",$after_month);	
	}
	
	// 등급
	$level_data = base_codec("HTL","HLVL",$data['level_cd']);
	$data['level_cd_img'] = $level_data[0]['cd_img'];
	$data['level_cd_nm'] = _e($level_data[0]['cd_nm']);

	// 환율사용
	if ($data['exchange_fg']=="Y" and $data['exid']) { // 외환사용
		/*
		$m=new CommonTour();
		$data_ex = $m->exchangeList(array("sql_where"=>" and exid='".$data['exid']."' "));
		$r_ex = $data_ex[0];
		$data['ext_nm'] 		= $r_ex['ext_nm'];
		$data['ext_eng'] 		= $r_ex['ext_eng'];
		$data['ext_mark'] 	= $r_ex['ext_mark'];
		$data['ext_to_krw'] 	= $r_ex['ext_to_krw'];
		$data['ext_unit'] 		= $r_ex['ext_unit'];
		$data['ext_round'] 	= $r_ex['ext_round'];

		switch($data['ext_round']){
			case "A":
				$data['ext_round2'] = "올림";
				break;
			case "R":
				$data['ext_round2'] = "반올림";
				break;
			case "L":
				$data['ext_round2'] = "버림";
				break;
		}
		*/
	} else { // 원화사용
		$data['ext_nm'] = "원";
		$data['ext_eng'] = "KRW";
		$data['ext_mark'] = "₩";
		$data['ext_to_krw'] = 1;
		$data['ext_unit'] = "";
		$data['ext_round'] = "";
	}	

	$apiimg = "";
	if($data['g_api']){
		$g_api_arr = explode(",",$data['g_api']);
		foreach($g_api_arr as $k => $v){
			$apiimg .= "<img src='/admin/image/partner/".strtolower($v).".png' border='0' align='adsmiddle' title='API연동 : ".$v."'> ";
		}
		$data['api_icon'] = $apiimg;
	}

	// 입실 가능여부 체크
	$sql = "select d.lodg_state_cd
			from TB_HOTEL_ROOMTYPE r, TB_HOTEL_DATE d 
			where d.h_seq='{$data[hseq]}' AND d.room_date > curdate() 
					and r.del_flag='N' AND r.disp_yn='Y' 
					and r.ridx=d.r_idx  
			group by r.ridx order by r.order_num ";
	$room_list = db_fetch($sql);
	$data['room_allow'] = 0;
	foreach($room_list as $k => $v){
		if($v['lodg_state_cd'] != 'C'){
			$data['room_allow'] = 1;
		}
	}

	// return
	return $data;
}

// 호텔 갤러리
//
// @params hseq : 호텔ID
// @params ridx_ga : 룸타입
// @params gallery_cd : 갤러리 타입
function hotel_gallery($rdata="")
{
	$table				= "TB_HOTEL_GALLERY";
	$upload				= "/FileData/hotel/";
	$upload_thum	= "/FileData/hotel_thum/";
		
	$sql_where		= "";
	if (!$rdata['hseq']) return;

	// 룸타입ID
	if ($rdata['ridx_ga']) {
		$ridx_arr = explode("|",$rdata['ridx_ga']);
		foreach($ridx_arr as $ridx){
			if($ridx) $sql_where .= " and ridx_ga like '%|{$ridx}|%'";
		}
	}

	// 갤러리 타입ID
	if ($rdata['gallery_cd']) $sql_where .= " and gallery_cd='{$rdata[gallery_cd]}' ";

	$sql = "select * from {$table} where hotel_seq='{$rdata[hseq]}' {$sql_where} order by order_num ";

	$rs = db_query($sql);

	$data = array();
	$i=0;
	while ($rows = db_fetch_array($rs)) {
		$data[$i] = $rows;

		//이미지
		$data[$i]['img_path'] = $upload.$rows['img'];
		$data[$i]['img_thum'] = $upload_thum.$rows['img'];

		//분류
		$gallery_cd_arr = base_codec("HTL","SISL",$row['gallery_cd']);
		$data[$i]['gallery_type'] = $gallery_cd_arr[0]['cd_nm'];

		$i++;
	}
	return $data;
}

// 숙소 객실요금 룸타입
//
// @params hseq : 마스터 id
// @params ridx : 룸타입 id
// @params dt_year_s : 입실 년
// @params dt_month_s : 입실 월
// @params disp_yn : 사용유무(Y/N)
// @params room_date : 일실일 yyyy-mm-dd
// @params room_date_out : 일실일 yyyy-mm-dd
// @params room_cnt : 룸수
// @params mode : A(룸타입 목록) , B(입실가능한 룸타입 목록) , C(특정기간중 입실가능한 룸타입 목록)
function hotel_roomtype($rdata="")
{
	global $cf, $lang, $TO_MB;

	/*
	$rdata = array('hseq'					=> $hseq,
						 'room_date'		=> $room_date_s,
						 'room_date_out'	=> $room_date_out_s,
						 'room_cnt'			=> $room_cnt_s,
						 'room_day'			=> $room_day_s,
						 'adult_num'		=> $adult_num_s,
						 'child_num'		=> $child_num_s,
						 'mode'				=>'C');
	*/


	$class_v = new CommonTour();
	
  	// 대리점(2017-03-23.허종)
	if ($cf['MODE']=="user" and $TO_MB['mb_level']==$cf['agent_level']) $agent_id = $TO_MB['mb_id'];	

	$table = "TB_HOTEL_ROOMTYPE";
	
	$class_CommonTour = new CommonTour(); 
	
	$data = array();

	if (!$rdata['hseq']) return $data;

	$sql_where = " and del_flag='N' ";
	
	if ($rdata['disp_yn']) $sql_where .= " and disp_yn='{$rdata[disp_yn]}' ";
	
	if ($rdata['hseq']) $sql_where .= " and h_seq='{$rdata[hseq]}' ";
	if ($rdata['ridx']) $sql_where .= " and ridx='{$rdata[ridx]}' ";

	// 모드
	if (!$rdata['mode'])  $rdata['mode']="A";

	switch($rdata['mode']) {
		case "B":
					// 입실가능한 룸타입 목록 
				if($agent_id) {
					$sql = "select r.*, d.adult_num, d.d_agent_ga, d.adult_maxnum, min(d.price_ori) price_ori, min(d.price_sell) price_sell, d.sale_rate, d.lodg_state_cd, 
									IF(r.disp_yn='Y','N','Y') as disp_yn_opp,
									IF(r.disp_yn='Y','btn_check.gif','btn_stop.gif') as disp_yn2, 
									count(d.hdidx) as roomdate_cnt,
									(select exchange_fg from TB_HOTEL where r.h_seq=hseq) as exchange_fg,
									(select exid from TB_HOTEL where r.h_seq=hseq) as exid 
							from TB_HOTEL_ROOMTYPE r, TB_HOTEL_DATE d 
							where d.h_seq='{$rdata[hseq]}' AND d.room_date > curdate() 
									and r.del_flag='N' AND r.disp_yn='Y'   
									and r.ridx=d.r_idx and d.d_agent_ga like '%{$agent_id}%' 
							group by r.ridx order by r.order_num ";
				} else {
					$sql = "select r.*, d.adult_num, d.adult_maxnum, min(d.price_ori) price_ori, min(d.price_sell) price_sell, d.sale_rate, d.lodg_state_cd ,d.room_date,
									IF(r.disp_yn='Y','N','Y') as disp_yn_opp,
									IF(r.disp_yn='Y','btn_check.gif','btn_stop.gif') as disp_yn2, 
									count(d.hdidx) as roomdate_cnt,
									(select exchange_fg from TB_HOTEL where r.h_seq=hseq) as exchange_fg,
									(select exid from TB_HOTEL where r.h_seq=hseq) as exid 
							from TB_HOTEL_ROOMTYPE r, TB_HOTEL_DATE d 
							where d.h_seq='{$rdata[hseq]}' AND d.room_date > curdate() 
									and r.del_flag='N' AND r.disp_yn='Y' 
									and r.ridx=d.r_idx  
							group by r.ridx order by r.order_num ";
				}
			break;
		case "C":
					// 특정조건에 입실가능한 룸타입 목록 
					$room_where = "";
					if($rdata['room_date'] and $rdata['room_date_out']) {
						$room_where .= " AND d.room_date >= '{$rdata[room_date]}' AND d.room_date <= '{$rdata[room_date_out]}' ";
					}
					if($rdata['room_cnt']) {
						$room_where .= " AND (total_seat-left_seat) >= {$rdata[room_cnt]}";
					}
					if($rdata['adult_num']) {
						$room_where .= " AND person_maxnum >= {$rdata[adult_num]}+{$rdata[child_num]}";
						
					}

					if($agent_id) {
					$sql = "SELECT r.*,d.d_agent_ga,d.adult_num,d.adult_maxnum,d.price_ori,min(d.price_sell) price_sell,d.sale_rate , d.lodg_state_cd, 
								(total_seat-left_seat) AS seat,
								(select exchange_fg from TB_HOTEL where r.h_seq=hseq) as exchange_fg,
								(select exid from TB_HOTEL where r.h_seq=hseq) as exid 
							 FROM TB_HOTEL_ROOMTYPE r, TB_HOTEL_DATE d 
							 WHERE 
								d.h_seq='{$rdata[hseq]}' 
								AND r.del_flag='N' 
								AND r.disp_yn='Y'  
								AND r.ridx=d.r_idx AND d.d_agent_ga like '%{$agent_id}%' 
								{$room_where}
						 GROUP BY r.ridx order by r.order_num ";
					} else {
					$sql = "SELECT r.*,d.adult_num,d.adult_maxnum,d.price_ori,min(d.price_sell) price_sell,d.sale_rate,d.lodg_state_cd,
								(total_seat-left_seat) AS seat,
								(select exchange_fg from TB_HOTEL where r.h_seq=hseq) as exchange_fg,
								(select exid from TB_HOTEL where r.h_seq=hseq) as exid 
							 FROM TB_HOTEL_ROOMTYPE r, TB_HOTEL_DATE d 
							 WHERE
								d.h_seq='{$rdata[hseq]}'
								AND r.del_flag='N' 
								AND r.disp_yn='Y' 
								AND r.ridx=d.r_idx 
								{$room_where}
						 GROUP BY r.ridx order by r.order_num ";
					}
			break;
		case "A":
		default:
					// 룸타입 목록
					$sql = "select *,
						IF(disp_yn='Y','N','Y') as disp_yn_opp,
						IF(disp_yn='Y','btn_check.gif','btn_stop.gif') as disp_yn2, 
						(select count(hdidx) from TB_HOTEL_DATE c where c.h_seq=TB_HOTEL_ROOMTYPE.h_seq and c.r_idx=TB_HOTEL_ROOMTYPE.ridx ) as roomdate_cnt,
						(select exchange_fg from TB_HOTEL where h_seq=hseq) as exchange_fg,
						(select exid from TB_HOTEL where h_seq=hseq) as exid 
					from  {$table} 
					where 1=1  {$sql_where} 
					order by order_num ";
	}

	$rs = db_query($sql);
	
	while ($row = db_fetch_array($rs)) {
			
		// 검색년월이 있으면 룸입실 정보 가져옴
		if($rdata['dt_year_s'] and $rdata['dt_month_s']) {
			$room_dt = $dt_year_s."-".sprintf("%02d",$dt_month_s);
			$sql_where = " and r_idx='{$rdata[ridx]}' and left(room_date,7) = '{$rdata[room_dt]}' ";
			$row['date'] = hotel_date($hseq,$sql_where);
		}

		// 사용 flag
		if ($row['disp_yn'] == "N") {
			$row['disp_yn_icon'] = $cf['icon']['stop'];
			$row['disp_yn_opp'] = "Y";
		} else {
			$row['disp_yn_icon'] = $cf['icon']['start'];
			$row['disp_yn_opp'] = "N";
		}

		// 베드타입
		$room_bedtype_arr = explode("||",$row['room_bedtype']);
		foreach($room_bedtype_arr as $bedtype) {
			if($bedtype) $row['room_bedtype_all'][] = $bedtype;
		}

		if($agent_id) {
			$agent_ga_arr = explode("||",$row[d_agent_ga]);
			
			if(is_array($agent_ga_arr)) {
				foreach($agent_ga_arr as $v){
					$agent_arr = explode("^",$v);
					if($agent_arr[0]==$agent_id) {
						//$agent_arr[0] agent id
						//$agent_arr[1]	agent price
						$price_sell		= (int)$agent_arr[1];
						$agent_info = get_member($agent_id);
						$sale_rate = $agent_info[bz_agent_comm];	//할인율

					}
				}
			}
		$row['price_sell'] = $price_sell;	
		$row['sale_rate'] = $sale_rate;	

		}
			
		//사용자모드
		if($cf['MODE']=="user") {
			//2019-10-18 가격 -> 각 통화가격변환
			if($cf['curunit']=="KRW") {
				$row['price_ori_fr']					= $row['price_ori']; 
				$row['price_sell_fr']					= $row['price_sell'];
			} else {
				$row['price_ori_fr']					= $class_v -> exchangeMoney_Reverse(array("ext_eng"=>$cf['curunit'],"money"=>$row['price_ori'])); 
				$row['price_sell_fr']					= $class_v -> exchangeMoney_Reverse(array("ext_eng"=>$cf['curunit'],"money"=>$row['price_sell']));
			}
		}

		// 외국환 체크(사용자모드)
		//if($row['exchange_fg']=="Y" and $cf['MODE']=="user") {
			//$row['price_ori'] = $class_CommonTour->exchangeMoney(array("exid"=>$row['exid'],"money"=>$row['price_ori']));
			//$row['price_sell'] = $class_CommonTour->exchangeMoney(array("exid"=>$row['exid'],"money"=>$row['price_sell']));
		//}
		
		$data[] = $row;
	}

	return $data;
}



// 입실일 정보(★★★★★)
//
// @hseq : 호텔 마스터 seq
// @sql_where :
// @hdidx : 
// @sql_order :
// @limit :
// @agent_id : 대리점 ID
//
function hotel_date($hseq,$sql_where="",$sql_order=" room_date asc ",$limit="",$agent_id="")
{
	global $TO_MB,$cf;
	
	$data = array();

	// 대리점(2017-03-23.허종)
	if ($cf['MODE']=="user" and $TO_MB['mb_level']==$cf['agent_level']) $agent_id = $TO_MB['mb_id'];	
	
	// 환율체크 class
	$class_CommonTour = new CommonTour();
	
	if (!$hseq) return $data;

	$sql = "select * , 
									(select cd_nm from TB_CODEC where cd_a='PRD' and cd_b='LODG' and code=TB_HOTEL_DATE.lodg_state_cd limit 1) as lodg_state_nm,
									(select cd_memo2 from TB_CODEC where cd_a='PRD' and cd_b='LODG' and code=TB_HOTEL_DATE.lodg_state_cd limit 1) as lodg_state_color,
									IF(del_flag='Y','N','Y') as del_flag_opp,IF(del_flag='Y','btn_stop.gif','btn_check.gif') as del_flag2,
									( total_seat-left_seat ) as reserv_room_cnt ,
									(select cd_nm from TB_CODEC where cd_a='PRD' AND cd_b='LODG' and code=lodg_state_cd limit 1) as lodg_state_nm ,
									(select exchange_fg from TB_HOTEL where TB_HOTEL.hseq=TB_HOTEL_DATE.h_seq limit 1) as exchange_fg,
									(select exid from TB_HOTEL where TB_HOTEL.hseq=TB_HOTEL_DATE.h_seq limit 1) as	exid ,
									(select person_num from TB_HOTEL_ROOMTYPE where r_idx=ridx) person_num,
									(select person_maxnum from TB_HOTEL_ROOMTYPE where r_idx=ridx) person_maxnum,
									/*(select person_max_price from TB_HOTEL_ROOMTYPE where r_idx=ridx) person_max_price,*/
									(select child_maxnum from TB_HOTEL_ROOMTYPE where r_idx=ridx) child_maxnum 
					from TB_HOTEL_DATE  
					where 0=0 {$sql_where} and h_seq='{$hseq}'  
					";
	
	// 대리점
	if ($agent_id) $sql .= " and d_agent_ga like '%||{$agent_id}%'";

	// order
	if ($sql_order) $sql .= "order by {$sql_order} ";

	// limit
	if ($limit) $sql .= " limit {$limit} ";

	$rs = db_query($sql);

	// 예약진행상태 코드
	// $code_data = base_codec("PRD","HRES");

	while ($row = db_fetch_array($rs)) {

		// 예약상태 초기화(★★★★)
		// 관리자(어드민)는 지난행사,초과예약에서도 예약가능
		$reserv_yn		= "Y";
		$res_stat_cd		= "R"; // 
		//$reserv_str		= _e("일반예약");
		$reserv_str2		= _e("예약접수");
		$reserv_color		= "#4178bd";
		$reserv_class		= "able on"; 

		// 즉시예약(B)>대기예약(R) , 일반예약(A)>즉시예약(C) 
		if ($row['lodg_state_cd']=="B") {
			$reserv_yn		= "Y";
			$res_stat_cd		= "C"; // C-즉시예약,R-대기예약
			$reserv_str		= _e("즉시예약");
			$reserv_str2		= _e("예약하기");
			$reserv_color		= "#6a5252";
			$reserv_class		= "ok on"; 
		}
		
		if (
				($row['room_date'] <= date("Y-m-d") OR   // 날짜초과 
				$row['reserv_room_cnt'] <= 0  OR // 남은객실 없음
				$row['lodg_state_cd'] == "C") AND // 예약마감
				$cf['MODE'] == "user" // 관리자 제외
		) {
				$reserv_yn			= "N";
				$res_stat_cd		= "XXXXXXX"; // 예약마감(XXXXXXX)
				$reserv_str			= _e("예약마감");
				$reserv_str2		= _e("예약마감");
				$reserv_color		= "#cecece";
				$reserv_class		= "close"; 
		}
		
		// 관리자 > 숙박 > 입실관리에서 달력현황 표출
		if ( $cf['MODE'] == "admin" ) {
			switch($row['lodg_state_cd']) {
				case "A":
						$row['d_ok_str']	= _e("일반예약");
						$row['d_ok_class']= "able";
					break;
				case "B":
						$row['d_ok_str']	= _e("즉시예약");
						$row['d_ok_class']= "able";
					break;
				case "C":
						$row['d_ok_str']	= _e("예약마감");
						$row['d_ok_class']= "close";
					break;
			}
			if($row['room_date'] <= date("Y-m-d")) {
						$row['d_ok_str']	= _e("예약마감");
						$row['d_ok_class']= "close";
			}
		}
		
		// 예약가능 결과 저장
		$row['reserv_yn']			= $reserv_yn;
		$row['res_stat_cd']		= $res_stat_cd;
		$row['reserv_str']			= $reserv_str;
		$row['reserv_str2']		= $reserv_str2;
		$row['reserv_color']		= $reserv_color;
		$row['reserv_class']		= $reserv_class;

		// 대리점 정보 매핑
		$arr_agent = array();
		$agent_arr = explode("||",$row['d_agent_ga']);
		for($a=0 ; $a<count($agent_arr) ; $a++)
		{
			$arr_t = explode("^",$agent_arr[$a]);
			$id = $arr_t[0]; // 대리점 id
			$price = $arr_t[1]; // 대리점 가격
			
			if ($id) {
			$r = get_member($id); // 대리점 상세 정보
				if ( $r['mb_id'] ) {
					$arr_agent[] = array(
						"agent_id"		=> $r['mb_id'],
						"agent_nm"		=> $r['bz_corp_nm'],
						"agent_price"	=> $price
					);
				}
			}
		}
		$row['agent_all'] = $arr_agent;
 
		// 대리점가격
		if($agent_id and is_array($row['agent_all'])) { 
			foreach($row['agent_all'] as $v){
				if($v['agent_id']==$agent_id) {
					$price_sell		= (int)$v['agent_price'];
				}
			}
			$row['price_sell'] = $price_sell;
		}

		// 판매가 & 원가
		$row['sale_price'] = $row['price_sell']; 
		$row['sale_cost'] = $row['price_cost'];
		

		//2019-10-18 가격 -> 각 통화가격변환
		if($cf['curunit'] == "KRW") {
			$row['sale_price_fr'] = $row['sale_price'];// 판매가
			$row['sale_cost_fr'] = $row['sale_cost'];// 원가
		} else {
			$row['sale_price_fr'] = $class_CommonTour->exchangeMoney_Reverse(array("ext_eng"=>$cf['curunit'],money=>$row['sale_price']));// 판매가
			$row['sale_cost_fr'] = $class_CommonTour->exchangeMoney_Reverse(array("ext_eng"=>$cf['curunit'],money=>$row['sale_cost']));// 원가
		}

		// 사용자용 외국환 체크 (외국환->원화 판매가)
		if($cf['MODE']=="user") {
			if($cf['curunit'] == "KRW") {
				$row['price_sell_fr'] = $row['price_sell'];// 판매가
				$row['price_cost_fr'] = $row['price_cost'];// 원가
				$row['price_ori_fr'] = $row['price_ori'];// 정상가
			} else {
				$row['price_sell_fr'] = $class_CommonTour->exchangeMoney_Reverse(array("ext_eng"=>$cf['curunit'],money=>$row['price_sell']));// 판매가
				$row['price_cost_fr'] = $class_CommonTour->exchangeMoney_Reverse(array("ext_eng"=>$cf['curunit'],money=>$row['price_cost']));// 원가
				$row['price_ori_fr'] = $class_CommonTour->exchangeMoney_Reverse(array("ext_eng"=>$cf['curunit'],money=>$row['price_ori']));// 정상가

			}
		}
		// 외국환체크 (외국환->원화 판매가)
		/*
		if($row['exchange_fg']=="Y") {
			$row['sale_price'] = $class_CommonTour->exchangeMoney(array("exid"=>$row['exid'],money=>$row['price_sell']));// 판매가
			$row['sale_cost'] = $class_CommonTour->exchangeMoney(array("exid"=>$row['exid'],money=>$row['price_cost']));// 원가
			//$row['person_max_price'] = $class_CommonTour->exchangeMoney(array("exid"=>$row['exid'],money=>$row['person_max_price']));// 초과요금
		}
		
		// 사용자용 외국환 체크 (외국환->원화 판매가)
		if($cf['MODE']=="user" and $row['exchange_fg']=="Y") {
			$row['price_sell'] = $class_CommonTour->exchangeMoney(array("exid"=>$row['exid'],money=>$row['price_sell']));// 판매가
			$row['price_cost'] = $class_CommonTour->exchangeMoney(array("exid"=>$row['exid'],money=>$row['price_cost']));// 원가
			$row['price_ori'] = $class_CommonTour->exchangeMoney(array("exid"=>$row['exid'],money=>$row['price_ori']));// 정상가
			$row['price_cost'] = $class_CommonTour->exchangeMoney(array("exid"=>$row['exid'],money=>$row['price_cost']));// 계약가
			//$row['person_max_price'] = $class_CommonTour->exchangeMoney(array("exid"=>$row['exid'],money=>$row['person_max_price']));// 초과요금
		}
		*/

		$data[] = $row;
	}
	return $data;
}


// 일실일 목록 정보 가공
//
// @params $data : Array
// @return : Array
function hotel_date_replace($data="")
{
	global $cf;

	if (!is_array($data)) return false;

	// 외환정보
	$CommonTour_v = new CommonTour();
	
	$yoil = get_yoil($data['room_date'],$cf['lang']);
	$yoil_odr = get_yoil($data['room_date'],"","w");

	if ($yoil_odr==0) { //일요일
		$data['yoil'] =  "<font color='red'>".$yoil."</font>";
	}elseif ($yoil_odr==6) { //토요일
		$data['yoil'] =  "<font color='blue'>".$yoil."</font>";
	}else{
		$data['yoil'] =  $yoil;//평일
	}
	$data['yoil_odr'] = $yoil_odr;

	// 호텔명
	$arr = db_fetch("select hotel_nm, hotel_code from TB_HOTEL where hseq='{$data[h_seq]}' limit 1");
	$data['hotel_nm'] = $arr['hotel_nm'];
	$data['hotel_code'] = $arr['hotel_code'];
	
	// 룸타입
	$sql = "select room_type, room_info, person_num, person_maxnum from TB_HOTEL_ROOMTYPE where h_seq='".$data['h_seq']."' and ridx='".$data['r_idx']."' limit 1";
	$arr = db_fetch($sql);
	$data['room_type'] = $arr['room_type'];
	$data['room_info'] = $arr['room_info'];
	$data['person_num'] = $arr['person_num'];
	$data['person_maxnum'] = $arr['person_maxnum'];
	//$data['person_max_price']
	//2019-10-18 가격 -> 각 통화가격변환
	if($cf['curunit'] == "KRW") {
		$data['person_max_price_fr'] = $data['person_max_price'];// 기준인원초과금
	} else {
		$data['person_max_price_fr'] = $CommonTour_v->exchangeMoney_Reverse(array("ext_eng"=>$cf['curunit'],money=>$data['person_max_price']));// 판매가
	}

	//$data['person_max_price'] = ($data['exchange_fg']=="Y") ? $CommonTour_v->exchangeMoney(array("exid"=>$data['exid'],"money"=>$data['person_max_price'])):$data['person_max_price'];

	
	// 옵션상품 정보
	$hotel_option_arr = explode("||",$data['d_option_ga']);
	if(is_array($hotel_option_arr)) {
		foreach($hotel_option_arr as $v){
			$option_arr = explode("^",$v);
			if($option_arr[0]) {
				$price_sell		= intval($option_arr[2]);
				$price_agent 	= intval($option_arr[3]);		
				$price_cost 	= intval($option_arr[3]);	

				//2019-10-18 원화를 각 통화금액으로 변환
				if($cf['curunit'] == "KRW") {
					$price_sell_fr = $price_sell;
					//$price_agent_fr = $price_agent;
					//$price_cost_fr = $price_cost;
				} else {
					$price_sell_fr = $CommonTour_v->exchangeMoney_Reverse(array("ext_eng"=>$cf['curunit'],"money"=>$price_sell));
					$price_agent_fr = $CommonTour_v->exchangeMoney_Reverse(array("ext_eng"=>$cf['curunit'],"money"=>$price_agent));
					$price_cost_fr = $CommonTour_v->exchangeMoney_Reverse(array("ext_eng"=>$cf['curunit'],"money"=>$price_cost));

				}

				// 외환체크(201702-13.허종)
// 				if($data['exchange_fg']=="Y"){
// 					$price_sell = $CommonTour_v->exchangeMoney(array("exid"=>$data['exid'],"money"=>$price_sell));
// 					$price_agent = $CommonTour_v->exchangeMoney(array("exid"=>$data['exid'],"money"=>$price_agent));
// 					$price_cost = $CommonTour_v->exchangeMoney(array("exid"=>$data['exid'],"money"=>$price_cost));
// 				}
				
				$data['option_all'][] = array(
					'opid'						=> $option_arr[0],
					'op_nm'					=> $option_arr[1],
					'op_price_sell'			=> $price_sell,
					'op_price_agent'		=> $price_agent,
					'op_price_cost'			=> $price_cost,
					'op_price_sell_fr'			=> $price_sell_fr,
					'op_price_agent_fr'		=> $price_agent_fr,
					'op_price_cost_fr'			=> $price_cost_fr
				);
				
			}
		}
	}


	// 베드타입
	$room_bedtype_arr = explode("||",$data['room_bedtype']);
	foreach($room_bedtype_arr as $bedtype) {
		if($bedtype) $data['room_bedtype_all'][] = $bedtype;
	}

	return $data;
}

/*--------------------------------------------------------------
@brief : 호텔별 옵션정보
@parameters : hseq : 호텔 마스터 seq
							opid : 옵션상품 id
@return :
------------------------------------------------------------ */
function hotel_option($hseq,$opid="",$disp_yn="")
{
	global $cf;
	$data = array();
	$table = "TB_HOTEL_OPTION";

	$sql = "select * from {$table} where hseq='{$hseq}'  ";
	if ($opid) $sql .= " and opid='{$opid}' ";
	if ($disp_yn) $sql .= " and disp_yn='{$disp_yn}' ";
	$sql .= " order by order_num , opid desc ";

	$rs = db_query($sql);

	while ($row = db_fetch_array($rs)) {
		// 사용 flag
		if ($row['disp_yn'] == "N") {
			$row['disp_yn_icon'] = $cf['icon']['stop'];
			$row['disp_yn_opp'] = "Y";
		} else {
			$row['disp_yn_icon'] = $cf['icon']['start'];
			$row['disp_yn_opp'] = "N";
		}

		$data[] = $row;
	}
	return $data;
}

//
// 입실일의 첫 Y-m-d, 마지막 Y-m-d
//
// @params hseq : 호텔 마스터 id
// @params sql_where : 
// @return Array();
function hotelDateMinMax($hseq,$sql_where="")
{
	$y = date("Y");

	if (!$hseq) return;

	$sql = "select MIN(room_date) AS first_dt, MAX(room_date) AS last_dt 
			from TB_HOTEL_DATE 
			where h_seq='{$hseq}' {$sql_where} ";

	$data = db_fetch($sql);

	if (!$data['first_dt']) $data['first_dt']=date("Y-m-d");
	if (!$data['last_dt']) $data['last_dt']=date("Y-m-d");

	$tmp_arr = explode("-",$data['first_dt']);

	// 현재년도와 5년이상 차이나면 현재년도에서 5년전 생성
	if (($y - $tmp_arr[0]) > 5) { 
		$data['first_dt1'] = $y-5;
	}else{
		$data['first_dt1'] = $tmp_arr[0];//년
	}
	$data['first_dt2'] = $tmp_arr[1];//월
	$data['first_dt3'] = $tmp_arr[2];//일

	$tmp_arr = explode("-",$data['last_dt']);
	$data['last_dt1'] = $tmp_arr[0];//년
	$data['last_dt2'] = $tmp_arr[1];//월
	$data['last_dt3'] = $tmp_arr[2];//일

	return $data;
}

//
// 입실일 폼값 셋팅
//
// @params hseq : 호텔ID
// @params ridx : 룸타입ID
// @params room_date : 입실일(0000-00-00)
// @params room_date_out : 퇴실일(0000-00-00)
// @params room_cnt : 룸수
// @params room_day : 박수
// @params agent_id : 대리점ID
// 
// return array : 룸수,박수,투숙인원(성인/소인)
function hotelSetDateCheckRoom($rdata="")
{
	global $cf;
	
	$data = array();
	
	if (!is_array($rdata)) return $data;

	// 환율체크 class
	$CommonTour_v = new CommonTour();

	
	// 리턴할 값 초기화
	$r_room_cnt_arr		= Array(); // 전체룸의 입실가능 룸수
	$r_price_sell			= 0 ;// 객실 단가
	$r_room_cnt			= 0; // 세팅 룸수
	$r_room_day			= 0; // 세팅 박수
	$r_adult_num			= 0; // 기본인원
	$r_adult_maxnum		= 0; // 최대인원
	$r_child_num			= 0; // 소인인원
	$r_price_tot			= 0; // 룸가격
	$r_sales_total			= 0; // 총판매가
	$r_cost_tot				= 0; // 룸원가
	$r_cost_total			= 0; // 총판매원가
	$r_agent_tot				= 0; // 룸거래처가
	$r_agent_total			= 0; // 총판매원가

	//2019-10-18 외화
	$r_price_sell_fr			= 0 ;// 객실 단가
	$r_price_tot_fr			= 0; // 룸가격
	$r_sales_total_fr			= 0; // 총판매가
	$r_cost_tot_fr				= 0; // 룸원가
	$r_cost_total_fr			= 0; // 총판매원가


	// 필수 파라메터 체크
	if (!$rdata[hseq] or !$rdata[ridx] or !$rdata[room_date]) return $data;
	
	// 퇴실일 지정
	if ($rdata['room_date_out']) {
		$r_room_date_out = $rdata['room_date_out'];
	}
	
	// 퇴실일 미지정
	else {
		if(!$rdata['room_day']) $r_room_date_out = date("Y-m-d",strtotime($rdata[room_date]." +1 day"));
		else $r_room_date_out = date("Y-m-d",strtotime($rdata[room_date]." +{$rdata[room_day]} day"));
	}
	
	// 일실일에서 퇴실일까지 입실일 정보
	$sql_where = " and r_idx='{$rdata[ridx]}' and room_date between '{$rdata[room_date]}' and '{$r_room_date_out}' ";
	$data_room = hotel_date($rdata[hseq],$sql_where);
	
	// 입실일에서 퇴실일까지 전구간 날짜
	$data_dd = date_to_date($rdata['room_date'],$r_room_date_out,"N");
	
	// 룸타입
	$row_roomtype = db_fetch("select * from TB_HOTEL_ROOMTYPE where ridx='".$rdata[ridx]."' ");	
	
	$sw = true;
	$ag_sw = true; // 대리점 첫날 객단가 리턴 하기위한 switch文
	if (is_array($data_dd)) {
		foreach ($data_dd as $row_dd) {
			if ($sw==true) { 
					for($i=0 ; $i<count($data_room) ; $i++) {
						$row_room = $data_room[$i];
							
						if($row_room['room_date']==$row_dd['date'] and $row_room['reserv_yn']=="Y") {
							
							// 초기값 세팅
							$r_room_day++; // 박수
							$r_room_cnt_arr[] = $row_room['reserv_room_cnt'];
							//$price_sell				= (int)$row_room['price_sell']; // 판매가
							//$price_cost				= (int)$row_room['price_cost']; // 원가
							$price_cost				= (int)$row_room['sale_cost']; // 원가(외환체크)
							$price_agent				= (int)$row_room['sale_agent']; // 원가(외환체크)
							$price_sell				= (int)$row_room['sale_price']; // 판매가(외환체크)
					
							$r_price_cost_arr[]	= $price_cost;
							$r_price_agent_arr[]	= $price_agent;
							$r_price_sell_arr[]	= $price_sell;

							//2019-10-18 외화
							$price_sell_fr				= (int)$row_room['sale_price_fr']; // 판매가(외환체크)
							$price_cost_fr				= (int)$row_room['sale_cost_fr']; // 원가(외환체크)
					
							$r_price_sell_arr_fr[]	= $price_sell_fr;

							
							// 대리점
							if ($rdata['agent_id']) {
								if(is_array($row_room['agent_all'])){
									foreach ($row_room['agent_all'] as $r) {
										
										if ($r['agent_id']==$rdata['agent_id']) {
											$price_sell = (int)$r['agent_price'];
											if ($ag_sw==true) { 
												$r_price_sell = (int)$r['agent_price'];
												$ag_sw=false; }
										}
										
									}
								}
							}

							// 객단가
							// 모든 입실일중 첫날 객단가만 리턴							
							else{
								if ($r_price_sell==0) $r_price_sell = $row_room['sale_price'];
								//외화
								if ($r_price_sell_fr==0) $r_price_sell_fr = $row_room['sale_price_fr'];

							}

							// 투숙인원 세팅
							if($r_adult_num==0 and $rdata['room_cnt']>0) { 
								$r_adult_num		= (int)$row_room['adult_num'] * (int)$rdata['room_cnt'];  
								$r_adult_maxnum = (int)$row_room['adult_maxnum'] * (int)$rdata['room_cnt']; 
								//$r_child_num		= $r_adult_maxnum - 1; // 소인인원 = 대인최대인원-1
								$r_child_num		= $row_roomtype['child_maxnum'] * (int)$rdata['room_cnt']; // (2017-04-11.허종)
							}
								
							// 룸 가격 & 원가
							$r_cost_tot		+= $price_cost * (int)$rdata['room_cnt'];
							$r_agent_tot		+= $price_agent * (int)$rdata['room_cnt'];
							$r_price_tot	+= $price_sell * (int)$rdata['room_cnt'];
							//외화
							$r_price_tot_fr	+= $price_sell_fr * (int)$rdata['room_cnt'];
							$r_cost_tot_fr		+= $price_cost_fr * (int)$rdata['room_cnt'];

							
							// 총판매가 & 총판매원가
							$r_cost_total	+= $r_cost_tot;
							$r_agent_total	+= $r_agent_tot;
							$r_sales_total	+= $r_price_tot;
							//외화
							$r_cost_total_fr	+= $r_cost_tot_fr;
							$r_sales_total_fr	+= $r_price_tot_fr;

							$sw=true;
								
							break;
						} else $sw=false;
							
					} // for
			}
		} // foreach
	}
	
	// 룸수 정렬
	sort($r_room_cnt_arr);
	
	// 최소 룸수
	$r_room_cnt = ($r_room_cnt_arr[0]>0) ? $r_room_cnt_arr[0] : 0;
	
	$data = array(
			'r_price_sell'				=> $r_price_sell,
			'r_room_date_out'			=> $r_room_date_out,
			'r_room_cnt'				=> $r_room_cnt,
			'r_room_day'				=> $r_room_day,
			'r_adult_num'				=> $r_adult_num,
			'r_adult_maxnum'			=> $r_adult_maxnum,
			'r_child_num'				=> $r_child_num,
			'r_cost_tot'					=> $r_cost_tot,
			'r_price_tot'					=> $r_price_tot,
			'r_sales_total'				=> $r_sales_total,
			'r_cost_total'				=> $r_cost_total,
			'r_is_room'					=> $sw, // 예약불가 false
			'r_price_cost_arr'			=> $r_price_cost_arr, // 공급가 20210123
			'r_price_agent_arr'		=> $r_price_agent_arr, // 거래처가 20210123
			'r_price_sell_arr'			=> $r_price_sell_arr, // 판매가

			//2019-10-18 외화
			'r_price_sell_fr'				=> $r_price_sell_fr,
			'r_price_tot_fr'					=> $r_price_tot_fr,
			'r_sales_total_fr'				=> $r_sales_total_fr,
			'r_cost_tot_fr'					=> $r_cost_tot_fr,
			'r_cost_total_fr'				=> $r_cost_total_fr,
			'r_price_sell_arr_fr'			=> $r_price_sell_arr_fr // 판매가

	);
	
	return $data;
}

//
// 호텔예약금액 검증(Validation)
//
// @params hseq : 호텔ID
// @params ridx : 룸타입ID
// @params room_date : 입실일(0000-00-00)
// @params room_cnt : 룸수
// @params room_day : 박수
// @params room_over_num : 초과(투숙)인원
// @params person_max_price : 기준인원 초과금
// @params room_cnt : 룸수
// @params room_day : 박수
// @params agnet_id : 대리점ID
// @params option_arr : 옵션상품 array()
//
// return sales_total
function hotelDateRoomChkVal($rdata="")
{
	global $cf;	

	// 환율체크 class
	$CommonTour_v = new CommonTour();

	$data = array();
	
	if (!is_array($rdata)) return $data;

	$sales_total= 0;// 총객실가
	$option_tot	= 0;// 옵션상품계
	$over_tot		= 0;// 초과금
	$price_tot	= 0;// 객실가
	
	$option_cost_tot	= 0;// 옵션원가계(2016-03-22)

	//외화
	$sales_total_fr= 0;// 총객실가
	$option_tot_fr	= 0;// 옵션상품계
	$over_tot_fr		= 0;// 초과금
	$price_tot_fr	= 0;// 객실가
	
	$option_cost_tot_fr	= 0;// 옵션원가계(2016-03-22)

		 
	// 객실가 계산
	$room_date = hotelSetDateCheckRoom($rdata);
	$price_tot = $room_date['r_price_tot']; // 객실가
	$cost_tot  = $room_date['r_cost_tot']; // 객실원가
	//외화
	$price_tot_fr = $room_date['r_price_tot_fr']; // 객실가
	$cost_tot_fr  = $room_date['r_cost_tot_fr']; // 객실원가


	// 초과금 계산
	$over_tot = (int)$rdata['room_over_num'] * (int)$rdata['person_max_price'] * (int)$rdata['room_cnt'] * (int)$rdata['room_day']; 
	// 초과금 계산 외화
	$over_tot_fr = (int)$rdata['room_over_num'] * (int)$rdata['person_max_price_fr'] * (int)$rdata['room_cnt'] * (int)$rdata['room_day']; 

	// 옵션가 계산
	if (is_array($rdata['option_arr'])) {
		foreach ($rdata['option_arr'] as $v) {
			
			if ($v['op_num']>0) {
				// 대리점 옵션판매
				if($rdata['agent_id']) {
					$option_tot += (int)$v['op_price_agent'] * (int)$v['op_num'];
				}
					
				// 옵션판매
				else{
					$option_tot += (int)$v['op_price_sell'] * (int)$v['op_num'];
					//외화
					$option_tot_fr += (int)$v['op_price_sell_fr'] * (int)$v['op_num'];
				}

				// 판매원가(2016-03-22)
				$option_cost_tot += (int)$v['op_price_cost'] * (int)$v['op_num'];
				//외화
				$option_cost_tot_fr += (int)$v['op_price_cost_fr'] * (int)$v['op_num'];

			}
			
		}
	}

	// 초과금 계산
	$over_tot = $rdata['room_over_num'] * $rdata['person_max_price'] * $rdata['room_cnt'] * $rdata['room_day'];
	// 외화 초과금 계산
	$over_tot_fr = $rdata['room_over_num'] * $rdata['person_max_price_fr'] * $rdata['room_cnt'] * $rdata['room_day'];

	// 판매가(★★★)
	$sales_total = (int)($price_tot) + (int)($over_tot) + (int)($option_tot);
	// 외화 판매가(★★★)
	$sales_total_fr = (int)($price_tot_fr) + (int)($over_tot_fr) + (int)($option_tot_fr);

	// 판매원가(★)
	$sales_total_cost = (int)$cost_tot + (int)($over_tot) + (int)($option_cost_tot);
	//외화 판매원가(★)
	$sales_total_cost_fr = (int)$cost_tot_fr + (int)($over_tot_fr) + (int)($option_cost_tot_fr);

	$data = array('sales_total'=>$sales_total,'sales_total_cost'=>$sales_total_cost,'sales_total_fr'=>$sales_total_fr,'sales_total_cost_fr'=>$sales_total_cost_fr);

	return $data;
}

//
// 호텔예약 및 입실정보 저장
//
// @params rdata : array()
//
// return true
function hotelRoomDateIns($rdata="")
{
	global $TO_MB,$cf;

	$table = "TB_RES_HOTEL";
	$data = array();
	
	if(!is_array($rdata)) return $data;
	
	if($cf['lang'])			$lang = $cf['lang'];
	if($rdata['lang'])	$lang = $rdata['lang'];


	if(!$rdata['res_no']) $rdata['res_no'] = auto_create_code("L");
	if(!$rdata['rsv_no']) $rdata['rsv_no'] = auto_create_voucher("L");

	$rdata['price_tot']						= str_replace(",","",$rdata['price_tot']); // 룸가격
	$rdata['over_tot']							= str_replace(",","",$rdata['over_tot']); // 초과금
	$rdata['option_tot']						= str_replace(",","",$rdata['option_tot']); // 옵션가격
	$rdata['sales_total']						= str_replace(",","",$rdata['sales_total']); // 총판매가
	$rdata['person_max_price']				= str_replace(",","",$rdata['person_max_price']); // 기준인원 초과금
	//외화
	$rdata['price_tot_fr']						= str_replace(",","",$rdata['price_tot_fr']); // 룸가격
	$rdata['over_tot_fr']							= str_replace(",","",$rdata['over_tot_fr']); // 초과금
	$rdata['option_tot_fr']						= str_replace(",","",$rdata['option_tot_fr']); // 옵션가격
	$rdata['sales_total_fr']						= str_replace(",","",$rdata['sales_total_fr']); // 총판매가
	$rdata['person_max_price_fr']				= str_replace(",","",$rdata['person_max_price_fr']); // 기준인원 초과금


	// 호텔정보
	$data_hotel = hotel_list(" and hseq='{$rdata[hseq]}' ");
	$row_hotel = $data_hotel[0];

	// 입실일 정보
	$data_date = hotel_date($rdata['hseq']," and r_idx='{$rdata[ridx]}' and hdidx='{$rdata[hdidx]}' ");
	$row_date = hotel_date_replace($data_date[0]); 

	// 대리점
	if ($rdata['agent_id']) $row_member = get_member($rdata['agent_id']);

	// 담당자
	if ($rdata['admin_id']) $row_admin = get_member($rdata['admin_id']);


	// 옵션상품
	$option_arr = array();
	for ($i=0 ; $i<count($rdata['opid_arr']) ; $i++) {
			$option_arr[] = array (
				'opid'						=> $rdata['opid_arr'][$i],
				'op_num'					=> $rdata['op_num_arr'][$i],
				'op_nm'						=> $rdata['op_nm_arr'][$i],
				'op_price_sell'		=> str_replace(",","",$rdata['op_price_sell_arr'][$i]),
				'op_price_sell_fr'		=> str_replace(",","",$rdata['op_price_sell_arr_fr'][$i]),
				'op_price_agent'	=> str_replace(",","",$rdata['op_price_agent_arr'][$i]),
				'op_price_cost'		=> str_replace(",","",$rdata['op_price_cost_arr'][$i])
		);
	}

	// 호텔예약금액 검증(Validation)
	$arr = array('hseq'								=> $rdata['hseq'],
							'ridx'							=> $rdata['ridx'],
							'room_date'					=> $rdata['room_date'],
							'room_date_out'			=> $rdata['room_date_out'],
							'room_cnt'					=> $rdata['room_cnt'],
							'room_day'					=> $rdata['room_day'],
							'room_over_num'			=> $rdata['room_over_num'], 
							'person_max_price'		=> $rdata['person_max_price'],
							'person_max_price_fr'		=> $rdata['person_max_price_fr'],
							'agent_id'					=> $rdata['agent_id'],
							'option_arr'					=> $option_arr);

	$data_res = hotelDateRoomChkVal($arr);
	if ($data_res['sales_total'] != $rdata['sales_total']) error_msg("alert('예약정보가 정확하지 않습니다.다시한번 확인해 주세요.');","script");

	// 입실일 정보
	$room_date_out2 = date("Y-m-d",strtotime($rdata['room_date_out']." -1 day"));
	$sql_where = " and r_idx='{$rdata[ridx]}' and room_date between '{$rdata[room_date]}' and '{$room_date_out2}' ";
	$data_room = hotel_date($rdata[hseq],$sql_where);

	// 입실일ID(hdidx) 저장
	$hdidx_ga = "";
	foreach ($data_room as $v) {
		$hdidx_ga .= $v['hdidx'].",";

		$buy_total += ($v['sale_cost'] * $rdata['room_cnt']);
	}
	
	// 적립금정보
	$row_room = $data_room[0];

	// 예약경로
	if (!$rdata['ins_route']) $rdata['ins_route'] = "A"; // A관리자,A1상담관리,B사용자,C사용자모바일

	//예약확정
	$res_stat_cd = "C";
	$order_state = "C"; // 신청 시 예약확정 > 입금대기 로 변경 210217


	// 예약마스터 저장
	$sql = "insert into {$table} set ";
	$sql .= " res_no					= '{$rdata[res_no]}',";
	$sql .= " rsv_no					= '{$rdata[rsv_no]}',";
	$sql .= " cseq						= '{$rdata[cseq]}',";
	$sql .= " hseq						= '{$rdata[hseq]}',";
	$sql .= " hnm						= '{$row_hotel[hotel_nm]}',";
	$sql .= " ridx						= '{$rdata[ridx]}',";
	$sql .= " rnm						= '{$row_date[room_type]}',";
	$sql .= " hdidx						= '{$rdata[hdidx]}',"; 
	$sql .= " room_date				= '{$rdata[room_date]}',";
	$sql .= " room_date_out		= '{$rdata[room_date_out]}',";
	$sql .= " room_cnt				= '{$rdata[room_cnt]}',";
	$sql .= " room_day				= '{$rdata[room_day]}',";
	$sql .= " room_adult_num		= '{$rdata[room_adult_num]}',";
	$sql .= " room_child_num		= '{$rdata[room_child_num]}',";
	$sql .= " room_over_num		= '{$rdata[room_over_num]}',";
	$sql .= " room_bedtype			= '{$rdata[room_bedtype]}',";
	$sql .= " price_tot				= '{$rdata[price_tot]}',";
	$sql .= " option_tot				= '{$rdata[option_tot]}',";
	$sql .= " over_tot					= '{$rdata[over_tot]}',";
	$sql .= " sales_total				= '{$rdata[sales_total]}',";
	$sql .= " sales_total_cost		= '{$rdata[sales_total_cost]}',"; // 판매원가(2016-03-22)

	$sql .= " buy_total				= '{$buy_total}',"; // 공급가 (20210121)

	$sql .= " price_tot_fr				= '{$rdata[price_tot_fr]}',";
	$sql .= " option_tot_fr				= '{$rdata[option_tot_fr]}',";
	$sql .= " over_tot_fr					= '{$rdata[over_tot_fr]}',";
	$sql .= " sales_total_fr				= '{$rdata[sales_total_fr]}',";

	if($cf[curunit]!='KRW') :
	$sql .= " total_pay_usd				= '{$rdata[total_pay_usd]}',";
	endif;

	$sql .= " person_num				= '{$row_room[person_num]}',"; // 성인기준인원(신규)
	$sql .= " person_maxnum		= '{$row_room[person_maxnum]}',"; // 성인 최대인원(신규)
	$sql .= " child_maxnum			= '{$row_room[child_maxnum]}',"; // 소인 최대인원(신규)	
	
	$sql .= " agent_ga				= '{$row_date[d_agent_ga]}',";
	$sql .= " agent_id					= '{$rdata[agent_id]}',";
	$sql .= " agent_corp_nm		= '{$row_member[bz_corp_nm]}',";
	$sql .= " res_cust_id				= '{$rdata[mb_id]}',";
	$sql .= " res_cust_nm			= '{$rdata[res_cust_nm]}',";
	$sql .= " res_cust_email			= '{$rdata[res_cust_email]}',";
	$sql .= " res_cust_addr			= '{$rdata[res_cust_addr]}',";
	$sql .= " res_cust_tel			= '{$rdata[res_cust_tel]}',";
	$sql .= " res_cust_hp			= '{$rdata[res_cust_hp]}',";
	$sql .= " res_cust_memo		= '{$rdata[res_cust_memo]}',";
	$sql .= " res_cust_nat_cd		= '{$rdata[res_nat_cd]}',";
	$sql .= " res_sns_id		= '{$rdata[res_sns_id]}',";

	//$sql .= " admin_memo='{$rdata[admin_memo]}',";
	//$sql .= " send_memo='{$rdata[send_memo]}',";
	$sql .= " hdidx_ga					= '{$hdidx_ga}',";
	$sql .= " admin_id					= '{$rdata[admin_id]}',";
	$sql .= " admin_nm				= '{$row_admin[mb_nm]}',";
	//$sql .= " edit_dt=now(),";
	//$sql .= " edit_id={$TO_MB[mb_id]},";
	//$sql .= " edit_nm={$TO_MB[mb_nm]},";
	$sql .= " res_stat_cd				= '{$res_stat_cd}',";
	$sql .= " order_state				='{$order_state}',";
	$sql .= " ins_dt					= now(),";
	$sql .= " ins_id						= '{$TO_MB[mb_id]}',";
	$sql .= " ins_nm					= '{$TO_MB[mb_nm]}',";
	$sql .= " ins_ip						= '{$cf['user_ip']}',";
	$sql .= " ins_route				= '{$rdata[ins_route]}',";

	$sql .= " point_yn					= '{$row_room[point_yn]}',";
	$sql .= " point_buy1				= '{$row_room[point_buy1]}',";
	$sql .= " point_buy2				= '{$row_room[point_buy2]}', ";

	//공급처
	$sql .= " producer_id						= '{$row_hotel[producer_id]}',";
	$sql .= " producer_corp_nm						= '{$row_hotel[producer_corp_nm]}',";

	$sql .= " lang				= '{$lang}', ";
	$sql .= " curunit				= '{$cf[curunit]}' ";


	db_query($sql);

	// 옵션상품 저장
	for ($i=0 ; $i<count($option_arr) ; $i++) {
		$r=$option_arr[$i];
		$sql = "insert into {$table}_OPTION set ";
		$sql .= "res_no						= '{$rdata[res_no]}', ";
		$sql .= "opid						= '{$r[opid]}', ";
		$sql .= "hseq						= '{$rdata[hseq]}', ";
		$sql .= "op_nm						= '{$r[op_nm]}', ";
		$sql .= "op_num					= '{$r[op_num]}', ";
		$sql .= "op_price_sell			= '{$r[op_price_sell]}', ";
		$sql .= "op_price_sell_fr			= '{$r[op_price_sell_fr]}', ";
		$sql .= "op_price_agent			= '{$r[op_price_agent]}', ";
		$sql .= "op_price_cost			= '{$r[op_price_cost]}', ";
		$sql .= "ins_dt						= now(), ";
		$sql .= "lang						= '{$cf[lang]}', ";
		$sql .= "curunit						= '{$cf[curunit]}' ";
	
		db_query($sql);
	}
	
	// 룸일자(R) 저장
	##$data_dt=date_to_date($rdata['room_date'] , $rdata['room_date_out'] ,"N");
	foreach($data_room as $v){
		$sql = "insert into TB_RES_HOTEL_ITEM set ";
		$sql .= " gu='R' ";
		$sql .= " ,res_no='{$rdata[res_no]}' ";
		$sql .= " ,hseq='{$rdata[hseq]}' ";
		$sql .= " ,hnm='{$row_hotel[hotel_nm]}' ";
		$sql .= " ,ridx='{$rdata[ridx]}' ";
		$sql .= " ,rnm='{$row_date[room_type]}' ";
		$sql .= " ,item_nm='호텔' ";
		$sql .= " ,room_date='{$v[room_date]}' "; /// 룸일자(이용일자)
		$sql .= " ,buy_price='{$row_date['sale_cost']}' "; // 공급가 (20210121)
		$sql .= " ,sell_price='{$v[price_sell]}' ";
		$sql .= " ,sell_price_fr='{$v[price_sell_fr]}' ";
		$sql .= " ,i_count='{$rdata[room_cnt]}' ";
		$sql .= " ,comt='' ";
		$sql .= " ,ins_dt=now() ";
		$sql .= " ,lang='{$cf[lang]}' ";
		$sql .= " ,curunit='{$cf[curunit]}' ";
		
		db_query($sql);
	}
	
	// 초과인원(U) 항목저장
	foreach($data_room as $v){
		$v=hotel_date_replace($v);
		$sql = "insert into TB_RES_HOTEL_ITEM set ";
		$sql .= " gu='U' ";
		$sql .= " ,res_no='{$rdata[res_no]}' ";
		$sql .= " ,hseq='{$rdata[hseq]}' ";
		$sql .= " ,hnm='{$row_hotel[hotel_nm]}' ";
		$sql .= " ,ridx='{$rdata[ridx]}' ";
		$sql .= " ,rnm='{$row_date[room_type]}' ";
		$sql .= " ,item_nm='객실초과인원' ";
		$sql .= " ,room_date='{$v[room_date]}' "; /// 룸일자(이용일자)
		$sql .= " ,buy_price='0' "; // 공급가 (호텔 입실정보에 초과인원에 대한 공급가 없음 / 수동입력)
		$sql .= " ,sell_price='".$v['person_max_price']."' ";
		$sql .= " ,sell_price_fr='".$v['person_max_price_fr']."' ";
		$sql .= " ,i_count='".intval($rdata['room_over_num'])."' ";
		$sql .= " ,comt='' ";
		$sql .= " ,ins_dt=now() ";
		$sql .= " ,lang='{$cf[lang]}' ";
		$sql .= " ,curunit='{$cf[curunit]}' ";

		db_query($sql);
	}
	
	// 성인 숙박자 저장
	for($i=0 ; $i<intval($rdata['room_adult_num']) ; $i++){
		$sql = "insert into TB_RES_HOTEL_PERSON set ";
		$sql .= " res_no='{$rdata[res_no]}' ";
		$sql .= ",hseq='{$rdata[hseq]}'";
		$sql .= ",hnm='{$row_hotel[hotel_nm]}'";
		$sql .= ",ridx='{$rdata[ridx]}'";
		$sql .= ",rnm='{$row_date[room_type]}'";
		$sql .= ",room_date='{$rdata[room_date]}'";
		$sql .= ",room_date_out='{$rdata[room_date_out]}'";
		$sql .= ",generation='A'";
		$sql .= ",gend=''";
		$sql .= ",name_kor=''";
		$sql .= ",name_eng=''";
		$sql .= ",tel=''";
		$sql .= ",birth=''";
		$sql .= ",passenger_num=''";
		$sql .= ",passenger_expire=''";
		$sql .= ",remarks=''";
		$sql .= ",ins_dt=now()";
		
		db_query($sql);
	}
	
	// 소인 숙박자 저장
	for($i=0 ; $i<intval($rdata['room_child_num']) ; $i++){
		$sql = "insert into TB_RES_HOTEL_PERSON set ";
		$sql .= " res_no='{$rdata[res_no]}' ";
		$sql .= ",hseq='{$rdata[hseq]}'";
		$sql .= ",hnm='{$row_hotel[hotel_nm]}'";
		$sql .= ",ridx='{$rdata[ridx]}'";
		$sql .= ",rnm='{$row_date[room_type]}'";
		$sql .= ",room_date='{$rdata[room_date]}'";
		$sql .= ",room_date_out='{$rdata[room_date_out]}'";
		$sql .= ",generation='C'";
		$sql .= ",gend=''";
		$sql .= ",name_kor=''";
		$sql .= ",name_eng=''";
		$sql .= ",tel=''";
		$sql .= ",birth=''";
		$sql .= ",passenger_num=''";
		$sql .= ",passenger_expire=''";
		$sql .= ",remarks=''";
		$sql .= ",ins_dt=now()";
	
		db_query($sql);
	}	

	// 블록 업데이트
	foreach ($data_room as $v) {
		if($v['hdidx']) db_query("call SP_RES_HOTEL_BLOCK('{$v[hdidx]}','{$rdata[room_cnt]}');");
	}

	$data = $rdata;

	return $data;
}


?>

Anon7 - 2021