<?php

/**
 * Class HideInfo
 * Module Hide Info Character
 * Variable in database HideInfoTime
 */

class HideInfo extends CharacterModule
{

    public function NeedToHide(){
        if($this->AccountOnline)
            return false;
        
        $HideInfoConfig = App::$Configs->mod_HideInfo;
        if (!$HideInfoConfig['Enable'])
            return false;
        
        $ReturnArr = array();
        $ReturnArr['NeedLevel'] = $HideInfoConfig['NeedLevel'];
        $ReturnArr['NeedReset'] = $HideInfoConfig['NeedReset'];
        $ReturnArr['Take']['Valutes'] = $HideInfoConfig['Take']['Valutes'];
        return $ReturnArr;

    }
    public function Hide($NickCharacter, $Time)
    {
        if ($this->AccountOnline)
        {
            return false;
        }
        if (App::$Post->selected_char = '')
            return false;
        
        $HideInfoConfig = App::$Configs->mod_HideInfo;
        if (!$HideInfoConfig['Enable'])
            return false;

        $Character = Character::GetActivePlayerInfo($NickCharacter);
        $Character = $Character[0];
        $Block = false;
        if($Character['cLevel'] < $HideInfoConfig['NeedLevel']){
            $Block = true;
            Messages::Add("block_hideinfo_class_need_level");
        }
        if($Character['Resets'] < $HideInfoConfig['NeedReset']){
            $Block = true;
            Messages::Add("block_hideinfo_class_need_reset");
        }
        if ($Time <= 0 && !is_numeric($Time)){
            $Block = true;
            Messages::Add("block_hideinfo_incorrect_value");
        }
        
        if ($Character['HideInfoTime'] > time())
            $FinalTime = $Character['HideInfoTime'] + ($Time * 60 * 60);
        else
            $FinalTime = time() + ($Time * 60 * 60);
        

        if ($Block == false) {
            if (ValuteManager::CheckFive($HideInfoConfig['Take']['Valutes'][0], $HideInfoConfig['Take']['Valutes'][1], $HideInfoConfig['Take']['Valutes'][2], $HideInfoConfig['Take']['Valutes'][3], $HideInfoConfig['Take']['Valutes'][4])) {

                if (App::$DBs[$_SESSION['user_db']]->where('Name', $Character['Name'])->update('Character', array('HideInfoTime' => $FinalTime))) {
                    ValuteManager::TakeFive($HideInfoConfig['Take']['Valutes'][0], $HideInfoConfig['Take']['Valutes'][1], $HideInfoConfig['Take']['Valutes'][2], $HideInfoConfig['Take']['Valutes'][3], $HideInfoConfig['Take']['Valutes'][4]);

                    Logs::WriteLog("Module: [HideInfo], Account [{$_SESSION['login']}]. Success HideInfo({$Time} Hour)", 'Modules.log');
                    Messages::Add('success_hideinfo');
                    return true;
                }
            }
        }
        Logs::WriteLog("Module: [HideInfo], Account [{$_SESSION['login']}]. Fail HideInfo", 'Modules.log');
        Messages::Add('fail_hideinfo');
        return false;
    }

    /**
     * @param $Nick string
     */

}