<?php
//-----------------------------------------------------------------
//
//  Copyright (c) 2013 Pixelzauber GmbH, Switzerland
//  stationCMS - Content-Management-System (CMS)
//
//-----------------------------------------------------------------
//  Settings
//-----------------------------------------------------------------
@header('content-type: text/html; charset=UTF-8');
date_default_timezone_set('Europe/Zurich');

//-----------------------------------------------------------------
// Set error reporting
//-----------------------------------------------------------------
if (1) {
	error_reporting(E_ALL);
	ini_set('display_errors', 1);
	$errorReporting = 'On';
} else {
	error_reporting(0);
	ini_set('display_errors', 0);
	$errorReporting = 'Off';
}


//-----------------------------------------------------------------
// rewriting to admin-tool
//-----------------------------------------------------------------
if (isset($_GET['page']) && $_GET['page'] == 'admin') {
	header('Location: stationcms/');
} else if (isset($_GET['page']) && $_GET['page'] == '/admin') {
	header('Location: stationcms/');
} else if (isset($_GET['page']) && $_GET['page'] == 'admin/') {
	header('Location: ../stationcms/');
}


//-----------------------------------------------------------------
// Load classes
//-----------------------------------------------------------------
include_once('config/configuration.php');

include_once('stationcms/core/class.database.php');
$objDB = new DB();

include_once('stationcms/core/class.navigation.php');
$objNavi = new Navigation();

include_once('stationcms/core/class.sitebuilder.php');
$objTemplate = new SiteBuilder();

require 'stationcms/lib/PHPMailer/src/PHPMailer.php';
require 'stationcms/lib/PHPMailer/src/SMTP.php';
require 'stationcms/lib/PHPMailer/src/Exception.php';
use PHPMailer\PHPMailer\PHPMailer;
//use PHPMailer\PHPMailer\Exception;
$objMail = new PHPMailer();

include_once('stationcms/core/class.session.php');
new MySessionHandler();

include_once('stationcms/core/class.login.php');
$login = new Login();

include_once('stationcms/lib/mobileDetect/Mobile_Detect.php');
include_once('stationcms/core/class.library.php');
include_once('stationcms/core/class.frontend.php');
$objFront = new Frontend();


//-------------------------------------------------------
// Check if system in the maintenances
//-------------------------------------------------------
if ($objFront->maintenance == 'on' && $_GET['page'] != 'admin' && $_GET['page'] != 'admin/') {

    header('location: maintenance.html');
    die(1);
}


//-------------------------------------------------------
// Force HTTPS
//-------------------------------------------------------
if ($objFront->forceHTTPS && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] !== 'on')) {
    if(!headers_sent()) {
        header("Status: 301 Moved Permanently");
        header(sprintf(
            'Location: https://%s%s',
            $_SERVER['HTTP_HOST'],
            $_SERVER['REQUEST_URI']
        ));
        exit();
    }
}


//-------------------------------------------------------
// Check forward
//-------------------------------------------------------
$forwardURL = $objFront->getForward();
if ($forwardURL != '') {
	header('Location: '.$forwardURL);
}


//-----------------------------------------------------------------
// Load variables
//-----------------------------------------------------------------
if (file_exists('stationcms/lang/'.$objFront->showLangCode().'/frontend.php')) {
	include_once('stationcms/lang/'.$objFront->showLangCode().'/frontend.php');
} else {
	include_once('stationcms/lang/de/frontend.php');
}


//-----------------------------------------------------------------
// Build Menu Array
//-----------------------------------------------------------------
$MenuArray = $objFront->MenuArray();


//-----------------------------------------------------------------
//  Load index.php
//-----------------------------------------------------------------
include_once('template/'.$objFront->showTemplate().'/index.php');


?>