<?php

// c/o stefano riva 2019
//include_once(__DIR__ . '/../library/php/licenseHandler/licenseHandler.php');

function initWEBAPP()
{

  if (!file_exists("instld.wap")) {

    // manca il file generato durante l'installazione, da installare.
    return "requires_installation";
  }

  // Verifichiamo la licenza

}


function InstallationStep($step)
{

  include("check_session.php");
  include("../library/php/functions.php");

  $ui = "";

  if ($step == '0') {

    unset($_SESSION['WEBAPP_INSTALLATION']);

    $ui .= "<div style='width: 100%; float: left; height: 13vw; box-sizing: border-box; padding-left: 33%; padding-top: 3%;'>
      <img src='ui/logo.png' style='width:30vw;'>
    </div>";


    $ui .= "<div id='installation-content' style='width: 50vw; height: 30vw; float: left; margin-left: 24%; border-radius: 0.75vw; box-sizing: border-box; padding-left: 5vw; padding-right: 5vw; box-sizing: border-box; border-bottom: 0.35vw solid #b3b3b3;  border-right: 0.25vw solid #a1a1a1; border-top: 0.1vw solid #f2f2f2; background-color: #ededed;'>";

    $ui .= "<div id='installation-content-hide' style='width: 100%; float: left; height: 100%;'>";

    $ui .= "<div style='width: 100%; float: left; font-size: 2.25vw; height: 4vw; font-weight: bold; color: #525252;  border-bottom: .05vw solid #b8b8b8; margin-top: 2vw; text-align: center;'>WEBAPP INSTALLATION</div>";
    $ui .= "<div style='width: 100%; float: left; font-size: 0.9vw; height: 12.5vw; color: #525252; margin-top: 0vw; text-align: center; margin-top: 2vw; box-sizing: border-box; padding-left: 0vw; padding-right: 0vw;'>Follow the instructions step by step to complete the installation of the Bitonline WebApp.<br> The installation will require a MYSQL Database to create the main Schema and all the required tables to get WebApp work on your local network.<br><br>Please make sure to meet those requirements before starting the process.</div>";

    $ui .= "<button onclick='installationStep(1)' style='width: 20vw; height: 2vw; float: left; box-sizing: border-box; text-align: center; margin-left: 25%; background-color: #c7c7c7; font-weight: bold; border-radius: 0.5vw; margin-top: 1vw; font-size:0.9vw; cursor:pointer; text-transform:uppercase'> Get Started </button>";

    $ui .= "</div>";

    $ui .= "</div>";
  }

  if ($step == '1') {



    $ip = isset($_SESSION['WEBAPP_INSTALLATION']['IP']) ? $_SESSION['WEBAPP_INSTALLATION']['IP'] : '127.0.0.1';
    $user = isset($_SESSION['WEBAPP_INSTALLATION']['USER']) ? $_SESSION['WEBAPP_INSTALLATION']['USER'] : 'root';
    $schema = isset($_SESSION['WEBAPP_INSTALLATION']['SCHEMA']) ? $_SESSION['WEBAPP_INSTALLATION']['SCHEMA'] : 'webapp';
    $prefix = isset($_SESSION['WEBAPP_INSTALLATION']['PREFIX']) ? $_SESSION['WEBAPP_INSTALLATION']['PREFIX'] : 'wa';

    $ui .= "<div id='installation-content-hide' style='display: none; width: 100%; float: left; height: 100%;'>";
    $ui .= "<div style='width: 100%; float: left; font-size: 2.25vw; height: 4vw; font-weight: bold; color: #525252; margin-top: 2vw;  border-bottom: .05vw solid #b8b8b8; text-align: center; text-transform:uppercase;'> DATABASE CONFIGURATION</div>";

    $ui .= "<div style='width: 100%; float: left; font-size: 0.9vw; height: 15vw; color: #525252; margin-top: 0vw; text-align: center; margin-top: 2vw; box-sizing: border-box; padding-left: 0vw; padding-right: 0vw;'>";

    $ui .= "<div style='width: 100%; float: left; height: 2vw; '>
        <div id='label_ip' style='width: 40%; float: left; height: 2vw; text-align: left;'>IP Address</div>
        <input id='db_ip' value='{$ip}' style='width: 50%; float: left; height: 1.75vw; text-align: left; font-size: 0.9vw; border:none; border-radius: 0.25vw; box-sizing: border-box; padding-left: 0.5vw;'>
      </div>";

    $ui .= "<div style='width: 100%; float: left; height: 2vw; '>
        <div id='label_user' style='width: 40%; float: left; height: 2vw; text-align: left;'>Username</div>
        <input id='db_user' value='{$user}' style='width: 50%; float: left; height: 1.75vw; text-align: left; font-size: 0.9vw; border:none; border-radius: 0.25vw; box-sizing: border-box; padding-left: 0.5vw;'>
        
      </div>";

    $ui .= "<div style='width: 100%; float: left; height: 2vw; '>
        <div id='label_pass' style='width: 40%; float: left; height: 2vw; text-align: left;'>Password</div>
        <input id='db_pwd' type='password' autocomplete='new-password' value='' style='width: 50%; float: left; height: 1.75vw; text-align: left; font-size: 0.9vw; border:none; border-radius: 0.25vw; box-sizing: border-box; padding-left: 0.5vw;'>
      </div>";

    $ui .= "<div style='width: 100%; float: left; height: 2vw; '>
        <div id='label_schema' style='width: 40%; float: left; height: 2vw; text-align: left;'>Schema</div>
        <input id='db_schema' value='{$schema}' style='width: 50%; float: left; height: 1.75vw; text-align: left; font-size: 0.9vw; border:none; border-radius: 0.25vw; box-sizing: border-box; padding-left: 0.5vw;'>
      </div>";

    $ui .= "<div style='width: 100%; float: left; height: 2vw; '>
        <div id='label_prefix' style='width: 40%; float: left; height: 2vw; text-align: left;'>Prefix</div>
        <input id='db_prefix' value='{$prefix}' style='width: 50%; float: left; height: 1.75vw; text-align: left; font-size: 0.9vw; border:none; border-radius: 0.25vw; box-sizing: border-box; padding-left: 0.5vw;'>
      </div>";

    $ui .= "<div style='width: 100%; float: left; font-size: 0.9vw; height: 12.5vw; color: #525252; margin-top: 0vw; text-align: left; margin-top: 2vw; box-sizing: border-box; padding-left: 0vw; padding-right: 0vw;'>The access to the database <strong>will be verified</strong> before continuing with the installation.</div>";

    $ui .= "</div>";

    $ui .= "<button id='saveDBInformation' onclick='saveDBInformation()' style='width: 20vw; height: 2vw; float: right; box-sizing: border-box; text-align: center; margin-left: 25%; background-color:  #99ff99; font-weight: bold; border-radius: 0.5vw; margin-top: 1vw; font-size:0.9vw; cursor:pointer; text-transform:uppercase'> Continue </button>";


    $ui .= "</div>";
  }


  /*if ($step == '2') {


    $shared = isset($_SESSION['WEBAPP_INSTALLATION']['SHARED']) ? $_SESSION['WEBAPP_INSTALLATION']['SHARED'] : 'K:/Shared/';

    $ui .= "<div id='installation-content-hide' style='display: none; width: 100%; float: left; height: 100%;'>";
    $ui .= "<div style='width: 100%; float: left; font-size: 2.25vw; height: 4vw; font-weight: bold; color: #525252;  border-bottom: .05vw solid #b8b8b8; margin-top: 2vw; text-align: center;'>SHARED CONFIGURATION</div>";

    $ui .= "<div style='width: 100%; float: left; font-size: 0.9vw; height: 15vw; color: #525252; margin-top: 0vw; text-align: center; margin-top: 2vw; box-sizing: border-box; padding-left: 0vw; padding-right: 0vw;'>";

    $ui .= "<div style='width: 100%; float: left; font-size: 0.9vw; height: 6vw; color: #525252; margin-top: 0vw; text-align: left; margin-top: 0vw; box-sizing: border-box; padding-left: 0vw; padding-right: 0vw;'>The Shared Folder has to be <strong>reachable and accessible</strong> , the installation cannot continue without that verification.</div>";

    $ui .= "<div style='width: 100%; float: left; height: 2vw; '>
          <div id='shared_folder_label' style='width: 20%; float: left; height: 2vw; text-align: left; box-sizing: border-box; padding-top: 0.25vw;'>Shared Folder</div>
          <input id='shared_folder' value='{$shared}' style='width: 70%; float: left; height: 1.75vw; text-align: left; font-size: 0.9vw; border:none; border-radius: 0.25vw; box-sizing: border-box; padding-left: 0.5vw;'>
        </div>";
    $ui .= "</div>";

    $ui .= "<button id='saveSharedPath' onclick='saveSharedPath()' style='width: 20vw; height: 2vw; float: right; box-sizing: border-box; text-align: center; margin-left: 25%; font-size:0.9vw; background-color:  #99ff99; font-weight: bold; border-radius: 0.5vw; margin-top: 0vw; cursor:pointer; text-transform:uppercase'> Continue </button>";

    $ui .= "<button onclick='installationStep(1)' style='width: 6vw; height: 2vw; float: left; box-sizing: border-box; text-align: center; font-size:0.9vw; background-color: #c7c7c7; font-weight: bold; border-radius: 0.5vw; margin-top: 0vw; cursor:pointer; text-transform:uppercase'> Back </button>";


    $ui .= "</div>";
  }*/


  if ($step == '2') {


    $ui .= "<div id='installation-content-hide' style='display: none; width: 100%; float: left; height: 100%;'>";
    $ui .= "<div style='width: 100%; float: left; font-size: 2.25vw; height: 4vw; font-weight: bold; color: #525252;  border-bottom: .05vw solid #b8b8b8; margin-top: 2vw; text-align: center;'>LOGIN CREDENTIALS</div>";

    $ui .= "<div style='width: 100%; float: left; font-size: 0.9vw; height: 15vw; color: #525252; margin-top: 0vw; text-align: center; margin-top: 2vw; box-sizing: border-box; padding-left: 0vw; padding-right: 0vw;'>";

    $ui .= "<div style='width: 100%; float: left; font-size: 0.9vw; height: 6vw; color: #525252; margin-top: 0vw; text-align: left; margin-top: 0vw; box-sizing: border-box; padding-left: 0vw; padding-right: 0vw;'>Choose the credentials for the Administrator account of WebApp <strong>required during any login once the installation is complete.</strong></div>";

    $ui .= "<div style='width: 100%; float: left; height: 2vw; '>
          <div id='username_label' style='width: 40%; float: left; height: 2vw; text-align: left; box-sizing: border-box; padding-top: 0.25vw;'>Username</div>
          <input id='username_login' value='admin' style='width: 50%; float: left; height: 1.75vw; text-align: left; font-size: 0.9vw; border:none; border-radius: 0.25vw; box-sizing: border-box; padding-left: 0.5vw;'>
        </div>";

    $ui .= "<div style='width: 100%; float: left; height: 2vw; '>
          <div id='password1_label' style='width: 40%; float: left; height: 2vw; text-align: left; box-sizing: border-box; padding-top: 0.25vw;'>Password</div>
          <input id='password1_login' type='password' style='width: 50%; float: left; height: 1.75vw; text-align: left; font-size: 0.9vw; border:none; border-radius: 0.25vw; box-sizing: border-box; padding-left: 0.5vw;'>
        </div>";

    $ui .= "<div style='width: 100%; float: left; height: 2vw; '>
          <div id='password2_label' style='width: 40%; float: left; height: 2vw; text-align: left; box-sizing: border-box; padding-top: 0.25vw;'>Confirm Password</div>
          <input id='password2_login' type='password' style='width: 50%; float: left; height: 1.75vw; text-align: left; font-size: 0.9vw; border:none; border-radius: 0.25vw; box-sizing: border-box; padding-left: 0.5vw;'>
        </div>";

    $ui .= "</div>";

    $ui .= "<button onclick='executeInstallationWebApp()' style='width: 20vw; height: 2vw; float: right; box-sizing: border-box; text-align: center; margin-left: 25%;  background-color:  #99ff99; font-weight: bold; border-radius: 0.5vw; margin-top: 0vw; cursor: pointer; font-size:0.9vw; text-transform:uppercase'> Install Webapp </button>";

    $ui .= "<button onclick='installationStep(2)' style='width: 6vw; height: 2vw; float: left; box-sizing: border-box; text-align: center; font-size:0.9vw; background-color: #c7c7c7; font-weight: bold; border-radius: 0.5vw; margin-top: 0vw; cursor:pointer; text-transform:uppercase'> Back </button>";

    $ui .= "</div>";
  }



  if ($step == 4) {

    $ui .= "<div id='installation-content-hide' style='width: 100%; float: left; height: 100%;'>";

    $ui .= "<div style='width: 100%; float: left; font-size: 2vw; height: 4vw; font-weight: bold; color: #525252;  border-bottom: .05vw solid #b8b8b8; margin-top: 2vw; text-align: center;'>WEBAPP INSTALLATION COMPLETED</div>";
    $ui .= "<div style='width: 100%; float: left; font-size: 0.9vw; height: 12.5vw; color: #525252; margin-top: 0vw; text-align: center; margin-top: 2vw; box-sizing: border-box; padding-left: 0vw; padding-right: 0vw;'>The WebApp has been installed successfully in your system and it will be accessible on any browser connected to this server at http://" . $_SERVER['SERVER_ADDR'] . ":" . $_SERVER['SERVER_PORT'] . "/Carambola</div>";

    $ui .= "<button onclick='window.open(\"../index.php\" , \"_self\")' style='width: 20vw; height: 2vw; float: left; font-size:0.9vw; box-sizing: border-box; text-align: center; margin-left: 25%; background-color: #c7c7c7; font-weight: bold; border-radius: 0.5vw;cursor:pointer;text-transform:uppercase'> Restart WebApp </button>";

    $ui .= "</div>";
  }




  return $ui;
}

function saveDBInformation($ip, $user, $password, $schema, $prefix)
{

  include("check_session.php");

  if (PingThisIP($ip) == 'offline') {

    return "error_ip";
  }

  if (!$testConnection = @mysqli_connect($ip, $user, $password))
    return "error_login";

  $_SESSION['WEBAPP_INSTALLATION']['IP'] = $ip;
  $_SESSION['WEBAPP_INSTALLATION']['USER'] = $user;
  $_SESSION['WEBAPP_INSTALLATION']['PASSWORD'] = $password;
  $_SESSION['WEBAPP_INSTALLATION']['SCHEMA'] = $schema;
  $_SESSION['WEBAPP_INSTALLATION']['PREFIX'] = $prefix;

  return "fine";
}



function verifyShared($path)
{

  include("check_session.php");

  if (file_exists($path) && is_dir($path)) {

    $_SESSION['WEBAPP_INSTALLATION']['SHARED'] = $path;

    return "valid";
  }

  return "error";
}


function executeInstallationWebApp($usernameLogin, $passwordLogin)
{

  include("check_session.php");



  if (!isset($_SESSION['WEBAPP_INSTALLATION']['IP']) || !isset($_SESSION['WEBAPP_INSTALLATION']['USER']) || !isset($_SESSION['WEBAPP_INSTALLATION']['PASSWORD']) || !isset($_SESSION['WEBAPP_INSTALLATION']['SCHEMA']))
    return "session_error";

  include_once("integrity.php");

  return verifyOrInstallWEBAPP($_SESSION['WEBAPP_INSTALLATION']['IP'], $_SESSION['WEBAPP_INSTALLATION']['USER'], $_SESSION['WEBAPP_INSTALLATION']['PASSWORD'], $_SESSION['WEBAPP_INSTALLATION']['SCHEMA'], $_SESSION['WEBAPP_INSTALLATION']['PREFIX'], "", $usernameLogin, $passwordLogin);
}





function PingThisIP($ip)
{

  if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {

    if (!exec("ping -n 1 -w 1 " . $ip . " 2>NUL > NUL && (echo 0) || (echo 1)"))
      return "online";

    return "offline";
  } else {

    $pingresult = exec("timeout 0.2 ping -c 1 " . $ip, $outcome, $status);

    //print_r($outcome);

    if (0 == $status) {
      return "online";
    } else {
      return "offline";
    }
  }
}

/* Fay 01-2021 */
function setupBadDBStartup($checking)
{

  include("check_session.php");
  include("../db_connection.php");
  include("../library/php/functions.php");

  $ui = "";
  $ui .= "<div class='' style='width:50%; height:100%; float:left; border-right:1px solid grey'><div class='card border-0' style='background-color:#f8f9fc'>
        <div class='card-body'>
          <div class='card-title'>
            <div style='height: 2.5vw;font-size: 1.5vw; text-transform:  uppercase;'>" . webapp_translator("Configurazione database") . "</div>
            <div style='font-size: 0.8vw; opacity: 0.7;'>" . webapp_translator("Impossibile connetersi al Database. Assicurati di controllare la configurazione effettiva") . ". </div>
          </div>";

  $ui .= "<div class='form-group'>
          <div>IP Address</div>
          <div style='font-size: 0.8vw; opacity: 0.7;'>" . webapp_translator("Indirizzo IP del database") . " .</div>
          <input value='{$db_connection['db-ip']}' oninput='cleardcvCheck()' type='text' class='form-control' style='font-size:1vw;;background-color: #bababa;font-size:1vw;width:100%' id='ipaddress_db'>
          </div>";

  $ui .= "<div class='form-group'>
          <div>Username</div>
          <div style='font-size: 0.8vw; opacity: 0.7;'> " . webapp_translator("Username per accedere al database") . ".</div>
          <input value='{$db_connection['user']}' type='text' oninput='cleardcvCheck()' class='form-control' style='background-color: #bababa;font-size:1vw;width:100%' id='username_db'>
          </div>";

  $ui .= "<div class='form-group'>
          <div>Pasword</div>
          <div style='font-size: 0.8vw; opacity: 0.7;'>" . webapp_translator("Password per accedere al database") . "</div>
          <input value='{$db_connection['password']}' type='password' oninput='cleardcvCheck()' class='form-control' style='background-color: #bababa;font-size:1vw;width:100%' id='password_db'>
          </div>";

  $ui .= "<div class='form-group'>
          <div>Schema</div>
          <div style='font-size: 0.8vw; opacity: 0.7;'>" . webapp_translator("Nome del database") . ".</div>
          <input value='{$db_connection['db-name']}' type='text' oninput='cleardcvCheck()' class='form-control' style='background-color: #bababa;font-size:1vw;width:100%' id='dbname_db'>
          </div>";

  $ui .= "</div></div></div>";

  $ui .= "<div class='' style='width:50%; height:100%; float:left;'><div class='card border-0' style='background-color:#f8f9fc'>
          <div class='card-body'>
          <div class='card-title'>
            <div style='height: 2.5vw;font-size: 1.5vw;text-transform: uppercase;'>  " . webapp_translator("Verifica connessione database") . " </div>
            <div style='font-size: 0.8vw; opacity: 0.7;'> " . webapp_translator("Avvia la verifica della configurazione del database per verificare cosa non va") . " </div>
          </div>";

  $ui .= "<div type='button' onclick='launchDCV()' class='btn btn-secondary' style='width:100%; height: 3vw;text-align:center;padding:0.8vw; font-size:1vw; text-transform: uppercase;'> <strong> " . webapp_translator("Verifica configurazione database") . " </strong> </div>";
  $ui .= "<div id='dcvCheck' class='' style='color: black;  width: 100%; height: 25vw; margin-top: 1vw;'></div>";

  $ui .= "</div></div></div>";


  return $ui;
}





/* verifica connessione db */
function executeDcv($ip, $user, $pass, $name)
{
  include("check_session.php");
  include("../library/php/functions.php");

  $hostimg = "";
  $logimg = "";
  $dbimg = "";

  $step1 = false;

  if (PingThisIP($ip) == 'online') {
    $hostimg = 'img/fineui.png';
    $step1 = true;
  } else {
    $hostimg = 'img/xui.png';
  }

  $ui = "";

  $ui .= "<div style='width:100%;'>
    <div style='width: 100%; float: left;  color: black; height: 3vw; '>
      <div style='width: 7.5%; float: left; height: 100%;'><img src='" . $hostimg . "' style='width: 1.5vw; height: 1.5vw; float: left'></div>
      <div style='width: 85%; float: left; height: 100%; font-size: 1vw;'>" . $ip . "</div>
   </div>";

  $maskedPass = "";
  for ($i = 0; $i < strlen($pass); $i++)
    $maskedPass .= "*";

  $step2 = false;

  if ($step1 == true) {

    if ($testConnection = @mysqli_connect($ip, $user, $pass)) {
      $step2 = true;
      $logimg = 'img/fineui.png';
    } else
      $logimg = 'img/xui.png';
  } else {

    $logimg = 'img/xui.png';
  }

  $step3 = false;

  if ($step2 == true) {

    if (mysqli_select_db($testConnection, $name)) {
      $step3 = true;
      $dbimg = 'img/fineui.png';
    } else
      $dbimg = 'img/xui.png';
  } else {

    $dbimg = 'img/xui.png';
  }

  $ui .= "<div style='width: 100%; float: left;  color: black; height:3vw; '>
      <div style='width: 7.5%; float: left; height: 100%;'><img src='" . $logimg . "' style='width: 1.5vw; height: 1.5vw; float: left'></div>
      <div style='width: 85%; float: left; height: 100%; font-size: 1vw;'><span style='opacity: 0.5'>Login:</span> " . $user . "@" . $maskedPass . "</div>
  </div>";

  $ui .= "<div style='width: 100%; float: left;  color: black; height: 2vw; '>
      <div style='width: 7.5%; float: left; height: 100%;'><img src='" . $dbimg . "' style='width: 1.5vw; height: 1.5vw; float: left'></div>
      <div style='width: 85%; float: left; height: 100%; font-size: 1vw;'><span style='opacity: 0.5'>Schema:</span> " . $name . "</div>
  </div></div>";


  if ($step1 == true && $step2 == true) {

    if ($step3 == true) {
      $text =  webapp_translator("Aggiorna database");
      $ui .= "<div id='dbCheck' style='width: 100%; float: left; height: 5vw;'>
    <div id='verificationComplete' style='width: 100%;  height: 50%; padding: 0.6vw; display: none; opacity: 0.85; font-size: 0.8vw;'>" . webapp_translator("Verifica completa") . " </div>
    <button id='databaseCheck' onclick='RUNdatabaseCheck()' class='selectKP' style='width: 15vw; opacity: 1; border-radius: 0.5vw; margin-left: 0vw; float: left;  height: 1.75vw; padding-left: 0.5vw; text-align: center; padding-top: 0vw; padding-left: 0; font-size: 0.8vw;'>" . $text . "</button>
    </div>";
    } else {
      $text = webapp_translator("Crea database e tabelle");
      $ui .= "<div id='dbCheck' style='width: 100%; float: left; height: 5vw;'>
    <div id='verificationComplete' style='width: 100%;  height: 50%; padding: 0.6vw; display: none; opacity: 0.85; font-size: 0.8vw;'> " . webapp_translator("Verifica completa") . "  </div>
    <button id='databaseCheck' onclick='RUNdbInstallation()' class='selectKP' style='width: 15vw; opacity: 1; border-radius: 0.5vw; margin-left: 0vw; float: left;  height: 1.75vw; padding-left: 0.5vw; text-align: center; padding-top: 0vw; padding-left: 0; font-size: 0.8vw;'>" . $text . "</button>
    </div>";
    }

    $ui .= "<div id='saveConfig'  style='width: 100%; float: left; height: 50%; display:none; '></div>";
  }

  return $ui;
}

function RUNdbInstallation()
{

  $ui = "";

  $ui .= "<div style='width: 100%; float: left; height: 20vw; margin-top: 0.1vw; box-sizing: border-box; padding: 0.5vw;'>";

  $ui .= "<div style='width: 100%; float: left; height: 2.5vw; margin-top: 0.5vw; box-sizing: border-box; padding: 0.5vw;'>
        <div style='width: 25%; float: left; height: 100%; text-align: right; box-sizing: border-box; padding: 0.15vw; padding-right: 1.5vw; font-size: 0.9vw; '>Prefix</div>
        <input value='wa' id='db_prefix' type='text'  autocomplete='off' style='width: 70%;  margin-left: 1vw; text-align: left; box-sizing: border-box; padding-left: 0.5vw; font-size: 1.15vw; border: none; background-color: #dedede; float: left; height: 1.75vw; '>
      </div>";


  $ui .= "<div style='width: 100%; float: left; height: 2.5vw; margin-top: 0.5vw; box-sizing: border-box; padding: 0.5vw;'>
        <div id='shared_folder_label' style='width: 25%; float: left; height: 100%; text-align: right; box-sizing: border-box; padding: 0.15vw; padding-right: 1.5vw; font-size: 0.9vw; '>Shared Folder</div>
        <input value='K:/Shared/' id='shared_folder' type='text'  autocomplete='off' style='width: 70%;  margin-left: 1vw; text-align: left; box-sizing: border-box; padding-left: 0.5vw; font-size: 1.15vw; border: none; background-color: #dedede; float: left; height: 1.75vw; '>
      </div>";

  $ui .= "<div style='width: 100%; float: left; height: 2.5vw; margin-top: 0.5vw; box-sizing: border-box; padding: 0.5vw;'>
        <div id='username_label' style='width: 25%; float: left; height: 100%; text-align: right; box-sizing: border-box; padding: 0.15vw; padding-right: 1.5vw; font-size: 0.9vw; '>Username</div>
        <input value='' id='username_login' type='text'  autocomplete='off' style='width: 70%;  margin-left: 1vw; text-align: left; box-sizing: border-box; padding-left: 0.5vw; font-size: 1.15vw; border: none; background-color: #dedede; float: left; height: 1.75vw; '>
      </div>";

  $ui .= "<div style='width: 100%; float: left; height: 2.5vw; margin-top: 0.5vw; box-sizing: border-box; padding: 0.5vw;'>
        <div id='password1_label' style='width: 25%; float: left; height: 100%; text-align: right; box-sizing: border-box; padding: 0.15vw; padding-right: 1.5vw; font-size: 0.9vw; '>Password</div>
        <input value='' id='password1_login' type='password'  autocomplete='off' style='width: 70%;  margin-left: 1vw; text-align: left; box-sizing: border-box; padding-left: 0.5vw; font-size: 1.15vw; border: none; background-color: #dedede; float: left; height: 1.75vw; '>
      </div>";

  $ui .= "<div style='width: 100%; float: left; height: 2.5vw; margin-top: 0.5vw; box-sizing: border-box; padding: 0.5vw;'>
        <div id='password2_label' style='width: 25%; float: left; height: 100%; text-align: right; box-sizing: border-box; padding: 0.15vw; padding-right: 1.5vw; font-size: 0.9vw; '>Confirm Password</div>
        <input value='' id='password2_login' type='password'  autocomplete='off' style='width: 70%;  margin-left: 1vw; text-align: left; box-sizing: border-box; padding-left: 0.5vw; font-size: 1.15vw; border: none; background-color: #dedede; float: left; height: 1.75vw; '>
      </div>
    </div>";

  $ui .= "<button onclick='checkConf()'  style='width: 15vw; height: 2vw; float: left; text-align: center; background-color: #55c223; margin-left: 20%; margin-top:0.5vw;  border: none; font-size: 0.9vw; color: white; border-radius: 0.5vw;'>CREATE SCHEMA AND TABLES</button>";
  $ui .= "<button onclick='closeWindow()' style='width: 10vw; height: 2vw; float: right; text-align: center; background-color: #5e5e5e; margin-right: 20%; margin-top: 0.5vw; border: none; font-size: 0.9vw; color: white; border-radius: 0.5vw;'>CANCEL</button>";

  return $ui;
}


// controllo db (creazione db o aggiornamento)
function RUNdatabaseCheck($ip, $user, $pass, $name, $prefix, $sharedPath, $username, $password)
{
  include("check_session.php");
  include("../db_connection.php");
  include("../include/setsession.php");
  include("integrity.php");

  $_SESSION['OLD_DB_CONFIG']['IP'] = $db_connection['db-ip'];
  $_SESSION['OLD_DB_CONFIG']['USER'] = $db_connection['user'];
  $_SESSION['OLD_DB_CONFIG']['PASSWORD'] = $db_connection['password'];
  $_SESSION['OLD_DB_CONFIG']['SCHEMA'] = $db_connection['db-name'];

  if (!isset($prefix)) $prefix = $s_prefix;

  return verifyOrInstallWEBAPP($ip, $user, $pass, $name, $prefix, $sharedPath, $username, $password);
}

function registerLicense($file_license)
{

  move_uploaded_file($file_license["tmp_name"], __DIR__ . "/../lic.bitonlive");
  $license_status = checkBitonliveLicense([144], __DIR__ . '/../lic.bitonlive');



  return $license_status['status'];

  /*
  if($license_status === 'missing_license') $licenseStatusText = 'Missing License';
  if($license_status === 'invalid_license') $licenseStatusText = 'Invalid License';
  if($license_status === 'license_expired') $licenseStatusText = 'Expired License';
  */
}


