
<?php
//Данный файл подключается в модуле logins
//постраничная навигация
  $ItPerPage = $EachPassw_ItemPerPage;
  $InitPos = $_GET['initpos'];
  $Participants = @file($PswdFile);
  //Выбираем пустые элементы из массива участников
  if(empty($InitPos))
    $InitPos = 0;
  $EndPos  = $InitPos + $ItPerPage*2;
  //определяем количество страниц
  $CountUsers = count($Participants);
  $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=ch_passwords&pswdfile={$PswdFile}&questlength={$QuestLength}&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=ch_passwords&pswdfile={$PswdFile}&questlength={$QuestLength}&initpos={$ElInitPos}>".($i+1)."</a>";
    }
    else
      $Navig .= "<span class=Navigation><b>".($i+1)."</b></span>";
    }
    if($EndPos < count($Participants))
    {
      $NextInitPos = $InitPos + ($ItPerPage*2);
      $Navig .= "<a class=Navigation href=index.php?page=ch_passwords&pswdfile={$PswdFile}&questlength={$QuestLength}&initpos={$NextInitPos}>{$Cpt_Next}</a>";
    }
    $Navig .= "</td></tr>";
  $Navig .= "</table>";

//меню
  print "<br><h4>{$Heading_lapfe_AddUser}</h4>";
  print "<h5><i>{$Question}</i></h5>";
  if($ShowTips == 'yes')
    ShowTips($Page);
  print "<form action='' method=post>";
  print "<fieldset class=GeneralField align=center>";
    print "<table align=center class=General border=0 cellpadding=0 cellspacing=0 width=100% >";
      print "<tr>";
        print "<td align=center><a href=index.php?page=ch_passwords_adduser&pswdfile={$PswdFile}&questlength={$QuestLength}>{$Menu_lapfe_AddUser}</a></td>";
        print "<td align=center><a href=index.php?page=ch_passwords_addusersfromfile&pswdfile={$PswdFile}&questlength={$QuestLength}>{$Menu_lapfe_LoadUsersFromFile}</a></td>";
        if(!empty($Participants))
          print "<td align=center><a href=index.php?page=ch_passwords_sort&pswdfile={$PswdFile}&questlength={$QuestLength}>{$Menu_lapfe_Sort}</a></td>";
      print "</tr>";
    print "</table>";
  print "</fieldset>";
//участники

  print "<h4 align=center>{$Heading_lapfe_Users}</h4>";
  if(empty($Participants))
  {
    print "{$Cpt_lapfe_NoUsers} </form></body></html>";
    exit;
  }
  //статистика
  $VotedUsers = 0;
  $CountParticipants = 0;
	  for($i = 0; $i < count($Participants); $i = $i + 2)
	  {
	    if(strpos($Participants[$i], ' (%%%voted%%%)') !== false)
	      $VotedUsers++;
      if(!empty($Participants[$i]))
        $CountParticipants++;
      else break;
    }
  $Total = $CountParticipants;
  $_1Percent = 100/$Total;
  $Percentage = $VotedUsers*$_1Percent;
  $Percentage = number_format($Percentage, 2);
  print "<table class=OrdTable align=center border=1 cellspacing=0 cellpadding=0 >";
    print "<tr><td>{$Cpt_lapfe_Total} - {$Total}; {$Cpt_lapfe_Voted} - {$VotedUsers} ({$Percentage}%)</td></tr>";
  print "</table>";
  //постраничная навигация
  print $Navig;

  print "<table class=OrdTable align=center border=1 cellspacing=0 cellpadding=0>";
    print "<tr>";
      print "<td width=30 align=center>&nbsp;</td>";
      print "<td width=220 align=center><b>{$TH_lapfe_Participant}</b></td>";
      print "<td width=100 align=center><b>{$TH_lapfe_State}</b></td>";
      print "<td width=65 align=center><b>{$TH_lapfe_Change}</b></td>";
      print "<td width=20 align=center>&nbsp;</td>";
    print "</tr>";
    $inx = ($InitPos)/2+1;
    for($i = $InitPos; $i < $EndPos; $i = $i + 2)
    {

      if(empty($Participants[$i]))
          break;
      $Status = $Cpt_lapfe_StateNotVoted;
      if(strpos($Participants[$i], "(%%%voted%%%)") !== false)
      {

        $Participants[$i] = str_replace('(%%%voted%%%)', '', $Participants[$i]);
        $Status = "<span class=mustred>{$Cpt_lapfe_StateVoted}</span>";
      }
      print "<tr>";
        print "<td align=center>{$inx}</td>";
        print "<td>{$Participants[$i]}</td>";
        print "<td>{$Status}</td>";
        print "<td><a href='index.php?page=ch_passwords_edituser&pswdfile={$PswdFile}&questlength={$QuestLength}&pos={$i}'>{$Cpt_Change}</a></td>";
        print "<td align=center><input type='checkbox' name='user{$i}' value='off'></td>";
      print "</tr>";
      $inx++;
    }
  print "</table>";
  //кнопки
  print "<fieldset align=center class=GeneralField style='width:516px'>";
  print "<table align=center border=0 cellspacing=0 cellpadding=0 >";
    print "<tr>";
      print "<td align=center>";
        print "<input class=button type=submit name=DeleteUser value='{$Button_lapfe_Delete}'>&nbsp;&nbsp;";
        print "<input class=button type=submit name=DeleteAll value='{$Button_lapfe_DeleteAll}'>";
      print "</td>";
    print "</tr>";
  print "</table>";
  print "</fieldset>";
  print "<input type=hidden name=page value=ch_passwords_deleteusers>";
  print "</form>";
  print $Navig;
?>