Version: 0.1
Type: Full Script
Category: Voting
License: GNU General Public License
Description: Allows visitors to vote upon questions and post there own.
<? /* ==================================================================== * Copyright (c) 2001 Huw, [email protected] * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of the code in any formmust retain the above * copyright notice, this list of conditions and the following * disclaimer. * * 2. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== */ include "html.inc"; $pole = "pole.dat"; $data = ""; $cfile = ""; $dfile = ""; global $view; global $page; global $results; global $topic; global $ans; global $email; global $guest; global $option1; global $option2; global $option3; global $question; if (! ($view) ) $view = "view"; $afile = file($pole); if (! ($page) ) $page = 1; if (! ($results) ) $results = 5; $Count_back_value1 = $page * $results; $nxt_page = $page + 1; $lst_page = $page - 1; if ($view == "add") { if (! ($email && $guest && $option1 && $option2 && $option3 && $question) ) { $title = "Submit A New Question"; $data = <<<EOT <form action="pole.php" name="pole" onSubmit="return pole.php"> <table align="center" cellspacing="0" cellpadding="0" border="0"> <tr> <td align="right" valign="top">Name :</td> <td valign="top"> <input type="text" name="guest" size="30" class="textbox" id="input"> <input name="view" id="input" type="hidden" value="add"> </td> </tr> <tr> <td align="right" valign="top">Email :</td> <td valign="top"><input type="text" name="email" size="30" class="textbox" id="input"></td> </tr> <tr> <td align="right" valign="top">Question :</td> <td valign="top"><input type="text" name="question" size="30" class="textbox" id="input"></td> </tr> <tr> <td align="right" valign="top">Option 1 :</td> <td valign="top"><input type="text" name="option1" size="30" class="textbox" id="input"></td> </tr> <tr> <td align="right" valign="top">Option 2 :</td> <td valign="top"><input type="text" name="option2" size="30" class="textbox" id="input"></td> </tr> <tr> <td align="right" valign="top">Option 3 :</td> <td valign="top"><input type="text" name="option3" size="30" class="textbox" id="input"></td> </tr> <tr> <td align="right" valign="top"></td> <td valign="top"> <input type="Submit" name="submit" value="Submit" class="button"> <input type="Reset" name="reset" value="Reset" class="button"><br> <center> All fields are Required </center> </td> </tr> </table> </form> EOT; } else { $afile = file($pole); $title = "Posting Compleat"; $data = "Thank You For Wanting Peoples Oppinions"; $posted_on = date('D F dS Y'); if (file_exists($pole)) { $poleentry = "n$guest|$email|$question|$option1|$option2|$option3|$posted_on|0|0|0"; $file = fopen($pole,"a"); fputs($file,$poleentry); if(flock($file,3)) fclose($file); else $data = "Error: couldn't close file"; } } } else if ($view == "view") { $title = "Viewing The Questions"; if (file_exists($pole)) { if ((count($afile)) > $Count_back_value1+1) { $Count_back_value2 = $Count_back_value1-$results+1; $Count_to = count($afile)-$Count_back_value1-1; for($num = count($afile)-$Count_back_value2; $num > $Count_to; $num--) { $pt7 = "0"; $pt8 = "0"; $pt9 = "0"; $bfile = explode("|",$afile[$num]); $Tmp = $data; $pt = $bfile[7] + $bfile[8] + $bfile[9]; if ($pt) { $pt7 = "100" / $pt * $bfile[7]; $pt8 = "100" / $pt * $bfile[8]; $pt9 = "100" / $pt * $bfile[9]; } $data = <<<EOT <table border="0" cellpadding="0" cellspacing="2" width="85%"> <tr> <td width="10%" align="right" valign="top"> Question :<br> By : </td> <td width="50%" valign="top"> $bfile[2]<br> $bfile[0] </td> </tr> <tr> <td width="10%" align="right" valign="top"> $bfile[3] :<br> $bfile[4] :<br> $bfile[5] : </td> <td width="50%" valign="top"> $bfile[7] votes - $pt7 % - <a href="pole.php?view=vote&topic=$num&ans=7">Vote</a><br> $bfile[8] votes - $pt8 % - <a href="pole.php?view=vote&topic=$num&ans=8">Vote</a><br> $bfile[9] votes - $pt9 % - <a href="pole.php?view=vote&topic=$num&ans=9">Vote</a> </td> </tr> </table><br> EOT; $Tmp2 = $data; $data = $Tmp . $Tmp2; } $Tmp = $data; if ($page < 2) $data = $Tmp . "<br><a>Previous Page</a> - n<a href='pole.php?view=view&page=$nxt_page&results=5'>Next Page</a>"; else if ($page > 1) $data = $Tmp . "<br><a href='pole.php?view=view&page=$lst_page&results=5'>Previous Page</a> - n<a href='pole.php?view=view&page=$nxt_page&results=5'>Next Page</a>"; } else { $Count_to = count($afile) - $Count_back_value1 + $results - 1; for($num = $Count_to; $num > 0; $num--) { $pt7 = "0"; $pt8 = "0"; $pt9 = "0"; $bfile = explode("|",$afile[$num]); $Tmp = $data; $pt = $bfile[7] + $bfile[8] + $bfile[9]; if ($pt) { $pt7 = "100" / $pt * $bfile[7]; $pt8 = "100" / $pt * $bfile[8]; $pt9 = "100" / $pt * $bfile[9]; } $data = <<<EOT <table border="0" cellpadding="0" cellspacing="2" width="85%"> <tr> <td width="10%" align="right" valign="top"> Question :<br> By : </td> <td width="50%" valign="top"> $bfile[2]<br> $bfile[0] </td> </tr> <tr> <td width="10%" align="right" valign="top"> $bfile[3] :<br> $bfile[4] :<br> $bfile[5] : </td> <td width="50%" valign="top"> $bfile[7] votes - $pt7 % - <a href="pole.php?view=vote&topic=$num&ans=7">Vote</a><br> $bfile[8] votes - $pt8 % - <a href="pole.php?view=vote&topic=$num&ans=8">Vote</a><br> $bfile[9] votes - $pt9 % - <a href="pole.php?view=vote&topic=$num&ans=9">Vote</a> </td> </tr> </table><br> EOT; $Tmp2 = $data; $data = $Tmp . $Tmp2; } $Tmp = $data; if ($page < 2) $data = $Tmp . "<br><a>Previous Page</a> - n<a>Next Page</a>"; else if ($page > 1) $data = $Tmp . "<br><a href='pole.php?view=view&page=$lst_page&results=5'>Previous Page</a> - n<a>Next Page</a>"; } } else { $data = "Error: blank file"; } } else if ($view == "vote") { $title = "Voting Compleat"; $data = "Thank You For Voting"; if (file_exists($pole)) { $afile = file($pole); $bfile = explode("|",$afile[$topic]); $bfile[$ans]++; $poleentry = "$bfile[0]|$bfile[1]|$bfile[2]|$bfile[3]|$bfile[4]|$bfile[5]|$bfile[6]|$bfile[7]|$bfile[8]|$bfile[9]"; for ($i = 0; $i < $topic; $i++) { $Tmp = $cfile; $cfile = $Tmp . $afile[$i]; } for ($i = $topic+1; $i < count($afile); $i++) { $Tmp = $dfile; $dfile = $Tmp . $afile[$i]; } $file = fopen($pole,"r+"); fwrite($file,$cfile . $poleentry . $dfile); if(flock($file,3)) fclose($file); else $data = "Error: couldn't close file"; } } echo $above_title; echo "n<TITLE>" . $title . "</TITLE>n"; echo $below_title; echo "n <div class='end'>" . $title . "</div>n"; echo "<center>n<a href='pole.php?view=view&results=5&page=1'>View the poles</a> - <a href='pole.php?view=add'>Add a question</a><br>n</center>"; echo $data; echo $base_html; ?>