<?php
  include '../includes/Global.php';
  
    TestLicence('3');

  if (array_key_exists('Mode', $_GET)) {
    $Mode = $_GET['Mode'];
  } else {
    $Mode = '';
  }
    
  If ($Mode == '') { // formulář přidání linku 
?>
  <form enctype="multipart/form-data" action="AddLinks.php?Mode=AddLinks" method="post">
  <table border="0">
    <tr><td>Název:</td><td><input type="text" name="Name"></td></tr>
    <tr><td>Adresa:</td><td><input type="text" value="http://" name="Address">Formát: http://adresa/</td></tr>
    <tr><td>Uživatel: </td><td><input type="text" name="User" value="<?php echo $_SESSION['User']; ?>"></td></tr>
    <tr><td>Popis: </td><td><textarea cols="30" name="Description" rows="10"></textarea></td></tr>
    <tr><td><input type="submit" value="Odeslat"></td></tr>
  </table>
  </form>

<?php
  }

  if ($Mode == 'AddLinks') {  //přidání linku
    $Name = mysql_escape_string($_POST['Name']);
    $User = mysql_escape_string($_POST['User']);
    $Address = mysql_escape_string($_POST['Address']);
    $Description = mysql_escape_string($_POST['Description']);
    echo('Jméno: '.$Name.'<br>');
    echo('Uživatel: '.$User.'<br>');
    echo('Address: '.$Address.'<br>');
    echo('Popis: '.$Description.'<br>');
    
    $sql = "SELECT max(ID) FROM links";
    $ID = $db->SQLCommand($sql);
    $Line = mysql_fetch_row($ID);
    $ID = $Line[0]+1;
    $sql = "INSERT links VALUE('$ID','$Name','$Description','$Address',now(),'$User')";
      $db->SQLCommand($sql);
      echo 'Odkaz '.$Name.' byl uložen';
      WriteLog('Odkaz byl uložen: '.$Name.' ID: '.$ID.' Popis: '.$Description.' User: '.$User.'Address: '.$Address,'2');
  }
  
  //TODO: editování, mazání
  
  ShowFooter()
?>
