<?php
$template_vars['header'] = array(
'TITLE' => $lang['STAT'],
'CSS' => $css
);
$template->set_vars('header', $template_vars['header']);
if( !$sql->query("SELECT COUNT(*) FROM `" . CATALOGUE_SITES . "`;") )
{
put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}
$total_sites = $sql->result($sql->result, 0);
if( !$sql->query("SELECT COUNT(*) FROM `" . CATALOGUE_SITES . "` WHERE `checked` = 1 AND `owner` = 'user' AND `in_today_all` > 0;") )
{
put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}
$active_sites = $sql->result($sql->result, 0);
if( !$sql->query("SELECT COUNT(*) FROM `" . CATALOGUE_SITES . "` WHERE `checked` = 0;") )
{
put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}
$unchecked_sites = $sql->result($sql->result, 0);
if( !$sql->query("SELECT SUM(`in_today_all`) AS `in`, SUM(`in_today_mp`) AS `in_mp`, SUM(`in`) AS `total_in`, SUM(`out_today`) AS `out`, SUM(`out`) AS `total_out` FROM `" . CATALOGUE_SITES . "`;") )
{
put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}
$stat = $sql->fetch_assoc();
$template_vars['body'] = array(
'SITES' => $lang['SITES'],
'SITES_QUANTITY' => $total_sites,
'ACTIVE_SITES_HREF' => gen_uri('top'),
'ACTIVE_SITES' => $lang['ACTIVE_SITES'],
'ACTIVE_SITES_QUANTITY' => $active_sites,
'UNCHECKED_SITES_HREF' => gen_uri('unchecked'),
'UNCHECKED_SITES' => $lang['UNCHECKED'],
'UNCHECKED_SITES_QUANTITY' => $unchecked_sites,
'TOTAL' => $lang['TOTAL'],
'IN_LANG' => $lang['IN'],
'IN' => $stat['total_in'],
'OUT_LANG' => $lang['OUT'],
'OUT' => $stat['total_out'],
'TODAY' => $lang['TODAY'],
'IN_TODAY' => $stat['in'],
'OUT_TODAY' => $stat['out'],
'STAT_DAY_HREF' => gen_uri('stat_day'),
'STAT_DAY' => $lang['STAT_DAY'],
'BACK_HREF' => gen_uri('index'),
'BACK' => $lang['BACK']
);
$percent = $stat['in'] ? ($stat['in_mp'] * 100) / $stat['in'] : NULL;
if( $percent )
{
$query =
"SELECT `" . CATALOGUE_COUNTRIES . "`.*, `provider`.`name` AS `provider_name`, `provider`.`clicks` FROM `" . CATALOGUE_COUNTRIES . "`
JOIN (
SELECT `" . CATALOGUE_PROVIDERS . "`.*, COUNT(`" . CATALOGUE_CLICKS . "`.`id`) AS `clicks` FROM `" . CATALOGUE_PROVIDERS . "`
JOIN `" . CATALOGUE_CLICKS . "` ON `" . CATALOGUE_CLICKS . "`.`provider_id` = `" . CATALOGUE_PROVIDERS . "`.`provider_id`
GROUP BY `" . CATALOGUE_PROVIDERS . "`.`provider_id`
) AS `provider` ON `provider`.`country_id` = `" . CATALOGUE_COUNTRIES . "`.`country_id`
ORDER BY `" . CATALOGUE_COUNTRIES . "`.`country_id` ASC";
if( !$sql->query($query) )
{
put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}
$mp_id = 0;
$template->set_block_vars('body', 'mobile_traffic', array(
'LANG' => $lang['MOBILE_TRAFFIC'],
'PERCENT' => sprintf('%.02f', $percent),
'OTHER' => $lang['OTHER'],
'OTHER_CLICKS' => ($stat['in'] - $stat['in_mp']),
'OTHER_PERCENT' => sprintf('%.02f', 100 - $percent)
));
while( $stat_data = $sql->fetch_assoc() )
{
if( $mp_id != $stat_data['country_id'] )
{
$mp_id = $stat_data['country_id'];
$country_name = "<b>" . output($stat_data['name']) . "</b><br />\r\n";
}
else
{
$country_name = '';
}
$template->set_block_vars('body', 'provider',
array(
'NAME' => output($stat_data['provider_name']),
'CLICKS' => $stat_data['clicks'],
'PERCENT' => sprintf('%.02f', ($stat_data['clicks'] * 100) / $stat['in']),
'COUNTRY_NAME' => $country_name
));
}
}
$template_vars['footer'] = array(
'SWITCH_VERSION' => switch_version($m, '', ''),
'COUNTER' => ''
);
$template->set_vars('body', $template_vars['body']);
$template->set_vars('footer', $template_vars['footer']);
?>