Index: trunk/core/units/general/country_states.php =================================================================== diff -u -N --- trunk/core/units/general/country_states.php (revision 2291) +++ trunk/core/units/general/country_states.php (revision 0) @@ -1,101 +0,0 @@ -CountriesWithStates); - } - - /** - * Prepares states dropdown based on country selected - * - * @param kEvent $event - * @param string $state_field - * @param string $country_field - */ - function PopulateStates(&$event, $state_field, $country_field) - { - $object =& $event->getObject(); - $country_abbr = $object->GetDBField($country_field); - - if (!$country_abbr) return; - $country_id = $this->Conn->GetOne('SELECT DestId FROM '.TABLE_PREFIX.'StdDestinations WHERE DestType=1 AND DestAbbr = '.$this->Conn->qstr($country_abbr)); - if (!$country_id) return; - - $query = - 'SELECT p.Translation as DestName, sd.DestAbbr - FROM '.TABLE_PREFIX.'StdDestinations AS sd - LEFT JOIN '.TABLE_PREFIX.'Phrase AS p - ON p.Phrase = sd.DestName - WHERE - DestType=2 AND DestParentId='.$country_id.' - AND - LanguageId = '.$this->Application->GetVar('m_lang').' - ORDER BY Translation'; - - $states = $this->Conn->GetCol($query, 'DestAbbr'); - $object->Fields[$state_field]['options'] = $states; - $object->Fields[$state_field]['options'][''] = ''; - } - - /** - * Returns valid state code for state name and country code passed - * - * @param string $state_name - * @param string $country_code - * @return string - */ - function CheckState($state_name, $country_code) - { - if( !$this->CountryHasStates($country_code) ) return $state_name; - - $sql = 'SELECT sdStates.DestAbbr - FROM '.TABLE_PREFIX.'StdDestinations AS sdStates - LEFT JOIN '.TABLE_PREFIX.'Phrase AS p ON p.Phrase = sdStates.DestName - LEFT JOIN '.TABLE_PREFIX.'StdDestinations AS sdCountries ON sdStates.DestParentId = sdCountries.DestId - WHERE (sdStates.DestType = 2) AND - (sdStates.DestParentId = sdCountries.DestId) AND - (p.LanguageId = %1$s) AND - (sdCountries.DestAbbr = %2$s) AND - ( - (LOWER(sdStates.DestAbbr) = %3$s) OR (LOWER(sdStates.DestAbbr2) = %3$s) OR (LOWER(sdStates.DestName) = %3$s) OR (LOWER(p.Translation) = %3$s) - )'; - - $state_name = trim( strtolower($state_name) ); - $sql = sprintf($sql, $this->Application->GetVar('m_lang'), $this->Conn->qstr($country_code), $this->Conn->qstr($state_name) ); - - return $this->Conn->GetOne($sql); - } - - function CheckStateField(&$event, $state_field, $country_field) - { - - $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); - if($items_info) - { - list($id, $field_values) = each($items_info); - if( isset($field_values[$state_field]) && isset($field_values[$country_field]) ) - { - $user_state = getArrayValue($field_values,$state_field); - $valid_state = $this->CheckState($user_state, getArrayValue($field_values,$country_field) ); - if($valid_state !== false) - { - $field_values[$state_field] = $valid_state; - $items_info[$id] = $field_values; - $this->Application->SetVar( $event->getPrefixSpecial(true), $items_info); - } - else - { - $object =& $event->getObject(); - $object->Fields[$state_field]['options'][$user_state] = $user_state; - $object->SetError($state_field, 'invalid_state', 'la_invalid_state'); - } - } - } - } - } - -?> \ No newline at end of file