<?php
require("../../inc/header.inc");
?>

<script language="JavaScript">
	function hide_and_show_table1()
	{
		if(document.all.t1.style.display=="none")
		{
			document.all.t0.style.display="";
			document.all.t1.style.display="";
			document.all.t2.style.display="";
			document.all.t3.style.display="";
			document.all.t4.style.display="";
			document.all.flag1.value="Hide";
		}
		else
		{
			document.all.t0.style.display="none";
			document.all.t1.style.display="none";
			document.all.t2.style.display="none";
			document.all.t3.style.display="none";
			document.all.t4.style.display="none";
			document.all.flag1.value="Show";
		}
	}
	function hide_and_show_table2()
	{
		if(document.all.t5.style.display=="none")
		{
			document.all.t5.style.display="";
			document.all.t6.style.display="";
			document.all.t7.style.display="";
			document.all.flag2.value="Hide";
		}
		else
		{
			document.all.t5.style.display="none";
			document.all.t6.style.display="none";
			document.all.t7.style.display="none";
			document.all.flag2.value="Show";
		}
	}
	function hide_and_show_table3()
	{
		if(document.all.t8.style.display=="none")
		{
			document.all.t8.style.display="";
			document.all.t9.style.display="";
			document.all.t10.style.display="";
			document.all.t11.style.display="";
			document.all.t12.style.display="";
			document.all.flag3.value="Hide";
		}
		else
		{
			document.all.t8.style.display="none";
			document.all.t9.style.display="none";
			document.all.t10.style.display="none";
			document.all.t11.style.display="none";
			document.all.t12.style.display="none";
			document.all.flag3.value="Show";
		}
	}
</script>


<?php
	//============scroll the page====================
	if($scroll_y > 0){
		//echo "<body style=\"overflow-x:hidden\" topmargin=\"5\" leftmargin=\"12\" onLoad='self.scrollBy(0,$scroll_y)'>";
		echo "<body leftmargin=\"15\" rightmargin=\"10\" onload=\"javascript:scroll_div('$scroll_y');javascript:adjust_frame('down');\" onresize=\"javascript:adjust_frame('down');\" style=\"overflow:hidden;overflow-x:hidden;overflow-y:hidden;\">";
	}else{
		echo "<body leftmargin=\"15\" rightmargin=\"10\" onload=\"javascript:adjust_frame('down');\" onresize=\"javascript:adjust_frame('down');\" style=\"overflow:hidden;overflow-x:hidden;overflow-y:hidden;\">";
	}
adjust_head_frame("down");
adjust_title_head_frame("down");
adjust_title_tail_frame("down");

adjust_content_head_frame("down");	
echo "<br>";	
//=====================================================================================|
//============================Function Flag============================================|
//=====================================================================================|
$Hide_Show_Function_On=0;
$DEBUG=0;
//=====================================================================================|
//============================Data From Index Page=====================================|
//=====================================================================================|
if(0)
{
	
	$url_temp=$_SERVER["REQUEST_URI"];
	echo "This page URL:$url_temp<br>";
	
	echo "sel_date_from:$sel_date_from<br>";
	echo "sel_date_to:$sel_date_to<br>";
}
//=====================================================================================|
//============================Define The Data==========================================|
//=====================================================================================|
	//data define
	for($i=0;$i<6;$i++)
	{
		for($j=0;$j<22;$j++)
		{                      	  
			/*									  0 attempt         
			0  call mo        	  1 success         
			1  call mt      			2 duration        
			2  sm mo      				3 lu_normal       
			3  sm mt    					4 lu_resNotOk     
			4  lu   							5 lu_serNotOk     
														6 lu_serNoImp     
														7 lu_msgError     
														8 lu_proError     
														9 cc_normal			  
													 10 cc_callDeny		  
			                     11 cc_netBusy			
			                     12 cc_callerClear	
			                     13 cc_subBusy			
			                     14 cc_noAnswer		  
			                     15 cc_sigError	    
			                     16 sm_normal		    
			                     17 sm_errSub		    
			                     18 sm_serNotOk	    
			                     19 sm_netBusy		  
			                     20 sm_msgError	    
			                     21 sm_proError	    
			                     22 sm_resNotOk     
			
			*/
			
			
			
			
			$service_csta[$i][$j]=0;
		}                         
	}                           
	                            
//===================================================================================|
//========================Get The Data From DB=======================================|
//===================================================================================|
	$db=$csta_db;               
	$bgn_time=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$sel_date_from,date("Y")));
	$end_time=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$sel_date_to,date("Y")));
	//get the numbers of days that selected
	$slot=$sel_date_from-$sel_date_to+1;
	if(0)
	{
		echo "bgn_time:$bgn_time<br>";
		echo "end_time:$end_time<br>";
		echo "slot:$slot<br>";
		echo "db:$csta_db<br>";
	}
	
	$detailTableFields=array("Attempt",
												   "Success",
												   "Duration",
												   "lu_normal",
												   "lu_res_not_ok",
												   "lu_ser_not_ok",
												   "lu_ser_no_imp",
												   "lu_msg_error",
												   "lu_pro_error",
												   "cc_normal",
												   "cc_call_deny",
												   "cc_net_busy",
												   "cc_caller_clear",
												   "cc_sub_busy",
												   "cc_no_answer",
												   "cc_sig_error",
												   "sm_normal",
												   "sm_error_sub",
												   "sm_ser_not_ok",
												   "sm_net_busy",
												   "sm_msg_error",
												   "sm_pro_error",
												   "sm_res_not_ok"
												   );
	$detailTableFieldsSql="";								   
	for($i=0;$i<sizeof($detailTableFields);$i++)
	{
		$detailTableFieldsSql.="sum(".$detailTableFields[$i].") as ".$detailTableFields[$i];
		if($i<sizeof($detailTableFields)-1)
			$detailTableFieldsSql.=",";
	}
	//echo "$detailTableFieldsSql<br>";
	
	$key_type_relation=array(5=>0,6=>1,7=>2,8=>3,9=>4,10=>5,11=>6,12=>7,13=>8,14=>9,15=>10,16=>11);
	for($day=0;$day<$slot;$day++)
	{
		$table_name="ipalimSum";
		$temp=date("d",mktime(0,0,0,date("m"),date("d")-$sel_date_from+$day,date("Y")));
		$table_name=$table_name."_".$temp;
		
		//echo "table_name:$table_name<br>";	
		$from_time=date("Y-m-d H:i:s",mktime(0,0,0,date("m"),date("d")-$sel_date_from+$day,date("Y")));
		$to_time=date("Y-m-d H:i:s",mktime(23,0,0,date("m"),date("d")-$sel_date_from+$day,date("Y")));
		//echo "from:$from_time--to:$to_time<br>";
		
		$select="select key_type,".$detailTableFieldsSql." ";
		
		$from="from $table_name ";
		$service_where="and key_type>0 and key_type<6 ";
		$where="where csta_datetime >='$from_time' and csta_datetime <'$to_time' ".$service_where;
		$group="group by key_type ";
		$order="order by key_type ";
		$sql=$select.$from.$where.$group.$order;
		//echo "$sql<br>";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		
		if(!$rows)
			continue;

		do{
			$key_type=$rows[key_type]+0;
			
			for($tt=0;$tt<23;$tt++)
			{
				$service_csta[$key_type][$tt]+=$rows[$tt+1];
				//echo "type-$key_type-$tt:{$service_csta[$key_type][$tt]}<br>";
			}
		}while($rows=mysqli_fetch_array($result));	
	}

	//get the 0-hour of the day
	for($day=0;$day<$slot;$day++)
	{
		$table_name="ipalimSum";
		$temp=date("d",mktime(0,0,0,date("m"),date("d")-$sel_date_from+$day-1,date("Y")));
		$table_name=$table_name."_".$temp;
		
		//echo "table_name:$table_name<br>";	
		$from_time=date("Y-m-d H:i:s",mktime(23,0,0,date("m"),date("d")-$sel_date_from+$day-1,date("Y")));
		$to_time=date("Y-m-d H:i:s",mktime(0,0,0,date("m"),date("d")-$sel_date_from+$day,date("Y")));
		//echo "from:$from_time--to:$to_time<br>";
		
		$select="select key_type,".$detailTableFieldsSql." ";
		$from="from $table_name ";
		$service_where="and key_type>0 and key_type<6 ";
		$where="where csta_datetime >='$from_time' and csta_datetime <'$to_time' ".$service_where;
		$group="group by key_type ";
		$order="order by key_type ";
		$sql=$select.$from.$where.$group.$order;
		//echo "$sql<br>";
		
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		
		if(!$rows)
			continue;

		do{
			$key_type=$rows[key_type]+0;
			
			for($tt=0;$tt<22;$tt++)
			{
				$service_csta[$key_type][$tt]+=$rows[$tt+1];
				//echo "type-$service_type-$tt:{$service_csta[$service_type][$tt]}<br>";
			}
		}while($rows=mysqli_fetch_array($result));	
	}


//===================================================================================|
//=======================Show The Table-1============================================|
//===================================================================================|
	//===table lu
	if($slot==1)
		$table_title="Service statistic Date:".$bgn_time;
	else
		$table_title="Service statistic Date:".$bgn_time." to ".$end_time;	
	echo "<center><b>$table_title</b></center>";
	echo "<table border=\"1\" width=\"100%\" cellpadding=\"2\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#FFFFFF\">";
	echo "<tr bgcolor=\"#E6E6E6\">";
		echo "<td align=\"center\" width=\"13%\">Type</td>";
		echo "<td align=\"center\" width=\"8%\">Attempt</td>";
		echo "<td align=\"center\" width=\"8%\">Success</td>";
		echo "<td align=\"center\" width=\"8%\">Normal</td>";
		echo "<td align=\"center\" width=\"8%\">No Resource</td>";
		echo "<td align=\"center\" width=\"8%\">No Service</td>";
		echo "<td align=\"center\" width=\"8%\">Invalid Service</td>";
		echo "<td align=\"center\" width=\"8%\">Invalid Message</td>";
		echo "<td align=\"center\" width=\"10%\">Signal Error</td>";
		echo "<td align=\"center\" width=\"8%\">Duration</td>";
		echo "<td align=\"center\" width=\"8%\">Average Duration</td>";
	echo "</tr>";	
	$service_type_label=array(1=>"LU");
	$type_map=array(0=>0,1=>1,2=>3,3=>4,4=>5,5=>6,6=>7,7=>8,8=>2);
	//========show subs to subs,subs to local,subs to toll,trunk to subs,trunk to trunk==========
	for($i=1;$i<2;$i++)
	{
		echo "<tr id=\"t$i\">";

		echo "<td align=\"center\"><a target=\"_parent\" href=\"../../performance/ipalimCsta/service_detail_index.php?on_top_index=0&service_type=$i&sel_date_from=$sel_date_from&sel_date_to=$sel_date_to\">$service_type_label[$i]</a></td>";
		for($j=0;$j<sizeof($type_map);$j++)
		{
			$m_j=$type_map[$j];
			echo "<td align=\"center\">";
			if($j==8)
			{
				echo "{$service_csta[$i][$m_j]}(s)";
				$hour=floor($service_csta[$i][$m_j]/3600);
				$minute=floor($service_csta[$i][$m_j]%3600/60);
				$second=$service_csta[$i][$m_j]%60;
				if($hour==0&&$minute==0&&$second==0)
					echo "<br>";
				else
					echo "<br>$hour:$minute:$second";
			}
			else
			{
				echo "{$service_csta[$i][$m_j]}";
			}
			
			if($j != 0&&$j != 8)
			{
				if($service_csta[$i][0]==0)
					$rate=0;
				else
				{
					$rate=$service_csta[$i][$m_j]/$service_csta[$i][0];
					$rate=$rate*100;
					if($rate!=0&&$rate!=100)
						$rate=number_format($rate, 2, '.', '');	
				}
				echo "<br>$rate%";
			}
			echo "</td>";
		}
		
		echo "<td align=\"center\">";
		if($service_csta[$i][1]!=0)
			$ave=round($service_csta[$i][2]/$service_csta[$i][1]);
		else
			$ave=0;
		echo "$ave";		
		echo "</td>";
		
		echo "</tr>";
	
	}	
	echo "</table>";
	
	//mo mt
	if($slot==1)
		$table_title="Service statistic Date:".$bgn_time;
	else
		$table_title="Service statistic Date:".$bgn_time." to ".$end_time;	
	//echo "<center><b>$table_title</b></center>";
	echo "<p><table border=\"1\" width=\"100%\" cellpadding=\"2\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#FFFFFF\">";
	echo "<tr bgcolor=\"#E6E6E6\">";
		echo "<td align=\"center\" width=\"13%\">Type</td>";
		echo "<td align=\"center\" width=\"8%\">Attempt</td>";
		echo "<td align=\"center\" width=\"8%\">Success</td>";
		echo "<td align=\"center\" width=\"8%\">Normal</td>";
		echo "<td align=\"center\" width=\"8%\">Call Deny</td>";
		echo "<td align=\"center\" width=\"8%\">Net Busy</td>";
		echo "<td align=\"center\" width=\"8%\">Caller Clear</td>";
		echo "<td align=\"center\" width=\"8%\">Sub Busy</td>";
		echo "<td align=\"center\" width=\"10%\">No Answer</td>";
		echo "<td align=\"center\" width=\"10%\">Signal Error</td>";
		echo "<td align=\"center\" width=\"8%\">Duration</td>";
		echo "<td align=\"center\" width=\"8%\">Average Duration</td>";
	echo "</tr>";	
	$service_type_label=array(2=>"Call MO",3=>"Call MT");
	$type_map=array(0=>0,1=>1,2=>9,3=>10,4=>11,5=>12,6=>13,7=>14,8=>15,9=>2);
	//========show subs to subs,subs to local,subs to toll,trunk to subs,trunk to trunk==========
	for($i=2;$i<4;$i++)
	{
		echo "<tr id=\"t$i\">";

		echo "<td align=\"center\"><a target=\"_parent\" href=\"../../performance/ipalimCsta/service_detail_index.php?on_top_index=0&service_type=$i&sel_date_from=$sel_date_from&sel_date_to=$sel_date_to\">$service_type_label[$i]</a></td>";
		for($j=0;$j<sizeof($type_map);$j++)
		{
			$m_j=$type_map[$j];
			echo "<td align=\"center\">";
			if($j==9)
			{
				echo "{$service_csta[$i][$m_j]}(s)";
				$hour=floor($service_csta[$i][$m_j]/3600);
				$minute=floor($service_csta[$i][$m_j]%3600/60);
				$second=$service_csta[$i][$m_j]%60;
				if($hour==0&&$minute==0&&$second==0)
					echo "<br>";
				else
					echo "<br>$hour:$minute:$second";
			}
			else
			{
				echo "{$service_csta[$i][$m_j]}";
			}
			
			if($j != 0&&$j != 9)
			{
				if($service_csta[$i][0]==0)
					$rate=0;
				else
				{
					$rate=$service_csta[$i][$m_j]/$service_csta[$i][0];
					$rate=$rate*100;
					if($rate!=0&&$rate!=100)
						$rate=number_format($rate, 2, '.', '');	
				}
				echo "<br>$rate%";
			}
			echo "</td>";
		}
		
		echo "<td align=\"center\">";
		if($service_csta[$i][1]!=0)
			$ave=round($service_csta[$i][2]/$service_csta[$i][1]);
		else
			$ave=0;
		echo "$ave";		
		echo "</td>";
		
		echo "</tr>";
	
	}	
	echo "</table>";
	
	//smo smt
	if($slot==1)
		$table_title="Service statistic Date:".$bgn_time;
	else
		$table_title="Service statistic Date:".$bgn_time." to ".$end_time;	
	//echo "<center><b>$table_title</b></center>";
	echo "<p><table border=\"1\" width=\"100%\" cellpadding=\"2\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#FFFFFF\">";
	echo "<tr bgcolor=\"#E6E6E6\">";
		echo "<td align=\"center\" width=\"13%\">Type</td>";
		echo "<td align=\"center\" width=\"8%\">Attempt</td>";
		echo "<td align=\"center\" width=\"8%\">Success</td>";
		echo "<td align=\"center\" width=\"8%\">Normal</td>";
		echo "<td align=\"center\" width=\"8%\">Sub Error</td>";
		echo "<td align=\"center\" width=\"8%\">No Service</td>";
		echo "<td align=\"center\" width=\"8%\">Net Busy</td>";
		echo "<td align=\"center\" width=\"8%\">Message Error</td>";
		echo "<td align=\"center\" width=\"10%\">Signal Error</td>";
		echo "<td align=\"center\" width=\"10%\">No Resource</td>";
		echo "<td align=\"center\" width=\"8%\">Duration</td>";
		echo "<td align=\"center\" width=\"8%\">Average Duration</td>";
	echo "</tr>";	
   

	$service_type_label=array(4=>"SM MO",5=>"SM MT");
	$type_map=array(0=>0,1=>1,2=>16,3=>17,4=>18,5=>19,6=>20,7=>21,8=>22,9=>2);
	//========show subs to subs,subs to local,subs to toll,trunk to subs,trunk to trunk==========
	for($i=4;$i<6;$i++)
	{
		echo "<tr id=\"t$i\">";

		echo "<td align=\"center\"><a target=\"_parent\" href=\"../../performance/ipalimCsta/service_detail_index.php?on_top_index=0&service_type=$i&sel_date_from=$sel_date_from&sel_date_to=$sel_date_to\">$service_type_label[$i]</a></td>";
		for($j=0;$j<sizeof($type_map);$j++)
		{
			$m_j=$type_map[$j];
			echo "<td align=\"center\">";
			if($j==9)
			{
				echo "{$service_csta[$i][$m_j]}(s)";
				$hour=floor($service_csta[$i][$m_j]/3600);
				$minute=floor($service_csta[$i][$m_j]%3600/60);
				$second=$service_csta[$i][$m_j]%60;
				if($hour==0&&$minute==0&&$second==0)
					echo "<br>";
				else
					echo "<br>$hour:$minute:$second";
			}
			else
			{
				echo "{$service_csta[$i][$m_j]}";
			}
			
			if($j != 0&&$j != 9)
			{
				if($service_csta[$i][0]==0)
					$rate=0;
				else
				{
					$rate=$service_csta[$i][$m_j]/$service_csta[$i][0];
					$rate=$rate*100;
					if($rate!=0&&$rate!=100)
						$rate=number_format($rate, 2, '.', '');	
				}
				echo "<br>$rate%";
			}
			echo "</td>";
		}
		
		echo "<td align=\"center\">";
		if($service_csta[$i][1]!=0)
			$ave=round($service_csta[$i][2]/$service_csta[$i][1]);
		else
			$ave=0;
		echo "$ave";		
		echo "</td>";
		
		echo "</tr>";
	
	}	
	echo "</table>";
	
//=====================================================================================|
//=======================Draw The Graphics-1===========================================|
//=====================================================================================|
echo "<p><b>2.Service(Attempt)</b><br>";
  //=====graphics size=======
	$sizex=500;
	$sizey=250;

	$im = ImageCreate ($sizex, $sizey);
	$background_color=ImageColorAllocate($im,255,255,255);
	$black_color=ImageColorAllocate($im,0,0,0);
	$white_color= imagecolorallocate($im, 255, 255, 255);
	
	$bgcolor=F8F8F8;
	$fgcolor=000000;
	
	$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)));
				
	//====graphics background=======
	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);
	
	imagedashedline($im,30,30,100,100,$black_color);
	
	//======draw the horizonal line========
	
	$style = array($black_color,$black_color,$black_color,$black_color,$black_color,$white_color,$white_color,$white_color,$white_color,$white_color);
	imagesetstyle($im, $style);
	for($i=10;$i>0;$i--)
	{
		$x1=40;
		$y1=20+(10-$i)*18;
		$x2=447;
		$y2=$y1;
		
		if($i!=10)
		{
			imageline($im, $x1,$y1,$x2,$y2, IMG_COLOR_STYLED);
		}
		
		imagestring($im,2,$x1-22,$y2-5,($i*10)."%",$black_color);		
	}
	
	//=======draw the vitical line=======
	
	$u=floor(750/20);
	for($i=0;$i<12;$i++)
	{
		$x1=40+$i*$u;
		$y1=20;
		$x2=$x1;
		$y2=200;
		ImageDashedLine($im,$x1,$y1,$x2,$y2,$black_color);
	}
	
	//=======get colors============
	$color[0]=ImageColorAllocate($im,0x99,0x00,0x33);
	$color[1]=ImageColorAllocate($im,0x99,0x00,0xcc);
	$color[2]=ImageColorAllocate($im,0x99,0x99,0x00);
	$color[3]=ImageColorAllocate($im,0x99,0xcc,0x99);
	$color[4]=ImageColorAllocate($im,0x99,0xff,0x33);
	$color[5]=ImageColorAllocate($im,0xff,0x99,0x66);
	$color[6]=ImageColorAllocate($im,0xff,0x99,0xff);
	$color[7]=ImageColorAllocate($im,0xff,0xff,0x00);
	$color[8]=ImageColorAllocate($im,0x33,0x3,0x33);
	$color[9]=ImageColorAllocate($im,0x00,0xcc,0xff);
	$color[10]=ImageColorAllocate($im,0x00,0x66,0xcc);
	$color[11]=ImageColorAllocate($im,0x33,0xff,0x99);
	
	//=====get the precent and block height(Part-1)======
	$attempt_sum_one=0;
	for($i=0;$i<6;$i++)
	{
		$attempt_sum_one+=$service_csta[$i][0];
	}
	if($attempt_sum_one==0)
	{
		//lu precent
		$lu_attempt_precent="0%";
		//mo precent
		$mo_attempt_precent="0%";
		//mt precent
		$mt_attempt_precent="0%";
		//smo precent
		$smo_attempt_precent="0%";
		//smt precent
		$smt_attempt_precent="0%";
			
		for($t=0;$t<5;$t++)
			$height[$t]=0;
	}
	else
	{
		//lu precent
		$lu_attempt_precent=number_format($service_csta[1][0]*100/$attempt_sum_one,2,'.','')."%";
		//mo precent
		$mo_attempt_precent=number_format($service_csta[2][0]*100/$attempt_sum_one,2,'.','')."%";
		//mt precent
		$mt_attempt_precent=number_format($service_csta[3][0]*100/$attempt_sum_one,2,'.','')."%";
		//smo precent
		$smo_attempt_precent=number_format($service_csta[4][0]*100/$attempt_sum_one,2,'.','')."%";
		//interconnection precent
		$smt_attempt_precent=number_format($service_csta[5][0]*100/$attempt_sum_one,2,'.','')."%";
		
		for($t=1;$t<6;$t++)
		{
			$height[$t-1]=floor(180*$service_csta[$t][0]/$attempt_sum_one);
		}
	}
	
	
	//======draw the data block======
	for($i=0;$i<5;$i++)
	{		
		$x1=40+(2*$i+1)*$u;
		if($height[$i]==0)
			$height[$i]=1;
		$y1=200-$height[$i];
		$x2=40+(2*$i+2)*$u;
		$y2=199;
		imagefilledrectangle($im,$x1,$y1,$x2,$y2,$color[$i]);
	}
	
	//======draw the legend string=======
	imagestring($im,2,90,205,"LU",$black_color);
	imagestring($im,2,70,220,"(".$lu_attempt_precent.")",$black_color);
	imagestring($im,2,150,205,"Call MO",$black_color);
	imagestring($im,2,148,220,"(".$mo_attempt_precent.")",$black_color);
	imagestring($im,2,225,205,"Call MT",$black_color);
	imagestring($im,2,225,220,"(".$mt_attempt_precent.")",$black_color);
	imagestring($im,2,305,205,"SM MO",$black_color);
	imagestring($im,2,300,221,"(".$smo_attempt_precent.")",$black_color);
	imagestring($im,2,380,205,"SM MT",$black_color);
	imagestring($im,2,375,221,"(".$smt_attempt_precent.")",$black_color);
	
	
	//draw the outline
	imageLine($im,40,20,40,200,$black_color);
	imageLine($im,40,20,447,20,$black_color);
	imageLine($im,447,200,447,20,$black_color);
	imageLine($im,40,200,447,200,$black_color);

  //======show the service attempt graphics==========
	//-----输出图形文件，请勿修改
	//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="ser3_".time().".png";
	if(1){
		ImagePng ($im,"$filename");
		
		ImageDestroy($im);	
	}
	//-----显示图片  
	echo "<img src=\"$filename\"></img>";
	
	
	
//=====================================================================================|
//========================Draw The Graphics-2==========================================|
//=====================================================================================|
//=======draw the Success failure graphics==========
	/*
	echo "<p><b>3.Success/Failure<br>";
	$sizex=500;
	$sizey=250;
	$image=imagecreate($sizex,$sizey);
	$bgcolor=imagecolorallocate($image,255,255,255);
	$black_color=ImageColorAllocate($image,0,0,0);
	
	$bgcolor=F8F8F8;
	$fgcolor=000000;
	
	$background_color = ImageColorAllocate ($image, 
				hexdec(substr($bgcolor, 0, 2)), 
				hexdec(substr($bgcolor, 2, 2)),
				hexdec(substr($bgcolor, 4, 2)));
	
	$text_color = ImageColorAllocate ($image, 
				hexdec(substr($fgcolor, 0, 2)), 
				hexdec(substr($fgcolor, 2, 2)),
				hexdec(substr($fgcolor, 4, 2)));
				
				
				
	//=====background========
	ImageFilledRectangle($image,0,0,$sizex,$sizey,ImageColorAllocate ($image, 198, 198, 198));
	ImageFilledRectangle($image,2,2,$sizex,$sizey,ImageColorAllocate ($image, 130, 130, 130));
	$pointArr=array(0,$sizey-1,3,$sizey-4,4,$sizey-1);
	Imagefilledpolygon($image, $pointArr, 3, ImageColorAllocate ($image, 130, 130, 130));
	$pointArr=array($sizex-1,0,$sizex-4,3,$sizex,4);
	Imagefilledpolygon($image, $pointArr, 3, ImageColorAllocate ($image, 130, 130, 130));
	ImageFilledRectangle($image,2,2,$sizex-3,$sizey-3,$background_color);
	
	//first
	imageLine($image,40,20,40,200,$black_color);
	imageLine($image,40,20,450,20,$black_color);
	imageLine($image,450,200,450,20,$black_color);
	imageLine($image,40,200,450,200,$black_color);
	
	
				
	//======show the answer failure graphics=====
	$tt=time()-2500;
	$file_name="ser4_".$tt.".png";
	imagepng($image,$file_name);
	imagedestroy($image);
	echo "<img src=$file_name></img>";	
	*/
adjust_content_tail("down");
?>


</body>
