<?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_razd.php";

  $query_org_no = "SELECT * FROM `tbl_organizaciya` WHERE `organizaciya` = '-' ";
   $org_no = mysql_query($query_org_no);
     if(!$org_no) puterror($TEXT['error-tbl7']);
       $result_org_no = mysql_fetch_array($org_no,MYSQL_ASSOC);

  if($_GET['org_id']!=="")
  {
  $org_razdel = " AND `org_id` = '".$_GET['org_id']."' ";
  $old_org_id = $_GET['org_id'];
  }
   else 
   {
   $org_razdel = " AND `org_id` = '".$result_org_no['org_id']."' ";
   $old_org_id = $result_org_no['org_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
  $query1 = "SELECT * FROM `tbl_razdel` WHERE `visible` = 'show' ".$org_razdel." ORDER BY position LIMIT $lim_ogr";
  $result = mysql_query($query1);
    if(!$result) puterror($TEXT['error-tbl15']);
     if(mysql_num_rows($result)>0);
      {
       while($razd = mysql_fetch_array($result,MYSQL_ASSOC))
        {
        echo "<tr align=left>
               <td width='33px'><img alt='Раздел' src='img/documents.png' /></td>
               <td><a href='documents.php?razd_id=".$razd['razd_id']."&amp;org_id=".$_GET['org_id']."'><span class='support4'>".$razd['razdel']."</span></a></td>
              </tr>";
        }
      }
?>
</table>
     <?php
       $query_count = mysql_query("SELECT COUNT(razd_id) FROM tbl_razdel WHERE `visible` = 'show' $org_razdel");
       $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='razdel.php?k=".$k."&amp;org_id=".$old_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='razdel.php?k=".$k."&amp;org_id=".$old_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=razdel.php?k=".$k."&amp;org_id=".$old_org_id.">".$j."</option>";
                       else echo "<option value=razdel.php?k=".$k."&amp;org_id=".$old_org_id.">".$j."</option>";
                    }
                    ?>
                    </select>
                    </td>
                   </tr>
                  </table>
                 <?php
                }
               ?>
</div>
<?php
  require_once "utils/bottom.php";
?>