コード例 #1
0
 /**
  * Set variables up before form is built.
  *
  * @param CRM_Core_Form $form
  *
  * @return void
  */
 public static function preProcess(&$form)
 {
     $contriDAO = new CRM_Contribute_DAO_Contribution();
     $contriDAO->id = $form->_id;
     $contriDAO->find(TRUE);
     if ($contriDAO->contribution_page_id) {
         $ufJoinParams = array('module' => 'soft_credit', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $contriDAO->contribution_page_id);
         $profileId = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         //check if any honree profile is enabled if yes then assign its profile type to $_honoreeProfileType
         // which will be used to constraint soft-credit contact type in formRule, CRM-13981
         if ($profileId[0]) {
             $form->_honoreeProfileType = CRM_Core_BAO_UFGroup::getContactType($profileId[0]);
         }
     }
 }
コード例 #2
0
ファイル: Confirm.php プロジェクト: hyebahi/civicrm-core
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     $this->assignToTemplate();
     $params = $this->_params;
     // make sure we have values for it
     if (!empty($this->_values['honoree_profile_id']) && !empty($params['soft_credit_type_id'])) {
         $honorName = NULL;
         $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
         $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]);
         CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($this, $params['honor']);
         $fieldTypes = array('Contact');
         $fieldTypes[] = CRM_Core_BAO_UFGroup::getContactType($this->_values['honoree_profile_id']);
         $this->buildCustom($this->_values['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes);
     }
     $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values));
     $amount_block_is_active = $this->get('amount_block_is_active');
     $this->assign('amount_block_is_active', $amount_block_is_active);
     $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
     if ($invoicing) {
         $getTaxDetails = FALSE;
         $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
         foreach ($this->_lineItem as $key => $value) {
             foreach ($value as $v) {
                 if (isset($v['tax_rate'])) {
                     if ($v['tax_rate'] != '') {
                         $getTaxDetails = TRUE;
                     }
                 }
             }
         }
         $this->assign('getTaxDetails', $getTaxDetails);
         $this->assign('taxTerm', $taxTerm);
         $this->assign('totalTaxAmount', $params['tax_amount']);
     }
     if (!empty($params['selectProduct']) && $params['selectProduct'] != 'no_thanks') {
         $option = CRM_Utils_Array::value('options_' . $params['selectProduct'], $params);
         $productID = $params['selectProduct'];
         CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE, $productID, $option);
         $this->set('productID', $productID);
         $this->set('option', $option);
     }
     $config = CRM_Core_Config::singleton();
     if (in_array('CiviMember', $config->enableComponents)) {
         if (isset($params['selectMembership']) && $params['selectMembership'] != 'no_thanks') {
             $this->buildMembershipBlock($this->_membershipContactID, FALSE, $params['selectMembership'], FALSE);
             if (!empty($params['auto_renew'])) {
                 $this->assign('auto_renew', TRUE);
             }
         } else {
             $this->assign('membershipBlock', FALSE);
         }
     }
     $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE);
     $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE);
     if (!empty($this->_values['onbehalf_profile_id']) && !empty($params['onbehalf'])) {
         $fieldTypes = array('Contact', 'Organization');
         $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
         $fieldTypes = array_merge($fieldTypes, $contactSubType);
         if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) {
             $fieldTypes = array_merge($fieldTypes, array('Membership'));
         } else {
             $fieldTypes = array_merge($fieldTypes, array('Contribution'));
         }
         $this->buildCustom($this->_values['onbehalf_profile_id'], 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes);
     }
     $this->_separateMembershipPayment = $this->get('separateMembershipPayment');
     $this->assign('is_separate_payment', $this->_separateMembershipPayment);
     if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
         $this->assign('lineItem', $this->_lineItem);
     } else {
         $this->assign('is_quick_config', 1);
         $this->_params['is_quick_config'] = 1;
     }
     $this->assign('priceSetID', $this->_priceSetId);
     $paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(FALSE, NULL, 'name');
     if ($this->_paymentProcessor && $this->_paymentProcessor['payment_processor_type_id'] == CRM_Utils_Array::key('Google_Checkout', $paymentProcessorType) && !$this->_params['is_pay_later'] && !($this->_amount == 0)) {
         $this->_checkoutButtonName = $this->getButtonName('next', 'checkout');
         $this->add('image', $this->_checkoutButtonName, $this->_paymentProcessor['url_button'], array('class' => 'crm-form-submit'));
         $this->addButtons(array(array('type' => 'back', 'name' => ts('Go Back'))));
     } else {
         // The concept of contributeMode is deprecated.
         // the is_monetary concept probably should be too as it can be calculated from
         // the existence of 'amount' & seems fragile.
         if ($this->_contributeMode == 'notify' || !$this->_values['is_monetary'] || $this->_amount <= 0.0 || $this->_params['is_pay_later'] || $this->_separateMembershipPayment && $this->_amount <= 0.0) {
             $contribButton = ts('Continue');
             $this->assign('button', ts('Continue'));
         } else {
             $contribButton = ts('Make Contribution');
             $this->assign('button', ts('Make Contribution'));
         }
         $this->addButtons(array(array('type' => 'next', 'name' => $contribButton, 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE, 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');")), array('type' => 'back', 'name' => ts('Go Back'))));
     }
     $defaults = array();
     $fields = array_fill_keys(array_keys($this->_fields), 1);
     $fields["billing_state_province-{$this->_bltID}"] = $fields["billing_country-{$this->_bltID}"] = $fields["email-{$this->_bltID}"] = 1;
     $contact = $this->_params;
     foreach ($fields as $name => $dontCare) {
         // Recursively set defaults for nested fields
         if (isset($contact[$name]) && is_array($contact[$name]) && ($name == 'onbehalf' || $name == 'honor')) {
             foreach ($contact[$name] as $fieldName => $fieldValue) {
                 if (is_array($fieldValue) && !in_array($this->_fields[$name][$fieldName]['html_type'], array('Multi-Select', 'AdvMulti-Select'))) {
                     foreach ($fieldValue as $key => $value) {
                         $defaults["{$name}[{$fieldName}][{$key}]"] = $value;
                     }
                 } else {
                     $defaults["{$name}[{$fieldName}]"] = $fieldValue;
                 }
             }
         } elseif (isset($contact[$name])) {
             $defaults[$name] = $contact[$name];
             if (substr($name, 0, 7) == 'custom_') {
                 $timeField = "{$name}_time";
                 if (isset($contact[$timeField])) {
                     $defaults[$timeField] = $contact[$timeField];
                 }
                 if (isset($contact["{$name}_id"])) {
                     $defaults["{$name}_id"] = $contact["{$name}_id"];
                 }
             } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && !empty($contact[$name . '_custom'])) {
                 $defaults[$name . '_custom'] = $contact[$name . '_custom'];
             }
         }
     }
     $this->assign('useForMember', $this->get('useForMember'));
     $this->setDefaults($defaults);
     $this->freeze();
 }
コード例 #3
0
 /**
  * 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');
                 }
             }
         }
     }
 }
コード例 #4
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     $this->assignToTemplate();
     $params = $this->_params;
     $honor_block_is_active = $this->get('honor_block_is_active');
     // make sure we have values for it
     if ($honor_block_is_active && !empty($params['soft_credit_type_id'])) {
         $honorName = null;
         $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
         $this->assign('honor_block_is_active', $honor_block_is_active);
         $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]);
         CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($this, $params['honor'], $params['honoree_profile_id']);
         $fieldTypes = array('Contact');
         $fieldTypes[] = CRM_Core_BAO_UFGroup::getContactType($params['honoree_profile_id']);
         $this->buildCustom($params['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes);
     }
     $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values));
     $amount_block_is_active = $this->get('amount_block_is_active');
     $this->assign('amount_block_is_active', $amount_block_is_active);
     if (!empty($params['selectProduct']) && $params['selectProduct'] != 'no_thanks') {
         $option = CRM_Utils_Array::value('options_' . $params['selectProduct'], $params);
         $productID = $params['selectProduct'];
         CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE, $productID, $option);
         $this->set('productID', $productID);
         $this->set('option', $option);
     }
     $config = CRM_Core_Config::singleton();
     if (in_array('CiviMember', $config->enableComponents)) {
         if (isset($params['selectMembership']) && $params['selectMembership'] != 'no_thanks') {
             CRM_Member_BAO_Membership::buildMembershipBlock($this, $this->_id, $this->_membershipContactID, FALSE, $params['selectMembership'], FALSE);
         } else {
             $this->assign('membershipBlock', FALSE);
         }
     }
     $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE);
     $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE);
     if (!empty($params['hidden_onbehalf_profile'])) {
         $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id);
         $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         $profileId = $OnBehalfProfile[0];
         $fieldTypes = array('Contact', 'Organization');
         $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
         $fieldTypes = array_merge($fieldTypes, $contactSubType);
         if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) {
             $fieldTypes = array_merge($fieldTypes, array('Membership'));
         } else {
             $fieldTypes = array_merge($fieldTypes, array('Contribution'));
         }
         $this->buildCustom($profileId, 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes);
     }
     $this->_separateMembershipPayment = $this->get('separateMembershipPayment');
     $this->assign('is_separate_payment', $this->_separateMembershipPayment);
     if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
         $this->assign('lineItem', $this->_lineItem);
     } else {
         $this->assign('is_quick_config', 1);
         $this->_params['is_quick_config'] = 1;
     }
     $this->assign('priceSetID', $this->_priceSetId);
     $paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(false, null, 'name');
     if ($this->_paymentProcessor && $this->_paymentProcessor['payment_processor_type_id'] == CRM_Utils_Array::key('Google_Checkout', $paymentProcessorType) && !$this->_params['is_pay_later'] && !($this->_amount == 0)) {
         $this->_checkoutButtonName = $this->getButtonName('next', 'checkout');
         $this->add('image', $this->_checkoutButtonName, $this->_paymentProcessor['url_button'], array('class' => 'form-submit'));
         $this->addButtons(array(array('type' => 'back', 'name' => ts('<< Go Back'))));
     } else {
         if ($this->_contributeMode == 'notify' || !$this->_values['is_monetary'] || $this->_amount <= 0.0 || $this->_params['is_pay_later'] || $this->_separateMembershipPayment && $this->_amount <= 0.0) {
             $contribButton = ts('Continue >>');
             $this->assign('button', ts('Continue'));
         } else {
             $contribButton = ts('Make Contribution');
             $this->assign('button', ts('Make Contribution'));
         }
         $this->addButtons(array(array('type' => 'next', 'name' => $contribButton, 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE, 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');")), array('type' => 'back', 'name' => ts('Go Back'))));
     }
     $defaults = array();
     $fields = array();
     foreach ($this->_fields as $name => $dontCare) {
         if ($name != 'onbehalf' || $name != 'honor') {
             $fields[$name] = 1;
         }
     }
     $fields["billing_state_province-{$this->_bltID}"] = $fields["billing_country-{$this->_bltID}"] = $fields["email-{$this->_bltID}"] = 1;
     $contact = $this->_params;
     foreach ($fields as $name => $dontCare) {
         if (isset($contact[$name])) {
             $defaults[$name] = $contact[$name];
             if (substr($name, 0, 7) == 'custom_') {
                 $timeField = "{$name}_time";
                 if (isset($contact[$timeField])) {
                     $defaults[$timeField] = $contact[$timeField];
                 }
                 if (isset($contact["{$name}_id"])) {
                     $defaults["{$name}_id"] = $contact["{$name}_id"];
                 }
             } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && !empty($contact[$name . '_custom'])) {
                 $defaults[$name . '_custom'] = $contact[$name . '_custom'];
             }
         }
     }
     $this->assign('useForMember', $this->get('useForMember'));
     // now fix all state country selectors
     CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
     $this->setDefaults($defaults);
     $this->freeze();
 }
コード例 #5
0
 /**
  * Function to assign honor profile fields to template/form, if $honorId (as soft-credit's contact_id)
  * is passed  then  whole honoreeprofile fields with title/value assoc array assigned or only honoreeName
  * is assigned
  *
  * @param CRM_Core_Form $form
  * @param array $params
  * @param int $honoreeprofileId
  * @param int $honorId
  */
 public static function formatHonoreeProfileFields($form, $params, $honoreeprofileId, $honorId = NULL)
 {
     $profileContactType = CRM_Core_BAO_UFGroup::getContactType($honoreeprofileId);
     $profileFields = CRM_Core_BAO_UFGroup::getFields($honoreeprofileId);
     $honoreeProfileFields = $values = array();
     $honorName = NULL;
     if ($honorId) {
         CRM_Core_BAO_UFGroup::getValues($honorId, $profileFields, $values, FALSE, $params);
         if (empty($params)) {
             foreach ($profileFields as $name => $field) {
                 $title = $field['title'];
                 $params[$field['name']] = $values[$title];
             }
         }
     }
     //remove name related fields and construct name string with prefix/suffix
     //which will be later assigned to template
     switch ($profileContactType) {
         case 'Individual':
             if (array_key_exists('prefix_id', $params)) {
                 $honorName = CRM_Utils_Array::value(CRM_Utils_Array::value('prefix_id', $params), CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id'));
                 unset($profileFields['prefix_id']);
             }
             $honorName .= ' ' . $params['first_name'] . ' ' . $params['last_name'];
             unset($profileFields['first_name']);
             unset($profileFields['last_name']);
             if (array_key_exists('suffix_id', $params)) {
                 $honorName .= ' ' . CRM_Utils_Array::value(CRM_Utils_Array::value('suffix_id', $params), CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id'));
                 unset($profileFields['suffix_id']);
             }
             break;
         case 'Organization':
             $honorName = $params['organization_name'];
             unset($profileFields['organization_name']);
             break;
         case 'Household':
             $honorName = $params['household_name'];
             unset($profileFields['household_name']);
             break;
     }
     if ($honorId) {
         $honoreeProfileFields['Name'] = $honorName;
         foreach ($profileFields as $name => $field) {
             $title = $field['title'];
             $honoreeProfileFields[$title] = $values[$title];
         }
         $form->assign('honoreeProfile', $honoreeProfileFields);
     } else {
         $form->assign('honorName', $honorName);
     }
 }
コード例 #6
0
ファイル: Form.php プロジェクト: hyebahi/civicrm-core
 /**
  * Global form rule.
  *
  * @param array $fields
  *   The input form values.
  * @param array $files
  *   The uploaded files if any.
  * @param CRM_Core_Form $form
  *   The form object.
  *
  * @return bool|array
  *   true if no errors, else array of errors
  */
 public static function formRule($fields, $files, $form)
 {
     CRM_Utils_Hook::validateProfile($form->_ufGroup['name']);
     $errors = array();
     // if no values, return
     if (empty($fields)) {
         return TRUE;
     }
     $register = NULL;
     // hack we use a -1 in options to indicate that its registration
     if ($form->_id) {
         $form->_isUpdateDupe = 1;
     }
     if ($form->_mode == CRM_Profile_Form::MODE_REGISTER) {
         $register = TRUE;
     }
     // dont check for duplicates during registration validation: CRM-375
     if (!$register && empty($fields['_qf_Edit_upload_duplicate'])) {
         // fix for CRM-3240
         if (!empty($fields['email-Primary'])) {
             $fields['email'] = CRM_Utils_Array::value('email-Primary', $fields);
         }
         // fix for CRM-6141
         if (!empty($fields['phone-Primary-1']) && empty($fields['phone-Primary'])) {
             $fields['phone-Primary'] = $fields['phone-Primary-1'];
         }
         $ctype = CRM_Core_BAO_UFGroup::getContactType($form->_gid);
         // If all profile fields is of Contact Type then consider
         // profile is of Individual type(default).
         if (!$ctype) {
             $ctype = 'Individual';
         }
         $dedupeParams = CRM_Dedupe_Finder::formatParams($fields, $ctype);
         if ($form->_mode == CRM_Profile_Form::MODE_CREATE) {
             // fix for CRM-2888
             $exceptions = array();
         } else {
             // for edit mode we need to allow our own record to be a dupe match!
             $exceptions = array($form->_session->get('userID'));
         }
         // for dialog mode we should always use fuzzy rule.
         $ruleType = 'Unsupervised';
         if ($form->_context == 'dialog') {
             $ruleType = 'Supervised';
         }
         $dedupeParams['check_permission'] = FALSE;
         $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $ctype, $ruleType, $exceptions, $form->_ruleGroupID);
         if ($ids) {
             if ($form->_isUpdateDupe == 2) {
                 CRM_Core_Session::setStatus(ts('Note: this contact may be a duplicate of an existing record.'), ts('Possible Duplicate Detected'), 'alert');
             } elseif ($form->_isUpdateDupe == 1) {
                 if (!$form->_id) {
                     $form->_id = $ids[0];
                 }
             } else {
                 if ($form->_context == 'dialog') {
                     $contactLinks = CRM_Contact_BAO_Contact_Utils::formatContactIDSToLinks($ids, TRUE, TRUE);
                     $duplicateContactsLinks = '<div class="matching-contacts-found">';
                     $duplicateContactsLinks .= ts('One matching contact was found. ', array('count' => count($contactLinks['rows']), 'plural' => '%count matching contacts were found.<br />'));
                     if ($contactLinks['msg'] == 'view') {
                         $duplicateContactsLinks .= ts('You can View the existing contact.', array('count' => count($contactLinks['rows']), 'plural' => 'You can View the existing contacts.'));
                     } else {
                         $duplicateContactsLinks .= ts('You can View or Edit the existing contact.', array('count' => count($contactLinks['rows']), 'plural' => 'You can View or Edit the existing contacts.'));
                     }
                     $duplicateContactsLinks .= '</div>';
                     $duplicateContactsLinks .= '<table class="matching-contacts-actions">';
                     $row = '';
                     for ($i = 0; $i < count($contactLinks['rows']); $i++) {
                         $row .= '  <tr>   ';
                         $row .= '    <td class="matching-contacts-name"> ';
                         $row .= $contactLinks['rows'][$i]['display_name'];
                         $row .= '    </td>';
                         $row .= '    <td class="matching-contacts-email"> ';
                         $row .= $contactLinks['rows'][$i]['primary_email'];
                         $row .= '    </td>';
                         $row .= '    <td class="action-items"> ';
                         $row .= $contactLinks['rows'][$i]['view'] . ' ';
                         $row .= $contactLinks['rows'][$i]['edit'];
                         $row .= '    </td>';
                         $row .= '  </tr>   ';
                     }
                     $duplicateContactsLinks .= $row . '</table>';
                     $duplicateContactsLinks .= "If you're sure this record is not a duplicate, click the 'Save Matching Contact' button below.";
                     $errors['_qf_default'] = $duplicateContactsLinks;
                     // let smarty know that there are duplicates
                     $template = CRM_Core_Smarty::singleton();
                     $template->assign('isDuplicate', 1);
                 } else {
                     $errors['_qf_default'] = ts('A record already exists with the same information.');
                 }
             }
         }
     }
     foreach ($fields as $key => $value) {
         list($fieldName, $locTypeId, $phoneTypeId) = CRM_Utils_System::explode('-', $key, 3);
         if ($fieldName == 'state_province' && !empty($fields["country-{$locTypeId}"])) {
             // Validate Country - State list
             $countryId = $fields["country-{$locTypeId}"];
             $stateProvinceId = $value;
             if ($stateProvinceId && $countryId) {
                 $stateProvinceDAO = new CRM_Core_DAO_StateProvince();
                 $stateProvinceDAO->id = $stateProvinceId;
                 $stateProvinceDAO->find(TRUE);
                 if ($stateProvinceDAO->country_id != $countryId) {
                     // country mismatch hence display error
                     $stateProvinces = CRM_Core_PseudoConstant::stateProvince();
                     $countries = CRM_Core_PseudoConstant::country();
                     $errors[$key] = "State/Province " . $stateProvinces[$stateProvinceId] . " is not part of " . $countries[$countryId] . ". It belongs to " . $countries[$stateProvinceDAO->country_id] . ".";
                 }
             }
         }
         if ($fieldName == 'county' && $fields["state_province-{$locTypeId}"]) {
             // Validate County - State list
             $stateProvinceId = $fields["state_province-{$locTypeId}"];
             $countyId = $value;
             if ($countyId && $stateProvinceId) {
                 $countyDAO = new CRM_Core_DAO_County();
                 $countyDAO->id = $countyId;
                 $countyDAO->find(TRUE);
                 if ($countyDAO->state_province_id != $stateProvinceId) {
                     // state province mismatch hence display error
                     $stateProvinces = CRM_Core_PseudoConstant::stateProvince();
                     $counties = CRM_Core_PseudoConstant::county();
                     $errors[$key] = "County " . $counties[$countyId] . " is not part of " . $stateProvinces[$stateProvinceId] . ". It belongs to " . $stateProvinces[$countyDAO->state_province_id] . ".";
                 }
             }
         }
     }
     foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
         if ($greetingType = CRM_Utils_Array::value($greeting, $fields)) {
             $customizedValue = CRM_Core_OptionGroup::getValue($greeting, 'Customized', 'name');
             if ($customizedValue == $greetingType && empty($fields[$greeting . '_custom'])) {
                 $errors[$greeting . '_custom'] = ts('Custom  %1 is a required field if %1 is of type Customized.', array(1 => ucwords(str_replace('_', ' ', $greeting))));
             }
         }
     }
     return empty($errors) ? TRUE : $errors;
 }
コード例 #7
0
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     $this->assignToTemplate();
     $productID = $this->get('productID');
     $option = $this->get('option');
     $membershipTypeID = $this->get('membershipTypeID');
     $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values));
     if ($productID) {
         CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE, $productID, $option);
     }
     if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
         $this->assign('lineItem', $this->_lineItem);
     } else {
         if (is_array($membershipTypeID)) {
             $membershipTypeID = current($membershipTypeID);
         }
         $this->assign('is_quick_config', 1);
         $this->_params['is_quick_config'] = 1;
     }
     $this->assign('priceSetID', $this->_priceSetId);
     $this->assign('useForMember', $this->get('useForMember'));
     $params = $this->_params;
     $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
     if ($invoicing) {
         $getTaxDetails = FALSE;
         $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
         foreach ($this->_lineItem as $key => $value) {
             foreach ($value as $v) {
                 if (isset($v['tax_rate'])) {
                     if ($v['tax_rate'] != '') {
                         $getTaxDetails = TRUE;
                     }
                 }
             }
         }
         $this->assign('getTaxDetails', $getTaxDetails);
         $this->assign('taxTerm', $taxTerm);
         $this->assign('totalTaxAmount', $params['tax_amount']);
     }
     if ($this->_honor_block_is_active && !empty($params['soft_credit_type_id'])) {
         $honorName = NULL;
         $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
         $this->assign('honor_block_is_active', $this->_honor_block_is_active);
         $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]);
         CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($this, $params['honor'], $params['honoree_profile_id']);
         $fieldTypes = array('Contact');
         $fieldTypes[] = CRM_Core_BAO_UFGroup::getContactType($params['honoree_profile_id']);
         $this->buildCustom($params['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes);
     }
     $qParams = "reset=1&amp;id={$this->_id}";
     //pcp elements
     if ($this->_pcpId) {
         $qParams .= "&amp;pcpId={$this->_pcpId}";
         $this->assign('pcpBlock', TRUE);
         foreach (array('pcp_display_in_roll', 'pcp_is_anonymous', 'pcp_roll_nickname', 'pcp_personal_note') as $val) {
             if (!empty($this->_params[$val])) {
                 $this->assign($val, $this->_params[$val]);
             }
         }
     }
     $this->assign('qParams', $qParams);
     if ($membershipTypeID) {
         $transactionID = $this->get('membership_trx_id');
         $membershipAmount = $this->get('membership_amount');
         $renewalMode = $this->get('renewal_mode');
         $this->assign('membership_trx_id', $transactionID);
         $this->assign('membership_amount', $membershipAmount);
         $this->assign('renewal_mode', $renewalMode);
         $this->buildMembershipBlock($this->_membershipContactID, FALSE, $membershipTypeID, TRUE, NULL);
         if (!empty($params['auto_renew'])) {
             $this->assign('auto_renew', TRUE);
         }
     }
     $this->_separateMembershipPayment = $this->get('separateMembershipPayment');
     $this->assign("is_separate_payment", $this->_separateMembershipPayment);
     $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE);
     $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE);
     if (!empty($params['hidden_onbehalf_profile'])) {
         $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id);
         $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         $profileId = $OnBehalfProfile[0];
         $fieldTypes = array('Contact', 'Organization');
         $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
         $fieldTypes = array_merge($fieldTypes, $contactSubType);
         if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) {
             $fieldTypes = array_merge($fieldTypes, array('Membership'));
         } else {
             $fieldTypes = array_merge($fieldTypes, array('Contribution'));
         }
         $this->buildCustom($profileId, 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes);
     }
     $this->assign('trxn_id', CRM_Utils_Array::value('trxn_id', $this->_params));
     $this->assign('receive_date', CRM_Utils_Date::mysqlToIso(CRM_Utils_Array::value('receive_date', $this->_params)));
     $defaults = array();
     $fields = array();
     foreach ($this->_fields as $name => $dontCare) {
         if ($name != 'onbehalf' || $name != 'honor') {
             $fields[$name] = 1;
         }
     }
     $fields['state_province'] = $fields['country'] = $fields['email'] = 1;
     $contact = $this->_params = $this->controller->exportValues('Main');
     foreach ($fields as $name => $dontCare) {
         if (isset($contact[$name])) {
             $defaults[$name] = $contact[$name];
             if (substr($name, 0, 7) == 'custom_') {
                 $timeField = "{$name}_time";
                 if (isset($contact[$timeField])) {
                     $defaults[$timeField] = $contact[$timeField];
                 }
             } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && !empty($contact[$name . '_custom'])) {
                 $defaults[$name . '_custom'] = $contact[$name . '_custom'];
             }
         }
     }
     $this->_submitValues = array_merge($this->_submitValues, $defaults);
     $this->setDefaults($defaults);
     $values['entity_id'] = $this->_id;
     $values['entity_table'] = 'civicrm_contribution_page';
     CRM_Friend_BAO_Friend::retrieve($values, $data);
     $tellAFriend = FALSE;
     if ($this->_pcpId) {
         if ($this->_pcpBlock['is_tellfriend_enabled']) {
             $this->assign('friendText', ts('Tell a Friend'));
             $subUrl = "eid={$this->_pcpId}&blockId={$this->_pcpBlock['id']}&pcomponent=pcp";
             $tellAFriend = TRUE;
         }
     } elseif (!empty($data['is_active'])) {
         $friendText = $data['title'];
         $this->assign('friendText', $friendText);
         $subUrl = "eid={$this->_id}&pcomponent=contribute";
         $tellAFriend = TRUE;
     }
     if ($tellAFriend) {
         if ($this->_action & CRM_Core_Action::PREVIEW) {
             $url = CRM_Utils_System::url("civicrm/friend", "reset=1&action=preview&{$subUrl}");
         } else {
             $url = CRM_Utils_System::url("civicrm/friend", "reset=1&{$subUrl}");
         }
         $this->assign('friendURL', $url);
     }
     $this->freeze();
     // can we blow away the session now to prevent hackery
     // CRM-9491
     $this->controller->reset();
 }
コード例 #8
0
ファイル: Form.php プロジェクト: ksecor/civicrm
 /**
  * global form rule
  *
  * @param array  $fields the input form values
  * @param array  $files  the uploaded files if any
  * @param object $form   the form object
  *
  * @return true if no errors, else array of errors
  * @access public
  * @static
  */
 static function formRule(&$fields, &$files, &$form)
 {
     $errors = array();
     // if no values, return
     if (empty($fields)) {
         return true;
     }
     $cid = $register = null;
     // hack we use a -1 in options to indicate that its registration
     if ($form->_id) {
         $cid = $form->_id;
         $form->_isUpdateDupe = true;
     }
     if ($form->_mode == CRM_Profile_Form::MODE_REGISTER) {
         $register = true;
     }
     // dont check for duplicates during registration validation: CRM-375
     if (!$register && !CRM_Utils_Array::value('_qf_Edit_upload_duplicate', $fields)) {
         // fix for CRM-3240
         if (CRM_Utils_Array::value('email-Primary', $fields)) {
             $fields['email'] = CRM_Utils_Array::value('email-Primary', $fields);
         }
         $session =& CRM_Core_Session::singleton();
         $ctype = CRM_Core_BAO_UFGroup::getContactType($form->_gid);
         require_once 'CRM/Dedupe/Finder.php';
         $dedupeParams = CRM_Dedupe_Finder::formatParams($fields, $ctype);
         if ($form->_mode == CRM_Profile_Form::MODE_CREATE) {
             // fix for CRM-2888
             $exceptions = array();
         } else {
             // for edit mode we need to allow our own record to be a dupe match!
             $exceptions = array($session->get('userID'));
         }
         // for dialog mode we should always use fuzzy rule.
         $ruleType = 'Strict';
         if ($form->_context == 'dialog') {
             $ruleType = 'Fuzzy';
         }
         $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $ctype, $ruleType, $exceptions);
         if ($ids) {
             if ($form->_isUpdateDupe) {
                 if (!$form->_id) {
                     $form->_id = $ids[0];
                 }
             } else {
                 if ($form->_context == 'dialog') {
                     $viewUrls = array();
                     require_once 'CRM/Contact/BAO/Contact/Utils.php';
                     list($viewUrls) = CRM_Contact_BAO_Contact_Utils::formatContactIDSToLinks($ids);
                     $viewUrl = implode(', ', $viewUrls);
                     $errors['_qf_default'] = ts('One matching contact was found.', array('count' => count($viewUrls), 'plural' => '%count matching contacts were found.'));
                     $errors['_qf_default'] .= '<br />';
                     $errors['_qf_default'] .= ts('If you need to verify if this is the same contact, click here - %1 - to VIEW the existing contact in a new tab.', array(1 => $viewUrl, 'count' => count($viewUrls), 'plural' => 'If you need to verify whether one of these is the same contact, click here - %1 - to VIEW the existing contact in a new tab.'));
                     $errors['_qf_default'] .= '<br />';
                     $errors['_qf_default'] .= ts('If you are sure this is NOT a duplicate, click the Save Matching Contact button to create a new contact record.');
                     // let smarty know that there are duplicates
                     $template =& CRM_Core_Smarty::singleton();
                     $template->assign('isDuplicate', 1);
                 } else {
                     $errors['_qf_default'] = ts('A record already exists with the same information.');
                 }
             }
         }
     }
     foreach ($fields as $key => $value) {
         list($fieldName, $locTypeId, $phoneTypeId) = CRM_Utils_System::explode('-', $key, 3);
         if ($fieldName == 'state_province' && $fields["country-{$locTypeId}"]) {
             // Validate Country - State list
             $countryId = $fields["country-{$locTypeId}"];
             $stateProvinceId = $value;
             if ($stateProvinceId && $countryId) {
                 $stateProvinceDAO =& new CRM_Core_DAO_StateProvince();
                 $stateProvinceDAO->id = $stateProvinceId;
                 $stateProvinceDAO->find(true);
                 if ($stateProvinceDAO->country_id != $countryId) {
                     // country mismatch hence display error
                     $stateProvinces = CRM_Core_PseudoConstant::stateProvince();
                     $countries =& CRM_Core_PseudoConstant::country();
                     $errors[$key] = "State/Province " . $stateProvinces[$stateProvinceId] . " is not part of " . $countries[$countryId] . ". It belongs to " . $countries[$stateProvinceDAO->country_id] . ".";
                 }
             }
         }
         if ($fieldName == 'county' && $fields["state_province-{$locTypeId}"]) {
             // Validate County - State list
             $stateProvinceId = $fields["state_province-{$locTypeId}"];
             $countyId = $value;
             if ($countyId && $stateProvinceId) {
                 $countyDAO =& new CRM_Core_DAO_County();
                 $countyDAO->id = $countyId;
                 $countyDAO->find(true);
                 if ($countyDAO->state_province_id != $stateProvinceId) {
                     // state province mismatch hence display error
                     $stateProvinces = CRM_Core_PseudoConstant::stateProvince();
                     $counties =& CRM_Core_PseudoConstant::county();
                     $errors[$key] = "County " . $counties[$countyId] . " is not part of " . $stateProvinces[$stateProvinceId] . ". It belongs to " . $stateProvinces[$countyDAO->state_province_id] . ".";
                 }
             }
         }
     }
     $elements = array('email_greeting' => 'email_greeting_custom', 'postal_greeting' => 'postal_greeting_custom', 'addressee' => 'addressee_custom');
     foreach ($elements as $greeting => $customizedGreeting) {
         if ($greetingType = CRM_Utils_Array::value($greeting, $fields)) {
             $customizedValue = CRM_Core_OptionGroup::getValue($greeting, 'Customized', 'name');
             if ($customizedValue == $greetingType && !CRM_Utils_Array::value($customizedGreeting, $fields)) {
                 $errors[$customizedGreeting] = ts('Custom  %1 is a required field if %1 is of type Customized.', array(1 => ucwords(str_replace('_', " ", $greeting))));
             }
         }
     }
     return empty($errors) ? true : $errors;
 }
コード例 #9
0
 /**
  * @param $form
  * @param array $params Parameters from the form.
  */
 public static function postProcess($form, $params)
 {
     if (!empty($form->_honor_block_is_active) && !empty($params['soft_credit_type_id'])) {
         $honorId = NULL;
         //check if there is any duplicate contact
         $profileContactType = CRM_Core_BAO_UFGroup::getContactType($params['honoree_profile_id']);
         $dedupeParams = CRM_Dedupe_Finder::formatParams($params['honor'], $profileContactType);
         $dedupeParams['check_permission'] = FALSE;
         $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $profileContactType);
         if (count($ids)) {
             $honorId = CRM_Utils_Array::value(0, $ids);
         }
         $honorId = CRM_Contact_BAO_Contact::createProfileContact($params['honor'], CRM_Core_DAO::$_nullArray, $honorId, NULL, $params['honoree_profile_id']);
         $softParams = array();
         $softParams['contribution_id'] = $form->_contributionID;
         $softParams['contact_id'] = $honorId;
         $softParams['soft_credit_type_id'] = $params['soft_credit_type_id'];
         $contribution = new CRM_Contribute_DAO_Contribution();
         $contribution->id = $form->_contributionID;
         $contribution->find();
         while ($contribution->fetch()) {
             $softParams['currency'] = $contribution->currency;
             $softParams['amount'] = $contribution->total_amount;
         }
         CRM_Contribute_BAO_ContributionSoft::add($softParams);
         if (CRM_Utils_Array::value('is_email_receipt', $form->_values)) {
             $form->_values['honor'] = array('soft_credit_type' => CRM_Utils_Array::value($params['soft_credit_type_id'], CRM_Core_OptionGroup::values("soft_credit_type")), 'honor_id' => $honorId, 'honor_profile_id' => $params['honoree_profile_id'], 'honor_profile_values' => $params['honor']);
         }
     }
 }
コード例 #10
0
ファイル: Application.php プロジェクト: JoeMurray/civihr
 /**
  * Function to process the form
  *
  * @access public
  * @return void
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     //Check the contact provided in Application form is existing or new
     $profileContactType = CRM_Core_BAO_UFGroup::getContactType($this->_profileID);
     $dedupeParams = CRM_Dedupe_Finder::formatParams($params, $profileContactType);
     $dedupeParams['check_permission'] = FALSE;
     $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $profileContactType);
     $applicantID = $this->_contactID;
     if (count($ids) && !$applicantID) {
         $applicantID = CRM_Utils_Array::value(0, $ids);
     }
     $applicantID = CRM_Contact_BAO_Contact::createProfileContact($params, CRM_Core_DAO::$_nullArray, $applicantID, NULL, $this->_profileID);
     if ($applicantID) {
         $params['start_date'] = date("YmdHis");
         $dao = new CRM_HRRecruitment_DAO_HRVacancyStage();
         $dao->vacancy_id = $this->_id;
         $dao->find();
         while ($dao->fetch()) {
             $params['case_status_id'] = $dao->case_status_id;
             break;
         }
         //Create case of type Application against creator applicant and assignee as Vacancy creator
         $caseTypes = array_flip(CRM_Case_PseudoConstant::caseType('name', TRUE, 'AND filter = 1'));
         $cases = CRM_Case_BAO_Case::retrieveCaseIdsByContactId($applicantID, FALSE, 'Application');
         foreach ($cases as $case) {
             $oldAppl = CRM_HRRecruitment_BAO_HRVacancy::getVacancyIDByCase($case);
             if ($oldAppl == $this->_id) {
                 $params['id'] = $case;
                 break;
             }
         }
         $params['case_type_id'] = $caseTypes['Application'];
         $caseObj = CRM_Case_BAO_Case::create($params);
         if (empty($params['id'])) {
             $contactParams = array('case_id' => $caseObj->id, 'contact_id' => $applicantID);
             CRM_Case_BAO_Case::addCaseToContact($contactParams);
             $xmlProcessor = new CRM_Case_XMLProcessor_Process();
             $xmlProcessorParams = array('clientID' => $applicantID, 'creatorID' => $this->_creatorID, 'standardTimeline' => 1, 'activityTypeName' => 'Open Case', 'caseID' => $caseObj->id, 'activity_date_time' => $params['start_date']);
             $xmlProcessor->run('Application', $xmlProcessorParams);
         }
         //process Custom data
         CRM_Core_BAO_CustomValueTable::postprocess($params, CRM_Core_DAO::$_nullArray, 'civicrm_case', $caseObj->id, 'Case');
         //Process case to vacancy one-to-one mapping in custom table 'application_case'
         $cgID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', 'application_case', 'id', 'name');
         $result = civicrm_api3('CustomField', 'get', array('custom_group_id' => $cgID, 'name' => 'vacancy_id'));
         civicrm_api3('custom_value', 'create', array("custom_{$result['id']}" => $this->_id, 'entity_id' => $caseObj->id));
     }
     if ($this->controller->getButtonName('submit') == "_qf_Application_upload") {
         CRM_Core_Session::setStatus(ts("Application has been successfully submitted."));
         CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/vacancy/publiclisting', 'reset=1'));
     }
 }
コード例 #11
0
ファイル: hrrecruitment.php プロジェクト: JoeMurray/civihr
/**
 * Implementation of hook_civicrm_postProcess
 *
 * @params string $formName - the name of the form
 *         object $form - reference to the form object
 * @return void
 */
function hrrecruitment_civicrm_postProcess($formName, &$form)
{
    if ($formName == 'CRM_Case_Form_Activity') {
        if (!empty($form->_submitValues['evaluationProfile']) && isset($_POST['new_activity_id'])) {
            //Save evaluation profile fields
            $pID = $form->_submitValues['evaluationProfile'];
            $profileContactType = CRM_Core_BAO_UFGroup::getContactType($pID);
            $dedupeParams = CRM_Dedupe_Finder::formatParams($params, $profileContactType);
            $dedupeParams['check_permission'] = FALSE;
            $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $profileContactType);
            $applicantID = $form->_currentlyViewedContactId;
            if (count($ids)) {
                $applicantID = CRM_Utils_Array::value(0, $ids);
            }
            $applicantID = CRM_Contact_BAO_Contact::createProfileContact($form->_submitValues, CRM_Core_DAO::$_nullArray, $applicantID, NULL, $pID);
            //set custom fields values
            $profileFields = CRM_Core_BAO_UFGroup::getFields($form->_submitValues['evaluationProfile']);
            foreach ($profileFields as $profileFieldKey => $profileFieldVal) {
                $params = array("entityID" => $_POST['new_activity_id'], $profileFieldKey => $form->_submitValues[$profileFieldKey]);
                CRM_Core_BAO_CustomValueTable::setValues($params);
            }
        }
    }
}