<?php
/*
  $Id: pollbooth.php,v 1.1.1.1 2002/11/28 23:21:34 wilt Exp $

  The Exchange Project - Community Made Shopping!
  http://www.theexchangeproject.org

  Copyright (c) 2000,2001 The Exchange Project

  Released under the GNU General Public License
*/
  require('includes/application_top.php');
  require(DIR_WS_LANGUAGES . $language . '/pollbooth.php');
  $location = ' : <a href="' . tep_href_link('pollbooth.php', 'op=results', 'NONSSL') . '" class="headerNavigation"> ' . NAVBAR_TITLE_1 . '</a>';
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<LINK href="images/favicon.ico" rel="shortcut icon">
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<?php
// BOF: WebMakers.com Changed: Header Tag Controller v1.0
// Replaced by header_tags.php
if ( file_exists(DIR_WS_INCLUDES . 'header_tags.php') ) {
  require(DIR_WS_INCLUDES . 'header_tags.php');
} else {
?>
  <title><?php echo TITLE ?></title>
<?php
}
// EOF: WebMakers.com Changed: Header Tag Controller v1.0
?>
<base href="<?php echo (getenv('HTTPS') == 'on' ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
<link rel="stylesheet" type="text/css" href="<? echo THEMA_STYLE;?>">
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="3" cellpadding="3">
  <tr>
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
    </table></td>
<!-- body_text //-->
    <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
      <tr>
        <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
            <td align="right"><?php echo tep_image(DIR_WS_IMAGES . 'table_background_specials.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
      <tr>


<?php
if ($HTTP_GET_VARS['warn']) {
?>
          <tr class="headerError">
            <td class="headerError"><?echo (_WARNING);$warn=$HTTP_GET_VARS['warn'];eval("\$temp=$warn;");echo($temp);?></td>
          </tr>
<?php
}
?>
     <tr>
       <td>
       <table width="100%">
<?php
if (!isset($HTTP_GET_VARS['op'])) {
        $HTTP_GET_VARS['op']="list";
        }
switch ($HTTP_GET_VARS['op']) {
        case "results":
                if (isset($HTTP_GET_VARS['pollid'])) {
                        $pollid=$HTTP_GET_VARS['pollid'];
                } else {
                $pollid=1;
                }
                      $poll_query = tep_db_query("SELECT pollid, polltitle, timeStamp FROM phesis_poll_desc WHERE pollid='".$pollid."'");
                        $polls = tep_db_fetch_array($poll_query);
?>
                <tr><td colspan="2" align="center"><b><br><br><?echo $polls['polltitle']?></b></td></tr>
                <tr><td>&nbsp;</td></tr>
<?php
                        $query="SELECT SUM(optionCount) AS sum FROM phesis_poll_data WHERE pollid='".$pollid."'";

                        $result=tep_db_query($query);
                        $polls=tep_db_fetch_array($result);
                        $sum=$polls['sum'];
                        for($i = 1; $i <= 12; $i++) {
                                $query = "SELECT pollid, optiontext, optioncount, voteid FROM phesis_poll_data WHERE (pollid='".$pollid."') AND (voteid='".$i."')";
                                $result=tep_db_query($query);$polls=tep_db_fetch_array($result);
                                $optiontext=$polls['optiontext'];
                                $optioncount=$polls['optioncount'];
                                if ($optiontext) {
?>
                                        <tr><td align="right">
                                        <?php echo $optiontext?></td>
<?php
                                        if ($sum) {
                                                $percent = 100 * $optioncount / $sum;
                                                } else {
                                                $percent = 0;
                                                }
?>
                                        <td align="left">
<?php
                                        $percentInt = (int)$percent * 4 * 1;
                                        $percent2 = (int)$percent;
                                        if ($percent > 0) {
?>
                                                   <img src="images/leftbar.gif" height="15" width="7" Alt="<?echo $percent2?> %"><img src="images/mainbar.gif" height="15" width="<?echo $percentInt?>" Alt="<?echo $percent2?> %"><img src="images/rightbar.gif" height="15" width="7" Alt="<?echo $percent2?> %">
<?php

                                                } else {
?>
                                                    <img src="images/leftbar.gif" height="15" width="7" Alt="<? echo $percent2?> %"><img src="images/mainbar.gif" height="15" width="3" Alt="<? echo $percent2?> %"><img src="images/rightbar.gif" height="15" width="7" Alt="<? echo $percent2?> %">
<?php
                                                }
                                        printf(" %.2f%% (%d)", $percent, $optioncount);
?>
                                        </td></tr>
<?php
                                        }
                                }
?>
                        <tr><td colspan="2" align="center">&nbsp;</td></tr>
                        <tr><td colspan="2" align="center"><? echo _TOTALVOTES?> = <? echo $sum?></td></tr>
                        <tr><td colspan="2" align="center">&nbsp;</td></tr>
                        <tr><td colspan="2" align="center">[ <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>
<?php
                        break;
                case 'list':
?>
                <tr><td colspan="3">&nbsp;</td></tr>
<?php
                $result=tep_db_query("SELECT pollid, polltitle, timestamp, voters, poll_type, poll_open FROM phesis_poll_desc ORDER BY timestamp desc");
                $row=0;
                while ($polls=tep_db_fetch_array($result)) {
                        $row++;
                        $id=$polls['pollid'];
                        if (($row / 2) == floor($row / 2)) {
?>
                        <tr class="Payment-even">
<?php
                } else {
?>
                        <tr class="Payment-odd">
<?php
                }
                $fullresults="<a href=\"".tep_href_link('pollbooth.php','op=results&pollid='.$id,'NONSSL')."\">"._POLLRESULTS."</a>";
                $result1 = tep_db_query("SELECT SUM(optioncount) AS sum FROM phesis_poll_data WHERE pollid='".$id."'");
                $poll_sum=tep_db_fetch_array($result1);
                $sum=$poll_sum['sum'];
                echo("<td>".$polls['polltitle']."</td><td>".$sum." "._VOTES."</td><td>".$fullresults."</td>");
                if ($polls['poll_type']=='0') {
                        echo ("<td>"._PUBLIC."</td>");
                          } else {
                        echo ("<td>"._PRIVATE."</td>");
                        }
                if ($polls['poll_open']=='0') {
                        echo ("<td>"._POLLOPEN."</td>");
                          } else {
                        echo ("<td>"._POLLCLOSED."</td>");
                        }

                echo("</tr>\n");
        }
        break;
        case "vote":
                $poll_query=tep_db_query("select polltitle, voters from phesis_poll_desc where pollid=$pollid");
                $poll_details=tep_db_fetch_array($poll_query);
?>
                <tr>
                <td align="center"><b><?echo $poll_details['polltitle']?></b><td>
                </tr>
<?php
                $url = tep_href_link('pollbooth.php','op=results&pollid='.$pollid,'NONSSL');
                 $content =  "<input type=\"hidden\" name=\"pollid\" value=\"".$pollid."\">\n";
                  $content .=  "<input type=\"hidden\" name=\"forwarder\" value=\"".$url."\">\n";
                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.= "<input type=\"radio\" name=\"voteid\" value=\"".$i."\">".$result['optiontext']."<br>\n";
                               }
                            }
                }
                $content .= "<br><center><input type=\"submit\" value=\""._VOTE."\"></center><br>\n";
                $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 .= "<center>[ <a href=\"".tep_href_link('pollbooth.php','op=results&pollid='.$pollid,'NONSSL')."\">"._RESULTS."</a> | <a href=\"".tep_href_link('pollbooth.php','op=list','NONSSL')."\">"._OTHERPOLLS."</a> ]";
                  $content .= "</br><center>" . $sum . " "._VOTES."</center>\n";
                echo '<tr><td align="center"><form name="poll" method="post" action="pollcollect.php">';

                echo $content;
                echo '<form>';
?>
                </td>
                </tr>
<?php
        break;
                }
?>
     </table>
      </tr>
      <tr>
        <td align="right" class="main"><br><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT, '', 'NONSSL') . '">' . tep_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE) . '</a>'; ?></td>
      </tr>
    </table></td>
<!-- body_text_eof //-->
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<!-- right_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_right.php'); ?>
<!-- right_navigation_eof //-->
    </table></td>
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>