<?php
  if (isset($_POST['login']) && ($_POST['login'] != "") && isset($_POST['heslo']) && ($_POST['heslo'] != "")) {
    $sql = "SELECT * FROM kpf_author WHERE login='" . $_POST['login'] . "' AND heslo=MD5('" . $_POST['heslo'] . "') LIMIT 1;";
	  $result = mysql_query($sql, $link);
	  if ($result) {
	    if ($row = mysql_fetch_assoc($result)) {
			  $_SESSION['aid'] = $row['aid'];
		    $_SESSION['login'] = $row['login']; 
		    $_SESSION['meno'] = $row['meno']; 
		    $_SESSION['priezvisko'] = $row['priezvisko']; 
		    $_SESSION['afotka'] = $row['afotka']; 
      }
		}
  
  }
   elseif (isset($_GET['action']) and $_GET['action']=="odhlas"){ 
    $_SESSION = array();
    session_destroy();
    if (($_GET['kat'] != '') AND ($_GET['str'] != ''))
      header("location: ".$_SERVER['PHP_SELF']."?kat=".$_GET['kat']."&str=".$_GET['str']);
    elseif (($_GET['id'] != '') AND ($_GET['str'] != ''))
      header("location: ".$_SERVER['PHP_SELF']."?id=".$_GET['id']."&str=".$_GET['str']);  
    elseif (($_GET['id'] != '') AND ($_GET['kat'] != '') AND ($_GET['aid'] != ''))
      header("location: ".$_SERVER['PHP_SELF']."?id=".$_GET['id']."&kat=".$_GET['kat']."&aid=".$_GET['aid']);
    elseif (($_GET['id'] != '') AND ($_GET['tem'] != '') AND ($_GET['aid'] != ''))
      header("location: ".$_SERVER['PHP_SELF']."?id=".$_GET['id']."&tem=".$_GET['tem']."&aid=".$_GET['aid']);    
    elseif ($_GET['str'] != '') 
      header("location: ".$_SERVER['PHP_SELF']."?str=".$_GET['str']);
    elseif ($_GET['kat'] != '') 
      header("location: ".$_SERVER['PHP_SELF']."?kat=".$_GET['kat']);    
    elseif ($_GET['id'] != '')
      header("location: ".$_SERVER['PHP_SELF']."?id=".$_GET['id']);
    elseif ($_GET['ord'] != '') 
      header("location: ".$_SERVER['PHP_SELF']."?ord=".$_GET['ord']);
    else
      header("location: ".$_SERVER['PHP_SELF']);
    exit;
  }
  function odkaz($kam) {
?>
      <div class="vedla">    
<?php
  if (!(isset($_SESSION['login']) && ($_SESSION['login'] != ""))) :
?>

    <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post" class="login">
                <p><em>login</em><input name="login" value="" size="15" type="text"/><br />
			          <em>heslo</em><input name="heslo" value="" size="15" type="password"/><br />
			          <em></em><input class="ok" name="submit" type="submit" value="Vstupiť" /></p>
    </form>
    
<?php
else :
// pouzivatel je prihlaseny 
  $adr = "http://sedf-klub.sk/photos/authors/".$_SESSION['afotka'];
  echo "<img src='".$adr."' alt='".$row['meno']." ".$row['priezvisko']."' title='".$row['meno']." ".$row['priezvisko']."' />";
  
?>

    <a href="<?php echo $kam; ?>author.php?id=<?php echo $_SESSION['aid']; ?>" class="meno"><?php echo $_SESSION['meno']; ?> <span><?php echo $_SESSION['priezvisko']; ?></span></a>
    <br /><br />
<?php

  
  if($_SESSION['aid'] != '1'){
?>
      <a href="<?php echo $kam; ?>vloz.php"><span>vložiť</span> fotografiu</a><br />
      <a href="<?php echo $kam; ?>nastav.php">na<span>stav</span>enie</a><br />
      <a href="<?php echo $kam; ?>nastav_fotka.php"><span>fotka</span> autora</a><br />
      
<?php
}
if ($_SESSION['aid'] == '1'){
?>
      <a href="<?php echo $kam; ?>registracia.php">registracia</a><br />
      <a href="<?php echo $kam; ?>zmena.php"><span>zmeniť</span> tému</a><br />
      <a href="<?php echo $kam; ?>zmaz.php">vymazať <span>člena</span></a><br />
<?php
}
      if (($_GET['kat'] != '') AND ($_GET['str'] != ''))
        echo '<br /><a href="?kat='.$_GET['kat'].'&str='.$_GET['str'].'&action=odhlas"><b>odhlásiť</b></a>';
      elseif (($_GET['id'] != '') AND ($_GET['str'] != ''))
        echo '<br /><a href="?id='.$_GET['id'].'&str='.$_GET['str'].'&action=odhlas"><b>odhlásiť</b></a>';
      elseif (($_GET['id'] != '') AND ($_GET['kat'] != '') AND ($_GET['aid'] != ''))
        echo '<br /><a href="?id='.$_GET['id'].'&kat='.$_GET['kat'].'&aid='.$_GET['aid'].'&action=odhlas"><b>odhlásiť</b></a>';
      elseif (($_GET['id'] != '') AND ($_GET['tem'] != '') AND ($_GET['aid'] != ''))
        echo '<br /><a href="?id='.$_GET['id'].'&tem='.$_GET['tem'].'&aid='.$_GET['aid'].'&action=odhlas"><b>odhlásiť</b></a>';
      elseif ($_GET['str'] != '')
        echo '<br /><a href="?str='.$_GET['str'].'&action=odhlas"><b>odhlásiť</b></a>';
      elseif ($_GET['kat'] != '')
        echo '<br /><a href="?kat='.$_GET['kat'].'&action=odhlas"><b>odhlásiť</b></a>';
      elseif ($_GET['id'] != '')
        echo '<br /><a href="?id='.$_GET['id'].'&action=odhlas"><b>odhlásiť</b></a>';
      elseif ($_GET['ord'] != '')
        echo '<br /><a href="?ord='.$_GET['ord'].'&action=odhlas"><b>odhlásiť</b></a>';
      else
        echo '<br /><a href="?action=odhlas"><b>odhlásiť</b></a>';
        
endif; // kontrola SESSION
?>           
          </div>    
<?php
  }
?>          
