<?php
if (isset($_POST['dl_ID'])) {
  if (($_POST['user']['name'] != '') && ($_POST['user']['vorname'] != '')) {
    if (!file_exists('downloads2.csv')) {
      $fp = fopen('downloads2.csv', 'a');
      flock($fp,2);
      fwrite($fp, 'ID; Name; Pfad; Version; Benutzername;  Benutzervorname; Benutzeremail; Datum
      ');
      flock($fp,3);
      fclose($fp);
    }
    $fp = fopen('downloads2.csv', 'a');
    flock($fp,2);
    fwrite($fp, '1; MFP-Project;  '.$_POST['data']['link'].'; '.gmdate("D, d M Y H:i:s", filectime($_POST['data']['link'])).'; '.$_POST['user']['name'].'; '.$_POST['user']['vorname'].'; '.$_POST['user']['email'].'; '.date('D, d M Y H:i:s').'
    ');
    flock($fp,3);
    fclose($fp);
    $link = $_POST['data']['link'];
  }
  else {
    echo '<table><tr><td class="alert">Bitte alle 3 Felder ausfuellen!</td></tr></table>';
    $_Get['show_ID'] = $POST['dl_ID'];
  }
}
?>
<html>
<head>
  <title>MFP - Downloads</title>
  <link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<!-- Umgebende Tabelle / Start -->
<table border="0" width="800">
  <tr>
    <td colspan="3" width="800" height="50"></td>
  </tr>
  <tr>
    <td width="150"></td>
    <td width="500" align="center">
<?php
if (!isset($link)) {
  echo '<table border="1">';
  echo '<tr><td colspan="3" class="headline1">The MFP-Project</h2></td></tr>';
  echo '<tr><td colspan="3"></td></tr>';
  echo '<tr><td colspan="3" class="headline2"><h4>SAS version</h4></td></tr>';
  echo '<tr><td colspan="3" class="headline2"><h4>last changed: february, 1, 2004</h4></td></tr>';
  echo '<tr><td colspan="3" class="standart0">Combining selection of variables with determination of functional relationships for continuous predictors</td></tr>';
  echo '<tr><td colspan="3"></td></tr>';
  echo '<form method="post" action="'.$PHP_SELF.'">';
  echo '<input type="hidden" name="data[link]" value="downloads/MFP2neu.zip" />';
  echo '<tr><td colspan="3" class="standart1">Please enter your name and prename to start the download.</td></tr>';
  echo '<tr><td class="standart0" width="150">First name:</td><td class="standart0" width="119"><input type="text" name="user[name]" size="15"';
  if (isset($_POST['user']['name'])) echo ' value="'.$_POST['user']['name'].'"'; 
  echo '/></td><td></td></tr>';
  echo '<tr><td class="standart0" width="150">Surname:</td><td class="standart0" width="119"><input type="text" name="user[vorname]" size="15"';
  if (isset($_POST['user']['name'])) echo ' value="'.$_POST['user']['vorname'].'"'; 
  echo '/></td><td></td></tr>';
  echo '<tr><td class="standart0" width="150">E-Mail (optional):</td><td class="standart0" width="119"><input type="text" name="user[email]" size="15"';
  if (isset($_POST['user']['name'])) echo ' value="'.$_POST['user']['email'].'"'; 
  echo '/></td><td></td></tr>';
  echo '<input type="hidden" name="dl_ID" value="'.$data[0][0].'">';
  echo '<tr><td colspan="3" align="center"><input type="submit" value="-> start download <-"></td></tr>';
  echo '</form>';
  echo '</table>';
}
else {
  echo '<table border="1">';
  echo '<tr><td colspan="3" class="headline1">The MFP-Project</h2></td></tr>';
  echo '<tr><td colspan="3"></td></tr>';
  echo '<tr><td colspan="3" class="headline2">SAS version</h4></td></tr>';
  echo '<tr><td colspan="3" class="standart0"><a href="'.$link.'">click here to download</a></td></tr>';
  echo '</table>';
}
?>
<!-- Umgebende Tabelle / Ende -->
    </td>
    <td width="150"></td>
  </tr>
</table>
</body>
</html>