<?php

if (!defined('MODULE_LOADED') || !isset($_GET['pg'])) {
  include(PATH . 'control/system/headers/403.php');
  exit;
}

$NPG = $SYS->load(array(
  'section' => 'new-page',
  'id' => (int) $_GET['pg']
));

if (!isset($NPG->id) || $NPG->en == 'no') {
  include(PATH . 'control/system/headers/403.php');
  exit;
}

if (!in_array($NPG->metat, array(null,''))) {
  $sysTitle = $NPG->metat;
  $metas['title'] = $sysTitle;
} else {
  $titlePrefix = $NPG->name;
  $metas['title'] = $titlePrefix;
}

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

$templateParams = [
  'PDATA' => [
    'info' => mswCD($SANTAGS->filter($NPG->info)),
    'name' => mswCD($NPG->name)
  ]
];

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

if ($NPG->tmp && file_exists(PATH . THEME_FOLDER . '/custom-templates/' . $NPG->tmp)) {
  $latte->render('custom-templates/' . $NPG->tmp, $templateParams);
} else {
  $latte->render('new-page.tpl', $templateParams);
}

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

?>
