<?php
include_once "../../../../tools/inc.php";
$page = include("../../../common.php");
$table_stat='stat'.$config["table_prefix"];
$n_id=intval($n_id);

$rate_source_list=array(
	'click'		=> '{rs:STATISTICS_RATE_SOURCE_CLICK_THROUGH}',
);

$rate_view_list=array(
	'column'		=> '{rs:STATISTICS_RATE_VIEW_COLUMN}',
	'pie'			=> '{rs:STATISTICS_RATE_VIEW_PIE}',
);
$rate_source=(isset($rate_source_list[$rate_source]) ? $rate_source : 'click');
$rate_view=(isset($rate_view_list[$rate_view]) ? $rate_view : 'pie');

$page=new Template('templates/statistics/charts/'.$rate_view.'/index.tpl');
$page->dictionary("common/dict.ru");
$page->assign(array(
	'Title'	=> $rate_source_list[$rate_source],
));
$sql=array();
$sql['click']=	"select count from $table_stat where code='NEWSLETTER[{$n_id}].CLICK.ALL.UNIQUE'";
$sql['all']=	"select count from $table_stat where code='NEWSLETTER[{$n_id}].SEND.ALL'";
$percent=($db->count($sql['click'], true)/$db->count($sql['all'], true))*100;
$percent=round($percent, ($percent<1 ? 2 : 0));
$legend['click']=array(
	'title'	=> '{rs:LEGEND_CLICK_THROUGHS}',
	'color'	=> '8080FF',
	'value'	=>  $percent,
);
$legend['unclick']=array(
	'title'	=> '{rs:LEGEND_UNCLICK_THROUGHS}',
	'color'	=> 'FF8A00',
	'value'	=> 100-$percent,
);
foreach ($legend as $key => $val) $page->addrow('DATA', array(
	'id'	=> $key,
	'color'	=> $val['color'],
	'title'	=> $val['title'],
	'value'	=> $val['value'],
));
$db->close();
header('Content-Type: text/xml');
print $page->evaluate(false);
?>