<?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"];

##if @TABLE.bMulticolor##
$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++];
}
##endif##

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

##CHART_INCLUDES##

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

<values decimal_places="##@TABLE.nDigits##" prefix="##@TABLE.strChartPrefix##" postfix="##@TABLE.strChartPostfix##" thousand_separator="," 
##if VerticalChart##
rotation="-90" 
##else##
position="center"
##endif##
##if @TABLE.bChartValues## show='yes' ##else## show='no' ##endif##>
##if VerticalChart##
  <font type="verdana_embed_tf" color="0x##@TABLE.strChartValuesColor##"/> 
##else##
  <font type="Verdana" color="0x##@TABLE.strChartValuesColor##"/> 
##endif##
  </values>

##if @TABLE.bChartValues##  
##if @TABLE.nChartType==CHART_STACKED_2D || @TABLE.nChartType==CHART_STACKED_3D || @TABLE.nChartType==CHART_STACKED_HOR_2D || @TABLE.nChartType==CHART_STACKED_HOR_3D##
<captions
##if VerticalChart##
rotation="-90" 
##endif##
>
##if VerticalChart##
  <font type="verdana_embed_tf" color="0x##@TABLE.strChartValuesColor##"/> 
##else##
  <font type="Verdana" color="0x##@TABLE.strChartValuesColor##"/> 
##endif##
</captions>
##endif##
##endif##

##if @TABLE.nChartType==CHART_STACKED_2D && !@TABLE.bChartValues##
<captions show="yes" text="">
  <font type="verdana_embed_tf" color="0x444444" /> 
</captions>
##endif##

<names 
##if VerticalChart##
rotation="25" 
##endif##
placement="chart" position="bottom" show="no">
##if VerticalChart##
  <font type="verdana_embed_tf" size="12"/> 
##else##
  <font type="Verdana" size="12"/> 
##endif## 
  </names>
  
  <hints enabled="no" /> 
<column_chart block_space="10" column_space="0" left_space="10" right_space="10" up_space="70" down_space="0"
##if @TABLE.nChartType==CHART_3DCOLUMN || @TABLE.nChartType==CHART_HORIZONTAL3D || @TABLE.nChartType==CHART_STACKED_3D || @TABLE.nChartType==CHART_STACKED_HOR_3D##
deep="10" _3d_rotation="45"
##endif##
>
  <border enabled="yes" /> 
  <background auto_color="no" color="0x7397C1"  ##if @TABLE.nChartType==CHART_STACKED_3D## alpha="70" ##endif##/> 
  
<block_names 
##if VerticalChart##
rotation="25" 
##endif##
placement="chart"
##if @TABLE.bChartNames## show='yes' ##else## show='no' ##endif##>
##if VerticalChart##
	<font type="verdana_embed_tf" size="12" color="0x##@TABLE.strChartNamesColor##"/> 
##else##
	<font type="Verdana" size="12" color="0x##@TABLE.strChartNamesColor##"/> 
##endif## 
  </block_names>

  </column_chart>

##if !@TABLE.bChartValues##
<captions show="no" /> 
##endif##

</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">
##if @TABLE.nChartType==CHART_2DCOLUMN || @TABLE.nChartType==CHART_3DCOLUMN || @TABLE.nChartType==CHART_STACKED_2D || @TABLE.nChartType==CHART_STACKED_3D##
<chart_area 
##if @TABLE.bChartPreview##  
width="##eval @TABLE.nChartWidth-70##" 
height="##eval @TABLE.nChartHeight-130##" 
##else##
width="<?php echo $width-70;?>" 
height="<?php echo $height-130;?>" 
##endif##
x="50" y="50" deep="0" block_space="10" column_space="10" left_space="10" right_space="10" up_space="70" down_space="0">
##else##
<chart_area 
##if @TABLE.bChartPreview##  
width="##eval @TABLE.nChartWidth-130##" 
height="##eval @TABLE.nChartHeight-130##" 
##else##
width="<?php echo $width-130;?>" 
height="<?php echo $height-130;?>" 
##endif##
x="110" y="50" deep="0" block_space="10" column_space="10" left_space="10" right_space="10" up_space="70" down_space="0">
##endif##
<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" /> 
  
##if @TABLE.bChartGrid##    
 <grid>
 <values>
 <captions>
  <font size="10" type="Verdana" /> 
  </captions>
  </values>
  </grid>
##endif##  
##if @TABLE.nChartType==CHART_2DCOLUMN || @TABLE.nChartType==CHART_3DCOLUMN || @TABLE.nChartType==CHART_STACKED_2D || @TABLE.nChartType==CHART_STACKED_3D##
<y_axis smart="yes" /> 
##else##
<x_axis smart="yes" /> 
##endif##  
  </workspace>
  
##if @TABLE.bChartLegend##  
    <legend enabled="yes" 
##if @TABLE.bChartPreview##  
	x="##eval @TABLE.m_nChartWidth-150##" 
##else##
	x="<?php echo $width-150;?>" 
##endif##
	y="60">
      <values enabled="no"/>
      <header enabled="no" names="Series"/>
      <names enabled="yes" width="150"/>
      <scroller enabled="no"/>
      <border enabled="no"/>
      <background enabled="no"/>
	  <colors width="20" /> 
    </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);

$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);

while ($row = db_fetch_array($rs)) 
{
$value=$row["##@TABLE.strChartLabelField s##"];
if(strlen($value)>15)
{
	$value=substr($row["##@TABLE.strChartLabelField s##"],0,12)."...";
}
echo "\r\n<block ##if @TABLE.bChartNames## name='".xmlencode($value)."' block_name_enabled='yes' ##else## block_name_enabled='no' ##endif## >";

##foreach @TABLE.arrChartDataSeries as @field filter @field.strDataField!=""##
	echo "\r\n<set value='".xmlencode($row["##@field.strDataField s##"]+0)."' name='##@field.strDataField s##' ##if @TABLE.bMulticolor## color='" . getcolor() . "'##else##color='0x##@field.strColor##'##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" size="14" bold="yes" align="center" color="0x##@TABLE.strChartHeaderColor##"/>
    </text>
    <text text="##@TABLE.strChartFooter s##" auto_size="yes" x="40" 
##if @TABLE.bChartPreview##  
	y="##eval @TABLE.nChartHeight-20##"
##else##
	y="<?php echo $height-20;?>"
##endif##
	>
      <font type="Verdana" size="14" align="center" color="0x##@TABLE.strChartFooterColor##"/>
    </text>
  </objects>

</root>


