<?php

/**
 * Smart Report Maker
 * Version 9.0.0
 * Author : Webuccino
 * All copyrights are preserved to Webuccino
 * URL : http://mysqlreports.com/
 */
/*
 * #################################################################################################
 * Preparing a database object to be used in all steps
 * ################################################################################################
 */

defined('DIRECTACESS') or die("Error 301: Access denied!");

require_once 'services/functions.php';
$connaction_name = isset($_SESSION[Session_report_Settings_key]["connection_name"]) ? trim($_SESSION[Session_report_Settings_key]["connection_name"]) : "";
$host = isset($_SESSION[Session_report_Settings_key]["host"]) ? trim($_SESSION[Session_report_Settings_key]["host"]) : "";
$user = isset($_SESSION[Session_report_Settings_key]["user"]) ? trim($_SESSION[Session_report_Settings_key]["user"]) : "";
$pass = isset($_SESSION[Session_report_Settings_key]["pass"]) ? trim($_SESSION[Session_report_Settings_key]["pass"]) : "";
$port = isset($_SESSION[Session_report_Settings_key]["port"]) ? trim($_SESSION[Session_report_Settings_key]["port"]) : "";
$charset = isset($_SESSION[Session_report_Settings_key]["charset"]) ? trim($_SESSION[Session_report_Settings_key]["charset"]) : "";
$collation = isset($_SESSION[Session_report_Settings_key]["collation"]) ? trim($_SESSION[Session_report_Settings_key]["collation"]) : "";
$db = isset($_SESSION[Session_report_Settings_key]["db"]) ? trim($_SESSION[Session_report_Settings_key]["db"]) : "";

if (Session_Save_Parameters != 1) {

    if ($connaction_name != default_connection_name) {
        $parameters = $srm_dashboard->get_connection_details($connaction_name);
    } else {
        $parameters = $srm_dashboard->get_default_connection_details();
    }
    $host = isset($parameters["server"]) ? $parameters["server"] : "";
    $user = isset($parameters["user"]) ? $parameters["user"] : "";
    $pass = isset($parameters["password"]) ? $parameters["password"] : "";
    $db = isset($parameters["db"]) ? $parameters["db"] : "";
    $charset = isset($parameters["charset"]) ? $parameters["charset"] : "";
    $collation = isset($parameters["collation"]) ? $parameters["collation"] : "";
    $port = isset($parameters["port"]) ? $parameters["port"] : "";
}

$dbHandler = new DatabaseHandler($host,$user,$pass,$db);



list ( $is_connection_failed, $connection_error ) = $dbHandler->is_connection_failed();

if ((basename(getcwd()) == "wizard") && (isset($_GET ["id"]) && $_GET ["id"] > 0) && (!$dbHandler || $is_connection_failed)) {
    $host = $_SERVER ['HTTP_HOST'];
    $uri = rtrim(dirname($_SERVER ['PHP_SELF']), '/\\');
    $http = isset($_SERVER ['HTTPS']) ? 'https://' : 'http://';
    $wizard_exact_directory = $http . $host . $uri . "/";
    header("location: $wizard_exact_directory?id=0");
    exit();
}
?>