Esempio n. 1
0
 /**
  * Build the form object.
  *
  *
  * @param CRM_Core_Form $form
  * @param $proxSearch
  *
  * @return void
  */
 public function buildQuickForm($form, $proxSearch)
 {
     // is proximity search required (2) or optional (1)?
     $proxRequired = $proxSearch == 2 ? TRUE : FALSE;
     $form->assign('proximity_search', TRUE);
     $form->add('text', 'prox_street_address', ts('Street Address'), NULL, FALSE);
     $form->add('text', 'prox_city', ts('City'), NULL, FALSE);
     $form->add('text', 'prox_postal_code', ts('Postal Code'), NULL, FALSE);
     $form->addChainSelect('prox_state_province_id', array('required' => $proxRequired));
     $country = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
     $form->add('select', 'prox_country_id', ts('Country'), $country, $proxRequired);
     $form->add('text', 'prox_distance', ts('Distance'), NULL, $proxRequired);
     $proxUnits = array('km' => ts('km'), 'miles' => ts('miles'));
     $form->add('select', 'prox_distance_unit', ts('Units'), $proxUnits, $proxRequired);
     // prox_distance_unit
     $form->addFormRule(array('CRM_Contact_Form_Task_ProximityCommon', 'formRule'), $form);
 }
Esempio n. 2
0
 /**
  * Add the payment fields to the template.
  *
  * Generally this is the payment processor fields & the billing fields required
  * for the payment processor. However, this has been complicated by adding
  * pay later billing fields into this mix
  *
  * We now have the situation where the required fields cannot be set as required
  * on the form level if they are required for the payment processor, as another
  * processor might be selected and the validation will then be incorrect.
  *
  * However, if they are required for pay later we DO set them on the form level,
  * presumably assuming they will be required whatever happens.
  *
  * As a side-note this seems to re-enforce the argument for making pay later
  * operate as a payment processor rather than as a 'special thing on its own'.
  *
  * @param CRM_Core_Form $form
  *   Form that the payment fields are to be added to.
  * @param array $paymentFields
  *   Fields that are to be shown on the payment form.
  */
 protected static function addCommonFields(&$form, $paymentFields)
 {
     $requiredPaymentFields = array();
     foreach ($paymentFields as $name => $field) {
         if (!empty($field['cc_field'])) {
             if ($field['htmlType'] == 'chainSelect') {
                 $form->addChainSelect($field['name'], array('required' => FALSE));
             } else {
                 $form->add($field['htmlType'], $field['name'], $field['title'], $field['attributes'], FALSE);
             }
         }
         // This will cause the fields to be marked as required - but it is up to the payment processor to
         // validate it.
         $requiredPaymentFields[$field['name']] = $field['is_required'];
     }
     $form->assign('requiredPaymentFields', $requiredPaymentFields);
 }
Esempio n. 3
0
 /**
  * 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
  */
 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 NULL;
     }
     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);
     if ($fieldName == 'image_URL' && $mode == CRM_Profile_Form::MODE_EDIT) {
         $deleteExtra = json_encode(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 = "' . htmlspecialchars("if (confirm({$deleteExtra})) this.href+='&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') {
         $form->addChainSelect($name, array('label' => $title, 'required' => $required));
         $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']) {
             $form->addChainSelect($name, array('label' => $title, 'required' => $required));
         }
     } 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' => 'activityDate'));
     } 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 (in_array($fieldName, array('gender_id', 'communication_style_id'))) {
         $options = array();
         $pseudoValues = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', $fieldName);
         foreach ($pseudoValues as $key => $var) {
             $options[$key] = $form->createElement('radio', NULL, ts($title), $var, $key);
         }
         $group = $form->addGroup($options, $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;
         }
         $form->add('select', $name, $title, $subtypeList, $required, array('class' => 'crm-select2', 'multiple' => 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, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Website', 'url'), $required);
         $form->addRule($name, ts('Enter a valid web address beginning with \'http://\' or \'https://\'.'), '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);
     } elseif ($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') {
         $name = "soft_credit_type[{$rowNumber}]";
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_OptionGroup::values("soft_credit_type"));
         //CRM-15350: choose SCT field default value as 'Gift' for membership use
         //else (for contribution), use configured SCT default value
         $SCTDefaultValue = CRM_Core_OptionGroup::getDefaultValue("soft_credit_type");
         if ($field['field_type'] == 'Membership') {
             $SCTDefaultValue = CRM_Core_OptionGroup::getValue('soft_credit_type', 'Gift', 'name');
         }
         $form->addElement('hidden', 'sct_default_id', $SCTDefaultValue, 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->add('wysiwyg', $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->add('wysiwyg', $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);
         }
     }
 }
Esempio n. 4
0
 /**
  * @param CRM_Core_Form $form
  * @param bool $useRequired
  * @param array $paymentFields
  */
 protected static function addCommonFields(&$form, $useRequired, $paymentFields)
 {
     foreach ($paymentFields as $name => $field) {
         if (!empty($field['cc_field'])) {
             if ($field['htmlType'] == 'chainSelect') {
                 $form->addChainSelect($field['name'], array('required' => $useRequired && $field['is_required']));
             } else {
                 $form->add($field['htmlType'], $field['name'], $field['title'], $field['attributes'], $useRequired ? $field['is_required'] : FALSE);
             }
         }
     }
 }
Esempio n. 5
0
 /**
  * Add the payment fields to the template.
  *
  * Generally this is the payment processor fields & the billing fields required
  * for the payment processor. However, this has been complicated by adding
  * pay later billing fields into this mix
  *
  * We now have the situation where the required fields cannot be set as required
  * on the form level if they are required for the payment processor, as another
  * processor might be selected and the validation will then be incorrect.
  *
  * However, if they are required for pay later we DO set them on the form level,
  * presumably assuming they will be required whatever happens.
  *
  * As a side-note this seems to re-enforce the argument for making pay later
  * operate as a payment processor rather than as a 'special thing on its own'.
  *
  * @param CRM_Core_Form $form
  *   Form that the payment fields are to be added to.
  * @param bool $useRequired
  *   Effectively this means are the fields required for pay-later - see above.
  * @param array $paymentFields
  *   Fields that are to be shown on the payment form.
  */
 protected static function addCommonFields(&$form, $useRequired, $paymentFields)
 {
     $requiredPaymentFields = array();
     foreach ($paymentFields as $name => $field) {
         if (!empty($field['cc_field'])) {
             if ($field['htmlType'] == 'chainSelect') {
                 $form->addChainSelect($field['name'], array('required' => $useRequired && $field['is_required']));
             } else {
                 $form->add($field['htmlType'], $field['name'], $field['title'], $field['attributes'], $useRequired ? $field['is_required'] : FALSE);
             }
         }
         // CRM-17071 We seem to be tying ourselves in knots around the addition
         // of requiring billing fields for pay-later. Here we 'tell' the form the
         // field is required if it is not otherwise marked as required and is
         // required for the billing block.
         $requiredPaymentFields[$field['name']] = !$useRequired ? $field['is_required'] : FALSE;
     }
     $form->assign('requiredPaymentFields', $requiredPaymentFields);
 }
Esempio n. 6
0
 /**
  * Build form for address input fields.
  *
  * @param CRM_Core_Form $form
  * @param int $addressBlockCount
  *   The index of the address array (if multiple addresses on a page).
  * @param bool $sharing
  *   False, if we want to skip the address sharing features.
  * @param bool $inlineEdit
  *   True when edit used in inline edit.
  *
  * @return void
  *
  */
 public static function buildQuickForm(&$form, $addressBlockCount = NULL, $sharing = TRUE, $inlineEdit = FALSE)
 {
     // passing this via the session is AWFUL. we need to fix this
     if (!$addressBlockCount) {
         $blockId = $form->get('Address_Block_Count') ? $form->get('Address_Block_Count') : 1;
     } else {
         $blockId = $addressBlockCount;
     }
     $config = CRM_Core_Config::singleton();
     $countryDefault = $config->defaultContactCountry;
     $form->applyFilter('__ALL__', 'trim');
     $js = array();
     if (!$inlineEdit) {
         $js = array('onChange' => 'checkLocation( this.id );', 'placeholder' => NULL);
     }
     //make location type required for inline edit
     $form->addSelect("address[{$blockId}][location_type_id]", array('entity' => 'address', 'class' => 'eight') + $js, $inlineEdit);
     if (!$inlineEdit) {
         $js = array('id' => 'Address_' . $blockId . '_IsPrimary', 'onClick' => 'singleSelect( this.id );');
     }
     $form->addElement('checkbox', "address[{$blockId}][is_primary]", ts('Primary location for this contact'), ts('Primary location for this contact'), $js);
     if (!$inlineEdit) {
         $js = array('id' => 'Address_' . $blockId . '_IsBilling', 'onClick' => 'singleSelect( this.id );');
     }
     $form->addElement('checkbox', "address[{$blockId}][is_billing]", ts('Billing location for this contact'), ts('Billing location for this contact'), $js);
     // hidden element to store master address id
     $form->addElement('hidden', "address[{$blockId}][master_id]");
     $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE);
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address');
     $elements = array('address_name' => array(ts('Address Name'), $attributes['address_name'], NULL), 'street_address' => array(ts('Street Address'), $attributes['street_address'], NULL), 'supplemental_address_1' => array(ts('Supplemental Address 1'), $attributes['supplemental_address_1'], NULL), 'supplemental_address_2' => array(ts('Supplemental Address 2'), $attributes['supplemental_address_2'], NULL), 'city' => array(ts('City'), $attributes['city'], NULL), 'postal_code' => array(ts('Zip / Postal Code'), array_merge($attributes['postal_code'], array('class' => 'crm_postal_code')), NULL), 'postal_code_suffix' => array(ts('Postal Code Suffix'), array('size' => 4, 'maxlength' => 12, 'class' => 'crm_postal_code_suffix'), NULL), 'country_id' => array(ts('Country'), $attributes['country_id'], 'country'), 'state_province_id' => array(ts('State/Province'), $attributes['state_province_id'], NULL), 'county_id' => array(ts('County'), $attributes['county_id'], NULL), 'geo_code_1' => array(ts('Latitude'), array('size' => 9, 'maxlength' => 12), NULL), 'geo_code_2' => array(ts('Longitude'), array('size' => 9, 'maxlength' => 12), NULL), 'street_number' => array(ts('Street Number'), $attributes['street_number'], NULL), 'street_name' => array(ts('Street Name'), $attributes['street_name'], NULL), 'street_unit' => array(ts('Apt/Unit/Suite'), $attributes['street_unit'], NULL));
     foreach ($elements as $name => $v) {
         list($title, $attributes, $select) = $v;
         $nameWithoutID = strpos($name, '_id') !== FALSE ? substr($name, 0, -3) : $name;
         if (empty($addressOptions[$nameWithoutID])) {
             $continue = TRUE;
             if (in_array($nameWithoutID, array('street_number', 'street_name', 'street_unit')) && !empty($addressOptions['street_address_parsing'])) {
                 $continue = FALSE;
             }
             if ($continue) {
                 continue;
             }
         }
         //build normal select if country is not present in address block
         if ($name == 'state_province_id' && !$addressOptions['country']) {
             $select = 'stateProvince';
         }
         if (!$select) {
             if ($name == 'state_province_id' || $name == 'county_id') {
                 $form->addChainSelect("address[{$blockId}][{$name}]");
             } else {
                 if ($name == 'address_name') {
                     $name = 'name';
                 }
                 $form->addElement('text', "address[{$blockId}][{$name}]", $title, $attributes);
             }
         } else {
             $form->addElement('select', "address[{$blockId}][{$name}]", $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select());
         }
     }
     $entityId = NULL;
     if (!empty($form->_values['address']) && !empty($form->_values['address'][$blockId])) {
         $entityId = $form->_values['address'][$blockId]['id'];
     }
     // CRM-11665 geocode override option
     $geoCode = FALSE;
     if (!empty($config->geocodeMethod)) {
         $geoCode = TRUE;
         $form->addElement('checkbox', "address[{$blockId}][manual_geo_code]", ts('Override automatic geocoding'));
     }
     $form->assign('geoCode', $geoCode);
     // Process any address custom data -
     $groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', $form, $entityId);
     if (isset($groupTree) && is_array($groupTree)) {
         // use simplified formatted groupTree
         $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $form);
         // make sure custom fields are added /w element-name in the format - 'address[$blockId][custom-X]'
         foreach ($groupTree as $id => $group) {
             foreach ($group['fields'] as $fldId => $field) {
                 $groupTree[$id]['fields'][$fldId]['element_custom_name'] = $field['element_name'];
                 $groupTree[$id]['fields'][$fldId]['element_name'] = "address[{$blockId}][{$field['element_name']}]";
             }
         }
         $defaults = array();
         CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults);
         // since we change element name for address custom data, we need to format the setdefault values
         $addressDefaults = array();
         foreach ($defaults as $key => $val) {
             if (empty($val)) {
                 continue;
             }
             // inorder to set correct defaults for checkbox custom data, we need to converted flat key to array
             // this works for all types custom data
             $keyValues = explode('[', str_replace(']', '', $key));
             $addressDefaults[$keyValues[0]][$keyValues[1]][$keyValues[2]] = $val;
         }
         $form->setDefaults($addressDefaults);
         // we setting the prefix to 'dnc_' below, so that we don't overwrite smarty's grouptree var.
         // And we can't set it to 'address_' because we want to set it in a slightly different format.
         CRM_Core_BAO_CustomGroup::buildQuickForm($form, $groupTree, FALSE, 'dnc_');
         // during contact editing : if no address is filled
         // required custom data must not produce 'required' form rule error
         // more handling done in formRule func
         if (!$inlineEdit) {
             CRM_Contact_Form_Edit_Address::storeRequiredCustomDataInfo($form, $groupTree);
         }
         $template = CRM_Core_Smarty::singleton();
         $tplGroupTree = $template->get_template_vars('address_groupTree');
         $tplGroupTree = empty($tplGroupTree) ? array() : $tplGroupTree;
         $form->assign('address_groupTree', $tplGroupTree + array($blockId => $groupTree));
         // unset the temp smarty var that got created
         $form->assign('dnc_groupTree', NULL);
     }
     // address custom data processing ends ..
     if ($sharing) {
         // shared address
         $form->addElement('checkbox', "address[{$blockId}][use_shared_address]", NULL, ts('Use another contact\'s address'));
         // Override the default profile links to add address form
         $profileLinks = CRM_Core_BAO_UFGroup::getCreateLinks(array('new_individual', 'new_organization', 'new_household'), 'shared_address');
         $form->addEntityRef("address[{$blockId}][master_contact_id]", ts('Share With'), array('create' => $profileLinks));
     }
 }
Esempio n. 7
0
 /**
  * @param CRM_Core_Form $form
  */
 public static function location(&$form)
 {
     $config = CRM_Core_Config::singleton();
     // Build location criteria based on _submitValues if
     // available; otherwise, use $form->_formValues.
     $formValues = $form->_submitValues;
     if (empty($formValues) && !empty($form->_formValues)) {
         $formValues = $form->_formValues;
     }
     $form->addElement('hidden', 'hidden_location', 1);
     $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE);
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address');
     $elements = array('street_address' => array(ts('Street Address'), $attributes['street_address'], NULL, NULL), 'city' => array(ts('City'), $attributes['city'], NULL, NULL), 'postal_code' => array(ts('Zip / Postal Code'), $attributes['postal_code'], NULL, NULL), 'country' => array(ts('Country'), $attributes['country_id'], 'country', FALSE), 'state_province' => array(ts('State/Province'), $attributes['state_province_id'], 'stateProvince', TRUE), 'county' => array(ts('County'), $attributes['county_id'], 'county', TRUE), 'address_name' => array(ts('Address Name'), $attributes['address_name'], NULL, NULL), 'street_number' => array(ts('Street Number'), $attributes['street_number'], NULL, NULL), 'street_name' => array(ts('Street Name'), $attributes['street_name'], NULL, NULL), 'street_unit' => array(ts('Apt/Unit/Suite'), $attributes['street_unit'], NULL, NULL));
     $parseStreetAddress = CRM_Utils_Array::value('street_address_parsing', $addressOptions, 0);
     $form->assign('parseStreetAddress', $parseStreetAddress);
     foreach ($elements as $name => $v) {
         list($title, $attributes, $select, $multiSelect) = $v;
         if (in_array($name, array('street_number', 'street_name', 'street_unit'))) {
             if (!$parseStreetAddress) {
                 continue;
             }
         } elseif (!$addressOptions[$name]) {
             continue;
         }
         if (!$attributes) {
             $attributes = $attributes[$name];
         }
         if ($select) {
             if ($select == 'stateProvince' || $select == 'county') {
                 $element = $form->addChainSelect($name);
             } else {
                 $selectElements = array('' => ts('- any -')) + CRM_Core_PseudoConstant::$select();
                 $element = $form->add('select', $name, $title, $selectElements, FALSE, array('class' => 'crm-select2'));
             }
             if ($multiSelect) {
                 $element->setMultiple(TRUE);
             }
         } else {
             $form->addElement('text', $name, $title, $attributes);
         }
         if ($addressOptions['postal_code']) {
             $attr = array('class' => 'six') + (array) CRM_Utils_Array::value('postal_code', $attributes);
             $form->addElement('text', 'postal_code_low', NULL, $attr + array('placeholder' => ts('From')));
             $form->addElement('text', 'postal_code_high', NULL, $attr + array('placeholder' => ts('To')));
         }
     }
     // extend addresses with proximity search
     if (!empty($config->geocodeMethod)) {
         $form->addElement('text', 'prox_distance', ts('Find contacts within'), array('class' => 'six'));
         $form->addElement('select', 'prox_distance_unit', NULL, array('miles' => ts('Miles'), 'kilos' => ts('Kilometers')));
         $form->addRule('prox_distance', ts('Please enter positive number as a distance'), 'numeric');
     }
     $form->addSelect('world_region', array('entity' => 'address', 'context' => 'search'));
     // select for location type
     $locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
     $form->add('select', 'location_type', ts('Address Location'), $locationType, FALSE, array('multiple' => TRUE, 'class' => 'crm-select2', 'placeholder' => ts('Primary')));
     // custom data extending addresses -
     $extends = array('Address');
     $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends);
     if ($groupDetails) {
         $form->assign('addressGroupTree', $groupDetails);
         foreach ($groupDetails as $group) {
             foreach ($group['fields'] as $field) {
                 $elementName = 'custom_' . $field['id'];
                 CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $field['id'], FALSE, FALSE, TRUE);
             }
         }
     }
 }
 /**
  * @param CRM_Core_Form $form
  */
 public function buildForm(&$form)
 {
     $config = CRM_Core_Config::singleton();
     $countryDefault = $config->defaultContactCountry;
     $form->add('text', 'distance', ts('Distance'), NULL, TRUE);
     $proxUnits = array('km' => ts('km'), 'miles' => ts('miles'));
     $form->add('select', 'prox_distance_unit', ts('Units'), $proxUnits, TRUE);
     $form->add('text', 'street_address', ts('Street Address'));
     $form->add('text', 'city', ts('City'));
     $form->add('text', 'postal_code', ts('Postal Code'));
     $defaults = array();
     if ($countryDefault) {
         $defaults['country_id'] = $countryDefault;
     }
     $form->addChainSelect('state_province_id');
     $country = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
     $form->add('select', 'country_id', ts('Country'), $country, TRUE, array('class' => 'crm-select2'));
     $group = array('' => ts('- any group -')) + CRM_Core_PseudoConstant::nestedGroup();
     $form->addElement('select', 'group', ts('Group'), $group, array('class' => 'crm-select2 huge'));
     $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
     $form->addElement('select', 'tag', ts('Tag'), $tag, array('class' => 'crm-select2 huge'));
     /**
      * You can define a custom title for the search form
      */
     $this->setTitle('Proximity Search');
     /**
      * if you are using the standard template, this array tells the template what elements
      * are part of the search criteria
      */
     $form->assign('elements', array('distance', 'prox_distance_unit', 'street_address', 'city', 'postal_code', 'country_id', 'state_province_id', 'group', 'tag'));
 }
/**
 * Add the billing field to the payment form if required.
 *
 * This requires 4.6.10 or greater due to an earlier bug. 4.7 should not require this.
 *
 * @param CRM_Core_Form $form
 */
function omnipaymultiprocessor_addBillingFieldsTo46Form(&$form)
{
    $billingDetailsFields = omnipaymultiprocessor_getBillingPersonalDetailsFields($form->_paymentProcessor);
    if (!empty($billingDetailsFields)) {
        if (empty($form->_paymentFields)) {
            $form->_paymentFields = $billingDetailsFields;
        }
        $metadata = omnipaymultiprocessor_getBillingPersonalDetailsMetadata($form->_paymentProcessor);
        foreach ($metadata as $name => $field) {
            if (!empty($field['cc_field'])) {
                if (!empty($field['cc_field'])) {
                    if ($field['htmlType'] == 'chainSelect') {
                        $form->addChainSelect($field['name'], array('required' => FALSE));
                    } else {
                        $form->add($field['htmlType'], $field['name'], $field['title'], $field['attributes'], FALSE);
                    }
                }
            }
            $requiredPaymentFields[$field['name']] = $field['is_required'];
        }
        $form->assign('requiredPaymentFields', $requiredPaymentFields);
        $form->assign('billingDetailsFields', $billingDetailsFields);
    }
    $form->billingFieldSets['billing_name_address-group']['fields'] = array();
}