<?php

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

// Ajax loader..
if (isset($_GET['ajax-ops'])) {
  include(PATH . 'control/system/_ajax.php');
  exit;
}

// Allowed parameters..
if ($cmd == 'logout')    { $cmd = 'login'; define('LOGOUT_OPS', 1); }
if (isset($_GET['pg']))  { $cmd = 'new-page'; }
if (isset($_GET['prd'])) { $cmd = 'product-view'; }
if (isset($_GET['ac']))  { $cmd = 'create'; }
if (isset($_GET['acc_del_confirm'])) { $cmd = 'login'; }

$accountCMD = array('home','profile','payments','commissions','referrals','products','product-view','close');
$allowedCMD = array('login','create','home','profile','payments','commissions','referrals','products','new-page','product-view','close');

if (in_array($cmd, $allowedCMD)) {
  if (!in_array($cmd, $accountCMD) && file_exists(PATH . 'control/system/modules/' . $cmd . '.php')) {
    define('MODULE_LOADED', 1);
    include(PATH . 'control/system/modules/' . $cmd . '.php');
  } elseif (in_array($cmd, $accountCMD) && file_exists(PATH . 'control/system/modules/account/' . $cmd . '.php')) {
    if (isset($loggedInUser['id'])) {
      define('ACCOUNT_AREA', 1);
      // If password hasn`t been changed, always go to profile screen..
      if ($loggedInUser['sys3'] == 'passchange') {
        $cmd = 'profile';
      }
      include(PATH . 'control/system/modules/account/' . $cmd . '.php');
    } else {
      header("Location: " . $SETTINGS->ifolder);
      exit;
    }
  } else{
    include(PATH . 'control/system/headers/403.php');
  }
} else {
  include(PATH . 'control/system/headers/403.php');
}

?>