<?php

/* INIT
----------------------------------*/

if (!defined('PARENT')) {
  include(PATH . 'control/modules/header/403.php');
}

use Detection\MobileDetect;

include(PATH . 'control/functions.php');
include(PATH . 'control/' . (file_exists(PATH . 'control/user-options.php') ? 'user-' : '') . 'options.php');
include(IPATH . 'control/functions.php');
include(IPATH . 'control/currencies.php');
include(IPATH . 'control/' . (file_exists(PATH . 'control/user-options.php') ? 'user-' : '') . 'options.php');

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

if(file_exists(IPATH . 'control/_cfg.php')){include(IPATH . 'control/_cfg.php');}else{die('File "control/_cfg.php" is missing, please see installation instructions.');}
include(IPATH . 'control/classes/system/class.db.php');
$DB = new db();
$DB->db_conn();

/* LOAD SETTINGS / PAY 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('THEME_FOLDER', 'content/' . (is_dir(IPATH . 'content/' . $SETTINGS->theme) ? $SETTINGS->theme : '_theme_default'));
define('MSW_ADM_LANG', LANG_BASE_PATH . $SETTINGS->language . '/' . LANG_FLDR_ADM . '/');
define('MSW_LANG', LANG_BASE_PATH . $SETTINGS->language . '/');
define('MSW_EM_LANG', LANG_BASE_PATH . $SETTINGS->language . '/' . LANG_FLDR_EM . '/');

include(MSW_LANG . 'global.php');
include(MSW_LANG . '1.1.php');
include(MSW_LANG . '2.0.php');
include(MSW_ADM_LANG . 'header.php');
include(MSW_ADM_LANG . 'nav-menu.php');

/* GLOBAL FILES
---------------------------------------*/

include(PATH . 'control/arrays.php');
include(PATH . 'control/modules/menu-controller.php');
include(IPATH . 'control/timezones.php');

/* INCLUDE FILES
---------------------------------------*/

mswFLCTR();
include(IPATH . 'control/classes/system/class.session.php');
include(IPATH . 'control/system/core/mm.php');
include(IPATH . 'control/classes/system/class.datetime.php');
include(IPATH . 'control/classes/system/class.page.php');
include(IPATH . 'control/classes/system/class.tags.php');
include(IPATH . 'control/classes/system/class.parser.php');
include(IPATH . 'control/classes/system/class.mail.php');
include(IPATH . 'control/classes/system/class.json.php');
include(PATH . 'control/classes/class.system.php');
include(IPATH . 'control/classes/class.social.php');

/*
  INITIALISE CLASSES
---------------------------------------*/

$JSON             = new json();
$SYS              = new mswsys();
$DETECT           = new MobileDetect();
$PRSR             = new parser();
$MAILR            = new mailr();
$SOCIAL           = new social();
$DT               = new dt();
$SSN              = new sessHandlr();
$SOCIAL->json     = $JSON;
$SOCIAL->settings = $SETTINGS;
$MAILR->parser    = $PRSR;
$DT->settings     = $SETTINGS;
$SYS->dt          = $DT;
$SYS->settings    = $SETTINGS;

/* LOGGED IN USER
---------------------------------------*/

$mswUser = mswUsr($SETTINGS, $DB, $SSN);

/* SECURE TOKENS
----------------------------------------*/

include(IPATH . 'control/tokens.php');

/* TIMEZONE
---------------------------------------*/

mswTZ($SETTINGS->timezone, $timezones);

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

$cmd        = (isset($_GET['p']) ? $_GET['p'] : 'dashboard');
$admin_links = $SYS->getCFG();
$pageTitle  = $msw_adm_header;
$pagePrefix = '';
$count      = 0;
$page       = (isset($_GET['next']) && $_GET['next'] > 0 ? (int) $_GET['next'] : '1');
$limit      = $page * PER_PAGE - (PER_PAGE);
$eString    = [];
$footer     = mswFoot($SETTINGS->afoot, 'admin');
$fjs        = [];

/* PLATFORM DETECTION
---------------------------------------*/

define('MSW_PFDTCT', ($DETECT->isMobile() ? ($DETECT->isTablet() ? 'tablet' : 'mobile') : 'pc'));

?>