<?php

//topic is $topicid (or $thisid - nice programming =] )
//Argh! What is the vote id?
// It's $vote!

//have they voted already?
$resultv=mysql_query("SELECT * FROM $votedtable WHERE intVoteId = '$vote' AND strName = '$gfcookie[1]'");
$num_rowsv = mysql_num_rows( $resultv );
if ($num_rowsv == 0)
{

    //not voted - display choices.
    $result=mysql_query("SELECT * FROM $votetable WHERE intId = '$vote'");
    $num_rows = mysql_num_rows( $result );
    while ( $a_row = mysql_fetch_object( $result ) )
    {
        $postthis = $a_row->strTitle;
        include ("formatposts.php");
        print "<table border=1 cellpadding=0 cellspacing=0 style=\"border-collapse: collapse\" width=\"65%\" bgcolor=\"$fgcolour\" bordercolor=\"$bordercolor\">
        <tr>
        <td width=\"100%\">

        <table border=0 cellpadding=0 cellspacing=0 width=\"100%\">
        <tr><td><font face=\"$font\" size=$fontsizeb><br><centeR>
        <b>$postthis</b><br><font face=\"$font\" size=$fontsize>";

        $postthis = $a_row->memInfo;
        include ("formatposts.php");
        print "$postthis<br>
        <form method=\"POST\" action=\"voteformat.php\">
        <table border=0 cellpadding=0 cellspacing=0>";


        if ($a_row->strOption1 != "")
        {
            $postthis = $a_row->strOption1;
            include ("formatposts.php");
            print "<tr><td><font face=\"$font\" size=$fontsize>$postthis&nbsp;<td>
            <td><input type=\"radio\" value=\"1\" name=\"choice\"></td></tr>";
        }
        if ($a_row->strOption2 != "")
        {
            $postthis = $a_row->strOption2;
            include ("formatposts.php");
            print "<tr><td><font face=\"$font\" size=$fontsize>$postthis&nbsp;<td>
          <td><input type=\"radio\" value=\"2\" name=\"choice\"></td></tr>";
        }
        if ($a_row->strOption3 != "")
        {
            $postthis = $a_row->strOption3;
            include ("formatposts.php");
            print "<tr><td><font face=\"$font\" size=$fontsize>$postthis&nbsp;<td>
          <td><input type=\"radio\" value=\"3\" name=\"choice\"></td></tr>";
        }
        if ($a_row->strOption4 != "")
        {
            $postthis = $a_row->strOption4;
            include ("formatposts.php");
            print "<tr><td><font face=\"$font\" size=$fontsize>$postthis&nbsp;<td>
          <td><input type=\"radio\" value=\"4\" name=\"choice\"></td></tr>";
        }
        if ($a_row->strOption5 != "")
        {
            $postthis = $a_row->strOption5;
            include ("formatposts.php");
            print "<tr><td><font face=\"$font\" size=$fontsize>$postthis&nbsp;<td>
          <td><input type=\"radio\" value=\"5\" name=\"choice\"></td></tr>";
        }
        if ($a_row->strOption6 != "")
        {
            $postthis = $a_row->strOption6;
            include ("formatposts.php");
            print "<tr><td><font face=\"$font\" size=$fontsize>$postthis&nbsp;<td>
          <td><input type=\"radio\" value=\"6\" name=\"choice\"></td></tr>";
        }
        if ($a_row->strOption7 != "")
        {
            $postthis = $a_row->strOption7;
            include ("formatposts.php");
            print "<tr><td><font face=\"$font\" size=$fontsize>$postthis&nbsp;<td>
          <td><input type=\"radio\" value=\"7\" name=\"choice\"></td></tr>";
        }
        if ($a_row->strOption8 != "")
        {
            $postthis = $a_row->strOption8;
            include ("formatposts.php");
            print "<tr><td><font face=\"$font\" size=$fontsize>$postthis&nbsp;<td>
          <td><input type=\"radio\" value=\"8\" name=\"choice\"></td></tr>";
        }
        if ($a_row->strOption9 != "")
        {
            $postthis = $a_row->strOption9;
            include ("formatposts.php");
            print "<tr><td><font face=\"$font\" size=$fontsize>$postthis&nbsp;<td>
            <td><input type=\"radio\" value=\"9\" name=\"choice\"></td></tr>";
        }
        if ($a_row->strOption10 != "")
        {
            $postthis = $a_row->strOption10;
            include ("formatposts.php");
            print "<tr><td><font face=\"$font\" size=$fontsize>$postthis&nbsp;<td>
            <td><input type=\"radio\" value=\"10\" name=\"choice\"></td></tr>";
        }
        print "<tr><td><font face=\"$font\" size=$fontsize>Abstain&nbsp;<td>
        <td><input type=\"radio\" value=\"11\" checked name=\"choice\"></td></tr></table><br>
        <input type=\"hidden\" value=\"$vote\" name=\"vote\">
        <input type=\"hidden\" value=\"$topicid\" name=\"topicid\">";

        if (isset($gfcookie[1]))
        {
            print "<input type=\"submit\" value=\"Vote!\"></form>";
        }
        else
        {
            print "<font face=\"$font\" size=$fontsize><a href=\"login.php\">Log In</a> to vote!<bR><br>";
        }

        print "</td></tr>
        </td></tr></table></td></tr></table><br><br>";
    }
}
else
{
    //already voted - show results!
    $result=mysql_query("SELECT * FROM $votetable WHERE intId = '$vote'");
    $num_rows = mysql_num_rows( $result );
    while ( $a_row = mysql_fetch_object( $result ) )
    {
        $postthis = $a_row->strTitle;
        include ("formatposts.php");
        print "<table border=1 cellpadding=0 cellspacing=0 style=\"border-collapse: collapse\" width=\"65%\" bgcolor=\"$fgcolour\" bordercolor=\"$bordercolor\">
        <tr>
        <td width=\"100%\">

        <table border=0 cellpadding=0 cellspacing=0 width=\"100%\">
        <tr><td><font face=\"$font\" size=$fontsizeb><br><centeR>
        <b>$postthis</b><br><font face=\"$font\" size=$fontsize>";

        $postthis = $a_row->memInfo;
        include ("formatposts.php");
        print "<font size=$fontsize face=\"$font\">$postthis<br>
        <table border=0 cellpadding=0 cellspacing=0>";

        if ($a_row->strOption1 != "")
        {
            if ($a_row->intVotes1 != 0 AND $a_row->intTotalVotes != 0)
            {
                $percent = $a_row->intVotes1 / $a_row->intTotalVotes;
                $percent *= 100;
            }
            else
            {
                $percent = 0;
            }
            $postthis = $a_row->strOption1;
            include ("formatposts.php");
            print "<tr><td><font size=$fontsize face=$font><center>$postthis&nbsp;</td><td><font size=$fontsize face=$font>($a_row->intVotes1)&nbsp;</td>
            <td>";
            $count=0;
            while ($count < $percent)
            {
                print "<image src=\"images/vote.jpg\" width=4 height=10 border=0>";
                $count ++;
            }

            print "</td></tr>";
        }


        if ($a_row->strOption2 != "")
        {
            if ($a_row->intVotes2 != 0 AND $a_row->intTotalVotes != 0)
            {
                $percent = $a_row->intVotes2 / $a_row->intTotalVotes;
                $percent *= 100;
            }
            else
            {
                $percent = 0;
            }
            $postthis = $a_row->strOption2;
            include ("formatposts.php");
            print "<tr><td><font size=$fontsize face=$font><center>$postthis&nbsp;</td><td><font size=$fontsize face=$font>($a_row->intVotes2)&nbsp;</td>
            <td>";
            $count=0;
            while ($count < $percent)
            {
                print "<image src=\"images/vote.jpg\" width=4 height=10 border=0>";
                $count ++;
            }

            print "</td></tr>";
        }

        if ($a_row->strOption3 != "")
        {
            if ($a_row->intVotes3 != 0 AND $a_row->intTotalVotes != 0)
            {
                $percent = $a_row->intVotes3 / $a_row->intTotalVotes;
                $percent *= 100;
            }
            else
            {
                $percent = 0;
            }
            $postthis = $a_row->strOption3;
            include ("formatposts.php");
            print "<tr><td><font size=$fontsize face=$font><center>$postthis&nbsp;</td><td><font size=$fontsize face=$font>($a_row->intVotes3)&nbsp;</td>
            <td>";
            $count=0;
            while ($count < $percent)
            {
                print "<image src=\"images/vote.jpg\" width=4 height=10 border=0>";
                $count ++;
            }

            print "</td></tr>";
        }

        if ($a_row->strOption4 != "")
        {
            if ($a_row->intVotes4 != 0 AND $a_row->intTotalVotes != 0)
            {
                $percent = $a_row->intVotes4 / $a_row->intTotalVotes;
                $percent *= 100;
            }
            else
            {
                $percent = 0;
            }
            $postthis = $a_row->strOption4;
            include ("formatposts.php");
            print "<tr><td><font size=$fontsize face=$font><center>$postthis&nbsp;</td><td><font size=$fontsize face=$font>($a_row->intVotes4)&nbsp;</td>
            <td>";
            $count=0;
            while ($count < $percent)
            {
                print "<image src=\"images/vote.jpg\" width=4 height=10 border=0>";
                $count ++;
            }

            print "</td></tr>";
        }

        if ($a_row->strOption5 != "")
        {
            if ($a_row->intVotes5 != 0 AND $a_row->intTotalVotes != 0)
            {
                $percent = $a_row->intVotes5 / $a_row->intTotalVotes;
                $percent *= 100;
            }
            else
            {
                $percent = 0;
            }
            $postthis = $a_row->strOption5;
            include ("formatposts.php");
            print "<tr><td><font size=$fontsize face=$font><center>$postthis&nbsp;</td><td><font size=$fontsize face=$font>($a_row->intVotes5)&nbsp;</td>
            <td>";
            $count=0;
            while ($count < $percent)
            {
                print "<image src=\"images/vote.jpg\" width=4 height=10 border=0>";
                $count ++;
            }

            print "</td></tr>";
        }

        if ($a_row->strOption6 != "")
        {
            if ($a_row->intVotes6 != 0 AND $a_row->intTotalVotes != 0)
            {
                $percent = $a_row->intVotes6 / $a_row->intTotalVotes;
                $percent *= 100;
            }
            else
            {
                $percent = 0;
            }
            $postthis = $a_row->strOption6;
            include ("formatposts.php");
            print "<tr><td><font size=$fontsize face=$font><center>$postthis&nbsp;</td><td><font size=$fontsize face=$font>($a_row->intVotes6)&nbsp;</td>
            <td>";
            $count=0;
            while ($count < $percent)
            {
                print "<image src=\"images/vote.jpg\" width=4 height=10 border=0>";
                $count ++;
            }

            print "</td></tr>";
        }

        if ($a_row->strOption7 != "")
        {
            if ($a_row->intVotes7 != 0 AND $a_row->intTotalVotes != 0)
            {
                $percent = $a_row->intVotes7 / $a_row->intTotalVotes;
                $percent *= 100;
            }
            else
            {
                $percent = 0;
            }
            $postthis = $a_row->strOption7;
            include ("formatposts.php");
            print "<tr><td><font size=$fontsize face=$font><center>$postthis&nbsp;</td><td><font size=$fontsize face=$font>($a_row->intVotes7)&nbsp;</td>
            <td>";
            $count=0;
            while ($count < $percent)
            {
                print "<image src=\"images/vote.jpg\" width=4 height=10 border=0>";
                $count ++;
            }

            print "</td></tr>";
        }

        if ($a_row->strOption8 != "")
        {
            if ($a_row->intVotes8 != 0 AND $a_row->intTotalVotes != 0)
            {
                $percent = $a_row->intVotes8 / $a_row->intTotalVotes;
                $percent *= 100;
            }
            else
            {
                $percent = 0;
            }
            $postthis = $a_row->strOption8;
            include ("formatposts.php");
            print "<tr><td><font size=$fontsize face=$font><center>$postthis&nbsp;</td><td><font size=$fontsize face=$font>($a_row->intVotes8)&nbsp;</td>
            <td>";
            $count=0;
            while ($count < $percent)
            {
                print "<image src=\"images/vote.jpg\" width=4 height=10 border=0>";
                $count ++;
            }

            print "</td></tr>";
        }

        if ($a_row->strOption9 != "")
        {
            if ($a_row->intVotes9 != 0 AND $a_row->intTotalVotes != 0)
            {
                $percent = $a_row->intVotes9 / $a_row->intTotalVotes;
                $percent *= 100;
            }
            else
            {
                $percent = 0;
            }
            $postthis = $a_row->strOption9;
            include ("formatposts.php");
            print "<tr><td><font size=$fontsize face=$font><center>$postthis&nbsp;</td><td><font size=$fontsize face=$font>($a_row->intVotes9)&nbsp;</td>
            <td>";
            $count=0;
            while ($count < $percent)
            {
                print "<image src=\"images/vote.jpg\" width=4 height=10 border=0>";
                $count ++;
            }

            print "</td></tr>";
        }

        if ($a_row->strOption10 != "")
        {
            if ($a_row->intVotes10 != 0 AND $a_row->intTotalVotes != 0)
            {
                $percent = $a_row->intVotes10 / $a_row->intTotalVotes;
                $percent *= 100;
            }
            else
            {
                $percent = 0;
            }
            $postthis = $a_row->strOption10;
            include ("formatposts.php");
            print "<tr><td><font size=$fontsize face=$font><center>$postthis&nbsp;</td><td><font size=$fontsize face=$font>($a_row->intVotes10)&nbsp;</td>
            <td>";
            $count=0;
            while ($count < $percent)
            {
                print "<image src=\"images/vote.jpg\" width=4 height=10 border=0>";
                $count ++;
            }

            print "</td></tr>";
        }


        if ($a_row->intVotes11 != 0 AND $a_row->intTotalVotes != 0)
        {
            $percent = $a_row->intVotes11 / $a_row->intTotalVotes;
            $percent *= 100;
        }
        else
        {
            $percent = 0;
        }
        print "<tr><td><font size=$fontsize face=$font><center>Abstain&nbsp;</td><td><font size=$fontsize face=$font>($a_row->intVotes11)&nbsp;</td>
        <td>";
        $count=0;
        while ($count < $percent)
        {
            print "<image src=\"images/vote.jpg\" width=4 height=10 border=0>";
            $count ++;
        }

        print "</td></tr>";



        print "</td></tr><br></td></tr></table></td></tr></table><br></td></tr></table>";
    }
}
