';
echo 'В начало';
require_once("../incfiles/end.php");
exit;
}
$id = abs(intval($_GET['id']));
$q = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM vote_name WHERE id='". $id ."';"));
if ($q[0] = false)
{
echo 'Нет такого опроса!
';
echo 'В начало';
require_once("../incfiles/end.php");
exit;
}
$us = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM vote_user WHERE id_vote='". $id ."' AND id_user=". $user_id .";"));
if ($us[0] > 0)
{
echo 'Вы уже принимали участие в этом опросе!
';
echo 'В начало';
require_once("../incfiles/end.php");
exit;
}
if (isset($_POST['submit']) and !empty($_POST['vote']))
{
$vote = abs(intval($_POST['vote']));
$v = mysql_query("SELECT count FROM votes_rezult WHERE id='". $vote ." AND id_vote=". $id ."';");
if (mysql_num_rows($v) == false)
{
echo 'Ошибка голосования!
';
echo 'В начало';
require_once("../incfiles/end.php");
exit;
}
$v_array = mysql_fetch_array($v);
mysql_query("UPDATE votes_rezult SET count='". ++$v_array['count'] ."' WHERE id='". $vote ."';");
mysql_query("INSERT INTO vote_user SET id_user='". $user_id ."', id_vote='". $id ."';");
echo 'Ваш голос засчитан =)
';
echo 'Назад';
unset ($_POST['submit'], $_POST['vote']);
} else
{
echo 'Ошибка голосования!
';
echo 'В начало';
}
break;
////////////////////////////////
case "result":
echo '
Результаты
';
if (empty($_GET['id']))
{
echo 'Ошибка выбора опроса!';
echo 'В начало';
require_once("../incfiles/end.php");
exit;
}
$id = abs(intval($_GET['id']));
$q = mysql_query("SELECT * FROM vote_name WHERE id='" . $id . "';");
if (mysql_num_rows($q) == false)
{
echo 'Ошибка выбора опроса!
';
echo 'В начало';
require_once("../incfiles/end.php");
exit;
}
$c = mysql_query("SELECT * FROM votes_rezult WHERE id_vote='". $id."';");
$sum_count_vote = mysql_fetch_array(mysql_query("SELECT SUM(count) FROM votes_rezult WHERE id_vote='". $id ."';"));
while ($array = mysql_fetch_array($c))
{
echo $array['name'] . ' - ' . $array['count'] . ' (' . ($sum_count_vote[0] > 0 ? round(100/$sum_count_vote[0] * $array['count']) : 0) . '%)
';
}
echo 'Всего голосов ' . $sum_count_vote[0] . '
';
echo 'Назад';
break;
////////////////////////////////
case "list":
$q = mysql_query("SELECT id, vote_name FROM vote_name ORDER BY id DESC;");
echo 'Список
';
if (mysql_num_rows($q) == 0)
{
echo 'Пока не за что голосовать =)
';
} else
{
while ($array = mysql_fetch_array($q))
{
echo '';
}
}
echo 'В начало';
break;
////////////////////////////////
default:
echo 'Опросы
';
if (empty($_GET['id']))
{
$q = mysql_query("SELECT * FROM `vote_name` ORDER BY id DESC LIMIT 1;");
} else
{
$id = abs(intval($_GET['id']));
$q = mysql_query("SELECT * FROM `vote_name` WHERE id='" . $id . "';");
}
if (mysql_num_rows($q) !== 0)
{
$vote_info = mysql_fetch_array($q);
$rezult = mysql_query("SELECT name, count FROM votes_rezult WHERE id_vote='". $vote_info['id'] ."';");
if (mysql_num_rows($rezult) == false)
{
echo 'Ошибка!';
require_once("../incfiles/end.php");
exit;
}
echo '';
if ($user_id)
{
$l = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM vote_user WHERE id_user='" . $user_id . "' AND id_vote='" . $vote_info['id'] . "' ;"));
}
$c = mysql_query("SELECT * FROM votes_rezult WHERE id_vote='". $vote_info['id'] ."';");
if (!$user_id or !empty($l[0]))
{
$sum_count_vote = mysql_fetch_array(mysql_query("SELECT SUM(count) FROM votes_rezult WHERE id_vote='". $vote_info['id'] ."';"));
while ($array = mysql_fetch_array($c))
{
echo $array['name'] . ' - ' . $array['count'] . ' (' . ($sum_count_vote[0] > 0 ? round(100/$sum_count_vote[0] * $array['count']) : 0) . '%)
';
}
echo 'Всего голосов ' . $sum_count_vote[0];
} else
{
echo '';
}
} else
{
echo 'Пока не за что голосовать =)';
}
echo '
Весь список';
break;
}
if ($dostsmod == 1)
{
echo '
Управление опросом';
}
require_once("../incfiles/end.php");
?>