<?php
$tpl->newBlock("osnovna_polja");
$tpl->assign("naslov", "Vprašanje");
$tpl->assign("vsebina", $r['anketa']);

$tpl->newBlock("osnovna_polja");
$tpl->assign("naslov", "Status ankete");
switch($r['enabled'])
{
	case 1:
		$status = "aktiven";
		break;
	case 0:
		$status = "neaktiven";
		break;
}

$tpl->assign("vsebina", $status);

$result2 = $db->query("SELECT SUM(st_glasov) AS vsi_glasovi FROM modul_anketa_odgovori WHERE anketa_id = '$clean[id]'");
$r2 = $result2->fetch();
if(!$r2['vsi_glasovi'])
{
	$r2['vsi_glasovi'] = 0;
}
$tpl->newBlock("osnovna_polja");
$tpl->assign("naslov", "Število glasov");
$tpl->assign("vsebina", $r2['vsi_glasovi']);

$tpl->newBlock("multipla_polja");
$tpl->assign("naslov", "Odgovori");
$result1 = $db->query("SELECT anketa_id, odgovor, st_glasov, SUM(st_glasov) AS vsi_glasovi FROM modul_anketa_odgovori GROUP BY odgovor HAVING anketa_id = '$clean[id]'");
while($r1 = $result1->fetch())
{

	if($r2['vsi_glasovi'])
	{
		$procent = round(100 / $r2['vsi_glasovi'] * $r1['st_glasov'], 1);
	}
	else
	{
		$procent = 0;
	}

	$tpl->newBlock("multipla_polja_vsebina");

	switch($r1['st_glasov'])
	{
		case 1:
			$g_prikaz = "glas";
		break;
		case 2:
			$g_prikaz = "glasova";
		break;
		case 3:
		case 4:
			$g_prikaz = "glasovi";
		break;
		default:
			$g_prikaz = "glasov";
		break;

	}
	$tpl->assign("vsebina", $r1['odgovor']."<br /><small>".$r1['st_glasov']. " ".$g_prikaz.", ".$procent."%</small>");

}

?>