<?php
if (!defined('_SAPE_USER')){
define('_SAPE_USER', '40e09a759bfada62896caa2b0b7aa652');
}
require_once($_SERVER['DOCUMENT_ROOT'].'/'._SAPE_USER.'/sape.php');
$sape = new SAPE_client();
?>
<?php
include '../inc/config.inc.php';
include '../inc/wap_tags.inc.php';
include '../inc/functions.inc.php';
ob_start('make_page');
// ---------------------------------------------------------------
connect_to_db();
// ---------------------------------------------------------------
include "config.php";
// проверка ввода page
if (empty($_GET['p']))
$page = 1;
else
$page = dig($_GET['p']);
// проверка ввода id
if (!empty($_GET['uid'])) {
$uid = dig((int)$_GET['uid']);
// проверка существования учетной записи
$result = mysql_query("SELECT `site_name`,`link`,`admin`,`info`,`cat_id` FROM `users` WHERE `uid`=".$uid.";");
$row = mysql_fetch_array($result);
if (!empty($row)) {
$cat_id = $row[4];
// ====================== пришло
$week_day = date("w");
$today = date("Ymd");
// подсчет
$result = mysql_query("SELECT `in` FROM `weeks` WHERE `date`=".$today." AND `uid`=".$uid." LIMIT 1;");
$row = mysql_fetch_array($result);
if (empty($row)) {
$nextMonday=date("Ymd",mktime(0,0,0,date("m"),date("d")+32));
@mysql_query("INSERT INTO `weeks` VALUES ('',".$uid.",".$nextMonday.",".$today.",".$week_day.",0,0,0,0,".$cat_id.");");
$in_count = 0;
} else {
$in_count = $row['in'];
}
$in_count++;
// сохранение
@mysql_query("UPDATE `weeks` SET `in`=".$in_count.",`cat_id`=".$cat_id." WHERE `date`=".$today." AND `uid`=".$uid." LIMIT 1;");
$today = date("Ymd");
$hour = date("H");
// за сегодня
$result = mysql_query("SELECT `host` FROM `weeks` WHERE `uid`=".$uid." AND `date`=".$today." LIMIT 1;");
$row = mysql_fetch_array($result);
$host_today = $row['host'];
// ----------------------- Место в топе---------------------------
$result = mysql_query("SELECT * FROM `weeks` WHERE `host` >= ".$host_today." AND `date`=".$today." ORDER BY `host` DESC;");
$top_place = @mysql_num_rows($result);
$page = ceil($top_place / $count_top);
if ($page <= 0) $page = 1;
}
}
// прелог
include './inc/head.php';
if(empty($_GET["day"])){
$today = date("Ymd");
$doday = date("Ymd",mktime(date("H"),date("i"),date("s"),date("m"),date("d")-1,date("Y")));
}else{
$doday = date("Ymd",mktime(date("H"),date("i"),date("s"),date("m"),date("d")-2,date("Y")));
$today=date("Ymd",mktime(date("H"),date("i"),date("s"),date("m"),date("d")-1,date("Y")));}
// получаем uid участников
$cid = dig((int)$_GET['cid']);
if($cat_id == 3 && empty($_GET['cid']))$cid = 3;
if($cat_id == 4 && empty($_GET['cid']))$cid = 4;
if (($cid == "")or($cid == "0"))
{
$cat_name = "ТОП-100";
$result = mysql_query("SELECT count(`uid`) FROM `weeks` WHERE `host` > 0 AND `date`=".$today." AND `uid` != '1' AND `cat_id` != '3' AND `cat_id` != '4';"); //Изменил из-за сообщения в госте
$cntData = mysql_fetch_row($result);
$count_users = $cntData[0];
$max_page = ceil ($count_users / $count_top);
$page = ($page > $max_page) ? (($max_page == 0)? $page : $max_page) : $page;
$start = $count_top * ($page-1);
$end = $count_top;
$result = mysql_query("SELECT DISTINCT `uid`,`count`,`host`,`in`,`out` FROM `weeks` WHERE `host` > 0 AND `date`=".$today." AND `uid` != '1' AND `cat_id` != '3' AND `cat_id` != '4' ORDER BY `host` DESC LIMIT ".$start.",".$end.";"); //Изменил из-за сообщения в госте
$count_users_on_page = mysql_num_rows($result);
}
else
{
$reza = mysql_query ("SELECT * FROM `cat` WHERE `id`='" . $cid . "';");
if (mysql_affected_rows() == 0) {
} else {
$raw = mysql_fetch_array ($reza);
$cat_name = $raw["name"];
}
$result = mysql_query("SELECT count(`uid`) FROM `weeks` WHERE `host` > '0' AND `cat_id`=".$cid." AND `date`=".$today." AND `uid` != '1';");
$cntData = mysql_fetch_row($result);
$count_users = $cntData[0];
$max_page = ceil ($count_users / $count_top);
$page = ($page > $max_page) ? (($max_page == 0)? $page : $max_page) : $page;
$start = $count_top * ($page-1);
$end = $count_top;
$result = mysql_query("SELECT DISTINCT `uid`,`count`,`host`,`in`,`out` FROM `weeks` WHERE `host` > '0' AND `date`=".$today." AND `cat_id`=".$cid." ORDER BY `host` DESC LIMIT ".$start.",".$end.";");
$count_users_on_page = mysql_num_rows($result);
}
//Начало вывода сайтов
echo "<!-- Начало центра, вывода сайтов -->
<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td bgcolor=\"#9c65c3\">
<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\">
<tr>
<td bgcolor=\"#9c65c3\">
<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"4\">
<tr background=\"/xhtml/tit1.gif\">
<td rowspan=\"2\" align=\"center\" style=\"color:#ffffff\"> # </td>
<td rowspan=\"2\" style=\"color:#ffffff\" width=\"100%\" align=\"center\">Сайты из категории «".$cat_name."»</td>
<td colspan=\"3\" align=\"center\" style=\"color:#ffffff\">Посещаемость</td>
</tr>
<tr background=\"/xhtml/tit.gif\" align=\"center\">
<td style=\"color:#ffffff\">Хостов</td>
<td style=\"color:#ffffff\">Хитов</td>
<td background=\"/xhtml/tit.gif\" style=\"color:#ffffff\"> ? </td>
</tr>
<!--Дальше должен быть вывод ссылок -->\n";
if($count_users != 0){
for($i = 0;$i < $count_users_on_page;$i++) {
$row = mysql_fetch_array($result);
$uid = $row['uid'];
$hits = $row['count'];
$hosts = $row['host'];
// данные участника
$user_data = mysql_query("SELECT `site_name`,`link`,`info` FROM `users` WHERE `uid`=".$uid.";");
$user_data_row = mysql_fetch_array($user_data);
$site_name = htmlspecialchars($user_data_row['site_name']);
$link = htmlspecialchars($user_data_row['link']);
$info = htmlspecialchars($user_data_row['info']);
$link = str_replace("http://", "", $link);
$vvv = $vvv+1;
$celoe = $vvv/2;
$psps = split("\.", $celoe);
if($psps[1] == 5)
echo "<tr background=\"/xhtml/sit0.gif\">\n";
else
echo "<tr background=\"/xhtml/sit22.gif\">\n";
////
if (($cid == "")or($cid == "0")){
$result1 = mysql_query("SELECT `host` FROM `weeks` WHERE `uid`=".$uid." AND `date`=".$doday." LIMIT 1;");
$row = mysql_fetch_row($result1);
$host_today = $row[0];
$result2 = mysql_query("SELECT `uid` FROM `weeks` WHERE `host` >= ".$host_today." AND `uid` !='1' AND `date`=".$doday." ORDER BY `host` DESC;");
$top_place = @mysql_num_rows($result2);
}else{
$result1 = mysql_query("SELECT `host` FROM `weeks` WHERE `uid`=".$uid." AND `date`=".$doday." LIMIT 1;");
$row = mysql_fetch_row($result1);
$host_today = $row[0];
$result2 = mysql_query("SELECT `uid` FROM `weeks` WHERE `host` >= ".$host_today." AND `cat_id`='".$cid."' AND `uid` !='1' AND `date`=".$doday." ORDER BY `host` DESC;");
$top_place = @mysql_num_rows($result2);
}
//echo $top_place;
///////////////
print "<td style=\"color:#0359dc\">" . (($i + 1) + ($count_top * ($page-1))) . "</td>\n";
print "<td><a href=\"/html/outtop/".$uid."/\">".$link."</a><br/><span style=\"color: #7b509a\">".$info."</span></td>\n";
print "<td align=\"right\" nowrap>".$hosts."</td>\n";
print "<td align=\"right\" nowrap>".$hits."</td>\n";
if((($i + 1) + ($count_top * ($page-1))) >= $top_place)print "<td align=\"center\"><a href=\"/html/stat/".$uid."/\"><img src=\"/img/privst.gif\" alt=\"(?)\" /></a></td>\n";
if((($i + 1) + ($count_top * ($page-1))) < $top_place)print "<td align=\"center\"><a href=\"/html/stat/".$uid."/\"><img src=\"/img/pubst.gif\" alt=\"(?)\" /></a></td>\n";
print "</tr>\n";
}
}else{echo "
<!--Если категория пуста ошибку выводим -->
<tr background=\"/xhtml/sit0.gif\">
<td style=\"color:#7b509a\">#</td>
<td>Категория пока пуста :(</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
<!--Если категория пуста, ошибка окончание -->\n";}
print "
<!-- Конец вывода сайтов-->
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!--Конец вывода сайтов -->\n";
//Конец вывода сайтов
print "<table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\">\n";
print "<tr>\n";
if(empty($_GET["day"]))
print "<td align=\"right\" nowrap><span style=\"color: #7b509a\">Рейтинг: </span>за сегодня <span style=\"color: #666666\">|</span> <a href=\"/html/?day=1\">за вчера</a></td>\n";
else
print "<td align=\"right\" nowrap><span style=\"color: #7b509a\">Рейтинг: </span><a href=\"/html/\">за сегодня</a> <span style=\"color: #666666\">|</span> за вчера</td>\n";
print "</tr>\n";
print "</table>\n";
//Вывод страниц
//echo "<br />\n";
print "<span style=\"color: #666666\">Страницы: <span style=\"font-size: 14px\">\n";
for($k = 0;$k < ($max_page);$k++) {
if (($k == 0)or(($k + 1) == $max_page)or(3 >= ($page - $k))and(-3 <= ($page - $k))) {
$kira = $k + 1;
if ($k == ($page-1)) {
$otvet = "<span class=\"noscr\">".$kira."</span> | ";
} else {
if(empty($_GET["day"])) $otvet = "<a class=\"scr\" href=\"/html".$categorii[$cid]."/".$kira."/\">".$kira."</a> | ";
if(!empty($_GET["day"])) $otvet = "<a class=\"scr\" href=\"/html".$categorii[$cid]."/".$kira."/?day=1\">".$kira."</a> | ";
}
print $otvet;
}
}
print "</span> (".($start+1)."-".($start+$i)." из ".$count_users.")</span>\n";
if($_GET["cid"] == 0 OR $_GET["cid"] == '')print "<br /><br /><span style=\"color: #7b509a\">Примечание: Top100 - это суммарный рейтинг сайтов из всех рубрик, не включая сайты из рубрик «Для взрослых» и «Халява».</span>\n";
include "./inc/foot.php";
echo $sape->return_links(5);
// ---------------------------------------------------------------
// вывод буфера
ob_end_flush();
?>