<?php

/**
 * Smart Report Maker
 * Version 9.0.0
 * Author : Webuccino
 * All copyrights are preserved to Webuccino
 * URL : http://mysqlreports.com/
 */
//error_reporting(0);
defined('DIRECTACESS') or die("Error 301: Access denied!");

if (!defined('ACCESS')) {
    define('ACCESS', true);
}

require_once "autoload.php";

$access_control->validate_access_to_wizard();

/*
 * ===============================================================================
 *               Demo Mode
 * ===============================================================================
 */

if (online_demo_mode === 1) {

    $_SESSION[Session_wizard_key]["edit_mode"] = true;
    $_SESSION[Session_wizard_key]["report_id"] =
    isset($_SESSION[Session_wizard_key]["report_id"])
    ? $_SESSION[Session_wizard_key]["report_id"]
    : $srm_dashboard->get_last_report_id()[0]["id"];

    $_SESSION[Session_wizard_key]["page_key"] = "step_2";
    // if (!isset($_SESSION[Session_wizard_key]["loaded_config_id"]) || $_SESSION[Session_wizard_key]["loaded_config_id"] != online_demo_report_id) {
    $result = $srm_dashboard->load_report_configurations($_SESSION[Session_wizard_key]["report_id"]);

    if (!$result) {
        // notify my server or email
    }

    // }

}

/*
 * ===============================================================================
 *               Live Edit mode
 * ===============================================================================
 */elseif (
    isset($_SESSION[Session_wizard_key]["edit_mode"]) &&
    isset($_SESSION[Session_wizard_key]["report_id"]) &&
    $srm_dashboard->is_report_existed_by_id(intval($_SESSION[Session_wizard_key]["report_id"]))
) {

// wizard in Edit mode

    if (!isset($_SESSION[Session_wizard_key]["loaded_config_id"]) || $_SESSION[Session_wizard_key]["loaded_config_id"] != $_SESSION[Session_wizard_key]["report_id"]) {
        $result = $srm_dashboard->load_report_configurations($_SESSION[Session_wizard_key]["report_id"]);

        if (!$result) {

            $_SESSION[Session_wizard_key]["edit_mode"] = false;
        }

    }

} else {
    /*
     * ===============================================================================
     *              Live insert mode
     * ===============================================================================
     */
    $_SESSION[Session_wizard_key]["edit_mode"] = false;
}

// Home page URL
$host                   = $_SERVER['HTTP_HOST'];
$uri                    = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$http                   = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
$wizard_exact_directory = $http . $host . $uri . "/";

// nw request token for CSRF protection
$request_token_value = md5(uniqid(rand(), true));
$admin_login_key     = "admin_access_SRM7";

if (isset($_GET["id"]) && $_GET["id"] > 0) {
    $connection_key = isset($_SESSION[Session_wizard_key]["validate_key"]) ? $_SESSION[Session_wizard_key]["validate_key"] : '';

    if ($connection_key !== md5("srm_f92024_report_settings_valid_1010") || !isset($_SESSION[Session_report_Settings_key]["connection_name"]) || empty($_SESSION[Session_report_Settings_key]["connection_name"])) {
        header("location: $wizard_exact_directory?id=0");
        exit();
    }

}

if (!isset($_SESSION[Session_wizard_key]["request_token_wizard"])) {
    $_SESSION[Session_wizard_key]["request_token_wizard"] = "";
}

// important HTML headers
header("X-XSS-Protection: 1");
header("X-Frame-Options: SAMEORIGIN");
header("X-Content-Type-Options: nosniff");
