<?

  include_once '../../config.inc.php';
  include_once '../../lang/english.php';
  if (!($result_proper = mysql_query ('select * from properties')))
  {
    exit ('<b>Error:</b>' . mysql_error ());
    ;
  }

  $proper = mysql_fetch_array ($result_proper);
  include '../lang/' . $proper['admin_language'];
  if (!include '../autorization.php')
  {
    echo 'Access denied!';
    exit ();
  }

  $SQL = 'SELECT * FROM session';
  if (!($result = mysql_query ($SQL)))
  {
    exit ('<b>Error:</b>' . mysql_error ());
    ;
  }

  $row = mysql_fetch_array ($result);
  $midnight = $curtime[0] - date ('H', $curtime[0]) * 3600 - date ('i', $curtime[0]) * 60 - date ('s', $curtime[0]);
  $SQL = '' . 'SELECT * FROM session_detail WHERE tim>' . $midnight;
  if (!($result = mysql_query ($SQL)))
  {
    exit ('<b>Error:</b>' . mysql_error ());
    ;
  }

  $row1 = mysql_num_rows ($result);
  echo '
<HTML><BODY STYLE="color: Navy;"><LINK HREF="../style.css" REL="stylesheet" TYPE="text/css"><TABLE WIDTH="100%" BORDER=0 CELLSPACING=0 CELLPADDING=1><TR><TD style="background-color:#505090;"><TABLE WIDTH="100%" BORDER=0 CELLSPACING=0 CELLPADDING=5 BGCOLOR="#EFEFF8">
<TR><TD VALIGN=top BGCOLOR="#BFBFDF" STYLE="border-bottom: 1px solid #505090;">
<FONT COLOR="navy"><B>';
  echo $admin_Host;
  echo '</B></FONT> ';
  echo $_SERVER['HTTP_HOST'];
  echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
';
  echo $admin_Total_visits;
  echo '<font color="#800000"><b>';
  echo $row['total_hits'];
  echo '</b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
';
  echo $admin_Unique_hosts;
  echo '<font color="#800000"><b>';
  echo $row['unique_hits'];
  echo '</b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
';
  echo $admin_Today;
  echo '<font color="#800000"><b>';
  echo $row1;
  echo '</b></font>
</TD></TR><TR><TD VALIGN=top>



';
  if ($_GET['action'] == 'last50')
  {
    echo '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=3>
<TR BGCOLOR="#505090">
<td align="center"><FONT COLOR="#FFFFFF">';
    echo $admin_table8[0];
    echo '</FONT></td>
<TD align="center"><FONT COLOR="#FFFFFF">';
    echo $admin_table8[1];
    echo '</FONT></TD>
<TD align="center"><FONT COLOR="#FFFFFF">';
    echo $admin_table8[2];
    echo '</FONT></TD>
<TD align="center"><FONT COLOR="#FFFFFF">';
    echo $admin_table8[3];
    echo '</FONT></TD>
<td align="center"><FONT COLOR="#FFFFFF">';
    echo $admin_table8[4];
    echo '</FONT></td>
<td align="center"><FONT COLOR="#FFFFFF">';
    echo $admin_table8[5];
    echo '</FONT></td>
</tr>

';
    $SQL = 'SELECT * FROM session_detail ORDER BY tim DESC LIMIT 50';
    if (!($result = mysql_query ($SQL)))
    {
      exit ('<b>Error:</b>' . mysql_error ());
      ;
    }

    while ($row = mysql_fetch_array ($result))
    {
      echo '					<TR bgcolor="';
      if ($i++ % 2)
      {
        echo '#BFBFDF';
      }
      else
      {
        echo '#DCDCED';
      }

      echo '">
					<td><font color="black" style="font-size: 10px;">';
      echo $row['REMOTE_ADDR'];
      echo '</font></td>
					<td><font color="black" style="font-size: 10px;">';
      echo $row['REMOTE_HOST'];
      echo '</font></td>
					<td><font color="black" style="font-size: 10px;">';
      echo date ('d/m', $row['tim']);
      echo '</font></td>
					<td><font color="black" style="font-size: 10px;">';
      echo date ('G:i', $row['tim']);
      echo '</font></td>
					<td><a href="';
      echo $row['HTTP_REFERER'];
      echo '" target="_blank" style="color:navy; text-decoration:none; font-size: 10px;">';
      echo $row['HTTP_REFERER'];
      echo '</a></td>
					<td><a href="';
      echo $row['REQUEST_URI'];
      echo '" target="_blank" style="color:maroon; text-decoration:none; font-size: 10px;">';
      echo $row['REQUEST_URI'];
      echo '</a></td>
					</tr>
			';
    }

    echo '</TABLE>
';
  }

  echo '



';
  if ($_GET['action'] == 'lasthour')
  {
    echo '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=3>
<TR BGCOLOR="#505090">
<td align="center"><FONT COLOR="#FFFFFF">';
    echo $admin_table8[0];
    echo '</FONT></td>
<TD align="center"><FONT COLOR="#FFFFFF">';
    echo $admin_table8[1];
    echo '</FONT></TD>
<TD align="center"><FONT COLOR="#FFFFFF">';
    echo $admin_table8[2];
    echo '</FONT></TD>
<TD align="center"><FONT COLOR="#FFFFFF">';
    echo $admin_table8[3];
    echo '</FONT></TD>
<td align="center"><FONT COLOR="#FFFFFF">';
    echo $admin_table8[4];
    echo '</FONT></td>
<td align="center"><FONT COLOR="#FFFFFF">';
    echo $admin_table8[5];
    echo '</FONT></td>
</tr>

';
    $hour_start = $curtime[0] - date ('i', $curtime[0]) * 60;
    $SQL = '' . 'SELECT * FROM session_detail WHERE tim>' . $hour_start . ' ORDER BY tim DESC';
    if (!($result = mysql_query ($SQL)))
    {
      exit ('<b>Error:</b>' . mysql_error ());
      ;
    }

    while ($row = mysql_fetch_array ($result))
    {
      echo '					<TR bgcolor="';
      if ($i++ % 2)
      {
        echo '#BFBFDF';
      }
      else
      {
        echo '#DCDCED';
      }

      echo '">
					<td><font color="black" style="font-size: 10px;">';
      echo $row['REMOTE_ADDR'];
      echo '</font></td>
					<td><font color="black" style="font-size: 10px;">';
      echo $row['REMOTE_HOST'];
      echo '</font></td>
					<td><font color="black" style="font-size: 10px;">';
      echo date ('d/m', $row['tim']);
      echo '</font></td>
					<td><font color="black" style="font-size: 10px;">';
      echo date ('G:i', $row['tim']);
      echo '</font></td>
					<td><a href="';
      echo $row['HTTP_REFERER'];
      echo '" target="_blank" style="color:navy; text-decoration:none; font-size: 10px;">';
      echo $row['HTTP_REFERER'];
      echo '</a></td>
					<td><a href="';
      echo $row['REQUEST_URI'];
      echo '" target="_blank" style="color:maroon; text-decoration:none; font-size: 10px;">';
      echo $row['REQUEST_URI'];
      echo '</a></td>
					</tr>
			';
    }

    echo '</TABLE>
';
  }

  echo '




';
  if ($_GET['action'] == 'top20pages')
  {
    echo '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=3>
<TR BGCOLOR="#505090">
<td align="center"><FONT COLOR="#FFFFFF">';
    echo $admin_table8[6];
    echo '</FONT></td>
<TD align="center"><FONT COLOR="#FFFFFF">';
    echo $admin_table8[7];
    echo '</FONT></TD>
</tr>

';
    $SQL = 'SELECT REQUEST_URI, count(*) FROM session_detail GROUP BY REQUEST_URI';
    if (!($result = mysql_query ($SQL)))
    {
      exit ('<b>Error:</b>' . mysql_error ());
      ;
    }

    while ($row = mysql_fetch_row ($result))
    {
      settype ($row[1], 'integer');
      $temp[$row[0]] = $row[1];
    }

    arsort ($temp);
    $per = current ($temp);
    for ($i = 0; $i < 20; ++$i)
    {
      echo '			<TR bgcolor="';
      if ($i++ % 2)
      {
        echo '#BFBFDF';
      }
      else
      {
        echo '#DCDCED';
      }

      echo '">
			<td><a href="';
      echo key ($temp);
      echo ' " target="_blank" style="color:navy; text-decoration:none; font-size: 10px;">';
      echo key ($temp);
      echo '</a></td>
			<TD HEIGHT=15 VALIGN="bottom">&nbsp;<IMG SRC="../../inc/images/bar.gif" HEIGHT=11 WIDTH="';
      echo current ($temp) * 100 / $per;
      echo '" BORDER="0"><B>&nbsp;';
      echo current ($temp);
      echo '&nbsp;</B>Hits&nbsp;</TD>
			</tr>
		';
      next ($temp);
    }

    echo '</TABLE>
';
  }

  echo '


';
  if ($_GET['action'] == 'month')
  {
    echo '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=3>
<TR BGCOLOR="#505090">
<td align="center"><FONT COLOR="#FFFFFF">';
    echo $admin_table8[9];
    echo '</FONT></td>
<TD align="center"><FONT COLOR="#FFFFFF">';
    echo $admin_table8[7];
    echo '</FONT></TD>
</tr>
';
    for ($i = 1; $i <= date ('t', $curtime[0]); ++$i)
    {
      $SQL = 'SELECT * FROM session_detail';
      if (!($result = mysql_query ($SQL)))
      {
        exit ('<b>Error:</b>' . mysql_error ());
        ;
      }

      $total = mysql_num_rows ($result);
      echo '					<TR bgcolor="';
      if ($i % 2)
      {
        echo '#BFBFDF';
      }
      else
      {
        echo '#DCDCED';
      }

      echo '">
					<td align="right"><font color="black" style="font-size: 10px;">';
      echo $i;
      echo '</font></td>

';
      $T_start = mktime (0, 0, 0, date ('n', $curtime[0]), $i, date ('Y', $curtime[0]));
      $T_end = mktime (23, 59, 59, date ('n', $curtime[0]), $i, date ('Y', $curtime[0]));
      $SQL = '' . 'SELECT * FROM session_detail WHERE tim>' . $T_start . ' AND tim<' . $T_end;
      if (!($result = mysql_query ($SQL)))
      {
        exit ('<b>Error:</b>' . mysql_error ());
        ;
      }

      $row = mysql_num_rows ($result);
      echo '
					<TD HEIGHT=15 VALIGN="bottom">&nbsp;<IMG SRC="../../inc/images/bar.gif" HEIGHT=11 WIDTH="';
      echo $row * 200 / $total;
      echo '" BORDER="0"><B>&nbsp;';
      echo $row;
      echo '&nbsp;</B>Hits&nbsp;</TD>
					</tr>
			';
    }

    echo '
</TABLE>

';
  }

  echo '


';
  if ($_GET['action'] == 'week')
  {
    echo '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=3>
<TR BGCOLOR="#505090">
<td align="center"><FONT COLOR="#FFFFFF">';
    echo $admin_table8[8];
    echo '</FONT></td>
<TD align="center"><FONT COLOR="#FFFFFF">';
    echo $admin_table8[7];
    echo '</FONT></TD>
</tr>

';
    $SQL = 'SELECT * FROM session_detail';
    if (!($result = mysql_query ($SQL)))
    {
      exit ('<b>Error:</b>' . mysql_error ());
      ;
    }

    $total = mysql_num_rows ($result);
    $weekstart = $curtime[0] - date ('w', $curtime[0]) * 3600 * 24 - date ('H', $curtime[0]) * 3600 - date ('i', $curtime[0]) * 60 - date ('s', $curtime[0]);
    $SQL = '' . 'SELECT * FROM session_detail WHERE tim>' . $weekstart . ' AND tim<' . ($weekstart + 86400);
    if (!($result = mysql_query ($SQL)))
    {
      exit ('<b>Error:</b>' . mysql_error ());
      ;
    }

    $row = mysql_num_rows ($result);
    echo '<TR bgcolor="';
    if ($i++ % 2)
    {
      echo '#BFBFDF';
    }
    else
    {
      echo '#DCDCED';
    }

    echo '">
<td>';
    echo $day[0];
    echo '</td>
<TD HEIGHT=15 VALIGN="bottom">&nbsp;<IMG SRC="../../inc/images/bar.gif" HEIGHT=11 WIDTH="';
    echo $row * 200 / $total;
    echo '" BORDER="0"><B>&nbsp;';
    echo $row;
    echo '&nbsp;</B>Hits&nbsp;</TD>
</tr>

';
    $SQL = 'SELECT * FROM session_detail WHERE tim>' . ($weekstart + 86400) . ' AND tim<' . ($weekstart + 172800);
    if (!($result = mysql_query ($SQL)))
    {
      exit ('<b>Error:</b>' . mysql_error ());
      ;
    }

    $row = mysql_num_rows ($result);
    echo '<TR bgcolor="';
    if ($i++ % 2)
    {
      echo '#BFBFDF';
    }
    else
    {
      echo '#DCDCED';
    }

    echo '">
<td>';
    echo $day[1];
    echo '</td>
<TD HEIGHT=15 VALIGN="bottom">&nbsp;<IMG SRC="../../inc/images/bar.gif" HEIGHT=11 WIDTH="';
    echo $row * 200 / $total;
    echo '" BORDER="0"><B>&nbsp;';
    echo $row;
    echo '&nbsp;</B>Hits&nbsp;</TD>
</tr>

';
    $SQL = 'SELECT * FROM session_detail WHERE tim>' . ($weekstart + 172800) . ' AND tim<' . ($weekstart + 259200);
    if (!($result = mysql_query ($SQL)))
    {
      exit ('<b>Error:</b>' . mysql_error ());
      ;
    }

    $row = mysql_num_rows ($result);
    echo '<TR bgcolor="';
    if ($i++ % 2)
    {
      echo '#BFBFDF';
    }
    else
    {
      echo '#DCDCED';
    }

    echo '">
<td>';
    echo $day[2];
    echo '</td>
<TD HEIGHT=15 VALIGN="bottom">&nbsp;<IMG SRC="../../inc/images/bar.gif" HEIGHT=11 WIDTH="';
    echo $row * 200 / $total;
    echo '" BORDER="0"><B>&nbsp;';
    echo $row;
    echo '&nbsp;</B>Hits&nbsp;</TD>
</tr>

';
    $SQL = 'SELECT * FROM session_detail WHERE tim>' . ($weekstart + 259200) . ' AND tim<' . ($weekstart + 345600);
    if (!($result = mysql_query ($SQL)))
    {
      exit ('<b>Error:</b>' . mysql_error ());
      ;
    }

    $row = mysql_num_rows ($result);
    echo '<TR bgcolor="';
    if ($i++ % 2)
    {
      echo '#BFBFDF';
    }
    else
    {
      echo '#DCDCED';
    }

    echo '">
<td>';
    echo $day[3];
    echo '</td>
<TD HEIGHT=15 VALIGN="bottom">&nbsp;<IMG SRC="../../inc/images/bar.gif" HEIGHT=11 WIDTH="';
    echo $row * 200 / $total;
    echo '" BORDER="0"><B>&nbsp;';
    echo $row;
    echo '&nbsp;</B>Hits&nbsp;</TD>
</tr>

';
    $SQL = 'SELECT * FROM session_detail WHERE tim>' . ($weekstart + 345600) . ' AND tim<' . ($weekstart + 432000);
    if (!($result = mysql_query ($SQL)))
    {
      exit ('<b>Error:</b>' . mysql_error ());
      ;
    }

    $row = mysql_num_rows ($result);
    echo '<TR bgcolor="';
    if ($i++ % 2)
    {
      echo '#BFBFDF';
    }
    else
    {
      echo '#DCDCED';
    }

    echo '">
<td>';
    echo $day[4];
    echo '</td>
<TD HEIGHT=15 VALIGN="bottom">&nbsp;<IMG SRC="../../inc/images/bar.gif" HEIGHT=11 WIDTH="';
    echo $row * 200 / $total;
    echo '" BORDER="0"><B>&nbsp;';
    echo $row;
    echo '&nbsp;</B>Hits&nbsp;</TD>
</tr>

';
    $SQL = 'SELECT * FROM session_detail WHERE tim>' . ($weekstart + 432000) . ' AND tim<' . ($weekstart + 518400);
    if (!($result = mysql_query ($SQL)))
    {
      exit ('<b>Error:</b>' . mysql_error ());
      ;
    }

    $row = mysql_num_rows ($result);
    echo '<TR bgcolor="';
    if ($i++ % 2)
    {
      echo '#BFBFDF';
    }
    else
    {
      echo '#DCDCED';
    }

    echo '">
<td>';
    echo $day[5];
    echo '</td>
<TD HEIGHT=15 VALIGN="bottom">&nbsp;<IMG SRC="../../inc/images/bar.gif" HEIGHT=11 WIDTH="';
    echo $row * 200 / $total;
    echo '" BORDER="0"><B>&nbsp;';
    echo $row;
    echo '&nbsp;</B>Hits&nbsp;</TD>
</tr>

';
    $SQL = 'SELECT * FROM session_detail WHERE tim>' . ($weekstart + 518400) . ' AND tim<' . ($weekstart + 604800);
    if (!($result = mysql_query ($SQL)))
    {
      exit ('<b>Error:</b>' . mysql_error ());
      ;
    }

    $row = mysql_num_rows ($result);
    echo '<TR bgcolor="';
    if ($i++ % 2)
    {
      echo '#BFBFDF';
    }
    else
    {
      echo '#DCDCED';
    }

    echo '">
<td>';
    echo $day[6];
    echo '</td>
<TD HEIGHT=15 VALIGN="bottom">&nbsp;<IMG SRC="../../inc/images/bar.gif" HEIGHT=11 WIDTH="';
    echo $row * 200 / $total;
    echo '" BORDER="0"><B>&nbsp;';
    echo $row;
    echo '&nbsp;</B>Hits&nbsp;</TD>
</tr>


</TABLE>
';
  }

  echo '


</TD></TR></TABLE></TD></TR></TABLE></BODY></HTML>';
?>
