Просмотр файла users/votes.php

Размер файла: 7.68Kb
<?
include('../core/core.php');
include(BASEDIR.INC.'func.php');
include(BASEDIR.INC.'session.php');
include(BASEDIR.INC.'session_user.php');
$mode = htmlspecialchars($_GET['mode']);
include(BASEDIR.INC.'head.php');
 echo '<div class="razdel">Голосования</div>';
show_title('Голосования');
switch ($mode):
case 'index':
$o= mysql_query("SELECT count(*) FROM `vote`");
$r = mysql_fetch_row($o);
$t = $r[0];
define('TOPAGE',10);
$page=(int)$_GET['page'];  
     
   $q=mysql_result(mysql_query("SELECT COUNT(*) FROM `vote`"),0);  
      
    $total = intval(($q - 1) / TOPAGE) + 1;  
      
    if(empty($page) or $page < 0) $page = 1;  
      
    if($page > $total) $page = $total;  
      
    $start = $page * TOPAGE -TOPAGE;  

    $g=mysql_query("SELECT * FROM `vote` ORDER BY `id` DESC LIMIT $start,".TOPAGE."");  
while($u=mysql_fetch_array($g)){ 
$oq= mysql_query("SELECT count(*) FROM `vote_golos` WHERE `vote`='".$u['id']."'");
$rq = mysql_fetch_row($oq);
$tq = $rq[0];
echo'<div class="menu">
<a href="?mode=pull&id='.$u['id'].'">'.$u['vote'].'</a>
<hr>
Создано: '.$u['data'].'<br />
Всего голосов: '.$tq.'
</div>';
}

if($t == 0){ echo'<div class="menu">Голосования еще не созданы!</div>'; } 
       if ($page != $total) $nextpage = ' <a href="?mode=index&page='. ($page + 1) .'">Далее</a>';  
      if($page - 1 > 0) $pageback = '<a href="?mode=index&page='. ($page - 1) .'">Назад</a> ';  
echo''.$pageback.' '.$nextpage.'';
break;
case 'pull':
$id = abs(intval($_GET['id']));
if($id == !NULL){
//---------------------------------------//
if(is_user()){
//---------------------------------------//
$vote = mysql_query('SELECT * FROM vote WHERE id = "'.$id.'"');
$vote = mysql_fetch_assoc($vote);
//--------------------------------------//
echo ' <div class="menu"><b>'.$vote['vote'].'</b> (Голосов: '.$vote['count'].')</div>';
//--------------------------------------//
$g = mysql_query('SELECT * FROM vote_golos WHERE vote = "'.$id.'" AND login = "'.$_COOKIE['login'].'"');
$g = mysql_fetch_assoc($g);
//---------------------------------------//
if (!empty($g['login'])) {
//---------------------------------------//
$vote = mysql_query('SELECT * FROM vote WHERE id = "'.$id.'"');
$vote = mysql_fetch_assoc($vote);
//--------------------------------------//
if($vote['id'] == !NULL){
$all = $vote['count'];
$query = mysql_query("SELECT * FROM `vote_answer` WHERE `vote`='".$id."'"); 
while($row = mysql_fetch_assoc($query)){
$del = round($row['count'] / $all * 100 , 1);
echo '<div class="menu">'.$row['answer'].' ('.$row['count'].' | '.$del.' %)<br />
<img src="/core/rating.php?img=' . $del . '" alt=" ' . $del . ' %" /></div>';
}
}
} else {
if($vote['close'] == 'on'){
echo '<div class="menu"><form action="?mode=vote&id='.$id.'" method="post">';
$query = mysql_query("SELECT * FROM `vote_answer` WHERE `vote`='".$id."'"); 
while($row = mysql_fetch_assoc($query)){
echo '<input name="poll" type="radio" value="'.$row['id'].'" /> '.$row['answer'].'<br />';
}
echo '<br /><input type="submit" value="Голосовать" /></form></div>';
} else {
$vote = mysql_query('SELECT * FROM vote WHERE id = "'.$id.'"');
$vote = mysql_fetch_assoc($vote);
//--------------------------------------//
if($vote['id'] == !NULL){
$all = $vote['count'];
$query = mysql_query("SELECT * FROM `vote_answer` WHERE `vote`='".$id."'"); 
while($row = mysql_fetch_assoc($query)){
$del = round($row['count'] / $all * 100 , 1);
echo '<div class="menu">'.$row['answer'].' ('.$row['count'].' | '.$del.' %)<br />
<img src="/core/rating.php?img=' . $del . '" alt=" ' . $del . ' %" /></div>';
}
}
}
$o= mysql_query("SELECT count(*) FROM `vote_answer` WHERE `vote`='".$id."'");
$r = mysql_fetch_row($o);
$total = $r[0];
echo '<div class="menu">Всего вариантов: <b>'.$total.'</b></div>';
}
//---------------------------------------//
} else {
$vote = mysql_query('SELECT * FROM vote WHERE id = "'.$id.'"');
$vote = mysql_fetch_assoc($vote);
//--------------------------------------//
if($vote['id'] == !NULL){
$all = $vote['count'];
$query = mysql_query("SELECT * FROM `vote_answer` WHERE `vote`='".$id."'"); 
while($row = mysql_fetch_assoc($query)){
$del = round($row['count'] / $all * 100 , 1);
echo '<div class="menu">'.$row['answer'].' ('.$row['count'].' | '.$del.' %)<br />
<img src="/core/rating.php?img=' . $del . '" alt=" ' . $del . ' %" /></div>';
}
}
}
//---------------------------------------//
} else { echo'Ошибка! опрос не выбран!'; }
echo' 
<a href="?mode=votes&id='.$id.'">Проголосовавшие</a><br />
<a href="?mode=index">К голосованиям</a><br />
<a href="/">На главную</a><br />';
break;
case 'vote':
echo'<div class="menu">';
$id = abs(intval($_GET['id']));
$poll = abs(intval($_POST['poll']));
if($id == !NULL){
//---------------------------------------//
if (!empty($poll)) {
//---------------------------------------//
if(is_user()){
//---------------------------------------//
$vote = mysql_query('SELECT * FROM vote WHERE id = "'.$id.'"');
$vote = mysql_fetch_assoc($vote);
//---------------------------------------//
if($vote['close'] == 'on'){
//---------------------------------------//
$g = mysql_query('SELECT * FROM vote_golos WHERE vote = "'.$id.'" AND login = "'.$_COOKIE['login'].'"');
$g = mysql_fetch_assoc($g);
//---------------------------------------//
if (empty($g['login'])) {
//---------------------------------------//
mysql_query("UPDATE `vote` SET `count`=`count` + 1 WHERE id = '".$id."';");
mysql_query("UPDATE `vote_answer` SET `count`=`count` + 1 WHERE id = '".$poll."';");
mysql_query('INSERT INTO `vote_golos`(`login`,`vote`) VALUES ("'.$_COOKIE['login'].'","'.$id.'")');
echo'Ваш голос успешно принят!';
//---------------------------------------//
} else { echo'Ошибка! Вы уже проголосовали в этом опросе!'; }
//---------------------------------------//
} else { echo'Ошибка! Данный опрос закрыт для голосования!'; }
//---------------------------------------//
} else { echo'Вы не авторизованы, чтобы участвовать в голосованиях, необходимо <a href="/pages/user.php">авторизоваться</a>!'; }
//---------------------------------------//
} else { echo'Ошибка! Вы не выбрали вариант ответа!'; }
//---------------------------------------//
} else { echo'Не указан ID опросa!'; }
echo'</div>';
echo' 
<a href="?mode=pull&id='.$id.'">Результаты</a><br />
<a href="?mode=index">К голосованиям</a><br />
<a href="/">На главную</a><br />';
break;
case 'votes':
$id = abs(intval($_GET['id']));
if($id == !NULL){
//---------------------------------------//
$vote = mysql_query('SELECT * FROM vote WHERE id = "'.$id.'"');
$vote = mysql_fetch_assoc($vote);
//---------------------------------------//
echo ' <div class="menu"><b>'.$vote['vote'].'</b> (Голосов: '.$vote['count'].')</div>';
echo'<div class="menu">';
$query = mysql_query('SELECT * FROM vote_golos WHERE vote = "'.$id.'"'); 
while($row = mysql_fetch_assoc($query)){

echo '<a href="/users/profile.php?user='.$row['login'].'">'.$row['login'].'</a><br />';

}
} else { echo'Не указан ID опросa!'; }
echo'</div>';
echo' 
<a href="?mode=pull&id='.$id.'">Результаты</a><br />
<a href="?mode=index">К голосованиям</a><br />
<a href="/">На главную</a><br />';
break;
default: 
header ('location: ?mode=index'); 
endswitch;
include(BASEDIR.INC.'foot.php');
?>