<?
if (!defined('webid')) {
    exit();
}
?>
<h3 style="border-bottom: 1px dotted #cccccc; color: #1c62b9; text-shadow: 0 1px 0 #fafafa;">Каталог сайтов</h3>
<div align="center">
<?
if (isset($_GET['id'])) {    
    $kolvo = 15;
    $allnews = mysql_num_rows(mysql_query("SELECT id FROM catalog_mes where cat_id = '" . intval($_GET['id']) . "'"));
    $vsego = intval($allnews / $kolvo);
    if ($vsego == 0) $vsego = 1; $nowpage = $_GET['pg'];
    if ($nowpage == '' or $nowpage <= 0) { $nowpage = 1; } else { $nowpage = intval($_GET["pg"]); }
    if ($nowpage - 1 > $vsego) $nowpage = $vsego;
    if (!isset($_GET["pg"]) or $_GET['pg'] == '') $nowpage = 1;
    $gg = $vsego * $kolvo;
    if ($gg < $allnews) { $vsego = $vsego + 1; }
    $pages = $vsego / $kolvo;
    $pages1 = floor($pages);
    $pg1 = $kolvo * ($nowpage - 1);
    $pg2 = $kolvo;
    if ($nowpage > $vsego) { $pg1 = 0; $pg2 = $kolvo; }
    if ($pages > $pages1) {
        $pages = $pages1 + 1;
    }
    
    $sql = mysql_query("SELECT * FROM catalog_mes where cat_id = '" . intval($_GET['id']) . "' ORDER BY id DESC limit $pg1,$pg2");
    echo "<table width='100%' style='margin-bottom: 5px;'><tr><td nowrap='nowrap'>";
    $nextp = $nowpage + 1;
    $lastp = $nowpage - 1;
    if ($nowpage != 1) { echo "<a href='/referals/pg=$lastp' class=\"link\"><span class='text14'>"; } else { echo "<span class='textgray'>"; } echo "&larr;&nbsp;Предыдущие</span>";
    if ($nowpage == 1) { echo "</a>"; } echo "</td><td width='90%' align='center'>Страница $nowpage из $vsego</td><td nowrap='nowrap'>";
    if ($nowpage == $vsego) { echo "<span class='textgray'>"; } else { echo "<a href='/referals/pg=$nextp' class=\"link\"><span class='text14'>"; } echo "Следующие&nbsp;&rarr;</span>"; 
    if ($nowpage == $vsego) { echo "</a>"; } echo "</td></tr></table>";
    
    if (mysql_num_rows($sql) < 1) {
        echo '<div style="margin:5px; color:#800000" align="center">Каталог не существует</div>';
    } else {
        while ($row = mysql_fetch_array($sql)) {
            $url = str_replace('http://', '', $row['url']);
            $url = str_replace('www.', '', $url);
            ?>
            <script type="text/javascript">
            $(document).ready(function(){
                $.post('catalog/seo.php?url=PR',{
                    url: '<?=$url?>'
                }, function(data) {
                    $('.cat_pr<?=$row['id']?>').html(data);
                });
                
                $.post('catalog/seo.php?url=TIC',{
                    url: '<?=$url?>'
                }, function(data) {
                    $('.cat_tic<?=$row['id']?>').html(data);
                });
                
                $.post('catalog/seo.php?url=alexa',{
                    url: '<?=$url?>'
                }, function(data) {
                    $('.alexa<?=$row['id']?>').html(data);
                });
            })
            </script>
            <div class="viewcat"><div style="color: #EEAC03; margin-bottom: 3px; text-shadow: 0 1px 0 #fafafa; font-size: 14px;" align="left"><?=$row['description']?></div><div style="text-align: justify;"><?=$row['full_text']?></div><div style="position: relative; color: #cccccc; margin-top: 15px;" align="left"><span class="cattime"><img src="<?=ROOT?>/theme/images/time.png" width="16" height="16" /></span><span style="padding-left: 20px;"><?=date('d.m.Y', $row['data'])?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#666666">ТИЦ: <font color="#800000" class="cat_tic<?=$row['id']?>"></font>&nbsp;&nbsp;&nbsp;PR: <font color="#800000" class="cat_pr<?=$row['id']?>"></font>&nbsp;&nbsp;&nbsp;Alexa: <font color="#800000" class="alexa<?=$row['id']?>"></font></font></span><div style="position: absolute; top: 0; right: 5px; color: #212121;">&nbsp;&nbsp;&nbsp;<a href="<?=$row['url']?>" target="_blank" class="link">Перейти</a></div></div></div>
            <?
        }
    }
} else {
$cat = mysql_query("SELECT * FROM catalog");
while ($catrow = mysql_fetch_array($cat)) {
    echo '<div class="cat">';
    echo '<div style="color:#666666; text-transform:uppercase; text-shadow: 0 1px 0 #ffffff; font-weight:bold; margin-bottom:10px" align="left">' . $catrow['name'] . ' [' . $catrow['idcount'] . ']</div>';
    $cid = mysql_query("SELECT * FROM catalog_id WHERE cat = '$catrow[id]'");
    while ($cidrow = mysql_fetch_array($cid)) {
        echo '<div align="left"><a href="/cat/' . $cidrow['id'] . '" class="link">' . $cidrow['name'] . ' [' . $cidrow['idcount'] . ']</a></div>';
    }
    echo '</div>';
}
?>
</div>
<? } ?>