<?php
# Script by seg0ro http://mobilarts.ru
# Not for sale!!!

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

$textl .= ' | Список проголосовавших';
require_once ('../incfiles/head.php');

if (!$topic){
  echo functions::display_error('Отсутствыет идентификатор темы!<br /><a href="index.php">Форум</a>');
  require_once('../incfiles/end.php');
  exit;
}

if (!$user_id){
  echo functions::display_error('Только для авторизованных!<br /><a href="index.php">Форум</a>');
  require_once('../incfiles/end.php');
  exit;
}

$tree = array('<a href="index.php">Форум</a>', '<a href="index.php?topic='.$topic.'">'.functions::checkout($topicRes['topicname']).'</a>', functions::checkout($topicRes['poll_name']));
echo '<div class="phdr">'.functions::display_menu($tree).'</div>';

$sql = $pollSet['poll_mod'] == 0 ? array('') : array(', COUNT(`forum_polled`.`user_id`) AS `count`', ' GROUP BY `forum_polled`.`user_id`');

$total = $pollSet['total_polled'];
if ($start >= $total){
  // Исправляем запрос на несуществующую страницу
  $start = max(0, $total - (($total % $kmess) == 0 ? $kmess : ($total % $kmess)));
}

if ($total){
  if ($total > $kmess)
    echo '<div class="topmenu">'.functions::display_pagination('index.php?act=polled&amp;topic='.$topic.'&amp;', $start, $total, $kmess).'</div>';
  
  $req = mysql_query("SELECT `forum_polled`.*".$sql[0].", `users`.`id`, `users`.`name`, `users`.`sex`, `users`.`rights`, `users`.`lastdate`, `users`.`status`, `users`.`datereg` FROM `forum_polled` LEFT JOIN `users` ON `forum_polled`.`user_id` = `users`.`id` WHERE `forum_polled`.`topic` = '$topic'".$sql[1]." LIMIT $start, $kmess ");
  
  while ($res = mysql_fetch_assoc($req)){
    echo $i % 2 ? '<div class="list2">' : '<div class="list1">';
    $array = array('header' => (($pollSet['poll_mod'] == 1 && $rights) ? ' ('.$res['count'].')' : ''), 'body' => '', 'sub' => '', 'iphide' => 1);
    echo functions::display_user($res, $array).'</div>';
    ++$i;
  }
  echo '<div class="phdr">Пользователей: '.$total.'</div>';
  if ($total > $kmess)
    echo '<div class="topmenu">'.functions::display_pagination('index.php?act=polled&amp;topic='.$topic.'&amp;', $start, $total, $kmess).'</div>';
}else{
  echo '<div class="list1">Пусто!</div>';
}