<?php

define('_IN_JOHNCMS', 1);
require_once ('../incfiles/core.php');
$textl = 'Fan-klub';
require_once ('../incfiles/head.php');

if (!$user_id) {
    echo functions::display_error('Faqat sayt a\'zolari uchun');
    require_once ('../incfiles/end.php');
    exit;
}
/*if ($rights < 9) {
echo    functions::display_error('Faqat Bosh admin uchun!');
require_once ('../incfiles/end.php');
exit;
}
*/
$req = mysql_query("SELECT * FROM `fanclub` WHERE `id`='$id'");
$res = mysql_fetch_assoc($req);
if (!$res) {
    echo functions::display_error('Ma\'lumotlar yo\'q!');
    require_once ('../incfiles/end.php');
    exit;
}


/*добавление коммa*/
if (isset($_POST['submit'])) {
    $komm = trim($_POST['komm']);
    if (!$komm) {
        echo '<div class="menu">Siz xabar kiritmadingiz!<br/><a href="titul_club.php?id=' . $id .
            '">Orqaga</a></div>';
        require_once ('../incfiles/end.php');
        exit;
    }
    if (@mysql_result(@mysql_query("SELECT COUNT(*) FROM `fanclub_komm` WHERE `user_id` = '" .
        $user_id . "' AND `komm` = '" . @mysql_escape_string($komm) . "' AND `time` > '" .
        ($time - 300) . "' LIMIT 1"), 0) != 0) {
        echo '<div class="menu">Sizning oldingi xabaringiz qaytalanyapti<br/>';
        echo '<a href="titul_club.php?id=' . $id . '">Orqaga</a></fiv>';
        require_once ('../incfiles/end.php');
        exit;
    }
    $komm = mb_substr($komm, 0, 500);
    $sql = mysql_query("INSERT INTO `fanclub_komm` SET
        `cid` = '" . $id . "',
        `time` = '" . $realtime . "',
         `user_id` = '" . $user_id . "',
        `komm` = '" . mysql_real_escape_string($komm) . "'
");
    if ($sql)
        echo '<div class="menu">Izoh qo\'shildi</div>';
}
echo '<div class="phdr" ><a href="index.php">Klublar</a></div>';
echo '<div class="menu">';

echo '<div style="text-align:center;" ><h3>' . $res['name'] . '</h3>';
if (file_exists('img/' . $id . '_small.png')) {
    echo '<img src="img/' . $id . '_small.png" align="middle" alt="' . $id . '"/>';
} else {
    echo '<a href="img.php?id=' . $id . '">Emblema yuklash</a>';
}
echo '<br/>' . $res['sport'] . '/' . $res['count'] .
    '<br/><a href="users_club.php?id=' . $id . '&amp;sort=1"><span class="green">['.$res['plus'] .']</span></a>| <a href="users_club.php?id=' . $id .
    '&amp;sort=0"><span class="red">['.$res['minus'] .']</span></a><br/><a href="case.php?act=yes&amp;id='.$id.'"><b>Men fanatman</b></a> | <a href="case.php?act=no&amp;id='.$id .'"><b>Men anti-fanatman</b></a></div>';

/*новости*/
$total = mysql_result(mysql_query("SELECT COUNT(*) FROM `news_fanclub` WHERE `cid`='" .
    $id . "' "), 0);
echo '<div class="phdr" >Yangiliklar (' . $total . ')</div>';
/*добавить новость с проверкой на старшего*/
if ($rights == 9 || $res['user'] == $user_id) {
    echo '<p><a href="create_news.php?id=' . $id .
        '"><input type="submit" class="write" value="Yangilik qo\'shish" /></a>';
}
if ($total) {
    $req = mysql_query("SELECT * FROM `news_fanclub` WHERE `cid`='" . $id .
        "' ORDER BY `time` DESC LIMIT $start, $kmess");
    while ($res = mysql_fetch_assoc($req)) {
        echo '<div>';
        echo '<span class="gray">' . date("d.m.o (H:i)", $res['time']) . '</span><br/>';
        echo '<a href="news.php?id=' . $id . '&amp;news=' . $res['id'] . '">' . $res['tema'] .
            '</a>';
        ++$i;
        echo '</div>';
    }
} else {
    echo '<div class="menu">Yangiliklar yo\'q!</div>';
}

/*стена*/

$total = mysql_result(mysql_query("SELECT COUNT(*) FROM `fanclub_komm`WHERE `cid` = '" .
    $id . "' "), 0);
echo '<div class="phdr" >Fikrlar doskasi (' . $total . ')</div>';

echo "<div class='list2'>Izoh qoldirish (max. 500):<br/><form action='titul_club.php?id=" . $id .
    "' method='post'>
<textarea name='komm'></textarea><br/>";

echo "<input type='submit' name='submit' class='write' value='Yozish' />
  </form></div><p>";

if ($total) {
    $req = mysql_query("SELECT `fanclub_komm`.`id` as `kommid`, `fanclub_komm`.*,`users`.`id`, `users`.`name`, `users`.`sex`, `users`.`lastdate` FROM `fanclub_komm` LEFT JOIN `users` ON `fanclub_komm`.`user_id`=`users`.`id` WHERE 
`fanclub_komm`.`cid`='" . $id . "'  ORDER BY `fanclub_komm`.`time` DESC LIMIT $start, $kmess");
    while ($res = mysql_fetch_assoc($req)) {
        echo $i % 2 ? '<div class="list2">' : '<div class="list1">';

        $sub = ($user_id != $res['user_id']) ? '[<a href="komm_otvet.php?id=' . $id .
            '&amp;komm_id=' . $res['kommid'] . '&amp;file_id=' . $res['file_id'] .
            '&amp;start=' . $start . '">о</a>]&nbsp;<span class="gray">' . date("d.m (H:i)",
            $res['time']) . '</span>' : '<span class="gray">' . date("d.m (H:i)", $res['time']) .
            '</span>';


                
        echo functions::display_user($res, 1, null, $sub);
        echo '<br/>' . functions::smileys($res['komm']) . '<br/>';
        if ($user_id == $res['user_id'] && $res['time'] > $realtime - 300) {
            echo '<div class="sub">';
            echo '<a href="komm_edit.php?komm_id=' . $res['kommid'] . '">o\'zgartirish</a>|';
            echo '<a href="komm_del_yes.php?id=' . $id . '&amp;komm_id=' . $res['kommid'] .
                '">o\'chirish</a>';
            echo '</div>';
        } elseif ($rights >= 7) {
            echo '<div class="sub">';
            echo '<a href="komm_del_yes_file.php?id=' . $id . '&amp;komm_id=' . $res['kommid'] .
                '">o\'chirish</a>';
            echo '</div>';
        }

        echo '</div>';
    }
    ++$i;
} else {
    echo '<div class="menu">Izohlar yo\'q!</div>';
}

        if ($total > $kmess) {
            echo '<div class="topmenu">' . functions::display_pagination('titul_club.php?id=' . $id . '&amp;', $start, $total, $kmess) . '</div>' .
                 '<p><form action="titul_club.php" method="get"><input type="text" name="page" size="2"/>' .
                 '<input type="submit" value="' . $lng['to_page'] . ' &gt;&gt;"/></form></p>';
        }


echo '</div>';
echo '<div class="phdr" ><a href="index.php">Fan klub</a></div>';

require_once ('../incfiles/end.php');

?>