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

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

?>

##CHART_INCLUDES##

<root>
<type>

<chart type="2DColumn" minimum_value="0">

  
  ##if @TABLE.bAnimation##<animation enabled="yes" speed="30" type="step" appearance="size" /> 
  ##else## <animation enabled="no" />
  ##endif##
  <values decimal_places="##@TABLE.nDigits##" prefix="##@TABLE.strChartPrefix##" postfix="##@TABLE.strChartPostfix##" thousand_separator=","
##if @TABLE.bChartValues##
  show='yes' 
##else##  
  show='no' 
##endif##
  position="top" y_offset="40" rotation="-90"> 
	<font type="verdana_embed_tf" /> 
   </values>

  <hints enabled="no" /> 
  <column_chart column_space="15">
  <border enabled="no" /> 
  <background auto_color="no" color="0x##@TABLE.arrChartDataSeries[nIndex==1].strColor##" alpha="80" /> 

<block_names enabled="no"/>
 </column_chart>
<names 
rotation="25" 
placement="chart"
##if @TABLE.bChartNames## show='yes' ##else## show='no' ##endif##>
	<font type="verdana_embed_tf" color="0x##@TABLE.strChartNamesColor##"/> 
  </names>
 </chart>
  
 <chart type="2DLine">
  ##if @TABLE.bAnimation##<animation enabled="yes" speed="50" type="all" appearance="size" /> 
  ##else## <animation enabled="no" />
  ##endif##
   <values 
   ##if @TABLE.bChartValues## show='yes' ##else## show='no' ##endif##
   decimal_places="##@TABLE.nDigits##"  y_offset="-30">
  <font type="Verdana" size="10" /> 
  </values>
  <arguments show="no" decimal_places="0" /> 
  <hints enabled="no" /> 
 <line_chart left_space="32" right_space="32" smoothing_enabled="no">
<block_names enabled="no"/>
  <lines color="0xFBAB00" size="4" auto_color="no" /> 
 <dots>
  <background auto_color="no" color="White" /> 
  <border enabled="yes" size="2" color="0xFDCF6C" /> 
  </dots>
  </line_chart>
  </chart>

  

<values decimal_places="##@TABLE.nDigits##" 
##if @TABLE.nChartType==CHART_2DCOLUMN || @TABLE.nChartType==CHART_3DCOLUMN || @TABLE.nChartType==CHART_STACKED_2D || @TABLE.nChartType==CHART_STACKED_3D##
rotation="-90" 
##else##
position="center"
##endif##
##if @TABLE.bChartValues## show='yes' ##else## show='no' ##endif##>
  <font type="verdana_embed_tf" color="0x##@TABLE.strChartValuesColor##"/> 
  </values>

 
<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 
##if @TABLE.bChartPreview##  
width="##eval @TABLE.nChartWidth-90##" 
height="##eval @TABLE.nChartHeight-130##" 
##else##
width="<?php echo $width-90;?>" 
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">
<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" /> 
  <y_axis smart="yes" />


##if @TABLE.bChartGrid##    
 <grid chart="2DColumn">
 <values start="0" >
  <lines color="0xC7C7C7" /> 
 <captions position="right">
  <font size="12" type="Verdana" /> 
  </captions>
  </values>
  </grid>


 <grid chart="2DLine">
 <arguments start="0">
 <captions>
  <font size="12" type="Verdana" /> 
  </captions>
  </arguments>
 <values  left_space="-32" right_space="-32" start="0">
  <lines color="0xC7C7C7" /> 
 <captions>
  <font size="12" type="Verdana" /> 
  </captions>
  </values>
  </grid>
##endif##  
  </workspace>
  
##if @TABLE.bChartLegend##  
    <legend enabled="yes" 
##if @TABLE.bChartPreview##  
##else##
##endif##
	x="##eval @TABLE.m_nChartWidth-180##" 
	y="15">
      <values enabled="no"/>
      <header enabled="no"/>
      <names enabled="yes" width="100"/>
      <scroller enabled="no"/>
      <border enabled="yes"/>
      <background enabled="yes"/>
	  <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);

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

##foreach @TABLE.arrChartDataSeries as @field filter @field.strDataField!=""##
$data_##@field.strDataField g##=array();
##endfor##

echo "\r\n<block chart_type=\"2DColumn\" name='##Fields[strName==@field.strDataField].strLabel hs##'>";
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 @index==1##
	echo "\r\n<set names_rotation=\"25\" value='".xmlencode($row["##@field.strDataField s##"]+0)."' name='".xmlencode($value)."' color='0x##@field.strColor##'/>";
##endif##
##endfor##

##foreach @TABLE.arrChartDataSeries as @field filter @field.strDataField!=""##
##if @index==2##	
	$data_##@field.strDataField g##[]="<set argument='".xmlencode($row["##@TABLE.strChartLabelField s##"])."' value='".xmlencode($row["##@field.strDataField s##"]+0)."' name='##@field.strDataField s##' />";
##endif##	
##endfor##

}
echo "\r\n</block>";

##foreach @TABLE.arrChartDataSeries as @field filter @field.strDataField!=""##
##if @index==2##	
echo "\r\n<block chart_type=\"2DLine\" name='##Fields[strName==@field.strDataField].strLabel hs##' color='0x##@field.strColor##' border_color='0x##@field.strColor##'>";
foreach($data_##@field.strDataField g## as $str)
{
	echo "\r\n";
	echo $str;
}
echo "\r\n</block>";
##endif##
##endfor##

		
// 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" 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" align="center" color="0x##@TABLE.strChartFooterColor##"/>
    </text>
  </objects>

</root>

