<?
require'../config.php';
$align='left';
$title='Голосование';
aut();
head();



$mesto='Голосование';
echo '<br />';




if (isset($_GET['msg']) && $_GET['msg']=='addv')
echo "<span style=\"color:$color[msg]\"><b>Голос успешно принят</b></span><br />\n";
if (isset($_GET['msg']) && $_GET['msg']=='add')
echo "<span style=\"color:$color[msg]\"><b>Голосование добавлено</b></span><br />\n";


$voice_ok='0';
$q = mysql_query("SELECT COUNT(*) FROM `$mysql[pref]voice`");
$k_voice=mysql_result($q, 0);


if ($k_voice==0)
{
echo "Голосований нет<br />\n";
if ($user['level']>=9){echo "<a href=\"add.php\">Добавить</a><br />\n";}
echo '<br />';
echo gb.'<a href="'.H.'enter">Прихожая</a><br/>'.div;
foot();
}




$page=1;
if (isset($_GET['page']) && $_GET['page']!='')
{
if ($_GET['page']=='end')
{
$page=$k_voice;
}
else
{
$page=intval($_GET['page']);
}
}
$page=intval($page);
if ($k_voice<$page){$page=$k_voice;}
if (0>$page){$page=1;}
$i=$page-1;

$q56 = mysql_query("SELECT * FROM `$mysql[pref]voice` ORDER BY id DESC LIMIT $i, 1;");
$voice56 = mysql_fetch_array($q56);

$q_v3 = mysql_query("SELECT COUNT(*) FROM `$mysql[pref]voices` WHERE `id_v` = '$voice56[id]' AND `id_user` = '$user[id]';");
if (mysql_result($q_v3, 0)==0)
{
$voice_ok=0;
}
else
{
$voice_ok=1;
}

echo "<div class=\"mess\">";
if ($voice_ok==0)
echo "<form method=\"post\" action=\"index.php?act=voice&amp;page=$page\">\n";

$q = mysql_query("SELECT * FROM `$mysql[pref]voice` ORDER BY id DESC LIMIT $i, 1;");
while ($voice = mysql_fetch_array($q))
{

echo "<b>".base64_decode($voice['name'])."</b>";
if ($user['level']>=9){echo "<a href='del.php?id=$voice[id]'>[X]</a><br />\n";}
echo "<br />\n";
for ($i_v=1;$i_v<=8;$i_v++)
{
if ($voice[$i_v]!='')
{
if ($voice_ok==0 && isset($_GET['act']) && $_GET['act']=='voice' && isset($_POST['voice_'.$voice['id']]) && $_POST['voice_'.$voice['id']]==$i_v)
{
mysql_query("INSERT INTO `$mysql[pref]voices` (`id_v`, `voice`, `id_user`, `time`)
values('$voice[id]', '$i_v', '$user[id]', '$time');");
header("Location: index.php?".SID."&page=$page&msg=addv");
exit;
}

$q_v1 = mysql_query("SELECT COUNT(*) FROM `$mysql[pref]voices` WHERE `id_v` = '$voice[id]';");
$q_v2 = mysql_query("SELECT COUNT(*) FROM `$mysql[pref]voices` WHERE `id_v` = '$voice[id]' AND `voice` = '$i_v';");
$k_p_voice1=mysql_result($q_v1, 0);
if ($k_p_voice1==0){$k_p_voice1=1;}
$k_p_voice2=mysql_result($q_v2, 0);

if ($voice_ok==0)
echo "<input name=\"voice_$voice[id]\" type=\"radio\" value=\"$i_v\" /> ";

echo "".base64_decode($voice[$i_v]).".... [$k_p_voice2]<br />\n";

$proc=round($k_p_voice2/$k_p_voice1*100, 0);
echo "<img src=\"rat.php?r=$proc\" act=\"\" /><br/>\n";




}
}

}
echo '<br />';
if ($voice_ok==0)
{
echo "<input value=\"Проголосовать\" class=\"form\" type=\"submit\" />\n";
echo "</form>\n";
}
echo "</div>\n";
echo "<hr />\n<div class=\"str\">";
str("index.php?",$k_voice,$page);
echo "</div>\n";
echo "<hr />\n";





if (isset($user) && $user['level']>=9){echo "<a href=\"add.php\">Добавить</a><br />\n";}
echo '<br />';
echo gb.'<a href="'.H.'enter">Прихожая</a><br/>'.div;
foot();
?>