<?php
if( !defined( 'SMARTY_DIR' ) ) {
	require_once( 'init.php' );
}

$pollid = $_GET['pollid'];

$rsQ =& $osDB->getRow( 'SELECT question, date from ! WHERE pollid = ?', array( POLLS_TABLE, $pollid ) );

$numtotal =  $osDB->getOne( 'SELECT sum( result ) as sm FROM ! WHERE pollid = ?', array( POLLOPTS_TABLE, $pollid ) );

$sqOpt =& $osDB->getAll( 'SELECT opt, result FROM ! WHERE pollid = ? order by optionid', array( POLLOPTS_TABLE, $pollid ) );

$date =  date( LONG_DATE_FORMAT, $rsQ['date'] );

$t->assign( 'question', stripslashes( $rsQ['question'] ) );
unset($rsQ);
$i = 1;

$data = array();

foreach( $sqOpt as $index => $rsOpt ) {

	$rsOpt['c'] = $i;

	if( $numtotal !=  0 ) {
		 $rsOpt['numw']  =  number_format( ( $rsOpt['result'] / $numtotal ) * 100, 2 );
	} else {
		$rsOpt['numw']  =  0;
	}

	$data[$index] = $rsOpt;

	$i++;
}

$t->assign( 'data', $data );

unset($sqOpt, $data );

$t->assign( 'numtotal',$numtotal );

$t->assign( 'title', get_lang('poll_result') );

$t->assign( 'err',$err );

$t->display( 'viewresult.tpl' );


?>