<?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">
          
<?php

		  $zobraz_formular = false;
  		if (isset($_POST['submit'])) {
              $sql = "INSERT INTO kpf_news (nid,aid,news,kedy) VALUES (NULL, '". $_SESSION["aid"] . "', '". $_POST["text"] ."', NOW());";
           		$result = mysql_query($sql, $link);
           		if ($result) {
                header("Location: vypis.php");
                      
          		} else {
        				echo '<p style="color: #FF0000;">Novinka NEbola odoslaná, nastal problém pri zápise do databázy - ' . mysql_errno($link) . ': ' . mysql_error($link) . '</p>';                
              }  
      } else {
        if ($_SESSION['aid'] == 0){
        $zobraz_formular = false;
        }
        else {
        $zobraz_formular = true;
        }
      }
      ?>
          
      <?php if ($zobraz_formular) : ?>    
          <h2>Vložiť <em>novinku</em></h2>
                  
          
              <form class="login" action="<?php echo $_SERVER['REQUEST_URI'] ?>" method="post">
                <p><textarea name="text" cols="57" rows="4"></textarea></p>
                <input class="ok" name="submit" type="submit" id="submit" value="Vložiť"/>
              </form>
              
              
      <?php
        else :
        if ($_SESSION['aid'] == 0){
      ?>
      <h2>Co ty chces vkladat?</h2>
      
      <?php
      }
      endif; // kontrola SESSION
      ?>      
      

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