<?php

error_reporting(E_ALL);
$site_config_path = "../application/config/config.php";
$dbConfigPath = "../application/config/database.php";
$redirect_url = isset($_SERVER['HTTPS']) && $_SERVER['HTPPS'] == 'on' ? 'https' : 'http';
$redirect_url = "://" . $_SERVER['HTTP_HOST'];
$redirect_url = str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
$style_url = $redirect_url;
if (!empty($_POST)) {
    require_once 'includes/config.php';
    require_once 'includes/database.php';
    $config = new Config();
    $db = new Database();
    if ($config->checkPostData($_POST)) {
        //        if (!$db->createDatabase($_POST)) {
        //            $error = "The database could not be created, please verify your settings.";
        //        } else
        if (!$db->createTable($_POST)) {
            $error = "The database tables could not be created, please verify your settings.";
        } else {
            if (!$db->createAdmin($_POST)) {
                $error = "The admin details could not be saved. Please verify.";
            } else {
                if (!$config->writeConfig($_POST)) {
                    $error = "The configuration file could not be written, \n                    please chmod the files to 0777";
                } else {
                    if (!$config->createExtraction($_POST['base_url'])) {
                        $error = "The extraction js file could not be written, \n                    please chmod the files to 0777";
                    }
                }