<?php
  ///////////////////////////////////////////////////
  //2007 (C)
  //Карпухин Павел
  ///////////////////////////////////////////////////

  $lang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0,2);
  if(is_file ("lang/".$lang.".php")) include "lang/".$lang.".php";
     else include "lang/ru.php";

  $title=$titlepage=$TEXT['global-doc'];

  require_once "config.php";
  require_once "utils/top_doc.php";

  if(strlen($_GET['razd_id'])>20) puterror($TEXT['error-razd']);
  $_GET['razd_id'] = rep($_GET['razd_id']);

  if(strlen($_GET['razd_id'])>20) puterror($TEXT['error-razd']);
  $_GET['razd_id'] = rep($_GET['razd_id']);
  $old_razd_id = $_GET['razd_id'];

  if(strlen($_GET['k'])>8) puterror2($TEXT['error-paging1']);
  if(empty($_GET['k'])) $_GET['k']=0;
  $stop_r = $_GET['k'];
  if($stop_r == 0) $lim_ogr = "20";
   else $lim_ogr = $stop_r.",20";

  $ktblvis = $stop_r+20;
  $str = $ktblvis/20;
?>
<table class="table" border="0" cellpadding="1" cellspacing="0" width="70%">
<?php
$query2 = "SELECT * FROM `tbl_documents` WHERE `razd_id` = '".$_GET['razd_id']."' AND `visible` = 'show' ORDER BY position LIMIT $lim_ogr";
 $document = mysql_query($query2);
  if(!$document) puterror($TEXT['error-tbl14']);
   if(mysql_num_rows($document)==0) puterror($TEXT['error-empty-doc']);
    {
    while($doc = mysql_fetch_array($document,MYSQL_ASSOC))
     {
     $docpath = preg_replace("/\.\.+./","",$doc['path']);
     echo "<tr align='left'>
     <td width='25px'><img alt='document' src='img/document.png'></td>
     <td><a href='get_doc.php?doc_id=".$doc['doc_id']."&amp;razd_id=".$old_razd_id."&amp;org_id=".$_GET['org_id']."' title='".$doc['description']."''<span class='support4'>".$doc['name']."</span></a></td>
     </tr>";
     }
   }
?>
</table>
     <?php
       $query_count = mysql_query("SELECT COUNT(doc_id) FROM tbl_documents WHERE `razd_id` = '".$_GET['razd_id']."' AND `visible` = 'show' ");
       $coun_rows = mysql_result($query_count, 0);
               $pag = $coun_rows/20;
               if($pag<=1) $pag = ceil($pag);
                else
                {
                 ?>
                  <hr align="center" width="80%"/>
                  <table align="center" border="0" cellpadding="0" cellspacing="0" width="60%" >
                   <tr align="center">
                    <td>
                <?php
                $pag=ceil($pag);
                $strn = $str-5;
                if($strn<1) $strn=1;
                $strk = $str+5;
                for($i=$strn; $i<=$pag; $i++)
                 {
                  if($i<=$strk)
                  {
                    if($i==$str)
                    {
                      $k = $i*20-20;
                      $kvis=$k+20;
                      $nvis=$k;
                      echo $pg = " <a class='zagolovok' href='documents.php?k=".$k."&amp;razd_id=".$old_razd_id."&amp;org_id=".$_GET['org_id']."' title='".$TEXT['zhurn-details2'].$nvis.$TEXT['zhurn-details1'].$kvis."'>".$i."</a>";
                    }
                    else
                    {
                    $k = $i*20-20;
                    $kvis=$k+20;
                    $nvis=$k;
                    echo $pg = " <a href='documents.php?k=".$k."&amp;razd_id=".$old_razd_id."&amp;org_id=".$_GET['org_id']."' title='".$TEXT['zhurn-details2'].$nvis.$TEXT['zhurn-details1'].$kvis."'>[".$i."]</a>";
                    }
                  }
                 }
                 ?>
                    <select name='k' onchange=window.location.href=this.options[this.selectedIndex].value;>
                    <?php
                    for($j=1; $j<=$pag; $j++)
                    {
                     $k = $j*20-20;
                     if($k == $_GET['k']) echo "<option selected value=documents.php?k=".$k."&amp;razd_id=".$old_razd_id."&amp;org_id=".$_GET['org_id'].">".$j."</option>";
                       else echo "<option value=documents.php?k=".$k."&amp;razd_id=".$old_razd_id."&amp;org_id=".$_GET['org_id'].">".$j."</option>";
                    }
                    ?>
                    </select>
                    </td>
                   </tr>
                  </table>
                 <?php
                }
  require_once "utils/bottom.php";
?>