Example #1
0
 function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     $parent = $this->controller->getParent();
     if (!empty($params)) {
         $fields = array('mailing_name', 'mailing_from', 'mailing_to', 'sort_name');
         foreach ($fields as $field) {
             if (isset($params[$field]) && !CRM_Utils_System::isNull($params[$field])) {
                 if (substr($field, 7) != 'name') {
                     $parent->set($field, CRM_Utils_Date::unformat(CRM_Utils_Date::processDate($params[$field]), ''));
                 } else {
                     $parent->set($field, $params[$field]);
                 }
             } else {
                 $parent->set($field, null);
             }
         }
     }
 }
Example #2
0
 function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     $parent = $this->controller->getParent();
     $parent->set('searchResult', 1);
     if (!empty($params)) {
         $fields = array('title', 'event_type_id', 'start_date', 'end_date', 'eventsByDates');
         foreach ($fields as $field) {
             if (isset($params[$field]) && !CRM_Utils_System::isNull($params[$field])) {
                 if (substr($field, -4) == 'date') {
                     $parent->set($field, CRM_Utils_Date::unformat(CRM_Utils_Date::processDate($params[$field]), ''));
                 } else {
                     $parent->set($field, $params[$field]);
                 }
             } else {
                 $parent->set($field, null);
             }
         }
     }
 }
Example #3
0
 static function dateParam($fieldName, &$field, &$defaults)
 {
     // type = 12 (datetime) is not recognized by Utils_Type::escape() method,
     // and therefore the below hack
     $type = 4;
     $from = self::getTypedValue("{$fieldName}_from", $type);
     $to = self::getTypedValue("{$fieldName}_to", $type);
     $relative = CRM_Utils_Array::value("{$fieldName}_relative", $_GET);
     if ($relative) {
         list($from, $to) = CRM_Report_Form::getFromTo($relative, null, null);
     }
     if (!($from || $to)) {
         return false;
     } else {
         if ($from || $to || $relative) {
             // unset other criteria
             self::unsetFilters($defaults);
         }
     }
     $defaults["{$fieldName}_from"] = CRM_Utils_Date::unformat($from, '');
     $defaults["{$fieldName}_to"] = CRM_Utils_Date::unformat($to, '');
 }
 /**
  * Function to extract the get params from the url, validate
  * and store it in session
  *
  * @param CRM_Core_Form $form the form object
  * @param string        $type the type of custom group we are using
  * @return void
  * @access public
  * @static
  */
 function extractGetParams(&$form, $type)
 {
     // if not GET params return
     if (empty($_GET)) {
         return;
     }
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree($type);
     $customFields =& CRM_Core_BAO_CustomField::getFields($type);
     $customValue = array();
     $htmlType = array('CheckBox', 'Multi-Select', 'Select', 'Radio');
     foreach ($groupTree as $group) {
         foreach ($group['fields'] as $key => $field) {
             $fieldName = 'custom_' . $key;
             $value = CRM_Utils_Request::retrieve($fieldName, $form);
             if ($value) {
                 if (!in_array($customFields[$key][3], $htmlType) || $customFields[$key][2] == 'Boolean') {
                     $valid = CRM_Core_BAO_CustomValue::typecheck($customFields[$key][2], $value);
                 }
                 if ($customFields[$key][3] == 'CheckBox' || $customFields[$key][3] == 'Multi-Select') {
                     $value = str_replace("|", ",", $value);
                     $mulValues = explode(',', $value);
                     $customOption = CRM_Core_BAO_CustomOption::getCustomOption($key, true);
                     $val = array();
                     foreach ($mulValues as $v1) {
                         foreach ($customOption as $v2) {
                             if (strtolower(trim($v2['label'])) == strtolower(trim($v1))) {
                                 $val[$v2['value']] = 1;
                             }
                         }
                     }
                     if (!empty($val)) {
                         $value = $val;
                         $valid = true;
                     } else {
                         $value = null;
                     }
                 } else {
                     if ($customFields[$key][3] == 'Select' || $customFields[$key][3] == 'Radio' && $customFields[$key][2] != 'Boolean') {
                         $customOption = CRM_Core_BAO_CustomOption::getCustomOption($key, true);
                         foreach ($customOption as $v2) {
                             if (strtolower(trim($v2['label'])) == strtolower(trim($value))) {
                                 $value = $v2['value'];
                                 $valid = true;
                             }
                         }
                     } else {
                         if ($customFields[$key][2] == 'Date') {
                             require_once 'CRM/Utils/Date.php';
                             if (is_numeric($value)) {
                                 $value = CRM_Utils_Date::unformat($value, null);
                             } else {
                                 $value = CRM_Utils_Date::unformat($value, $separator = '-');
                             }
                             $valid = true;
                         }
                     }
                 }
                 if ($valid) {
                     $customValue[$fieldName] = $value;
                 }
             }
         }
     }
     $form->set('customGetValues', $customValue);
     $form->set('groupTree', $groupTree);
 }
Example #5
0
 function fixFormValues()
 {
     // if this search has been forced
     // then see if there are any get values, and if so over-ride the post values
     // note that this means that GET over-rides POST :)
     // we fix date_to here if set to be the end of the day, i.e. 23:59:59
     if (!CRM_Utils_System::isNull($this->_formValues['contribution_date_to'])) {
         $this->_formValues['contribution_date_to']['H'] = 23;
         $this->_formValues['contribution_date_to']['i'] = 59;
         $this->_formValues['contribution_date_to']['s'] = 59;
     }
     if (!$this->_force) {
         return;
     }
     $nullObject = null;
     $status = CRM_Utils_Request::retrieve('status', $nullObject);
     if ($status) {
         switch ($status) {
             case 'Valid':
             case 'Cancelled':
             case 'All':
                 $this->_formValues['contribution_status'] = $status;
                 $this->_defaults['contribution_status'] = $status;
                 break;
         }
     }
     $cid = CRM_Utils_Request::retrieve('cid', $nullObject);
     if ($cid) {
         $cid = CRM_Utils_Type::escape($cid, 'Integer');
         if ($cid > 0) {
             $this->_formValues['contact_id'] = $cid;
             list($display, $image) = CRM_Contact_BAO_Contact::getDisplayAndImage($cid);
             $this->_defaults['sort_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'sort_name');
             // also assign individual mode to the template
             $this->_single = true;
         }
     }
     $fromDate = CRM_Utils_Request::retrieve('start', $nullObject);
     if ($fromDate) {
         $fromDate = CRM_Utils_Type::escape($fromDate, 'Timestamp');
         $date = CRM_Utils_Date::unformat($fromDate, '');
         $this->_formValues['contribution_date_from'] = $date;
         $this->_defaults['contribution_date_from'] = $date;
     }
     $toDate = CRM_Utils_Request::retrieve('end', $nullObject);
     if ($toDate) {
         $toDate = CRM_Utils_Type::escape($toDate, 'Timestamp');
         $date = CRM_Utils_Date::unformat($toDate, '');
         $this->_formValues['contribution_date_to'] = $date;
         $this->_defaults['contribution_date_to'] = $date;
         $this->_formValues['contribution_date_to']['H'] = 23;
         $this->_formValues['contribution_date_to']['i'] = 59;
         $this->_formValues['contribution_date_to']['s'] = 59;
     }
     $this->_limit = CRM_Utils_Request::retrieve('limit', $this);
 }
Example #6
0
 /**
  * convert any given date string to default date array.
  *
  * @param array  $params     has given date-format
  * @param array  $formatted  store formatted date in this array
  * @param int    $dateType   type of date  
  * @param string $dateParam  index of params
  * @static
  */
 function formatCustomDate(&$params, &$formatted, $dateType, $dateParam)
 {
     //fix for CRM-2687
     CRM_Utils_Date::convertToDefaultDate($params, $dateType, $dateParam);
     if ($dateType == 1) {
         if (strstr($params[$dateParam], '-')) {
             $formatted[$dateParam] = CRM_Utils_Date::unformat($params[$dateParam]);
         } else {
             $formatted[$dateParam] = CRM_Utils_Date::unformat(CRM_Utils_Date::mysqlToIso($params[$dateParam]));
         }
     } else {
         $formatted[$dateParam] = CRM_Utils_Date::unformat(CRM_Utils_Date::mysqlToIso($params[$dateParam]));
     }
 }
 /**
  * Given a custom field value, its id and the set of options
  * find the default value for this field
  *
  * @param  mixed  $value     the custom field value
  * @param  int    $id        the custom field id
  * @param  int    $options   the assoc array of option name/value pairs
  *
  * @return   mixed   the default value
  * @static
  * @access public
  */
 function getDefaultValue($value, $id, &$options)
 {
     $option =& $options[$id];
     $attributes =& $option['attributes'];
     $html_type = $attributes['html_type'];
     $index = $attributes['label'];
     $default = $value;
     switch ($html_type) {
         case "CheckBox":
             $checkedData = explode(CRM_CORE_BAO_CUSTOMOPTION_VALUE_SEPERATOR, $value);
             $default = array();
             foreach ($checkedData as $val) {
                 $default[$val] = 1;
             }
             break;
         case "Select Date":
             $default = CRM_Utils_Date::unformat($value);
             break;
     }
     return $default;
 }
Example #8
0
 /**
  * Given a custom field value, its id and the set of options
  * find the default value for this field
  *
  * @param  mixed  $value     the custom field value
  * @param  int    $id        the custom field id
  * @param  int    $options   the assoc array of option name/value pairs
  *
  * @return   mixed   the default value
  * @static
  * @access public
  */
 function getDefaultValue($value, $id, &$options)
 {
     $option =& $options[$id];
     $attributes =& $option['attributes'];
     $html_type = $attributes['html_type'];
     $default = $value;
     switch ($html_type) {
         case "CheckBox":
             $checkedData = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, substr($value, 1, -1));
             $default = array();
             foreach ($checkedData as $val) {
                 $default[$val] = 1;
             }
             break;
         case "Select Date":
             $default = CRM_Utils_Date::unformat($value);
             break;
     }
     return $default;
 }
Example #9
0
 function alterDisplay(&$rows)
 {
     // custom code to alter rows
     $entryFound = false;
     foreach ($rows as $rowNum => $row) {
         // make count columns point to detail report
         if (CRM_Utils_Array::value('join_date', $this->_params['group_bys']) && CRM_Utils_Array::value('civicrm_membership_join_date_start', $row) && $row['civicrm_membership_join_date_start'] && $row['civicrm_membership_join_date_subtotal']) {
             $dateStart = CRM_Utils_Date::customFormat($row['civicrm_membership_join_date_start'], '%Y%m%d');
             $dateEnd = CRM_Utils_Date::unformat($dateStart, '');
             switch (strtolower($this->_params['group_bys_freq']['join_date'])) {
                 case 'month':
                     $dateEnd = date("Ymd", mktime(0, 0, 0, $dateEnd['M'] + 1, $dateEnd['d'] - 1, $dateEnd['Y']));
                     break;
                 case 'year':
                     $dateEnd = date("Ymd", mktime(0, 0, 0, $dateEnd['M'], $dateEnd['d'] - 1, $dateEnd['Y'] + 1));
                     break;
                 case 'yearweek':
                     $dateEnd = date("Ymd", mktime(0, 0, 0, $dateEnd['M'], $dateEnd['d'] + 6, $dateEnd['Y']));
                     break;
                 case 'quarter':
                     $dateEnd = date("Ymd", mktime(0, 0, 0, $dateEnd['M'] + 3, $dateEnd['d'] - 1, $dateEnd['Y']));
                     break;
             }
             $url = CRM_Report_Utils_Report::getNextUrl('member/detail', "reset=1&force=1&join_date_from={$dateStart}&join_date_to={$dateEnd}", $this->_absoluteUrl, $this->_id);
             $row['civicrm_membership_join_date_start'] = CRM_Utils_Date::format($row['civicrm_membership_join_date_start']);
             $rows[$rowNum]['civicrm_membership_join_date_start_link'] = $url;
             $rows[$rowNum]['civicrm_membership_join_date_start_hover'] = ts("Lists Summary of Memberships for this date unit.");
             $entryFound = true;
         }
         // handle Membership Types
         if (array_key_exists('civicrm_membership_membership_type_id', $row)) {
             if ($value = $row['civicrm_membership_membership_type_id']) {
                 $value = explode(',', $value);
                 foreach ($value as $key => $id) {
                     $value[$key] = CRM_Member_PseudoConstant::membershipType($id, false);
                 }
                 $rows[$rowNum]['civicrm_membership_membership_type_id'] = implode(' , ', $value);
             }
             $entryFound = true;
         }
         // make subtotals look nicer
         if (array_key_exists('civicrm_membership_join_date_subtotal', $row) && !$row['civicrm_membership_join_date_subtotal']) {
             $this->fixSubTotalDisplay($rows[$rowNum], $this->_statFields);
             $entryFound = true;
         }
         // skip looking further in rows, if first row itself doesn't
         // have the column we need
         if (!$entryFound) {
             break;
         }
     }
 }
Example #10
0
 function createActivity($activityTypeXML, &$params)
 {
     $activityTypeName = (string) $activityTypeXML->name;
     $activityTypes =& $this->allActivityTypes();
     $activityTypeInfo = CRM_Utils_Array::value($activityTypeName, $activityTypes);
     if (!$activityTypeInfo) {
         require_once 'CRM/Utils/System.php';
         $docLink = CRM_Utils_System::docURL2("CiviCase Configuration");
         CRM_Core_Error::fatal(ts('Activity type %1, found in case configuration file, is not present in the database %2', array(1 => $activityTypeName, 2 => $docLink)));
         return false;
     }
     $activityTypeID = $activityTypeInfo['id'];
     if (isset($activityTypeXML->status)) {
         $statusName = (string) $activityTypeXML->status;
     } else {
         $statusName = 'Scheduled';
     }
     require_once 'CRM/Core/OptionGroup.php';
     if ($activityTypeName == 'Open Case') {
         $activityParams = array('activity_type_id' => $activityTypeID, 'source_contact_id' => $params['creatorID'], 'is_auto' => false, 'is_current_revision' => 1, 'subject' => CRM_Utils_Array::value('subject', $params) ? $params['subject'] : $activityTypeName, 'status_id' => CRM_Core_OptionGroup::getValue('activity_status', $statusName, 'name'), 'target_contact_id' => $params['clientID'], 'medium_id' => CRM_Utils_Array::value('medium_id', $params), 'location' => CRM_Utils_Array::value('location', $params), 'details' => CRM_Utils_Array::value('details', $params), 'duration' => CRM_Utils_Array::value('duration', $params));
     } else {
         $activityParams = array('activity_type_id' => $activityTypeID, 'source_contact_id' => $params['creatorID'], 'is_auto' => true, 'is_current_revision' => 1, 'status_id' => CRM_Core_OptionGroup::getValue('activity_status', $statusName, 'name'), 'target_contact_id' => $params['clientID']);
     }
     if ($activityTypeName == 'Open Case') {
         // we don't set activity_date_time for auto generated
         // activities, but we want it to be set for open case.
         $activityParams['activity_date_time'] = $params['activity_date_time'];
         if (array_key_exists('custom', $params) && is_array($params['custom'])) {
             $activityParams['custom'] = $params['custom'];
         }
     } else {
         $activityDate = null;
         //get date of reference activity if set.
         if ($referenceActivityName = (string) $activityTypeXML->reference_activity) {
             //we skip open case as reference activity.CRM-4374.
             if (CRM_Utils_Array::value('resetTimeline', $params) && $referenceActivityName == 'Open Case') {
                 $activityDate = $params['activity_date_time'];
             } else {
                 $referenceActivityInfo = CRM_Utils_Array::value($referenceActivityName, $activityTypes);
                 if ($referenceActivityInfo['id']) {
                     $caseActivityParams = array('activity_type_id' => $referenceActivityInfo['id']);
                     //if reference_select is set take according activity.
                     if ($referenceSelect = (string) $activityTypeXML->reference_select) {
                         $caseActivityParams[$referenceSelect] = 1;
                     }
                     require_once 'CRM/Case/BAO/Case.php';
                     $referenceActivity = CRM_Case_BAO_Case::getCaseActivityDates($params['caseID'], $caseActivityParams, true);
                     if (is_array($referenceActivity)) {
                         foreach ($referenceActivity as $aId => $details) {
                             $activityDate = CRM_Utils_Array::value('activity_date', $details);
                             break;
                         }
                     }
                 }
             }
         }
         if (!$activityDate) {
             $activityDate = $params['activity_date_time'];
         }
         $datetime = new DateTime($activityDate);
         $activityDateTime = CRM_Utils_Date::unformat($datetime->format('Y:m:d:H:i:s'), ':');
         //add reference offset to date.
         if ((int) $activityTypeXML->reference_offset) {
             $activityDateTime = CRM_Utils_Date::intervalAdd('day', (int) $activityTypeXML->reference_offset, $activityDateTime);
         }
         $activityParams['activity_date_time'] = CRM_Utils_Date::format($activityDateTime);
     }
     // if same activity is already there, skip and dont touch
     $params['activityTypeID'] = $activityTypeID;
     $params['activityTypeName'] = $activityTypeName;
     if ($this->isActivityPresent($params)) {
         return true;
     }
     $activityParams['case_id'] = $params['caseID'];
     if (CRM_Utils_Array::value('is_auto', $activityParams)) {
         $activityParams['skipRecentView'] = true;
     }
     require_once 'CRM/Activity/BAO/Activity.php';
     $activity = CRM_Activity_BAO_Activity::create($activityParams);
     if (!$activity) {
         CRM_Core_Error::fatal();
         return false;
     }
     // create case activity record
     $caseParams = array('activity_id' => $activity->id, 'case_id' => $params['caseID']);
     require_once 'CRM/Case/BAO/Case.php';
     CRM_Case_BAO_Case::processCaseActivity($caseParams);
     return true;
 }
Example #11
0
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     require_once 'CRM/Utils/Money.php';
     $this->addYesNo('is_monetary', ts('Paid Event'), null, null, array('onclick' => "return showHideByValue('is_monetary','0','event-fees','block','radio',false);"));
     require_once 'CRM/Contribute/PseudoConstant.php';
     $paymentProcessor =& CRM_Core_PseudoConstant::paymentProcessor();
     $this->assign('paymentProcessor', $paymentProcessor);
     $this->add('select', 'payment_processor_id', ts('Payment Processor'), array('' => ts('- select -')) + $paymentProcessor);
     $this->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType());
     // add pay later options
     $this->addElement('checkbox', 'is_pay_later', ts('Enable Pay Later option?'), null, array('onclick' => "return showHideByValue('is_pay_later','','payLaterOptions','block','radio',false);"));
     $this->addElement('textarea', 'pay_later_text', ts('Pay Later Label'), CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'pay_later_text'), false);
     $this->addElement('textarea', 'pay_later_receipt', ts('Pay Later Instructions'), CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'pay_later_receipt'), false);
     $this->add('text', 'fee_label', ts('Fee Label'));
     require_once 'CRM/Price/BAO/Set.php';
     $this->add('select', 'price_set_id', ts('Price Set'), array('' => ts('- none -')) + CRM_Price_BAO_Set::getAssoc(false, 'Event'), null, array('onchange' => "return showHideByValue('price_set_id', '', 'map-field', 'block', 'select', false);"));
     $default = array();
     for ($i = 1; $i <= self::NUM_OPTION; $i++) {
         // label
         $this->add('text', "label[{$i}]", ts('Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'label'));
         // value
         $this->add('text', "value[{$i}]", ts('Value'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'value'));
         $this->addRule("value[{$i}]", ts('Please enter a valid money value for this field (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money');
         // default
         $default[] = $this->createElement('radio', null, null, null, $i);
     }
     $this->addGroup($default, 'default');
     $this->addElement('checkbox', 'is_discount', ts('Discounts by Signup Date?'), null, array('onclick' => "warnDiscountDel(); return showHideByValue('is_discount','','discount','block','radio',false);"));
     $discountSection = $this->get('discountSection');
     $this->assign('discountSection', $discountSection);
     require_once 'CRM/Core/ShowHideBlocks.php';
     // form fields of Discount sets
     $defaultOption = array();
     $_showHide =& new CRM_Core_ShowHideBlocks('', '');
     for ($i = 1; $i <= self::NUM_DISCOUNT; $i++) {
         //the show hide blocks
         $showBlocks = 'discount_' . $i;
         if ($i > 2) {
             $_showHide->addHide($showBlocks);
         } else {
             $_showHide->addShow($showBlocks);
         }
         //Increment by 1 of start date of previous end date.
         if (is_array($this->_submitValues) && !empty($this->_submitValues['discount_name'][$i]) && !empty($this->_submitValues['discount_name'][$i + 1]) && isset($this->_submitValues['discount_end_date']) && isset($this->_submitValues['discount_end_date'][$i]) && array_values($this->_submitValues['discount_end_date'][$i]) && $i < self::NUM_DISCOUNT - 1) {
             $end_date = CRM_Utils_Date::format($this->_submitValues['discount_end_date'][$i], '-');
             if (!empty($this->_submitValues['discount_end_date'][$i + 1]['M']) && empty($this->_submitValues['discount_start_date'][$i + 1]['M'])) {
                 $this->_submitValues['discount_start_date'][$i + 1] = CRM_Utils_Date::unformat(date('Y-m-d', strtotime("+1 days {$end_date}")));
             }
         }
         //Decrement by 1 of end date from next start date.
         if ($i > 1 && is_array($this->_submitValues) && !empty($this->_submitValues['discount_name'][$i]) && !empty($this->_submitValues['discount_name'][$i - 1]) && isset($this->_submitValues['discount_start_date']) && isset($this->_submitValues['discount_start_date'][$i]) && array_values($this->_submitValues['discount_start_date'][$i])) {
             $start_date = CRM_Utils_Date::format($this->_submitValues['discount_start_date'][$i], '-');
             if (!empty($this->_submitValues['discount_start_date'][$i]['M']) && empty($this->_submitValues['discount_end_date'][$i - 1]['M'])) {
                 $this->_submitValues['discount_end_date'][$i - 1] = CRM_Utils_Date::unformat(date('Y-m-d', strtotime("-1 days {$start_date}")));
             }
         }
         //discount name
         $this->add('text', 'discount_name[' . $i . ']', ts('Discount Name'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'label'));
         //discount start date
         $this->add('date', 'discount_start_date[' . $i . ']', ts('Discount Start Date'), CRM_Core_SelectValues::date('activityDate'));
         //discount end date
         $this->add('date', 'discount_end_date[' . $i . ']', ts('Discount End Date'), CRM_Core_SelectValues::date('activityDate'));
     }
     $_showHide->addToTemplate();
     $this->addElement('submit', $this->getButtonName('submit'), ts('Add Discount Set to Fee Table'), array('class' => 'form-submit'));
     $this->buildAmountLabel();
     parent::buildQuickForm();
 }
Example #12
0
 function fixFormValues()
 {
     if (!$this->_force) {
         return;
     }
     // set pledge payment related fields
     $status = CRM_Utils_Request::retrieve('status', 'String', CRM_Core_DAO::$_nullObject);
     if ($status) {
         $this->_formValues['pledge_payment_status_id'] = array($status => 1);
         $this->_defaults['pledge_payment_status_id'] = array($status => 1);
     }
     $fromDate = CRM_Utils_Request::retrieve('start', 'Date', CRM_Core_DAO::$_nullObject);
     if ($fromDate) {
         $date = CRM_Utils_Date::unformat($fromDate, '');
         $this->_formValues['pledge_payment_date_low'] = $date;
         $this->_defaults['pledge_payment_date_low'] = $date;
     }
     $toDate = CRM_Utils_Request::retrieve('end', 'Date', CRM_Core_DAO::$_nullObject);
     if ($toDate) {
         $date = CRM_Utils_Date::unformat($toDate, '');
         $this->_formValues['pledge_payment_date_high'] = $date;
         $this->_defaults['pledge_payment_date_high'] = $date;
     }
     // set pledge related fields
     $pledgeStatus = CRM_Utils_Request::retrieve('pstatus', 'String', CRM_Core_DAO::$_nullObject);
     if ($pledgeStatus) {
         require_once 'CRM/Contribute/PseudoConstant.php';
         $statusValues = CRM_Contribute_PseudoConstant::contributionStatus();
         // Remove status values that are only used for recurring contributions for now (Failed).
         unset($statusValues['4']);
         // we need set all statuses except Cancelled
         unset($statusValues[$pledgeStatus]);
         $statuses = array();
         foreach ($statusValues as $statusId => $value) {
             $statuses[$statusId] = 1;
         }
         $this->_formValues['pledge_status_id'] = $statuses;
         $this->_defaults['pledge_status_id'] = $statuses;
     }
     $pledgeFromDate = CRM_Utils_Request::retrieve('pstart', 'Date', CRM_Core_DAO::$_nullObject);
     if ($pledgeFromDate) {
         list($date) = CRM_Utils_Date::setDateDefaults($pledgeFromDate);
         $this->_formValues['pledge_create_date_low'] = $this->_defaults['pledge_create_date_low'] = $date;
     }
     $pledgeToDate = CRM_Utils_Request::retrieve('pend', 'Date', CRM_Core_DAO::$_nullObject);
     if ($pledgeToDate) {
         list($date) = CRM_Utils_Date::setDateDefaults($pledgeToDate);
         $this->_formValues['pledge_create_date_high'] = $this->_defaults['pledge_create_date_high'] = $date;
     }
     $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     if ($cid) {
         $cid = CRM_Utils_Type::escape($cid, 'Integer');
         if ($cid > 0) {
             require_once 'CRM/Contact/BAO/Contact.php';
             $this->_formValues['contact_id'] = $cid;
             list($display, $image) = CRM_Contact_BAO_Contact::getDisplayAndImage($cid);
             $this->_defaults['sort_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'sort_name');
             // also assign individual mode to the template
             $this->_single = true;
         }
     }
 }
Example #13
0
 function alterDisplay(&$rows)
 {
     // custom code to alter rows
     $entryFound = false;
     foreach ($rows as $rowNum => $row) {
         // make count columns point to detail report
         if (CRM_Utils_Array::value('receive_date', $this->_params['group_bys']) && CRM_Utils_Array::value('civicrm_contribution_receive_date_start', $row) && CRM_Utils_Array::value('civicrm_contribution_receive_date_start', $row) && CRM_Utils_Array::value('civicrm_contribution_receive_date_subtotal', $row)) {
             $dateStart = CRM_Utils_Date::customFormat($row['civicrm_contribution_receive_date_start'], '%Y%m%d');
             $dateEnd = CRM_Utils_Date::unformat($dateStart, '');
             switch (strtolower($this->_params['group_bys_freq']['receive_date'])) {
                 case 'month':
                     $dateEnd = date("Ymd", mktime(0, 0, 0, $dateEnd['M'] + 1, $dateEnd['d'] - 1, $dateEnd['Y']));
                     break;
                 case 'year':
                     $dateEnd = date("Ymd", mktime(0, 0, 0, $dateEnd['M'], $dateEnd['d'] - 1, $dateEnd['Y'] + 1));
                     break;
                 case 'yearweek':
                     $dateEnd = date("Ymd", mktime(0, 0, 0, $dateEnd['M'], $dateEnd['d'] + 6, $dateEnd['Y']));
                     break;
                 case 'quarter':
                     $dateEnd = date("Ymd", mktime(0, 0, 0, $dateEnd['M'] + 3, $dateEnd['d'] - 1, $dateEnd['Y']));
                     break;
             }
             $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail', "reset=1&force=1&receive_date_from={$dateStart}&receive_date_to={$dateEnd}", $this->_absoluteUrl, $this->_id);
             $rows[$rowNum]['civicrm_contribution_receive_date_start_link'] = $url;
             $rows[$rowNum]['civicrm_contribution_receive_date_start_hover'] = ts('List all contribution(s) for this date unit.');
             $entryFound = true;
         }
         // make subtotals look nicer
         if (array_key_exists('civicrm_contribution_receive_date_subtotal', $row) && !$row['civicrm_contribution_receive_date_subtotal']) {
             $this->fixSubTotalDisplay($rows[$rowNum], $this->_statFields);
             $entryFound = true;
         }
         // handle state province
         if (array_key_exists('civicrm_address_state_province_id', $row)) {
             if ($value = $row['civicrm_address_state_province_id']) {
                 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value, false);
                 $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail', "reset=1&force=1&state_province_id_op=in&state_province_id_value={$value}", $this->_absoluteUrl, $this->_id);
                 $rows[$rowNum]['civicrm_address_state_province_id_link'] = $url;
                 $rows[$rowNum]['civicrm_address_state_province_id_hover'] = ts('List all contribution(s) for this state.');
             }
             $entryFound = true;
         }
         // handle country
         if (array_key_exists('civicrm_address_country_id', $row)) {
             if ($value = $row['civicrm_address_country_id']) {
                 $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value, false);
                 $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail', "reset=1&force=1&" . "country_id_op=in&country_id_value={$value}", $this->_absoluteUrl, $this->_id);
                 $rows[$rowNum]['civicrm_address_country_id_link'] = $url;
                 $rows[$rowNum]['civicrm_address_country_id_hover'] = ts('List all contribution(s) for this country.');
             }
             $entryFound = true;
         }
         // convert display name to links
         if (array_key_exists('civicrm_contact_display_name', $row) && array_key_exists('civicrm_contact_id', $row)) {
             $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail', 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contact_id'], $this->_absoluteUrl, $this->_id);
             $rows[$rowNum]['civicrm_contact_display_name_link'] = $url;
             $rows[$rowNum]['civicrm_contact_display_name_hover'] = ts("Lists detailed contribution(s) for this record.");
             $entryFound = true;
         }
         // skip looking further in rows, if first row itself doesn't
         // have the column we need
         if (!$entryFound) {
             break;
         }
     }
 }
Example #14
0
 static function create($params)
 {
     require_once 'CRM/Contribute/PseudoConstant.php';
     require_once 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     $scheduled_date = CRM_Utils_Date::unformat($params['scheduled_date'], '');
     $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus();
     //calculation of schedule date according to frequency day of period
     //frequency day is not applicable for daily installments
     if ($params['frequency_unit'] != 'day') {
         if ($params['frequency_unit'] != 'week') {
             //for month use day of next month & for year use day of month Jan of next year as next payment date
             $scheduled_date['d'] = $params['frequency_day'];
             if ($params['frequency_unit'] == 'year') {
                 $scheduled_date['M'] = 1;
             }
         } else {
             if ($params['frequency_unit'] == 'week') {
                 //for week calculate day of week ie. Sunday,Monday etc. as next payment date
                 $dayOfWeek = date('w', mktime(0, 0, 0, $scheduled_date['M'], $scheduled_date['d'], $scheduled_date['Y']));
                 $frequencyDay = $params['frequency_day'] - $dayOfWeek;
                 $scheduleDate = explode("-", date('n-j-Y', mktime(0, 0, 0, $scheduled_date['M'], $scheduled_date['d'] + $frequencyDay, $scheduled_date['Y'])));
                 $scheduled_date['M'] = $scheduleDate[0];
                 $scheduled_date['d'] = $scheduleDate[1];
                 $scheduled_date['Y'] = $scheduleDate[2];
             }
         }
     }
     //calculate the scheduled date for every installment
     $now = date('Ymd');
     $prevScheduledDate = array();
     $statues = array();
     $prevScheduledDate[1] = CRM_Utils_Date::format($params['scheduled_date']);
     if (CRM_Utils_Date::overdue(CRM_Utils_Date::customFormat($prevScheduledDate[1], '%Y%m%d'), $now)) {
         $statues[1] = array_search('Overdue', $contributionStatus);
     } else {
         $statues[1] = array_search('Pending', $contributionStatus);
     }
     for ($i = 1; $i < $params['installments']; $i++) {
         $prevScheduledDate[$i + 1] = CRM_Utils_Date::format(CRM_Utils_Date::intervalAdd($params['frequency_unit'], $i * $params['frequency_interval'], $scheduled_date));
         if (CRM_Utils_Date::overdue(CRM_Utils_Date::customFormat($prevScheduledDate[$i + 1], '%Y%m%d'), $now)) {
             $statues[$i + 1] = array_search('Overdue', $contributionStatus);
         } else {
             $statues[$i + 1] = array_search('Pending', $contributionStatus);
         }
     }
     if ($params['installment_amount']) {
         $params['scheduled_amount'] = $params['installment_amount'];
     } else {
         $params['scheduled_amount'] = round($params['amount'] / $params['installments'], 2);
     }
     for ($i = 1; $i <= $params['installments']; $i++) {
         //calculate the scheduled amount for every installment.
         if ($i == $params['installments']) {
             $params['scheduled_amount'] = $params['amount'] - ($i - 1) * $params['scheduled_amount'];
         }
         if (!isset($params['contribution_id']) && $params['installments'] > 1) {
             $params['status_id'] = $statues[$i];
         }
         $params['scheduled_date'] = $prevScheduledDate[$i];
         $payment = self::add($params);
         if (is_a($payment, 'CRM_Core_Error')) {
             $transaction->rollback();
             return $payment;
         }
         // we should add contribution id to only first payment record
         if (isset($params['contribution_id'])) {
             unset($params['contribution_id']);
         }
     }
     //update pledge status
     self::updatePledgePaymentStatus($params['pledge_id']);
     $transaction->commit();
     return $payment;
 }
Example #15
0
 /**
  * Given the list of params in the params array, fetch the object
  * and store the values in the values array
  *
  * @param array $params input parameters to find object
  * @param array $values output values of the object
  * @param array $ids    the array that holds all the db ids
  *
  * @return CRM_Contact_BAO_Contact|null the found object or null
  * @access public
  * @static
  */
 static function getValues(&$params, &$values, &$ids)
 {
     $individual =& new CRM_Contact_BAO_Individual();
     $individual->copyValues($params);
     if ($individual->find(true)) {
         $ids['individual'] = $individual->id;
         CRM_Core_DAO::storeValues($individual, $values);
         if (isset($individual->birth_date)) {
             $values['birth_date'] = CRM_Utils_Date::unformat($individual->birth_date);
         }
         return $individual;
     }
     return null;
 }
Example #16
0
 function fixFormValues()
 {
     if (!$this->_force) {
         return;
     }
     $caseStatus = CRM_Utils_Request::retrieve('status', 'Positive', CRM_Core_DAO::$_nullObject);
     if ($caseStatus) {
         $this->_formValues['case_status_id'] = $caseStatus;
         $this->_defaults['case_status_id'] = $caseStatus;
     }
     $caseType = CRM_Utils_Request::retrieve('type', 'Positive', CRM_Core_DAO::$_nullObject);
     if ($caseType) {
         $this->_formValues['case_type_id'][$caseType] = 1;
         $this->_defaults['case_type_id'][$caseType] = 1;
     }
     $caseFromDate = CRM_Utils_Request::retrieve('pstart', 'Date', CRM_Core_DAO::$_nullObject);
     if ($caseFromDate) {
         $date = CRM_Utils_Date::unformat($caseFromDate, '');
         $this->_formValues['case_start_date_low'] = $date;
         $this->_defaults['case_start_date_low'] = $date;
     }
     $caseToDate = CRM_Utils_Request::retrieve('pend', 'Date', CRM_Core_DAO::$_nullObject);
     if ($caseToDate) {
         $date = CRM_Utils_Date::unformat($caseToDate, '');
         $this->_formValues['case_start_date_high'] = $date;
         $this->_defaults['case_start_date_high'] = $date;
     }
     $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     if ($cid) {
         $cid = CRM_Utils_Type::escape($cid, 'Integer');
         if ($cid > 0) {
             require_once 'CRM/Contact/BAO/Contact.php';
             $this->_formValues['contact_id'] = $cid;
             list($display, $image) = CRM_Contact_BAO_Contact::getDisplayAndImage($cid);
             $this->_defaults['sort_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'sort_name');
             // also assign individual mode to the template
             $this->_single = true;
         }
     } else {
         $session =& CRM_Core_Session::singleton();
         if (!CRM_Utils_Request::retrieve('all', 'Positive', $session)) {
             $this->_formValues['case_mycases'] = 0;
             $this->_formValues['case_owner'] = 0;
             $this->_defaults['case_owner'] = 0;
         } else {
             $this->_formValues['case_owner'] = 1;
             $this->_defaults['case_owner'] = 1;
         }
         $caseOwner = CRM_Utils_Request::retrieve('case_owner', 'Boolean', CRM_Core_DAO::$_nullObject);
         if ($caseOwner) {
             $this->_formValues['case_owner'] = 0;
             $this->_defaults['case_owner'] = 0;
         }
     }
 }
 /**
  * This function sets the default values for the form. Relationship that in edit/view mode
  * the default values are retrieved from the database
  * 
  * @access public
  * @return None
  */
 function setDefaultValues()
 {
     $defaults = array();
     $params = array();
     if ($this->_action & CRM_CORE_ACTION_UPDATE) {
         $relationship =& new CRM_Contact_DAO_Relationship();
         $relationship->id = $this->_relationshipId;
         if ($relationship->find(true)) {
             $defaults['relationship_type_id'] = $relationship->relationship_type_id . '_' . $this->_rtype;
             $defaults['start_date'] = CRM_Utils_Date::unformat($relationship->start_date);
             $defaults['end_date'] = CRM_Utils_Date::unformat($relationship->end_date);
             $contact =& new CRM_Contact_DAO_Contact();
             if ($this->_rtype == 'a_b' && $relationship->contact_id_a == $this->_contactId) {
                 $contact->id = $relationship->contact_id_b;
             } else {
                 $contact->id = $relationship->contact_id_a;
             }
             if ($contact->find(true)) {
                 $this->assign('sort_name', $contact->sort_name);
             }
         }
     }
     return $defaults;
 }
Example #18
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']) {
         $renewalDate = CRM_Utils_Date::processDate($formValues['renewal_date']);
         $changeToday = array();
         $dateUnformated = CRM_Utils_Date::unformat($renewalDate, '');
         $changeToday['month'] = $dateUnformated[$config->dateformatMonthVar];
         $changeToday['day'] = $dateUnformated['d'];
         $changeToday['year'] = $dateUnformated['Y'];
         $this->set('renewDate', $changeToday);
     }
     $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::mysqlToIso(CRM_Utils_Date::format($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_contribution', 'valueName' => 'contribution_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);
 }