<?php
include("cap.php");
$news_sub=file("db/mail.txt");
for($n=0;$n<count($news_sub);$n++)$news_sub[$n]=trim($news_sub[$n]);

//Постраничная навигация
 $topic_count_page=100;
 if(!isset($_GET['page']) || !is_numeric(@$_GET['page']) || @$_GET['page']<1 )$page=1;
 else $page=$_GET['page'];
 if($page > ceil(count($news_sub)/ $topic_count_page))$page=1;
 $start=$page * $topic_count_page-$topic_count_page;
 $pages=ceil(count($news_sub)/ $topic_count_page);
 if(empty($_GET['ind']) || !is_numeric(@$_GET['ind']) || @$_GET['ind']>ceil($pages/$topic_count_page)  || @$_GET['ind']<1)$index=1;
 else $index= $_GET['ind'];


 if(isset($_GET['d']))
  {
     $f=fopen("db/mail.txt","w");
     foreach($news_sub as $line)
      {
        $line=trim($line);
        if($line==$_GET['d'])continue;
        fwrite($f,$line."\r\n");
      }
     fclose($f);
     echo "<meta http-equiv=refresh content='0; url=db_mail.php?page=$page&ind=$index'>";
     exit();

  }

 if(count($file)> $topic_count_page)
    {
      //Постраничная навигаця
         echo "<table   align=center><tr><td>";

          if($index>1)echo "
         <a class='navig_passiv' href=db_mail.php?page=".(($index-1)*10)."&ind=".($index-1)." title=назад><<</a>";

         for($i=$index*10-9,$p=1; $i < $pages+1; $i++,$p++)
          {

            if($p>10 )
          	  {
          	  	echo "<a class='navig_passiv'  href=db_mail.php?page=".($i)."&ind=".($index+1)." title=далее>>></a>";
          	  	break;
          	  }
          	if($page==$i)
            echo "<a class='navig_activ' href=db_mail.php?page=$i&ind=$index>$i</a>";
            else
            echo "<a class='navig_passiv'href=db_mail.php?page=$i&ind=$index>$i</a>";
          }


       echo "</td></tr></table><br />";
    }

echo"<table  class=tab1 CELLPADDING=10 CELLSPACING=0 align=center >";
$news_sub = array_unique($news_sub);
 for($x=$start,$y=0; $x<count($news_sub); $x++,$y++)
     {
     	if($y==$topic_count_page)break;
     	echo "<tr><td class=sett1>$news_sub[$x]</td><td align=center class=sett2><a href=db_mail.php?&page=$page&ind=$index&d=$news_sub[$x]>удалить</a></td></tr>";


     }



echo"</table>";

  if(count($file)> $topic_count_page)
    {
      //Постраничная навигаця
         echo "<table   align=center><tr><td>";

          if($index>1)echo "
         <a class='navig_passiv' href=db_mail.php?page=".(($index-1)*10)."&ind=".($index-1)." title=назад><<</a>";

         for($i=$index*10-9,$p=1; $i < $pages+1; $i++,$p++)
          {

            if($p>10 )
          	  {
          	  	echo "<a class='navig_passiv'  href=db_mail.php?page=".($i)."&ind=".($index+1)." title=далее>>></a>";
          	  	break;
          	  }
          	if($page==$i)
            echo "<a class='navig_activ' href=db_mail.php?page=$i&ind=$index>$i</a>";
            else
            echo "<a class='navig_passiv'href=db_mail.php?page=$i&ind=$index>$i</a>";
          }


       echo "</td></tr></table><br />";
    }
?>

</div>
</body>
</html>