<?php
 
defined('_IN_JOHNCMS') or die('Error: restricted access');

$obj = new Hashtags(0);

if (isset($_GET['tag'])) {
    $tag = urldecode($_GET['tag']);
    if ($obj->get_all_tag_stats($tag)) {
        $total = sizeof($obj->get_all_tag_stats($tag));                                                                       
        $page = $page >= ceil($total / $kmess) ? ceil($total / $kmess) : $page;
        $start = $page == 1 ? 0 : ($page - 1) * $kmess;    

echo ' <div class="menu"><a href="/"><img src="/ico/home.png"></a> &raquo; <a href="/library/i.php">Qiziqarli va Foydali</a></div>';

        echo '<div class="phdr">Manba bo\'yicha</div>';
                    echo '<div class="menu">';
        
        foreach (new LimitIterator(new ArrayIterator($obj->get_all_tag_stats($tag)), $start, $kmess) as $txt) {
            $row = mysql_fetch_assoc(mysql_query("SELECT `id`, `name`, `time`, `uploader`, `uploader_id`, `count_views`, `count_comments`, `comments` FROM `library_texts` WHERE `id` = " . $txt));
            $obj = new Hashtags($row['id']);
echo '<center>' . ($obj->get_all_stat_tags() ? Manba: ' . $obj->get_all_stat_tags(1) . ' ' : '') . '</center>';
            echo '<a href="index.php?id=' . $row['id'] . '"><img src="/ico/forum.png"> ' . functions::checkout($row['name']) . '</a><hr>';
        }
        
        echo '</div>';
        
        if ($total > $kmess) {
            echo '<div class="menu"><center>' . functions::display_pagination('?act=tags&amp;tag=' . urlencode($tag) . '&amp;', $start, $total, $kmess) . '</center></div>';            
        }
        echo '<p><a href="?">' . $lng_lib['to_library'] . '</a></p>';
    }
} else {
    redir404();
}