<?php
class Admin
{
    public static function Login()
    {
        $conf = file_get_contents("configs/admin_auth.json");
        $conf = json_decode($conf, true);
        if (App::$Post->adm_captcha == $_SESSION['captcha'])
        {
            if (App::$Post->adm_login == $conf['AdminLogin'] && App::$Post->adm_pass == $conf['AdminPass'])
            {
                $_SESSION['admin'] = true;
                return true;
            }
        }
        return false;
    }
    public static function Logout()
    {
        $_SESSION['admin'] = false;
        unset($_SESSION['admin']);
        session_unset();
        session_destroy();
        setcookie(session_name(),'');
    }
    public static function ConfigGenerals()
    {
        $Config = file_get_contents("configs/main.json");
        $Config = json_decode($Config,true);
        if (property_exists(App::$Post,'default_lang'))
            $Config['default_lang'] = App::$Post->default_lang;
        if (property_exists(App::$Post,'template'))
            $Config['template'] = App::$Post->template;
        if (property_exists(App::$Post,'RF')) {
                $Config['RF'] = true;
        }
        else {
                $Config['RF'] = false;
        }
        if (property_exists(App::$Post,'LoginSimplePage')) {
                $Config['LoginSimplePage'] = true;
        }
        else {
                $Config['LoginSimplePage'] = false;
        }
        if (property_exists(App::$Post,'RegisterSimplePage')) {
                $Config['RegisterSimplePage'] = true;
        }
        else {
                $Config['RegisterSimplePage'] = false;
        }
        if (property_exists(App::$Post,'RestoreSimplePage')) {
                $Config['RestoreSimplePage'] = true;
        }
        else {
                $Config['RestoreSimplePage'] = false;
        }

        //Intro
        if (property_exists(App::$Post,'IntroEnable')) {
            $Config['IntroEnable'] = true;
        }
        else {
            $Config['IntroEnable'] = false;
        }
        if (property_exists(App::$Post,'IntroActionTime'))
            $Config['IntroActionTime'] = App::$Post->IntroActionTime;

        file_put_contents('configs/main.json', json_encode($Config));
    }
    
    public static function ConfigUser()
    {
        $Config = file_get_contents("configs/user.json");
        $Config = json_decode($Config,true);
        if (property_exists(App::$Post,'NeedName')) {
                $Config['NeedName'] = true;
        } else {
                $Config['NeedName'] = false;
        }
        
        if (property_exists(App::$Post,'LoginToLower')) {
                $Config['LoginToLower'] = true;
        } else {
                $Config['LoginToLower'] = false;
        }
        file_put_contents('configs/user.json', json_encode($Config));
    }
    public static function ConfigCache()
    {
        $Config = file_get_contents("configs/cache.json");
        $Config = json_decode($Config,true);
        if (property_exists(App::$Post,'actionIndex'))
            $Config['actionIndex'] = App::$Post->actionIndex;

        if (property_exists(App::$Post,'actionPlayers'))
            $Config['actionPlayers'] = App::$Post->actionPlayers;

        if (property_exists(App::$Post,'actionIndex'))
            $Config['actionIndex'] = App::$Post->actionIndex;

        if (property_exists(App::$Post,'actionPk'))
            $Config['actionPk'] = App::$Post->actionPk;

        if (property_exists(App::$Post,'actionGuilds'))
            $Config['actionGuilds'] = App::$Post->actionGuilds;

        if (property_exists(App::$Post,'actionCastle'))
            $Config['actionCastle'] = App::$Post->actionCastle;

        if (property_exists(App::$Post,'actionPrisons'))
            $Config['actionPrisons'] = App::$Post->actionPrisons;

        //Widgets

        if (property_exists(App::$Post,'WidgetForum'))
            $Config['WidgetForum'] = App::$Post->WidgetForum;

        if (property_exists(App::$Post,'WidgetServerInfo'))
            $Config['WidgetServerInfo'] = App::$Post->WidgetServerInfo;

        if (property_exists(App::$Post,'WidgetStrongest'))
            $Config['WidgetStrongest'] = App::$Post->WidgetStrongest;

        if (property_exists(App::$Post,'WidgetTopGuilds'))
            $Config['WidgetTopGuilds'] = App::$Post->WidgetTopGuilds;

        file_put_contents('configs/cache.json', json_encode($Config));
    }

    public static function ConfigWidgetsForum()
    {
        $Config = file_get_contents("configs/widgets/forum.json");
        $Config = json_decode($Config,true);
        if (property_exists(App::$Post,'Enable')) {
            $Config['Enable'] = true;
        }
        else {
            $Config['Enable'] = false;
        }
        if (property_exists(App::$Post,'Link'))
            $Config['Link'] = $_POST['Link'];// No Validate
        if (property_exists(App::$Post,'CountPost'))
            $Config['CountPost'] = App::$Post->CountPost;

        file_put_contents('configs/widgets/forum.json', json_encode($Config));
    }
    public static function ConfigWidgetsServerInfo()
    {
        $Config = file_get_contents("configs/widgets/serverinfo.json");
        $Config = json_decode($Config,true);
        if (property_exists(App::$Post,'TopPlayer')) {
            $Config['TopPlayer'] = true;
        }
        else {
            $Config['TopPlayer'] = false;
        }
        if (property_exists(App::$Post,'TopGuild')) {
            $Config['TopGuild'] = true;
        }
        else {
            $Config['TopGuild'] = false;
        }
        if (property_exists(App::$Post,'Castle')) {
            $Config['Castle'] = true;
        }
        else {
            $Config['Castle'] = false;
        }
        if (property_exists(App::$Post,'Accounts')) {
            $Config['Accounts'] = true;
        }
        else {
            $Config['Accounts'] = false;
        }
        if (property_exists(App::$Post,'Players')) {
            $Config['Players'] = true;
        }
        else {
            $Config['Players'] = false;
        }
        file_put_contents('configs/widgets/serverinfo.json', json_encode($Config));
    }
    public static function ConfigWidgetsStrongest()
    {
        $Config = file_get_contents("configs/widgets/strongest.json");
        $Config = json_decode($Config,true);
        if (property_exists(App::$Post,'Enable')) {
            $Config['Enable'] = true;
        }
        else {
            $Config['Enable'] = false;
        }
        if (property_exists(App::$Post,'Level')) {
            $Config['Level'] = true;
        }
        else {
            $Config['Level'] = false;
        }
        if (property_exists(App::$Post,'Reset')) {
            $Config['Reset'] = true;
        }
        else {
            $Config['Reset'] = false;
        }
        if (property_exists(App::$Post,'GrandReset')) {
            $Config['GrandReset'] = true;
        }
        else {
            $Config['GrandReset'] = false;
        }
        if (property_exists(App::$Post,'CountPost'))
            $Config['CountPost'] = App::$Post->CountPost;
        
        file_put_contents('configs/widgets/strongest.json', json_encode($Config));
    }
    public static function ConfigWidgetsTopGuilds()
    {
        $Config = file_get_contents("configs/widgets/topguilds.json");
        $Config = json_decode($Config,true);
        if (property_exists(App::$Post,'Enable')) {
            $Config['Enable'] = true;
        }
        else {
            $Config['Enable'] = false;
        }
        if (property_exists(App::$Post,'CountGuild'))
            $Config['CountGuild'] = App::$Post->CountGuild;

        file_put_contents('configs/widgets/topguilds.json', json_encode($Config));

    }
    public static function ConfigValuteManager($Db)
    {
        $Config = file_get_contents("configs/DB_" . $Db . "/ValuteManager.json");
        $Config = json_decode($Config,true);

        for ($i = 0; $i < 5; $i++) {
            if (property_exists(App::$Post,'val' . $i . '_name'))
                $Config[$i]['Name'] = $_POST['val' . $i . '_name'];
            if (property_exists(App::$Post,'val' . $i . '_table'))
                $Config[$i]['Table'] = $_POST['val' . $i . '_table'];
            if (property_exists(App::$Post,'val' . $i . '_column'))
                $Config[$i]['Column'] = $_POST['val' . $i . '_column'];
            if (property_exists(App::$Post,'val' . $i . '_charnamecolumn'))
                $Config[$i]['CharacterNameColumn'] = $_POST['val' . $i . '_charnamecolumn'];
            if (property_exists(App::$Post,'val' . $i . '_accnamecolumn'))
                $Config[$i]['AccountNameColumn'] = $_POST['val' . $i . '_accnamecolumn'];
        }

        file_put_contents('configs/DB_' . $Db . '/ValuteManager.json', json_encode($Config));

    }
    
    public static function ConfigModulesAddStats($Db)
    {
        $Config = file_get_contents("configs/modules/DB_" . $Db . "/AddStats.json");
        $Config = json_decode($Config,true);
        if (property_exists(App::$Post,'Enable')) {
            $Config['Enable'] = true;
        }
        else {
            $Config['Enable'] = false;
        }
        if (property_exists(App::$Post,'MaxStats'))
            $Config['MaxStats'] = App::$Post->MaxStats;

        file_put_contents('configs/modules/DB_' . $Db . '/AddStats.json', json_encode($Config));

    }
    public static function ConfigModulesChangeClass($Db)
    {
        $Config = file_get_contents("configs/modules/DB_" . $Db . "/ChangeClass.json");
        $Config = json_decode($Config,true);
        if (property_exists(App::$Post,'Enable')) {
            $Config['Enable'] = true;
        }
        else {
            $Config['Enable'] = false;
        }
        if (property_exists(App::$Post,'NeedLevel'))
            $Config['NeedLevel'] = App::$Post->NeedLevel;
        if (property_exists(App::$Post,'NeedReset'))
            $Config['NeedReset'] = App::$Post->NeedReset;
        if (property_exists(App::$Post,'NeedEmptyInv')) {
            $Config['NeedEmptyInv'] = true;
        }
        else {
            $Config['NeedEmptyInv'] = false;
        }
        if (property_exists(App::$Post,'Characters')) {
            $Config['Classes']['DW'] = false;
            $Config['Classes']['DK'] = false;
            $Config['Classes']['ELF'] = false;
            $Config['Classes']['SUM'] = false;
            $Config['Classes']['MG'] = false;
            $Config['Classes']['DL'] = false;
            $Config['Classes']['RF'] = false;
            foreach ($_POST['Characters'] as $value) {
                if ($value == 0) $Config['Classes']['DW'] = true;
                if ($value == 1) $Config['Classes']['DK'] = true;
                if ($value == 2) $Config['Classes']['ELF'] = true;
                if ($value == 3) $Config['Classes']['SUM'] = true;
                if ($value == 4) $Config['Classes']['MG'] = true;
                if ($value == 5) $Config['Classes']['DL'] = true;
                if ($value == 6) $Config['Classes']['RF'] = true;
            }
        }
        $ValuteConfig = file_get_contents("configs/DB_" . $Db . "/ValuteManager.json");
        $ValuteConfig = json_decode($ValuteConfig,true);
        for ($i = 0; $i < 5; $i++) {
            if ($ValuteConfig[$i]['Name'] != '' && property_exists(App::$Post,'val_take_'.$i)) {
                $Config['Take']['Valutes'][$i] = App::$Post->{'val_take_'.$i};
            }
            else {
                $Config['Take']['Valutes'][$i] = 0;
            }
        }

        file_put_contents('configs/modules/DB_' . $Db . '/ChangeClass.json', json_encode($Config));

    }
    public static function ConfigModulesReset($Db)
    {
        $Config = file_get_contents("configs/modules/DB_" . $Db . "/Reset.json");
        $Config = json_decode($Config,true);
        if (property_exists(App::$Post,'Enable')) {
            $Config['Enable'] = true;
        }
        else {
            $Config['Enable'] = false;
        }
        if (property_exists(App::$Post,'NeedLevel'))
            $Config['NeedLevel'] = App::$Post->NeedLevel;
        if (property_exists(App::$Post,'NeedEmptyInv')) {
            $Config['NeedEmptyInv'] = true;
        }
        else {
            $Config['NeedEmptyInv'] = false;
        }
        if (property_exists(App::$Post,'ClearSkill')) {
            $Config['ClearSkill'] = true;
        }
        else {
            $Config['ClearSkill'] = false;
        }
        if (property_exists(App::$Post,'reward_point_type'))
            $Config['RewardPoint']['Type'] = App::$Post->reward_point_type;
        
        if (property_exists(App::$Post,'reward_point_dw'))
            $Config['RewardPoint']['DW'] = App::$Post->reward_point_dw;
        if (property_exists(App::$Post,'reward_point_dk'))
            $Config['RewardPoint']['DK'] = App::$Post->reward_point_dk;
        if (property_exists(App::$Post,'reward_point_elf'))
            $Config['RewardPoint']['ELF'] = App::$Post->reward_point_elf;
        if (property_exists(App::$Post,'reward_point_sum'))
            $Config['RewardPoint']['SUM'] = App::$Post->reward_point_sum;
        if (property_exists(App::$Post,'reward_point_mg'))
            $Config['RewardPoint']['MG'] = App::$Post->reward_point_mg;
        if (property_exists(App::$Post,'reward_point_dl'))
            $Config['RewardPoint']['DL'] = App::$Post->reward_point_dl;
        if (property_exists(App::$Post,'reward_point_rf'))
            $Config['RewardPoint']['RF'] = App::$Post->reward_point_rf;
        
        $ValuteConfig = file_get_contents("configs/DB_" . $Db . "/ValuteManager.json");
        $ValuteConfig = json_decode($ValuteConfig,true);
        for ($i = 0; $i < 5; $i++) {
            if ($ValuteConfig[$i]['Name'] != '' && property_exists(App::$Post,'val_take_'.$i)) {
                $Config['Take']['Valutes'][$i] = App::$Post->{'val_take_'.$i};
            }
            else {
                $Config['Take']['Valutes'][$i] = 0;
            }
        }
        for ($i = 0; $i < 5; $i++) {
            if ($ValuteConfig[$i]['Name'] != '' && property_exists(App::$Post,'val_reward_'.$i)) {
                $Config['Reward']['Valutes'][$i] = App::$Post->{'val_reward_'.$i};
            }
            else {
                $Config['Reward']['Valutes'][$i] = 0;
            }
        }

        file_put_contents('configs/modules/DB_' . $Db . '/Reset.json', json_encode($Config));
    }

    public static function ConfigModulesGrandReset($Db)
    {
        $Config = file_get_contents("configs/modules/DB_" . $Db . "/GrandReset.json");
        $Config = json_decode($Config,true);
        if (property_exists(App::$Post,'Enable')) {
            $Config['Enable'] = true;
        }
        else {
            $Config['Enable'] = false;
        }
        if (property_exists(App::$Post,'NeedLevel'))
            $Config['NeedLevel'] = App::$Post->NeedLevel;
        if (property_exists(App::$Post,'NeedReset'))
            $Config['NeedReset'] = App::$Post->NeedReset;
        if (property_exists(App::$Post,'NeedEmptyInv')) {
            $Config['NeedEmptyInv'] = true;
        }
        else {
            $Config['NeedEmptyInv'] = false;
        }
        if (property_exists(App::$Post,'ClearSkill')) {
            $Config['ClearSkill'] = true;
        }
        else {
            $Config['ClearSkill'] = false;
        }
        if (property_exists(App::$Post,'reward_point_type'))
            $Config['RewardPoint']['Type'] = App::$Post->reward_point_type;

        if (property_exists(App::$Post,'reward_point_dw'))
            $Config['RewardPoint']['DW'] = App::$Post->reward_point_dw;
        if (property_exists(App::$Post,'reward_point_dk'))
            $Config['RewardPoint']['DK'] = App::$Post->reward_point_dk;
        if (property_exists(App::$Post,'reward_point_elf'))
            $Config['RewardPoint']['ELF'] = App::$Post->reward_point_elf;
        if (property_exists(App::$Post,'reward_point_sum'))
            $Config['RewardPoint']['SUM'] = App::$Post->reward_point_sum;
        if (property_exists(App::$Post,'reward_point_mg'))
            $Config['RewardPoint']['MG'] = App::$Post->reward_point_mg;
        if (property_exists(App::$Post,'reward_point_dl'))
            $Config['RewardPoint']['DL'] = App::$Post->reward_point_dl;
        if (property_exists(App::$Post,'reward_point_rf'))
            $Config['RewardPoint']['RF'] = App::$Post->reward_point_rf;

        $ValuteConfig = file_get_contents("configs/DB_" . $Db . "/ValuteManager.json");
        $ValuteConfig = json_decode($ValuteConfig,true);
        for ($i = 0; $i < 5; $i++) {
            if ($ValuteConfig[$i]['Name'] != '' && property_exists(App::$Post,'val_take_'.$i)) {
                $Config['Take']['Valutes'][$i] = App::$Post->{'val_take_'.$i};
            }
            else {
                $Config['Take']['Valutes'][$i] = 0;
            }
        }
        for ($i = 0; $i < 5; $i++) {
            if ($ValuteConfig[$i]['Name'] != '' && property_exists(App::$Post,'val_reward_'.$i)) {
                $Config['Reward']['Valutes'][$i] = App::$Post->{'val_reward_'.$i};
            }
            else {
                $Config['Reward']['Valutes'][$i] = 0;
            }
        }

        file_put_contents('configs/modules/DB_' . $Db . '/GrandReset.json', json_encode($Config));

    }

    public static function ConfigModulesPkClear($Db)
    {
        $Config = file_get_contents("configs/modules/DB_" . $Db . "/PkClear.json");
        $Config = json_decode($Config,true);
        if (property_exists(App::$Post,'Enable')) {
            $Config['Enable'] = true;
        }
        else {
            $Config['Enable'] = false;
        }
        if (property_exists(App::$Post,'NeedLevel'))
            $Config['NeedLevel'] = App::$Post->NeedLevel;
        if (property_exists(App::$Post,'NeedReset'))
            $Config['NeedReset'] = App::$Post->NeedReset;
        
        $ValuteConfig = file_get_contents("configs/DB_" . $Db . "/ValuteManager.json");
        $ValuteConfig = json_decode($ValuteConfig,true);
        for ($i = 0; $i < 5; $i++) {
            if ($ValuteConfig[$i]['Name'] != '' && property_exists(App::$Post,'val_take_'.$i)) {
                $Config['Take']['Valutes'][$i] = App::$Post->{'val_take_'.$i};
            }
            else {
                $Config['Take']['Valutes'][$i] = 0;
            }
        }

        file_put_contents('configs/modules/DB_' . $Db . '/PkClear.json', json_encode($Config));

    }
    public static function ConfigModulesReferralSystem($Db)
    {
        $Config = file_get_contents("configs/modules/DB_" . $Db . "/ReferralSystem.json");
        $Config = json_decode($Config,true);
        if (property_exists(App::$Post,'Enable')) {
            $Config['Enable'] = true;
        }
        else {
            $Config['Enable'] = false;
        }
        if (property_exists(App::$Post,'CountStep'))
            $Config['CountStep'] = App::$Post->CountStep;

        $ValuteConfig = file_get_contents("configs/DB_" . $Db . "/ValuteManager.json");
        $ValuteConfig = json_decode($ValuteConfig,true);

        for ($j = 1; $j <=5; $j++) {
            if (property_exists(App::$Post,'NeedReset_'.$j))
                $Config['Steps'][$j]['NeedReset'] = App::$Post->{'NeedReset_'.$j};
            for ($i = 0; $i < 5; $i++) {
                if ($ValuteConfig[$i]['Name'] != '' && property_exists(App::$Post, 'step_'. $j .'_val_reward_' . $i)) {
                    $Config['Steps'][$j]['Valutes'][$i] = App::$Post->{'step_'. $j .'_val_reward_' . $i};
                } else {
                    $Config['Steps'][$j]['Valutes'][$i] = 0;
                }
            }
        }

        file_put_contents('configs/modules/DB_' . $Db . '/ReferralSystem.json', json_encode($Config));

    }

    public static function DeleteCache($name="", $Db = null, $Widget = false)
    {
        
    }

    public static function UpdateFile($filename, $content)
    {
        if ($content == ''){
            return false;
        }
        if(file_put_contents($filename, $content)){
            return true;
        }
        else{
            return false;
        }
    }
    public static function SiteSpace()
    {
        //get disc spaces
        $free_space = disk_free_space('/');
        $all_space = disk_total_space('/');
        $used_space = $all_space - $free_space;

        //convert bytes to string
        $units = array('B', 'KB', 'MB', 'GB', 'TB'); $bytes = max($all_space, 0); $pow = floor(($bytes?log($bytes):0)/log(1024)); $pow = min($pow, count($units)-1); $bytes /= pow(1024, $pow);
        $string_all_space = round($bytes, 2).' '.$units[$pow];
        $units = array('B', 'KB', 'MB', 'GB', 'TB'); $bytes = max($free_space, 0); $pow = floor(($bytes?log($bytes):0)/log(1024)); $pow = min($pow, count($units)-1);$bytes /= pow(1024, $pow);
        $string_free_space = round($bytes, 2).' '.$units[$pow];
        $units = array('B', 'KB', 'MB', 'GB', 'TB'); $bytes = max($used_space, 0); $pow = floor(($bytes?log($bytes):0)/log(1024)); $pow = min($pow, count($units)-1); $bytes /= pow(1024, $pow);
        $string_used_space = round($bytes, 2).' '.$units[$pow];

        $procent_used_space = round($used_space * 100 / $all_space, 0);
        return array(
            'string_all_space' => $string_all_space,        
            'string_free_space' => $string_free_space,        
            'string_used_space' => $string_used_space,   
            'procent_used_space' => $procent_used_space
        );
    }
    public static function LangRuEdit()
    {
        $Param = '';
        $Value = '';
        if (property_exists(App::$Post,'param') && App::$Post->param != '')
            $Param = App::$Post->param;
        if (property_exists(App::$Post,'extend_area') && App::$Post->extend_area != '')
            $Value = $_POST['extend_area'];
        else if (property_exists(App::$Post,'value'))
            $Value = $_POST['value'];

        if ($Param == 'Messages' || $Param == '')
            return;

        $Config = file_get_contents("configs/Lang/ru.json");
        $Config = json_decode($Config,true);

        if ($Value == '' && isset($Config[$Param])){
            unset($Config[$Param]);
        } elseif ($Value != '') {
            $Config[$Param] = $Value;
        }

        file_put_contents('configs/Lang/ru.json', json_encode($Config));
    }
    public static function LangEnEdit()
    {
        $Param = '';
        $Value = '';
        if (property_exists(App::$Post,'param') && App::$Post->param != '')
            $Param = App::$Post->param;
        if (property_exists(App::$Post,'extend_area') && App::$Post->extend_area != '')
            $Value = $_POST['extend_area'];
        else if (property_exists(App::$Post,'value'))
            $Value = $_POST['value'];

        if ($Param == 'Messages' || $Param == '')
            return;

        $Config = file_get_contents("configs/Lang/en.json");
        $Config = json_decode($Config,true);

        if ($Value == '' && isset($Config[$Param])){
            unset($Config[$Param]);
        } elseif ($Value != '') {
            $Config[$Param] = $Value;
        }

        file_put_contents('configs/Lang/en.json', json_encode($Config));
    }
    public static function LangMessagesRuEdit()
    {
        $Param = '';
        $Value = '';
        if (property_exists(App::$Post,'param') && App::$Post->param != '')
            $Param = App::$Post->param;
        if (property_exists(App::$Post,'value'))
            $Value = $_POST['value'];

        if ($Param == '')
            return;

        $Config = file_get_contents("configs/Lang/ru.json");
        $Config = json_decode($Config,true);

        if ($Value == '' && isset($Config['Messages'][$Param])){
            unset($Config['Messages'][$Param]);
        } elseif ($Value != '') {
            $Config['Messages'][$Param] = $Value;
        }

        file_put_contents('configs/Lang/ru.json', json_encode($Config));
    }
public static function LangMessagesEnEdit()
    {
        $Param = '';
        $Value = '';
        if (property_exists(App::$Post,'param') && App::$Post->param != '')
            $Param = App::$Post->param;
        if (property_exists(App::$Post,'value'))
            $Value = $_POST['value'];

        if ($Param == '')
            return;

        $Config = file_get_contents("configs/Lang/en.json");
        $Config = json_decode($Config,true);

        if ($Value == '' && isset($Config['Messages'][$Param])){
            unset($Config['Messages'][$Param]);
        } elseif ($Value != '') {
            $Config['Messages'][$Param] = $Value;
        }

        file_put_contents('configs/Lang/en.json', json_encode($Config));
    }


    public static function ConfigModulesChangeName($Db)
    {
        $Config = file_get_contents("configs/modules/DB_" . $Db . "/ChangeName.json");
        $Config = json_decode($Config,true);
        if (property_exists(App::$Post,'Enable')) {
            $Config['Enable'] = true;
        }
        else {
            $Config['Enable'] = false;
        }
        if (property_exists(App::$Post,'MinLevel'))
            $Config['MinLevel'] = App::$Post->MinLevel;
        if (property_exists(App::$Post,'MinReset'))
            $Config['MinReset'] = App::$Post->MinReset;

        $ValuteConfig = file_get_contents("configs/DB_" . $Db . "/ValuteManager.json");
        $ValuteConfig = json_decode($ValuteConfig,true);
        for ($i = 0; $i < 5; $i++) {
            if ($ValuteConfig[$i]['Name'] != '' && property_exists(App::$Post,'val_take_'.$i)) {
                $Config['Price']['Valutes'][$i] = App::$Post->{'val_take_'.$i};
            }
            else {
                $Config['Price']['Valutes'][$i] = 0;
            }
        }

        file_put_contents('configs/modules/DB_' . $Db . '/ChangeName.json', json_encode($Config));

    }

    public static function ConfigModulesResetStats($Db)
    {
        $Config = file_get_contents("configs/modules/DB_" . $Db . "/ResetStats.json");
        $Config = json_decode($Config,true);
        if (property_exists(App::$Post,'Enable')) {
            $Config['Enable'] = true;
        }
        else {
            $Config['Enable'] = false;
        }
        if (property_exists(App::$Post,'MinLevel'))
            $Config['MinLevel'] = App::$Post->MinLevel;
        if (property_exists(App::$Post,'MinReset'))
            $Config['MinReset'] = App::$Post->MinReset;

        $ValuteConfig = file_get_contents("configs/DB_" . $Db . "/ValuteManager.json");
        $ValuteConfig = json_decode($ValuteConfig,true);
        for ($i = 0; $i < 5; $i++) {
            if ($ValuteConfig[$i]['Name'] != '' && property_exists(App::$Post,'val_take_'.$i)) {
                $Config['Price']['Valutes'][$i] = App::$Post->{'val_take_'.$i};
            }
            else {
                $Config['Price']['Valutes'][$i] = 0;
            }
        }

        file_put_contents('configs/modules/DB_' . $Db . '/ResetStats.json', json_encode($Config));

    }


    public static function GetAccountForIp($Db, $IP)
    {
        $Accs = App::$DBs[$Db]->select(array('MEMB_INFO.memb___id', 'MEMB_INFO.rdate', 'MEMB_STAT.IP', 'AccountCharacter.GameID1', 'AccountCharacter.GameID2', 'AccountCharacter.GameID3', 'AccountCharacter.GameID4', 'AccountCharacter.GameID5'))
            ->from('MEMB_STAT')->where('MEMB_STAT.IP', $IP)
            ->join('MEMB_INFO', "MEMB_STAT.memb___id = MEMB_INFO.memb___id COLLATE DATABASE_DEFAULT",'left', false)
            ->join('AccountCharacter', "MEMB_STAT.memb___id = AccountCharacter.ID COLLATE DATABASE_DEFAULT",'left', false)
            ->get()->result_array();
        $Accs[0]['AccountCharacters'] = $Accs[0]['GameID1'] . ', ' . $Accs[0]['GameID2'] . ', ' . $Accs[0]['GameID3'] . ', ' . $Accs[0]['GameID4'] . ', ' . $Accs[0]['GameID5'];
        return $Accs;
    }
    public static function GetAccountForAcc($Db, $Acc)
    {
        $Accs = App::$DBs[$Db]->select(array('MEMB_INFO.memb___id', 'MEMB_INFO.rdate', 'MEMB_STAT.IP', 'AccountCharacter.GameID1', 'AccountCharacter.GameID2', 'AccountCharacter.GameID3', 'AccountCharacter.GameID4', 'AccountCharacter.GameID5'))
            ->from('MEMB_INFO')->like('MEMB_INFO.memb___id', $Acc)
            ->join('MEMB_STAT', "MEMB_STAT.memb___id = MEMB_INFO.memb___id COLLATE DATABASE_DEFAULT",'left', false)
            ->join('AccountCharacter', "MEMB_STAT.memb___id = AccountCharacter.ID COLLATE DATABASE_DEFAULT",'left', false)
            ->get()->result_array();
        for ($i = 0; $i < count($Accs); $i++)
            $Accs[$i]['AccountCharacters'] = $Accs[$i]['GameID1'] . ', ' . $Accs[$i]['GameID2'] . ', ' . $Accs[$i]['GameID3'] . ', ' . $Accs[$i]['GameID4'] . ', ' . $Accs[$i]['GameID5'];
        return $Accs;
    }

    public static function GetAccountForChar($Db, $Char)
    {
        $Accs = App::$DBs[$Db]->select(array('MEMB_INFO.memb___id', 'MEMB_INFO.rdate', 'MEMB_STAT.IP', 'AccountCharacter.GameID1', 'AccountCharacter.GameID2', 'AccountCharacter.GameID3', 'AccountCharacter.GameID4', 'AccountCharacter.GameID5'))
            ->from('Character')->where('Character.Name', $Char)

            ->join('MEMB_STAT', "Character.AccountID = MEMB_STAT.memb___id COLLATE DATABASE_DEFAULT",'left', false)
            ->join('MEMB_INFO', "Character.AccountID = MEMB_INFO.memb___id COLLATE DATABASE_DEFAULT",'left', false)
            ->join('AccountCharacter', "Character.AccountID = AccountCharacter.ID COLLATE DATABASE_DEFAULT",'left', false)
            ->get()->result_array();
        $Accs[0]['AccountCharacters'] = $Accs[0]['GameID1'] . ', ' . $Accs[0]['GameID2'] . ', ' . $Accs[0]['GameID3'] . ', ' . $Accs[0]['GameID4'] . ', ' . $Accs[0]['GameID5'];
        return $Accs;
    }


    public static function ConfigModulesHideInfo($Db)
    {
        $Config = file_get_contents("configs/modules/DB_" . $Db . "/HideInfo.json");
        $Config = json_decode($Config,true);
        if (property_exists(App::$Post,'Enable')) {
            $Config['Enable'] = true;
        }
        else {
            $Config['Enable'] = false;
        }
        if (property_exists(App::$Post,'NeedLevel'))
            $Config['NeedLevel'] = App::$Post->NeedLevel;
        if (property_exists(App::$Post,'NeedReset'))
            $Config['NeedReset'] = App::$Post->NeedReset;

        $ValuteConfig = file_get_contents("configs/DB_" . $Db . "/ValuteManager.json");
        $ValuteConfig = json_decode($ValuteConfig,true);
        for ($i = 0; $i < 5; $i++) {
            if ($ValuteConfig[$i]['Name'] != '' && property_exists(App::$Post,'val_take_'.$i)) {
                $Config['Take']['Valutes'][$i] = App::$Post->{'val_take_'.$i};
            }
            else {
                $Config['Take']['Valutes'][$i] = 0;
            }
        }

        file_put_contents('configs/modules/DB_' . $Db . '/HideInfo.json', json_encode($Config));

    }
}