Location: PHPKode > scripts > MW Poll2 > mwpoll/cast.php
<?php

include("config.php");
include("language.dat");

$file="poll.dat";

$t = $_GET['t'];

if ($t == 'v')
{
   if (isset($_COOKIE["MWpoll"]))
   { 
   echo $lang[2];
   return;
   }
         
   if (isset($_GET['c']))
   { 
   $c = $_GET['c']; 
       if (($c != 1) & ($c != 2) & ($c != 3) & ($c != 4))
       {
	   echo $lang[3];
	   return;
	   }
   }
   else
   { 
   echo $lang[4];
   return;
   }
   
    // Lettura votazioni
    if (!(file_exists($file)))
    {
	   for ($i=0;$i<4;$i++)
	   { $voti[$i] = 0;  }
	}
	else
	{

	$read_file = fopen($file,"r");
    $content = fread($read_file,filesize($file));
    fclose($read_file);	
	
	$voti = explode("|",$content);
    
	}

$voti[$c-1]++;    

$content = implode("|",$voti);

$write_file = fopen($file,"w");
fwrite($write_file,$content);
fclose($write_file);	

setcookie("MWpoll", "votato", time() + $timeout);

echo $lang[5];

}
else
{
    echo "<table border='0'>";
	echo "<tr><td width='140'><b>$lang[6]</b></td><td width='40'><b>$lang[7]</b></td></tr>";

    if (file_exists($file))
    {
    $read_file = fopen($file,"r");
    $content = fread($read_file,filesize($file));
    fclose($read_file);	 
    
	$arr_voti = explode("|",$content);
	    
		$tot_voti = 0;
		for ($i=1;$i<5;$i++)
	    {
			if ($choice[$i] != '')
			{
				$k=$i-1;	
				$tot_voti = $tot_voti + $arr_voti[$k];
				}
		}
	
	        for ($i=1;$i<5;$i++)
	        {
				if ($choice[$i] != '')
	            {
				$k=$i-1;	
				$perc = ($arr_voti[$k] * 100) / $tot_voti;
				echo "<tr><td width='140'>$choice[$i]</td><td width='40' align='center'>$arr_voti[$k]"."(".round($perc,0)."%".")"."</td></tr>";
				}  
			}
		}
	else
	{
		echo "<tr><td width='140'>$lang[8]</td><td width='40'>&nbsp;</td></tr>";
    }
 
 echo "</table>";   
}

?>
Return current item: MW Poll2