/** * Constructor * * @param object database row */ function Subregion($db_row = NULL) { // Call parent constructor: parent::DataObject('T_regional__subregion', 'subrg_', 'subrg_ID'); if ($db_row) { $this->ID = $db_row->subrg_ID; $this->rgn_ID = $db_row->subrg_rgn_ID; $this->code = $db_row->subrg_code; $this->name = $db_row->subrg_name; $this->enabled = $db_row->subrg_enabled; $this->preferred = $db_row->subrg_preferred; // Load Region class load_class('regional/model/_region.class.php', 'Region'); $RegionCache =& get_RegionCache(); if (!empty($this->rgn_ID)) { if (($Region =& $RegionCache->get_by_ID($db_row->subrg_rgn_ID, false)) !== false) { // Get country ID $this->ctry_ID = $Region->ctry_ID; } } } }
/** * Constructor * * @param object database row */ function Subregion($db_row = NULL) { // Call parent constructor: parent::DataObject('T_regional__subregion', 'subrg_', 'subrg_ID'); $this->delete_restrictions = array(array('table' => 'T_users', 'fk' => 'user_subrg_ID', 'msg' => T_('%d related users')), array('table' => 'T_regional__city', 'fk' => 'city_subrg_ID', 'msg' => T_('%d related cities'))); $this->delete_cascades = array(); if ($db_row) { $this->ID = $db_row->subrg_ID; $this->rgn_ID = $db_row->subrg_rgn_ID; $this->code = $db_row->subrg_code; $this->name = $db_row->subrg_name; $this->enabled = $db_row->subrg_enabled; $this->preferred = $db_row->subrg_preferred; // Load Region class load_class('regional/model/_region.class.php', 'Region'); $RegionCache =& get_RegionCache(); if (!empty($this->rgn_ID)) { if (($Region =& $RegionCache->get_by_ID($db_row->subrg_rgn_ID, false)) !== false) { // Get country ID $this->ctry_ID = $Region->ctry_ID; } } } }
/** * 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; }
/** * Get region of current Item * * @param array params * @return string Region name */ function get_region($params = array()) { // Make sure we are not missing any param: $params = array_merge(array('before' => '', 'after' => ''), $params); $this->load_Blog(); if ($this->rgn_ID == 0 || !$this->region_visible()) { // Region is not defined for current Item return; } load_class('regional/model/_region.class.php', 'Region'); $RegionCache =& get_RegionCache(); if ($Region = $RegionCache->get_by_ID($this->rgn_ID)) { // Display region name $result = $params['before']; $result .= $Region->get_name(); $result .= $params['after']; return $result; } }
* @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', 'regions'); // Get action parameter from request: param_action(); if (param('rgn_ID', 'integer', '', true)) { // Load region from cache: $RegionCache =& get_RegionCache(); if (($edited_Region =& $RegionCache->get_by_ID($rgn_ID, false)) === false) { unset($edited_Region); forget_param('rgn_ID'); $Messages->add(sprintf(T_('Requested «%s» object does not exist any longer.'), T_('Region')), 'error'); $action = 'nil'; } } switch ($action) { case 'disable_region': case 'enable_region': // Check that this action request is not a CSRF hacked request: $Session->assert_received_crumb('region'); // Disable a region only if it is enabled, and user has edit access. $current_User->check_perm('options', 'edit', true); // Make sure the region information was loaded. If not, just exit with error.