<?php
session_start();
$content=file("../../sg_cm/conf/conf/conf.php");
if (session_id()!=$content[2])
 {
  $url=urlencode("Пройдите_авторизацию!");
  echo "<meta http-equiv=refresh content='0; url=../../sg_cm/admin/index.php?acc=$url'>";
  exit();
 }

if(!isset($_GET['id']))
   {
   	 echo "<meta http-equiv=refresh content='0; url=admin3.php?sel3=selected'>";
     exit();
   }

 if(!file_exists("cons/cons/$_GET[id]"))
   {
   	 echo "<meta http-equiv=refresh content='0; url=admin3.php?sel3=selected'>";
     exit();
   }

 if(isset($_POST['exit']))
   {
   	 echo "<meta http-equiv=refresh content='0; url=admin3.php?sel3=selected'>";
     exit();
   }

$cons=array();
$cons=file("conf/cons.txt");
 foreach($cons as $line)
  {
    $expl=explode("*",$line);
    if($expl[0]==$_GET['id'])
       {
         list($p_id,$p_name,$p_email,$p_pasv)=$expl;
         break;
       }
  }

 $file=array();
 $d=opendir("cons/db/$_GET[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'];




?>
<!DOCTYPE html>
<html>
	<head>
	<meta charset="utf-8" />
  <title><?echo $p_name?> :: ответы</title>

<style>
  #head
         {
          font-family: Arial, sans-serif;
          font-size:14pt;
          color:#808080;

         }
  #none {
         font-family: Arial, sans-serif;
         font-size:10pt;
          color:#5C5C5C;
 	     font-size:11pt;
      }
  #button {

       font-family:"Times New Roman", "serif";
       color:#408080;
       font-size:9pt;
       background-color:#C0C0C0;
      font-weight:600;
      text-align:center;
      width:120px;
      }

  #cit
         {
          color:#808080;
          font-size:11pt;
          font-family: Arial, sans-serif;
          border-style:solid;
          border-width: 1px;
          border-color:#C0C0C0;
          top-margin:20px;
          bottom-margin:20px;

         }
    #cit a
         {
          color:#0061C1;
          font-size:9pt;
          font-family: Arial, sans-serif;

         }

       #quest
         {
          font-family:"Times New Roman", "serif";
 	      font-size:11pt;
          font-weight:300;
          color:#005F8C;
          border-style:solid;
          border-left-width: 0px;
          border-right-width: 0px;
          border-top-width: 1px;
          border-bottom-width:0px;
          border-color: #C0C0C0;
         }

         .navig_activ
         {
          font-family: Arial, sans-serif;
          font-size:10pt;
          border-style:solid;
          border-width: 1px;
          border-color:#D2D2D2;
          background-color:#800040;
          padding:5px;
          text-align:center;
          color:#ffffff;

         }

 .navig_passiv
        {

          fontfont-family: Arial, sans-serif;
          font-size:10pt;
          border-style:solid;
          border-width: 1px;
          border-color:#D2D2D2;
          background-color:#F0F0F0;
          padding:5px;
          text-align:center;
          color:#676767;
       }

   a.navig_activ
     {
      text-decoration:none;
     }
   a.navig_passiv
      {
      text-decoration:none;
      }

</style>
</head>

<body>
<form  action=view.php?id=<?echo $_GET['id']?> method="post">
<span id=head><?echo $p_name?> :: ответы</span>
&nbsp;&nbsp;<input type="submit" value="Выход" name=exit id=button>
</form>

<?php



    if(!count($file)) echo"<span id=none>Ответов не найдено</span>";
    else
      {
         for($x=$start,$y=0; $x<count($file); $x++,$y++)
            {
               if($y==$topic_count_page)break;
               $text=file("cons/db/$_GET[id]/$file[$x]");
               for($n=0;$n<count($text);$n++)$text[$n]=trim($text[$n]);

                    $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?op=1&q=$file[$x]&id=$_GET[id]>Редактировать</a>&nbsp;&nbsp;
                 <a href=red.php?op=2&q=$file[$x]&id=$_GET[id]>Удалить</a>&nbsp;&nbsp;
                 <a href=red.php?op=3&q=$file[$x]&id=$_GET[id]>Чёрный список</a>&nbsp;&nbsp;</td></tr>
               </table><br /><br />";
            }
      }


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

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

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

?>



</body>

</html>