<?php

include('includes/hlava.php');
title('Klub priateľov fotografie', '');

if ($link) {
  if ($db_selected) {
  
include('includes/vedla.php');
odkaz('');
include('includes/menu.php');
menu('galeria','');
?>        
          
        <div class="obsah">   
        
        <form class="login" action="<?php echo $_SERVER['REQUEST_URI'] ?>" method="get">  
          <p><select name="kat" onchange="this.form.submit();">
            <option value="0">Všetky</option>
<?php
  include('includes/kategoria.php'); 
?>
         </select>
         <input class="ok" type="submit" value="OK"/></p>
        </form>
        
<?php

      $kolko = '20';

  		if (!isset($_GET['str']) || (int) $_GET['str'] == 0) $od = 1;
  		else $od = $_GET['str'];



      if ($_GET['kat']) {
      $i=$_GET['kat'];
      
      $sql = "SELECT P.id, P.aid, P.foto, P.nazov
             FROM kpf_photos P
             WHERE P.kategoria='". $pole[$i] ."'
             ORDER BY P.pridane DESC
             LIMIT " . ($od - 1) * $kolko . ", $kolko;";
             
      $sql2 = "SELECT count(P.id) as zopar
               FROM kpf_photos P
               WHERE P.kategoria='". $pole[$i] ."';";
      
      }
      else {
      $sql = "SELECT P.id, P.aid, P.foto, P.nazov
             FROM kpf_photos P
             ORDER BY P.pridane DESC
             LIMIT " . ($od - 1) * $kolko . ", $kolko;";
      
      $sql2 = "SELECT count(P.id) as zopar FROM kpf_photos P;";
             
      }             
     
		  $result = mysql_query($sql, $link);
		  if ($result) {
		  
		  
		  $result2 = mysql_query($sql2, $link);
		  if ($result2) {
        $row2 = mysql_fetch_assoc($result2);
        
        
        $pocetstran = ceil($row2['zopar'] / $kolko);
        if ($pocetstran > '1'){
          echo '<p class="str">';
            
    for ($i = 1; $i <= $pocetstran; $i++) {
        if ($i < 10) $i = '0'.$i;
        if ((($i > $od - 3) && ($i < $od + 3)) || ($i == 1) || ($i == $pocetstran) AND ($od > 5)) {
            // nahrada cisel skrytych stranok za bodky
            if (($i != $pocetstran) AND (($i < $od+2) OR ($i > $pocetstran-3))) $bodky_l = ' | '; else $bodky_l = '';
            $bodky_p = '';
            if (($i == 1) AND ($od > 5)) $bodky_l = ' ... ';
            if (($i == $pocetstran) && ($od < $pocetstran - 4)) $bodky_p = ' ... ';
            if ($i == $od) {
                if ($i != $pocetstran) echo ($i).' | '; else echo ($i);// aktualnu stranku zvyrazni inou farbou
            } elseif (($i == 1) AND ($od > 5)) {
                echo '<a href="?'.(($_GET['kat']) ? 'kat='.$_GET['kat'].'&' : '').'str='.$i.'" title="Strana '.($i).'">začiatok</a> '.$bodky_l;
            } elseif (($i == $pocetstran) AND ($od < $pocetstran-4)) {
                echo $bodky_p.' <a href="?'.(($_GET['kat']) ? 'kat='.$_GET['kat'].'&' : '').'str='.$i.'" title="Strana '.($i).'">koniec</a>';
            } else {
                echo $bodky_p.' <a href="?'.(($_GET['kat']) ? 'kat='.$_GET['kat'].'&' : '').'str='.$i.'" title="Strana '.($i).'">'.($i).'</a> '.$bodky_l;
            }
        } if (($i == $pocetstran-1) && ($od == $pocetstran-4) && ($pocetstran > 7)) echo '<a href="?'.(($_GET['kat']) ? 'kat='.$_GET['kat'].'&' : '').'str='.$i.'" title="Strana '.($i).'">'.($i).'</a> | ';
          if (($i == 2) && ($od == 5)) echo ' <a href="?'.(($_GET['kat']) ? 'kat='.$_GET['kat'].'&' : '').'str='.$i.'" title="Strana '.($i).'">'.($i).'</a> | ';
          elseif (($od < 6) AND ($i == 7)) echo ' <a href="?'.(($_GET['kat']) ? 'kat='.$_GET['kat'].'&' : '').'str='.$i.'" title="Strana '.($i).'">'.($i).'</a> ... <a href="?'.(($_GET['kat']) ? 'kat='.$_GET['kat'].'&' : '').'str='.$pocetstran.'" title="Strana '.($pocetstran).'">koniec</a>';
          elseif (($od < 6) AND ($i < 8) AND ($od != $i) AND ($i != $pocetstran)) echo ' <a href="?'.(($_GET['kat']) ? 'kat='.$_GET['kat'].'&' : '').'str='.$i.'" title="Strana '.($i).'">'.($i).'</a> | ';
          elseif (($od < 6) AND ($i < 8) AND ($od != $i)) echo ' <a href="?'.(($_GET['kat']) ? 'kat='.$_GET['kat'].'&' : '').'str='.$i.'" title="Strana '.($i).'">'.($i).'</a>';
          elseif (($od < 6) AND ($i < 8) AND ($od == $i) AND ($i != $pocetstran)) echo $i.' |';
          elseif (($od < 6) AND ($i < 8) AND ($od == $i)) echo $i.'';
    }
            
            /*for ($i = 1; $i<=$pocetstran; $i++) {
              if ($od == $i){
                if ($i == $pocetstran) echo $i;
                else echo $i. ' | ';
              } elseif ((($i > $od+2) AND ($i != $pocetstran)) OR (($i < $od-2) AND ($i != 1))) {
                echo '';
              } elseif (($i > $pocetstran-2) AND ($i < $pocetstran)) {
                  echo 'aaaaaaaa <a href="?'.(($_GET['kat']) ? 'kat='.$_GET['kat'].'&' : '').'str='.$i.'">'.$i.'</a> ';
              } else {
                if ($i == $pocetstran) {
                  echo ' ... | <a href="?'.(($_GET['kat']) ? 'kat='.$_GET['kat'].'&' : '').'str='.$i.'">'.$i.'</a> ';
                }elseif($i == 1 ){
                  echo '<a href="?'.(($_GET['kat']) ? 'kat='.$_GET['kat'].'&' : '').'str='.$i.'">'.$i.'</a> | ... | ';
                } 
                
                 else echo '<a href="?'.(($_GET['kat']) ? 'kat='.$_GET['kat'].'&' : '').'str='.$i.'">'.$i.'</a> | ';
              }
            }*/
          echo '</p>
          ';
        }
        
        
      } else echo 'chyba';
		                   		                		 
        $abc = 0; 
        if ($_GET['kat'] == '') $_GET['kat'] = '0';  
        if ($_GET['aid'] == '') $_GET['aid'] = '0';
        while ($row = mysql_fetch_assoc($result)) {
          $abc ++; 
  		    $subor = 'photos/small/'.$row['foto'];
          list($sirka, $vyska) = getimagesize($subor);
          if ($sirka == '130') $c = 's';
          else $c = 'v';
          echo '<p class="foto">';
          echo '<span class="photos"><a href="photo.php?id='.$row['id'].'&kat='.$_GET['kat'].'&aid='.$_GET['aid'].'">';
          echo '<img src="photos/small/'.$row['foto'].'" class="'.$c.'" alt="'.$row['nazov'].'" title="'.$row['nazov'].'" /></a></span>
                    ';
                    
          $sql2 = "SELECT sum(H.body) AS body
                   FROM kpf_hodnot H
                   WHERE H.id=".$row['id'].";";
    		  $result2 = mysql_query($sql2, $link);
    		  if ($result2) {
            $row2 = mysql_fetch_assoc($result2);
            if ($row2['body'] == '') $row2['body'] = '0';
            echo '<a href="photo.php?id='.$row['id'].'&kat='.$_GET['kat'].'&aid='.$_GET['aid'].'">'.$row['nazov'].'</a> <em>('.$row2['body'].')</em><br/>';          
          }                             
                                 
          
          $sql2 = "SELECT A.meno, A.priezvisko
                  FROM kpf_author A
                  WHERE A.aid=".$row['aid'].";";
    		  $result2 = mysql_query($sql2, $link);
    		  if ($result2) {
            $row2 = mysql_fetch_assoc($result2);
            echo '<a href="author.php?id='.$row['aid'].'" class="fmeno">'.$row2['meno'].' '.$row2['priezvisko'].'</a></p>';
          }
                  $zvysok = $abc%5;
                  if (($zvysok == 0)) echo '
                  <p class="clear"></p>
                  ';
                                             
        }
        
      }               

        		}   
	   mysql_close($link);   
 
	}
 
include('includes/pata.php');
?>