<?

include_once '../system/sys.php';
include '../system/funcs.php';

if (!isset ($us['id'])) {
    
    header ('location: /');
    exit;

}

if (!isset ($_GET['id'])) {
    header ('location: /forum.php');
    exit;
}

$query = DB :: $dbs -> query ("SELECT * FROM `forum_t` WHERE (`id`=?)", array ((int) $_GET['id']));
if ($query -> rowCount ()==0) {

    header ('location: /forum.php');

    exit;

}

$t = $query -> fetch ();
    
$a = DB :: $dbs -> queryFetch ("SELECT * FROM `us` WHERE (`id`='" . $t['us'] . "')");
    
$query = DB :: $dbs -> query ("SELECT * FROM `forum_pr` WHERE (`id`='" . $t['id_pr'] . "')");
if ($query -> rowCount ()==0) {

    header ('location: /forum.php');

    exit;

}

$pr = $query -> fetch ();
    
$query = DB :: $dbs -> query ("SELECT * FROM `forum_r` WHERE (`id`='" . $t['id_r'] . "')");
if ($query -> rowCount ()==0) {

    header ('location: /forum.php');

    exit;

}

$r = $query -> fetch ();

H ($t['name'], '<a href="/forum" style="color:white;">Форум</a> | <a href="/forum/razd' . $r['id'] . '" style="color:white;">' . $r['name'].'</a> | <a href="/forum/' . $r['id'] . '/' . $pr['id'] . '" style="color:white;">' . $pr['name'] . '</a> | ' . $t['name']);

if ($t['type'] == 2) {
        echo '<div class="lst">Данная тема была удалена!</div>';
}
else {
                
                $query = DB :: $dbs -> query ("SELECT * FROM `forum_op` WHERE (`id_t`='" . $t['id'] . "')");
                if ($query -> rowCount () == 0) {
                        echo '<div class="list1">В данной теме нет опроса!</div>';
                }
                else {
                        $op = $query -> fetch ();
                        if ($op['type']==0) {
                                echo '<div class="list1">В этой теме закрытое голосование!</div>';
                        }
                        echo 'Вопрос: ' . $op['vopros'] . '<br/>';
                        $query = DB :: $dbs -> query ("SELECT * FROM `forum_op_otv` WHERE (`id_op`='" . $op['id'] . "')");
                        while ($otv = $query-> fetch () ) {
                                echo '<b>' . $otv['text'] . '</b> (' . endi (DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `forum_op_vote` WHERE (`id_otv`='" . $otv['id'] . "')"), array ('голос', 'голоса', 'голосов')) . ')<br/>';
                                $q = DB :: $dbs -> query ("SELECT * FROM `forum_op_vote` WHERE (`id_otv`='" . $otv['id'] . "')");
                                while ($vote =$q-> fetch ()) {
                                        echo uNick ($vote['us']) . ', ';
                                }
                                echo '<br/>';
                        }
                
                }
                
        
        echo '<div class="list1"><a href="/forum/thema' . $t['id'] . '">Вернуться в тему</a></div>';

}


F ();

?>