Exemple #1
0
 /**
  * Set variables up before form is built.
  *
  * @param CRM_Core_Form $form
  */
 public static function preProcess(&$form)
 {
     $session = CRM_Core_Session::singleton();
     $contactID = $form->_contactID;
     $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $form->_id);
     $profileId = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
     $form->_profileId = $profileId[0];
     if (!$form->_profileId || !CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_profileId, '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.'));
     }
     $requiredProfileFields = array('organization_name', 'email');
     $validProfile = CRM_Core_BAO_UFGroup::checkValidProfile($form->_profileId, $requiredProfileFields);
     if (!$validProfile) {
         CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of an organization and the required fields of the selected onbehalf profile are disabled.'));
     }
     $form->assign('profileId', $form->_profileId);
     $form->assign('mode', $form->_mode);
     if ($contactID) {
         $form->_employers = CRM_Contact_BAO_Relationship::getPermissionedEmployer($contactID);
         if (!empty($form->_membershipContactID) && $contactID != $form->_membershipContactID) {
             // renewal case - membership being renewed may or may not be for organization
             if (!empty($form->_employers) && array_key_exists($form->_membershipContactID, $form->_employers)) {
                 // if _membershipContactID belongs to employers list, we can say:
                 $form->_relatedOrganizationFound = TRUE;
             }
         } elseif (!empty($form->_employers)) {
             // not a renewal case and _employers list is not empty
             $form->_relatedOrganizationFound = TRUE;
         }
         if ($form->_relatedOrganizationFound) {
             // Related org url - pass checksum if needed
             $args = array('cid' => '');
             if (!empty($_GET['cs'])) {
                 $args = array('uid' => $form->_contactID, 'cs' => $_GET['cs'], 'cid' => '');
             }
             $locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', $args, FALSE, NULL, FALSE);
             $form->assign('locDataURL', $locDataURL);
             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']));
             }
         }
         if ($form->_values['is_for_organization'] != 2) {
             $form->assign('relatedOrganizationFound', $form->_relatedOrganizationFound);
         } else {
             $form->assign('onBehalfRequired', $form->_onBehalfRequired);
         }
         if (count($form->_employers) == 1) {
             foreach ($form->_employers as $id => $value) {
                 $form->_organizationName = $value['name'];
                 $orgId = $id;
             }
             $form->assign('orgId', $orgId);
             $form->assign('organizationName', $form->_organizationName);
         }
     }
 }
 /**
  * Set variables up before form is built.
  *
  * @param CRM_Core_Form $form
  */
 public static function preProcess(&$form)
 {
     $session = CRM_Core_Session::singleton();
     $contactID = $session->get('userID');
     $ufJoinParams = array('module' => 'soft_credit', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $form->_id);
     $profileId = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
     $form->_honoreeProfileId = $profileId[0];
     if (!$form->_honoreeProfileId || !CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_honoreeProfileId, '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->_honoreeProfileId);
     $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->_honoreeProfileId, $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.'));
     }
 }
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 static function preProcess(&$form)
 {
     $session = CRM_Core_Session::singleton();
     $contactID = $session->get('userID');
     $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $form->_id);
     $profileId = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
     $form->_profileId = $profileId[0];
     if (!$form->_profileId || !CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_profileId, '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.'));
     }
     $requiredProfileFields = array('organization_name', 'email');
     $validProfile = CRM_Core_BAO_UFGroup::checkValidProfile($form->_profileId, $requiredProfileFields);
     if (!$validProfile) {
         CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of an organization and the required fields of the selected onbehalf profile are disabled.'));
     }
     $form->assign('profileId', $form->_profileId);
     $form->assign('mode', $form->_mode);
     if ($contactID) {
         $form->_employers = CRM_Contact_BAO_Relationship::getPermissionedEmployer($contactID);
         if (!empty($form->_employers)) {
             $form->_relatedOrganizationFound = TRUE;
             $locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', 'cid=', FALSE, NULL, FALSE);
             $form->assign('locDataURL', $locDataURL);
             $dataURL = CRM_Utils_System::url('civicrm/ajax/employer', 'cid=' . $contactID, FALSE, NULL, FALSE);
             $form->assign('employerDataURL', $dataURL);
         }
         if ($form->_values['is_for_organization'] != 2) {
             $form->assign('relatedOrganizationFound', $form->_relatedOrganizationFound);
         } else {
             $form->assign('onBehalfRequired', $form->_onBehalfRequired);
         }
         if (count($form->_employers) == 1) {
             foreach ($form->_employers as $id => $value) {
                 $form->_organizationName = $value['name'];
                 $orgId = $id;
             }
             $form->assign('orgId', $orgId);
             $form->assign('organizationName', $form->_organizationName);
         }
     }
 }
 /**
  * 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 #5
0
 /**
  * Global validation rules for the form.
  *
  * @param array $values
  *   Posted values of the form.
  *
  * @param $files
  * @param $self
  *
  * @return array
  *   list of errors to be posted back to the form
  */
 public static function formRule($values, $files, $self)
 {
     $errors = array();
     $contributionPageId = $self->_id;
     //CRM-4286
     if (strstr($values['title'], '/')) {
         $errors['title'] = ts("Please do not use '/' in Title");
     }
     // ensure on-behalf-of profile meets minimum requirements
     if (!empty($values['is_organization'])) {
         if (empty($values['onbehalf_profile_id'])) {
             $errors['onbehalf_profile_id'] = ts('Please select a profile to collect organization information on this contribution page.');
         } else {
             $requiredProfileFields = array('organization_name', 'email');
             if (!CRM_Core_BAO_UFGroup::checkValidProfile($values['onbehalf_profile_id'], $requiredProfileFields)) {
                 $errors['onbehalf_profile_id'] = ts('Profile does not contain the minimum required fields for an On Behalf Of Organization');
             }
         }
     }
     //CRM-11494
     $start = CRM_Utils_Date::processDate($values['start_date']);
     $end = CRM_Utils_Date::processDate($values['end_date']);
     if ($end < $start && $end != 0) {
         $errors['end_date'] = ts('End date should be after Start date.');
     }
     if (!empty($self->_values['payment_processor']) && ($financialType = CRM_Contribute_BAO_Contribution::validateFinancialType($values['financial_type_id']))) {
         $errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for Financial Type : ") . $financialType;
     }
     //dont allow on behalf of save when
     //pre or post profile consists of membership fields
     if ($contributionPageId && !empty($values['is_organization'])) {
         $ufJoinParams = array('module' => 'CiviContribute', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $contributionPageId);
         list($contributionProfiles['custom_pre_id'], $contributionProfiles['custom_post_id']) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         $conProfileType = NULL;
         if ($contributionProfiles['custom_pre_id']) {
             $preProfileType = CRM_Core_BAO_UFField::getProfileType($contributionProfiles['custom_pre_id']);
             if ($preProfileType == 'Membership') {
                 $conProfileType = "'Includes Profile (top of page)'";
             }
         }
         if ($contributionProfiles['custom_post_id']) {
             $postProfileType = CRM_Core_BAO_UFField::getProfileType($contributionProfiles['custom_post_id']);
             if ($postProfileType == 'Membership') {
                 $conProfileType = empty($conProfileType) ? "'Includes Profile (bottom of page)'" : "{$conProfileType} and 'Includes Profile (bottom of page)'";
             }
         }
         if (!empty($conProfileType)) {
             $errors['is_organization'] = ts("You should move the membership related fields configured in %1 to the 'On Behalf' profile for this Contribution Page", array(1 => $conProfileType));
         }
     }
     return $errors;
 }
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     $this->_first = TRUE;
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage');
     // name
     $this->add('text', 'title', ts('Title'), $attributes['title'], TRUE);
     $this->add('select', 'contribution_type_id', ts('Contribution Type'), CRM_Contribute_PseudoConstant::contributionType(), TRUE);
     //CRM-7362 --add campaigns.
     CRM_Campaign_BAO_Campaign::addCampaign($this, CRM_Utils_Array::value('campaign_id', $this->_values));
     $this->addWysiwyg('intro_text', ts('Introductory Message'), $attributes['intro_text']);
     $this->addWysiwyg('footer_text', ts('Footer Message'), $attributes['footer_text']);
     // is on behalf of an organization ?
     $this->addElement('checkbox', 'is_organization', ts('Allow individuals to contribute and / or signup for membership on behalf of an organization?'), NULL, array('onclick' => "showHideByValue('is_organization',true,'for_org_text','table-row','radio',false);showHideByValue('is_organization',true,'for_org_option','table-row','radio',false);"));
     $required = array('Contact', 'Organization');
     $optional = array('Contribution', 'Membership');
     $profiles = CRM_Core_BAO_UFGroup::getValidProfiles($required, $optional);
     //Check profiles for Organization subtypes
     $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
     foreach ($contactSubType as $type) {
         $required = array('Contact', $type);
         $subTypeProfiles = CRM_Core_BAO_UFGroup::getValidProfiles($required, $optional);
         foreach ($subTypeProfiles as $profileId => $profileName) {
             $profiles[$profileId] = $profileName;
         }
     }
     $requiredProfileFields = array('organization_name', 'email');
     if (!empty($profiles)) {
         foreach ($profiles as $id => $dontCare) {
             $validProfile = CRM_Core_BAO_UFGroup::checkValidProfile($id, $requiredProfileFields);
             if (!$validProfile) {
                 unset($profiles[$id]);
             }
         }
     }
     if (empty($profiles)) {
         $invalidProfiles = TRUE;
         $this->assign('invalidProfiles', $invalidProfiles);
     }
     $this->add('select', 'onbehalf_profile_id', ts('Organization Profile'), array('' => ts('- select -')) + $profiles);
     $options = array();
     $options[] = $this->createElement('radio', NULL, NULL, ts('Optional'), 1);
     $options[] = $this->createElement('radio', NULL, NULL, ts('Required'), 2);
     $this->addGroup($options, 'is_for_organization', ts(''));
     $this->add('textarea', 'for_organization', ts('On behalf of Label'), $attributes['for_organization']);
     // collect goal amount
     $this->add('text', 'goal_amount', ts('Goal Amount'), array('size' => 8, 'maxlength' => 12));
     $this->addRule('goal_amount', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money');
     // is confirmation page enabled?
     $this->addElement('checkbox', 'is_confirm_enabled', ts('Use a confirmation page?'));
     // is this page shareable through social media ?
     $this->addElement('checkbox', 'is_share', ts('Allow sharing through social media?'));
     // is this page active ?
     $this->addElement('checkbox', 'is_active', ts('Is this Online Contribution Page Active?'));
     // should the honor be enabled
     $this->addElement('checkbox', 'honor_block_is_active', ts('Honoree Section Enabled'), NULL, array('onclick' => "showHonor()"));
     $this->add('text', 'honor_block_title', ts('Honoree Section Title'), $attributes['honor_block_title']);
     $this->add('textarea', 'honor_block_text', ts('Honoree Introductory Message'), $attributes['honor_block_text']);
     // add optional start and end dates
     $this->addDateTime('start_date', ts('Start Date'));
     $this->addDateTime('end_date', ts('End Date'));
     $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Settings', 'formRule'));
     parent::buildQuickForm();
 }