View file menu/votes.php

File size: 18.6Kb
<?php
#############################################
# 0JXRgdC70Lgg0YLRiyDRh9C40YLQsNC10YjRjCDRj #
# dGC0L4g0YHQvtC+0LHRidC10L3QuNC1LCDQt9C90L #
# DRh9C40YIg0YLRiyDQvdC10LzQvdC+0LPQviDQt9C #
#          90LDQtdGI0YwgUEhQIQ==            #
#__---------------------------------------__#
#__        0JrQu9C40Log0JrQu9GD0LE=       __#
#  ---------------------------------------  #
# 0JDQstGC0L7RgCA6IE1vcmdhbg==              #
# SUNRIDog0L3QtSDRgdC60LDQttGDIHhE          #
#                                           #
#############################################

require '../inc/start.php';
require '../inc/regvars.php';
require '../inc/db.php';
require '../inc/config.php';
require '../inc/funct.php';
require '../inc/antidos.php';
require '../inc/gzip.php';
require '../inc/header.php';

only_reg('/aut.php?',true);

if($user_prof['admin']<$config['enable_log_aut']){location('menu/index.php');}

if(is_active_user($user_prof['id'],0))
{

$title = 'Голосования';
require '../inc/head.php';

 switch($mode = !empty($_GET['mode']) ? $_GET['mode'] : null)
{
default:
echo '<div class="sec">
<b>Голосования</b>
</div><div class="vstavka">';

# echo '<div class="ad"><img src="/pic/" alt=""/> <a href="votes.php?mode="></a></div>';

if($user_prof['admin'] >= 2)echo '<div class="ad"><img src="/pic/add.png" alt="add"/> <a href="votes.php?mode=add">Добавить опрос</a></div><br />';

$where = 'WHERE `status` = \'2\'';
if($user_prof['admin'] >= 2)$where = null;

$count = mysql_result(query("SELECT COUNT(*) FROM `$db[prefix]votes` $where"),0);

if($count > 0)
{

$res = query("SELECT id,name,cv FROM `$db[prefix]votes` $where ORDER BY RAND()");
 while($vote = mysql_fetch_array($res))
{
echo '<div class="ie"><img src="/pic/help.png"/> <a href="votes.php?mode=vote&vid='.$vote['id'].'"><b>'.$vote['name'].'</b></a>('.$vote['cv'].')</div>';
}

}else{echo 'Голосований нет!<br />';}

break;
#####################################################################################################################
#####################################################################################################################
#####################################################################################################################
 case 'add':

if($user_prof['admin'] < 2)location('menu/votes.php');

echo '<div class="sec">
<a href="votes.php">Голосования</a> / <b>Добавление опроса</b>
</div><div class="vstavka">';

if(!empty($_GET['confirm']) && $_GET['confirm'] == 'yes')
 {

 $name = obr($_POST['name'],'string',255);

 $answer1 = obr($_POST['answer1'],'string',100);
 $answer2 = obr($_POST['answer2'],'string',100);
 $answer3 = obr($_POST['answer3'],'string',100);
 $answer4 = obr($_POST['answer4'],'string',100);
 $answer5 = obr($_POST['answer5'],'string',100);
 $answer6 = obr($_POST['answer6'],'string',100);
 $answer7 = obr($_POST['answer7'],'string',100);
 $answer8 = obr($_POST['answer8'],'string',100);
 $answer9 = obr($_POST['answer9'],'string',100);
 $answer10 = obr($_POST['answer10'],'string',100);

 $status = obr($_POST['status'],'integer',1);

 if(!empty($name) && !empty($answer1) && !empty($answer2) && ($status == 0 || $status == 1 || $status == 2))
  {
  if(mysql_result(query("SELECT COUNT(*) FROM `$db[prefix]votes` WHERE `name` = '$name'"),0) == 0)
   {
   if(query("INSERT INTO `$db[prefix]votes` SET `user` = '$user_prof[id]',`name` = '$name',`answer1` = '$answer1',`answer2` = '$answer2',`answer3` = '$answer3',`answer4` = '$answer4',`answer5` = '$answer5',`answer6` = '$answer6',`answer7` = '$answer7',`answer8` = '$answer8',`answer9` = '$answer9',`answer10` = '$answer10',`status` = '$status'"))
    {
    echo 'Голосование успешно создано<br />
<a href="votes.php">Далее&gt;&gt;&gt;</a>';
    }else{echo 'Неизвестная ошибка!<br />
<a href="votes.php?mode=add">&lt;&lt;&lt;Назад</a>';}
   }else{echo 'Голосование с таким названием уже существует!<br />
<a href="votes.php?mode=add">&lt;&lt;&lt;Назад</a>';}
  }else{echo 'Заполните название и как минимум 2 варианта!<br />
<a href="votes.php?mode=add">&lt;&lt;&lt;Назад</a>';}
 }
else
 {
 echo '<form action="votes.php?mode=add&confirm=yes" method="POST">
Вопрос : <br />
<input name="name" type="text" maxlength="250"><br />
Вариант 1 : * <br />
<input name="answer1" type="text" maxlength="100"><br />
Вариант 2 : * <br />
<input name="answer2" type="text" maxlength="100"><br />
Вариант 3 : <br />
<input name="answer3" type="text" maxlength="100"><br />
Вариант 4 : <br />
<input name="answer4" type="text" maxlength="100"><br />
Вариант 5 : <br />
<input name="answer5" type="text" maxlength="100"><br />
Вариант 6 : <br />
<input name="answer6" type="text" maxlength="100"><br />
Вариант 7 : <br />
<input name="answer7" type="text" maxlength="100"><br />
Вариант 8 : <br />
<input name="answer8" type="text" maxlength="100"><br />
Вариант 9 : <br />
<input name="answer9" type="text" maxlength="100"><br />
Вариант 10 : <br />
<input name="answer10" type="text" maxlength="100"><br />
Статус : <br />
<select size="1" name="status">
  <option value="0">Отключен полностью</option>
  <option value="1">Только просмотр результатов</option>
  <option value="2" selected="selected">Активна</option>
</select><br />
<input type="submit" value="Добавить">
</form>';
 }

break;
#####################################################################################################################
#####################################################################################################################
#####################################################################################################################
 case 'vote':

if(empty($_GET['vid']))location('menu/votes.php');

$vid = obr($_GET['vid'],'integer');

$where = 'AND `status` = \'2\'';
if($user_prof['admin'] >= 2)$where = null;

if(mysql_result(query("SELECT COUNT(*) FROM `$db[prefix]votes` WHERE `id` = '$vid' $where"),0) == 0)location('menu/votes.php');

$vote = mysql_fetch_array(query("SELECT * FROM `$db[prefix]votes` WHERE `id` = '$vid'"));

echo '<div class="sec">
<a href="votes.php">Голосования</a> / <a href="votes.php?mode=vote&vid='.$vid.'"><b>'.$vote['name'].'</b></a>
</div><div class="vstavka">';

 switch($act = !empty($_GET['act']) ? $_GET['act'] : null)
{
default:

echo '<b>'.$vote['name'].'</b><br /><br />';

if($user_prof['admin'] >= 2)
{
echo '<div class="ad"><img src="/pic/element.png"/> <a href="votes.php?mode=vote&vid='.$vid.'&act=edit">Изменить</a></div>';
if($vote['cv'] > 0)echo '<div class="ad"><img src="/pic/element.png"/> <a href="votes.php?mode=vote&vid='.$vid.'&act=clean">Сбросить результаты</a></div>';
echo '<div class="ad"><img src="/pic/element.png"/> <a href="votes.php?mode=vote&vid='.$vid.'&act=del">Удалить </a></div>';
}

//-- Если пользователь уже голосовал
if(mysql_result(query("SELECT COUNT(*) FROM `$db[prefix]votes_voices` WHERE `vid` = '$vid' AND `user` = '$user_prof[id]'"),0) > 0 || $vote['status'] < 2)
{

//-- Получаем результаты
$count = mysql_result(query("SELECT COUNT(*) FROM `$db[prefix]votes_voices` WHERE `vid` = '$vid'"),0);

if($count != $vote['cv'])query("UPDATE `$db[prefix]votes` SET `cv` = '$count' WHERE `id` = '$vid'");

$answers = array();

$res = query("SELECT answer,COUNT(*) as count FROM `$db[prefix]votes_voices` WHERE `vid` = '$vid' GROUP BY `answer` ORDER BY COUNT(*) DESC");
while($voice = mysql_fetch_array($res)){ $answers[$voice['answer']] = $voice['count']; }

#array_dump($answers);

 for($i = 1;$i <= 10;$i ++)
{
if(empty($vote['answer'.$i]))
 {
 if(isset($answers[$i]))query("DELETE FROM `$db[prefix]votes_voices` WHERE `vid` = '$vid' AND `answer` = '$i'");
 continue;
 }

$ca = (!empty($answers[$i])) ? $answers[$i] : 0;

echo '<div class="ie"><b>'.$i.'.</b> <b>'.$vote['answer'.$i].'</b> : '.$ca.' '.postfix($ca,'голосов','голоса','голос').' / '.round(($ca / $count) * 100).'%<br />';
echo '<img src="/voices.php?voices='.round(($ca / $count) * 100).'" alt="'.round(($ca / $count) * 100).'%"/>';
if($ca > 0 && $user_prof['admin'] >= 2)echo '<br />&raquo;<a href="votes.php?mode=vote&vid='.$vid.'&act=stat&ans='.$i.'">Подоробней</a>';
echo '</div>';
}

}
else
{

 for($i = 1;$i <= 10;$i ++)
{
if(!empty($vote['answer'.$i]))echo '<b>'.$i.'.</b> <a href="votes.php?mode=vote&vid='.$vid.'&act=voice&ans='.$i.'">'.$vote['answer'.$i].'</a><br />';
}

}

break;
##########################################################
##########################################################
 case 'voice':

if(empty($_GET['ans']) || $vote['status'] > 2)location('menu/votes.php');

if(mysql_result(query("SELECT COUNT(*) FROM `$db[prefix]votes_voices` WHERE `vid` = '$vid' AND `user` = '$user_prof[id]'"),0) > 0)location('menu/votes.php');

$ans = obr($_GET['ans'],'answer',2);

if($ans > 10 || $ans < 1)location('menu/votes.php');

if(empty($vote['answer'.$ans]))location('menu/votes.php');

if(query("INSERT INTO `$db[prefix]votes_voices` SET `vid` = '$vid',`answer` = '$ans',`user` = '$user_prof[id]',`date` = '$sitetime'"))
 {
 query("UPDATE `$db[prefix]users` SET `credits` = credits + $config[price_votes] WHERE `id`='$user_prof[id]' ");
echo 'Ваш голос успешно принят<br />
<a href="votes.php?mode=vote&vid='.$vid.'">Далее&gt;&gt;&gt;</a>';
 }
 else{echo 'Неизвестная ошибка!<br />
<a href="votes.php?mode=vote&vid='.$vid.'">&lt;&lt;&lt;Назад</a>';}

break;
##########################################################
##########################################################
 case 'edit':

if($user_prof['admin'] < 2)location('menu/votes.php');

if(!empty($_GET['confirm']) && $_GET['confirm'] == 'yes')
 {

 $name = obr($_POST['name'],'string',255);

 $answer1 = obr($_POST['answer1'],'string',100);
 $answer2 = obr($_POST['answer2'],'string',100);
 $answer3 = obr($_POST['answer3'],'string',100);
 $answer4 = obr($_POST['answer4'],'string',100);
 $answer5 = obr($_POST['answer5'],'string',100);
 $answer6 = obr($_POST['answer6'],'string',100);
 $answer7 = obr($_POST['answer7'],'string',100);
 $answer8 = obr($_POST['answer8'],'string',100);
 $answer9 = obr($_POST['answer9'],'string',100);
 $answer10 = obr($_POST['answer10'],'string',100);

 $status = obr($_POST['status'],'integer',1);

 if(!empty($name) && !empty($answer1) && !empty($answer2) && ($status == 0 || $status == 1 || $status == 2))
  {
  if($name == $vote['name'] || mysql_result(query("SELECT COUNT(*) FROM `$db[prefix]votes` WHERE `name` = '$name'"),0) == 0)
   {
   if(query("UPDATE `$db[prefix]votes` SET `user` = '$user_prof[id]',`name` = '$name',`answer1` = '$answer1',`answer2` = '$answer2',`answer3` = '$answer3',`answer4` = '$answer4',`answer5` = '$answer5',`answer6` = '$answer6',`answer7` = '$answer7',`answer8` = '$answer8',`answer9` = '$answer9',`answer10` = '$answer10',`status` = '$status' WHERE `id` = '$vid'"))
    {
    echo 'Голосование успешно изменено<br />
<a href="votes.php?mode=vote&vid='.$vid.'">Далее&gt;&gt;&gt;</a>';
    }else{echo 'Неизвестная ошибка!<br />
<a href="votes.php?mode=vote&vid='.$vid.'&act=edit">&lt;&lt;&lt;Назад</a>';}
   }else{echo 'Голосование с таким названием уже существует!<br />
<a href="votes.php?mode=vote&vid='.$vid.'&act=edit">&lt;&lt;&lt;Назад</a>';}
  }else{echo 'Заполните название и как минимум 2 варианта!<br />
<a href="votes.php?mode=vote&vid='.$vid.'&act=edit">&lt;&lt;&lt;Назад</a>';}
 }
else
 {
 echo '<form action="votes.php?mode=vote&vid='.$vid.'&act=edit&confirm=yes" method="POST">
Вопрос : <br />
<input name="name" type="text" value="'.$vote['name'].'" maxlength="250"><br />
Вариант 1 : * <br />
<input name="answer1" type="text" value="'.$vote['answer1'].'" maxlength="100"><br />
Вариант 2 : * <br />
<input name="answer2" type="text" value="'.$vote['answer2'].'" maxlength="100"><br />
Вариант 3 : <br />
<input name="answer3" type="text" value="'.$vote['answer3'].'" maxlength="100"><br />
Вариант 4 : <br />
<input name="answer4" type="text" value="'.$vote['answer4'].'" maxlength="100"><br />
Вариант 5 : <br />
<input name="answer5" type="text" value="'.$vote['answer5'].'" maxlength="100"><br />
Вариант 6 : <br />
<input name="answer6" type="text" value="'.$vote['answer6'].'" maxlength="100"><br />
Вариант 7 : <br />
<input name="answer7" type="text" value="'.$vote['answer7'].'" maxlength="100"><br />
Вариант 8 : <br />
<input name="answer8" type="text" value="'.$vote['answer8'].'" maxlength="100"><br />
Вариант 9 : <br />
<input name="answer9" type="text" value="'.$vote['answer9'].'" maxlength="100"><br />
Вариант 10 : <br />
<input name="answer10" type="text" value="'.$vote['answer10'].'" maxlength="100"><br />
Статус : <br />
<select size="1" name="status">
  <option value="0">Отключен полностью</option>
  <option value="1">Только просмотр результатов</option>
  <option value="2" selected="selected">Активна</option>
</select><br />
<input type="submit" value="Добавить">
</form>';
 }

break;
##########################################################
##########################################################
 case 'del':

if($user_prof['admin'] < 2)location('menu/votes.php');

if(!empty($_GET['confirm']) && $_GET['confirm'] == 'yes')
 {

 if(query("DELETE FROM `$db[prefix]votes_voices` WHERE `vid` = '$vid'"))
  {
  if(query("DELETE FROM `$db[prefix]votes` WHERE `id` = '$vid'"))
   {
   echo 'Голосование успешно удалено<br />
<a href="votes.php">Далее&gt;&gt;&gt;</a>';
   }else{echo 'Немогу удалить голосование<br />
<a href="votes.php?mode=vote&vid='.$vid.'&act=del">&lt;&lt;&lt;Назад</a>';}
  }else{echo 'Немогу удалить результаты!<br />
<a href="votes.php?mode=vote&vid='.$vid.'&act=del">&lt;&lt;&lt;Назад</a>';}
 }
else
 {
 echo 'Вы действительно хотите удалить голосование "<b>'.$vote['name'].'</b>"'.($vote['cv'] > 0 ? ', со всеми результатами' : null).'<br />
<center><a href="votes.php?mode=vote&vid='.$vid.'&act=del&confirm=yes">Да</a> | <a href="votes.php?mode=vote&vid='.$vid.'">Нет</a></center>';
 }

break;
##########################################################
##########################################################
 case 'stat':

if($user_prof['admin'] < 2)location('menu/votes.php');

if(empty($_GET['ans']))location('menu/votes.php');

$ans = obr($_GET['ans'],'answer',2);

if($ans > 10 || $ans < 1)location('menu/votes.php');

if(empty($vote['answer'.$ans]))location('menu/votes.php');

echo 'Ответили <b>'.$vote['answer'.$ans].'</b>[<a href="votes.php?mode=vote&vid='.$vid.'&act=clean&ans='.$ans.'">очистить</a>]';

$count = mysql_result(query("SELECT COUNT(*) FROM `$db[prefix]votes_voices` WHERE `vid` = '$vid' AND `answer` = '$ans'"),0);

if($count > 0)
{

$str = ceil($count/$set_on_page);
if($page > $str)location('menu/votes.php?mode=vote&vid='.$vid.'&act=stat&ans='.$ans);

$res = query("SELECT * FROM `$db[prefix]votes_voices` WHERE `vid` = '$vid' AND `answer` = '$ans' ORDER BY `date` DESC");
$num = $p_str;
 while($voice = mysql_fetch_array($res))
{
$num ++;

echo '<div class="ie"><b>'.$num.'.</b> ';

if($user_prof['set_econom_traf'] == 1)
{
echo 'Пользователь '.userlogin($voice['user'],1,1,$mfvl,1,$user_prof['set_econom_traf']).'<br />
Дата : '.formatdate($voice['date']);
}else
{
echo formatdate($voice['date']).' : '.userlogin($voice['user'],1,1,$mfvl,1,$user_prof['set_econom_traf']).'<br />';
}

echo '</div>';

}

}else echo 'Никто еще не голосовал!';

break;
##########################################################
##########################################################
 case 'clean':

#if($user_prof['admin'] < 2)location('menu/votes.php');

$where = $get_ans = null;
if(!empty($_GET['ans']))
 {
 $int_ans = obr($_GET['ans'],'integer');
 if($int_ans >= 1 && $int_ans <= 10)
  {
  $where = "AND `answer` = '$int_ans'";
  $get_ans = '&ans='.$int_ans;
  }
 }

if(!empty($_GET['confirm']) && $_GET['confirm'] == 'yes')
 {
 if(query("DELETE FROM `$db[prefix]votes_voices` WHERE `vid` = '$vid' $where"))
  {
  echo 'Успешно очищено<br />
<a href="votes.php?mode=vote&vid='.$vid.'">Далее&gt;&gt;&gt;</a>';
  }else{echo 'Ошибка!<br />
<a href="votes.php?mode=vote&vid='.$vid.$get_ans.'&act=clean">&lt;&lt;&lt;Назад</a>';}
 }
else
 {
 echo 'Сбросить результаты голосования<br />
<center><a href="votes.php?mode=vote&vid='.$vid.'&act=clean'.$get_ans.'&confirm=yes">Да</a> | <a href="votes.php?mode=vote&vid='.$vid.'">Нет</a></center>';
 }


break;
/*
##########################################################
##########################################################
 case '-':


break;
*/
}

break;
/*
#####################################################################################################################
#####################################################################################################################
#####################################################################################################################
 case '-':
echo '<div class="sec">

</div><div class="vstavka">';

break;
*/
}

}else
{
 $title = 'Ошибка';
 require '../inc/head.php';
 echo '<div class="sec">Ошибка</div><div class="vstavka">
 Ваш статус неактивен!<br />Голосования недоступны!';
}

echo '<hr/>';
if(!empty($act) && isset($vote['name']) && isset($vid))echo '...<a href="votes.php?mode=vote&vid='.$vid.'">'.$vote['name'].'</a><br />';
if(!empty($mode)) echo '..<a href="votes.php">Голосования</a><br />';
echo '.<a href="/menu/">Кабинет</a><br />';

require '../inc/foot.php';

################################################
# 0KHQutGA0LjQv9GCINC90LUg0L/QsNCx0LvQuNC6IQ== #
#   0KHRgtCw0LLRgNC+0L/QvtC70YwsIDIwMDkg0LMu   #
################################################

?>