<?php
/*********************************************************      
 程序说明：         
    功能说明：
              
    调用关系：调用: header.inc     
              被调用:        
 
    变量说明：

    Author: lilong    2003-12-19      
      
*********************************************************/
require("../../inc/header.inc");
?>
<!--
<body onLoad="clock()" leftmargin="12" topmargin="0">
-->
<body leftmargin="15" rightmargin="10" onload="javascript:adjust_frame('down');javascript:clock();" onresize="javascript:adjust_frame('down');" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">

<?php

function show_alarm($info,$backurl)
{
	echo "\n<script language=\"JavaScript\">\n";
	echo "parent.window.location.href=\"../../element/bssSpecific/alarm_show.php?info=$info&backurl=$backurl\";\n";
	echo "</script>\n";
		
}
adjust_head_frame("down");
adjust_title_head_frame("down");
adjust_title_tail_frame("down");

adjust_content_head_frame("down");	
echo "<br>";

$DEBUG=0;
$db='PPS_DB';
global $OMC_server;
$ppsDbConn = mysqli_connect($OMC_server[0]['host'],$OMC_server[0]['user'],$OMC_server[0]['password'], $db);

$face_value_type = 6;
$moneyPara = getMoneyPara_forPpsReport();		//显示的货币单位是最小货币单位的倍数

$moneyPara=$moneyPara+0;

if(!isset($moneyPara)||$moneyPara==0||trim($moneyPara)=="")
{
  $info="The parameter (currency_decimal) <br> has no value,please set it!";
 	$backurl="../../sysDefine/pubVarDef/paramList.php";
 	show_alarm($info,$backurl);
}


$dotLen = strLen($moneyPara) - 1;
//echo "<br>dotLen=$dotLen";

$query_year=$_REQUEST['query_year'];
$query_week=$_REQUEST['query_week'];


if ($DEBUG) echo "query_year = $query_year,query_week = $query_week<br>";
$fmtBit = "%01.".$dotLen."f";
?>

<script LANGUAGE="JavaScript" language="JavaScript1.2">
var server_timestamp=<?php echo mktime(); ?>;
var now = new Date();
var client_timestamp = now.getTime() / 1000;
var diff_seconds = server_timestamp - client_timestamp;

function clock()
{
	now = new Date();
	var timeZoneOffsetMin = now.getTimezoneOffset();
	var years   = now.getFullYear();
	var months  = now.getMonth();
	var days    = now.getDate();
	var hours   = now.getHours();
	var minutes = now.getMinutes()+timeZoneOffsetMin;
	var seconds = now.getSeconds()+diff_seconds;

	theDate=new Date(Date.UTC(years,months,days,hours,minutes,seconds));
	var DateYear=theDate.getFullYear();
      
	var DateMonth=theDate.getUTCMonth()+1;
	DateMonth=((DateMonth < 10) ? "0" : "")+DateMonth;
      
	var DateDay=theDate.getUTCDate();
	DateDay=((DateDay < 10) ? "0" : "")+DateDay;

	var DateHour=theDate.getUTCHours();
	DateHour=((DateHour < 10) ? "0" : "")+DateHour;

	var DateMinute=theDate.getUTCMinutes();
	DateMinute=((DateMinute < 10) ? "0" : "")+DateMinute;

	var DateSecond=theDate.getUTCSeconds();
	DateSecond=((DateSecond < 10) ? "0" : "")+DateSecond;

	var Time=DateYear+"-"+DateMonth+"-"+DateDay+" "+DateHour+":"+DateMinute+":"+DateSecond;
		
	//document.clock.time.value=Time;
	document.getElementById("time").value=Time;
	Timer = setTimeout("clock()",1000);
}
</script>
<?php

function getWeekNumFromDay($day){
	$DEBUG = 0;
	$pieces = explode("-",$day);
	$weekNum = date("w",mktime(0,0,0,$pieces[1],$pieces[2],$pieces[0]));
	if($DEBUG) echo "day=$day, weekNum=$weekNum<br>";
	return ($weekNum);
}

if(!$query_year) 
{
	$query_year=date("Y",mktime(0,0,0,date("m"),date("d")-1,date("Y")));	
}

$firstw			= date("w",mktime(0,1,0,1,1,date($query_year)));
$lastDayNumber	= date("z",mktime(0,0,0,date("m"),date("d")-1,date("Y")))+1;
$lastWeekNumber	= floor(($lastDayNumber-(7-$firstw)) / 7)+1;
if ($DEBUG) echo "firstw = $firstw,";
if ($DEBUG) echo "lastDayNumber=$lastDayNumber,";
if ($DEBUG) echo "lastWeekNumber=$lastWeekNumber<br>";

if(!$query_week) 
{
	$query_week=$lastWeekNumber;
}

$defaultWeek="$query_year-$query_week";
if($DEBUG) echo "defaultWeek=$defaultWeek<br>";
$year=date("Y")."-".date("m")."-".date("d").",".date("w");
if($DEBUG) echo "Today is $year<br>";

$thisFebDays=date("t",mktime(0,0,0,2,1,date("Y")));
if($DEBUG) echo "thisFebDays=$thisFebDays<br>";

$strWeek = array(
	"0" => "Sun",
	"1" => "Mon",
	"2" => "Tue",
	"3" => "Wed",
	"4" => "Thu",
	"5" => "Fri",
	"6" => "Sat",
);

$monDays = array(
	"0" => "31",
	"1" => "$thisFebDays",
	"2" => "31",
	"3" => "30",
	"4" => "31",
	"5" => "30",
	"6" => "31",
	"7" => "31",
	"8" => "30",
	"9" => "31",
	"10" => "30",
	"11" => "31",
);
/*
$i=0;
for($i=0;$i<12;$i++){
	echo "$monDays[$i],";
}
*/
$selWeekFirstDayNumber	= 7-$firstw+($query_week-2)*7+1;
if($DEBUG) echo "selWeekFirstDayNumber=$selWeekFirstDayNumber,";

$i=0;
while($selWeekFirstDayNumber>=$monDays[$i]){
	$selWeekFirstDayNumber = $selWeekFirstDayNumber-$monDays[$i];
	$i++;
};
$bgnMonth = $i+1;
$bgnDay = $selWeekFirstDayNumber;

$bgnDay = (($bgnDay<10&&$bgnDay>0)?"0":"").$bgnDay;
if($bgnDay>0)
	$bgnDay = $query_year."-".$bgnMonth."-".$bgnDay;
elseif($bgnDay<=0){
        if($bgnMonth<=1)
        {
                $bgnYear=$query_year-1;
                $bgnDay =31+$bgnDay;
                $bgnDay = $bgnYear."-12"."-".$bgnDay;
        }
        else
        {
                $bgnMonth = $bgnMonth - 1;
                $bgnDay =$monDays[$bgnMonth-1];
                $bgnDay = $query_year."-".$bgnMonth."-".$bgnDay;
        }
}


if($DEBUG) echo "bgnMonth=$bgnMonth,";
if($DEBUG) echo "bgnDay=$bgnDay<br>";


$selWeekLastDayNumber	= 7-$firstw+($query_week-1)*7;
if($DEBUG) echo "selWeekLastDayNumber=$selWeekLastDayNumber,";

$i=0;
while($selWeekLastDayNumber>=$monDays[$i]){
	$selWeekLastDayNumber = $selWeekLastDayNumber-$monDays[$i];
	$i++;
};
$endMonth = $i+1;
$endDay = $selWeekLastDayNumber;
$endDay = ($endDay<10?"0":"").$endDay;
$endDay = $query_year."-".$endMonth."-".$endDay;
if($DEBUG) echo "endDay=$endDay<br>";

echo "<br>";

$selSQL	="SELECT * FROM daily_report WHERE date>='$bgnDay' and date<='$endDay' order by date ASC";
if($DEBUG) echo "selSQL=$selSQL<br>";
$selRes	= mysqli_query($ppsDbConn,$selSQL);
echo mysqli_error($ppsDbConn);
$selRow	= @mysqli_fetch_array($selRes);
if(!$selRow){
	echo "No record found!($query_year-$query_week)!"; 
	exit();
}
//Account summary
$lastWeekBalance=0;
$thisWeekRecharge=0;
$thisWeekBalance=0;
$thisWeekCharge=0;

//Account report
$thisWeekFresh=0;
$thisWeekInuse=0;
$thisWeekSuspended=0;
$thisWeekBlacklist=0;
$thisWeekReleased=0;
$thisWeekOprTrial=0;
$thisWeekTotal=0;

//Recharge card
$faceValue1=0;
$thisWeekFaceValue1Used=0;
$thisWeekFaceValue1Unused=0;
$faceValue2=0;
$thisWeekFaceValue2Used=0;
$thisWeekFaceValue2Unused=0;
$faceValue3=0;
$thisWeekFaceValue3Used=0;
$thisWeekFaceValue3Unused=0;
$faceValue4=0;
$thisWeekFaceValue4Used=0;
$thisWeekFaceValue4Unused=0;
$faceValue5=0;
$thisWeekFaceValue5Used=0;
$thisWeekFaceValue5Unused=0;
$faceValue6=0;
$thisWeekFaceValue6Used=0;
$thisWeekFaceValue6Unused=0;

//Call statistics
$thisWeekIncomingCallNumber=0;
$thisWeekIncomingCallDuration=0;
$thisWeekIncomingCallCharge=0;

$thisWeekLocalCallNumber=0;
$thisWeekLocalCallDuration=0;
$thisWeekLocalCallCharge=0;

$thisWeekIDDCallNumber=0;
$thisWeekIDDCallDuration=0;
$thisWeekIDDCallCharge=0;

$thisWeekNDDCallNumber=0;
$thisWeekNDDCallDuration=0;
$thisWeekNDDCallCharge=0;

$thisWeekShortMessageNumber=0;
$thisWeekShortMessageDuration=0;
$thisWeekShortMessageCharge=0;

$thisWeekShortMessageViaWebNumber=0;
$thisWeekShortMessageViaWebDuration=0;
$thisWeekShortMessageViaWebCharge=0;

$thisWeekConferenceCallNumber=0;
$thisWeekConferenceCallDuration=0;
$thisWeekConferenceCallCharge=0;

$thisWeekRentNumber=0;
$thisWeekRentDuration=0;
$thisWeekRentCharge=0;

$thisWeekRechargeSuccNumber=0;
$thisWeekRechargeSuccDuration=0;
$thisWeekRechargeSuccCharge=0;

$thisWeekRechargeFailNumber=0;
$thisWeekRechargeFailDuration=0;
$thisWeekRechargeFailCharge=0;

$thisWeekOperatorRechargeNumber=0;
$thisWeekOperatorRechargeDuration=0;
$thisWeekOperatorRechargeCharge=0;

$thisWeekChargeNumber=0;
$thisWeekChargeDuration=0;
$thisWeekChargeCharge=0;

$thisWeekTotalNumber=0;
$thisWeekTotalDuration=0;
$thisWeekTotalCharge=0;

$thisWeekTotalGPRSVolume=0;
$thisWeekTotalGPRSDuration=0;
$thisWeekTotalGPRSCharged=0;

$thisWeekTotalSMSNumber=0;
$thisWeekTotalSMSCharged=0;
$thisWeekTotalMMSSendNumber=0;
$thisWeekTotalMMSSendCharged=0;
$thisWeekTotalMMSRetrieveNumber=0;
$thisWeekTotalMMSRetrieveCharged=0;
$thisWeekTotalMMSEmailNumber=0;
$thisWeekTotalMMSEmailCharged=0;

do{
	//Account summary
	if($lastWeekBalance == 0){
		$lastWeekBalance	= $selRow[yesterday_balance];
	}
	$thisWeekRecharge	+= $selRow[today_recharge];
	$thisWeekBalance	= $selRow[today_balance];
	$thisWeekCharge		+= $selRow[today_charge];
	$weekNum			= getWeekNumFromDay("$selRow[date]");
	$dayCharge[$weekNum]	= $selRow[today_charge];

	//Account report
	$thisWeekFresh		= $selRow[fresh_user_num];
	$thisWeekInuse		= $selRow[normal_user_num];
	$thisWeekSuspended	= $selRow[suspend_user_num];
	$thisWeekBlacklist	= $selRow[blacklist_user_num];
	$thisWeekReleased	= $selRow[released_user_num];
	$thisWeekOprTrial = $selRow[opr_trial_user_num];
	$thisWeekTotal		= $selRow[total_user_num];

	//Recharge card
	$faceValue1						= ($selRow[precard_facevalue1]>0)?$selRow[precard_facevalue1]:$faceValue1;
	$thisWeekFaceValue1Used			+= $selRow[precard_used_today1];
	$dayFaceValue1Used[$weekNum]	= $selRow[precard_used_today1];
	$thisWeekFaceValue1Unused		= $selRow[precard_unused1];

	$faceValue2						= ($selRow[precard_facevalue2]>0)?$selRow[precard_facevalue2]:$faceValue2;
	$thisWeekFaceValue2Used			+= $selRow[precard_used_today2];
	$dayFaceValue2Used[$weekNum]	= $selRow[precard_used_today2];
	$thisWeekFaceValue2Unused		= $selRow[precard_unused2];
	
	$faceValue3						= ($selRow[precard_facevalue3]>0)?$selRow[precard_facevalue3]:$faceValue3;
	$thisWeekFaceValue3Used			+= $selRow[precard_used_today3];
	$dayFaceValue3Used[$weekNum]	= $selRow[precard_used_today3];
	$thisWeekFaceValue3Unused		= $selRow[precard_unused3];
	
	$faceValue4						= ($selRow[precard_facevalue4]>0)?$selRow[precard_facevalue4]:$faceValue4;
	$thisWeekFaceValue4Used			+= $selRow[precard_used_today4];
	$dayFaceValue4Used[$weekNum]	= $selRow[precard_used_today4];
	$thisWeekFaceValue4Unused		= $selRow[precard_unused4];
	
	$faceValue5						= ($selRow[precard_facevalue5]>0)?$selRow[precard_facevalue5]:$faceValue5;
	$thisWeekFaceValue5Used			+= $selRow[precard_used_today5];
	$dayFaceValue5Used[$weekNum]	= $selRow[precard_used_today5];
	$thisWeekFaceValue5Unused		= $selRow[precard_unused5];
	
	$faceValue6						= ($selRow[precard_facevalue6]>0)?$selRow[precard_facevalue6]:$faceValue6;
	$thisWeekFaceValue6Used			+= $selRow[precard_used_today6];
	$dayFaceValue6Used[$weekNum]	= $selRow[precard_used_today6];
	$thisWeekFaceValue6Unused		= $selRow[precard_unused6];

	//Call statistics
	$thisWeekIncomingCallNumber	+= $selRow[incoming_call_num ];
	$thisWeekIncomingCallDuration	+= $selRow[incoming_call_duration];
	$thisWeekIncomingCallCharge	+= $selRow[incoming_call_charge];

	$thisWeekLocalCallNumber	+= $selRow[local_callout_num];
	$thisWeekLocalCallDuration	+= $selRow[local_callout_duration];
	$thisWeekLocalCallCharge	+= $selRow[local_callout_charge];

	$thisWeekIDDCallNumber		+= $selRow[IDD_call_num];
	$thisWeekIDDCallDuration	+= $selRow[IDD_call_duration];
	$thisWeekIDDCallCharge		+= $selRow[IDD_call_charge];

	$thisWeekNDDCallNumber		+= $selRow[NDD_call_num];
	$thisWeekNDDCallDuration	+= $selRow[NDD_call_duration];
	$thisWeekNDDCallCharge		+= $selRow[NDD_call_charge];

	$thisWeekShortMessageNumber		+= $selRow[short_message_num];
	$thisWeekShortMessageDuration	+= $selRow[short_message_duration];
	$thisWeekShortMessageCharge		+= $selRow[short_message_charge];

	$thisWeekShortMessageViaWebNumber		+= $selRow[short_message_via_web_num];
	$thisWeekShortMessageViaWebDuration		+= $selRow[short_message_via_web_duration];
	$thisWeekShortMessageViaWebCharge		+= $selRow[short_message_via_web_charge];

	$thisWeekConferenceCallNumber	+= $selRow[conference_call_num];
	$thisWeekConferenceCallDuration	+= $selRow[conference_call_duration];
	$thisWeekConferenceCallCharge	+= $selRow[conference_call_charge];

	$thisWeekRentNumber				+= $selRow[rent_charging_num];
	$thisWeekRentDuration			+= $selRow[rent_charging_duration];
	$thisWeekRentCharge				+= $selRow[rent_charge];

	$thisWeekRechargeSuccNumber		+= $selRow[recharge_suc_num];
	$thisWeekRechargeSuccDuration	+= $selRow[recharge_suc_duration];
	$thisWeekRechargeSuccCharge		+= $selRow[recharge_suc];

	$thisWeekRechargeFailNumber		+= $selRow[recharge_fail_num];
	$thisWeekRechargeFailDuration	+= $selRow[recharge_fail_duration];
	$thisWeekRechargeFailCharge		+= $selRow[recharge_fail];

	$thisWeekOperatorRechargeNumber		+= $selRow[ast_recharge_num];
	$thisWeekOperatorRechargeDuration	+= $selRow[ast_recharge_duration];
	$thisWeekOperatorRechargeCharge		+= $selRow[ast_recharge];
	
	$thisWeekChargeNumber				+= $selRow[ast_charge_num];
	$thisWeekChargeDuration				+= $selRow[ast_charge_duration];
	$thisWeekChargeCharge				+= $selRow[ast_charge];

	$thisWeekTotalNumber				+= $selRow[total_call_num];
	$thisWeekTotalDuration				+= $selRow[total_call_duration];
	
	$thisWeekTotalCharge				+= $selRow[total_call_charge];
	
	$thisWeekTotalGPRSVolume+=($selRow[gprs_volume]-0)/1024;
	$thisWeekTotalGPRSDuration+=($selRow[gprs_duration]-0)/3600;
	$thisWeekTotalGPRSCharged+=$selRow[gprs_charged]-0;

	$thisWeekTotalSMSNumber+=$selRow[sms_number];
	$thisWeekTotalSMSCharged+=$selRow[sms_charged];
	$thisWeekTotalMMSSendNumber+=$selRow[mms_send_number];
	$thisWeekTotalMMSSendCharged+=$selRow[mms_send_charged];
	$thisWeekTotalMMSRetrieveNumber+=$selRow[mms_retrieve_number];
	$thisWeekTotalMMSRetrieveCharged+=$selRow[mms_retrieve_charged];
	$thisWeekTotalMMSEmailNumber+=$selRow[mms_email_number];
	$thisWeekTotalMMSEmailCharged+=$selRow[mms_email_charged];
	
}while($selRow=mysqli_fetch_array($selRes));

$thisWeekTotalGPRSVolume=number_format($thisWeekTotalGPRSVolume,3,'.','');
$thisWeekTotalGPRSDuration=number_format($thisWeekTotalGPRSDuration,3,'.','');

if($DEBUG){
	echo "lastWeekBalance=$lastWeekBalance, ";
	echo "thisWeekRecharge=$thisWeekRecharge, ";
	echo "thisWeekBalance=$thisWeekBalance, ";
	echo "thisWeekCharge=$thisWeekCharge, ";
	echo "<br>";
	echo "thisWeekFresh=$thisWeekFresh, ";
	echo "thisWeekInuse=$thisWeekInuse, ";
	echo "thisWeekSuspended=$thisWeekSuspended, ";
	echo "thisWeekBlacklist=$thisWeekBlacklist, ";
	echo "thisWeekReleased=$thisWeekReleased, ";
	echo "thisWeekTotal=$thisWeekTotal, ";
	echo "<br>";
	echo "faceValue1=$faceValue1, ";
	echo "thisWeekFaceValue1Used=$thisWeekFaceValue1Used, ";
	echo "thisWeekFaceValue1Unused=$thisWeekFaceValue1Unused, ";
	echo "<br>";
	echo "thisWeekFaceValue2Used=$thisWeekFaceValue2Used, ";
	echo "thisWeekFaceValue2Unused=$thisWeekFaceValue2Unused, ";
	echo "thisWeekFaceValue3Used=$thisWeekFaceValue3Used, ";
	echo "thisWeekFaceValue3Unused=$thisWeekFaceValue3Unused, ";
	echo "thisWeekFaceValue4Used=$thisWeekFaceValue4Used, ";
	echo "thisWeekFaceValue4Unused=$thisWeekFaceValue4Unused, ";
	echo "<br>";
}

/*********************   统计该月几周的收费情况及充值卡 *************************/
/*
echo "bgnDay=$bgnDay, endDay=$endDay<br>";
$pieces = explode("-",$endDay);
$query_month = $pieces[1];
$tmp = date("w",mktime(0,0,0,$query_month,1,$query_year));
echo "query_month=$query_month, tmp=$tmp<br>";
$week1FirstDay = date("Y",mktime(0,0,0,$query_month,1-$tmp,$query_year))."-".
				date("m",mktime(0,0,0,$query_month,1-$tmp,$query_year))."-".
				date("d",mktime(0,0,0,$query_month,1-$tmp,$query_year));
echo "week1FirstDay=$week1FirstDay<br>";
*/

/*********************   统计该周前5周的收费情况及充值卡情况 ********************/
if($DEBUG) echo "bgnDay=$bgnDay, endDay=$endDay<br>";
for($i=4;$i>0;$i--){
	//start day
	$pieces = explode("-",$bgnDay);
	$query_month	= $pieces[1];
	$query_day		= $pieces[2];
	
	$weekStart[4-$i] = date("Y",mktime(0,0,0,$pieces[1],$pieces[2]-$i*7,$pieces[0]))."-".
				date("m",mktime(0,0,0,$pieces[1],$pieces[2]-$i*7,$pieces[0]))."-".
				date("d",mktime(0,0,0,$pieces[1],$pieces[2]-$i*7,$pieces[0]));

	//end day
	$pieces = explode("-",$endDay);
	$query_month	= $pieces[1];
	$query_day		= $pieces[2];
	$weekEnd[4-$i] = date("Y",mktime(0,0,0,$pieces[1],$pieces[2]-$i*7,$pieces[0]))."-".
				date("m",mktime(0,0,0,$pieces[1],$pieces[2]-$i*7,$pieces[0]))."-".
				date("d",mktime(0,0,0,$pieces[1],$pieces[2]-$i*7,$pieces[0]));
}
$weekStart[4]	= $bgnDay;
$weekEnd[4]		= $endDay;
if($DEBUG){
	echo "$weekStart[0], $weekEnd[0]<br>";
	echo "$weekStart[1], $weekEnd[1]<br>";
	echo "$weekStart[2], $weekEnd[2]<br>";
	echo "$weekStart[3], $weekEnd[3]<br>";
	echo "$weekStart[4], $weekEnd[4]<br>";
}

for($i=0;$i<5;$i++){
	$weekCharge[$i]=0;
	$selBgnDay		= $weekStart[$i];
	$selEndDay		= $weekEnd[$i];
	if($DEBUG) echo "selBgnDay=$selBgnDay, selEndDay=$selEndDay<br>";
	$selSQL	= "SELECT * FROM daily_report WHERE date>='$selBgnDay' and date<='$selEndDay'";
	if($DEBUG) echo "selSQL=$selSQL<br>";
	$selRes	= mysqli_query($ppsDbConn,$selSQL);
	echo mysqli_error($ppsDbConn);
	$selRow	= @mysqli_fetch_array($selRes);
	do{
		$weekCharge[$i]			+= $selRow[today_charge];
		$weekFaceValue1Used[$i]	+= $selRow[precard_used_today1];
		$weekFaceValue2Used[$i]	+= $selRow[precard_used_today2];
		$weekFaceValue3Used[$i]	+= $selRow[precard_used_today3];
		$weekFaceValue4Used[$i]	+= $selRow[precard_used_today4];
		$weekFaceValue5Used[$i]	+= $selRow[precard_used_today5];
		$weekFaceValue6Used[$i]	+= $selRow[precard_used_today6];
	}while($selRow	= @mysqli_fetch_array($selRes));
	if($DEBUG){
		echo "weekCharge[$i]=$weekCharge[$i]<br>";
		echo "weekFaceValue1Used[$i]=$weekFaceValue1Used[$i]<br>";
		echo "weekFaceValue2Used[$i]=$weekFaceValue2Used[$i]<br>";
		echo "weekFaceValue3Used[$i]=$weekFaceValue3Used[$i]<br>";
		echo "weekFaceValue4Used[$i]=$weekFaceValue4Used[$i]<br>";
	}

	$thisWeek	= $query_week-4+$i;
	if($thisWeek<1)
		$thisWeek=$thisWeek+52;
	$label[$i]	= "W".$thisWeek;
	if($DEBUG) echo "label[$i]=$label[$i]<br>";
	if($DEBUG) echo "<br>";
}
$firstWeek	= $label[0];
$lastWeek	= $label[4];

?>

<?php 
//----------------------------------页面标题---------------------------------------------------------
?>
<table border="0" width="100%" cellpadding="2" cellspacing="0" bordercolor="#FFFFFF" bordercolordark="#FFFFFF">  
  <tr>
    <td width="25%">
	</td>
	<td width="50%" align="center">
	&nbsp;
	</td>
<td width="20%" align="right">      
<div onClick="window.print();" style="cursor:hand">
<img align=absBottom border=0 src="../../images/printer.gif" width="16" height="16"><?php echo "&nbsp;$strDailyBtnPrint";?>
</div>
</td>
  </tr>
</table>
<br>


<?php
echo "<center><b>";
echo "PPS report W$query_week($bgnDay ~ $endDay)";
echo "</b></center>";
//----------------------------------全局统计--------------------------------------------------------
?>
<table border="1" width="100%" cellpadding="2" cellspacing="0" bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF">  
  <tr bgcolor=#E6E6E6 >  
  <?php
    echo "<td width=\"16%\">&nbsp;</td>";
    echo "<td width=\"42%\">$strDailyUserState</td> "; 
    echo "<td align=\"right\" width=\"42%\">$strDailyUserNum</td> ";  
  ?>  
  </tr>  
   <?php
    echo "<tr>";
    echo "<td rowspan=\"7\">$strDailyUserTitle</td>";
    $fresh_user_num = showComma($thisWeekFresh);
    echo "<td>$strDailyFresh</td>";
    echo "<td align=\"right\">$fresh_user_num</td>";
    echo "</tr>";

    echo "<tr>";
    $normal_user_num = showComma($thisWeekInuse);
    echo "<td>$strDailyUsing</td>";
    echo "<td align=\"right\">$normal_user_num</td>";
    echo "</tr>";

    echo "<tr>";
    $suspend_user_num = showComma($thisWeekSuspended);
    echo "<td>$strDailySuspend</td>";
    echo "<td align=\"right\">$suspend_user_num</td>";
    echo "</tr>";

    echo "<tr>";
    $blacklist_user_num = showComma($thisWeekBlacklist);
    echo "<td>$strBlackList</td>";
    echo "<td align=\"right\">$blacklist_user_num</td>";
    echo "</tr>";

    echo "<tr>";
    $released_user_num = showComma($thisWeekReleased);
    echo "<td>$strReleased</td>";
    echo "<td align=\"right\">$released_user_num</td>";
    echo "</tr>";
    
    echo "<tr>";
    $opr_trial_user_num = showComma($thisWeekOprTrial);
    echo "<td>OPR Trial</td>";
    echo "<td align=\"right\">$opr_trial_user_num</td>";
    echo "</tr>";
    
    $selRow[released_user_num];
    
    echo "<tr>";
    $total_user_num = showComma($thisWeekTotal);
    echo "<td>$strTotal</td>";
    echo "<td align=\"right\">$total_user_num</td>";
    echo "</tr>";
?>  
</table>  

<?php
//-------------------------------------------充值卡本周统计---------------------------------------------
?>   
<p></p>
<table  border="1" width="100%" cellpadding="2" cellspacing="0" bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF">   
  <tr bgcolor=#E6E6E6>   
  <?php
    echo "<td width=\"16%\">&nbsp;</td>";
    echo "<td width=\"16.8%\">$strDailyCardFace</td>  ";
	for($i=1;$i<=$face_value_type;$i++)
	{
		$ValueList="precard_facevalue".$i;
		$showValue=${"faceValue".$i}/$moneyPara;
		if($showValue == 0){
			echo "<td align=\"right\" width=\"10%\">--</td>";
			$arr_FaceValueList[$i] = 0;
		}else{
			echo "<td align=\"right\" width=\"10%\">&nbsp;($strValueCurrency";
			echo "$showValue)";
			echo "</td>";
			$arr_FaceValueList[$i] = 1;
		}
	}
  ?>
  </tr>  
  <?php
    echo "<tr>";
    echo "<td rowspan=\"2\">$strPrepaidCard</td>";  
    echo "<td>Used</td>";
	for($i=1;$i<=$face_value_type;$i++)
	{
		$precard_used_today="precard_used_today".$i;
		$precardUsed=showComma(${"thisWeekFaceValue".$i."Used"});
		if($arr_FaceValueList[$i] == 1){
			echo "<td align=\"right\">$precardUsed</td>";
		}else{
			echo "<td align=\"right\">--</td>";
		}
	}
	echo "</tr>";

	echo "<tr>";  
    echo "<td>$strNotCharged</td>";
	for($i=1;$i<$face_value_type+1;$i++)
	{
		$precard_unused="precard_unused".$i;
		$precardUnused=showComma(${"thisWeekFaceValue".$i."Unused"});
		if($arr_FaceValueList[$i] == 1){
			echo "<td align=\"right\">$precardUnused</td>";
		}else{
			echo "<td align=\"right\">--</td>";
		}
	}
	echo "</tr>";
   ?>

</table>

<?php
//----------------------------------当日话单统计-----------------------------------------------------------
?>  
<p></p>
<table border="1" width="100%" cellpadding="2" cellspacing="0" bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF">  
  <tr bgcolor=#E6E6E6>  
  <?php
    echo "<td width=\"16%\">&nbsp;</td>";
    echo "<td width=\"21%\">$strDailyCallType</td>  ";
    echo "<td width=\"21%\" align=\"right\">$strDailyCallTimes</td>  ";
    echo "<td width=\"21%\" align=\"right\">$strDailyCallDuration</td>  ";
    echo "<td width=\"21%\" align=\"right\">$strDailyCallCharge</td>  ";
  ?>
  </tr>
 
  <tr >
    <td rowspan="11"><?php echo "$strCallStatistics"; ?></td>  
    <?php
    echo "<td>$strDailyCallIncoming</td>";
    $incoming_call_nums = showComma($thisWeekIncomingCallNumber);
    $incoming_call_duration = showComma($thisWeekIncomingCallDuration);
    $incoming_call_charge = showComma(sprintf("$fmtBit",$thisWeekIncomingCallCharge/$moneyPara));
    echo "<td align=\"right\">$incoming_call_nums</td>";
    echo "<td align=\"right\">$incoming_call_duration</td>";
    echo "<td align=\"right\">$incoming_call_charge</td>";
    ?>
  </tr>

  <tr >
   <?php
    echo "<td>$strDailyCallIDD</td>";
    $IDD_call_nums = showComma($thisWeekIDDCallNumber);
    $IDD_call_duration = showComma($thisWeekIDDCallDuration);
    $IDD_call_charge = showComma(sprintf("$fmtBit",$thisWeekIDDCallCharge/$moneyPara));
    echo "<td align=\"right\">$IDD_call_nums</td>";
    echo "<td align=\"right\">$IDD_call_duration</td>";
    echo "<td align=\"right\">$IDD_call_charge</td>";
   ?>
  </tr>

  <tr >
   <?php
    echo "<td>$strDailyCallNDD</td>";
    $NDD_call_nums = showComma($thisWeekNDDCallNumber);
    $NDD_call_duration = showComma($thisWeekNDDCallDuration);
    $NDD_call_charge = showComma(sprintf("$fmtBit",$thisWeekNDDCallCharge/$moneyPara));
    echo "<td align=\"right\">$NDD_call_nums</td>";
    echo "<td align=\"right\">$NDD_call_duration</td>";
    echo "<td align=\"right\">$NDD_call_charge</td>";
   ?>
  </tr>

  <tr >
   <?php
    echo "<td>$strDailyCallLocalOut</td>";
    $local_callout_nums = showComma($thisWeekLocalCallNumber);
    $local_callout_duration = showComma($thisWeekLocalCallDuration);
    $local_callout_charge = showComma(sprintf("$fmtBit",$thisWeekLocalCallCharge/$moneyPara));
    echo "<td align=\"right\">$local_callout_nums</td>";
    echo "<td align=\"right\">$local_callout_duration</td>";
    echo "<td align=\"right\">$local_callout_charge</td>";
   ?>
  </tr>

<!--	Short message	-->
  <tr>
   <?php
    echo "<td>$strDailyCallSMS</td>";
    $short_message_nums = showComma($thisWeekShortMessageNumber);
    $short_message_duration = showComma($thisWeekShortMessageDuration);
    $short_message_charge = showComma(sprintf("$fmtBit",$thisWeekShortMessageCharge/$moneyPara));
    echo "<td align=\"right\">$short_message_nums</td>";
    echo "<td align=\"right\">$short_message_duration</td>";
    echo "<td align=\"right\">$short_message_charge</td>";
   ?>
  </tr>

<!--	Short message via web	-->
  <tr>
   <?php
    echo "<td>$strDailyCallSMSViaWeb</td>";
    $short_message_nums = showComma($thisWeekShortMessageViaWebNumber);
    $short_message_duration = showComma($thisWeekShortMessageViaWebDuration);
    $short_message_charge = showComma(sprintf("$fmtBit",$thisWeekShortMessageViaWebCharge/$moneyPara));
    echo "<td align=\"right\">$short_message_nums</td>";
    echo "<td align=\"right\">$short_message_duration</td>";
    echo "<td align=\"right\">$short_message_charge</td>";
   ?>
  </tr>

  <tr>
   <?php
    echo "<td>$strDailyCallConferenceCall</td>";
    $conference_call_nums = showComma($thisWeekConferenceCallNumber);
    $conference_call_duration = showComma($thisWeekConferenceCallDuration);
    $conference_call_charge = showComma(sprintf("$fmtBit",$thisWeekConferenceCallCharge/$moneyPara));
    echo "<td align=\"right\">$conference_call_nums</td>";
    echo "<td align=\"right\">$conference_call_duration</td>";
    echo "<td align=\"right\">$conference_call_charge</td>";
   ?>
  </tr>

  <tr>
   <?php
    echo "<td>$strDailyCallRent</td>";
    $rent_charging_nums = showComma($thisWeekRentNumber);
    $rent_charging_duration = showComma($thisWeekRentDuration);
    $rent_charge = showComma(sprintf("$fmtBit",$thisWeekRentCharge/$moneyPara));
    echo "<td align=\"right\">$rent_charging_nums</td>";
    echo "<td align=\"right\">$rent_charging_duration</td>";
    echo "<td align=\"right\">$rent_charge</td>";
   ?>
  </tr>
<!--
  <tr>
   <?php
    echo "<td>$strDailyCharged</td>";
    $recharge_suc_nums = showComma($thisWeekRechargeSuccNumber);
    $recharge_suc_duration = showComma($thisWeekRechargeSuccDuration);
    $recharge_suc = showComma(sprintf("$fmtBit",$thisWeekRechargeSuccCharge/$moneyPara));
    echo "<td align=\"right\">$recharge_suc_nums</td>";
    echo "<td align=\"right\">$recharge_suc_duration</td>";
    echo "<td align=\"right\">$recharge_suc</td>";
   ?>
  </tr>
-->
  <tr>
   <?php
    echo "<td>$strOperatorRecharge</td>";
    $ast_recharge_nums = showComma($thisWeekOperatorRechargeNumber);
    $ast_recharge_duration = showComma($thisWeekOperatorRechargeDuration);
    $ast_recharge = showComma(sprintf("$fmtBit",$thisWeekOperatorRechargeCharge/$moneyPara));
    echo "<td align=\"right\">$ast_recharge_nums</td>";
    echo "<td align=\"right\">$ast_recharge_duration</td>";
    echo "<td align=\"right\">$ast_recharge</td>";
   ?>
  </tr>

  <tr>
   <?php
    echo "<td>$strOperatorCharge</td>";
    $ast_charge_nums = showComma($thisWeekChargeNumber);
    $ast_charge_duration = showComma($thisWeekChargeDuration);
    $ast_charge = showComma(sprintf("$fmtBit",$thisWeekChargeCharge/$moneyPara));
    echo "<td align=\"right\">$ast_charge_nums</td>";
    echo "<td align=\"right\">$ast_charge_duration</td>";
    echo "<td align=\"right\">$ast_charge</td>";
   ?>
  </tr>

  <tr>
   <?php
    echo "<td>$strTotal</td>";
    $total_call_num = showComma($thisWeekTotalNumber);
    $total_call_charge = showComma(sprintf("$fmtBit",$thisWeekTotalCharge/$moneyPara));
    $total_call_duration = showComma($thisWeekTotalDuration);
    echo "<td align=\"right\">$total_call_num</td>";
    echo "<td align=\"right\">$total_call_duration</td>";
    echo "<td align=\"right\">$total_call_charge</td>";
   ?>
  </tr>
</table>
<p></p>
<?php
	echo "<table border=\"1\" width=\"100%\" cellpadding=\"2\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#FFFFFF\">";
	echo "<tr bgcolor=\"#E6E6E6\">";
	echo "<td width=16%>&nbsp;</td>";
	echo "<td>GPRS volume(MB)</td>";
	echo "<td>GPRS duration(H)</td>";
	echo "<td>GPRS charged</td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<td>GPRS statistic</td>";
	echo "<td align=\"right\">&nbsp;$thisWeekTotalGPRSVolume</td>";
	echo "<td align=\"right\">&nbsp;$thisWeekTotalGPRSDuration</td>";
	echo "<td align=\"right\">&nbsp;$thisWeekTotalGPRSCharged</td>";
	echo "</tr>";
	
	echo "</table><br>";
	
	
	echo "<table border=\"1\" width=\"100%\" cellpadding=\"2\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#FFFFFF\">";
	echo "<tr bgcolor=\"#E6E6E6\">";
	echo "<td width=16%>&nbsp;</td>";
	echo "<td>SMS number</td>";
	echo "<td>SMS charged</td>";
	echo "<td>MMS send number</td>";
	echo "<td>MMS send charged</td>";
	echo "<td>MMS retrieve number</td>";
	echo "<td>MMS retrieve charged</td>";
	echo "<td>MMS email number</td>";
	echo "<td>MMS email number</td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<td>MMS statistic</td>";
	echo "<td align=\"right\">&nbsp;$thisWeekTotalSMSNumber</td>";
	echo "<td align=\"right\">&nbsp;$thisWeekTotalSMSCharged</td>";
	echo "<td align=\"right\">&nbsp;$thisWeekTotalMMSSendNumber</td>";
	echo "<td align=\"right\">&nbsp;$thisWeekTotalMMSSendCharged</td>";
	echo "<td align=\"right\">&nbsp;$thisWeekTotalMMSRetrieveNumber</td>";
	echo "<td align=\"right\">&nbsp;$thisWeekTotalMMSRetrieveCharged</td>";
	echo "<td align=\"right\">&nbsp;$thisWeekTotalMMSEmailNumber</td>";
	echo "<td align=\"right\">&nbsp;$thisWeekTotalMMSEmailCharged</td>";
	echo "</tr>";
	
	echo "</table>";
	
?>


<p></p>

<table border="1" width="100%" cellpadding="2" cellspacing="0" bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF">  
  <tr bgcolor=#E6E6E6>  
  <?php
    echo "<td width=\"16%\">&nbsp;</td>";
    echo "<td width=\"21%\" align=\"right\">$strAccountLastWeekBalance</td>";
    echo "<td width=\"21%\" align=\"right\">$strAccountThisWeekRecharge</td>";
    echo "<td width=\"21%\" align=\"right\">$strAccountThisWeekBalance</td>";
	echo "<td width=\"21%\" align=\"right\">$strAccountThisWeekCharge</td>";
  ?>
  </tr>
 
  <tr >
   <?php
    echo "<td>$strAccountSummary</td>";
    $yesterday_balance = showComma(sprintf("$fmtBit",$lastWeekBalance/$moneyPara));
    $today_recharge = showComma(sprintf("$fmtBit",$thisWeekRecharge/$moneyPara));
    $today_balance = showComma(sprintf("$fmtBit",$thisWeekBalance/$moneyPara));
	$today_charge = showComma(sprintf("$fmtBit",$thisWeekCharge/$moneyPara));
    echo "<td align=\"right\">$yesterday_balance</td>";
    echo "<td align=\"right\">$today_recharge</td>";
	echo "<td align=\"right\">$today_balance</td>";
	echo "<td align=\"right\">$today_charge</td>";
   ?>
  </tr>
<table>
<br>

<!--
******************************* Draw charge statistic graphic *************************
-->

<?php
$maxYNum=1;
for ($i=0;$i<7;$i++){
	$dayCharge[$i] = $dayCharge[$i]/$moneyPara;
	if($DEBUG) echo "dayCharge[$i]=$dayCharge[$i]<br>";
	$maxYNum = ($dayCharge[$i]>$maxYNum)?$dayCharge[$i]:$maxYNum;
}
$maxYNum = (ceil($maxYNum/80)+1)*80;
if($DEBGU) echo "maxYNum=$maxYNum<br>";
$legendArr=array(
			array('Charge','7D0000',0)
			);
$title="W".$query_week." call charge statistic.";


//-----图片背景和坐标，标示等基本元素，请勿修改这部分
$DEBUG=0;
$sizex=550;
$sizey=270;
$bgcolor=F8F8F8;
$fgcolor=000000;
$dayStr=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$i,date("Y")));

$im = ImageCreate ($sizex, $sizey);

$background_color = ImageColorAllocate ($im, hexdec(substr($bgcolor, 0, 2)), hexdec(substr($bgcolor, 2, 2)),hexdec(substr($bgcolor, 4, 2)));

$text_color = ImageColorAllocate ($im, hexdec(substr($fgcolor, 0, 2)), hexdec(substr($fgcolor, 2, 2)),hexdec(substr($fgcolor, 4, 2)));

//背景
ImageFilledRectangle($im,0,0,$sizex,$sizey,ImageColorAllocate ($im, 198, 198, 198));
ImageFilledRectangle($im,2,2,$sizex,$sizey,ImageColorAllocate ($im, 130, 130, 130));
$pointArr=array(0,$sizey-1,3,$sizey-4,4,$sizey-1);
Imagefilledpolygon($im, $pointArr, 3, ImageColorAllocate ($im, 130, 130, 130));
$pointArr=array($sizex-1,0,$sizex-4,3,$sizex,4);
Imagefilledpolygon($im, $pointArr, 3, ImageColorAllocate ($im, 130, 130, 130));
ImageFilledRectangle($im,2,2,$sizex-3,$sizey-3,$background_color);

//边框
$xBgn=75;
$yBgn=15;
$xEnd=500;
$yEnd=215;
$unitXPix=60;
ImageLine($im, $xBgn, $yBgn, $xBgn, $yEnd, $text_color);
ImageLine($im, $xBgn, $yBgn, $xEnd, $yBgn, $text_color);
ImageLine($im, $xBgn, $yEnd, $xEnd, $yEnd, $text_color);
ImageLine($im, $xEnd, $yBgn, $xEnd, $yEnd, $text_color);

//竖网格及标注
for($i=0;$i<7;$i++){
	ImageDashedLine($im, $xBgn + $i*60, $yBgn, $xBgn + $i*60, $yEnd, $text_color);
	$strThisWeek = $strWeek[$i];
	Imagestring($im, 2, $xBgn + $i*60 - 4, $yEnd, "$strThisWeek",  $text_color);
}

//横网格及标注
for($i=0;$i<8;$i++){
	ImageDashedLine($im, $xBgn, $yBgn + $i*25, $xEnd, $yBgn + $i*25, $text_color);
/*
	$yRemark=$maxYNum / 8 * (8 - $i);
	Imagestring($im, 2, $xBgn - 50, $yBgn + $i*25 - 5, "$yRemark",  $text_color);
*/

	$scale=$maxYNum / 8 * (8 - $i);
	if($scale>1000*1000){
		$displayMaxData = round($scale/100000)/10;
		$displayMaxData = $displayMaxData."M";	
	}elseif($scale>1000){
		$displayMaxData = round($scale/100)/10;
		$displayMaxData = $displayMaxData."K";	
	}else
		$displayMaxData=$scale;
	Imagestring($im, 2, $xBgn - 50, $yBgn + $i*25 - 5, "$displayMaxData",  $text_color);	
}

//色块图标及说明
for($i=0;$i<sizeof($legendArr);$i++){
	$tmpName=$legendArr[$i][0];
	$tmpColor=$legendArr[$i][1];
	$color = ImageColorAllocate ($im, hexdec(substr($tmpColor, 0, 2)), hexdec(substr($tmpColor, 2, 2)),hexdec(substr($tmpColor, 4, 2)));
	$legendArr[$i][2]=$color;
	ImageFilledRectangle($im,82 + $i* 100,$yEnd + 22,80 + $i* 100 + 10,$yEnd + 30,$legendArr[$i][2]);
	Imagestring($im, 2, 95 + $i* 100,$yEnd + 20, "$tmpName",  $text_color);
}

//下部图表名称
//Imagestring($im, 2, 200,$yEnd + 40, $title,  $text_color);

//坐标转换函数，将数值转换成坐标
function getNewXY($pointArr)
{
	global	$xBgn,$yBgn,$xEnd,$yEnd,$maxYNum,$unitXPix;
	$DEBUG=0;
	for($i=0;$i<sizeof($pointArr);$i=$i+2){
		$pointArr[$i]	= $xBgn + $pointArr[$i] * $unitXPix;
		if($DEBUG) echo "<br>pointArr[$i]={$pointArr[$i]}";
		$pointArr[$i+1]	= $yEnd - round(($yEnd - $yBgn) * ($pointArr[$i+1] / $maxYNum));
		if($DEBUG) echo "<br>pointArr[$i+1]={$pointArr[$i+1]}";
	}
	$pointArr[$i]	= $pointArr[$i-2];
	if($DEBUG) echo "<br>pointArr[$i]={$pointArr[$i]}";
	$pointArr[$i+1]	= $yEnd-1;
	if($DEBUG) echo "<br>pointArr[$i+1]={$pointArr[$i+1]}";
	return($pointArr);
}

for($i=0;$i<7;$i++){
	$pointArr[$i*2] = $i;
	$pointArr[$i*2+1]	= $dayCharge[$i];
}
//-----开始画图（线或色块），需要修改
//色块
/*
$pointArr=getNewXY($pointArr);
$pointNum= sizeof($pointArr) / 2;
$tmpColor=$legendArr[0][2];
imagefilledpolygon($im, $pointArr, $pointNum, $tmpColor);
*/
//线条
$pointArr=getNewXY($pointArr);
$pointNum= sizeof($pointArr) / 2;
$tmpColor=$legendArr[0][2];
//imagepolygon($im, $pointArr, $pointNum, $tmpColor);
for($i=0;$i<6;$i++){
	imageline($im,$pointArr[$i*2],$pointArr[$i*2+1],$pointArr[$i*2+2],$pointArr[$i*2+3],$tmpColor);
}

?>

<table border="0" width="100%" cellpadding="2" cellspacing="0" bordercolor="#FFFFFF" bordercolordark="#FFFFFF">  
  <tr>
	<td width="75%" align="center">
	  <b>
	  <?php echo "Week $query_week call charge statistics";?>
	  </b>
	</td>
	<td width="25%"></td>
  </tr>
</table>

<?php
//-----输出图形文件，请勿修改
//delete *.png
$handle=opendir('.');
while($file=readdir($handle)){
	$retval="";
	$pt=strrpos($file,".");
	if($pt) $retval=substr($file,$pt+1,strlen($file)-$pt);
	if($retval=='png') unlink($file);
}
$filename=time().".png";
if(!$DEBUG){
	ImagePng ($im,"$filename");  
	ImageDestroy($im);	
}

//-----显示图片
echo "<body topmargin=\"0\" leftmargin=\"5\">";  
echo "<img src=\"$filename\">";
echo "</body>";
?>
<br><br>

<!--
******************************* Draw used charge card statistic graphic *************************
-->

<?php
$maxYNum=0;
for ($i=0;$i<7;$i++){
//	$j = (($i<10)?"0":"").$i;
	for($k=1;$k<=6;$k++){
//		${"dayFaceValue".$k."Used"}[$i] = ${"dayFaceValue".$k."Used"}[$j];
		$maxYNum = (${"dayFaceValue".$k."Used"}[$i]>$maxYNum)?${"dayFaceValue".$k."Used"}[$i]:$maxYNum;
	}
}
$maxYNum = (ceil($maxYNum/8)+1)*8;
if($DEBUG) echo "maxYNum=$maxYNum<br>";
for($i=0;$i<6;$i++){
	$faceValue[$i] = "Face value(".${"faceValue".($i+1)}/$moneyPara.")";
	$moneyPara;
}

$legendArr=array(
			array($faceValue[0],'0000FF',0),
			array($faceValue[1],'00FF00',0),
			array($faceValue[2],'FF0000',0),
			array($faceValue[3],'7D0000',0),
			array($faceValue[4],'FF00FF',0),
			array($faceValue[5],'eeaa22',0)
			);
/*
for($i=0;$i<4;$i++){
	$legendArr[$i*3]	= "Face value(".${"faceValue".$i}.")";
	$legendArr[$i*3+1]	= "7D7D00";
	$legendArr[$i*3+2]	= 0;
}
*/
$title="Week".$query_week." recharge card statistic.";


//-----图片背景和坐标，标示等基本元素，请勿修改这部分
$sizex=700;
$sizey=270;
$bgcolor=F8F8F8;
$fgcolor=000000;
$dayStr=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$i,date("Y")));

$im = ImageCreate ($sizex, $sizey);

$background_color = ImageColorAllocate ($im, hexdec(substr($bgcolor, 0, 2)), hexdec(substr($bgcolor, 2, 2)),hexdec(substr($bgcolor, 4, 2)));

$text_color = ImageColorAllocate ($im, hexdec(substr($fgcolor, 0, 2)), hexdec(substr($fgcolor, 2, 2)),hexdec(substr($fgcolor, 4, 2)));

//背景
ImageFilledRectangle($im,0,0,$sizex,$sizey,ImageColorAllocate ($im, 198, 198, 198));
ImageFilledRectangle($im,2,2,$sizex,$sizey,ImageColorAllocate ($im, 130, 130, 130));
$pointArr=array(0,$sizey-1,3,$sizey-4,4,$sizey-1);
Imagefilledpolygon($im, $pointArr, 3, ImageColorAllocate ($im, 130, 130, 130));
$pointArr=array($sizex-1,0,$sizex-4,3,$sizex,4);
Imagefilledpolygon($im, $pointArr, 3, ImageColorAllocate ($im, 130, 130, 130));
ImageFilledRectangle($im,2,2,$sizex-3,$sizey-3,$background_color);

//边框
$xBgn=75;
$yBgn=15;
$xEnd=500;
$yEnd=215;
$unitXPix=60;
ImageLine($im, $xBgn, $yBgn, $xBgn, $yEnd, $text_color);
ImageLine($im, $xBgn, $yBgn, $xEnd, $yBgn, $text_color);
ImageLine($im, $xBgn, $yEnd, $xEnd, $yEnd, $text_color);
ImageLine($im, $xEnd, $yBgn, $xEnd, $yEnd, $text_color);

//竖网格及标注
for($i=0;$i<7;$i++){
	ImageDashedLine($im, $xBgn + $i*60, $yBgn, $xBgn + $i*60, $yEnd, $text_color);
	$strThisWeek = $strWeek[$i];
	Imagestring($im, 2, $xBgn + $i*60 - 4, $yEnd, "$strThisWeek",  $text_color);
}

//横网格及标注
for($i=0;$i<8;$i++){
	ImageDashedLine($im, $xBgn, $yBgn + $i*25, $xEnd, $yBgn + $i*25, $text_color);
/*
	$yRemark=$maxYNum / 8 * (8 - $i);
	Imagestring($im, 2, $xBgn - 50, $yBgn + $i*25 - 5, "$yRemark",  $text_color);
*/
	$scale=$maxYNum / 8 * (8 - $i);
	if($scale>1000*1000){
		$displayMaxData = round($scale/100000)/10;
		$displayMaxData = $displayMaxData."M";	
	}elseif($scale>1000){
		$displayMaxData = round($scale/100)/10;
		$displayMaxData = $displayMaxData."K";	
	}else
		$displayMaxData=$scale;
	Imagestring($im, 2, $xBgn - 50, $yBgn + $i*25 - 5, "$displayMaxData",  $text_color);	
}


//色块图标及说明
for($i=0;$i<sizeof($legendArr);$i++){
	$tmpName=$legendArr[$i][0];
	$tmpColor=$legendArr[$i][1];
	$color = ImageColorAllocate ($im, hexdec(substr($tmpColor, 0, 2)), hexdec(substr($tmpColor, 2, 2)),hexdec(substr($tmpColor, 4, 2)));
	$legendArr[$i][2]=$color;
	ImageFilledRectangle($im,32 + $i* 110,$yEnd + 22,30 + $i* 110 + 10,$yEnd + 30,$legendArr[$i][2]);
	Imagestring($im, 2, 45 + $i* 110,$yEnd + 20, "$tmpName",  $text_color);
}

//下部图表名称
//Imagestring($im, 2, 200,$yEnd + 40, $title,  $text_color);

//face value 1
for($i=0;$i<7;$i++){
	$pointArr1[$i*2] = $i;
	$pointArr1[$i*2+1]	= $dayFaceValue1Used[$i];
	//echo "dayFaceValue1Used[$i]=$dayFaceValue1Used[$i]<br>";
}
//线条
$pointArr1=getNewXY($pointArr1);
$pointNum1= sizeof($pointArr1) / 2;
$tmpColor1=$legendArr[0][2];
if($DEBUG){
	for($i=0;$i<14;){
		echo "pointArr1[$i]=$pointArr1[$i], ";
		$i++;
		echo "pointArr1[$i]=$pointArr1[$i]<br>";
		$i++;
	}
}
for($i=0;$i<6;$i++){
	imageline($im,$pointArr1[$i*2],$pointArr1[$i*2+1],$pointArr1[$i*2+2],$pointArr1[$i*2+3],$tmpColor1);
}

//face value 2
for($i=0;$i<7;$i++){
	$pointArr2[$i*2] = $i;
	$pointArr2[$i*2+1]	= $dayFaceValue2Used[$i];
	//echo "dayFaceValue2Used[$i]=$dayFaceValue2Used[$i]<br>";
}
//线条
$pointArr2=getNewXY($pointArr2);
$pointNum2= sizeof($pointArr2) / 2;
$tmpColor2=$legendArr[1][2];
for($i=0;$i<6;$i++){
	imageline($im,$pointArr2[$i*2],$pointArr2[$i*2+1],$pointArr2[$i*2+2],$pointArr2[$i*2+3],$tmpColor2);
}

//face value 3
for($i=0;$i<7;$i++){
	$pointArr3[$i*2] = $i;
	$pointArr3[$i*2+1]	= $dayFaceValue3Used[$i];
	//echo "dayFaceValue3Used[$i]=$dayFaceValue3Used[$i]<br>";
}
//线条
$pointArr3=getNewXY($pointArr3);
$pointNum3= sizeof($pointArr3) / 2;
$tmpColor3=$legendArr[2][2];
for($i=0;$i<6;$i++){
	imageline($im,$pointArr3[$i*2],$pointArr3[$i*2+1],$pointArr3[$i*2+2],$pointArr3[$i*2+3],$tmpColor3);
}

//face value 4
for($i=0;$i<7;$i++){
	$pointArr4[$i*2] = $i;
	$pointArr4[$i*2+1]	= $dayFaceValue4Used[$i];
	//echo "dayFaceValue4Used[$i]=$dayFaceValue4Used[$i]<br>";
}
//线条
$pointArr4=getNewXY($pointArr4);
$pointNum4= sizeof($pointArr4) / 2;
$tmpColor4=$legendArr[3][2];
for($i=0;$i<6;$i++){
	imageline($im,$pointArr4[$i*2],$pointArr4[$i*2+1],$pointArr4[$i*2+2],$pointArr4[$i*2+3],$tmpColor4);
}

//face value 5
for($i=0;$i<7;$i++){
	$pointArr5[$i*2] = $i;
	$pointArr5[$i*2+1]	= $dayFaceValue5Used[$i];
	//echo "dayFaceValue5Used[$i]=$dayFaceValue5Used[$i]<br>";
}
//线条
$pointArr5=getNewXY($pointArr5);
$pointNum5= sizeof($pointArr5) / 2;
$tmpColor5=$legendArr[4][2];
for($i=0;$i<6;$i++){
	imageline($im,$pointArr5[$i*2],$pointArr5[$i*2+1],$pointArr5[$i*2+2],$pointArr5[$i*2+3],$tmpColor5);
}

//face value 6
for($i=0;$i<7;$i++){
	$pointArr6[$i*2] = $i;
	$pointArr6[$i*2+1]	= $dayFaceValue6Used[$i];
	//echo "dayFaceValue6Used[$i]=$dayFaceValue6Used[$i]<br>";
}
//线条
$pointArr6=getNewXY($pointArr6);
$pointNum6= sizeof($pointArr6) / 2;
$tmpColor6=$legendArr[5][2];
for($i=0;$i<6;$i++){
	imageline($im,$pointArr6[$i*2],$pointArr6[$i*2+1],$pointArr6[$i*2+2],$pointArr6[$i*2+3],$tmpColor6);
}

?>

<table border="0" width="100%" cellpadding="2" cellspacing="0" bordercolor="#FFFFFF" bordercolordark="#FFFFFF">  
  <tr>
	<td width="75%" align="center">
	  <b>
	  <?php echo "Week $query_week recharge card statistics";?>
	  </b>
	</td>
	<td width="25%"></td>
  </tr>
</table>

<?php
//-----输出图形文件，请勿修改
//delete *.png
$filename1=time()."1.png";
if(!$DEBUG){
	ImagePng ($im,"$filename1");  
	ImageDestroy($im);	
}

//-----显示图片
echo "<body topmargin=\"0\" leftmargin=\"5\">";  
echo "<img src=\"$filename1\">";
echo "</body>";
?>
<br><br>

<!--
***************       画前5周收费统计图       **********************
-->
<table border="0" width="100%" cellpadding="2" cellspacing="0" bordercolor="#FFFFFF" bordercolordark="#FFFFFF">  
  <tr>
	<td width="75%" align="center">
	  <b>
	  <?php echo "$firstWeek~$lastWeek call charge statistics";?>
	  </b>
	</td>
	<td width="25%"></td>
  </tr>
</table>
<br>
<?php
$height=300;
$width=550;
$jc=$height/100;
$font=3;
$fontwidth= imagefontwidth ($font);
$fontheight=imagefontheight($font);
$dot=6;

$maxData=0;
for($i=0;$i<5;$i++){
	$data[$i]	= $weekCharge[$i]/$moneyPara;
	$maxData = ($data[$i]>$maxData)?$data[$i]:$maxData;
	if($DEBUG) echo "maxData=$maxData<br>";
	if($DEBUG) echo "data[$i-1]=${data[$i-1]}, label[$i-1]=${label[$i-1]}<br>";
}
$maxData = (ceil($maxData/1000)+1)*1000;
$image= imagecreate ($width,$height+20);
$bg=imagecolorallocate($image,0xff,0xff,0xff);
#$point= imagecolorallocate($image,0xff,0xff,0xff);
$line=imagecolorallocate($image,0x7d,0x00,0x00);
$lineFrame=imagecolorallocate($image,0xbb,0xbb,0xbb);
$text=imagecolorallocate($image,0x00,0x00,0x00);
$dotcolor=imagecolorallocate($image,0x7d,0x00,0x00);
imageline ($image,50,0,50,$height,$lineFrame);
imageline($image,50,$height,$width,$height,$lineFrame);

for ($i=1;$i<11;$i++)
{
	imagedashedline($image,50,$height - $jc*$i*10 ,$width ,$height -$jc*$i*10 ,$lineFrame );
//	imagestring ($image,$font,0,$height-$jc*$i*10,$maxData/10*$i,$text);

	$scale	= $maxData/10*$i;
	if($scale>1000*1000){
		$displayMaxData = round($scale/100000)/10;
		$displayMaxData = $displayMaxData."M";	
	}elseif($scale>1000){
		$displayMaxData = round($scale/100)/10;
		$displayMaxData = $displayMaxData."K";	
	}else
		$displayMaxData=$scale;
	imagestring ($image,$font,0,$height-$jc*$i*10,$displayMaxData,$text);
}
for ($i=0;$i<count($data);$i++)
{
	$tmp=round($data [$i]/$maxData*10000)/100;
	#echo $tmp."<BR>";
	$x1=(($width-50)/count($data))*($i)+40+10;
	#echo $x1 ."<BR>";
	$y1=$height-$tmp*$jc;
	$x2=$x1;
	$y2=$y1+$tmp*$jc;
	#echo $y1."<BR>";
//	imagestring($image,$font,$x1,$y1-2*$fontheight,$tmp."%(".$data[$i].")",$text);

	if($data[$i]>1000*1000){
		$displayData[$i] = round($data[$i]/100000)/10;
		$displayData[$i] = $displayData[$i]."M";	
	}elseif($data[$i]>1000){
		$displayData[$i] = round($data[$i]/100)/10;
		$displayData[$i] = $displayData[$i]."K";	
	}
	else
		$displayData[$i] = $data[$i];
	//imagestring($image,$font,$x1,$y1-2*$fontheight,$data[$i],$text);
	imagestring($image,$font,$x1+$dot,$y1-$dot,$displayData[$i],$text);
	imagearc ($image,$x1 ,$y1,$dot,$dot,0,360,$dotcolor);
	imagefilltoborder ($image,$x1,$y1,$dotcolor,$dotcolor);
	imagestring ($image,$font,$x1,$y2,$label[$i],$text);
	if ($i>0)
	{
		imageline($image,$tmpx1,$tmpy1,$x1,$y1,$line);
	}
	$tmpx1=$x1;$tmpy1=$y1;
}
$filename2=time()."2.png";
ImagePng ($image,$filename2);  
ImageDestroy($image);	

//display the picture
echo "<body topmargin=\"0\" leftmargin=\"5\">";  
echo "<table";
echo "<td width=\"100%\" align=\"center\">";
echo "<img src=\"$filename2\">";
echo "</td>";
echo "</table>";
echo "</body>";
?>  

<br><br>

<!--
***************       画前5个月充值卡统计图       **********************
-->
<table border="0" width="100%" cellpadding="2" cellspacing="0" bordercolor="#FFFFFF" bordercolordark="#FFFFFF">  
  <tr>
	<td width="75%" align="center">
	  <b>
	  <?php echo "$firstWeek~$lastWeek recharge card statistics";?>
	  </b>
	</td>
	<td width="25%"></td>
  </tr>
</table>
<br>
<?php
$height=300;
$yEnd	= 300;
$width=550;
$jc=$height/100;
$font=3;
$fontwidth= imagefontwidth ($font);
$fontheight=imagefontheight($font);
$dot=6;

$maxData=0;
for($i=0;$i<5;$i++){
	$data1[$i]	= $weekFaceValue1Used[$i];
	$data2[$i]	= $weekFaceValue2Used[$i];
	$data3[$i]	= $weekFaceValue3Used[$i];
	$data4[$i]	= $weekFaceValue4Used[$i];
	$data5[$i]	= $weekFaceValue5Used[$i];
	$data6[$i]	= $weekFaceValue6Used[$i];
	$maxData = ($data1[$i]>$maxData)?$data1[$i]:$maxData;
	$maxData = ($data2[$i]>$maxData)?$data2[$i]:$maxData;
	$maxData = ($data3[$i]>$maxData)?$data3[$i]:$maxData;
	$maxData = ($data4[$i]>$maxData)?$data4[$i]:$maxData;
	$maxData = ($data5[$i]>$maxData)?$data5[$i]:$maxData;
	$maxData = ($data6[$i]>$maxData)?$data6[$i]:$maxData;
	if($DEBUG) echo "maxData=$maxData<br>";
	if($DEBUG) echo "data1[$i-1]=${data1[$i-1]}, label[$i-1]=${label[$i-1]}<br>";
}
$maxData = (ceil($maxData/10)+1)*10;
$image= imagecreate ($width,$height+20);
$bg=imagecolorallocate($image,0xff,0xff,0xff);
#$point= imagecolorallocate($image,0xff,0xff,0xff);
$line1=imagecolorallocate($image,0x00,0x00,0xFF);
$line2=imagecolorallocate($image,0x00,0xFF,0x00);
$line3=imagecolorallocate($image,0xFF,0x00,0x00);
$line4=imagecolorallocate($image,0x7d,0x00,0x00);
$line5=imagecolorallocate($image,0xFF,0x00,0xFF);
$line6=imagecolorallocate($image,0xee,0xaa,0x22);

$lineFrame=imagecolorallocate($image,0xbb,0xbb,0xbb);
$text=imagecolorallocate($image,0x00,0x00,0x00);
$dotcolor1=imagecolorallocate($image,0x00,0x00,0xFF);
$dotcolor2=imagecolorallocate($image,0x00,0xFF,0x00);
$dotcolor3=imagecolorallocate($image,0xFF,0x00,0x00);
$dotcolor4=imagecolorallocate($image,0x7d,0x00,0x00);
$dotcolor5=imagecolorallocate($image,0xFF,0x00,0xFF);
$dotcolor6=imagecolorallocate($image,0xee,0xaa,0x22);
imageline ($image,50,0,50,$height,$lineFrame);
imageline($image,50,$height,$width,$height,$lineFrame);
for ($i=1;$i<11;$i++)
{
	imagedashedline($image,50,$height - $jc*$i*10 ,$width ,$height -$jc*$i*10 ,$lineFrame );
//	imagestring ($image,$font,0,$height-$jc*$i*10,$maxData/10*$i,$text);

	$scale	= $maxData/10*$i;
	if($scale>1000*1000){
		$displayMaxData = round($scale/100000)/10;
		$displayMaxData = $displayMaxData."M";	
	}elseif($scale>1000){
		$displayMaxData = round($scale/100)/10;
		$displayMaxData = $displayMaxData."K";	
	}else
		$displayMaxData	= $scale;
	imagestring ($image,$font,0,$height-$jc*$i*10,$displayMaxData,$text);
}

//face value 1
for ($i=0;$i<count($data1);$i++)
{
	$tmp=round($data1[$i]/$maxData*10000)/100;
	#echo $tmp."<BR>";
	$x1=(($width-50)/count($data1))*($i)+40+10;
	#echo $x1 ."<BR>";
	$y1=$height-$tmp*$jc;
	$x2=$x1;
	$y2=$y1+$tmp*$jc;
	#echo $y1."<BR>";

	if($data1[$i]>1000*1000){
		$displayData1[$i] = round($data1[$i]/100000);
		$displayData1[$i] = $displayData1[$i]/10;
		$displayData1[$i] = $displayData1[$i]."M";	
	}elseif($data1[$i]>1000){
		$displayData1[$i] = round($data1[$i]/100);
		$displayData1[$i] = $displayData1[$i]/10;
		$displayData1[$i] = $displayData1[$i]."K";	
	}
	else
		$displayData1[$i] = $data1[$i];
	//imagestring($image,$font,$x1,$y1-2*$fontheight,$data1[$i],$text);
	imagestring($image,$font,$x1+$dot,$y1-$dot,$displayData1[$i],$text);
	imagearc ($image,$x1 ,$y1,$dot,$dot,0,360,$dotcolor1);
	imagefilltoborder ($image,$x1,$y1,$dotcolor1,$dotcolor1);
	imagestring ($image,$font,$x1,$y2,$label[$i],$text);
	if ($i>0)
	{
		imageline($image,$tmpx1,$tmpy1,$x1,$y1,$line1);
	}
	$tmpx1=$x1;$tmpy1=$y1;
}
//face value 2
for ($i=0;$i<count($data2);$i++)
{
	$tmp=round($data2[$i]/$maxData*10000)/100;
	#echo $tmp."<BR>";
	$x1=(($width-50)/count($data2))*($i)+40+10;
	#echo $x1 ."<BR>";
	$y1=$height-$tmp*$jc;
	$x2=$x1;
	$y2=$y1+$tmp*$jc;
	#echo $y1."<BR>";

	if($data2[$i]>1000*1000){
		$displayData2[$i] = round($data2[$i]/100000);
		$displayData2[$i] = $displayData2[$i]/10;
		$displayData2[$i] = $displayData2[$i]."M";	
	}elseif($data2[$i]>1000){
		$displayData2[$i] = round($data2[$i]/100);
		$displayData2[$i] = $displayData2[$i]/10;
		$displayData2[$i] = $displayData2[$i]."K";	
	}
	else
		$displayData2[$i] = $data2[$i];
	//imagestring($image,$font,$x1,$y1-2*$fontheight,$data2[$i],$text);
	imagestring($image,$font,$x1+$dot,$y1-$dot,$displayData2[$i],$text);
	imagearc ($image,$x1 ,$y1,$dot,$dot,0,360,$dotcolor2);
	imagefilltoborder ($image,$x1,$y1,$dotcolor2,$dotcolor2);
	imagestring ($image,$font,$x1,$y2,$label[$i],$text);
	if ($i>0)
	{
		imageline($image,$tmpx1,$tmpy1,$x1,$y1,$line2);
	}
	$tmpx1=$x1;$tmpy1=$y1;
}
//face value 3
for ($i=0;$i<count($data3);$i++)
{
	$tmp=round($data3[$i]/$maxData*10000)/100;
	#echo $tmp."<BR>";
	$x1=(($width-50)/count($data3))*($i)+40+10;
	#echo $x1 ."<BR>";
	$y1=$height-$tmp*$jc;
	$x2=$x1;
	$y2=$y1+$tmp*$jc;
	#echo $y1."<BR>";

	if($data3[$i]>1000*1000){
		$displayData3[$i] = round($data3[$i]/100000);
		$displayData3[$i] = $displayData3[$i]/10;
		$displayData3[$i] = $displayData3[$i]."M";	
	}elseif($data3[$i]>1000){
		$displayData3[$i] = round($data3[$i]/100);
		$displayData3[$i] = $displayData3[$i]/10;
		$displayData3[$i] = $displayData3[$i]."K";	
	}
	else
		$displayData3[$i] = $data3[$i];
	//imagestring($image,$font,$x1,$y1-2*$fontheight,$data3[$i],$text);
	imagestring($image,$font,$x1+$dot,$y1-$dot,$displayData3[$i],$text);
	imagearc ($image,$x1 ,$y1,$dot,$dot,0,360,$dotcolor3);
	imagefilltoborder ($image,$x1,$y1,$dotcolor3,$dotcolor3);
	imagestring ($image,$font,$x1,$y2,$label[$i],$text);
	if ($i>0)
	{
		imageline($image,$tmpx1,$tmpy1,$x1,$y1,$line3);
	}
	$tmpx1=$x1;$tmpy1=$y1;
}
//face value 4
for ($i=0;$i<count($data4);$i++)
{
	$tmp=round($data4[$i]/$maxData*10000)/100;
	#echo $tmp."<BR>";
	$x1=(($width-50)/count($data4))*($i)+40+10;
	#echo $x1 ."<BR>";
	$y1=$height-$tmp*$jc;
	$x2=$x1;
	$y2=$y1+$tmp*$jc;
	#echo $y1."<BR>";

	if($data4[$i]>1000*1000){
		$displayData4[$i] = round($data4[$i]/100000);
		$displayData4[$i] = $displayData4[$i]/10;
		$displayData4[$i] = $displayData4[$i]."M";	
	}elseif($data4[$i]>1000){
		$displayData4[$i] = round($data4[$i]/100);
		$displayData4[$i] = $displayData4[$i]/10;
		$displayData4[$i] = $displayData4[$i]."K";	
	}
	else
		$displayData4[$i] = $data4[$i];
	//imagestring($image,$font,$x1,$y1-2*$fontheight,$data4[$i],$text);
	imagestring($image,$font,$x1+$dot,$y1-$dot,$displayData4[$i],$text);
	imagearc ($image,$x1 ,$y1,$dot,$dot,0,360,$dotcolor4);
	imagefilltoborder ($image,$x1,$y1,$dotcolor4,$dotcolor4);
	imagestring ($image,$font,$x1,$y2,$label[$i],$text);
	if ($i>0)
	{
		imageline($image,$tmpx1,$tmpy1,$x1,$y1,$line4);
	}
	$tmpx1=$x1;$tmpy1=$y1;
}

//face value 5
for ($i=0;$i<count($data5);$i++)
{
	$tmp=round($data5[$i]/$maxData*10000)/100;
	#echo $tmp."<BR>";
	$x1=(($width-50)/count($data5))*($i)+40+10;
	#echo $x1 ."<BR>";
	$y1=$height-$tmp*$jc;
	$x2=$x1;
	$y2=$y1+$tmp*$jc;
	#echo $y1."<BR>";

	if($data5[$i]>1000*1000){
		$displayData5[$i] = round($data5[$i]/100000);
		$displayData5[$i] = $displayData5[$i]/10;
		$displayData5[$i] = $displayData5[$i]."M";	
	}elseif($data5[$i]>1000){
		$displayData5[$i] = round($data5[$i]/100);
		$displayData5[$i] = $displayData5[$i]/10;
		$displayData5[$i] = $displayData5[$i]."K";	
	}
	else
		$displayData5[$i] = $data5[$i];
	//imagestring($image,$font,$x1,$y1-2*$fontheight,$data5[$i],$text);
	imagestring($image,$font,$x1+$dot,$y1-$dot,$displayData5[$i],$text);
	imagearc ($image,$x1 ,$y1,$dot,$dot,0,360,$dotcolor5);
	imagefilltoborder ($image,$x1,$y1,$dotcolor5,$dotcolor5);
	imagestring ($image,$font,$x1,$y2,$label[$i],$text);
	if ($i>0)
	{
		imageline($image,$tmpx1,$tmpy1,$x1,$y1,$line5);
	}
	$tmpx1=$x1;$tmpy1=$y1;
}

//face value 6
for ($i=0;$i<count($data6);$i++)
{
	$tmp=round($data6[$i]/$maxData*10000)/100;
	#echo $tmp."<BR>";
	$x1=(($width-50)/count($data6))*($i)+40+10;
	#echo $x1 ."<BR>";
	$y1=$height-$tmp*$jc;
	$x2=$x1;
	$y2=$y1+$tmp*$jc;
	#echo $y1."<BR>";

	if($data6[$i]>1000*1000){
		$displayData6[$i] = round($data6[$i]/100000);
		$displayData6[$i] = $displayData6[$i]/10;
		$displayData6[$i] = $displayData6[$i]."M";	
	}elseif($data6[$i]>1000){
		$displayData6[$i] = round($data6[$i]/100);
		$displayData6[$i] = $displayData6[$i]/10;
		$displayData6[$i] = $displayData6[$i]."K";	
	}
	else
		$displayData6[$i] = $data6[$i];
	//imagestring($image,$font,$x1,$y1-2*$fontheight,$data6[$i],$text);
	imagestring($image,$font,$x1+$dot,$y1-$dot,$displayData6[$i],$text);
	imagearc ($image,$x1 ,$y1,$dot,$dot,0,360,$dotcolor6);
	imagefilltoborder ($image,$x1,$y1,$dotcolor6,$dotcolor6);
	imagestring ($image,$font,$x1,$y2,$label[$i],$text);
	if ($i>0)
	{
		imageline($image,$tmpx1,$tmpy1,$x1,$y1,$line6);
	}
	$tmpx1=$x1;$tmpy1=$y1;
}

//色块图标及说明
for($i=0;$i<sizeof($legendArr);$i++){
	$tmpName=$legendArr[$i][0];
	$tmpColor=$legendArr[$i][1];
	$color = ImageColorAllocate ($image, hexdec(substr($tmpColor, 0, 2)), hexdec(substr($tmpColor, 2, 2)),hexdec(substr($tmpColor, 4, 2)));
	$legendArr[$i][2]=$color;
	ImageFilledRectangle($image,82 + $i* 120,$yEnd + 22,80 + $i* 120 + 10,$yEnd + 30,$legendArr[$i][2]);
	Imagestring($image, 2, 95 + $i* 120,$yEnd + 20, "$tmpName",  $text_color);
}

$filename2=time()."3.png";
ImagePng ($image,$filename2);  
ImageDestroy($image);	

//display the picture
echo "<body topmargin=\"0\" leftmargin=\"5\">";  
echo "<table";
echo "<td width=\"100%\" align=\"center\">";
echo "<img src=\"$filename2\">";
echo "</td>";
echo "</table>";
echo "</body>";
?>  

<p>&nbsp;</p>
<table>
<form name="clock">
<?php
     echo "<b>$strDailyOperator:&nbsp;</b>";
	 echo "$userInfo[ID]";
	 echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	 echo "<b>$strDailyPrintTime</b>";
?>
 <INPUT TYPE="text" id="time" SIZE="22" style="border-left:medium none;border-right:medium none;border-top:medium none;border-bottom:medium none" class="text">
</form>
</table>
<?php
adjust_content_tail("down");
?>
<!--
<form name="printf button">
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  <INPUT TYPE="button" name="print" align="right" value="<?php echo "$strDailyBtnPrint"; ?>" onClick="javascript:window.print()">  
</form>
-->
</body>
</html>
