Exemplo n.º 1
0
 /**
  * Get city of current Item
  *
  * @param array params
  * @return string City name + postcode
  */
 function get_city($params = array())
 {
     // Make sure we are not missing any param:
     $params = array_merge(array('before' => '', 'after' => '', 'template' => '$name$ ($postcode$)'), $params);
     $this->load_Blog();
     if ($this->city_ID == 0 || !$this->city_visible()) {
         // City is not defined for current Item
         return;
     }
     load_class('regional/model/_city.class.php', 'City');
     $CityCache =& get_CityCache();
     if ($City = $CityCache->get_by_ID($this->city_ID)) {
         // Display city info
         $result = $params['before'];
         $city_tamplates = array('$name$', '$postcode$');
         $city_data = array($City->get_name(), $City->get_postcode());
         $result .= str_replace($city_tamplates, $city_data, $params['template']);
         $result .= $params['after'];
         return $result;
     }
 }
Exemplo n.º 2
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;
}
Exemplo n.º 3
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', 'cities');
// Get action parameter from request:
param_action();
if (param('city_ID', 'integer', '', true)) {
    // Load city from cache:
    $CityCache =& get_CityCache();
    if (($edited_City =& $CityCache->get_by_ID($city_ID, false)) === false) {
        unset($edited_City);
        forget_param('city_ID');
        $Messages->add(sprintf(T_('Requested «%s» object does not exist any longer.'), T_('City')), 'error');
        $action = 'nil';
    }
}
switch ($action) {
    case 'disable_city':
    case 'enable_city':
        // Check that this action request is not a CSRF hacked request:
        $Session->assert_received_crumb('city');
        // Disable a city only if it is enabled, and user has edit access.
        $current_User->check_perm('options', 'edit', true);
        // Make sure the city information was loaded. If not, just exit with error.