<!-- polls //-->
<?php
/*
osCommerce, Open Source E-Commerce Solutions 
http://www.oscommerce.com 

Copyright (c) 2003 osCommerce 

osCommRes, Services Oline 
http://www.oscommres.com 
Copyright (c) 2005 osCommRes 

Freeway eCommerce 
http://www.zac-ware.com/freeway 
Copyright (c) 2007 ZacWare 

Released under the GNU General Public License
*/
// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();
$hide = tep_hide_session_id();

function pollnewest() {
	global $customer_id;
	if (DISPLAY_POLL_HOW==3)  $extra_query=" and pollID='" . DISPLAY_POLL_ID . "'";	        
	if (!isset($customer_id))  $extra_query.=" and poll_type='0' ";		
	if (DISPLAY_POLL_HOW==2)  $order = 'voters DESC';
 	else $order = 'timestamp DESC';		
	$query= tep_db_query("select pollid FROM phesis_poll_desc where poll_open='0'".$extra_query."order by ".$order);	
	$count=tep_db_num_rows($query);
	$pollid = false;
	if (!DISPLAY_POLL_HOW==0 || $count==1) {
		if ($result=tep_db_fetch_array($query)) {
			$pollid = $result['pollid'];
		}
	} else {
		mt_srand((double) microtime() * 1000000);
		$rand = mt_rand(1,$count);
		for($i=0;$i<$rand;$i++) {
			$result=tep_db_fetch_array($query);
			$pollid = $result['pollid'];
			}
	}
	return $pollid;
}
//if (basename($PHP_SELF) !='pollbooth.php') {
$pollid=pollnewest();
if ($pollid) {
?>
  <tr>
	<td>
<?php
	$poll_query=tep_db_query("select polltitle, voters from phesis_poll_desc where pollid=$pollid and poll_open='0'");
	$poll_details=tep_db_fetch_array($poll_query);
	$info_box_contents = array();
  	$info_box_contents[] = array('align' => 'center',
                               'text'  => POLL_TITLE
                              );
  	new infoBoxHeading($info_box_contents, true, true);
  	$url = tep_href_link('pollbooth.php', 'op=results&pollid='.$pollid);
 	$content =  "<input type=\"hidden\" name=\"pollid\" value=\"".$pollid."\">\n";
  	$content .=  "<input type=\"hidden\" name=\"forwarder\" value=\"".$url."\">\n";
        $content .= "<tr class=\"polltitle\"><td colspan=\"2\">". $poll_details['polltitle'] . "</td></tr>";
	for ($i=1;$i<=12;$i++) {
	      $query=tep_db_query("select pollid, optiontext, optioncount, voteid from phesis_poll_data where (pollid=$pollid) and (voteid=$i)");
      	if ($result=tep_db_fetch_array($query)) {
     	 		if ($result['optiontext']) {
       		$content.= "<tr class=\"pollOptRow\"><td class=\"pollBoxRow\"><input type=\"radio\" name=\"voteid\" value=\"".$i."\"></td><td class=\"pollBoxRow\">".$result['optiontext']."</td></tr>";
       		}
    		}
	}
	$content .= "<tr class=\"pollFooter\"><td colspan=\"2\"><center><input type=\"submit\" value=\""._VOTE."\"></center>\n</td></tr>";
	$query=tep_db_query("select sum(optioncount) as sum from phesis_poll_data where pollid=$pollid");
	if ($result=tep_db_fetch_array($query)) {
		$sum=$result['sum'];
	}
	$content .= "<tr class=\"pollFooter\"><td colspan=\"2\" class=\"pollBoxText\"><center>[ <a href=\"pollbooth.php?op=results&amp;pollid=$pollid\">"._RESULTS."</a> | <a href=\"pollbooth.php?op=list\">"._POLLS."</a> ]</td></tr>";
  	$content .= "<tr class=\"pollFooter\"><td colspan=\"2\" class=\"pollBoxText\"><center>" . $sum . " "._VOTES."</center>\n</td></tr>";
$info_box_contents = array();
$info_box_contents[] = array('form' => '<form name="poll" method="post" action="'. tep_href_link('pollcollect.php') .'">',
                               'align' => 'left',
                               'text'  =>   $content
                              );
 new infoBox($info_box_contents);
$info_box_contents = array();
  $info_box_contents[] = array('align' => 'left',
'text'  => tep_draw_separator('pixel_trans.gif', '100%', '1')
                              );
  new infoboxFooter($info_box_contents, true, true);

?>
	</td>
  </tr>
<?php
} elseif (SHOW_NOPOLL==1) {
?>
  <tr>
	<td>
<?php
$info_box_contents = array();
$info_box_contents[] = array('align' => 'center',
                               'text'  => _NOPOLLS
                            );
new infoBoxHeading($info_box_contents, true, true);
$info_box_contents = array();
$info_box_contents[] = array('align' => 'center',
                              'text'  => _NOPOLLSCONTENT
                             );
new infoBox($info_box_contents);
$info_box_contents = array();
  $info_box_contents[] = array('align' => 'left',
'text'  => tep_draw_separator('pixel_trans.gif', '100%', '1')
                              );
  new infoboxFooter($info_box_contents, true, true);

?>
	</td>
  </tr>
<?php
}
//}
?>
<!-- polls-eof //-->
