<?php
for($i=0;$i<18;$i++){
	$flagNum="flag$i";
	${$flagNum}=$_REQUEST[$flagNum];
}
if(0)
{
	echo "$PHP_SELF<br>";
	echo "sysTypeNo=$sysTypeNo,show_type=$show_type,page_id=$page_id,keyOne=$keyOne<br>";
	echo "sel_date_from=$sel_date_from,sel_date_to=$sel_date_to<br>";
	echo "select_checkbox_id=$select_checkbox_id<br>";
}

echo "<input type=\"hidden\" name=\"select_checkbox_id\" value=\"$select_checkbox_id\">";
echo "<input type=\"hidden\" name=\"scroll_y\" value=\"$scroll_y\">";
//echo "sysTypeNo=$sysTypeNo,keyOne=$keyOne";
$cstaConf=GetCstaConf($sysTypeNo);

	$keyOneobj=array(
			"Subs to subs"=>"5,17",
			"Subs to trunk"=>"6,18",
			"Trunk to subs"=>"7,19",
			"Trunk to trunk"=>"8",
			"Intraconnection"=>"9",
			"Subs to IP"=>"10,20",
			"Trunk to IP"=>"11",
			"Mobile originated"=>"12,21",
			"Mobile terminated"=>"13,22",
			"In trunk"=>"14",
			"Out trunk"=>"15",
			"IP terminated"=>"16",
			"GSM"=>"12+13",
			"UMTS"=>"21+22"
		);
	
	$keyOne1=$keyOneobj[$keyOne];
	if($keyOne=="GSM" ||$keyOne=="UMTS")
	{
		$keyOne1=explode('+',$keyOne1);
		$keyOneNum=1;
	}
	else
	{
		$keyOne1=explode(',',$keyOne1);
		$keyOneNum=sizeof($keyOne1);
	}
//echo "$keyOne1[0],$keyOne1[1]";
	
$slot=$sel_date_from-$sel_date_to+1;
$startTime=date("Y-m-d H:i:s",mktime(0,0,0,date("m"),date("d")-$sel_date_from,date("Y")));
$endTime=date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-$sel_date_to,date("Y")));
//echo "startTime=$startTime,endTime=$endTime<br>";

//Table-1
{
	$sub_title=array(
		5=>"Subs to subs",
		6=>"Subs to trunk",
		7=>"Trunk to subs",
		8=>"Trunk to trunk",
		9=>"Intraconnection",
		10=>"Subs to IP",
		11=>"Trunk to IP",
		12=>"Mobile originated",
		13=>"Mobile terminated",
		14=>"In trunk",
		15=>"Out trunk",
		16=>"IP terminated",
	);
	
	$columnTitle=array(
		"Time",
		"Attempt",
		"Success",
		"Call Deny",
		"Net Busy",
		"Caller<br>Clear",
		"Sub Busy",
		"No<br>Answer",
		"Signal<br>Error",
		"Total Call<br>Duration",
		"Average Call<br>Duration(s)"
	);
	$columnNum=sizeof($columnTitle);

	if($keyOne=="GSM" ||$keyOne=="UMTS")
	{
		if($slot > 1)
			$table_title=$keyOne." Statistic&nbsp;&nbsp;Date:".date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$sel_date_from,date("Y")))." to ".date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$sel_date_to,date("Y")));
		else
			$table_title=$keyOne." Statistic&nbsp;&nbsp;Date:".date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$sel_date_from,date("Y")));
	}
	else
	{
		if($slot > 1)
			$table_title=$sub_title[$keyOne1[0]]." Statistic&nbsp;&nbsp;Date:".date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$sel_date_from,date("Y")))." to ".date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$sel_date_to,date("Y")));
		else
			$table_title=$sub_title[$keyOne1[0]]." Statistic&nbsp;&nbsp;Date:".date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$sel_date_from,date("Y")));		
	}
	echo "<br><b><center>$table_title</center></b>";
	echo "<table width=\"100%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#FFFFFF\">";
	echo "<tr bgcolor=\"#E6E6E6\">";
	
	for($i=0;$i<$columnNum;$i++)
	{
		if($keyOneNum>1&&$i==0)
			echo "<td colspan=\"2\" align=\"center\">{$columnTitle[$i]}</td>";
		else
			echo "<td align=\"center\">{$columnTitle[$i]}</td>";
	}
	echo "</tr>";

	$objInderRelation=array(5=>1,6=>1,7=>1,8=>1,9=>2,10=>3,11=>3,12=>4,13=>4,14=>5,15=>5,16=>6,17=>7,18=>7,19=>7,20=>7,21=>7,22=>7);
	
	$total_hour=$slot*24;
	$total_record_num=0;
	//echo "total_hour=$total_hour<br>";
	for($hour=0;$hour<$total_hour;$hour++)
	{			
		for($ii=0;$ii<$keyOneNum;$ii++)
		{		
			$keyOneName=$keyOne1[$ii];	
			if($keyOne=="GSM" ||$keyOne=="UMTS")
			{
				$cstaData1=GetCstaDataByHour($cstaConf,$startTime,$endTime,"sum",$keyOne1[0]);
				$cstaData2=GetCstaDataByHour($cstaConf,$startTime,$endTime,"sum",$keyOne1[1]);			
				$att_value=$cstaData1[$objInderRelation[$keyOne1[0]]][$keyOne1[0]][Attempt][$hour]+$cstaData2[$objInderRelation[$keyOne1[1]]][$keyOne1[1]][Attempt][$hour];
			}
			else
			{
				$cstaData=GetCstaDataByHour($cstaConf,$startTime,$endTime,"sum",$keyOne1[$ii]);
				$att_value=$cstaData[$objInderRelation[$keyOne1[$ii]]][$keyOne1[$ii]][Attempt][$hour];
			}

			if(isset($att_value) && trim($att_value)!="")
			{
				if($ii==0)
					echo "<tr>";
				if($keyOne=="GSM" ||$keyOne=="UMTS")
				{
					$success_value[$keyOneName][$hour]=$cstaData1[$objInderRelation[$keyOne1[0]]][$keyOne1[0]][Success][$hour]+$cstaData2[$objInderRelation[$keyOne1[1]]][$keyOne1[1]][Success][$hour]+0;
					$calldeny_value[$keyOneName][$hour]=$cstaData1[$objInderRelation[$keyOne1[0]]][$keyOne1[0]][CallDeny][$hour]+$cstaData2[$objInderRelation[$keyOne1[1]]][$keyOne1[1]][CallDeny][$hour]+0;
					$netbusy_value[$keyOneName][$hour]=$cstaData1[$objInderRelation[$keyOne1[0]]][$keyOne1[0]][NetBusy][$hour]+$cstaData2[$objInderRelation[$keyOne1[1]]][$keyOne1[1]][NetBusy][$hour]+0;
					$callerclear_value[$keyOneName][$hour]=$cstaData1[$objInderRelation[$keyOne1[0]]][$keyOne1[0]][CallerClear][$hour]+$cstaData2[$objInderRelation[$keyOne1[1]]][$keyOne1[1]][CallerClear][$hour];
					$subbusy_value[$keyOneName][$hour]=$cstaData1[$objInderRelation[$keyOne1[0]]][$keyOne1[0]][SubBusy][$hour]+$cstaData2[$objInderRelation[$keyOne1[1]]][$keyOne1[1]][SubBusy][$hour];
					$noanswer_value[$keyOneName][$hour]=$cstaData1[$objInderRelation[$keyOne1[0]]][$keyOne1[0]][NoAnswer][$hour]+$cstaData2[$objInderRelation[$keyOne1[1]]][$keyOne1[1]][NoAnswer][$hour];
					$signalerr_value[$keyOneName][$hour]=$cstaData1[$objInderRelation[$keyOne1[0]]][$keyOne1[0]][SignalErr][$hour]+$cstaData2[$objInderRelation[$keyOne1[1]]][$keyOne1[1]][SignalErr][$hour];
					$duration_value[$keyOneName][$hour]=$cstaData1[$objInderRelation[$keyOne1[0]]][$keyOne1[0]][Duration][$hour]+$cstaData2[$objInderRelation[$keyOne1[1]]][$keyOne1[1]][Duration][$hour];										
				}
				else
				{
					$success_value[$keyOneName][$hour]=$cstaData[$objInderRelation[$keyOne1[$ii]]][$keyOne1[$ii]][Success][$hour]+0;
					$calldeny_value[$keyOneName][$hour]=$cstaData[$objInderRelation[$keyOne1[$ii]]][$keyOne1[$ii]][CallDeny][$hour]+0;
					$netbusy_value[$keyOneName][$hour]=$cstaData[$objInderRelation[$keyOne1[$ii]]][$keyOne1[$ii]][NetBusy][$hour]+0;
					$callerclear_value[$keyOneName][$hour]=$cstaData[$objInderRelation[$keyOne1[$ii]]][$keyOne1[$ii]][CallerClear][$hour];
					$subbusy_value[$keyOneName][$hour]=$cstaData[$objInderRelation[$keyOne1[$ii]]][$keyOne1[$ii]][SubBusy][$hour];
					$noanswer_value[$keyOneName][$hour]=$cstaData[$objInderRelation[$keyOne1[$ii]]][$keyOne1[$ii]][NoAnswer][$hour];
					$signalerr_value[$keyOneName][$hour]=$cstaData[$objInderRelation[$keyOne1[$ii]]][$keyOne1[$ii]][SignalErr][$hour];
					$duration_value[$keyOneName][$hour]=$cstaData[$objInderRelation[$keyOne1[$ii]]][$keyOne1[$ii]][Duration][$hour];
				}	
				$hour_title=date("m-d H",mktime($hour,0,0,date("m"),date("d")-$sel_date_from,date("Y")));
				
				if($keyOneNum>1&&$ii==0)
				{
					echo "<td rowspan=\"2\" align=\"center\">{$hour_title}H</td>";
					echo "<td>GSM</td>";
				}
				else if($keyOneNum>1&&$ii==1)
					echo "<tr><td>UMTS</td>";
				else if($ii==0)
					echo "<td align=\"center\">{$hour_title}H</td>";
					
				//Attempt
				echo "<td align=\"center\">";
				echo "{$att_value}";
				echo "</td>";
				
				//Success
				$value=$success_value[$keyOneName][$hour];
				$percent=GetPercent($value,$att_value);
				echo "<td align=\"center\">$value<br>$percent</td>";
				
				//CallDeny
				$value=$calldeny_value[$keyOneName][$hour];
				$percent=GetPercent($value,$att_value);
				echo "<td align=\"center\">$value<br>$percent</td>";
				
				//NetBusy
				$value=$netbusy_value[$keyOneName][$hour];
				$percent=GetPercent($value,$att_value);
				echo "<td align=\"center\">$value<br>$percent</td>";
				
				//CallerClear
				$value=$callerclear_value[$keyOneName][$hour]+0;
				$percent=GetPercent($value,$att_value);
				echo "<td align=\"center\">$value<br>$percent</td>";
				
				//SubBusy
				$value=$subbusy_value[$keyOneName][$hour]+0;
				$percent=GetPercent($value,$att_value);
				echo "<td align=\"center\">$value<br>$percent</td>";
				
				//NoAnswer
				$value=$noanswer_value[$keyOneName][$hour]+0;
				$percent=GetPercent($value,$att_value);
				echo "<td align=\"center\">$value<br>$percent</td>";
				
				//SignalErr
				$value=$signalerr_value[$keyOneName][$hour]+0;
				$percent=GetPercent($value,$att_value);
				echo "<td align=\"center\">$value<br>$percent</td>";
									
				//TotalCallDuration
				$value=$duration_value[$keyOneName][$hour]+0;
				echo "<td align=\"center\">";
				echo "{$value}<br>";
				$timestamp=SecondToTimeStamp($cstaData[Duration][$hour]);
				echo "{$timestamp}";
				echo "</td>";
				
				//AverageCallDuration
				if($success_value[$keyOneName][$hour] > 0)
					$value=ceil($duration_value[$keyOneName][$hour]/$success_value[$keyOneName][$hour]);
				else
					$value=0;
				echo "<td align=\"center\">";
				echo "{$value}";
				echo "</td>";					
				echo "</tr>";
				
				$total_record_num++;
			}
			else
			{
				$success_value[$keyOneName][$hour]=0;
				$calldeny_value[$keyOneName][$hour]=0;
				$netbusy_value[$keyOneName][$hour]=0;
				$callerclear_value[$keyOneName][$hour]=0;
				$subbusy_value[$keyOneName][$hour]=0;
				$noanswer_value[$keyOneName][$hour]=0;
				$signalerr_value[$keyOneName][$hour]=0;
				$duration_value[$keyOneName][$hour]=0;
			}
		}		
	}
	if($total_record_num == 0 && $keyOneNum>1)
		echo "<td>--</td><td>--</td><td>--</td><td>--</td><td>--</td><td>--</td><td>--</td><td>--</td><td>--</td><td>--</td><td>--</td><td>--</td></tr>";
	else if($total_record_num == 0)
		echo "<td>--</td><td>--</td><td>--</td><td>--</td><td>--</td><td>--</td><td>--</td><td>--</td><td>--</td><td>--</td><td>--</td></tr>";
	
	echo "</table>";
}

//Graphics-1
{
	unset($tmpColor);
	unset($tmpData);
	if($flag0 == "on")
	{
		$tmpColor[]=array(0x66,0xff,0x33);
		$tmpData[]=$success_value[$keyOne1[0]];
		//print_r($tmpData);
	}
	if($flag1 == "on")
	{
		$tmpColor[]=array(0x66,0xff,0xff);
		$tmpData[]=$calldeny_value[$keyOne1[0]];
	}
	if($flag2 == "on")
	{
		$tmpColor[]=array(0,0x66,0x66);
		$tmpData[]=$netbusy_value[$keyOne1[0]];
	}
	if($flag3 == "on")
	{
		$tmpColor[]=array(0x66,0,0xcc);
		$tmpData[]=$callerclear_value[$keyOne1[0]];
	}
	if($flag4 == "on")
	{
		$tmpColor[]=array(0x66,0x33,0);
		$tmpData[]=$subbusy_value[$keyOne1[0]];
	}
	if($flag5 == "on")
	{
		$tmpColor[]=array(0xcc,0,0x66);
		$tmpData[]=$noanswer_value[$keyOne1[0]];
	}
	if($flag6 == "on")
	{
		$tmpColor[]=array(0xff,0,0);
		$tmpData[]=$signalerr_value[$keyOne1[0]];
	}
	
	echo "<br><b>Hourly Statistic Chart(GSM)</b><br>";
	if($select_checkbox_id>=0&&$select_checkbox_id<7)
	{
		if(0)
		{
			echo "flag0=$flag0,flag1=$flag1,flag2=$flag2,flag3=$flag3,flag4=$flag4,flag5=$flag5,flag6=$flag6,flag7=$flag7,flag8=$flag8,flag9=$flag9,flag10=$flag10,flag11=$flag11,flag12=$flag12,flag13=$flag13,flag14=$flag14,flag15=$flag15,flag16=$flag16<br>";
		}
		$boldline1=$select_checkbox_id;
		//echo "1boldline1=$boldline1";
		for($i=0;$i<$select_checkbox_id;$i++)
		{
			$param="flag$i";
			if($$param != "on")
				$boldline1--;
		}
	}
	//echo "2boldline1=$boldline1";
	$image=CreateImage(820,390);
	$image=DrawLineHistogram(
		$image,
		$tmpData,
		$tmpColor,
		750/(24*$slot),
		24,
		array(50,20),
		array(750,280),
		$boldline1,1,0,1
	);
	
	$remarkBlock=array(
		"Success",
		"Call Deny",
		"Network Busy",
		"Caller Clear",
		"Sub Busy",
		"No Answer",
		"Signal Error"
	);
	$pointArr=array(
		array(60,367),
		array(160,367),
		array(260,367),
		array(360,367),
		array(460,367),
		array(560,367),
		array(660,367)
	);
	unset($tmpColor);
	$tmpColor[]=array(0x66,0xff,0x33);
	$tmpColor[]=array(0x66,0xff,0xff);
	$tmpColor[]=array(0,0x66,0x66);
	$tmpColor[]=array(0x66,0,0xcc);
	$tmpColor[]=array(0x66,0x33,0);
	$tmpColor[]=array(0xcc,0,0x66);
	$tmpColor[]=array(0xff,0,0);
	$image=AddRemarkToImage($image,$pointArr,$remarkBlock,$tmpColor,0,2);
	DrawTimeStamp($image,$sel_date_from,$sel_date_to,array(50,355),750/24);
	
	echo "<table border=0 width=\"820\">";
	echo "<tr>";
	for($i=0;$i<sizeof($remarkBlock);$i++)
	{
		echo "<td>";
		AddCheckbox($remarkBlock[$i]);
		echo "</td>";
	}
	echo "</tr>";
	echo "</table>";
	
	DrawImage($image);
}



if($keyOneNum>1)
{
//Graphics-2
	unset($tmpColor);
	unset($tmpData);
	if($flag7 == "on")
	{
		$tmpColor[]=array(0x66,0xff,0x33);
		$tmpData[]=$success_value[$keyOne1[1]];
	}
	if($flag8 == "on")
	{
		$tmpColor[]=array(0x66,0xff,0xff);
		$tmpData[]=$calldeny_value[$keyOne1[1]];
	}
	if($flag9 == "on")
	{
		$tmpColor[]=array(0,0x66,0x66);
		$tmpData[]=$netbusy_value[$keyOne1[1]];
	}
	if($flag10 == "on")
	{
		$tmpColor[]=array(0x66,0,0xcc);
		$tmpData[]=$callerclear_value[$keyOne1[1]];
	}
	if($flag11 == "on")
	{
		$tmpColor[]=array(0x66,0x33,0);
		$tmpData[]=$subbusy_value[$keyOne1[1]];
	}
	if($flag12 == "on")
	{
		$tmpColor[]=array(0xcc,0,0x66);
		$tmpData[]=$noanswer_value[$keyOne1[1]];
	}
	if($flag13 == "on")
	{
		$tmpColor[]=array(0xff,0,0);
		$tmpData[]=$signalerr_value[$keyOne1[1]];
	}
	
	echo "<br><b>Hourly Statistic Chart(UMTS)</b><br>";
	if($select_checkbox_id>6&&$select_checkbox_id<14)
	{
		if(0)
		{
			echo "flag7=$flag7,flag8=$flag8,flag9=$flag9,flag10=$flag10,flag11=$flag11,flag12=$flag12,flag13=$flag13,select_checkbox_id=$select_checkbox_id<br>";
		}
		$boldline=$select_checkbox_id-7;
		for($i=7;$i<$select_checkbox_id;$i++)
		{
			$param="flag$i";
			if($$param != "on")
				$boldline--;
		}
	}
	$image=CreateImage(820,390);
	$image=DrawLineHistogram(
		$image,
		$tmpData,
		$tmpColor,
		750/(24*$slot),
		24,
		array(50,20),
		array(750,280),
		$boldline,1,0,1
	);
	
	$remarkBlock=array(
		"Success",
		"Call Deny",
		"Network Busy",
		"Caller Clear",
		"Sub Busy",
		"No Answer",
		"Signal Error"
	);
	$pointArr=array(
		array(60,367),
		array(160,367),
		array(260,367),
		array(360,367),
		array(460,367),
		array(560,367),
		array(660,367)
	);
	unset($tmpColor);
	$tmpColor[]=array(0x66,0xff,0x33);
	$tmpColor[]=array(0x66,0xff,0xff);
	$tmpColor[]=array(0,0x66,0x66);
	$tmpColor[]=array(0x66,0,0xcc);
	$tmpColor[]=array(0x66,0x33,0);
	$tmpColor[]=array(0xcc,0,0x66);
	$tmpColor[]=array(0xff,0,0);
	$image=AddRemarkToImage($image,$pointArr,$remarkBlock,$tmpColor,0,2);
	DrawTimeStamp($image,$sel_date_from,$sel_date_to,array(50,355),750/24);
	
	echo "<table border=0 width=\"820\">";
	echo "<tr>";
	for($i=0;$i<sizeof($remarkBlock);$i++)
	{
		echo "<td>";
		AddCheckbox($remarkBlock[$i]);
		echo "</td>";
	}
	echo "</tr>";
	echo "</table>";
	
	DrawImage($image);
}



//Graphics-3 GSM
{
	for($i=0;$i<$total_hour;$i++)
	{
		if($success_value[$keyOne1[0]][$i] > 0)
			$aveduration_value[$keyOne1[0]][$i]=ceil($duration_value[$keyOne1[0]][$i]/$success_value[$keyOne1[0]][$i]);
		else
			$aveduration_value[$keyOne1[0]][$i]=0;
	}
	if(0)
	{
		echo "<pre>";
		print_r($duration_value);
		print_r($success_value);
		print_r($aveduration_value);
		echo "</pre>";
	}
	unset($tmpColor);
	unset($tmpData);
	
	if($keyOneNum>1)
	{
		if($flag14 == "on")
		{
			$tmpColor[]=array(0x66,0xff,0xff);
			$tmpData[]=$duration_value[$keyOne1[0]];
		}
		if($flag15 == "on")
		{
			$tmpColor[]=array(0,0x66,0x66);	
			$tmpData[]=$aveduration_value[$keyOne1[0]];
		}
	}
	else
	{
		if($flag7 == "on")
		{
			$tmpColor[]=array(0x66,0xff,0xff);
			$tmpData[]=$duration_value[$keyOne1[0]];
		}
		if($flag8 == "on")
		{
			$tmpColor[]=array(0,0x66,0x66);	
			$tmpData[]=$aveduration_value[$keyOne1[0]];
		}
	}

	echo "<br><br><b>Duration Statistic Chart(GSM)</b><br>";
	$image=CreateImage(820,390);
	if($keyOneNum>1)
	{
		if($select_checkbox_id>13&&$select_checkbox_id<16)
		{
			$boldline2=$select_checkbox_id-14;
			for($i=14;$i<$select_checkbox_id;$i++)
			{
				$param="flag$i";
				if($$param != "on")
					$boldline2--;
			}
		}
	}
	else
	{
		if($select_checkbox_id>6&&$select_checkbox_id<9)
		{
			$boldline2=$select_checkbox_id-7;
			for($i=7;$i<$select_checkbox_id;$i++)
			{
				$param="flag$i";
				if($$param != "on")
					$boldline2--;
			}
		}		
	}
	$image=DrawLineHistogram(
		$image,
		$tmpData,
		$tmpColor,
		750/(24*$slot),
		24,
		array(50,20),
		array(750,280),
		$boldline2,1,0,1
	);
	
	unset($tmpColor);
	$tmpColor[]=array(0x66,0xff,0xff);
	$tmpColor[]=array(0,0x66,0x66);	
	
	$remarkBlock=array(
		"Total Call Duration",
		"Average Call Duration"
	);
	$pointArr=array(
		array(60,367),
		array(260,367)
	);
	$image=AddRemarkToImage($image,$pointArr,$remarkBlock,$tmpColor,0,2);
	DrawTimeStamp($image,$sel_date_from,$sel_date_to,array(50,355),750/24);
	
	echo "<table border=0 width=\"820\">";
	echo "<tr>";
	for($i=0;$i<sizeof($remarkBlock);$i++)
	{
		echo "<td>";
		AddCheckbox($remarkBlock[$i]);
		echo "</td>";
	}
	echo "</tr>";
	echo "</table>";
	
	DrawImage($image);
}



//Graphics-4 UMTS
if($keyOneNum>1)
{
	for($i=0;$i<$total_hour;$i++)
	{
		if($success_value[$keyOne1[1]][$i] > 0)
			$aveduration_value[$keyOne1[1]][$i]=ceil($duration_value[$keyOne1[1]][$i]/$success_value[$keyOne1[1]][$i]);
		else
			$aveduration_value[$keyOne1[1]][$i]=0;
	}
	if(0)
	{
		echo "<pre>";
		print_r($duration_value);
		print_r($success_value);
		print_r($aveduration_value);
		echo "</pre>";
	}
	unset($tmpColor);
	unset($tmpData);
	
	if($flag16 == "on")
	{
		$tmpColor[]=array(0x66,0xff,0xff);
		$tmpData[]=$duration_value[$keyOne1[1]];
	}
	if($flag17 == "on")
	{
		$tmpColor[]=array(0,0x66,0x66);	
		$tmpData[]=$aveduration_value[$keyOne1[1]];
	}

	echo "<br><br><b>Duration Statistic Chart(UMTS)</b><br>";
	$image=CreateImage(820,390);
	if($select_checkbox_id>15)
	{
		$boldline3=$select_checkbox_id-16;
		for($i=16;$i<$select_checkbox_id;$i++)
		{
			$param="flag$i";
			if($$param != "on")
				$boldline3--;
		}
	}
	$image=DrawLineHistogram(
		$image,
		$tmpData,
		$tmpColor,
		750/(24*$slot),
		24,
		array(50,20),
		array(750,280),
		$boldline3,1,0,1
	);
	
	unset($tmpColor);
	$tmpColor[]=array(0x66,0xff,0xff);
	$tmpColor[]=array(0,0x66,0x66);	
	
	$remarkBlock=array(
		"Total Call Duration",
		"Average Call Duration"
	);
	$pointArr=array(
		array(60,367),
		array(260,367)
	);
	$image=AddRemarkToImage($image,$pointArr,$remarkBlock,$tmpColor,0,2);
	DrawTimeStamp($image,$sel_date_from,$sel_date_to,array(50,355),750/24);
	
	echo "<table border=0 width=\"820\">";
	echo "<tr>";
	for($i=0;$i<sizeof($remarkBlock);$i++)
	{
		echo "<td>";
		AddCheckbox($remarkBlock[$i]);
		echo "</td>";
	}
	echo "</tr>";
	echo "</table>";
	
	DrawImage($image);
}
?>
