ÿØÿà 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/admin/ajaxData/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

Buat Folder Baru:
Buat File Baru:

Current File : /tkt_travelbus/www/admin/ajaxData/index.php
<?php
	include $_SERVER['DOCUMENT_ROOT']."/Lib/config.php";
	include $_SERVER['DOCUMENT_ROOT']."/Lib/common.lib.php";
	include $_SERVER['DOCUMENT_ROOT']."/Lib/connect.php";

	$mode = $_POST['mode'];

//	if(devCookie()){
//		$mode = $_GET['mode'];
//	}

	$time = time() - 120;
	$nowTime = date("Y-m-d H:i:s", $time);
	if($mode == 'newBbs'){
		$sql = "SELECT count(*) AS total FROM QNA WHERE INSDT >= '{$nowTime}' AND MSTEP = 0";
		$row = db_fetch($sql);
		$bbsTotal = $row['total'];

		$sql = "SELECT count(*) AS total FROM TB_INTRA_DATA WHERE INSDT >= '{$nowTime}' AND MSTEP = 0 AND MCATE = 'IVQ'";
		$row = db_fetch($sql);
		$intraCalcuTotal = $row['total'];

		echo json_encode(
			array(
				'result' => true,
				'bbsTotal' => $bbsTotal,
				'intraCalcuTotal' => $intraCalcuTotal,
				'nowTime' => $nowTime,
//				'sql' => $sql,
			)
		);
	}else if($mode == 'modifyWorkRequestStatus'){
		$seq = (int) $_POST['seq'];
		if(!$seq){
			$result = false;
			echo json_encode(
				array(
					'result' => $result,
				)
			);
			exit;
		}

		$workStatusValue = $_POST['workStatusValue'];

		if($workStatusValue != 'Y' && $workStatusValue != 'E' && $workStatusValue != 'N'){
			$result = false;
			echo json_encode(
				array(
					'result' => $result,
				)
			);
			exit;
		}

		$chgTime = date("Y-m-d H:i:s", time());

		$sql = "UPDATE TB_WORK_REQUEST SET CONFIRM_YN = '{$workStatusValue}',STATUS_CHG_DT = '{$chgTime}' WHERE SEQ = {$seq}";

		if(db_query($sql)){
			$result = true;
		}else{
			$result = false;
		}

		echo json_encode(
			array(
				'result' => $result,
//				'sql' => $sql,
			)
		);
	}else if($mode == 'addSubWorkRequest'){
		$parentSeq = $_POST['seq'];
		$subWorkType = $_POST['subWorkType'];
		$subPerformer = $_POST['subPerformer'];
		$subWorkRequestContents = addslashes($_POST['subWorkRequestContents']);
//		$current
//		$mTitle = $parentSeq.'의 서브 업무 요청';
		$mTitle = addslashes($_POST['mtitle']);
		$currentLoginPeopleID = $_POST['currentLoginPeopleID'];
		$currentLoginPersonName = $_POST['currentLoginPersonName'];

		$sql = "INSERT INTO TB_WORK_REQUEST SET MEM_ID = '{$currentLoginPeopleID}', MEM_NM = '{$currentLoginPersonName}',PARENT_SEQ = {$parentSeq}, workType = '{$subWorkType}', performer = '{$subPerformer}', MTITLE='{$mTitle}', MCONT = '{$subWorkRequestContents}', INSDT = NOW() ";

		/*echo json_encode(
			array(
				'result' => true,
				'regTime' => date('Y-m-d', time()),
				'seq' => $sql,
			)
		);
		exit;*/

		if(db_query($sql)){
			$SEQ = db_insert_id();
			echo json_encode(
				array(
					'result' => true,
					'regTime' => date('Y-m-d', time()),
					'seq' => $SEQ,
				)
			);
		}else{
			echo json_encode(
				array(
					'result' => false,
//					'POST' => $_POST,
				)
			);
		}
	}else if($mode == 'newWorkRequest'){
		//새로운 업무요청 알림
		$myID = $_COOKIE['MemberID'];

		$sql = "SELECT count(*) AS total FROM TB_WORK_REQUEST WHERE performer = '{$myID}' AND INSDT >= '{$nowTime}' AND CONFIRM_YN = 'N'";
		$row = db_fetch($sql);
		$cnt = (int) $row['total'];

		echo json_encode(
			array(
				'result' => true,
				'cnt' => $cnt,
			)
		);
	}

	else if($mode == 'smartStoreProductQna'){
		$sql3 = "SELECT count(*) AS cnt FROM smart_store_product_qna WHERE answered = 'N'";
		$smartStoreProductNoAnswerCnt = db_fetch($sql3);
		$smartStoreProductNoAnswerCnt = (int) $smartStoreProductNoAnswerCnt['cnt'];

		echo json_encode(
			array(
				'result' => true,
				'cnt' => $smartStoreProductNoAnswerCnt,
			)
		);
	}

	else if($mode == 'smartStoreCustomerQna'){
		$sql3 = "SELECT count(*) AS cnt FROM smart_store_customer_qna WHERE answered = 'N'";
		$smartStoreCustomerNoAnswerCnt = db_fetch($sql3);
		$smartStoreCustomerNoAnswerCnt = (int) $smartStoreCustomerNoAnswerCnt['cnt'];

		echo json_encode(
			array(
				'result' => true,
				'cnt' => $smartStoreCustomerNoAnswerCnt,
			)
		);
	}


	/*else if($mode == 'WorkRequestStart'){
		//새로운 업무요청 알림
		$myID = $_COOKIE['MemberID'];

		$sql = "SELECT count(*) AS total FROM TB_WORK_REQUEST WHERE performer = '{$myID}' AND INSDT >= '{$nowTime}' AND CONFIRM_YN = 'N'";
		$row = db_fetch($sql);
		$cnt = (int) $row['total'];

		echo json_encode(
			array(
				'result' => true,
				'cnt' => $cnt,
			)
		);
	}*/


	else if($mode == 'subWorkRequestCheckCompleted') {
		//요청한 업무의 상태 체크
		$myID = $_COOKIE['MemberID'];

		$sql = "SELECT count(*) AS total FROM TB_WORK_REQUEST WHERE MEM_ID = '{$myID}' AND PARENT_SEQ <> 0 AND STATUS_CHG_DT >= '{$nowTime}' AND CONFIRM_YN = 'Y'";
		$row = db_fetch($sql);
		$cnt = (int) $row['total'];

		echo json_encode(
			array(
				'result' => true,
				'cnt' => $cnt,
			)
		);
	}else if($mode == 'delSubWorkRequestContents'){
		$seq = (int) $_POST['seq'];
		$sql = "DELETE FROM TB_WORK_REQUEST WHERE SEQ = {$seq}";

		$result = false;

		if(db_query($sql)){
			$result = true;

		}

		echo json_encode(
			array(
				'result' => $result,
//				'sql' => $sql,
			)
		);
	}else if($mode == 'modifyConfirmYN'){
		$seq = (int) $_POST['seq'];
		$confirmValue = $_POST['confirmValue'];

		if($confirmValue != 'Y' && $confirmValue != 'N' && $confirmValue != 'E'){
			echo json_encode(
				array(
					'result' => false,
				)
			);
			exit;
		}

		$sql = "UPDATE TB_WORK_REQUEST SET CONFIRM_YN = '{$confirmValue}' WHERE SEQ = {$seq}";
		$result = false;

		if(db_query($sql)){
			$result = true;
		}

		echo json_encode(
			array(
				'result' => $result,
//				'sql' => $sql,
			)
		);
	}else if($mode == 'modifyNaverCheckIn'){
		$isChecked = $_POST['isChecked'];
		$adminNm = $_POST['adminNm'];
		$adminId = $_POST['adminId'];

		$adminNmSql = "";
		$adminIdSql = "";

		if($adminNm){
			$adminNmSql = ", admin_nm = '{$adminNm}'";
		}

		if($adminId){
			$adminIdSql = ", admin_id = '{$adminId}'";
		}

		if($isChecked != 'Y' && $isChecked != 'N'){
			echo json_encode(
				array(
					'result' => false,
					'data' => $_POST,
				)
			);
			exit;
		}
		$resNo = $_POST['resNo'];
		if(!$resNo){
			echo json_encode(
				array(
					'result' => false,
					'data' => $_POST,
				)
			);
			exit;
		}

		$result = false;

		$sql = "UPDATE TB_RES_GOOD SET checkInNaver = '{$isChecked}'{$adminNmSql}{$adminIdSql} WHERE res_no = '{$resNo}'";
		if(db_query($sql)){
			$result = true;
		}

		echo json_encode(
			array(
				'result' => $result,
//				'sql' => $sql,
			)
		);
		exit;
	}


	else if($mode == 'starbucksCouponCheck'){
		$isChecked = $_POST['isChecked'];

		$adminNm = $_POST['adminNm'];
		$adminId = $_POST['adminId'];

		$adminNmSql = "";
		$adminIdSql = "";

		/*if($adminNm){
			$adminNmSql = ", admin_nm = '{$adminNm}'";
		}

		if($adminId){
			$adminIdSql = ", admin_id = '{$adminId}'";
		}*/

		if($isChecked != 'Y' && $isChecked != 'N'){
			echo json_encode(
				array(
					'result' => false,
					'data' => $_POST,
				)
			);
			exit;
		}
		$resNo = $_POST['resNo'];
		if(!$resNo){
			echo json_encode(
				array(
					'result' => false,
					'data' => $_POST,
				)
			);
			exit;
		}

		$result = false;

//		$sql = "UPDATE TB_RES_GOOD SET checkInNaver = '{$isChecked}'{$adminNmSql}{$adminIdSql} WHERE res_no = '{$resNo}'";

		$sql = "UPDATE TB_RES_GOOD SET starbucks_coupon = '{$isChecked}', starbucks_coupon_ins_id = '{$adminNm}' WHERE res_no = '{$resNo}'";

		if(db_query($sql)){
			$result = true;
		}

		echo json_encode(
			array(
				'result' => $result,
				'sql' => $sql,
			)
		);
		exit;
	}







	else if($mode == 'fromZiplineDateModify'){
		$sql = "SELECT count(*) AS total FROM `zipline_date_mod_log` WHERE regTime >= {$time}";
		$row = db_fetch($sql);
		$cnt = (int) $row['total'];

		echo json_encode(
			array(
				'result' => true,
				'cnt' => $cnt,
				'sql' => $sql,
			)
		);
	}




	else if($mode == 'modifyCheckConfirmation'){
		$isChecked = $_POST['isChecked'];
		$adminNm = $_POST['adminNm'];
		$adminId = $_POST['adminId'];

		$adminNmSql = "";
		$adminIdSql = "";

		if($adminNm){
			$adminNmSql = ", admin_nm = '{$adminNm}'";
		}

		if($adminId){
			$adminIdSql = ", admin_id = '{$adminId}'";
		}

		if($isChecked != 'Y' && $isChecked != 'N'){
			echo json_encode(
				array(
					'result' => false,
					'data' => $_POST,
				)
			);
			exit;
		}
		$resNo = $_POST['resNo'];
		if(!$resNo){
			echo json_encode(
				array(
					'result' => false,
					'data' => $_POST,
				)
			);
			exit;
		}

		$result = false;

		$sql = "UPDATE TB_RES_GOOD SET checkConfirmation = '{$isChecked}'{$adminNmSql}{$adminIdSql} WHERE res_no = '{$resNo}'";
		if(db_query($sql)){
			$result = true;
		}

		echo json_encode(
			array(
				'result' => $result,
//				'sql' => $sql,
			)
		);
		exit;
	}else if($mode == 'translatePapago'){

		$korKeyword = $_POST['korKeyword'];
		$targetLang = $_POST['targetLang'];


		$translateWord = papago($korKeyword,$targetLang);

		$result = false;
		if($translateWord){
			$result = true;
		}
		echo json_encode(
			array(
				'result' => $result,
				'translateWord' => $translateWord,
			)
		);
		exit;
	}else if($mode == 'translatePapagoWithStartLang'){

		$korKeyword = $_POST['korKeyword'];
		$startLang = $_POST['startLang'];
		$targetLang = $_POST['targetLang'];


		$translateWord = papago($korKeyword,$targetLang,$startLang);

		$result = false;
		if($translateWord){
			$result = true;
		}
		echo json_encode(
			array(
				'result' => $result,
				'translateWord' => $translateWord,
			)
		);
		exit;
	}


	else if($mode == 'modifyDepartScheduleView'){
		$result = false;

		$isChecked = $_POST['isChecked'];
		$g_uid = (int) $_POST['g_uid'];

		if($g_uid && ($isChecked == 'Y' || $isChecked == 'N')){

			if($isChecked == 'Y'){
				$is_depart_schedule_show = 'Y';
			}else{
				$is_depart_schedule_show = 'N';
			}

			$sql = "UPDATE good SET is_depart_schedule_show = '{$is_depart_schedule_show}' WHERE g_uid = {$g_uid}";

//			$result = true;

			if(db_query($sql)){
				$result = true;
			}else{
				$result = false;
			}

			echo json_encode(
				array(
					'result' => $result,
					'isChecked' => $isChecked,
					'g_uid' => $g_uid,
//					'sql' => $sql,
				)
			);
		}else{
			echo json_encode(
				array(
					'result' => $result,
				)
			);
		}
		exit;
	}else if($mode == 'callRecentlyTicketGroupTicketNumber'){
		$groupCode = $_POST['groupCode'];

		if(!$groupCode){
			echo json_encode(
				array(
					'result' => false,
				)
			);
			exit;
		}

		$ticket_number = '';
		$sql = "SELECT ticket_number FROM TB_TICKET WHERE group_code = '{$groupCode}' ORDER BY seq DESC LiMIT 1";
		$rs = db_query($sql);
		$row = db_fetch_array($rs);

		$result = false;

		if($row){
			$result = true;
		}

		$ticket_number = $row['ticket_number'];

		echo json_encode(
			array(
				'result' => $result,
				'ticket_number' => $ticket_number,
			)
		);

		exit;
	}else if($mode == 'setDepartScheduleData') {


		$g_uid = (int)$_POST['g_uid'];

		if ($g_uid) {
			$remaining_seats = (int)$_POST['remaining_seats'];
			$wait_depart = (int)$_POST['wait_depart'];
			$confirmed_depart = (int)$_POST['confirmed_depart'];

			$sql = "UPDATE good SET remaining_seats = {$remaining_seats}, wait_depart = {$wait_depart}, confirmed_depart = {$confirmed_depart} WHERE g_uid = {$g_uid}";

			$result = false;
			if (db_query($sql)) {
				$result = true;
			}

			echo json_encode(
				array(
					'result' => $result,
					'sql' => $sql,
					'remaining_seats' => $remaining_seats,
					'wait_depart' => $wait_depart,
					'confirmed_depart' => $confirmed_depart,
				)
			);
			exit;
		} else {
			echo json_encode(
				array(
					'result' => false,
				)
			);
			exit;
		}
	}else if($mode == 'setDepartScheduleGuideName'){
		$guideName = $_POST['guideName'];
		$g_uid = (int)$_POST['g_uid'];

		if($g_uid){

			$sql = "UPDATE good SET guide_name = '{$guideName}' WHERE g_uid = {$g_uid}";

			$result = false;
			if (db_query($sql)) {
				$result = true;
			}


			echo json_encode(
				array(
					'result' => $result,
//					'sql' => $sql,
				)
			);
			exit;

		}else{
			echo json_encode(
				array(
					'result' => false,
				)
			);
			exit;
		}
	}else if($mode == 'issueTicketFailedCnt'){



//		$sql = "SELECT * FROM TB_RES_GOOD WHERE ";
		/*if($row['tab'] == 'T' && $row['order_state'] == 'B'){

			$row_ticket = TO_list_ticket($row['rsv_no'], $sql_where="");

			if($row_ticket){

			}else{
				$issueTicketFailedCnt++;
			}
		}*/
	}else if($mode == 'setTourDepartResBus'){



		$tableName = "tour_depart_res_bus";
		$d_uid = (int) $_POST['d_uid'];

		$tourTypeColor = $_POST['thisColor'];

		$sqlWhereNormalBusResStartTime = "";

		$normalBusResStartTime = $_POST['normalBusResStartTime'];

		/*if(isset($_POST['normalBusResStartTime'])){
			if($_POST['normalBusResStartTime']){

				$sqlWhereNormalBusResStartTime = ", startTime = '{$normalBusResStartTime}'";
			}
		}*/

		if(!$d_uid){
			echo json_encode(
				array(
					'result' => false,
				)
			);
			exit;
		}

		$resMemo = $_POST['resMemo'];
		$isBusCheck = $_POST['isBusCheck'];

		$ins_id = $_POST['ins_id'];

		$sql = "SELECT count(*) as total FROM {$tableName} WHERE d_uid = {$d_uid}";
		$rs = db_fetch($sql);
		$total = (int) $rs['total'];

		if($total > 0){
			//update
			$sql = "UPDATE {$tableName} SET tourTypeColor = '{$tourTypeColor}', chk_res_bus = '{$isBusCheck}', memo = '{$resMemo}', ins_id = '{$ins_id}', startTime = '{$normalBusResStartTime}', ins_dt = now() WHERE d_uid = {$d_uid}";
		}else{
			//insert
			$sql = "INSERT INTO {$tableName} SET tourTypeColor = '{$tourTypeColor}', chk_res_bus = '{$isBusCheck}', memo = '{$resMemo}', ins_id = '{$ins_id}', d_uid = {$d_uid}, startTime = '{$normalBusResStartTime}', ins_dt = now()";
		}

		$isResult = false;

		if(db_query($sql)){
			$isResult = true;
		}

		echo json_encode(
			array(
				'result' => $isResult,
				'data' => $rs,
				'total' => $total,
				'sql' => $sql,
			)
		);

		exit;
	}

	//일반 예약 버스 가이드 정보 저장
	else if($mode == 'setTourDepartResBusGuideInfo'){

		$tableName = "tour_depart_res_bus";
		$d_uid = (int) $_POST['d_uid'];

		$ins_id = $_POST['ins_id'];

		$sql = "SELECT count(*) as total FROM {$tableName} WHERE d_uid = {$d_uid}";
		$rs = db_fetch($sql);
		$total = (int) $rs['total'];

		$guideInfo = $_POST['guideInfo'];

		if($total > 0){
			//update
			$sql = "UPDATE {$tableName} SET guideInfo = '{$guideInfo}',  ins_id = '{$ins_id}', ins_dt = now() WHERE d_uid = {$d_uid}";
		}else{
			//insert
			$sql = "INSERT INTO {$tableName} SET guideInfo = '{$guideInfo}', ins_id = '{$ins_id}', d_uid = {$d_uid}, ins_dt = now()";
		}


		$isResult = false;

		if(db_query($sql)){
			$isResult = true;
		}

		echo json_encode(
			array(
				'result' => $isResult,
				'data' => $rs,
				'total' => $total,
//				'sql' => $sql,
			)
		);

		exit;



//		data: {mode:'setPrivateTourDepartResBusGuideInfo',seq, guideInfo, ins_id},
	}

	//일반 예약 버스 가이드 정보 저장
	else if($mode == 'setPrivateTourDepartResBusGuideInfo'){

		$tableName = "TB_PRIVATE_DEPART";
		$seq = (int) $_POST['seq'];

		$ins_id = $_POST['ins_id'];

		$sql = "SELECT count(*) as total FROM {$tableName} WHERE seq = {$seq}";
		$rs = db_fetch($sql);
		$total = (int) $rs['total'];

		$guideInfo = $_POST['guideInfo'];

		if($total > 0){
			/*$matchPrivateBusKey = $_POST['matchPrivateBusKey'];
			if($matchPrivateBusKey){
				$sql = "SELECT * FROM {$tableName} WHERE seq = {$seq}";
				$ptData = db_fetch($sql);
				$startTime = $ptData[''];
			}*/


			//update
			$sql = "UPDATE {$tableName} SET guideInfo = '{$guideInfo}',  ins_id = '{$ins_id}', ins_dt = now() WHERE seq = {$seq}";
		}else{
			//insert
			$sql = "INSERT INTO {$tableName} SET guideInfo = '{$guideInfo}', ins_id = '{$ins_id}', ins_dt = now()";
		}

		$isResult = false;

		if(db_query($sql)){
			$isResult = true;
		}

		echo json_encode(
			array(
				'result' => $isResult,
				'data' => $rs,
				'total' => $total,
//				'sql' => $sql,
			)
		);

		exit;



//		data: {mode:'setPrivateTourDepartResBusGuideInfo',seq, guideInfo, ins_id},
	}



	//b2b 팝업 노출 설정
	else if($mode == 'modifyB2BPopupView'){
		$lang = $_POST['lang'];
		$viewStatus = $_POST['viewStatus'];

		if(($lang != 'en' && $lang != 'cn' && $lang != 'hk') || ($viewStatus != 'Y' && $viewStatus != 'N')){
			echo json_encode(
				array(
					'result' => false,
				)
			);
			exit;
		}

		$tableName = "TB_B2BPopup";
		$sql = "UPDATE {$tableName} SET isShow = '{$viewStatus}' WHERE lang = '{$lang}'";

		$isResult = false;

		if(db_query($sql)){
			$isResult = true;
		}

		echo json_encode(
			array(
				'result' => $isResult,
			)
		);
		exit;
	}else if($mode == 'setSeqMainViewSection'){

		$seqData = $_POST['seqData'];

		$seqDataArr = explode(",",$seqData);

		$result = false;

		$isSuccessCnt = 0;
		foreach($seqDataArr as $item){
			$data = explode("-",$item);
			$id = $data[0];
			$seq = $data[1];

			if(!$id || !$seq){
				$result = false;
				break;
			}

			$sql = "UPDATE mainViewSection SET seq = {$seq} WHERE mainViewSectionID = {$id}";
			if(db_query($sql)){
				$isSuccessCnt += 1;
			}else{
				$result = false;
			}
		}

		if($isSuccessCnt == count($seqDataArr)){
			$result = true;
		}

		echo json_encode(
			array(
				'result' => $result,
				'data' => $seqData,
//				'sql' => $sql,
			)
		);

		exit;

	}else if($mode == 'setMainPageViewSectionIsView'){

		$tableName = "mainViewSection";

		$sectionID = $_POST['sectionID'];
		$checkValue = $_POST['checkValue'];
		$lang = $_POST['lang'];

		if($checkValue == 'Y'){
			//가장 큰 시퀀스를 찾아서 1을 더해서 업데이트
			$sql = "SELECT seq FROM {$tableName} WHERE lang = '{$lang}' ORDER BY seq DESC LIMIT 1";
			$data = db_fetch($sql);
			if($data){
				$maxSeq = (int) $data['seq'];
				$seq = $maxSeq + 1;
			}else{
				$seq = 99;
			}


			$sql = "UPDATE {$tableName} SET isView = '{$checkValue}', seq = {$seq} WHERE mainViewSectionID = {$sectionID}";

			$result = false;

			if(db_query($sql)){
				$result = true;
			}

		}else{
			$sql = "UPDATE {$tableName} SET isView = '{$checkValue}' WHERE mainViewSectionID = {$sectionID}";

			$result = false;

			if(db_query($sql)){
				$result = true;
			}

		}

		echo json_encode(
			array(
				'result' => $result,
				'sectionID' => $sectionID,
				'checkValue' => $checkValue,
				'lang' => $lang,
				'maxSeq' => $maxSeq,
			)
		);
		exit;
	}else if($mode == 'setMainPageViewGoods'){

		$tableName = "mainViewSectionGoods";

		$g_uid = $_POST['gUid'];
		$mainSectionID = $_POST['mainSectionID'];
		$lang = $_POST['lang'];

		$insId = $_POST['to_mb_id'];
		$dbType = $_POST['dbType'];

		if($dbType == 'insert'){
			//가장 큰 시퀀스를 찾아서 1을 더해서 업데이트
			$sql = "SELECT seq FROM {$tableName} WHERE lang = '{$lang}' ORDER BY seq DESC LIMIT 1";
			$data = db_fetch($sql);
			if($data){
				$maxSeq = (int) $data['seq'];
				$seq = $maxSeq + 1;
			}else{
				$seq = 99;
			}

			$sql = "INSERT INTO {$tableName} SET mainViewSectionID = {$mainSectionID}, lang = '{$lang}', g_uid = {$g_uid}, seq = {$seq}, ins_id = '{$insId}', ins_dt = now()";

			$result = false;

			if(db_query($sql)){
				$result = true;
			}
		}else{
			$sql = "DELETE FROM {$tableName} WHERE g_uid = {$g_uid}";

			$result = false;

			if(db_query($sql)){
				$result = true;
			}
		}




		echo json_encode(
			array(
				'result' => $result,
//				'sql' => $sql,
			)
		);
		exit;

	}else if($mode == 'setSeqMainViewGoods'){
		$seqData = $_POST['seqData'];
		$seqDataArr = explode(",",$seqData);
		$result = false;

		$isSuccessCnt = 0;

		foreach($seqDataArr as $item){
			$data = explode("-",$item);
			$id = $data[0];
			$seq = $data[1];

			if(!$id || !$seq){
				$result = false;
				break;
			}

			$sql = "UPDATE mainViewSectionGoods SET seq = {$seq} WHERE mainViewSectionGoodsID = {$id}";
			if(db_query($sql)){
				$isSuccessCnt += 1;
			}else{
				$result = false;
			}

		}

		if($isSuccessCnt == count($seqDataArr)){
			$result = true;
		}

		echo json_encode(
			array(
				'result' => $result,
				'data' => $seqData,
//				'sql' => $sql,
			)
		);

		exit;

	}else if($mode == 'setMainViewDel'){
		$mainViewSectionGoodsID = (int) $_POST['mainViewSectionGoodsID'];

		if(!$mainViewSectionGoodsID){

			$result = false;

		}else{

			$sql = "DELETE FROM mainViewSectionGoods WHERE mainViewSectionGoodsID = {$mainViewSectionGoodsID}";

			if(db_query($sql)){
				$result = true;
			}else{
				$result = false;
			}

		}

		echo json_encode(
			array(
				'result' => $result,
//				'sql' => $sql,
			)
		);

		exit;
	}else if($mode == 'setYoutubeContentsSequence'){
        $seqData = $_POST['seqData'];
		$seqDataArr = explode(",",$seqData);
		$result = false;

		$isSuccessCnt = 0;

		foreach($seqDataArr as $item){
			$data = explode("-",$item);
			$id = $data[0];
			$seq = $data[1];

			if(!$id || !$seq){
				$result = false;
				break;
			}

			$sql = "UPDATE youtube_link SET seq = {$seq} WHERE ytid = {$id}";
			if(db_query($sql)){
				$isSuccessCnt += 1;
			}else{
				$result = false;
			}

		}

		if($isSuccessCnt == count($seqDataArr)){
			$result = true;
		}

		echo json_encode(
			array(
				'result' => $result,
				'data' => $seqData,
//				'sql' => $sql,
			)
		);

		exit;

    }

	else if($mode == 'setFooterIconSequence'){
		$seqData = $_POST['seqData'];
		$seqDataArr = explode(",",$seqData);
		$result = false;

		$isSuccessCnt = 0;

		foreach($seqDataArr as $item){
			$data = explode("-",$item);
			$id = $data[0];
			$seq = $data[1];

			if(!$id || !$seq){
				$result = false;
				break;
			}

			$sql = "UPDATE footerIconLink SET seq = {$seq} WHERE footerIconLinkID = {$id}";
			if(db_query($sql)){
				$isSuccessCnt += 1;
			}else{
				$result = false;
			}
		}

		if($isSuccessCnt == count($seqDataArr)){
			$result = true;
		}

		echo json_encode(
			array(
				'result' => $result,
				'data' => $seqData,
//				'sql' => $sql,
			)
		);

		exit;

	}



	else if($mode == 'benepiaQuery'){
		//data: {mode:'benepiaQuery',bi,bp},


		$benepiaID = trim($_POST['bi']);
		$benepiaPW = trim($_POST['bp']);
		$memberID = trim($_POST['memberID']);
		$resNo = $_POST['ordr_idxx'];
		$benepiaPayAmount = $_POST['ba'];

		//결제할 가격 검증
		if(!$resNo){
			echo json_encode(
				array(
					'result' => false,
					'res_msg' => '예약번호가 없습니다.',
				)
			);
			exit;
		}

		//
		$sql = "SELECT * FROM TB_RES_GOOD WHERE res_no = '{$resNo}'";
		$resData = db_fetch($sql);

		if($resData){
			if($benepiaPayAmount != $resData['sales_total']){
				echo json_encode(
					array(
						'result' => false,
						'res_msg' => '변조 데이터 확인',
//                        'benepiaPayAmount' => $benepiaPayAmount,
//                        'sales_total' => $resData['sales_total'],
					)
				);
				exit;
			}
		}else{
			echo json_encode(
				array(
					'result' => false,
					'res_msg' => '예약데이터가 없습니다.',
				)
			);
			exit;
		}

		$isNoCallLibCommon = true;
		include_once $_SERVER['DOCUMENT_ROOT'].'/partner/benepia/class.Benepia.php';

		$benepia = new Benepia();

		$returnData = $benepia->pointQuery($benepiaID,$benepiaPW);

		$result = false;

		//남은 포인트로 결제 가능한지 확인
		if($returnData){

			if($returnData['res_cd'] == "0000"){


				$rsvPnt = (int) $returnData['rsv_pnt'];

				$rsvPntNF = number_format($rsvPnt);
				$benepiaPayAmount = (int) $benepiaPayAmount;

				if($benepiaPayAmount > $rsvPnt){
					$result = true;


				}else{
					$result = true;
				}
			}else{
				$result = false;
			}

		}

		echo json_encode(
			array(
				'result' => $result,
				'data' => $returnData,
				'rsvPntNF' => $rsvPntNF,
//                'benepiaID' => $benepiaID,
//                'benepiaPW' => $benepiaPW,
			)
		);

		exit;
	}



	else if($mode == 'benepiaQueryOnly'){
//		data: {mode:'benepiaQueryOnly', bi, bp, memberID},


		$benepiaID = trim($_POST['bi']);
		$benepiaPW = trim($_POST['bp']);

		$resNo = 'OnlyQuery';

		$isNoCallLibCommon = true;
		include_once $_SERVER['DOCUMENT_ROOT'].'/partner/benepia/class.Benepia.php';

		$benepia = new Benepia();

		$returnData = $benepia->pointQuery($benepiaID,$benepiaPW);

		$result = false;

		//남은 포인트로 결제 가능한지 확인
		if($returnData){
			$result = true;
			echo json_encode(
				array(
					'result' => $result,
					'data' => $returnData,
//					'rsvPntNF' => $rsvPntNF,
//                'benepiaID' => $benepiaID,
//                'benepiaPW' => $benepiaPW,
				)
			);
		}



		exit;
	}
	else if($mode == 'saveIp'){
		//베네피아 포인트 사용 후 나이스페이 SignData 재생성용.

		$merchantKey	= $cf['pg']['nice']['merchantKey']; // 상점키
		$MID			= $cf['pg']['nice']['merchantID']; // 상점아이디

		$price = (int) $_POST['op'];

		$ediDate = date("YmdHis");
		$hashString = bin2hex(hash('sha256', $ediDate.$MID.$price.$merchantKey, true));

		if($merchantKey && $MID && $price && $ediDate && $hashString){
			echo json_encode(
				array(
					'result' => true,
					'ip' => $hashString,
					'ediDate' => $ediDate,
//					'merchantKey' => $merchantKey,
//					'MID' => $MID,
				)
			);
		}else{
			echo json_encode(
				array(
					'result' => false,
				)
			);
		}
		exit;
	}
	//베네피아와 카드결제 혼용시 사용하는 베네피아 포인트 결제
	else if($mode == 'benepiaPointPaymentForAjax'){
		//data: {'mode' : 'benepiaPointPaymentForAjax',pt_idno, pt_pwd, amount, good_name, buyr_name, buyr_tel2, buyr_mail, res_no},

		$postData = array();
		$postData['pt_idno'] = $_POST['pt_idno'];
		$postData['pt_pwd'] = $_POST['pt_pwd'];
		$postData['amount'] = $_POST['amount'];
		$postData['good_name'] = $_POST['good_name'];
		$postData['buyr_name'] = $_POST['buyr_name'];
		$postData['buyr_tel2'] = $_POST['buyr_tel2'];
		$postData['buyr_mail'] = $_POST['buyr_mail'];
		$postData['ordr_idxx'] = $_POST['res_no'];


//		$amount = $postData['amount'];
//		$cust_ip = $_SERVER['REMOTE_ADDR'];
//		$pt_idno = $postData['pt_idno'];
//		$pt_pwd = $postData['pt_pwd'];
//		$ordr_idxx = $postData['res_no'];
//		$good_name = trim($postData['good_name']);
//		$buyr_name = trim($postData['buyr_name']);
//		$buyr_mail = trim($postData['buyr_mail']);
//		$buyr_tel2 = trim($postData['buyr_tel2']);


//		echo json_encode(
//			array(
//				'amount' => $amount,
//				'cust_ip' => $cust_ip,
//				'pt_idno' => $pt_idno,
//				'pt_pwd' => $pt_pwd,
//				'ordr_idxx' => $ordr_idxx,
//				'good_name' => $good_name,
//				'buyr_name' => $buyr_name,
//				'buyr_mail' => $buyr_mail,
//				'buyr_tel2' => $buyr_tel2,
//			)
//		);
//		exit;

		$isNoCallLibCommon = true;
		include_once $_SERVER['DOCUMENT_ROOT'].'/partner/benepia/class.Benepia.php';

		$benepia = new Benepia();
		$benepiaPaymentResultStr = $benepia->payment($postData,true);

		echo json_encode(
			array(
				'benepiaPaymentResultStr' => $benepiaPaymentResultStr,
			)
		);
		exit;


	}else if($mode == 'benepiaPointCancel'){
		//예약도중 베네피아 포인트 결제 후 취소버튼 누른 경우 포인트 취소처리

		$resNo = $_POST['resNo'];

		if(!$resNo){
			echo json_encode(
				array(
					'result' => false,
					'errorMsg' => '예약번호가 없습니다.'
				)
			);
			exit;
		}




		$sql = "SELECT pg_tno, bank_plus, pgcase_cd FROM TB_ACCOUNT_CUSTOMER WHERE res_no = '{$resNo}'";
		$res = db_query($sql);

		$cardPlus = 0;
		$benepiaPointPlus = 0;





		$tno = "";
		while($dataRow = db_fetch_array($res)){
			if($dataRow['pgcase_cd'] == 'INST002'){
				$cardPlus += (int) $dataRow['bank_plus'];
			}

			if($dataRow['pgcase_cd'] == 'INST006'){
				$tno = $dataRow['pg_tno'];
				$benepiaPointPlus += (int) $dataRow['bank_plus'];
			}
		}




		if($cardPlus == 0 && $benepiaPointPlus > 0){

			//취소 가능
			if(!$tno){

				echo json_encode(
					array(
						'result' => true,
						'errorMsg' => 'no tno',
					)
				);
				exit;

			}else{

				$isNoCallLibCommon = true;
				include_once $_SERVER['DOCUMENT_ROOT'].'/partner/benepia/class.Benepia.php';

				$benepia = new Benepia();
				$cancelData = $benepia->paymentCancel($tno, 'STSC', '고객 취소', '', '', '');

				$benepiaPointPlus = (int) $benepiaPointPlus;

				if($cancelData['res_cd'] == "0000"){

					$sql = "INSERT INTO TB_ACCOUNT_CUSTOMER SET res_no = '{$resNo}', ";
					$sql .= "acnt_cd = 'benepiaPoint', ";
					$sql .= "bank_minus = {$benepiaPointPlus}, ";
					$sql .= "pgcase_cd = 'INST006', ";
					$sql .= "bank_cd = 'benepia', ";
					$sql .= "bank_nm = 'benepia', ";
					$sql .= "remarks = '고객 취소', ";
					$sql .= "pg_suply = 'kcp', ";
					$sql .= "pg_tno = '{$tno}', ";
					$sql .= "ins_dt = now(), ";
					$sql .= "benepia_pnt_amount = {$benepiaPointPlus}";
					db_query($sql);

					if($resNo){
						$sql2 = "UPDATE TB_RES_GOOD SET order_state = 'H', res_stat_cd = 'D', cancel_dt = now(), benepiaNotDaily = 'Y' WHERE res_no = '{$resNo}'";
						db_query($sql2);
					}

				}

				echo json_encode(
					array(
						'result' => true,
						'errorMsg' => $cancelData['res_msg'],
						'tno' => $cancelData['tno'],
						'res_cd' => $cancelData['res_cd'],
						'sql' => $sql,
						'sql2' => $sql2,
					)
				);
			}
			exit;

		}else if($cardPlus == 0 && $benepiaPointPlus == 0){

			echo json_encode(
				array(
					'result' => true,
					'errorMsg' => 'no payment',
				)
			);


		}else{
			//취소불가능
			echo json_encode(
				array(
					'result' => false,
					'errorMsg' => '베네피아 포인트만 취소할 수 없는 상태입니다. 고객센터에 문의부탁드립니다.',
					'cardPlus' => $cardPlus,
					'benepiaPointPlus' => $benepiaPointPlus,
				)
			);
			exit;
		}



//		if(!$data){
//			echo json_encode(
//				array(
//					'result' => false,
//					'errorMsg' => '결제 데이터가 없습니다.'
//				)
//			);
//			exit;
//		}




	}







	/*else if($mode == 'benepiaQuery'){
        //data: {mode:'benepiaQuery',bi,bp},


        $benepiaID = trim($_POST['bi']);
        $benepiaPW = trim($_POST['bp']);
        $memberID = trim($_POST['memberID']);
        $resNo = $_POST['ordr_idxx'];
        $benepiaPayAmount = $_POST['ba'];

        //결제할 가격 검증
        if(!$resNo){
            echo json_encode(
                array(
                    'result' => false,
                    'res_msg' => '예약번호가 없습니다.',
                )
            );
            exit;
        }

        //
        $sql = "SELECT * FROM TB_RES_GOOD WHERE res_no = '{$resNo}'";
        $resData = db_fetch($sql);

        if($resData){
            if($benepiaPayAmount != $resData['sales_total']){
                echo json_encode(
                    array(
                        'result' => false,
                        'res_msg' => '변조 데이터 확인',
//                        'benepiaPayAmount' => $benepiaPayAmount,
//                        'sales_total' => $resData['sales_total'],
                    )
                );
                exit;
            }
        }else{
            echo json_encode(
                array(
                    'result' => false,
                    'res_msg' => '예약데이터가 없습니다.',
                )
            );
            exit;
        }

        $isNoCallLibCommon = true;
        include_once $_SERVER['DOCUMENT_ROOT'].'/partner/benepia/class.Benepia.php';

        $benepia = new Benepia();

        $returnData = $benepia->pointQuery($benepiaID,$benepiaPW);

        $result = false;

        //남은 포인트로 결제 가능한지 확인
        if($returnData){

            if($returnData['res_cd'] == "0000"){

                $rsvPnt = (int) $returnData['rsv_pnt'];
                $benepiaPayAmount = (int) $benepiaPayAmount;

                if($benepiaPayAmount > $rsvPnt){
                    $result = false;

                    echo json_encode(
                        array(
                            'result' => $result,
                            'res_msg' => '베네피아 포인트가 결제할 포인트보다 적습니다.(베네피아 남은 포인트 : '.$rsvPnt.')',
                        )
                    );
                    exit;
				}else{
                    $result = true;
                }
			}else{
                $result = false;
            }

        }

        echo json_encode(
            array(
                'result' => $result,
                'data' => $returnData,
//                'benepiaID' => $benepiaID,
//                'benepiaPW' => $benepiaPW,
            )
        );

        exit;
    }*/



	else if($mode == 'setBannerShowSite'){
        $idx = (int) $_POST['idx'];
        $value = $_POST['value'];
        $site = $_POST['site'];

        $tableName = "TB_HOMEPAGE_BANNER";

        if(!$idx){
            echo json_encode(
                array(
                    'result' => false,
                    'errorMsg' => '일련번호 에러',
                )
            );
            exit;
        }

        if($value != 'Y' && $value != 'N'){
            echo json_encode(
                array(
                    'result' => false,
                    'errorMsg' => '노출 값 에러',
                )
            );
            exit;
        }

        if($site != 'tb' && $site != 'bp'){
            echo json_encode(
                array(
                    'result' => false,
                    'errorMsg' => '사이트 값 에러',
                )
            );
            exit;
        }

        $setFieldName = "disp_site_tb";

        if($site == 'bp'){
            $setFieldName = "disp_site_bp";
        }

        $sql = "UPDATE {$tableName} SET {$setFieldName} = '{$value}' WHERE idx = {$idx}";

        $isResult = false;

        if(db_query($sql)){
            $isResult = true;
        }

        echo json_encode(
            array(
                'result' => $isResult,
                'sql' => $sql
            )
        );
        exit;
    }

    //data: {mode:'setGoodOption',opid, op_nm, op_nm_ko, order_num, op_price_cost, op_price_sell, op_price_agent},
    else if($mode == 'setGoodOption'){

        $g_uid = $_POST['gUid'];
        $opid = $_POST['opid'];
        $op_nm = $_POST['op_nm'];
        $op_nm_ko = $_POST['op_nm_ko'];
        $order_num = $_POST['order_num'];
        $op_price_cost = $_POST['op_price_cost'];
        $op_price_sell = $_POST['op_price_sell'];
        $op_price_agent = $_POST['op_price_agent'];

        if(!$g_uid || !$opid){
            echo json_encode(
                array(
                    'result' => false,
                    'errorMsg' =>"상품번호 또는 옵션번호가 없습니다."
                )
            );
            exit;
        }

        if(	isCheckQuot($op_nm) == true ){
            echo json_encode(
                array(
                    'result' => false,
                    'errorMsg' =>"쌍따옴표,홑따옴표는 사용불가합니다."
                )
            );
            exit;
        }

        $op_nm = str_replace("^","",$op_nm); // 쓸수없는문자
        $op_nm = str_replace("|","",$op_nm); // 쓸수없는문자

        $op_nm_ko = str_replace("^","",$op_nm_ko); // 쓸수없는문자
        $op_nm_ko = str_replace("|","",$op_nm_ko); // 쓸수없는문자

        $op_price_cost = str_replace(",","",$op_price_cost);
        $op_price_sell = str_replace(",","",$op_price_sell);
        $op_price_agent = str_replace(",","",$op_price_agent);

		$table = "TB_GOOD_OPTION";

        $sql = "UPDATE {$table} SET";
        $sql .= " op_nm='{$op_nm}',";
        $sql .= " op_nm_ko='{$op_nm_ko}',";
        $sql .= " op_price_cost={$op_price_cost},";
        $sql .= " op_price_sell={$op_price_sell},";
        $sql .= " op_price_agent={$op_price_agent},";
        $sql .= " order_num={$order_num}";
        $sql .= " WHERE g_uid = {$g_uid} AND opid = {$opid}";

        $isResult = false;

		$errorMsg = "에러 발생";

        if(db_query($sql)){
			$dateResult = false;

			$opidS = (string) $opid;

			$sql = "SELECT * FROM date WHERE g_uid = {$g_uid}";
			$dateRes = db_query($sql);

			$setValue = $opid.'^'.$op_nm.'^'.$op_price_sell.'^';

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

				$dGoodOption = explode("||",$row['d_good_option']);

				$newDGoodOption = "";

				foreach($dGoodOption as $item){

					$isFind = false;

					if(!$item){
						continue;
					}

					$value = $item;

					if(strpos($item, $opidS) !== false){
						$isFind = true;
						$value = $setValue;
					}

					if(!$newDGoodOption){
						$newDGoodOption = "||".$value;
					}else{
						$newDGoodOption .= "||".$value;
					}
				}

				$dUid = $row['d_uid'];

				if(strpos($newDGoodOption, $opidS) !== false){
					$sql = "UPDATE date SET d_good_option = '{$newDGoodOption}' WHERE d_uid = {$dUid}";
					if(db_query($sql)){
//					if(true){
						$dateResult = true;
					}else{
						$dateResult = false;
						echo json_encode(
							array(
								'result' => false,
								'errorMsg' => $sql,
							)
						);
						exit;
					}
				}
			}

			$isResult = true;
            $errorMsg = "";

			if($dateResult){
				echo json_encode(
					array(
						'result' => true,
//						'sql' => $sql,
					)
				);
				exit;
			}
		}

		echo json_encode(
            array(
                'result' => $isResult,
                'errorMsg' => $errorMsg,
            )
        );
        exit;
	}else if($mode == 'setResGmemo'){
		//data: {'mode':'setResMemo',resSeq,memoContents},

		$resSeq = (int) $_POST['resSeq'];
		if(!$resSeq){

			echo json_encode(
				array(
					'result' => false,
					'errorMsg' => '예약일련번호가 없습니다.',
				)
			);
			exit;
		}

		$adminId = trim($_POST['to_mb_id']);
		$adminNm = trim($_POST['to_mb_nm']);

		$gMemoContents = $_POST['gMemoContents'];
		$gMemoContents = str_replace("'","\'",$gMemoContents);

		$sql = "UPDATE TB_RES_GOOD SET edit_id = '{$adminId}',  edit_nm = '{$adminNm}', g_memo = '{$gMemoContents}' WHERE res_seq = {$resSeq}";
		$returnData = false;

		if(db_query($sql)){
			$returnData = true;
		}

		echo json_encode(
			array(
				'result' => $returnData,
				'sql' => $sql,
				'gMemoContents' => $gMemoContents,
//				'gMemoContents2' => $_POST['gMemoContents'],
			)
		);
		exit;
	}else if($mode == 'setResEmemo'){
		//data: {'mode': 'setResEmemo', bidx, eMemoContents},

		$bidx = (int) $_POST['bidx'];

		if(!$bidx){

			echo json_encode(
				array(
					'result' => false,
					'errorMsg' => '버스예약일련번호가 없습니다.',
				)
			);
			exit;

		}

		$eMemoContents = $_POST['eMemoContents'];
		$eMemoContents = str_replace("'","\'",$eMemoContents);

		$sql = "UPDATE TB_ERP_BUS SET e_memo = '{$eMemoContents}' WHERE b_idx = {$bidx}";
		$returnData = false;

		if(db_query($sql)){
			$returnData = true;
		}

		echo json_encode(
			array(
				'result' => $returnData,
				'sql' => $sql,
				'eMemoContents' => $eMemoContents,
//				'gMemoContents2' => $_POST['gMemoContents'],
			)
		);
		exit;
	}else if($mode == 'setResErpMemo'){
//		data: {'mode': 'setResErpMemo', aidx, gMemoContents},

		$aidx = (int) $_POST['aidx'];

		if(!$aidx){

			echo json_encode(
				array(
					'result' => false,
					'errorMsg' => '견적서일련번호가 없습니다.',
				)
			);
			exit;

		}

		$gMemoContents = $_POST['gMemoContents'];
		$gMemoContents = str_replace("'","\'",$gMemoContents);

		$sql = "UPDATE TB_ERP_ALL SET g_memo = '{$gMemoContents}' WHERE a_idx = {$aidx}";
		$returnData = false;

		if(db_query($sql)){
			$returnData = true;
		}

		echo json_encode(
			array(
				'result' => $returnData,
				'sql' => $sql,
				'gMemoContents' => $gMemoContents,
//				'gMemoContents2' => $_POST['gMemoContents'],
			)
		);
		exit;
	}


	else if($mode == 'setBusTypeMemo') {

		//data: {mode:'setCalendarMemo',siteType, targetDay, memoContents},
		$goodType = $_POST['goodType'];
		$targetDay = $_POST['targetDay'];
		$memoContents = $_POST['memoContents'];


		if (!$goodType || !$targetDay) {
			echo json_encode(
				array(
					'result' => false,
					'errorMsg' => '날짜정보 또는 상품구분 정보가 없습니다.',
				)
			);
			exit;
		}

//		TB_RES_CUSTOMER_LIST_BUS_TYPE_MEMO
		//데이터가 있는지 확인
		$sql = "SELECT count(*) AS cnt FROM TB_RES_CUSTOMER_LIST_BUS_TYPE_MEMO WHERE good_type = '{$goodType}' AND calendar_date = '{$targetDay}'";
		$isCntData = db_fetch($sql);
		$isCntData = (int)$isCntData['cnt'];

		$insID = $_POST['toMbId'];

		$return = false;

		$errorMsg = "";
		if (!$isCntData) {
			//insert
			$sql = "INSERT INTO TB_RES_CUSTOMER_LIST_BUS_TYPE_MEMO SET good_type = '{$goodType}', calendar_date = '{$targetDay}', ins_id = '{$insID}', memo = '{$memoContents}', ins_dt = now() ";

			if (db_query($sql)) {
				$return = true;
			}
			$errorMsg = "데이터 입력 실패";

		} else {
			//update
			$sql = "UPDATE TB_RES_CUSTOMER_LIST_BUS_TYPE_MEMO SET memo = '{$memoContents}', ins_id = '{$insID}', ins_dt = now() WHERE good_type = '{$goodType}' AND calendar_date = '{$targetDay}'";

			if (db_query($sql)) {
				$return = true;
			}
			$errorMsg = "데이터 입력 실패";
		}

		echo json_encode(
			array(
				'result' => $return,
				'cnt' => $isCntData,
				'sql' => $sql,
				'TO' => $_POST['toMbId'],
				'errorMsg' => $errorMsg,
			)
		);
		exit;
	}






	else if($mode == 'setResCustomerOptionVerydayCnt') {
		//data: {mode:'setResCustomerOptionVerydayCnt',optName, dayIdx, goodType, cnt,toMbId},

		$cnt = (int) $_POST['cnt'];
		$optName = $_POST['optName'];
		$goodType = $_POST['goodType'];
		$targetDay = $_POST['dayIdx'];

		if (!$goodType || !$targetDay || !$optName) {
			echo json_encode(
				array(
					'result' => false,
					'errorMsg' => '날짜정보 또는 상품구분 등 필수정보가 없습니다. 정보가 없습니다.',
				)
			);
			exit;
		}

//		TB_RES_CUSTOMER_LIST_BUS_TYPE_MEMO
		//데이터가 있는지 확인
		$sql = "SELECT count(*) AS cnt FROM TB_RES_CUSTOMER_OPT_VERYDAY_CNT WHERE good_type = '{$goodType}' AND calendar_date = '{$targetDay}' AND opt_name = '{$optName}'";
		$isCntData = db_fetch($sql);
		$isCntData = (int)$isCntData['cnt'];

		$insID = $_POST['toMbId'];

		$return = false;

		$errorMsg = "";
		if (!$isCntData) {
			//insert
			$sql = "INSERT INTO TB_RES_CUSTOMER_OPT_VERYDAY_CNT SET good_type = '{$goodType}', opt_name = '{$optName}', cnt = {$cnt}, calendar_date = '{$targetDay}', ins_id = '{$insID}', ins_dt = now() ";

			if (db_query($sql)) {
				$return = true;
			}
			$errorMsg = "데이터 입력 실패";

		} else {
			//update
			$sql = "UPDATE TB_RES_CUSTOMER_OPT_VERYDAY_CNT SET cnt = {$cnt}, ins_id = '{$insID}', ins_dt = now() WHERE good_type = '{$goodType}' AND calendar_date = '{$targetDay}' AND opt_name = '{$optName}'";

			if (db_query($sql)) {
				$return = true;
			}
			$errorMsg = "데이터 입력 실패";
		}

		echo json_encode(
			array(
				'result' => $return,
				'cnt' => $isCntData,
				'sql' => $sql,
				'TO' => $_POST['toMbId'],
				'errorMsg' => $errorMsg,
			)
		);
		exit;
	}


	//setResCustomerDayMemo

	else if($mode == 'setResCustomerDayMemo') {
		//data: {mode:'setCalendarMemo',siteType, targetDay, memoContents},
		$goodType = $_POST['goodType'];
		$targetDay = $_POST['targetDay'];
		$memoContents = $_POST['memoContents'];

		if (!$goodType || !$targetDay) {
			echo json_encode(
				array(
					'result' => false,
					'errorMsg' => '날짜정보 또는 사이트구분 정보가 없습니다.',
				)
			);
			exit;
		}


//		TB_RES_CUSTOMER_LIST_BUS_TYPE_MEMO
		//데이터가 있는지 확인
		$sql = "SELECT count(*) AS cnt FROM TB_RES_CUSTOMER_DAY_MEMO WHERE good_type = '{$goodType}' AND calendar_date = '{$targetDay}'";
		$isCntData = db_fetch($sql);
		$isCntData = (int)$isCntData['cnt'];

		$insID = $_POST['toMbId'];

		$return = false;

		$errorMsg = "";
		if (!$isCntData) {
			//insert
			$sql = "INSERT INTO TB_RES_CUSTOMER_DAY_MEMO SET good_type = '{$goodType}', calendar_date = '{$targetDay}', ins_id = '{$insID}', memo = '{$memoContents}', ins_dt = now() ";

			if (db_query($sql)) {
				$return = true;
			}
			$errorMsg = "데이터 입력 실패";

		} else {
			//update
			$sql = "UPDATE TB_RES_CUSTOMER_DAY_MEMO SET memo = '{$memoContents}', ins_id = '{$insID}', ins_dt = now() WHERE good_type = '{$goodType}' AND calendar_date = '{$targetDay}'";

			if (db_query($sql)) {
				$return = true;
			}
			$errorMsg = "데이터 입력 실패";
		}

		echo json_encode(
			array(
				'result' => $return,
				'cnt' => $isCntData,
				'sql' => $sql,
				'TO' => $_POST['toMbId'],
				'errorMsg' => $errorMsg,
			)
		);
		exit;
	}



	else if($mode == 'setRoomTypeMemo') {

		//data: {mode:'setCalendarMemo',siteType, targetDay, memoContents},

		$goodType = $_POST['goodType'];
		$targetDay = $_POST['targetDay'];
		$memoContents = $_POST['memoContents'];
		$resNo = $_POST['resNo'];

		if (!$goodType || !$targetDay || !resNo ) {
			echo json_encode(
				array(
					'result' => false,
					'errorMsg' => '날짜정보 또는 상품구분 또는 예약번호 정보가 없습니다.',
				)
			);
			exit;
		}

//		TB_RES_CUSTOMER_LIST_ROOM_TYPE_MEMO
		//데이터가 있는지 확인
		$sql = "SELECT count(*) AS cnt FROM TB_RES_CUSTOMER_LIST_ROOM_TYPE_MEMO WHERE good_type = '{$goodType}' AND res_no = '{$resNo}' AND calendar_date = '{$targetDay}'";
		$isCntData = db_fetch($sql);
		$isCntData = (int)$isCntData['cnt'];

		$insID = $_POST['toMbId'];
		$return = false;

		$errorMsg = "";
		if (!$isCntData) {
			//insert
			$sql = "INSERT INTO TB_RES_CUSTOMER_LIST_ROOM_TYPE_MEMO SET good_type = '{$goodType}', res_no = '{$resNo}', calendar_date = '{$targetDay}', ins_id = '{$insID}', memo = '{$memoContents}', ins_dt = now() ";

			if (db_query($sql)) {
				$return = true;
			}
			$errorMsg = "데이터 입력 실패";

		} else {
			//update
			$sql = "UPDATE TB_RES_CUSTOMER_LIST_ROOM_TYPE_MEMO SET memo = '{$memoContents}', ins_id = '{$insID}', ins_dt = now() WHERE good_type = '{$goodType}' AND res_no = '{$resNo}'"; // = '{}'

			if (db_query($sql)) {
				$return = true;
			}
			$errorMsg = "데이터 입력 실패";
		}

		echo json_encode(
			array(
				'result' => $return,
				'cnt' => $isCntData,
				'sql' => $sql,
				'TO' => $_POST['toMbId'],
				'errorMsg' => $errorMsg,
			)
		);
		exit;




	}




	else if($mode == 'setCalendarMemo') {
		//data: {mode:'setCalendarMemo',siteType, targetDay, memoContents},
		$siteType = $_POST['siteType'];
		$targetDay = $_POST['targetDay'];
		$memoContents = $_POST['memoContents'];

		if (!$siteType || !$targetDay) {
			echo json_encode(
				array(
					'result' => false,
					'errorMsg' => '날짜정보 또는 사이트구분 정보가 없습니다.',
				)
			);
			exit;
		}

//		TB_RES_CUSTOMER_LIST_BUS_TYPE_MEMO
		//데이터가 있는지 확인
		$sql = "SELECT count(*) AS cnt FROM TB_RES_CALENDAR_DAY_MEMO WHERE site_type = '{$siteType}' AND calendar_date = '{$targetDay}'";
		$isCntData = db_fetch($sql);
		$isCntData = (int)$isCntData['cnt'];

		$insID = $_POST['toMbId'];

		$return = false;

		$errorMsg = "";
		if (!$isCntData) {
			//insert
			$sql = "INSERT INTO TB_RES_CALENDAR_DAY_MEMO SET site_type = '{$siteType}', calendar_date = '{$targetDay}', ins_id = '{$insID}', memo = '{$memoContents}', ins_dt = now() ";

			if (db_query($sql)) {
				$return = true;
			}
			$errorMsg = "데이터 입력 실패";

		} else {
			//update
			$sql = "UPDATE TB_RES_CALENDAR_DAY_MEMO SET memo = '{$memoContents}', ins_id = '{$insID}', ins_dt = now() WHERE site_type = '{$siteType}' AND calendar_date = '{$targetDay}'";

			if (db_query($sql)) {
				$return = true;
			}
			$errorMsg = "데이터 입력 실패";
		}

		echo json_encode(
			array(
				'result' => $return,
				'cnt' => $isCntData,
				'sql' => $sql,
				'TO' => $_POST['toMbId'],
				'errorMsg' => $errorMsg,
			)
		);
		exit;
	}else if($mode == 'recoveryPrivateTour'){
		$seq = (int) $_POST['seq'];

		if(!$seq){
			echo json_encode(
				array(
					'result' => false,
					'errorMsg' => '일련번호가 없습니다.',
				)
			);
			exit;
		}

		$return = false;
		$sql = "UPDATE TB_PRIVATE_DEPART SET isShow = 'Y' WHERE seq = {$seq}";

		if(db_query($sql)){
			$return = true;
		}

		echo json_encode(
			array(
				'result' => $return,
				'errorMsg' => '프라이빗 투어 데이터 복원 실패',
			)
		);
		exit;

	}else if($mode == 'setBgStaticsColor') {
		//data: {'mode': 'setBgStaticsColor', colorvalue, dayIdx, gUid},

		/*CREATE TABLE `TB_COLOR_RES_STATICS` (
		`seq` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '일련번호',
 `g_uid` int unsigned not null COMMENT '상품번호',
 `color` char(7) NOT NULL COMMENT '칼라값',
 `date` char(10) not null COMMENT '날짜값',
 `ins_id` varchar(40) NOT NULL COMMENT '작성자 아이디',
 `ins_dt` datetime DEFAULT NULL COMMENT '등록일',
 PRIMARY KEY (`seq`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8*/

		$colorvalue = $_POST['colorvalue'];
		$dayIdx = $_POST['dayIdx'];
		$gUid = $_POST['gUid'];

		if (!$colorvalue || !$dayIdx || !$gUid) {
			echo json_encode(
				array(
					'result' => false,
					'errorMsg' => '필수값이 없습니다.(컬러정보, 날짜정보, 상품정보)',
//					'post' => $_POST,
					'$colorvalue' => $colorvalue,
					'$dayIdx' => $dayIdx,
					'$gUid' => $gUid,
				)
			);
			exit;
		}

		//데이터가 있는지 확인
		$sql = "SELECT count(*) AS cnt FROM TB_COLOR_RES_STATICS WHERE g_uid = {$gUid} AND datevalue = '{$dayIdx}' ";
		$isCntData = db_fetch($sql);
		$isCntData = (int)$isCntData['cnt'];

		$insID = $_POST['toMbId'];

		$return = false;

		$errorMsg = "";

		if (!$isCntData) {
			//insert
			$sql = "INSERT INTO TB_COLOR_RES_STATICS SET g_uid = '{$gUid}', datevalue = '{$dayIdx}', ins_id = '{$insID}', color = '{$colorvalue}', ins_dt = now() ";

			if (db_query($sql)) {
				$return = true;
			}
			$errorMsg = "데이터 입력 실패";

		} else {
			//update
			$sql = "UPDATE TB_COLOR_RES_STATICS SET ins_id = '{$insID}', color = '{$colorvalue}', ins_dt = now() WHERE datevalue = '{$dayIdx}' AND g_uid = '{$gUid}'";

			if (db_query($sql)) {
				$return = true;
			}
			$errorMsg = "데이터 입력 실패";
		}

		echo json_encode(
			array(
				'result' => $return,
				'color' => $colorvalue,
				'dayIdx' => $dayIdx,
				'datevalue' => $dayIdx,
			)
		);
		exit;
	}else if($mode == 'loadPhotoBBSData'){

		$tableName = $_POST['tbName'];
		$page = $_POST['currentPage'];
		$sqlWhere = $_POST['sqlWhere'];
		$bbsline = $_POST['bbsline'];
		$bbslist = $_POST['bbslist'];

		$GRP_CD = $_POST['GRP_CD'];
		$BD_CD = $_POST['BD_CD'];
		$BD_SORT = $_POST['BD_SORT'];
		$BD_NM = $_POST['BD_NM'];
		$BD_EM = $_POST['BD_EM'];
		$BD_DT = $_POST['BD_DT'];
		$BD_PS = $_POST['BD_PS'];
		$BD_PM = $_POST['BD_PM'];
		$BD_FS = $_POST['BD_FS'];
		$BD_MG = $_POST['BD_MG'];

		$BD_NG = $_POST['BD_NG'];
		$BD_CG = $_POST['BD_CG'];
		$BD_MO = $_POST['BD_MO'];
		$BD_RG = $_POST['BD_RG'];
		$BD_SC = $_POST['BD_SC'];
		$BD_FL = $_POST['BD_FL'];
		$BD_WE = $_POST['BD_WE'];
		$BD_TP = $_POST['BD_TP'];
		$BD_OD = $_POST['BD_OD'];
		$DELFLAG = $_POST['DELFLAG'];

		$OrderNum = $_POST['OrderNum'];
		$delpermit = $_POST['delpermit'];
		$GRP_NM = $_POST['GRP_NM'];
		$TABLE = $_POST['TABLE'];
		$TABLE_COMT = $_POST['TABLE_COMT'];

		$TO_BD['GRP_CD'] = $GRP_CD;
		$TO_BD['BD_CD'] = $BD_CD;
		$TO_BD['BD_SORT'] = $BD_SORT;
		$TO_BD['BD_NM'] = $BD_NM;
		$TO_BD['BD_EM'] = $BD_EM;
		$TO_BD['BD_DT'] = $BD_DT;
		$TO_BD['BD_PS'] = $BD_PS;
		$TO_BD['BD_PM'] = $BD_PM;
		$TO_BD['BD_FS'] = $BD_FS;
		$TO_BD['BD_MG'] = $BD_MG;
		$TO_BD['BD_NG'] = $BD_NG;
		$TO_BD['BD_CG'] = $BD_CG;
		$TO_BD['BD_MO'] = $BD_MO;
		$TO_BD['BD_RG'] = $BD_RG;
		$TO_BD['BD_SC'] = $BD_SC;
		$TO_BD['BD_FL'] = $BD_FL;
		$TO_BD['BD_WE'] = $BD_WE;
		$TO_BD['BD_TP'] = $BD_TP;
		$TO_BD['BD_OD'] = $BD_OD;
		$TO_BD['DELFLAG'] = $DELFLAG;
		$TO_BD['OrderNum'] = $OrderNum;
		$TO_BD['delpermit'] = $delpermit;
		$TO_BD['GRP_NM'] = $GRP_NM;
		$TO_BD['TABLE'] = $TABLE;
		$TO_BD['TABLE_COMT'] = $TABLE_COMT;


		// 페이지수 설정
		if (!$page) $page = 1;

		$line = $bbsline; // 보여줄 갯수




		$olds = ($page - 1) * $line;

		// 정렬 설정
		$sql_order = " order by ";

		if ($TO_BD[BD_OD] == "Y") {
			$sql_order .= " OrderNum asc, ";
		}

		if ($sort) {
			$sql_order .= " $sort $sord ";
		}
		else {
			$sql_order .= " FIXED_YN ASC, MRef DESC, MStep ASC, INSDT ASC, MSEQ DESC ";
		}

		// 리스트 가져옴
		$sql = "SELECT a.*, (SELECT count(*) FROM {$tableName}_COMT WHERE MSEQ = a.MSEQ) AS comment FROM {$tableName} a {$sqlWhere} {$sql_order} LIMIT {$olds}, {$line}";
		$rs = db_query($sql);

		// 게시물을 배열에 저장
		$data = array();
		$i = 0;

//		include_once $_SERVER['DOCUMENT_ROOT'].'/cmm/_common.html';

		while ($row = db_fetch_array($rs)) {
			// 게시물 데이터를 일괄 정리후 배열로 저장
//			array_push($data, $row);
			//			$data[$i] = TO_get_board_ajax($row, $TO_BD, 20);
			$data[$i] = $row;
			$data[$i][num] = ($data[$i][is_notice]) ? $data[$i][icon_notice] : $total - ($page - 1) * $line - $i;

			$i++;
		}

		echo json_encode(
			array(
				'result' => true,
				'tableName' => $tableName,
				'currentPage' => $page,
				'sqlWhere' => $sqlWhere,
				'data' => $data,
				'sql' => $sql,
			)
		);
		exit;


	}

	else if($mode == 'setSmartStoreErrorCompleted'){
//		data: {'mode': 'setSmartStoreErrorCompleted', ssid},

		$ssid = (int) $_POST['ssid'];
		if(!$ssid){

			echo json_encode(
				array(
					'result' => false,
					'errorMsg' => '일련번호가 없습니다.',
				)
			);
			exit;

		}

		$mbId = $_POST['to_mb_id'];

		$sql = "UPDATE smart_store_res_error SET checkYn = 'Y', confirm_id = '{$mbId}' WHERE ssid = {$ssid}";
		$returnData = false;

		if(db_query($sql)){
			$returnData = true;
		}

		echo json_encode(
			array(
				'result' => $returnData,
				'sql' => $sql,
			)
		);
		exit;
	}else if($mode == 'setSmartPlaceErrorCompleted'){
		//data: {'mode': 'setSmartPlaceErrorCompleted', spid, to_mb_id},

		$spid = (int) $_POST['spid'];

		if(!$spid){

			echo json_encode(
				array(
					'result' => false,
					'errorMsg' => '일련번호가 없습니다.',
				)
			);
			exit;

		}

		$mbId = $_POST['to_mb_id'];

		$sql = "UPDATE smart_place_res_error SET checkYn = 'Y', confirm_id = '{$mbId}' WHERE spid = {$spid}";
		$returnData = false;

		if(db_query($sql)){
			$returnData = true;
		}

		echo json_encode(
			array(
				'result' => $returnData,
				'sql' => $sql,
			)
		);
		exit;

	}
	else if($mode == 'setCoupangErrorCompleted'){
//		data: {'mode': 'setCoupangErrorCompleted', cid, to_mb_id},

		$cid = (int) $_POST['cid'];

		if(!$cid){

			echo json_encode(
				array(
					'result' => false,
					'errorMsg' => '일련번호가 없습니다.',
				)
			);
			exit;

		}

		$mbId = $_POST['to_mb_id'];

		$sql = "UPDATE coupang_res_error SET checkYn = 'Y', confirm_id = '{$mbId}'  WHERE cid = {$cid}";
		$returnData = false;

		if(db_query($sql)){
			$returnData = true;
		}

		echo json_encode(
			array(
				'result' => $returnData,
				'sql' => $sql,
			)
		);

		exit;
	}

	//tmon
	else if($mode == 'setTmonErrorCompleted'){
//		data: {'mode': 'setCoupangErrorCompleted', cid, to_mb_id},

		$tid = (int) $_POST['tid'];

		if(!$tid){

			echo json_encode(
				array(
					'result' => false,
					'errorMsg' => '일련번호가 없습니다.',
				)
			);
			exit;

		}

		$mbId = $_POST['to_mb_id'];

		$sql = "UPDATE tmon_res_error SET checkYn = 'Y', confirm_id = '{$mbId}'  WHERE tid = {$tid}";
		$returnData = false;

		if(db_query($sql)){
			$returnData = true;
		}

		echo json_encode(
			array(
				'result' => $returnData,
				'sql' => $sql,
			)
		);

		exit;
	}


	//야놀자 예약 누락 알림정보 숨김 처리
	else if($mode == 'setYanoljaErrorCompleted'){

		$yid = (int) $_POST['yid'];

		if(!$yid){

			echo json_encode(
				array(
					'result' => false,
					'errorMsg' => '일련번호가 없습니다.',
				)
			);
			exit;

		}

		$mbId = $_POST['to_mb_id'];

		$sql = "UPDATE yanolja_res_error SET checkYn = 'Y', confirm_id = '{$mbId}'  WHERE yid = {$yid}";
		$returnData = false;

		if(db_query($sql)){
			$returnData = true;
		}

		echo json_encode(
			array(
				'result' => $returnData,
				'sql' => $sql,
			)
		);

		exit;


	}

	//스마트스토어 상품문의 답변
	else if($mode == 'sendSmartStoreProductAnswer'){

//		data: {'mode': 'sendSmartStoreProductAnswer',questionId, answerText},


		$questionId = $_POST['questionId'];
		$answerText = $_POST['answerText'];

		if(!$questionId || !$answerText){

			echo json_encode(
				array(
					'result' => false,
					'errorMsg' => '답변ID 또는 답변문구가 없습니다.',
				)
			);
			exit;

		}


		//엑세스 토큰 획득
		$url = 'https://api.commerce.naver.com/external';
		$url2 = '/v1/oauth2/token';

		$url = $url.$url2;

		$millisec = (int)(microtime(TRUE) * 1000);

		$applicationID = '6A8ybd21sFrJGHQIMQM7hI';
		$applicationSecret = '$2a$04$aVpa1.MNj8.zMsbMIZ.Vi.';

		$signature = generateSignature($applicationID, $applicationSecret, $millisec);

		$apiData = array(
			'client_id' => $applicationID,
			'timestamp' => $millisec,
			'client_secret_sign' => $signature,
			'grant_type' => 'client_credentials',
			'type' => 'SELF'
		);

		$accessToken = requestCurl("POST", $url, $apiData);

		$accessToken = json_encode($accessToken);
		$accessToken = json_decode($accessToken, true);
		$accessToken = $accessToken['access_token'];







//		$questionId = $_POST['questionId'];
//		$answerText = $_POST['answerText'];

		$postData = array(
			'commentContent' => $answerText,
		);

		$postData = json_encode($postData);

		$curl = curl_init();

		curl_setopt_array($curl, [
			CURLOPT_URL => "https://api.commerce.naver.com/external/v1/contents/qnas/{$questionId}",
			CURLOPT_RETURNTRANSFER => true,
			CURLOPT_ENCODING => "",
			CURLOPT_MAXREDIRS => 10,
			CURLOPT_TIMEOUT => 30,
			CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
			CURLOPT_CUSTOMREQUEST => "PUT",
			CURLOPT_POSTFIELDS => $postData,
			CURLOPT_HTTPHEADER => [
				"Authorization: Bearer {$accessToken}",
				"content-type: application/json"
			],
		]);

		$response = curl_exec($curl);
		$err = curl_error($curl);

		curl_close($curl);

		if ($err) {
			echo json_encode(
				array(
					'result' => false,
					'errorMsg' => 'API 실패'
				)
			);
			exit;
		} else {
			//답변처리
			$sql = "UPDATE smart_store_product_qna SET answered = 'Y', answer = '{$answerText}' WHERE questionId = {$questionId}";
			db_query($sql);



			echo json_encode(
				array(
					'result' => true,
				)
			);
			exit;
		}








	}

	//스마트스토어 고객문의 답변
	else if($mode == 'sendSmartStoreCustomerAnswer'){

//		data: {'mode': 'sendSmartStoreProductAnswer',questionId, answerText},


		$inquiryNo = $_POST['inquiryNo'];
		$answerComment = $_POST['answerText'];

		if(!$inquiryNo || !$answerComment){

			echo json_encode(
				array(
					'result' => false,
					'errorMsg' => '답변ID 또는 답변문구가 없습니다.',
				)
			);
			exit;

		}


		//엑세스 토큰 획득
		$url = 'https://api.commerce.naver.com/external';
		$url2 = '/v1/oauth2/token';

		$url = $url.$url2;

		$millisec = (int)(microtime(TRUE) * 1000);

		$applicationID = '6A8ybd21sFrJGHQIMQM7hI';
		$applicationSecret = '$2a$04$aVpa1.MNj8.zMsbMIZ.Vi.';

		$signature = generateSignature($applicationID, $applicationSecret, $millisec);

		$apiData = array(
			'client_id' => $applicationID,
			'timestamp' => $millisec,
			'client_secret_sign' => $signature,
			'grant_type' => 'client_credentials',
			'type' => 'SELF'
		);

		$accessToken = requestCurl("POST", $url, $apiData);

		$accessToken = json_encode($accessToken);
		$accessToken = json_decode($accessToken, true);
		$accessToken = $accessToken['access_token'];


//		$questionId = $_POST['questionId'];
//		$answerText = $_POST['answerText'];

		$postData = array(
			'answerComment' => $answerComment,
		);

		$postData = json_encode($postData);

		$curl = curl_init();

//		https://api.commerce.naver.com/external/v1/pay-merchant/inquiries/{inquiryNo}/answer

		curl_setopt_array($curl, [
			CURLOPT_URL => "https://api.commerce.naver.com/external/v1/pay-merchant/inquiries/{$inquiryNo}/answer",
			CURLOPT_RETURNTRANSFER => true,
			CURLOPT_ENCODING => "",
			CURLOPT_MAXREDIRS => 10,
			CURLOPT_TIMEOUT => 30,
			CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
			CURLOPT_CUSTOMREQUEST => "POST",
			CURLOPT_POSTFIELDS => $postData,
			CURLOPT_HTTPHEADER => [
				"Authorization: Bearer {$accessToken}",
				"content-type: application/json"
			],
		]);

		$response = curl_exec($curl);
		$err = curl_error($curl);

		curl_close($curl);

		if ($err) {
			echo json_encode(
				array(
					'result' => false,
					'errorMsg' => 'API 실패'
				)
			);
			exit;
		} else {
			echo json_encode(
				array(
					'result' => true,
				)
			);
			exit;
		}
	}else if($mode == 'setBenepiaAllCancelFee'){

		$resNo = $_POST['resNo'];
		$checkValue = $_POST['checkValue'];

		$isResult = false;

		$errMsg = "eeeee";

		if($resNo && $checkValue){

			$sql = "UPDATE TB_RES_GOOD SET benepiaAllCancelFee = '{$checkValue}' WHERE res_no = '{$resNo}'";

			if(db_query($sql)){
				$isResult = true;
			}

		}else{

			$errMsg = "예약번호 또는 체크값이 없습니다. - 개발자에게 문의하세요.";

		}

		echo json_encode(
			array(
				'result' => $isResult,
//				'post' => $_POST,
//				'sql' => $sql,
				'errMsg' => $errMsg,
			)
		);

		exit;
	}else if($mode == 'getPrivateResInfo'){
		$matchKey = $_POST['matchPrivateKey'];

		$isReturn = false;
		$isReturnData = "";

		if($matchKey){
			$sql = "SELECT res_cust_nm, res_cust_nat_cd, res_cust_hp, b2b_sns_id FROM TB_RES_GOOD WHERE match_private_bus_key = '{$matchKey}'";
//			$sql = "SELECT * FROM TB_RES_GOOD WHERE match_private_bus_key = '{$matchKey}'";
			$isReturnData = db_fetch($sql);
			if($isReturnData){
				$isReturn = true;
			}
		}

		echo json_encode(
			array(
				'result' => $isReturn,
				'data' => $isReturnData,
			)
		);
		exit;
	}else if($mode == 'setGroup'){
		$seq = (int) $_POST['seq'];
		$val = $_POST['val'];

		if($seq && $val){
			$sql = "UPDATE TB_RES_GROUP_INQUIRY SET isConfirm = '{$val}' WHERE seq = {$seq}";

			if(db_query($sql)){
				echo json_encode(
					array(
						'result' => true,
						'val' => $val,
						'sql' => $sql,
					)
				);
				exit;
			}else{
				echo json_encode(
					array(
						'result' => false,
					)
				);
				exit;
			}
		}
	}else if($mode == 'setBreakfastPaid'){

		//조식 정산처리
		$resNo = $_POST['resNo'];

		if(!$resNo){
			echo json_encode(
				array(
					'result' => false,
				)
			);
			exit;
		}

		$tbName = "TB_RES_HOTEL_ITEM";

		//해당 조식에 대한 정보를 가져온다.
		$sql = "SELECT seq, buy_price, i_count FROM {$tbName} WHERE res_no = '{$resNo}' AND gu = 'B' AND self_calcu = 'N'";
		$res = db_query($sql);

		//기장일자
		$acc_dt = date('Y-m-d');

		$adminId = $_POST['to_mb_id'];
		$adminNm = $_POST['to_mb_nm'];

		while($rowData = db_fetch_array($res)){
			$peopleCnt = (int) $rowData['i_count'];

			$bankplus = (int) $rowData['buy_price'] * $peopleCnt;

			$seq = (int) $rowData['seq'];

			$remarks = $adminNm.' - 조식정산';
			$sql = "";
			$sql .= "INSERT INTO TB_ACCOUNT_CUSTOMER SET ";
			$sql .= "res_no = '{$resNo}',";
			$sql .= "acc_dt = '{$acc_dt}',";
			$sql .= "bank_plus = $bankplus,";
			$sql .= "pgcase_cd = 'INST001',";
			$sql .= "remarks = '{$adminNm}',";
			$sql .= "ins_nm = '{$adminNm}',";
			$sql .= "ins_dt = now(),";
			$sql .= "admin_id = '{$adminId}',";
			$sql .= "admin_nm = '{$adminNm}',";
			$sql .= "ins_mb_id = '{$adminId}'";

			if(db_query($sql)){
				if($seq){
					$sql2 = "UPDATE {$tbName} SET self_calcu = 'Y' WHERE seq = {$seq}";
					db_query($sql2);
				}
			}else{
				$sql2 = 'aaa';
			}
		}

		echo json_encode(
			array(
				'result' => true,
				'sql' => $sql,
				'sql2' => $sql2,
			)
		);

		exit;
	}


	else if($mode == 'getWxPayData'){

		$res_no = $_POST['res_no'];
		if($res_no){
			$sql = "SELECT count(*) AS cnt FROM TB_ACCOUNT_CUSTOMER WHERE res_no = '{$res_no}' AND pgcase_cd = 'INST010' AND bank_plus > 0";
			$res = db_fetch($sql);
			$cnt = (int) $res['cnt'];

			if($cnt > 0){
				echo json_encode(
					array(
						'result' => true,
						'sql'=>$sql,
					)
				);
			}else{
				echo json_encode(
					array(
						'result' => false,
						'sql'=>$sql,
					)
				);
			}

		}else{
			echo json_encode(
				array(
					'result' => false,
					'errorMsg' => 'no res_no',
				)
			);

		}
		exit;

	}else if($mode == 'setWishGood'){


		$g_uid = $_POST['g_uid_no'];
		$gTitle = $_POST['gTitle'];
		$b_uid = $_POST['b_uid_no'];
		$m_uid = $_POST['m_uid_no'];
		$s_uid = $_POST['s_uid_no'];
		$tab = $_POST['tabInfo'];
		$memberId = $_POST['memberId'];
		$memberName = $_POST['memberName'];
		$dUid = $_POST['dUid'];
		$dTitle = $_POST['dTitle'];
		$lang = $_POST['lang'];
		$curunit = $_POST['curunit'];

		$dstart = $_POST['dstart'];

		if($dstart){
			$dstart = explode(" ",$dstart);
			$dstart = str_replace(".","-",$dstart[0]);
		}

		$sql = "INSERT INTO TB_MEMBER_WISH SET ";
		$sql .= "mb_id = '{$memberId}', ";
		$sql .= "mb_nm = '{$memberName}', ";
		$sql .= "b_uid = {$b_uid}, ";
		$sql .= "m_uid = {$m_uid}, ";
		$sql .= "s_uid = 0, ";
		$sql .= "tab = '{$tab}', ";
		$sql .= "g_uid = {$g_uid}, ";
		$sql .= "g_title = '{$gTitle}', ";
		$sql .= "d_uid = {$dUid}, ";
		$sql .= "d_title = '{$dTitle}', ";
		$sql .= "d_start = '{$dstart}', ";
		$sql .= "ins_dt = now(), ";
		$sql .= "lang = '{$lang}', ";
		$sql .= "curunit = '{$curunit}'";

		db_query($sql);

		echo json_encode(
			array(
				'result' => true,
//				'errorMsg' => 'wish',
//				'sql' => $sql,
			)
		);
		exit;
	}

	//메일 매크로
	//예약정보 새로 받기
	else if($mode == 'resetErrorMailReservation'){
		$resNo = $_POST['resNo'];
		$voucherNo = $_POST['voucherNo'];
		$naverEmailSeq = $_POST['naverEmailSeq'];

		if(!$resNo || !$voucherNo || !$naverEmailSeq){

			echo json_encode(
				array(
					'result' => false,
					'resNo' => $resNo,
					'voucherNo' => $voucherNo,
					'errorMsg' => '예약번호 또는 바우처번호가 없습니다.',
				)
			);

			exit;
		}

		$sql = "DELETE FROM TB_RES_GOOD WHERE res_no = '{$resNo}'";
		db_query($sql);

		$sql = "DELETE FROM TB_RES_GOOD_PERSON WHERE res_no = '{$resNo}'";
		db_query($sql);

		$sql = "DELETE FROM TB_ACCOUNT_CUSTOMER WHERE res_no = '{$resNo}'";
		db_query($sql);

		$sql = "UPDATE macro_naver_mail SET status = 'N' WHERE naver_mail_id = '{$naverEmailSeq}'";
		db_query($sql);

		echo json_encode(
			array(
				'result' => true,
				'resNo' => $resNo,
				'voucherNo' => $voucherNo,
			)
		);

		exit;
	}


	//네이버 스마트스토어 값 변경
	// ssid, thisValue
	else if($mode == 'setCheckSmartStore'){
		$ssid = (int) $_POST['ssid'];
		$thisValue = $_POST['thisValue'];

		if($thisValue == 'N'){
			$thisValue = 'Y';
		}else{
			$thisValue = 'N';
		}

		if($ssid > 0){

			$tbName = "smart_store_api_error";

			$sql = "UPDATE {$tbName} SET checkYn = '{$thisValue}' WHERE ssid = {$ssid}";

			$isResult = false;
			if(db_query($sql)){
				$isResult = true;
			}

			echo json_encode(
				array(
					'result' => true,
					'errMsg' => '',
					'process' => $isResult,
					'val' => $thisValue,
				)
			);

		}else{
			echo json_encode(
				array(
					'result' => false,
					'errMsg' => '수신 데이터가 없습니다.',
				)
			);
		}
		exit;
	}


	//(gUid, thisValue)
	else if($mode == 'setSeoIndexing'){
		$gUid = (int) $_POST['gUid'];
		$thisValue = $_POST['thisValue'];
		$device =  $_POST['device'];

		if($thisValue == 'N'){
			$thisValue = 'Y';
		}else{
			$thisValue = 'N';
		}

		if($gUid > 0){

			$tbName = "good";

			$targetField = "is_seo_indexing_pc";
			if($device == 'mo'){
				$targetField = "is_seo_indexing_mobile";
			}

			$sql = "UPDATE {$tbName} SET {$targetField} = '{$thisValue}' WHERE g_uid = {$gUid}";

			$isResult = false;
			if(db_query($sql)){
				$isResult = true;
			}

			echo json_encode(
				array(
					'result' => true,
					'errMsg' => '',
					'process' => $isResult,
					'val' => $thisValue,
					'sql' => $sql,
				)
			);
			exit;

		}else{
			echo json_encode(
				array(
					'result' => false,
					'errMsg' => '수신 데이터가 없습니다.',
				)
			);
		}
		exit;
	}



	else if($mode == 'setGoodsRecommend'){
		//data: {mode: 'setGoodsRecommend', gUid, isRecommendChecked},
		$gUid = (int) $_POST['gUid'];

		$isCheckedRecommend = '0';
		if($_POST['isRecommendChecked'] == 'true'){
			$isCheckedRecommend = '1';
		}

		if($gUid > 0){
			$sql = "UPDATE good SET GM02 = '{$isCheckedRecommend}' WHERE g_uid = {$gUid}";

			if(db_query($sql)){

				echo json_encode(
					array(
						'result' => true,
					)
				);

			}else{

				echo json_encode(
					array(
						'result' => false,
						'errorMsg' => '실패 개발자에게 문의하세요.',
					)
				);

			}
		}else{
			echo json_encode(
				array(
					'result' => false,
					'errorMsg' => '상품번호가 없습니다.',
				)
			);
		}
		exit;
	}


	else if($mode == 'setHotelsRecommend'){
		//data: {mode: 'setGoodsRecommend', gUid, isRecommendChecked},
		$hseq = (int) $_POST['hseq'];

		$isCheckedRecommend = 'N';
		if($_POST['isRecommendChecked'] == 'true'){
			$isCheckedRecommend = 'Y';
		}

		if($hseq > 0){
			$sql = "UPDATE TB_HOTEL SET g_main2 = '{$isCheckedRecommend}' WHERE hseq = {$hseq}";

			if(db_query($sql)){
//			if(1){

				echo json_encode(
					array(
						'result' => true,
//						'sql' => $sql,
					)
				);

			}else{

				echo json_encode(
					array(
						'result' => false,
						'errorMsg' => '실패 개발자에게 문의하세요.',
					)
				);

			}
		}else{
			echo json_encode(
				array(
					'result' => false,
					'errorMsg' => '상품번호가 없습니다.',
				)
			);
		}
		exit;
	}



	/**
	 *
	 * 메인페이지 예약달력 다음달 예약인원수
	 * data: {mode:'afterResForCalendarOnMainPage', nextMonth},
	 */
	else if($mode == 'afterResForCalendarOnMainPage'){

		$nextMonth = $_POST['nextMonth'];

		if($nextMonth){

			$resCntList = array();

			$evStartDate = $nextMonth;
			$sqlRes = "SELECT res_no, ev_start  FROM TB_RES_GOOD WHERE order_state IN ('B','F') AND lang != 'ko' AND tab IN ('P','D') AND srh_b_uid NOT IN (162, 114, 127,135,143) AND srh_m_uid NOT IN (389,449,300,383,321,395,448,296) AND ev_start LIKE '{$evStartDate}%'";
			$resRes = db_query($sqlRes);


			while($dataRowRes = db_fetch_array($resRes)){

				if(isset($resCntList[$dataRowRes['ev_start']])){
					$resCntList[$dataRowRes['ev_start']] += 1;
				}else{
					$resCntList[$dataRowRes['ev_start']] = 1;
				}
			}

			//                            p($resCntList);

			$sql = "SELECT calendar_date FROM TB_PRIVATE_DEPART WHERE calendar_date LIKE '{$evStartDate}%' AND isShow = 'Y' {$siteTypeWhereSQL}";
			$rs = db_query($sql);

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

				if(isset($resCntList[$row['calendar_date']])){
					$resCntList[$row['calendar_date']] += 1;
				}else{
					$resCntList[$row['calendar_date']] = 1;
				}
			}



		}else{

		}
		echo json_encode(
			array(
				'result' => true,
				'val' => $nextMonth,
				'data' => $resCntList,
			)
		);

	}

	//SEO URL 카테고리 추가
	else if($mode == 'inputSeoCategoryUrl'){
//		data: {mode:'inputSeoCategoryUrl',seoCategoryUrl},



		$seoCategoryUrl = trim($_POST['seoCategoryUrl']);
		$seoCategoryUrl = strip_tags($seoCategoryUrl);

//		$seoCategoryUrl = str_replace("-","a2a2a2a2",$seoCategoryUrl);

		$seoCategoryUrl = strtolower($seoCategoryUrl);
//		$seoCategoryUrl = RemoveSpecialChar($seoCategoryUrl);

//		$seoCategoryUrl = str_replace("a2a2a2a2","-",$seoCategoryUrl);


		$ins_id = $_POST['ins_id'];



		if($seoCategoryUrl){

			//중복 데이터가 있는지 확인
			$sql = "SELECT count(*) AS cnt FROM seo_category_url WHERE seo_category_url = '{$seoCategoryUrl}'";
			$data = db_fetch($sql);


			if($data['cnt'] == 0){

				//폴더생성

				$isCreatingFolder = true;

				/*$isCreatingFolder = false;
				if(mkdir($_SERVER['DOCUMENT_ROOT'].'/'.$seoCategoryUrl)){
					$isCreatingFolder = true;
				}else{
					//폴더가 있는지 확인
					if(is_dir($_SERVER['DOCUMENT_ROOT'].'/'.$seoCategoryUrl)){
						$isCreatingFolder = true;
					}
				}*/

				$sql = "INSERT INTO seo_category_url SET seo_category_url = '{$seoCategoryUrl}'";
				$sql .= ", ins_id = '{$ins_id}'";
				$sql .= ", ins_dt = now()";


				if(db_query($sql)){




					echo json_encode(
						array(
							'result' => true,
							'isCreatingFolder' => $isCreatingFolder
						)
					);
					exit;

				}else{
					echo json_encode(
						array(
							'result' => true,
							'errMsg' => 'SEO 카테고리명 입력 실패했습니다. - 개발자에게 문의하세요.',
						)
					);
					exit;
				}

			}else{

				echo json_encode(
					array(
						'result' => false,
						'errMsg' => '이미 SEO 카테고리명이 있습니다.',
					)
				);
				exit;

			}

		}else{
			echo json_encode(
				array(
					'result' => false,
					'errMsg' => 'SEO 카테고리명을 입력하세요.',
				)
			);
			exit;
		}


	}
	//seo good url 중복체크
	else if($mode == 'seoDuplicateCheck'){
//		data: {mode:'seoDuplicateCheck', seoGoodUrl, nowLang},

		$firstCategoryUrl = $_POST['firstCategoryUrl'];
		$secondCategoryUrl = $_POST['secondCategoryUrl']; //concert
		$seoGoodUrl = $_POST['seoGoodUrl']; //
		$nowLang = $_POST['nowLang'];

//		$categoryUrl = 'concert'; //concert
//		$seoGoodUrl = 'bof-busan-one-asia-festival-kpop'; //
//		$nowLang = 'hk';

		$sql = "SELECT b_uid FROM good WHERE seo_first_category_url = '{$firstCategoryUrl}' AND seo_second_category_url = '{$secondCategoryUrl}' AND seo_good_url = '{$seoGoodUrl}'";
		$res = db_query($sql);

		$goodList = array();

		while($dataRow = db_fetch_array($res)){
			array_push($goodList, $dataRow['b_uid']);
		}


		$sql = "SELECT b_uid, b_lang FROM bc WHERE DelFlag = 'N' AND b_lang IN ('ko','en','cn','hk')";
		$res = db_query($sql);

		$bUidList = array();

		while($dataRow = db_fetch_array($res)){
			$bUidList[$dataRow['b_uid']] = $dataRow['b_lang'];
		}

		//중복검사
		$isDuplicate = false;

		foreach($goodList as $item){
			if($bUidList[$item] == $nowLang){
				$isDuplicate = true;
			}
		}

		echo json_encode(
			array(
				'result' => true,
				'isDuplicate' => $isDuplicate,
			)
		);

		exit;

	}

	//SEO URL 초기화
	else if($mode == 'initSeoUrl'){
		//data: {mode:'initSeoUrl',guid},
		$gUid = (int) $_POST['guid'];
		if($gUid){
			$sql = "UPDATE good SET seo_first_category_url = NULL, seo_second_category_url = NULL, seo_good_url = NULL WHERE g_uid = {$gUid}";


			if(db_query($sql)){

				echo json_encode(
					array(
						'result' => true,
						'sql' => $sql,
					)
				);
				exit;

			}else{

				echo json_encode(
					array(
						'result' => false,
						'errMsg' => '개발자에게 문의하세요.',
					)
				);
				exit;

			}





		}else{
			echo json_encode(
				array(
					'result' => false,
					'errMsg' => '상품번호가 없습니다. - 개발자 문의',
				)
			);
			exit;
		}
	}

	//특수문자제거
function RemoveSpecialChar($str)
{
	$res = preg_replace('/[0-9\@\.\;\" "]+/', '', $str);
	return $res;
}


/**
 * 전자서명 생성
 * @param String $clientId          클라이언트 ID
 * @param String $clientSecret      클라이언트 시크릿
 * @param String $timestamp         밀리초(millisecond) 단위의 Unix 시간
 * @return String
 */
function generateSignature($clientId, $clientSecret, $timestamp)
{
	if (strlen($clientSecret) < 22) {
		return '';
	}

	// 밑줄로 연결하여 password 생성
	$password = $clientId . "_" . $timestamp;
	$clientSecret = str_replace('+', '.', $clientSecret);

	// 암호화
	$cryptedSignature = crypt($password, $clientSecret);

	// base64 인코딩
	return base64_encode($cryptedSignature);
}

function requestCurl($method, $url, $data = array())
{

	$curlHandle = curl_init();

	/* CURL option Setting */
	if ($method === "GET") {

	} elseif ($method === "POST" || $method == "PUT") {
		curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $data);
	}
	curl_setopt($curlHandle, CURLOPT_CUSTOMREQUEST, $method);
	curl_setopt($curlHandle, CURLOPT_URL, $url);
	curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);

	/* CURL result */
	$response = curl_exec($curlHandle);
	curl_close($curlHandle);
	return json_decode($response);
}



function myEncrypt($str, $secret_key='secret key', $secret_iv='secret iv')
{
	$key = hash('sha256', $secret_key);
	$iv = substr(hash('sha256', $secret_iv), 0, 32)    ;
	return str_replace("=", "", base64_encode(
			openssl_encrypt($str, "AES-256-CBC", $key, 0, $iv))
	);
}

function myDecrypt($str, $secret_key='secret key', $secret_iv='secret iv')
{
	$key = hash('sha256', $secret_key);
	$iv = substr(hash('sha256', $secret_iv), 0, 32);
	return openssl_decrypt(
		base64_decode($str), "AES-256-CBC", $key, 0, $iv
	);
}


	exit;



?>
























Anon7 - 2021