<?php

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

if ($SSN->active('panel-state') == 'yes') {
  $SSN->delete(array('panel-state'));
}

include(LANG_FLDR . 'footer.php');
include(LANG_FLDR . 'payments.php');
include(LANG_FLDR . 'commissions.php');
include(LANG_FLDR . 'referrals.php');
include(LANG_FLDR . 'home.php');

$sysTitle = $msw_footer[5] . ': ' . mswCD($SETTINGS->website);

include(PATH . 'control/system/modules/_header.php');

$templateParams = [
  'TEXT' => $msw_home,
  'FTEXT' => $msw_footer,
  'PTEXT' => $msw_payments,
  'CTEXT' => $msw_commissions,
  'RTEXT' => $msw_referrals,
  'H2TEXT' => [
    str_replace('{count}', AFF_DASH_PAYMENTS_LIMIT, $msw_home[5]),
    str_replace('{count}', AFF_DASH_COMMISSIONS_LIMIT, $msw_home[6]),
    str_replace('{count}', AFF_DASH_REFERRALS_LIMIT, $msw_home[7])
  ],
  'TOTALS' => [
    $ACC->totals(['area' => 'commissions', 'id' => $loggedInUser['id']]),
    $ACC->totals(['area' => 'payments', 'id' => $loggedInUser['id']]),
    $ACC->totals(['area' => 'referrals', 'id' => $loggedInUser['id']])
  ],
  'LAST_PAYMENT' => $ACC->totals(['area' => 'last_payment', 'id' => $loggedInUser['id']]),
  'CODE' => $ACC->affcode($loggedInUser),
  'PAYMENTS' => (AFF_DASH_PAYMENTS_LIMIT > 0 ? $HTML->payments([
    'id' => $loggedInUser['id'],
    'home_limit' => AFF_DASH_PAYMENTS_LIMIT,
    'lang' => [$msw_common, $msw_common2]
  ]) : ''),
  'COMMISSIONS' => (AFF_DASH_COMMISSIONS_LIMIT > 0 ? $HTML->commissions([
    'id' => $loggedInUser['id'],
    'home_limit' => AFF_DASH_COMMISSIONS_LIMIT,
    'lang' => [$msw_common, $msw_common2]
  ]) : ''),
  'REFERRALS' => (AFF_DASH_REFERRALS_LIMIT > 0 ? $HTML->referrals([
    'id' => $loggedInUser['id'],
    'home_limit' => AFF_DASH_REFERRALS_LIMIT,
    'lang' => [$msw_common, $msw_common2]
  ]) : '')
];

// Global..
include(PATH . 'control/system/global.php');

$latte->render('acc-home.tpl', $templateParams);

include(PATH . 'control/system/modules/_footer.php');

?>
