<?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">   
                  
    		    <h2>Zmazanie <em>fotky</em></h2>
          
<?php
      
      
    if (isset($_GET['id']) AND ($_GET['id'] != '')) {
    
      $sql = "SELECT P.aid
              FROM kpf_photos P
              WHERE P.id= '".$_GET['id']."'";            
      $result = mysql_query($sql, $link);
      if ($result) {
  		  $row = mysql_fetch_assoc($result);
        if ($row['aid'] == $_SESSION['aid'])
          $zobraz = true;
        else $zobraz = false; 
      }

          
      if ($zobraz){          
      
        $sql = "SELECT P.*
                FROM kpf_photos P
                WHERE P.id=".$_GET['id'].";";
        $result = mysql_query($sql, $link);
        if ($result){
          $row = mysql_fetch_assoc($result);
          echo '<p>Zmazať túto fotku?<br /><img src="photos/small/'.$row['foto'].'" alt="'.$row['nazov'].'" title="'.$row['nazov'].'" /><br /><a href="photo_zmaz.php?id='.$_GET['id'].'&amp;del=ano">Ano</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="photo_zmaz.php?id='.$_GET['id'].'&amp;del=nie">Nie</a></p>';
        }
        
        if ($_GET['del'] == 'nie'){
          header("location: author.php?id=".$_SESSION['aid']);
        } 
        
        if ($_GET['del'] == 'ano'){
          $sql = "DELETE H.*
                  FROM kpf_hodnot H
                  WHERE H.id=".$_GET['id'].";";
          $result = mysql_query($sql, $link);
          if ($result) {
            echo 'komentare zmazane';   
          }
          
          $sql = "DELETE P.*
                   FROM kpf_photos P
                   WHERE P.id=".$_GET['id'].";";
           $result = mysql_query($sql, $link);
          if ($result) {
            unlink('photos/small/'.$_SESSION['aid'].'-'.$_GET['id'].'.jpg');
            unlink('photos/'.$_SESSION['aid'].'-'.$_GET['id'].'.jpg');
            header("location: author.php?id=".$_SESSION['aid']);   
          }    
        }        
          
      } else echo '<p>Fotku môže mazať iba jej autor.</p>';
    } else echo '<p>Treba zadat ID.</p>';
    // end vyber db
  } // end spojenie s db
  mysql_close($link);
}
include('includes/pata.php');
      ?>
