/** * Browse all CiviCRM Profile group fields. * * @return void * @access public * @static */ function browse() { CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js'); $ufField = array(); $ufFieldBAO = new CRM_Core_BAO_UFField(); // fkey is gid $ufFieldBAO->uf_group_id = $this->_gid; $ufFieldBAO->orderBy('weight', 'field_name'); $ufFieldBAO->find(); $otherModules = CRM_Core_BAO_UFGroup::getUFJoinRecord($this->_gid); $this->assign('otherModules', $otherModules); $isGroupReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'is_reserved'); $this->assign('isGroupReserved', $isGroupReserved); $profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid); if ($profileType == 'Contribution' || $profileType == 'Membership' || $profileType == 'Activity' || $profileType == 'Participant') { $this->assign('skipCreate', TRUE); } $locationType = array(); $locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); $fields = CRM_Contact_BAO_Contact::exportableFields('All', FALSE, TRUE); $fields = array_merge(CRM_Contribute_BAO_Contribution::getContributionFields(), $fields); $select = array(); foreach ($fields as $name => $field) { if ($name) { $select[$name] = $field['title']; } } $select['group'] = ts('Group(s)'); $select['tag'] = ts('Tag(s)'); $visibility = CRM_Core_SelectValues::ufVisibility(); while ($ufFieldBAO->fetch()) { $ufField[$ufFieldBAO->id] = array(); $phoneType = $locType = ''; CRM_Core_DAO::storeValues($ufFieldBAO, $ufField[$ufFieldBAO->id]); $ufField[$ufFieldBAO->id]['visibility_display'] = $visibility[$ufFieldBAO->visibility]; $ufField[$ufFieldBAO->id]['label'] = $ufFieldBAO->label; $action = array_sum(array_keys($this->actionLinks())); if ($ufFieldBAO->is_active) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } if ($ufFieldBAO->is_reserved) { $action -= CRM_Core_Action::UPDATE; $action -= CRM_Core_Action::DISABLE; $action -= CRM_Core_Action::DELETE; } $ufField[$ufFieldBAO->id]['order'] = $ufField[$ufFieldBAO->id]['weight']; $ufField[$ufFieldBAO->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $ufFieldBAO->id, 'gid' => $this->_gid), ts('more'), FALSE, 'ufField.row.actions', 'UFField', $ufFieldBAO->id); } $returnURL = CRM_Utils_System::url('civicrm/admin/uf/group/field', "reset=1&action=browse&gid={$this->_gid}"); $filter = "uf_group_id = {$this->_gid}"; CRM_Utils_Weight::addOrder($ufField, 'CRM_Core_DAO_UFField', 'id', $returnURL, $filter); $this->assign('ufField', $ufField); // retrieve showBestResult from session $session = CRM_Core_Session::singleton(); $showBestResult = $session->get('showBestResult'); $this->assign('showBestResult', $showBestResult); $session->set('showBestResult', 0); }
/** * Get a list of Backbone-Form models * * @param array $entityTypes model names ("IndividualModel") * @return array; keys are model names ("IndividualModel") and values describe 'sections' and 'schema' * @see js/model/crm.core.js * @see js/model/crm.mappedcore.js */ static function getSchema($entityTypes) { // FIXME: Depending on context (eg civicrm/profile/create vs search-columns), it may be appropriate to // pick importable or exportable fields $entityTypes = array_unique($entityTypes); $availableFields = NULL; foreach ($entityTypes as $entityType) { if (!$availableFields) { $availableFields = CRM_Core_BAO_UFField::getAvailableFieldsFlat(); //dpm($availableFields); } switch ($entityType) { case 'IndividualModel': $civiSchema[$entityType] = self::convertCiviModelToBackboneModel('Individual', ts('Individual'), $availableFields); break; case 'ActivityModel': $civiSchema[$entityType] = self::convertCiviModelToBackboneModel('Activity', ts('Activity'), $availableFields); break; case 'ContributionModel': $civiSchema[$entityType] = self::convertCiviModelToBackboneModel('Contribution', ts('Contribution'), $availableFields); break; case 'MembershipModel': $civiSchema[$entityType] = self::convertCiviModelToBackboneModel('Membership', ts('Membership'), $availableFields); break; case 'ParticipantModel': $civiSchema[$entityType] = self::convertCiviModelToBackboneModel('Participant', ts('Participant'), $availableFields); break; default: throw new CRM_Core_Exception("Unrecognized entity type: {$entityType}"); } } return $civiSchema; }
function buildQuickForm() { // Build list of options for individual, org and household // contact types. $ind_profile_options = array(); $house_profile_options = array(); $org_profile_options = array(); try { $params = array('rowCount' => 200); $result = civicrm_api3('UFGroup', 'get', $params); } catch (CiviCRM_API3_Exception $e) { $error = $e->getMessage(); $session = CRM_Core_Session::singleton(); $session->setStatus(ts("Failed to get list of profiles.")); return; } reset($result['values']); while (list($k, $v) = each($result['values'])) { if (array_key_exists('group_type', $v) && $v['is_active'] == 1) { $id = $v['id']; // Ensure it's not a mixed type profile, because you cannot edit mixed type // profiles if (CRM_Core_BAO_UFField::checkProfileType($id)) { continue; } if (is_array($v['group_type'])) { // Just check the first one (this is arbitrary) $group_type = array_pop($v['group_type']); } else { $group_type = $v['group_type']; } if (preg_match('/Individual/', $group_type)) { $ind_profile_options[$id] = $v['title']; } if (preg_match('/Household/', $group_type)) { $house_profile_options[$id] = $v['title']; } if (preg_match('/Organization/', $group_type)) { $org_profile_options[$id] = $v['title']; } } } if (!empty($ind_profile_options)) { $this->addElement('select', 'ind_profile_id', ts('Individual'), $ind_profile_options, NULL); } if (!empty($house_profile_options)) { $this->addElement('select', 'house_profile_id', ts('Household'), $house_profile_options, NULL); } if (!empty($org_profile_options)) { $this->addElement('select', 'org_profile_id', ts('Organization'), $org_profile_options, NULL); } $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); }
/** * @param CRM_Contribute_Form_Contribution_Main|CRM_Event_Form_Registration_Register|CRM_Financial_Form_Payment $form * @param null $type * @param null $mode * * @throws Exception */ public static function preProcess(&$form, $type = NULL, $mode = NULL) { if ($type) { $form->_type = $type; } else { $form->_type = CRM_Utils_Request::retrieve('type', 'String', $form); } if ($form->_type) { $form->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($form->_type, $form->_mode); } if (empty($form->_paymentProcessor)) { // This would happen when hitting the back-button on a multi-page form with a $0 selection in play. return; } $form->set('paymentProcessor', $form->_paymentProcessor); $form->_paymentObject = System::singleton()->getByProcessor($form->_paymentProcessor); $form->assign('suppressSubmitButton', $form->_paymentObject->isSuppressSubmitButtons()); $form->assign('currency', CRM_Utils_Array::value('currency', $form->_values)); // also set cancel subscription url if (!empty($form->_paymentProcessor['is_recur']) && !empty($form->_values['is_recur'])) { $form->_values['cancelSubscriptionUrl'] = $form->_paymentObject->subscriptionURL(NULL, NULL, 'cancel'); } if (!empty($form->_values['custom_pre_id'])) { $profileAddressFields = array(); $fields = CRM_Core_BAO_UFGroup::getFields($form->_values['custom_pre_id'], FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL); foreach ((array) $fields as $key => $value) { CRM_Core_BAO_UFField::assignAddressField($key, $profileAddressFields, array('uf_group_id' => $form->_values['custom_pre_id'])); } if (count($profileAddressFields)) { $form->set('profileAddressFields', $profileAddressFields); } } //checks after setting $form->_paymentProcessor // we do this outside of the above conditional to avoid // saving the country/state list in the session (which could be huge) CRM_Core_Payment_Form::setPaymentFieldsByProcessor($form, $form->_paymentProcessor, CRM_Utils_Request::retrieve('billing_profile_id', 'String')); $form->assign_by_ref('paymentProcessor', $form->_paymentProcessor); // check if this is a paypal auto return and redirect accordingly //@todo - determine if this is legacy and remove if (CRM_Core_Payment::paypalRedirect($form->_paymentProcessor)) { $url = CRM_Utils_System::url('civicrm/contribute/transact', "_qf_ThankYou_display=1&qfKey={$form->controller->_key}"); CRM_Utils_System::redirect($url); } // make sure we have a valid payment class, else abort if (!empty($form->_values['is_monetary']) && !$form->_paymentProcessor['class_name'] && empty($form->_values['is_pay_later'])) { CRM_Core_Error::fatal(ts('Payment processor is not set for this page')); } if (!empty($form->_membershipBlock) && !empty($form->_membershipBlock['is_separate_payment']) && (!empty($form->_paymentProcessor['class_name']) && !$form->_paymentObject->supports('MultipleConcurrentPayments'))) { CRM_Core_Error::fatal(ts('This contribution page is configured to support separate contribution and membership payments. This %1 plugin does not currently support multiple simultaneous payments, or the option to "Execute real-time monetary transactions" is disabled. Please contact the site administrator and notify them of this error', array(1 => $form->_paymentProcessor['payment_processor_type']))); } }
/** * Get a list of Backbone-Form models * * @param array $entityTypes * Model names ("IndividualModel"). * * @throws CRM_Core_Exception * @return array; keys are model names ("IndividualModel") and values describe 'sections' and 'schema' * @see js/model/crm.core.js * @see js/model/crm.mappedcore.js */ public static function getSchema($entityTypes) { // FIXME: Depending on context (eg civicrm/profile/create vs search-columns), it may be appropriate to // pick importable or exportable fields $entityTypes = array_unique($entityTypes); $availableFields = NULL; $civiSchema = array(); foreach ($entityTypes as $entityType) { if (!$availableFields) { $availableFields = CRM_Core_BAO_UFField::getAvailableFieldsFlat(); } switch ($entityType) { case 'IndividualModel': $civiSchema[$entityType] = self::convertCiviModelToBackboneModel('Individual', ts('Individual'), $availableFields); break; case 'OrganizationModel': $civiSchema[$entityType] = self::convertCiviModelToBackboneModel('Organization', ts('Organization'), $availableFields); break; case 'HouseholdModel': $civiSchema[$entityType] = self::convertCiviModelToBackboneModel('Household', ts('Household'), $availableFields); break; case 'ActivityModel': $civiSchema[$entityType] = self::convertCiviModelToBackboneModel('Activity', ts('Activity'), $availableFields); break; case 'ContributionModel': $civiSchema[$entityType] = self::convertCiviModelToBackboneModel('Contribution', ts('Contribution'), $availableFields); break; case 'MembershipModel': $civiSchema[$entityType] = self::convertCiviModelToBackboneModel('Membership', ts('Membership'), $availableFields); break; case 'ParticipantModel': $civiSchema[$entityType] = self::convertCiviModelToBackboneModel('Participant', ts('Participant'), $availableFields); break; case 'CaseModel': $civiSchema[$entityType] = self::convertCiviModelToBackboneModel('Case', ts('Case'), $availableFields); break; default: throw new CRM_Core_Exception("Unrecognized entity type: {$entityType}"); } } // Adding the oddball "formatting" field here because there's no other place to put it foreach (array('Individual', 'Organization', 'Household') as $type) { if (isset($civiSchema[$type . 'Model'])) { $civiSchema[$type . 'Model']['schema'] += array('formatting' => array('type' => 'Markup', 'title' => ts('Free HTML'), 'civiFieldType' => 'Formatting', 'section' => 'formatting')); $civiSchema[$type . 'Model']['sections'] += array('formatting' => array('title' => ts('Formatting'), 'is_addable' => FALSE)); } } return $civiSchema; }
/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { $config = CRM_Core_Config::singleton(); $session = CRM_Core_Session::singleton(); // current contribution page id $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); if (!$this->_id) { // seems like the session is corrupted and/or we lost the id trail // lets just bump this to a regular session error and redirect user to main page $this->controller->invalidKeyRedirect(); } // this was used prior to the cleverer this_>getContactID - unsure now $this->_userID = $session->get('userID'); $this->_contactID = $this->_membershipContactID = $this->getContactID(); $this->_mid = NULL; if ($this->_contactID) { $this->_mid = CRM_Utils_Request::retrieve('mid', 'Positive', $this); if ($this->_mid) { $membership = new CRM_Member_DAO_Membership(); $membership->id = $this->_mid; if ($membership->find(TRUE)) { $this->_defaultMemTypeId = $membership->membership_type_id; if ($membership->contact_id != $this->_contactID) { $validMembership = FALSE; $employers = CRM_Contact_BAO_Relationship::getPermissionedEmployer($this->_userID); if (!empty($employers) && array_key_exists($membership->contact_id, $employers)) { $this->_membershipContactID = $membership->contact_id; $this->assign('membershipContactID', $this->_membershipContactID); $this->assign('membershipContactName', $employers[$this->_membershipContactID]['name']); $validMembership = TRUE; } else { $membershipType = new CRM_Member_BAO_MembershipType(); $membershipType->id = $membership->membership_type_id; if ($membershipType->find(TRUE)) { // CRM-14051 - membership_type.relationship_type_id is a CTRL-A padded string w one or more ID values. // Convert to commma separated list. $inheritedRelTypes = implode(CRM_Utils_Array::explodePadded($membershipType->relationship_type_id), ','); $permContacts = CRM_Contact_BAO_Relationship::getPermissionedContacts($this->_userID, $membershipType->relationship_type_id); if (array_key_exists($membership->contact_id, $permContacts)) { $this->_membershipContactID = $membership->contact_id; $validMembership = TRUE; } } } if (!$validMembership) { CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership."), ts('Membership Invalid'), 'alert'); } } } else { CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership."), ts('Membership Invalid'), 'alert'); } unset($membership); } } // we do not want to display recently viewed items, so turn off $this->assign('displayRecent', FALSE); // Contribution page values are cleared from session, so can't use normal Printer Friendly view. // Use Browser Print instead. $this->assign('browserPrint', TRUE); // action $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add'); $this->assign('action', $this->_action); // current mode $this->_mode = $this->_action == 1024 ? 'test' : 'live'; $this->_values = $this->get('values'); $this->_fields = $this->get('fields'); $this->_bltID = $this->get('bltID'); $this->_paymentProcessor = $this->get('paymentProcessor'); $this->_priceSetId = $this->get('priceSetId'); $this->_priceSet = $this->get('priceSet'); if (!$this->_values) { // get all the values from the dao object $this->_values = array(); $this->_fields = array(); CRM_Contribute_BAO_ContributionPage::setValues($this->_id, $this->_values); // check if form is active if (!CRM_Utils_Array::value('is_active', $this->_values)) { // form is inactive, die a fatal death CRM_Core_Error::fatal(ts('The page you requested is currently unavailable.')); } // also check for billing informatin // get the billing location type $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate'); // CRM-8108 remove ts around Billing location type //$this->_bltID = array_search( ts('Billing'), $locationTypes ); $this->_bltID = array_search('Billing', $locationTypes); if (!$this->_bltID) { CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing'))); } $this->set('bltID', $this->_bltID); // check for is_monetary status $isMonetary = CRM_Utils_Array::value('is_monetary', $this->_values); $isPayLater = CRM_Utils_Array::value('is_pay_later', $this->_values); //FIXME: to support multiple payment processors if ($isMonetary && (!$isPayLater || CRM_Utils_Array::value('payment_processor', $this->_values))) { $ppID = CRM_Utils_Array::value('payment_processor', $this->_values); if (!$ppID) { CRM_Core_Error::fatal(ts('A payment processor must be selected for this contribution page (contact the site administrator for assistance).')); } $ppIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $ppID); $this->_paymentProcessors = CRM_Financial_BAO_PaymentProcessor::getPayments($ppIds, $this->_mode); $this->set('paymentProcessors', $this->_paymentProcessors); //set default payment processor if (!empty($this->_paymentProcessors) && empty($this->_paymentProcessor)) { foreach ($this->_paymentProcessors as $ppId => $values) { if ($values['is_default'] == 1 || count($this->_paymentProcessors) == 1) { $defaultProcessorId = $ppId; break; } } } if (isset($defaultProcessorId)) { $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($defaultProcessorId, $this->_mode); $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor); } if (!CRM_Utils_System::isNull($this->_paymentProcessors)) { foreach ($this->_paymentProcessors as $eachPaymentProcessor) { // check selected payment processor is active if (empty($eachPaymentProcessor)) { CRM_Core_Error::fatal(ts('A payment processor configured for this page might be disabled (contact the site administrator for assistance).')); } // ensure that processor has a valid config $this->_paymentObject =& CRM_Core_Payment::singleton($this->_mode, $eachPaymentProcessor, $this); $error = $this->_paymentObject->checkConfig(); if (!empty($error)) { CRM_Core_Error::fatal($error); } } } } // get price info // CRM-5095 CRM_Price_BAO_PriceSet::initSet($this, $this->_id, 'civicrm_contribution_page'); // this avoids getting E_NOTICE errors in php $setNullFields = array('amount_block_is_active', 'honor_block_is_active', 'is_allow_other_amount', 'footer_text'); foreach ($setNullFields as $f) { if (!isset($this->_values[$f])) { $this->_values[$f] = NULL; } } //check if Membership Block is enabled, if Membership Fields are included in profile //get membership section for this contribution page $this->_membershipBlock = CRM_Member_BAO_Membership::getMembershipBlock($this->_id); $this->set('membershipBlock', $this->_membershipBlock); if ($this->_values['custom_pre_id']) { $preProfileType = CRM_Core_BAO_UFField::getProfileType($this->_values['custom_pre_id']); } if ($this->_values['custom_post_id']) { $postProfileType = CRM_Core_BAO_UFField::getProfileType($this->_values['custom_post_id']); } if ((isset($postProfileType) && $postProfileType == 'Membership' || isset($preProfileType) && $preProfileType == 'Membership') && !$this->_membershipBlock['is_active']) { CRM_Core_Error::fatal(ts('This page includes a Profile with Membership fields - but the Membership Block is NOT enabled. Please notify the site administrator.')); } $pledgeBlock = CRM_Pledge_BAO_PledgeBlock::getPledgeBlock($this->_id); if ($pledgeBlock) { $this->_values['pledge_block_id'] = CRM_Utils_Array::value('id', $pledgeBlock); $this->_values['max_reminders'] = CRM_Utils_Array::value('max_reminders', $pledgeBlock); $this->_values['initial_reminder_day'] = CRM_Utils_Array::value('initial_reminder_day', $pledgeBlock); $this->_values['additional_reminder_day'] = CRM_Utils_Array::value('additional_reminder_day', $pledgeBlock); //set pledge id in values $pledgeId = CRM_Utils_Request::retrieve('pledgeId', 'Positive', $this); //authenticate pledge user for pledge payment. if ($pledgeId) { $this->_values['pledge_id'] = $pledgeId; //lets override w/ pledge campaign. $this->_values['campaign_id'] = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Pledge', $pledgeId, 'campaign_id'); self::authenticatePledgeUser(); } } $this->set('values', $this->_values); $this->set('fields', $this->_fields); } // Handle PCP $pcpId = CRM_Utils_Request::retrieve('pcpId', 'Positive', $this); if ($pcpId) { $pcp = CRM_PCP_BAO_PCP::handlePcp($pcpId, 'contribute', $this->_values); $this->_pcpId = $pcp['pcpId']; $this->_pcpBlock = $pcp['pcpBlock']; $this->_pcpInfo = $pcp['pcpInfo']; } // Link (button) for users to create their own Personal Campaign page if ($linkText = CRM_PCP_BAO_PCP::getPcpBlockStatus($this->_id, 'contribute')) { $linkTextUrl = CRM_Utils_System::url('civicrm/contribute/campaign', "action=add&reset=1&pageId={$this->_id}&component=contribute", FALSE, NULL, TRUE); $this->assign('linkTextUrl', $linkTextUrl); $this->assign('linkText', $linkText); } //set pledge block if block id is set if (CRM_Utils_Array::value('pledge_block_id', $this->_values)) { $this->assign('pledgeBlock', TRUE); } // check if one of the (amount , membership) bloks is active or not $this->_membershipBlock = $this->get('membershipBlock'); if (!$this->_values['amount_block_is_active'] && !$this->_membershipBlock['is_active'] && !$this->_priceSetId) { CRM_Core_Error::fatal(ts('The requested online contribution page is missing a required Contribution Amount section or Membership section or Price Set. Please check with the site administrator for assistance.')); } if ($this->_values['amount_block_is_active']) { $this->set('amount_block_is_active', $this->_values['amount_block_is_active']); } $this->_contributeMode = $this->get('contributeMode'); $this->assign('contributeMode', $this->_contributeMode); //assigning is_monetary and is_email_receipt to template $this->assign('is_monetary', $this->_values['is_monetary']); $this->assign('is_email_receipt', $this->_values['is_email_receipt']); $this->assign('bltID', $this->_bltID); //assign cancelSubscription URL to templates $this->assign('cancelSubscriptionUrl', CRM_Utils_Array::value('cancelSubscriptionUrl', $this->_values)); // assigning title to template in case someone wants to use it, also setting CMS page title if ($this->_pcpId) { $this->assign('title', $this->_pcpInfo['title']); CRM_Utils_System::setTitle($this->_pcpInfo['title']); } else { $this->assign('title', $this->_values['title']); CRM_Utils_System::setTitle($this->_values['title']); } $this->_defaults = array(); $this->_amount = $this->get('amount'); //CRM-6907 $config = CRM_Core_Config::singleton(); $config->defaultCurrency = CRM_Utils_Array::value('currency', $this->_values, $config->defaultCurrency); //lets allow user to override campaign. $campID = CRM_Utils_Request::retrieve('campID', 'Positive', $this); if ($campID && CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Campaign', $campID)) { $this->_values['campaign_id'] = $campID; } //do check for cancel recurring and clean db, CRM-7696 if (CRM_Utils_Request::retrieve('cancel', 'Boolean', CRM_Core_DAO::$_nullObject)) { self::cancelRecurring(); } }
/** * Flush static caches in functions that might have stored available custom fields */ function _civicrm_api3_custom_field_flush_static_caches() { civicrm_api('custom_field', 'getfields', array('version' => 3, 'cache_clear' => 1)); CRM_Core_BAO_UFField::getAvailableFieldsFlat(TRUE); }
/** * Format profile contact parameters. * * @param array $params * @param $fields * @param int $contactID * @param int $ufGroupId * @param null $ctype * @param bool $skipCustom * * @return array */ public static function formatProfileContactParams(&$params, &$fields, $contactID = NULL, $ufGroupId = NULL, $ctype = NULL, $skipCustom = FALSE) { $data = $contactDetails = array(); // get the contact details (hier) if ($contactID) { list($details, $options) = self::getHierContactDetails($contactID, $fields); $contactDetails = $details[$contactID]; $data['contact_type'] = CRM_Utils_Array::value('contact_type', $contactDetails); $data['contact_sub_type'] = CRM_Utils_Array::value('contact_sub_type', $contactDetails); } else { //we should get contact type only if contact if ($ufGroupId) { $data['contact_type'] = CRM_Core_BAO_UFField::getProfileType($ufGroupId); //special case to handle profile with only contact fields if ($data['contact_type'] == 'Contact') { $data['contact_type'] = 'Individual'; } elseif (CRM_Contact_BAO_ContactType::isaSubType($data['contact_type'])) { $data['contact_type'] = CRM_Contact_BAO_ContactType::getBasicType($data['contact_type']); } } elseif ($ctype) { $data['contact_type'] = $ctype; } else { $data['contact_type'] = 'Individual'; } } //fix contact sub type CRM-5125 if (array_key_exists('contact_sub_type', $params) && !empty($params['contact_sub_type'])) { $data['contact_sub_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, (array) $params['contact_sub_type']) . CRM_Core_DAO::VALUE_SEPARATOR; } elseif (array_key_exists('contact_sub_type_hidden', $params) && !empty($params['contact_sub_type_hidden'])) { // if profile was used, and had any subtype, we obtain it from there $data['contact_sub_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, (array) $params['contact_sub_type_hidden']) . CRM_Core_DAO::VALUE_SEPARATOR; } if ($ctype == 'Organization') { $data['organization_name'] = CRM_Utils_Array::value('organization_name', $contactDetails); } elseif ($ctype == 'Household') { $data['household_name'] = CRM_Utils_Array::value('household_name', $contactDetails); } $locationType = array(); $count = 1; if ($contactID) { //add contact id $data['contact_id'] = $contactID; $primaryLocationType = self::getPrimaryLocationType($contactID); } else { $defaultLocation = CRM_Core_BAO_LocationType::getDefault(); $defaultLocationId = $defaultLocation->id; } // get the billing location type $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate'); $billingLocationTypeId = array_search('Billing', $locationTypes); $blocks = array('email', 'phone', 'im', 'openid'); $multiplFields = array('url'); // prevent overwritten of formatted array, reset all block from // params if it is not in valid format (since import pass valid format) foreach ($blocks as $blk) { if (array_key_exists($blk, $params) && !is_array($params[$blk])) { unset($params[$blk]); } } $primaryPhoneLoc = NULL; $session = CRM_Core_Session::singleton(); foreach ($params as $key => $value) { $fieldName = $locTypeId = $typeId = NULL; list($fieldName, $locTypeId, $typeId) = CRM_Utils_System::explode('-', $key, 3); //store original location type id $actualLocTypeId = $locTypeId; if ($locTypeId == 'Primary') { if ($contactID) { if (in_array($fieldName, $blocks)) { $locTypeId = self::getPrimaryLocationType($contactID, FALSE, $fieldName); } else { $locTypeId = self::getPrimaryLocationType($contactID, FALSE, 'address'); } $primaryLocationType = $locTypeId; } else { $locTypeId = $defaultLocationId; } } if (is_numeric($locTypeId) && !in_array($fieldName, $multiplFields) && substr($fieldName, 0, 7) != 'custom_') { $index = $locTypeId; if (is_numeric($typeId)) { $index .= '-' . $typeId; } if (!in_array($index, $locationType)) { $locationType[$count] = $index; $count++; } $loc = CRM_Utils_Array::key($index, $locationType); $blockName = in_array($fieldName, $blocks) ? $fieldName : 'address'; $data[$blockName][$loc]['location_type_id'] = $locTypeId; //set is_billing true, for location type "Billing" if ($locTypeId == $billingLocationTypeId) { $data[$blockName][$loc]['is_billing'] = 1; } if ($contactID) { //get the primary location type if ($locTypeId == $primaryLocationType) { $data[$blockName][$loc]['is_primary'] = 1; } } elseif ($locTypeId == $defaultLocationId) { $data[$blockName][$loc]['is_primary'] = 1; } if (in_array($fieldName, array('phone'))) { if ($typeId) { $data['phone'][$loc]['phone_type_id'] = $typeId; } else { $data['phone'][$loc]['phone_type_id'] = ''; } $data['phone'][$loc]['phone'] = $value; //special case to handle primary phone with different phone types // in this case we make first phone type as primary if (isset($data['phone'][$loc]['is_primary']) && !$primaryPhoneLoc) { $primaryPhoneLoc = $loc; } if ($loc != $primaryPhoneLoc) { unset($data['phone'][$loc]['is_primary']); } } elseif ($fieldName == 'phone_ext') { $data['phone'][$loc]['phone_ext'] = $value; } elseif ($fieldName == 'email') { $data['email'][$loc]['email'] = $value; } elseif ($fieldName == 'im') { if (isset($params[$key . '-provider_id'])) { $data['im'][$loc]['provider_id'] = $params[$key . '-provider_id']; } if (strpos($key, '-provider_id') !== FALSE) { $data['im'][$loc]['provider_id'] = $params[$key]; } else { $data['im'][$loc]['name'] = $value; } } elseif ($fieldName == 'openid') { $data['openid'][$loc]['openid'] = $value; } else { if ($fieldName === 'state_province') { // CRM-3393 if (is_numeric($value) && (int) $value >= 1000) { $data['address'][$loc]['state_province_id'] = $value; } elseif (empty($value)) { $data['address'][$loc]['state_province_id'] = ''; } else { $data['address'][$loc]['state_province'] = $value; } } elseif ($fieldName === 'country') { // CRM-3393 if (is_numeric($value) && (int) $value >= 1000) { $data['address'][$loc]['country_id'] = $value; } elseif (empty($value)) { $data['address'][$loc]['country_id'] = ''; } else { $data['address'][$loc]['country'] = $value; } } elseif ($fieldName === 'county') { $data['address'][$loc]['county_id'] = $value; } elseif ($fieldName == 'address_name') { $data['address'][$loc]['name'] = $value; } elseif (substr($fieldName, 0, 14) === 'address_custom') { $data['address'][$loc][substr($fieldName, 8)] = $value; } else { $data['address'][$loc][$fieldName] = $value; } } } else { if (substr($key, 0, 4) === 'url-') { $websiteField = explode('-', $key); $data['website'][$websiteField[1]]['website_type_id'] = $websiteField[1]; $data['website'][$websiteField[1]]['url'] = $value; } elseif (in_array($key, self::$_greetingTypes, TRUE)) { //save email/postal greeting and addressee values if any, CRM-4575 $data[$key . '_id'] = $value; } elseif (!$skipCustom && ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key))) { // for autocomplete transfer hidden value instead of label if ($params[$key] && isset($params[$key . '_id'])) { $value = $params[$key . '_id']; } // we need to append time with date if ($params[$key] && isset($params[$key . '_time'])) { $value .= ' ' . $params[$key . '_time']; } // if auth source is not checksum / login && $value is blank, do not proceed - CRM-10128 if (($session->get('authSrc') & CRM_Core_Permission::AUTH_SRC_CHECKSUM + CRM_Core_Permission::AUTH_SRC_LOGIN) == 0 && ($value == '' || !isset($value))) { continue; } $valueId = NULL; if (!empty($params['customRecordValues'])) { if (is_array($params['customRecordValues']) && !empty($params['customRecordValues'])) { foreach ($params['customRecordValues'] as $recId => $customFields) { if (is_array($customFields) && !empty($customFields)) { foreach ($customFields as $customFieldName) { if ($customFieldName == $key) { $valueId = $recId; break; } } } } } } $type = $data['contact_type']; if (!empty($data['contact_sub_type'])) { $type = $data['contact_sub_type']; $type = explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($type, CRM_Core_DAO::VALUE_SEPARATOR)); // generally a contact even if, has multiple subtypes the parent-type is going to be one only // and since formatCustomField() would be interested in parent type, lets consider only one subtype // as the results going to be same. $type = $type[0]; } CRM_Core_BAO_CustomField::formatCustomField($customFieldId, $data['custom'], $value, $type, $valueId, $contactID); } elseif ($key == 'edit') { continue; } else { if ($key == 'location') { foreach ($value as $locationTypeId => $field) { foreach ($field as $block => $val) { if ($block == 'address' && array_key_exists('address_name', $val)) { $value[$locationTypeId][$block]['name'] = $value[$locationTypeId][$block]['address_name']; } } } } if ($key == 'phone' && isset($params['phone_ext'])) { $data[$key] = $value; foreach ($value as $cnt => $phoneBlock) { if ($params[$key][$cnt]['location_type_id'] == $params['phone_ext'][$cnt]['location_type_id']) { $data[$key][$cnt]['phone_ext'] = CRM_Utils_Array::retrieveValueRecursive($params['phone_ext'][$cnt], 'phone_ext'); } } } elseif (in_array($key, array('nick_name', 'job_title', 'middle_name', 'birth_date', 'gender_id', 'current_employer', 'prefix_id', 'suffix_id')) && ($value == '' || !isset($value)) && ($session->get('authSrc') & CRM_Core_Permission::AUTH_SRC_CHECKSUM + CRM_Core_Permission::AUTH_SRC_LOGIN) == 0) { // CRM-10128: if auth source is not checksum / login && $value is blank, do not fill $data with empty value // to avoid update with empty values continue; } else { $data[$key] = $value; } } } } if (!isset($data['contact_type'])) { $data['contact_type'] = 'Individual'; } //set the values for checkboxes (do_not_email, do_not_mail, do_not_trade, do_not_phone) $privacy = CRM_Core_SelectValues::privacy(); foreach ($privacy as $key => $value) { if (array_key_exists($key, $fields)) { // do not reset values for existing contacts, if fields are added to a profile if (array_key_exists($key, $params)) { $data[$key] = $params[$key]; if (empty($params[$key])) { $data[$key] = 0; } } elseif (!$contactID) { $data[$key] = 0; } } } return array($data, $contactDetails); }
/** * @return array|null */ public static function getMemberBatchEntryFields() { if (self::$_memberBatchEntryFields === NULL) { self::$_memberBatchEntryFields = array('send_receipt' => array('name' => 'send_receipt', 'title' => ts('Send Receipt')), 'soft_credit' => array('name' => 'soft_credit', 'title' => ts('Soft Credit')), 'product_name' => array('name' => 'product_name', 'title' => ts('Premiums')), 'financial_type' => array('name' => 'financial_type', 'title' => ts('Financial Type')), 'total_amount' => array('name' => 'total_amount', 'title' => ts('Total Amount')), 'receive_date' => array('name' => 'receive_date', 'title' => ts('Receive Date')), 'payment_instrument' => array('name' => 'payment_instrument', 'title' => ts('Payment Instrument')), 'contribution_status_id' => array('name' => 'contribution_status_id', 'title' => ts('Contribution Status'))); } return self::$_memberBatchEntryFields; }
/** * Browse all uf data groups. * * @param * * @return void */ public function browse($action = NULL) { $ufGroup = array(); $allUFGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup(); if (empty($allUFGroups)) { return; } $ufGroups = CRM_Core_PseudoConstant::get('CRM_Core_DAO_UFField', 'uf_group_id'); CRM_Utils_Hook::aclGroup(CRM_Core_Permission::ADMIN, NULL, 'civicrm_uf_group', $ufGroups, $allUFGroups); foreach ($allUFGroups as $id => $value) { $ufGroup[$id] = array(); $ufGroup[$id]['id'] = $id; $ufGroup[$id]['title'] = $value['title']; $ufGroup[$id]['created_id'] = $value['created_id']; $ufGroup[$id]['created_by'] = CRM_Contact_BAO_Contact::displayName($value['created_id']); $ufGroup[$id]['description'] = $value['description']; $ufGroup[$id]['is_active'] = $value['is_active']; $ufGroup[$id]['group_type'] = $value['group_type']; $ufGroup[$id]['is_reserved'] = $value['is_reserved']; // form all action links $action = array_sum(array_keys(self::actionLinks())); // update enable/disable links depending on uf_group properties. if ($value['is_active']) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } // drop certain actions if the profile is reserved if ($value['is_reserved']) { $action -= CRM_Core_Action::UPDATE; $action -= CRM_Core_Action::DISABLE; $action -= CRM_Core_Action::DELETE; } $groupTypes = self::extractGroupTypes($value['group_type']); // drop Create, Edit and View mode links if profile group_type is one of the following: // Contribution, Membership, Activity, Participant, Case, Grant $isMixedProfile = CRM_Core_BAO_UFField::checkProfileType($id); if ($isMixedProfile) { $action -= CRM_Core_Action::ADD; $action -= CRM_Core_Action::ADVANCED; $action -= CRM_Core_Action::BASIC; $action -= CRM_Core_Action::PROFILE; } $ufGroup[$id]['group_type'] = self::formatGroupTypes($groupTypes); $ufGroup[$id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $id), ts('more'), FALSE, 'ufGroup.row.actions', 'UFGroup', $id); //get the "Used For" from uf_join $ufGroup[$id]['module'] = implode(', ', CRM_Core_BAO_UFGroup::getUFJoinRecord($id, TRUE)); } $this->assign('rows', $ufGroup); }
/** * Decides the contact type for given survey. */ public static function getSurveyContactType($surveyId) { $contactType = NULL; //apply filter of profile type on search. $profileId = self::getSurveyProfileId($surveyId); if ($profileId) { $profileType = CRM_Core_BAO_UFField::getProfileType($profileId); if (in_array($profileType, CRM_Contact_BAO_ContactType::basicTypes())) { $contactType = $profileType; } } return $contactType; }
/** * global validation rules for the form * * @param array $fields posted values of the form * * @return array list of errors to be posted back to the form * @static * @access public */ static function formRule($fields) { if (CRM_Core_BAO_UFField::checkProfileType($fields['uf_group_id'])) { $errorMsg['uf_group_id'] = "You cannot select mix profile for batch update."; } if (!empty($errorMsg)) { return $errorMsg; } return TRUE; }
/** * Build the form object. */ public function buildQuickForm() { // build profiles first so that we can determine address fields etc // and then show copy address checkbox $this->buildCustom($this->_values['custom_pre_id'], 'customPre'); $this->buildCustom($this->_values['custom_post_id'], 'customPost'); if (!empty($this->_fields) && !empty($this->_values['custom_pre_id'])) { $profileAddressFields = array(); foreach ($this->_fields as $key => $value) { CRM_Core_BAO_UFField::assignAddressField($key, $profileAddressFields, array('uf_group_id' => $this->_values['custom_pre_id'])); } $this->set('profileAddressFields', $profileAddressFields); } // Build payment processor form if (empty($_GET['onbehalf'])) { CRM_Core_Payment_ProcessorForm::buildQuickForm($this); // Return if we are in an ajax - this is probably redundant now as // processor does not call this form for a snippet anymore - but unsure about // cdType if ($this->_snippet) { return; } } $config = CRM_Core_Config::singleton(); $contactID = $this->getContactID(); if ($contactID) { $this->assign('contact_id', $contactID); $this->assign('display_name', CRM_Contact_BAO_Contact::displayName($contactID)); } if ($this->_onbehalf) { CRM_Contribute_Form_Contribution_OnBehalfOf::buildQuickForm($this); // Return if we are in an ajax callback if ($this->_snippet) { return; } } $this->applyFilter('__ALL__', 'trim'); $this->add('text', "email-{$this->_bltID}", ts('Email Address'), array('size' => 30, 'maxlength' => 60, 'class' => 'email'), TRUE); $this->addRule("email-{$this->_bltID}", ts('Email is not valid.'), 'email'); $pps = array(); //@todo - this should be replaced by a check as to whether billing fields are set $onlinePaymentProcessorEnabled = FALSE; if (!empty($this->_paymentProcessors)) { foreach ($this->_paymentProcessors as $key => $name) { if ($name['billing_mode'] == 1) { $onlinePaymentProcessorEnabled = TRUE; } $pps[$key] = $name['name']; } } if (!empty($this->_values['is_pay_later'])) { $pps[0] = $this->_values['pay_later_text']; } if (count($pps) > 1) { $this->addRadio('payment_processor_id', ts('Payment Method'), $pps, NULL, " ", TRUE); } elseif (!empty($pps)) { $key = array_keys($pps); $key = array_pop($key); $this->addElement('hidden', 'payment_processor_id', $key); if ($key === 0) { $this->assign('is_pay_later', $this->_values['is_pay_later']); $this->assign('pay_later_text', $this->_values['pay_later_text']); } } $contactID = $this->getContactID(); if ($this->getContactID() === 0) { $this->addCidZeroOptions($onlinePaymentProcessorEnabled); } //build pledge block. $this->_useForMember = 0; //don't build membership block when pledge_id is passed if (empty($this->_values['pledge_id'])) { $this->_separateMembershipPayment = FALSE; if (in_array('CiviMember', $config->enableComponents)) { $isTest = 0; if ($this->_action & CRM_Core_Action::PREVIEW) { $isTest = 1; } if ($this->_priceSetId && CRM_Core_Component::getComponentID('CiviMember') == CRM_Utils_Array::value('extends', $this->_priceSet)) { $this->_useForMember = 1; $this->set('useForMember', $this->_useForMember); } $this->_separateMembershipPayment = CRM_Member_BAO_Membership::buildMembershipBlock($this, $this->_id, $this->_membershipContactID, TRUE, NULL, FALSE, $isTest); } $this->set('separateMembershipPayment', $this->_separateMembershipPayment); } $this->assign('useForMember', $this->_useForMember); // If we configured price set for contribution page // we are not allow membership signup as well as any // other contribution amount field, CRM-5095 if (isset($this->_priceSetId) && $this->_priceSetId) { $this->add('hidden', 'priceSetId', $this->_priceSetId); // build price set form. $this->set('priceSetId', $this->_priceSetId); CRM_Price_BAO_PriceSet::buildPriceSet($this); if ($this->_values['is_monetary'] && $this->_values['is_recur'] && empty($this->_values['pledge_id'])) { self::buildRecur($this); } } if ($this->_priceSetId) { $is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config'); if ($is_quick_config) { $this->_useForMember = 0; $this->set('useForMember', $this->_useForMember); } } if ($this->_values['is_for_organization']) { $this->buildOnBehalfOrganization(); } //we allow premium for pledge during pledge creation only. if (empty($this->_values['pledge_id'])) { CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, TRUE); } //add honor block if ($this->_honor_block_is_active) { $this->assign('honor_block_is_active', TRUE); //build soft-credit section CRM_Contribute_Form_SoftCredit::buildQuickForm($this); //build honoree profile section CRM_Contact_Form_ProfileContact::buildQuickForm($this); } //don't build pledge block when mid is passed if (!$this->_mid) { $config = CRM_Core_Config::singleton(); if (in_array('CiviPledge', $config->enableComponents) && !empty($this->_values['pledge_block_id'])) { CRM_Pledge_BAO_PledgeBlock::buildPledgeBlock($this); } } //to create an cms user if (!$this->_contactID) { $createCMSUser = FALSE; if ($this->_values['custom_pre_id']) { $profileID = $this->_values['custom_pre_id']; $createCMSUser = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileID, 'is_cms_user'); } if (!$createCMSUser && $this->_values['custom_post_id']) { if (!is_array($this->_values['custom_post_id'])) { $profileIDs = array($this->_values['custom_post_id']); } else { $profileIDs = $this->_values['custom_post_id']; } foreach ($profileIDs as $pid) { if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $pid, 'is_cms_user')) { $profileID = $pid; $createCMSUser = TRUE; break; } } } if ($createCMSUser) { CRM_Core_BAO_CMSUser::buildForm($this, $profileID, TRUE); } } if ($this->_pcpId) { if ($pcpSupporter = CRM_PCP_BAO_PCP::displayName($this->_pcpId)) { $pcp_supporter_text = ts('This contribution is being made thanks to the effort of <strong>%1</strong>, who supports our campaign.', array(1 => $pcpSupporter)); // Only tell people that can also create a PCP if the contribution page has a non-empty value in the "Create Personal Campaign Page link" field. $text = CRM_PCP_BAO_PCP::getPcpBlockStatus($this->_id, 'contribute'); if (!empty($text)) { $pcp_supporter_text .= ts("You can support it as well - once you complete the donation, you will be able to create your own Personal Campaign Page!"); } $this->assign('pcpSupporterText', $pcp_supporter_text); } $prms = array('id' => $this->_pcpId); CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $prms, $pcpInfo); if ($pcpInfo['is_honor_roll']) { $this->assign('isHonor', TRUE); $this->add('checkbox', 'pcp_display_in_roll', ts('Show my contribution in the public honor roll'), NULL, NULL, array('onclick' => "showHideByValue('pcp_display_in_roll','','nameID|nickID|personalNoteID','block','radio',false); pcpAnonymous( );")); $extraOption = array('onclick' => "return pcpAnonymous( );"); $elements = array(); $elements[] =& $this->createElement('radio', NULL, '', ts('Include my name and message'), 0, $extraOption); $elements[] =& $this->createElement('radio', NULL, '', ts('List my contribution anonymously'), 1, $extraOption); $this->addGroup($elements, 'pcp_is_anonymous', NULL, ' '); $this->add('text', 'pcp_roll_nickname', ts('Name'), array('maxlength' => 30)); $this->add('textarea', 'pcp_personal_note', ts('Personal Note'), array('style' => 'height: 3em; width: 40em;')); } } //we have to load confirm contribution button in template //when multiple payment processor as the user //can toggle with payment processor selection $billingModePaymentProcessors = 0; if (!empty($this->_paymentProcessors)) { foreach ($this->_paymentProcessors as $key => $values) { if ($values['billing_mode'] == CRM_Core_Payment::BILLING_MODE_BUTTON) { $billingModePaymentProcessors++; } } } if ($billingModePaymentProcessors && count($this->_paymentProcessors) == $billingModePaymentProcessors) { $allAreBillingModeProcessors = TRUE; } else { $allAreBillingModeProcessors = FALSE; } if (!($allAreBillingModeProcessors && !$this->_values['is_pay_later'])) { $submitButton = array('type' => 'upload', 'name' => CRM_Utils_Array::value('is_confirm_enabled', $this->_values) ? ts('Confirm Contribution') : ts('Contribute'), 'spacing' => ' ', 'isDefault' => TRUE); // Add submit-once behavior when confirm page disabled if (empty($this->_values['is_confirm_enabled'])) { $submitButton['js'] = array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');"); } $this->addButtons(array($submitButton)); } $this->addFormRule(array('CRM_Contribute_Form_Contribution_Main', 'formRule'), $this); }
/** * Send the emails. * * @param int $contactID * Contact id. * @param array $values * Associated array of fields. * @param bool $isTest * If in test mode. * @param bool $returnMessageText * Return the message text instead of sending the mail. * * @param null $fieldTypes * * @return void */ public static function sendMail($contactID, $values, $isTest = FALSE, $returnMessageText = FALSE, $fieldTypes = NULL) { $gIds = $params = array(); $email = NULL; if (isset($values['custom_pre_id'])) { $preProfileType = CRM_Core_BAO_UFField::getProfileType($values['custom_pre_id']); if ($preProfileType == 'Membership' && !empty($values['membership_id'])) { $params['custom_pre_id'] = array(array('member_id', '=', $values['membership_id'], 0, 0)); } elseif ($preProfileType == 'Contribution' && !empty($values['contribution_id'])) { $params['custom_pre_id'] = array(array('contribution_id', '=', $values['contribution_id'], 0, 0)); } $gIds['custom_pre_id'] = $values['custom_pre_id']; } if (isset($values['custom_post_id'])) { $postProfileType = CRM_Core_BAO_UFField::getProfileType($values['custom_post_id']); if ($postProfileType == 'Membership' && !empty($values['membership_id'])) { $params['custom_post_id'] = array(array('member_id', '=', $values['membership_id'], 0, 0)); } elseif ($postProfileType == 'Contribution' && !empty($values['contribution_id'])) { $params['custom_post_id'] = array(array('contribution_id', '=', $values['contribution_id'], 0, 0)); } $gIds['custom_post_id'] = $values['custom_post_id']; } if (!empty($values['is_for_organization'])) { if (!empty($values['membership_id'])) { $params['onbehalf_profile'] = array(array('member_id', '=', $values['membership_id'], 0, 0)); } elseif (!empty($values['contribution_id'])) { $params['onbehalf_profile'] = array(array('contribution_id', '=', $values['contribution_id'], 0, 0)); } } //check whether it is a test drive if ($isTest && !empty($params['custom_pre_id'])) { $params['custom_pre_id'][] = array('contribution_test', '=', 1, 0, 0); } if ($isTest && !empty($params['custom_post_id'])) { $params['custom_post_id'][] = array('contribution_test', '=', 1, 0, 0); } if (!$returnMessageText && !empty($gIds)) { //send notification email if field values are set (CRM-1941) foreach ($gIds as $key => $gId) { if ($gId) { $email = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify'); if ($email) { $val = CRM_Core_BAO_UFGroup::checkFieldsEmptyValues($gId, $contactID, CRM_Utils_Array::value($key, $params), TRUE); CRM_Core_BAO_UFGroup::commonSendMail($contactID, $val); } } } } if (!empty($values['is_email_receipt']) || !empty($values['onbehalf_dupe_alert']) || $returnMessageText) { $template = CRM_Core_Smarty::singleton(); // get the billing location type if (!array_key_exists('related_contact', $values)) { $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate'); $billingLocationTypeId = array_search('Billing', $locationTypes); } else { // presence of related contact implies onbehalf of org case, // where location type is set to default. $locType = CRM_Core_BAO_LocationType::getDefault(); $billingLocationTypeId = $locType->id; } if (!array_key_exists('related_contact', $values)) { list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID, FALSE, $billingLocationTypeId); } // get primary location email if no email exist( for billing location). if (!$email) { list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID); } if (empty($displayName)) { list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID); } //for display profile need to get individual contact id, //hence get it from related_contact if on behalf of org true CRM-3767 //CRM-5001 Contribution/Membership:: On Behalf of Organization, //If profile GROUP contain the Individual type then consider the //profile is of Individual ( including the custom data of membership/contribution ) //IF Individual type not present in profile then it is consider as Organization data. $userID = $contactID; if ($preID = CRM_Utils_Array::value('custom_pre_id', $values)) { if (!empty($values['related_contact'])) { $preProfileTypes = CRM_Core_BAO_UFGroup::profileGroups($preID); //@todo - following line should not refer to undefined $postProfileTypes? figure out way to test if (in_array('Individual', $preProfileTypes) || in_array('Contact', $postProfileTypes)) { //Take Individual contact ID $userID = CRM_Utils_Array::value('related_contact', $values); } } self::buildCustomDisplay($preID, 'customPre', $userID, $template, $params['custom_pre_id']); } $userID = $contactID; if ($postID = CRM_Utils_Array::value('custom_post_id', $values)) { if (!empty($values['related_contact'])) { $postProfileTypes = CRM_Core_BAO_UFGroup::profileGroups($postID); if (in_array('Individual', $postProfileTypes) || in_array('Contact', $postProfileTypes)) { //Take Individual contact ID $userID = CRM_Utils_Array::value('related_contact', $values); } } self::buildCustomDisplay($postID, 'customPost', $userID, $template, $params['custom_post_id']); } if (isset($values['honor'])) { $honorValues = $values['honor']; CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($template, $honorValues['honor_profile_values'], $honorValues['honor_profile_id'], $honorValues['honor_id']); } $title = isset($values['title']) ? $values['title'] : CRM_Contribute_PseudoConstant::contributionPage($values['contribution_page_id']); // set email in the template here $tplParams = array('email' => $email, 'receiptFromEmail' => CRM_Utils_Array::value('receipt_from_email', $values), 'contactID' => $contactID, 'displayName' => $displayName, 'contributionID' => CRM_Utils_Array::value('contribution_id', $values), 'contributionOtherID' => CRM_Utils_Array::value('contribution_other_id', $values), 'lineItem' => CRM_Utils_Array::value('lineItem', $values), 'priceSetID' => CRM_Utils_Array::value('priceSetID', $values), 'title' => $title, 'isShare' => CRM_Utils_Array::value('is_share', $values), 'thankyou_title' => CRM_Utils_Array::value('thankyou_title', $values)); if ($contributionTypeId = CRM_Utils_Array::value('financial_type_id', $values)) { $tplParams['contributionTypeId'] = $contributionTypeId; $tplParams['contributionTypeName'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $contributionTypeId); } if ($contributionPageId = CRM_Utils_Array::value('id', $values)) { $tplParams['contributionPageId'] = $contributionPageId; } // address required during receipt processing (pdf and email receipt) if ($displayAddress = CRM_Utils_Array::value('address', $values)) { $tplParams['address'] = $displayAddress; } // CRM-6976 $originalCCReceipt = CRM_Utils_Array::value('cc_receipt', $values); // cc to related contacts of contributor OR the one who // signs up. Is used for cases like - on behalf of // contribution / signup ..etc if (array_key_exists('related_contact', $values)) { list($ccDisplayName, $ccEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($values['related_contact']); $ccMailId = "{$ccDisplayName} <{$ccEmail}>"; //@todo - this is the only place in this function where $values is altered - but I can't find any evidence it is used $values['cc_receipt'] = !empty($values['cc_receipt']) ? $values['cc_receipt'] . ',' . $ccMailId : $ccMailId; // reset primary-email in the template $tplParams['email'] = $ccEmail; $tplParams['onBehalfName'] = $displayName; $tplParams['onBehalfEmail'] = $email; $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $values['id']); $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); $profileId = $OnBehalfProfile[0]; $userID = $contactID; self::buildCustomDisplay($profileId, 'onBehalfProfile', $userID, $template, $params['onbehalf_profile'], $fieldTypes); } // use either the contribution or membership receipt, based on whether it’s a membership-related contrib or not $sendTemplateParams = array('groupName' => !empty($values['isMembership']) ? 'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution', 'valueName' => !empty($values['isMembership']) ? 'membership_online_receipt' : 'contribution_online_receipt', 'contactId' => $contactID, 'tplParams' => $tplParams, 'isTest' => $isTest, 'PDFFilename' => 'receipt.pdf'); if ($returnMessageText) { list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); return array('subject' => $subject, 'body' => $message, 'to' => $displayName, 'html' => $html); } if ($values['is_email_receipt']) { $sendTemplateParams['from'] = CRM_Utils_Array::value('receipt_from_name', $values) . ' <' . $values['receipt_from_email'] . '>'; $sendTemplateParams['toName'] = $displayName; $sendTemplateParams['toEmail'] = $email; $sendTemplateParams['cc'] = CRM_Utils_Array::value('cc_receipt', $values); $sendTemplateParams['bcc'] = CRM_Utils_Array::value('bcc_receipt', $values); //send email with pdf invoice $template = CRM_Core_Smarty::singleton(); $taxAmt = $template->get_template_vars('dataArray'); $prefixValue = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings'); $invoicing = CRM_Utils_Array::value('invoicing', $prefixValue); if (count($taxAmt) > 0 && (isset($invoicing) && isset($prefixValue['is_email_pdf']))) { $sendTemplateParams['isEmailPdf'] = TRUE; $sendTemplateParams['contributionId'] = $values['contribution_id']; } list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); } // send duplicate alert, if dupe match found during on-behalf-of processing. if (!empty($values['onbehalf_dupe_alert'])) { $sendTemplateParams['groupName'] = 'msg_tpl_workflow_contribution'; $sendTemplateParams['valueName'] = 'contribution_dupalert'; $sendTemplateParams['from'] = ts('Automatically Generated') . " <{$values['receipt_from_email']}>"; $sendTemplateParams['toName'] = CRM_Utils_Array::value('receipt_from_name', $values); $sendTemplateParams['toEmail'] = CRM_Utils_Array::value('receipt_from_email', $values); $sendTemplateParams['tplParams']['onBehalfID'] = $contactID; $sendTemplateParams['tplParams']['receiptMessage'] = $message; // fix cc and reset back to original, CRM-6976 $sendTemplateParams['cc'] = $originalCCReceipt; CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); } } }
/** * Global form rule. * * @param array $fields * The input form values. * * @param $files * @param int $contributionPageId * * @return bool|array * true if no errors, else array of errors */ public static function formRule($fields, $files, $contributionPageId) { $errors = array(); $preProfileType = $postProfileType = NULL; // for membership profile make sure Membership section is enabled // get membership section for this contribution page $dao = new CRM_Member_DAO_MembershipBlock(); $dao->entity_table = 'civicrm_contribution_page'; $dao->entity_id = $contributionPageId; $membershipEnable = FALSE; if ($dao->find(TRUE) && $dao->is_active) { $membershipEnable = TRUE; } if ($fields['custom_pre_id']) { $preProfileType = CRM_Core_BAO_UFField::getProfileType($fields['custom_pre_id']); } if ($fields['custom_post_id']) { $postProfileType = CRM_Core_BAO_UFField::getProfileType($fields['custom_post_id']); } $errorMsg = ts('You must enable the Membership Block for this Contribution Page if you want to include a Profile with Membership fields.'); if ($preProfileType == 'Membership' && !$membershipEnable) { $errors['custom_pre_id'] = $errorMsg; } if ($postProfileType == 'Membership' && !$membershipEnable) { $errors['custom_post_id'] = $errorMsg; } $behalf = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contributionPageId, 'is_for_organization'); if ($fields['custom_pre_id']) { $errorMsg = ts('You should move the membership related fields in the "On Behalf" profile for this Contribution Page'); if ($preProfileType == 'Membership' && $behalf) { $errors['custom_pre_id'] = isset($errors['custom_pre_id']) ? $errors['custom_pre_id'] . $errorMsg : $errorMsg; } } if ($fields['custom_post_id']) { $errorMsg = ts('You should move the membership related fields in the "On Behalf" profile for this Contribution Page'); if ($postProfileType == 'Membership' && $behalf) { $errors['custom_post_id'] = isset($errors['custom_post_id']) ? $errors['custom_post_id'] . $errorMsg : $errorMsg; } } return empty($errors) ? TRUE : $errors; }
/** * Update the is_active flag in the db. * * @param int $id * Id of the database record. * @param bool $is_active * Value we want to set the is_active field. * * @return Object * DAO object on success, null otherwise */ public static function setIsActive($id, $is_active) { // reset the cache CRM_Core_BAO_Cache::deleteGroup('contact fields'); if (!$is_active) { CRM_Core_BAO_UFField::setUFFieldStatus($id, $is_active); } return CRM_Core_DAO::setFieldValue('CRM_Core_DAO_CustomGroup', $id, 'is_active', $is_active); }
/** * returns the column headers as an array of tuples: * (name, sortName (key to the sort array)) * * @param string $action the action being performed * @param enum $output what should the result set include (web/email/csv) * * @return array the column headers that need to be displayed * @access public */ function &getColumnHeaders($action = NULL, $output = NULL) { static $skipFields = array('group', 'tag'); $multipleFields = array('url'); $direction = CRM_Utils_Sort::ASCENDING; $empty = TRUE; if (!isset(self::$_columnHeaders)) { self::$_columnHeaders = array(array('name' => ''), array('name' => ts('Name'), 'sort' => 'sort_name', 'direction' => CRM_Utils_Sort::ASCENDING, 'field_name' => 'sort_name')); $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); foreach ($this->_fields as $name => $field) { // skip pseudo fields if (substr($name, 0, 9) == 'phone_ext') { continue; } if (!empty($field['in_selector']) && !in_array($name, $skipFields)) { if (strpos($name, '-') !== FALSE) { $value = explode('-', $name); $fieldName = CRM_Utils_Array::value(0, $value); $lType = CRM_Utils_Array::value(1, $value); $type = CRM_Utils_Array::value(2, $value); if (!in_array($fieldName, $multipleFields)) { if ($lType == 'Primary') { $locationTypeName = 1; } else { $locationTypeName = $locationTypes[$lType]; } if (in_array($fieldName, array('phone', 'im', 'email'))) { if ($type) { $name = "`{$locationTypeName}-{$fieldName}-{$type}`"; } else { $name = "`{$locationTypeName}-{$fieldName}`"; } } else { $name = "`{$locationTypeName}-{$fieldName}`"; } } else { $name = "website-{$lType}-{$fieldName}"; } } self::$_columnHeaders[] = array('name' => $field['title'], 'sort' => $name, 'direction' => $direction, 'field_name' => CRM_Core_BAO_UFField::isValidFieldName($name) ? $name : $fieldName); $direction = CRM_Utils_Sort::DONTCARE; $empty = FALSE; } } // if we dont have any valid columns, dont add the implicit ones // this allows the template to check on emptiness of column headers if ($empty) { self::$_columnHeaders = array(); } else { self::$_columnHeaders[] = array('desc' => ts('Actions')); } } return self::$_columnHeaders; }
/** * When omitting a GID, return a list of all fields. */ public function testGetAvailableFlat() { $fields = CRM_Core_BAO_UFField::getAvailableFieldsFlat(); // Make sure that each entity appears with at least one field $this->assertEquals('Contact', $fields['do_not_sms']['field_type']); $this->assertEquals('Contact', $fields['city']['field_type']); $this->assertEquals('Individual', $fields['first_name']['field_type']); $this->assertEquals('Individual', $fields['birth_date']['field_type']); $this->assertEquals('Organization', $fields['organization_name']['field_type']); $this->assertEquals('Organization', $fields['legal_name']['field_type']); $this->assertEquals('Contribution', $fields['amount_level']['field_type']); $this->assertEquals('Contribution', $fields['cancel_reason']['field_type']); $this->assertEquals('Participant', $fields['participant_note']['field_type']); $this->assertEquals('Participant', $fields['participant_role']['field_type']); $this->assertEquals('Membership', $fields['join_date']['field_type']); $this->assertEquals('Membership', $fields['membership_end_date']['field_type']); $this->assertEquals('Activity', $fields['activity_date_time']['field_type']); $this->assertEquals('Activity', $fields['activity_subject']['field_type']); // Make sure that some of the blacklisted fields don't appear $this->assertFalse(isset($fields['is_pay_later'])); $this->assertFalse(isset($fields['participant_role_id'])); $this->assertFalse(isset($fields['membership_type_id'])); }
/** * Submit a set of fields against a profile. * * Note choice of submit versus create is discussed CRM-13234 & related to the fact * 'profile' is being treated as a data-entry entity * * @param array $params * * @throws API_Exception * @return array * API result array */ function civicrm_api3_profile_submit($params) { $profileID = _civicrm_api3_profile_getProfileID($params['profile_id']); if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileID, 'is_active')) { //@todo declare pseudoconstant & let api do this throw new API_Exception('Invalid value for profile_id'); } $isContactActivityProfile = CRM_Core_BAO_UFField::checkContactActivityProfileType($profileID); if (!empty($params['id']) && CRM_Core_BAO_UFField::checkProfileType($profileID) && !$isContactActivityProfile) { throw new API_Exception('Update profiles including more than one entity not currently supported'); } $contactParams = $activityParams = $missingParams = array(); $profileFields = civicrm_api3('Profile', 'getfields', array('action' => 'submit', 'profile_id' => $profileID)); $profileFields = $profileFields['values']; if ($isContactActivityProfile) { civicrm_api3_verify_mandatory($params, NULL, array('activity_id')); $errors = CRM_Profile_Form::validateContactActivityProfile($params['activity_id'], $params['contact_id'], $profileID); if (!empty($errors)) { throw new API_Exception(array_pop($errors)); } } foreach ($profileFields as $fieldName => $field) { if (!isset($params[$fieldName])) { continue; } $value = $params[$fieldName]; if ($params[$fieldName] && isset($params[$fieldName . '_id'])) { $value = $params[$fieldName . '_id']; } $contactEntities = array('contact', 'individual', 'organization', 'household'); $locationEntities = array('email', 'address', 'phone', 'website', 'im'); $entity = strtolower(CRM_Utils_Array::value('entity', $field)); if ($entity && !in_array($entity, array_merge($contactEntities, $locationEntities))) { $contactParams['api.' . $entity . '.create'][$fieldName] = $value; //@todo we are not currently declaring this option if (isset($params['batch_id']) && strtolower($entity) == 'contribution') { $contactParams['api.' . $entity . '.create']['batch_id'] = $params['batch_id']; } if (isset($params[$entity . '_id'])) { //todo possibly declare $entity_id in getfields ? $contactParams['api.' . $entity . '.create']['id'] = $params[$entity . '_id']; } } else { $contactParams[_civicrm_api3_profile_translate_fieldnames_for_bao($fieldName)] = $value; } } if (isset($contactParams['api.contribution.create']) && isset($contactParams['api.membership.create'])) { $contactParams['api.membership_payment.create'] = array('contribution_id' => '$value.api.contribution.create.id', 'membership_id' => '$value.api.membership.create.id'); } if (isset($contactParams['api.contribution.create']) && isset($contactParams['api.participant.create'])) { $contactParams['api.participant_payment.create'] = array('contribution_id' => '$value.api.contribution.create.id', 'participant_id' => '$value.api.participant.create.id'); } $contactParams['contact_id'] = CRM_Utils_Array::value('contact_id', $params); $contactParams['profile_id'] = $profileID; $contactParams['skip_custom'] = 1; $contactProfileParams = civicrm_api3_profile_apply($contactParams); // Contact profile fields $profileParams = $contactProfileParams['values']; // If profile having activity fields if ($isContactActivityProfile && !empty($activityParams)) { $activityParams['id'] = $params['activity_id']; $profileParams['api.activity.create'] = $activityParams; } return civicrm_api3('contact', 'create', $profileParams); }
/** * get all the registration fields * * @param int $action what action are we doing * @param int $mode mode * * @return array the fields that are needed for registration * @static * @access public */ function getRegistrationFields($action, $mode) { if ($mode & CRM_PROFILE_FORM_MODE_REGISTER) { $ufGroups =& CRM_Core_BAO_UFGroup::getModuleUFGroup('User Registration'); } else { $ufGroups =& CRM_Core_BAO_UFGroup::getModuleUFGroup('Profile'); } if (!is_array($ufGroups)) { return false; } $fields = array(); require_once "CRM/Core/BAO/UFField.php"; foreach ($ufGroups as $id => $title) { if (CRM_Core_BAO_UFField::checkProfileType($id)) { // to skip mix profiles continue; } $subset = CRM_Core_BAO_UFGroup::getFields($id, true, $action); // we do not allow duplicates. the first field is the winner foreach ($subset as $name => $field) { if (!CRM_Utils_Array::value($name, $fields)) { $fields[$name] = $field; } } } return $fields; }
/** * Check if we are rendering mixed profiles. * * @param array $profileIds * Associated array of profile ids. * * @return bool * true if profile is mixed */ public static function checkForMixProfiles($profileIds) { $mixProfile = FALSE; $contactTypes = array('Individual', 'Household', 'Organization'); $subTypes = CRM_Contact_BAO_ContactType::subTypes(); $components = array('Contribution', 'Participant', 'Membership', 'Activity'); $typeCount = array('ctype' => array(), 'subtype' => array()); foreach ($profileIds as $gid) { $profileType = CRM_Core_BAO_UFField::getProfileType($gid); // ignore profile of type Contact if ($profileType == 'Contact') { continue; } if (in_array($profileType, $contactTypes)) { if (!isset($typeCount['ctype'][$profileType])) { $typeCount['ctype'][$profileType] = 1; } // check if we are rendering profile of different contact types if (count($typeCount['ctype']) == 2) { $mixProfile = TRUE; break; } } elseif (in_array($profileType, $components)) { $mixProfile = TRUE; break; } else { if (!isset($typeCount['subtype'][$profileType])) { $typeCount['subtype'][$profileType] = 1; } // check if we are rendering profile of different contact sub types if (count($typeCount['subtype']) == 2) { $mixProfile = TRUE; break; } } } return $mixProfile; }
/** * update the is_active flag in the db * * @param int $id id of the database record * @param boolean $is_active value we want to set the is_active field * * @return Object DAO object on sucess, null otherwise * @static * @access public */ static function setIsActive($id, $is_active) { require_once 'CRM/Core/BAO/UFField.php'; if ($is_active) { //CRM_Core_BAO_UFField::setUFFieldStatus($id, $is_active); } else { CRM_Core_BAO_UFField::setUFFieldStatus($id, $is_active); } return CRM_Core_DAO::setFieldValue('CRM_Core_DAO_CustomGroup', $id, 'is_active', $is_active); }
/** * Process the user submitted custom data values. * * * @return void */ public function postProcess() { $params = $this->controller->exportValues($this->_name); //if the delete record button is clicked if ($this->_deleteButtonName) { if (!empty($_POST[$this->_deleteButtonName]) && $this->_recordId) { $filterParams['id'] = $this->_customGroupId; $returnProperties = array('is_multiple', 'table_name'); CRM_Core_DAO::commonRetrieve("CRM_Core_DAO_CustomGroup", $filterParams, $returnValues, $returnProperties); if (!empty($returnValues['is_multiple'])) { if ($tableName = CRM_Utils_Array::value('table_name', $returnValues)) { $sql = "DELETE FROM {$tableName} WHERE id = %1 AND entity_id = %2"; $sqlParams = array(1 => array($this->_recordId, 'Integer'), 2 => array($this->_id, 'Integer')); CRM_Core_DAO::executeQuery($sql, $sqlParams); CRM_Core_Session::setStatus(ts('Your record has been deleted.'), ts('Deleted'), 'success'); } } return; } } CRM_Utils_Hook::processProfile($this->_ufGroup['name']); if (!empty($params['image_URL'])) { CRM_Contact_BAO_Contact::processImageParams($params); } $greetingTypes = array('addressee' => 'addressee_id', 'email_greeting' => 'email_greeting_id', 'postal_greeting' => 'postal_greeting_id'); $details = array(); if ($this->_id) { $contactDetails = CRM_Contact_BAO_Contact::getHierContactDetails($this->_id, $greetingTypes); $details = $contactDetails[0][$this->_id]; } if (!(!empty($details['addressee_id']) || !empty($details['email_greeting_id']) || CRM_Utils_Array::value('postal_greeting_id', $details))) { $profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid); //Though Profile type is contact we need //Individual/Household/Organization for setting Greetings. if ($profileType == 'Contact') { $profileType = 'Individual'; //if we editing Household/Organization. if ($this->_id) { $profileType = CRM_Contact_BAO_Contact::getContactType($this->_id); } } if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType); } foreach ($greetingTypes as $key => $value) { if (!array_key_exists($key, $params)) { $params[$key] = CRM_Contact_BAO_Contact_Utils::defaultGreeting($profileType, $key); } } } $transaction = new CRM_Core_Transaction(); //used to send subscribe mail to the group which user want. //if the profile double option in is enabled $mailingType = array(); $result = NULL; foreach ($params as $name => $values) { if (substr($name, 0, 6) == 'email-') { $result['email'] = $values; } } //array of group id, subscribed by contact $contactGroup = array(); if (!empty($params['group']) && CRM_Core_BAO_UFGroup::isProfileDoubleOptin()) { $groupSubscribed = array(); if (!empty($result['email'])) { if ($this->_id) { $contactGroups = new CRM_Contact_DAO_GroupContact(); $contactGroups->contact_id = $this->_id; $contactGroups->status = 'Added'; $contactGroups->find(); $contactGroup = array(); while ($contactGroups->fetch()) { $contactGroup[] = $contactGroups->group_id; $groupSubscribed[$contactGroups->group_id] = 1; } } foreach ($params['group'] as $key => $val) { if (!$val) { unset($params['group'][$key]); continue; } $groupTypes = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $key, 'group_type', 'id'); $groupType = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($groupTypes, 1, -1)); //filter group of mailing type and unset it from params if (in_array(2, $groupType)) { //if group is already subscribed , ignore it $groupExist = CRM_Utils_Array::key($key, $contactGroup); if (!isset($groupExist)) { $mailingType[] = $key; unset($params['group'][$key]); } } } } } $addToGroupId = CRM_Utils_Array::value('add_to_group_id', $this->_ufGroup); if (!empty($addToGroupId)) { //run same check whether group is a mailing list $groupTypes = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $addToGroupId, 'group_type', 'id'); $groupType = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($groupTypes, 1, -1)); //filter group of mailing type and unset it from params if (in_array(2, $groupType) && !empty($result['email']) && CRM_Core_BAO_UFGroup::isProfileAddToGroupDoubleOptin()) { if (!count($contactGroup)) { //array of group id, subscribed by contact $contactGroup = array(); if ($this->_id) { $contactGroups = new CRM_Contact_DAO_GroupContact(); $contactGroups->contact_id = $this->_id; $contactGroups->status = 'Added'; $contactGroups->find(); $contactGroup = array(); while ($contactGroups->fetch()) { $contactGroup[] = $contactGroups->group_id; $groupSubscribed[$contactGroups->group_id] = 1; } } } //if group is already subscribed , ignore it $groupExist = CRM_Utils_Array::key($addToGroupId, $contactGroup); if (!isset($groupExist)) { $mailingType[] = $addToGroupId; $addToGroupId = NULL; } } else { // since we are directly adding contact to group lets unset it from mailing if ($key = array_search($addToGroupId, $mailingType)) { unset($mailingType[$key]); } } } if ($this->_grid) { $params['group'] = $groupSubscribed; } // commenting below code, since we potentially // triggered maximum name field formatting cases during CRM-4430. // CRM-4343 // $params['preserveDBName'] = true; $profileFields = $this->_fields; if ($this->_mode & self::MODE_EDIT && $this->_activityId && $this->_isContactActivityProfile) { $profileFields = $activityParams = array(); foreach ($this->_fields as $fieldName => $field) { if (CRM_Utils_Array::value('field_type', $field) == 'Activity') { if (isset($params[$fieldName])) { $activityParams[$fieldName] = $params[$fieldName]; } if (isset($params['activity_date_time'])) { $activityParams['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']); } if (!empty($params[$fieldName]) && isset($params["{$fieldName}_id"])) { $activityParams[$fieldName] = $params["{$fieldName}_id"]; } } else { $profileFields[$fieldName] = $field; } } if (!empty($activityParams)) { $activityParams['version'] = 3; $activityParams['id'] = $this->_activityId; $activityParams['skipRecentView'] = TRUE; civicrm_api('Activity', 'create', $activityParams); } } if ($this->_multiRecord && $this->_recordId && $this->_multiRecordFields && $this->_recordExists) { $params['customRecordValues'][$this->_recordId] = array_keys($this->_multiRecordFields); } $this->_id = CRM_Contact_BAO_Contact::createProfileContact($params, $profileFields, $this->_id, $addToGroupId, $this->_gid, $this->_ctype, TRUE); //mailing type group if (!empty($mailingType)) { // we send in the contactID so we match the same groups and are exact, rather than relying on email // CRM-8710 CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($mailingType, $result, $this->_id, 'profile'); } $ufGroups = array(); if ($this->_gid) { $ufGroups[$this->_gid] = 1; } elseif ($this->_mode == self::MODE_REGISTER) { $ufGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup('User Registration'); } foreach ($ufGroups as $gId => $val) { if ($notify = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify')) { $values = CRM_Core_BAO_UFGroup::checkFieldsEmptyValues($gId, $this->_id, NULL); CRM_Core_BAO_UFGroup::commonSendMail($this->_id, $values); } } //create CMS user (if CMS user option is selected in profile) if (!empty($params['cms_create_account']) && $this->_mode == self::MODE_CREATE) { $params['contactID'] = $this->_id; if (!CRM_Core_BAO_CMSUser::create($params, $this->_mail)) { CRM_Core_Session::setStatus(ts('Your profile is not saved and Account is not created.'), ts('Profile Error'), 'error'); CRM_Core_Error::debug_log_message("Rolling back transaction as CMSUser Create failed in Profile_Form for contact " . $params['contactID']); $transaction->rollback(); return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/profile/create', 'reset=1&gid=' . $this->_gid)); } } $transaction->commit(); }
/** * global validation rules for the form * * @param array $fields posted values of the form * * @return array list of errors to be posted back to the form * @static * @access public */ static function formRule(&$fields, &$files, $self) { $is_required = CRM_Utils_Array::value('is_required', $fields, false); $is_registration = CRM_Utils_Array::value('is_registration', $fields, false); $is_view = CRM_Utils_Array::value('is_view', $fields, false); $in_selector = CRM_Utils_Array::value('in_selector', $fields, false); $is_searchable = CRM_Utils_Array::value('is_searchable', $fields, false); $visibility = CRM_Utils_Array::value('visibility', $fields, false); $is_active = CRM_Utils_Array::value('is_active', $fields, false); $errors = array(); if ($is_view && $is_registration) { $errors['is_registration'] = ts('View Only cannot be selected if this field is to be included on the registration form'); } if ($is_view && $is_required) { $errors['is_view'] = ts('A View Only field cannot be required'); } $fieldName = $fields['field_name'][0]; if (!$fieldName) { $errors['field_name'] = ts('Please select a field name'); } if ($in_selector && in_array($fieldName, array('Contribution', 'Participant', 'Membership'))) { $errors['in_selector'] = ts("'In Selector' cannot be checked for %1 fields.", array(1 => $fieldName)); } if (!empty($fields['field_id'])) { //get custom field id $customFieldId = explode('_', $fieldName); if ($customFieldId[0] == 'custom') { $customField =& new CRM_Core_DAO_CustomField(); $customField->id = $customFieldId[1]; $customField->find(true); if (!$customField->is_active && $is_active) { $errors['field_name'] = ts('Cannot set this field "Active" since the selected custom field is disabled.'); } } } //check profile is configured for double option process //adding group field, email field should be present in the group //fixed for issue CRM-2861 & CRM-4153 $config =& CRM_Core_Config::singleton(); if ($config->profileDoubleOptIn) { if ($fields['field_name'][1] == 'group') { require_once 'CRM/Core/BAO/UFField.php'; $dao =& new CRM_Core_BAO_UFField(); $dao->uf_group_id = $fields['group_id']; $dao->find(); $emailField = false; while ($dao->fetch()) { //check email field is present in the group if ($dao->field_name == 'email') { $emailField = true; } } if (!$emailField) { $disableSetting = "define( 'CIVICRM_PROFILE_DOUBLE_OPTIN' , 0 );"; $errors['field_name'] = ts('Your site is currently configured to require double-opt in when users join (subscribe) to Group(s) via a Profile form. In this mode, you need to include an Email field in a Profile BEFORE you can add the Group(s) field. This ensures that an opt-in confirmation email can be sent. Your site administrator can disable double opt-in by adding this line to the CiviCRM settings file: <em>%1</em>', array(1 => $disableSetting)); } } } //fix for CRM-3037 $fieldType = $fields['field_name'][0]; //get the group type. $groupType = CRM_Core_BAO_UFGroup::calculateGroupType($self->_gid, CRM_Utils_Array::value('field_id', $fields)); switch ($fieldType) { case 'Individual': if (in_array('Household', $groupType) || in_array('Organization', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Individual with combination of Household or Organization'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Household': if (in_array('Individual', $groupType) || in_array('Organization', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Household with combination of Individual or Organization'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Organization': if (in_array('Household', $groupType) || in_array('Individual', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Organization with combination of Household or Individual'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Participant': if (in_array('Membership', $groupType) || in_array('Contribution', $groupType) || in_array('Organization', $groupType) || in_array('Household', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Participant with combination of Membership or Contribution or Household or Organization'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Contribution': if (in_array('Participant', $groupType) || in_array('Membership', $groupType) || in_array('Organization', $groupType) || in_array('Household', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Contribution with combination of Membership or Participant or Household or Organization'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Membership': if (in_array('Participant', $groupType) || in_array('Contribution', $groupType) || in_array('Organization', $groupType) || in_array('Household', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Membership with combination of Participant or Contribution or Household or Organization'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; default: $profileType = CRM_Core_BAO_UFField::getProfileType($fields['group_id'], true, false, true); if (CRM_Contact_BAO_ContactType::isaSubType($fieldType)) { if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { if ($fieldType != $profileType) { $errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination of "%2".', array(1 => $fieldType, 2 => $profileType)); } } else { $basicType = CRM_Contact_BAO_ContactType::getBasicType($fieldType); if ($profileType && $profileType != $basicType && $profileType != 'Contact') { $errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination of "%2".', array(1 => $fieldType, 2 => $profileType)); } } } elseif ($fields['field_name'][1] == 'contact_sub_type' && !in_array($profileType, array('Individual', 'Household', 'Organization')) && !in_array($profileType, CRM_Contact_BAO_ContactType::subTypes())) { $errors['field_name'] = ts('Cannot add or update profile field Contact Subtype as profile type is not one of Individual, Household or Organization.'); } } return empty($errors) ? true : $errors; }
/** * update the is_active flag in the db * * @param int $id Id of the database record * @param boolean $is_active Value we want to set the is_active field * * @return Object DAO object on sucess, null otherwise * * @access public * @static */ static function setIsActive($id, $is_active) { require_once 'CRM/Core/BAO/UFField.php'; //enable-disable UFField CRM_Core_BAO_UFField::setUFField($id, $is_active); return CRM_Core_DAO::setFieldValue('CRM_Core_DAO_CustomField', $id, 'is_active', $is_active); }
/** * 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; }
/** * Class constructor. * * @param int $id * The contact id. * @param int $gid * The group id. * * @param $restrict * @param bool $skipPermission * @param null $profileIds * * @return \CRM_Profile_Page_Dynamic */ public function __construct($id, $gid, $restrict, $skipPermission = FALSE, $profileIds = NULL) { parent::__construct(); $this->_id = $id; $this->_gid = $gid; $this->_restrict = $restrict; $this->_skipPermission = $skipPermission; if (!array_key_exists('multiRecord', $_GET)) { $this->set('multiRecord', NULL); } if (!array_key_exists('recordId', $_GET)) { $this->set('recordId', NULL); } if (!array_key_exists('allFields', $_GET)) { $this->set('allFields', NULL); } //specifies the action being done on a multi record field $multiRecordAction = CRM_Utils_Request::retrieve('multiRecord', 'String', $this); $this->_multiRecord = !is_numeric($multiRecordAction) ? CRM_Core_Action::resolve($multiRecordAction) : $multiRecordAction; if ($this->_multiRecord) { $this->set('multiRecord', $this->_multiRecord); } if ($this->_multiRecord & CRM_Core_Action::VIEW) { $this->_recordId = CRM_Utils_Request::retrieve('recordId', 'Positive', $this); $this->_allFields = CRM_Utils_Request::retrieve('allFields', 'Integer', $this); } if ($profileIds) { $this->_profileIds = $profileIds; } else { $this->_profileIds = array($gid); } $this->_activityId = CRM_Utils_Request::retrieve('aid', 'Positive', $this, FALSE, 0, 'GET'); if (is_numeric($this->_activityId)) { $latestRevisionId = CRM_Activity_BAO_Activity::getLatestActivityId($this->_activityId); if ($latestRevisionId) { $this->_activityId = $latestRevisionId; } } $this->_isContactActivityProfile = CRM_Core_BAO_UFField::checkContactActivityProfileType($this->_gid); }
/** * Delete the Custom Field. * * @param object $field * The field object. */ public static function deleteField($field) { CRM_Utils_System::flushCache(); // first delete the custom option group and values associated with this field if ($field->option_group_id) { //check if option group is related to any other field, if //not delete the option group and related option values self::checkOptionGroup($field->option_group_id); } // next drop the column from the custom value table self::createField($field, 'delete'); $field->delete(); CRM_Core_BAO_UFField::delUFField($field->id); CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_CustomField'); }
/** * Delete uf field. * * @param array $params * * @throws API_Exception * * @return array */ function civicrm_api3_uf_field_delete($params) { $fieldId = $params['id']; $ufGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFField', $fieldId, 'uf_group_id'); if (!$ufGroupId) { throw new API_Exception('Invalid value for field_id.'); } $result = CRM_Core_BAO_UFField::del($fieldId); $fieldsType = CRM_Core_BAO_UFGroup::calculateGroupType($ufGroupId, TRUE); CRM_Core_BAO_UFGroup::updateGroupTypes($ufGroupId, $fieldsType); return civicrm_api3_create_success($result, $params); }
/** * Function to get profiles by type eg: pure Individual etc * * @param array $types associative array of types eg: types('Individual') * @param boolean $onlyPure true if only pure profiles are required * * @return array $profiles associative array of profiles * @static * @access public */ static function getProfiles($types, $onlyPure = false) { require_once "CRM/Core/BAO/UFField.php"; $profiles = array(); $ufGroups = CRM_Core_PseudoConstant::ufgroup(); require_once 'CRM/Utils/Hook.php'; CRM_Utils_Hook::aclGroup(CRM_Core_Permission::ADMIN, null, 'civicrm_uf_group', $ufGroups, $ufGroups); foreach ($ufGroups as $id => $title) { $ptype = CRM_Core_BAO_UFField::getProfileType($id, false, $onlyPure); if (in_array($ptype, $types)) { $profiles[$id] = $title; } } return $profiles; }