<?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-photo'];
  require_once "config.php";
  require_once "utils/top_photogal.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(!empty($_GET['org_id'])) $org_photo = " AND `org_id` = '".$_GET['org_id']."' ";
   else $org_photo = " AND `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="80%">
<?php
     $query = "SELECT * FROM `tbl_meropriyatiya` WHERE `visible` = 'show' ".$org_photo." ORDER BY position LIMIT $lim_ogr";
     $result = mysql_query($query);
     if(!$result) puterror($TEXT['error-tbl12']);
      if(mysql_num_rows($result)>0);
       {
        while($result_merop = mysql_fetch_array($result,MYSQL_ASSOC))
         {
         echo "<tr align='left'>
               <td width='5%'><img alt='картинка' src='img/photo.gif'></td>
               <td><a href='photos.php?mer_id=".$result_merop['mer_id']."&amp;org_id=".$_GET['org_id']."'><span class='support4'>".$result_merop['meropriyatie']."</span></a></td>
               </tr>";
         }
       }
?>
</table>
     <?php
       $query_count = mysql_query("SELECT COUNT(mer_id) FROM tbl_meropriyatiya WHERE `visible` = 'show' ".$org_photo."");
       $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='photoalbum.php?k=".$k."&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='photoalbum.php?k=".$k."&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=photoalbum.php?k=".$k."&amp;org_id=".$_GET['org_id'].">".$j."</option>";
                       else echo "<option value=photoalbum.php?k=".$k."&amp;org_id=".$_GET['org_id'].">".$j."</option>";
                    }
                    ?>
                    </select>
                    </td>
                   </tr>
                  </table>
                 <?php
                }
               ?>
<?php
  require_once "utils/bottom.php";
?>