<?php

error_reporting(E_ALL);
ini_set('display_errors','on');
 
require_once '../../core_factory.php';
Logaholic_sessionStart();

$lang = Logaholic_setLang();

include_once "../../languages/$lang.php";
include "../../includes/version.php";

$msg="";

if (isset($_POST['license'])) {
    if (isset($_COOKIE['update_license'])) {
        setcookie("update_license", "", time() - 86400);
    }

    $lic = $_POST['license'];

    if (strpos($lic, md5($_SERVER['HTTP_HOST'])) === false) {
        if (strpos($lic, "100b8cad7cf2a56f6df78f171f97a1ec") !== false) {
            // we're ok    
        } else {
            echo _LICENSE_CHECK_FAIL;
            exit();
        }
    }
    if (strlen($lic) < 10) {
        echo _LICENSE_FILE_EMPTY;
        exit();
    } else {
        echo "<b>"._LICENSE_RECEIVED."...</b><br>"; 
        
	      $gfile=logaholic_dir() . "files/";
        if (is_writable($gfile)) { 
        } else {
          echo _PROBLEM.": <font face=courier color=blue>$path/files</font><p>";
          echo _FILES_DIR_NOT_WRITABLE;
          echo _EXPLAIN_CHANGE_PERMISSIONS;  
          echo _PLEASE_TRY_AGAIN;
          exit();
        }
        //$gfile=$path . "../../files/licensefile.txt";
        $gfile=$gfile."licensefile.txt";
  		  $fp = fopen ($gfile,"w+") or die(_COULD_NOT_WRITE_TO_LICENSEFILE);
  		  fwrite ($fp, trim($_POST['license']));
  		  fclose ($fp);
  		  echo "<br><br><div class='alert alert-success'><i class='fa fa-check'></i>". _LICENSE_SAVED ."</div>";
  	}
} else {
  include "../../markup.php"; 
  $lo->PrintInfo();
}