<?php

function __RB_check_error($action) {
    global $__RB_error;

    if (!empty($__RB_error[$action])) {
        __RB_error_alert($__RB_error[$action]);
    }
}

function __RB_check_success($action) {
    global $__RB_success;

    if (!empty($__RB_success[$action]) && $__RB_success[$action] && empty($__RB_error[$action])) {
        __RB_success_alert($action);
    }
}

//TODO: Fix localization
function __RB_check_geoShow() {
    global $__RB_config, $__RB_client_lng;

    if (!empty($_GET['debugMode']) && $_GET['debugMode'] == 'justLetMeTestSomething' || __RB_check_geoArray('geoShow')) {
        return true;
    }

    return false;
}

function __RB_check_geoHide() {
    global $__RB_config, $__RB_client_lng;

    if (!empty($_GET['debugMode']) && $_GET['debugMode'] == 'justLetMeTestSomething' || !__RB_check_geoArray('geoHide')) {
        return true;
    }

    return false;
}

function __RB_check_geoGwShow() {
    global $__RB_config, $__RB_client_lng;

    if (!empty($_GET['debugMode']) && $_GET['debugMode'] == 'justLetMeTestSomething' || __RB_check_geoArray('gwShow')) {
        return true;
    }

    return false;
}

function __RB_check_geoGwHide() {
    if (!empty($_GET['debugMode']) && $_GET['debugMode'] == 'justLetMeTestSomething' || !__RB_check_geoArray('gwHide')) {
        return true;
    }

    return false;
}

function __RB_check_geoArray($name) {
    global $__RB_config, $__RB_client_lng;

    if (!is_array($__RB_config['geo_block'][$name])) {
        return false;
    }

    foreach ($__RB_config['geo_block'][$name] as $val) {
        if ($val['lng_code'] == $__RB_client_lng || $val['lng_code'] == $__RB_client_lng .'-'.$val['lng_code']) {
            return true;
        }
    }

    return false;
}