
<?php
  print "<form name=pollusersdataform action='' method=post>" ;
  print "<h4>{$Heading_PollUsersDataBase}</h4>";
  //подсказки
  if($ShowTips == 'yes')
    ShowTips('pollusersdata');
  //меню
  print "<fieldset class=GeneralField align=center>";
    print "<table align=center class=General border=0 cellpadding=0 cellspacing=0 width=90% >";
      print "<tr>";
        print "<td align=center><a href=index.php?page=pollusersdata_addnewuser>{$Menu_pud_AddUser}</a></td>";
        print "<td align=center><a href=index.php?page=pollusersdata_loadusersfromfile>{$Menu_pud_AddUsersFromFile}</a></td>";
        print "<td align=center><a href=# onClick=location.href='index.php?page=pollusersdata_sort&mode='+document.pollusersdataform.SortType.value>{$Menu_pud_Sort}</a>&nbsp;&nbsp;";
                                                         print "<select name=SortType>";
                                                           print "<option value=NameSort>$Menu_pud_SortByName";
                                                           print "<option value=EmailSort>$Menu_pud_SortByEmail";
                                                         print "</select>";
        print "</td>";
      print "</tr>";
    print "</table>";
  print "</fieldset><br>";

  $UsersArr = @file($UsersDatabase);
  //Если нет ни одного участника
  if(empty($UsersArr))
  {
    print "<br>";
    print "<table align=center class=General border=0 cellpadding=0 cellspacing=0 width=85% >";
      print "<tr><td><b class=Mustred>{$Cpt_pud_NoUsers}</b></td></tr>";
    print "</table>";
    print "</body></html>";
    exit;
  }
  else {
	//постраничная навигация (верхняя)
	  //определяем страницы
    $ItPerPage = $PollUsers_ItemPerPage;
    $InitPos = $_GET['initpos'];
	  if(empty($InitPos))
	    $InitPos = 0;
	  $EndPos  = $InitPos + $ItPerPage*2;
	  //определяем количество страниц
	  $CountUsers = count($UsersArr);
	  $CountPages = ceil($CountUsers/($ItPerPage*2));
	  //выводим шапку таблицы

    $Navig =  "<table align=center class=General border=0 cellpadding=0 cellspacing=0 width=85% >";
	    $Navig .= "<tr><td align=center>";
	    //вычисляем позицию предыдущего элемента
	    if($InitPos != 0)
	    {
	      $PrecInitPos = $InitPos - ($ItPerPage*2);
	      $Navig .= "<a class=Navigation href=index.php?page=pollusersdata&initpos={$PrecInitPos}>{$Cpt_Prev}</a>";
	    }

	    for($i = 0; $i < $CountPages; $i++)
	    {
	      $ElInitPos = $i * ($ItPerPage*2);
	      if($ElInitPos != $InitPos)
	      {
	        $Navig .= "<a class=Navigation href=index.php?page=pollusersdata&initpos={$ElInitPos}>".($i+1)."</a>";
	      }
	      else
	        $Navig .= "<span class=Navigation><b>".($i+1)."</b></span>";
	    }
	    if($EndPos < count($UsersArr))
	    {
	      $NextInitPos = $InitPos + ($ItPerPage*2);
	      $Navig .= "<a class=Navigation href=index.php?page=pollusersdata&initpos={$NextInitPos}>{$Cpt_Next}</a>";
	    }
	    $Navig .= "</td></tr>";
	  $Navig .= "</table>";
	  print $Navig;
	//список участников
	  print "<table align=center border=1 cellpadding=0 cellspacing=0>";
	    print "<tr class=OrdTable >";
	        print "<td width=30 align=center><b>№</b></td>";
	        print "<td width=180 align=center><b>{$TH_User}</b></td>";
	        print "<td width=180 align=center><b>{$TH_Email}</b></td>";
	        print "<td width=65 align=center>&nbsp;</td>";
	        print "<td width=20>&nbsp;</td>";
	      print "</tr>";

      $inx = ($InitPos+2)/2;

      for($i = $InitPos; $i < $EndPos; $i = $i + 2)
	    {
	      if($UsersArr[$i] == '')
	        break;
	      print "<tr class=OrdTable >";
	        print "<td align=center>{$inx}</td>";
	        print "<td>{$UsersArr[$i]}</td>";
	        print "<td>".$UsersArr[($i+1)]."</td>";
	        print "<td ><a href=index.php?page=pollusersdata_edit_item&pos={$i}&initpos={$InitPos}>{$Cpt_Change}</a></td>";
	        print "<td><input type=checkbox name=user{$i}></td>";
	      print "</tr>";
        $inx++;
	    }
	  print "<table>";
    //кнопки
    print "<table width=537 align=center border=1 cellpadding=0 cellspacing=0>";
      print "<tr><td class=OrdTable align=center>";
        print "<input class=Button type=submit name=DeleteUser value={$Cpt_Delete}>";
        print "<input class=Button type=submit name=DeleteAll value='{$Cpt_pud_DeleteAll}'>";
        print "<input type=hidden name=page value='pollusersdata_delete_item'>";
      print "</td></tr>";
    print "</table>";
    print "</form>";
	//постраничная навигация (нижняя)
	  print $Navig;
  } //else
?>