Пример #1
0
 /**
  * A hackish function needed to massage CRM_Contact_Form_$ctype::formRule()
  * object into a valid $params array for dedupe
  *
  * @param array $fields  contact structure from formRule()
  * @param string $ctype  contact type of the given contact
  *
  * @return array  valid $params array for dedupe
  */
 static function formatParams($fields, $ctype)
 {
     $flat = array();
     CRM_Utils_Array::flatten($fields, $flat);
     $replace_these = array('individual_prefix' => 'prefix_id', 'individual_suffix' => 'suffix_id', 'gender' => 'gender_id');
     //handle for individual_suffix, individual_prefix, gender
     foreach (array('individual_suffix', 'individual_prefix', 'gender') as $name) {
         if (CRM_Utils_Array::value($name, $fields)) {
             $flat[$replace_these[$name]] = $flat[$name];
             unset($flat[$name]);
         }
     }
     // handle {birth,deceased}_date
     foreach (array('birth_date', 'deceased_date') as $date) {
         if (CRM_Utils_Array::value($date, $fields)) {
             $flat[$date] = $fields[$date];
             if (is_array($flat[$date])) {
                 $flat[$date] = CRM_Utils_Date::format($flat[$date]);
             }
             $flat[$date] = CRM_Utils_Date::processDate($flat[$date]);
         }
     }
     if (CRM_Utils_Array::value('contact_source', $flat)) {
         $flat['source'] = $flat['contact_source'];
         unset($flat['contact_source']);
     }
     // handle preferred_communication_method
     if (array_key_exists('preferred_communication_method', $fields)) {
         $methods = array_intersect($fields['preferred_communication_method'], array('1'));
         $methods = array_keys($methods);
         sort($methods);
         if ($methods) {
             $flat['preferred_communication_method'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $methods) . CRM_Core_DAO::VALUE_SEPARATOR;
         }
     }
     // handle custom data
     $tree = CRM_Core_BAO_CustomGroup::getTree($ctype, CRM_Core_DAO::$_nullObject, NULL, -1);
     CRM_Core_BAO_CustomGroup::postProcess($tree, $fields, TRUE);
     foreach ($tree as $key => $cg) {
         if (!is_int($key)) {
             continue;
         }
         foreach ($cg['fields'] as $cf) {
             $flat[$cf['column_name']] = CRM_Utils_Array::value('data', $cf['customValue']);
         }
     }
     // if the key is dotted, keep just the last part of it
     foreach ($flat as $key => $value) {
         if (substr_count($key, '.')) {
             $last = array_pop(explode('.', $key));
             // make sure the first occurence is kept, not the last
             if (!isset($flat[$last])) {
                 $flat[$last] = $value;
             }
             unset($flat[$key]);
         }
     }
     // drop the -digit (and -Primary, for CRM-3902) postfixes (so event registration's $flat['email-5'] becomes $flat['email'])
     // FIXME: CRM-5026 should be fixed here; the below clobbers all address info; we should split off address fields and match
     // the -digit to civicrm_address.location_type_id and -Primary to civicrm_address.is_primary
     foreach ($flat as $key => $value) {
         $matches = array();
         if (preg_match('/(.*)-(\\d+|Primary)$/', $key, $matches)) {
             $flat[$matches[1]] = $value;
             unset($flat[$key]);
         }
     }
     $params = array();
     $supportedFields = CRM_Dedupe_BAO_RuleGroup::supportedFields($ctype);
     if (is_array($supportedFields)) {
         foreach ($supportedFields as $table => $fields) {
             if ($table == 'civicrm_address') {
                 // for matching on civicrm_address fields, we also need the location_type_id
                 $fields['location_type_id'] = '';
                 // FIXME: we also need to do some hacking for id and name fields, see CRM-3902’s comments
                 $fixes = array('address_name' => 'name', 'country' => 'country_id', 'state_province' => 'state_province_id', 'county' => 'county_id');
                 foreach ($fixes as $orig => $target) {
                     if (CRM_Utils_Array::value($orig, $flat)) {
                         $params[$table][$target] = $flat[$orig];
                     }
                 }
             }
             foreach ($fields as $field => $title) {
                 if (CRM_Utils_Array::value($field, $flat)) {
                     $params[$table][$field] = $flat[$field];
                 }
             }
         }
     }
     return $params;
 }
Пример #2
0
 /** 
  * Function to process the form 
  * 
  * @access public 
  * @return None 
  */
 function postProcess()
 {
     if ($this->_action & CRM_CORE_ACTION_DELETE) {
         require_once 'CRM/Contribute/BAO/Contribution.php';
         CRM_Contribute_BAO_Contribution::deleteContribution($this->_id);
         return;
     }
     // get the submitted form values.
     $formValues = $this->controller->exportValues($this->_name);
     //print_r($formValues);
     $config =& CRM_Core_Config::singleton();
     $params = array();
     $ids = array();
     $params['contact_id'] = $this->_contactID;
     $params['currency'] = $config->defaultCurrency;
     $fields = array('contribution_type_id', 'payment_instrument_id', 'non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount', 'trxn_id', 'invoice_id', 'cancel_reason', 'source', 'note');
     foreach ($fields as $f) {
         $params[$f] = CRM_Utils_Array::value($f, $formValues);
     }
     $dates = array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date');
     $currentTime = getDate();
     foreach ($dates as $d) {
         if (!CRM_Utils_System::isNull($formValues[$d])) {
             $formValues[$d]['H'] = $currentTime['hours'];
             $formValues[$d]['i'] = $currentTime['minutes'];
             $formValues[$d]['s'] = '00';
             $params[$d] = CRM_Utils_Date::format($formValues[$d]);
         }
     }
     $ids['contribution'] = $params['id'] = $this->_id;
     $contribution =& CRM_Contribute_BAO_Contribution::create($params, $ids);
     // do the updates/inserts
     CRM_Core_BAO_CustomGroup::postProcess($this->_groupTree, $formValues);
     //process premium
     if ($formValues['product_name'][0]) {
         require_once 'CRM/Contribute/DAO/ContributionProduct.php';
         $dao =& new CRM_Contribute_DAO_ContributionProduct();
         $dao->contribution_id = $contribution->id;
         $dao->product_id = $formValues['product_name'][0];
         $dao->fulfilled_date = CRM_Utils_Date::format($formValues['fulfilled_date']);
         $dao->product_option = $this->_options[$formValues['product_name'][0]][$formValues['product_name'][1]];
         if ($this->_premiumId) {
             $premoumDAO =& new CRM_Contribute_DAO_ContributionProduct();
             $premoumDAO->id = $this->_premiumId;
             $premoumDAO->find(true);
             if ($premoumDAO->product_id == $formValues['product_name'][0]) {
                 $dao->id = $this->_premiumId;
                 $premium = $dao->save();
             } else {
                 $premoumDAO->delete();
                 $premium = $dao->save();
             }
         } else {
             $premium = $dao->save();
         }
     }
     CRM_Core_BAO_CustomGroup::updateCustomData($this->_groupTree, 'Contribution', $contribution->id);
 }
Пример #3
0
 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 function postProcess()
 {
     if ($this->_action & CRM_CORE_ACTION_VIEW) {
         return;
     }
     if ($this->_action & CRM_CORE_ACTION_DELETE) {
         CRM_Core_BAO_Meeting::del($this->_id);
         CRM_Core_Session::setStatus(ts("Selected Meeting is deleted sucessfully."));
         return;
     }
     // store the submitted values in an array
     $params = $this->controller->exportValues($this->_name);
     $ids = array();
     $dateTime = $params['scheduled_date_time'];
     $dateTime = CRM_Utils_Date::format($dateTime);
     // store the date with proper format
     $params['scheduled_date_time'] = $dateTime;
     // store the contact id and current drupal user id
     $params['source_contact_id'] = $this->_userId;
     $params['target_entity_id'] = $this->_contactId;
     $params['target_entity_table'] = 'civicrm_contact';
     //set parent id if exists for follow up activities
     if ($this->_pid) {
         $params['parent_id'] = $this->_pid;
     }
     if ($this->_action & CRM_CORE_ACTION_UPDATE) {
         $ids['meeting'] = $this->_id;
     }
     $meeting = CRM_Core_BAO_Meeting::add($params, $ids);
     CRM_Core_BAO_CustomGroup::postProcess($this->_groupTree, $params);
     // do the updates/inserts
     CRM_Core_BAO_CustomGroup::updateCustomData($this->_groupTree, 'Meeting', $meeting->id);
     if ($meeting->status == 'Completed') {
         // we need to insert an activity history record here
         $params = array('entity_table' => 'civicrm_contact', 'entity_id' => $this->_contactId, 'activity_type' => ts('Meeting'), 'module' => 'CiviCRM', 'callback' => 'CRM_Activity_Form_Meeting::showMeetingDetails', 'activity_id' => $meeting->id, 'activity_summary' => $meeting->subject, 'activity_date' => $meeting->scheduled_date_time);
         if (is_a(crm_create_activity_history($params), 'CRM_Core_Error')) {
             return false;
         }
     }
     if ($meeting->status == 'Completed') {
         CRM_Core_Session::setStatus(ts('Meeting "%1" has been logged to Activity History.', array(1 => $meeting->subject)));
     } else {
         CRM_Core_Session::setStatus(ts('Meeting "%1" has been saved.', array(1 => $meeting->subject)));
     }
 }
Пример #4
0
 /**
  * Form submission of new/edit contact is processed.
  *
  * @access public
  * @return None
  */
 function postProcess()
 {
     // check if dedupe button, if so return.
     $buttonName = $this->controller->getButtonName();
     if ($buttonName == $this->_dedupeButtonName) {
         return;
     }
     // store the submitted values in an array
     $params = $this->controller->exportValues($this->_name);
     // action is taken depending upon the mode
     $ids = array();
     if ($this->_action & CRM_CORE_ACTION_UPDATE) {
         // if update get all the valid database ids
         // from the session
         $ids = $this->get('ids');
     }
     $params['contact_type'] = $this->_contactType;
     $contact = CRM_Contact_BAO_Contact::create($params, $ids, CRM_CONTACT_FORM_EDIT_LOCATION_BLOCKS);
     //add contact to gruoup
     CRM_Contact_BAO_GroupContact::create($params['group'], $params['contact_id']);
     //add contact to tags
     CRM_Core_BAO_EntityTag::create($params['tag'], $params['contact_id']);
     // here we replace the user context with the url to view this contact
     $config =& CRM_Core_Config::singleton();
     $session =& CRM_Core_Session::singleton();
     CRM_Core_Session::setStatus(ts('Your %1 contact record has been saved.', array(1 => $contact->contact_type_display)));
     $buttonName = $this->controller->getButtonName();
     if ($buttonName == $this->getButtonName('next', 'new')) {
         // add the recently viewed contact
         list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($contact->id);
         CRM_Utils_Recent::add($displayName, CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $contact->id), $contactImage, $contact->id);
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/add' . $contact->contact_type[0], 'reset=1&c_type=' . $contact->contact_type));
     } else {
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $contact->id));
     }
     CRM_Core_BAO_CustomGroup::postProcess($this->_groupTree, $params);
     // do the updates/inserts
     CRM_Core_BAO_CustomGroup::updateCustomData($this->_groupTree, $this->_contactType, $contact->id);
 }
Пример #5
0
 /**
  * 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']);
     }
 }
Пример #6
0
 /**
  * Process the form when submitted
  *
  * @return void
  * @access public
  */
 function postProcess()
 {
     if ($this->_action & CRM_CORE_ACTION_DELETE) {
         CRM_Contact_BAO_Group::discard($this->_id);
         CRM_Core_Session::setStatus(ts('The Group "%1" has been deleted.', array(1 => $this->_title)));
     } else {
         // store the submitted values in an array
         $params = $this->exportValues();
         $params['domain_id'] = CRM_Core_Config::domainID();
         $params['is_active'] = 1;
         if ($this->_action & CRM_CORE_ACTION_UPDATE) {
             $params['id'] = $this->_id;
         }
         $group =& CRM_Contact_BAO_Group::create($params);
         // do the updates/inserts
         CRM_Core_BAO_CustomGroup::postProcess($this->_groupTree, $params);
         CRM_Core_BAO_CustomGroup::updateCustomData($this->_groupTree, 'Group', $group->id);
         CRM_Core_Session::setStatus(ts('The Group "%1" has been saved.', array(1 => $group->title)));
         /*
          * Add context to the session, in case we are adding members to the group
          */
         if ($this->_action & CRM_CORE_ACTION_ADD) {
             $this->set('context', 'amtg');
             $this->set('amtgID', $group->id);
             $session =& CRM_Core_Session::singleton();
             $session->pushUserContext(CRM_Utils_System::url('civicrm/group/search', 'reset=1&force=1&context=smog&gid=' . $group->id));
         }
     }
 }
Пример #7
0
 /**
  * Process the user submitted custom data values.
  *
  * @access public
  * @return void
  */
 function postProcess()
 {
     // Get the form values and groupTree
     $fv = $this->controller->exportValues($this->_name);
     CRM_Core_BAO_CustomGroup::postProcess($this->_groupTree, $fv);
     // do the updates/inserts
     CRM_Core_BAO_CustomGroup::updateCustomData($this->_groupTree, $this->_entityType, $this->_tableId);
 }