Esempio n. 1
0
 /**
  * Do AlterDisplay processing on Address Fields.
  *
  * @param array $row
  * @param array $rows
  * @param int $rowNum
  * @param string $baseUrl
  * @param string $linkText
  *
  * @return bool
  */
 public function alterDisplayAddressFields(&$row, &$rows, &$rowNum, $baseUrl, $linkText)
 {
     $criteriaQueryParams = CRM_Report_Utils_Report::getPreviewCriteriaQueryParams($this->_defaults, $this->_params);
     $entryFound = FALSE;
     // handle country
     if (array_key_exists('civicrm_address_country_id', $row)) {
         if ($value = $row['civicrm_address_country_id']) {
             $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value, FALSE);
             if ($baseUrl) {
                 $url = CRM_Report_Utils_Report::getNextUrl($baseUrl, "reset=1&force=1&{$criteriaQueryParams}&" . "country_id_op=in&country_id_value={$value}", $this->_absoluteUrl, $this->_id);
                 $rows[$rowNum]['civicrm_address_country_id_link'] = $url;
                 $rows[$rowNum]['civicrm_address_country_id_hover'] = ts("%1 for this country.", array(1 => $linkText));
             }
         }
         $entryFound = TRUE;
     }
     if (array_key_exists('civicrm_address_county_id', $row)) {
         if ($value = $row['civicrm_address_county_id']) {
             $rows[$rowNum]['civicrm_address_county_id'] = CRM_Core_PseudoConstant::county($value, FALSE);
             if ($baseUrl) {
                 $url = CRM_Report_Utils_Report::getNextUrl($baseUrl, "reset=1&force=1&{$criteriaQueryParams}&" . "county_id_op=in&county_id_value={$value}", $this->_absoluteUrl, $this->_id);
                 $rows[$rowNum]['civicrm_address_county_id_link'] = $url;
                 $rows[$rowNum]['civicrm_address_county_id_hover'] = ts("%1 for this county.", array(1 => $linkText));
             }
         }
         $entryFound = TRUE;
     }
     // handle state province
     if (array_key_exists('civicrm_address_state_province_id', $row)) {
         if ($value = $row['civicrm_address_state_province_id']) {
             $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value, FALSE);
             if ($baseUrl) {
                 $url = CRM_Report_Utils_Report::getNextUrl($baseUrl, "reset=1&force=1&{$criteriaQueryParams}&state_province_id_op=in&state_province_id_value={$value}", $this->_absoluteUrl, $this->_id);
                 $rows[$rowNum]['civicrm_address_state_province_id_link'] = $url;
                 $rows[$rowNum]['civicrm_address_state_province_id_hover'] = ts("%1 for this state.", array(1 => $linkText));
             }
         }
         $entryFound = TRUE;
     }
     return $entryFound;
 }
Esempio n. 2
0
 /**
  * Get the values for pseudoconstants for name->value and reverse.
  *
  * @param array $defaults
  *   (reference) the default values, some of which need to be resolved.
  * @param bool $reverse
  *   True if we want to resolve the values in the reverse direction (value -> name).
  */
 public static function resolveDefaults(&$defaults, $reverse = FALSE)
 {
     // Hack for birth_date.
     if (!empty($defaults['birth_date'])) {
         if (is_array($defaults['birth_date'])) {
             $defaults['birth_date'] = CRM_Utils_Date::format($defaults['birth_date'], '-');
         }
     }
     CRM_Utils_Array::lookupValue($defaults, 'prefix', CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id'), $reverse);
     CRM_Utils_Array::lookupValue($defaults, 'suffix', CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id'), $reverse);
     CRM_Utils_Array::lookupValue($defaults, 'gender', CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'), $reverse);
     CRM_Utils_Array::lookupValue($defaults, 'communication_style', CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'communication_style_id'), $reverse);
     //lookup value of email/postal greeting, addressee, CRM-4575
     foreach (self::$_greetingTypes as $greeting) {
         $filterCondition = array('contact_type' => CRM_Utils_Array::value('contact_type', $defaults), 'greeting_type' => $greeting);
         CRM_Utils_Array::lookupValue($defaults, $greeting, CRM_Core_PseudoConstant::greeting($filterCondition), $reverse);
     }
     $blocks = array('address', 'im', 'phone');
     foreach ($blocks as $name) {
         if (!array_key_exists($name, $defaults) || !is_array($defaults[$name])) {
             continue;
         }
         foreach ($defaults[$name] as $count => &$values) {
             //get location type id.
             CRM_Utils_Array::lookupValue($values, 'location_type', CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'), $reverse);
             if ($name == 'address') {
                 // FIXME: lookupValue doesn't work for vcard_name
                 if (!empty($values['location_type_id'])) {
                     $vcardNames = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'vcard_name'));
                     $values['vcard_name'] = $vcardNames[$values['location_type_id']];
                 }
                 if (!CRM_Utils_Array::lookupValue($values, 'country', CRM_Core_PseudoConstant::country(), $reverse) && $reverse) {
                     CRM_Utils_Array::lookupValue($values, 'country', CRM_Core_PseudoConstant::countryIsoCode(), $reverse);
                 }
                 // CRM-7597
                 // if we find a country id above, we need to restrict it to that country
                 // rather than the list of all countries
                 if (!empty($values['country_id'])) {
                     $stateProvinceList = CRM_Core_PseudoConstant::stateProvinceForCountry($values['country_id']);
                 } else {
                     $stateProvinceList = CRM_Core_PseudoConstant::stateProvince();
                 }
                 if (!CRM_Utils_Array::lookupValue($values, 'state_province', $stateProvinceList, $reverse) && $reverse) {
                     if (!empty($values['country_id'])) {
                         $stateProvinceList = CRM_Core_PseudoConstant::stateProvinceForCountry($values['country_id'], 'abbreviation');
                     } else {
                         $stateProvinceList = CRM_Core_PseudoConstant::stateProvinceAbbreviation();
                     }
                     CRM_Utils_Array::lookupValue($values, 'state_province', $stateProvinceList, $reverse);
                 }
                 if (!empty($values['state_province_id'])) {
                     $countyList = CRM_Core_PseudoConstant::countyForState($values['state_province_id']);
                 } else {
                     $countyList = CRM_Core_PseudoConstant::county();
                 }
                 CRM_Utils_Array::lookupValue($values, 'county', $countyList, $reverse);
             }
             if ($name == 'im') {
                 CRM_Utils_Array::lookupValue($values, 'provider', CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $reverse);
             }
             if ($name == 'phone') {
                 CRM_Utils_Array::lookupValue($values, 'phone_type', CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'), $reverse);
             }
             // Kill the reference.
             unset($values);
         }
     }
 }
Esempio n. 3
0
 /**
  * Build qill for field.
  *
  * Qill refers to the query detail visible on the UI.
  *
  * @param string $daoName
  * @param string $fieldName
  * @param mixed $fieldValue
  * @param string $op
  * @param array $pseudoExtraParam
  * @param int $type
  *   Type of the field per CRM_Utils_Type
  *
  * @return array
  */
 public static function buildQillForFieldValue($daoName, $fieldName, $fieldValue, $op, $pseudoExtraParam = array(), $type = CRM_Utils_Type::T_STRING)
 {
     $qillOperators = CRM_Core_SelectValues::getSearchBuilderOperators();
     // if Operator chosen is NULL/EMPTY then
     if (strpos($op, 'NULL') !== FALSE || strpos($op, 'EMPTY') !== FALSE) {
         return array(CRM_Utils_Array::value($op, $qillOperators, $op), '');
     }
     if ($fieldName == 'activity_type_id') {
         $pseudoOptions = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE);
     } elseif ($fieldName == 'country_id') {
         $pseduoOptions = CRM_Core_PseudoConstant::country();
     } elseif ($fieldName == 'county_id') {
         $pseduoOptions = CRM_Core_PseudoConstant::county();
     } elseif ($fieldName == 'world_region') {
         $pseduoOptions = CRM_Core_PseudoConstant::worldRegion();
     } elseif ($daoName == 'CRM_Event_DAO_Event' && $fieldName == 'id') {
         $pseudoOptions = CRM_Event_BAO_Event::getEvents(0, $fieldValue, TRUE, TRUE, TRUE);
     } elseif ($fieldName == 'contribution_product_id') {
         $pseudoOptions = CRM_Contribute_PseudoConstant::products();
     } elseif ($daoName == 'CRM_Contact_DAO_Group' && $fieldName == 'id') {
         $pseudoOptions = CRM_Core_PseudoConstant::group();
     } elseif ($fieldName == 'country_id') {
         $pseudoOptions = CRM_Core_PseudoConstant::country();
     } elseif ($daoName) {
         $pseudoOptions = CRM_Core_PseudoConstant::get($daoName, $fieldName, $pseudoExtraParam);
     }
     //API usually have fieldValue format as array(operator => array(values)),
     //so we need to separate operator out of fieldValue param
     if (is_array($fieldValue) && in_array(key($fieldValue), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) {
         $op = key($fieldValue);
         $fieldValue = $fieldValue[$op];
     }
     if (is_array($fieldValue)) {
         $qillString = array();
         if (!empty($pseudoOptions)) {
             foreach ((array) $fieldValue as $val) {
                 $qillString[] = CRM_Utils_Array::value($val, $pseudoOptions, $val);
             }
             $fieldValue = implode(', ', $qillString);
         } else {
             if ($type == CRM_Utils_Type::T_DATE) {
                 foreach ($fieldValue as $index => $value) {
                     $fieldValue[$index] = CRM_Utils_Date::customFormat($value);
                 }
             }
             $separator = ', ';
             // @todo - this is a bit specific (one operator).
             // However it is covered by a unit test so can be altered later with
             // some confidence.
             if ($op == 'BETWEEN') {
                 $separator = ' AND ';
             }
             $fieldValue = implode($separator, $fieldValue);
         }
     } elseif (!empty($pseudoOptions) && array_key_exists($fieldValue, $pseudoOptions)) {
         $fieldValue = $pseudoOptions[$fieldValue];
     } elseif ($type === CRM_Utils_Type::T_DATE) {
         $fieldValue = CRM_Utils_Date::customFormat($fieldValue);
     }
     return array(CRM_Utils_Array::value($op, $qillOperators, $op), $fieldValue);
 }
Esempio n. 4
0
 /**
  * check for correct state / country mapping.
  *
  * @param array reference $fields - submitted form values.
  * @param array reference $errors - if any errors found add to this array. please.
  * @return true if no errors
  *         array of errors if any present.
  *
  * @access public
  * @static
  */
 static function formRule($fields, $errors)
 {
     $errors = array();
     // check for state/county match if not report error to user.
     if (is_array($fields['address'])) {
         foreach ($fields['address'] as $instance => $addressValues) {
             if (CRM_Utils_System::isNull($addressValues)) {
                 continue;
             }
             if ($countryId = CRM_Utils_Array::value('country_id', $addressValues)) {
                 if (!array_key_exists($countryId, CRM_Core_PseudoConstant::country())) {
                     $countryId = null;
                     $errors["address[{$instance}][country_id]"] = ts('Enter a valid country name.');
                 }
             }
             if ($stateProvinceId = CRM_Utils_Array::value('state_province_id', $addressValues)) {
                 // hack to skip  - type first letter(s) - for state_province
                 // CRM-2649
                 if ($stateProvinceId != ts('- type first letter(s) -')) {
                     if (!array_key_exists($stateProvinceId, CRM_Core_PseudoConstant::stateProvince(false, false))) {
                         $stateProvinceId = null;
                         $errors["address[{$instance}][state_province_id]"] = ts('Please select a valid State/Province name.');
                     }
                 }
             }
             //do check for mismatch countries
             if ($stateProvinceId && $countryId) {
                 $stateProvinceDAO = new CRM_Core_DAO_StateProvince();
                 $stateProvinceDAO->id = $stateProvinceId;
                 $stateProvinceDAO->find(true);
                 if ($stateProvinceDAO->country_id != $countryId) {
                     // countries mismatch hence display error
                     $stateProvinces = CRM_Core_PseudoConstant::stateProvince();
                     $countries =& CRM_Core_PseudoConstant::country();
                     $errors["address[{$instance}][state_province_id]"] = ts('State/Province %1 is not part of %2. It belongs to %3.', array(1 => $stateProvinces[$stateProvinceId], 2 => $countries[$countryId], 3 => $countries[$stateProvinceDAO->country_id]));
                 }
             }
             $countyId = CRM_Utils_Array::value('county_id', $addressValues);
             //state county validation
             if ($stateProvinceId && $countyId) {
                 $countyDAO = new CRM_Core_DAO_County();
                 $countyDAO->id = $countyId;
                 $countyDAO->find(true);
                 if ($countyDAO->state_province_id != $stateProvinceId) {
                     $counties =& CRM_Core_PseudoConstant::county();
                     $errors["address[{$instance}][county_id]"] = ts('County %1 is not part of %2. It belongs to %3.', array(1 => $counties[$countyId], 2 => $stateProvinces[$stateProvinceId], 3 => $stateProvinces[$countyDAO->state_province_id]));
                 }
             }
             if (CRM_Utils_Array::value('use_shared_address', $addressValues) && !CRM_Utils_Array::value('master_id', $addressValues)) {
                 $errors["address[{$instance}][use_shared_address]"] = ts('Please select valid shared contact or a contact with valid address.');
             }
         }
     }
     return empty($errors) ? true : $errors;
 }
Esempio n. 5
0
 /**
  * Global form rule.
  *
  * @param array $fields
  *   The input form values.
  * @param array $files
  *   The uploaded files if any.
  * @param CRM_Core_Form $form
  *   The form object.
  *
  * @return bool|array
  *   true if no errors, else array of errors
  */
 public static function formRule($fields, $files, $form)
 {
     CRM_Utils_Hook::validateProfile($form->_ufGroup['name']);
     $errors = array();
     // if no values, return
     if (empty($fields)) {
         return TRUE;
     }
     $register = NULL;
     // hack we use a -1 in options to indicate that its registration
     if ($form->_id) {
         $form->_isUpdateDupe = 1;
     }
     if ($form->_mode == CRM_Profile_Form::MODE_REGISTER) {
         $register = TRUE;
     }
     // dont check for duplicates during registration validation: CRM-375
     if (!$register && empty($fields['_qf_Edit_upload_duplicate'])) {
         // fix for CRM-3240
         if (!empty($fields['email-Primary'])) {
             $fields['email'] = CRM_Utils_Array::value('email-Primary', $fields);
         }
         // fix for CRM-6141
         if (!empty($fields['phone-Primary-1']) && empty($fields['phone-Primary'])) {
             $fields['phone-Primary'] = $fields['phone-Primary-1'];
         }
         $ctype = CRM_Core_BAO_UFGroup::getContactType($form->_gid);
         // If all profile fields is of Contact Type then consider
         // profile is of Individual type(default).
         if (!$ctype) {
             $ctype = 'Individual';
         }
         $dedupeParams = CRM_Dedupe_Finder::formatParams($fields, $ctype);
         if ($form->_mode == CRM_Profile_Form::MODE_CREATE) {
             // fix for CRM-2888
             $exceptions = array();
         } else {
             // for edit mode we need to allow our own record to be a dupe match!
             $exceptions = array($form->_session->get('userID'));
         }
         // for dialog mode we should always use fuzzy rule.
         $ruleType = 'Unsupervised';
         if ($form->_context == 'dialog') {
             $ruleType = 'Supervised';
         }
         $dedupeParams['check_permission'] = FALSE;
         $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $ctype, $ruleType, $exceptions, $form->_ruleGroupID);
         if ($ids) {
             if ($form->_isUpdateDupe == 2) {
                 CRM_Core_Session::setStatus(ts('Note: this contact may be a duplicate of an existing record.'), ts('Possible Duplicate Detected'), 'alert');
             } elseif ($form->_isUpdateDupe == 1) {
                 if (!$form->_id) {
                     $form->_id = $ids[0];
                 }
             } else {
                 if ($form->_context == 'dialog') {
                     $contactLinks = CRM_Contact_BAO_Contact_Utils::formatContactIDSToLinks($ids, TRUE, TRUE);
                     $duplicateContactsLinks = '<div class="matching-contacts-found">';
                     $duplicateContactsLinks .= ts('One matching contact was found. ', array('count' => count($contactLinks['rows']), 'plural' => '%count matching contacts were found.<br />'));
                     if ($contactLinks['msg'] == 'view') {
                         $duplicateContactsLinks .= ts('You can View the existing contact.', array('count' => count($contactLinks['rows']), 'plural' => 'You can View the existing contacts.'));
                     } else {
                         $duplicateContactsLinks .= ts('You can View or Edit the existing contact.', array('count' => count($contactLinks['rows']), 'plural' => 'You can View or Edit the existing contacts.'));
                     }
                     $duplicateContactsLinks .= '</div>';
                     $duplicateContactsLinks .= '<table class="matching-contacts-actions">';
                     $row = '';
                     for ($i = 0; $i < count($contactLinks['rows']); $i++) {
                         $row .= '  <tr>   ';
                         $row .= '    <td class="matching-contacts-name"> ';
                         $row .= $contactLinks['rows'][$i]['display_name'];
                         $row .= '    </td>';
                         $row .= '    <td class="matching-contacts-email"> ';
                         $row .= $contactLinks['rows'][$i]['primary_email'];
                         $row .= '    </td>';
                         $row .= '    <td class="action-items"> ';
                         $row .= $contactLinks['rows'][$i]['view'] . ' ';
                         $row .= $contactLinks['rows'][$i]['edit'];
                         $row .= '    </td>';
                         $row .= '  </tr>   ';
                     }
                     $duplicateContactsLinks .= $row . '</table>';
                     $duplicateContactsLinks .= "If you're sure this record is not a duplicate, click the 'Save Matching Contact' button below.";
                     $errors['_qf_default'] = $duplicateContactsLinks;
                     // let smarty know that there are duplicates
                     $template = CRM_Core_Smarty::singleton();
                     $template->assign('isDuplicate', 1);
                 } else {
                     $errors['_qf_default'] = ts('A record already exists with the same information.');
                 }
             }
         }
     }
     foreach ($fields as $key => $value) {
         list($fieldName, $locTypeId, $phoneTypeId) = CRM_Utils_System::explode('-', $key, 3);
         if ($fieldName == 'state_province' && !empty($fields["country-{$locTypeId}"])) {
             // Validate Country - State list
             $countryId = $fields["country-{$locTypeId}"];
             $stateProvinceId = $value;
             if ($stateProvinceId && $countryId) {
                 $stateProvinceDAO = new CRM_Core_DAO_StateProvince();
                 $stateProvinceDAO->id = $stateProvinceId;
                 $stateProvinceDAO->find(TRUE);
                 if ($stateProvinceDAO->country_id != $countryId) {
                     // country mismatch hence display error
                     $stateProvinces = CRM_Core_PseudoConstant::stateProvince();
                     $countries = CRM_Core_PseudoConstant::country();
                     $errors[$key] = "State/Province " . $stateProvinces[$stateProvinceId] . " is not part of " . $countries[$countryId] . ". It belongs to " . $countries[$stateProvinceDAO->country_id] . ".";
                 }
             }
         }
         if ($fieldName == 'county' && $fields["state_province-{$locTypeId}"]) {
             // Validate County - State list
             $stateProvinceId = $fields["state_province-{$locTypeId}"];
             $countyId = $value;
             if ($countyId && $stateProvinceId) {
                 $countyDAO = new CRM_Core_DAO_County();
                 $countyDAO->id = $countyId;
                 $countyDAO->find(TRUE);
                 if ($countyDAO->state_province_id != $stateProvinceId) {
                     // state province mismatch hence display error
                     $stateProvinces = CRM_Core_PseudoConstant::stateProvince();
                     $counties = CRM_Core_PseudoConstant::county();
                     $errors[$key] = "County " . $counties[$countyId] . " is not part of " . $stateProvinces[$stateProvinceId] . ". It belongs to " . $stateProvinces[$countyDAO->state_province_id] . ".";
                 }
             }
         }
     }
     foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
         if ($greetingType = CRM_Utils_Array::value($greeting, $fields)) {
             $customizedValue = CRM_Core_OptionGroup::getValue($greeting, 'Customized', 'name');
             if ($customizedValue == $greetingType && empty($fields[$greeting . '_custom'])) {
                 $errors[$greeting . '_custom'] = ts('Custom  %1 is a required field if %1 is of type Customized.', array(1 => ucwords(str_replace('_', ' ', $greeting))));
             }
         }
     }
     return empty($errors) ? TRUE : $errors;
 }
Esempio n. 6
0
 static function fixStateSelect(&$form, $countryElementName, $stateElementName, $countyElementName, $countryDefaultValue, $stateDefaultValue = NULL)
 {
     $countryID = $stateID = NULL;
     if (isset($form->_elementIndex[$countryElementName])) {
         //get the country id to load states -
         //first check for submitted value,
         //then check for user passed value.
         //finally check for element default val.
         $submittedVal = $form->getSubmitValue($countryElementName);
         if ($submittedVal) {
             $countryID = $submittedVal;
         } elseif ($countryDefaultValue) {
             $countryID = $countryDefaultValue;
         } else {
             $countryID = CRM_Utils_Array::value(0, $form->getElementValue($countryElementName));
         }
     }
     $stateTitle = ts('State/Province');
     if (isset($form->_fields[$stateElementName]['title'])) {
         $stateTitle = $form->_fields[$stateElementName]['title'];
     }
     if (isset($form->_elementIndex[$stateElementName])) {
         $submittedValState = $form->getSubmitValue($stateElementName);
         if ($submittedValState) {
             $stateID = $submittedValState;
         } elseif ($stateDefaultValue) {
             $stateID = $stateDefaultValue;
         } else {
             $stateID = CRM_Utils_Array::value(0, $form->getElementValue($stateElementName));
         }
     }
     if (isset($form->_elementIndex[$stateElementName])) {
         if ($countryID) {
             $stateProvinces = CRM_Core_PseudoConstant::stateProvinceForCountry($countryID);
         } else {
             $stateProvinces = CRM_Core_PseudoConstant::stateProvince();
         }
         $stateSelect =& $form->addElement('select', $stateElementName, $stateTitle, array('' => ts('- select -')) + $stateProvinces);
     }
     if (isset($form->_elementIndex[$stateElementName]) && isset($form->_elementIndex[$countyElementName])) {
         if ($stateID) {
             $counties = CRM_Core_PseudoConstant::countyForState($stateID);
         } else {
             $counties = CRM_Core_PseudoConstant::county();
         }
         $form->addElement('select', $countyElementName, ts('County'), array('' => ts('- select -')) + $counties);
     }
     // CRM-7296 freeze the select for state if address is shared with household
     // CRM-9070 freeze the select for state if it is view only
     if (isset($form->_fields) && !empty($form->_fields[$stateElementName]) && (!empty($form->_fields[$stateElementName]['is_shared']) || !empty($form->_fields[$stateElementName]['is_view']))) {
         $stateSelect->freeze();
     }
 }
Esempio n. 7
0
 function alterCountyID($value, &$row, $selectedfield, $criteriaFieldName)
 {
     $url = CRM_Utils_System::url(CRM_Utils_System::currentPath(), "reset=1&force=1&{$criteriaFieldName}_op=in&{$criteriaFieldName}_value={$value}", $this->_absoluteUrl);
     $row[$selectedfield . '_link'] = $url;
     $row[$selectedfield . '_hover'] = ts("%1 for this county.", array(1 => $value));
     $counties = CRM_Core_PseudoConstant::county($value, FALSE);
     if (!is_array($counties)) {
         return $counties;
     }
 }
Esempio n. 8
0
 /**
  * global form rule
  *
  * @param array  $fields the input form values
  * @param array  $files  the uploaded files if any
  * @param object $form   the form object
  *
  * @return true if no errors, else array of errors
  * @access public
  * @static
  */
 static function formRule(&$fields, &$files, &$form)
 {
     $errors = array();
     // if no values, return
     if (empty($fields)) {
         return true;
     }
     $cid = $register = null;
     // hack we use a -1 in options to indicate that its registration
     if ($form->_id) {
         $cid = $form->_id;
         $form->_isUpdateDupe = true;
     }
     if ($form->_mode == CRM_Profile_Form::MODE_REGISTER) {
         $register = true;
     }
     // dont check for duplicates during registration validation: CRM-375
     if (!$register && !CRM_Utils_Array::value('_qf_Edit_upload_duplicate', $fields)) {
         // fix for CRM-3240
         if (CRM_Utils_Array::value('email-Primary', $fields)) {
             $fields['email'] = CRM_Utils_Array::value('email-Primary', $fields);
         }
         $session =& CRM_Core_Session::singleton();
         $ctype = CRM_Core_BAO_UFGroup::getContactType($form->_gid);
         require_once 'CRM/Dedupe/Finder.php';
         $dedupeParams = CRM_Dedupe_Finder::formatParams($fields, $ctype);
         if ($form->_mode == CRM_Profile_Form::MODE_CREATE) {
             // fix for CRM-2888
             $exceptions = array();
         } else {
             // for edit mode we need to allow our own record to be a dupe match!
             $exceptions = array($session->get('userID'));
         }
         // for dialog mode we should always use fuzzy rule.
         $ruleType = 'Strict';
         if ($form->_context == 'dialog') {
             $ruleType = 'Fuzzy';
         }
         $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $ctype, $ruleType, $exceptions);
         if ($ids) {
             if ($form->_isUpdateDupe) {
                 if (!$form->_id) {
                     $form->_id = $ids[0];
                 }
             } else {
                 if ($form->_context == 'dialog') {
                     $viewUrls = array();
                     require_once 'CRM/Contact/BAO/Contact/Utils.php';
                     list($viewUrls) = CRM_Contact_BAO_Contact_Utils::formatContactIDSToLinks($ids);
                     $viewUrl = implode(', ', $viewUrls);
                     $errors['_qf_default'] = ts('One matching contact was found.', array('count' => count($viewUrls), 'plural' => '%count matching contacts were found.'));
                     $errors['_qf_default'] .= '<br />';
                     $errors['_qf_default'] .= ts('If you need to verify if this is the same contact, click here - %1 - to VIEW the existing contact in a new tab.', array(1 => $viewUrl, 'count' => count($viewUrls), 'plural' => 'If you need to verify whether one of these is the same contact, click here - %1 - to VIEW the existing contact in a new tab.'));
                     $errors['_qf_default'] .= '<br />';
                     $errors['_qf_default'] .= ts('If you are sure this is NOT a duplicate, click the Save Matching Contact button to create a new contact record.');
                     // let smarty know that there are duplicates
                     $template =& CRM_Core_Smarty::singleton();
                     $template->assign('isDuplicate', 1);
                 } else {
                     $errors['_qf_default'] = ts('A record already exists with the same information.');
                 }
             }
         }
     }
     foreach ($fields as $key => $value) {
         list($fieldName, $locTypeId, $phoneTypeId) = CRM_Utils_System::explode('-', $key, 3);
         if ($fieldName == 'state_province' && $fields["country-{$locTypeId}"]) {
             // Validate Country - State list
             $countryId = $fields["country-{$locTypeId}"];
             $stateProvinceId = $value;
             if ($stateProvinceId && $countryId) {
                 $stateProvinceDAO =& new CRM_Core_DAO_StateProvince();
                 $stateProvinceDAO->id = $stateProvinceId;
                 $stateProvinceDAO->find(true);
                 if ($stateProvinceDAO->country_id != $countryId) {
                     // country mismatch hence display error
                     $stateProvinces = CRM_Core_PseudoConstant::stateProvince();
                     $countries =& CRM_Core_PseudoConstant::country();
                     $errors[$key] = "State/Province " . $stateProvinces[$stateProvinceId] . " is not part of " . $countries[$countryId] . ". It belongs to " . $countries[$stateProvinceDAO->country_id] . ".";
                 }
             }
         }
         if ($fieldName == 'county' && $fields["state_province-{$locTypeId}"]) {
             // Validate County - State list
             $stateProvinceId = $fields["state_province-{$locTypeId}"];
             $countyId = $value;
             if ($countyId && $stateProvinceId) {
                 $countyDAO =& new CRM_Core_DAO_County();
                 $countyDAO->id = $countyId;
                 $countyDAO->find(true);
                 if ($countyDAO->state_province_id != $stateProvinceId) {
                     // state province mismatch hence display error
                     $stateProvinces = CRM_Core_PseudoConstant::stateProvince();
                     $counties =& CRM_Core_PseudoConstant::county();
                     $errors[$key] = "County " . $counties[$countyId] . " is not part of " . $stateProvinces[$stateProvinceId] . ". It belongs to " . $stateProvinces[$countyDAO->state_province_id] . ".";
                 }
             }
         }
     }
     $elements = array('email_greeting' => 'email_greeting_custom', 'postal_greeting' => 'postal_greeting_custom', 'addressee' => 'addressee_custom');
     foreach ($elements as $greeting => $customizedGreeting) {
         if ($greetingType = CRM_Utils_Array::value($greeting, $fields)) {
             $customizedValue = CRM_Core_OptionGroup::getValue($greeting, 'Customized', 'name');
             if ($customizedValue == $greetingType && !CRM_Utils_Array::value($customizedGreeting, $fields)) {
                 $errors[$customizedGreeting] = ts('Custom  %1 is a required field if %1 is of type Customized.', array(1 => ucwords(str_replace('_', " ", $greeting))));
             }
         }
     }
     return empty($errors) ? true : $errors;
 }
Esempio n. 9
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('Is 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');
                                 $config = CRM_Core_Config::singleton();
                                 $limitCodes = $config->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);
                     }
             }
         }
     }
 }
Esempio n. 10
0
 /**
  *
  * Get the values for pseudoconstants for name->value and reverse.
  *
  * @param array   $defaults (reference) the default values, some of which need to be resolved.
  * @param boolean $reverse  true if we want to resolve the values in the reverse direction (value -> name)
  *
  * @return none
  * @access public
  * @static
  */
 static function resolveDefaults(&$defaults, $reverse = false)
 {
     // hack for birth_date
     if (CRM_Utils_Array::value('birth_date', $defaults)) {
         if (is_array($defaults['birth_date'])) {
             $defaults['birth_date'] = CRM_Utils_Date::format($defaults['birth_date'], '-');
         }
     }
     CRM_Utils_Array::lookupValue($defaults, 'prefix', CRM_Core_PseudoConstant::individualPrefix(), $reverse);
     CRM_Utils_Array::lookupValue($defaults, 'suffix', CRM_Core_PseudoConstant::individualSuffix(), $reverse);
     CRM_Utils_Array::lookupValue($defaults, 'gender', CRM_Core_PseudoConstant::gender(), $reverse);
     //lookup value of email/postal greeting, addressee, CRM-4575
     $filterCondition = array('contact_type' => CRM_Utils_Array::value('contact_type', $defaults), 'greeting_type' => 'email_greeting');
     CRM_Utils_Array::lookupValue($defaults, 'email_greeting', CRM_Core_PseudoConstant::greeting($filterCondition), $reverse);
     $filterCondition = array('contact_type' => CRM_Utils_Array::value('contact_type', $defaults), 'greeting_type' => 'postal_greeting');
     CRM_Utils_Array::lookupValue($defaults, 'postal_greeting', CRM_Core_PseudoConstant::greeting($filterCondition), $reverse);
     $filterCondition = array('contact_type' => CRM_Utils_Array::value('contact_type', $defaults), 'greeting_type' => 'addressee');
     CRM_Utils_Array::lookupValue($defaults, 'addressee', CRM_Core_PseudoConstant::greeting($filterCondition), $reverse);
     $blocks = array('address', 'im', 'phone');
     foreach ($blocks as $name) {
         if (!array_key_exists($name, $defaults) || !is_array($defaults[$name])) {
             continue;
         }
         foreach ($defaults[$name] as $count => &$values) {
             //get location type id.
             CRM_Utils_Array::lookupValue($values, 'location_type', CRM_Core_PseudoConstant::locationType(), $reverse);
             if ($name == 'address') {
                 // FIXME: lookupValue doesn't work for vcard_name
                 if (CRM_Utils_Array::value('location_type_id', $values)) {
                     $vcardNames =& CRM_Core_PseudoConstant::locationVcardName();
                     $values['vcard_name'] = $vcardNames[$values['location_type_id']];
                 }
                 if (!CRM_Utils_Array::lookupValue($values, 'state_province', CRM_Core_PseudoConstant::stateProvince(), $reverse) && $reverse) {
                     CRM_Utils_Array::lookupValue($values, 'state_province', CRM_Core_PseudoConstant::stateProvinceAbbreviation(), $reverse);
                 }
                 if (!CRM_Utils_Array::lookupValue($values, 'country', CRM_Core_PseudoConstant::country(), $reverse) && $reverse) {
                     CRM_Utils_Array::lookupValue($values, 'country', CRM_Core_PseudoConstant::countryIsoCode(), $reverse);
                 }
                 CRM_Utils_Array::lookupValue($values, 'county', CRM_Core_PseudoConstant::county(), $reverse);
             }
             if ($name == 'im') {
                 CRM_Utils_Array::lookupValue($values, 'provider', CRM_Core_PseudoConstant::IMProvider(), $reverse);
             }
             if ($name == 'phone') {
                 CRM_Utils_Array::lookupValue($values, 'phone_type', CRM_Core_PseudoConstant::phoneType(), $reverse);
             }
             //kill the reference.
             unset($values);
         }
     }
 }
Esempio n. 11
0
 function restWhere(&$values)
 {
     list($name, $op, $value, $grouping, $wildcard) = $values;
     if (!CRM_Utils_Array::value($grouping, $this->_where)) {
         $this->_where[$grouping] = array();
     }
     $multipleFields = array('url');
     //check if the location type exits for fields
     $lType = '';
     $locType = array();
     $locType = explode('-', $name);
     if (!in_array($locType[0], $multipleFields)) {
         //add phone type if exists
         if (isset($locType[2]) && $locType[2]) {
             $locType[2] = CRM_Core_DAO::escapeString($locType[2]);
         }
     }
     $field = CRM_Utils_Array::value($name, $this->_fields);
     if (!$field) {
         $field = CRM_Utils_Array::value($locType[0], $this->_fields);
         if (!$field) {
             return;
         }
     }
     $setTables = true;
     $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
     if (substr($name, 0, 14) === 'state_province') {
         if (isset($locType[1]) && is_numeric($locType[1])) {
             $setTables = false;
             //get the location name
             $locationType =& CRM_Core_PseudoConstant::locationType();
             list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
             $this->_whereTables[$tName] = $this->_tables[$tName];
             $where = "`{$tName}`.{$fldName}";
         } else {
             $where = $field['where'];
         }
         $wc = $op != 'LIKE' ? "LOWER({$where})" : $where;
         if (is_numeric($value)) {
             $where = str_replace('.name', '.id', $where);
             $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive');
             $states =& CRM_Core_PseudoConstant::stateProvince();
             $value = $states[(int) $value];
         } else {
             $wc = $op != 'LIKE' ? "LOWER({$where})" : $where;
             $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         }
         if (!$lType) {
             $this->_qill[$grouping][] = ts('State') . " {$op} '{$value}'";
         } else {
             $this->_qill[$grouping][] = ts('State') . " ({$lType}) {$op} '{$value}'";
         }
     } else {
         if (substr($name, 0, 7) === 'country') {
             if (isset($locType[1]) && is_numeric($locType[1])) {
                 $setTables = false;
                 //get the location name
                 $locationType =& CRM_Core_PseudoConstant::locationType();
                 list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
                 $this->_whereTables[$tName] = $this->_tables[$tName];
                 $where = "`{$tName}`.{$fldName}";
             } else {
                 $where = $field['where'];
             }
             if (is_numeric($value)) {
                 $where = str_replace('.name', '.id', $where);
                 $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive');
                 $countries =& CRM_Core_PseudoConstant::country();
                 $value = $countries[(int) $value];
             } else {
                 $wc = $op != 'LIKE' ? "LOWER({$where})" : $where;
                 $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
             }
             if (!$lType) {
                 $this->_qill[$grouping][] = ts('Country') . " {$op} '{$value}'";
             } else {
                 $this->_qill[$grouping][] = ts('Country') . " ({$lType}) {$op} '{$value}'";
             }
         } else {
             if (substr($name, 0, 6) === 'county') {
                 if (isset($locType[1]) && is_numeric($locType[1])) {
                     $setTables = false;
                     //get the location name
                     $locationType =& CRM_Core_PseudoConstant::locationType();
                     list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
                     $this->_whereTables[$tName] = $this->_tables[$tName];
                     $where = "`{$tName}`.{$fldName}";
                 } else {
                     $where = $field['where'];
                 }
                 if (is_numeric($value)) {
                     $where = str_replace('.name', '.id', $where);
                     $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive');
                     $counties =& CRM_Core_PseudoConstant::county();
                     $value = $counties[(int) $value];
                 } else {
                     $wc = $op != 'LIKE' ? "LOWER({$where})" : $where;
                     $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                 }
                 if (!$lType) {
                     $this->_qill[$grouping][] = ts('County') . " {$op} '{$value}'";
                 } else {
                     $this->_qill[$grouping][] = ts('County') . " ({$lType}) {$op} '{$value}'";
                 }
             } else {
                 if ($name === 'world_region') {
                     $worldRegions =& CRM_Core_PseudoConstant::worldRegion();
                     if (is_numeric($value)) {
                         $value = $worldRegions[(int) $value];
                     }
                     $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                     $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                     $this->_qill[$grouping][] = ts('World Region') . " {$op} '{$value}'";
                 } else {
                     if ($name === 'individual_prefix') {
                         $individualPrefixs =& CRM_Core_PseudoConstant::individualPrefix();
                         if (is_numeric($value)) {
                             $value = $individualPrefixs[(int) $value];
                         }
                         $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                         $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                         $this->_qill[$grouping][] = ts('Individual Prefix') . " {$op} '{$value}'";
                     } else {
                         if ($name === 'individual_suffix') {
                             $individualSuffixs =& CRM_Core_PseudoConstant::individualsuffix();
                             if (is_numeric($value)) {
                                 $value = $individualSuffixs[(int) $value];
                             }
                             $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                             $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                             $this->_qill[$grouping][] = ts('Individual Suffix') . " {$op} '{$value}'";
                         } else {
                             if ($name === 'gender') {
                                 $genders =& CRM_Core_PseudoConstant::gender();
                                 if (is_numeric($value)) {
                                     $value = $genders[(int) $value];
                                 }
                                 $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                                 $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                                 $this->_qill[$grouping][] = ts('Gender') . " {$op} '{$value}'";
                             } else {
                                 if ($name === 'birth_date') {
                                     $date = CRM_Utils_Date::processDate($value);
                                     $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $date);
                                     if ($date) {
                                         $date = CRM_Utils_Date::customFormat($date);
                                         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$date}\"";
                                     } else {
                                         $this->_qill[$grouping][] = "{$field['title']} {$op}";
                                     }
                                 } else {
                                     if ($name === 'deceased_date') {
                                         $date = CRM_Utils_Date::processDate($value);
                                         $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $date);
                                         if ($date) {
                                             $date = CRM_Utils_Date::customFormat($date);
                                             $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$date}\"";
                                         } else {
                                             $this->_qill[$grouping][] = "{$field['title']} {$op}";
                                         }
                                     } else {
                                         if ($name === 'is_deceased') {
                                             $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $value);
                                             $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
                                         } else {
                                             if ($name === 'contact_id') {
                                                 if (is_int($value)) {
                                                     $this->_where[$grouping][] = self::buildClause($field['where'], $op, $value);
                                                     $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}";
                                                 }
                                             } else {
                                                 if ($name === 'name') {
                                                     $value = $strtolower(CRM_Core_DAO::escapeString($value));
                                                     if ($wildcard) {
                                                         $value = "%{$value}%";
                                                         $op = 'LIKE';
                                                     }
                                                     $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                                                     $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}'");
                                                     $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
                                                 } else {
                                                     if ($name === 'current_employer') {
                                                         $value = $strtolower(CRM_Core_DAO::escapeString($value));
                                                         if ($wildcard) {
                                                             $value = "%{$value}%";
                                                             $op = 'LIKE';
                                                         }
                                                         $wc = $op != 'LIKE' ? "LOWER(contact_a.organization_name)" : "contact_a.organization_name";
                                                         $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}' AND contact_a.contact_type ='Individual'");
                                                         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
                                                     } else {
                                                         if ($name === 'email_greeting') {
                                                             $filterCondition = array('greeting_type' => 'email_greeting');
                                                             $emailGreetings =& CRM_Core_PseudoConstant::greeting($filterCondition);
                                                             if (is_numeric($value)) {
                                                                 $value = $emailGreetings[(int) $value];
                                                             }
                                                             $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                                                             $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                                                             $this->_qill[$grouping][] = ts('Email Greeting') . " {$op} '{$value}'";
                                                         } else {
                                                             if ($name === 'postal_greeting') {
                                                                 $filterCondition = array('greeting_type' => 'postal_greeting');
                                                                 $postalGreetings =& CRM_Core_PseudoConstant::greeting($filterCondition);
                                                                 if (is_numeric($value)) {
                                                                     $value = $postalGreetings[(int) $value];
                                                                 }
                                                                 $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                                                                 $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                                                                 $this->_qill[$grouping][] = ts('Postal Greeting') . " {$op} '{$value}'";
                                                             } else {
                                                                 if ($name === 'addressee') {
                                                                     $filterCondition = array('greeting_type' => 'addressee');
                                                                     $addressee =& CRM_Core_PseudoConstant::greeting($filterCondition);
                                                                     if (is_numeric($value)) {
                                                                         $value = $addressee[(int) $value];
                                                                     }
                                                                     $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                                                                     $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                                                                     $this->_qill[$grouping][] = ts('Addressee') . " {$op} '{$value}'";
                                                                 } else {
                                                                     if (substr($name, 0, 4) === 'url-') {
                                                                         $tName = 'civicrm_website';
                                                                         $this->_whereTables[$tName] = $this->_tables[$tName] = "\nLEFT JOIN civicrm_website ON ( civicrm_website.contact_id = contact_a.id )";
                                                                         $value = $strtolower(CRM_Core_DAO::escapeString($value));
                                                                         if ($wildcard) {
                                                                             $value = "%{$value}%";
                                                                             $op = 'LIKE';
                                                                         }
                                                                         $wc = 'civicrm_website.url';
                                                                         $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}'");
                                                                         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
                                                                     } else {
                                                                         // sometime the value is an array, need to investigate and fix
                                                                         if (is_array($value)) {
                                                                             CRM_Core_Error::fatal();
                                                                         }
                                                                         if (!empty($field['where'])) {
                                                                             if ($op != 'IN') {
                                                                                 $value = $strtolower(CRM_Core_DAO::escapeString($value));
                                                                             }
                                                                             if ($wildcard) {
                                                                                 $value = "%{$value}%";
                                                                                 $op = 'LIKE';
                                                                             }
                                                                             if ($op != 'IN') {
                                                                                 $value = "'{$value}'";
                                                                             }
                                                                             if (isset($locType[1]) && is_numeric($locType[1])) {
                                                                                 $setTables = false;
                                                                                 //get the location name
                                                                                 $locationType =& CRM_Core_PseudoConstant::locationType();
                                                                                 list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
                                                                                 $where = "`{$tName}`.{$fldName}";
                                                                                 $this->_where[$grouping][] = self::buildClause("LOWER({$where})", $op, $value);
                                                                                 $this->_whereTables[$tName] = $this->_tables[$tName];
                                                                                 $this->_qill[$grouping][] = "{$field['title']} {$op} '{$value}'";
                                                                             } else {
                                                                                 list($tableName, $fieldName) = explode('.', $field['where'], 2);
                                                                                 if ($tableName == 'civicrm_contact') {
                                                                                     $fieldName = "LOWER(contact_a.{$fieldName})";
                                                                                 } else {
                                                                                     if ($op != 'IN' && !is_numeric($value)) {
                                                                                         $fieldName = "LOWER({$field['where']})";
                                                                                     } else {
                                                                                         $fieldName = "{$field['where']}";
                                                                                     }
                                                                                 }
                                                                                 $this->_where[$grouping][] = self::buildClause($fieldName, $op, $value);
                                                                                 $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}";
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($setTables) {
         list($tableName, $fieldName) = explode('.', $field['where'], 2);
         if (isset($tableName)) {
             $this->_tables[$tableName] = 1;
             $this->_whereTables[$tableName] = 1;
         }
     }
 }
Esempio n. 12
0
 function restWhere(&$values)
 {
     list($name, $op, $value, $grouping, $wildcard) = $values;
     if (!CRM_Utils_Array::value($grouping, $this->_where)) {
         $this->_where[$grouping] = array();
     }
     //check if the location type exits for fields
     $lType = '';
     $locType = array();
     $locType = explode('-', $name);
     //add phone type if exists
     if (isset($locType[2]) && $locType[2]) {
         $locType[2] = CRM_Core_DAO::escapeString($locType[2]);
     }
     $field = CRM_Utils_Array::value($name, $this->_fields);
     if (!$field) {
         $field = CRM_Utils_Array::value($locType[0], $this->_fields);
         if (!$field) {
             return;
         }
     }
     $setTables = true;
     // FIXME: the LOWER/strtolower pairs below most probably won't work
     // with non-US-ASCII characters, as even if MySQL does the proper
     // thing with LOWER-ing them (4.0 almost certainly won't, but then
     // we don't officially support 4.0 for non-US-ASCII data), PHP
     // won't do the proper thing with strtolower-ing them unless the
     // underlying operating system uses an UTF-8 locale for LC_CTYPE
     // for the user the webserver runs at (or suEXECs); we should use
     // mb_strtolower(), but then we'd require mb_strings support; we
     // could wrap this in function_exist(), though
     if (substr($name, 0, 14) === 'state_province') {
         if (isset($locType[1]) && is_numeric($locType[1])) {
             $setTables = false;
             //get the location name
             $locationType =& CRM_Core_PseudoConstant::locationType();
             list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
             $this->_whereTables[$tName] = $this->_tables[$tName];
             $where = "`{$tName}`.{$fldName}";
         } else {
             $where = $field['where'];
         }
         $wc = $op != 'LIKE' ? "LOWER({$where})" : $where;
         if (is_numeric($value)) {
             $where = str_replace('.name', '.id', $where);
             $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive');
             $states =& CRM_Core_PseudoConstant::stateProvince();
             $value = $states[(int) $value];
         } else {
             $wc = $op != 'LIKE' ? "LOWER({$where})" : $where;
             $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         }
         if (!$lType) {
             $this->_qill[$grouping][] = ts('State') . " {$op} '{$value}'";
         } else {
             $this->_qill[$grouping][] = ts('State') . " ({$lType}) {$op} '{$value}'";
         }
     } else {
         if (substr($name, 0, 7) === 'country') {
             if (isset($locType[1]) && is_numeric($locType[1])) {
                 $setTables = false;
                 //get the location name
                 $locationType =& CRM_Core_PseudoConstant::locationType();
                 list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
                 $this->_whereTables[$tName] = $this->_tables[$tName];
                 $where = "`{$tName}`.{$fldName}";
             } else {
                 $where = $field['where'];
             }
             if (is_numeric($value)) {
                 $where = str_replace('.name', '.id', $where);
                 $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive');
                 $countries =& CRM_Core_PseudoConstant::country();
                 $value = $countries[(int) $value];
             } else {
                 $wc = $op != 'LIKE' ? "LOWER({$where})" : $where;
                 $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
             }
             if (!$lType) {
                 $this->_qill[$grouping][] = ts('Country') . " {$op} '{$value}'";
             } else {
                 $this->_qill[$grouping][] = ts('Country') . " ({$lType}) {$op} '{$value}'";
             }
         } else {
             if (substr($name, 0, 6) === 'county') {
                 if (isset($locType[1]) && is_numeric($locType[1])) {
                     $setTables = false;
                     //get the location name
                     $locationType =& CRM_Core_PseudoConstant::locationType();
                     list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
                     $this->_whereTables[$tName] = $this->_tables[$tName];
                     $where = "`{$tName}`.{$fldName}";
                 } else {
                     $where = $field['where'];
                 }
                 if (is_numeric($value)) {
                     $where = str_replace('.name', '.id', $where);
                     $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive');
                     $counties =& CRM_Core_PseudoConstant::county();
                     $value = $counties[(int) $value];
                 } else {
                     $wc = $op != 'LIKE' ? "LOWER({$where})" : $where;
                     $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                 }
                 if (!$lType) {
                     $this->_qill[$grouping][] = ts('County') . " {$op} '{$value}'";
                 } else {
                     $this->_qill[$grouping][] = ts('County') . " ({$lType}) {$op} '{$value}'";
                 }
             } else {
                 if ($name === 'world_region') {
                     $worldRegions =& CRM_Core_PseudoConstant::worldRegion();
                     if (is_numeric($value)) {
                         $value = $worldRegions[(int) $value];
                     }
                     $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                     $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                     $this->_qill[$grouping][] = ts('World Region') . " {$op} '{$value}'";
                 } else {
                     if ($name === 'individual_prefix') {
                         $individualPrefixs =& CRM_Core_PseudoConstant::individualPrefix();
                         if (is_numeric($value)) {
                             $value = $individualPrefixs[(int) $value];
                         }
                         $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                         $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                         $this->_qill[$grouping][] = ts('Individual Prefix') . " {$op} '{$value}'";
                     } else {
                         if ($name === 'individual_suffix') {
                             $individualSuffixs =& CRM_Core_PseudoConstant::individualsuffix();
                             if (is_numeric($value)) {
                                 $value = $individualSuffixs[(int) $value];
                             }
                             $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                             $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                             $this->_qill[$grouping][] = ts('Individual Suffix') . " {$op} '{$value}'";
                         } else {
                             if ($name === 'gender') {
                                 $genders =& CRM_Core_PseudoConstant::gender();
                                 if (is_numeric($value)) {
                                     $value = $genders[(int) $value];
                                 }
                                 $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                                 $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                                 $this->_qill[$grouping][] = ts('Gender') . " {$op} '{$value}'";
                             } else {
                                 if ($name === 'birth_date') {
                                     $date = CRM_Utils_Date::format($value);
                                     $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $date);
                                     if ($date) {
                                         $date = CRM_Utils_Date::customFormat($date);
                                         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$date}\"";
                                     } else {
                                         $this->_qill[$grouping][] = "{$field['title']} {$op}";
                                     }
                                 } else {
                                     if ($name === 'deceased_date') {
                                         $date = CRM_Utils_Date::format($value);
                                         $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $date);
                                         if ($date) {
                                             $date = CRM_Utils_Date::customFormat($date);
                                             $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$date}\"";
                                         } else {
                                             $this->_qill[$grouping][] = "{$field['title']} {$op}";
                                         }
                                     } else {
                                         if ($name === 'is_deceased') {
                                             $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $value);
                                             $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
                                         } else {
                                             if ($name === 'contact_id') {
                                                 if (is_int($value)) {
                                                     $this->_where[$grouping][] = self::buildClause($field['where'], $op, $value);
                                                     $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}";
                                                 }
                                             } else {
                                                 if ($name === 'name') {
                                                     $value = strtolower(CRM_Core_DAO::escapeString($value));
                                                     if ($wildcard) {
                                                         $value = "%{$value}%";
                                                         $op = 'LIKE';
                                                     }
                                                     $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                                                     $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}'");
                                                     $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
                                                 } else {
                                                     if ($name === 'current_employer') {
                                                         $value = strtolower(CRM_Core_DAO::escapeString($value));
                                                         if ($wildcard) {
                                                             $value = "%{$value}%";
                                                             $op = 'LIKE';
                                                         }
                                                         $wc = $op != 'LIKE' ? "LOWER(contact_a.organization_name)" : "contact_a.organization_name";
                                                         $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}' AND contact_a.contact_type ='Individual'");
                                                         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
                                                     } else {
                                                         if ($name === 'email_greeting') {
                                                             $filterCondition = array('greeting_type' => 'email_greeting');
                                                             $emailGreetings =& CRM_Core_PseudoConstant::greeting($filterCondition);
                                                             if (is_numeric($value)) {
                                                                 $value = $emailGreetings[(int) $value];
                                                             }
                                                             $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                                                             $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                                                             $this->_qill[$grouping][] = ts('Email Greeting') . " {$op} '{$value}'";
                                                         } else {
                                                             if ($name === 'postal_greeting') {
                                                                 $filterCondition = array('greeting_type' => 'postal_greeting');
                                                                 $postalGreetings =& CRM_Core_PseudoConstant::greeting($filterCondition);
                                                                 if (is_numeric($value)) {
                                                                     $value = $postalGreetings[(int) $value];
                                                                 }
                                                                 $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                                                                 $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                                                                 $this->_qill[$grouping][] = ts('Postal Greeting') . " {$op} '{$value}'";
                                                             } else {
                                                                 if ($name === 'addressee') {
                                                                     $filterCondition = array('greeting_type' => 'addressee');
                                                                     $addressee =& CRM_Core_PseudoConstant::greeting($filterCondition);
                                                                     if (is_numeric($value)) {
                                                                         $value = $addressee[(int) $value];
                                                                     }
                                                                     $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                                                                     $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                                                                     $this->_qill[$grouping][] = ts('Addressee') . " {$op} '{$value}'";
                                                                 } else {
                                                                     // sometime the value is an array, need to investigate and fix
                                                                     if (is_array($value)) {
                                                                         CRM_Core_Error::fatal();
                                                                     }
                                                                     if (!empty($field['where'])) {
                                                                         if ($op != 'IN') {
                                                                             $value = strtolower(CRM_Core_DAO::escapeString($value));
                                                                         }
                                                                         if ($wildcard) {
                                                                             $value = "%{$value}%";
                                                                             $op = 'LIKE';
                                                                         }
                                                                         if ($op != 'IN') {
                                                                             $value = "'{$value}'";
                                                                         }
                                                                         if (isset($locType[1]) && is_numeric($locType[1])) {
                                                                             $setTables = false;
                                                                             //get the location name
                                                                             $locationType =& CRM_Core_PseudoConstant::locationType();
                                                                             list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
                                                                             $where = "`{$tName}`.{$fldName}";
                                                                             $this->_where[$grouping][] = self::buildClause("LOWER({$where})", $op, $value);
                                                                             $this->_whereTables[$tName] = $this->_tables[$tName];
                                                                             $this->_qill[$grouping][] = "{$field['title']} {$op} '{$value}'";
                                                                         } else {
                                                                             list($tableName, $fieldName) = explode('.', $field['where'], 2);
                                                                             if ($tableName == 'civicrm_contact') {
                                                                                 $fieldName = "LOWER(contact_a.{$fieldName})";
                                                                             } else {
                                                                                 if ($op != 'IN' && !is_numeric($value)) {
                                                                                     $fieldName = "LOWER({$field['where']})";
                                                                                 } else {
                                                                                     $fieldName = "{$field['where']}";
                                                                                 }
                                                                             }
                                                                             $this->_where[$grouping][] = self::buildClause($fieldName, $op, $value);
                                                                             $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}";
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($setTables) {
         list($tableName, $fieldName) = explode('.', $field['where'], 2);
         if (isset($tableName)) {
             $this->_tables[$tableName] = 1;
             $this->_whereTables[$tableName] = 1;
         }
     }
 }
Esempio n. 13
0
 function buildAddressBlock($locationId, $title, $phone, $alternatePhone = null, $addressRequired = null, $phoneRequired = null, $altPhoneRequired = null, $locationName = null)
 {
     if (!$locationName) {
         $locationName = "location";
     }
     $config = CRM_Core_Config::singleton();
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address');
     $location[$locationId]['address']['street_address'] = $this->addElement('text', "{$locationName}[{$locationId}][address][street_address]", $title, $attributes['street_address']);
     if ($addressRequired) {
         $this->addRule("{$locationName}[{$locationId}][address][street_address]", ts("Please enter the Street Address for %1.", array(1 => $title)), 'required');
     }
     $location[$locationId]['address']['supplemental_address_1'] = $this->addElement('text', "{$locationName}[{$locationId}][address][supplemental_address_1]", ts('Additional Address 1'), $attributes['supplemental_address_1']);
     $location[$locationId]['address']['supplemental_address_2'] = $this->addElement('text', "{$locationName}[{$locationId}][address][supplemental_address_2]", ts('Additional Address 2'), $attributes['supplemental_address_2']);
     $location[$locationId]['address']['city'] = $this->addElement('text', "{$locationName}[{$locationId}][address][city]", ts('City'), $attributes['city']);
     if ($addressRequired) {
         $this->addRule("{$locationName}[{$locationId}][address][city]", ts("Please enter the City for %1.", array(1 => $title)), 'required');
     }
     $location[$locationId]['address']['postal_code'] = $this->addElement('text', "{$locationName}[{$locationId}][address][postal_code]", ts('Zip / Postal Code'), $attributes['postal_code']);
     if ($addressRequired) {
         $this->addRule("{$locationName}[{$locationId}][address][postal_code]", ts("Please enter the Zip/Postal Code for %1.", array(1 => $title)), 'required');
     }
     $location[$locationId]['address']['postal_code_suffix'] = $this->addElement('text', "{$locationName}[{$locationId}][address][postal_code_suffix]", ts('Add-on Code'), array('size' => 4, 'maxlength' => 12));
     $this->addRule("{$locationName}[{$locationId}][address][postal_code_suffix]", ts('Zip-Plus not valid.'), 'positiveInteger');
     if ($config->includeCounty) {
         $location[$locationId]['address']['county_id'] = $this->addElement('select', "{$locationName}[{$locationId}][address][county_id]", ts('County'), array('' => ts('- select -')) + CRM_Core_PseudoConstant::county());
     }
     $location[$locationId]['address']['state_province_id'] = $this->addElement('select', "{$locationName}[{$locationId}][address][state_province_id]", ts('State / Province'), array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince());
     $location[$locationId]['address']['country_id'] = $this->addElement('select', "{$locationName}[{$locationId}][address][country_id]", ts('Country'), array('' => ts('- select -')) + CRM_Core_PseudoConstant::country());
     if ($addressRequired) {
         $this->addRule("{$locationName}[{$locationId}][address][country_id]", ts("Please select the Country for %1.", array(1 => $title)), 'required');
     }
     if ($phone) {
         $location[$locationId]['phone'][1]['phone'] = $this->addElement('text', "{$locationName}[{$locationId}][phone][1][phone]", $phone, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone'));
         if ($phoneRequired) {
             $this->addRule("{$locationName}[{$locationId}][phone][1][phone]", ts('Please enter a value for %1', array(1 => $phone)), 'required');
         }
         $this->addRule("{$locationName}[{$locationId}][phone][1][phone]", ts('Please enter a valid number for %1', array(1 => $phone)), 'phone');
     }
     if ($alternatePhone) {
         $location[$locationId]['phone'][2]['phone'] = $this->addElement('text', "{$locationName}[{$locationId}][phone][2][phone]", $alternatePhone, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone'));
         if ($alternatePhoneRequired) {
             $this->addRule("{$locationName}[{$locationId}][phone][2][phone]", ts('Please enter a value for %1', array(1 => $alternatePhone)), 'required');
         }
         $this->addRule("{$locationName}[{$locationId}][phone][2][phone]", ts('Please enter a valid number for %1', array(1 => $alternatePhone)), 'phone');
     }
 }
 /**
  * check for correct state / country mapping.
  *
  * @param array reference $fields - submitted form values.
  * @param array reference $errors - if any errors found add to this array. please.
  *
  * @return true if no errors
  *         array of errors if any present.
  *
  * @access public
  * @static
  */
 static function formRule($fields)
 {
     $errors = array();
     // check for state/county match if not report error to user.
     if (CRM_Utils_Array::value('address', $fields) && is_array($fields['address'])) {
         foreach ($fields['address'] as $instance => $addressValues) {
             if (CRM_Utils_System::isNull($addressValues)) {
                 continue;
             }
             $countryId = CRM_Utils_Array::value('country_id', $addressValues);
             $stateProvinceId = CRM_Utils_Array::value('state_province_id', $addressValues);
             //do check for mismatch countries
             if ($stateProvinceId && $countryId) {
                 $stateProvinceDAO = new CRM_Core_DAO_StateProvince();
                 $stateProvinceDAO->id = $stateProvinceId;
                 $stateProvinceDAO->find(TRUE);
                 if ($stateProvinceDAO->country_id != $countryId) {
                     // countries mismatch hence display error
                     $stateProvinces = CRM_Core_PseudoConstant::stateProvince();
                     $countries = CRM_Core_PseudoConstant::country();
                     $errors["address[{$instance}][state_province_id]"] = ts('State/Province %1 is not part of %2. It belongs to %3.', array(1 => $stateProvinces[$stateProvinceId], 2 => $countries[$countryId], 3 => $countries[$stateProvinceDAO->country_id]));
                 }
             }
             $countyId = CRM_Utils_Array::value('county_id', $addressValues);
             //state county validation
             if ($stateProvinceId && $countyId) {
                 $countyDAO = new CRM_Core_DAO_County();
                 $countyDAO->id = $countyId;
                 $countyDAO->find(TRUE);
                 if ($countyDAO->state_province_id != $stateProvinceId) {
                     $counties = CRM_Core_PseudoConstant::county();
                     $errors["address[{$instance}][county_id]"] = ts('County %1 is not part of %2. It belongs to %3.', array(1 => $counties[$countyId], 2 => $stateProvinces[$stateProvinceId], 3 => $stateProvinces[$countyDAO->state_province_id]));
                 }
             }
             if (CRM_Utils_Array::value('use_shared_address', $addressValues) && !CRM_Utils_Array::value('master_id', $addressValues)) {
                 $errors["address[{$instance}][use_shared_address]"] = ts('Please select valid shared contact or a contact with valid address.');
             }
         }
     }
     return empty($errors) ? TRUE : $errors;
 }
Esempio n. 15
0
 /**
  * Function to build the array for display the profile fields
  *
  * @param array $params key value.
  * @param int $gid profile Id
  * @param array $groupTitle Profile Group Title.
  * @param array $values formatted array of key value
  *
  * @param array $profileFields
  *
  * @return void
  * @access public
  * @static
  */
 static function displayProfile(&$params, $gid, &$groupTitle, &$values, &$profileFields = array())
 {
     if ($gid) {
         $config = CRM_Core_Config::singleton();
         $session = CRM_Core_Session::singleton();
         $contactID = $session->get('userID');
         if ($contactID) {
             if (CRM_Core_BAO_UFGroup::filterUFGroups($gid, $contactID)) {
                 $fields = CRM_Core_BAO_UFGroup::getFields($gid, FALSE, CRM_Core_Action::VIEW);
             }
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($gid, FALSE, CRM_Core_Action::ADD);
         }
         foreach ($fields as $v) {
             if (!empty($v['groupTitle'])) {
                 $groupTitle['groupTitle'] = $v['groupTitle'];
                 break;
             }
         }
         $customVal = '';
         $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
         //start of code to set the default values
         foreach ($fields as $name => $field) {
             $skip = FALSE;
             // skip fields that should not be displayed separately
             if ($field['skipDisplay']) {
                 continue;
             }
             $index = $field['title'];
             if ($name === 'organization_name') {
                 $values[$index] = $params[$name];
             }
             if ('state_province' == substr($name, 0, 14)) {
                 if ($params[$name]) {
                     $values[$index] = CRM_Core_PseudoConstant::stateProvince($params[$name]);
                 } else {
                     $values[$index] = '';
                 }
             } elseif ('date' == substr($name, -4)) {
                 $values[$index] = CRM_Utils_Date::customFormat(CRM_Utils_Date::processDate($params[$name]), $config->dateformatFull);
             } elseif ('country' == substr($name, 0, 7)) {
                 if ($params[$name]) {
                     $values[$index] = CRM_Core_PseudoConstant::country($params[$name]);
                 } else {
                     $values[$index] = '';
                 }
             } elseif ('county' == substr($name, 0, 6)) {
                 if ($params[$name]) {
                     $values[$index] = CRM_Core_PseudoConstant::county($params[$name]);
                 } else {
                     $values[$index] = '';
                 }
             } elseif (in_array(substr($name, 0, -3), array('gender', 'prefix', 'suffix', 'communication_style'))) {
                 $values[$index] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', $name, $params[$name]);
             } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting'))) {
                 $filterCondition = array('greeting_type' => $name);
                 $greeting = CRM_Core_PseudoConstant::greeting($filterCondition);
                 $values[$index] = $greeting[$params[$name]];
             } elseif ($name === 'preferred_communication_method') {
                 $communicationFields = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
                 $compref = array();
                 $pref = $params[$name];
                 if (is_array($pref)) {
                     foreach ($pref as $k => $v) {
                         if ($v) {
                             $compref[] = $communicationFields[$k];
                         }
                     }
                 }
                 $values[$index] = implode(',', $compref);
             } elseif ($name == 'contact_sub_type') {
                 $values[$index] = implode(', ', $params[$name]);
             } elseif ($name == 'group') {
                 $groups = CRM_Contact_BAO_GroupContact::getGroupList();
                 $title = array();
                 foreach ($params[$name] as $gId => $dontCare) {
                     if ($dontCare) {
                         $title[] = $groups[$gId];
                     }
                 }
                 $values[$index] = implode(', ', $title);
             } elseif ($name == 'tag') {
                 $entityTags = $params[$name];
                 $allTags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
                 $title = array();
                 if (is_array($entityTags)) {
                     foreach ($entityTags as $tagId => $dontCare) {
                         $title[] = $allTags[$tagId];
                     }
                 }
                 $values[$index] = implode(', ', $title);
             } elseif ('participant_role_id' == $name or 'participant_role' == $name) {
                 $roles = CRM_Event_PseudoConstant::participantRole();
                 $values[$index] = $roles[$params[$name]];
             } elseif ('participant_status_id' == $name or 'participant_status' == $name) {
                 $status = CRM_Event_PseudoConstant::participantStatus();
                 $values[$index] = $status[$params[$name]];
             } elseif (substr($name, -11) == 'campaign_id') {
                 $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($params[$name]);
                 $values[$index] = CRM_Utils_Array::value($params[$name], $campaigns);
             } elseif (strpos($name, '-') !== FALSE) {
                 list($fieldName, $id) = CRM_Utils_System::explode('-', $name, 2);
                 $detailName = str_replace(' ', '_', $name);
                 if (in_array($fieldName, array('state_province', 'country', 'county'))) {
                     $values[$index] = $params[$detailName];
                     $idx = $detailName . '_id';
                     $values[$index] = $params[$idx];
                 } elseif ($fieldName == 'im') {
                     $providerName = NULL;
                     if ($providerId = $detailName . '-provider_id') {
                         $providerName = CRM_Utils_Array::value($params[$providerId], $imProviders);
                     }
                     if ($providerName) {
                         $values[$index] = $params[$detailName] . " (" . $providerName . ")";
                     } else {
                         $values[$index] = $params[$detailName];
                     }
                 } elseif ($fieldName == 'phone') {
                     $phoneExtField = str_replace('phone', 'phone_ext', $detailName);
                     if (isset($params[$phoneExtField])) {
                         $values[$index] = $params[$detailName] . " (" . $params[$phoneExtField] . ")";
                     } else {
                         $values[$index] = $params[$detailName];
                     }
                 } else {
                     $values[$index] = $params[$detailName];
                 }
             } else {
                 if (substr($name, 0, 7) === 'do_not_' or substr($name, 0, 3) === 'is_') {
                     if ($params[$name]) {
                         $values[$index] = '[ x ]';
                     }
                 } else {
                     if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                         $query = "\nSELECT html_type, data_type\nFROM   civicrm_custom_field\nWHERE  id = {$cfID}\n";
                         $dao = CRM_Core_DAO::executeQuery($query);
                         $dao->fetch();
                         $htmlType = $dao->html_type;
                         if ($htmlType == 'File') {
                             $values[$index] = $params[$index];
                         } else {
                             if ($dao->data_type == 'Int' || $dao->data_type == 'Boolean') {
                                 $v = $params[$name];
                                 if (!CRM_Utils_System::isNull($v)) {
                                     $customVal = (int) $v;
                                 }
                             } elseif ($dao->data_type == 'Float') {
                                 $customVal = (double) $params[$name];
                             } elseif ($dao->data_type == 'Date') {
                                 //@todo note the currently we are using default date time formatting. Since you can select/set
                                 // different date and time format specific to custom field we should consider fixing this
                                 // sometime in the future
                                 $customVal = $displayValue = CRM_Utils_Date::customFormat(CRM_Utils_Date::processDate($params[$name]), $config->dateformatFull);
                                 if (!empty($params[$name . '_time'])) {
                                     $customVal = $displayValue = CRM_Utils_Date::customFormat(CRM_Utils_Date::processDate($params[$name], $params[$name . '_time']), $config->dateformatDatetime);
                                 }
                                 $skip = TRUE;
                             } else {
                                 $customVal = $params[$name];
                             }
                             //take the custom field options
                             $returnProperties = array($name => 1);
                             $query = new CRM_Contact_BAO_Query($params, $returnProperties, $fields);
                             $options =& $query->_options;
                             if (!$skip) {
                                 $displayValue = CRM_Core_BAO_CustomField::getDisplayValue($customVal, $cfID, $options);
                             }
                             //Hack since we dont have function to check empty.
                             //FIXME in 2.3 using crmIsEmptyArray()
                             $customValue = TRUE;
                             if (is_array($customVal) && is_array($displayValue)) {
                                 $customValue = array_diff($customVal, $displayValue);
                             }
                             //use difference of arrays
                             if (empty($customValue) || !$customValue) {
                                 $values[$index] = '';
                             } else {
                                 $values[$index] = $displayValue;
                             }
                         }
                     } elseif ($name == 'home_URL' && !empty($params[$name])) {
                         $url = CRM_Utils_System::fixURL($params[$name]);
                         $values[$index] = "<a href=\"{$url}\">{$params[$name]}</a>";
                     } elseif (in_array($name, array('birth_date', 'deceased_date', 'participant_register_date'))) {
                         $values[$index] = CRM_Utils_Date::customFormat(CRM_Utils_Date::format($params[$name]));
                     } else {
                         $values[$index] = $params[$name];
                     }
                 }
             }
             $profileFields[$name] = $field;
         }
     }
 }
Esempio n. 16
0
 /**
  * check for correct state / country mapping.
  *
  * @param array reference $fields - submitted form values.
  * @param array reference $errors - if any errors found add to this array. please.
  * @return true if no errors
  *         array of errors if any present.
  *
  * @access public
  * @static
  */
 static function formRule(&$fields, &$errors)
 {
     // check for state/county match if not report error to user.
     if (is_array($fields['address'])) {
         foreach ($fields['address'] as $instance => $addressValues) {
             if (CRM_Utils_System::isNull($addressValues)) {
                 continue;
             }
             if ($countryId = CRM_Utils_Array::value('country_id', $addressValues)) {
                 if (!array_key_exists($countryId, CRM_Core_PseudoConstant::country())) {
                     $countryId = null;
                     $errors["address[{$instance}][country_id]"] = ts('Enter a valid country name.');
                 }
             }
             if ($stateProvinceId = CRM_Utils_Array::value('state_province_id', $addressValues)) {
                 // hack to skip  - type first letter(s) - for state_province
                 // CRM-2649
                 if ($stateProvinceId != ts('- type first letter(s) -')) {
                     if (!array_key_exists($stateProvinceId, CRM_Core_PseudoConstant::stateProvince(false, false))) {
                         $stateProvinceId = null;
                         $errors["address[{$instance}][state_province_id]"] = "Please select a valid State/Province name.";
                     }
                 }
             }
             //do check for mismatch countries
             if ($stateProvinceId && $countryId) {
                 $stateProvinceDAO =& new CRM_Core_DAO_StateProvince();
                 $stateProvinceDAO->id = $stateProvinceId;
                 $stateProvinceDAO->find(true);
                 if ($stateProvinceDAO->country_id != $countryId) {
                     // countries mismatch hence display error
                     $stateProvinces = CRM_Core_PseudoConstant::stateProvince();
                     $countries =& CRM_Core_PseudoConstant::country();
                     $errors["address[{$instance}][state_province_id]"] = "State/Province " . $stateProvinces[$stateProvinceId] . " is not part of " . $countries[$countryId] . ". It belongs to " . $countries[$stateProvinceDAO->country_id] . ".";
                 }
             }
             $countyId = CRM_Utils_Array::value('county_id', $addressValues);
             //state county validation
             if ($stateProvinceId && $countyId) {
                 $countyDAO =& new CRM_Core_DAO_County();
                 $countyDAO->id = $countyId;
                 $countyDAO->find(true);
                 if ($countyDAO->state_province_id != $stateProvinceId) {
                     $counties =& CRM_Core_PseudoConstant::county();
                     $errors["address[{$instance}][county_id]"] = "County " . $counties[$countyId] . " is not part of " . $stateProvinces[$stateProvinceId] . ". It belongs to " . $stateProvinces[$countyDAO->state_province_id] . ".";
                 }
             }
         }
     }
 }
Esempio n. 17
0
 /**
  * Add the formatted address to $this-> display.
  *
  * @param bool $microformat
  *   Unexplained parameter that I've always wondered about.
  */
 public function addDisplay($microformat = FALSE)
 {
     $fields = array('address_id' => $this->id, 'address_name' => str_replace('', ' ', $this->name), 'street_address' => $this->street_address, 'supplemental_address_1' => $this->supplemental_address_1, 'supplemental_address_2' => $this->supplemental_address_2, 'city' => $this->city, 'state_province_name' => isset($this->state_name) ? $this->state_name : "", 'state_province' => isset($this->state) ? $this->state : "", 'postal_code' => isset($this->postal_code) ? $this->postal_code : "", 'postal_code_suffix' => isset($this->postal_code_suffix) ? $this->postal_code_suffix : "", 'country' => isset($this->country) ? $this->country : "", 'world_region' => isset($this->world_region) ? $this->world_region : "");
     if (isset($this->county_id) && $this->county_id) {
         $fields['county'] = CRM_Core_PseudoConstant::county($this->county_id);
     } else {
         $fields['county'] = NULL;
     }
     $this->display = CRM_Utils_Address::format($fields, NULL, $microformat);
     $this->display_text = CRM_Utils_Address::format($fields);
 }
Esempio n. 18
0
 /**
  * Function to build profile form
  *
  * @params object  $form       form object
  * @params array   $field      array field properties
  * @params int     $mode       profile mode
  * @params int     $contactID  contact id
  *
  * @return null
  * @static
  * @access public
  */
 static function buildProfile(&$form, &$field, $mode, $contactId = null, $online = false)
 {
     require_once "CRM/Profile/Form.php";
     require_once "CRM/Core/OptionGroup.php";
     require_once 'CRM/Core/BAO/UFField.php';
     require_once 'CRM/Contact/BAO/ContactType.php';
     $defaultValues = array();
     $fieldName = $field['name'];
     $title = $field['title'];
     $attributes = $field['attributes'];
     $rule = $field['rule'];
     $view = $field['is_view'];
     $required = $mode == CRM_Profile_Form::MODE_SEARCH ? false : $field['is_required'];
     $search = $mode == CRM_Profile_Form::MODE_SEARCH ? true : false;
     // do not display view fields in drupal registration form
     // CRM-4632
     if ($view && $mode == CRM_Profile_Form::MODE_REGISTER) {
         return;
     }
     if ($contactId && !$online) {
         $name = "field[{$contactId}][{$fieldName}]";
     } else {
         $name = $fieldName;
     }
     require_once 'CRM/Core/BAO/Preferences.php';
     $addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true);
     if (substr($fieldName, 0, 14) === 'state_province') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required);
     } else {
         if (substr($fieldName, 0, 7) === 'country') {
             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required);
             $config =& CRM_Core_Config::singleton();
             if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactCountry) {
                 $defaultValues[$name] = $config->defaultContactCountry;
                 $form->setDefaults($defaultValues);
             }
         } else {
             if (substr($fieldName, 0, 6) === 'county') {
                 if ($addressOptions['county']) {
                     $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::county(), $required);
                 }
             } else {
                 if (substr($fieldName, 0, 2) === 'im') {
                     if (!$contactId) {
                         $form->add('select', $name . '-provider_id', $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::IMProvider(), $required);
                         if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) {
                             $form->freeze($name . "-provider_id");
                         }
                     }
                     $form->add('text', $name, $title, $attributes, $required);
                 } else {
                     if ($fieldName === 'birth_date' || $fieldName === 'deceased_date') {
                         $form->addDate($name, $title, $required, array('formatType' => 'birth'));
                     } else {
                         if (in_array($fieldName, array("membership_start_date", "membership_end_date", "join_date"))) {
                             $form->addDate($name, $title, $required, array('formatType' => 'custom'));
                         } else {
                             if ($field['name'] == 'membership_type_id') {
                                 require_once 'CRM/Member/PseudoConstant.php';
                                 $form->add('select', 'membership_type_id', $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipType(), $required);
                             } else {
                                 if ($field['name'] == 'status_id') {
                                     require_once 'CRM/Member/PseudoConstant.php';
                                     $form->add('select', 'status_id', $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(), $required);
                                 } else {
                                     if ($fieldName === 'gender') {
                                         $genderOptions = array();
                                         $gender = CRM_Core_PseudoConstant::gender();
                                         foreach ($gender as $key => $var) {
                                             $genderOptions[$key] = HTML_QuickForm::createElement('radio', null, ts('Gender'), $var, $key);
                                         }
                                         $form->addGroup($genderOptions, $name, $title);
                                         if ($required) {
                                             $form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required');
                                         }
                                     } else {
                                         if ($fieldName === 'individual_prefix') {
                                             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix(), $required);
                                         } else {
                                             if ($fieldName === 'individual_suffix') {
                                                 $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix(), $required);
                                             } else {
                                                 if ($fieldName === 'contact_sub_type') {
                                                     $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $form->_fields[$fieldName]);
                                                     $profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : null;
                                                     $setSubtype = false;
                                                     if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
                                                         $setSubtype = $profileType;
                                                         $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
                                                     }
                                                     $subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array();
                                                     if ($setSubtype) {
                                                         $subtypeList = array();
                                                         $subtypeList[$setSubtype] = $subtypes[$setSubtype];
                                                     } else {
                                                         $subtypeList = array('' => ts('- select -')) + $subtypes;
                                                     }
                                                     $form->add('select', $name, $title, $subtypeList, $required);
                                                 } else {
                                                     if (in_array($fieldName, array('email_greeting', 'postal_greeting', 'addressee'))) {
                                                         //add email greeting, postal greeting, addressee, CRM-4575
                                                         $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
                                                         $profileType = CRM_Core_BAO_UFField::getProfileType($gId, true, false, true);
                                                         if (empty($profileType) || in_array($profileType, array('Contact', 'Contribution', 'Participant', 'Membership'))) {
                                                             $profileType = 'Individual';
                                                         }
                                                         if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
                                                             $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
                                                         }
                                                         if ($fieldName == 'email_greeting') {
                                                             $emailGreeting = array('contact_type' => $profileType, 'greeting_type' => 'email_greeting');
                                                             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($emailGreeting), $required);
                                                             // adding custom email greeting element alongwith email greeting
                                                             $form->add('text', 'email_greeting_custom', ts('Custom Email Greeting'), null, false);
                                                         } else {
                                                             if ($fieldName === 'postal_greeting') {
                                                                 $postalGreeting = array('contact_type' => $profileType, 'greeting_type' => 'postal_greeting');
                                                                 $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($postalGreeting), $required);
                                                                 // adding custom postal greeting element alongwith postal greeting
                                                                 $form->add('text', 'postal_greeting_custom', ts('Custom Postal Greeting'), null, false);
                                                             } else {
                                                                 if ($fieldName === 'addressee') {
                                                                     $addressee = array('contact_type' => $profileType, 'greeting_type' => 'addressee');
                                                                     $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($addressee), $required);
                                                                     // adding custom addressee  element alongwith addressee type
                                                                     $form->add('text', 'addressee_custom', ts('Custom Addressee'), null, false);
                                                                 }
                                                             }
                                                         }
                                                     } else {
                                                         if ($fieldName === 'preferred_communication_method') {
                                                             $communicationFields = CRM_Core_PseudoConstant::pcm();
                                                             foreach ($communicationFields as $key => $var) {
                                                                 if ($key == '') {
                                                                     continue;
                                                                 }
                                                                 $communicationOptions[] =& HTML_QuickForm::createElement('checkbox', $key, null, $var);
                                                             }
                                                             $form->addGroup($communicationOptions, $name, $title, '<br/>');
                                                         } else {
                                                             if ($fieldName === 'preferred_mail_format') {
                                                                 $form->add('select', $name, $title, CRM_Core_SelectValues::pmf());
                                                             } else {
                                                                 if ($fieldName == 'external_identifier') {
                                                                     $form->add('text', $name, $title, $attributes, $required);
                                                                     $contID = $contactId;
                                                                     if (!$contID) {
                                                                         $contID = $form->get('id');
                                                                     }
                                                                     $form->addRule($name, ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $contID, 'external_identifier'));
                                                                 } else {
                                                                     if ($fieldName === 'group') {
                                                                         require_once 'CRM/Contact/Form/Edit/TagsAndGroups.php';
                                                                         CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, true, $required, $title, null, $name);
                                                                     } else {
                                                                         if ($fieldName === 'tag') {
                                                                             require_once 'CRM/Contact/Form/Edit/TagsAndGroups.php';
                                                                             CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::TAG, false, $required, null, $title, $name);
                                                                         } else {
                                                                             if ($fieldName === 'home_URL') {
                                                                                 $form->addElement('text', $name, $title, array_merge(CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'home_URL'), array('onfocus' => "if (!this.value) this.value='http://'; else return false", 'onblur' => "if ( this.value == 'http://') this.value=''; else return false")));
                                                                                 $form->addRule($name, ts('Enter a valid Website.'), 'url');
                                                                             } else {
                                                                                 if (substr($fieldName, 0, 6) === 'custom') {
                                                                                     $customFieldID = CRM_Core_BAO_CustomField::getKeyID($fieldName);
                                                                                     if ($customFieldID) {
                                                                                         CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, false, $required, $search, $title);
                                                                                     }
                                                                                 } else {
                                                                                     if (in_array($fieldName, array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) {
                                                                                         $form->addDate($name, $title, $required, array('formatType' => 'custom'));
                                                                                     } else {
                                                                                         if ($fieldName == 'payment_instrument') {
                                                                                             require_once "CRM/Contribute/PseudoConstant.php";
                                                                                             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required);
                                                                                         } else {
                                                                                             if ($fieldName == 'contribution_type') {
                                                                                                 require_once "CRM/Contribute/PseudoConstant.php";
                                                                                                 $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType(), $required);
                                                                                             } else {
                                                                                                 if ($fieldName == 'contribution_status_id') {
                                                                                                     require_once "CRM/Contribute/PseudoConstant.php";
                                                                                                     $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionStatus(), $required);
                                                                                                 } else {
                                                                                                     if ($fieldName == 'participant_register_date') {
                                                                                                         $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
                                                                                                     } else {
                                                                                                         if ($fieldName == 'participant_status_id') {
                                                                                                             require_once "CRM/Event/PseudoConstant.php";
                                                                                                             $cond = null;
                                                                                                             if ($online == true) {
                                                                                                                 $cond = "visibility_id = 1";
                                                                                                             }
                                                                                                             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantStatus(null, $cond), $required);
                                                                                                         } else {
                                                                                                             if ($fieldName == 'participant_role_id') {
                                                                                                                 require_once "CRM/Event/PseudoConstant.php";
                                                                                                                 $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantRole(), $required);
                                                                                                             } else {
                                                                                                                 if ($fieldName == 'scholarship_type_id') {
                                                                                                                     $form->add('select', $name, $title, array("" => "-- Select -- ") + array_flip(CRM_Core_OptionGroup::values('scholarship_type', true)));
                                                                                                                 } else {
                                                                                                                     if ($fieldName == 'applicant_status_id') {
                                                                                                                         $form->add('select', $name, $title, array("" => "-- Select -- ") + array_flip(CRM_Core_OptionGroup::values('applicant_status', true)));
                                                                                                                     } else {
                                                                                                                         if ($fieldName == 'highschool_gpa_id') {
                                                                                                                             $form->add('select', $name, $title, array("" => "-- Select -- ") + CRM_Core_OptionGroup::values('highschool_gpa'));
                                                                                                                         } else {
                                                                                                                             if ($fieldName == 'world_region') {
                                                                                                                                 require_once "CRM/Core/PseudoConstant.php";
                                                                                                                                 $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::worldRegion(), $required);
                                                                                                                             } else {
                                                                                                                                 $processed = false;
                                                                                                                                 if (CRM_Core_Permission::access('Quest', false)) {
                                                                                                                                     require_once 'CRM/Quest/BAO/Student.php';
                                                                                                                                     $processed = CRM_Quest_BAO_Student::buildStudentForm($form, $fieldName, $title, $contactId);
                                                                                                                                 }
                                                                                                                                 if (!$processed) {
                                                                                                                                     if (substr($fieldName, 0, 3) === 'is_' or substr($fieldName, 0, 7) === 'do_not_') {
                                                                                                                                         $form->add('checkbox', $name, $title, $attributes, $required);
                                                                                                                                     } else {
                                                                                                                                         $form->add('text', $name, $title, $attributes, $required);
                                                                                                                                     }
                                                                                                                                 }
                                                                                                                             }
                                                                                                                         }
                                                                                                                     }
                                                                                                                 }
                                                                                                             }
                                                                                                         }
                                                                                                     }
                                                                                                 }
                                                                                             }
                                                                                         }
                                                                                     }
                                                                                 }
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     static $hiddenSubtype = false;
     if (!$hiddenSubtype && CRM_Contact_BAO_ContactType::isaSubType($field['field_type'])) {
         // In registration mode params are submitted via POST and we don't have any clue
         // about profile-id or the profile-type (which could be a subtype)
         // To generalize the  behavior and simplify the process,
         // lets always add the hidden
         //subtype value if there is any, and we won't have to
         // compute it while processing.
         $form->addElement('hidden', 'contact_sub_type_hidden', $field['field_type']);
         $hiddenSubtype = true;
     }
     if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) {
         $form->freeze($name);
     }
     //add the rules
     if (in_array($fieldName, array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) {
         $form->addRule($name, ts('Please enter a valid amount.'), 'money');
     }
     if ($rule) {
         if (!($rule == 'email' && $mode == CRM_Profile_Form::MODE_SEARCH)) {
             $form->addRule($name, ts('Please enter a valid %1', array(1 => $title)), $rule);
         }
     }
 }
Esempio n. 19
0
 /**
  * where / qill clause for county (if present)
  *
  * @return void
  * @access public
  */
 function county(&$values, $status = null)
 {
     list($name, $op, $value, $grouping, $wildcard) = $values;
     if (!is_array($value)) {
         // force the county to be an array
         $value = array($value);
     }
     // check if the values are ids OR names of the counties
     $inputFormat = 'id';
     foreach ($value as $v) {
         if (!is_numeric($v)) {
             $inputFormat = 'name';
             break;
         }
     }
     $names = array();
     if ($inputFormat == 'id') {
         $clause = 'civicrm_county.id IN (' . implode(',', $value) . ')';
         $county = CRM_Core_PseudoConstant::county();
         foreach ($value as $id) {
             $names[] = CRM_Utils_Array::value($id, $county);
         }
     } else {
         $inputClause = array();
         foreach ($value as $name) {
             $name = trim($name);
             $inputClause[] = "'{$name}'";
         }
         $clause = 'civicrm_county.name IN (' . implode(',', $inputClause) . ')';
         $names = $value;
     }
     $this->_tables['civicrm_county'] = 1;
     $this->_whereTables['civicrm_county'] = 1;
     $this->_where[$grouping][] = $clause;
     if (!$status) {
         $this->_qill[$grouping][] = ts('County') . ' - ' . implode(' ' . ts('or') . ' ', $names);
     } else {
         return implode(' ' . ts('or') . ' ', $names);
     }
 }
Esempio n. 20
0
 /**
  * Where / qill clause for county (if present)
  *
  * @param $values
  * @param null $status
  *
  * @return void
  */
 public function county(&$values, $status = NULL)
 {
     list($name, $op, $value, $grouping, $wildcard) = $values;
     if (!is_array($value)) {
         // force the county to be an array
         $value = array($value);
     }
     // check if the values are ids OR names of the counties
     $inputFormat = 'id';
     foreach ($value as $v) {
         if (!is_numeric($v)) {
             $inputFormat = 'name';
             break;
         }
     }
     $names = array();
     if ($op == '=') {
         $op = 'IN';
     } elseif ($op == '!=') {
         $op = 'NOT IN';
     } else {
         // this converts IS (NOT)? EMPTY to IS (NOT)? NULL
         $op = str_replace('EMPTY', 'NULL', $op);
     }
     if (in_array($op, array('IS NULL', 'IS NOT NULL', 'IS EMPTY', 'IS NOT EMPTY'))) {
         $clause = "civicrm_address.county_id {$op}";
     } elseif ($inputFormat == 'id') {
         $clause = 'civicrm_address.county_id IN (' . implode(',', $value) . ')';
         $county = CRM_Core_PseudoConstant::county();
         foreach ($value as $id) {
             $names[] = CRM_Utils_Array::value($id, $county);
         }
     } else {
         $inputClause = array();
         $county = CRM_Core_PseudoConstant::county();
         foreach ($value as $name) {
             $name = trim($name);
             $inputClause[] = CRM_Utils_Array::key($name, $county);
         }
         $clause = 'civicrm_address.county_id IN (' . implode(',', $inputClause) . ')';
         $names = $value;
     }
     $this->_tables['civicrm_address'] = 1;
     $this->_whereTables['civicrm_address'] = 1;
     $this->_where[$grouping][] = $clause;
     if (!$status) {
         $this->_qill[$grouping][] = ts('County') . ' - ' . implode(' ' . ts('or') . ' ', $names);
     } else {
         return implode(' ' . ts('or') . ' ', $names);
     }
 }
Esempio n. 21
0
 /**  
  * Function to build the array for display the profile fields
  *  
  * @param array $params key value. 
  * @param int $gid profile Id
  * @param array $groupTitle Profile Group Title.
  * @param array $values formatted array of key value
  *
  * @return None  
  * @access public  
  */
 function displayProfile(&$params, $gid, &$groupTitle, &$values)
 {
     if ($gid) {
         require_once 'CRM/Core/BAO/UFGroup.php';
         require_once 'CRM/Profile/Form.php';
         require_once 'CRM/Event/PseudoConstant.php';
         $session = CRM_Core_Session::singleton();
         $contactID = $session->get('userID');
         if ($contactID) {
             if (CRM_Core_BAO_UFGroup::filterUFGroups($gid, $contactID)) {
                 $fields = CRM_Core_BAO_UFGroup::getFields($gid, false, CRM_Core_Action::VIEW);
             }
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($gid, false, CRM_Core_Action::ADD);
         }
         if (is_array($fields)) {
             // unset any email-* fields since we already collect it, CRM-2888
             foreach (array_keys($fields) as $fieldName) {
                 if (substr($fieldName, 0, 6) == 'email-') {
                     unset($fields[$fieldName]);
                 }
             }
         }
         foreach ($fields as $v) {
             if (CRM_Utils_Array::value('groupTitle', $v)) {
                 $groupTitle['groupTitle'] = $v["groupTitle"];
                 break;
             }
         }
         $config = CRM_Core_Config::singleton();
         require_once 'CRM/Core/PseudoConstant.php';
         $locationTypes = $imProviders = array();
         $locationTypes = CRM_Core_PseudoConstant::locationType();
         $imProviders = CRM_Core_PseudoConstant::IMProvider();
         //start of code to set the default values
         foreach ($fields as $name => $field) {
             $index = $field['title'];
             $customFieldName = null;
             if ($name === 'organization_name') {
                 $values[$index] = $params[$name];
             }
             if ('state_province' == substr($name, 0, 14)) {
                 if ($params[$name]) {
                     $values[$index] = CRM_Core_PseudoConstant::stateProvince($params[$name]);
                 } else {
                     $values[$index] = '';
                 }
             } else {
                 if ('country' == substr($name, 0, 7)) {
                     if ($params[$name]) {
                         $values[$index] = CRM_Core_PseudoConstant::country($params[$name]);
                     } else {
                         $values[$index] = '';
                     }
                 } else {
                     if ('county' == substr($name, 0, 6)) {
                         if ($params[$name]) {
                             $values[$index] = CRM_Core_PseudoConstant::county($params[$name]);
                         } else {
                             $values[$index] = '';
                         }
                     } else {
                         if ('gender' == substr($name, 0, 6)) {
                             $gender = CRM_Core_PseudoConstant::gender();
                             $values[$index] = $gender[$params[$name]];
                         } else {
                             if ('individual_prefix' == substr($name, 0, 17)) {
                                 $prefix = CRM_Core_PseudoConstant::individualPrefix();
                                 $values[$index] = $prefix[$params[$name]];
                             } else {
                                 if ('individual_suffix' == substr($name, 0, 17)) {
                                     $suffix = CRM_Core_PseudoConstant::individualSuffix();
                                     $values[$index] = $suffix[$params[$name]];
                                 } else {
                                     if (in_array($name, array('addressee', 'email_greeting', 'postal_greeting'))) {
                                         $filterCondition = array('greeting_type' => $name);
                                         $greeting =& CRM_Core_PseudoConstant::greeting($filterCondition);
                                         $values[$index] = $greeting[$params[$name]];
                                     } else {
                                         if ($name === 'preferred_communication_method') {
                                             $communicationFields = CRM_Core_PseudoConstant::pcm();
                                             $pref = array();
                                             $compref = array();
                                             $pref = $params[$name];
                                             if (is_array($pref)) {
                                                 foreach ($pref as $k => $v) {
                                                     if ($v) {
                                                         $compref[] = $communicationFields[$k];
                                                     }
                                                 }
                                             }
                                             $values[$index] = implode(",", $compref);
                                         } else {
                                             if ($name == 'group') {
                                                 require_once 'CRM/Contact/BAO/GroupContact.php';
                                                 $groups = CRM_Contact_BAO_GroupContact::getGroupList();
                                                 $title = array();
                                                 foreach ($params[$name] as $gId => $dontCare) {
                                                     if ($dontCare) {
                                                         $title[] = $groups[$gId];
                                                     }
                                                 }
                                                 $values[$index] = implode(', ', $title);
                                             } else {
                                                 if ($name == 'tag') {
                                                     require_once 'CRM/Core/BAO/EntityTag.php';
                                                     $entityTags = $params[$name];
                                                     $allTags =& CRM_Core_PseudoConstant::tag();
                                                     $title = array();
                                                     if (is_array($entityTags)) {
                                                         foreach ($entityTags as $tagId => $dontCare) {
                                                             $title[] = $allTags[$tagId];
                                                         }
                                                     }
                                                     $values[$index] = implode(', ', $title);
                                                 } else {
                                                     if ('participant_role_id' == $name) {
                                                         $roles = CRM_Event_PseudoConstant::participantRole();
                                                         $values[$index] = $roles[$params[$name]];
                                                     } else {
                                                         if ('participant_status_id' == $name) {
                                                             $status = CRM_Event_PseudoConstant::participantStatus();
                                                             $values[$index] = $status[$params[$name]];
                                                         } else {
                                                             if (strpos($name, '-') !== false) {
                                                                 list($fieldName, $id) = CRM_Utils_System::explode('-', $name, 2);
                                                                 $detailName = str_replace(' ', '_', $name);
                                                                 if (in_array($fieldName, array('state_province', 'country', 'county'))) {
                                                                     $values[$index] = $params[$detailName];
                                                                     $idx = $detailName . '_id';
                                                                     $values[$index] = $params[$idx];
                                                                 } else {
                                                                     if ($fieldName == 'im') {
                                                                         $providerName = null;
                                                                         if ($providerId = $detailName . '-provider_id') {
                                                                             $providerName = CRM_Utils_Array::value($params[$providerId], $imProviders);
                                                                         }
                                                                         if ($providerName) {
                                                                             $values[$index] = $params[$detailName] . " (" . $providerName . ")";
                                                                         } else {
                                                                             $values[$index] = $params[$detailName];
                                                                         }
                                                                     } else {
                                                                         $values[$index] = $params[$detailName];
                                                                     }
                                                                 }
                                                             } else {
                                                                 if (substr($name, 0, 7) === 'do_not_' or substr($name, 0, 3) === 'is_') {
                                                                     if ($params[$name]) {
                                                                         $values[$index] = '[ x ]';
                                                                     }
                                                                 } else {
                                                                     require_once 'CRM/Core/BAO/CustomField.php';
                                                                     if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                                                                         $query = "\nSELECT html_type, data_type\nFROM   civicrm_custom_field\nWHERE  id = {$cfID}\n";
                                                                         $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
                                                                         $dao->fetch();
                                                                         $htmlType = $dao->html_type;
                                                                         $dataType = $dao->data_type;
                                                                         if ($htmlType == 'File') {
                                                                             //$fileURL = CRM_Core_BAO_CustomField::getFileURL( $contactID, $cfID );
                                                                             //$params[$index] = $values[$index] = $fileURL['file_url'];
                                                                             $values[$index] = $params[$index];
                                                                         } else {
                                                                             if ($dao->data_type == 'Int' || $dao->data_type == 'Boolean') {
                                                                                 $customVal = (int) $params[$name];
                                                                             } else {
                                                                                 if ($dao->data_type == 'Float') {
                                                                                     $customVal = (double) $params[$name];
                                                                                 } else {
                                                                                     if ($dao->data_type == 'Date') {
                                                                                         $date = CRM_Utils_Date::format($params[$name], null, 'invalidDate');
                                                                                         if ($date != 'invalidDate') {
                                                                                             $customVal = $date;
                                                                                         }
                                                                                     } else {
                                                                                         $customVal = $params[$name];
                                                                                     }
                                                                                 }
                                                                             }
                                                                             //take the custom field options
                                                                             $returnProperties = array($name => 1);
                                                                             require_once 'CRM/Contact/BAO/Query.php';
                                                                             $query = new CRM_Contact_BAO_Query($params, $returnProperties, $fields);
                                                                             $options =& $query->_options;
                                                                             $displayValue = CRM_Core_BAO_CustomField::getDisplayValue($customVal, $cfID, $options);
                                                                             //Hack since we dont have function to check empty.
                                                                             //FIXME in 2.3 using crmIsEmptyArray()
                                                                             $customValue = true;
                                                                             if (is_array($customVal) && is_array($displayValue)) {
                                                                                 $customValue = array_diff($customVal, $displayValue);
                                                                             }
                                                                             //use difference of arrays
                                                                             if (empty($customValue) || !$customValue) {
                                                                                 $values[$index] = '';
                                                                             } else {
                                                                                 $values[$index] = $displayValue;
                                                                             }
                                                                             if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $cfID, 'is_search_range')) {
                                                                                 $customFieldName = "{$name}_from";
                                                                             }
                                                                         }
                                                                     } else {
                                                                         if ($name == 'home_URL' && !empty($params[$name])) {
                                                                             $url = CRM_Utils_System::fixURL($params[$name]);
                                                                             $values[$index] = "<a href=\"{$url}\">{$params[$name]}</a>";
                                                                         } else {
                                                                             if (in_array($name, array('birth_date', 'deceased_date', 'participant_register_date'))) {
                                                                                 require_once 'CRM/Utils/Date.php';
                                                                                 $values[$index] = CRM_Utils_Date::customFormat(CRM_Utils_Date::format($params[$name]));
                                                                             } else {
                                                                                 $values[$index] = $params[$name];
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 22
0
 /**
  * Function to add profile field to a form
  *
  * @param CRM_Core_Form $form
  * @param array $field properties
  * @param int $mode profile mode
  * @param int $contactId
  * @param bool $online
  * @param string $usedFor for building up prefixed fieldname for special cases (e.g. onBehalf, Honor)
  * @param int $rowNumber
  * @param string $prefix
  *
  * @return null
  * @static
  * @access public
  */
 static function buildProfile(&$form, &$field, $mode, $contactId = NULL, $online = FALSE, $usedFor = NULL, $rowNumber = NULL, $prefix = '')
 {
     $defaultValues = array();
     $fieldName = $field['name'];
     $title = $field['title'];
     $attributes = $field['attributes'];
     $rule = $field['rule'];
     $view = $field['is_view'];
     $required = $mode == CRM_Profile_Form::MODE_SEARCH ? FALSE : $field['is_required'];
     $search = $mode == CRM_Profile_Form::MODE_SEARCH ? TRUE : FALSE;
     $isShared = CRM_Utils_Array::value('is_shared', $field, 0);
     // do not display view fields in drupal registration form
     // CRM-4632
     if ($view && $mode == CRM_Profile_Form::MODE_REGISTER) {
         return;
     }
     if ($usedFor == 'onbehalf') {
         $name = "onbehalf[{$fieldName}]";
     } elseif ($usedFor == 'honor') {
         $name = "honor[{$fieldName}]";
     } elseif ($contactId && !$online) {
         $name = "field[{$contactId}][{$fieldName}]";
     } elseif ($rowNumber) {
         $name = "field[{$rowNumber}][{$fieldName}]";
     } elseif (!empty($prefix)) {
         $name = $prefix . "[{$fieldName}]";
     } else {
         $name = $fieldName;
     }
     $selectAttributes = array('class' => 'crm-select2', 'placeholder' => TRUE);
     // CRM-15172 - keep track of all the fields we've processed
     // This is hackish but we can't always rely on $form->_fields depending on how this is called
     static $fieldsProcessed = array();
     $fieldsProcessed[] = $name;
     if ($fieldName == 'image_URL' && $mode == CRM_Profile_Form::MODE_EDIT) {
         $deleteExtra = ts('Are you sure you want to delete contact image.');
         $deleteURL = array(CRM_Core_Action::DELETE => array('name' => ts('Delete Contact Image'), 'url' => 'civicrm/contact/image', 'qs' => 'reset=1&id=%%id%%&gid=%%gid%%&action=delete', 'extra' => 'onclick = "if (confirm( \'' . $deleteExtra . '\' ) ) this.href+=\'&amp;confirmed=1\'; else return false;"'));
         $deleteURL = CRM_Core_Action::formLink($deleteURL, CRM_Core_Action::DELETE, array('id' => $form->get('id'), 'gid' => $form->get('gid')), ts('more'), FALSE, 'contact.profileimage.delete', 'Contact', $form->get('id'));
         $form->assign('deleteURL', $deleteURL);
     }
     $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE);
     if (substr($fieldName, 0, 14) === 'state_province') {
         $controlField = str_replace('state_province', 'country', $name);
         if (isset($form->_fields[$controlField]) || in_array($controlField, $fieldsProcessed)) {
             $form->addChainSelect($name, array('label' => $title, 'required' => $required));
         } else {
             $options = CRM_Core_PseudoConstant::stateProvince();
             $form->add('select', $name, $title, $options, $required && $options, $selectAttributes);
         }
         $config = CRM_Core_Config::singleton();
         if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactStateProvince) {
             $defaultValues[$name] = $config->defaultContactStateProvince;
             $form->setDefaults($defaultValues);
         }
     } elseif (substr($fieldName, 0, 7) === 'country') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required, $selectAttributes);
         $config = CRM_Core_Config::singleton();
         if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactCountry) {
             $defaultValues[$name] = $config->defaultContactCountry;
             $form->setDefaults($defaultValues);
         }
     } elseif (substr($fieldName, 0, 6) === 'county') {
         if ($addressOptions['county']) {
             $controlField = str_replace('county', 'state_province', $name);
             if (isset($form->_fields[$controlField]) || in_array($controlField, $fieldsProcessed)) {
                 $form->addChainSelect($name, array('label' => $title, 'required' => $required));
             } else {
                 $options = CRM_Core_PseudoConstant::county();
                 $form->add('select', $name, $title, $options, $required && $options, $selectAttributes);
             }
         }
     } elseif (substr($fieldName, 0, 9) === 'image_URL') {
         $form->add('file', $name, $title, $attributes, $required);
         $form->addUploadElement($name);
     } elseif (substr($fieldName, 0, 2) === 'im') {
         $form->add('text', $name, $title, $attributes, $required);
         if (!$contactId) {
             if ($usedFor) {
                 if (substr($name, -1) == ']') {
                     $providerName = substr($name, 0, -1) . '-provider_id]';
                 }
                 $form->add('select', $providerName, NULL, array('' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $required);
             } else {
                 $form->add('select', $name . '-provider_id', $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $required);
             }
             if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) {
                 $form->freeze($name . '-provider_id');
             }
         }
     } elseif ($fieldName === 'birth_date' || $fieldName === 'deceased_date') {
         $form->addDate($name, $title, $required, array('formatType' => 'birth'));
     } elseif (in_array($fieldName, array('membership_start_date', 'membership_end_date', 'join_date'))) {
         $form->addDate($name, $title, $required, array('formatType' => 'custom'));
     } elseif (CRM_Utils_Array::value('name', $field) == 'membership_type') {
         list($orgInfo, $types) = CRM_Member_BAO_MembershipType::getMembershipTypeInfo();
         $sel =& $form->addElement('hierselect', $name, $title);
         $select = array('' => ts('- select -'));
         if (count($orgInfo) == 1 && $field['is_required']) {
             // we only have one org - so we should default to it. Not sure about defaulting to first type
             // as it could be missed - so adding a select
             // however, possibly that is more similar to the membership form
             if (count($types[1]) > 1) {
                 $types[1] = $select + $types[1];
             }
         } else {
             $orgInfo = $select + $orgInfo;
         }
         $sel->setOptions(array($orgInfo, $types));
     } elseif (CRM_Utils_Array::value('name', $field) == 'membership_status') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'), $required);
     } elseif ($fieldName === 'gender_id') {
         $genderOptions = array();
         $gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id');
         foreach ($gender as $key => $var) {
             $genderOptions[$key] = $form->createElement('radio', NULL, ts('Gender'), $var, $key);
         }
         $group = $form->addGroup($genderOptions, $name, $title);
         if ($required) {
             $form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required');
         } else {
             $group->setAttribute('allowClear', TRUE);
         }
     } elseif ($fieldName === 'prefix_id' || $fieldName === 'suffix_id') {
         $form->addSelect($name, array('label' => $title, 'entity' => 'contact', 'field' => $fieldName, 'class' => 'six', 'placeholder' => ''), $required);
     } elseif ($fieldName === 'contact_sub_type') {
         $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
         if ($usedFor == 'onbehalf') {
             $profileType = 'Organization';
         } elseif ($usedFor == 'honor') {
             $profileType = CRM_Core_BAO_UFField::getProfileType($form->_params['honoree_profile_id']);
         } else {
             $profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : NULL;
             if ($profileType == 'Contact') {
                 $profileType = 'Individual';
             }
         }
         $setSubtype = FALSE;
         if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
             $setSubtype = $profileType;
             $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
         }
         $subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array();
         if ($setSubtype) {
             $subtypeList = array();
             $subtypeList[$setSubtype] = $subtypes[$setSubtype];
         } else {
             $subtypeList = $subtypes;
         }
         $sel = $form->add('select', $name, $title, $subtypeList, $required);
         $sel->setMultiple(TRUE);
     } elseif (in_array($fieldName, CRM_Contact_BAO_Contact::$_greetingTypes)) {
         //add email greeting, postal greeting, addressee, CRM-4575
         $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
         $profileType = CRM_Core_BAO_UFField::getProfileType($gId, TRUE, FALSE, TRUE);
         if (empty($profileType) || in_array($profileType, array('Contact', 'Contribution', 'Participant', 'Membership'))) {
             $profileType = 'Individual';
         }
         if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
             $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
         }
         $greeting = array('contact_type' => $profileType, 'greeting_type' => $fieldName);
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($greeting), $required);
         // add custom greeting element
         $form->add('text', $fieldName . '_custom', ts('Custom %1', array(1 => ucwords(str_replace('_', ' ', $fieldName)))), NULL, FALSE);
     } elseif ($fieldName === 'preferred_communication_method') {
         $communicationFields = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
         foreach ($communicationFields as $key => $var) {
             if ($key == '') {
                 continue;
             }
             $communicationOptions[] = $form->createElement('checkbox', $key, NULL, $var);
         }
         $form->addGroup($communicationOptions, $name, $title, '<br/>');
     } elseif ($fieldName === 'preferred_mail_format') {
         $form->add('select', $name, $title, CRM_Core_SelectValues::pmf());
     } elseif ($fieldName === 'preferred_language') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contact_BAO_Contact::buildOptions('preferred_language'));
     } elseif ($fieldName == 'external_identifier') {
         $form->add('text', $name, $title, $attributes, $required);
         $contID = $contactId;
         if (!$contID) {
             $contID = $form->get('id');
         }
         $form->addRule($name, ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $contID, 'external_identifier'));
     } elseif ($fieldName === 'group') {
         CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, TRUE, $required, $title, NULL, $name);
     } elseif ($fieldName === 'tag') {
         CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::TAG, FALSE, $required, NULL, $title, $name);
     } elseif (substr($fieldName, 0, 4) === 'url-') {
         $form->add('text', $name, $title, array_merge(CRM_Core_DAO::getAttribute('CRM_Core_DAO_Website', 'url'), array('onfocus' => "if (!this.value) {  this.value='http://';} else return false", 'onblur' => "if ( this.value == 'http://') {  this.value='';} else return false")), $required);
         $form->addRule($name, ts('Enter a valid Website.'), 'url');
     } elseif (substr($fieldName, -4) == 'note') {
         $form->add('textarea', $name, $title, $attributes, $required);
     } elseif (substr($fieldName, 0, 6) === 'custom') {
         $customFieldID = CRM_Core_BAO_CustomField::getKeyID($fieldName);
         if ($customFieldID) {
             CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title);
         }
     } elseif (substr($fieldName, 0, 14) === 'address_custom') {
         list($fName, $locTypeId) = CRM_Utils_System::explode('-', $fieldName, 2);
         $customFieldID = CRM_Core_BAO_CustomField::getKeyID(substr($fName, 8));
         if ($customFieldID) {
             CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title);
         }
     } elseif (in_array($fieldName, array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) {
         $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
     } elseif ($fieldName == 'send_receipt') {
         $form->addElement('checkbox', $name, $title);
     } elseif ($fieldName == 'soft_credit') {
         $form->addEntityRef("soft_credit_contact_id[{$rowNumber}]", ts('Soft Credit To'), array('create' => TRUE));
         $form->addMoney("soft_credit_amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE);
     } elseif ($fieldName == 'product_name') {
         list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo();
         $sel =& $form->addElement('hierselect', $name, $title);
         $products = array('0' => ts('- select -')) + $products;
         $sel->setOptions(array($products, $options));
     } elseif ($fieldName == 'payment_instrument') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required);
     } else {
         if ($fieldName == 'financial_type') {
             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType(), $required);
         } elseif ($fieldName == 'contribution_status_id') {
             $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus();
             $statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
             foreach (array('In Progress', 'Overdue', 'Refunded') as $suppress) {
                 unset($contributionStatuses[CRM_Utils_Array::key($suppress, $statusName)]);
             }
             $form->add('select', $name, $title, array('' => ts('- select -')) + $contributionStatuses, $required);
         } elseif ($fieldName == 'soft_credit_type') {
             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_OptionGroup::values("soft_credit_type"));
             $form->addElement('hidden', 'sct_default_id', CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"), array('id' => 'sct_default_id'));
         } elseif ($fieldName == 'currency') {
             $form->addCurrency($name, $title, $required);
         } elseif ($fieldName == 'contribution_page_id') {
             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage(), $required, 'class="big"');
         } elseif ($fieldName == 'participant_register_date') {
             $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
         } elseif ($fieldName == 'activity_status_id') {
             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::activityStatus(), $required);
         } elseif ($fieldName == 'activity_engagement_level') {
             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Campaign_PseudoConstant::engagementLevel(), $required);
         } elseif ($fieldName == 'activity_date_time') {
             $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
         } elseif ($fieldName == 'participant_status') {
             $cond = NULL;
             if ($online == TRUE) {
                 $cond = 'visibility_id = 1';
             }
             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantStatus(NULL, $cond, 'label'), $required);
         } elseif ($fieldName == 'participant_role') {
             if (!empty($field['is_multiple'])) {
                 $form->addCheckBox($name, $title, CRM_Event_PseudoConstant::participantRole(), NULL, NULL, NULL, NULL, '&nbsp', TRUE);
             } else {
                 $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantRole(), $required);
             }
         } elseif ($fieldName == 'world_region') {
             $form->add('select', $name, $title, CRM_Core_PseudoConstant::worldRegion(), $required, $selectAttributes);
         } elseif ($fieldName == 'signature_html') {
             $form->addWysiwyg($name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName));
         } elseif ($fieldName == 'signature_text') {
             $form->add('textarea', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName));
         } elseif (substr($fieldName, -11) == 'campaign_id') {
             if (CRM_Campaign_BAO_Campaign::isCampaignEnable()) {
                 $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(CRM_Utils_Array::value($contactId, $form->_componentCampaigns));
                 $form->add('select', $name, $title, array('' => ts('- select -')) + $campaigns, $required, 'class="crm-select2 big"');
             }
         } elseif ($fieldName == 'activity_details') {
             $form->addWysiwyg($fieldName, $title, array('rows' => 4, 'cols' => 60), $required);
         } elseif ($fieldName == 'activity_duration') {
             $form->add('text', $name, $title, $attributes, $required);
             $form->addRule($name, ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger');
         } else {
             if (substr($fieldName, 0, 3) === 'is_' or substr($fieldName, 0, 7) === 'do_not_') {
                 $form->add('advcheckbox', $name, $title, $attributes, $required);
             } else {
                 $form->add('text', $name, $title, $attributes, $required);
             }
         }
     }
     static $hiddenSubtype = FALSE;
     if (!$hiddenSubtype && CRM_Contact_BAO_ContactType::isaSubType($field['field_type'])) {
         // In registration mode params are submitted via POST and we don't have any clue
         // about profile-id or the profile-type (which could be a subtype)
         // To generalize the  behavior and simplify the process,
         // lets always add the hidden
         //subtype value if there is any, and we won't have to
         // compute it while processing.
         if ($usedFor) {
             $form->addElement('hidden', $usedFor . '[contact_sub_type]', $field['field_type']);
         } else {
             $form->addElement('hidden', 'contact_sub_type_hidden', $field['field_type']);
         }
         $hiddenSubtype = TRUE;
     }
     if ($view && $mode != CRM_Profile_Form::MODE_SEARCH || $isShared) {
         $form->freeze($name);
     }
     //add the rules
     if (in_array($fieldName, array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) {
         $form->addRule($name, ts('Please enter a valid amount.'), 'money');
     }
     if ($rule) {
         if (!($rule == 'email' && $mode == CRM_Profile_Form::MODE_SEARCH)) {
             $form->addRule($name, ts('Please enter a valid %1', array(1 => $title)), $rule);
         }
     }
 }