<?php
include "top.php";
include "utils.php";

$polls = file("polls.txt");

foreach ($polls as $pollname)
{
	preg_match("/^(!)?(\d+):(.*)$/s", $pollname, $m);
	$pollname = $m[3];
	$num = $m[2];
	echo "<h3>$pollname</h3>\n";
	$nom = file("$num/nom.txt");
	$res = file("$num/res.txt");
	$nnum = 0;
	$max = 0;
	$names = $codes = $results = array();
	for ($i = 0; $i < count($nom); $i += 2)	
	{
		$names[$nnum] = $nom[$i];
		$codes[$nnum] = $nom[$i+1];
		$results[$nnum] = intval($res[$nnum]);		
		if ($results[$nnum] > $max)
			$max = $results[$nnum];
		$nnum++;
	}
	#arsort($results, SORT_NUMERIC);
	if ($max == 0)
	{
		echo "Результаты недоступны<br />";
	}
	else
	{
		echo "<table border='0' cellpadding='5px'>\n";
		foreach ($results as $nnum => $rating)
		{
			$precent = ($rating/$max)*100;
			echo "<tr><td style='font-size:13px;'>{$names[$nnum]}</td><td width='100px'><div style='background: black; width: {$precent}px; height: 12px'></div></td><td>$rating</td></tr>\n";
		}
		echo "</table>";
	}
}

echo "<br /><a href='index.php'>Вернуться к прослушиванию&hellip;</a>";
include "bottom.php";
?>