[APORTES]: Sistema de Clientes WHMCS

  • Autor Autor JamesPierre
  • Fecha de inicio Fecha de inicio
J

JamesPierre

No recomendado
Verificado
Verificación en dos pasos activada
Verificado por Whatsapp
Hola Betanos, abro este post con un buen aporte para los que usamos este grandioso sistema, dando iniciativa para que ustedes también aporten en este post algo de su conocimiento.

Pues bien, esto es algo que de repente muchos han necesitado o buscado. Se trata de MÓDULO GEOLOCALIZACIÓN, sirve para cuando un usuario ingresa a nuestro web, al usuario le muestre en su idioma y moneda automáticamente.

En este array puedes agregar las monedas que quieras, juntamente con el código del país.

PHP:
$country_to_currency = array(    'default' => 'USD',    'US'      => 'USD',    'PE'      => 'PEN',    'ES'      => 'EUR',    'CL'      => 'CLP',    'CA'      => 'CAD',    'AR'      => 'ARS',    'CO'      => 'COP',    'MX'      => 'MXN',    'BR'      => 'BRL'

 // NOTE: Puedes agregar mas lineas    );

En este otro array mostramos el idioma al usuario según el código de País.

PHP:
$country_to_language = array(    'default' => 'english',    'US'    => 'english',    'PE'    => 'spanish',    'ES'    => 'spanish',    'BR'    => 'portuguese-br',    'CL'    => 'spanish',    'CO'    => 'spanish',    'PT'    => 'portuguese-pt',    'MX'    => 'spanish',    'AR'    => 'spanish',    'BO'    => 'spanish',    'CN'    => 'english',    'EC'    => 'spanish',    'CR'    => 'spanish',    'PA'    => 'spanish',    'PY'    => 'spanish',    'UY'    => 'spanish'        // NOTE: Puedes agregar mas lineas);


Si tienes un theme, deberás cambiarle de nombre a six. (si no no funciona)

PHP:
$language_to_template = array(    'default'  => 'six',    'english'  => 'six',    'spanish' => 'six'
);

Para hacer posible las anteriores funciones, debemos de descargar los archivos: geoip.inc y GeoIP.dat desde
GeoLite Legacy Downloadable Databases « Maxmind Developer Site y deberás subirlo a la carpeta whmcs/inclues/hooks

PHP:
     * NEW: Get Country using external service - Maxmind GeoLite Example     * http://dev.maxmind.com/geoip/geolite     * NOTE: You can handle this part with any other method.     */    include "geoip.inc";    $gi = geoip_open(dirname(__FILE__).DIRECTORY_SEPARATOR."GeoIP.dat", GEOIP_STANDARD);     $current_country = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);    geoip_close($gi);        /**

En esta función podemos limitar al usuario a que cambie el tipo de moneda (no podrá cambiar de moneda)
Esta función es opcional. Si deseas habilitar, retira los /**

PHP:
/** * Preventing from switching currency by user * NOTE: You can remove/disable this part if not needed. **  if(isset($_SESSION['switched_currency']) && $_SESSION['switched_currency'] != $_SESSION['currency'] ) {    $_SESSION['currency'] = $_SESSION['switched_currency'];}}*/

Copio el código completo de lo que uso.

PHP:
<?php
/** * GEOLOCATION HOOK FOR WHMCS * This hook will automatically setup currency and language * for nonlogged users in your clientarea. *  *  * For more information, read the whole article here: * http://blog.whmcs.com *  *  * @author  ModulesGarden *  [MENTION=3037]Link[/MENTION]    [url=http://www.modulesgarden.com]ModulesGarden - Top Quality Custom Software Development[/url] */

/**  * Response code, set 301 or 302 */$responseCode = 301;
$country_to_currency = array(    'default' => 'USD',    'US'      => 'USD',    'PE'      => 'PEN',    'ES'      => 'EUR',    'CL'      => 'CLP',    'CA'      => 'CAD',    'AR'      => 'ARS',    'CO'      => 'COP',    'MX'      => 'MXN',    'BR'      => 'BRL'        // NOTE: You can add more below);
$country_to_language = array(    'default' => 'english',    'US'    => 'english',    'PE'    => 'spanish',    'ES'    => 'spanish',    'BR'    => 'portuguese-br',    'CL'    => 'spanish',    'CO'    => 'spanish',    'PT'    => 'portuguese-br',    'MX'    => 'spanish',    'AR'    => 'spanish',    'BO'    => 'spanish',    'CN'    => 'english',    'EC'    => 'spanish',    'CR'    => 'spanish',    'PA'    => 'spanish',    'PY'    => 'spanish',    'UY'    => 'spanish'        // NOTE: You can add more below);
/**  * Please note that templates available in WHMCS V6 are: 'six' and 'five'. * In WHMCS V5 there are: 'dafault', 'portal' and 'classic' templates. * It is important to use a template that exists within your WHMCS system. * You must not mix up these two groups together. */$language_to_template = array(    'default'  => 'six',    'english'  => 'six',    'spanish' => 'six'
    // NOTE: You can add more below);
$allowed_scripts = array(    'p1.php',    'index.php',    'clientarea.php',    'cart.php',    'knowledgebase.php',    'announcements.php',    'serverstatus.php',    'affiliates.php',    'contact.php'    // NOTE: You can add more below);


/*** FUNCTION geolocation_getCurrencyId* This function will return currency id for specific code.* * @param  string * @return int*/function geolocation_getCurrencyId($currency) {    $q = mysql_query('SELECT id FROM tblcurrencies WHERE code = "'.mysql_escape_string($currency).'"'); // escape string just in case    $r = mysql_fetch_assoc($q);    mysql_free_result($q);        if(isset($r['id']))     {        return $r['id'];    }}
$script_path        = substr($_SERVER['SCRIPT_NAME'], strrpos($_SERVER['SCRIPT_NAME'], DIRECTORY_SEPARATOR)+1);$current_template   = $_SESSION['Template'];$_language          = $_SESSION['Language'];

/** * Main Geolocation Script *  * NOT run script * - if we are in adminarea * - if already setup for this session * - if user is logged in * - NEW: allowing to run the hook only for specific scripts (defined above) */
if(in_array($script_path, $allowed_scripts) && strpos($_SERVER['REQUEST_URI'], $customadminpath) === false && $_SESSION['geolocation_setup'] !== true && $_SESSION['uid'] == false) {     $_SESSION['geolocation_setup'] = true; // prevent from redirecting back again in this session           /**     * Get Country using external service - Hostip.info example     * NOTE: You can handle this part with any other method.     *    $current_country = '';    $ret = file_get_contents("http://api.hostip.info/get_json.php?ip=".$_SERVER['REMOTE_ADDR']); // this can be called also via cURL    $parsed_json = @json_decode($ret,true);    if(isset($parsed_json['country_code'])) {        $current_country = $parsed_json['country_code'];    }     *     */        /**     * NEW: Get Country using external service - Maxmind GeoLite Example     * [url=http://dev.maxmind.com/geoip/geolite]GeoLite Legacy Downloadable Databases « Maxmind Developer Site[/url]     * NOTE: You can handle this part with any other method.     */    include "geoip.inc";    $gi = geoip_open(dirname(__FILE__).DIRECTORY_SEPARATOR."GeoIP.dat", GEOIP_STANDARD);     $current_country = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);    geoip_close($gi);        /**     * Get language, currency and currency ID in order to setup the right values in the system     */    $currency = $current_country != '' && isset($country_to_currency[$current_country])                 ? $country_to_currency[$current_country]                : $country_to_currency['default'];            $currency_id = geolocation_getCurrencyId($currency);        $_language = $current_country != '' && isset($country_to_language[$current_country])                 ? $country_to_language[$current_country]                : $country_to_language['default'];                /**     * Setup Currency Session     * NOTE: You can remove/disable this part if not needed.     */    if($currency_id && (!isset($_SESSION['currency']) || $_SESSION['currency'] != $currency))    {                 $_SESSION['currency'] = $_SESSION['switched_currency'] = $currency_id;    }            /**     * Setting up template for redirect     * NOTE: You can remove/disable this part if not needed.     */    $systpl = isset($language_to_template[$_language])                 ? $language_to_template[$_language]                : $language_to_template['default'];        /**     * Setup URL Redirection to Switch Language     * NOTE: You can remove/disable this part if not needed.     */     if(!isset($_SESSION['Language']) || $_SESSION['Language'] != $_language)    {         if(!empty($_language) && !empty($systpl))        {            $location = $_SERVER['REQUEST_URI'];                          $_SESSION['Language'] = $_language;            $_SESSION['Template'] = $systpl;                         $_SESSION['preserveTemplate'] = $systpl ? $systpl : false; //comment this line to allow template changes on language change                        ob_clean();             header('location: '.$location, true, $responseCode);            die();        }    }} 
/** * Change template if * - current template is NOT correct for this language * - current template is NOT default, if no language was chosen *  * Special thanks to Shalom Burla from Star Network & Promotion LTD :) * NOTE: You can remove/disable this part if not needed. */if($_SESSION['preserveTemplate']){    $systpl = $_SESSION['preserveTemplate'];}else{    $systpl = isset($language_to_template[$_language])         ? $language_to_template[$_language]        : $language_to_template['default'];    }
if(in_array($script_path, $allowed_scripts) && strpos($_SERVER['REQUEST_URI'], $customadminpath) === false && $current_template != $systpl && !empty($systpl)) {     if($systpl != $_GET['systpl'])    {        $location = $_SERVER['REQUEST_URI'];          $_SESSION['Template'] = $systpl;                   $tmp = explode('?', $location);         $args = $tmp[1] ? explode('&amp', $tmp[1]) : '';         foreach($args as $key => $value)        {            if($value == 'systpl='.$_GET['systpl'])            {                unset($args[$key]);            }                        if(strpos($tmp[1], 'language=') > 0 || strpos($tmp[1], 'language=') === 0)            {                 $_SESSION['Language'] = str_replace('language=', '', $value);                unset($args[$key]);            }                    }
        $nArgs = implode('&', $args);        $location = $nArgs ? $tmp[0].'?'.$nArgs : $tmp[0];                        ob_clean();        header('location: '.$location, false, $responseCode);        die();    }}

/** * Preventing from switching currency by user * NOTE: You can remove/disable this part if not needed. **  if(isset($_SESSION['switched_currency']) && $_SESSION['switched_currency'] != $_SESSION['currency'] ) {    $_SESSION['currency'] = $_SESSION['switched_currency'];}}*/

Les dejo todos los archivos completos aqui.
La clave del archivo comprimido: jamespierre


Para agregar más paises, les dejo el link para copiar el ISO Códigos de Países - Países del Mundo

Ojo: este modulo no ha sido creado por mi, el autor está en este link: http://www.blog.modulesgarden.com/automatic-currency-and-language-setup-for-whmcs/
 

Temas similares

Atrás
Arriba