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

switch($mode) {

	//입찰 금액 수정 
	case "changePrice":

		$cd_userid = trim($_SESSION["admin_cd_userid"]);
		$cd_tender = trim($_POST["cd_tender"]);
		$nm_price = trim($_POST["nm_price"]);

		$sql="UPDATE tender_master set 
				nm_price ='$nm_price'
				, dt_update = now()
				, nm_update = '$cd_userid'
			where cd_tender = '$cd_tender'";

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

		if ($result) {
			echo("Y");
			exit;
		}else{
			echo("N");
			exit;
		}

	break;

	//관리자 낙찰하기 
	case "changeTender":

		$cd_userid = trim($_SESSION["admin_cd_userid"]);
		$cd_sale = trim($_POST["cd_sale"]);
		$cd_tender = trim($_POST["cd_tender"]);

		// 낙찰 내역 확인
		$table_name = "tender_master";
		$_whereis = " cd_sale = '". $cd_sale . "' and ds_status = 'Z0' and ds_delind = 'N' ";

		$row = $dbCon->selectDAO("*", $table_name, $_whereis);	

		//현재 낙찰된 내역 초기화
		if ($row['cd_tender']) {
			$cd_tender_old = $row['cd_tender'];
			$sql="UPDATE tender_master set 
					ds_status = 'A0'
					, dt_update = now()
					, nm_update = '$cd_userid'
				where cd_tender = '$cd_tender_old' ";

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

			if ($result) {
			}else{
				echo("N");
				exit;
			}
		}

		$sql="UPDATE tender_master set 
				ds_status = 'Z0' 
				, dt_update = now()
				, nm_update = '$cd_userid'
			where cd_tender = '$cd_tender'";

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

		$sql="update sale_master as a 
					inner join tender_master as b 
					on (
						a.cd_sale = b.cd_sale 
						and b.cd_tender = $cd_tender 
					) 
				set 
					a.ds_status = 'Z0'
					, a.nm_price = b.nm_price 
					, a.dt_update = now()
					, a.nm_update = '$cd_userid' 
				"; 

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

		if ($result) {
			echo("Y");
			exit;
		}else{
			echo("N");
			exit;
		}

	break;

	default :
		AlertRedirect("지정되지않은 요청입니다","/index.php");
	break;
}
mysql_close($connect);
?>