<?
/*
=====================================================
 Volkov NET!! - by SaNcHeS Group 
-----------------------------------------------------
 http://AllForCS.RU/
-----------------------------------------------------
 Copyright (c) 2009 SaNcHeS Group
=====================================================
 Данный код защищен авторскими правами
=====================================================
 Файл: voite.php
-----------------------------------------------------
 Назначение: Голосование
=====================================================
*/
include("./../inc/config.php");
include("./passwd.php");
include("./auth.php");
include("./html.php");
include("./generator.php");

echo $HEAD;
echo $JS_POPUP;
echo $STYLE;
echo $BODY;

print <<<vivod
<table align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="600">
<p>
vivod;

if ($_GET['voite']=="1")
{
if ($_POST['variant']==""){
echo "<center>Вы не ввели ни одного варианта ответа на голосование!</center></html>";
exit;
}
else
{

if ($_POST['rezet'])
{

$query = mysql_query("SELECT count(*) FROM `m3_voite_ip` WHERE `ip`='".$HTTP_SERVER_VARS["REMOTE_ADDR"]."';");
list($voted_ip) = mysql_fetch_array($query);
$query = mysql_query("SELECT * FROM `m3_question`;");
list($active_vote) = mysql_fetch_array($query);

mysql_query("UPDATE `m3_answer` SET `counter`='0' WHERE `id`>'0';");
mysql_query("DELETE FROM `m3_voite_ip` WHERE `ip` != 'wow';");



echo "<center>Голосование аннулированно!</center>
</html>";
exit;
}

if ($_POST['change'])
{

if ($_POST['qu']==""){
echo "<center>Вы не ввели вопрос для голосования!</center>
</html>";
exit;
}

mysql_query("DELETE FROM `m3_question` WHERE `question` != 'wow';");
mysql_query("DELETE FROM `m3_answer` WHERE `id` != 'wow';");
mysql_query("DELETE FROM `m3_voite_ip` WHERE `ip` != 'wow';");
mysql_query("INSERT INTO `m3_question` ( question, id) VALUES ('$_POST[qu]', 1);");



$record = $_POST['variant'];
$eto_answer = explode("\r\n",$record);

for ($i=0; $i<count($eto_answer); $i++) {
if (pos($eto_answer)!=""){
mysql_query("INSERT INTO `m3_answer` ( id , answer , counter ) VALUES ( '".($i+1)."', '".pos($eto_answer)."' , '0' );");
}
next($eto_answer);
}

echo "<meta http-equiv=\"refresh\" content=\"2;url=voite.php\"><br><br><br><br><center>Операция выполнена!</center>";exit;}
}
exit;
}

$query = mysql_query("SELECT * FROM `m3_question`;");
list($active_vote) = mysql_fetch_array($query);

$rezz = mysql_query("SELECT * FROM `m3_answer` ORDER BY `id` ASC;") or die (mysql_error());

if ($rezz && mysql_num_rows($rezz)>0){
$sst = null;
while ($row = mysql_fetch_array($rezz, MYSQL_ASSOC)){
$sst.=$row["answer"]."
";
}

}

echo "<center><form enctype='multipart/form-data' action='voite.php?voite=1' method=post>
Вопрос: <input type='text' name='qu' value='".$active_vote."' size='41'><br><br>Варианты:<br>
<textarea name='variant' rows='7' cols='51'>".$sst."</textarea></font></p>
<p align='center'><font face='Verdana' size='2'><input type='submit' name='rezet' value='Сброс'> &nbsp;<input type='submit' name='change' value='Применить!'></font></p>
</form></center>";
generate_voite();
@mysql_free_result();
@mysql_close();
?>

</form>
</td>
</tr>
</table>
</td>
</tr>
</table>