Файл: votes/index.php
Строк: 168
<?
include_once '../sys/inc/start.php';
include_once '../sys/inc/compress.php';
include_once '../sys/inc/sess.php';
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once '../sys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
include_once '../sys/inc/fnc.php';
include_once '../sys/inc/user.php';
if (isset($_GET['act'])){
switch($_GET['act'])
{
case 'create':
if(isset($user) && $user['level']>2)
{
include 'inc/create.php';
}else{
header("Location: ?");
}
break;
case 'setting':
if(isset($user) && $user['level']>2)
{
include 'inc/setting.php';
}else{
header("Location: ?");
}
break;
case 'under':
$set['title']='Другие голосования';
include_once '../sys/inc/thead.php';
title();
aut();
$votes=mysql_query("SELECT * FROM `votes` WHERE `priority`!='1' AND `close`!='1' ORDER BY `create_date` DESC");
echo "<table class='post'>n";
while($vote=mysql_fetch_array($votes))
{
echo " <tr>n";
echo " <td class='icon' rowspan='2'>n";
echo " <img src='/style/themes/$set[set_them]/votes/vote.png' alt='' />n";
echo " </td>n";
echo " <td class='p_t'>n";
echo" <a href="?v_id=".$vote['id'].""><b>".esc(trim(br(bbcode(smiles(links(stripcslashes(htmlspecialchars($vote['text']))))))))."</b></a>";
echo " </td>n";
echo " </tr>n";
echo " <tr>n";
echo " <td class='p_m'>n";
echo "всего голосов: ".$vote['all_click'];
echo " </td>n";
echo " </tr>n";
}
echo "</table>n";
echo "<a href="?">Главное голосование</a>";
break;
case 'old':
$set['title']='Завершенные голосования';
include_once '../sys/inc/thead.php';
title();
aut();
$votes=mysql_query("SELECT * FROM `votes` WHERE `close`='1' ORDER BY `create_date` DESC");
echo "<table class='post'>n";
while($vote=mysql_fetch_array($votes))
{
echo " <tr>n";
echo " <td class='icon' rowspan='2'>n";
echo " <img src='/style/themes/$set[set_them]/votes/vote.png' alt='' />n";
echo " </td>n";
echo " <td class='p_t'>n";
echo" <a href="?v_id=".$vote['id'].""><b>".esc(trim(br(bbcode(smiles(links(stripcslashes(htmlspecialchars($vote['text']))))))))."</b></a>";
echo " </td>n";
echo " </tr>n";
echo " <tr>n";
echo " <td class='p_m'>n";
echo "всего голосов: ".$vote['all_click'];
echo " </td>n";
echo " </tr>n";
}
echo "</table>n";
echo "<a href="?">Главное голосование</a>";
break;
case 'vote':
$d_id=abs(intval($_POST['id_d']));
if(empty($d_id))
{
header("Location: ?err");
exit;
}else{
$vd=mysql_fetch_array(mysql_query("SELECT * FROM `votes_dilem` WHERE `id`='$d_id'"));
$vote=mysql_fetch_array(mysql_query("SELECT * FROM `votes` WHERE `id`='".$vd['v_id']."'"));
$cv=mysql_result(mysql_query("SELECT COUNT(*) FROM `votes_user` WHERE `v_id`='".$vote['id']."' AND `u_id`='".$user['id']."'"),0);
if($cv>0)
{
header("Location: ?isset");
exit;
}
if($vote['close']==1)
{
header("Location: ?err");
exit;
}else{
mysql_query("UPDATE `votes` SET `all_click` = all_click+1 WHERE `id`='".$vd['v_id']."'");
mysql_query("UPDATE `votes_dilem` SET `click` = click+1 WHERE `id`='".$vd['id']."'");
mysql_query("INSERT INTO `votes_user` (`v_id`, `u_id`, `time`) VALUES('".$vd['v_id']."','".$user['id']."', '$time')");
header("Location: ?voteok&v_id=".$vd['v_id']);
exit;
}
}
break;
}
}else
{
$set['title']='Голосования';
include_once '../sys/inc/thead.php';
title();
aut();
if(isset($_GET['addok']))
{
msg('Голосование успешно создано');
}
if(isset($_GET['voteok']))
{
msg('Ваш голос засчитан');
}
if(isset($_GET['err']))
{
$err='Ошибка';
err();
}
if(isset($_GET['isset']))
{
$err='Вы уже проголосовали';
err();
}
if(isset($user))
{
$count=mysql_result(mysql_query("SELECT COUNT(*) FROM `votes` WHERE `close`='0'"),0);
if($count==0)
{
echo"Нет активных голосований<br />n";
}else{
if(isset($_GET['v_id']))
{
$vote=mysql_fetch_array(mysql_query("SELECT * FROM `votes` WHERE `id`='".abs(intval($_GET['v_id']))."'"));
}else{
$vote=mysql_fetch_array(mysql_query("SELECT * FROM `votes` WHERE `priority`='1'"));
}
$cv=mysql_result(mysql_query("SELECT COUNT(*) FROM `votes_user` WHERE `v_id`='".$vote['id']."' AND `u_id`='".$user['id']."'"),0);
$vv=mysql_query("SELECT * FROM `votes_dilem` WHERE `v_id`='".$vote['id']."' ORDER BY `click` DESC");
if($cv==0 && $vote['close']==0)
{
echo "<table class='post'>n";
echo " <tr>n";
echo " <td class='icon' rowspan='2'>n";
echo " <img src='/style/themes/$set[set_them]/votes/vote.png' alt='' />n";
echo " </td>n";
echo " <td class='p_m'>n";
echo " Голосование на тему:";
echo " </td>n";
echo " </tr>n";
echo " <tr>n";
echo " <td class='p_m'>n";
echo " <big><b>".esc(trim(br(bbcode(smiles(links(stripcslashes(htmlspecialchars($vote['text']))))))))."</b></big>";
echo " </td>n";
echo " </tr>n";
echo "</table>n";
echo "<form method="post" action="?act=vote">n";
while($vd=mysql_fetch_array($vv))
{
echo "<input type="radio" name="id_d" value="".$vd['id'].""/> ".esc(trim(br(bbcode(stripcslashes(htmlspecialchars($vd['text']))))))."<br />n";
}
echo "<br /><input value="Голосовать" type="submit" /><br />n";
echo "</form>n";
}else{
echo "<table class='post'>n";
echo " <tr>n";
echo " <td class='icon' rowspan='2'>n";
echo " <img src='/style/themes/$set[set_them]/votes/vote.png' alt='' />n";
echo " </td>n";
echo " <td class='p_m' colspan='2'>n";
echo " Результаты голосования на тему:";
echo " </td>n";
echo " </tr>n";
echo " <tr>n";
echo " <td class='p_m' colspan='2'>n";
echo " <big><b>".esc(trim(br(bbcode(smiles(links(stripcslashes(htmlspecialchars($vote['text']))))))))."</b></big>";
echo " </td>n";
echo " </tr>n";
while($vd=mysql_fetch_array($vv))
{
$p=round($vd['click']/$vote['all_click']*100);
echo " <tr>n";
echo " <td class='icon' rowspan='2'>n";
echo " $p%n";
echo " </td>n";
echo " <td class='p_t' colspan='2'>n";
echo " ".esc(trim(br(bbcode(smiles(links(stripcslashes(htmlspecialchars($vd['text']))))))))."n";
echo " </td>n";
echo " </tr>n";
echo " <tr>n";
echo " <td class='p_m'>n";
echo " голосов: ".$vd['click'];
echo "<br />n<img src='static.php?p=$p' alt='' />n";
echo " </td>n";
echo " </tr>n";
}
echo "</table>n";
}
if($vote['priority']<>1)
{
echo "<a href="?">Главное голосование</a><br />n";
}
}
if($count>1)
{
echo "<a href="?act=under">Другие голосования</a> (".($count-1).")<br />n";
}
$c_close=mysql_result(mysql_query("SELECT COUNT(*) FROM `votes` WHERE `close`='1'"),0);
if($c_close>0)
{
echo "<a href="?act=old">Завершенные голосования</a> ($c_close)n";
}
if(isset($user) && $user['level']>2)
{
include 'inc/admin_form.php';
}
}else{
$err='Извините, но чтобы принять участие в голосованиях и просматривать их результаты Вы должны быть авторизованным пользователем сайта';
err();
}
}
include_once '../sys/inc/tfoot.php';
?>