示例#1
0
 /**
  * Process form submission.
  *
  * This function is also accessed by a unit test.
  */
 protected function submit()
 {
     $this->storeContactFields($this->_params);
     $this->beginPostProcess();
     $now = CRM_Utils_Date::getToday(NULL, 'YmdHis');
     $this->convertDateFieldsToMySQL($this->_params);
     $this->assign('receive_date', $this->_params['receive_date']);
     $this->processBillingAddress();
     list($userName) = CRM_Contact_BAO_Contact_Location::getEmailDetails(CRM_Core_Session::singleton()->get('userID'));
     $this->_params['total_amount'] = CRM_Utils_Array::value('total_amount', $this->_params, CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'minimum_fee'));
     $this->_membershipId = $this->_id;
     $customFieldsFormatted = CRM_Core_BAO_CustomField::postProcess($this->_params, $this->_id, 'Membership');
     if (empty($this->_params['financial_type_id'])) {
         $this->_params['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'financial_type_id');
     }
     $contributionRecurID = NULL;
     $this->assign('membershipID', $this->_id);
     $this->assign('contactID', $this->_contactID);
     $this->assign('module', 'Membership');
     $this->assign('receiptType', 'membership renewal');
     $this->_params['currencyID'] = CRM_Core_Config::singleton()->defaultCurrency;
     $this->_params['invoice_id'] = $this->_params['invoiceID'] = md5(uniqid(rand(), TRUE));
     if (!empty($this->_params['send_receipt'])) {
         $this->_params['receipt_date'] = $now;
         $this->assign('receipt_date', CRM_Utils_Date::mysqlToIso($this->_params['receipt_date']));
     } else {
         $this->_params['receipt_date'] = NULL;
     }
     if ($this->_mode) {
         $this->_params['register_date'] = $now;
         $this->_params['description'] = ts("Contribution submitted by a staff person using member's credit card for renewal");
         $this->_params['amount'] = $this->_params['total_amount'];
         // 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 passed params
         // so we copy stuff over to first_name etc.
         $paymentParams = $this->_params;
         if (!empty($this->_params['send_receipt'])) {
             $paymentParams['email'] = $this->_contributorEmail;
         }
         $paymentParams['contactID'] = $this->_contributorContactID;
         CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, TRUE);
         $payment = $this->_paymentProcessor['object'];
         if (!empty($this->_params['auto_renew'])) {
             $contributionRecurParams = $this->processRecurringContribution($paymentParams);
             $contributionRecurID = $contributionRecurParams['contributionRecurID'];
             $paymentParams = array_merge($paymentParams, $contributionRecurParams);
         }
         $result = $payment->doPayment($paymentParams);
         $this->_params = array_merge($this->_params, $result);
         $this->_params['contribution_status_id'] = $result['payment_status_id'];
         $this->_params['trxn_id'] = $result['trxn_id'];
         $this->_params['payment_instrument_id'] = 1;
         $this->_params['is_test'] = $this->_mode == 'live' ? 0 : 1;
         $this->set('params', $this->_params);
         $this->assign('trxn_id', $result['trxn_id']);
     }
     $renewalDate = !empty($this->_params['renewal_date']) ? $renewalDate = CRM_Utils_Date::processDate($this->_params['renewal_date']) : NULL;
     // check for test membership.
     $isTestMembership = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_membershipId, 'is_test');
     // chk for renewal for multiple terms CRM-8750
     $numRenewTerms = 1;
     if (is_numeric(CRM_Utils_Array::value('num_terms', $this->_params))) {
         $numRenewTerms = $this->_params['num_terms'];
     }
     //if contribution status is pending then set pay later
     $this->_params['is_pay_later'] = FALSE;
     if ($this->_params['contribution_status_id'] == array_search('Pending', CRM_Contribute_PseudoConstant::contributionStatus())) {
         $this->_params['is_pay_later'] = 1;
     }
     // These variable sets prior to renewMembership may not be required for this form. They were in
     // a function this form shared with other forms.
     $membershipSource = NULL;
     if (!empty($this->_params['membership_source'])) {
         $membershipSource = $this->_params['membership_source'];
     }
     $isPending = $this->_params['contribution_status_id'] == 2 ? TRUE : FALSE;
     list($renewMembership) = CRM_Member_BAO_Membership::renewMembership($this->_contactID, $this->_params['membership_type_id'][1], $isTestMembership, $renewalDate, NULL, $customFieldsFormatted, $numRenewTerms, $this->_membershipId, $isPending, $contributionRecurID, $membershipSource, $this->_params['is_pay_later'], CRM_Utils_Array::value('campaign_id', $this->_params));
     $this->endDate = CRM_Utils_Date::processDate($renewMembership->end_date);
     $this->membershipTypeName = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $renewMembership->membership_type_id, 'name');
     if (!empty($this->_params['record_contribution']) || $this->_mode) {
         // set the source
         $this->_params['contribution_source'] = "{$this->membershipTypeName} Membership: Offline membership renewal (by {$userName})";
         //create line items
         $lineItem = array();
         $this->_params = $this->setPriceSetParameters($this->_params);
         CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], $this->_params, $lineItem[$this->_priceSetId]);
         //CRM-11529 for quick config backoffice transactions
         //when financial_type_id is passed in form, update the
         //line items with the financial type selected in form
         if ($submittedFinancialType = CRM_Utils_Array::value('financial_type_id', $this->_params)) {
             foreach ($lineItem[$this->_priceSetId] as &$li) {
                 $li['financial_type_id'] = $submittedFinancialType;
             }
         }
         if (!empty($lineItem)) {
             $this->_params['lineItems'] = $lineItem;
             $this->_params['processPriceSet'] = TRUE;
         }
         //assign contribution contact id to the field expected by recordMembershipContribution
         if ($this->_contributorContactID != $this->_contactID) {
             $this->_params['contribution_contact_id'] = $this->_contributorContactID;
             if (!empty($this->_params['soft_credit_type_id'])) {
                 $this->_params['soft_credit'] = array('soft_credit_type_id' => $this->_params['soft_credit_type_id'], 'contact_id' => $this->_contactID);
             }
         }
         $this->_params['contact_id'] = $this->_contactID;
         //recordMembershipContribution receives params as a reference & adds one variable. This is
         // not a great pattern & ideally it would not receive as a reference. We assign our params as a
         // temporary variable to avoid e-notice & to make it clear to future refactorer that
         // this function is NOT reliant on that var being set
         $temporaryParams = array_merge($this->_params, array('membership_id' => $renewMembership->id));
         CRM_Member_BAO_Membership::recordMembershipContribution($temporaryParams);
     }
     if (!empty($this->_params['send_receipt'])) {
         $receiptFrom = $this->_params['from_email_address'];
         if (!empty($this->_params['payment_instrument_id'])) {
             $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
             $this->_params['paidBy'] = $paymentInstrument[$this->_params['payment_instrument_id']];
         }
         //get the group Tree
         $this->_groupTree = CRM_Core_BAO_CustomGroup::getTree('Membership', $this, $this->_id, FALSE, $this->_memType);
         // retrieve custom data
         $customFields = $customValues = $fo = array();
         foreach ($this->_groupTree as $groupID => $group) {
             if ($groupID == 'info') {
                 continue;
             }
             foreach ($group['fields'] as $k => $field) {
                 $field['title'] = $field['label'];
                 $customFields["custom_{$k}"] = $field;
             }
         }
         $members = array(array('member_id', '=', $this->_membershipId, 0, 0));
         // check whether its a test drive
         if ($this->_mode == 'test') {
             $members[] = array('member_test', '=', 1, 0, 0);
         }
         CRM_Core_BAO_UFGroup::getValues($this->_contactID, $customFields, $customValues, FALSE, $members);
         $this->assign_by_ref('formValues', $this->_params);
         if (!empty($this->_params['contribution_id'])) {
             $this->assign('contributionID', $this->_params['contribution_id']);
         }
         $this->assign('membership_name', CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $renewMembership->membership_type_id));
         $this->assign('customValues', $customValues);
         $this->assign('mem_start_date', CRM_Utils_Date::customFormat($renewMembership->start_date));
         $this->assign('mem_end_date', CRM_Utils_Date::customFormat($renewMembership->end_date));
         if ($this->_mode) {
             // assign the address formatted up for display
             $addressParts = array("street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "state_province-{$this->_bltID}", "country-{$this->_bltID}");
             $addressFields = array();
             foreach ($addressParts as $part) {
                 list($n) = explode('-', $part);
                 if (isset($this->_params['billing_' . $part])) {
                     $addressFields[$n] = $this->_params['billing_' . $part];
                 }
             }
             $this->assign('address', CRM_Utils_Address::format($addressFields));
             $this->assign('contributeMode', 'direct');
             $this->assign('isAmountzero', 0);
             $this->assign('is_pay_later', 0);
             $this->assign('isPrimary', 1);
             $this->assign('receipt_text_renewal', $this->_params['receipt_text']);
             if ($this->_mode == 'test') {
                 $this->assign('action', '1024');
             }
         }
         list($this->isMailSent) = CRM_Core_BAO_MessageTemplate::sendTemplate(array('groupName' => 'msg_tpl_workflow_membership', 'valueName' => 'membership_offline_receipt', 'contactId' => $this->_receiptContactId, 'from' => $receiptFrom, 'toName' => $this->_contributorDisplayName, 'toEmail' => $this->_contributorEmail, 'isTest' => $this->_mode == 'test'));
     }
 }
示例#2
0
 /**
  * Given a contact id and a group id, returns the field values from the db
  * for this group and notify email only if group's notify field is
  * set and field values are not empty
  *
  * @param int $gid
  *   Group id.
  * @param int $cid
  *   Contact id.
  * @param array $params
  * @param bool $skipCheck
  *
  * @return array
  */
 public function checkFieldsEmptyValues($gid, $cid, $params, $skipCheck = FALSE)
 {
     if ($gid) {
         if (CRM_Core_BAO_UFGroup::filterUFGroups($gid, $cid) || $skipCheck) {
             $values = array();
             $fields = CRM_Core_BAO_UFGroup::getFields($gid, FALSE, CRM_Core_Action::VIEW);
             CRM_Core_BAO_UFGroup::getValues($cid, $fields, $values, FALSE, $params, TRUE);
             $email = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gid, 'notify');
             if (!empty($values) && !empty($email)) {
                 $val = array('id' => $gid, 'values' => $values, 'email' => $email);
                 return $val;
             }
         }
     }
     return NULL;
 }
 /**
  * Add the custom fields for contribution page (ie profile)
  *
  * @param int $gid
  *   Uf group id.
  * @param string $name
  * @param int $cid
  *   Contact id.
  * @param $template
  * @param array $params
  *   Params to build component whereclause.
  *
  * @param null $fieldTypes
  *
  * @return void
  */
 public static function buildCustomDisplay($gid, $name, $cid, &$template, &$params, $fieldTypes = NULL)
 {
     if ($gid) {
         if (CRM_Core_BAO_UFGroup::filterUFGroups($gid, $cid)) {
             $values = array();
             $groupTitle = NULL;
             $fields = CRM_Core_BAO_UFGroup::getFields($gid, FALSE, CRM_Core_Action::VIEW, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
             foreach ($fields as $k => $v) {
                 if (!$groupTitle) {
                     $groupTitle = $v["groupTitle"];
                 }
                 // suppress all file fields from display and formatting fields
                 if (CRM_Utils_Array::value('data_type', $v, '') == 'File' || CRM_Utils_Array::value('name', $v, '') == 'image_URL' || CRM_Utils_Array::value('field_type', $v) == 'Formatting') {
                     unset($fields[$k]);
                 }
                 if (!empty($fieldTypes) && !in_array($v['field_type'], $fieldTypes)) {
                     unset($fields[$k]);
                 }
             }
             if ($groupTitle) {
                 $template->assign($name . "_grouptitle", $groupTitle);
             }
             CRM_Core_BAO_UFGroup::getValues($cid, $fields, $values, FALSE, $params);
             if (count($values)) {
                 $template->assign($name, $values);
             }
         }
     }
 }
示例#4
0
 /**  
  * Given a contact id and a group id, returns the field values from the db
  * for this group and notify email only if group's notify field is
  * set and field values are not empty 
  *  
  * @params $gid      group id
  * @params $cid      contact id
  * @params $params   associative array 
  * @return array
  * @access public  
  */
 function checkFieldsEmptyValues($gid, $cid, $params)
 {
     if ($gid) {
         require_once 'CRM/Core/BAO/UFGroup.php';
         if (CRM_Core_BAO_UFGroup::filterUFGroups($gid, $cid)) {
             $values = array();
             $fields = CRM_Core_BAO_UFGroup::getFields($gid, false, CRM_Core_Action::VIEW);
             CRM_Core_BAO_UFGroup::getValues($cid, $fields, $values, false, $params);
             $count = 0;
             //checks for array with only keys and not values
             foreach ($values as $value) {
                 if ($value) {
                     $count++;
                 }
             }
             $email = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gid, 'notify');
             $val = array('id' => $gid, 'values' => $values, 'email' => $email);
             return $val;
         }
     }
 }
示例#5
0
文件: Pledge.php 项目: hguru/224Civi
 /**
  * Function to send Acknowledgment and create activity.
  *
  * @param object $form form object.
  * @param array  $params (reference ) an assoc array of name/value pairs.
  * @access public
  *
  * @return None.
  */
 function sendAcknowledgment(&$form, $params)
 {
     //handle Acknowledgment.
     $allPayments = $payments = array();
     //get All Payments status types.
     $paymentStatusTypes = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
     $returnProperties = array('status_id', 'scheduled_amount', 'scheduled_date', 'contribution_id');
     //get all paymnets details.
     CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_PledgePayment', 'pledge_id', $params['id'], $allPayments, $returnProperties);
     if (!empty($allPayments)) {
         foreach ($allPayments as $payID => $values) {
             $contributionValue = $contributionStatus = array();
             if (isset($values['contribution_id'])) {
                 $contributionParams = array('id' => $values['contribution_id']);
                 $returnProperties = array('contribution_status_id', 'receive_date');
                 CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_Contribution', $contributionParams, $contributionStatus, $returnProperties);
                 $contributionValue = array('status' => CRM_Utils_Array::value('contribution_status_id', $contributionStatus), 'receive_date' => CRM_Utils_Array::value('receive_date', $contributionStatus));
             }
             $payments[$payID] = array_merge($contributionValue, array('amount' => CRM_Utils_Array::value('scheduled_amount', $values), 'due_date' => CRM_Utils_Array::value('scheduled_date', $values)));
             //get the first valid payment id.
             if (!isset($form->paymentId) && ($paymentStatusTypes[$values['status_id']] == 'Pending' || $paymentStatusTypes[$values['status_id']] == 'Overdue')) {
                 $form->paymentId = $values['id'];
             }
         }
     }
     //end
     //assign pledge fields value to template.
     $pledgeFields = array('create_date', 'total_pledge_amount', 'frequency_interval', 'frequency_unit', 'installments', 'frequency_day', 'scheduled_amount', 'currency');
     foreach ($pledgeFields as $field) {
         if (CRM_Utils_Array::value($field, $params)) {
             $form->assign($field, $params[$field]);
         }
     }
     //assign all payments details.
     if ($payments) {
         $form->assign('payments', $payments);
     }
     //assign honor fields.
     $honor_block_is_active = FALSE;
     //make sure we have values for it
     if (CRM_Utils_Array::value('honor_type_id', $params) && (!empty($params['honor_first_name']) && !empty($params['honor_last_name']) || !empty($params['honor_email']))) {
         $honor_block_is_active = TRUE;
         $prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id');
         $honor = CRM_Core_PseudoConstant::get('CRM_Pledge_DAO_Pledge', 'honor_type_id');
         $form->assign('honor_type', $honor[$params['honor_type_id']]);
         $form->assign('honor_prefix', $prefix[$params['honor_prefix_id']]);
         $form->assign('honor_first_name', $params['honor_first_name']);
         $form->assign('honor_last_name', $params['honor_last_name']);
         $form->assign('honor_email', $params['honor_email']);
     }
     $form->assign('honor_block_is_active', $honor_block_is_active);
     //handle domain token values
     $domain = CRM_Core_BAO_Domain::getDomain();
     $tokens = array('domain' => array('name', 'phone', 'address', 'email'), 'contact' => CRM_Core_SelectValues::contactTokens());
     $domainValues = array();
     foreach ($tokens['domain'] as $token) {
         $domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain);
     }
     $form->assign('domain', $domainValues);
     //handle contact token values.
     $ids = array($params['contact_id']);
     $fields = array_merge(array_keys(CRM_Contact_BAO_Contact::importableFields()), array('display_name', 'checksum', 'contact_id'));
     foreach ($fields as $key => $val) {
         $returnProperties[$val] = TRUE;
     }
     $details = CRM_Utils_Token::getTokenDetails($ids, $returnProperties, TRUE, TRUE, NULL, $tokens, get_class($form));
     $form->assign('contact', $details[0][$params['contact_id']]);
     //handle custom data.
     if (CRM_Utils_Array::value('hidden_custom', $params)) {
         $groupTree = CRM_Core_BAO_CustomGroup::getTree('Pledge', CRM_Core_DAO::$_nullObject, $params['id']);
         $pledgeParams = array(array('pledge_id', '=', $params['id'], 0, 0));
         $customGroup = array();
         // retrieve custom data
         foreach ($groupTree as $groupID => $group) {
             $customFields = $customValues = array();
             if ($groupID == 'info') {
                 continue;
             }
             foreach ($group['fields'] as $k => $field) {
                 $field['title'] = $field['label'];
                 $customFields["custom_{$k}"] = $field;
             }
             //to build array of customgroup & customfields in it
             CRM_Core_BAO_UFGroup::getValues($params['contact_id'], $customFields, $customValues, FALSE, $pledgeParams);
             $customGroup[$group['title']] = $customValues;
         }
         $form->assign('customGroup', $customGroup);
     }
     //handle acknowledgment email stuff.
     list($pledgerDisplayName, $pledgerEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($params['contact_id']);
     //check for online pledge.
     $session = CRM_Core_Session::singleton();
     if (CRM_Utils_Array::value('receipt_from_email', $params)) {
         $userName = CRM_Utils_Array::value('receipt_from_name', $params);
         $userEmail = CRM_Utils_Array::value('receipt_from_email', $params);
     } elseif (CRM_Utils_Array::value('from_email_id', $params)) {
         $receiptFrom = $params['from_email_id'];
     } elseif ($userID = $session->get('userID')) {
         //check for loged in user.
         list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID);
     } else {
         //set the domain values.
         $userName = CRM_Utils_Array::value('name', $domainValues);
         $userEmail = CRM_Utils_Array::value('email', $domainValues);
     }
     if (!isset($receiptFrom)) {
         $receiptFrom = "{$userName} <{$userEmail}>";
     }
     list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(array('groupName' => 'msg_tpl_workflow_pledge', 'valueName' => 'pledge_acknowledge', 'contactId' => $params['contact_id'], 'from' => $receiptFrom, 'toName' => $pledgerDisplayName, 'toEmail' => $pledgerEmail));
     //check if activity record exist for this pledge
     //Acknowledgment, if exist do not add activity.
     $activityType = 'Pledge Acknowledgment';
     $activity = new CRM_Activity_DAO_Activity();
     $activity->source_record_id = $params['id'];
     $activity->activity_type_id = CRM_Core_OptionGroup::getValue('activity_type', $activityType, 'name');
     $config = CRM_Core_Config::singleton();
     $details = 'Total Amount ' . CRM_Utils_Money::format($params['total_pledge_amount'], CRM_Utils_Array::value('currency', $params)) . ' To be paid in ' . $params['installments'] . ' installments of ' . CRM_Utils_Money::format($params['scheduled_amount'], CRM_Utils_Array::value('currency', $params)) . ' every ' . $params['frequency_interval'] . ' ' . $params['frequency_unit'] . '(s)';
     if (!$activity->find()) {
         $activityParams = array('subject' => $subject, 'source_contact_id' => $params['contact_id'], 'source_record_id' => $params['id'], 'activity_type_id' => CRM_Core_OptionGroup::getValue('activity_type', $activityType, 'name'), 'activity_date_time' => CRM_Utils_Date::isoToMysql($params['acknowledge_date']), 'is_test' => $params['is_test'], 'status_id' => 2, 'details' => $details, 'campaign_id' => CRM_Utils_Array::value('campaign_id', $params));
         //lets insert assignee record.
         if (CRM_Utils_Array::value('contact_id', $params)) {
             $activityParams['assignee_contact_id'] = $params['contact_id'];
         }
         if (is_a(CRM_Activity_BAO_Activity::create($activityParams), 'CRM_Core_Error')) {
             CRM_Core_Error::fatal("Failed creating Activity for acknowledgment");
         }
     }
 }
示例#6
0
 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     require_once 'CRM/Member/BAO/Membership.php';
     require_once 'CRM/Member/BAO/MembershipType.php';
     require_once 'CRM/Member/BAO/MembershipStatus.php';
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Member_BAO_Membership::deleteRelatedMemberships($this->_id);
         CRM_Member_BAO_Membership::deleteMembership($this->_id);
         return;
     }
     $config =& CRM_Core_Config::singleton();
     // get the submitted form values.
     $this->_params = $formValues = $this->controller->exportValues($this->_name);
     $params = array();
     $ids = array();
     // set the contact, when contact is selected
     if (CRM_Utils_Array::value('contact_select_id', $formValues)) {
         $this->_contactID = CRM_Utils_Array::value('contact_select_id', $formValues);
     }
     $params['contact_id'] = $this->_contactID;
     // we need to retrieve email address
     if ($this->_context == 'standalone' && CRM_Utils_Array::value('send_receipt', $formValues)) {
         require_once 'CRM/Contact/BAO/Contact/Location.php';
         list($this->_contributorDisplayName, $this->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
     }
     $fields = array('status_id', 'source', 'is_override');
     foreach ($fields as $f) {
         $params[$f] = CRM_Utils_Array::value($f, $formValues);
     }
     // fix for CRM-3724
     // when is_override false ignore is_admin statuses during membership
     // status calculation. similarly we did fix for import in CRM-3570.
     if (!CRM_Utils_Array::value('is_override', $params)) {
         $params['exclude_is_admin'] = true;
     }
     $params['membership_type_id'] = $formValues['membership_type_id'][1];
     $joinDate = CRM_Utils_Date::processDate($formValues['join_date']);
     $startDate = CRM_Utils_Date::processDate($formValues['start_date']);
     $endDate = CRM_Utils_Date::processDate($formValues['end_date']);
     $calcDates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($params['membership_type_id'], $joinDate, $startDate, $endDate);
     $dates = array('join_date', 'start_date', 'end_date', 'reminder_date', 'receive_date');
     $currentTime = getDate();
     foreach ($dates as $d) {
         if (isset($formValues[$d]) && !CRM_Utils_System::isNull($formValues[$d])) {
             $params[$d] = CRM_Utils_Date::processDate($formValues[$d]);
         } else {
             if (isset($calcDates[$d])) {
                 $params[$d] = CRM_Utils_Date::processDate($calcDates[$d]);
             }
         }
     }
     if ($this->_id) {
         $ids['membership'] = $params['id'] = $this->_id;
     }
     $session = CRM_Core_Session::singleton();
     $ids['userId'] = $session->get('userID');
     // membership type custom data
     $customFields = CRM_Core_BAO_CustomField::getFields('Membership', false, false, CRM_Utils_Array::value('membership_type_id', $params));
     $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Membership', false, false, null, null, true));
     $params['custom'] = CRM_Core_BAO_CustomField::postProcess($formValues, $customFields, $this->_id, 'Membership');
     // Retrieve the name and email of the current user - this will be the FROM for the receipt email
     require_once 'CRM/Contact/BAO/Contact/Location.php';
     list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($ids['userId']);
     if (CRM_Utils_Array::value('record_contribution', $formValues)) {
         $recordContribution = array('total_amount', 'contribution_type_id', 'payment_instrument_id', 'trxn_id', 'contribution_status_id', 'check_number');
         foreach ($recordContribution as $f) {
             $params[$f] = CRM_Utils_Array::value($f, $formValues);
         }
         $membershipType = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $formValues['membership_type_id'][1]);
         if (!$this->_onlinePendingContributionId) {
             $params['contribution_source'] = "{$membershipType} Membership: Offline membership signup (by {$userName})";
         }
         if ($formValues['send_receipt']) {
             $params['receipt_date'] = $params['receive_date'];
         }
         //insert contribution type name in receipt.
         $formValues['contributionType_name'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionType', $formValues['contribution_type_id']);
     }
     if ($this->_mode) {
         $params['total_amount'] = $formValues['total_amount'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $params['membership_type_id'], 'minimum_fee');
         $params['contribution_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $params['membership_type_id'], 'contribution_type_id');
         require_once 'CRM/Core/BAO/PaymentProcessor.php';
         $this->_paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($formValues['payment_processor_id'], $this->_mode);
         require_once "CRM/Contact/BAO/Contact.php";
         $now = date('YmdHis');
         $fields = array();
         // set email for primary location.
         $fields["email-Primary"] = 1;
         $formValues["email-5"] = $formValues["email-Primary"] = $this->_contributorEmail;
         $params['register_date'] = $now;
         // now set the values for the billing location.
         foreach ($this->_fields as $name => $dontCare) {
             $fields[$name] = 1;
         }
         // also add location name to the array
         $formValues["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $formValues) . ' ' . CRM_Utils_Array::value('billing_middle_name', $formValues) . ' ' . CRM_Utils_Array::value('billing_last_name', $formValues);
         $formValues["address_name-{$this->_bltID}"] = trim($formValues["address_name-{$this->_bltID}"]);
         $fields["address_name-{$this->_bltID}"] = 1;
         $fields["email-{$this->_bltID}"] = 1;
         $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactID, 'contact_type');
         $nameFields = array('first_name', 'middle_name', 'last_name');
         foreach ($nameFields as $name) {
             $fields[$name] = 1;
             if (array_key_exists("billing_{$name}", $formValues)) {
                 $formValues[$name] = $formValues["billing_{$name}"];
                 $formValues['preserveDBName'] = true;
             }
         }
         $contactID = CRM_Contact_BAO_Contact::createProfileContact($formValues, $fields, $this->_contactID, null, null, $ctype);
         // add all the additioanl payment params we need
         $this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
         $this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
         $this->_params['year'] = $this->_params['credit_card_exp_date']['Y'];
         $this->_params['month'] = $this->_params['credit_card_exp_date']['M'];
         $this->_params['ip_address'] = CRM_Utils_System::ipAddress();
         $this->_params['amount'] = $params['total_amount'];
         $this->_params['currencyID'] = $config->defaultCurrency;
         $this->_params['payment_action'] = 'Sale';
         $this->_params['invoiceID'] = md5(uniqid(rand(), true));
         // 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 (CRM_Utils_Array::value('send_receipt', $this->_params)) {
             $paymentParams['email'] = $this->_contributorEmail;
         }
         require_once 'CRM/Core/Payment/Form.php';
         CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, true);
         $payment =& CRM_Core_Payment::singleton($this->_mode, 'Contribute', $this->_paymentProcessor, $this);
         $result =& $payment->doDirectPayment($paymentParams);
         if (is_a($result, 'CRM_Core_Error')) {
             CRM_Core_Error::displaySessionError($result);
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/membership', "reset=1&action=add&cid={$this->_contactID}&context=&mode={$this->_mode}"));
         }
         if ($result) {
             $this->_params = array_merge($this->_params, $result);
         }
         $params['contribution_status_id'] = 1;
         $params['receive_date'] = $now;
         $params['invoice_id'] = $this->_params['invoiceID'];
         $params['contribution_source'] = ts('Online Membership: Admin Interface');
         $params['source'] = $formValues['source'] ? $formValues['source'] : $params['contribution_source'];
         $params['trxn_id'] = $result['trxn_id'];
         $params['payment_instrument_id'] = 1;
         $params['is_test'] = $this->_mode == 'live' ? 0 : 1;
         if (CRM_Utils_Array::value('send_receipt', $this->_params)) {
             $params['receipt_date'] = $now;
         } else {
             $params['receipt_date'] = null;
         }
         $this->set('params', $this->_params);
         $this->assign('trxn_id', $result['trxn_id']);
         $this->assign('receive_date', CRM_Utils_Date::mysqlToIso($params['receive_date']));
         // required for creating membership for related contacts
         $params['action'] = $this->_action;
         $membership =& CRM_Member_BAO_Membership::create($params, $ids);
         $contribution = new CRM_Contribute_BAO_Contribution();
         $contribution->trxn_id = $result['trxn_id'];
         if ($contribution->find(true)) {
             // next create the transaction record
             $trxnParams = array('contribution_id' => $contribution->id, 'trxn_date' => $now, 'trxn_type' => 'Debit', 'total_amount' => $params['total_amount'], 'fee_amount' => CRM_Utils_Array::value('fee_amount', $result), 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $params['total_amount']), 'currency' => $config->defaultCurrency, 'payment_processor' => $this->_paymentProcessor['payment_processor_type'], 'trxn_id' => $result['trxn_id']);
             require_once 'CRM/Contribute/BAO/FinancialTrxn.php';
             $trxn =& CRM_Contribute_BAO_FinancialTrxn::create($trxnParams);
         }
     } else {
         $params['action'] = $this->_action;
         if ($this->_onlinePendingContributionId && CRM_Utils_Array::value('record_contribution', $formValues)) {
             // update membership as well as contribution object, CRM-4395
             require_once 'CRM/Contribute/Form/Contribution.php';
             $params['contribution_id'] = $this->_onlinePendingContributionId;
             $params['componentId'] = $params['id'];
             $params['componentName'] = 'contribute';
             $result = CRM_Contribute_BAO_Contribution::transitionComponents($params, true);
             //carry updated membership object.
             $membership =& new CRM_Member_DAO_Membership();
             $membership->id = $this->_id;
             $membership->find(true);
             $cancelled = true;
             if ($membership->end_date) {
                 //display end date w/ status message.
                 $endDate = $membership->end_date;
                 require_once 'CRM/Member/PseudoConstant.php';
                 $membershipStatues = CRM_Member_PseudoConstant::membershipStatus();
                 if (!in_array($membership->status_id, array(array_search('Cancelled', $membershipStatues), array_search('Expired', $membershipStatues)))) {
                     $cancelled = false;
                 }
             }
             // suppress form values in template.
             $this->assign('cancelled', $cancelled);
         } else {
             $membership =& CRM_Member_BAO_Membership::create($params, $ids);
         }
     }
     if (CRM_Utils_Array::value('send_receipt', $formValues)) {
         require_once 'CRM/Core/DAO.php';
         CRM_Core_DAO::setFieldValue('CRM_Member_DAO_MembershipType', $params['membership_type_id'], 'receipt_text_signup', $formValues['receipt_text_signup']);
     }
     $receiptSend = false;
     if (CRM_Utils_Array::value('send_receipt', $formValues)) {
         $receiptSend = true;
         $receiptFrom = "{$userName} <{$userEmail}>";
         if (CRM_Utils_Array::value('payment_instrument_id', $formValues)) {
             $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
             $formValues['paidBy'] = $paymentInstrument[$formValues['payment_instrument_id']];
         }
         // retrieve custom data
         require_once "CRM/Core/BAO/UFGroup.php";
         $customFields = $customValues = array();
         foreach ($this->_groupTree as $groupID => $group) {
             if ($groupID == 'info') {
                 continue;
             }
             foreach ($group['fields'] as $k => $field) {
                 $field['title'] = $field['label'];
                 $customFields["custom_{$k}"] = $field;
             }
         }
         $members = array(array('member_id', '=', $membership->id, 0, 0));
         // check whether its a test drive
         if ($this->_mode) {
             $members[] = array('member_test', '=', 1, 0, 0);
         }
         CRM_Core_BAO_UFGroup::getValues($this->_contactID, $customFields, $customValues, false, $members);
         if ($this->_mode) {
             if (CRM_Utils_Array::value('billing_first_name', $this->_params)) {
                 $name = $this->_params['billing_first_name'];
             }
             if (CRM_Utils_Array::value('billing_middle_name', $this->_params)) {
                 $name .= " {$this->_params['billing_middle_name']}";
             }
             if (CRM_Utils_Array::value('billing_last_name', $this->_params)) {
                 $name .= " {$this->_params['billing_last_name']}";
             }
             $this->assign('billingName', $name);
             // assign the address formatted up for display
             $addressParts = array("street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "state_province-{$this->_bltID}", "country-{$this->_bltID}");
             $addressFields = array();
             foreach ($addressParts as $part) {
                 list($n, $id) = explode('-', $part);
                 if (isset($this->_params['billing_' . $part])) {
                     $addressFields[$n] = $this->_params['billing_' . $part];
                 }
             }
             require_once 'CRM/Utils/Address.php';
             $this->assign('address', CRM_Utils_Address::format($addressFields));
             $date = CRM_Utils_Date::format($this->_params['credit_card_exp_date']);
             $date = CRM_Utils_Date::mysqlToIso($date);
             $this->assign('credit_card_exp_date', $date);
             $this->assign('credit_card_number', CRM_Utils_System::mungeCreditCard($this->_params['credit_card_number']));
             $this->assign('credit_card_type', $this->_params['credit_card_type']);
             $this->assign('contributeMode', 'direct');
             $this->assign('isAmountzero', 0);
             $this->assign('is_pay_later', 0);
             $this->assign('isPrimary', 1);
         }
         $this->assign('module', 'Membership');
         $this->assign('contactID', $this->_contactID);
         $this->assign('membershipID', $params['membership_id']);
         $this->assign('receiptType', 'membership signup');
         $this->assign('receive_date', $params['receive_date']);
         $this->assign('formValues', $formValues);
         $this->assign('mem_start_date', CRM_Utils_Date::customFormat($calcDates['start_date']));
         $this->assign('mem_end_date', CRM_Utils_Date::customFormat($calcDates['end_date']));
         $this->assign('membership_name', CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $formValues['membership_type_id'][1]));
         $this->assign('customValues', $customValues);
         require_once 'CRM/Core/BAO/MessageTemplates.php';
         list($mailSend, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_contribution', 'valueName' => 'contribution_offline_receipt', 'contactId' => $this->_contactID, 'from' => $receiptFrom, 'toName' => $this->_contributorDisplayName, 'toEmail' => $this->_contributorEmail, 'isTest' => (bool) ($this->_action & CRM_Core_Action::PREVIEW)));
     }
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $statusMsg = ts('Membership for %1 has been updated.', array(1 => $this->_contributorDisplayName));
         if ($endDate) {
             $endDate = CRM_Utils_Date::customFormat($endDate);
             $statusMsg .= ' ' . ts('The membership End Date is %1.', array(1 => $endDate));
         }
         if ($receiptSend) {
             $statusMsg .= ' ' . ts('A confirmation and receipt has been sent to %1.', array(1 => $this->_contributorEmail));
         }
     } elseif ($this->_action & CRM_Core_Action::ADD) {
         require_once 'CRM/Core/DAO.php';
         $memType = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $params['membership_type_id']);
         $statusMsg = ts('%1 membership for %2 has been added.', array(1 => $memType, 2 => $this->_contributorDisplayName));
         //get the end date from calculated dates.
         $endDate = $endDate ? $endDate : CRM_Utils_Array::value('end_date', $calcDates);
         if ($endDate) {
             $endDate = CRM_Utils_Date::customFormat($endDate);
             $statusMsg .= ' ' . ts('The new membership End Date is %1.', array(1 => $endDate));
         }
         if ($receiptSend && $mailSend) {
             $statusMsg .= ' ' . ts('A membership confirmation and receipt has been sent to %1.', array(1 => $this->_contributorEmail));
         }
     }
     CRM_Core_Session::setStatus($statusMsg);
     $buttonName = $this->controller->getButtonName();
     if ($this->_context == 'standalone') {
         if ($buttonName == $this->getButtonName('upload', 'new')) {
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/member/add', 'reset=1&action=add&context=standalone'));
         } else {
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_contactID}&selectedChild=member"));
         }
     } else {
         if ($buttonName == $this->getButtonName('upload', 'new')) {
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/membership', "reset=1&action=add&context=membership&cid={$this->_contactID}"));
         }
     }
 }
 /**
  * Get the profile title and fields.
  *
  * @param int $gid
  * @param int $cid
  * @param array $params
  * @param array $fieldTypes
  *
  * @return array
  */
 protected static function getProfileNameAndFields($gid, $cid, &$params, $fieldTypes = array())
 {
     $groupTitle = NULL;
     $values = array();
     if ($gid) {
         if (CRM_Core_BAO_UFGroup::filterUFGroups($gid, $cid)) {
             $fields = CRM_Core_BAO_UFGroup::getFields($gid, FALSE, CRM_Core_Action::VIEW, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
             foreach ($fields as $k => $v) {
                 if (!$groupTitle) {
                     $groupTitle = $v["groupTitle"];
                 }
                 // suppress all file fields from display and formatting fields
                 if (CRM_Utils_Array::value('data_type', $v, '') == 'File' || CRM_Utils_Array::value('name', $v, '') == 'image_URL' || CRM_Utils_Array::value('field_type', $v) == 'Formatting') {
                     unset($fields[$k]);
                 }
                 if (!empty($fieldTypes) && !in_array($v['field_type'], $fieldTypes)) {
                     unset($fields[$k]);
                 }
             }
             CRM_Core_BAO_UFGroup::getValues($cid, $fields, $values, FALSE, $params);
         }
     }
     return array($groupTitle, $values);
 }
示例#8
0
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the
  * type of action and executes that action.
  *
  * @return void
  */
 public function run()
 {
     $template = CRM_Core_Smarty::singleton();
     if ($this->_id && $this->_gid) {
         // first check that id is part of the limit group id, CRM-4822
         $limitListingsGroupsID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'limit_listings_group_id');
         $config = CRM_Core_Config::singleton();
         if ($limitListingsGroupsID) {
             if (!CRM_Contact_BAO_GroupContact::isContactInGroup($this->_id, $limitListingsGroupsID)) {
                 CRM_Utils_System::setTitle(ts('Profile View - Permission Denied'));
                 return CRM_Core_Session::setStatus(ts('You do not have permission to view this contact record. Contact the site administrator if you need assistance.'), ts('Permission Denied'), 'error');
             }
         }
         $session = CRM_Core_Session::singleton();
         $userID = $session->get('userID');
         $this->_isPermissionedChecksum = $allowPermission = FALSE;
         $permissionType = CRM_Core_Permission::VIEW;
         if (CRM_Core_Permission::check('administer users') || CRM_Core_Permission::check('view all contacts') || CRM_Contact_BAO_Contact_Permission::allow($this->_id)) {
             $allowPermission = TRUE;
         }
         if ($this->_id != $userID) {
             // do not allow edit for anon users in joomla frontend, CRM-4668, unless u have checksum CRM-5228
             if ($config->userFrameworkFrontend) {
                 $this->_isPermissionedChecksum = CRM_Contact_BAO_Contact_Permission::validateOnlyChecksum($this->_id, $this, FALSE);
                 if (!$this->_isPermissionedChecksum) {
                     $this->_isPermissionedChecksum = $allowPermission;
                 }
             } else {
                 $this->_isPermissionedChecksum = CRM_Contact_BAO_Contact_Permission::validateChecksumContact($this->_id, $this, FALSE);
             }
         }
         // CRM-10853
         // Users with create or edit permission should be allowed to view their own profile
         if ($this->_id == $userID || $this->_isPermissionedChecksum) {
             if (!CRM_Core_Permission::check('profile view')) {
                 if (CRM_Core_Permission::check('profile create') || CRM_Core_Permission::check('profile edit')) {
                     $this->_skipPermission = TRUE;
                 }
             }
         }
         // make sure we dont expose all fields based on permission
         $admin = FALSE;
         if (!$config->userFrameworkFrontend && $allowPermission || $this->_id == $userID || $this->_isPermissionedChecksum) {
             $admin = TRUE;
         }
         $values = array();
         $fields = CRM_Core_BAO_UFGroup::getFields($this->_profileIds, FALSE, CRM_Core_Action::VIEW, NULL, NULL, FALSE, $this->_restrict, $this->_skipPermission, NULL, $permissionType);
         if ($this->_multiRecord & CRM_Core_Action::VIEW && $this->_recordId && !$this->_allFields) {
             CRM_Core_BAO_UFGroup::shiftMultiRecordFields($fields, $multiRecordFields);
             $fields = $multiRecordFields;
         }
         if ($this->_isContactActivityProfile && $this->_gid) {
             $errors = CRM_Profile_Form::validateContactActivityProfile($this->_activityId, $this->_id, $this->_gid);
             if (!empty($errors)) {
                 CRM_Core_Error::fatal(array_pop($errors));
             }
         }
         //reformat fields array
         foreach ($fields as $name => $field) {
             // also eliminate all formatting fields
             if (CRM_Utils_Array::value('field_type', $field) == 'Formatting') {
                 unset($fields[$name]);
             }
             // make sure that there is enough permission to expose this field
             if (!$admin && $field['visibility'] == 'User and User Admin Only') {
                 unset($fields[$name]);
             }
         }
         if ($this->_isContactActivityProfile) {
             $contactFields = $activityFields = array();
             foreach ($fields as $fieldName => $field) {
                 if (CRM_Utils_Array::value('field_type', $field) == 'Activity') {
                     $activityFields[$fieldName] = $field;
                 } else {
                     $contactFields[$fieldName] = $field;
                 }
             }
             CRM_Core_BAO_UFGroup::getValues($this->_id, $contactFields, $values);
             if ($this->_activityId) {
                 CRM_Core_BAO_UFGroup::getValues(NULL, $activityFields, $values, TRUE, array(array('activity_id', '=', $this->_activityId, 0, 0)));
             }
         } else {
             $customWhereClause = NULL;
             if ($this->_multiRecord & CRM_Core_Action::VIEW && $this->_recordId) {
                 if ($this->_allFields) {
                     $copyFields = $fields;
                     CRM_Core_BAO_UFGroup::shiftMultiRecordFields($copyFields, $multiRecordFields);
                     $fieldKey = key($multiRecordFields);
                 } else {
                     $fieldKey = key($fields);
                 }
                 if ($fieldID = CRM_Core_BAO_CustomField::getKeyID($fieldKey)) {
                     $tableColumnGroup = CRM_Core_BAO_CustomField::getTableColumnGroup($fieldID);
                     $columnName = "{$tableColumnGroup[0]}.id";
                     $customWhereClause = $columnName . ' = ' . $this->_recordId;
                 }
             }
             CRM_Core_BAO_UFGroup::getValues($this->_id, $fields, $values, TRUE, NULL, FALSE, $customWhereClause);
         }
         // $profileFields array can be used for customized display of field labels and values in Profile/View.tpl
         $profileFields = array();
         $labels = array();
         foreach ($fields as $name => $field) {
             //CRM-14338
             // Create a unique, non-empty index for each field.
             $index = $field['title'];
             if ($index === '') {
                 $index = ' ';
             }
             while (array_key_exists($index, $labels)) {
                 $index .= ' ';
             }
             $labels[$index] = preg_replace('/\\s+|\\W+/', '_', $name);
         }
         foreach ($values as $title => $value) {
             $profileFields[$labels[$title]] = array('label' => $title, 'value' => $value);
         }
         $template->assign_by_ref('row', $values);
         $template->assign_by_ref('profileFields', $profileFields);
     }
     $name = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'name');
     $this->assign('ufGroupName', $name);
     CRM_Utils_Hook::viewProfile($name);
     if (strtolower($name) == 'summary_overlay') {
         $template->assign('overlayProfile', TRUE);
     }
     if ($this->_multiRecord & CRM_Core_Action::VIEW && $this->_recordId && !$this->_allFields) {
         $fieldDetail = reset($fields);
         $fieldId = CRM_Core_BAO_CustomField::getKeyID($fieldDetail['name']);
         $customGroupDetails = CRM_Core_BAO_CustomGroup::getGroupTitles(array($fieldId));
         $multiRecTitle = $customGroupDetails[$fieldId]['groupTitle'];
     } else {
         $title = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'title');
     }
     //CRM-4131.
     $displayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_id, 'display_name');
     if ($displayName) {
         $session = CRM_Core_Session::singleton();
         $config = CRM_Core_Config::singleton();
         if ($session->get('userID') && CRM_Core_Permission::check('access CiviCRM') && CRM_Contact_BAO_Contact_Permission::allow($session->get('userID'), CRM_Core_Permission::VIEW) && !$config->userFrameworkFrontend) {
             $contactViewUrl = CRM_Utils_System::url('civicrm/contact/view', "action=view&reset=1&cid={$this->_id}", TRUE);
             $this->assign('displayName', $displayName);
             $displayName = "<a href=\"{$contactViewUrl}\">{$displayName}</a>";
         }
         $title .= ' - ' . $displayName;
     }
     $title = isset($multiRecTitle) ? ts('View %1 Record', array(1 => $multiRecTitle)) : $title;
     CRM_Utils_System::setTitle($title);
     // invoke the pagRun hook, CRM-3906
     CRM_Utils_Hook::pageRun($this);
     return trim($template->fetch($this->getHookedTemplateFileName()));
 }
示例#9
0
 /**  
  * Function to add the custom fields for contribution page (ie profile)
  * 
  * @param int    $gid            uf group id
  * @param string $name 
  * @param int    $cid            contact id
  * @param array  $params         params to build component whereclause
  *   
  * @return void  
  * @access public
  * @static  
  */
 function buildCustomDisplay($gid, $name, $cid, &$template, &$params)
 {
     if ($gid) {
         require_once 'CRM/Core/BAO/UFGroup.php';
         if (CRM_Core_BAO_UFGroup::filterUFGroups($gid, $cid)) {
             $values = array();
             $groupTitle = null;
             $fields = CRM_Core_BAO_UFGroup::getFields($gid, false, CRM_Core_Action::VIEW);
             foreach ($fields as $k => $v) {
                 if (!$groupTitle) {
                     $groupTitle = $v["groupTitle"];
                 }
                 // suppress all file fields from display
                 if (CRM_Utils_Array::value('data_type', $v, '') == 'File') {
                     unset($fields[$k]);
                 }
             }
             if ($groupTitle) {
                 $template->assign($name . "_grouptitle", $groupTitle);
             }
             CRM_Core_BAO_UFGroup::getValues($cid, $fields, $values, false, $params);
             if (count($values)) {
                 $template->assign($name, $values);
             }
         }
     }
 }
示例#10
0
 /**
  * Function to process the renewal form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     require_once 'CRM/Member/BAO/Membership.php';
     require_once 'CRM/Member/BAO/MembershipType.php';
     require_once 'CRM/Member/BAO/MembershipStatus.php';
     // get the submitted form values.
     $this->_params = $formValues = $this->controller->exportValues($this->_name);
     $params = array();
     $ids = array();
     $config =& CRM_Core_Config::singleton();
     $params['contact_id'] = $this->_contactID;
     if ($this->_mode) {
         $formValues['total_amount'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'minimum_fee');
         $formValues['contribution_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'contribution_type_id');
         require_once 'CRM/Core/BAO/PaymentProcessor.php';
         $this->_paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($formValues['payment_processor_id'], $this->_mode);
         require_once "CRM/Contact/BAO/Contact.php";
         $now = CRM_Utils_Date::getToday($now, 'YmdHis');
         $fields = array();
         // set email for primary location.
         $fields["email-Primary"] = 1;
         $formValues["email-5"] = $formValues["email-Primary"] = $this->_contributorEmail;
         $formValues['register_date'] = $now;
         // now set the values for the billing location.
         foreach ($this->_fields as $name => $dontCare) {
             $fields[$name] = 1;
         }
         // also add location name to the array
         $formValues["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $formValues) . ' ' . CRM_Utils_Array::value('billing_middle_name', $formValues) . ' ' . CRM_Utils_Array::value('billing_last_name', $formValues);
         $formValues["address_name-{$this->_bltID}"] = trim($formValues["address_name-{$this->_bltID}"]);
         $fields["address_name-{$this->_bltID}"] = 1;
         $fields["email-{$this->_bltID}"] = 1;
         $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactID, 'contact_type');
         $nameFields = array('first_name', 'middle_name', 'last_name');
         foreach ($nameFields as $name) {
             $fields[$name] = 1;
             if (array_key_exists("billing_{$name}", $formValues)) {
                 $formValues[$name] = $formValues["billing_{$name}"];
                 $formValues['preserveDBName'] = true;
             }
         }
         $contactID = CRM_Contact_BAO_Contact::createProfileContact($formValues, $fields, $this->_contactID, null, null, $ctype);
         // add all the additioanl payment params we need
         $this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
         $this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
         $this->_params['year'] = $this->_params['credit_card_exp_date']['Y'];
         $this->_params['month'] = $this->_params['credit_card_exp_date']['M'];
         $this->_params['ip_address'] = CRM_Utils_System::ipAddress();
         $this->_params['amount'] = $formValues['total_amount'];
         $this->_params['currencyID'] = $config->defaultCurrency;
         $this->_params['payment_action'] = 'Sale';
         $this->_params['invoiceID'] = md5(uniqid(rand(), true));
         // 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 (CRM_Utils_Array::value('send_receipt', $this->_params)) {
             $paymentParams['email'] = $this->_contributorEmail;
         }
         require_once 'CRM/Core/Payment/Form.php';
         CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, true);
         $payment =& CRM_Core_Payment::singleton($this->_mode, 'Contribute', $this->_paymentProcessor, $this);
         $result =& $payment->doDirectPayment($paymentParams);
         if (is_a($result, 'CRM_Core_Error')) {
             CRM_Core_Error::displaySessionError($result);
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/membership', "reset=1&action=renew&cid={$this->_contactID}&id={$this->_id}&context=membership&mode={$this->_mode}"));
         }
         if ($result) {
             $this->_params = array_merge($this->_params, $result);
         }
         $formValues['contribution_status_id'] = 1;
         $formValues['receive_date'] = $now;
         $formValues['invoice_id'] = $this->_params['invoiceID'];
         $formValues['trxn_id'] = $result['trxn_id'];
         $formValues['payment_instrument_id'] = 1;
         $formValues['is_test'] = $this->_mode == 'live' ? 0 : 1;
         if (CRM_Utils_Array::value('send_receipt', $this->_params)) {
             $formValues['receipt_date'] = $now;
         } else {
             $formValues['receipt_date'] = null;
         }
         $this->set('params', $this->_params);
         $this->assign('trxn_id', $result['trxn_id']);
         $this->assign('receive_date', CRM_Utils_Date::mysqlToIso($formValues['receive_date']));
     }
     $renewalDate = null;
     if ($formValues['renewal_date']) {
         $this->set('renewDate', CRM_Utils_Date::processDate($formValues['renewal_date']));
     }
     $this->_membershipId = $this->_id;
     // check for test membership.
     $isTestMembership = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_membershipId, 'is_test');
     $renewMembership = CRM_Member_BAO_Membership::renewMembership($this->_contactID, $this->_memType, $isTestMembership, $this, null);
     $endDate = CRM_Utils_Date::processDate($renewMembership->end_date);
     require_once 'CRM/Contact/BAO/Contact/Location.php';
     // Retrieve the name and email of the current user - this will be the FROM for the receipt email
     $session =& CRM_Core_Session::singleton();
     $userID = $session->get('userID');
     list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID);
     $memType = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $renewMembership->membership_type_id, 'name');
     if (CRM_Utils_Array::value('record_contribution', $formValues) || $this->_mode) {
         //building contribution params
         $contributionParams = array();
         $config =& CRM_Core_Config::singleton();
         $contributionParams['currency'] = $config->defaultCurrency;
         $contributionParams['contact_id'] = $params['contact_id'];
         $contributionParams['source'] = "{$memType} Membership: Offline membership renewal (by {$userName})";
         $contributionParams['non_deductible_amount'] = 'null';
         $contributionParams['receive_date'] = date('Y-m-d H:i:s');
         $contributionParams['receipt_date'] = CRM_Utils_Array::value('send_receipt', $formValues) ? $contributionParams['receive_date'] : 'null';
         $recordContribution = array('total_amount', 'contribution_type_id', 'payment_instrument_id', 'trxn_id', 'contribution_status_id', 'invoice_id', 'check_number', 'is_test');
         foreach ($recordContribution as $f) {
             $contributionParams[$f] = CRM_Utils_Array::value($f, $formValues);
         }
         require_once 'CRM/Contribute/BAO/Contribution.php';
         $contribution =& CRM_Contribute_BAO_Contribution::create($contributionParams, $ids);
         require_once 'CRM/Member/DAO/MembershipPayment.php';
         $mpDAO =& new CRM_Member_DAO_MembershipPayment();
         $mpDAO->membership_id = $renewMembership->id;
         $mpDAO->contribution_id = $contribution->id;
         $mpDAO->save();
         if ($this->_mode) {
             $trxnParams = array('contribution_id' => $contribution->id, 'trxn_date' => $now, 'trxn_type' => 'Debit', 'total_amount' => $formValues['total_amount'], 'fee_amount' => CRM_Utils_Array::value('fee_amount', $result), 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $formValues['total_amount']), 'currency' => $config->defaultCurrency, 'payment_processor' => $this->_paymentProcessor['payment_processor_type'], 'trxn_id' => $result['trxn_id']);
             require_once 'CRM/Contribute/BAO/FinancialTrxn.php';
             $trxn =& CRM_Contribute_BAO_FinancialTrxn::create($trxnParams);
         }
     }
     if (CRM_Utils_Array::value('send_receipt', $formValues)) {
         require_once 'CRM/Core/DAO.php';
         CRM_Core_DAO::setFieldValue('CRM_Member_DAO_MembershipType', CRM_Utils_Array::value('membership_type_id', $params), 'receipt_text_renewal', $formValues['receipt_text_renewal']);
     }
     $receiptSend = false;
     if (CRM_Utils_Array::value('send_receipt', $formValues)) {
         $receiptSend = true;
         // Retrieve the name and email of the contact - this will be the TO for receipt email
         list($this->_contributorDisplayName, $this->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
         $receiptFrom = '"' . $userName . '" <' . $userEmail . '>';
         $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
         $formValues['paidBy'] = $paymentInstrument[$formValues['payment_instrument_id']];
         //get the group Tree
         $this->_groupTree =& CRM_Core_BAO_CustomGroup::getTree('Membership', $this, $this->_id, false, $this->_memType);
         // retrieve custom data
         require_once "CRM/Core/BAO/UFGroup.php";
         $customFields = $customValues = $fo = array();
         foreach ($this->_groupTree as $groupID => $group) {
             if ($groupID == 'info') {
                 continue;
             }
             foreach ($group['fields'] as $k => $field) {
                 $field['title'] = $field['label'];
                 $customFields["custom_{$k}"] = $field;
             }
         }
         CRM_Core_BAO_UFGroup::getValues($this->_contactID, $customFields, $customValues, false, array(array('member_id', '=', $renewMembership->id, 0, 0)));
         $this->assign_by_ref('formValues', $formValues);
         $this->assign('receive_date', $renewalDate);
         $this->assign('module', 'Membership');
         $this->assign('receiptType', 'membership renewal');
         $this->assign('mem_start_date', CRM_Utils_Date::customFormat($renewMembership->start_date));
         $this->assign('mem_end_date', CRM_Utils_Date::customFormat($renewMembership->end_date));
         $this->assign('membership_name', CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $renewMembership->membership_type_id));
         $this->assign('customValues', $customValues);
         if ($this->_mode) {
             if (CRM_Utils_Array::value('billing_first_name', $this->_params)) {
                 $name = $this->_params['billing_first_name'];
             }
             if (CRM_Utils_Array::value('billing_middle_name', $this->_params)) {
                 $name .= " {$this->_params['billing_middle_name']}";
             }
             if (CRM_Utils_Array::value('billing_last_name', $this->_params)) {
                 $name .= " {$this->_params['billing_last_name']}";
             }
             $this->assign('billingName', $name);
             // assign the address formatted up for display
             $addressParts = array("street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "state_province-{$this->_bltID}", "country-{$this->_bltID}");
             $addressFields = array();
             foreach ($addressParts as $part) {
                 list($n, $id) = explode('-', $part);
                 if (isset($this->_params['billing_' . $part])) {
                     $addressFields[$n] = $this->_params['billing_' . $part];
                 }
             }
             require_once 'CRM/Utils/Address.php';
             $this->assign('address', CRM_Utils_Address::format($addressFields));
             $date = CRM_Utils_Date::format($this->_params['credit_card_exp_date']);
             $date = CRM_Utils_Date::mysqlToIso($date);
             $this->assign('credit_card_exp_date', $date);
             $this->assign('credit_card_number', CRM_Utils_System::mungeCreditCard($this->_params['credit_card_number']));
             $this->assign('credit_card_type', $this->_params['credit_card_type']);
             $this->assign('contributeMode', 'direct');
             $this->assign('isAmountzero', 0);
             $this->assign('is_pay_later', 0);
             $this->assign('isPrimary', 1);
             if ($this->_mode == 'test') {
                 $this->assign('action', '1024');
             }
         }
         require_once 'CRM/Core/BAO/MessageTemplates.php';
         list($mailSend, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_membership', 'valueName' => 'membership_offline_receipt', 'contactId' => $this->_contactID, 'from' => $receiptFrom, 'toName' => $this->_contributorDisplayName, 'toEmail' => $this->_contributorEmail, 'isTest' => $this->_mode == 'test'));
     }
     $statusMsg = ts('%1 membership for %2 has been renewed.', array(1 => $memType, 2 => $this->_contributorDisplayName));
     $endDate = CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $this->_id, "end_date"));
     if ($endDate) {
         $statusMsg .= ' ' . ts('The new membership End Date is %1.', array(1 => $endDate));
     }
     if ($receiptSend && $mailSend) {
         $statusMsg .= ' ' . ts('A renewal confirmation and receipt has been sent to %1.', array(1 => $this->_contributorEmail));
     }
     CRM_Core_Session::setStatus($statusMsg);
 }
 /** 
  * Function to send email receipt.
  * 
  * @form object  of Contribution form.
  * @param array  $params (reference ) an assoc array of name/value pairs.
  * @$ccContribution boolen,  is it credit card contribution.
  * @access public. 
  * @return None.
  */
 function emailReceipt(&$form, &$params, $ccContribution = false)
 {
     $this->assign('receiptType', 'contribution');
     // Retrieve Contribution Type Name from contribution_type_id
     $params['contributionType_name'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionType', $params['contribution_type_id']);
     if (CRM_Utils_Array::value('payment_instrument_id', $params)) {
         require_once 'CRM/Contribute/PseudoConstant.php';
         $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
         $params['paidBy'] = $paymentInstrument[$params['payment_instrument_id']];
     }
     // retrieve individual prefix value for honoree
     if (CRM_Utils_Array::value('hidden_Honoree', $params)) {
         $individualPrefix = CRM_Core_PseudoConstant::individualPrefix();
         $honor = CRM_Core_PseudoConstant::honor();
         $params['honor_prefix'] = CRM_Utils_Array::value($params['honor_prefix_id'], $individualPrefix);
         $params["honor_type"] = CRM_Utils_Array::value($params["honor_type_id"], $honor);
     }
     // retrieve premium product name and assigned fulfilled
     // date to template
     if (CRM_Utils_Array::value('hidden_Premium', $params)) {
         if (CRM_Utils_Array::value($params['product_name'][0], $form->_options)) {
             $params['product_option'] = $form->_options[$params['product_name'][0]][$params['product_name'][1]];
         }
         //fix for crm-4584
         if (!empty($params['product_name'])) {
             require_once 'CRM/Contribute/DAO/Product.php';
             $productDAO = new CRM_Contribute_DAO_Product();
             $productDAO->id = $params['product_name'][0];
             $productDAO->find(true);
             $params['product_name'] = $productDAO->name;
             $params['product_sku'] = $productDAO->sku;
         }
         $this->assign('fulfilled_date', CRM_Utils_Date::processDate($params['fulfilled_date']));
     }
     $this->assign('ccContribution', $ccContribution);
     if ($ccContribution) {
         //build the name.
         $name = CRM_Utils_Array::value('billing_first_name', $params);
         if (CRM_Utils_Array::value('billing_middle_name', $params)) {
             $name .= " {$params['billing_middle_name']}";
         }
         $name .= ' ' . CRM_Utils_Array::value('billing_last_name', $params);
         $name = trim($name);
         $this->assign('billingName', $name);
         //assign the address formatted up for display
         $addressParts = array("street_address" => "billing_street_address-{$form->_bltID}", "city" => "billing_city-{$form->_bltID}", "postal_code" => "billing_postal_code-{$form->_bltID}", "state_province" => "state_province-{$form->_bltID}", "country" => "country-{$form->_bltID}");
         $addressFields = array();
         foreach ($addressParts as $name => $field) {
             $addressFields[$name] = CRM_Utils_Array::value($field, $params);
         }
         require_once 'CRM/Utils/Address.php';
         $this->assign('address', CRM_Utils_Address::format($addressFields));
         $date = CRM_Utils_Date::format($params['credit_card_exp_date']);
         $date = CRM_Utils_Date::mysqlToIso($date);
         $this->assign('credit_card_type', CRM_Utils_Array::value('credit_card_type', $params));
         $this->assign('credit_card_exp_date', $date);
         $this->assign('credit_card_number', CRM_Utils_System::mungeCreditCard($params['credit_card_number']));
     } else {
         //offline contribution
         //Retrieve the name and email from receipt is to be send
         $params['receipt_from_name'] = $form->userDisplayName;
         $params['receipt_from_email'] = $form->userEmail;
         // assigned various dates to the templates
         $form->assign('receipt_date', CRM_Utils_Date::processDate($params['receipt_date']));
         $form->assign('cancel_date', CRM_Utils_Date::processDate($params['cancel_date']));
         if (CRM_Utils_Array::value('thankyou_date', $params)) {
             $form->assign('thankyou_date', CRM_Utils_Date::processDate($params['thankyou_date']));
         }
         if ($form->_action & CRM_Core_Action::UPDATE) {
             $form->assign('lineItem', empty($form->_lineItems) ? false : $form->_lineItems);
         }
     }
     //handle custom data
     if (CRM_Utils_Array::value('hidden_custom', $params)) {
         $contribParams = array(array('contribution_id', '=', $params['contribution_id'], 0, 0));
         if ($form->_mode == 'test') {
             $contribParams[] = array('contribution_test', '=', 1, 0, 0);
         }
         //retrieve custom data
         require_once "CRM/Core/BAO/UFGroup.php";
         $customGroup = array();
         foreach ($form->_groupTree as $groupID => $group) {
             $customFields = $customValues = array();
             if ($groupID == 'info') {
                 continue;
             }
             foreach ($group['fields'] as $k => $field) {
                 $field['title'] = $field['label'];
                 $customFields["custom_{$k}"] = $field;
             }
             //build the array of customgroup contain customfields.
             CRM_Core_BAO_UFGroup::getValues($params['contact_id'], $customFields, $customValues, false, $contribParams);
             $customGroup[$group['title']] = $customValues;
         }
         //assign all custom group and corresponding fields to template.
         $form->assign('customGroup', $customGroup);
     }
     $form->assign_by_ref('formValues', $params);
     require_once 'CRM/Contact/BAO/Contact/Location.php';
     require_once 'CRM/Utils/Mail.php';
     list($contributorDisplayName, $contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($params['contact_id']);
     $this->assign('contactID', $params['contact_id']);
     $this->assign('contributionID', $params['contribution_id']);
     $this->assign('currency', $params['currency']);
     $this->assign('receive_date', CRM_Utils_Date::processDate($params['receive_date']));
     $session = CRM_Core_Session::singleton();
     $userID = $session->get('userID');
     list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID);
     require_once 'CRM/Core/BAO/MessageTemplates.php';
     list($sendReceipt, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_contribution', 'valueName' => 'contribution_offline_receipt', 'contactId' => $params['contact_id'], 'from' => "{$userName} <{$userEmail}>", 'toName' => $contributorDisplayName, 'toEmail' => $contributorEmail, 'isTest' => $form->_mode == 'test'));
     return $sendReceipt;
 }
示例#12
0
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the  
  * type of action and executes that action. 
  *
  * @return void
  * @access public
  *
  */
 function run()
 {
     $template = CRM_Core_Smarty::singleton();
     if ($this->_id && $this->_gid) {
         // first check that id is part of the limit group id, CRM-4822
         $limitListingsGroupsID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'limit_listings_group_id');
         $config = CRM_Core_Config::singleton();
         if ($limitListingsGroupsID) {
             require_once 'CRM/Contact/BAO/GroupContact.php';
             if (!CRM_Contact_BAO_GroupContact::isContactInGroup($this->_id, $limitListingsGroupsID)) {
                 CRM_Utils_System::setTitle(ts('Profile View - Permission Denied'));
                 return CRM_Core_Session::setStatus(ts('You do not have permission to view this contact record. Contact the site administrator if you need assistance.'));
             }
         }
         require_once 'CRM/Core/BAO/UFGroup.php';
         $values = array();
         $fields = CRM_Core_BAO_UFGroup::getFields($this->_profileIds, false, CRM_Core_Action::VIEW, null, null, false, $this->_restrict, $this->_skipPermission, null, CRM_Core_Permission::VIEW);
         require_once 'CRM/Contact/BAO/Contact/Permission.php';
         // make sure we dont expose all fields based on permission
         $admin = false;
         $session = CRM_Core_Session::singleton();
         if (!$config->userFrameworkFrontend && (CRM_Core_Permission::check('administer users') || CRM_Core_Permission::check('view all contacts') || CRM_Contact_BAO_Contact_Permission::allow($this->_id, CRM_Core_Permission::VIEW)) || $this->_id == $session->get('userID')) {
             $admin = true;
         }
         if (!$admin) {
             foreach ($fields as $name => $field) {
                 // make sure that there is enough permission to expose this field
                 if ($field['visibility'] == 'User and User Admin Only') {
                     unset($fields[$name]);
                 }
             }
         }
         CRM_Core_BAO_UFGroup::getValues($this->_id, $fields, $values);
         // $profileFields array can be used for customized display of field labels and values in Profile/View.tpl
         $profileFields = array();
         $labels = array();
         foreach ($fields as $name => $field) {
             $labels[$field['title']] = preg_replace('/\\s+|\\W+/', '_', $name);
         }
         foreach ($values as $title => $value) {
             $profileFields[$labels[$title]] = array('label' => $title, 'value' => $value);
         }
         $template->assign_by_ref('row', $values);
         $template->assign_by_ref('profileFields', $profileFields);
     }
     $name = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'name');
     if (strtolower($name) == 'summary_overlay') {
         $template->assign('overlayProfile', true);
     }
     $title = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'title');
     //CRM-4131.
     $displayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_id, 'display_name');
     if ($displayName) {
         require_once 'CRM/Core/Permission.php';
         require_once 'CRM/Contact/BAO/Contact/Permission.php';
         $session = CRM_Core_Session::singleton();
         $config = CRM_Core_Config::singleton();
         if ($session->get('userID') && CRM_Core_Permission::check('access CiviCRM') && CRM_Contact_BAO_Contact_Permission::allow($session->get('userID'), CRM_Core_Permission::VIEW) && !$config->userFrameworkFrontend) {
             $contactViewUrl = CRM_Utils_System::url('civicrm/contact/view', "action=view&reset=1&cid={$this->_id}", true);
             $this->assign('displayName', $displayName);
             $displayName = "<a href=\"{$contactViewUrl}\">{$displayName}</a>";
         }
         $title .= ' - ' . $displayName;
     }
     CRM_Utils_System::setTitle($title);
     // invoke the pagRun hook, CRM-3906
     require_once 'CRM/Utils/Hook.php';
     CRM_Utils_Hook::pageRun($this);
     return trim($template->fetch($this->getTemplateFileName()));
 }
示例#13
0
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the  
  * type of action and executes that action. 
  *
  * @return void
  * @access public
  *
  */
 function run()
 {
     $template =& CRM_Core_Smarty::singleton();
     if ($this->_id && $this->_gid) {
         require_once 'CRM/Core/BAO/UFGroup.php';
         $values = array();
         $fields = CRM_Core_BAO_UFGroup::getFields($this->_gid, false, CRM_CORE_ACTION_VIEW);
         // make sure we dont expose all fields based on permission
         $admin = false;
         $session =& CRM_Core_Session::singleton();
         if (CRM_Utils_System::checkPermission('administer users') || $this->_id == $session->get('userID')) {
             $admin = true;
         }
         if (!$admin) {
             foreach ($fields as $name => $field) {
                 // make sure that there is enough permission to expose this field
                 if ($field['visibility'] == 'User and User Admin Only') {
                     unset($fields[$name]);
                 }
             }
         }
         CRM_Core_BAO_UFGroup::getValues($this->_id, $fields, $values);
         $template->assign_by_ref('row', $values);
     }
     return trim($template->fetch('CRM/Profile/Page/Dynamic.tpl'));
 }
示例#14
0
 /**
  * Function to assign honor profile fields to template/form, if $honorId (as soft-credit's contact_id)
  * is passed  then  whole honoreeprofile fields with title/value assoc array assigned or only honoreeName
  * is assigned
  *
  * @param CRM_Core_Form $form
  * @param array $params
  * @param int $honoreeprofileId
  * @param int $honorId
  */
 public static function formatHonoreeProfileFields($form, $params, $honoreeprofileId, $honorId = NULL)
 {
     $profileContactType = CRM_Core_BAO_UFGroup::getContactType($honoreeprofileId);
     $profileFields = CRM_Core_BAO_UFGroup::getFields($honoreeprofileId);
     $honoreeProfileFields = $values = array();
     $honorName = NULL;
     if ($honorId) {
         CRM_Core_BAO_UFGroup::getValues($honorId, $profileFields, $values, FALSE, $params);
         if (empty($params)) {
             foreach ($profileFields as $name => $field) {
                 $title = $field['title'];
                 $params[$field['name']] = $values[$title];
             }
         }
     }
     //remove name related fields and construct name string with prefix/suffix
     //which will be later assigned to template
     switch ($profileContactType) {
         case 'Individual':
             if (array_key_exists('prefix_id', $params)) {
                 $honorName = CRM_Utils_Array::value(CRM_Utils_Array::value('prefix_id', $params), CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id'));
                 unset($profileFields['prefix_id']);
             }
             $honorName .= ' ' . $params['first_name'] . ' ' . $params['last_name'];
             unset($profileFields['first_name']);
             unset($profileFields['last_name']);
             if (array_key_exists('suffix_id', $params)) {
                 $honorName .= ' ' . CRM_Utils_Array::value(CRM_Utils_Array::value('suffix_id', $params), CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id'));
                 unset($profileFields['suffix_id']);
             }
             break;
         case 'Organization':
             $honorName = $params['organization_name'];
             unset($profileFields['organization_name']);
             break;
         case 'Household':
             $honorName = $params['household_name'];
             unset($profileFields['household_name']);
             break;
     }
     if ($honorId) {
         $honoreeProfileFields['Name'] = $honorName;
         foreach ($profileFields as $name => $field) {
             $title = $field['title'];
             $honoreeProfileFields[$title] = $values[$title];
         }
         $form->assign('honoreeProfile', $honoreeProfileFields);
     } else {
         $form->assign('honorName', $honorName);
     }
 }
示例#15
0
 /**
  * Send email receipt.
  *
  * @param CRM_Core_Form $form
  *   instance of Contribution form.
  * @param array $params
  *   (reference ) an assoc array of name/value pairs.
  * @param bool $ccContribution
  *   is it credit card contribution.
  *
  * @return array
  */
 public static function emailReceipt(&$form, &$params, $ccContribution = FALSE)
 {
     $form->assign('receiptType', 'contribution');
     // Retrieve Financial Type Name from financial_type_id
     $params['contributionType_name'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $params['financial_type_id']);
     if (!empty($params['payment_instrument_id'])) {
         $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
         $params['paidBy'] = $paymentInstrument[$params['payment_instrument_id']];
         if ($params['paidBy'] != 'Check' && isset($params['check_number'])) {
             unset($params['check_number']);
         }
     }
     // retrieve individual prefix value for honoree
     if (isset($params['soft_credit'])) {
         $softCreditTypes = $softCredits = array();
         foreach ($params['soft_credit'] as $key => $softCredit) {
             $softCredits[$key] = array('Name' => $softCredit['contact_name'], 'Amount' => CRM_Utils_Money::format($softCredit['amount'], $softCredit['currency']));
             $softCreditTypes[$key] = $softCredit['soft_credit_type_label'];
         }
         $form->assign('softCreditTypes', $softCreditTypes);
         $form->assign('softCredits', $softCredits);
     }
     // retrieve premium product name and assigned fulfilled
     // date to template
     if (!empty($params['hidden_Premium'])) {
         if (isset($params['product_name']) && is_array($params['product_name']) && !empty($params['product_name'])) {
             $productDAO = new CRM_Contribute_DAO_Product();
             $productDAO->id = $params['product_name'][0];
             $productOptionID = $params['product_name'][1];
             $productDAO->find(TRUE);
             $params['product_name'] = $productDAO->name;
             $params['product_sku'] = $productDAO->sku;
             if (empty($params['product_option']) && !empty($form->_options[$productDAO->id])) {
                 $params['product_option'] = $form->_options[$productDAO->id][$productOptionID];
             }
         }
         if (!empty($params['fulfilled_date'])) {
             $form->assign('fulfilled_date', CRM_Utils_Date::processDate($params['fulfilled_date']));
         }
     }
     $form->assign('ccContribution', $ccContribution);
     if ($ccContribution) {
         //build the name.
         $name = CRM_Utils_Array::value('billing_first_name', $params);
         if (!empty($params['billing_middle_name'])) {
             $name .= " {$params['billing_middle_name']}";
         }
         $name .= ' ' . CRM_Utils_Array::value('billing_last_name', $params);
         $name = trim($name);
         $form->assign('billingName', $name);
         //assign the address formatted up for display
         $addressParts = array("street_address" => "billing_street_address-{$form->_bltID}", "city" => "billing_city-{$form->_bltID}", "postal_code" => "billing_postal_code-{$form->_bltID}", "state_province" => "state_province-{$form->_bltID}", "country" => "country-{$form->_bltID}");
         $addressFields = array();
         foreach ($addressParts as $name => $field) {
             $addressFields[$name] = CRM_Utils_Array::value($field, $params);
         }
         $form->assign('address', CRM_Utils_Address::format($addressFields));
         $date = CRM_Utils_Date::format($params['credit_card_exp_date']);
         $date = CRM_Utils_Date::mysqlToIso($date);
         $form->assign('credit_card_type', CRM_Utils_Array::value('credit_card_type', $params));
         $form->assign('credit_card_exp_date', $date);
         $form->assign('credit_card_number', CRM_Utils_System::mungeCreditCard($params['credit_card_number']));
     } else {
         //offline contribution
         // assigned various dates to the templates
         $form->assign('receipt_date', CRM_Utils_Date::processDate($params['receipt_date']));
         if (!empty($params['cancel_date'])) {
             $form->assign('cancel_date', CRM_Utils_Date::processDate($params['cancel_date']));
         }
         if (!empty($params['thankyou_date'])) {
             $form->assign('thankyou_date', CRM_Utils_Date::processDate($params['thankyou_date']));
         }
         if ($form->_action & CRM_Core_Action::UPDATE) {
             $form->assign('lineItem', empty($form->_lineItems) ? FALSE : $form->_lineItems);
         }
     }
     //handle custom data
     if (!empty($params['hidden_custom'])) {
         $contribParams = array(array('contribution_id', '=', $params['contribution_id'], 0, 0));
         if ($form->_mode == 'test') {
             $contribParams[] = array('contribution_test', '=', 1, 0, 0);
         }
         //retrieve custom data
         $customGroup = array();
         foreach ($form->_groupTree as $groupID => $group) {
             $customFields = $customValues = array();
             if ($groupID == 'info') {
                 continue;
             }
             foreach ($group['fields'] as $k => $field) {
                 $field['title'] = $field['label'];
                 $customFields["custom_{$k}"] = $field;
             }
             //build the array of customgroup contain customfields.
             CRM_Core_BAO_UFGroup::getValues($params['contact_id'], $customFields, $customValues, FALSE, $contribParams);
             $customGroup[$group['title']] = $customValues;
         }
         //assign all custom group and corresponding fields to template.
         $form->assign('customGroup', $customGroup);
     }
     $form->assign_by_ref('formValues', $params);
     list($contributorDisplayName, $contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($params['contact_id']);
     $form->assign('contactID', $params['contact_id']);
     $form->assign('contributionID', $params['contribution_id']);
     if (!empty($params['currency'])) {
         $form->assign('currency', $params['currency']);
     }
     if (!empty($params['receive_date'])) {
         $form->assign('receive_date', CRM_Utils_Date::processDate($params['receive_date']));
     }
     $template = CRM_Core_Smarty::singleton();
     $taxAmt = $template->get_template_vars('dataArray');
     $eventTaxAmt = $template->get_template_vars('totalTaxAmount');
     $prefixValue = Civi::settings()->get('contribution_invoice_settings');
     $invoicing = CRM_Utils_Array::value('invoicing', $prefixValue);
     if ((!empty($taxAmt) || isset($eventTaxAmt)) && (isset($invoicing) && isset($prefixValue['is_email_pdf']))) {
         $isEmailPdf = TRUE;
     } else {
         $isEmailPdf = FALSE;
     }
     list($sendReceipt, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(array('groupName' => 'msg_tpl_workflow_contribution', 'valueName' => 'contribution_offline_receipt', 'contactId' => $params['contact_id'], 'contributionId' => $params['contribution_id'], 'from' => $params['from_email_address'], 'toName' => $contributorDisplayName, 'toEmail' => $contributorEmail, 'isTest' => $form->_mode == 'test', 'PDFFilename' => ts('receipt') . '.pdf', 'isEmailPdf' => $isEmailPdf));
     return $sendReceipt;
 }
示例#16
0
 /**
  * Function to add the custom fields OR array of participant's
  * profile info
  *
  * @param $id
  * @param $name
  * @param $cid
  * @param $template
  * @param $participantId
  * @param $isTest
  * @param bool $isCustomProfile
  * @param array $participantParams
  *
  * @return void
  * @access public
  */
 static function buildCustomDisplay($id, $name, $cid, &$template, $participantId, $isTest, $isCustomProfile = FALSE, $participantParams = array())
 {
     if (!$id) {
         return array(NULL, NULL);
     }
     if (!is_array($id)) {
         $id = CRM_Utils_Type::escape($id, 'Positive');
         $profileIds = array($id);
     } else {
         $profileIds = $id;
     }
     foreach ($profileIds as $gid) {
         if (CRM_Core_BAO_UFGroup::filterUFGroups($gid, $cid)) {
             $values = array();
             $fields = CRM_Core_BAO_UFGroup::getFields($gid, FALSE, CRM_Core_Action::VIEW, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, 'field_name', TRUE);
             //this condition is added, since same contact can have multiple event registrations..
             $params = array(array('participant_id', '=', $participantId, 0, 0));
             //add participant id
             $fields['participant_id'] = array('name' => 'participant_id', 'title' => 'Participant Id');
             //check whether its a text drive
             if ($isTest) {
                 $params[] = array('participant_test', '=', 1, 0, 0);
             }
             //display campaign on thankyou page.
             if (array_key_exists('participant_campaign_id', $fields)) {
                 if ($participantId) {
                     $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $participantId, 'campaign_id');
                     $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
                     $values[$fields['participant_campaign_id']['title']] = CRM_Utils_Array::value($campaignId, $campaigns);
                 }
                 unset($fields['participant_campaign_id']);
             }
             $groupTitle = NULL;
             foreach ($fields as $k => $v) {
                 if (!$groupTitle) {
                     $groupTitle = $v['groupTitle'];
                 }
                 // suppress all file fields from display
                 if (CRM_Utils_Array::value('data_type', $v, '') == 'File' || CRM_Utils_Array::value('name', $v, '') == 'image_URL' || CRM_Utils_Array::value('field_type', $v) == 'Formatting') {
                     unset($fields[$k]);
                 }
             }
             if ($groupTitle) {
                 $groupTitles[] = $groupTitle;
             }
             //display profile groups those are subscribed by participant.
             if (($groups = CRM_Utils_Array::value('group', $participantParams)) && is_array($groups)) {
                 $grpIds = array();
                 foreach ($groups as $grpId => $isSelected) {
                     if ($isSelected) {
                         $grpIds[] = $grpId;
                     }
                 }
                 if (!empty($grpIds)) {
                     //get the group titles.
                     $grpTitles = array();
                     $query = 'SELECT title FROM civicrm_group where id IN ( ' . implode(',', $grpIds) . ' )';
                     $grp = CRM_Core_DAO::executeQuery($query);
                     while ($grp->fetch()) {
                         $grpTitles[] = $grp->title;
                     }
                     if (!empty($grpTitles) && CRM_Utils_Array::value('title', CRM_Utils_Array::value('group', $fields))) {
                         $values[$fields['group']['title']] = implode(', ', $grpTitles);
                     }
                     unset($fields['group']);
                 }
             }
             CRM_Core_BAO_UFGroup::getValues($cid, $fields, $values, FALSE, $params);
             if (isset($fields['participant_status_id']['title']) && isset($values[$fields['participant_status_id']['title']]) && is_numeric($values[$fields['participant_status_id']['title']])) {
                 $status = array();
                 $status = CRM_Event_PseudoConstant::participantStatus();
                 $values[$fields['participant_status_id']['title']] = $status[$values[$fields['participant_status_id']['title']]];
             }
             if (isset($fields['participant_role_id']['title']) && isset($values[$fields['participant_role_id']['title']]) && is_numeric($values[$fields['participant_role_id']['title']])) {
                 $roles = array();
                 $roles = CRM_Event_PseudoConstant::participantRole();
                 $values[$fields['participant_role_id']['title']] = $roles[$values[$fields['participant_role_id']['title']]];
             }
             if (isset($fields['participant_register_date']['title']) && isset($values[$fields['participant_register_date']['title']])) {
                 $values[$fields['participant_register_date']['title']] = CRM_Utils_Date::customFormat($values[$fields['participant_register_date']['title']]);
             }
             //handle fee_level for price set
             if (isset($fields['participant_fee_level']['title']) && isset($values[$fields['participant_fee_level']['title']])) {
                 $feeLevel = explode(CRM_Core_DAO::VALUE_SEPARATOR, $values[$fields['participant_fee_level']['title']]);
                 foreach ($feeLevel as $key => $value) {
                     if (!$value) {
                         unset($feeLevel[$key]);
                     }
                 }
                 $values[$fields['participant_fee_level']['title']] = implode(',', $feeLevel);
             }
             unset($values[$fields['participant_id']['title']]);
             $val[] = $values;
         }
     }
     if (count($val)) {
         $template->assign($name, $val);
     }
     if (count($groupTitles)) {
         $template->assign($name . '_grouptitle', $groupTitles);
     }
     //return if we only require array of participant's info.
     if ($isCustomProfile) {
         if (count($val)) {
             return array($val, $groupTitles);
         } else {
             return NULL;
         }
     }
 }
示例#17
0
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the  
  * type of action and executes that action. 
  *
  * @return void
  * @access public
  *
  */
 function run()
 {
     $template =& CRM_Core_Smarty::singleton();
     if ($this->_id && $this->_gid) {
         // first check that id is part of the limit group id, CRM-4822
         $limitListingsGroupsID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'limit_listings_group_id');
         $config =& CRM_Core_Config::singleton();
         if ($limitListingsGroupsID) {
             require_once 'CRM/Contact/BAO/GroupContact.php';
             if (!CRM_Contact_BAO_GroupContact::isContactInGroup($this->_id, $limitListingsGroupsID)) {
                 CRM_Core_Error::statusBounce(ts('You do not have permission to view this contact record. Contact the site administrator if you need assistance.'), $config->userFrameworkBaseURL);
             }
         }
         require_once 'CRM/Core/BAO/UFGroup.php';
         $values = array();
         $fields = CRM_Core_BAO_UFGroup::getFields($this->_gid, false, CRM_Core_Action::VIEW, null, null, false, $this->_restrict, $this->_skipPermission, null, CRM_Core_Permission::VIEW);
         // make sure we dont expose all fields based on permission
         $admin = false;
         $session =& CRM_Core_Session::singleton();
         if (!$config->userFrameworkFrontend && (CRM_Core_Permission::check('administer users') || CRM_Core_Permission::check('view all contacts')) || $this->_id == $session->get('userID')) {
             $admin = true;
         }
         if (!$admin) {
             foreach ($fields as $name => $field) {
                 // make sure that there is enough permission to expose this field
                 if ($field['visibility'] == 'User and User Admin Only') {
                     unset($fields[$name]);
                 }
             }
         }
         CRM_Core_BAO_UFGroup::getValues($this->_id, $fields, $values);
         // $profileFields_$gid array can be used for customized display of field labels and values in Profile/View.tpl
         $profileFields = array();
         $labels = array();
         foreach ($fields as $name => $field) {
             $labels[$field['title']] = preg_replace('/\\s+|\\W+/', '_', $name);
         }
         foreach ($values as $title => $value) {
             $profileFields[$labels[$title]] = array('label' => $title, 'value' => $value);
         }
         $template->assign_by_ref('row', $values);
         $template->assign_by_ref('profileFields_' . $this->_gid, $profileFields);
     }
     // invoke the pagRun hook, CRM-3906
     require_once 'CRM/Utils/Hook.php';
     CRM_Utils_Hook::pageRun($this);
     return trim($template->fetch($this->getTemplateFileName()));
 }
示例#18
0
 /**  
  * Function to add the custom fields OR array of participant's
  * profile info
  *  
  * @return None  
  * @access public  
  */
 function buildCustomDisplay($gid, $name, $cid, &$template, $participantId, $isTest, $isCustomProfile = false, $participantParams = array())
 {
     if ($gid) {
         require_once 'CRM/Core/BAO/UFGroup.php';
         if (CRM_Core_BAO_UFGroup::filterUFGroups($gid, $cid)) {
             $values = array();
             $fields = CRM_Core_BAO_UFGroup::getFields($gid, false, CRM_Core_Action::VIEW);
             //this condition is added, since same contact can have multiple event registrations..
             $params = array(array('participant_id', '=', $participantId, 0, 0));
             //add participant id
             $fields['participant_id'] = array('name' => 'participant_id', 'title' => 'Participant Id');
             //check whether its a text drive
             if ($isTest) {
                 $params[] = array('participant_test', '=', 1, 0, 0);
             }
             $groupTitles = array();
             $groupTitle = null;
             foreach ($fields as $k => $v) {
                 if (!$groupTitle) {
                     $groupTitle = $v["groupTitle"];
                 }
                 // suppress all file fields from display
                 if (CRM_Utils_Array::value('data_type', $v, '') == 'File' || CRM_Utils_Array::value('name', $v, '') == 'image_URL') {
                     unset($fields[$k]);
                 }
             }
             if ($groupTitle) {
                 $template->assign($name . "_grouptitle", $groupTitle);
                 $groupTitles[$name . "_grouptitle"] = $groupTitle;
             }
             //display profile groups those are subscribed by participant.
             if (($groups = CRM_Utils_Array::value('group', $participantParams)) && is_array($groups)) {
                 $grpIds = array();
                 foreach ($groups as $grpId => $isSelected) {
                     if ($isSelected) {
                         $grpIds[] = $grpId;
                     }
                 }
                 if (!empty($grpIds)) {
                     //get the group titles.
                     $grpTitles = array();
                     $query = 'SELECT title FROM civicrm_group where id IN ( ' . implode(',', $grpIds) . ' )';
                     $grp = CRM_Core_DAO::executeQuery($query);
                     while ($grp->fetch()) {
                         $grpTitles[] = $grp->title;
                     }
                     $values[$fields['group']['title']] = implode(', ', $grpTitles);
                     unset($fields['group']);
                 }
             }
             CRM_Core_BAO_UFGroup::getValues($cid, $fields, $values, false, $params);
             if (isset($values[$fields['participant_status_id']['title']]) && is_numeric($values[$fields['participant_status_id']['title']])) {
                 $status = array();
                 $status = CRM_Event_PseudoConstant::participantStatus();
                 $values[$fields['participant_status_id']['title']] = $status[$values[$fields['participant_status_id']['title']]];
             }
             if (isset($values[$fields['participant_role_id']['title']]) && is_numeric($values[$fields['participant_role_id']['title']])) {
                 $roles = array();
                 $roles = CRM_Event_PseudoConstant::participantRole();
                 $values[$fields['participant_role_id']['title']] = $roles[$values[$fields['participant_role_id']['title']]];
             }
             if (isset($fields['participant_register_date']['title']) && isset($values[$fields['participant_register_date']['title']])) {
                 $values[$fields['participant_register_date']['title']] = CRM_Utils_Date::customFormat($values[$fields['participant_register_date']['title']]);
             }
             //handle fee_level for price set
             if (isset($values[$fields['participant_fee_level']['title']])) {
                 $feeLevel = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $values[$fields['participant_fee_level']['title']]);
                 foreach ($feeLevel as $key => $val) {
                     if (!$val) {
                         unset($feeLevel[$key]);
                     }
                 }
                 $values[$fields['participant_fee_level']['title']] = implode(",", $feeLevel);
             }
             unset($values[$fields['participant_id']['title']]);
             //return if we only require array of participant's info.
             if ($isCustomProfile) {
                 if (count($values)) {
                     return array($values, $groupTitles);
                 } else {
                     return null;
                 }
             }
             if (count($values)) {
                 $template->assign($name, $values);
             }
         }
     }
 }
 /**
  * Process the renewal form.
  *
  *
  * @return void
  */
 public function postProcess()
 {
     $ids = array();
     $config = CRM_Core_Config::singleton();
     // get the submitted form values.
     $this->_params = $formValues = $this->controller->exportValues($this->_name);
     $this->storeContactFields($formValues);
     // use values from screen
     if ($formValues['membership_type_id'][1] != 0) {
         $defaults['receipt_text_renewal'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $formValues['membership_type_id'][1], 'receipt_text_renewal');
     }
     $now = CRM_Utils_Date::getToday(NULL, 'YmdHis');
     $this->convertDateFieldsToMySQL($formValues);
     $this->assign('receive_date', $formValues['receive_date']);
     if (!empty($this->_params['send_receipt'])) {
         $formValues['receipt_date'] = $now;
         $this->assign('receipt_date', CRM_Utils_Date::mysqlToIso($formValues['receipt_date']));
     } else {
         $formValues['receipt_date'] = NULL;
     }
     if ($this->_mode) {
         $formValues['total_amount'] = CRM_Utils_Array::value('total_amount', $this->_params, CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'minimum_fee'));
         if (empty($formValues['financial_type_id'])) {
             $formValues['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'financial_type_id');
         }
         $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($formValues['payment_processor_id'], $this->_mode);
         $fields = array();
         // set email for primary location.
         $fields['email-Primary'] = 1;
         $formValues['email-5'] = $formValues['email-Primary'] = $this->_contributorEmail;
         $formValues['register_date'] = $now;
         // now set the values for the billing location.
         foreach ($this->_fields as $name => $dontCare) {
             $fields[$name] = 1;
         }
         // also add location name to the array
         $formValues["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $formValues) . ' ' . CRM_Utils_Array::value('billing_middle_name', $formValues) . ' ' . CRM_Utils_Array::value('billing_last_name', $formValues);
         $formValues["address_name-{$this->_bltID}"] = trim($formValues["address_name-{$this->_bltID}"]);
         $fields["address_name-{$this->_bltID}"] = 1;
         $fields["email-{$this->_bltID}"] = 1;
         $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactID, 'contact_type');
         $nameFields = array('first_name', 'middle_name', 'last_name');
         foreach ($nameFields as $name) {
             $fields[$name] = 1;
             if (array_key_exists("billing_{$name}", $formValues)) {
                 $formValues[$name] = $formValues["billing_{$name}"];
                 $formValues['preserveDBName'] = TRUE;
             }
         }
         //here we are setting up the billing contact - if different from the member they are already created
         // but they will get billing details assigned
         CRM_Contact_BAO_Contact::createProfileContact($formValues, $fields, $this->_contributorContactID, NULL, NULL, $ctype);
         // add all the additional payment params we need
         $this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
         $this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
         $this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($this->_params);
         $this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params);
         $this->_params['description'] = ts('Office Credit Card Membership Renewal Contribution');
         $this->_params['ip_address'] = CRM_Utils_System::ipAddress();
         $this->_params['amount'] = $formValues['total_amount'];
         $this->_params['currencyID'] = $config->defaultCurrency;
         $this->_params['payment_action'] = 'Sale';
         $paymentParams['invoiceID'] = $this->_params['invoiceID'] = md5(uniqid(rand(), TRUE));
         // 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 passed params
         // so we copy stuff over to first_name etc.
         $paymentParams = $this->_params;
         if (!empty($this->_params['send_receipt'])) {
             $paymentParams['email'] = $this->_contributorEmail;
         }
         $paymentParams['contactID'] = $this->_contributorContactID;
         CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, TRUE);
         $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this);
         if (!empty($paymentParams['auto_renew'])) {
             $contributionRecurParams = $this->processRecurringContribution($paymentParams);
             $this->_params['contributionRecurID'] = $contributionRecurParams['contributionRecurID'];
             $paymentParams = array_merge($paymentParams, $contributionRecurParams);
         }
         $result = $payment->doDirectPayment($paymentParams);
         if (is_a($result, 'CRM_Core_Error')) {
             CRM_Core_Error::displaySessionError($result);
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/membership', "reset=1&action=renew&cid={$this->_contactID}&id={$this->_id}&context=membership&mode={$this->_mode}"));
         }
         if ($result) {
             $this->_params = array_merge($this->_params, $result);
         }
         $formValues['contribution_status_id'] = 1;
         $formValues['invoice_id'] = $this->_params['invoiceID'];
         $formValues['trxn_id'] = $result['trxn_id'];
         $formValues['payment_instrument_id'] = 1;
         $formValues['is_test'] = $this->_mode == 'live' ? 0 : 1;
         $this->set('params', $this->_params);
         $this->assign('trxn_id', $result['trxn_id']);
     }
     $renewalDate = NULL;
     if ($formValues['renewal_date']) {
         $this->set('renewalDate', CRM_Utils_Date::processDate($formValues['renewal_date']));
     }
     $this->_membershipId = $this->_id;
     // membership type custom data
     $customFields = CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, $formValues['membership_type_id'][1]);
     $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, NULL, NULL, TRUE));
     $customFieldsFormatted = CRM_Core_BAO_CustomField::postProcess($formValues, $customFields, $this->_id, 'Membership');
     // check for test membership.
     $isTestMembership = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_membershipId, 'is_test');
     // chk for renewal for multiple terms CRM-8750
     $numRenewTerms = 1;
     if (is_numeric(CRM_Utils_Array::value('num_terms', $formValues))) {
         $numRenewTerms = $formValues['num_terms'];
     }
     //if contribution status is pending then set pay later
     if ($formValues['contribution_status_id'] == array_search('Pending', CRM_Contribute_PseudoConstant::contributionStatus())) {
         $this->_params['is_pay_later'] = 1;
     }
     $renewMembership = CRM_Member_BAO_Membership::renewMembershipFormWrapper($this->_contactID, $formValues['membership_type_id'][1], $isTestMembership, $this, NULL, NULL, $customFieldsFormatted, $numRenewTerms, $this->_membershipId);
     $endDate = CRM_Utils_Date::processDate($renewMembership->end_date);
     // Retrieve the name and email of the current user - this will be the FROM for the receipt email
     $session = CRM_Core_Session::singleton();
     $userID = $session->get('userID');
     list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID);
     $memType = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $renewMembership->membership_type_id, 'name');
     if (!empty($formValues['record_contribution']) || $this->_mode) {
         // set the source
         $formValues['contribution_source'] = "{$memType} Membership: Offline membership renewal (by {$userName})";
         //create line items
         $lineItem = array();
         $priceSetId = NULL;
         CRM_Member_BAO_Membership::createLineItems($this, $formValues['membership_type_id'], $priceSetId);
         CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], $this->_params, $lineItem[$priceSetId]);
         //CRM-11529 for quick config backoffice transactions
         //when financial_type_id is passed in form, update the
         //line items with the financial type selected in form
         if ($submittedFinancialType = CRM_Utils_Array::value('financial_type_id', $formValues)) {
             foreach ($lineItem[$priceSetId] as &$li) {
                 $li['financial_type_id'] = $submittedFinancialType;
             }
         }
         $formValues['total_amount'] = CRM_Utils_Array::value('amount', $this->_params);
         if (!empty($lineItem)) {
             $formValues['lineItems'] = $lineItem;
             $formValues['processPriceSet'] = TRUE;
         }
         //assign contribution contact id to the field expected by recordMembershipContribution
         if ($this->_contributorContactID != $this->_contactID) {
             $formValues['contribution_contact_id'] = $this->_contributorContactID;
             if (!empty($this->_params['soft_credit_type_id'])) {
                 $formValues['soft_credit'] = array('soft_credit_type_id' => $this->_params['soft_credit_type_id'], 'contact_id' => $this->_contactID);
             }
         }
         $formValues['contact_id'] = $this->_contactID;
         //recordMembershipContribution receives params as a reference & adds one variable. This is
         // not a great pattern & ideally it would not receive as a reference. We assign our params as a
         // temporary variable to avoid e-notice & to make it clear to future refactorer that
         // this function is NOT reliant on that var being set
         $temporaryParams = array_merge($formValues, array('membership_id' => $renewMembership->id));
         CRM_Member_BAO_Membership::recordMembershipContribution($temporaryParams);
     }
     $receiptSend = FALSE;
     if (!empty($formValues['send_receipt'])) {
         $receiptSend = TRUE;
         $receiptFrom = $formValues['from_email_address'];
         if (!empty($formValues['payment_instrument_id'])) {
             $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
             $formValues['paidBy'] = $paymentInstrument[$formValues['payment_instrument_id']];
         }
         //get the group Tree
         $this->_groupTree = CRM_Core_BAO_CustomGroup::getTree('Membership', $this, $this->_id, FALSE, $this->_memType);
         // retrieve custom data
         $customFields = $customValues = $fo = array();
         foreach ($this->_groupTree as $groupID => $group) {
             if ($groupID == 'info') {
                 continue;
             }
             foreach ($group['fields'] as $k => $field) {
                 $field['title'] = $field['label'];
                 $customFields["custom_{$k}"] = $field;
             }
         }
         $members = array(array('member_id', '=', $this->_membershipId, 0, 0));
         // check whether its a test drive
         if ($this->_mode == 'test') {
             $members[] = array('member_test', '=', 1, 0, 0);
         }
         CRM_Core_BAO_UFGroup::getValues($this->_contactID, $customFields, $customValues, FALSE, $members);
         $this->assign_by_ref('formValues', $formValues);
         if (!empty($formValues['contribution_id'])) {
             $this->assign('contributionID', $formValues['contribution_id']);
         }
         $this->assign('membershipID', $this->_id);
         $this->assign('contactID', $this->_contactID);
         $this->assign('module', 'Membership');
         $this->assign('receiptType', 'membership renewal');
         $this->assign('mem_start_date', CRM_Utils_Date::customFormat($renewMembership->start_date));
         $this->assign('mem_end_date', CRM_Utils_Date::customFormat($renewMembership->end_date));
         $this->assign('membership_name', CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $renewMembership->membership_type_id));
         $this->assign('customValues', $customValues);
         if ($this->_mode) {
             if (!empty($this->_params['billing_first_name'])) {
                 $name = $this->_params['billing_first_name'];
             }
             if (!empty($this->_params['billing_middle_name'])) {
                 $name .= " {$this->_params['billing_middle_name']}";
             }
             if (!empty($this->_params['billing_last_name'])) {
                 $name .= " {$this->_params['billing_last_name']}";
             }
             $this->assign('billingName', $name);
             // assign the address formatted up for display
             $addressParts = array("street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "state_province-{$this->_bltID}", "country-{$this->_bltID}");
             $addressFields = array();
             foreach ($addressParts as $part) {
                 list($n, $id) = explode('-', $part);
                 if (isset($this->_params['billing_' . $part])) {
                     $addressFields[$n] = $this->_params['billing_' . $part];
                 }
             }
             $this->assign('address', CRM_Utils_Address::format($addressFields));
             $date = CRM_Utils_Date::format($this->_params['credit_card_exp_date']);
             $date = CRM_Utils_Date::mysqlToIso($date);
             $this->assign('credit_card_exp_date', $date);
             $this->assign('credit_card_number', CRM_Utils_System::mungeCreditCard($this->_params['credit_card_number']));
             $this->assign('credit_card_type', $this->_params['credit_card_type']);
             $this->assign('contributeMode', 'direct');
             $this->assign('isAmountzero', 0);
             $this->assign('is_pay_later', 0);
             $this->assign('isPrimary', 1);
             if ($this->_mode == 'test') {
                 $this->assign('action', '1024');
             }
         }
         list($mailSend, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(array('groupName' => 'msg_tpl_workflow_membership', 'valueName' => 'membership_offline_receipt', 'contactId' => $this->_receiptContactId, 'from' => $receiptFrom, 'toName' => $this->_contributorDisplayName, 'toEmail' => $this->_contributorEmail, 'isTest' => $this->_mode == 'test'));
     }
     $statusMsg = ts('%1 membership for %2 has been renewed.', array(1 => $memType, 2 => $this->_memberDisplayName));
     if ($endDate) {
         $statusMsg .= ' ' . ts('The new membership End Date is %1.', array(1 => CRM_Utils_Date::customFormat(substr($endDate, 0, 8))));
     }
     if ($receiptSend && $mailSend) {
         $statusMsg .= ' ' . ts('A renewal confirmation and receipt has been sent to %1.', array(1 => $this->_contributorEmail));
     }
     CRM_Core_Session::setStatus($statusMsg, ts('Complete'), 'success');
 }
示例#20
0
 /**
  * Send email receipt.
  *
  * @param CRM_Core_Form $form
  *   Form object.
  * @param array $formValues
  * @param object $membership
  *   Object.
  *
  * @return bool
  *   true if mail was sent successfully
  */
 public static function emailReceipt(&$form, &$formValues, &$membership)
 {
     // retrieve 'from email id' for acknowledgement
     $receiptFrom = $formValues['from_email_address'];
     if (!empty($formValues['payment_instrument_id'])) {
         $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
         $formValues['paidBy'] = $paymentInstrument[$formValues['payment_instrument_id']];
     }
     // retrieve custom data
     $customFields = $customValues = array();
     if (property_exists($form, '_groupTree') && !empty($form->_groupTree)) {
         foreach ($form->_groupTree as $groupID => $group) {
             if ($groupID == 'info') {
                 continue;
             }
             foreach ($group['fields'] as $k => $field) {
                 $field['title'] = $field['label'];
                 $customFields["custom_{$k}"] = $field;
             }
         }
     }
     $members = array(array('member_id', '=', $membership->id, 0, 0));
     // check whether its a test drive
     if ($form->_mode == 'test') {
         $members[] = array('member_test', '=', 1, 0, 0);
     }
     CRM_Core_BAO_UFGroup::getValues($formValues['contact_id'], $customFields, $customValues, FALSE, $members);
     if ($form->_mode) {
         if (!empty($form->_params['billing_first_name'])) {
             $name = $form->_params['billing_first_name'];
         }
         if (!empty($form->_params['billing_middle_name'])) {
             $name .= " {$form->_params['billing_middle_name']}";
         }
         if (!empty($form->_params['billing_last_name'])) {
             $name .= " {$form->_params['billing_last_name']}";
         }
         $form->assign('billingName', $name);
         // assign the address formatted up for display
         $addressParts = array("street_address-{$form->_bltID}", "city-{$form->_bltID}", "postal_code-{$form->_bltID}", "state_province-{$form->_bltID}", "country-{$form->_bltID}");
         $addressFields = array();
         foreach ($addressParts as $part) {
             list($n, $id) = explode('-', $part);
             if (isset($form->_params['billing_' . $part])) {
                 $addressFields[$n] = $form->_params['billing_' . $part];
             }
         }
         $form->assign('address', CRM_Utils_Address::format($addressFields));
         $date = CRM_Utils_Date::format($form->_params['credit_card_exp_date']);
         $date = CRM_Utils_Date::mysqlToIso($date);
         $form->assign('credit_card_exp_date', $date);
         $form->assign('credit_card_number', CRM_Utils_System::mungeCreditCard($form->_params['credit_card_number']));
         $form->assign('credit_card_type', $form->_params['credit_card_type']);
         $form->assign('contributeMode', 'direct');
         $form->assign('isAmountzero', 0);
         $form->assign('is_pay_later', 0);
         $form->assign('isPrimary', 1);
     }
     $form->assign('module', 'Membership');
     $form->assign('contactID', $formValues['contact_id']);
     $form->assign('membershipID', CRM_Utils_Array::value('membership_id', $form->_params, CRM_Utils_Array::value('membership_id', $form->_defaultValues)));
     if (!empty($formValues['contribution_id'])) {
         $form->assign('contributionID', $formValues['contribution_id']);
     } elseif (isset($form->_onlinePendingContributionId)) {
         $form->assign('contributionID', $form->_onlinePendingContributionId);
     }
     if (!empty($formValues['contribution_status_id'])) {
         $form->assign('contributionStatusID', $formValues['contribution_status_id']);
         $form->assign('contributionStatus', CRM_Contribute_PseudoConstant::contributionStatus($formValues['contribution_status_id'], 'name'));
     }
     if (!empty($formValues['is_renew'])) {
         $form->assign('receiptType', 'membership renewal');
     } else {
         $form->assign('receiptType', 'membership signup');
     }
     $form->assign('receive_date', CRM_Utils_Date::processDate(CRM_Utils_Array::value('receive_date', $formValues)));
     $form->assign('formValues', $formValues);
     if (empty($lineItem)) {
         $form->assign('mem_start_date', CRM_Utils_Date::customFormat($membership->start_date, '%B %E%f, %Y'));
         if (!CRM_Utils_System::isNull($membership->end_date)) {
             $form->assign('mem_end_date', CRM_Utils_Date::customFormat($membership->end_date, '%B %E%f, %Y'));
         }
         $form->assign('membership_name', CRM_Member_PseudoConstant::membershipType($membership->membership_type_id));
     }
     $form->assign('customValues', $customValues);
     $isBatchProcess = is_a($form, 'CRM_Batch_Form_Entry');
     if (empty($form->_contributorDisplayName) || empty($form->_contributorEmail) || $isBatchProcess) {
         // in this case the form is being called statically from the batch editing screen
         // having one class in the form layer call another statically is not greate
         // & we should aim to move this function to the BAO layer in future.
         // however, we can assume that the contact_id passed in by the batch
         // function will be the recipient
         list($form->_contributorDisplayName, $form->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($formValues['contact_id']);
         if (empty($form->_receiptContactId) || $isBatchProcess) {
             $form->_receiptContactId = $formValues['contact_id'];
         }
     }
     $template = CRM_Core_Smarty::singleton();
     $taxAmt = $template->get_template_vars('dataArray');
     $eventTaxAmt = $template->get_template_vars('totalTaxAmount');
     $prefixValue = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
     $invoicing = CRM_Utils_Array::value('invoicing', $prefixValue);
     if ((!empty($taxAmt) || isset($eventTaxAmt)) && (isset($invoicing) && isset($prefixValue['is_email_pdf']))) {
         $isEmailPdf = TRUE;
     } else {
         $isEmailPdf = FALSE;
     }
     list($mailSend, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(array('groupName' => 'msg_tpl_workflow_membership', 'valueName' => 'membership_offline_receipt', 'contactId' => $form->_receiptContactId, 'from' => $receiptFrom, 'toName' => $form->_contributorDisplayName, 'toEmail' => $form->_contributorEmail, 'PDFFilename' => ts('receipt') . '.pdf', 'isEmailPdf' => $isEmailPdf, 'contributionId' => $formValues['contribution_id'], 'isTest' => (bool) ($form->_action & CRM_Core_Action::PREVIEW)));
     return TRUE;
 }
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the
  * type of action and executes that action.
  *
  * @return void
  * @access public
  *
  */
 function run()
 {
     $template = CRM_Core_Smarty::singleton();
     if ($this->_id && $this->_gid) {
         // first check that id is part of the limit group id, CRM-4822
         $limitListingsGroupsID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'limit_listings_group_id');
         $config = CRM_Core_Config::singleton();
         if ($limitListingsGroupsID) {
             if (!CRM_Contact_BAO_GroupContact::isContactInGroup($this->_id, $limitListingsGroupsID)) {
                 CRM_Utils_System::setTitle(ts('Profile View - Permission Denied'));
                 return CRM_Core_Session::setStatus(ts('You do not have permission to view this contact record. Contact the site administrator if you need assistance.'));
             }
         }
         $values = array();
         $fields = CRM_Core_BAO_UFGroup::getFields($this->_profileIds, FALSE, CRM_Core_Action::VIEW, NULL, NULL, FALSE, $this->_restrict, $this->_skipPermission, NULL, CRM_Core_Permission::VIEW);
         if ($this->_isContactActivityProfile && $this->_gid) {
             $errors = CRM_Profile_Form::validateContactActivityProfile($this->_activityId, $this->_id, $this->_gid);
             if (!empty($errors)) {
                 CRM_Core_Error::fatal(array_pop($errors));
             }
         }
         $session = CRM_Core_Session::singleton();
         $userID = $session->get('userID');
         $this->_isPermissionedChecksum = FALSE;
         if ($this->_id != $userID) {
             // do not allow edit for anon users in joomla frontend, CRM-4668, unless u have checksum CRM-5228
             if ($config->userFrameworkFrontend) {
                 $this->_isPermissionedChecksum = CRM_Contact_BAO_Contact_Permission::validateOnlyChecksum($this->_id, $this, FALSE);
             } else {
                 $this->_isPermissionedChecksum = CRM_Contact_BAO_Contact_Permission::validateChecksumContact($this->_id, $this, FALSE);
             }
         }
         // make sure we dont expose all fields based on permission
         $admin = FALSE;
         if (!$config->userFrameworkFrontend && (CRM_Core_Permission::check('administer users') || CRM_Core_Permission::check('view all contacts') || CRM_Contact_BAO_Contact_Permission::allow($this->_id, CRM_Core_Permission::VIEW)) || $this->_id == $userID || $this->_isPermissionedChecksum) {
             $admin = TRUE;
         }
         if (!$admin) {
             foreach ($fields as $name => $field) {
                 // make sure that there is enough permission to expose this field
                 if ($field['visibility'] == 'User and User Admin Only') {
                     unset($fields[$name]);
                 }
             }
         }
         // also eliminate all formatting fields
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('field_type', $field) == 'Formatting') {
                 unset($fields[$name]);
             }
         }
         if ($this->_isContactActivityProfile) {
             $contactFields = $activityFields = array();
             foreach ($fields as $fieldName => $field) {
                 if (CRM_Utils_Array::value('field_type', $field) == 'Activity') {
                     $activityFields[$fieldName] = $field;
                 } else {
                     $contactFields[$fieldName] = $field;
                 }
             }
             CRM_Core_BAO_UFGroup::getValues($this->_id, $contactFields, $values);
             if ($this->_activityId) {
                 CRM_Core_BAO_UFGroup::getValues(NULL, $activityFields, $values, TRUE, array(array('activity_id', '=', $this->_activityId, 0, 0)));
             }
         } else {
             CRM_Core_BAO_UFGroup::getValues($this->_id, $fields, $values);
         }
         // $profileFields array can be used for customized display of field labels and values in Profile/View.tpl
         $profileFields = array();
         $labels = array();
         foreach ($fields as $name => $field) {
             $labels[$field['title']] = preg_replace('/\\s+|\\W+/', '_', $name);
         }
         foreach ($values as $title => $value) {
             $profileFields[$labels[$title]] = array('label' => $title, 'value' => $value);
         }
         $template->assign_by_ref('row', $values);
         $template->assign_by_ref('profileFields', $profileFields);
     }
     $name = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'name');
     if (strtolower($name) == 'summary_overlay') {
         $template->assign('overlayProfile', TRUE);
     }
     $title = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'title');
     //CRM-4131.
     $displayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_id, 'display_name');
     if ($displayName) {
         $session = CRM_Core_Session::singleton();
         $config = CRM_Core_Config::singleton();
         if ($session->get('userID') && CRM_Core_Permission::check('access CiviCRM') && CRM_Contact_BAO_Contact_Permission::allow($session->get('userID'), CRM_Core_Permission::VIEW) && !$config->userFrameworkFrontend) {
             $contactViewUrl = CRM_Utils_System::url('civicrm/contact/view', "action=view&reset=1&cid={$this->_id}", TRUE);
             $this->assign('displayName', $displayName);
             $displayName = "<a href=\"{$contactViewUrl}\">{$displayName}</a>";
         }
         $title .= ' - ' . $displayName;
     }
     CRM_Utils_System::setTitle($title);
     // invoke the pagRun hook, CRM-3906
     CRM_Utils_Hook::pageRun($this);
     return trim($template->fetch($this->getTemplateFileName()));
 }