<?php

require_once dirname(__FILE__) . '/BSA_PRO_Agency_Ordering_form.php';
// require ordering form if stats
$ad_id = $_GET['bsa_pro_id'];
$model = new BSA_PRO_Model();
$statsFrom = $model->bsaIntervalStats($ad_id, 'from') != null ? $model->bsaIntervalStats($ad_id, 'from') : 0;
$countClicks = $model->bsaIntervalStats($ad_id, 'from') != null ? $model->bsaCountClicks($ad_id, $statsFrom[0]) : 0;
$countViews = $model->bsaIntervalStats($ad_id, 'from') != null ? $model->bsaCountViews($ad_id, $statsFrom[0]) : 0;
echo '
<div class="bsaStatsWrapperBg"></div>
<div class="bsaStatsWrapper" data-ad-id="' . $ad_id . '" data-days="7" data-from="' . $statsFrom[0] . '" data-time="' . time() . '">
	<div class="bsaStatsWrapperInner">
		<h2><span>' . get_option("bsa_pro_plugin_trans_stats_header") . '</span> <span class="bsaLoader bsaLoaderStats" style="display: none"></span></h2>
		<div class="bsaStatsButtons">
			<a class="bsaPrevWeek" href="#" onclick="bsaPrevStats()">' . get_option("bsa_pro_plugin_trans_stats_prev_week") . '</a>
			<a class="bsaNextWeek" href="#" onclick="bsaNextStats()">' . get_option("bsa_pro_plugin_trans_stats_next_week") . '</a>
		</div>
		<div class="bsaStatsChart">
			<div class="bsaSumStats">
				' . get_option("bsa_pro_plugin_trans_stats_clicks") . ' <strong>' . $countClicks[0] . '</strong>
			</div>
			<div class="bsaSumStats" style="margin: 0 5%">
				' . get_option("bsa_pro_plugin_trans_stats_views") . ' <strong>' . $countViews[0] . '</strong>
			</div>
			<div class="bsaSumStats">
				' . get_option("bsa_pro_plugin_trans_stats_ctr") . ' <strong>' . ($countViews[0] > 1 ? number_format($countClicks[0] / $countViews[0] * 100, 2) . " %" : " - ") . '</strong>
			</div>
			<div class="bsaChart ct-chart"></div>
		</div>';
echo '<h3 class="bsaHeaderClicks">' . get_option("bsa_pro_plugin_trans_stats_clicks") . '</h3>';