Exemple #1
0
 function buildQuickForm()
 {
     $this->add('text', 'email', ts('Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'email'), true);
     $fields = CRM_Core_BAO_UFGroup::getFields($this->_profileID, false, CRM_Core_Action::ADD, null, null, false, null, true);
     $this->assign('custom', $fields);
     require_once 'CRM/Profile/Form.php';
     foreach ($fields as $key => $field) {
         CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE);
         $this->_fields[$key] = $field;
     }
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
 }
 function buildQuickForm(&$form)
 {
     $textarea_size = array('size' => 30, 'maxlength' => 60);
     $form->add('text', $this->email_field_name(), ts('Email Address'), $textarea_size, TRUE);
     list($custom_fields_pre, $custom_fields_post) = $this->get_participant_custom_data_fields($this->participant->event_id);
     foreach ($custom_fields_pre as $key => $field) {
         CRM_Core_BAO_UFGroup::buildProfile($form, $field, CRM_Profile_Form::MODE_CREATE, $this->participant->id);
     }
     foreach ($custom_fields_post as $key => $field) {
         CRM_Core_BAO_UFGroup::buildProfile($form, $field, CRM_Profile_Form::MODE_CREATE, $this->participant->id);
     }
     $custom = CRM_Utils_Array::value('custom', $form->getTemplate()->_tpl_vars, array());
     $form->assign('custom', array_merge($custom, array($this->html_field_name('customPre') => $custom_fields_pre, $this->html_field_name('customPost') => $custom_fields_post, $this->html_field_name('number') => $this->name())));
 }
 /**
  * Build form for honoree contact / on behalf of organization.
  *
  * @param CRM_Core_Form $form
  *
  */
 public static function buildQuickForm(&$form)
 {
     $ufGroup = new CRM_Core_DAO_UFGroup();
     $ufGroup->id = $form->_honoreeProfileId;
     if (!$ufGroup->find(TRUE)) {
         CRM_Core_Error::fatal(ts('Chosen honoree profile for this contribution is disabled'));
     }
     $prefix = 'honor';
     $honoreeProfileFields = CRM_Core_BAO_UFGroup::getFields($form->_honoreeProfileId, FALSE, NULL, NULL, NULL, FALSE, NULL, TRUE, NULL, CRM_Core_Permission::CREATE);
     $form->addElement('hidden', 'honoree_profile_id', $form->_honoreeProfileId);
     $form->assign('honoreeProfileFields', $honoreeProfileFields);
     // add the form elements
     foreach ($honoreeProfileFields as $name => $field) {
         // If soft credit type is not chosen then make omit requiredness from honoree profile fields
         if (count($form->_submitValues) && empty($form->_submitValues['soft_credit_type_id']) && !empty($field['is_required'])) {
             $field['is_required'] = FALSE;
         }
         CRM_Core_BAO_UFGroup::buildProfile($form, $field, CRM_Profile_Form::MODE_CREATE, NULL, FALSE, FALSE, NULL, $prefix);
     }
 }
 /**
  * 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 for Activities') . ' - ' . CRM_Core_BAO_UFGroup::getTitle($ufGroupId);
     CRM_Utils_System::setTitle($this->_title);
     $this->addDefaultButtons(ts('Save'));
     $this->_fields = array();
     $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 to reduce size as we are using this field in grid
         if (is_array($field['attributes']) && $this->_fields[$name]['attributes']['size'] > 19) {
             //shrink class to "form-text-medium"
             $this->_fields[$name]['attributes']['size'] = 19;
         }
     }
     $this->_fields = array_slice($this->_fields, 0, $this->_maxFields);
     $this->addButtons(array(array('type' => 'submit', 'name' => ts('Update Activities'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->assign('profileTitle', $this->_title);
     $this->assign('componentIds', $this->_activityHolderIds);
     $fileFieldExists = FALSE;
     //load all campaigns.
     if (array_key_exists('activity_campaign_id', $this->_fields)) {
         $this->_componentCampaigns = array();
         CRM_Core_PseudoConstant::populate($this->_componentCampaigns, 'CRM_Activity_DAO_Activity', TRUE, 'campaign_id', 'id', ' id IN (' . implode(' , ', array_values($this->_activityHolderIds)) . ' ) ');
     }
     $customFields = CRM_Core_BAO_CustomField::getFields('Activity');
     foreach ($this->_activityHolderIds as $activityId) {
         $typeId = CRM_Core_DAO::getFieldValue("CRM_Activity_DAO_Activity", $activityId, 'activity_type_id');
         foreach ($this->_fields as $name => $field) {
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 $customValue = CRM_Utils_Array::value($customFieldID, $customFields);
                 if (!empty($customValue['extends_entity_column_value'])) {
                     $entityColumnValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, $customValue['extends_entity_column_value']);
                 }
                 if (!empty($entityColumnValue[$typeId]) || CRM_Utils_System::isNull($entityColumnValue[$typeId])) {
                     CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $activityId);
                 }
             } else {
                 // handle non custom fields
                 CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $activityId);
             }
         }
     }
     $this->assign('fields', $this->_fields);
     // don't set the status message when form is submitted.
     // $buttonName = $this->controller->getButtonName('submit');
     if ($suppressFields) {
         CRM_Core_Session::setStatus(ts("FILE or Autocomplete Select type field(s) in the selected profile are not supported for Batch Update."), ts("Some fields have been excluded"), "info");
     }
     $this->addDefaultButtons(ts('Update Activities'));
 }
Exemple #5
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);
             }
         }
     }
 }
 /**
  * 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 for Events') . ' - ' . CRM_Core_BAO_UFGroup::getTitle($ufGroupId);
     CRM_Utils_System::setTitle($this->_title);
     $this->addDefaultButtons(ts('Save'));
     $this->_fields = array();
     $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 to reduce size as we are using this field in grid
         if (is_array($field['attributes']) && $this->_fields[$name]['attributes']['size'] > 19) {
             //shrink class to "form-text-medium"
             $this->_fields[$name]['attributes']['size'] = 19;
         }
     }
     $this->_fields = array_slice($this->_fields, 0, $this->_maxFields);
     $this->addButtons(array(array('type' => 'submit', 'name' => ts('Update Participant(s)'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->assign('profileTitle', $this->_title);
     $this->assign('componentIds', $this->_participantIds);
     $fileFieldExists = FALSE;
     //load all campaigns.
     if (array_key_exists('participant_campaign_id', $this->_fields)) {
         $this->_componentCampaigns = array();
         CRM_Core_PseudoConstant::populate($this->_componentCampaigns, 'CRM_Event_DAO_Participant', TRUE, 'campaign_id', 'id', ' id IN (' . implode(' , ', array_values($this->_participantIds)) . ' ) ');
     }
     //fix for CRM-2752
     // get the option value for custom data type
     $this->_roleCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantRole', 'name');
     $this->_eventNameCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventName', 'name');
     // build custom data getFields array
     $customFieldsRole = CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, NULL, $this->_roleCustomDataTypeID);
     $customFieldsEvent = CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, NULL, $this->_eventNameCustomDataTypeID);
     $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsRole, CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, NULL, NULL, TRUE));
     $this->_customFields = CRM_Utils_Array::crmArrayMerge($customFieldsEvent, $customFields);
     foreach ($this->_participantIds as $participantId) {
         $roleId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Participant", $participantId, 'role_id');
         $eventId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Participant", $participantId, 'event_id');
         foreach ($this->_fields as $name => $field) {
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 $customValue = CRM_Utils_Array::value($customFieldID, $this->_customFields);
                 $entityColumnValue = array();
                 if (CRM_Utils_Array::value('extends_entity_column_value', $customValue)) {
                     $entityColumnValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, $customValue['extends_entity_column_value']);
                 }
                 $entityColumnValueRole = CRM_Utils_Array::value($roleId, $entityColumnValue);
                 if ($this->_roleCustomDataTypeID == $customValue['extends_entity_column_id'] && $entityColumnValueRole) {
                     CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $participantId);
                 } elseif ($this->_eventNameCustomDataTypeID == $customValue['extends_entity_column_id'] && $eventId == $entityColumnValueRole) {
                     CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $participantId);
                 } elseif (CRM_Utils_System::isNull($entityColumnValueRole)) {
                     CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $participantId);
                 }
             } else {
                 if ($field['name'] == 'participant_role_id') {
                     $field['is_multiple'] = TRUE;
                 }
                 // handle non custom fields
                 CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $participantId);
             }
         }
     }
     $this->assign('fields', $this->_fields);
     // don't set the status message when form is submitted.
     $buttonName = $this->controller->getButtonName('submit');
     if ($suppressFields && $buttonName != '_qf_Batch_next') {
         CRM_Core_Session::setStatus("FILE or Autocomplete Select type field(s) in the selected profile are not supported for Batch Update and have been excluded.");
     }
     $this->addDefaultButtons(ts('Update Participant(s)'));
 }
 /**
  * Function to add the custom fields
  *
  * @param $id
  * @param $name
  * @param bool $viewOnly
  * @param null $profileContactType
  * @param null $fieldTypes
  *
  * @return void
  * @access public
  */
 function buildCustom($id, $name, $viewOnly = FALSE, $profileContactType = NULL, $fieldTypes = NULL)
 {
     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-' && $profileContactType != 'honor') {
                     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;
                 }
                 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);
             if ($addCaptcha && !$viewOnly) {
                 $captcha = CRM_Utils_ReCAPTCHA::singleton();
                 $captcha->add($this);
                 $this->assign('isCaptcha', TRUE);
             }
         }
     }
 }
 /**
  * Add onbehalf/honoree profile fields and native module fields.
  *
  * @param int $id
  * @param CRM_Core_Form $form
  */
 public function buildComponentForm($id, $form)
 {
     if (empty($id)) {
         return;
     }
     $contactID = $this->getContactID();
     foreach (array('soft_credit', 'on_behalf') as $module) {
         if ($module == 'soft_credit') {
             if (empty($form->_values['honoree_profile_id'])) {
                 continue;
             }
             if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_values['honoree_profile_id'], 'is_active')) {
                 CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of honoree and the selected honoree profile is either disabled or not found.'));
             }
             $profileContactType = CRM_Core_BAO_UFGroup::getContactType($form->_values['honoree_profile_id']);
             $requiredProfileFields = array('Individual' => array('first_name', 'last_name'), 'Organization' => array('organization_name', 'email'), 'Household' => array('household_name', 'email'));
             $validProfile = CRM_Core_BAO_UFGroup::checkValidProfile($form->_values['honoree_profile_id'], $requiredProfileFields[$profileContactType]);
             if (!$validProfile) {
                 CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of honoree and the required fields of the selected honoree profile are disabled or doesn\'t exist.'));
             }
             foreach (array('honor_block_title', 'honor_block_text') as $name) {
                 $form->assign($name, $form->_values[$name]);
             }
             $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
             // radio button for Honor Type
             foreach ($form->_values['soft_credit_types'] as $value) {
                 $honorTypes[$value] = $form->createElement('radio', NULL, NULL, $softCreditTypes[$value], $value);
             }
             $form->addGroup($honorTypes, 'soft_credit_type_id', NULL)->setAttribute('allowClear', TRUE);
             $honoreeProfileFields = CRM_Core_BAO_UFGroup::getFields($this->_values['honoree_profile_id'], FALSE, NULL, NULL, NULL, FALSE, NULL, TRUE, NULL, CRM_Core_Permission::CREATE);
             $form->assign('honoreeProfileFields', $honoreeProfileFields);
             // add the form elements
             foreach ($honoreeProfileFields as $name => $field) {
                 // If soft credit type is not chosen then make omit requiredness from honoree profile fields
                 if (count($form->_submitValues) && empty($form->_submitValues['soft_credit_type_id']) && !empty($field['is_required'])) {
                     $field['is_required'] = FALSE;
                 }
                 CRM_Core_BAO_UFGroup::buildProfile($form, $field, CRM_Profile_Form::MODE_CREATE, NULL, FALSE, FALSE, NULL, 'honor');
             }
         } else {
             if (empty($form->_values['onbehalf_profile_id'])) {
                 continue;
             }
             if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_values['onbehalf_profile_id'], 'is_active')) {
                 CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of an organization and the selected onbehalf profile is either disabled or not found.'));
             }
             $member = CRM_Member_BAO_Membership::getMembershipBlock($form->_id);
             if (empty($member['is_active'])) {
                 $msg = ts('Mixed profile not allowed for on behalf of registration/sign up.');
                 $onBehalfProfile = CRM_Core_BAO_UFGroup::profileGroups($form->_values['onbehalf_profile_id']);
                 foreach (array('Individual', 'Organization', 'Household') as $contactType) {
                     if (in_array($contactType, $onBehalfProfile) && (in_array('Membership', $onBehalfProfile) || in_array('Contribution', $onBehalfProfile))) {
                         CRM_Core_Error::fatal($msg);
                     }
                 }
             }
             if ($contactID) {
                 // retrieve all permissioned organizations of contact $contactID
                 $organizations = CRM_Contact_BAO_Relationship::getPermissionedContacts($contactID, NULL, NULL, 'Organization');
                 if (count($organizations)) {
                     // Related org url - pass checksum if needed
                     $args = array('ufId' => $form->_values['onbehalf_profile_id'], 'cid' => '');
                     if (!empty($_GET['cs'])) {
                         $args = array('ufId' => $form->_values['onbehalf_profile_id'], 'uid' => $this->_contactID, 'cs' => $_GET['cs'], 'cid' => '');
                     }
                     $locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', $args, FALSE, NULL, FALSE);
                     $form->assign('locDataURL', $locDataURL);
                 }
                 if (count($organizations) > 0) {
                     $form->add('select', 'onbehalfof_id', '', CRM_Utils_Array::collect('name', $organizations));
                     $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->assign('fieldSetTitle', ts('Organization Details'));
             if (CRM_Utils_Array::value('is_for_organization', $form->_values)) {
                 if ($form->_values['is_for_organization'] == 2) {
                     $form->assign('onBehalfRequired', TRUE);
                 } else {
                     $form->addElement('checkbox', 'is_for_organization', $form->_values['for_organization'], NULL);
                 }
             }
             $profileFields = CRM_Core_BAO_UFGroup::getFields($form->_values['onbehalf_profile_id'], FALSE, CRM_Core_Action::VIEW, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
             $form->assign('onBehalfOfFields', $profileFields);
             if (!empty($form->_submitValues['onbehalf'])) {
                 if (!empty($form->_submitValues['onbehalfof_id'])) {
                     $form->assign('submittedOnBehalf', $form->_submitValues['onbehalfof_id']);
                 }
                 $form->assign('submittedOnBehalfInfo', json_encode($form->_submitValues['onbehalf']));
             }
             $fieldTypes = array('Contact', 'Organization');
             $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
             $fieldTypes = array_merge($fieldTypes, $contactSubType);
             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('organization_name', 'email')) && empty($field['is_required'])) {
                         $field['is_required'] = 1;
                     }
                     if (count($form->_submitValues) && empty($form->_submitValues['is_for_organization']) && $form->_values['is_for_organization'] == 1 && !empty($field['is_required'])) {
                         $field['is_required'] = FALSE;
                     }
                     CRM_Core_BAO_UFGroup::buildProfile($form, $field, NULL, NULL, FALSE, 'onbehalf', NULL, 'onbehalf');
                 }
             }
         }
     }
 }
Exemple #9
0
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     $this->add('hidden', 'gid', $this->_gid);
     switch ($this->_mode) {
         case self::MODE_CREATE:
         case self::MODE_EDIT:
         case self::MODE_REGISTER:
             CRM_Utils_Hook::buildProfile($this->_ufGroup['name']);
             break;
         case self::MODE_SEARCH:
             CRM_Utils_Hook::searchProfile($this->_ufGroup['name']);
             break;
         default:
     }
     //lets have single status message, CRM-4363
     $return = FALSE;
     $statusMessage = NULL;
     if ($this->_multiRecord & CRM_Core_Action::ADD && $this->_maxRecordLimit) {
         return;
     }
     if ($this->_multiRecord & CRM_Core_Action::DELETE) {
         if (!$this->_recordExists) {
             CRM_Core_Session::setStatus(ts('The record %1 doesnot exists', array(1 => $this->_recordId)), ts('Record doesnot exists'), 'alert');
         } else {
             $this->assign('deleteRecord', TRUE);
         }
         return;
     }
     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 single status message,
     $this->assign('statusMessage', $statusMessage);
     if ($return) {
         return FALSE;
     }
     $this->assign('id', $this->_id);
     $this->assign('mode', $this->_mode);
     $this->assign('action', $this->_action);
     $this->assign('fields', $this->_fields);
     $this->assign('fieldset', isset($this->_fieldset) ? $this->_fieldset : "");
     // 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 == $this->_currentUserID || $this->_isPermissionedChecksum || in_array($this->_gid, CRM_ACL_API::group(CRM_Core_Permission::EDIT, NULL, 'civicrm_uf_group', CRM_Core_PseudoConstant::get('CRM_Core_DAO_UFField', 'uf_group_id')))) {
             $admin = TRUE;
         }
     }
     // if false, user is not logged-in.
     $anonUser = FALSE;
     if (!$this->_currentUserID) {
         $defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
         $primaryLocationType = $defaultLocationType->id;
         $anonUser = TRUE;
     }
     $this->assign('anonUser', $anonUser);
     $addCaptcha = array();
     $emailPresent = FALSE;
     // 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);
         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) {
         // suppress captcha for logged in users only
         if ($this->_currentUserID) {
             $this->_isAddCaptcha = FALSE;
         } elseif (!$this->_isAddCaptcha && !empty($addCaptcha)) {
             $this->_isAddCaptcha = TRUE;
         }
         if ($this->_gid) {
             $dao = new CRM_Core_DAO_UFGroup();
             $dao->id = $this->_gid;
             $dao->addSelect();
             $dao->addSelect('is_update_dupe');
             if ($dao->find(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->_ufGroup['add_to_group_id'] = $addToGroupId;
         }
     }
     //let's do set defaults for the profile
     $this->setDefaultsValues();
     $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);
     // 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'));
     }
 }
 /**
  * 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);
 }
 /**  
  * 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);
             }
         }
     }
 }
 /**
  * Function to assign profiles to a Smarty template
  *
  * @param string $name The name to give the Smarty variable
  * @access public
  */
 function buildCustom($name)
 {
     $fields = array();
     $session = CRM_Core_Session::singleton();
     $contactID = $session->get('userID');
     $id = $this->_ufgroup_id;
     if ($id) {
         $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);
         foreach ($fields as $key => $field) {
             CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
             $this->_fields[$key] = $field;
         }
         $this->assign($name, $fields);
     }
 }
 /**
  * Build the form
  *
  * @access public
  * @return void
  */
 function buildQuickForm()
 {
     $this->assign('surveyTypeId', $this->_surveyTypeId);
     //pickup the uf fields.
     $this->_surveyFields = array();
     if ($this->_ufGroupId) {
         require_once 'CRM/Core/BAO/UFGroup.php';
         $this->_surveyFields = CRM_Core_BAO_UFGroup::getFields($this->_ufGroupId, false, CRM_Core_Action::VIEW);
     }
     //don't load these fields in grid.
     $removeFields = array('File', 'Autocomplete-Select', 'RichTextEditor');
     require_once 'CRM/Core/BAO/CustomField.php';
     foreach ($this->_surveyFields as $name => $field) {
         if (CRM_Core_BAO_CustomField::getKeyID($name) && in_array($field['html_type'], $removeFields)) {
             unset($this->_surveyFields[$name]);
         }
     }
     //build all fields.
     $exposedSurveyFields = array();
     foreach ($this->_contactIds as $contactId) {
         //build the profile fields.
         foreach ($this->_surveyFields as $name => $field) {
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 $customValue = CRM_Utils_Array::value($customFieldID, $customFields);
                 // allow custom fields from profile which are having
                 // the activty type same of that selected survey.
                 $valueType = CRM_Utils_Array::value('extends_entity_column_value', $customValue);
                 if (!$valueType || $valueType == $this->_surveyTypeId) {
                     CRM_Core_BAO_UFGroup::buildProfile($this, $field, null, $contactId);
                     $exposedSurveyFields[$name] = $field;
                 }
             }
         }
         //build the result field.
         if (!empty($this->_resultOptions)) {
             $this->add('select', "field[{$contactId}][result]", ts('Result'), array('' => ts('- select -')) + array_combine($this->_resultOptions, $this->_resultOptions));
         }
         $this->add('text', "field[{$contactId}][note]", ts('Note'));
         //need to keep control for release/reserve.
         if ($this->_allowAjaxReleaseButton) {
             $this->addElement('hidden', "field[{$contactId}][is_release_or_reserve]", 0, array('id' => "field_{$contactId}_is_release_or_reserve"));
         }
     }
     $this->assign('surveyFields', empty($exposedSurveyFields) ? false : $exposedSurveyFields);
     //no need to get qf buttons.
     if ($this->_votingTab) {
         return;
     }
     $buttons = array(array('type' => 'cancel', 'name' => ts('Done'), 'subName' => 'interview', 'isDefault' => true));
     $manageCampaign = CRM_Core_Permission::check('manage campaign');
     $adminCampaign = CRM_Core_Permission::check('administer CiviCampaign');
     if ($manageCampaign || $adminCampaign || CRM_Core_Permission::check('release campaign contacts')) {
         $buttons[] = array('type' => 'next', 'name' => ts('Release Respondents >>'), 'subName' => 'interviewToRelease');
     }
     if ($manageCampaign || $adminCampaign || CRM_Core_Permission::check('reserve campaign contacts')) {
         $buttons[] = array('type' => 'done', 'name' => ts('Reserve More Respondents >>'), 'subName' => 'interviewToReserve');
     }
     $this->addButtons($buttons);
 }
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     $this->assign('surveyTypeId', $this->_surveyTypeId);
     $options = array('' => ' - none - ', 'civicrm_address.street_name' => 'Street Name', 'civicrm_address.street_number%2' => 'Odd / Even Street Number', 'civicrm_address.street_number' => 'Street Number', 'contact_a.sort_name' => 'Respondent Name');
     for ($i = 1; $i < count($options); $i++) {
         $this->addElement('select', "order_bys[{$i}][column]", ts('Order by Column'), $options);
         $this->addElement('select', "order_bys[{$i}][order]", ts('Order by Order'), array('ASC' => 'Ascending', 'DESC' => 'Descending'));
     }
     //pickup the uf fields.
     $this->_surveyFields = CRM_Campaign_BAO_Survey::getSurveyResponseFields($this->_surveyId, $this->_surveyTypeId);
     foreach ($this->_contactIds as $contactId) {
         //build the profile fields.
         foreach ($this->_surveyFields as $name => $field) {
             if ($field) {
                 CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $contactId);
             }
         }
         //build the result field.
         if (!empty($this->_resultOptions)) {
             $this->add('select', "field[{$contactId}][result]", ts('Result'), array('' => ts('- select -')) + array_combine($this->_resultOptions, $this->_resultOptions));
         }
         $this->add('text', "field[{$contactId}][note]", ts('Note'));
         //need to keep control for release/reserve.
         if ($this->_allowAjaxReleaseButton) {
             $this->addElement('hidden', "field[{$contactId}][is_release_or_reserve]", 0, array('id' => "field_{$contactId}_is_release_or_reserve"));
         }
     }
     $this->assign('surveyFields', empty($this->_surveyFields) ? FALSE : $this->_surveyFields);
     //no need to get qf buttons.
     if ($this->_votingTab) {
         return;
     }
     $buttons = array(array('type' => 'cancel', 'name' => ts('Done'), 'subName' => 'interview', 'isDefault' => TRUE));
     $buttons[] = array('type' => 'submit', 'name' => ts('Order By >>'), 'subName' => 'orderBy');
     $manageCampaign = CRM_Core_Permission::check('manage campaign');
     $adminCampaign = CRM_Core_Permission::check('administer CiviCampaign');
     if ($manageCampaign || $adminCampaign || CRM_Core_Permission::check('release campaign contacts')) {
         $buttons[] = array('type' => 'next', 'name' => ts('Release Respondents >>'), 'subName' => 'interviewToRelease');
     }
     if ($manageCampaign || $adminCampaign || CRM_Core_Permission::check('reserve campaign contacts')) {
         $buttons[] = array('type' => 'done', 'name' => ts('Reserve More Respondents >>'), 'subName' => 'interviewToReserve');
     }
     $this->addButtons($buttons);
 }
Exemple #15
0
 /**
  * Build the form
  *
  * @access public
  * @return void
  */
 function buildQuickForm()
 {
     $ufGroupId = $this->get('ufGroupId');
     if (!$ufGroupId) {
         CRM_Core_Error::fatal('ufGroupId is missing');
     }
     require_once "CRM/Core/BAO/UFGroup.php";
     $this->_title = ts('Batch Update') . ' - ' . CRM_Core_BAO_UFGroup::getTitle($ufGroupId);
     CRM_Utils_System::setTitle($this->_title);
     $this->addDefaultButtons(ts('Save'));
     $this->_fields = array();
     $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]);
         }
     }
     $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);
     foreach ($this->_contactIds as $contactId) {
         foreach ($this->_fields as $name => $field) {
             CRM_Core_BAO_UFGroup::buildProfile($this, $field, null, $contactId);
         }
     }
     $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("FILE or Autocomplete Select type field(s) in the selected profile are not supported for Batch Update and have been excluded.");
     }
     $this->addDefaultButtons(ts('Update Contacts'));
     $this->addFormRule(array('CRM_Contact_Form_Task_Batch', 'formRule'));
 }
 /**
  * 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);
             }
         }
     }
 }
Exemple #17
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     foreach ($this->_fields as $name => $field) {
         if (!CRM_Utils_Array::value('is_view', $field)) {
             CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE);
         }
     }
     $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done with Preview'), 'isDefault' => true)));
 }
Exemple #18
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     foreach ($this->_fields as $name => $field) {
         if (!CRM_Utils_Array::value('is_view', $field)) {
             CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE);
         }
     }
 }
Exemple #19
0
 /**
  * Build the petition profile form.
  *
  * @param int $id
  * @param string $name
  * @param bool $viewOnly
  */
 public function buildCustom($id, $name, $viewOnly = FALSE)
 {
     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) {
             $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);
                 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;
                 }
             }
             if ($addCaptcha && !$viewOnly) {
                 $captcha = CRM_Utils_ReCAPTCHA::singleton();
                 $captcha->add($this);
                 $this->assign("isCaptcha", TRUE);
             }
         }
     }
 }
 /** 
  * Function to build the form 
  * 
  * @return None 
  * @access public 
  */
 public function buildQuickForm()
 {
     require_once 'CRM/Contribute/BAO/PCP.php';
     $id = CRM_Contribute_BAO_PCP::getSupporterProfileId($this->_pageId);
     if (CRM_Contribute_BAO_PCP::checkEmailProfile($id)) {
         $this->assign('profileDisplay', true);
     }
     $fields = null;
     require_once "CRM/Core/BAO/UFGroup.php";
     if ($this->_contactID) {
         if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $this->_contactID)) {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, false, CRM_Core_Action::ADD);
         }
         $this->addFormRule(array('CRM_Contribute_Form_PCP_PCPAccount', 'formRule'), $this);
     } else {
         require_once 'CRM/Core/BAO/CMSUser.php';
         CRM_Core_BAO_CMSUser::buildForm($this, $id, true);
         $fields = CRM_Core_BAO_UFGroup::getFields($id, false, CRM_Core_Action::ADD);
     }
     if ($fields) {
         $this->assign('fields', $fields);
         $addCaptcha = false;
         foreach ($fields as $key => $field) {
             if (isset($field['data_type']) && $field['data_type'] == 'File') {
                 // ignore file upload fields
                 continue;
             }
             require_once "CRM/Core/BAO/UFGroup.php";
             require_once "CRM/Profile/Form.php";
             CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE);
             $this->_fields[$key] = $field;
             if ($field['add_captcha']) {
                 $addCaptcha = true;
             }
         }
         if ($addCaptcha) {
             require_once 'CRM/Utils/ReCAPTCHA.php';
             $captcha =& CRM_Utils_ReCAPTCHA::singleton();
             $captcha->add($this);
             $this->assign("isCaptcha", true);
         }
     }
     require_once "CRM/Contribute/PseudoConstant.php";
     $this->assign('campaignName', CRM_Contribute_PseudoConstant::contributionPage($this->_pageId));
     if ($this->_single) {
         $button = array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')));
     } else {
         $button[] = array('type' => 'next', 'name' => ts('Continue >>'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => true);
     }
     $this->addFormRule(array('CRM_Contribute_Form_PCP_PCPAccount', 'formRule'), $this);
     $this->addButtons($button);
 }
Exemple #21
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     $ufGroupId = $this->get('ufGroupId');
     if (!$ufGroupId) {
         CRM_Core_Error::fatal('ufGroupId is missing');
     }
     $this->_title = ts('Update multiple contacts') . ' - ' . 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');
     foreach ($this->_contactIds as $contactId) {
         $profileFields = $this->_fields;
         CRM_Core_BAO_Address::checkContactSharedAddressFields($profileFields, $contactId);
         foreach ($profileFields as $name => $field) {
             CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $contactId);
             if (in_array($field['name'], $preserveDefaultsArray)) {
                 $this->_preserveDefault = FALSE;
             }
         }
     }
     $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 Update multiple contacts."), ts('Some Fields Excluded'), 'info');
     }
     $this->addDefaultButtons(ts('Update Contacts'));
     $this->addFormRule(array('CRM_Contact_Form_Task_Batch', 'formRule'));
 }
Exemple #22
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 object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     foreach ($this->_fields as $name => $field) {
         if (empty($field['is_view'])) {
             CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE);
         }
     }
 }
Exemple #24
0
 /**
  * Build form for related contacts / on behalf of organization.
  *
  * @param CRM_Core_Form $form
  *
  */
 public static function buildQuickForm(&$form)
 {
     $form->assign('fieldSetTitle', ts('Organization Details'));
     $form->assign('buildOnBehalfForm', TRUE);
     $contactID = $form->_contactID;
     if ($contactID && count($form->_employers) >= 1) {
         $form->add('text', 'organization_id', ts('Select an existing related Organization OR enter a new one'));
         $form->add('select', 'onbehalfof_id', '', CRM_Utils_Array::collect('name', $form->_employers));
         $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'));
     }
     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('organization_name', 'email')) && empty($field['is_required'])) {
                 $field['is_required'] = 1;
             }
             CRM_Core_BAO_UFGroup::buildProfile($form, $field, NULL, NULL, FALSE, 'onbehalf');
         }
     }
     $form->assign('onBehalfOfFields', $profileFields);
     $form->addElement('hidden', 'hidden_onbehalf_profile', 1);
 }
Exemple #25
0
 /**
  * Build the form
  *
  * @access public
  * @return void
  */
 function buildQuickForm()
 {
     $ufGroupId = $this->get('ufGroupId');
     if (!$ufGroupId) {
         CRM_Core_Error::fatal('ufGroupId is missing');
     }
     require_once "CRM/Core/BAO/UFGroup.php";
     require_once "CRM/Core/BAO/CustomGroup.php";
     $this->_title = ts('Batch Update for Contributions') . ' - ' . CRM_Core_BAO_UFGroup::getTitle($ufGroupId);
     CRM_Utils_System::setTitle($this->_title);
     $this->addDefaultButtons(ts('Save'));
     $this->_fields = array();
     $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 to reduce size as we are using this field in grid
         if (is_array($field['attributes']) && $this->_fields[$name]['attributes']['size'] > 19) {
             //shrink class to "form-text-medium"
             $this->_fields[$name]['attributes']['size'] = 19;
         }
     }
     $this->_fields = array_slice($this->_fields, 0, $this->_maxFields);
     $this->addButtons(array(array('type' => 'submit', 'name' => ts('Update Contribution(s)'), 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->assign('profileTitle', $this->_title);
     $this->assign('componentIds', $this->_contributionIds);
     $fileFieldExists = false;
     //fix for CRM-2752
     require_once "CRM/Core/BAO/CustomField.php";
     $customFields = CRM_Core_BAO_CustomField::getFields('Contribution');
     foreach ($this->_contributionIds as $contributionId) {
         $typeId = CRM_Core_DAO::getFieldValue("CRM_Contribute_DAO_Contribution", $contributionId, 'contribution_type_id');
         foreach ($this->_fields as $name => $field) {
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 $customValue = CRM_Utils_Array::value($customFieldID, $customFields);
                 if ($typeId == $customValue['extends_entity_column_value'] || CRM_Utils_System::isNull($customValue['extends_entity_column_value'])) {
                     CRM_Core_BAO_UFGroup::buildProfile($this, $field, null, $contributionId);
                 }
             } else {
                 // handle non custom fields
                 CRM_Core_BAO_UFGroup::buildProfile($this, $field, null, $contributionId);
             }
         }
     }
     $this->assign('fields', $this->_fields);
     // don't set the status message when form is submitted.
     $buttonName = $this->controller->getButtonName('submit');
     if ($suppressFields && $buttonName != '_qf_Batch_next') {
         CRM_Core_Session::setStatus("FILE or Autocomplete Select type field(s) in the selected profile are not supported for Batch Update and have been excluded.");
     }
     $this->addDefaultButtons(ts('Update Contributions'));
 }
 /**
  * assign profiles to a Smarty template
  *
  * @param string $name The name to give the Smarty variable
  * @access public
  */
 function buildCustom()
 {
     $contactID = CRM_Utils_Array::value('userID', $_SESSION['CiviCRM']);
     $profiles = array();
     $fieldList = array();
     // master field list
     foreach ($this->getProfileIDs() as $profileID) {
         $fields = CRM_Core_BAO_UFGroup::getFields($profileID, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, 'field_name', TRUE);
         foreach ($fields as $key => $field) {
             if (array_key_exists($key, $fieldList)) {
                 continue;
             }
             CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
             $profiles[$profileID][$key] = $fieldList[$key] = $field;
         }
     }
     $this->assign('customProfiles', $profiles);
 }
Exemple #27
0
 /**
  * Build the form
  *
  * @access public
  *
  * @return void
  */
 function buildQuickForm()
 {
     if (!$this->_profileId) {
         CRM_Core_Error::fatal(ts('Profile for bulk data entry is missing.'));
     }
     $this->addElement('hidden', 'batch_id', $this->_batchId);
     // get the profile information
     if ($this->_batchInfo['type_id'] == 1) {
         CRM_Utils_System::setTitle(ts('Batch Data Entry for Contributions'));
         $customFields = CRM_Core_BAO_CustomField::getFields('Contribution');
     } else {
         CRM_Utils_System::setTitle(ts('Batch Data Entry for Memberships'));
         $customFields = CRM_Core_BAO_CustomField::getFields('Membership');
     }
     $this->_fields = array();
     $this->_fields = CRM_Core_BAO_UFGroup::getFields($this->_profileId, 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 to reduce size as we are using this field in grid
         if (is_array($field['attributes']) && $this->_fields[$name]['attributes']['size'] > 19) {
             //shrink class to "form-text-medium"
             $this->_fields[$name]['attributes']['size'] = 19;
         }
     }
     $this->addFormRule(array('CRM_Batch_Form_Entry', 'formRule'), $this);
     // add the force save button
     $forceSave = $this->getButtonName('upload', 'force');
     $this->addElement('submit', $forceSave, ts('Ignore Mismatch & Process the Batch?'));
     $this->addButtons(array(array('type' => 'upload', 'name' => ts('Validate & Process the Batch'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Save & Continue Later'))));
     $this->assign('rowCount', $this->_batchInfo['item_count'] + 1);
     $fileFieldExists = FALSE;
     $preserveDefaultsArray = array('first_name', 'last_name', 'middle_name', 'organization_name', 'household_name');
     $contactTypes = array('Contact', 'Individual', 'Household', 'Organization');
     $contactReturnProperties = array();
     for ($rowNumber = 1; $rowNumber <= $this->_batchInfo['item_count']; $rowNumber++) {
         $this->addEntityRef("primary_contact_id[{$rowNumber}]", '', array('create' => TRUE, 'placeholder' => ts('- select -')));
         // special field specific to membership batch udpate
         if ($this->_batchInfo['type_id'] == 2) {
             $options = array(1 => ts('Add Membership'), 2 => ts('Renew Membership'));
             $this->add('select', "member_option[{$rowNumber}]", '', $options);
         }
         foreach ($this->_fields as $name => $field) {
             if (in_array($field['field_type'], $contactTypes)) {
                 $fld = explode('-', $field['name']);
                 $contactReturnProperties[$field['name']] = $fld[0];
             }
             CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, NULL, FALSE, FALSE, $rowNumber);
             if (in_array($field['name'], $preserveDefaultsArray)) {
                 $this->_preserveDefault = FALSE;
             }
         }
     }
     $this->assign('fields', $this->_fields);
     CRM_Core_Resources::singleton()->addSetting(array('contact' => array('return' => implode(',', $contactReturnProperties), 'fieldmap' => array_flip($contactReturnProperties))));
     // don't set the status message when form is submitted.
     $buttonName = $this->controller->getButtonName('submit');
     if ($suppressFields && $buttonName != '_qf_Entry_next') {
         CRM_Core_Session::setStatus(ts("FILE or Autocomplete Select type field(s) in the selected profile are not supported for Batch Update."), ts("Some fields have been excluded."), "info");
     }
 }
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     $profileID = CRM_Core_DAO::getFieldValue('CRM_Auction_DAO_Auction', $this->_aid, 'donor_profile_id');
     if (!$profileID) {
         CRM_Core_Error::fatal('Profile not configured for this auction.');
     }
     require_once 'CRM/Auction/BAO/Item.php';
     if (CRM_Auction_BAO_Item::isEmailInProfile($profileID)) {
         $this->assign('profileDisplay', TRUE);
     }
     $fields = NULL;
     require_once "CRM/Core/BAO/UFGroup.php";
     if ($this->_donorID) {
         if (CRM_Core_BAO_UFGroup::filterUFGroups($profileID, $this->_donorID)) {
             $fields = CRM_Core_BAO_UFGroup::getFields($profileID, FALSE, CRM_Core_Action::ADD);
         }
         $this->addFormRule(array('CRM_Auction_Form_ItemAccount', 'formRule'), $this);
     } else {
         require_once 'CRM/Core/BAO/CMSUser.php';
         CRM_Core_BAO_CMSUser::buildForm($this, $profileID, TRUE);
         $fields = CRM_Core_BAO_UFGroup::getFields($profileID, FALSE, CRM_Core_Action::ADD);
     }
     if ($fields) {
         $this->assign('fields', $fields);
         $addCaptcha = FALSE;
         foreach ($fields as $key => $field) {
             if (isset($field['data_type']) && $field['data_type'] == 'File') {
                 // ignore file upload fields
                 continue;
             }
             require_once "CRM/Core/BAO/UFGroup.php";
             require_once "CRM/Profile/Form.php";
             CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE);
             $this->_fields[$key] = $field;
             if ($field['add_captcha']) {
                 $addCaptcha = TRUE;
             }
         }
         if ($addCaptcha) {
             require_once 'CRM/Utils/ReCAPTCHA.php';
             $captcha =& CRM_Utils_ReCAPTCHA::singleton();
             $captcha->add($this);
             $this->assign("isCaptcha", TRUE);
         }
     }
     $button[] = array('type' => 'next', 'name' => ts('Continue >>'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE);
     $this->addButtons($button);
 }
Exemple #29
0
 /**
  * Add the custom fields.
  *
  * @param int $id
  * @param string $name
  * @param bool $viewOnly
  */
 public function buildCustom($id, $name, $viewOnly = FALSE)
 {
     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 (empty($this->_params[0]['additional_participants']) && 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);
                 CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
                 $this->_fields[$key] = $field;
             }
         }
         if ($addCaptcha && !$viewOnly) {
             $captcha = CRM_Utils_ReCAPTCHA::singleton();
             $captcha->add($this);
             $this->assign('isCaptcha', TRUE);
         }
     }
 }
Exemple #30
0
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     $id = CRM_PCP_BAO_PCP::getSupporterProfileId($this->_pageId, $this->_component);
     if (CRM_PCP_BAO_PCP::checkEmailProfile($id)) {
         $this->assign('profileDisplay', TRUE);
     }
     $fields = NULL;
     if ($this->_contactID) {
         if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $this->_contactID)) {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD);
         }
         $this->addFormRule(array('CRM_PCP_Form_PCPAccount', 'formRule'), $this);
     } else {
         CRM_Core_BAO_CMSUser::buildForm($this, $id, TRUE);
         $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD);
     }
     if ($fields) {
         $this->assign('fields', $fields);
         $addCaptcha = FALSE;
         foreach ($fields as $key => $field) {
             if (isset($field['data_type']) && $field['data_type'] == 'File') {
                 // ignore file upload fields
                 continue;
             }
             CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE);
             $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;
             }
         }
         if ($addCaptcha) {
             $captcha =& CRM_Utils_ReCAPTCHA::singleton();
             $captcha->add($this);
             $this->assign('isCaptcha', TRUE);
         }
     }
     if ($this->_component == 'contribute') {
         $this->assign('campaignName', CRM_Contribute_PseudoConstant::contributionPage($this->_pageId));
     } elseif ($this->_component == 'event') {
         $this->assign('campaignName', CRM_Event_PseudoConstant::event($this->_pageId));
     }
     if ($this->_single) {
         $button = array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')));
     } else {
         $button[] = array('type' => 'next', 'name' => ts('Continue >>'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE);
     }
     $this->addFormRule(array('CRM_PCP_Form_PCPAccount', 'formRule'), $this);
     $this->addButtons($button);
 }