home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / PHP / phppolls.php3.txt < prev    next >
Encoding:
Text File  |  2002-05-06  |  4.9 KB  |  124 lines

  1. PHPolls 
  2.  
  3. PHPolls creates simple polls with a graphical display of the results. 
  4.  
  5.  
  6. <? 
  7. /* 
  8. ///////// PHPOLLS v2.1 
  9. ///////// 
  10.  
  11. Copyright 2000, Mathias Daval / PHPVault (http://www.phpvault.com) 
  12. ////////////////////////////////////////////////////////////////////////// 
  13. 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) 
  14. PHPolls permet de crΘer des sondages avec un affichage graphique des rΘsultats, sans avoir besoin de base de donnΘes. 
  15. ///////////////////////////////////////////////////////////////////////// 
  16. 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 
  17. (webmaster@phpvault.com) 
  18. PHPolls allows the webmaster to create online polls, with graphical display of the results, with no need of database. 
  19. ///////////////////////////////////////////////////////////////////////// 
  20. Installation: 
  21. 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) 
  22. 2. Create a blank file called votes.dat / CrΘer un fichier vierge appelΘ votes.dat. 
  23. 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) 
  24. 4. Choose an image for the graphical display of the results / Choisissez une image pour l'affichage des rΘsultats. 
  25. 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 : 
  26. <? require("path/to/phpolls.inc"); ?> 
  27. /////////////////////////////////////////////////////////////////////// */ 
  28.  
  29.  
  30. /* Chemin d'accΦs α data.dat / Path to data.dat */ 
  31. $data="data.dat"; 
  32.  
  33. /* Chemin d'accΦs α votes.dat / Path to votes.dat */ 
  34. $votes="votes.dat"; 
  35.  
  36. /* Chemin d'accΦs au fichier image / Path to the image file */ 
  37. $path_img="red.gif"; 
  38.  
  39. /* Nom de votre sondage / Name of your poll */ 
  40.  
  41. $poll_name="Where are you from ?"; 
  42.  
  43.  
  44. /////////////////////////////// 
  45. // NOTHING TO CHANGE BELOW // 
  46. /////////////////////////////// 
  47.  
  48. $dataf=file("data.dat"); 
  49.  
  50. if ($go !=1) { 
  51.      
  52.      /* Impression des choix */ 
  53.      echo "<center><i>$poll_name</i></center><br>\n"; 
  54.      echo "<form method=post>"; 
  55.      for ($i=0; $i<=count($dataf)-1; $i++) { 
  56.          echo "<input type=radio name=\"vote\" value=\"$i\"> $dataf[$i]<br>\n"; 
  57.      } 
  58.      echo "<input type=hidden name=go value=1>"; 
  59.      echo "<p><center><input type=submit value=Vote>"; 
  60.      echo "</form>"; 
  61.      echo "<a href='index.php3?result=1&go=1'>Results</a></center>"; 
  62.  
  63. else { 
  64.      
  65.      $file_votes=fopen($votes, "r"); 
  66.      $line_votes=fgets($file_votes, 255); 
  67.      $single_vote=explode("|", $line_votes); 
  68.      fclose($file_votes); 
  69.      
  70.      if ($result!=1) { 
  71.          
  72.          /* Log du vote */ 
  73.          $file_votes=file($votes, "r"); 
  74.          if ($REMOTE_ADDR == $file_votes[1]) { 
  75.              echo "<center><font color=red>You have already voted</font></center>"; 
  76.              exit; 
  77.          } 
  78.          
  79.          $ficdest=fopen($votes, "w"); 
  80.          for ($i=0; $i<=count($dataf)-1; $i++) { 
  81.              if ($i == $vote) { 
  82.                  $single_vote[$i]+=1; 
  83.              } 
  84.              fputs($ficdest, "$single_vote[$i]|"); 
  85.          } 
  86.          fclose($ficdest); 
  87.          $ficdest=fopen($votes, "a"); 
  88.          fputs($ficdest, "\n$REMOTE_ADDR"); 
  89.          fclose($ficdest); 
  90.          $result=1; 
  91.      } 
  92.      
  93.      if ($result==1) { 
  94.          
  95.          /* Affichage des rΘsultats */ 
  96.          echo "<table cellpadding=10>"; 
  97.          echo "<tr><td align=center><font face=Verdana size=2>"; 
  98.          echo "<i>Choice</i></font>"; 
  99.          echo "</td><td align=center><font face=Verdana size=2>"; 
  100.          echo "<i>%</i></font></td>"; 
  101.          echo "<td align=center><font face=Verdana size=2>"; 
  102.          echo "<i>Votes</i></font></td></tr>"; 
  103.          for ($i=0; $i<=count($dataf)-1; $i++) { 
  104.              $tot_votes+=$single_vote[$i]; 
  105.          } 
  106.          for ($i=0; $i<=count($dataf)-1; $i++) { 
  107.              $stat[$i]=$single_vote[$i]/$tot_votes*100; 
  108.              echo "<tr><td><li><font face=Verdana size=2>"; 
  109.              echo "$dataf[$i]</font></td><td align=left><font face=Verdana size=2>"; 
  110.              echo "<img src=\"$path_img\" height=10 width=$stat[$i] align=middle> "; 
  111.              printf("%.1f", "$stat[$i]"); 
  112.              echo "%</font></td><td align=center><font face=Verdana size=2>"; 
  113.              echo "$single_vote[$i]</font>"; 
  114.              echo "</td></tr>"; 
  115.          } 
  116.          echo "</table><p>"; 
  117.          echo "<center>Total: $tot_votes votes</center>"; 
  118.      } 
  119.  
  120. ?>
  121.  
  122.