<?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('atelier','');
?>
          
        <div class="obsah">
          <h2>Zmazanie <em>člena</em> klubu</h2>
          
          

<?php
   if ($_SESSION['aid'] == 1){
     $zobraz = true;
   }
   else {
     $zobraz = false;
   }
   
   if ($zobraz){
     echo '<p class="zmaz">';
   
     if (isset($_GET['id'])) {
       echo 'ideš mazať osobu s menom <strong class="meno"><a href="?id='.$_GET['id'].'&author='.$_GET['id'].'">'.$_GET['meno'].'</a></strong><br />';
       $sql = "SELECT count(H.hid) AS kom
               FROM kpf_hodnot H
               WHERE H.aid=".$_GET['id'].";";
	     $result = mysql_query($sql, $link);
       if ($result) {
         $row = mysql_fetch_assoc($result);
         if ($row['kom'] > 0) echo '<a href="?id='.$_GET['id'].'&meno='.$_GET['meno'].'&komenty='.$_GET['id'].'">zmaž komentáre ('.$row['kom'].')</a>';
       }
       
       if (isset($_GET['author'])){
         $sql = "DELETE A.*
                 FROM kpf_author A
                 WHERE A.aid=".$_GET['author'].";";
	       $result = mysql_query($sql, $link);
         if ($result) {
           $_GET['author'] = 0;
           header("location: zmaz.php"); 
         }
       }
       
       if (isset($_GET['komenty'])){
         $sql = "DELETE H.*
                 FROM kpf_hodnot H
                 WHERE H.aid=".$_GET['komenty'].";";
	       $result = mysql_query($sql, $link);
         if ($result) {
           $_GET['komenty'] = 0;
           header("location: ".$_SERVER['PHP_SELF']."?id=".$_GET['id']."&meno=".$_GET['meno']);   
         }       
       }       
       
       $sql = "SELECT P.*
               FROM kpf_photos P
               WHERE P.aid=".$_GET['id']."
               ORDER BY pridane DESC;";
	     $result = mysql_query($sql, $link);
       if ($result) {
         $abc == 0;
         while ($row = mysql_fetch_assoc($result)) {
           $abc++;
           echo '<p class="foto mini">';
           echo $row['nazov'].'<br />';
           $sql2 = "SELECT count(H.hid) AS kolko
                   FROM kpf_hodnot H
                   WHERE H.id=".$row['id'].";";
	         $result2 = mysql_query($sql2, $link);
           if ($result2) {
           $row2 = mysql_fetch_assoc($result2);
             if ($row2['kolko'] > 0) echo '<a href="?id='.$_GET['id'].'&meno='.$_GET['meno'].'&body='.$row['id'].'" class="edit">zmaž body ('.$row2['kolko'].')</a>';
             else echo '<a href="?id='.$_GET['id'].'&meno='.$_GET['meno'].'&foto='.$row['id'].'" class="edit black">vymazat fotku</a>';
           }          
           
           echo '</p>';
           $zvysok = $abc%5;
           if (($zvysok == 0)) echo '<div class="clear"></div>'; 
         }
        
       }
       
       if (isset($_GET['foto'])){
         $sql = "DELETE P.*
                 FROM kpf_photos P
                 WHERE P.id=".$_GET['foto'].";";
	       $result = mysql_query($sql, $link);
         if ($result) {
           unlink('photos/small/'.$_GET['id'].'-'.$_GET['foto'].'.jpg');
           unlink('photos/'.$_GET['id'].'-'.$_GET['foto'].'.jpg');
           header("location: ".$_SERVER['PHP_SELF']."?id=".$_GET['id']."&meno=".$_GET['meno']);   
         }
       }
       
       if (isset($_GET['body'])){
         $sql = "DELETE H.*
                 FROM kpf_hodnot H
                 WHERE H.id=".$_GET['body'].";";
	       $result = mysql_query($sql, $link);
         if ($result) {
           $_GET['body'] = 0;
           header("location: ".$_SERVER['PHP_SELF']."?id=".$_GET['id']."&meno=".$_GET['meno']);   
         }       
       }
       
       
     }   
     else{
   
     $sql = "SELECT A.priezvisko, A.aid
             FROM kpf_author A
             ORDER BY A.aid ASC
             ;";
	   $result = mysql_query($sql, $link);
	   if ($result) {
       while ($row = mysql_fetch_assoc($result)) {
         echo '<a href="?id='.$row['aid'].'&meno='.$row['priezvisko'].'">'.$row['aid'].' '.$row['priezvisko'].'</a><br />';
       }
     }
     }   
     echo '</p>';
   }
   else {
     echo '<p>nie si admin, mazat nemozes!</p>';
   }
        		}   
	   mysql_close($link);   
 
	}
include('includes/pata.php'); 
?>
