Esempio n. 1
0
 /**
  * Build the form
  *
  * @access public
  *
  * @return void
  */
 function buildQuickForm()
 {
     $ufGroupId = $this->get('ufGroupId');
     if (!$ufGroupId) {
         CRM_Core_Error::fatal('ufGroupId is missing');
     }
     $this->_title = ts('Batch Update') . ' - ' . CRM_Core_BAO_UFGroup::getTitle($ufGroupId);
     CRM_Utils_System::setTitle($this->_title);
     $this->addDefaultButtons(ts('Save'));
     $this->_fields = CRM_Core_BAO_UFGroup::getFields($ufGroupId, FALSE, CRM_Core_Action::VIEW);
     // remove file type field and then limit fields
     $suppressFields = FALSE;
     $removehtmlTypes = array('File', 'Autocomplete-Select');
     foreach ($this->_fields as $name => $field) {
         if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name) && in_array($this->_fields[$name]['html_type'], $removehtmlTypes)) {
             $suppressFields = TRUE;
             unset($this->_fields[$name]);
         }
     }
     //FIX ME: phone ext field is added at the end and it gets removed because of below code
     //$this->_fields = array_slice($this->_fields, 0, $this->_maxFields);
     $this->addButtons(array(array('type' => 'submit', 'name' => ts('Update Contact(s)'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->assign('profileTitle', $this->_title);
     $this->assign('componentIds', $this->_contactIds);
     // if below fields are missing we should not reset sort name / display name
     // CRM-6794
     $preserveDefaultsArray = array('first_name', 'last_name', 'middle_name', 'organization_name', 'prefix_id', 'suffix_id', 'household_name');
     $stateCountryMap = array();
     foreach ($this->_contactIds as $contactId) {
         $profileFields = $this->_fields;
         CRM_Core_BAO_Address::checkContactSharedAddressFields($profileFields, $contactId);
         foreach ($profileFields as $name => $field) {
             // Link state to country, county to state per location per contact
             list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
             if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') {
                 $stateCountryMap["{$index}-{$contactId}"][$prefixName] = "field_{$contactId}_{$field['name']}";
                 $this->_stateCountryCountyFields["{$index}-{$contactId}"][$prefixName] = "field[{$contactId}][{$field['name']}]";
             }
             CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $contactId);
             if (in_array($field['name'], $preserveDefaultsArray)) {
                 $this->_preserveDefault = FALSE;
             }
         }
     }
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
     $this->assign('fields', $this->_fields);
     // don't set the status message when form is submitted.
     $buttonName = $this->controller->getButtonName('submit');
     if ($suppressFields && $buttonName != '_qf_BatchUpdateProfile_next') {
         CRM_Core_Session::setStatus(ts("File or Autocomplete Select type field(s) in the selected profile are not supported for Batch Update and have been excluded."), ts('Some Fields Excluded'), 'info');
     }
     $this->addDefaultButtons(ts('Update Contacts'));
     $this->addFormRule(array('CRM_Contact_Form_Task_Batch', 'formRule'));
 }
Esempio n. 2
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     //lets have single status message, CRM-4363
     $return = false;
     $statusMessage = null;
     //we should not allow component and mix profiles in search mode
     if ($this->_mode != self::MODE_REGISTER) {
         //check for mix profile fields (eg:  individual + other contact type)
         if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) {
             $statusMessage = ts('Profile search, view and edit are not supported for Profiles which include fields for more than one record type.');
         }
         $profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid);
         if ($this->_id) {
             list($contactType, $contactSubType) = CRM_Contact_BAO_Contact::getContactTypes($this->_id);
             if ($profileType != 'Contact' && $contactType != $profileType && !CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
                 $return = true;
                 if (!$statusMessage) {
                     $statusMessage = ts('This profile is not configured for "%1" contact type.', array(1 => $contactType));
                 }
             }
             if ($contactSubType && CRM_Contact_BAO_ContactType::isaSubType($profileType) && $profileType != $contactSubType) {
                 $return = true;
                 if (!$statusMessage) {
                     $statusMessage = ts('This profile is not configured for "%1" contact subtype.', array(1 => $contactSubType));
                 }
             }
         }
         if (in_array($profileType, array("Membership", "Participant", "Contribution"))) {
             $return = true;
             if (!$statusMessage) {
                 $statusMessage = ts('Profile is not configured for the selected action.');
             }
         }
     }
     //lets have sigle status message,
     $this->assign('statusMessage', $statusMessage);
     if ($return) {
         return false;
     }
     $sBlocks = array();
     $hBlocks = array();
     $config =& CRM_Core_Config::singleton();
     $this->assign('id', $this->_id);
     $this->assign('mode', $this->_mode);
     $this->assign('action', $this->_action);
     $this->assign_by_ref('fields', $this->_fields);
     $this->assign('fieldset', isset($this->_fieldset) ? $this->_fieldset : "");
     // do we need inactive options ?
     if ($this->_action & CRM_Core_Action::VIEW) {
         $inactiveNeeded = true;
     } else {
         $inactiveNeeded = false;
     }
     $session =& CRM_Core_Session::singleton();
     // should we restrict what we display
     $admin = true;
     if ($this->_mode == self::MODE_EDIT) {
         $admin = false;
         // show all fields that are visibile: if we are a admin or the same user or in registration mode
         if (CRM_Core_Permission::check('administer users') || $this->_id == $session->get('userID')) {
             $admin = true;
         }
     }
     $userID = $session->get('userID');
     $anonUser = false;
     // if false, user is not logged-in.
     if (!$userID) {
         require_once 'CRM/Core/BAO/LocationType.php';
         $defaultLocationType =& CRM_Core_BAO_LocationType::getDefault();
         $primaryLocationType = $defaultLocationType->id;
         $anonUser = true;
         $this->assign('anonUser', true);
     }
     $addCaptcha = array();
     $emailPresent = false;
     // cache the state country fields. based on the results, we could use our javascript solution
     // in create or register mode
     $stateCountryMap = array();
     // add the form elements
     foreach ($this->_fields as $name => $field) {
         // make sure that there is enough permission to expose this field
         if (!$admin && $field['visibility'] == 'User and User Admin Only' || CRM_Utils_Array::value('is_view', $field)) {
             unset($this->_fields[$name]);
             continue;
         }
         // since the CMS manages the email field, suppress the email display if in
         // register mode which occur within the CMS form
         if ($this->_mode == self::MODE_REGISTER && substr($name, 0, 5) == 'email') {
             unset($this->_fields[$name]);
             continue;
         }
         list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
         if ($prefixName == 'state_province' || $prefixName == 'country') {
             if (!array_key_exists($index, $stateCountryMap)) {
                 $stateCountryMap[$index] = array();
             }
             $stateCountryMap[$index][$prefixName] = $name;
         }
         CRM_Core_BAO_UFGroup::buildProfile($this, $field, $this->_mode);
         if ($field['add_to_group_id']) {
             $addToGroupId = $field['add_to_group_id'];
         }
         //build array for captcha
         if ($field['add_captcha']) {
             $addCaptcha[$field['group_id']] = $field['add_captcha'];
         }
         if ($name == 'email-Primary' || ($name == 'email-' . isset($primaryLocationType) ? $primaryLocationType : "")) {
             $emailPresent = true;
             $this->_mail = $name;
         }
     }
     $setCaptcha = false;
     // do this only for CiviCRM created forms
     if ($this->_mode == self::MODE_CREATE) {
         if (!empty($addCaptcha)) {
             $setCaptcha = true;
         }
         if ($this->_gid) {
             $dao = new CRM_Core_DAO_UFGroup();
             $dao->id = $this->_gid;
             $dao->addSelect();
             $dao->addSelect('add_captcha', 'is_update_dupe');
             if ($dao->find(true)) {
                 if ($dao->add_captcha) {
                     $setCaptcha = true;
                 }
                 if ($dao->is_update_dupe) {
                     $this->_isUpdateDupe = true;
                 }
             }
         }
         if ($setCaptcha) {
             require_once 'CRM/Utils/ReCAPTCHA.php';
             $captcha =& CRM_Utils_ReCAPTCHA::singleton();
             $captcha->add($this);
             $this->assign("isCaptcha", true);
         }
     }
     if ($this->_mode != self::MODE_SEARCH) {
         if (isset($addToGroupId)) {
             $this->add('hidden', "group[{$addToGroupId}]", 1);
             $this->_addToGroupID = $addToGroupId;
         }
     }
     // also do state country js
     require_once 'CRM/Core/BAO/Address.php';
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap, $this->_defaults);
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, false, null);
     if ($this->_mode == self::MODE_CREATE) {
         require_once 'CRM/Core/BAO/CMSUser.php';
         CRM_Core_BAO_CMSUser::buildForm($this, $this->_gid, $emailPresent, $action);
     } else {
         $this->assign('showCMS', false);
     }
     $this->assign('groupId', $this->_gid);
     // now fix all state country selectors
     require_once 'CRM/Core/BAO/Address.php';
     CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
     // if view mode pls freeze it with the done button.
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
     }
     if ($this->_context == 'dialog') {
         $this->addElement('submit', $this->_duplicateButtonName, ts('Save Matching Contact'));
     }
 }
 /**
  * Build the form
  *
  * @access public
  *
  * @return void
  */
 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);
     $defaults = self::setDefaultValues($form);
     if (CRM_Utils_Array::value('prox_country_id', $defaults)) {
         $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($defaults['prox_country_id']);
     } else {
         $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince();
     }
     $form->add('select', 'prox_state_province_id', ts('State/Province'), $stateProvince, $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
     // state country js, CRM-5233
     $stateCountryMap = array();
     $stateCountryMap[] = array('state_province' => 'prox_state_province_id', 'country' => 'prox_country_id');
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
     CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
     $form->addFormRule(array('CRM_Contact_Form_Task_ProximityCommon', 'formRule'), $form);
 }
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     //lets have single status message, CRM-4363
     $return = FALSE;
     $statusMessage = NULL;
     CRM_Core_BAO_Address::checkContactSharedAddressFields($this->_fields, $this->_id);
     //we should not allow component and mix profiles in search mode
     if ($this->_mode != self::MODE_REGISTER) {
         //check for mix profile fields (eg:  individual + other contact type)
         if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) {
             if ($this->_mode & self::MODE_EDIT && $this->_isContactActivityProfile) {
                 $errors = self::validateContactActivityProfile($this->_activityId, $this->_id, $this->_gid);
                 if (!empty($errors)) {
                     $statusMessage = array_pop($errors);
                     $return = TRUE;
                 }
             } else {
                 $statusMessage = ts('Profile search, view and edit are not supported for Profiles which include fields for more than one record type.');
                 $return = TRUE;
             }
         }
         $profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid);
         if ($this->_id) {
             $contactTypes = CRM_Contact_BAO_Contact::getContactTypes($this->_id);
             $contactType = $contactTypes[0];
             array_shift($contactTypes);
             $contactSubtypes = $contactTypes;
             $profileSubType = FALSE;
             if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
                 $profileSubType = $profileType;
                 $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
             }
             if ($profileType != 'Contact' && !$this->_isContactActivityProfile && ($profileSubType && !empty($contactSubtypes) && !in_array($profileSubType, $contactSubtypes) || $profileType != $contactType)) {
                 $return = TRUE;
                 if (!$statusMessage) {
                     $statusMessage = ts("This profile is configured for contact type '%1'. It cannot be used to edit contacts of other types.", array(1 => $profileSubType ? $profileSubType : $profileType));
                 }
             }
         }
         if (in_array($profileType, array("Membership", "Participant", "Contribution"))) {
             $return = TRUE;
             if (!$statusMessage) {
                 $statusMessage = ts('Profile is not configured for the selected action.');
             }
         }
     }
     //lets have sigle status message,
     $this->assign('statusMessage', $statusMessage);
     if ($return) {
         return FALSE;
     }
     $sBlocks = array();
     $hBlocks = array();
     $config = CRM_Core_Config::singleton();
     $this->assign('id', $this->_id);
     $this->assign('mode', $this->_mode);
     $this->assign('action', $this->_action);
     $this->assign_by_ref('fields', $this->_fields);
     $this->assign('fieldset', isset($this->_fieldset) ? $this->_fieldset : "");
     // do we need inactive options ?
     if ($this->_action & CRM_Core_Action::VIEW) {
         $inactiveNeeded = TRUE;
     } else {
         $inactiveNeeded = FALSE;
     }
     $session = CRM_Core_Session::singleton();
     // should we restrict what we display
     $admin = TRUE;
     if ($this->_mode == self::MODE_EDIT) {
         $admin = FALSE;
         // show all fields that are visibile:
         // if we are a admin OR the same user OR acl-user with access to the profile
         // or we have checksum access to this contact (i.e. the user without a login) - CRM-5909
         if (CRM_Core_Permission::check('administer users') || $this->_id == $session->get('userID') || $this->_isPermissionedChecksum || in_array($this->_gid, CRM_ACL_API::group(CRM_Core_Permission::EDIT, NULL, 'civicrm_uf_group', CRM_Core_PseudoConstant::ufGroup()))) {
             $admin = TRUE;
         }
     }
     $userID = $session->get('userID');
     // if false, user is not logged-in.
     $anonUser = FALSE;
     if (!$userID) {
         $defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
         $primaryLocationType = $defaultLocationType->id;
         $anonUser = TRUE;
         $this->assign('anonUser', TRUE);
     }
     $addCaptcha = array();
     $emailPresent = FALSE;
     // cache the state country fields. based on the results, we could use our javascript solution
     // in create or register mode
     $stateCountryMap = array();
     // add the form elements
     foreach ($this->_fields as $name => $field) {
         // make sure that there is enough permission to expose this field
         if (!$admin && $field['visibility'] == 'User and User Admin Only') {
             unset($this->_fields[$name]);
             continue;
         }
         // since the CMS manages the email field, suppress the email display if in
         // register mode which occur within the CMS form
         if ($this->_mode == self::MODE_REGISTER && substr($name, 0, 5) == 'email') {
             unset($this->_fields[$name]);
             continue;
         }
         list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
         if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') {
             if (!array_key_exists($index, $stateCountryMap)) {
                 $stateCountryMap[$index] = array();
             }
             $stateCountryMap[$index][$prefixName] = $name;
         }
         CRM_Core_BAO_UFGroup::buildProfile($this, $field, $this->_mode);
         if ($field['add_to_group_id']) {
             $addToGroupId = $field['add_to_group_id'];
         }
         //build array for captcha
         if ($field['add_captcha']) {
             $addCaptcha[$field['group_id']] = $field['add_captcha'];
         }
         if ($name == 'email-Primary' || ($name == 'email-' . isset($primaryLocationType) ? $primaryLocationType : "")) {
             $emailPresent = TRUE;
             $this->_mail = $name;
         }
     }
     // add captcha only for create mode.
     if ($this->_mode == self::MODE_CREATE) {
         if (!$this->_isAddCaptcha && !empty($addCaptcha)) {
             $this->_isAddCaptcha = TRUE;
         }
         if ($this->_gid) {
             $dao = new CRM_Core_DAO_UFGroup();
             $dao->id = $this->_gid;
             $dao->addSelect();
             $dao->addSelect('add_captcha', 'is_update_dupe');
             if ($dao->find(TRUE)) {
                 if ($dao->add_captcha) {
                     $setCaptcha = TRUE;
                 }
                 if ($dao->is_update_dupe) {
                     $this->_isUpdateDupe = $dao->is_update_dupe;
                 }
             }
         }
     } else {
         $this->_isAddCaptcha = FALSE;
     }
     //finally add captcha to form.
     if ($this->_isAddCaptcha) {
         $captcha = CRM_Utils_ReCAPTCHA::singleton();
         $captcha->add($this);
     }
     $this->assign("isCaptcha", $this->_isAddCaptcha);
     if ($this->_mode != self::MODE_SEARCH) {
         if (isset($addToGroupId)) {
             $this->add('hidden', "add_to_group", $addToGroupId);
             $this->_addToGroupID = $addToGroupId;
         }
     }
     // also do state country js
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap, $this->_defaults);
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, NULL);
     if ($this->_mode == self::MODE_CREATE) {
         CRM_Core_BAO_CMSUser::buildForm($this, $this->_gid, $emailPresent, $action);
     } else {
         $this->assign('showCMS', FALSE);
     }
     $this->assign('groupId', $this->_gid);
     // now fix all state country selectors
     CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
     // if view mode pls freeze it with the done button.
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
     }
     if ($this->_context == 'dialog') {
         $this->addElement('submit', $this->_duplicateButtonName, ts('Save Matching Contact'));
     }
     $this->setDefaultsValues();
 }
Esempio n. 5
0
 /**
  * build form for address input fields 
  *
  * @param object $form - CRM_Core_Form (or subclass)
  * @param array reference $location - location array
  * @param int $locationId - location id whose block needs to be built.
  * @return none
  *
  * @access public
  * @static
  */
 static function buildQuickForm(&$form)
 {
     $blockId = $form->get('Address_Block_Count') ? $form->get('Address_Block_Count') : 1;
     $config =& CRM_Core_Config::singleton();
     $countryDefault = $config->defaultContactCountry;
     $form->applyFilter('__ALL__', 'trim');
     $js = array('onChange' => 'checkLocation( this.id );');
     $form->addElement('select', "address[{$blockId}][location_type_id]", ts('Location Type'), array('' => ts('- select -')) + CRM_Core_PseudoConstant::locationType(), $js);
     $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);
     $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);
     require_once 'CRM/Core/BAO/Preferences.php';
     $addressOptions = CRM_Core_BAO_Preferences::valueOptions('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('Addt\'l Address 1'), $attributes['supplemental_address_1'], null), 'supplemental_address_2' => array(ts('Addt\'l Address 2'), $attributes['supplemental_address_2'], null), 'city' => array(ts('City'), $attributes['city'], null), 'postal_code' => array(ts('Zip / Postal Code'), $attributes['postal_code'], null), 'postal_code_suffix' => array(ts('Postal Code Suffix'), array('size' => 4, 'maxlength' => 12), null), 'county_id' => array(ts('County'), $attributes['county_id'], 'county'), 'state_province_id' => array(ts('State / Province'), $attributes['state_province_id'], null), 'country_id' => array(ts('Country'), $attributes['country_id'], null), 'geo_code_1' => array(ts('Latitude'), array('size' => 9, 'maxlength' => 10), null), 'geo_code_2' => array(ts('Longitude'), array('size' => 9, 'maxlength' => 10), null));
     $stateCountryMap = array();
     foreach ($elements as $name => $v) {
         list($title, $attributes, $select) = $v;
         $nameWithoutID = strpos($name, '_id') !== false ? substr($name, 0, -3) : $name;
         if (!CRM_Utils_Array::value($nameWithoutID, $addressOptions)) {
             continue;
         }
         if (!$attributes) {
             $attributes = $attributes[$name];
         }
         //build normal select if country is not present in address block
         if ($name == 'state_province_id' && !$addressOptions['country']) {
             $select = 'stateProvince';
         }
         if (!$select) {
             if ($name == 'country_id' || $name == 'state_province_id') {
                 if ($name == 'country_id') {
                     $stateCountryMap[$blockId]['country'] = "address_{$blockId}_{$name}";
                     $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
                 } else {
                     $stateCountryMap[$blockId]['state_province'] = "address_{$blockId}_{$name}";
                     if ($countryDefault) {
                         $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
                     } else {
                         $selectOptions = array('' => ts('- select a country -'));
                     }
                 }
                 $form->addElement('select', "address[{$blockId}][{$name}]", $title, $selectOptions);
             } 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());
         }
     }
     require_once 'CRM/Core/BAO/Address.php';
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
 }
Esempio n. 6
0
 /**
  * Set the default form values
  *
  * @access protected
  * @return array the default array reference
  */
 function &setDefaultValues()
 {
     $defaults = array();
     $stateCountryMap = array();
     foreach ($this->_fields as $name => $field) {
         if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name'])) {
             CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $defaults, null, CRM_Profile_Form::MODE_REGISTER);
         }
         //CRM-5403
         if (substr($name, 0, 14) === 'state_province' || substr($name, 0, 7) === 'country') {
             list($fieldName, $index) = CRM_Utils_System::explode('-', $name, 2);
             if (!array_key_exists($index, $stateCountryMap)) {
                 $stateCountryMap[$index] = array();
             }
             $stateCountryMap[$index][$fieldName] = $name;
         }
     }
     // also take care of state country widget
     if (!empty($stateCountryMap)) {
         require_once 'CRM/Core/BAO/Address.php';
         CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap, $defaults);
     }
     //set default for country.
     CRM_Core_BAO_UFGroup::setRegisterDefaults($this->_fields, $defaults);
     // now fix all state country selectors
     require_once 'CRM/Core/BAO/Address.php';
     CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
     return $defaults;
 }
 /**
  * Function to add the custom fields
  *
  * @return void
  * @access public
  */
 function buildCustom($id, $name, $viewOnly = FALSE, $profileContactType = NULL, $fieldTypes = NULL)
 {
     $stateCountryMap = array();
     if ($id) {
         $contactID = $this->getContactID();
         // we don't allow conflicting fields to be
         // configured via profile - CRM 2100
         $fieldsToIgnore = array('receive_date' => 1, 'trxn_id' => 1, 'invoice_id' => 1, 'net_amount' => 1, 'fee_amount' => 1, 'non_deductible_amount' => 1, 'total_amount' => 1, 'amount_level' => 1, 'contribution_status_id' => 1, 'payment_instrument' => 1, 'check_number' => 1, 'financial_type' => 1);
         $fields = NULL;
         if ($contactID && CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
         }
         if ($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]);
                 }
             }
             if (array_intersect_key($fields, $fieldsToIgnore)) {
                 $fields = array_diff_key($fields, $fieldsToIgnore);
                 CRM_Core_Session::setStatus(ts('Some of the profile fields cannot be configured for this page.'), ts('Warning'), 'alert');
             }
             $fields = array_diff_assoc($fields, $this->_fields);
             CRM_Core_BAO_Address::checkContactSharedAddressFields($fields, $contactID);
             $addCaptcha = FALSE;
             foreach ($fields as $key => $field) {
                 if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File' || $viewOnly && $field['name'] == 'image_URL') {
                     // ignore file upload fields
                     continue;
                 }
                 list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
                 if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') {
                     if (!array_key_exists($index, $stateCountryMap)) {
                         $stateCountryMap[$index] = array();
                     }
                     $stateCountryMap[$index][$prefixName] = $key;
                     if ($prefixName == "state_province") {
                         if ($profileContactType == 'onbehalf') {
                             //CRM-11881: Bypass required-ness check for state/province on Contribution Confirm page
                             //as already done during Contribution registration via onBehalf's quickForm
                             $field['is_required'] = FALSE;
                         } else {
                             if (count($this->_submitValues)) {
                                 $locationTypeId = $field['location_type_id'];
                                 if (array_key_exists("country-{$locationTypeId}", $fields) && array_key_exists("state_province-{$locationTypeId}", $fields) && !empty($this->_submitValues["country-{$locationTypeId}"])) {
                                     $field['is_required'] = CRM_Core_Payment_Form::checkRequiredStateProvince($this, "country-{$locationTypeId}");
                                 }
                             }
                         }
                     }
                 }
                 if ($profileContactType) {
                     //Since we are showing honoree name separately so we are removing it from honoree profile just for display
                     $honoreeNamefields = array('prefix_id', 'first_name', 'last_name', 'suffix_id', 'organization_name', 'household_name');
                     if ($profileContactType == 'honor' && in_array($field['name'], $honoreeNamefields)) {
                         unset($fields[$field['name']]);
                         continue;
                     }
                     if (!empty($fieldTypes) && in_array($field['field_type'], $fieldTypes)) {
                         CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE, $profileContactType);
                         $this->_fields[$profileContactType][$key] = $field;
                     } else {
                         unset($fields[$key]);
                     }
                 } else {
                     CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
                     $this->_fields[$key] = $field;
                 }
                 // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
                 if ($field['add_captcha'] && !$this->_userID) {
                     $addCaptcha = TRUE;
                 }
             }
             $this->assign($name, $fields);
             CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
             if ($addCaptcha && !$viewOnly) {
                 $captcha = CRM_Utils_ReCAPTCHA::singleton();
                 $captcha->add($this);
                 $this->assign('isCaptcha', TRUE);
             }
         }
     }
 }
Esempio n. 8
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
  * @params string  $usedFor    for building up prefixed fieldname for special cases (e.g. onBehalf, Honor)
  *
  * @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;
     }
     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+=\'&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->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $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);
         $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->add('select', $name, $title, array('' => ts('(choose state first)')), $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' => '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('unselectable', TRUE);
         }
     } elseif ($fieldName === 'prefix_id' || $fieldName === 'suffix_id') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Contact_BAO_Contact', $fieldName), $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');
         //Website type select
         if ($usedFor) {
             if (substr($name, -1) == ']') {
                 $websiteTypeName = substr($name, 0, -1) . '-website_type_id]';
             }
             $form->addElement('select', $websiteTypeName, NULL, CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id'));
         } else {
             $form->addElement('select', $name . '-website_type_id', NULL, CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id'));
         }
     } 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') {
         CRM_Contact_Form_NewContact::buildQuickForm($form, $rowNumber, NULL, FALSE, 'soft_credit_');
         $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, array('' => ts('- select -')) + CRM_Core_PseudoConstant::worldRegion(), $required);
         } 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="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');
     }
     $stateCountryMap = array();
     if (!empty($form->_stateCountryMap['state_province']) && !empty($form->_stateCountryMap['country'])) {
         foreach ($form->_stateCountryMap['state_province'] as $key => $value) {
             $stateCountryMap[$key]['state_province'] = $value;
             $stateCountryMap[$key]['country'] = $form->_stateCountryMap['country'][$key];
         }
         CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
     }
     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. 9
0
 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'));
     $stateCountryMap = array();
     $stateCountryMap[] = array('state_province' => 'state_province_id', 'country' => 'country_id');
     $defaults = array();
     if ($countryDefault) {
         $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
         $defaults['country_id'] = $countryDefault;
     } else {
         $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince();
     }
     $form->addElement('select', 'state_province_id', ts('State/Province'), $stateProvince);
     $country = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
     $form->add('select', 'country_id', ts('Country'), $country, TRUE);
     $group = array('' => ts('- any group -')) + CRM_Core_PseudoConstant::group();
     $form->addElement('select', 'group', ts('Group'), $group);
     $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);
     // state country js, CRM-5233
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
     CRM_Core_BAO_Address::fixAllStateSelects($form, $defaults);
     /**
      * 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'));
 }
Esempio n. 10
0
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     $config = CRM_Core_Config::singleton();
     $i18n = CRM_Core_I18n::singleton();
     CRM_Utils_System::setTitle(ts('Settings - Localization'));
     $locales = CRM_Core_I18n::languages();
     $warningTitle = json_encode(ts("Warning"));
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     if ($domain->locales) {
         // for multi-lingual sites, populate default language drop-down with available languages
         $lcMessages = array();
         foreach ($locales as $loc => $lang) {
             if (substr_count($domain->locales, $loc)) {
                 $lcMessages[$loc] = $lang;
             }
         }
         $this->addElement('select', 'lcMessages', ts('Default Language'), $lcMessages);
         // add language limiter and language adder
         $this->addCheckBox('languageLimit', ts('Available Languages'), array_flip($lcMessages), NULL, NULL, NULL, NULL, ' &nbsp; ');
         $this->addElement('select', 'addLanguage', ts('Add Language'), array_merge(array('' => ts('- select -')), array_diff($locales, $lcMessages)));
         // add the ability to return to single language
         $warning = ts('This will make your CiviCRM installation a single-language one again. THIS WILL DELETE ALL DATA RELATED TO LANGUAGES OTHER THAN THE DEFAULT ONE SELECTED ABOVE (and only that language will be preserved).');
         $this->assign('warning', $warning);
         $warning = json_encode($warning);
         $this->addElement('checkbox', 'makeSinglelingual', ts('Return to Single Language'), NULL, array('onChange' => "if (this.checked) CRM.alert({$warning}, {$warningTitle})"));
     } else {
         // for single-lingual sites, populate default language drop-down with all languages
         $this->addElement('select', 'lcMessages', ts('Default Language'), $locales);
         $warning = ts('Enabling multiple languages changes the schema of your database, so make sure you know what you are doing when enabling this function; making a database backup is strongly recommended.');
         $this->assign('warning', $warning);
         $warning = json_encode($warning);
         $validTriggerPermission = CRM_Core_DAO::checkTriggerViewPermission(TRUE);
         if ($validTriggerPermission && !$config->logging) {
             $this->addElement('checkbox', 'makeMultilingual', ts('Enable Multiple Languages'), NULL, array('onChange' => "if (this.checked) CRM.alert({$warning}, {$warningTitle})"));
         }
     }
     $this->addElement('checkbox', 'inheritLocale', ts('Inherit CMS Language'));
     $this->addElement('text', 'monetaryThousandSeparator', ts('Thousands Separator'), array('size' => 2));
     $this->addElement('text', 'monetaryDecimalPoint', ts('Decimal Delimiter'), array('size' => 2));
     $this->addElement('text', 'moneyformat', ts('Monetary Amount Display'));
     $this->addElement('text', 'moneyvalueformat', ts('Monetary Value Display'));
     $country = array();
     CRM_Core_PseudoConstant::populate($country, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active');
     $i18n->localizeArray($country, array('context' => 'country'));
     asort($country);
     $includeCountry =& $this->addElement('advmultiselect', 'countryLimit', ts('Available Countries') . ' ', $country, array('size' => 5, 'style' => 'width:150px', 'class' => 'advmultiselect'));
     $includeCountry->setButtonAttributes('add', array('value' => ts('Add >>')));
     $includeCountry->setButtonAttributes('remove', array('value' => ts('<< Remove')));
     $includeState =& $this->addElement('advmultiselect', 'provinceLimit', ts('Available States and Provinces') . ' ', $country, array('size' => 5, 'style' => 'width:150px', 'class' => 'advmultiselect'));
     $includeState->setButtonAttributes('add', array('value' => ts('Add >>')));
     $includeState->setButtonAttributes('remove', array('value' => ts('<< Remove')));
     $this->addElement('select', 'defaultContactCountry', ts('Default Country'), array('' => ts('- select -')) + $country);
     /***Default State/Province***/
     $stateCountryMap = array();
     $stateCountryMap[] = array('state_province' => 'defaultContactStateProvince', 'country' => 'defaultContactCountry');
     $countryDefault = isset($this->_submitValues['defaultContactCountry']) ? $this->_submitValues['defaultContactCountry'] : $config->defaultContactCountry;
     if ($countryDefault) {
         $selectStateProvinceOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
     } else {
         $selectStateProvinceOptions = array('' => ts('- select a country -'));
     }
     $i18n->localizeArray($selectStateProvinceOptions, array('context' => 'state_province'));
     asort($selectStateProvinceOptions);
     $this->addElement('select', 'defaultContactStateProvince', ts('Default State/Province'), $selectStateProvinceOptions);
     // state country js
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
     $defaults = array();
     CRM_Core_BAO_Address::fixAllStateSelects($form, $defaults);
     // we do this only to initialize currencySymbols, kinda hackish but works!
     $config->defaultCurrencySymbol();
     $symbol = $config->currencySymbols;
     foreach ($symbol as $key => $value) {
         $this->_currencySymbols[$key] = "{$key}";
         if ($value) {
             $this->_currencySymbols[$key] .= " ({$value})";
         }
     }
     $this->addElement('select', 'defaultCurrency', ts('Default Currency'), $this->_currencySymbols);
     $includeCurrency =& $this->addElement('advmultiselect', 'currencyLimit', ts('Available Currencies') . ' ', $this->_currencySymbols, array('size' => 5, 'style' => 'width:150px', 'class' => 'advmultiselect'));
     $includeCurrency->setButtonAttributes('add', array('value' => ts('Add >>')));
     $includeCurrency->setButtonAttributes('remove', array('value' => ts('<< Remove')));
     $this->addElement('text', 'legacyEncoding', ts('Legacy Encoding'));
     $this->addElement('text', 'customTranslateFunction', ts('Custom Translate Function'));
     $this->addElement('text', 'fieldSeparator', ts('Import / Export Field Separator'), array('size' => 2));
     $this->addFormRule(array('CRM_Admin_Form_Setting_Localization', 'formRule'));
     parent::buildQuickForm();
 }
Esempio n. 11
0
 /**
  * Function to add the custom fields
  *
  * @return None
  * @access public
  */
 function buildCustom($id, $name, $viewOnly = FALSE)
 {
     $stateCountryMap = $fields = array();
     if ($id) {
         $button = substr($this->controller->getButtonName(), -4);
         $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
         $session = CRM_Core_Session::singleton();
         $contactID = $session->get('userID');
         // we don't allow conflicting fields to be
         // configured via profile
         $fieldsToIgnore = array('participant_fee_amount' => 1, 'participant_fee_level' => 1);
         if ($contactID) {
             //FIX CRM-9653
             if (is_array($id)) {
                 $fields = array();
                 foreach ($id as $profileID) {
                     $field = CRM_Core_BAO_UFGroup::getFields($profileID, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, 'field_name', TRUE);
                     $fields = array_merge($fields, $field);
                 }
             } else {
                 if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
                     $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, 'field_name', TRUE);
                 }
             }
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, 'field_name', TRUE);
         }
         if (array_intersect_key($fields, $fieldsToIgnore)) {
             $fields = array_diff_key($fields, $fieldsToIgnore);
             CRM_Core_Session::setStatus(ts('Some of the profile fields cannot be configured for this page.'));
         }
         $addCaptcha = FALSE;
         if (!empty($this->_fields)) {
             $fields = @array_diff_assoc($fields, $this->_fields);
         }
         if (!CRM_Utils_Array::value('additional_participants', $this->_params[0]) && is_null($cid)) {
             CRM_Core_BAO_Address::checkContactSharedAddressFields($fields, $contactID);
         }
         $this->assign($name, $fields);
         if (is_array($fields)) {
             foreach ($fields as $key => $field) {
                 if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File' || $viewOnly && $field['name'] == 'image_URL') {
                     // ignore file upload fields
                     continue;
                 }
                 //make the field optional if primary participant
                 //have been skip the additional participant.
                 if ($button == 'skip') {
                     $field['is_required'] = FALSE;
                 } elseif ($field['add_captcha'] && !$contactID) {
                     // only add captcha for first page
                     $addCaptcha = TRUE;
                 }
                 list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
                 if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') {
                     if (!array_key_exists($index, $stateCountryMap)) {
                         $stateCountryMap[$index] = array();
                     }
                     $stateCountryMap[$index][$prefixName] = $key;
                 }
                 CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
                 $this->_fields[$key] = $field;
             }
         }
         CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
         if ($addCaptcha && !$viewOnly) {
             $captcha = CRM_Utils_ReCAPTCHA::singleton();
             $captcha->add($this);
             $this->assign('isCaptcha', TRUE);
         }
     }
 }
Esempio n. 12
0
 /**
  * build form for address input fields 
  *
  * @param object $form - CRM_Core_Form (or subclass)
  * @param array reference $location - location array
  * @param int $locationId - location id whose block needs to be built.
  * @return none
  *
  * @access public
  * @static
  */
 static function buildQuickForm(&$form, $addressBlockCount = null)
 {
     // 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('onChange' => 'checkLocation( this.id );');
     $form->addElement('select', "address[{$blockId}][location_type_id]", ts('Location Type'), array('' => ts('- select -')) + CRM_Core_PseudoConstant::locationType(), $js);
     $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);
     $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]");
     require_once 'CRM/Core/BAO/Preferences.php';
     $addressOptions = CRM_Core_BAO_Preferences::valueOptions('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('Addt\'l Address 1'), $attributes['supplemental_address_1'], null), 'supplemental_address_2' => array(ts('Addt\'l Address 2'), $attributes['supplemental_address_2'], null), 'city' => array(ts('City'), $attributes['city'], null), 'postal_code' => array(ts('Zip / Postal Code'), $attributes['postal_code'], null), 'postal_code_suffix' => array(ts('Postal Code Suffix'), array('size' => 4, 'maxlength' => 12), null), 'county_id' => array(ts('County'), $attributes['county_id'], 'county'), 'state_province_id' => array(ts('State / Province'), $attributes['state_province_id'], null), 'country_id' => array(ts('Country'), $attributes['country_id'], null), 'geo_code_1' => array(ts('Latitude'), array('size' => 9, 'maxlength' => 10), null), 'geo_code_2' => array(ts('Longitude'), array('size' => 9, 'maxlength' => 10), 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));
     $stateCountryMap = array();
     foreach ($elements as $name => $v) {
         list($title, $attributes, $select) = $v;
         $nameWithoutID = strpos($name, '_id') !== false ? substr($name, 0, -3) : $name;
         if (!CRM_Utils_Array::value($nameWithoutID, $addressOptions)) {
             $continue = true;
             if (in_array($nameWithoutID, array('street_number', 'street_name', 'street_unit')) && CRM_Utils_Array::value('street_address_parsing', $addressOptions)) {
                 $continue = false;
             }
             if ($continue) {
                 continue;
             }
         }
         if (!$attributes) {
             $attributes = $attributes[$name];
         }
         //build normal select if country is not present in address block
         if ($name == 'state_province_id' && !$addressOptions['country']) {
             $select = 'stateProvince';
         }
         if (!$select) {
             if ($name == 'country_id' || $name == 'state_province_id') {
                 if ($name == 'country_id') {
                     $stateCountryMap[$blockId]['country'] = "address_{$blockId}_{$name}";
                     $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
                 } else {
                     $stateCountryMap[$blockId]['state_province'] = "address_{$blockId}_{$name}";
                     if ($countryDefault) {
                         $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
                     } else {
                         $selectOptions = array('' => ts('- select a country -'));
                     }
                 }
                 $form->addElement('select', "address[{$blockId}][{$name}]", $title, $selectOptions);
             } 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());
         }
     }
     require_once 'CRM/Core/BAO/Address.php';
     require_once 'CRM/Core/BAO/CustomGroup.php';
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
     $entityId = null;
     if (!empty($form->_values['address'])) {
         $entityId = $form->_values['address'][$blockId]['id'];
     }
     // 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);
         // For some of the custom fields like checkboxes, the defaults doesn't populate
         // in proper format due to the different element-name format - 'address[$blockId][custom-X]'.
         // Below eval() fixes this issue.
         $address = array();
         foreach ($defaults as $key => $val) {
             eval("\${$key} = " . (!is_array($val) ? "'{$val}'" : var_export($val, true)) . ";");
         }
         $defaults = array('address' => $address);
         $form->setDefaults($defaults);
         // 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, 1, "dnc_");
         $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));
         $form->assign("dnc_groupTree", null);
         // unset the temp smarty var that got created
     }
     // address custom data processing ends ..
     // shared address
     $form->addElement('checkbox', "address[{$blockId}][use_shared_address]", null, ts('Share Address With'));
     // get the reserved for address
     $profileId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'shared_address', 'id', 'name');
     if (!$profileId) {
         CRM_Core_Error::fatal(ts('Your install is missing required "Shared Address" profile.'));
     }
     require_once 'CRM/Contact/Form/NewContact.php';
     CRM_Contact_Form_NewContact::buildQuickForm($form, $blockId, array($profileId));
 }
Esempio n. 13
0
 /**
  * generic function to build all the form elements for a specific group tree
  *
  * @param object    $form             the form object
  * @param array     $groupTree        the group tree object
  * @param boolean   $inactiveNeeded   return inactive custom groups
  * @param string    $prefix           prefix for custom grouptree assigned to template
  *
  * @return void
  * @access public
  * @static
  */
 static function buildQuickForm(&$form, &$groupTree, $inactiveNeeded = FALSE, $prefix = '')
 {
     $form->assign_by_ref("{$prefix}groupTree", $groupTree);
     // this is fix for date field
     $form->assign('currentYear', date('Y'));
     foreach ($groupTree as $id => $group) {
         CRM_Core_ShowHideBlocks::links($form, $group['title'], '', '');
         foreach ($group['fields'] as $field) {
             $required = CRM_Utils_Array::value('is_required', $field);
             //fix for CRM-1620
             if ($field['data_type'] == 'File') {
                 if (!empty($field['element_value']['data'])) {
                     $required = 0;
                 }
             }
             $fieldId = $field['id'];
             $elementName = $field['element_name'];
             CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, $inactiveNeeded, $required);
         }
     }
     if (!empty($form->_stateCountryMap['state_province']) && !empty($form->_stateCountryMap['country'])) {
         foreach ($form->_stateCountryMap['state_province'] as $key => $value) {
             $stateCountryMap[$key]['state_province'] = $value;
             $stateCountryMap[$key]['country'] = $form->_stateCountryMap['country'][$key];
         }
         CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
     }
 }
Esempio n. 14
0
 function setDefaultValues()
 {
     $this->_defaults = array();
     if ($this->_contactID) {
         foreach ($this->_fields as $name => $dontcare) {
             $fields[$name] = 1;
         }
         CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactID, $fields, $this->_defaults);
     }
     $stateCountryMap = array();
     //set custom field defaults
     foreach ($this->_fields as $name => $field) {
         if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
             if (!isset($this->_defaults[$name])) {
                 CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, NULL, CRM_Profile_Form::MODE_REGISTER);
             }
         }
         if (substr($name, 0, 14) === 'state_province' || substr($name, 0, 7) === 'country' || substr($name, 0, 6) === 'county') {
             list($fieldName, $index) = CRM_Utils_System::explode('-', $name, 2);
             if (!array_key_exists($index, $stateCountryMap)) {
                 $stateCountryMap[$index] = array();
             }
             $stateCountryMap[$index][$fieldName] = $name;
         }
         // also take care of state country widget
         if (!empty($stateCountryMap)) {
             CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap, $this->_defaults);
         }
     }
     // now fix all state country selectors
     CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
     return $this->_defaults;
 }
Esempio n. 15
0
 /**  
  * Function to add the custom fields
  *  
  * @return None  
  * @access public  
  */
 function buildCustom($id, $name, $viewOnly = false)
 {
     $stateCountryMap = array();
     if ($id) {
         $button = substr($this->controller->getButtonName(), -4);
         require_once 'CRM/Core/BAO/UFGroup.php';
         require_once 'CRM/Profile/Form.php';
         $session =& CRM_Core_Session::singleton();
         $contactID = $session->get('userID');
         // we don't allow conflicting fields to be
         // configured via profile
         $fieldsToIgnore = array('participant_fee_amount' => 1, 'participant_fee_level' => 1);
         $fields = null;
         if ($contactID) {
             if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
                 $fields = CRM_Core_BAO_UFGroup::getFields($id, false, CRM_Core_Action::ADD);
             }
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, 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]);
                 }
             }
         }
         if (array_intersect_key($fields, $fieldsToIgnore)) {
             $fields = array_diff_key($fields, $fieldsToIgnore);
             CRM_Core_Session::setStatus("Some of the profile fields cannot be configured for this page.");
         }
         $addCaptcha = false;
         $this->assign($name, $fields);
         if (is_array($fields)) {
             foreach ($fields as $key => $field) {
                 if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File') {
                     // ignore file upload fields
                     continue;
                 }
                 //make the field optional if primary participant
                 //have been skip the additional participant.
                 if ($button == 'skip') {
                     $field['is_required'] = false;
                 } else {
                     if ($field['add_captcha']) {
                         // only add captcha for first page
                         $addCaptcha = true;
                     }
                 }
                 list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
                 if ($prefixName == 'state_province' || $prefixName == 'country') {
                     if (!array_key_exists($index, $stateCountryMap)) {
                         $stateCountryMap[$index] = array();
                     }
                     $stateCountryMap[$index][$prefixName] = $key;
                 }
                 CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, true);
                 $this->_fields[$key] = $field;
             }
         }
         require_once 'CRM/Core/BAO/Address.php';
         CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
         if ($addCaptcha && !$viewOnly) {
             require_once 'CRM/Utils/ReCAPTCHA.php';
             $captcha =& CRM_Utils_ReCAPTCHA::singleton();
             $captcha->add($this);
             $this->assign("isCaptcha", true);
         }
     }
 }
Esempio n. 16
0
 /**
  * Function to build the petition profile form
  *
  * @return void
  * @access public
  */
 function buildCustom($id, $name, $viewOnly = FALSE)
 {
     // create state country map array to hold selectors
     $stateCountryMap = array();
     if ($id) {
         $session = CRM_Core_Session::singleton();
         $this->assign("petition", $this->petition);
         //$contactID = $this->_contactId;
         $contactID = NULL;
         $this->assign('contact_id', $this->_contactId);
         $fields = NULL;
         // TODO: contactID is never set (commented above)
         if ($contactID) {
             if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
                 $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD);
             }
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD);
         }
         if ($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] );
                 }
             }
             */
             $this->assign($name, $fields);
             $addCaptcha = FALSE;
             foreach ($fields as $key => $field) {
                 if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File' || $viewOnly && $field['name'] == 'image_URL') {
                     // ignore file upload fields
                     continue;
                 }
                 // if state or country in the profile, create map
                 list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
                 if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') {
                     if (!array_key_exists($index, $stateCountryMap)) {
                         $stateCountryMap[$index] = array();
                     }
                     $stateCountryMap[$index][$prefixName] = $key;
                 }
                 CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
                 $this->_fields[$key] = $field;
                 // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
                 if ($field['add_captcha'] && !$this->_contactId) {
                     $addCaptcha = TRUE;
                 }
             }
             // initialize the state country map
             CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
             if ($addCaptcha && !$viewOnly) {
                 $captcha = CRM_Utils_ReCAPTCHA::singleton();
                 $captcha->add($this);
                 $this->assign("isCaptcha", TRUE);
             }
         }
     }
 }
 static function location(&$form)
 {
     // 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), 'county' => array(ts('County'), $attributes['county_id'], 'county', TRUE), 'state_province' => array(ts('State / Province'), $attributes['state_province_id'], 'stateProvince', TRUE), 'country' => array(ts('Country'), $attributes['country_id'], 'country', FALSE), '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) {
             $config = CRM_Core_Config::singleton();
             $countryDefault = $config->defaultContactCountry;
             $stateCountryMap[] = array('state_province' => 'state_province', 'country' => 'country', 'county' => 'county');
             if ($select == 'stateProvince') {
                 if ($countryDefault && !isset($formValues['country'])) {
                     $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
                 } elseif ($formValues['country']) {
                     $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($formValues['country']);
                 } else {
                     //if not setdefault any country
                     $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select();
                 }
                 $element = $form->addElement('select', $name, $title, $selectElements);
             } elseif ($select == 'country') {
                 if ($countryDefault) {
                     //for setdefault country
                     $defaultValues = array();
                     $defaultValues[$name] = $countryDefault;
                     $form->setDefaults($defaultValues);
                 }
                 $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select();
                 $element = $form->addElement('select', $name, $title, $selectElements);
             } elseif ($select == 'county') {
                 if (array_key_exists('state_province', $formValues) && !CRM_Utils_System::isNull($formValues['state_province'])) {
                     $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::countyForState($formValues['state_province']);
                 } else {
                     $selectElements = array('' => ts('- select a state -'));
                 }
                 $element = $form->addElement('select', $name, $title, $selectElements);
             } else {
                 $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select();
                 $element = $form->addElement('select', $name, $title, $selectElements);
             }
             if ($multiSelect) {
                 $element->setMultiple(TRUE);
             }
         } else {
             $form->addElement('text', $name, $title, $attributes);
         }
         if ($addressOptions['postal_code']) {
             $form->addElement('text', 'postal_code_low', ts('Range-From'), CRM_Utils_Array::value('postal_code', $attributes));
             $form->addElement('text', 'postal_code_high', ts('To'), CRM_Utils_Array::value('postal_code', $attributes));
         }
     }
     // extend addresses with proximity search
     $form->addElement('text', 'prox_distance', ts('Find contacts within'));
     $form->addElement('select', 'prox_distance_unit', NULL, array('miles' => ts('Miles'), 'kilos' => ts('Kilometers')));
     // is there another form rule that does decimals besides money ? ...
     $form->addRule('prox_distance', ts('Please enter positive number as a distance'), 'numeric');
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
     $worldRegions = array('' => ts('- any region -')) + CRM_Core_PseudoConstant::worldRegion();
     $form->addElement('select', 'world_region', ts('World Region'), $worldRegions);
     // checkboxes for location type
     $location_type = array();
     $locationType = CRM_Core_PseudoConstant::locationType();
     foreach ($locationType as $locationTypeID => $locationTypeName) {
         $location_type[] = $form->createElement('checkbox', $locationTypeID, NULL, $locationTypeName);
     }
     $form->addGroup($location_type, 'location_type', ts('Location Types'), '&nbsp;');
     // 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);
             }
         }
     }
 }
Esempio n. 18
0
 function buildForm(&$form)
 {
     $config =& CRM_Core_Config::singleton();
     $countryDefault = $config->defaultContactCountry;
     $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::tag();
     $form->addElement('select', 'tag', ts('Tag'), $tag);
     $form->add('text', 'distance', ts('Distance'));
     $form->add('text', 'street_address', ts('Street Address'));
     $form->add('text', 'city', ts('City'));
     $form->add('text', 'postal_code', ts('Postal Code'));
     $stateCountryMap = array();
     $stateCountryMap[] = array('state_province' => 'state_province_id', 'country' => 'country_id');
     $defaults = array();
     if ($countryDefault) {
         $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
         $defaults['country_id'] = $countryDefault;
     } else {
         $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince();
     }
     $form->addElement('select', 'state_province_id', ts('State/Province'), $stateProvince);
     $country = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
     $form->add('select', 'country_id', ts('Country'), $country, true);
     $form->add('text', 'distance', ts('Radius for Proximity Search (in km)'), null, true);
     // state country js, CRM-5233
     require_once 'CRM/Core/BAO/Address.php';
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
     CRM_Core_BAO_Address::fixAllStateSelects($form, $defaults);
     /**
      * 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('tag', 'street_address', 'city', 'postal_code', 'country_id', 'state_province_id', 'distance'));
 }
Esempio n. 19
0
 /**
  * Function to add all the credit card fields
  *
  * @return None
  * @access public
  */
 function buildCreditCard(&$form, $useRequired = FALSE)
 {
     if ($form->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM) {
         self::setCreditCardFields($form);
         foreach ($form->_paymentFields as $name => $field) {
             if (isset($field['cc_field']) && $field['cc_field']) {
                 $form->add($field['htmlType'], $field['name'], $field['title'], $field['attributes'], $useRequired ? $field['is_required'] : FALSE);
             }
         }
         $form->addRule('cvv2', ts('Please enter a valid value for your card security code. This is usually the last 3-4 digits on the card\'s signature panel.'), 'integer');
         $form->addRule('credit_card_exp_date', ts('Credit card expiration date cannot be a past date.'), 'currentDate', TRUE);
         // also take care of state country widget
         $stateCountryMap = array(1 => array('country' => "billing_country_id-{$form->_bltID}", 'state_province' => "billing_state_province_id-{$form->_bltID}"));
         CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
     }
     if ($form->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON) {
         $form->_expressButtonName = $form->getButtonName('upload', 'express');
         $form->assign('expressButtonName', $form->_expressButtonName);
         $form->add('image', $form->_expressButtonName, $form->_paymentProcessor['url_button'], array('class' => 'form-submit'));
     }
 }
Esempio n. 20
0
 /** 
  * Function to add all the credit card fields
  * 
  * @return None 
  * @access public 
  */
 function buildCreditCard(&$form, $useRequired = false)
 {
     require_once 'CRM/Core/Payment.php';
     // CRM-2462
     if (!$useRequired && !in_array($form->_paymentProcessor['payment_processor_type'], array('PayPal_Express', 'PayPal', 'Dummy'))) {
         // this is only set for paypal's case where we need to not throw an error if someone
         // clicks paypal express
         $useRequired = true;
     }
     if ($form->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM) {
         foreach ($form->_fields as $name => $field) {
             if (isset($field['cc_field']) && $field['cc_field']) {
                 $form->add($field['htmlType'], $field['name'], $field['title'], $field['attributes'], $useRequired ? $field['is_required'] : false);
             }
         }
         $form->addRule('cvv2', ts('Please enter a valid value for your card security code. This is usually the last 3-4 digits on the card\'s signature panel.'), 'integer');
         $form->addRule('credit_card_exp_date', ts('Credit card expiration date cannot be a past date.'), 'currentDate', true);
         // also take care of state country widget
         require_once 'CRM/Core/BAO/Address.php';
         $stateCountryMap = array(1 => array('country' => "billing_country_id-{$form->_bltID}", 'state_province' => "billing_state_province_id-{$form->_bltID}"));
         CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
     }
     if ($form->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON) {
         $form->_expressButtonName = $form->getButtonName('upload', 'express');
         $form->assign('expressButtonName', $form->_expressButtonName);
         $form->add('image', $form->_expressButtonName, $form->_paymentProcessor['url_button'], array('class' => 'form-submit'));
     }
 }
 /**  
  * Function to add the custom fields
  *  
  * @return None  
  * @access public  
  */
 function buildCustom($id, $name, $viewOnly = false)
 {
     $stateCountryMap = array();
     if ($id) {
         require_once 'CRM/Core/BAO/UFGroup.php';
         require_once 'CRM/Profile/Form.php';
         $session = CRM_Core_Session::singleton();
         $contactID = $this->_userID;
         // we don't allow conflicting fields to be
         // configured via profile - CRM 2100
         $fieldsToIgnore = array('receive_date' => 1, 'trxn_id' => 1, 'invoice_id' => 1, 'net_amount' => 1, 'fee_amount' => 1, 'non_deductible_amount' => 1, 'total_amount' => 1, 'amount_level' => 1, 'contribution_status_id' => 1, 'payment_instrument' => 1, 'check_number' => 1, 'contribution_type' => 1);
         $fields = null;
         if ($contactID) {
             require_once "CRM/Core/BAO/UFGroup.php";
             if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
                 $fields = CRM_Core_BAO_UFGroup::getFields($id, false, CRM_Core_Action::ADD);
             }
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, false, CRM_Core_Action::ADD);
         }
         if ($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]);
                 }
             }
             if (array_intersect_key($fields, $fieldsToIgnore)) {
                 $fields = array_diff_key($fields, $fieldsToIgnore);
                 CRM_Core_Session::setStatus("Some of the profile fields cannot be configured for this page.");
             }
             $fields = array_diff_assoc($fields, $this->_fields);
             $this->assign($name, $fields);
             $addCaptcha = false;
             foreach ($fields as $key => $field) {
                 if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File' || $viewOnly && $field['name'] == 'image_URL') {
                     // ignore file upload fields
                     continue;
                 }
                 list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
                 if ($prefixName == 'state_province' || $prefixName == 'country') {
                     if (!array_key_exists($index, $stateCountryMap)) {
                         $stateCountryMap[$index] = array();
                     }
                     $stateCountryMap[$index][$prefixName] = $key;
                 }
                 CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, true);
                 $this->_fields[$key] = $field;
                 if ($field['add_captcha']) {
                     $addCaptcha = true;
                 }
             }
             require_once 'CRM/Core/BAO/Address.php';
             CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
             if ($addCaptcha && !$viewOnly) {
                 require_once 'CRM/Utils/ReCAPTCHA.php';
                 $captcha =& CRM_Utils_ReCAPTCHA::singleton();
                 $captcha->add($this);
                 $this->assign("isCaptcha", true);
             }
         }
     }
 }
Esempio n. 22
0
 /**
  * build form for address input fields
  *
  * @param object  $form - CRM_Core_Form (or subclass)
  * @param int     $addressBlockCount - the index of the address array (if multiple addresses on a page)
  * @param boolean $sharing - false, if we want to skip the address sharing features
  * @param boolean $inlineEdit true when edit used in inline edit
  *
  * @return void
  *
  * @access public
  * @static
  */
 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 );');
     }
     $form->addSelect("address[{$blockId}][location_type_id]", array('entity' => 'address', 'class' => 'eight') + $js);
     if (!$inlineEdit) {
         $js = array('id' => 'Address_' . $blockId . '_IsPrimary', 'onClick' => 'singleSelect( this.id );');
     } else {
         //make location type required for inline edit
         $form->addRule("address[{$blockId}][location_type_id]", ts('%1 is a required field.', array(1 => ts('Location Type'))), 'required');
     }
     $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), 'county_id' => array(ts('County'), $attributes['county_id'], NULL), 'state_province_id' => array(ts('State / Province'), $attributes['state_province_id'], NULL), 'country_id' => array(ts('Country'), $attributes['country_id'], NULL), 'geo_code_1' => array(ts('Latitude'), array('size' => 9, 'maxlength' => 11), NULL), 'geo_code_2' => array(ts('Longitude'), array('size' => 9, 'maxlength' => 11), 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));
     $stateCountryMap = array();
     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;
             }
         }
         if (!$attributes) {
             $attributes = $attributes[$name];
         }
         //build normal select if country is not present in address block
         if ($name == 'state_province_id' && !$addressOptions['country']) {
             $select = 'stateProvince';
         }
         if (!$select) {
             if ($name == 'country_id' || $name == 'state_province_id' || $name == 'county_id') {
                 if ($name == 'country_id') {
                     $stateCountryMap[$blockId]['country'] = "address_{$blockId}_{$name}";
                     $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
                 } elseif ($name == 'state_province_id') {
                     $stateCountryMap[$blockId]['state_province'] = "address_{$blockId}_{$name}";
                     if ($countryDefault) {
                         $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
                     } else {
                         $selectOptions = array('' => ts('- select a country -'));
                     }
                 } elseif ($name == 'county_id') {
                     $stateCountryMap[$blockId]['county'] = "address_{$blockId}_{$name}";
                     if ($form->getSubmitValue("address[{$blockId}][state_province_id]")) {
                         $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::countyForState($form->getSubmitValue("address[{$blockId}][state_province_id]"));
                     } elseif ($form->getSubmitValue("address[{$blockId}][county_id]")) {
                         $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::county();
                     } else {
                         $selectOptions = array('' => ts('- select a state -'));
                     }
                 }
                 $form->addElement('select', "address[{$blockId}][{$name}]", $title, $selectOptions);
             } else {
                 if ($name == 'address_name') {
                     $name = 'name';
                 }
                 $form->addElement('text', "address[{$blockId}][{$name}]", $title, $attributes);
             }
         } else {
             if ($name == 'state_province_id') {
                 $stateCountryMap[$blockId]['state_province'] = "address_{$blockId}_{$name}";
             }
             $form->addElement('select', "address[{$blockId}][{$name}]", $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select());
         }
     }
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
     $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'));
         // get the reserved for address
         $profileId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'shared_address', 'id', 'name');
         if (!$profileId) {
             CRM_Core_Error::fatal(ts('Your install is missing required "Shared Address" profile.'));
         }
         CRM_Contact_Form_NewContact::buildQuickForm($form, $blockId, array($profileId));
     }
 }
 /**
  * Function to build form for related contacts / on behalf of organization.
  *
  * @param $form              object  invoking Object
  * @param $contactType       string  contact type
  * @param $title             string  fieldset title
  *
  * @static
  */
 static function buildQuickForm(&$form)
 {
     $form->assign('fieldSetTitle', ts('Organization Details'));
     $form->assign('buildOnBehalfForm', TRUE);
     $session = CRM_Core_Session::singleton();
     $contactID = $session->get('userID');
     if ($contactID && count($form->_employers) >= 1) {
         $form->add('text', 'organization_id', ts('Select an existing related Organization OR enter a new one'));
         $form->add('hidden', 'onbehalfof_id', '', array('id' => 'onbehalfof_id'));
         $orgOptions = array(0 => ts('Select an existing organization'), 1 => ts('Enter a new organization'));
         $form->addRadio('org_option', ts('options'), $orgOptions);
         $form->setDefaults(array('org_option' => 0));
         $form->add('checkbox', 'mode', '');
     }
     $profileFields = CRM_Core_BAO_UFGroup::getFields($form->_profileId, FALSE, CRM_Core_Action::VIEW, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
     $fieldTypes = array('Contact', 'Organization');
     $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
     $fieldTypes = array_merge($fieldTypes, $contactSubType);
     if (is_array($form->_membershipBlock) && !empty($form->_membershipBlock)) {
         $fieldTypes = array_merge($fieldTypes, array('Membership'));
     } else {
         $fieldTypes = array_merge($fieldTypes, array('Contribution'));
     }
     $stateCountryMap = array();
     foreach ($profileFields as $name => $field) {
         if (in_array($field['field_type'], $fieldTypes)) {
             list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
             if (in_array($prefixName, array('state_province', 'country', 'county'))) {
                 if (!array_key_exists($index, $stateCountryMap)) {
                     $stateCountryMap[$index] = array();
                 }
                 $stateCountryMap[$index][$prefixName] = 'onbehalf[' . $name . ']';
             } elseif (in_array($prefixName, array('organization_name', 'email')) && !CRM_Utils_Array::value('is_required', $field)) {
                 $field['is_required'] = 1;
             }
             CRM_Core_BAO_UFGroup::buildProfile($form, $field, NULL, NULL, FALSE, TRUE);
         }
     }
     if (!empty($stateCountryMap)) {
         CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
         // now fix all state country selectors
         CRM_Core_BAO_Address::fixAllStateSelects($form, CRM_Core_DAO::$_nullArray);
     }
     $form->assign('onBehalfOfFields', $profileFields);
     $form->addElement('hidden', 'hidden_onbehalf_profile', 1);
 }
Esempio n. 24
0
 /**
  * Function to add the custom fields
  *
  * @return None
  * @access public
  */
 function buildCustom($id, $name, $viewOnly = FALSE, $onBehalf = FALSE, $fieldTypes = NULL)
 {
     $stateCountryMap = array();
     if ($id) {
         $contactID = $this->getContactID();
         // we don't allow conflicting fields to be
         // configured via profile - CRM 2100
         $fieldsToIgnore = array('receive_date' => 1, 'trxn_id' => 1, 'invoice_id' => 1, 'net_amount' => 1, 'fee_amount' => 1, 'non_deductible_amount' => 1, 'total_amount' => 1, 'amount_level' => 1, 'contribution_status_id' => 1, 'payment_instrument' => 1, 'check_number' => 1, 'financial_type' => 1);
         $fields = NULL;
         if ($contactID && CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
         }
         if ($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]);
                 }
             }
             if (array_intersect_key($fields, $fieldsToIgnore)) {
                 $fields = array_diff_key($fields, $fieldsToIgnore);
                 CRM_Core_Session::setStatus(ts('Some of the profile fields cannot be configured for this page.'), ts('Warning'), 'alert');
             }
             $fields = array_diff_assoc($fields, $this->_fields);
             CRM_Core_BAO_Address::checkContactSharedAddressFields($fields, $contactID);
             $addCaptcha = FALSE;
             foreach ($fields as $key => $field) {
                 if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File' || $viewOnly && $field['name'] == 'image_URL') {
                     // ignore file upload fields
                     continue;
                 }
                 list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
                 if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') {
                     if (!array_key_exists($index, $stateCountryMap)) {
                         $stateCountryMap[$index] = array();
                     }
                     $stateCountryMap[$index][$prefixName] = $key;
                 }
                 if ($onBehalf) {
                     if (!empty($fieldTypes) && in_array($field['field_type'], $fieldTypes)) {
                         CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
                         $this->_fields['onbehalf'][$key] = $field;
                     } else {
                         unset($fields[$key]);
                     }
                 } else {
                     CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
                     $this->_fields[$key] = $field;
                 }
                 // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
                 if ($field['add_captcha'] && !$this->_userID) {
                     $addCaptcha = TRUE;
                 }
             }
             $this->assign($name, $fields);
             CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
             if ($addCaptcha && !$viewOnly) {
                 $captcha = CRM_Utils_ReCAPTCHA::singleton();
                 $captcha->add($this);
                 $this->assign('isCaptcha', TRUE);
             }
         }
     }
 }
Esempio n. 25
0
 static function location(&$form)
 {
     $form->addElement('hidden', 'hidden_location', 1);
     require_once 'CRM/Core/BAO/Preferences.php';
     $addressOptions = CRM_Core_BAO_Preferences::valueOptions('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), 'county' => array(ts('County'), $attributes['county_id'], 'county', false), 'state_province' => array(ts('State / Province'), $attributes['state_province_id'], 'stateProvince', true), 'country' => array(ts('Country'), $attributes['country_id'], 'country', false), 'address_name' => array(ts('Address Name'), $attributes['address_name'], null, null));
     foreach ($elements as $name => $v) {
         list($title, $attributes, $select, $multiSelect) = $v;
         if (!$addressOptions[$name]) {
             continue;
         }
         if (!$attributes) {
             $attributes = $attributes[$name];
         }
         if ($select) {
             $config = CRM_Core_Config::singleton();
             $countryDefault = $config->defaultContactCountry;
             $stateCountryMap[] = array('state_province' => 'state_province', 'country' => 'country');
             if ($select == 'stateProvince') {
                 if ($countryDefault && !isset($form->_submitValues['country'])) {
                     $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
                 } else {
                     if ($form->_submitValues['country']) {
                         $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($form->_submitValues['country']);
                     } else {
                         //if not setdefault any country
                         $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select();
                     }
                 }
                 $element = $form->addElement('select', $name, $title, $selectElements);
             } else {
                 if ($select == 'country') {
                     if ($countryDefault) {
                         //for setdefault country
                         $defaultValues = array();
                         $defaultValues[$name] = $countryDefault;
                         $form->setDefaults($defaultValues);
                     }
                     $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select();
                     $element = $form->addElement('select', $name, $title, $selectElements);
                 } else {
                     $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select();
                     $element = $form->addElement('select', $name, $title, $selectElements);
                 }
             }
             if ($multiSelect) {
                 $element->setMultiple(true);
             }
         } else {
             $form->addElement('text', $name, $title, $attributes);
         }
         if ($addressOptions['postal_code']) {
             $form->addElement('text', 'postal_code_low', ts('Range-From'), CRM_Utils_Array::value('postal_code', $attributes));
             $form->addElement('text', 'postal_code_high', ts('To'), CRM_Utils_Array::value('postal_code', $attributes));
         }
     }
     // extend addresses with proximity search
     $form->addElement('text', 'prox_distance', ts('Find contacts within'));
     $form->addElement('select', 'prox_distance_unit', null, array('miles' => ts('Miles'), 'kilos' => ts('Kilometers')));
     // is there another form rule that does decimals besides money ? ...
     $form->addRule('prox_distance', ts('Please enter positive number as a distance'), 'numeric');
     require_once 'CRM/Core/BAO/Address.php';
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
     $worldRegions = array('' => ts('- any region -')) + CRM_Core_PseudoConstant::worldRegion();
     $form->addElement('select', 'world_region', ts('World Region'), $worldRegions);
     // checkboxes for location type
     $location_type = array();
     $locationType = CRM_Core_PseudoConstant::locationType();
     foreach ($locationType as $locationTypeID => $locationTypeName) {
         $location_type[] = HTML_QuickForm::createElement('checkbox', $locationTypeID, null, $locationTypeName);
     }
     $form->addGroup($location_type, 'location_type', ts('Location Types'), '&nbsp;');
     // custom data extending addresses -
     require_once 'CRM/Core/BAO/CustomGroup.php';
     $extends = array('Address');
     $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(null, true, $extends);
     if ($groupDetails) {
         require_once 'CRM/Core/BAO/CustomField.php';
         $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);
             }
         }
     }
 }