public static function detectLocation(erLhcoreClassModelChat &$instance)
 {
     $geoData = erLhcoreClassModelChatConfig::fetch('geo_data');
     $geo_data = (array) $geoData->data;
     if (isset($geo_data['geo_detection_enabled']) && $geo_data['geo_detection_enabled'] == 1) {
         $params = array();
         if ($geo_data['geo_service_identifier'] == 'mod_geoip2') {
             $params['country_code'] = $geo_data['mod_geo_ip_country_code'];
             $params['country_name'] = $geo_data['mod_geo_ip_country_name'];
             $params['mod_geo_ip_city_name'] = $geo_data['mod_geo_ip_city_name'];
             $params['mod_geo_ip_latitude'] = $geo_data['mod_geo_ip_latitude'];
             $params['mod_geo_ip_longitude'] = $geo_data['mod_geo_ip_longitude'];
         } elseif ($geo_data['geo_service_identifier'] == 'locatorhq') {
             $params['username'] = $geo_data['locatorhqusername'];
             $params['api_key'] = $geo_data['locatorhq_api_key'];
         } elseif ($geo_data['geo_service_identifier'] == 'ipinfodbcom') {
             $params['api_key'] = $geo_data['ipinfodbcom_api_key'];
         } elseif ($geo_data['geo_service_identifier'] == 'max_mind') {
             $params['detection_type'] = $geo_data['max_mind_detection_type'];
             $params['city_file'] = isset($geo_data['max_mind_city_location']) ? $geo_data['max_mind_city_location'] : '';
         }
         $location = erLhcoreClassModelChatOnlineUser::getUserData($geo_data['geo_service_identifier'], $instance->ip, $params);
         if ($location !== false) {
             $instance->country_code = $location->country_code;
             $instance->country_name = $location->country_name;
             $instance->lat = $location->lat;
             $instance->lon = $location->lon;
             $instance->city = $location->city;
         }
     }
 }
             $filledAPIData = true;
             if ($form->hasValidData('ipinfodbAPIKey') && $form->ipinfodbAPIKey != '') {
                 $data['ipinfodbcom_api_key'] = $form->ipinfodbAPIKey;
             } else {
                 $filledAPIData = false;
                 $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/onlineusers', 'Please enter the API key!');
             }
             if ($filledAPIData == true) {
                 $responseDetection = erLhcoreClassModelChatOnlineUser::getUserData('ipinfodbcom', erLhcoreClassIPDetect::getServerAddress(), array('api_key' => $data['ipinfodbcom_api_key']));
                 if ($responseDetection == false || !isset($responseDetection->country_code)) {
                     $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/onlineusers', 'Setting service provider failed, please check that your service provider allows you to make requests to remote pages and your API key is correct!');
                 }
             }
         } elseif ($form->UseGeoIP == 'php_geoip') {
             $data['geo_service_identifier'] = 'php_geoip';
             $responseDetection = erLhcoreClassModelChatOnlineUser::getUserData('php_geoip', '94.23.200.91');
             if ($responseDetection == false || !isset($responseDetection->country_code)) {
                 $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/onlineusers', 'Setting service provider failed, please check that you have installed php-GeoIP module and GeoIPCity.dat file is available!');
             }
         }
     } else {
         $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/onlineusers', 'Please choose a service provider!');
     }
 }
 if (count($Errors) == 0) {
     $geoData->value = serialize($data);
     $geoData->saveThis();
     $tpl->set('updated', 'done');
 } else {
     $tpl->set('errors', $Errors);
 }