Просмотр файла info.php

Размер файла: 5.59Kb
<?php
include 'verh.php';

//Существует ли такой сайт в базе
$id=intval($_GET['id']);
$sql=mysql_query('SELECT name,url FROM inet_sites WHERE id='.$id.' LIMIT 1');
if(mysql_num_rows($sql)==0)
{
 exit;
}
else
{
 $name=mysql_result($sql,0,'name');
 $url=mysql_result($sql,0,'url');
}

echo 'Статистика по сайту:<br />';
echo "<a href=\"$workdir/out.php?id=$id\">$name</a><br />";
echo "</div><div class=\"b\">";
echo '<b>По дням</b>: <br />';
echo (@$_GET['date']!='week' && @$_GET['date']!='month')?
'За 2 дня':'<a href="info.php?id='.$id.'&amp;date=1&amp;stat='.@$_GET['stat'].'">За 2 дня</a>';
echo ' | ';
echo (@$_GET['date']=='week')?
'За 7 дней':'<a href="info.php?id='.$id.'&amp;date=week&amp;stat='.@$_GET['stat'].'">За 7 дней</a>';
echo ' | ';
echo (@$_GET['date']=='month')?
'За 30 дней':'<a href="info.php?id='.$id.'&amp;date=month&amp;stat='.@$_GET['stat'].'">За 30 дней</a>';
echo '<br />';
echo "</div><div class=\"b\">";
echo '<b>Тип</b>:<br />';
echo (@$_GET['stat']!='mobil' && @$_GET['stat']!='operator')?
'Обшая':'<a href="info.php?id='.$id.'&amp;date='.@$_GET['date'].'&amp;stat=1">Общая</a>';
echo ' | ';
echo (@$_GET['stat']=='mobil')?
'По мобилам':'<a href="info.php?id='.$id.'&amp;date='.@$_GET['date'].'&amp;stat=mobil">По мобилам</a>';
echo ' | ';
echo (@$_GET['stat']=='operator')?
'По операторам':'<a href="info.php?id='.$id.'&amp;date='.@$_GET['date'].'&amp;stat=operator">По операторам</a>';

echo "</div><div class=\"b\">";
//Обработка дней
if(@$_GET['date']=='week')
 $date=7;
elseif(@$_GET['date']=='month')
 $date=30;
else
 $date=2;
//Статистика по категориям
if(@$_GET['stat']=='mobil')
{
 $sql=mysql_query('SELECT name,
(SELECT COUNT(*) FROM inet_in b WHERE b.mobil=a.id AND id_site='.$id.'  AND TO_DAYS(NOW()) - TO_DAYS(b.date) <'.$date.') AS `in`,
(SELECT COUNT(*) FROM inet_out c WHERE c.mobil=a.id AND id_site='.$id.'  AND TO_DAYS(NOW()) - TO_DAYS(c.date) <'.$date.') AS `out`
FROM inet_mobil a WHERE (SELECT COUNT(*) FROM inet_in b WHERE b.mobil=a.id AND id_site='.$id.'  AND TO_DAYS(NOW()) - TO_DAYS(b.date) <'.$date.')> 0 OR (SELECT COUNT(*) FROM inet_out c WHERE c.mobil=a.id AND id_site='.$id.'  AND TO_DAYS(NOW()) - TO_DAYS(c.date) <'.$date.')>0 ORDER BY `out` DESC');

  echo '<table border="1"> <tr align="center"><td>Мобилы</td><td>Ушло</td><td>Пришло</td></tr>';
  while($s=mysql_fetch_object($sql))
  {
  echo '<tr align="center"><td>'.$s->name.'</td><td>'.$s->out.'</td><td>'.$s->in.'</td></tr>';
  }
  $sql=mysql_query('SELECT
(SELECT COUNT(*) FROM inet_in b WHERE b.mobil=0 AND id_site='.$id.'  AND TO_DAYS(NOW()) - TO_DAYS(b.date) <'.$date.') AS `in`,
(SELECT COUNT(*) FROM inet_out c WHERE c.mobil=0 AND id_site='.$id.'  AND TO_DAYS(NOW()) - TO_DAYS(c.date) <'.$date.') AS `out`');
  $s=mysql_fetch_object($sql);
  echo '<tr align="center"><td>Другие</td><td>'.$s->out.'</td><td>'.$s->in.'</td></tr>';
  echo '</table>';


}
elseif(@$_GET['stat']=='operator')
{
 $sql=mysql_query('SELECT name,
(SELECT COUNT(*) FROM inet_in b WHERE b.operator=a.id AND id_site='.$id.'  AND TO_DAYS(NOW()) - TO_DAYS(b.date) <'.$date.') AS `in`,
(SELECT COUNT(*) FROM inet_out c WHERE c.operator=a.id AND id_site='.$id.'  AND TO_DAYS(NOW()) - TO_DAYS(c.date) <'.$date.') AS `out`
FROM inet_operator a WHERE (SELECT COUNT(*) FROM inet_in b WHERE b.operator=a.id AND id_site='.$id.'  AND TO_DAYS(NOW()) - TO_DAYS(b.date) <'.$date.')>0 OR (SELECT COUNT(*) FROM inet_out c WHERE c.operator=a.id AND id_site='.$id.'  AND TO_DAYS(NOW()) - TO_DAYS(c.date) <'.$date.')>0 ORDER BY `out` DESC');

  echo '<table border="1"> <tr align="center"><td>Операторы</td><td>Ушло</td><td>Пришло</td></tr>';
  while($s=mysql_fetch_object($sql))
  {
  echo '<tr align="center"><td>'.$s->name.'</td><td>'.$s->out.'</td><td>'.$s->in.'</td></tr>';
  }
  $sql=mysql_query('SELECT
(SELECT COUNT(*) FROM inet_in b WHERE b.operator=0 AND id_site='.$id.'  AND TO_DAYS(NOW()) - TO_DAYS(b.date) <'.$date.') AS `in`,
(SELECT COUNT(*) FROM inet_out c WHERE c.operator=0 AND id_site='.$id.'  AND TO_DAYS(NOW()) - TO_DAYS(c.date) <'.$date.') AS `out`');
  $s=mysql_fetch_object($sql);
  echo '<tr align="center"><td>Другие</td><td>'.$s->out.'</td><td>'.$s->in.'</td></tr>';
  echo '</table>';

}
else
{
 $sql=mysql_query('SELECT
DISTINCT DATE_FORMAT(c.date,"%d.%m") AS `date`,
(SELECT COUNT(*) FROM inet_out b WHERE b.id_site='.$id.' AND b.date=c.date) AS `out`,
(SELECT COUNT(*) FROM inet_in a WHERE a.id_site='.$id.' AND a.date=c.date) AS `in`
FROM inet_in c
WHERE TO_DAYS(NOW()) - TO_DAYS(c.date) < '.$date.' AND c.id_site='.$id.' ORDER BY c.date DESC');

 if(mysql_num_rows($sql)==0)
 {

  echo '<br/>Нет данных за этот период';
 }
 else
 {
  echo '<table border="1"> <tr align="center"><td>День</td><td>Ушло</td><td>Пришло</td></tr>';
  $sum_in=0; $sum_out=0; $sum=0;
  while($s=mysql_fetch_object($sql))
  {
  $sum++;
  $sum_in+=$s->in;
  $sum_out+=$s->out;
  echo '<tr align="center"><td>'.$s->date.'</td><td>'.$s->out.'</td><td>'.$s->in.'</td></tr>';
  }
  if($date!=2)
  {
  echo '<tr align="center"><td>Средние</td><td>'.(int)($sum_out/$sum).'</td><td>'.(int)($sum_in/$sum).'</td></tr>';
  echo '<tr align="center"><td>Всего</td><td>'.$sum_out.'</td><td>'.$sum_in.'</td></tr>';
  }
  echo '</table>';
 }


}

echo "</div><div class=\"b\">
&#187;<a href=\"index.php\">На главную</a><br/>";

include 'niz.php';
?>