<?php
/*
  www.oscGold.com (C) Kamelia-Net Jacek Krysiak
  modul oscGold wer 4.0
*/
?>

<table align="center" cellspacing="0" cellpadding="2" border="0">
	<?php
	if (isset($HTTP_GET_VARS['pollid'])) {
	 $pollid=$HTTP_GET_VARS['pollid'];
	 } else {
	 $pollid=1;
	}
	$poll_query = tep_db_query("SELECT pollid, timeStamp FROM phesis_poll_desc WHERE pollid='".$pollid."'");
	$polls = tep_db_fetch_array($poll_query);
	$title_query = tep_db_query("SELECT optionText from phesis_poll_data where pollid='".$pollid."' and voteid='0' and language_id = '" . $languages_id . "'");
	$title = tep_db_fetch_array($title_query);
	?>
	<tr><td colspan="3" align="center" class="main"><font size="+1"><b><?php echo $title['optionText']?></b></font></td></tr>
	<tr><td colspan="3">&nbsp;</td></tr>
		<?php
		$result=tep_db_query("SELECT SUM(optionCount) AS sum FROM phesis_poll_data WHERE pollid='".$pollid."' and language_id = '" . $languages_id . "'");
		$polls=tep_db_fetch_array($result);
		$sum=$polls['sum'];
		$licznik = 0;
		for($i = 1; $i <= 12; $i++) {
			$result=tep_db_query("SELECT pollid, optiontext, optioncount, voteid FROM phesis_poll_data WHERE (language_id = '" . $languages_id . "') and (pollid='".$pollid."') AND (voteid='".$i."')");
			$polls=tep_db_fetch_array($result);
			$optiontext=$polls['optiontext'];
			$optioncount=$polls['optioncount'];
			if ($optiontext) {
			   if ($optiontext != '') {
				  $licznik++;
			   }	
			?>
			<?php
			if ($sum) {
			$percent = 100 * $optioncount / $sum;
			} else {
			$percent = 0;
			}
			?>
			<tr><td align="right" class="main">
				<b><?php echo $optiontext; ?></b> :</td><td align="left" class="main"><?php printf(" %.2f%% (%d)", $percent, $optioncount); ?>
				</td>
			<td align="left">
			<?php
			$percentInt = (int)$percent * 4 * 1 * .5;
			$percent2 = (int)$percent;
			?>					
			<?php
			if ($percent > 0) {
				?>
				<table width="<?echo $percentInt?>" cellspacing="0" cellpadding="0" border="0">
					<tr>
						<td height="5" width="100%" style="border:1px solid #000000;background:#fe8f00"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '5'); ?></td>
					</tr>	
				</table>				
				<?php
				} else {
				?>
				<table width="5" cellspacing="0" cellpadding="0" border="0">
					<tr>
						<td height="5" width="100%" style="border:1px solid #000000;background:#fe8f00"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '5'); ?></td>
					</tr>	
				</table>
				<?php
			}
			?>
			</td></tr>
			<?php			
			}
		}
	
	if ($licznik > 0) {
	
	$comments_query_raw = "select * from phesis_comments where pollid = '" . $pollid . "' and language_id = '" . $languages_id . "'";
	$comments_query = tep_db_query($comments_query_raw);
	
	if ((int)tep_db_num_rows($comments_query) > 0) {
		echo '<tr><td colspan="3">&nbsp;</td></tr>';
	}

    while ($comments = tep_db_fetch_array($comments_query)) {
	  if ($comments['customer_id'] != '0') {
	    $name_query = tep_db_query("select customers_firstname, customers_lastname from " . TABLE_CUSTOMERS . " where customers_id = '". $comments['customer_id'] . "'");
	    $name = tep_db_fetch_array($name_query);
	    $comment_name = $name['customers_firstname'] . " " . $name['customers_lastname'];
	  } else {
		$comment_name = $comments['name'];
	  }
	  $post_details = _COMMENTS_BY . "<u>" . $comment_name . "</u>" . _COMMENTS_ON . $comments['date'] . '<br>';
	  ?>
      <tr><td class="main" colspan="3"><b><?php echo $post_details; ?></b></td></tr>
      <tr><td class="main" colspan="3"><em><?php echo htmlspecialchars($comments['comment']); ?></em></td></tr>
      <?php
    }
	?>
	<tr><td class="main" colspan="3">
		<table align="center">
			<tr><td align="center">&nbsp;</td></tr>
			<tr><td align="center" class="main"><? echo _TOTALVOTES?> = <? echo $sum?></td></tr>
			<?php
			if (SHOW_POLL_COMMENTS == '1') {
				$komentarz = '<a href="'.tep_href_link('pollbooth.php','pollid='.$pollid.'&op=comment','NONSSL').'">'._ADD_COMMENTS.'</a> | ';
				} else {
				$komentarz = '';			
			}
			?>
			<tr><td align="center" class="main"><?php echo $komentarz; ?><a href="<?php echo tep_href_link('pollbooth.php','pollid='.$pollid.'&op=vote','NONSSL')?>"><? echo _VOTING?></a> | <a href="<? echo tep_href_link('pollbooth.php','op=list','NONSSL')?>"><?echo _OTHERPOLLS?></a></td></tr>
		</table>
	</td></tr>
	
	<?php } ?>
</table> 
