<?

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

include "./config.php";
    $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);
if (($_GET[v3]) AND (!$voted_ip))
{
mysql_query("UPDATE `m3_answer` SET `counter`=`counter`+1 WHERE `id`='".(int)$_GET[v3]."';");
mysql_query("INSERT INTO `m3_voite_ip` VALUES ('".$HTTP_SERVER_VARS["REMOTE_ADDR"]."');");}
$result=mysql_query("SELECT sum(counter) AS sum FROM `m3_answer`;") or die(mysql_error());
if(!empty($result))
{$vote_sum = (int) mysql_result($result,0,"sum");mysql_free_result($result);}

    $result=mysql_query("SELECT sum(counter) AS sum FROM `m3_answer`;") or die(mysql_error());
    if(!empty($result))
    {
        $vote_sum = (int) mysql_result($result,0,"sum");
        mysql_free_result($result);
    }
?>
<table width="100%" border="0" cellspacing="3" cellpadding="0">
  <tr>
    <td colspan="2" valign="top">
<div style="font-family:Verdana; font-size:10px; text-align:left">
    <?php
    echo "<b><i>Q</i>: ".$active_vote."</b><br><br>\r\n";
    ?>
</div>
    </td>
  </tr>
<?php

if (isset($_GET[v3])){
echo "<STYLE>
TD.votebarout {
	BORDER-RIGHT: 0px; BORDER-TOP: 0px; BACKGROUND: #999999; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px
}
TD.votebarin {
	BORDER-RIGHT: 0px; BORDER-TOP: 0px; BACKGROUND: #F7A34A; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px
}
DIV.votespace {
	FONT-SIZE: 4pt; TEXT-ALIGN: center
}
.suka {
	font-family:Verdana; font-size:10px
}
</STYLE>";

    $votebar_width="100";
    $votebar_height="10";
    $result=mysql_query("SELECT `answer`,`counter` FROM `m3_answer` ORDER BY `id` ASC") or die(mysql_error());
    while($row=mysql_fetch_row($result)) {
        echo "<tr><td style=\"BORDER-TOP: #333333 1px dotted\" colspan=\"2\"><p class=suka>". $row[0] ."</p></td></tr><tr>";
        if($vote_sum) {
            $per = (int)(100 * $row[1]/$vote_sum);
            echo "<td width=$votebar_width>\r\n";
            echo "<table align=center border=0 cellspacing=0 cellpadding=1 width=\"$votebar_width\" height=\"$votebar_height\">\r\n";
            echo " <tr>\r\n";
            echo "  <td class=\"votebarout\">\r\n";
            if ($per){
                    echo "   <table align=left border=0 cellspacing=0 cellpadding=0 width=\"".$per."%\" height=\"100%\">\r\n";
                    echo "    <tr>\r\n";
                    echo "     <td class=\"votebarin\">\r\n";
                    echo "        <div class=\"votespace\">&nbsp;</div>\r\n";
                    echo "     </td>\r\n";
                    echo "    </tr>\r\n";
                    echo "   </table>\r\n";
            }
            echo "  </td>\r\n";
            echo " </tr>\r\n";
            echo "</table>\r\n";
            echo"</td><td align=right class=suka nowrap>" .$row[1]. " / " .$per. "%</td>\r\n";
            }
        }
}
echo "<tr><td class=suka colspan=2 valign=center align=right height=25>Всего голосов: $vote_sum</td></tr>";
?>
</table>