Пример #1
0
 /**
  * Get all the countries from database.
  *
  * The static array country is returned, and if it's
  * called the first time, the <b>Country DAO</b> is used
  * to get all the countries.
  *
  * Note: any database errors will be trapped by the DAO.
  *
  *
  * @param bool|int $id - Optional id to return
  *
  * @param bool $applyLimit
  *
  * @return array
  *   array reference of all countries.
  */
 public static function country($id = FALSE, $applyLimit = TRUE)
 {
     if ($id && !CRM_Utils_Array::value($id, self::$country) || !self::$country || !$id) {
         $config = CRM_Core_Config::singleton();
         $limitCodes = array();
         if ($applyLimit) {
             // limit the country list to the countries specified in CIVICRM_COUNTRY_LIMIT
             // (ensuring it's a subset of the legal values)
             // K/P: We need to fix this, i dont think it works with new setting files
             $limitCodes = CRM_Core_BAO_Country::countryLimit();
             if (!is_array($limitCodes)) {
                 $limitCodes = array($config->countryLimit => 1);
             }
             $limitCodes = array_intersect(self::countryIsoCode(), $limitCodes);
         }
         if (count($limitCodes)) {
             $whereClause = "iso_code IN ('" . implode("', '", $limitCodes) . "')";
         } else {
             $whereClause = NULL;
         }
         self::populate(self::$country, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active', $whereClause);
         // if default country is set, percolate it to the top
         if ($config->defaultContactCountry()) {
             $countryIsoCodes = self::countryIsoCode();
             $defaultID = array_search($config->defaultContactCountry(), $countryIsoCodes);
             if ($defaultID !== FALSE) {
                 $default[$defaultID] = CRM_Utils_Array::value($defaultID, self::$country);
                 self::$country = $default + self::$country;
             }
         }
         // localise the country names if in an non-en_US locale
         global $tsLocale;
         if ($tsLocale != '' and $tsLocale != 'en_US') {
             $i18n = CRM_Core_I18n::singleton();
             $i18n->localizeArray(self::$country, array('context' => 'country'));
             self::$country = CRM_Utils_Array::asort(self::$country);
         }
     }
     if ($id) {
         if (array_key_exists($id, self::$country)) {
             return self::$country[$id];
         } else {
             return CRM_Core_DAO::$_nullObject;
         }
     }
     return self::$country;
 }
Пример #2
0
 /**
  * @deprecated
  *
  * @param string $defaultCurrency
  *
  * @return string
  */
 public function defaultCurrencySymbol($defaultCurrency = NULL)
 {
     return CRM_Core_BAO_Country::defaultCurrencySymbol($defaultCurrency);
 }
Пример #3
0
 /**
  * Check if an error in Core( non-custom fields ) field
  *
  * @param array $params
  * @param string $errorMessage
  *   A string containing all the error-fields.
  */
 public function isErrorInCoreData($params, &$errorMessage)
 {
     foreach ($params as $key => $value) {
         if ($value) {
             $session = CRM_Core_Session::singleton();
             $dateType = $session->get("dateTypes");
             switch ($key) {
                 case 'birth_date':
                     if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
                         if (!CRM_Utils_Rule::date($params[$key])) {
                             self::addToErrorMsg(ts('Birth Date'), $errorMessage);
                         }
                     } else {
                         self::addToErrorMsg(ts('Birth-Date'), $errorMessage);
                     }
                     break;
                 case 'deceased_date':
                     if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
                         if (!CRM_Utils_Rule::date($params[$key])) {
                             self::addToErrorMsg(ts('Deceased Date'), $errorMessage);
                         }
                     } else {
                         self::addToErrorMsg(ts('Deceased Date'), $errorMessage);
                     }
                     break;
                 case 'is_deceased':
                     if (CRM_Utils_String::strtoboolstr($value) === FALSE) {
                         self::addToErrorMsg(ts('Deceased'), $errorMessage);
                     }
                     break;
                 case 'gender':
                 case 'gender_id':
                     if (!self::checkGender($value)) {
                         self::addToErrorMsg(ts('Gender'), $errorMessage);
                     }
                     break;
                 case 'preferred_communication_method':
                     $preffComm = array();
                     $preffComm = explode(',', $value);
                     foreach ($preffComm as $v) {
                         if (!self::in_value(trim($v), CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method'))) {
                             self::addToErrorMsg(ts('Preferred Communication Method'), $errorMessage);
                         }
                     }
                     break;
                 case 'preferred_mail_format':
                     if (!array_key_exists(strtolower($value), array_change_key_case(CRM_Core_SelectValues::pmf(), CASE_LOWER))) {
                         self::addToErrorMsg(ts('Preferred Mail Format'), $errorMessage);
                     }
                     break;
                 case 'individual_prefix':
                 case 'prefix_id':
                     if (!self::in_value($value, CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id'))) {
                         self::addToErrorMsg(ts('Individual Prefix'), $errorMessage);
                     }
                     break;
                 case 'individual_suffix':
                 case 'suffix_id':
                     if (!self::in_value($value, CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id'))) {
                         self::addToErrorMsg(ts('Individual Suffix'), $errorMessage);
                     }
                     break;
                 case 'state_province':
                     if (!empty($value)) {
                         foreach ($value as $stateValue) {
                             if ($stateValue['state_province']) {
                                 if (self::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvinceAbbreviation()) || self::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvince())) {
                                     continue;
                                 } else {
                                     self::addToErrorMsg(ts('State/Province'), $errorMessage);
                                 }
                             }
                         }
                     }
                     break;
                 case 'country':
                     if (!empty($value)) {
                         foreach ($value as $stateValue) {
                             if ($stateValue['country']) {
                                 CRM_Core_PseudoConstant::populate($countryNames, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active');
                                 CRM_Core_PseudoConstant::populate($countryIsoCodes, 'CRM_Core_DAO_Country', TRUE, 'iso_code');
                                 $limitCodes = CRM_Core_BAO_Country::countryLimit();
                                 //If no country is selected in
                                 //localization then take all countries
                                 if (empty($limitCodes)) {
                                     $limitCodes = $countryIsoCodes;
                                 }
                                 if (self::in_value($stateValue['country'], $limitCodes) || self::in_value($stateValue['country'], CRM_Core_PseudoConstant::country())) {
                                     continue;
                                 } else {
                                     if (self::in_value($stateValue['country'], $countryIsoCodes) || self::in_value($stateValue['country'], $countryNames)) {
                                         self::addToErrorMsg(ts('Country input value is in table but not "available": "This Country is valid but is NOT in the list of Available Countries currently configured for your site. This can be viewed and modifed from Administer > Localization > Languages Currency Locations." '), $errorMessage);
                                     } else {
                                         self::addToErrorMsg(ts('Country input value not in country table: "The Country value appears to be invalid. It does not match any value in CiviCRM table of countries."'), $errorMessage);
                                     }
                                 }
                             }
                         }
                     }
                     break;
                 case 'county':
                     if (!empty($value)) {
                         foreach ($value as $county) {
                             if ($county['county']) {
                                 $countyNames = CRM_Core_PseudoConstant::county();
                                 if (!empty($county['county']) && !in_array($county['county'], $countyNames)) {
                                     self::addToErrorMsg(ts('County input value not in county table: The County value appears to be invalid. It does not match any value in CiviCRM table of counties.'), $errorMessage);
                                 }
                             }
                         }
                     }
                     break;
                 case 'geo_code_1':
                     if (!empty($value)) {
                         foreach ($value as $codeValue) {
                             if (!empty($codeValue['geo_code_1'])) {
                                 if (CRM_Utils_Rule::numeric($codeValue['geo_code_1'])) {
                                     continue;
                                 } else {
                                     self::addToErrorMsg(ts('Geo code 1'), $errorMessage);
                                 }
                             }
                         }
                     }
                     break;
                 case 'geo_code_2':
                     if (!empty($value)) {
                         foreach ($value as $codeValue) {
                             if (!empty($codeValue['geo_code_2'])) {
                                 if (CRM_Utils_Rule::numeric($codeValue['geo_code_2'])) {
                                     continue;
                                 } else {
                                     self::addToErrorMsg(ts('Geo code 2'), $errorMessage);
                                 }
                             }
                         }
                     }
                     break;
                     //check for any error in email/postal greeting, addressee,
                     //custom email/postal greeting, custom addressee, CRM-4575
                 //check for any error in email/postal greeting, addressee,
                 //custom email/postal greeting, custom addressee, CRM-4575
                 case 'email_greeting':
                     $emailGreetingFilter = array('contact_type' => $this->_contactType, 'greeting_type' => 'email_greeting');
                     if (!self::in_value($value, CRM_Core_PseudoConstant::greeting($emailGreetingFilter))) {
                         self::addToErrorMsg(ts('Email Greeting must be one of the configured format options. Check Administer >> System Settings >> Option Groups >> Email Greetings for valid values'), $errorMessage);
                     }
                     break;
                 case 'postal_greeting':
                     $postalGreetingFilter = array('contact_type' => $this->_contactType, 'greeting_type' => 'postal_greeting');
                     if (!self::in_value($value, CRM_Core_PseudoConstant::greeting($postalGreetingFilter))) {
                         self::addToErrorMsg(ts('Postal Greeting must be one of the configured format options. Check Administer >> System Settings >> Option Groups >> Postal Greetings for valid values'), $errorMessage);
                     }
                     break;
                 case 'addressee':
                     $addresseeFilter = array('contact_type' => $this->_contactType, 'greeting_type' => 'addressee');
                     if (!self::in_value($value, CRM_Core_PseudoConstant::greeting($addresseeFilter))) {
                         self::addToErrorMsg(ts('Addressee must be one of the configured format options. Check Administer >> System Settings >> Option Groups >> Addressee for valid values'), $errorMessage);
                     }
                     break;
                 case 'email_greeting_custom':
                     if (array_key_exists('email_greeting', $params)) {
                         $emailGreetingLabel = key(CRM_Core_OptionGroup::values('email_greeting', TRUE, NULL, NULL, 'AND v.name = "Customized"'));
                         if (CRM_Utils_Array::value('email_greeting', $params) != $emailGreetingLabel) {
                             self::addToErrorMsg(ts('Email Greeting - Custom'), $errorMessage);
                         }
                     }
                     break;
                 case 'postal_greeting_custom':
                     if (array_key_exists('postal_greeting', $params)) {
                         $postalGreetingLabel = key(CRM_Core_OptionGroup::values('postal_greeting', TRUE, NULL, NULL, 'AND v.name = "Customized"'));
                         if (CRM_Utils_Array::value('postal_greeting', $params) != $postalGreetingLabel) {
                             self::addToErrorMsg(ts('Postal Greeting - Custom'), $errorMessage);
                         }
                     }
                     break;
                 case 'addressee_custom':
                     if (array_key_exists('addressee', $params)) {
                         $addresseeLabel = key(CRM_Core_OptionGroup::values('addressee', TRUE, NULL, NULL, 'AND v.name = "Customized"'));
                         if (CRM_Utils_Array::value('addressee', $params) != $addresseeLabel) {
                             self::addToErrorMsg(ts('Addressee - Custom'), $errorMessage);
                         }
                     }
                     break;
                 case 'url':
                     if (is_array($value)) {
                         foreach ($value as $values) {
                             if (!empty($values['url']) && !CRM_Utils_Rule::url($values['url'])) {
                                 self::addToErrorMsg(ts('Website'), $errorMessage);
                                 break;
                             }
                         }
                     }
                     break;
                 case 'do_not_email':
                 case 'do_not_phone':
                 case 'do_not_mail':
                 case 'do_not_sms':
                 case 'do_not_trade':
                     if (CRM_Utils_Rule::boolean($value) == FALSE) {
                         $key = ucwords(str_replace("_", " ", $key));
                         self::addToErrorMsg($key, $errorMessage);
                     }
                     break;
                 case 'email':
                     if (is_array($value)) {
                         foreach ($value as $values) {
                             if (!empty($values['email']) && !CRM_Utils_Rule::email($values['email'])) {
                                 self::addToErrorMsg($key, $errorMessage);
                                 break;
                             }
                         }
                     }
                     break;
                 default:
                     if (is_array($params[$key]) && isset($params[$key]["contact_type"])) {
                         //check for any relationship data ,FIX ME
                         self::isErrorInCoreData($params[$key], $errorMessage);
                     }
             }
         }
     }
 }