<?php
	session_start();	
	require_once("db/db.php");	
	require_once("common/common.php");

	require_once("JpGraph/src/jpgraph.php");
	require_once("JpGraph/src/jpgraph_bar.php");
	
	$strHotelDay=$_REQUEST['HotelDate'];
	$strnewchainno=$_REQUEST['ChainNo'];
	$strHotelDay1=$strHotelDay;
	
	$strDayName1="";
	$fltDayVal1=0;
	
	$strDayName2="";
	$fltDayVal2=0;
	
	$strDayName3="";
	$fltDayVal3=0;
	
	$strDayName4="";
	$fltDayVal4=0;
	
	$strDayName5="";
	$fltDayVal5=0;
	
	$strDayName6="";
	$fltDayVal6=0;
	
	$strDayName7="";
	$fltDayVal7=0;
	
	$strDayName8="";
	$fltDayVal8=0;
	
	$strDayName9="";
	$fltDayVal9=0;
	
	$strDayName10="";
	$fltDayVal10=0;
	
	$strDayName11="";
	$fltDayVal11=0;
	
	$strDayName12="";
	$fltDayVal12=0;
	
	$strDayName13="";
	$fltDayVal13=0;
	
	$strDayName14="";
	$fltDayVal14=0;
	
	$strDayName15="";
	$fltDayVal15=0;
	
	$sql=sprintf("SELECT RIGHT(convert(varchar(10),'%s',120),5)+' ' AS DayName,RIGHT(convert(varchar(10),DateAdd(day,-1,'%s'),120),5)+' ' AS DayName1,
					RIGHT(convert(varchar(10),DateAdd(day,-2,'%s'),120),5)+' ' AS DayName2,RIGHT(convert(varchar(10),DateAdd(day,-3,'%s'),120),5)+' ' AS DayName3,
					RIGHT(convert(varchar(10),DateAdd(day,-4,'%s'),120),5)+' ' AS DayName4,RIGHT(convert(varchar(10),DateAdd(day,-5,'%s'),120),5)+' ' AS DayName5,
					RIGHT(convert(varchar(10),DateAdd(day,-6,'%s'),120),5)+' ' AS DayName6,RIGHT(convert(varchar(10),DateAdd(day,-7,'%s'),120),5)+' ' AS DayName7,
					RIGHT(convert(varchar(10),DateAdd(day,-8,'%s'),120),5)+' ' AS DayName8,RIGHT(convert(varchar(10),DateAdd(day,-9,'%s'),120),5)+' ' AS DayName9,
					RIGHT(convert(varchar(10),DateAdd(day,-10,'%s'),120),5)+' ' AS DayName10,RIGHT(convert(varchar(10),DateAdd(day,-11,'%s'),120),5)+' ' AS DayName11,
					RIGHT(convert(varchar(10),DateAdd(day,-12,'%s'),120),5)+' ' AS DayName12,RIGHT(convert(varchar(10),DateAdd(day,-13,'%s'),120),5)+' ' AS DayName13,
					RIGHT(convert(varchar(10),DateAdd(day,-14,'%s'),120),5)+' ' AS DayName14,DATEADD(DAY,-16,'%s') AS StartDay",$strHotelDay,$strHotelDay,$strHotelDay,$strHotelDay,$strHotelDay,$strHotelDay,$strHotelDay,
					$strHotelDay,$strHotelDay,$strHotelDay,$strHotelDay,$strHotelDay,$strHotelDay,$strHotelDay,$strHotelDay,$strHotelDay);
	$result = querySql($sql);		
	if($row = fetch_array($result))
	{
		$strDayName1=$row['DayName'];
		$strDayName2=$row['DayName1'];
		$strDayName3=$row['DayName2'];
		$strDayName4=$row['DayName3'];
		$strDayName5=$row['DayName4'];
		$strDayName6=$row['DayName5'];
		$strDayName7=$row['DayName6'];
		$strDayName8=$row['DayName7'];
		$strDayName9=$row['DayName8'];
		$strDayName10=$row['DayName9'];
		$strDayName11=$row['DayName10'];
		$strDayName12=$row['DayName11'];
		$strDayName13=$row['DayName12'];
		$strDayName14=$row['DayName13'];
		$strDayName15=$row['DayName14'];
		
		$strHotelDay1=$row['StartDay'];
	}
	freeResult($result);
	
	$intPos=1;
	$strTemp="";
	$fltTemp=1;
	
	$sql=sprintf("SELECT HotelDate,RIGHT(convert(varchar(10),HotelDate,120),5)+' 'AS DayName,ROUND(DayVal,0)AS DayVal FROM TR_RepHotelDayReport 
				WHERE ItemName='客房出租率' AND HotelDate>'%s' And HotelDate<='%s' AND Chain_No='%s' ORDER BY HotelDate DESC",$strHotelDay1,$strHotelDay,$strnewchainno);
	
	$result = querySql($sql);		
	while($row = fetch_array($result))
	{
		$strTemp=$row['DayName'];
		$fltTemp=$row['DayVal'];
		
		switch($intPos)
		{
			case 1:
				$strDayName1=$strTemp;
				$fltDayVal1=$fltTemp;
				break;
			case 2:
				$strDayName2=$strTemp;
				$fltDayVal2=$fltTemp;
				break;
			case 3:
				$strDayName3=$strTemp;
				$fltDayVal3=$fltTemp;
				break;
			case 4:
				$strDayName4=$strTemp;
				$fltDayVal4=$fltTemp;
				break;
			case 5:
				$strDayName5=$strTemp;
				$fltDayVal5=$fltTemp;	
				break;
			case 6:
				$strDayName6=$strTemp;
				$fltDayVal6=$fltTemp;
				break;
			case 7:
				$strDayName7=$strTemp;
				$fltDayVal7=$fltTemp;	
				break;
			case 8:
				$strDayName8=$strTemp;
				$fltDayVal8=$fltTemp;	
				break;
			case 9:
				$strDayName9=$strTemp;
				$fltDayVal9=$fltTemp;	
				break;
			case 10:
				$strDayName10=$strTemp;
				$fltDayVal10=$fltTemp;	
				break;
			case 11:
				$strDayName11=$strTemp;
				$fltDayVal11=$fltTemp;	
				break;
			case 12:
				$strDayName12=$strTemp;
				$fltDayVal12=$fltTemp;	
				break;
			case 13:
				$strDayName13=$strTemp;
				$fltDayVal13=$fltTemp;	
				break;
			case 14:
				$strDayName14=$strTemp;
				$fltDayVal14=$fltTemp;	
				break;
			case 15:
				$strDayName15=$strTemp;
				$fltDayVal15=$fltTemp;	
				break;
			}	
			$intPos=$intPos + 1;
		}
		//释放数据库
		freeResult($result);
		closeDb();	
		
		$strChrTitle=sprintf("最近15日出租率 (结束日期%s)",$strHotelDay);
		
		//header("content-type:image/jpeg");
		$datay=array($fltDayVal15,$fltDayVal14,$fltDayVal13,$fltDayVal12,$fltDayVal11,$fltDayVal10,$fltDayVal9,$fltDayVal8,$fltDayVal7,$fltDayVal6,$fltDayVal5,$fltDayVal4,$fltDayVal3,$fltDayVal2,$fltDayVal1);	//定义数组
		$graph=new Graph(350,250,"auto");			//创建画布
		$graph->SetScale('textlin');
		$graph->yaxis->scale->SetGrace(20);
		$graph->SetShadow();						//创建画布阴影
		//设置统计图所在画布的位置，左边距40，右边距30，上边距30，下边距40 单位像素
		$graph->img->SetMargin(40,20,30,20);
		$bplot=new BarPlot($datay);					//创建一个矩形的对象
		$graph->Add($bplot);						//将柱形图添加到图像中
		//$bplot->SetFillColor('orange');				//设置柱形的颜色
		$bplot->value->SetFormat('%d');				//在柱形图中显示格式化的出租率
		$bplot->value->Show();						//设置显示数字
		//$graph->SetMarginColor('lightblue');		//设置画布背景色为淡蓝色
		$graph->title->Set($strChrTitle);//创建标题
		
		//设置X坐标轴文字
		$strDayName2="";
		$strDayName4="";
		$strDayName6="";
		$strDayName8="";
		$strDayName10="";
		$strDayName12="";
		$strDayName14="";
		$a=array($strDayName15,$strDayName14,$strDayName13,$strDayName12,$strDayName11,$strDayName10,$strDayName9,$strDayName8,$strDayName7,$strDayName6,$strDayName5,$strDayName4,$strDayName3,$strDayName2,$strDayName1);
		$graph->xaxis->SetTickLabels($a);			//设置X轴
		$graph->title->SetFont(FF_SIMSUN);			//设置标题的字体
		$graph->xaxis->SetFont(FF_SIMSUN,FS_BOLD,8);			//设置X轴的字体
		$graph->Stroke();							//输出图像
		
?>