<?php
include './assets/functions.php';
include './settings/settings_redirector.php';
include './settings/config_redirector.php';
include_once './settings/translations/translations_US.php';

if (isset($_GET['email'])){
  //Update unscribe array
  $unscribe = array("email" => strip_tags(trim($_GET['email'])));
  
  //GET USERKEY
  $data = json_encode(array("username" => interface_user, "password" => interface_pw), JSON_UNESCAPED_UNICODE);
  //Secure data
  $payload = generate_payload($data);
  //API call
  $responses = ioServer('/v1/authorization', $payload);
  //Decode Payload
  if (!empty($responses)){$responses = decode_payload($responses);}else{$responses = '400';}
  
  if ($responses === 'NOK' || $responses === '400'){
    //Not allowed
    exit;
  } 
  else {
    // Start a new session
    session_start();    
    // Store data in session
    $_SESSION['userkey'] = $responses->userkey;
    // GET ALL POST DATA
    $data = json_encode($unscribe, JSON_UNESCAPED_UNICODE);
    // Secure data
    $payload = generate_payload($data);
    // API call
    $message_return = ioServer('/v1/application/unscribe', $payload);
    if (!empty($message_return)){
        $message_return = decode_payload($message_return);
      }
        else{
          $message_return = '400';
        }
  }
}
echo '
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1">
    <title>Unscribe</title>
    <link rel="icon" type="image/png" href="'.icon_image.'">
    <style>
    * {
        box-sizing: border-box;
        font-family: -apple-system, BlinkMacSystemFont, "segoe ui", roboto, oxygen, ubuntu, cantarell, "fira sans", "droid sans", "helvetica neue", Arial, sans-serif;
        font-size: 16px;
      }
      
      html {
        height: 100%;
      }
      
      body {
        position: relative;
        min-height: 100%;
        color: #555555;
        background-color: #FFFFFF;
        margin: 0;
        padding-bottom: 100px;
        /* Same height as footer */
      }
      
      h1, h2, h3, h4, h5 {
        color: #394352;
      }
      
      .content-wrapper {
        width: 1050px;
        margin: 0 auto;
      }
      
      header {
        position: relative;
        border-bottom: 1px solid #EEEEEE;
      }
      
      header .content-wrapper {
        display: flex;
      }
      
      
      main .myaccount h1 {
        display: block;
        font-weight: normal;
        background-color: #005655;
        color: #fff;
        margin: 0;
        padding: 40px 0;
        font-size: 50px;
        text-align: center;
        width: 100%;
      }
      
      main .myaccount {
        display: flex;
        flex-flow: wrap;
      }
      
      main .myaccount form {
        width: 100%;
      }
      
      main .myaccount h2 {
        width: 100%;
        font-weight: normal;
        font-size: 20px;
        padding: 30px 0 20px 0;
        margin: 0 0 10px 0;
        border-bottom: 1px solid #EEEEEE;
      }
      
      main .myaccount .login-register {
        display: flex;
        width: 100%;
        justify-content: space-between;
        margin-top: 40px;
      }
      
      main .myaccount .login-register h1 {
        text-align: left;
        padding-top: 15px;
      }
      
      main .myaccount .login-register .login {
        width: 100%;
        border-right: 1px solid #f6f6f6;
        padding-right: 45px;
      }
      
      main .myaccount .login-register .register {
        width: 100%;
        padding-left: 45px;
      }
      
      main .myaccount .login-register .btn {
        margin-top: 25px;
      }
      
      .btn {
        text-decoration: none;
        background: #03337a;
        border: 0;
        color: #FFFFFF;
        padding: 11px 16px;
        font-size: 14px;
        font-weight: 500;
        border-radius: 4px;
        cursor: pointer;
      }
      
      .btn:hover {
        background: #444954;
      }
      
      .btn:disabled {
        background: #ddd;
      }
      
      .form-label {
        display: block;
        padding: 20px 0 10px 0;
      }
      
      .form-field {
        width: 100%;
        padding: 10px;
        border: 1px solid #d5d5d5;
        border-radius: 4px;
        background-color: #fff;
      }
      
      footer {
        position: absolute;
        padding: 20px 0;
        width: 100%;
      }
      
      footer a {
        text-decoration: none;
        color: #555555;
      }
      
      footer a:hover {
        text-decoration: underline;
      }
      
      /* Responsive CSS below */
      @media screen and (max-width: 1050px) {
        .rhide {
          display: none;
        }
        .content-wrapper {
          width: 100%;
          padding: 0 10px;
        }
       
        main .checkout form, main .myaccount form {
          width: 100%;
        }
        main .myaccount .login-register {
          flex-flow: column;
        }
        main .myaccount .login-register .login {
          border-right: 0;
          padding: 10px;
        }
        main .myaccount .login-register .register {
          padding: 10px;
        }
        main .myaccount .menu {
          width: 100%;
          padding-right: 0;
        }
      }
      </style>
</head>
<body>
<header>
</header>
<main>       
<div class="myaccount content-wrapper">
    <div class="login-register">
        <div class="login">';    
            if (!empty($message_return)){
              echo '
                <div class="register">
                  <h4>unsubscribe from mailinglist</h4>
                  <p>'.$message_return.'</p>';
            }
echo'
    </div>  
</div>
</main>
<footer>
</footer>
</body>
</html>
';

