<?php

use MGModule\DNSManager2\mgLibs\custom\manager\GlobalSettingHelper;
use MGModule\DNSManager2\models\custom\globalsetting\GlobalSettingEnum;


if(!defined('DS'))define('DS',DIRECTORY_SEPARATOR);

function DNSManager2_config(){
    require_once __DIR__ . DIRECTORY_SEPARATOR . 'loader.php';
    $loader = new \MGModule\DNSManager2\loader();
    return MGModule\DNSManager2\addon::config();
}

function DNSManager2_activate(){
    require_once __DIR__ . DIRECTORY_SEPARATOR . 'loader.php';
    $loader = new \MGModule\DNSManager2\loader();
    return MGModule\DNSManager2\addon::activate();
}

function DNSManager2_deactivate(){
    require_once __DIR__ . DIRECTORY_SEPARATOR . 'loader.php';
    $loader = new \MGModule\DNSManager2\loader();
    return MGModule\DNSManager2\addon::deactivate();
}

function DNSManager2_upgrade($vars){
    require_once __DIR__ . DIRECTORY_SEPARATOR . 'loader.php';
    $loader = new \MGModule\DNSManager2\loader();
    return MGModule\DNSManager2\addon::upgrade($vars);
}

function DNSManager2_output($params){

    
    
    require_once __DIR__ . DIRECTORY_SEPARATOR . 'loader.php';
    $loader = new \MGModule\DNSManager2\loader();
    
    MGModule\DNSManager2\addon::I(FALSE,$params);

    if(!empty($_REQUEST['json']))
    {
        if(ob_get_level() > 0)
        {
            ob_start();
            ob_clean();
        }
        if(GlobalSettingHelper::getSetting(GlobalSettingEnum::EMPTY_POST_FIX)) { //use it when other modules removes empty values from $_POST 
            parse_str(file_get_contents('php://input'), $_POST); //$_REQUEST['json'] == '1' && 
            $_REQUEST = array_merge($_GET, $_POST);
        }
        echo MGModule\DNSManager2\addon::getJSONAdminPage($_REQUEST);
        die();
    }
    elseif(!empty($_REQUEST['customPage']))
    {
        if(ob_get_level() > 0)
        {
            ob_start();
            ob_clean();
        }
        echo MGModule\DNSManager2\addon::getHTMLAdminCustomPage($_REQUEST);
        die();
    }
    else
    {
        echo MGModule\DNSManager2\addon::getHTMLAdminPage($_REQUEST);
    }
}


function DNSManager2_clientarea($params){
    require_once __DIR__ . DIRECTORY_SEPARATOR . 'loader.php';
    $loader = new \MGModule\DNSManager2\loader();


    if(!empty($_REQUEST['json']))
    { 
        if(ob_get_level() > 0)
        {
            ob_start();
            ob_clean();
        }
        if(GlobalSettingHelper::getSetting(GlobalSettingEnum::EMPTY_POST_FIX)) { //use it when other modules removes empty values from $_POST 
            parse_str(file_get_contents('php://input'), $_POST); //$_REQUEST['json'] == '1' && 
            $_REQUEST = array_merge($_GET, $_POST);
        }
        echo MGModule\DNSManager2\addon::I()->getJSONClientAreaPage($_REQUEST);
        die();
    }
    else
    {
         return MGModule\DNSManager2\addon::I()->getHTMLClientAreaPage($_REQUEST);
    }
}

