<?php
session_start();
?>
<!DOCTYPE html>
<html lang="no">
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta charset="UTF-8">
  <meta name="theme-color" content="#263238"/>
  <link rel="icon" type="image/png" href="/dist/favicon.png">
  <link rel="stylesheet" href="/css/main.css">
  
  <style media="screen">

  #upload_button 
  {
    display: inline-block;
  }
  #upload_button input[type=file] {
    display:none;
  }

  </style>
  
    <script>
  const copyToClipboard = str => {
    const el = document.createElement('textarea');
    el.value = str;
    el.setAttribute('readonly', '');
    el.style.position = 'absolute';
    el.style.left = '-9999px';
    document.body.appendChild(el);
    el.select();
    document.execCommand('copy');
    document.body.removeChild(el);
  };
  </script>
</head>
<body class="theme-auto">

  <?php include "../common/header.html"; ?>

<body>

<div class="cont">
  <h1 class="center-txt">Filopplasting</h1>
  <p class="center-txt">
    Her kan du laste opp filer for å dele med andre. Filene kan være maks 5GB.<br /> Serveren ligger i Kristiansand og har 500/500 internet <br />
    All opplasting skjer på eget ansvar.
  </p>
  <div class="center-txt">
    <a href="http://trygve.me/filopplasting/filer/">Se alle filer</a>
  </div>
  <hr class="my-4">
   <div class="center-txt">
     <form action="upload.php" method="post" enctype="multipart/form-data">
       <div class="form-group">
         <input type="hidden" name="<?php echo ini_get("session.upload_progress.name"); ?>" value="123" />
         <input type="file" name="file" class="" >
         <button type="submit" class="btn btn-primary">Last opp </button>
       </div>
     </form>  
   </div>
  <?php
    $errorMSG = '
    <div class="alert alert-warning" role="alert">
      Hmmmm 🤔 Her var det visst noe som gikk galt.
    </div>';

    $bannedMSG = '
    <div class="alert alert-warning" role="alert">
      Denne filtypen er ikke tillatt. 
    </div>';


    if(isset($_SESSION['fileupload-response'])) {
      if($_SESSION['fileupload-response'] == "success") {

        $successMSG = '
        <div class="alert alert-primary center" role="alert">
        '
        . $_SESSION['linkData'] . 
        '
        <button type="button" class="btn btn-primary" onclick="copyToClipboard(\'' . $_SESSION['link'] . '\')">Kopier lenke</button>
        </div>
        ';

        echo($successMSG);
        }
      elseif ($_SESSION['fileupload-response'] == "failed") {
        echo($errorMSG);
      }
      elseif ($_SESSION['fileupload-response'] == "banned") {
        echo($bannedMSG);
      }
          session_destroy();
        }
    ?>
</ul>
</div>
</body>
</html>