/** * Confirm a pending subscription * * @param int $contact_id The id of the contact * @param int $subscribe_id The id of the subscription event * @param string $hash The hash * * @return boolean True on success * @access public * @static */ public static function confirm($contact_id, $subscribe_id, $hash) { $se =& CRM_Mailing_Event_BAO_Subscribe::verify($contact_id, $subscribe_id, $hash); if (!$se) { return FALSE; } // before we proceed lets just check if this contact is already 'Added' // if so, we should ignore this request and hence avoid sending multiple // emails - CRM-11157 $details = CRM_Contact_BAO_GroupContact::getMembershipDetail($contact_id, $se->group_id); if ($details && $details->status == 'Added') { // This contact is already subscribed // lets return the group title return CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $se->group_id, 'title'); } $transaction = new CRM_Core_Transaction(); $ce = new CRM_Mailing_Event_BAO_Confirm(); $ce->event_subscribe_id = $se->id; $ce->time_stamp = date('YmdHis'); $ce->save(); CRM_Contact_BAO_GroupContact::addContactsToGroup(array($contact_id), $se->group_id, 'Email', 'Added', $ce->id); $transaction->commit(); $config = CRM_Core_Config::singleton(); $domain = CRM_Core_BAO_Domain::getDomain(); list($domainEmailName, $_) = CRM_Core_BAO_Domain::getNameAndEmail(); list($display_name, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($se->contact_id); $group = new CRM_Contact_DAO_Group(); $group->id = $se->group_id; $group->find(TRUE); $component = new CRM_Mailing_BAO_Component(); $component->is_default = 1; $component->is_active = 1; $component->component_type = 'Welcome'; $component->find(TRUE); $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain(); $html = $component->body_html; if ($component->body_text) { $text = $component->body_text; } else { $text = CRM_Utils_String::htmlToText($component->body_html); } $bao = new CRM_Mailing_BAO_Mailing(); $bao->body_text = $text; $bao->body_html = $html; $tokens = $bao->getTokens(); $html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html']); $html = CRM_Utils_Token::replaceWelcomeTokens($html, $group->title, TRUE); $text = CRM_Utils_Token::replaceDomainTokens($text, $domain, FALSE, $tokens['text']); $text = CRM_Utils_Token::replaceWelcomeTokens($text, $group->title, FALSE); $mailParams = array('groupName' => 'Mailing Event ' . $component->component_type, 'subject' => $component->subject, 'from' => "\"{$domainEmailName}\" <do-not-reply@{$emailDomain}>", 'toEmail' => $email, 'toName' => $display_name, 'replyTo' => "do-not-reply@{$emailDomain}", 'returnPath' => "do-not-reply@{$emailDomain}", 'html' => $html, 'text' => $text); // send - ignore errors because the desired status change has already been successful $unused_result = CRM_Utils_Mail::send($mailParams); return $group->title; }
/** * Confirm email verification * * @param int $contact_id The id of the contact * @param int $subscribe_id The id of the subscription event * @param string $hash The hash * * @return boolean True on success * @access public * @static */ public static function confirm($contact_id, $subscribe_id, $hash, $activity_id, $petition_id) { $se = CRM_Mailing_Event_BAO_Subscribe::verify($contact_id, $subscribe_id, $hash); if (!$se) { return FALSE; } $transaction = new CRM_Core_Transaction(); $ce = new CRM_Mailing_Event_BAO_Confirm(); $ce->event_subscribe_id = $se->id; $ce->time_stamp = date('YmdHis'); $ce->save(); CRM_Contact_BAO_GroupContact::updateGroupMembershipStatus($contact_id, $se->group_id, 'Email', $ce->id); $bao = new CRM_Campaign_BAO_Petition(); $bao->confirmSignature($activity_id, $contact_id, $petition_id); }
/** * Confirm a pending subscription * * @param int $contact_id The id of the contact * @param int $subscribe_id The id of the subscription event * @param string $hash The hash * @return boolean True on success * @access public * @static */ function confirm($contact_id, $subscribe_id, $hash) { $se =& CRM_Mailing_Event_BAO_Subscribe::verify($contact_id, $subscribe_id, $hash); if (!$se) { return false; } CRM_Core_DAO::transaction('BEGIN'); $ce =& new CRM_Mailing_Event_BAO_Confirm(); $ce->event_subscribe_id = $se->id; $ce->time_stamp = date('YmdHis'); $ce->save(); CRM_Contact_BAO_GroupContact::updateGroupMembershipStatus($contact_id, $se->group_id, 'Email', $ce->id); CRM_Core_DAO::transaction('COMMIT'); $config =& CRM_Core_Config::singleton(); $domain =& CRM_Mailing_Event_BAO_Subscribe::getDomain($subscribe_id); list($display_name, $email) = CRM_Contact_BAO_Contact::getEmailDetails($se->contact_id); $group =& new CRM_Contact_DAO_Group(); $group->id = $se->group_id; $group->find(true); require_once 'CRM/Mailing/BAO/Component.php'; $component =& new CRM_Mailing_BAO_Component(); $component->domain_id = $domain->id; $component->is_default = 1; $component->is_active = 1; $component->component_type = 'Welcome'; $component->find(true); $headers = array('Subject' => $component->subject, 'From' => ts('"%1 Administrator" <do-not-reply@%2>', array(1 => $domain->name, 2 => $domain->email_domain)), 'To' => $email, 'Reply-To' => "do-not-reply@{$domain->email_domain}", 'Return-Path' => "do-not-reply@{$domain->email_domain}"); $html = $component->body_html; require_once 'CRM/Utils/Token.php'; $html = CRM_Utils_Token::replaceDomainTokens($html, $domain, true); $html = CRM_Utils_Token::replaceWelcomeTokens($html, $group->name, true); $text = $component->body_text; $text = CRM_Utils_Token::replaceDomainTokens($text, $domain, false); $text = CRM_Utils_Token::replaceWelcomeTokens($text, $group->name, false); $message =& new Mail_Mime("\n"); $message->setHTMLBody($html); $message->setTxtBody($text); $b = $message->get(); $h = $message->headers($headers); $mailer =& $config->getMailer(); PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('CRM_Mailing_BAO_Mailing', 'catchSMTP')); $mailer->send($email, $h, $b); CRM_Core_Error::setCallback(); return true; }
/** * Subscribe from mailing group * * @param array $params Associative array of property * name/value pairs to insert in new 'survey' * * @throws API_Exception * @return array api result array * {@getfields mailing_event_subscribe_create} * @access public */ function civicrm_api3_mailing_event_subscribe_create($params) { $email = $params['email']; $group_id = $params['group_id']; $contact_id = CRM_Utils_Array::value('contact_id', $params); $group = new CRM_Contact_DAO_Group(); $group->is_active = 1; $group->id = (int) $group_id; if (!$group->find(TRUE)) { throw new API_Exception('Invalid Group id'); } $subscribe = CRM_Mailing_Event_BAO_Subscribe::subscribe($group_id, $email, $contact_id); if ($subscribe !== NULL) { /* Ask the contact for confirmation */ $subscribe->send_confirm_request($email); $values = array(); $values[$subscribe->id]['contact_id'] = $subscribe->contact_id; $values[$subscribe->id]['subscribe_id'] = $subscribe->id; $values[$subscribe->id]['hash'] = $subscribe->hash; return civicrm_api3_create_success($values); } return civicrm_api3_create_error('Subscription failed'); }
/** * Update contact fields. * * @param int $contactID * @param array $params * @param array $fields * @param CRM_Core_Form $form * * @return int */ public static function updateContactFields($contactID, $params, $fields, &$form) { //add the contact to group, if add to group is selected for a //particular uf group // get the add to groups $addToGroups = array(); if (!empty($form->_fields)) { foreach ($form->_fields as $key => $value) { if (!empty($value['add_to_group_id'])) { $addToGroups[$value['add_to_group_id']] = $value['add_to_group_id']; } } } // check for profile double opt-in and get groups to be subscribed $subscribeGroupIds = CRM_Core_BAO_UFGroup::getDoubleOptInGroupIds($params, $contactID); foreach ($addToGroups as $k) { if (array_key_exists($k, $subscribeGroupIds)) { unset($addToGroups[$k]); } } // since we are directly adding contact to group lets unset it from mailing if (!empty($addToGroups)) { foreach ($addToGroups as $groupId) { if (isset($subscribeGroupIds[$groupId])) { unset($subscribeGroupIds[$groupId]); } } } if ($contactID) { $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'contact_type'); if (array_key_exists('contact_id', $params) && empty($params['contact_id'])) { // we unset this here because the downstream function ignores the contactID we give it // if it is set & it is difficult to understand the implications of 'fixing' this downstream // but if we are passing a contact id into this function it's reasonable to assume we don't // want it ignored unset($params['contact_id']); } $contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $contactID, $addToGroups, NULL, $ctype, TRUE); } else { foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) { if (!isset($params[$greeting . '_id'])) { $params[$greeting . '_id'] = CRM_Contact_BAO_Contact_Utils::defaultGreeting('Individual', $greeting); } } $contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, NULL, $addToGroups, NULL, NULL, TRUE); $form->set('contactID', $contactID); } //get email primary first if exist $subscribtionEmail = array('email' => CRM_Utils_Array::value('email-Primary', $params)); if (!$subscribtionEmail['email']) { $subscribtionEmail['email'] = CRM_Utils_Array::value("email-{$form->_bltID}", $params); } // subscribing contact to groups if (!empty($subscribeGroupIds) && $subscribtionEmail['email']) { CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($subscribeGroupIds, $subscribtionEmail, $contactID); } return $contactID; }
/** * function to update contact fields * * @return void * @access public */ public function updateContactFields($contactID, $params, $fields) { //add the contact to group, if add to group is selected for a //particular uf group // get the add to groups $addToGroups = array(); if (!empty($this->_fields)) { foreach ($this->_fields as $key => $value) { if (CRM_Utils_Array::value('add_to_group_id', $value)) { $addToGroups[$value['add_to_group_id']] = $value['add_to_group_id']; } } } // check for profile double opt-in and get groups to be subscribed $subscribeGroupIds = CRM_Core_BAO_UFGroup::getDoubleOptInGroupIds($params, $contactID); foreach ($addToGroups as $k) { if (array_key_exists($k, $subscribeGroupIds)) { unset($addToGroups[$k]); } } // since we are directly adding contact to group lets unset it from mailing if (!empty($addToGroups)) { foreach ($addToGroups as $groupId) { if (isset($subscribeGroupIds[$groupId])) { unset($subscribeGroupIds[$groupId]); } } } if ($contactID) { $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'contact_type'); $contactID =& CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $contactID, $addToGroups, NULL, $ctype, TRUE); } else { foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) { if (!isset($params[$greeting . '_id'])) { $params[$greeting . '_id'] = CRM_Contact_BAO_Contact_Utils::defaultGreeting('Individual', $greeting); } } $contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, NULL, $addToGroups, NULL, NULL, TRUE); $this->set('contactID', $contactID); } //get email primary first if exist $subscribtionEmail = array('email' => CRM_Utils_Array::value('email-Primary', $params)); if (!$subscribtionEmail['email']) { $subscribtionEmail['email'] = CRM_Utils_Array::value("email-{$this->_bltID}", $params); } // subscribing contact to groups if (!empty($subscribeGroupIds) && $subscribtionEmail['email']) { CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($subscribeGroupIds, $subscribtionEmail, $contactID); } return $contactID; }
/** * 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(); }
/** * * @return void */ public function postProcess() { $params = $this->controller->exportValues($this->_name); $groups = array(); if ($this->_groupID) { $groups[] = $this->_groupID; } else { foreach ($params as $name => $dontCare) { if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) { $groups[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN); } } } CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($groups, $params); }
/** * 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(); }
/** * Process the form * * @return void * @access public */ public function postProcess() { $config = CRM_Core_Config::singleton(); require_once 'CRM/Contact/BAO/Contact.php'; $contactID = $this->_userID; // add a description field at the very beginning $this->_params['description'] = ts('Online Contribution') . ': ' . ($this->_pcpInfo['title'] ? $this->_pcpInfo['title'] : $this->_values['title']); // also add accounting code $this->_params['accountingCode'] = CRM_Utils_Array::value('accountingCode', $this->_values); // fix currency ID $this->_params['currencyID'] = $config->defaultCurrency; $premiumParams = $membershipParams = $tempParams = $params = $this->_params; //carry payment processor id. if ($paymentProcessorId = CRM_Utils_Array::value('id', $this->_paymentProcessor)) { $this->_params['payment_processor_id'] = $paymentProcessorId; foreach (array('premiumParams', 'membershipParams', 'tempParams', 'params') as $p) { ${$p}['payment_processor_id'] = $paymentProcessorId; } } $now = date('YmdHis'); $fields = array(); if (CRM_Utils_Array::value('image_URL', $params)) { CRM_Contact_BAO_Contact::processImageParams($params); } // set email for primary location. $fields['email-Primary'] = 1; // don't create primary email address, just add it to billing location //$params["email-Primary"] = $params["email-{$this->_bltID}"]; // get the add to groups $addToGroups = array(); // now set the values for the billing location. foreach ($this->_fields as $name => $value) { $fields[$name] = 1; // get the add to groups for uf fields if (CRM_Utils_Array::value('add_to_group_id', $value)) { $addToGroups[$value['add_to_group_id']] = $value['add_to_group_id']; } } if (!array_key_exists('first_name', $fields)) { $nameFields = array('first_name', 'middle_name', 'last_name'); foreach ($nameFields as $name) { $fields[$name] = 1; if (array_key_exists("billing_{$name}", $params)) { $params[$name] = $params["billing_{$name}"]; $params['preserveDBName'] = true; } } } // billing email address $fields["email-{$this->_bltID}"] = 1; //unset the billing parameters if it is pay later mode //to avoid creation of billing location if ($params['is_pay_later']) { $billingFields = array('billing_first_name', 'billing_middle_name', 'billing_last_name', "billing_street_address-{$this->_bltID}", "billing_city-{$this->_bltID}", "billing_state_province-{$this->_bltID}", "billing_state_province_id-{$this->_bltID}", "billing_postal_code-{$this->_bltID}", "billing_country-{$this->_bltID}", "billing_country_id-{$this->_bltID}"); foreach ($billingFields as $value) { unset($params[$value]); unset($fields[$value]); } } // if onbehalf-of-organization contribution, take out // organization params in a separate variable, to make sure // normal behavior is continued. And use that variable to // process on-behalf-of functionality. if (CRM_Utils_Array::value('is_for_organization', $this->_values)) { $behalfOrganization = array(); foreach (array('organization_name', 'organization_id', 'org_option') as $fld) { if (array_key_exists($fld, $params)) { $behalfOrganization[$fld] = $params[$fld]; unset($params[$fld]); } } if (array_key_exists('onbehalf_location', $params) && is_array($params['onbehalf_location'])) { foreach ($params['onbehalf_location'] as $block => $vals) { $behalfOrganization[$block] = $vals; } unset($params['onbehalf_location']); } } // check for profile double opt-in and get groups to be subscribed require_once 'CRM/Core/BAO/UFGroup.php'; $subscribeGroupIds = CRM_Core_BAO_UFGroup::getDoubleOptInGroupIds($params, $contactID); // since we are directly adding contact to group lets unset it from mailing if (!empty($addToGroups)) { foreach ($addToGroups as $groupId) { if (isset($subscribeGroupIds[$groupId])) { unset($subscribeGroupIds[$groupId]); } } } foreach ($addToGroups as $k) { if (array_key_exists($k, $subscribeGroupIds)) { unset($addToGroups[$k]); } } if (!isset($contactID)) { require_once 'CRM/Dedupe/Finder.php'; $dedupeParams = CRM_Dedupe_Finder::formatParams($params, 'Individual'); $dedupeParams['check_permission'] = false; $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual'); // if we find more than one contact, use the first one $contact_id = CRM_Utils_Array::value(0, $ids); $contactID =& CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $contact_id, $addToGroups); $this->set('contactID', $contactID); } else { $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'contact_type'); $contactID =& CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $contactID, $addToGroups, null, $ctype); } //get email primary first if exist $subscribtionEmail = array('email' => CRM_Utils_Array::value('email-Primary', $params)); if (!$subscribtionEmail['email']) { $subscribtionEmail['email'] = CRM_Utils_Array::value("email-{$this->_bltID}", $params); } // subscribing contact to groups if (!empty($subscribeGroupIds) && $subscribtionEmail['email']) { require_once 'CRM/Mailing/Event/BAO/Subscribe.php'; CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($subscribeGroupIds, $subscribtionEmail, $contactID); } // If onbehalf-of-organization contribution / signup, add organization // and it's location. if (isset($params['is_for_organization']) && isset($behalfOrganization['organization_name'])) { self::processOnBehalfOrganization($behalfOrganization, $contactID, $this->_values, $this->_params); } // lets store the contactID in the session // for things like tell a friend $session = CRM_Core_Session::singleton(); if (!$session->get('userID')) { $session->set('transaction.userID', $contactID); } else { $session->set('transaction.userID', null); } // store the fact that this is a membership and membership type is selected $processMembership = false; if (CRM_Utils_Array::value('selectMembership', $membershipParams) && $membershipParams['selectMembership'] != 'no_thanks') { $processMembership = true; $this->assign('membership_assign', true); $this->set('membershipTypeID', $this->_params['selectMembership']); if ($this->_action & CRM_Core_Action::PREVIEW) { $membershipParams['is_test'] = 1; } if ($this->_params['is_pay_later']) { $membershipParams['is_pay_later'] = 1; } } if ($processMembership) { require_once 'CRM/Core/Payment/Form.php'; CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $membershipParams, true); // added new parameter for cms user contact id, needed to distinguish behaviour for on behalf of sign-ups if (isset($this->_params['related_contact'])) { $membershipParams['cms_contactID'] = $this->_params['related_contact']; } else { $membershipParams['cms_contactID'] = $contactID; } require_once 'CRM/Member/BAO/Membership.php'; CRM_Member_BAO_Membership::postProcessMembership($membershipParams, $contactID, $this, $premiumParams); } else { // at this point we've created a contact and stored its address etc // all the payment processors expect the name and address to be in the // so we copy stuff over to first_name etc. $paymentParams = $this->_params; $contributionTypeId = $this->_values['contribution_type_id']; require_once 'CRM/Contribute/BAO/Contribution/Utils.php'; CRM_Contribute_BAO_Contribution_Utils::processConfirm($this, $paymentParams, $premiumParams, $contactID, $contributionTypeId, 'contribution'); } }
/** * Send subscribe mail. * * @param array $groups * The list of group ids for subscribe. * @param array $params * The list of email. * @param int $contactId * Currently used during event registration/contribution. * Specifically to avoid linking group to wrong duplicate contact * during event registration. * @param string $context * * @return void */ public static function commonSubscribe(&$groups, &$params, $contactId = NULL, $context = NULL) { $contactGroups = CRM_Mailing_Event_BAO_Subscribe::getContactGroups($params['email'], $contactId); $group = array(); $success = NULL; foreach ($groups as $groupID) { $title = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $groupID, 'title'); if (array_key_exists($groupID, $contactGroups) && $contactGroups[$groupID]['status'] != 'Removed') { $group[$groupID]['title'] = $contactGroups[$groupID]['title']; $group[$groupID]['status'] = $contactGroups[$groupID]['status']; $status = ts('You are already subscribed in %1, your subscription is %2.', array(1 => $group[$groupID]['title'], 2 => ts($group[$groupID]['status']))); CRM_Utils_System::setUFMessage($status); continue; } $se = self::subscribe($groupID, $params['email'], $contactId, $context); if ($se !== NULL) { $success = TRUE; $groupAdded[] = $title; // Ask the contact for confirmation $se->send_confirm_request($params['email']); } else { $success = FALSE; $groupFailed[] = $title; } } if ($success) { $groupTitle = implode(', ', $groupAdded); CRM_Utils_System::setUFMessage(ts('Your subscription request has been submitted for %1. Check your inbox shortly for the confirmation email(s). If you do not see a confirmation email, please check your spam/junk mail folder.', array(1 => $groupTitle))); } elseif ($success === FALSE) { $groupTitle = implode(',', $groupFailed); CRM_Utils_System::setUFMessage(ts('We had a problem processing your subscription request for %1. You have tried to subscribe to a private group and/or we encountered a database error. Please contact the site administrator.', array(1 => $groupTitle))); } }
/** * takes an associative array and sends a thank you or email verification email * * @param array $params (reference ) an assoc array of name/value pairs * * @param $sendEmailMode * * @throws Exception * @return void @access public * @static */ public static function sendEmail($params, $sendEmailMode) { /* sendEmailMode * CRM_Campaign_Form_Petition_Signature::EMAIL_THANK * connected user via login/pwd - thank you * or dedupe contact matched who doesn't have a tag CIVICRM_TAG_UNCONFIRMED - thank you * or login using fb connect - thank you + click to add msg to fb wall * * CRM_Campaign_Form_Petition_Signature::EMAIL_CONFIRM * send a confirmation request email */ // check if the group defined by CIVICRM_PETITION_CONTACTS exists, else create it $petitionGroupName = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'petition_contacts', NULL, 'Petition Contacts'); $dao = new CRM_Contact_DAO_Group(); $dao->title = $petitionGroupName; if (!$dao->find(TRUE)) { $dao->is_active = 1; $dao->visibility = 'User and User Admin Only'; $dao->save(); } $group_id = $dao->id; // get petition info $petitionParams['id'] = $params['sid']; $petitionInfo = array(); CRM_Campaign_BAO_Survey::retrieve($petitionParams, $petitionInfo); if (empty($petitionInfo)) { CRM_Core_Error::fatal('Petition doesn\'t exist.'); } //get the default domain email address. list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail(); $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain(); $toName = CRM_Contact_BAO_Contact::displayName($params['contactId']); $replyTo = "do-not-reply@{$emailDomain}"; // set additional general message template params (custom tokens to use in email msg templates) // tokens then available in msg template as {$petition.title}, etc $petitionTokens['title'] = $petitionInfo['title']; $petitionTokens['petitionId'] = $params['sid']; $tplParams['petition'] = $petitionTokens; switch ($sendEmailMode) { case CRM_Campaign_Form_Petition_Signature::EMAIL_THANK: // add this contact to the CIVICRM_PETITION_CONTACTS group // Cannot pass parameter 1 by reference $p = array($params['contactId']); CRM_Contact_BAO_GroupContact::addContactsToGroup($p, $group_id, 'API'); if ($params['email-Primary']) { CRM_Core_BAO_MessageTemplate::sendTemplate(array('groupName' => 'msg_tpl_workflow_petition', 'valueName' => 'petition_sign', 'contactId' => $params['contactId'], 'tplParams' => $tplParams, 'from' => "\"{$domainEmailName}\" <{$domainEmailAddress}>", 'toName' => $toName, 'toEmail' => $params['email-Primary'], 'replyTo' => $replyTo, 'petitionId' => $params['sid'], 'petitionTitle' => $petitionInfo['title'])); } break; case CRM_Campaign_Form_Petition_Signature::EMAIL_CONFIRM: // create mailing event subscription record for this contact // this will allow using a hash key to confirm email address by sending a url link $se = CRM_Mailing_Event_BAO_Subscribe::subscribe($group_id, $params['email-Primary'], $params['contactId'], 'profile'); // require_once 'CRM/Core/BAO/Domain.php'; // $domain = CRM_Core_BAO_Domain::getDomain(); $config = CRM_Core_Config::singleton(); $localpart = CRM_Core_BAO_MailSettings::defaultLocalpart(); $replyTo = implode($config->verpSeparator, array($localpart . 'c', $se->contact_id, $se->id, $se->hash)) . "@{$emailDomain}"; $confirmUrl = CRM_Utils_System::url('civicrm/petition/confirm', "reset=1&cid={$se->contact_id}&sid={$se->id}&h={$se->hash}&a={$params['activityId']}&p={$params['sid']}", TRUE); $confirmUrlPlainText = CRM_Utils_System::url('civicrm/petition/confirm', "reset=1&cid={$se->contact_id}&sid={$se->id}&h={$se->hash}&a={$params['activityId']}&p={$params['sid']}", TRUE, NULL, FALSE); // set email specific message template params and assign to tplParams $petitionTokens['confirmUrl'] = $confirmUrl; $petitionTokens['confirmUrlPlainText'] = $confirmUrlPlainText; $tplParams['petition'] = $petitionTokens; if ($params['email-Primary']) { CRM_Core_BAO_MessageTemplate::sendTemplate(array('groupName' => 'msg_tpl_workflow_petition', 'valueName' => 'petition_confirmation_needed', 'contactId' => $params['contactId'], 'tplParams' => $tplParams, 'from' => "\"{$domainEmailName}\" <{$domainEmailAddress}>", 'toName' => $toName, 'toEmail' => $params['email-Primary'], 'replyTo' => $replyTo, 'petitionId' => $params['sid'], 'petitionTitle' => $petitionInfo['title'], 'confirmUrl' => $confirmUrl)); } break; } }
/** * Confirm a pending subscription * * @param int $contact_id The id of the contact * @param int $subscribe_id The id of the subscription event * @param string $hash The hash * @return boolean True on success * @access public * @static */ public static function confirm($contact_id, $subscribe_id, $hash) { require_once 'CRM/Mailing/Event/BAO/Subscribe.php'; $se =& CRM_Mailing_Event_BAO_Subscribe::verify($contact_id, $subscribe_id, $hash); if (!$se) { return false; } require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $ce =& new CRM_Mailing_Event_BAO_Confirm(); $ce->event_subscribe_id = $se->id; $ce->time_stamp = date('YmdHis'); $ce->save(); require_once 'CRM/Contact/BAO/GroupContact.php'; CRM_Contact_BAO_GroupContact::updateGroupMembershipStatus($contact_id, $se->group_id, 'Email', $ce->id); $transaction->commit(); $config =& CRM_Core_Config::singleton(); require_once 'CRM/Core/BAO/Domain.php'; $domain =& CRM_Core_BAO_Domain::getDomain(); list($domainEmailName, $_) = CRM_Core_BAO_Domain::getNameAndEmail(); require_once 'CRM/Contact/BAO/Contact/Location.php'; list($display_name, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($se->contact_id); require_once 'CRM/Contact/DAO/Group.php'; $group =& new CRM_Contact_DAO_Group(); $group->id = $se->group_id; $group->find(true); require_once 'CRM/Mailing/BAO/Component.php'; $component =& new CRM_Mailing_BAO_Component(); $component->is_default = 1; $component->is_active = 1; $component->component_type = 'Welcome'; $component->find(true); require_once 'CRM/Core/BAO/MailSettings.php'; $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain(); $headers = array('Subject' => $component->subject, 'From' => "\"{$domainEmailName}\" <do-not-reply@{$emailDomain}>", 'To' => $email, 'Reply-To' => "do-not-reply@{$emailDomain}", 'Return-Path' => "do-not-reply@{$emailDomain}"); $html = $component->body_html; if ($component->body_text) { $text = $component->body_text; } else { $text = CRM_Utils_String::htmlToText($component->body_html); } require_once 'CRM/Mailing/BAO/Mailing.php'; $bao =& new CRM_Mailing_BAO_Mailing(); $bao->body_text = $text; $bao->body_html = $html; $tokens = $bao->getTokens(); require_once 'CRM/Utils/Token.php'; $html = CRM_Utils_Token::replaceDomainTokens($html, $domain, true, $tokens['html']); $html = CRM_Utils_Token::replaceWelcomeTokens($html, $group->title, true); $text = CRM_Utils_Token::replaceDomainTokens($text, $domain, false, $tokens['text']); $text = CRM_Utils_Token::replaceWelcomeTokens($text, $group->title, false); // we need to wrap Mail_mime because PEAR is apparently unable to fix // a six-year-old bug (PEAR bug #30) in Mail_mime::_encodeHeaders() // this fixes CRM-5466 require_once 'CRM/Utils/Mail/FixedMailMIME.php'; $message =& new CRM_Utils_Mail_FixedMailMIME("\n"); $message->setHTMLBody($html); $message->setTxtBody($text); $b =& CRM_Utils_Mail::setMimeParams($message); $h =& $message->headers($headers); $mailer =& $config->getMailer(); require_once 'CRM/Mailing/BAO/Mailing.php'; PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('CRM_Core_Error', 'nullHandler')); if (is_object($mailer)) { $mailer->send($email, $h, $b); CRM_Core_Error::setCallback(); } return $group->title; }
/** * Handle a subscription event * * @param string $email The email address to subscribe * @param int $domain_id The domain of the subscription * @param int $group_id The group of the subscription * @return boolean */ function crm_mailer_event_subscribe($email, $domain_id, $group_id) { $se =& CRM_Mailing_Event_BAO_Subscribe::subscribe($domain_id, $group_id, $email); if ($se !== null) { /* Ask the contact for confirmation */ $se->send_confirm_request($email); return true; } return false; }
/** * Confirm email verification * * @param int $contact_id The id of the contact * @param int $subscribe_id The id of the subscription event * @param string $hash The hash * @return boolean True on success * @access public * @static */ public static function confirm($contact_id, $subscribe_id, $hash, $activity_id, $petition_id) { require_once 'CRM/Mailing/Event/BAO/Subscribe.php'; $se =& CRM_Mailing_Event_BAO_Subscribe::verify($contact_id, $subscribe_id, $hash); if (!$se) { return false; } require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $ce = new CRM_Mailing_Event_BAO_Confirm(); $ce->event_subscribe_id = $se->id; $ce->time_stamp = date('YmdHis'); $ce->save(); require_once 'CRM/Contact/BAO/GroupContact.php'; CRM_Contact_BAO_GroupContact::updateGroupMembershipStatus($contact_id, $se->group_id, 'Email', $ce->id); require_once 'CRM/Campaign/BAO/Petition.php'; $bao = new CRM_Campaign_BAO_Petition(); $bao->confirmSignature($activity_id, $contact_id, $petition_id); }
/** * function to update contact fields * * @return void * @access public */ public function updateContactFields($contactID, $params, $fields) { //add the contact to group, if add to group is selected for a //particular uf group // get the add to groups $addToGroups = array(); if (!empty($this->_fields)) { foreach ($this->_fields as $key => $value) { if (CRM_Utils_Array::value('add_to_group_id', $value)) { $addToGroups[$value['add_to_group_id']] = $value['add_to_group_id']; } } } // check for profile double opt-in and get groups to be subscribed require_once 'CRM/Core/BAO/UFGroup.php'; $subscribeGroupIds = CRM_Core_BAO_UFGroup::getDoubleOptInGroupIds($params, $contactID); foreach ($addToGroups as $k) { if (array_key_exists($k, $subscribeGroupIds)) { unset($addToGroups[$k]); } } // since we are directly adding contact to group lets unset it from mailing if (!empty($addToGroups)) { foreach ($addToGroups as $groupId) { if (isset($subscribeGroupIds[$groupId])) { unset($subscribeGroupIds[$groupId]); } } } require_once "CRM/Contact/BAO/Contact.php"; if ($contactID) { $ctype = CRM_Core_DAO::getFieldValue("CRM_Contact_DAO_Contact", $contactID, "contact_type"); $contactID =& CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $contactID, $addToGroups, null, $ctype); } else { $contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, null, $addToGroups); $this->set('contactID', $contactID); } //get email primary first if exist $subscribtionEmail = array('email' => CRM_Utils_Array::value('email-Primary', $params)); if (!$subscribtionEmail['email']) { $subscribtionEmail['email'] = CRM_Utils_Array::value("email-{$this->_bltID}", $params); } // subscribing contact to groups if (!empty($subscribeGroupIds) && $subscribtionEmail['email']) { require_once 'CRM/Mailing/Event/BAO/Subscribe.php'; CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($subscribeGroupIds, $subscribtionEmail, $contactID); } return $contactID; }
/** * Get the domain object given a subscribe event * * @param int $subscribe_id ID of the subscribe event * @return object $domain The domain owning the event * @access public * @static */ function &getDomain($subscribe_id) { $dao =& new CRM_Core_Dao(); $subscribe = CRM_Mailing_Event_BAO_Subscribe::getTableName(); require_once 'CRM/Contact/BAO/Group.php'; $group = CRM_Contact_BAO_Group::getTableName(); $dao->query("SELECT {$group}.domain_id as domain_id\n FROM {$group}\n INNER JOIN {$subscribe}\n ON {$subscribe}.group_id = {$group}.id\n WHERE {$subscribe}.id = " . CRM_Utils_Type::escape($subscribe_id, 'Integer')); $dao->fetch(); if (empty($dao->domain_id)) { return null; } require_once 'CRM/Core/BAO/Domain.php'; return CRM_Core_BAO_Domain::getDomainById($dao->domain_id); }
/** * 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(); }
/** * Handle a subscription event * * @param array $params * * @return array */ function civicrm_mailer_event_subscribe($params) { $errors = _civicrm_mailer_check_params($params, array('email', 'group_id')); if (!empty($errors)) { return $errors; } $email = $params['email']; $group_id = $params['group_id']; $contact_id = CRM_Utils_Array::value('contact_id', $params); $group = new CRM_Contact_DAO_Group(); $group->is_active = 1; $group->id = (int) $group_id; if (!$group->find(TRUE)) { return civicrm_create_error(ts('Invalid Group id')); } $subscribe = CRM_Mailing_Event_BAO_Subscribe::subscribe($group_id, $email, $contact_id); if ($subscribe !== NULL) { /* Ask the contact for confirmation */ $subscribe->send_confirm_request($email); $values = array(); $values['contact_id'] = $subscribe->contact_id; $values['subscribe_id'] = $subscribe->id; $values['hash'] = $subscribe->hash; $values['is_error'] = 0; return $values; } return civicrm_create_error(ts('Subscription failed')); }
/** * Process the form * * @return void * @access public */ public function postProcess() { $config = CRM_Core_Config::singleton(); $contactID = $this->getContactID(); // add a description field at the very beginning $this->_params['description'] = ts('Online Contribution') . ': ' . ($this->_pcpInfo['title'] ? $this->_pcpInfo['title'] : $this->_values['title']); // also add accounting code $this->_params['accountingCode'] = CRM_Utils_Array::value('accountingCode', $this->_values); // fix currency ID $this->_params['currencyID'] = $config->defaultCurrency; $premiumParams = $membershipParams = $tempParams = $params = $this->_params; //carry payment processor id. if ($paymentProcessorId = CRM_Utils_Array::value('id', $this->_paymentProcessor)) { $this->_params['payment_processor_id'] = $paymentProcessorId; foreach (array('premiumParams', 'membershipParams', 'tempParams', 'params') as $p) { ${$p}['payment_processor_id'] = $paymentProcessorId; } } $fields = array(); if (!empty($params['image_URL'])) { CRM_Contact_BAO_Contact::processImageParams($params); } // set email for primary location. $fields['email-Primary'] = 1; // get the add to groups $addToGroups = array(); // now set the values for the billing location. foreach ($this->_fields as $name => $value) { $fields[$name] = 1; // get the add to groups for uf fields if (!empty($value['add_to_group_id'])) { $addToGroups[$value['add_to_group_id']] = $value['add_to_group_id']; } } if (!array_key_exists('first_name', $fields)) { $nameFields = array('first_name', 'middle_name', 'last_name'); foreach ($nameFields as $name) { $fields[$name] = 1; if (array_key_exists("billing_{$name}", $params)) { $params[$name] = $params["billing_{$name}"]; $params['preserveDBName'] = TRUE; } } } // billing email address $fields["email-{$this->_bltID}"] = 1; //unset the billing parameters if it is pay later mode //to avoid creation of billing location if ($params['is_pay_later']) { $billingFields = array('billing_first_name', 'billing_middle_name', 'billing_last_name', "billing_street_address-{$this->_bltID}", "billing_city-{$this->_bltID}", "billing_state_province-{$this->_bltID}", "billing_state_province_id-{$this->_bltID}", "billing_postal_code-{$this->_bltID}", "billing_country-{$this->_bltID}", "billing_country_id-{$this->_bltID}"); foreach ($billingFields as $value) { unset($params[$value]); unset($fields[$value]); } } // if onbehalf-of-organization contribution, take out // organization params in a separate variable, to make sure // normal behavior is continued. And use that variable to // process on-behalf-of functionality. if (!empty($this->_params['hidden_onbehalf_profile'])) { $behalfOrganization = array(); $orgFields = array('organization_name', 'organization_id', 'org_option'); foreach ($orgFields as $fld) { if (array_key_exists($fld, $params)) { $behalfOrganization[$fld] = $params[$fld]; unset($params[$fld]); } } if (is_array($params['onbehalf']) && !empty($params['onbehalf'])) { foreach ($params['onbehalf'] as $fld => $values) { if (strstr($fld, 'custom_')) { $behalfOrganization[$fld] = $values; } elseif (!strstr($fld, '-')) { if (in_array($fld, array('contribution_campaign_id', 'member_campaign_id'))) { $fld = 'campaign_id'; } else { $behalfOrganization[$fld] = $values; } $this->_params[$fld] = $values; } } } if (array_key_exists('onbehalf_location', $params) && is_array($params['onbehalf_location'])) { foreach ($params['onbehalf_location'] as $block => $vals) { //fix for custom data (of type checkbox, multi-select) if (substr($block, 0, 7) == 'custom_') { continue; } // fix the index of block elements if (is_array($vals)) { foreach ($vals as $key => $val) { //dont adjust the index of address block as //it's index is WRT to location type $newKey = $block == 'address' ? $key : ++$key; $behalfOrganization[$block][$newKey] = $val; } } } unset($params['onbehalf_location']); } if (!empty($params['onbehalf[image_URL]'])) { $behalfOrganization['image_URL'] = $params['onbehalf[image_URL]']; } } // check for profile double opt-in and get groups to be subscribed $subscribeGroupIds = CRM_Core_BAO_UFGroup::getDoubleOptInGroupIds($params, $contactID); // since we are directly adding contact to group lets unset it from mailing if (!empty($addToGroups)) { foreach ($addToGroups as $groupId) { if (isset($subscribeGroupIds[$groupId])) { unset($subscribeGroupIds[$groupId]); } } } foreach ($addToGroups as $k) { if (array_key_exists($k, $subscribeGroupIds)) { unset($addToGroups[$k]); } } if (empty($contactID)) { $dupeParams = $params; if (!empty($dupeParams['onbehalf'])) { unset($dupeParams['onbehalf']); } $dedupeParams = CRM_Dedupe_Finder::formatParams($dupeParams, 'Individual'); $dedupeParams['check_permission'] = FALSE; $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual'); // if we find more than one contact, use the first one $contact_id = CRM_Utils_Array::value(0, $ids); // Fetch default greeting id's if creating a contact if (!$contact_id) { foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) { if (!isset($params[$greeting])) { $params[$greeting] = CRM_Contact_BAO_Contact_Utils::defaultGreeting('Individual', $greeting); } } } $contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $contact_id, $addToGroups, NULL, NULL, TRUE); } else { $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'contact_type'); $contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $contactID, $addToGroups, NULL, $ctype, TRUE); } // Make the contact ID associated with the contribution available at the Class level. // Also make available to the session. //@todo consider handling this in $this->getContactID(); $this->set('contactID', $contactID); $this->_contactID = $contactID; //get email primary first if exist $subscribtionEmail = array('email' => CRM_Utils_Array::value('email-Primary', $params)); if (!$subscribtionEmail['email']) { $subscribtionEmail['email'] = CRM_Utils_Array::value("email-{$this->_bltID}", $params); } // subscribing contact to groups if (!empty($subscribeGroupIds) && $subscribtionEmail['email']) { CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($subscribeGroupIds, $subscribtionEmail, $contactID); } // If onbehalf-of-organization contribution / signup, add organization // and it's location. if (isset($params['hidden_onbehalf_profile']) && isset($behalfOrganization['organization_name'])) { $ufFields = array(); foreach ($this->_fields['onbehalf'] as $name => $value) { $ufFields[$name] = 1; } self::processOnBehalfOrganization($behalfOrganization, $contactID, $this->_values, $this->_params, $ufFields); } else { if (!empty($this->_membershipContactID) && $contactID != $this->_membershipContactID) { // this is an onbehalf renew case for inherited membership. For e.g a permissioned member of household, // store current user id as related contact for later use for mailing / activity.. $this->_values['related_contact'] = $contactID; $this->_params['related_contact'] = $contactID; // swap contact like we do for on-behalf-org case, so parent/primary membership is affected $contactID = $this->_membershipContactID; } } // lets store the contactID in the session // for things like tell a friend $session = CRM_Core_Session::singleton(); if (!$session->get('userID')) { $session->set('transaction.userID', $contactID); } else { $session->set('transaction.userID', NULL); } $this->_useForMember = $this->get('useForMember'); // store the fact that this is a membership and membership type is selected $processMembership = FALSE; if (!empty($membershipParams['selectMembership']) && $membershipParams['selectMembership'] != 'no_thanks' || $this->_useForMember) { $processMembership = TRUE; if (!$this->_useForMember) { $this->assign('membership_assign', TRUE); $this->set('membershipTypeID', $this->_params['selectMembership']); } if ($this->_action & CRM_Core_Action::PREVIEW) { $membershipParams['is_test'] = 1; } if ($this->_params['is_pay_later']) { $membershipParams['is_pay_later'] = 1; } } if ($processMembership) { CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $membershipParams, TRUE); // added new parameter for cms user contact id, needed to distinguish behaviour for on behalf of sign-ups if (isset($this->_params['related_contact'])) { $membershipParams['cms_contactID'] = $this->_params['related_contact']; } else { $membershipParams['cms_contactID'] = $contactID; } //inherit campaign from contirb page. if (!array_key_exists('campaign_id', $membershipParams)) { $membershipParams['campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values); } if (!empty($membershipParams['onbehalf']) && is_array($membershipParams['onbehalf']) && !empty($membershipParams['onbehalf']['member_campaign_id'])) { $this->_params['campaign_id'] = $membershipParams['onbehalf']['member_campaign_id']; } $customFieldsFormatted = $fieldTypes = array(); if (!empty($membershipParams['onbehalf']) && is_array($membershipParams['onbehalf'])) { foreach ($membershipParams['onbehalf'] as $key => $value) { if (strstr($key, 'custom_')) { $customFieldId = explode('_', $key); CRM_Core_BAO_CustomField::formatCustomField($customFieldId[1], $customFieldsFormatted, $value, 'Membership', NULL, $contactID); } } $fieldTypes = array('Contact', 'Organization', 'Membership'); } $priceFieldIds = $this->get('memberPriceFieldIDS'); if (!empty($priceFieldIds)) { $contributionTypeID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceFieldIds['id'], 'financial_type_id'); unset($priceFieldIds['id']); $membershipTypeIds = array(); $membershipTypeTerms = array(); foreach ($priceFieldIds as $priceFieldId) { if ($id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_type_id')) { $membershipTypeIds[] = $id; $term = 1; if ($term = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_num_terms')) { $membershipTypeTerms[$id] = $term > 1 ? $term : 1; } else { $membershipTypeTerms[$id] = 1; } } } $membershipParams['selectMembership'] = $membershipTypeIds; $membershipParams['financial_type_id'] = $contributionTypeID; $membershipParams['types_terms'] = $membershipTypeTerms; } if (!empty($membershipParams['selectMembership'])) { // CRM-12233 if ($this->_separateMembershipPayment && $this->_values['amount_block_is_active']) { foreach ($this->_values['fee'] as $key => $feeValues) { if ($feeValues['name'] == 'membership_amount') { $fieldId = $this->_params['price_' . $key]; $this->_memLineItem[$this->_priceSetId][$fieldId] = $this->_lineItem[$this->_priceSetId][$fieldId]; unset($this->_lineItem[$this->_priceSetId][$fieldId]); break; } } } CRM_Member_BAO_Membership::postProcessMembership($membershipParams, $contactID, $this, $premiumParams, $customFieldsFormatted, $fieldTypes); } } else { // at this point we've created a contact and stored its address etc // all the payment processors expect the name and address to be in the // so we copy stuff over to first_name etc. $paymentParams = $this->_params; $contributionTypeId = $this->_values['financial_type_id']; $fieldTypes = array(); if (!empty($paymentParams['onbehalf']) && is_array($paymentParams['onbehalf'])) { foreach ($paymentParams['onbehalf'] as $key => $value) { if (strstr($key, 'custom_')) { $this->_params[$key] = $value; } } $fieldTypes = array('Contact', 'Organization', 'Contribution'); } CRM_Contribute_BAO_Contribution_Utils::processConfirm($this, $paymentParams, $premiumParams, $contactID, $contributionTypeId, 'contribution', $fieldTypes); } }
/** * function to update contact fields * * @return void * @access public */ public function updateContactFields($contactID, $params, $fields) { //add the contact to group, if add to group is selected for a //particular uf group // get the add to groups $addToGroups = array(); if (!empty($this->_fields)) { foreach ($this->_fields as $key => $value) { if (CRM_Utils_Array::value('add_to_group_id', $value)) { $addToGroups[$value['add_to_group_id']] = $value['add_to_group_id']; } } } // check for profile double opt-in and get groups to be subscribed require_once 'CRM/Core/BAO/UFGroup.php'; $subscribeGroupIds = CRM_Core_BAO_UFGroup::getDoubleOptInGroupIds($params, $contactID); require_once "CRM/Contact/BAO/Contact.php"; if ($contactID) { $ctype = CRM_Core_DAO::getFieldValue("CRM_Contact_DAO_Contact", $contactID, "contact_type"); $contactID =& CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $contactID, $addToGroups, null, $ctype); } else { // when we have allow_same_participant_emails = 1 // don't take email address in dedupe params - CRM-4886 // here we are making dedupe weak - so to make dedupe // more effective please update individual 'Strict' rule. $allowSameEmailAddress = CRM_Utils_Array::value('allow_same_participant_emails', $this->_values['event']); require_once 'CRM/Dedupe/Finder.php'; //suppress "email-Primary" when allow_same_participant_emails = 1 if ($allowSameEmailAddress && ($email = CRM_Utils_Array::value('email-Primary', $params)) && CRM_Utils_Array::value('registered_by_id', $params)) { //skip dedupe check only for additional participants unset($params['email-Primary']); } $dedupeParams = CRM_Dedupe_Finder::formatParams($params, 'Individual'); $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual'); // if we find more than one contact, use the first one $contact_id = $ids[0]; if (isset($email)) { $params['email-Primary'] = $email; } $contactID =& CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $contact_id, $addToGroups); $this->set('contactID', $contactID); } //get email primary first if exist $subscribtionEmail = array('email' => CRM_Utils_Array::value('email-Primary', $params)); if (!$subscribtionEmail['email']) { $subscribtionEmail['email'] = CRM_Utils_Array::value("email-{$this->_bltID}", $params); } // subscribing contact to groups if (!empty($subscribeGroupIds) && $subscribtionEmail['email']) { require_once 'CRM/Mailing/Event/BAO/Subscribe.php'; CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($subscribeGroupIds, $subscribtionEmail, $contactID); } return $contactID; }
/** * Post form submission handling. * * This is also called from the test suite. * * @param int $contactID * * @return array */ protected function processFormSubmission($contactID) { $isPayLater = $this->_params['is_pay_later']; if (!isset($this->_params['payment_processor_id'])) { // If there is no processor we are using the pay-later manual pseudo-processor. // (note it might make sense to make this a row in the processor table in the db). $this->_params['payment_processor_id'] = 0; } if (isset($this->_params['payment_processor_id']) && $this->_params['payment_processor_id'] == 0) { $this->_params['is_pay_later'] = $isPayLater = TRUE; } // add a description field at the very beginning $this->_params['description'] = ts('Online Contribution') . ': ' . ($this->_pcpInfo['title'] ? $this->_pcpInfo['title'] : $this->_values['title']); $this->_params['accountingCode'] = CRM_Utils_Array::value('accountingCode', $this->_values); // fix currency ID $this->_params['currencyID'] = CRM_Core_Config::singleton()->defaultCurrency; //carry payment processor id. if (CRM_Utils_Array::value('id', $this->_paymentProcessor)) { $this->_params['payment_processor_id'] = $this->_paymentProcessor['id']; } $premiumParams = $membershipParams = $params = $this->_params; if (!empty($params['image_URL'])) { CRM_Contact_BAO_Contact::processImageParams($params); } $fields = array('email-Primary' => 1); // get the add to groups $addToGroups = array(); // now set the values for the billing location. foreach ($this->_fields as $name => $value) { $fields[$name] = 1; // get the add to groups for uf fields if (!empty($value['add_to_group_id'])) { $addToGroups[$value['add_to_group_id']] = $value['add_to_group_id']; } } $fields = $this->formatParamsForPaymentProcessor($fields); // billing email address $fields["email-{$this->_bltID}"] = 1; // if onbehalf-of-organization contribution, take out // organization params in a separate variable, to make sure // normal behavior is continued. And use that variable to // process on-behalf-of functionality. if (!empty($this->_values['onbehalf_profile_id'])) { $behalfOrganization = array(); $orgFields = array('organization_name', 'organization_id', 'org_option'); foreach ($orgFields as $fld) { if (array_key_exists($fld, $params)) { $behalfOrganization[$fld] = $params[$fld]; unset($params[$fld]); } } if (is_array($params['onbehalf']) && !empty($params['onbehalf'])) { foreach ($params['onbehalf'] as $fld => $values) { if (strstr($fld, 'custom_')) { $behalfOrganization[$fld] = $values; } elseif (!strstr($fld, '-')) { if (in_array($fld, array('contribution_campaign_id', 'member_campaign_id'))) { $fld = 'campaign_id'; } else { $behalfOrganization[$fld] = $values; } $this->_params[$fld] = $values; } } } if (array_key_exists('onbehalf_location', $params) && is_array($params['onbehalf_location'])) { foreach ($params['onbehalf_location'] as $block => $vals) { //fix for custom data (of type checkbox, multi-select) if (substr($block, 0, 7) == 'custom_') { continue; } // fix the index of block elements if (is_array($vals)) { foreach ($vals as $key => $val) { //dont adjust the index of address block as //it's index is WRT to location type $newKey = $block == 'address' ? $key : ++$key; $behalfOrganization[$block][$newKey] = $val; } } } unset($params['onbehalf_location']); } if (!empty($params['onbehalf[image_URL]'])) { $behalfOrganization['image_URL'] = $params['onbehalf[image_URL]']; } } // check for profile double opt-in and get groups to be subscribed $subscribeGroupIds = CRM_Core_BAO_UFGroup::getDoubleOptInGroupIds($params, $contactID); // since we are directly adding contact to group lets unset it from mailing if (!empty($addToGroups)) { foreach ($addToGroups as $groupId) { if (isset($subscribeGroupIds[$groupId])) { unset($subscribeGroupIds[$groupId]); } } } foreach ($addToGroups as $k) { if (array_key_exists($k, $subscribeGroupIds)) { unset($addToGroups[$k]); } } if (empty($contactID)) { $dupeParams = $params; if (!empty($dupeParams['onbehalf'])) { unset($dupeParams['onbehalf']); } if (!empty($dupeParams['honor'])) { unset($dupeParams['honor']); } $dedupeParams = CRM_Dedupe_Finder::formatParams($dupeParams, 'Individual'); $dedupeParams['check_permission'] = FALSE; $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual'); // if we find more than one contact, use the first one $contactID = CRM_Utils_Array::value(0, $ids); // Fetch default greeting id's if creating a contact if (!$contactID) { foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) { if (!isset($params[$greeting])) { $params[$greeting] = CRM_Contact_BAO_Contact_Utils::defaultGreeting('Individual', $greeting); } } } $contactType = NULL; } else { $contactType = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'contact_type'); } $contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $contactID, $addToGroups, NULL, $contactType, TRUE); // Make the contact ID associated with the contribution available at the Class level. // Also make available to the session. //@todo consider handling this in $this->getContactID(); $this->set('contactID', $contactID); $this->_contactID = $contactID; //get email primary first if exist $subscriptionEmail = array('email' => CRM_Utils_Array::value('email-Primary', $params)); if (!$subscriptionEmail['email']) { $subscriptionEmail['email'] = CRM_Utils_Array::value("email-{$this->_bltID}", $params); } // subscribing contact to groups if (!empty($subscribeGroupIds) && $subscriptionEmail['email']) { CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($subscribeGroupIds, $subscriptionEmail, $contactID); } // If onbehalf-of-organization contribution / signup, add organization // and it's location. if (isset($this->_values['onbehalf_profile_id']) && isset($behalfOrganization['organization_name'])) { $ufFields = array(); foreach ($this->_fields['onbehalf'] as $name => $value) { $ufFields[$name] = 1; } self::processOnBehalfOrganization($behalfOrganization, $contactID, $this->_values, $this->_params, $ufFields); } elseif (!empty($this->_membershipContactID) && $contactID != $this->_membershipContactID) { // this is an onbehalf renew case for inherited membership. For e.g a permissioned member of household, // store current user id as related contact for later use for mailing / activity.. $this->_values['related_contact'] = $contactID; $this->_params['related_contact'] = $contactID; // swap contact like we do for on-behalf-org case, so parent/primary membership is affected $contactID = $this->_membershipContactID; } // lets store the contactID in the session // for things like tell a friend $session = CRM_Core_Session::singleton(); if (!$session->get('userID')) { $session->set('transaction.userID', $contactID); } else { $session->set('transaction.userID', NULL); } $this->_useForMember = $this->get('useForMember'); // store the fact that this is a membership and membership type is selected if (!empty($membershipParams['selectMembership']) && $membershipParams['selectMembership'] != 'no_thanks' || $this->_useForMember) { if (!$this->_useForMember) { $this->assign('membership_assign', TRUE); $this->set('membershipTypeID', $this->_params['selectMembership']); } if ($this->_action & CRM_Core_Action::PREVIEW) { $membershipParams['is_test'] = 1; } if ($this->_params['is_pay_later']) { $membershipParams['is_pay_later'] = 1; } //inherit campaign from contribution page. if (!array_key_exists('campaign_id', $membershipParams)) { $membershipParams['campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values); } CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $membershipParams, TRUE); $this->doMembershipProcessing($contactID, $membershipParams, $premiumParams, $isPayLater); } else { // at this point we've created a contact and stored its address etc // all the payment processors expect the name and address to be in the // so we copy stuff over to first_name etc. $paymentParams = $this->_params; if (!empty($paymentParams['onbehalf']) && is_array($paymentParams['onbehalf'])) { foreach ($paymentParams['onbehalf'] as $key => $value) { if (strstr($key, 'custom_')) { $this->_params[$key] = $value; } } } $result = CRM_Contribute_BAO_Contribution_Utils::processConfirm($this, $paymentParams, $contactID, $this->wrangleFinancialTypeID($this->_values['financial_type_id']), 'contribution', $this->_mode == 'test' ? 1 : 0, CRM_Utils_Array::value('is_recur', $paymentParams)); if (empty($result['is_payment_failure'])) { // @todo move premium processing to complete transaction if it truly is an 'after' action. $this->postProcessPremium($premiumParams, $result['contribution']); } if (!empty($result['contribution'])) { // Not quite sure why it would be empty at this stage but tests show it can be ... at least in tests. $this->completeTransaction($result, $result['contribution']->id); } return $result; } }
/** * Function to delete the group and all the object that connect to * this group. Incredibly destructive * * @param int $id group id * * @return null * @access public * @static * */ static function discard($id) { require_once 'CRM/Utils/Hook.php'; require_once 'CRM/Contact/DAO/SubscriptionHistory.php'; CRM_Utils_Hook::pre('delete', 'Group', $id, CRM_Core_DAO::$_nullArray); require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); // added for CRM-1631 and CRM-1794 // delete all subscribed mails with the selected group id require_once 'CRM/Mailing/Event/BAO/Subscribe.php'; $subscribe = new CRM_Mailing_Event_BAO_Subscribe(); $subscribe->deleteGroup($id); // delete all Subscription records with the selected group id $subHistory = new CRM_Contact_DAO_SubscriptionHistory(); $subHistory->group_id = $id; $subHistory->delete(); // delete all crm_group_contact records with the selected group id require_once 'CRM/Contact/DAO/GroupContact.php'; $groupContact = new CRM_Contact_DAO_GroupContact(); $groupContact->group_id = $id; $groupContact->delete(); // make all the 'add_to_group_id' field of 'civicrm_uf_group table', pointing to this group, as null $params = array(1 => array($id, 'Integer')); $query = "update civicrm_uf_group SET `add_to_group_id`= NULL where `add_to_group_id` = %1"; CRM_Core_DAO::executeQuery($query, $params); $query = "update civicrm_uf_group SET `limit_listings_group_id`= NULL where `limit_listings_group_id` = %1"; CRM_Core_DAO::executeQuery($query, $params); if (defined('CIVICRM_MULTISITE') && CIVICRM_MULTISITE) { // clear any descendant groups cache if exists require_once 'CRM/Core/BAO/Cache.php'; $finalGroups =& CRM_Core_BAO_Cache::deleteGroup('descendant groups for an org'); } // delete from group table $group = new CRM_Contact_DAO_Group(); $group->id = $id; $group->delete(); $transaction->commit(); CRM_Utils_Hook::post('delete', 'Group', $id, $group); // delete the recently created Group require_once 'CRM/Utils/Recent.php'; $groupRecent = array('id' => $id, 'type' => 'Group'); CRM_Utils_Recent::del($groupRecent); }
/** * takes an associative array and sends a thank you or email verification email * * @param array $params (reference ) an assoc array of name/value pairs * * @return * @access public * @static */ function sendEmail($params, $sendEmailMode) { /* sendEmailMode * CRM_Campaign_Form_Petition_Signature::EMAIL_THANK * connected user via login/pwd - thank you * or dedupe contact matched who doesn't have a tag CIVICRM_TAG_UNCONFIRMED - thank you * or login using fb connect - thank you + click to add msg to fb wall * * CRM_Campaign_Form_Petition_Signature::EMAIL_CONFIRM * send a confirmation request email */ require_once 'CRM/Campaign/Form/Petition/Signature.php'; // define constant CIVICRM_PETITION_CONTACTS, if not exist in civicrm.settings.php if (!defined('CIVICRM_PETITION_CONTACTS')) { define('CIVICRM_PETITION_CONTACTS', 'Petition Contacts'); } // check if the group defined by CIVICRM_PETITION_CONTACTS exists, else create it require_once 'api/v2/Group.php'; $group_params['title'] = CIVICRM_PETITION_CONTACTS; $groups = civicrm_group_get($group_params); if (CRM_Utils_Array::value('is_error', $groups) == 1 && CRM_Utils_Array::value('error_message', $groups) == 'No such group exists') { $group_params['is_active'] = 1; $group_params['visibility'] = 'Public Pages'; $newgroup = civicrm_group_add($group_params); if ($newgroup['is_error'] == 0) { $group_id[0] = $newgroup['result']; } } else { $group_id = array_keys($groups); } // get petition info $petitionParams['id'] = $params['sid']; $petitionInfo = array(); CRM_Campaign_BAO_Survey::retrieve($petitionParams, $petitionInfo); if (empty($petitionInfo)) { CRM_Core_Error::fatal('Petition doesn\'t exist.'); } require_once 'CRM/Core/BAO/Domain.php'; //get the default domain email address. list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail(); require_once 'CRM/Core/BAO/MailSettings.php'; $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain(); require_once 'CRM/Contact/BAO/Contact.php'; $toName = CRM_Contact_BAO_Contact::displayName($params['contactId']); $replyTo = "do-not-reply@{$emailDomain}"; // set additional general message template params (custom tokens to use in email msg templates) // tokens then available in msg template as {$petition.title}, etc $petitionTokens['title'] = $petitionInfo['title']; $petitionTokens['petitionId'] = $params['sid']; $tplParams['petition'] = $petitionTokens; switch ($sendEmailMode) { case CRM_Campaign_Form_Petition_Signature::EMAIL_THANK: //add this contact to the CIVICRM_PETITION_CONTACTS group require_once 'api/v2/GroupContact.php'; $params['group_id'] = $group_id[0]; $params['contact_id'] = $params['contactId']; civicrm_group_contact_add($params); require_once 'CRM/Core/BAO/MessageTemplates.php'; if ($params['email-Primary']) { CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_petition', 'valueName' => 'petition_sign', 'contactId' => $params['contactId'], 'tplParams' => $tplParams, 'from' => "\"{$domainEmailName}\" <{$domainEmailAddress}>", 'toName' => $toName, 'toEmail' => $params['email-Primary'], 'replyTo' => $replyTo, 'petitionId' => $params['sid'], 'petitionTitle' => $petitionInfo['title'])); } break; case CRM_Campaign_Form_Petition_Signature::EMAIL_CONFIRM: // create mailing event subscription record for this contact // this will allow using a hash key to confirm email address by sending a url link require_once 'CRM/Mailing/Event/BAO/Subscribe.php'; $se = CRM_Mailing_Event_BAO_Subscribe::subscribe($group_id[0], $params['email-Primary'], $params['contactId']); // require_once 'CRM/Core/BAO/Domain.php'; // $domain =& CRM_Core_BAO_Domain::getDomain(); $config = CRM_Core_Config::singleton(); $localpart = CRM_Core_BAO_MailSettings::defaultLocalpart(); require_once 'CRM/Utils/Verp.php'; $replyTo = implode($config->verpSeparator, array($localpart . 'c', $se->contact_id, $se->id, $se->hash)) . "@{$emailDomain}"; $confirmUrl = CRM_Utils_System::url('civicrm/petition/confirm', "reset=1&cid={$se->contact_id}&sid={$se->id}&h={$se->hash}&a={$params['activityId']}&p={$params['sid']}", true); $confirmUrlPlainText = CRM_Utils_System::url('civicrm/petition/confirm', "reset=1&cid={$se->contact_id}&sid={$se->id}&h={$se->hash}&a={$params['activityId']}&p={$params['sid']}", true, null, false); // set email specific message template params and assign to tplParams $petitionTokens['confirmUrl'] = $confirmUrl; $petitionTokens['confirmUrlPlainText'] = $confirmUrlPlainText; $tplParams['petition'] = $petitionTokens; require_once 'CRM/Core/BAO/MessageTemplates.php'; if ($params['email-Primary']) { CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_petition', 'valueName' => 'petition_confirmation_needed', 'contactId' => $params['contactId'], 'tplParams' => $tplParams, 'from' => "\"{$domainEmailName}\" <{$domainEmailAddress}>", 'toName' => $toName, 'toEmail' => $params['email-Primary'], 'replyTo' => $replyTo, 'petitionId' => $params['sid'], 'petitionTitle' => $petitionInfo['title'], 'confirmUrl' => $confirmUrl)); } break; } }
/** * Delete a contact and all its associated records * * @param int $id id of the contact to delete * * @return boolean true if contact deleted, false otherwise * @access public * @static */ function deleteContact($id) { require_once 'CRM/Core/BAO/EmailHistory.php'; require_once 'CRM/Core/BAO/Meeting.php'; require_once 'CRM/Core/BAO/Phonecall.php'; // make sure we have edit permission for this contact // before we delete if (!CRM_Contact_BAO_Contact::permissionedContact($id, CRM_CORE_PERMISSION_EDIT)) { return false; } require_once 'CRM/Utils/Hook.php'; $contact =& new CRM_Contact_DAO_Contact(); $contact->id = $id; if (!$contact->find(true)) { return false; } $contactType = $contact->contact_type; CRM_Utils_Hook::pre('delete', $contactType, $id); CRM_Core_DAO::transaction('BEGIN'); // do a top down deletion CRM_Mailing_Event_BAO_Subscribe::deleteContact($id); CRM_Contact_BAO_GroupContact::deleteContact($id); CRM_Contact_BAO_SubscriptionHistory::deleteContact($id); CRM_Contact_BAO_Relationship::deleteContact($id); CRM_Contribute_BAO_Contribution::deleteContact($id); CRM_Core_BAO_Note::deleteContact($id); CRM_Core_DAO::deleteEntityContact('CRM_Core_DAO_CustomValue', $id); CRM_Core_DAO::deleteEntityContact('CRM_Core_DAO_ActivityHistory', $id); require_once 'CRM/Core/BAO/UFMatch.php'; CRM_Core_BAO_UFMatch::deleteContact($id); // need to remove them from email, meeting and phonecall CRM_Core_BAO_EmailHistory::deleteContact($id); CRM_Core_BAO_Meeting::deleteContact($id); CRM_Core_BAO_Phonecall::deleteContact($id); // location shld be deleted after phonecall, since fields in phonecall are // fkeyed into location/phone. CRM_Core_BAO_Location::deleteContact($id); // fix household and org primary contact ids foreach ($GLOBALS['_CRM_CONTACT_BAO_CONTACT']['misc'] as $name) { require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Contact_DAO_" . $name) . ".php"; eval('$object =& new CRM_Contact_DAO_' . $name . '( );'); $object->primary_contact_id = $id; $object->find(); while ($object->fetch()) { // we need to set this to null explicitly $object->primary_contact_id = 'null'; $object->save(); } } require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Contact_BAO_" . $contactType) . ".php"; eval('$object =& new CRM_Contact_BAO_' . $contactType . '( );'); $object->contact_id = $contact->id; $object->delete(); $contact->delete(); //delete the contact id from recently view CRM_Utils_Recent::del($id); CRM_Core_DAO::transaction('COMMIT'); CRM_Utils_Hook::post('delete', $contactType, $contact->id, $contact); return true; }