<?php

header("Content-Type: text/xml");

ini_set("display_errors","1");
ini_set("display_startup_errors","1");
header("Expires: Thu, 01 Jan 1970 00:00:01 GMT"); 
set_magic_quotes_runtime(0);

include("oldinclude/dbcommon.php");
include("oldinclude/##@TABLE.strShortTableName s##_variables.php");
$width=700;
$height=530;
if($_REQUEST["width"])
	$width=$_REQUEST["width"];
	
if($_REQUEST["height"])
	$height=$_REQUEST["height"];

$counter=0;
$colors=array();

##foreach @TABLE.arrColors as @field##
	$colors[$counter++]="0x##@field##";
##endfor##

$counter=0;

function getcolor()
{
	global $colors, $counter;
	if ($counter>=##@TABLE.arrColors.len##)
		$counter=0;
	return $colors[$counter++];

}	
echo "<?xml version=\"1.0\" standalone=\"yes\"?>";
?>

##CHART_INCLUDES##
<root>
<type>
<chart type='##@TABLE.strChartType##'>
	##if @TABLE.bAnimation##<animation enabled="yes" appearance="size" speed="10" type="step" />
	##else## <animation enabled="no" />
	##endif##


##if @TABLE.bChartNames##
  <names show="yes" >
    <font type="Verdana" size="12"  bold="yes" color="0x##@TABLE.strChartNamesColor##"/>
  </names>
##else##
  <names show="no" />
##endif##	  
	  
	  
##if @TABLE.bChartValues##
	  <values show="yes" decimal_places="##@TABLE.nDigits##" prefix="##@TABLE.strChartPrefix##" postfix="##@TABLE.strChartPostfix##" thousand_separator=",">
	    <font type="Verdana" size="12" color="0x##@TABLE.strChartValuesColor##"/>	  
	  </values>
##else##
  <values show="no" />
##endif##	  
	  
	  <captions show="yes">
	    <font type="Verdana" size="12" color="0x##@TABLE.strChartValuesColor##"/>	  
	  </captions>  
	  
	  <hints enabled="yes" width="100" height="30" auto_size="yes" horizontal_position="center" vertical_position="top" >
	    <background enabled="yes" color="0xFEE7C0"/>
		<border enabled="yes" color="0x##@TABLE.strChartBorderColor##"/>
	    <font type="Verdana" size="12" color="Black" />	  
	  </hints>	  
	  
##if @TABLE.bChartLegend##  
	  <pie_chart 
##if @TABLE.bChartPreview##  
	  x="##eval 30+(@TABLE.nChartWidth-40)*3/5##" 
	  y="##eval @TABLE.nChartHeight/2##" 
	##if @TABLE.bChartValues || @TABLE.bChartNames##
	  radius="##eval (@TABLE.nChartWidth-40)/4##" 
	##else##
	  radius="##eval (@TABLE.nChartWidth-40)/3##" 
	 ##endif##
##else##
	  x="<?php echo 30+($width-40)*3/5;?>" 
	  y="<?php echo $height/2;?>" 
	##if @TABLE.bChartValues || @TABLE.bChartNames##
	  radius="<?php echo ($width-40)/4;?>" 
	##else##
	  radius="<?php echo ($width-40)/3;?>" 
	 ##endif##
##endif##	 
##else##
	  <pie_chart 
##if @TABLE.bChartPreview##  
	  x="##eval @TABLE.nChartWidth/2##" 
	  y="##eval @TABLE.nChartHeight/2##" 
	##if @TABLE.bChartValues || @TABLE.bChartNames##
	  radius="##eval (@TABLE.nChartWidth-40)/4##" 
	##else##
	  radius="##eval (@TABLE.nChartWidth-40)/3##" 
	 ##endif##
##else##
	  x="<?php echo $width/2;?>" 
	  y="<?php echo $height/2;?>" 
	##if @TABLE.bChartValues || @TABLE.bChartNames##
	  radius="<?php echo ($width-40)/4;?>" 
	##else##
	  radius="<?php echo ($width-40)/3;?>" 
	 ##endif##
##endif##
##endif##	  
	  rotation="0" captions_radius="1.1" protrusion_radius="10"
##if @TABLE.nChartType==CHART_3DPIE##
_3d_rotation_grade="45" _3d_height="10"
##elseif @TABLE.nChartType==CHART_2DDOUGHNUT##
##if @TABLE.bChartPreview##  
inner_radius="##eval (@TABLE.nChartWidth-40)/9##"
##else##
inner_radius="<?php echo ($width-40)/9;?>"
##endif##
##endif##
	  >
	    <border enabled="yes" size="1" color="0xF4E1C4" />
		<background enabled="yes" color="0xFFFFFF" alpha="100" auto_color="yes" />
	  </pie_chart>
	  
    </chart>
	<workspace 
##if @TABLE.bChartPreview##  
	width="##@TABLE.nChartWidth##" 
	height="##@TABLE.nChartHeight##" 
##else##
	width="<?php echo $width;?>" 
	height="<?php echo $height;?>" 
##endif##	
	x="0" y="0">
	<chart_area enabled="yes" 
##if @TABLE.bChartPreview##  
	width="##eval @TABLE.nChartWidth-20##" 
	height="##eval @TABLE.nChartHeight-40##" 
##else##
	width="<?php echo $width-20;?>" 
	height="<?php echo $height-40;?>" 
##endif##
	x="10" y="20" deep="0" block_space="0" rotation_grade="45">
<background enabled="yes" type="gradient" gradient_type="linear">
 <colors>
  <color>0x##@TABLE.strChartFirstColor##</color> 
  <color>0x##@TABLE.strChartSecondColor##</color> 
  </colors>
 <alphas>
  <alpha>100</alpha> 
  <alpha>100</alpha> 
  </alphas>
 <ratios>
  <ratio>127</ratio> 
  <ratio>0xFF</ratio> 
  </ratios>
  <matrix r="-1.7" /> 
  </background>
  <border enabled="yes" color="0x##@TABLE.strChartBorderColor##" /> 
  </chart_area>

	  <base_area enabled="no" />
	  <name text="">
	    <font type="Verdana" size="14"  />	  
	  </name>
	  <subname text="">
	    <font type="Verdana" size="14"  />	  
	  </subname>
	</workspace>	

##if @TABLE.bChartLegend##  
	<legend enabled="yes" x="30" y="50">
  <background enabled="no" /> 
  <border enabled="no" /> 
  <scroller enabled="no" /> 
  <header values="##Fields[strName==@TABLE.arrChartDataSeries.strDataField].strLabel h##" names="##Fields[strName==@TABLE.strChartLabelField].strLabel h##" /> 
  <names>
    <font type="Verdana" size="12"  bold="yes" color="0x##@TABLE.strChartNamesColor##"/>
  </names>
  <values>
    <font type="Verdana" size="12"  bold="yes" color="0x##@TABLE.strChartValuesColor##"/>
  </values>
	</legend>
##endif##	

  </type>
  <data>
  
##CHART_DATA_START##
  
<?php

$conn=db_connect();

//$strSQL= "##@TABLE.strSQL ls##";
$strWhereClause = CalcSearchParameters();

##if @TABLE.nSecOptions==ADVSECURITY_VIEW_OWN  && @BUILDER.nLoginMethod==SECURITY_TABLE && @BUILDER.bCreateLoginPage##
$strWhereClause = whereAdd($strWhereClause,SecuritySQL("Search"));
//if(SecuritySQL("Search"))
//	$strSQL = AddWhere($strSQL, SecuritySQL("Search"));
##endif##

$strSQL = gSQLWhere($strWhereClause);

$strOrderBy = $gstrOrderBy;
$strSQL.= " ".$strOrderBy;

$strSQLbak=$strSQL;
if(function_exists("BeforeQueryChart"))
	BeforeQueryChart($strSQL,$strWhereClause,$strOrderBy);
if($strSQLbak == $strSQL)
{
	$strSQL=gSQLWhere($strWhereClause);
	$strSQL.= " ".$strOrderBy;
}

$rs=db_query($strSQL,$conn);

echo "\r\n<block>";



while ($row = db_fetch_array($rs)) 
{
$value=$row["##@TABLE.strChartLabelField s##"];
if(strlen($value)>15)
{
	$value=substr($row["##@TABLE.strChartLabelField s##"],0,12)."...";
}

##foreach @TABLE.arrChartDataSeries as @field filter @field.strDataField!=""##
##if @first##
	echo "\r\n<set value='".xmlencode($row["##@field.strDataField s##"]+0)."' name='".xmlencode($value)."' color='" . getcolor() . "'/>";
##endif##	
##endfor##

}
echo "\r\n</block>";
		
// close connection:
db_close($conn);



?>

##CHART_DATA_END##

  </data>
  <objects>
    <text text="##@TABLE.strChartHeader s##" auto_size="yes" x="40" y="20" 
##if @TABLE.bChartPreview##  
	width="##@TABLE.nChartWidth##" 
##else##
	width="<?php echo $width;?>" 
##endif##
	height="20">
      <font type="Verdana" bold="yes" size="14" align="center" color="0x##@TABLE.strChartHeaderColor##"/>
    </text>
    <text text="##@TABLE.strChartFooter s##" auto_size="yes" x="40" 
##if @TABLE.bChartPreview##  
	y="##eval @TABLE.nChartHeight-40##"
##else##
	y="<?php echo $height-40;?>"
##endif##	
	>
      <font type="Verdana" size="14" align="center" color="0x##@TABLE.strChartFooterColor##"/>
    </text>
  </objects>
</root>