<?php
/*
  www.oscGold.com (C) Kamelia-Net Jacek Krysiak
  modul oscGold wer 4.0
*/
require(DIR_WS_LANGUAGES . $language . '/pollbooth.php');
$boxHeading = _POLLS;
$corner_left = 'rounded';
$corner_right = 'rounded';
$box_base_name = 'polls';
$boxContent_attributes = ' align="center"';
$box_id = $box_base_name . 'Box';

$hide = tep_hide_session_id();


  function pollnewest() {
       $extra_query = '';
       global $customer_id, $HTTP_GET_VARS;
        if (DISPLAY_POLL_HOW==3) {
                $extra_query=" and pollID='" . DISPLAY_POLL_ID . "'";
                }
        if ((int)$customer_id > 0) {
                //$extra_query.=" and poll_type='1' ";
                } else {
				 $extra_query .= " and poll_type='0' ";
				}
        if (DISPLAY_POLL_HOW==2) {
                $order = 'voters DESC';
                 } else {
                $order = 'timestamp DESC';
                }
        $query= tep_db_query("select pollid, catID FROM phesis_poll_desc where poll_open='0'".$extra_query."and catID != 0 order by ".$order);
        $count=tep_db_num_rows($query);
        $result = tep_db_fetch_array($query);
        $pollid = false;
        if ($count>0) {
           if ($HTTP_GET_VARS['cPath']) $mypath = $HTTP_GET_VARS['cPath'];
           if ($HTTP_GET_VARS['products_id'])$mypath = tep_get_product_path($HTTP_GET_VARS['products_id']);
           if ($mypath) {
             $sub_cat_ids = split("[_]", $mypath);
             for ($i = 0; $i < count($sub_cat_ids); $i++) {
               if ($sub_cat_ids[$i] == $result['catID']) $pollid = $result['pollid'];
             }
           }
        }
		if(empty($HTTP_GET_VARS['cPath'])){
		$catid=0;
		}
		if( isset($HTTP_GET_VARS['cPath']) && $HTTP_GET_VARS['cPath']) {
		$mypath = $HTTP_GET_VARS['cPath'];
		list($catid, $subcatid)=split("[_]", $mypath);
		}

		$query= tep_db_query("select pollid, catID FROM phesis_poll_desc where poll_open='0'".$extra_query." and catID = ".$catid ." order by ".$order);

        $count=tep_db_num_rows($query);
               if ((!DISPLAY_POLL_HOW==0 || $count==1) && !$pollid) {
                if ($result=tep_db_fetch_array($query)) {
                        $pollid = $result['pollid'];
                }
        } elseif (!$pollid) {
                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) {
        $poll_query=tep_db_query("select voters from phesis_poll_desc where pollid=$pollid and poll_open='0'");
        $poll_details=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 . "'");
		//
		$licznik = 0;
		//
        $title = tep_db_fetch_array($title_query);
        $url = tep_href_link('pollbooth.php', 'op=results&pollid='.$pollid);
		$boxContent = '<form name="poll" method="post" action="'. tep_href_link('pollcollect.php') .'">';
        $boxContent .= '<div class="poll_kont"><div class="poll_tytul"><span class="main"><b>' . $title['optionText'] . '</b></span>';
        $boxContent .= '<input type="hidden" name="pollid" value="'.$pollid.'">';
        $boxContent .= '<input type="hidden" name="forwarder" value="'.$url.'"></div>';
        $boxContent .= '<div class="poll_poll"><table align="center" border="0"><tr><td align="left" class="main">';
        for ($i=1;$i<=8;$i++) {
              $query=tep_db_query("select pollid, optiontext, optioncount, voteid from phesis_poll_data where (pollid=$pollid) and (voteid=$i) and (language_id=$languages_id)");
              if ($result=tep_db_fetch_array($query)) {
                    if ($result['optiontext']) {
					   if ($result['optiontext'] != '') {
						  $licznik++;
					   }
                       $boxContent.= '<input type="radio" name="voteid" value="'.$i.'">'.$result['optiontext'].'<br>';
                    }
              }
        }
        $boxContent .= '</td></tr></table></div><div class="poll_img">'.tep_image_submit('button_poll.gif', _VOTE).'</div>';
        $boxContent .= '<div class="poll_poz"><div class="main"><a class="boxLink" href="' . tep_href_link('pollbooth.php', 'op=results&pollid=' .$pollid, 'NONSSL').'">'._RESULTS.'</a></div></div></div></form>';
		if ($licznik > 0) {
			include (bts_select('boxes', $box_base_name)); // BTS 1.5
          } else {
            $boxContent = '';
		}
    } elseif (SHOW_NOPOLL==1) {
		$boxContent = '<div class="main">' . _NOPOLLSCONTENT;
		$boxContent .= '</div>';
		$boxContent = $boxContent;
		include (bts_select('boxes', $box_base_name)); // BTS 1.5
}
}
?>