/** * Register a subscription event. Create a new contact if one does not * already exist. * * @param int $domain_id The domain id of the new subscription * @param int $group_id The group id to subscribe to * @param string $email The email address of the (new) contact * @return int|null $se_id The id of the subscription event, null on failure * @access public * @static */ function &subscribe($domain_id, $group_id, $email) { /* First, find out if the contact already exists */ $params = array('email' => $email, 'domain_id' => $domain_id); require_once 'CRM/Core/BAO/UFGroup.php'; $contact_id = CRM_Core_BAO_UFGroup::findContact($params); CRM_Core_DAO::transaction('BEGIN'); if (is_a($contact_id, CRM_Core_Error)) { require_once 'CRM/Core/BAO/LocationType.php'; /* If the contact does not exist, create one. */ $formatted = array('contact_type' => 'Individual'); $value = array('email' => $email, 'location_type' => CRM_Core_BAO_LocationType::getDefaultID()); _crm_add_formatted_param($value, $formatted); $contact =& crm_create_contact_formatted($formatted, CRM_IMPORT_PARSER_DUPLICATE_SKIP); if (is_a($contact, CRM_Core_Error)) { return null; } $contact_id = $contact->id; } require_once 'CRM/Core/BAO/Email.php'; require_once 'CRM/Core/BAO/Location.php'; require_once 'CRM/Contact/BAO/Contact.php'; /* Get the primary email id from the contact to use as a hash input */ $dao =& new CRM_Core_DAO(); $emailTable = CRM_Core_BAO_Email::getTableName(); $locTable = CRM_Core_BAO_Location::getTableName(); $contactTable = CRM_Contact_BAO_Contact::getTableName(); $dao->query("SELECT {$emailTable}.id as email_id\n FROM {$emailTable}\n INNER JOIN {$locTable}\n ON {$emailTable}.location_id = {$locTable}.id\n WHERE {$emailTable}.is_primary = 1\n AND {$locTable}.is_primary = 1\n AND {$locTable}.entity_table = '{$contactTable}'\n AND {$locTable}.entity_id = " . CRM_Utils_Type::escape($contact_id, 'Integer')); $dao->fetch(); $se =& new CRM_Mailing_Event_BAO_Subscribe(); $se->group_id = $group_id; $se->contact_id = $contact_id; $se->time_stamp = date('YmdHis'); $se->hash = sha1("{$group_id}:{$contact_id}:{$dao->email_id}"); $se->save(); $contacts = array($contact_id); require_once 'CRM/Contact/BAO/GroupContact.php'; CRM_Contact_BAO_GroupContact::addContactsToGroup($contacts, $group_id, 'Email', 'Pending', $se->id); CRM_Core_DAO::transaction('COMMIT'); return $se; }
/** * Takes an associative array and creates a friend object. * * @param array $params * (reference ) an assoc array of name/value pairs. * * @return void */ public static function create(&$params) { $transaction = new CRM_Core_Transaction(); $mailParams = array(); //create contact corresponding to each friend foreach ($params['friend'] as $key => $details) { if ($details["first_name"]) { $contactParams[$key] = array('first_name' => $details["first_name"], 'last_name' => $details["last_name"], 'contact_source' => ts('Tell a Friend') . ": {$params['title']}", 'email-Primary' => $details["email"]); $displayName = $details["first_name"] . " " . $details["last_name"]; $mailParams['email'][$displayName] = $details["email"]; } } $frndParams = array(); $frndParams['entity_id'] = $params['entity_id']; $frndParams['entity_table'] = $params['entity_table']; self::getValues($frndParams); $activityTypeId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', 'Tell a Friend', 'value', 'name'); //create activity $activityParams = array('source_contact_id' => $params['source_contact_id'], 'source_record_id' => NULL, 'activity_type_id' => $activityTypeId, 'title' => $params['title'], 'activity_date_time' => date("YmdHis"), 'subject' => ts('Tell a Friend') . ": {$params['title']}", 'details' => $params['suggested_message'], 'status_id' => 2, 'is_test' => $params['is_test'], 'campaign_id' => CRM_Utils_Array::value('campaign_id', $params)); //activity creation $activity = CRM_Activity_BAO_Activity::create($activityParams); $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); //friend contacts creation foreach ($contactParams as $key => $value) { //create contact only if it does not exits in db $value['email'] = $value['email-Primary']; $value['check_permission'] = FALSE; $contact = CRM_Core_BAO_UFGroup::findContact($value, NULL, 'Individual'); if (!$contact) { $contact = self::add($value); } // attempt to save activity targets $targetParams = array('activity_id' => $activity->id, 'contact_id' => $contact, 'record_type_id' => $targetID); // See if it already exists $activityContact = new CRM_Activity_DAO_ActivityContact(); $activityContact->activity_id = $activity->id; $activityContact->contact_id = $contact; $activityContact->find(TRUE); if (empty($activityContact->id)) { $resultTarget = CRM_Activity_BAO_ActivityContact::create($targetParams); } } $transaction->commit(); //process sending of mails $mailParams['title'] = CRM_Utils_Array::value('title', $params); $mailParams['general_link'] = CRM_Utils_Array::value('general_link', $frndParams); $mailParams['message'] = CRM_Utils_Array::value('suggested_message', $params); // get domain $domainDetails = CRM_Core_BAO_Domain::getNameAndEmail(); list($username, $mailParams['domain']) = explode('@', $domainDetails[1]); $default = array(); $findProperties = array('id' => $params['entity_id']); if ($params['entity_table'] == 'civicrm_contribution_page') { $returnProperties = array('receipt_from_email', 'is_email_receipt'); CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $findProperties, $default, $returnProperties); //if is_email_receipt is set then take receipt_from_email //as from_email if (!empty($default['is_email_receipt']) && !empty($default['receipt_from_email'])) { $mailParams['email_from'] = $default['receipt_from_email']; } $urlPath = 'civicrm/contribute/transact'; $mailParams['module'] = 'contribute'; } elseif ($params['entity_table'] == 'civicrm_event') { $returnProperties = array('confirm_from_email', 'is_email_confirm'); CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Event', $findProperties, $default, $returnProperties); $mailParams['email_from'] = $domainDetails['1']; //if is_email_confirm is set then take confirm_from_email //as from_email if (!empty($default['is_email_confirm']) && !empty($default['confirm_from_email'])) { $mailParams['email_from'] = $default['confirm_from_email']; } $urlPath = 'civicrm/event/info'; $mailParams['module'] = 'event'; } elseif ($params['entity_table'] == 'civicrm_pcp') { $mailParams['email_from'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Email', $params['source_contact_id'], 'email', 'contact_id'); $urlPath = 'civicrm/pcp/info'; $mailParams['module'] = 'contribute'; } $mailParams['page_url'] = CRM_Utils_System::url($urlPath, "reset=1&id={$params['entity_id']}", TRUE, NULL, FALSE, TRUE); //send mail self::sendMail($params['source_contact_id'], $mailParams); }
/** * global form rule * * @param array $fields the input form values * @param array $files the uploaded files if any * @param array $options additional user data * * @return true if no errors, else array of errors * @access public * @static */ function formRule(&$fields, &$files, $options) { $errors = array(); $primaryEmail = CRM_Contact_Form_Edit::formRule($fields, $errors); // check for state/country mapping CRM_Contact_Form_Address::formRule($fields, $errors); // make sure that firstName and lastName or a primary email is set if (!(CRM_Utils_Array::value('first_name', $fields) && CRM_Utils_Array::value('last_name', $fields) || !empty($primaryEmail))) { $errors['_qf_default'] = ts('First Name and Last Name OR an email in the Primary Location should be set.'); } // if this is a forced save, ignore find duplicate rule if (!CRM_Utils_Array::value('_qf_Edit_next_duplicate', $fields)) { $cid = null; if ($options) { $cid = (int) $options; } $ids = CRM_Core_BAO_UFGroup::findContact($fields, $cid, true); if ($ids) { $urls = array(); foreach (explode(',', $ids) as $id) { $displayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $id, 'display_name'); $urls[] = '<a href="' . CRM_Utils_System::url('civicrm/contact/view', 'reset=1&action=update&cid=' . $id) . '">' . $displayName . '</a>'; } $url = implode(', ', $urls); $errors['_qf_default'] = ts('One matching contact was found. You can edit it here: %1, or click Save Duplicate Contact button below.', array(1 => $url, 'count' => count($urls), 'plural' => '%count matching contacts were found. You can edit them here: %1, or click Save Duplicate Contact button below.')); // let smarty know that there are duplicates $template =& CRM_Core_Smarty::singleton(); $template->assign('isDuplicate', 1); } else { if (CRM_Utils_Array::value('_qf_Edit_refresh_dedupe', $fields)) { // add a session message for no matching contacts CRM_Core_Session::setStatus('No matching contact found.'); } } } return empty($errors) ? true : $errors; }
static function formRule(&$fields, &$files, &$self) { if (!CRM_Utils_Array::value('cms_create_account', $fields)) { return true; } $config =& CRM_Core_Config::singleton(); $isDrupal = ucfirst($config->userFramework) == 'Drupal' ? TRUE : FALSE; $isJoomla = ucfirst($config->userFramework) == 'Joomla' ? TRUE : FALSE; $errors = array(); if ($isDrupal || $isJoomla) { $emailName = null; if (!empty($self->_bltID)) { // this is a transaction related page $emailName = 'email-' . $self->_bltID; } else { // find the email field in a profile page foreach ($fields as $name => $dontCare) { if (substr($name, 0, 5) == 'email') { $emailName = $name; break; } } } if ($emailName == null) { $errors['_qf_default'] == ts('Could not find an email address.'); return $errors; } if (empty($fields['cms_name'])) { $errors['cms_name'] = ts('Please specify a username.'); } if (empty($fields[$emailName])) { $errors[$emailName] = ts('Please specify a valid email address.'); } if ($isDrupal && !variable_get('user_email_verification', TRUE) or $isJoomla) { if (empty($fields['cms_pass']) || empty($fields['cms_confirm_pass'])) { $errors['cms_pass'] = ts('Please enter a password.'); } if ($fields['cms_pass'] != $fields['cms_confirm_pass']) { $errors['cms_pass'] = ts('Password and Confirm Password values are not the same.'); } } if (!empty($errors)) { return $errors; } // now check that the cms db does not have the user name and/or email if ($isDrupal or $isJoomla) { $params = array('name' => $fields['cms_name'], 'mail' => $fields[$emailName]); } self::checkUserNameEmailExists($params, $errors, $emailName); if ($isJoomla) { require_once 'CRM/Core/BAO/UFGroup.php'; $ids = CRM_Core_BAO_UFGroup::findContact($fields, null, 'Individual'); if ($ids) { $errors['_qf_default'] = ts('An account already exists with the same information.'); } } } return !empty($errors) ? $errors : true; }
/** * takes an associative array and creates a friend object * * @param array $params (reference ) an assoc array of name/value pairs * * @return object CRM_Contact_BAO_Contact object * @access public * @static */ static function create(&$params) { require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $mailParams = array(); //create contact corresponding to each friend foreach ($params['friend'] as $key => $details) { if ($details["first_name"]) { $contactParams[$key] = array('first_name' => $details["first_name"], 'last_name' => $details["last_name"], 'contact_source' => ts('Tell a Friend') . ": {$params['title']}", 'email-Primary' => $details["email"]); $displayName = $details["first_name"] . " " . $details["last_name"]; $mailParams['email'][$displayName] = $details["email"]; } } $frndParams = array(); $frndParams['entity_id'] = $params['entity_id']; $frndParams['entity_table'] = $params['entity_table']; self::getValues($frndParams); require_once 'CRM/Activity/BAO/Activity.php'; $activityTypeId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', 'Tell a Friend', 'value', 'name'); //create activity $activityParams = array('source_contact_id' => $params['source_contact_id'], 'source_record_id' => NULL, 'activity_type_id' => $activityTypeId, 'title' => $params['title'], 'activity_date_time' => date("YmdHis"), 'subject' => ts('Tell a Friend') . ": {$params['title']}", 'details' => $params['suggested_message'], 'status_id' => 2, 'is_test' => $params['is_test']); //activity creation $activity = CRM_Activity_BAO_Activity::create($activityParams); //friend contacts creation require_once 'CRM/Activity/BAO/ActivityTarget.php'; require_once 'CRM/Core/BAO/UFGroup.php'; foreach ($contactParams as $key => $value) { //create contact only if it does not exits in db $value['email'] = $value['email-Primary']; $contact = CRM_Core_BAO_UFGroup::findContact($value, null, 'Individual'); if (!$contact) { $contact = self::add($value); } // attempt to save activity targets $targetParams = array('activity_id' => $activity->id, 'target_contact_id' => $contact); $resultTarget = CRM_Activity_BAO_ActivityTarget::create($targetParams); } $transaction->commit(); //process sending of mails $mailParams['title'] = CRM_Utils_Array::value('title', $params); $mailParams['general_link'] = CRM_Utils_Array::value('general_link', $frndParams); $mailParams['message'] = CRM_Utils_Array::value('suggested_message', $params); // get domain require_once 'CRM/Core/BAO/Domain.php'; $domainDetails = CRM_Core_BAO_Domain::getNameAndEmail(); list($username, $mailParams['domain']) = split('@', $domainDetails[1]); if ($params['entity_table'] == 'civicrm_contribution_page') { $mailParams['email_from'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $params['entity_id'], 'receipt_from_email', 'id'); $urlPath = 'civicrm/contribute/transact'; $mailParams['module'] = 'contribute'; } elseif ($params['entity_table'] == 'civicrm_event') { $mailParams['email_from'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['entity_id'], 'confirm_from_email'); $mailParams['email_from'] = $mailParams['email_from'] ? $mailParams['email_from'] : $domainDetails['1']; $urlPath = 'civicrm/event/info'; $mailParams['module'] = 'event'; } elseif ($params['entity_table'] == 'civicrm_pcp') { $mailParams['email_from'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Email', $params['source_contact_id'], 'email', 'contact_id'); $urlPath = 'civicrm/contribute/pcp/info'; $mailParams['module'] = 'contribute'; } $mailParams['page_url'] = CRM_Utils_System::url($urlPath, "reset=1&id={$params['entity_id']}", true, null, false); //send mail self::sendMail($params['source_contact_id'], $mailParams); }
function &_crm_duplicate_formatted_contact(&$params) { if ($params['contact_type'] == 'Individual') { require_once 'CRM/Core/BAO/UFGroup.php'; if (($ids =& CRM_Core_BAO_UFGroup::findContact($params, null, true)) != null) { $error =& _crm_error("Found matching contacts: {$ids}", CRM_CORE_ERROR_DUPLICATE_CONTACT, 'Fatal', $ids); return $error; } return true; } else { require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Contact_DAO_" . $params['contact_type']) . ".php"; eval('$contact =& new CRM_Contact_DAO_' . $params['contact_type'] . '();'); if ($params['contact_type'] == 'Household') { $contact->household_name = $params['household_name']; } else { $contact->organization_name = $params['organization_name']; } if ($contact->find(true)) { $error =& _crm_error("Found matching contacts: {$contact->contact_id}", CRM_CORE_ERROR_DUPLICATE_CONTACT, 'Fatal', $contact->contact_id); return $error; } return true; } }
/** * Function to create is honor of * * @param array $params associated array of fields (by reference) * @param int $honorId honor Id * * @return contact id */ function createHonorContact(&$params, $honorId = null) { $honorParams = array('first_name' => $params["honor_first_name"], 'last_name' => $params["honor_last_name"], 'prefix_id' => $params["honor_prefix_id"], 'email-Primary' => $params["honor_email"]); if (!$honorId) { require_once "CRM/Core/BAO/UFGroup.php"; $honorParams['email'] = $params["honor_email"]; $ids = CRM_Core_BAO_UFGroup::findContact($honorParams, null, 'Individual'); $contactsIds = explode(',', $ids); if (is_numeric($contactsIds[0]) && count($contactsIds) == 1) { $honorId = $contactsIds[0]; } } $contact =& CRM_Contact_BAO_Contact::createProfileContact($honorParams, CRM_Core_DAO::$_nullArray, $honorId); return $contact; }
/** * global form rule * * @param array $fields the input form values * @param array $files the uploaded files if any * @param array $options additional user data * * @return true if no errors, else array of errors * @access public * @static */ function formRule(&$fields, &$files, $options = null) { $errors = array(); // if no values, return if (empty($fields)) { return true; } // hack add the email, does not work in registration, we need the real user object // hack this will not work in mambo/joomla, not sure why we need it global $user; if (isset($user) && !CRM_Utils_Array::value('email', $fields)) { $fields['email'] = $user->mail; } $cid = $register = null; // hack we use a -1 in options to indicate that its registration if ($options) { $options = (int) $options; if ($options > 0) { $cid = $options; } else { $register = true; } } $cid = null; if ($options) { $cid = (int) $options; // get the primary location type id and email list($name, $primaryEmail, $primaryLocationType) = CRM_Contact_BAO_Contact::getEmailDetails($cid); } // dont check for duplicates during registration validation: CRM-375 if (!$register) { $locationType = array(); $count = 1; $primaryLocation = 0; foreach ($fields as $key => $value) { $keyValue = explode('-', $key); if (is_numeric($keyValue[1])) { if (!in_array($keyValue[1], $locationType)) { $locationType[$count] = $keyValue[1]; $count++; } require_once 'CRM/Utils/Array.php'; $loc = CRM_Utils_Array::key($keyValue[1], $locationType); $data['location'][$loc]['location_type_id'] = $keyValue[1]; // if we are getting in a new primary email, dont overwrite the new one if ($keyValue[1] == $primaryLocationType) { if (CRM_Utils_Array::value('email-' . $primaryLocationType, $fields)) { $data['location'][$loc]['email'][$loc]['email'] = $fields['email-' . $primaryLocationType]; } else { $data['location'][$loc]['email'][$loc]['email'] = $primaryEmail; } $primaryLocation++; } if ($loc == 1) { $data['location'][$loc]['is_primary'] = 1; } if ($keyValue[0] == 'phone') { if ($keyValue[2]) { $data['location'][$loc]['phone'][$loc]['phone_type'] = $keyValue[2]; } else { $data['location'][$loc]['phone'][$loc]['phone_type'] = ''; } $data['location'][$loc]['phone'][$loc]['phone'] = $value; } else { if ($keyValue[0] == 'email') { $data['location'][$loc]['email'][$loc]['email'] = $value; } elseif ($keyValue[0] == 'im') { $data['location'][$loc]['im'][$loc]['name'] = $value; } else { if ($keyValue[0] === 'state_province') { $data['location'][$loc]['address']['state_province_id'] = $value; } else { if ($keyValue[0] === 'country') { $data['location'][$loc]['address']['country_id'] = $value; } else { $data['location'][$loc]['address'][$keyValue[0]] = $value; } } } } } else { if ($key === 'individual_suffix') { $data['suffix_id'] = $value; } else { if ($key === 'individual_prefix') { $data['prefix_id'] = $value; } else { if ($key === 'gender') { $data['gender_id'] = $value; } else { if (substr($key, 0, 6) === 'custom') { if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) { //fix checkbox if ($customFields[$customFieldID][3] == 'CheckBox') { $value = implode(CRM_CORE_BAO_CUSTOMOPTION_VALUE_SEPERATOR, array_keys($value)); } // fix the date field if ($customFields[$customFieldID][2] == 'Date') { $date = CRM_Utils_Date::format($value); if (!$date) { $date = ''; } $value = $date; } $data['custom'][$customFieldID] = array('id' => $id, 'value' => $value, 'extends' => $customFields[$customFieldID][3], 'type' => $customFields[$customFieldID][2], 'custom_field_id' => $customFieldID); } } else { if ($key == 'edit') { continue; } else { $data[$key] = $value; } } } } } } } if (!$primaryLocation) { $loc++; $data['location'][$loc]['email'][$loc]['email'] = $primaryEmail; } $ids = CRM_Core_BAO_UFGroup::findContact($data, $cid, true); if ($ids) { $errors['_qf_default'] = ts('An account already exists with the same information.'); } } // Validate Country - State list $countryId = $fields['country']; $stateProvinceId = $fields['state_province']; if ($stateProvinceId && $countryId) { $stateProvinceDAO =& new CRM_Core_DAO_StateProvince(); $stateProvinceDAO->id = $stateProvinceId; $stateProvinceDAO->find(true); if ($stateProvinceDAO->country_id != $countryId) { // country mismatch hence display error $stateProvinces = CRM_Core_PseudoConstant::stateProvince(); $countries =& CRM_Core_PseudoConstant::country(); $errors['state_province'] = "State/Province " . $stateProvinces[$stateProvinceId] . " is not part of " . $countries[$countryId] . ". It belongs to " . $countries[$stateProvinceDAO->country_id] . "."; } } return empty($errors) ? true : $errors; }
/** * Process the form * * @return void * @access public */ function postProcess() { $contactID = $this->get('contactID'); if (!$contactID) { // make a copy of params so we dont destroy our params // (since we pass this by reference) $premiumParams = $params = $this->_params; // so now we have a confirmed financial transaction // lets create or update a contact first require_once 'api/crm.php'; $ids = CRM_Core_BAO_UFGroup::findContact($params); $contactsIDs = explode(',', $ids); // if we find more than one contact, use the first one $contact_id = $contactsIDs[0]; $contact = null; if ($contact_id) { $contact =& crm_get_contact(array('contact_id' => $contact_id)); } $ids = array(); if (!$contact || !is_a($contact, 'CRM_Contact_BAO_Contact')) { $contact =& CRM_Contact_BAO_Contact::createFlat($params, $ids); } else { // need to fix and unify all contact creation $idParams = array('id' => $contact_id, 'contact_id' => $contact_id); $defaults = array(); CRM_Contact_BAO_Contact::retrieve($idParams, $defaults, $ids); $contact =& CRM_Contact_BAO_Contact::createFlat($params, $ids); } if (is_a($contact, 'CRM_Core_Error')) { CRM_Core_Error::fatal("Failed creating contact for contributor"); } $contactID = $contact->id; $this->set('contactID', $contactID); } $contributionType =& new CRM_Contribute_DAO_ContributionType(); $contributionType->id = $this->_values['contribution_type_id']; if (!$contributionType->find(true)) { CRM_Core_Error::fatal("Could not find a system table"); } // add some contribution type details to the params list // if folks need to use it $this->_params['contributionType_name'] = $contributionType->name; $this->_params['contributionType_accounting_code'] = $contributionType->accounting_code; $this->_params['contributionForm_id'] = $this->_values['id']; require_once 'CRM/Contribute/Payment.php'; $payment =& CRM_Contribute_Payment::singleton($this->_mode); if ($this->_contributeMode == 'express') { $result =& $payment->doExpressCheckout($this->_params); } else { $result =& $payment->doDirectPayment($this->_params); } if (is_a($result, 'CRM_Core_Error')) { CRM_Core_Error::displaySessionError($result); CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contribute/transact', '_qf_Main_display=true')); } $now = date('YmdHis'); $this->_params = array_merge($this->_params, $result); $this->_params['receive_date'] = $now; $this->set('params', $this->_params); $this->assign('trxn_id', $result['trxn_id']); $this->assign('receive_date', CRM_Utils_Date::mysqlToIso($this->_params['receive_date'])); // result has all the stuff we need // lets archive it to a financial transaction $config =& CRM_Core_Config::singleton(); $receiptDate = null; if ($this->_values['is_email_receipt']) { $receiptDate = $now; } if ($contributionType->is_deductible) { $this->assign('is_deductible', true); $this->set('is_deductible', true); } // assigning Premium information to receipt tpl if ($premiumParams['selectProduct'] && $premiumParams['selectProduct'] != 'no_thanks') { $startDate = $endDate = ""; $this->assign('selectPremium', true); require_once 'CRM/Contribute/DAO/Product.php'; $productDAO =& new CRM_Contribute_DAO_Product(); $productDAO->id = $premiumParams['selectProduct']; $productDAO->find(true); $this->assign('product_name', $productDAO->name); $this->assign('price', $productDAO->price); $this->assign('sku', $productDAO->sku); $this->assign('option', $premiumParams['options_' . $premiumParams['selectProduct']]); $periodType = $productDAO->period_type; if ($periodType) { $fixed_period_start_day = $productDAO->fixed_period_start_day; $duration_unit = $productDAO->duration_unit; $duration_interval = $productDAO->duration_interval; if ($periodType == 'rolling') { $startDate = date('Y-m-d'); } else { if ($periodType == 'fixed') { if ($fixed_period_start_day) { $date = explode('-', date('Y-m-d')); $month = substr($fixed_period_start_day, 0, strlen($fixed_period_start_day) - 2); $day = substr($fixed_period_start_day, -2) . "<br>"; $year = $date[0]; $startDate = $year . '-' . $month . '-' . $day; } else { $startDate = date('Y-m-d'); } } } $date = explode('-', $startDate); $year = $date[0]; $month = $date[1]; $day = $date[2]; switch ($duration_unit) { case 'year': $year = $year + $duration_interval; break; case 'month': $month = $month + $duration_interval; break; case 'day': $day = $day + $duration_interval; break; case 'week': $day = $day + $duration_interval * 7; } $endDate = date('Y-m-d H:i:s', mktime($hour, $minute, $second, $month, $day, $year)); $this->assign('start_date', $startDate); $this->assign('end_date', $endDate); } require_once 'CRM/Contribute/DAO/Premium.php'; $dao =& new CRM_Contribute_DAO_Premium(); $dao->entity_table = 'civicrm_contribution_page'; $dao->entity_id = $this->_id; $dao->find(true); $this->assign('contact_phone', $dao->premiums_contact_phone); $this->assign('contact_email', $dao->premiums_contact_email); } CRM_Core_DAO::transaction('BEGIN'); $nonDeductibleAmount = $result['gross_amount']; if ($contributionType->is_deductible) { if ($premiumParams['selectProduct'] != 'no_thanks') { require_once 'CRM/Contribute/DAO/Product.php'; $productDAO =& new CRM_Contribute_DAO_Product(); $productDAO->id = $premiumParams['selectProduct']; $productDAO->find(true); if ($result['gross_amount'] < $productDAO->price) { $nonDeductibleAmount = $result['gross_amount']; } else { $nonDeductibleAmount = $productDAO->price; } } else { $nonDeductibleAmount = '0.00'; } } // check contribution Type // first create the contribution record $params = array('contact_id' => $contactID, 'contribution_type_id' => $contributionType->id, 'payment_instrument_id' => 1, 'receive_date' => $now, 'non_deductible_amount' => $nonDeductibleAmount, 'total_amount' => $result['gross_amount'], 'fee_amount' => CRM_Utils_Array::value('fee_amount', $result), 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $result['gross_amount']), 'trxn_id' => $result['trxn_id'], 'invoice_id' => $this->_params['invoiceID'], 'currency' => $this->_params['currencyID'], 'receipt_date' => $receiptDate, 'source' => ts('Online Contribution:') . ' ' . $this->_values['title']); $ids = array(); $contribution =& CRM_Contribute_BAO_Contribution::add($params, $ids); //create Premium record if ($premiumParams['selectProduct'] && $premiumParams['selectProduct'] != 'no_thanks') { require_once 'CRM/Contribute/DAO/Product.php'; $productDAO =& new CRM_Contribute_DAO_Product(); $productDAO->id = $premiumParams['selectProduct']; $productDAO->find(true); $periodType = $productDAO->period_type; require_once 'CRM/Utils/Date.php'; $params = array('product_id' => $premiumParams['selectProduct'], 'contribution_id' => $contribution->id, 'product_option' => $premiumParams['options_' . $premiumParams['selectProduct']], 'quantity' => 1, 'start_date' => CRM_Utils_Date::customFormat($startDate, '%Y%m%d'), 'end_date' => CRM_Utils_Date::customFormat($endDate, '%Y%m%d')); CRM_Contribute_BAO_Contribution::addPremium($params); } // process the custom data that is submitted or that came via the url $groupTree = $this->get('groupTree'); $customValues = $this->get('customGetValues'); $customValues = array_merge($this->_params, $customValues); require_once 'CRM/Core/BAO/CustomGroup.php'; CRM_Core_BAO_CustomGroup::postProcess($groupTree, $customValues); CRM_Core_BAO_CustomGroup::updateCustomData($groupTree, 'Contribution', $contribution->id); // next create the transaction record $params = array('entity_table' => 'civicrm_contribution', 'entity_id' => $contribution->id, 'trxn_date' => $now, 'trxn_type' => 'Debit', 'total_amount' => $result['gross_amount'], 'fee_amount' => CRM_Utils_Array::value('fee_amount', $result), 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $result['gross_amount']), 'currency' => $this->_params['currencyID'], 'payment_processor' => $config->paymentProcessor, 'trxn_id' => $result['trxn_id']); require_once 'CRM/Contribute/BAO/FinancialTrxn.php'; $trxn =& CRM_Contribute_BAO_FinancialTrxn::create($params); // also create an activity history record require_once 'CRM/Utils/Money.php'; $params = array('entity_table' => 'civicrm_contact', 'entity_id' => $contactID, 'activity_type' => $contributionType->name, 'module' => 'CiviContribute', 'callback' => 'CRM_Contribute_Page_Contribution::details', 'activity_id' => $contribution->id, 'activity_summary' => 'Online - ' . CRM_Utils_Money::format($this->_params['amount']), 'activity_date' => $now); if (is_a(crm_create_activity_history($params), 'CRM_Core_Error')) { CRM_Core_Error::fatal("Could not create a system record"); } CRM_Core_DAO::transaction('COMMIT'); // finally send an email receipt if ($this->_values['is_email_receipt']) { list($displayName, $email) = CRM_Contact_BAO_Contact::getEmailDetails($contactID); $template =& CRM_Core_Smarty::singleton(); $subject = trim($template->fetch('CRM/Contribute/Form/Contribution/ReceiptSubject.tpl')); $message = $template->fetch('CRM/Contribute/Form/Contribution/ReceiptMessage.tpl'); $receiptFrom = '"' . $this->_values['receipt_from_name'] . '" <' . $this->_values['receipt_from_email'] . '>'; require_once 'CRM/Utils/Mail.php'; CRM_Utils_Mail::send($receiptFrom, $displayName, $email, $subject, $message, $this->_values['cc_receipt'], $this->_values['bcc_receipt']); } }
static function sendInviteEmail($message_template, $contact_id, $emailParams = array(), $teampcpId, $activityId) { $mailParams = array(); $contactParams = array(); if (isset($emailParams['tplParams'])) { $mailParams['tplParams'] = $emailParams['tplParams']; } //create contact corresponding to each friend foreach ($emailParams['friend'] as $key => $details) { if ($details["first_name"]) { $displayName = $details["first_name"] . " " . $details["last_name"]; $contactParams[$key] = array('first_name' => $details["first_name"], 'last_name' => $details["last_name"], 'contact_source' => ts('PCP Team Invite'), 'email-Primary' => $details["email"], 'display_name' => $displayName); $mailParams['email'][$displayName] = $contactParams[$key]; } } if (empty($mailParams)) { return NULL; } $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); //friend contacts creation foreach ($contactParams as $key => $value) { //create contact only if it does not exits in db $value['email'] = $value['email-Primary']; $value['check_permission'] = FALSE; $contact = CRM_Core_BAO_UFGroup::findContact($value, NULL, 'Individual'); if (!$contact) { $contact = CRM_Contact_BAO_Contact::createProfileContact($value, CRM_Core_DAO::$_nullArray); } // attempt to save activity targets $targetParams = array('activity_id' => $activityId, 'contact_id' => $contact, 'record_type_id' => $targetID); // See if it already exists $activityContact = new CRM_Activity_DAO_ActivityContact(); $activityContact->activity_id = $activityId; $activityContact->contact_id = $contact; $activityContact->find(TRUE); if (empty($activityContact->id)) { CRM_Activity_BAO_ActivityContact::create($targetParams); } } $mailParams['valueName'] = $message_template; return self::sendMail($contact_id, $mailParams); }