<?php

if (!defined('PARENT')) {
  include(PATH . 'control/system/headers/403.php');
  exit;
}

/* DB CONNECTION
---------------------------------------*/

include(PATH . 'control/classes/system/class.db.php');
$DB = new db();
$DB->db_conn();

/* LOAD SETTINGS
---------------------------------------*/

if (!in_array(DB_PREFIX . 'settings', $DB->db_table_status())) {
  header("Location: install/index.php");
  exit;
}

$Q = $DB->db_query("SELECT * FROM `" . DB_PREFIX . "settings`", true);
$SETTINGS = $DB->db_object($Q);

/* LANGUAGE FILES
---------------------------------------*/

define('LANG_FLDR', mswLang($SETTINGS));
define('MSW_EM_LANG', LANG_FLDR . LANG_FLDR_EM . '/');
include(LANG_FLDR . 'global.php');
include(LANG_FLDR . '1.1.php');
include(LANG_FLDR . '2.0.php');

/* CHECK FOR UPGRADE RUN
---------------------------------------*/

if ($SETTINGS->reason == 'msw-offline-run') {
  echo $msw_public_11_global[2];
  exit;
}

/* INITIALISE VARIABLES
-------------------------------------------*/

$cmd          = (isset($_GET['p']) ? $_GET['p'] : 'login');
$page         = (isset($_GET['next']) && $_GET['next'] > 0 ? (int) $_GET['next'] : '1');
$limit        = $page * DEF_PER_PAGE - (DEF_PER_PAGE);
$sysTitle     = str_replace('{website}', mswCD($SETTINGS->website), $msg_meta);
$count        = 0;
$loadJS       = [];
$jsParams     = [];
$formErrors   = [];
$breadcrumbs  = [];
$pr_areas     = ($SETTINGS->pr_areas ? @unserialize($SETTINGS->pr_areas) : []);

/* LOAD CONTROLLERS
-----------------------------------------------*/

include(PATH . 'control/controllers.php');

/* IS USER LOGGED IN?
-----------------------------------------*/

$loggedInUser = $ACC->login();
$systemAcc    = (is_array($loggedInUser) && isset($loggedInUser['id']) ? $loggedInUser : []);

/* ONLINE / OFFLINE
--------------------------------------*/

if ($SETTINGS->sysstatus == 'no') {
  include(PATH . 'control/system/modules/offline.php');
  exit;
}

?>