<?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('','');
?>
      
        <div class="obsah">   

          <h2>Fotka <em>autora</em></h2>
          
<?php
  
    if (isset($_POST["submit"])){
  		$size = getimagesize($_FILES['foto']['tmp_name']);
      if (($size[0] == 80) && ($size[1] == 100) && isset($_FILES['foto']) && ($_FILES['foto']['size'] < 51200)){
      $nazov = 'xxx';
      if (isset($_FILES['foto'])) :
      	  if ($_FILES['foto']['error'] == UPLOAD_ERR_OK) {
      			if (is_uploaded_file($_FILES['foto']['tmp_name'])) {
      			  $nazov = $_SESSION['aid'].'.jpg';
      				move_uploaded_file($_FILES['foto']['tmp_name'], 'photos/authors/' . $nazov);
      			}
      		} elseif ($_FILES['foto']['error'] != UPLOAD_ERR_NO_FILE) { 
               echo '<p style="color: #FF0000;">Foto NEbolo prenesené, nastal problém pri uploadovaní súboru. Chyba č. ' . $_FILES['obr']['error'] . '</p>';
      	   	  $zobraz_formular = true;
          }
      	endif;
      	if ($nazov !== 'xxx'){ 
      	
      	  $sql = "UPDATE kpf_author SET afotka='$nazov' WHERE aid='".$_SESSION['aid']."';";

          $result = mysql_query($sql, $link);
          if ($result) {      	  
                header("Location: index.php");
          }
        }
        else echo 'Fotka nezodpoveda kriteriam.<br /><br />';
      }
      else {
        echo 'Fotka nezodpoveda kriteriam. <br /><br />';
        }
    }
  
  if ($_SESSION['aid'] == 0){$zobraz_formular = FALSE;}
  else $zobraz_formular = TRUE;

      if ($zobraz_formular) :  ?>

              <p>Veľkost <strong>80x100</strong> pixelov.<br/>Subor musi byt vo formate <strong>JPG</strong>.<br/> Nesmie byt vacsi ako <strong>50kb</strong>.</p>
              <form class="login" action="<?php echo $_SERVER['REQUEST_URI'] ?>" method="post" enctype="multipart/form-data">
                <p class="form">
                  <input type="file" name="foto" size="35" /><input type="hidden" name="MAX_FILE_SIZE" value="1" /><br/>
                  <input class="ok" name="submit" type="submit" id="submit" value="vložiť"/>
                </p>                
              </form>
      <?php
        else :
        if ($_SESSION['aid'] == 0){
      ?>
      <p>nie si prihlaseny, fotku nemit nemozes!</p>
      
      <?php
      }
      endif; // kontrola SESSION
      ?>     

<?php
	}	
	mysql_close($link);
}
include('includes/pata.php'); 
?>
