home *** CD-ROM | disk | FTP | other *** search
Wrap
PHPolls PHPolls creates simple polls with a graphical display of the results. <? /* ///////// PHPOLLS v2.1 ///////// Copyright 2000, Mathias Daval / PHPVault (http://www.phpvault.com) ////////////////////////////////////////////////////////////////////////// Ce script est un freeware. Vous pouvez l'utiliser et le modifier librement, mais vous devez laisser le copyright. Merci de me faire savoir si vous trouvez ce script utile. (webmaster@phpvault.com) PHPolls permet de crΘer des sondages avec un affichage graphique des rΘsultats, sans avoir besoin de base de donnΘes. ///////////////////////////////////////////////////////////////////////// This script is a freeware. You can use it and modify it freely as long as you leave the copyright. Please tell me if you find this script useful (webmaster@phpvault.com) PHPolls allows the webmaster to create online polls, with graphical display of the results, with no need of database. ///////////////////////////////////////////////////////////////////////// Installation: 1. Copy this file in the directory of your choice (must be accessible to reading and writing) / Copier ce fichier dans le rΘpertoire de votre choix, (accessible en lecture et en Θcriture) 2. Create a blank file called votes.dat / CrΘer un fichier vierge appelΘ votes.dat. 3. Create a file called data.dat which contains the choices of your poll (1 line per choice) / CrΘer un fichier appelΘ data.dat qui contient les choix de votre sondage (1 ligne par choix) 4. Choose an image for the graphical display of the results / Choisissez une image pour l'affichage des rΘsultats. 5. Insert the poll wherever you want in a PHP page with the line / InsΘrer le sondage α l'endroit souhaitΘ dans une page en PHP avec la ligne : <? require("path/to/phpolls.inc"); ?> /////////////////////////////////////////////////////////////////////// */ /* Chemin d'accΦs α data.dat / Path to data.dat */ $data="data.dat"; /* Chemin d'accΦs α votes.dat / Path to votes.dat */ $votes="votes.dat"; /* Chemin d'accΦs au fichier image / Path to the image file */ $path_img="red.gif"; /* Nom de votre sondage / Name of your poll */ $poll_name="Where are you from ?"; /////////////////////////////// // NOTHING TO CHANGE BELOW // /////////////////////////////// $dataf=file("data.dat"); if ($go !=1) { /* Impression des choix */ echo "<center><i>$poll_name</i></center><br>\n"; echo "<form method=post>"; for ($i=0; $i<=count($dataf)-1; $i++) { echo "<input type=radio name=\"vote\" value=\"$i\"> $dataf[$i]<br>\n"; } echo "<input type=hidden name=go value=1>"; echo "<p><center><input type=submit value=Vote>"; echo "</form>"; echo "<a href='index.php3?result=1&go=1'>Results</a></center>"; } else { $file_votes=fopen($votes, "r"); $line_votes=fgets($file_votes, 255); $single_vote=explode("|", $line_votes); fclose($file_votes); if ($result!=1) { /* Log du vote */ $file_votes=file($votes, "r"); if ($REMOTE_ADDR == $file_votes[1]) { echo "<center><font color=red>You have already voted</font></center>"; exit; } $ficdest=fopen($votes, "w"); for ($i=0; $i<=count($dataf)-1; $i++) { if ($i == $vote) { $single_vote[$i]+=1; } fputs($ficdest, "$single_vote[$i]|"); } fclose($ficdest); $ficdest=fopen($votes, "a"); fputs($ficdest, "\n$REMOTE_ADDR"); fclose($ficdest); $result=1; } if ($result==1) { /* Affichage des rΘsultats */ echo "<table cellpadding=10>"; echo "<tr><td align=center><font face=Verdana size=2>"; echo "<i>Choice</i></font>"; echo "</td><td align=center><font face=Verdana size=2>"; echo "<i>%</i></font></td>"; echo "<td align=center><font face=Verdana size=2>"; echo "<i>Votes</i></font></td></tr>"; for ($i=0; $i<=count($dataf)-1; $i++) { $tot_votes+=$single_vote[$i]; } for ($i=0; $i<=count($dataf)-1; $i++) { $stat[$i]=$single_vote[$i]/$tot_votes*100; echo "<tr><td><li><font face=Verdana size=2>"; echo "$dataf[$i]</font></td><td align=left><font face=Verdana size=2>"; echo "<img src=\"$path_img\" height=10 width=$stat[$i] align=middle> "; printf("%.1f", "$stat[$i]"); echo "%</font></td><td align=center><font face=Verdana size=2>"; echo "$single_vote[$i]</font>"; echo "</td></tr>"; } echo "</table><p>"; echo "<center>Total: $tot_votes votes</center>"; } } ?>