Файл: o5on.ru/xhtml/stat.php
Строк: 553
<?php
include '../inc/config.inc.php';
include '../inc/wap_tags.inc.php';
include '../inc/functions.inc.php';
connect_to_db();
include "config.php";
// ------------------------------ вывод статистики пользователя ---------------------
// проверка ввода id
if (empty($_GET['uid'])) exit;
$uid = dig((int)$_GET['uid']);
// проверка существования учетной записи
$result = mysql_query("SELECT `site_name`,`link`,`admin`,`info` FROM `users` WHERE `uid`=".$uid.";");
$row = mysql_fetch_array($result);
if (empty($row)) {header("Location: /"); exit;}
// проверка ввода action
if (empty($_GET['act'])) $act = "";
else $act = $_GET['act'];
$site_name = htmlspecialchars($row['site_name']);
$link = $row['link'];
$admin = htmlspecialchars($row['admin']);
$info = htmlspecialchars($row['info']);
$week_day = date("w");
$today = date("Ymd");
$downtoday = mktime(0, 0, 0, date("Y") , date("m"), date("d")-1);
// за сегодня
$result = mysql_query("SELECT `host` FROM `weeks` WHERE `uid`=".$uid." AND `date`=".$today." LIMIT 1;");
$row = mysql_fetch_array($result);
$host_today = $row['host'];
$act = latin($act);
include './inc/head.php';
switch ($act) {
case 'operators':
echo "<div class="rg"><a href="/xhtml/outtop/" . $uid . "/">" . str_replace("http://", "", $link) . "</a> - операторы<br />n";
print "<table width="100%" border="0" cellspacing="1" cellpadding="2">n";
print "<tr background="/xhtml/tit.gif" align="center">n";
print " <td style="color: #ffffff" width="50%"> <b>Страна</b> </td>n";
print " <td style="color: #ffffff" width="50%"> <b>Доля, %</b> </td>n";
print "</tr>n";
$result = mysql_query("
SELECT `top_operators`.`name`, `top_operators`.`label`, `top_operators_stat`.`count`
FROM `top_operators_stat`
LEFT JOIN `top_operators`
ON `top_operators`.`id` = `top_operators_stat`.`id_operator`
WHERE `date` = ".$today." AND `day_week` = ".$week_day." AND `uid` = ".$uid."
ORDER BY `top_operators_stat`.`count` DESC
");
$oper_array = array();
$summ = 0;
if (mysql_num_rows($result)) {
while ($row = mysql_fetch_assoc($result)) {
$oper_array[] = $row;
$summ += $row['count'];
// echo ((empty($row['name']))? 'Прочие' : $row['name']).': '.$row['count'].'<br/>';
}
}
//echo "<b>Статистика по операторам:</b> <br/>n";
foreach ($oper_array AS $position => $row) {
$vvv = $vvv+1;
$celoe = $vvv/2;
$psps = split(".", $celoe);
if($psps[1] == 5){
echo "<tr background="/xhtml/site.gif">n";
}else{
echo "<tr background="/xhtml/sit.gif">n";
}
echo ((empty($row['name']))? '<td>Другие</td>' : "<td>".$row['name']."</td>").' <td>'.(round($row['count']/$summ*10000)/100).'%</td>';
print "</tr>n";
}
print "</table>n";
print "</div>n";
// echo "<a href='stat.php?act=telinfo&uid=$uid'>Статистика по маркам телефонов</a> <br/>n";
break;
case "telinfo":
$tel = array("Siemens",
"Nokia",
"Samsung",
"Motorola",
"LG",
"Sagem",
"SonyEricsson",
"Alcatel",
"Sharp",
"Pantech",
"Panasonic",
"Другие"
);
// подсчет когад браузер не отределен
$result = mysql_query("SELECT `Siemens`,`Nokia`,`Samsung`,`Motorola`,`LG`,`Sagem`,`SonyEricsson`,`Alcatel`,`Sharp`,`Pantech`,`Panasonic`,`Other` FROM `weeks` WHERE `date`=$today AND `day_week`=$week_day AND `uid`=$uid LIMIT 1");
$tel_data = mysql_fetch_row($result);
if (empty($tel_data)) $tel_data = array (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
$hour = date("H");
echo "<div class="body"><a href="/xhtml/outtop/" . $uid . "/">" . str_replace("http://", "", $link) . "</a> - модели<br />n";
print "<table width="100%" border="0" cellspacing="1" cellpadding="2">n";
print "<tr background="/xhtml/tit.gif" align="center">n";
print " <td style="color: #ffffff" width="50%"> <b>Модель</b> </td>n";
print " <td style="color: #ffffff" width="50%"> <b>Хитов</b> </td>n";
print "</tr>n";
foreach ($tel_data as $index => $value) {
$vvv = $vvv+1;
$celoe = $vvv/2;
$psps = split(".", $celoe);
if($psps[1] == 5){
echo "<tr background="/xhtml/site.gif">n";
}else{
echo "<tr background="/xhtml/sit.gif">n";
}
echo "<td>".$tel[$index] . "</td><td>".$value."</td>n";
print "</tr>n";
}
print "</table>n";
print "</div>n";
break;
// По дням
case "day":
echo "<div class="body"><a href="/xhtml/outtop/" . $uid . "/">" . str_replace("http://", "", $link) . "</a> - по дням<br />n";
print "<table width="100%" border="0" cellspacing="1" cellpadding="2">n";
print "<tr background="/xhtml/tit.gif" align="center">n";
print " <td width="30%" style="color:#ffffff"><b>Дата</b></td>n";
print " <td width="30%" style="color:#ffffff"><b>Хосты</b></td>n";
print " <td width="30%" style="color:#ffffff"><b>Хиты</b></td>n";
print "</tr>n";
$result = mysql_query("SELECT * FROM `weeks` where `uid`='".$uid."' ORDER BY `id` DESC LIMIT 30;");
$stat1 = array();
$stat2 = array();
$stat3 = array();
while(false!==$fetch=mysql_fetch_array($result)){
$stat1[(int)$fetch['date']] = $fetch['host'];
$stat2[(int)$fetch['date']] = $fetch['count'];
$stat3[(int)$fetch['date']] = $fetch['date'];
}
//print $stat3;
for($i=0; $i < 30; $i++){
$vvv = $vvv+1;
$celoe = $vvv/2;
$psps = split(".", $celoe);
if($psps[1] == 5){
echo "<tr background="/xhtml/site.gif">n";
}else{
echo "<tr background="/xhtml/sit.gif">n";
}
$er = date("Ymd",mktime(date("H"),date("i"),date("s"),date("m"),date("d")-$i,date("Y")));
$err = date("Y.m.d",mktime(date("H"),date("i"),date("s"),date("m"),date("d")-$i,date("Y")));
if(!empty($stat3[$er])){
$stat3[$er] = str_replace(date("Y"),date("Y").".",$stat3[$er]);
$stat3[$er] = str_replace(".".date("m"),".".date("m").".",$stat3[$er]);
}
echo "<td>".(isset($stat3[$er])?$stat3[$er]:$err)."</td>n";
echo "<td>".(isset($stat1[$er])?$stat1[$er]:'-')."</td>n";
echo "<td>".(isset($stat2[$er])?$stat2[$er]:'-')."</td>n";
$host_al = $host_al + (int)$stat1[$er];
$count_al = $count_al + (int)$stat2[$er];
echo "</tr>n";
}
echo "<tr background="/xhtml/tit.gif"><td style="color:#ffffff">Всего:</td><td style="color:#ffffff">".$host_al."</td><td style="color:#ffffff">".$count_al."</td></tr> n";
$hour_24 = split(".", ($host_al/$vvv));
$count_24 = split(".", ($count_al/$vvv));
echo "<tr background="/xhtml/tit.gif"><td style="color:#ffffff">В среднем за день:</td><td style="color:#ffffff">".$hour_24[0]."</td><td style="color:#ffffff">".$count_24[0]."</td></tr> n";
//print "<tr background="/xhtml/tit.gif"><td style="color: #ffffff"><b>Cредн. (" . $ddd . " дней)</b></td><td style="color: #ffffff"><b>" . $alh . "</b></td><td style="color: #ffffff"><b>" . $alc . "</b></td></tr>n";
print "</table>n";
print "</div>n";
break;
// По часам
case "hour":
print "<div class="body">n";
echo "<a href="/xhtml/outtop/" . $uid . "/">".str_replace("http://", "", $link)."</a> - по часам ".date("d.m.Y")."n";
print "<table width="100%" border="0" cellspacing="1" cellpadding="2">n";
print "<tr background="/xhtml/tit.gif" align="center">n";
print " <td style="color:#ffffff" width="30%"><b>Часы</b></td>n";
print " <td style="color:#ffffff" width="30%"><b>Хосты</b></td>n";
print " <td style="color:#ffffff" width="30%"><b>Хиты</b></td>n";
print "</tr>n";
//echo "Часы | Хосты | Хиты<br/>";
$result = mysql_query("SELECT * FROM `count_24` where `uid`=".$uid." and `date`=".$today." ORDER BY `id` DESC;");
$stat1 = array();
$stat2 = array();
while(false!==$fetch=mysql_fetch_array($result)){
$stat1[(int)$fetch['hour']] = $fetch['host'];
$stat2[(int)$fetch['hour']] = $fetch['count'];
}
for($i=0; $i < 24; $i++){
$vvv = $vvv+1;
$celoe = $vvv/2;
$psps = split(".", $celoe);
if($psps[1] == 5){
echo "<tr background="/xhtml/site.gif">n";
}else{
echo "<tr background="/xhtml/sit.gif">n";
}
echo "<td>".$i.":00 - ".($i<23?$i+1:0).":00 </td>n";
if($stat1[$i] != ''){
echo "<td>".$stat1[$i]."</td>n";
}else{
echo "<td> - </td>n";
}
if($stat2[$i] != ''){
echo "<td>".$stat2[$i]."</td>n";
}else{
echo "<td> - </td>n";
}
echo "</tr>n";
$host_al = $host_al + (int)$stat1[$i];
$count_al = $count_al + (int)$stat2[$i];
//$dddd = $dddd+1;
}
echo "<tr background="/xhtml/tit.gif"><td style="color:#ffffff">Всего:</td><td style="color:#ffffff">".(int)$host_al."</td><td style="color:#ffffff">".(int)$count_al."</td></tr> n";
$hour_24 = split(".", ($host_al/$vvv));
$count_24 = split(".", ($count_al/$vvv));
echo "<tr background="/xhtml/tit.gif"><td style="color:#ffffff">В среднем за час:</td><td style="color:#ffffff">".(int)$hour_24[0]."</td><td style="color:#ffffff">".(int)$count_24[0]."</td></tr> n";
echo "</table>n</div>n";
break;
default:
// ======================== Статистика участника ======================
$hour = date("H");
$downtoday = date("Ymd", time()-86400);
// за сегодня
$result = mysql_query("SELECT `count`,`host` FROM `weeks` WHERE `uid`=".$uid." AND `date`=".$today." LIMIT 1;");
$row = mysql_fetch_array($result);
$count_today = (int)$row['count'];
$host_today = (int)$row['host'];
// за вчера
$result = mysql_query("SELECT `count`,`host` FROM `weeks` WHERE `uid`=".$uid." AND `date`=".$downtoday." LIMIT 1;");
$row = mysql_fetch_array($result);
$count_downtoday = (int)$row['count'];
$host_downtoday = (int)$row['host'];
// за 24 часа
$result = mysql_query("SELECT sum(`count`),sum(`host`) FROM `count_24` WHERE ((`date`=".$today."-1 AND `hour`>".$hour.") OR (`date`=".$today." AND `hour`<=".$hour.")) AND `uid`=".$uid.";");
$row = mysql_fetch_row($result);
$count_24 = (int)$row[0];
$host_24 = (int)$row[1];
// данные за текущий час
$result = mysql_query("SELECT `count`,`host` FROM `count_24` WHERE `hour`=".$hour." AND `date`=".$today." AND `uid`=".$uid.";");
$row = mysql_fetch_row($result);
// поверка наличия записи в базе
if (empty($row)) {
$hour_count = 0;
$hour_host = 0;
} else {
$hour_count = (int)$row[0];
$hour_host = (int)$row[1];
}
// ---------------------------- посещения за месяц --------------------
$months = array("Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь");
$today = date("Ym");
$index_month = date("m")-1;
// данные за текущий месяц
$result = mysql_query("SELECT `count`,`host` FROM `months` WHERE `date`=".$today." AND `uid`=".$uid.";");
$row = mysql_fetch_row($result);
// поверка наличия записи в базе
if (empty($row[0])) {
$this_month_count = 0;
$this_month_host = 0;
} else {
$this_month_count = (int)$row[0];
$this_month_host = (int)$row[1];
}
// -------------------------- недельная статистика----------------
$week_day = date("w");
$day7 = date("Ymd", (time()-604800));
//$today = date("Ymd");
// посещений за неделю
$result = mysql_query("SELECT sum(`count`),sum(`host`) FROM `weeks` WHERE `date`>" . $day7 . " AND `uid`=".$uid.";");
$row = mysql_fetch_row($result);
$total_week_count = (int)$row[0];
$total_week_host = (int)$row[1];
// -----------------------Всего---------------------------
$result = mysql_query("SELECT sum(`count`),sum(`host`) FROM `months` WHERE `uid`=".$uid.";");
$row = mysql_fetch_row($result);
$all_hits = (int)$row[0];
$all_hosts = (int)$row[1];
// -----------------------Пришло Ушло сегодня---------------------------
$week_day = date("w");
$today = date("Ymd");
$counts_in_out = mysql_query("SELECT `in`,`out` FROM `weeks` WHERE `date`=" . $today . " AND `day_week`=" . $week_day . " AND `uid`=" . $uid . " LIMIT 1;");
$count_row = mysql_fetch_array($counts_in_out);
$in_count = (int)$count_row['in'];
$out_count = (int)$count_row['out'];
// -----------------------Пришло Ушло вчера---------------------------
$counts_in_out_downtoday = mysql_query("SELECT `in`,`out` FROM `weeks` WHERE `date`=" . $downtoday . " AND `uid`=" . $uid . " LIMIT 1;");
$count_row_downtoday = mysql_fetch_array($counts_in_out_downtoday);
$in_count_downtoday = (int)$count_row_downtoday['in'];
$out_count_downtoday = (int)$count_row_downtoday['out'];
// -----------------------Пришло Ушло за 7 дней---------------------------
$day7 = date("Ymd", (time()-604800));
$counts_in_out_day7 = mysql_query("SELECT `in`,`out` FROM `weeks` WHERE `date`>" . $day7 . " AND `uid`=" . $uid . ";");
while ($count_row_day7 = mysql_fetch_array($counts_in_out_day7)) {
$total_week_count_in = $total_week_count_in + ((int)$count_row_day7['in']);
$total_week_host_out = $total_week_host_out + ((int)$count_row_day7['out']);
}
echo "<div class="body">n";
print "<a href="/xhtml/outtop/" . $uid . "/">" . str_replace("http://", "", $link) . "</a> - Статистика<br />n";
print "<table width="100%" border="0" cellspacing="1" cellpadding="2">n";
print "<tr background="/xhtml/tit.gif">n";
print "<td colspan="2">Сегодня</td>n";
print "</tr>n";
print " <tr>n";
print " <td width="50%">Хосты</td>n";
print " <td width="50%">" . $host_today . "</td>n";
print " </tr>n";
print " <tr background="/xhtml/site.gif">n";
print " <td>Хиты</td>n";
print " <td>" . $count_today . "</td>n";
print " </tr>n";
print " <tr>n";
print " <td>в топ / из топа</td>n";
print " <td>" . $in_count . " / " . (($out_count*2)+$in_count) . "</td>n";
print " </tr>n";
print "<tr background="/xhtml/tit.gif">n";
print " <td colspan="2">Вчера</td>n";
print " </tr>n";
print " <tr>n";
print " <td>Хосты</td>n";
print " <td>" . $host_downtoday . "</td>n";
print " </tr>n";
print " <tr background="/xhtml/site.gif">n";
print " <td>Хиты</td>n";
print " <td>" . $count_downtoday . "</td>n";
print " </tr>n";
print " <tr>n";
print " <td>В топ / из топа</td>n";
print " <td>" . $in_count_downtoday . " / " . (($out_count_downtoday*2)+$in_count_downtoday) . "</td>n";
print " </tr>n";
print " <tr background="/xhtml/tit.gif">n";
print " <td colspan="2">За 7 дней</td>n";
print " </tr>n";
print " <tr>n";
print " <td>Хосты</td>n";
print " <td>" . $total_week_host . "</td>n";
print " </tr>n";
print " <tr background="/xhtml/site.gif">n";
print " <td>Хиты</td>n";
print " <td>" . $total_week_count . "</td>n";
print " </tr>n";
print " <tr>n";
print " <td>В топ / из топа</td>n";
print " <td>" . $total_week_count_in . " / " . (($total_week_host_out*2)+$total_week_count_in) . "</td>n";
print " </tr>n";
print "n";
print " <tr background="/xhtml/tit.gif">n";
print " <td colspan="2">За текущий месяц</td>n";
print " </tr>n";
print " <tr>n";
print " <td>Хосты</td>n";
print " <td>" . $this_month_host . "</td>n";
print " </tr>n";
print " <tr background="/xhtml/site.gif">n";
print " <td>Хиты</td>n";
print " <td>" . $this_month_count . "</td>n";
print " </tr>n";
print " <tr>n";
print " <td>В топ / из топа</td>n";
print " <td>- / -</td>n";
print " </tr>n";
print " <tr background="/xhtml/tit.gif">n";
print " <td colspan="2">Всего</td>n";
print " </tr>n";
print " <tr>n";
print " <td>Хосты</td>n";
print " <td>" . $all_hosts . "</td>n";
print " </tr>n";
print " <tr background="/xhtml/site.gif">n";
print " <td>Хиты</td>n";
print " <td>" . $all_hits . "</td>n";
print " </tr>n";
print " <tr>n";
print " <td>В топ / из топа</td>n";
print " <td>- / -</td>n";
print " </tr>n";
print "</table>n";
print "</div>n";
}
// общая навигация
print "<div class="downban">n";
print "Статистика: n";
if ($_GET["act"] == "") {
echo "общая n";
} else {
echo "<a href='/xhtml/stat/" . $uid . "/'>общая</a> n";
}
if ($_GET["act"] == "day") {
echo "по дням n";
} else {
echo "<a href='/xhtml/stat/" . $uid . "/day/'>по дням</a> n";
}
if ($_GET["act"] == "hour") {
echo "по часам n";
} else {
echo "<a href='/xhtml/stat/" . $uid . "/hour/'>по часам</a> n";
}
if ($_GET["act"] == "operators") {
echo "операторы n";
} else {
echo "<a href='/xhtml/stat/" . $uid . "/operators/'>операторы</a> n";
}
if ($_GET["act"] == "telinfo") {
echo "модели <br />n";
} else {
echo "<a href='/xhtml/stat/" . $uid . "/telinfo/'>модели</a> <br/>n";
}
print "</div>n";
include "./inc/foot.php";
// ---------------------------------------------------------------
// вывод буфера
ob_end_flush();
?>