/**
 * Callback to add filters on top of the result set
 *
 * @param Form
 */
function filter_regions(&$Form)
{
    load_class('regional/model/_country.class.php', 'Country');
    $CountryCache =& get_CountryCache(NT_('All'));
    $Form->select_country('c', get_param('c'), $CountryCache, T_('Country'), array('allow_none' => true));
    $Form->text('s', get_param('s'), 30, T_('Search'), '', 255);
}
Example #2
0
 * @var User
 */
global $current_User;
// Check minimum permission:
$current_User->check_perm('options', 'view', true);
// Memorize this as the last "tab" used in the Global Settings:
$UserSettings->set('pref_glob_settings_tab', $ctrl);
$UserSettings->set('pref_glob_regional_tab', $ctrl);
$UserSettings->dbupdate();
// Set options path:
$AdminUI->set_path('options', 'regional', 'countries');
// Get action parameter from request:
param_action();
if (param('ctry_ID', 'integer', '', true)) {
    // Load country from cache:
    $CountryCache =& get_CountryCache();
    if (($edited_Country =& $CountryCache->get_by_ID($ctry_ID, false)) === false) {
        unset($edited_Country);
        forget_param('ctry_ID');
        $Messages->add(sprintf(T_('Requested «%s» object does not exist any longer.'), T_('Country')), 'error');
        $action = 'nil';
    }
}
switch ($action) {
    case 'disable_country':
    case 'enable_country':
        // Check that this action request is not a CSRF hacked request:
        $Session->assert_received_crumb('country');
        // Disable a country only if it is enabled, and user has edit access.
        $current_User->check_perm('options', 'edit', true);
        // Make sure the country information was loaded. If not, just exit with error.
Example #3
0
/**
 * Callback to add filters on top of the result set
 *
 * @param Form
 */
function filter_cities(&$Form)
{
    load_class('regional/model/_country.class.php', 'Country');
    $CountryCache =& get_CountryCache(T_('All'));
    $Form->select_country('c', get_param('c'), $CountryCache, T_('Country'), array('allow_none' => true));
    $Form->select_input_options('r', get_regions_option_list(get_param('c'), get_param('r')), T_('Region'));
    $Form->select_input_options('sr', get_subregions_option_list(get_param('r'), get_param('sr')), T_('Sub-region'));
    $Form->text('s', get_param('s'), 30, T_('Search'), '', 255);
}
Example #4
0
 /**
  * Get comment's country that was detected by IP address
  *
  * @param string String to display before country, if country_ID is defined
  * @param string String to display after country, if country_ID is defined
  * @return string Country with flag
  */
 function get_ip_country($before = '', $after = '')
 {
     $country = '';
     if (!empty($this->IP_ctry_ID)) {
         // Country ID is defined
         load_funcs('regional/model/_regional.funcs.php');
         load_class('regional/model/_country.class.php', 'Country');
         $CountryCache =& get_CountryCache();
         if ($Country = $CountryCache->get_by_ID($this->IP_ctry_ID, false)) {
             $country .= $before;
             $country .= country_flag($Country->get('code'), $Country->get_name(), 'w16px', 'flag', '', false);
             $country .= ' ' . $Country->get_name();
             $country .= $after;
         }
     }
     return $country;
 }
Example #5
0
/**
 * Get regional data (Used to get regional IDs for user & item by regional names)
 *
 * @param string Country code
 * @param string Region name
 * @param string Subregion name
 * @param string City name
 * @return array Regional data
 */
function wp_get_regional_data($country_code, $region, $subregion, $city)
{
    $data = array('country' => 0, 'region' => 0, 'subregion' => 0, 'city' => 0);
    if (!empty($country_code)) {
        // Get country ID from DB by code
        $CountryCache =& get_CountryCache();
        if ($Country =& $CountryCache->get_by_name($country_code, false)) {
            $data['country'] = $Country->ID;
            if (!empty($region)) {
                // Get region ID from DB by name
                $RegionCache =& get_RegionCache();
                if ($Region =& $RegionCache->get_by_name($region, false)) {
                    if ($Region->ctry_ID == $data['country']) {
                        $data['region'] = $Region->ID;
                        if (!empty($subregion)) {
                            // Get subregion ID from DB by name
                            $SubregionCache =& get_SubregionCache();
                            if ($Subregion =& $SubregionCache->get_by_name($subregion, false)) {
                                if ($Subregion->rgn_ID == $data['region']) {
                                    $data['subregion'] = $Subregion->ID;
                                }
                            }
                        }
                        if (!empty($city)) {
                            // Get city ID from DB by name
                            $CityCache =& get_CityCache();
                            if ($City =& $CityCache->get_by_name($city, false)) {
                                if ($City->rgn_ID == $data['region']) {
                                    $data['city'] = $City->ID;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return $data;
}
Example #6
0
/**
 * Display location select elements (Country, Region, Subregion, City)
 *
 * @param object Form
 * @param object Edited Item
 */
function echo_item_location_form(&$Form, &$edited_Item)
{
    load_class('regional/model/_country.class.php', 'Country');
    load_funcs('regional/model/_regional.funcs.php');
    $edited_Item_Blog = $edited_Item->get_Blog();
    if (!$edited_Item_Blog->country_visible()) {
        // If country is NOT visible it means all other location fields also are not visible, so exit here
        return;
    }
    global $rsc_url;
    $Form->begin_fieldset(T_('Location'));
    $table_class = '';
    if ($edited_Item->is_special()) {
        // A post with special type should always has the location fields as not required
        // This css class hides all red stars of required fields
        $table_class = ' not_required';
    }
    $Form->switch_layout('table');
    $Form->formstart = '<table id="item_locations" cellspacing="0" class="fform' . $table_class . '">' . "\n";
    $Form->labelstart = '<td class="right"><strong>';
    $Form->labelend = '</strong></td>';
    echo $Form->formstart;
    $button_refresh_regional = '<button id="%s" type="submit" name="actionArray[edit_switchtab]" class="action_icon refresh_button">' . get_icon('refresh') . '</button>';
    $button_refresh_regional .= '<img src="' . $rsc_url . 'img/ajax-loader.gif" alt="' . T_('Loading...') . '" title="' . T_('Loading...') . '" style="display:none;margin-left:5px" align="top" />';
    // Country
    $CountryCache =& get_CountryCache();
    $country_is_required = $edited_Item->Blog->get_setting('location_country') == 'required';
    $Form->select_country('item_ctry_ID', $edited_Item->ctry_ID, $CountryCache, T_('Country'), array('required' => $country_is_required, 'allow_none' => true));
    if ($edited_Item->Blog->region_visible()) {
        // Region
        $region_is_required = $edited_Item->Blog->get_setting('location_region') == 'required';
        $Form->select_input_options('item_rgn_ID', get_regions_option_list($edited_Item->ctry_ID, $edited_Item->rgn_ID, array('none_option_text' => T_('Unknown'))), T_('Region'), sprintf($button_refresh_regional, 'button_refresh_region'), array('required' => $region_is_required));
    }
    if ($edited_Item->Blog->subregion_visible()) {
        // Subregion
        $subregion_is_required = $edited_Item->Blog->get_setting('location_subregion') == 'required';
        $Form->select_input_options('item_subrg_ID', get_subregions_option_list($edited_Item->rgn_ID, $edited_Item->subrg_ID, array('none_option_text' => T_('Unknown'))), T_('Sub-region'), sprintf($button_refresh_regional, 'button_refresh_subregion'), array('required' => $subregion_is_required));
    }
    if ($edited_Item->Blog->city_visible()) {
        // City
        $city_is_required = $edited_Item->Blog->get_setting('location_city') == 'required';
        $Form->select_input_options('item_city_ID', get_cities_option_list($edited_Item->ctry_ID, $edited_Item->rgn_ID, $edited_Item->subrg_ID, $edited_Item->city_ID, array('none_option_text' => T_('Unknown'))), T_('City'), sprintf($button_refresh_regional, 'button_refresh_city'), array('required' => $city_is_required));
    }
    echo $Form->formend;
    $Form->switch_layout(NULL);
    $Form->end_fieldset();
}
Example #7
0
 /**
  * Get country of current Item
  *
  * @param array params
  * @return string Country name
  */
 function get_country($params = array())
 {
     // Make sure we are not missing any param:
     $params = array_merge(array('before' => '', 'after' => ''), $params);
     $this->load_Blog();
     if ($this->ctry_ID == 0 || !$this->country_visible()) {
         // Country is not defined for current Item OR Counries are hidden
         return;
     }
     load_class('regional/model/_country.class.php', 'Country');
     $CountryCache =& get_CountryCache();
     if ($Country = $CountryCache->get_by_ID($this->ctry_ID)) {
         // Display country name
         $result = $params['before'];
         $result .= $Country->get_name();
         $result .= $params['after'];
         return $result;
     }
 }
Example #8
0
/**
 * Callback to add filters on top of the result set
 *
 * @param Form
 */
function callback_filter_userlist(&$Form)
{
    global $Settings, $current_User;
    $Form->hidden('filter', 'new');
    $Form->text('keywords', get_param('keywords'), 20, T_('Name'), '', 50);
    echo '<span class="nowrap">';
    $Form->checkbox('gender_men', get_param('gender_men'), T_('Men'));
    $Form->checkbox('gender_women', get_param('gender_women'), T_('Women'));
    echo '</span>';
    if (!is_admin_page()) {
        echo '<br />';
    }
    if (is_admin_page()) {
        // show this filters only on admin interface
        if ($current_User->check_perm('users', 'edit')) {
            // Show "Reported users" filter only for users with edit user permission
            $Form->checkbox('reported', get_param('reported'), T_('Reported users'));
            $Form->checkbox('custom_sender_email', get_param('custom_sender_email'), T_('Users with custom sender address'));
            $Form->checkbox('custom_sender_name', get_param('custom_sender_name'), T_('Users with custom sender name'));
        }
        $Form->select_input_array('account_status', get_param('account_status'), get_user_statuses(T_('All')), T_('Account status'));
        $GroupCache = new DataObjectCache('Group', true, 'T_groups', 'grp_', 'grp_ID', 'grp_name');
        $group_options_array = array('-1' => T_('All (Ungrouped)'), '0' => T_('All (Grouped)')) + $GroupCache->get_option_array();
        $Form->select_input_array('group', get_param('group'), $group_options_array, T_('User group'), '', array('force_keys_as_values' => true));
        echo '<br />';
    }
    if (user_country_visible()) {
        // Filter by country
        load_class('regional/model/_country.class.php', 'Country');
        load_funcs('regional/model/_regional.funcs.php');
        $CountryCache =& get_CountryCache(T_('All'));
        $Form->select_country('country', get_param('country'), $CountryCache, T_('Country'), array('allow_none' => true));
    }
    if (user_region_visible()) {
        // Filter by region
        echo '<span id="region_filter"' . (!regions_exist(get_param('country'), true) ? ' style="display:none"' : '') . '>';
        $Form->select_input_options('region', get_regions_option_list(get_param('country'), get_param('region')), T_('Region'));
        echo '</span>';
    }
    if (user_subregion_visible()) {
        // Filter by subregion
        echo '<span id="subregion_filter"' . (!subregions_exist(get_param('region'), true) ? ' style="display:none"' : '') . '>';
        $Form->select_input_options('subregion', get_subregions_option_list(get_param('region'), get_param('subregion')), T_('Sub-region'));
        echo '</span>';
    }
    if (user_city_visible()) {
        // Filter by city
        echo '<span id="city_filter"' . (!cities_exist(get_param('country'), get_param('region'), get_param('subregion'), true) ? ' style="display:none"' : '') . '>';
        $Form->select_input_options('city', get_cities_option_list(get_param('country'), get_param('region'), get_param('subregion'), get_param('city')), T_('City'));
        echo '</span>';
    }
    echo '<br />';
    $Form->interval('age_min', get_param('age_min'), 'age_max', get_param('age_max'), 3, T_('Age group'));
    echo '<br />';
    $criteria_types = param('criteria_type', 'array/integer');
    $criteria_values = param('criteria_value', 'array/string');
    if (count($criteria_types) == 0) {
        // Init one criteria fieldset for first time
        $criteria_types[] = '';
        $criteria_values[] = '';
    }
    foreach ($criteria_types as $c => $type) {
        $value = trim(strip_tags($criteria_values[$c]));
        if ($value == '' && count($criteria_types) > 1 && $c > 0) {
            // Don't display empty field again after filter request
            continue;
        }
        if ($c > 0) {
            // Separator between criterias
            echo '<br />';
        }
        $Form->output = false;
        $criteria_input = $Form->text('criteria_value[]', $value, 17, '', '', 50);
        $criteria_input .= get_icon('add', 'imgtag', array('rel' => 'add_criteria'));
        $Form->output = true;
        global $user_fields_empty_name;
        $user_fields_empty_name = T_('Select...');
        $Form->select('criteria_type[]', $type, 'callback_options_user_new_fields', T_('Specific criteria'), $criteria_input);
    }
    if (user_region_visible()) {
        // JS functions for AJAX loading of regions, subregions & cities
        ?>
<script type="text/javascript">
jQuery( '#country' ).change( function()
{
	var this_obj = jQuery( this );
	jQuery.ajax( {
	type: 'POST',
	url: '<?php 
        echo get_samedomain_htsrv_url();
        ?>
anon_async.php',
	data: 'action=get_regions_option_list&ctry_id=' + jQuery( this ).val(),
	success: function( result )
		{
			jQuery( '#region' ).html( ajax_debug_clear( result ) );
			if( jQuery( '#region option' ).length > 1 )
			{
				jQuery( '#region_filter' ).show();
			}
			else
			{
				jQuery( '#region_filter' ).hide();
			}
			load_subregions( 0 ); // Reset sub-regions
		}
	} );
} );

jQuery( '#region' ).change( function ()
{	// Change option list with sub-regions
	load_subregions( jQuery( this ).val() );
} );

jQuery( '#subregion' ).change( function ()
{	// Change option list with cities
	load_cities( jQuery( '#country' ).val(), jQuery( '#region' ).val(), jQuery( this ).val() );
} );

function load_subregions( region_ID )
{	// Load option list with sub-regions for seleted region
	jQuery.ajax( {
	type: 'POST',
	url: '<?php 
        echo get_samedomain_htsrv_url();
        ?>
anon_async.php',
	data: 'action=get_subregions_option_list&rgn_id=' + region_ID,
	success: function( result )
		{
			jQuery( '#subregion' ).html( ajax_debug_clear( result ) );
			if( jQuery( '#subregion option' ).length > 1 )
			{
				jQuery( '#subregion_filter' ).show();
			}
			else
			{
				jQuery( '#subregion_filter' ).hide();
			}
			load_cities( jQuery( '#country' ).val(), region_ID, 0 );
		}
	} );
}

function load_cities( country_ID, region_ID, subregion_ID )
{	// Load option list with cities for seleted region or sub-region
	jQuery.ajax( {
	type: 'POST',
	url: '<?php 
        echo get_samedomain_htsrv_url();
        ?>
anon_async.php',
	data: 'action=get_cities_option_list&ctry_id=' + country_ID + '&rgn_id=' + region_ID + '&subrg_id=' + subregion_ID,
	success: function( result )
		{
			jQuery( '#city' ).html( ajax_debug_clear( result ) );
			if( jQuery( '#city option' ).length > 1 )
			{
				jQuery( '#city_filter' ).show();
			}
			else
			{
				jQuery( '#city_filter' ).hide();
			}
		}
	} );
}
</script>
<?php 
    }
}
Example #9
0
 /**
  * Get country by IP address
  *
  * @param string IP in format xxx.xxx.xxx.xxx
  * @return object Country
  */
 function get_country_by_IP($IP)
 {
     if (function_exists('geoip_country_code_by_name')) {
         // GeoIP extension
         // Get country code by user IP address
         $country_code = @geoip_country_code_by_name($IP);
     } else {
         // Include GeoIP API
         require_once dirname(__FILE__) . '/geoip.inc';
         // Open GeoIP database
         $GeoIP = geoip_open($this->geoip_file_path, GEOIP_STANDARD);
         // Get country code by user IP address
         $country_code = geoip_country_code_by_addr($GeoIP, $IP);
         // Close GeoIP DB
         geoip_close($GeoIP);
     }
     if (!$country_code) {
         // No found country with current IP address
         return false;
     }
     global $DB;
     // Get country ID by code
     $SQL = new SQL();
     $SQL->SELECT('ctry_ID');
     $SQL->FROM('T_regional__country');
     $SQL->WHERE('ctry_code = ' . $DB->quote($country_code));
     $country_ID = $DB->get_var($SQL->get());
     if (!$country_ID) {
         // No found country in the b2evo DB
         return false;
     }
     // Load Country class (PHP4):
     load_class('regional/model/_country.class.php', 'Country');
     $CountryCache =& get_CountryCache();
     $Country = $CountryCache->get_by_ID($country_ID, false);
     return $Country;
 }
Example #10
0
/**
 * Block request by country
 *
 * @param integer country ID
 * @param boolean set true to block the requet here, or false to handle outside the function
 * @return boolean true if blocked, false otherwise
 */
function antispam_block_by_country($country_ID, $assert = true)
{
    global $DB;
    $CountryCache =& get_CountryCache();
    $Country = $CountryCache->get_by_ID($country_ID, false);
    if ($Country && $Country->get('status') == 'blocked') {
        // The country exists in the database and has blocked status
        if ($assert) {
            // block the request
            $debug_message = sprintf('A request from \'%s\' was blocked because of this country is blocked.', $Country->get_name());
            exit_blocked_request('Country', $debug_message);
            // WILL exit();
        }
        // Update the number of requests from blocked countries
        $DB->query('UPDATE T_regional__country
			SET ctry_block_count = ctry_block_count + 1
			WHERE ctry_ID = ' . $Country->ID);
        return true;
    }
    return false;
}