<?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('tema', '../');
?>        
               
            <ul class="menu pmenu">
              <li><a href="index.php" class="aktual" title="zadanie fototémy">Úvod</a></li>
              <li><a href="galeria.php" title="galeria fototémy">Galéria</a></li>
              <li><a href="archiv.php" title="staré fototémy">Archív</a></li>
          
<?php
if (!(isset($_SESSION['login']) && ($_SESSION['login'] != ""))) :
// pouzivatel sa musi prihlasit, treba zobrazit prihlasovaci formular
?>
<?
else :
// pouzivatel je prihlaseny
    ?>
              <li class="medzera">&nbsp;</li>
              <li><a href="vloz.php" title="vloženie fotky do fototémy">Vložiť fotografiu</a></li>
    
<?php
endif; // kontrola SESSION
  

        	
?>                    
          
            </ul>
        <div class="obsah">   
                  
<?php

$sql = "SELECT C.nadpis, C.text
        FROM kpf_clanky C
        WHERE C.kategoria = 'Fototéma'
        ORDER BY cas DESC
        LIMIT 1;";
$result = mysql_query($sql, $link);
    		if ($result) {
    		  $pocet = mysql_num_rows($result);
    		  if ($pocet != '0') {
    		    $row = mysql_fetch_assoc($result);
            echo '<h2>'.$row['nadpis'].'</h2>';
            echo $row['text']; 
          } else echo '<p>Nová téma ešte nebola spustená.</p>';
    		}
        
         

$sql = "(SELECT P.*, A.*, sum(H.body) AS body
            FROM kpf_tema_photos P, kpf_author A, kpf_tema_hodnot H
            WHERE H.id=P.id AND P.aid=A.aid AND P.tema = 0
            GROUP BY H.id)
            UNION
            (SELECT P.*, A.*, 0 AS body
            FROM kpf_tema_photos P, kpf_author A, kpf_tema_hodnot H
            WHERE P.aid=A.aid AND P.tema = 0 AND P.id NOT IN (SELECT HH.id FROM kpf_tema_hodnot HH))
            ORDER BY pridane DESC
            LIMIT 5;";
		$result = mysql_query($sql, $link);
        		if ($result) {
        		  $pocet = mysql_num_rows($result);
        		  if ($pocet > 0) {
                echo '<hr/>';
                echo '<h2>Najnovšie <em>fotografie</em></h2>';  
          		  while ($row = mysql_fetch_assoc($result)) {
          		    $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">';                  
                  echo "<a href='photo.php?id=".$row['id']."&tem=0'>";    		    
                  echo "<img src='photos/small/".$row['foto']."' class='".$c."' alt='".$row['nazov']."' title='".$row['nazov']."' /></a></span>
        ";
                  echo '<a href="photo.php?id='.$row['id'].'&tem=0">'.$row['nazov'].'</a> <em>('.$row['body'].')</em><br/>';
                  echo '<a href="../author.php?id='.$row['aid'].'" class="fmeno">'.$row['meno'].' '.$row['priezvisko'].'</a>
      </p>';
                  echo '
                  
';
                 }
               } else {
                echo '<p><strong>Fotogaléria je prázdna.</strong></p>';
              }

        			mysql_free_result($result);
        		} else {
        			echo '<p style="color: #FF0000;">Chyba pri získavaní údajov z databázy - ' . mysql_errno($link) . ': ' . mysql_error($link) . '</p>';
        		}
?>  
     	
<?php
}
}
include('../includes/pata.php')        	
?>  