<?php


$data =& $osDB->getAll( 'SELECT pollid FROM ! WHERE enabled = ? AND active = ? and date >= ?', array( POLLS_TABLE, 'Y', '1', time() ) );

if (count($data) > 0)  {

	srand((float) microtime() * 10000000);

	$key = array_rand($data, 1);

	$pollid = $data[$key]['pollid'];

	$row =& $osDB->getAll( 'SELECT * FROM ! WHERE pollid = ? ', array( POLLS_TABLE, $pollid ) );

	$options =& $osDB->getAll( 'SELECT * FROM ! WHERE pollid = ? ', array( POLLOPTS_TABLE, $pollid ) );

	$row['curtime'] = time();

	$row['question'] = stripslashes( $row['question'] );

	$row['options'] = poll_opts( $options );
	unset($options);
	$t->assign( 'poll_data', $row );

	unset($row);
}

function poll_opts( $options )
{
	$result = array();

	foreach( $options as $index => $row ) {

		$result[ $row['optionid'] ] = $row;
	}

	return $result;
}
?>
