<?php
// 매물정보 DAO 
include $_SERVER['DOCUMENT_ROOT'].'/common/lib/comm.php';
	
$cdDealerP= trim(avoid_crack($_REQUEST["cdDealerP"]));
$PageNo = trim(avoid_crack($_REQUEST["PageNo"]));
$PageSize = trim(avoid_crack($_REQUEST["PageSize"]));
$pageStartPoint = trim(avoid_crack($_REQUEST["pageStartPoint"]));


$defaultWhere =" where s.ds_delind='N' ";
switch($mode) {
	
	//매물리스트 
	case "listNormal" :
		$where_is ="";
		$where_is = $where_is. " and s.ds_status in ('ZS') ";
		$where_is = $where_is. " and s.nm_cont_postscript != '' ";
		$where_is = $where_is. " and s.cd_sale in (select cd_sale from tender_master where cd_dealer_p = '$cdDealerP') ";
		 
		$totalCount = @mysql_result(mysql_query("select count(*) from sale_master 
													$defaultWhere $where_is "),0,0);		
		
		$sql = " SELECT 
			s.*
			, (select (select nm_model from car_model where cd_model = c.cd_model) from car_master c where c.cd_car = s.cd_car) as nm_model
		FROM sale_master s 
		$defaultWhere $where_is order by s.cd_sale desc LIMIT $pageStartPoint,$PageSize";

		$r = mysql_query($sql);
		
		$jsonArray = array();
		while($row = mysql_fetch_array($r)) {

			$row[totalCnt] = $totalCount;

			array_push($jsonArray,$row);
		}	
	   	echo json_encode($jsonArray);		
	break;
	default :
		echo "999";
	break;
}
$dbCon->close();
die();

?>