<?php
// $Id: poll.html.php,v 1.14 2004/03/25 21:28:10 rcastley Exp $
/**
* Content code
* @package Mambo Open Source
* @Copyright (C) 2000 - 2003 Miro International Pty Ltd
* @ All rights reserved
* @ Mambo Open Source is Free Software
* @ Released under GNU/GPL License : http://www.gnu.org/copyleft/gpl.html
* @version $Revision: 1.14 $
**/

defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

class poll_html {
	
	function showResults( &$poll, &$votes, $first_vote, $last_vote, $pollist ) {
		global $mosConfig_live_site;
		?>
<link rel="stylesheet" href="components/com_poll/poll_bars.css" type="text/css" />
<form name="poll" id="poll"> 
  <table cellpadding="0" cellspacing="4" border="0" width="100%" class="contentpane"> 
    <tr> 
      <td class="componentheading"><?php echo _POLL_TITLE; ?></td> 
    </tr> 
    <tr> 
     <td align="center"> 
      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="contentpane"> 
      <tr> 
          <td align="left"><?php echo _SEL_POLL; ?>&nbsp;</td> 
          <td align="left"><?php echo $pollist; ?></td> 
        </tr> 
      <tr> 
       <td>&nbsp;</td> 
      <td> 
      <table cellpadding="1" cellspacing="0" border="0" width="100%" class="contentpane"> <tr> 
         <td> 
         <table cellpadding="0" cellspacing="0" border="0"> 
          <tr> 
             <td> <?php
		if ($votes) {
			$j=0;
			$data_arr["text"]=null;
			$data_arr["hits"]=null;
			foreach ($votes as $vote) {
				$data_arr["text"][$j]=trim($vote->text);
				$data_arr["hits"][$j]=$vote->hits;
				$j++;
			}
			graphit($data_arr, $poll->title, $first_vote, $last_vote);
		} else {
			?>
          <tr> 
             <td valign="bottom"><?php echo _NO_RESULTS; ?></td> 
           </tr> 
          <?php
		}
		?> 
          </td> 
          </tr> 
           </table> 
          </td> 
           </tr> 
            </table> 
      </td> 
       </tr> 
        </table> 
    </td> 
     </tr> 
      </table> 

</form> 
<?php }
}

function graphit(&$data_arr, $graphtitle, $first_vote, $last_vote) {
	
	global $mosConfig_live_site, $polls_maxcolors, $tabclass,
	$polls_barheight, $polls_graphwidth, $polls_barcolor;
	
	$tabclass_arr = explode( ",", $tabclass );
	$tabcnt = 0;
	$colorx = 0;
	$maxval = 0;
	
	array_multisort( $data_arr["hits"], SORT_NUMERIC,SORT_DESC, $data_arr["text"] );
	
	foreach($data_arr["hits"] as $hits) {
		if ($maxval < $hits) {
			$maxval = $hits;
		}
	}
	$sumval = array_sum( $data_arr["hits"] );
?> 
<br /> 
<table class='pollstableborder' cellspacing="0" cellpadding="0" border="0"> 
  <tr> 
    <td colspan="2" class="sectiontableheader"> <img src="<?php echo $mosConfig_live_site; ?>/components/com_poll/images/poll.png "align="absmiddle" border="0" width="12" height="14" /> <?php echo $graphtitle; ?> </td> 
  </tr> 
  <?php

for ($i=0, $n=count($data_arr["text"]); $i < $n; $i++) {
	$text = &$data_arr["text"][$i];
	$hits = &$data_arr["hits"][$i];
	
	if ($maxval > 0 && $sumval > 0) {
		$width = ceil( $hits*$polls_graphwidth/$maxval );
		$percent = round( 100*$hits/$sumval, 1 );
	} else {
		$width = 0;
		$percent = 0;
	}
		?> 
  <tr class="<?php echo $tabclass_arr[$tabcnt]; ?>"> 
    <td width='100%' colspan='2'><?php echo $text; ?></td> 
  </tr> 
  <tr class="<?php echo $tabclass_arr[$tabcnt]; ?>"> 
    <td> <table cellspacing="0" cellpadding="0" border="0" width="100%">

        <tr class='<?php echo $tabclass_arr[$tabcnt]; ?>'> 
          <td align="right" width="25"> <b><?php echo $hits; ?></b> </td> 
          <td align="left" width="2">&nbsp; </td> 
          <td width="30" align="left"> <?php echo $percent; ?>% </td> 
          <?php
		$tdclass='';
		if ($polls_barcolor==0) {
			if ($colorx < $polls_maxcolors) {
				$colorx = ++$colorx;
			} else {
				$colorx = 1;
			}
			$tdclass = "polls_color_".$colorx;
		} else {
			$tdclass = "polls_color_".$polls_barcolor;
		}
	?> 
          <td width="300" align="left"> 
            <div align="left">&nbsp;<img src='<?php echo $mosConfig_live_site; ?>/components/com_poll/images/blank.png' class='<?php echo $tdclass; ?>' height='<?php echo $polls_barheight; ?>' width='<?php echo $width; ?>'> 
            </div></td> 
        </tr> 
      </table></td> 
  </tr> 
  <?php
	$tabcnt = 1 - $tabcnt;
}
	?> 

</table> 
<br> 
<table cellspacing="0" cellpadding="0" border="0"> 
  <tr> 
    <td class='smalldark'> <?php echo _NUM_VOTERS; ?> </td> 
    <td class='smalldark'> &nbsp;:&nbsp;<?php echo $sumval; ?> </td> 
  </tr> 
  <tr> 
    <td class='smalldark'> <?php echo _FIRST_VOTE; ?> </td> 
    <td class='smalldark'> &nbsp;:&nbsp;<?php echo $first_vote; ?> </td> 
  </tr> 
  <tr> 
    <td class='smalldark'> <?php echo _LAST_VOTE; ?> </td> 
    <td class='smalldark'> &nbsp;:&nbsp;<?php echo $last_vote; ?> </td> 
  </tr> 

</table> 
<?php
}
?>
