<?php
     include("cap.php");
     $file=array();
     $d=opendir("db/$id");
      while(($e=readdir($d))!=false)
        {
          if($e =="." || $e ==".." || $e==".htaccess" ) continue;
          $file[]=$e;
        }
     closedir($d);
rsort($file,SORT_NUMERIC);
 $topic_count_page=20;
                  if(!isset($_GET['page']) || !is_numeric(@$_GET['page']) || @$_GET['page']<1 )$page=1;
                  else $page=$_GET['page'];
                  if($page > ceil(count($file)/ $topic_count_page))$page=1;
                  $start=$page * $topic_count_page-$topic_count_page;
                  $pages=ceil(count($file)/ $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'];

?>
<table align=center class=consTable>
  <tr>
    <td>
<?php
   if(!count($file))echo "Ответов пока нет";
   else
     {
        for($x=$start,$y=0; $x<count($file); $x++,$y++)
          {
                    if($y==$topic_count_page)break;
                    $text=file("db/$id/$file[$x]");
                    $text[0]=trim($text[0]);
                    $expl=explode("*",$text[0]);
            echo"<table width=80% bgcolor=#ffffff id=cit CELLPADDING=5>
                  <tr>
                      <td>
                         <font color=#408080><b>$expl[0]&nbsp;&nbsp;$expl[1]</b></font>
                      </td>
                 </tr>
               <tr>
                      <td>$text[1]</td>
               </tr>
               <tr>
                      <td id=quest>$text[2]</td>
               </tr>
                 <tr><td align=right><a href=red.php?q=$file[$x]>Редактировать</a></td></tr>
               </table><br /><br />";
          }

     }

?>

    </td>

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

       if($index>1)echo "
       <a class='navig_passiv' href=admin2.php?sel2=selected&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=admin2.php?sel2=selected&page=".($i)."&ind=".($index+1)." title=далее>>></a>";
          	  	break;
          	  }
          	if($page==$i)
            echo "<a class='navig_activ' href=admin2.php?sel2=selected&page=$i&ind=$index>$i</a>";
            else
            echo "<a class='navig_passiv'href=admin2.php?sel2=selected&page=$i&ind=$index>$i</a>";
          }

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



</body>
</html>