<?php
  ///////////////////////////////////////////////////
error_reporting(E_ALL ^ E_NOTICE);
session_start();
include_once("session_class.php");
$session = new Sessions;
if (!$session->is_session(session_id())) { die('Сначала зайдите в игру <a href=/chat.htm>enter</a>') ; }
  ///////////////////////////////////////////////////
?>
<HTML><HEAD>
<link rel=stylesheet type="text/css" href="../i/main.css">
<meta content="text/html; charset=windows-1251" http-equiv=Content-type>
<META Http-Equiv=Cache-Control Content=no-cache>
<meta http-equiv=PRAGMA content=NO-CACHE>
<META Http-Equiv=Expires Content=0>
</HEAD>
<body bgcolor=e2e0e0><p align=right><INPUT TYPE=button value="Вернуться" onClick="top.returned()"></p>
<?php
  //include_once('paths.inc');
  include_once('poll/pollconfig.inc');
  include_once("poll/lng/rus_lng.inc");
  include_once('poll/functions.inc');
  //Убираем пустые строки из массива Polls

  if(($ProtSession == 'yes') || ($ProtCookie == 'yes'))
  {
    include_once('poll/sessionstart.inc');
  }
  $dr = opendir('poll/txt');
  while($file = readdir($dr))
  {
    if(strpos($file, 'cp') !== false)
      $PollFiles[] = $file;
  }
  closedir($dr);

  if(!empty($PollFiles))
  {
    $MdInx = 0; //индекс многомерного массива
    for($i = (count($PollFiles)-1); $i >= 0; $i--)
    {
      $Poll = file('poll/txt/'.$PollFiles[$i]);
      $TypeFile = "poll/txt/".str_replace('cp', 'type', $PollFiles[$i]);
      $TypeArr  = @file($TypeFile);
      if($TypeArr[0] == '') $TypeArr[0] = 'radio';
      $PollsMD[$MdInx]['type'] = trim($TypeArr[0]);
      $PollsMD[$MdInx]['min'] = trim($TypeArr[1]);
      $PollsMD[$MdInx]['max'] = trim($TypeArr[2]);

      for($b = 0; $b < count($Poll); $b++)
	    {
	      if(strpos($Poll[$b], '[quest]') !== false)
	      {
	        $PollsMD[$MdInx]['quest'] = trim(StripBBCode($Poll[$b]));
          $PollsMD[$MdInx]['file'] = base64_encode($PollFiles[$i]);
	      }
	      if(ereg("\[var[0-9a-z]+\]", $Poll[$b]) !== false)
	        $PollsMD[$MdInx][$Variants][] = trim(StripBBCode($Poll[$b]));
	      if(strpos($Poll[$b], '[show]') !== false)
	      {
	        $PollsMD[$MdInx]['showstatus'] = trim(StripBBCode($Poll[$b]));
          $ShowStatusStr .= $PollsMD[$MdInx]['showstatus'];
        }
	      if(strpos($Poll[$b], '[protect]') !== false)
	      {
	        $PollsMD[$MdInx]['protect'] = trim(StripBBCode($Poll[$b]));
	      }
	      if(strpos($Poll[$b], '[time]') !== false)
	      {
	        $PollsMD[$MdInx]['time'] = trim(StripBBCode($Poll[$b]));
	        $MdInx++;
	      }
      }
    } //for($i = 0; $i < count($Polls); $i++)
  } //if(file_exists($File_CurrentPoll) && (filesize($File_CurrentPoll)>3))

  if(strpos($ShowStatusStr, '1') !== false)
  {
    for($i = 0; $i < count($PollsMD); $i++)
    {

      if($PollsMD[$i]['showstatus'] == '1')
      {
         if($PollsMD[$i]['type'] == 'checkbox')
      	 {
          $Count = (count($PollsMD[$i][$Variants])) / 2;
	        if($Count < $PollsMD[$i]['max'])
	          $PollsMD[$i]['max'] = $Count;
          $Tmp = $Cpt_chkbx_Limit;
          $Tmp = str_replace('MIN', $PollsMD[$i]['min'], $Tmp);
	        $Tmp = str_replace('MAX', $PollsMD[$i]['max'], $Tmp);
          print $Tmp;
	      }
        print "<form name=PollForm{$i} method=post action=vote.php>";
        $First = 'checked';
        print "<table cellspacing=0 cellpadding=0 width=60% border=1>";
          print "<tr><td>{$PollsMD[$i]['quest']}</td></tr>";
        print "</table>";
        //print count($PollsMD[$Variants]);
        print "<table cellspacing=0 cellpadding=0 width=60% border=1>";
          $Total = 0;
          for($b = 0; $b < count($PollsMD[$i][$Variants]); $b = $b + 2)
          {
            $Tmp = (int)$PollsMD[$i][$Variants][($b+1)];
            $Total += $Tmp;
            print "<tr>";

              if($PollsMD[$i]['type'] == 'checkbox')
                print "<td width=20><input type=checkbox name=check[$b] {$First}></td>";
              if($PollsMD[$i]['type'] == 'radio')
                print "<td width=20><input type=radio name=variant value={$b} {$First}></td>";
            print "<td>{$PollsMD[$i][$Variants][$b]}</td>";
            print "</tr>";
            $First = '';
          }
        print "</table>";

        //выводим общее количество проголосовавших
        if($ShowResultsOnFirst == 'yes')
        {
          print "<table cellspacing=2 cellpadding=5 width=60% border=1>";
            print "<tr><td>{$Cpt_Total} {$Total}</td></tr>";
          print "</table>";
        }
        //один пароль на всех
        if($PollsMD[$i]['protect'] == 'pswrdall')
        {
          print "<table cellspacing=2 cellpadding=5 width=60% border=1>";
            print "<tr>";
              print "<td>{$Cpt_Password}</td>";
              print "<td><input type=password name=password value='' size=35 maxlength=35></td>";
            print "</tr>";
          print "</table>";
        }
        //логин и пароль для каждого
        if($PollsMD[$i]['protect'] == 'pswrdeach')
        {
          print "<table cellspacing=2 cellpadding=5 width=60% border=1>";
            print "<tr>";
              print "<td>{$Cpt_Login}</td>";
              print "<td><input type=password name=login value='' size=35 maxlength=35></td>";
            print "</tr>";
            print "<tr>";
              print "<td>{$Cpt_Password}</td>";
              print "<td><input type=password name=password value='' size=35 maxlength=35></td>";
            print "</tr>";
          print "</table>";
        }
        //кнопки
        $Time = base64_encode($PollsMD[$i]['time']);
        print "<table cellspacing=2 cellpadding=5 width=60% border=1>";
          print "<tr>";
            print "<td><input type=Submit name=Vote value='{$Button_Vote}'></td>";
            if($Total != 0)
              print "<td><input type=Submit name=ShowResults value='{$Button_ShowResults}'></td>";
            print "<td><input type=Submit name=PollArchive value='{$Button_ShowArchive}'></td>";
            print "<input type=hidden name=blague value='{$PollsMD[$i]['file']}'>";
            print "<input type=hidden name=time value='{$Time}'>";
          print "</tr>";
        print "</table>";
        if($PollsMD[$i]['type'] == 'checkbox')
        {
          print "<input type=hidden name=MinChosenCount value={$PollsMD[$i]['min']}>";
          print "<input type=hidden name=MaxChosenCount value={$PollsMD[$i]['max']}>";
        }
        print "</form>";
      } //if($PollsMD['showstatus'] == 1)
    } //for($i = 0; $i < count($PollsMD); $i++)
  }
?>