Beispiel #1
0
 /**
  * Handle process after the confirmation of payment by User.
  *
  * @param int $contactID
  * @param null $contribution
  * @param null $payment
  */
 public function confirmPostProcess($contactID = NULL, $contribution = NULL, $payment = NULL)
 {
     // add/update contact information
     $fields = array();
     unset($this->_params['note']);
     //to avoid conflict overwrite $this->_params
     $this->_params = $this->get('value');
     //get the amount of primary participant
     if (!empty($this->_params['is_primary'])) {
         $this->_params['fee_amount'] = $this->get('primaryParticipantAmount');
     }
     // add participant record
     $participant = CRM_Event_Form_Registration::addParticipant($this, $contactID);
     $this->_participantIDS[] = $participant->id;
     //setting register_by_id field and primaryContactId
     if (!empty($this->_params['is_primary'])) {
         $this->set('registerByID', $participant->id);
         $this->set('primaryContactId', $contactID);
         // CRM-10032
         $this->processFirstParticipant($participant->id);
     }
     CRM_Core_BAO_CustomValueTable::postProcess($this->_params, 'civicrm_participant', $participant->id, 'Participant');
     $createPayment = CRM_Utils_Array::value('amount', $this->_params, 0) != 0 ? TRUE : FALSE;
     // force to create zero amount payment, CRM-5095
     // we know the amout is zero since createPayment is false
     if (!$createPayment && (isset($contribution) && $contribution->id) && $this->_priceSetId && $this->_lineItem) {
         $createPayment = TRUE;
     }
     if ($createPayment && $this->_values['event']['is_monetary'] && !empty($this->_params['contributionID'])) {
         $paymentParams = array('participant_id' => $participant->id, 'contribution_id' => $contribution->id);
         $ids = array();
         $paymentPartcipant = CRM_Event_BAO_ParticipantPayment::create($paymentParams, $ids);
     }
     //set only primary participant's params for transfer checkout.
     // The concept of contributeMode is deprecated.
     if (($this->_contributeMode == 'checkout' || $this->_contributeMode == 'notify') && !empty($this->_params['is_primary'])) {
         $this->_params['participantID'] = $participant->id;
         $this->set('primaryParticipant', $this->_params);
     }
     $this->assign('action', $this->_action);
     // create CMS user
     if (!empty($this->_params['cms_create_account'])) {
         $this->_params['contactID'] = $contactID;
         if (array_key_exists('email-5', $this->_params)) {
             $mail = 'email-5';
         } else {
             foreach ($this->_params as $name => $dontCare) {
                 if (substr($name, 0, 5) == 'email') {
                     $mail = $name;
                     break;
                 }
             }
         }
         // we should use primary email for
         // 1. free event registration.
         // 2. pay later participant.
         // 3. waiting list participant.
         // 4. require approval participant.
         if (!empty($this->_params['is_pay_later']) || $this->_allowWaitlist || $this->_requireApproval || empty($this->_values['event']['is_monetary'])) {
             $mail = 'email-Primary';
         }
         if (!CRM_Core_BAO_CMSUser::create($this->_params, $mail)) {
             CRM_Core_Error::statusBounce(ts('Your profile is not saved and Account is not created.'));
         }
     }
 }
Beispiel #2
0
 /**
  * Post process function.
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $params = $this->exportValues();
     CRM_Core_BAO_CMSUser::create($params, 'email');
     CRM_Core_Session::setStatus('', ts('User Added'), 'success');
 }
Beispiel #3
0
 static function createCMSUser(&$params, $contactID, $mail)
 {
     // lets ensure we only create one CMS user
     static $created = false;
     if ($created) {
         return;
     }
     $created = true;
     if (CRM_Utils_Array::value('cms_create_account', $params)) {
         $params['contactID'] = $contactID;
         require_once 'CRM/Core/BAO/CMSUser.php';
         if (!CRM_Core_BAO_CMSUser::create($params, $mail)) {
             CRM_Core_Error::statusBounce(ts('Your profile is not saved and Account is not created.'));
         }
     }
 }
Beispiel #4
0
 /**
  * Process the user submitted custom data values.
  *
  *
  * @return void
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     //if the delete record button is clicked
     if ($this->_deleteButtonName) {
         if (!empty($_POST[$this->_deleteButtonName]) && $this->_recordId) {
             $filterParams['id'] = $this->_customGroupId;
             $returnProperties = array('is_multiple', 'table_name');
             CRM_Core_DAO::commonRetrieve("CRM_Core_DAO_CustomGroup", $filterParams, $returnValues, $returnProperties);
             if (!empty($returnValues['is_multiple'])) {
                 if ($tableName = CRM_Utils_Array::value('table_name', $returnValues)) {
                     $sql = "DELETE FROM {$tableName} WHERE id = %1 AND entity_id = %2";
                     $sqlParams = array(1 => array($this->_recordId, 'Integer'), 2 => array($this->_id, 'Integer'));
                     CRM_Core_DAO::executeQuery($sql, $sqlParams);
                     CRM_Core_Session::setStatus(ts('Your record has been deleted.'), ts('Deleted'), 'success');
                 }
             }
             return;
         }
     }
     CRM_Utils_Hook::processProfile($this->_ufGroup['name']);
     if (!empty($params['image_URL'])) {
         CRM_Contact_BAO_Contact::processImageParams($params);
     }
     $greetingTypes = array('addressee' => 'addressee_id', 'email_greeting' => 'email_greeting_id', 'postal_greeting' => 'postal_greeting_id');
     $details = array();
     if ($this->_id) {
         $contactDetails = CRM_Contact_BAO_Contact::getHierContactDetails($this->_id, $greetingTypes);
         $details = $contactDetails[0][$this->_id];
     }
     if (!(!empty($details['addressee_id']) || !empty($details['email_greeting_id']) || CRM_Utils_Array::value('postal_greeting_id', $details))) {
         $profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid);
         //Though Profile type is contact we need
         //Individual/Household/Organization for setting Greetings.
         if ($profileType == 'Contact') {
             $profileType = 'Individual';
             //if we editing Household/Organization.
             if ($this->_id) {
                 $profileType = CRM_Contact_BAO_Contact::getContactType($this->_id);
             }
         }
         if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
             $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
         }
         foreach ($greetingTypes as $key => $value) {
             if (!array_key_exists($key, $params)) {
                 $params[$key] = CRM_Contact_BAO_Contact_Utils::defaultGreeting($profileType, $key);
             }
         }
     }
     $transaction = new CRM_Core_Transaction();
     //used to send subscribe mail to the group which user want.
     //if the profile double option in is enabled
     $mailingType = array();
     $result = NULL;
     foreach ($params as $name => $values) {
         if (substr($name, 0, 6) == 'email-') {
             $result['email'] = $values;
         }
     }
     //array of group id, subscribed by contact
     $contactGroup = array();
     if (!empty($params['group']) && CRM_Core_BAO_UFGroup::isProfileDoubleOptin()) {
         $groupSubscribed = array();
         if (!empty($result['email'])) {
             if ($this->_id) {
                 $contactGroups = new CRM_Contact_DAO_GroupContact();
                 $contactGroups->contact_id = $this->_id;
                 $contactGroups->status = 'Added';
                 $contactGroups->find();
                 $contactGroup = array();
                 while ($contactGroups->fetch()) {
                     $contactGroup[] = $contactGroups->group_id;
                     $groupSubscribed[$contactGroups->group_id] = 1;
                 }
             }
             foreach ($params['group'] as $key => $val) {
                 if (!$val) {
                     unset($params['group'][$key]);
                     continue;
                 }
                 $groupTypes = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $key, 'group_type', 'id');
                 $groupType = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($groupTypes, 1, -1));
                 //filter group of mailing type and unset it from params
                 if (in_array(2, $groupType)) {
                     //if group is already subscribed , ignore it
                     $groupExist = CRM_Utils_Array::key($key, $contactGroup);
                     if (!isset($groupExist)) {
                         $mailingType[] = $key;
                         unset($params['group'][$key]);
                     }
                 }
             }
         }
     }
     $addToGroupId = CRM_Utils_Array::value('add_to_group_id', $this->_ufGroup);
     if (!empty($addToGroupId)) {
         //run same check whether group is a mailing list
         $groupTypes = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $addToGroupId, 'group_type', 'id');
         $groupType = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($groupTypes, 1, -1));
         //filter group of mailing type and unset it from params
         if (in_array(2, $groupType) && !empty($result['email']) && CRM_Core_BAO_UFGroup::isProfileAddToGroupDoubleOptin()) {
             if (!count($contactGroup)) {
                 //array of group id, subscribed by contact
                 $contactGroup = array();
                 if ($this->_id) {
                     $contactGroups = new CRM_Contact_DAO_GroupContact();
                     $contactGroups->contact_id = $this->_id;
                     $contactGroups->status = 'Added';
                     $contactGroups->find();
                     $contactGroup = array();
                     while ($contactGroups->fetch()) {
                         $contactGroup[] = $contactGroups->group_id;
                         $groupSubscribed[$contactGroups->group_id] = 1;
                     }
                 }
             }
             //if group is already subscribed , ignore it
             $groupExist = CRM_Utils_Array::key($addToGroupId, $contactGroup);
             if (!isset($groupExist)) {
                 $mailingType[] = $addToGroupId;
                 $addToGroupId = NULL;
             }
         } else {
             // since we are directly adding contact to group lets unset it from mailing
             if ($key = array_search($addToGroupId, $mailingType)) {
                 unset($mailingType[$key]);
             }
         }
     }
     if ($this->_grid) {
         $params['group'] = $groupSubscribed;
     }
     // commenting below code, since we potentially
     // triggered maximum name field formatting cases during CRM-4430.
     // CRM-4343
     // $params['preserveDBName'] = true;
     $profileFields = $this->_fields;
     if ($this->_mode & self::MODE_EDIT && $this->_activityId && $this->_isContactActivityProfile) {
         $profileFields = $activityParams = array();
         foreach ($this->_fields as $fieldName => $field) {
             if (CRM_Utils_Array::value('field_type', $field) == 'Activity') {
                 if (isset($params[$fieldName])) {
                     $activityParams[$fieldName] = $params[$fieldName];
                 }
                 if (isset($params['activity_date_time'])) {
                     $activityParams['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']);
                 }
                 if (!empty($params[$fieldName]) && isset($params["{$fieldName}_id"])) {
                     $activityParams[$fieldName] = $params["{$fieldName}_id"];
                 }
             } else {
                 $profileFields[$fieldName] = $field;
             }
         }
         if (!empty($activityParams)) {
             $activityParams['version'] = 3;
             $activityParams['id'] = $this->_activityId;
             $activityParams['skipRecentView'] = TRUE;
             civicrm_api('Activity', 'create', $activityParams);
         }
     }
     if ($this->_multiRecord && $this->_recordId && $this->_multiRecordFields && $this->_recordExists) {
         $params['customRecordValues'][$this->_recordId] = array_keys($this->_multiRecordFields);
     }
     $this->_id = CRM_Contact_BAO_Contact::createProfileContact($params, $profileFields, $this->_id, $addToGroupId, $this->_gid, $this->_ctype, TRUE);
     //mailing type group
     if (!empty($mailingType)) {
         // we send in the contactID so we match the same groups and are exact, rather than relying on email
         // CRM-8710
         CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($mailingType, $result, $this->_id, 'profile');
     }
     $ufGroups = array();
     if ($this->_gid) {
         $ufGroups[$this->_gid] = 1;
     } elseif ($this->_mode == self::MODE_REGISTER) {
         $ufGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup('User Registration');
     }
     foreach ($ufGroups as $gId => $val) {
         if ($notify = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify')) {
             $values = CRM_Core_BAO_UFGroup::checkFieldsEmptyValues($gId, $this->_id, NULL);
             CRM_Core_BAO_UFGroup::commonSendMail($this->_id, $values);
         }
     }
     //create CMS user (if CMS user option is selected in profile)
     if (!empty($params['cms_create_account']) && $this->_mode == self::MODE_CREATE) {
         $params['contactID'] = $this->_id;
         if (!CRM_Core_BAO_CMSUser::create($params, $this->_mail)) {
             CRM_Core_Session::setStatus(ts('Your profile is not saved and Account is not created.'), ts('Profile Error'), 'error');
             CRM_Core_Error::debug_log_message("Rolling back transaction as CMSUser Create failed in Profile_Form for contact " . $params['contactID']);
             $transaction->rollback();
             return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/profile/create', 'reset=1&gid=' . $this->_gid));
         }
     }
     $transaction->commit();
 }
Beispiel #5
0
 /**
  * @param array $params
  * @param int $contactID
  * @param $mail
  */
 public static function createCMSUser(&$params, $contactID, $mail)
 {
     // lets ensure we only create one CMS user
     static $created = FALSE;
     if ($created) {
         return;
     }
     $created = TRUE;
     if (!empty($params['cms_create_account'])) {
         $params['contactID'] = $contactID;
         if (!CRM_Core_BAO_CMSUser::create($params, $mail)) {
             CRM_Core_Error::statusBounce(ts('Your profile is not saved and Account is not created.'));
         }
     }
 }
Beispiel #6
0
 /**
  * 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();
 }
Beispiel #7
0
 /**  
  * Function to handle  process after the confirmation of payment by User
  *  
  * @return None  
  * @access public  
  */
 function confirmPostProcess($contactID = null, $contribution = null, $payment = null)
 {
     // add/update contact information
     $fields = array();
     unset($this->_params['note']);
     //to avoid conflict overwrite $this->_params
     $this->_params = $this->get('value');
     // create CMS user
     if (CRM_Utils_Array::value('cms_create_account', $this->_params)) {
         $this->_params['contactID'] = $contactID;
         $mail = 'email-5';
         // we should use primary email for
         // 1. free event registration.
         // 2. pay later participant.
         // 3. waiting list participant.
         // 4. require approval participant.
         if (CRM_Utils_Array::value('is_pay_later', $this->_params) || $this->_allowWaitlist || $this->_requireApproval || !CRM_Utils_Array::value('is_monetary', $this->_values['event'])) {
             $mail = 'email-Primary';
         }
         require_once "CRM/Core/BAO/CMSUser.php";
         if (!CRM_Core_BAO_CMSUser::create($this->_params, $mail)) {
             CRM_Core_Error::statusBounce(ts('Your profile is not saved and Account is not created.'));
         }
     }
     //get the amount of primary participant
     if (CRM_Utils_Array::value('is_primary', $this->_params)) {
         $this->_params['fee_amount'] = $this->get('primaryParticipantAmount');
     }
     // add participant record
     $participant = $this->addParticipant($this->_params, $contactID);
     $this->_participantIDS[] = $participant->id;
     //setting register_by_id field and primaryContactId
     if (CRM_Utils_Array::value('is_primary', $this->_params)) {
         $this->set('registerByID', $participant->id);
         $this->set('primaryContactId', $contactID);
     }
     require_once 'CRM/Core/BAO/CustomValueTable.php';
     CRM_Core_BAO_CustomValueTable::postProcess($this->_params, CRM_Core_DAO::$_nullArray, 'civicrm_participant', $participant->id, 'Participant');
     $createPayment = $this->_params['amount'] != 0 ? true : false;
     // force to create zero amount payment, CRM-5095
     if (!$createPayment && $contribution->id && $this->_params['amount'] == 0 && $this->_priceSetId && $this->_lineItem) {
         $createPayment = true;
     }
     if ($createPayment && $this->_values['event']['is_monetary'] && CRM_Utils_Array::value('contributionID', $this->_params)) {
         require_once 'CRM/Event/BAO/ParticipantPayment.php';
         $paymentParams = array('participant_id' => $participant->id, 'contribution_id' => $contribution->id);
         $ids = array();
         $paymentPartcipant = CRM_Event_BAO_ParticipantPayment::create($paymentParams, $ids);
     }
     //set only primary participant's params for transfer checkout.
     if (($this->_contributeMode == 'checkout' || $this->_contributeMode == 'notify') && CRM_Utils_Array::value('is_primary', $this->_params)) {
         $this->_params['participantID'] = $participant->id;
         $this->set('primaryParticipant', $this->_params);
     }
     $this->assign('action', $this->_action);
 }
Beispiel #8
0
 /**
  * Process the user submitted custom data values.
  *
  * @access public
  * @return void
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     if (CRM_Utils_Array::value('image_URL', $params)) {
         CRM_Contact_BAO_Contact::processImageParams($params);
     }
     $greetingTypes = array('addressee' => 'addressee_id', 'email_greeting' => 'email_greeting_id', 'postal_greeting' => 'postal_greeting_id');
     if ($this->_id) {
         $contactDetails = CRM_Contact_BAO_Contact::getHierContactDetails($this->_id, $greetingTypes);
         $details = $contactDetails[0][$this->_id];
     }
     if (!(CRM_Utils_Array::value('addressee_id', $details) || CRM_Utils_Array::value('email_greeting_id', $details) || CRM_Utils_Array::value('postal_greeting_id', $details))) {
         $profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid);
         //Though Profile type is contact we need
         //Individual/Household/Organization for setting Greetings.
         if ($profileType == 'Contact') {
             $profileType = 'Individual';
             //if we editing Household/Organization.
             if ($this->_id) {
                 $profileType = CRM_Contact_BAO_Contact::getContactType($this->_id);
             }
         }
         if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
             $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
         }
         $contactTypeFilters = array(1 => 'Individual', 2 => 'Household', 3 => 'Organization');
         $filter = CRM_Utils_Array::key($profileType, $contactTypeFilters);
         if ($filter) {
             foreach ($greetingTypes as $key => $value) {
                 if (!array_key_exists($key, $params)) {
                     $defaultGreetingTypeId = CRM_Core_OptionGroup::values($key, null, null, null, "AND is_default =1\n                                                                               AND (filter = \n                                                                               {$filter} OR \n                                                                               filter = 0 )", 'value');
                     $params[$key] = key($defaultGreetingTypeId);
                 }
             }
         }
         if ($profileType == 'Organization') {
             unset($params['email_greeting'], $params['postal_greeting']);
         }
     }
     if ($this->_mode == self::MODE_REGISTER) {
         require_once 'CRM/Core/BAO/Address.php';
         CRM_Core_BAO_Address::setOverwrite(false);
     }
     require_once 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     //used to send subcribe mail to the group which user want.
     //if the profile double option in is enabled
     $mailingType = array();
     $config = CRM_Core_Config::singleton();
     if ($config->profileDoubleOptIn && CRM_Utils_Array::value('group', $params)) {
         $result = null;
         foreach ($params as $name => $values) {
             if (substr($name, 0, 6) == 'email-') {
                 $result['email'] = $values;
             }
         }
         $groupSubscribed = array();
         if (CRM_Utils_Array::value('email', $result)) {
             require_once 'CRM/Contact/DAO/Group.php';
             //array of group id, subscribed by contact
             $contactGroup = array();
             if ($this->_id) {
                 $contactGroups = new CRM_Contact_DAO_GroupContact();
                 $contactGroups->contact_id = $this->_id;
                 $contactGroups->status = 'Added';
                 $contactGroups->find();
                 $contactGroup = array();
                 while ($contactGroups->fetch()) {
                     $contactGroup[] = $contactGroups->group_id;
                     $groupSubscribed[$contactGroups->group_id] = 1;
                 }
             }
             foreach ($params['group'] as $key => $val) {
                 if (!$val) {
                     unset($params['group'][$key]);
                     continue;
                 }
                 $groupTypes = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $key, 'group_type', 'id');
                 $groupType = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, substr($groupTypes, 1, -1));
                 //filter group of mailing type and unset it from params
                 if (in_array(2, $groupType)) {
                     //if group is already subscribed , ignore it
                     $groupExist = CRM_Utils_Array::key($key, $contactGroup);
                     if (!isset($groupExist)) {
                         $mailingType[] = $key;
                         unset($params['group'][$key]);
                     }
                 }
             }
         }
     }
     if (CRM_Utils_Array::value('add_to_group', $params)) {
         $addToGroupId = $params['add_to_group'];
         // since we are directly adding contact to group lets unset it from mailing
         if ($key = array_search($addToGroupId, $mailingType)) {
             unset($mailingType[$key]);
         }
     }
     if ($this->_grid) {
         $params['group'] = $groupSubscribed;
     }
     // commenting below code, since we potentially
     // triggered maximum name field formatting cases during CRM-4430.
     // CRM-4343
     // $params['preserveDBName'] = true;
     $this->_id = CRM_Contact_BAO_Contact::createProfileContact($params, $this->_fields, $this->_id, $this->_addToGroupID, $this->_gid, $this->_ctype, true);
     //mailing type group
     if (!empty($mailingType)) {
         require_once 'CRM/Mailing/Event/BAO/Subscribe.php';
         CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($mailingType, $result);
     }
     require_once 'CRM/Core/BAO/UFGroup.php';
     $ufGroups = array();
     if ($this->_gid) {
         $ufGroups[$this->_gid] = 1;
     } else {
         if ($this->_mode == self::MODE_REGISTER) {
             $ufGroups =& CRM_Core_BAO_UFGroup::getModuleUFGroup('User Registration');
         }
     }
     foreach ($ufGroups as $gId => $val) {
         if ($notify = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify')) {
             $values = CRM_Core_BAO_UFGroup::checkFieldsEmptyValues($gId, $this->_id, null);
             CRM_Core_BAO_UFGroup::commonSendMail($this->_id, $values);
         }
     }
     //create CMS user (if CMS user option is selected in profile)
     if (CRM_Utils_Array::value('cms_create_account', $params) && $this->_mode == self::MODE_CREATE) {
         $params['contactID'] = $this->_id;
         require_once "CRM/Core/BAO/CMSUser.php";
         if (!CRM_Core_BAO_CMSUser::create($params, $this->_mail)) {
             CRM_Core_Session::setStatus(ts('Your profile is not saved and Account is not created.'));
             $transaction->rollback();
             return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/profile/create', 'reset=1&gid=' . $this->_gid));
         }
     }
     $transaction->commit();
 }