<?php
use Illuminate\Database\Capsule\Manager as Capsule;

function wgs_dfordomain_currency() {
    $clientCurrency = '';
    if (isset($_SESSION['uid']) && !empty($_SESSION['uid'])) {
        $clientCurrency = Capsule::table('tblclients')->select('currency')->where('id', $_SESSION['uid'])->get();
    }
    if (isset($clientCurrency) && !empty($clientCurrency) && $clientCurrency[0]->currency != '0') {
        $currency = Capsule::table('tblcurrencies')->where('id', $clientCurrency[0]->currency)->get();
    } else if (isset($_SESSION['currency']) && !empty($_SESSION['currency'])) {
        $currency = Capsule::table('tblcurrencies')->where('id', $_SESSION['currency'])->get();
    } else {
        $currency = Capsule::table('tblcurrencies')->where('default', '1')->get();
    }
    return $currency;
}


add_hook('ClientAreaFooterOutput', 1, function($vars) {
    if ($_GET['a'] == 'checkout' || $_GET['a'] == 'view') {
        $currencyData = wgs_dfordomain_currency();        
        if ($currencyData['0']->code != 'INR') {
            return <<<HTML
            <script type="text/javascript">            
            jQuery('input[type=radio]').each(function(){
                    var name = jQuery(this).val();                    
                    if(name == 'payu'){                            
                            jQuery(this).closest('li').hide();
                    }

            });
            </script>
HTML;
        }
    }
});

add_hook('ClientAreaPageViewInvoice', 1, function($vars) {
    $currencyData = wgs_dfordomain_currency();        
    //echo '<pre>'; print_r($currencyData); die('test');
    if ($currencyData['0']->code != 'INR')
    {
        $script = '<script src="../../assets/js/jquery.min.js"></script><script type="text/javascript">
                jQuery(document).ready(function(){
                    jQuery("select[name=\'gateway\'] option").each(function(){
                        if(jQuery(this).val() == "payu")
                            jQuery(this).remove();
                    });
                });
            </script>';
        echo $script;
    }
});

?>
