示例#1
0
 /**
  * Process the form after the input has been submitted and validated.
  */
 public function postProcess()
 {
     $params = $this->exportValues();
     $ufGroupId = $this->get('ufGroupId');
     $notify = NULL;
     $inValidSubtypeCnt = 0;
     //send profile notification email if 'notify' field is set
     $notify = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $ufGroupId, 'notify');
     foreach ($params['field'] as $key => $value) {
         //CRM-5521
         //validate subtype before updating
         if (!empty($value['contact_sub_type']) && !CRM_Contact_BAO_ContactType::isAllowEdit($key)) {
             unset($value['contact_sub_type']);
             $inValidSubtypeCnt++;
         }
         $value['preserveDBName'] = $this->_preserveDefault;
         //parse street address, CRM-7768
         self::parseStreetAddress($value, $this);
         CRM_Contact_BAO_Contact::createProfileContact($value, $this->_fields, $key, NULL, $ufGroupId, NULL, TRUE);
         if ($notify) {
             $values = CRM_Core_BAO_UFGroup::checkFieldsEmptyValues($ufGroupId, $key, NULL);
             CRM_Core_BAO_UFGroup::commonSendMail($key, $values);
         }
     }
     CRM_Core_Session::setStatus('', ts("Updates Saved"), 'success');
     if ($inValidSubtypeCnt) {
         CRM_Core_Session::setStatus(ts('Contact Subtype field of 1 contact has not been updated.', array('plural' => 'Contact Subtype field of %count contacts has not been updated.', 'count' => $inValidSubtypeCnt)), ts('Invalid Subtype'));
     }
 }
 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     $params = $this->exportValues();
     $ufGroupId = $this->get('ufGroupId');
     $notify = NULL;
     $inValidSubtypeCnt = 0;
     //send profile notification email if 'notify' field is set
     $notify = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $ufGroupId, 'notify');
     foreach ($params['field'] as $key => $value) {
         //CRM-5521
         //validate subtype before updating
         if (CRM_Utils_Array::value('contact_sub_type', $value) && !CRM_Contact_BAO_ContactType::isAllowEdit($key)) {
             unset($value['contact_sub_type']);
             $inValidSubtypeCnt++;
         }
         $value['preserveDBName'] = $this->_preserveDefault;
         //parse street address, CRM-7768
         self::parseStreetAddress($value, $this);
         CRM_Contact_BAO_Contact::createProfileContact($value, $this->_fields, $key, NULL, $ufGroupId);
         if ($notify) {
             $values = CRM_Core_BAO_UFGroup::checkFieldsEmptyValues($ufGroupId, $key, NULL);
             CRM_Core_BAO_UFGroup::commonSendMail($key, $values);
         }
     }
     $statusMsg = ts("Your updates have been saved.");
     if ($inValidSubtypeCnt) {
         $statusMsg .= ' ' . ts('Contact SubType field of %1 number of contact(s) has not been updated.', array(1 => $inValidSubtypeCnt));
     }
     CRM_Core_Session::setStatus("{$statusMsg}");
 }
示例#3
0
 /**
  * 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();
 }
 /**
  * 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);
         }
     }
 }
示例#5
0
文件: Form.php 项目: ksecor/civicrm
 /**
  * Process the user submitted custom data values.
  *
  * @access public
  * @return void
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     if ($this->_mode == self::MODE_REGISTER) {
         require_once 'CRM/Core/BAO/Address.php';
         CRM_Core_BAO_Address::setOverwrite(false);
     }
     require_once 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     //used to send subcribe mail to the group which user want.
     //if the profile double option in is enabled
     $mailingType = array();
     $config =& CRM_Core_Config::singleton();
     if ($config->profileDoubleOptIn && CRM_Utils_Array::value('group', $params)) {
         $result = null;
         foreach ($params as $name => $values) {
             if (substr($name, 0, 6) == 'email-') {
                 $result['email'] = $values;
             }
         }
         $groupSubscribed = array();
         if (CRM_Utils_Array::value('email', $result)) {
             require_once 'CRM/Contact/DAO/Group.php';
             //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;
                 }
             }
             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_BAO_CustomOption::VALUE_SEPERATOR, 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]);
                     }
                 }
             }
         }
     }
     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;
     $this->_id = CRM_Contact_BAO_Contact::createProfileContact($params, $this->_fields, $this->_id, $this->_addToGroupID, $this->_gid, $this->_ctype, true);
     //mailing type group
     if (!empty($mailingType)) {
         require_once 'CRM/Mailing/Event/BAO/Subscribe.php';
         CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($mailingType, $result);
     }
     require_once 'CRM/Core/BAO/UFGroup.php';
     $ufGroups = array();
     if ($this->_gid) {
         $ufGroups[$this->_gid] = 1;
     } else {
         if ($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 (CRM_Utils_Array::value('cms_create_account', $params) && $this->_mode == self::MODE_CREATE) {
         $params['contactID'] = $this->_id;
         require_once "CRM/Core/BAO/CMSUser.php";
         if (!CRM_Core_BAO_CMSUser::create($params, $this->_mail)) {
             CRM_Core_Session::setStatus(ts('Your profile is not saved and Account is not created.'));
             $transaction->rollback();
             return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/profile/create', 'reset=1&gid=' . $this->_gid));
         }
     }
     $transaction->commit();
 }
示例#6
0
 /**
  * Function to send the emails
  * 
  * @param int     $contactID         contact id 
  * @param array   $values            associated array of fields
  * @param boolean $isTest            if in test mode
  * @param boolean $returnMessageText return the message text instead of sending the mail
  *
  * @return void
  * @access public
  * @static
  */
 static function sendMail($contactID, &$values, $isTest = false, $returnMessageText = false)
 {
     require_once "CRM/Core/BAO/UFField.php";
     $gIds = array();
     $params = array();
     if (isset($values['custom_pre_id'])) {
         $preProfileType = CRM_Core_BAO_UFField::getProfileType($values['custom_pre_id']);
         if ($preProfileType == 'Membership' && CRM_Utils_Array::value('membership_id', $values)) {
             $params['custom_pre_id'] = array(array('membership_id', '=', $values['membership_id'], 0, 0));
         } else {
             if ($preProfileType == 'Contribution' && CRM_Utils_Array::value('contribution_id', $values)) {
                 $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' && CRM_Utils_Array::value('membership_id', $values)) {
             $params['custom_post_id'] = array(array('membership_id', '=', $values['membership_id'], 0, 0));
         } else {
             if ($postProfileType == 'Contribution' && CRM_Utils_Array::value('contribution_id', $values)) {
                 $params['custom_post_id'] = array(array('contribution_id', '=', $values['contribution_id'], 0, 0));
             }
         }
         $gIds['custom_post_id'] = $values['custom_post_id'];
     }
     //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) {
         //send notification email if field values are set (CRM-1941)
         require_once 'CRM/Core/BAO/UFGroup.php';
         foreach ($gIds as $key => $gId) {
             $email = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify');
             if ($email) {
                 $val = CRM_Core_BAO_UFGroup::checkFieldsEmptyValues($gId, $contactID, $params[$key]);
                 CRM_Core_BAO_UFGroup::commonSendMail($contactID, $val);
             }
         }
     }
     if (CRM_Utils_Array::value('is_email_receipt', $values) || CRM_Utils_Array::value('onbehalf_dupe_alert', $values)) {
         $template =& CRM_Core_Smarty::singleton();
         // get the billing location type
         if (!array_key_exists('related_contact', $values)) {
             $locationTypes =& CRM_Core_PseudoConstant::locationType();
             $billingLocationTypeId = array_search('Billing', $locationTypes);
         } else {
             // presence of related contact implies onbehalf of org case,
             // where location type is set to default.
             require_once 'CRM/Core/BAO/LocationType.php';
             $locType = CRM_Core_BAO_LocationType::getDefault();
             $billingLocationTypeId = $locType->id;
         }
         require_once 'CRM/Contact/BAO/Contact/Location.php';
         if (!array_key_exists('related_contact', $values)) {
             list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID, false, $billingLocationTypeId);
         } else {
             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.
         require_once 'CRM/Core/BAO/UFGroup.php';
         $userID = $contactID;
         if ($preID = CRM_Utils_Array::value('custom_pre_id', $values)) {
             if (CRM_Utils_Array::value('related_contact', $values)) {
                 $preProfileTypes = CRM_Core_BAO_UFGroup::profileGroups($preID);
                 if (in_array('Individual', $preProfileTypes)) {
                     //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 (CRM_Utils_Array::value('related_contact', $values)) {
                 $postProfileTypes = CRM_Core_BAO_UFGroup::profileGroups($postID);
                 if (in_array('Individual', $postProfileTypes)) {
                     //Take Individual contact ID
                     $userID = CRM_Utils_Array::value('related_contact', $values);
                 }
             }
             self::buildCustomDisplay($postID, 'customPost', $userID, $template, $params['custom_post_id']);
         }
         // set email in the template here
         $tplParams = array('email' => $email, 'receiptFromEmail' => $values['receipt_from_email'], 'contactID' => $contactID, 'contributionID' => $values['contribution_id'], 'membershipID' => CRM_Utils_Array::value('membership_id', $values), 'lineItem' => CRM_Utils_Array::value('lineItem', $values), 'priceSetID' => CRM_Utils_Array::value('priceSetID', $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}>";
             $values['cc_receipt'] = CRM_Utils_Array::value('cc_receipt', $values) ? $values['cc_receipt'] . ',' . $ccMailId : $ccMailId;
             // reset primary-email in the template
             $tplParams['email'] = $ccEmail;
             $tplParams['onBehalfName'] = $displayName;
             $tplParams['onBehalfEmail'] = $email;
         }
         $sendTemplateParams = array('groupName' => 'msg_tpl_workflow_contribution', 'valueName' => 'contribution_receipt', 'contactId' => $contactID, 'tplParams' => $tplParams, 'isTest' => $isTest);
         require_once 'CRM/Core/BAO/MessageTemplates.php';
         if ($returnMessageText) {
             list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate($sendTemplateParams);
             return array('subject' => $subject, 'body' => $message, 'to' => $displayName);
         }
         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);
             list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate($sendTemplateParams);
         }
         // send duplicate alert, if dupe match found during on-behalf-of processing.
         if (CRM_Utils_Array::value('onbehalf_dupe_alert', $values)) {
             $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'] = $values['receipt_from_email'];
             $sendTemplateParams['tplParams']['onBehalfID'] = $contactID;
             $sendTemplateParams['tplParams']['receiptMessage'] = $message;
             CRM_Core_BAO_MessageTemplates::sendTemplate($sendTemplateParams);
         }
     }
 }
示例#7
0
文件: Batch.php 项目: ksecor/civicrm
 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     $params = $this->exportValues();
     $ufGroupId = $this->get('ufGroupId');
     $notify = null;
     //send profile notification email if 'notify' field is set
     $notify = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $ufGroupId, 'notify');
     foreach ($params['field'] as $key => $value) {
         CRM_Contact_BAO_Contact::createProfileContact($value, $this->_fields, $key, null, $ufGroupId);
         if ($notify) {
             $values = CRM_Core_BAO_UFGroup::checkFieldsEmptyValues($ufGroupId, $key, null);
             CRM_Core_BAO_UFGroup::commonSendMail($key, $values);
         }
     }
     CRM_Core_Session::setStatus("Your updates have been saved.");
 }
示例#8
0
 /**
  * Process the user submitted custom data values.
  *
  * @access public
  * @return void
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     if (CRM_Utils_Array::value('image_URL', $params)) {
         CRM_Contact_BAO_Contact::processImageParams($params);
     }
     $greetingTypes = array('addressee' => 'addressee_id', 'email_greeting' => 'email_greeting_id', 'postal_greeting' => 'postal_greeting_id');
     if ($this->_id) {
         $contactDetails = CRM_Contact_BAO_Contact::getHierContactDetails($this->_id, $greetingTypes);
         $details = $contactDetails[0][$this->_id];
     }
     if (!(CRM_Utils_Array::value('addressee_id', $details) || CRM_Utils_Array::value('email_greeting_id', $details) || 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);
         }
         $contactTypeFilters = array(1 => 'Individual', 2 => 'Household', 3 => 'Organization');
         $filter = CRM_Utils_Array::key($profileType, $contactTypeFilters);
         if ($filter) {
             foreach ($greetingTypes as $key => $value) {
                 if (!array_key_exists($key, $params)) {
                     $defaultGreetingTypeId = CRM_Core_OptionGroup::values($key, null, null, null, "AND is_default =1\n                                                                               AND (filter = \n                                                                               {$filter} OR \n                                                                               filter = 0 )", 'value');
                     $params[$key] = key($defaultGreetingTypeId);
                 }
             }
         }
         if ($profileType == 'Organization') {
             unset($params['email_greeting'], $params['postal_greeting']);
         }
     }
     if ($this->_mode == self::MODE_REGISTER) {
         require_once 'CRM/Core/BAO/Address.php';
         CRM_Core_BAO_Address::setOverwrite(false);
     }
     require_once 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     //used to send subcribe mail to the group which user want.
     //if the profile double option in is enabled
     $mailingType = array();
     $config = CRM_Core_Config::singleton();
     if ($config->profileDoubleOptIn && CRM_Utils_Array::value('group', $params)) {
         $result = null;
         foreach ($params as $name => $values) {
             if (substr($name, 0, 6) == 'email-') {
                 $result['email'] = $values;
             }
         }
         $groupSubscribed = array();
         if (CRM_Utils_Array::value('email', $result)) {
             require_once 'CRM/Contact/DAO/Group.php';
             //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;
                 }
             }
             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_BAO_CustomOption::VALUE_SEPERATOR, 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]);
                     }
                 }
             }
         }
     }
     if (CRM_Utils_Array::value('add_to_group', $params)) {
         $addToGroupId = $params['add_to_group'];
         // 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;
     $this->_id = CRM_Contact_BAO_Contact::createProfileContact($params, $this->_fields, $this->_id, $this->_addToGroupID, $this->_gid, $this->_ctype, true);
     //mailing type group
     if (!empty($mailingType)) {
         require_once 'CRM/Mailing/Event/BAO/Subscribe.php';
         CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($mailingType, $result);
     }
     require_once 'CRM/Core/BAO/UFGroup.php';
     $ufGroups = array();
     if ($this->_gid) {
         $ufGroups[$this->_gid] = 1;
     } else {
         if ($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 (CRM_Utils_Array::value('cms_create_account', $params) && $this->_mode == self::MODE_CREATE) {
         $params['contactID'] = $this->_id;
         require_once "CRM/Core/BAO/CMSUser.php";
         if (!CRM_Core_BAO_CMSUser::create($params, $this->_mail)) {
             CRM_Core_Session::setStatus(ts('Your profile is not saved and Account is not created.'));
             $transaction->rollback();
             return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/profile/create', 'reset=1&gid=' . $this->_gid));
         }
     }
     $transaction->commit();
 }