<?php

$kolko = 20;

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

if ($link) {
  if ($db_selected) {
  
include('includes/vedla.php');
odkaz('');
include('includes/menu.php');
menu('clenovia','');
?>        
          
        <div class="obsah">   
          
<?php          
        		
  if (isset($_GET['id'])) {            
            $sql = "SELECT A.*
                    FROM kpf_author A
                    WHERE A.aid=".$_GET['id'].";";
        		$result = mysql_query($sql, $link);
            if ($result) {
          		  while ($row = mysql_fetch_assoc($result)) {
                    echo '<h2>'.$row['meno'].' <em>'.$row['priezvisko'].'</em></h2>';
                    echo '<p class="info_a">';
                    echo "<img src='photos/authors/".$row['afotka']."' alt='".$row['meno']." ".$row['priezvisko']."' title='".$row['meno']." ".$row['priezvisko']."' />";
                    $sql2 = "SELECT count(P.id) AS fotky
                            FROM kpf_photos P
                            WHERE P.aid='".$_GET['id']."'";
                    $result2 = mysql_query($sql2, $link);
                    if ($result2) {  
                      if ($row2 = mysql_fetch_assoc($result2)) {
                        if ($row2['fotky'] < 1) $row2['fotky'] = '0'; 
                        echo '<em>Fotky:</em> '.$row2['fotky'].'<br/>';
                        $fotka = $row2['fotky'];
                      }
                    } 
                    $sql2 = "SELECT sum(H.body) AS bodky
                            FROM kpf_photos P, kpf_hodnot H
                            WHERE H.id=P.id AND P.aid='".$_GET['id']."'";
                    $result2 = mysql_query($sql2, $link);
                    if ($result2) {  
                      if ($row2 = mysql_fetch_assoc($result2)) {
                        if ($row2['bodky'] < 1) $row2['bodky'] = '0'; 
                        echo '<em>Body:</em> '.$row2['bodky'].'<br/>';
                        $bod = $row2['bodky'];
                      } else {
                          echo '0';
                          $bod = '0';
                      }
                    }
                    $sql2 = "SELECT count(H.id) AS komenty
                             FROM kpf_author A, kpf_hodnot H
                             WHERE H.aid='".$_GET['id']."'
                             GROUP BY A.aid;";
                    $result2 = mysql_query($sql2, $link);
                    if ($result2) {  
                      if ($row2 = mysql_fetch_assoc($result2)) { 
                        echo '<em>Hlasy:</em> '.$row2['komenty'].'<br/>';
                      } else echo '<em>Hlasy:</em> 0<br/>';
                    } 
                    if ($fotka != 0) {
                      $priemer = round($bod / $fotka, 2);
                      echo '<em>Priemer:</em> '.$priemer.'<br /><br />';
                    }
                    if ($_SESSION['aid'] != 0) echo '<em>E-mail:</em> '.$row['mail'];
		                else echo '<br />';   
                    echo '</p>';
                    echo '
                    ';    
                }
            }
            
            if (!isset($_GET['str']) || (int) $_GET['str'] == 0) $od = 1;
		        else $od = $_GET['str'];           
		        
		        $sql = "SELECT P.id, P.aid, P.foto, P.nazov, P.index
                    FROM kpf_photos P
                    WHERE P.aid=".$_GET['id']."
                    ORDER BY P.index DESC, P.pridane DESC
                    LIMIT " . ($od - 1) * $kolko . ", $kolko;";
                    
            $sql2 = "SELECT count(id) as zopar FROM kpf_photos P WHERE ".$_GET['id']."=P.aid;";
            
            $result = mysql_query($sql, $link);
        		if ($result) {
        		
  				  $result2 = mysql_query($sql2, $link);
      		  if ($result2) {
              $row2 = mysql_fetch_assoc($result2);
              $stranok = ceil($row2['zopar'] / $kolko);
              if ($stranok > '1'){
                echo '<p class="str">';
                  for ($i = 1; $i<=$stranok; $i++) {
                    if ($od == $i){
                      if ($i == $stranok) echo $i;
                      else echo $i. ' | ';
                    } else {
                      if ($i == $stranok) 
                        echo '<a href="?id='.$_GET['id'].'&amp;str='.$i.'">'.$i.'</a>';
                        else echo '<a href="?id='.$_GET['id'].'&amp;str='.$i.'">'.$i.'</a> | ';
                    }
                  }
                echo '</p>
                ';
              }
            } else echo 'chyba';
        		
              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'].'&amp;kat='.$_GET['kat'].'&amp;aid='.$_GET['id'].'">';
                  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'].'&amp;kat='.$_GET['kat'].'&amp;aid='.$_GET['id'].'">'.$row['nazov'].'</a> <em>('.$row2['body'].')</em><br/>';
                    if (($row['aid'] == $_SESSION['aid'])){
                      echo '<a href="photo_edit.php?id='.$row['id'].'" class="edit">Editovať</a><br />';
                      echo '<a href="photo_zmaz.php?id='.$row['id'].'" class="edit">Zmazať</a><br />';
                      if ($row['index'] == '0')
                        echo '<a href="photo_index.php?id='.$row['id'].'&amp;aid='.$_GET['id'].'&amp;zmen=1" class="edit">Prezentovať</a></p>';
                      else
                        echo '<a href="photo_index.php?id='.$row['id'].'&amp;aid='.$_GET['id'].'&amp;zmen=0" class="index">NEprezentovať</a></p>';
                      }
                    $zvysok = $abc%5;
                    if (($zvysok == 0)) echo '
                    <p class="clear"></p>
                    ';          
                  } 
                  
                  echo '</p>';   
              }
                if ($stranok > '1'){
                  echo '<p class="str">';
                    for ($i = 1; $i<=$stranok; $i++) {
                      if ($od == $i){
                        if ($i == $stranok) echo $i;
                        else echo $i. ' | ';
                      } else {
                        if ($i == $stranok) 
                          echo '<a href="?id='.$_GET['id'].'&amp;str='.$i.'">'.$i.'</a>';
                          else echo '<a href="?id='.$_GET['id'].'&amp;str='.$i.'">'.$i.'</a> | ';
                      }
                    }
                  echo '</p>
                  ';
                }
            }        
        		
        } else {
        //neboli zadane vsetky potrebne udaje
        echo "<div class='lavy'><p style='color: #FF0000;'>Nebolo odoslané ID autora, ktorého treba zobraziť.</p></div>";
      }
            
            
        		        		} // end vyber db
        		mysql_close($link);
        	} // end spojenie s db
include('includes/pata.php');    

      ?>
