<?php
//  Advanced Poll 1.25
//  Copyright (c)2000 bp135
//  URL: http://bp135.cjb.net

$config_file = "pollconfig.php3"; // path to config file
$poll_dat = "polldata.txt";      // path to poll data file
$poll_ip = "poll_ip.txt";        // path to poll ip file

//////////////////////////////////////////////////////
require "$config_file";
$found=0;
function sort_keys($a, $b) {
 if ($a == $b) return 0;
 return ($a > $b) ? -1 : 1;
}
function checkIP($rem_addr,$voting) {
  global $poll_ip,$lock_timeout,$found;
  $ip_array = @file($poll_ip);
  $this_time = time();
  if ($voting==1) { $ip_table = fopen($poll_ip,"w+"); }
  for ($i=0; $i<sizeof($ip_array); $i++) {
    list($ip_addr,$time_stamp) = split("\|",$ip_array[$i]);
    if ($this_time < ($time_stamp+3600*$lock_timeout)) {
      if ($ip_addr == $rem_addr) {
        $found=1;
        if ($voting==0) { break;}
      }
      if ($voting==1) { fwrite($ip_table,"$ip_addr|$time_stamp"); }
    }
  }
  if ($voting==1) {
    fwrite($ip_table,"$rem_addr|$this_time\n");
    fclose($ip_table);
  }
}
if ($check_vote>=1 && $status==1) {
  $cookie_name = "AdvancedPoll";
  if(isset($AdvancedPoll)==1){
    $found=1;
  }
  else {
    if ($check_vote==2) {
      checkIP($REMOTE_ADDR,0);
    }
    if ($vote_for && $found==0) {
      setcookie($cookie_name, "1", time()+(3600*$lock_timeout));
      if ($check_vote==2) { checkIP($REMOTE_ADDR,1); }
    }
  }
}
if ($vote_for && $found==0 && $status==1) {
  $line = file($poll_dat);
  $count_dat = fopen($poll_dat,"r+");
  for ($i=1; $i<sizeof($line); $i++) {
    list($name,$vote,$color) = split("\|",$line[$i]);
      if ($name == "$vote_for") {
        $vote += 1;
      }
      $poll[$name] = $vote;
      $gif[$name] = $color;
      $total += $vote;
  }
  fwrite($count_dat,$line[0]);
  for(reset($poll); $key=key($poll); next($poll)) {
    fwrite($count_dat,"$key|$poll[$key]|$gif[$key]");
  }
  fclose($count_dat);
}
else {
  $line = file($poll_dat);
  for ($i=1; $i<sizeof($line); $i++) {
    list($name,$vote,$color) = split("\|",$line[$i]);
    $poll[$name] = $vote;
    $gif[$name] = $color;
    $total += $vote;
  }
}
?>
<?
include('http://bambusratte.com/header.php');
?>
<html>
<head>
<title>Umfrage</title>
</head>
<body bgcolor="#ffffff" text="#000000">
<br>

<!--Cut here -->

<table width="<?php echo $table_width; ?>" align="center" border="0" cellspacing="0" cellpadding="1" bgcolor="<?php echo $bgcolor_fr; ?>">
  <tr align="center">
    <td><font face="Verdana" size="3" color="#000000"><b></b></font></td>
  </tr>
  <tr align="center">
    <td>
      <table width="100%" border="0" cellspacing="0" cellpadding="2" align="center" bgcolor="<?php echo $bgcolor_tab; ?>" height="60">
        <tr valign="middle">
          <td colspan="2" height="40"><font face= size="2""Verdana"><b><?php echo chop($line[0]); ?></b></font></td>
        </tr>
        <tr align="right" valign="bottom">
          <td colspan="2">
            <form method="post" action="<?php echo $PHP_SELF; ?>">
              <table width="100%" border="0" cellspacing="0" cellpadding="1" height="100%">
<?php
if ($found==1 || $status==0 || $vote_for || $results==1) {
  if (count($poll)) {
    uasort($poll,sort_keys);
    $top_pos = reset($poll);
  }
  if ($total <= 0) {
    $top_pos = 1;
  }
  for (reset($poll); $key=key($poll); next($poll)) {
    if ($total==0) {
      $vote_val="0";
    }
    else {
      $vote_val = ($show_type==1) ? sprintf("%.1f",($poll[$key]*100/$total))."%" : $poll[$key];
    }
    $img_width = (int) ($poll[$key]*$img_length/$top_pos);
    $image = chop($gif[$key]);
    echo"         <tr bgcolor=\"$bgcolor_tab\">\n";
    echo"            <td height=\"22\"><font face=\"Verdana\" size=\"2\">$key</font></td>\n";
    echo"            <td nowrap height=\"22\"><font face=\"Verdana\" size=\"2\"><img src=\"$base_gif/$image.gif\" width=\"$img_width\" height=\"$img_height\">\n";
    echo"              $vote_val</font></td>\n";
    echo"         </tr>\n";
  }
?>
           <tr bgcolor="<?php echo $bgcolor_tab; ?>" valign="top">
              <td colspan="2" height="80"> <font size="2" face="Verdana"><br>
                Abstimmungen: <font color="#CC0000"><?php echo $total; ?></font><?php if ($found == 1) {echo "<br>Du hast schon abgestimmt!";} ?></font>
              <style type="text/css">
               <!--
               .links { color: #000000}
               -->
              </style>
            </td>
<?php  } else { ?>
<?php
for (reset($poll); $key=key($poll); next($poll)) {
  echo"         <tr bgcolor=\"$bgcolor_tab\">\n";
  echo"            <td width=\"15%\">\n";
  echo"              <input type=\"radio\" name=\"vote_for\" value=\"$key\">\n";
  echo"            </td>\n";
  echo"            <td width=\"85%\"><font face=\"Verdana\" size=\"2\">$key</font></td>\n";
  echo"         </tr>\n";
}
?>
            <tr align="center" bgcolor="<?php echo $bgcolor_tab; ?>" valign="top">
              <td colspan="2" height="80">
                <style type="text/css">
                 <!--
                  .input { font-family: Verdana font-size: 10pt}
                  .links { color: #000000}
                 -->
                </style><br>
                <input type="submit" name="Vote" value="Abstimmen!" class="input"><br>
                <font face="Verdana" size="2"><br><br><a href="<?php echo $PHP_SELF; ?>?results=1" class="links">Ergebnis</a></font></td>
<?php } ?>
              </tr>
             </table>
           </form>
         </td>
       </tr>
     </table>
   </td>
 </tr>
</table>

<!--Cut here -->

</body>
</html>
<?
include('http://bambusratte.com/footer.php');
?>