/**
  * Build custom data view.
  *
  * @param CRM_Core_Form $form
  *   Page object.
  * @param array $groupTree
  * @param bool $returnCount
  *   True if customValue count needs to be returned.
  * @param int $gID
  * @param null $prefix
  * @param int $customValueId
  * @param int $entityId
  *
  * @return array|int
  */
 public static function buildCustomDataView(&$form, &$groupTree, $returnCount = FALSE, $gID = NULL, $prefix = NULL, $customValueId = NULL, $entityId = NULL)
 {
     $details = array();
     foreach ($groupTree as $key => $group) {
         if ($key === 'info') {
             continue;
         }
         foreach ($group['fields'] as $k => $properties) {
             $groupID = $group['id'];
             if (!empty($properties['customValue'])) {
                 foreach ($properties['customValue'] as $values) {
                     if (!empty($customValueId) && $customValueId != $values['id']) {
                         continue;
                     }
                     $details[$groupID][$values['id']]['title'] = CRM_Utils_Array::value('title', $group);
                     $details[$groupID][$values['id']]['name'] = CRM_Utils_Array::value('name', $group);
                     $details[$groupID][$values['id']]['help_pre'] = CRM_Utils_Array::value('help_pre', $group);
                     $details[$groupID][$values['id']]['help_post'] = CRM_Utils_Array::value('help_post', $group);
                     $details[$groupID][$values['id']]['collapse_display'] = CRM_Utils_Array::value('collapse_display', $group);
                     $details[$groupID][$values['id']]['collapse_adv_display'] = CRM_Utils_Array::value('collapse_adv_display', $group);
                     $details[$groupID][$values['id']]['fields'][$k] = array('field_title' => CRM_Utils_Array::value('label', $properties), 'field_type' => CRM_Utils_Array::value('html_type', $properties), 'field_data_type' => CRM_Utils_Array::value('data_type', $properties), 'field_value' => CRM_Core_BAO_CustomField::displayValue($values['data'], $properties['id'], $entityId), 'options_per_line' => CRM_Utils_Array::value('options_per_line', $properties));
                     // also return contact reference contact id if user has view all or edit all contacts perm
                     if ((CRM_Core_Permission::check('view all contacts') || CRM_Core_Permission::check('edit all contacts')) && $details[$groupID][$values['id']]['fields'][$k]['field_data_type'] == 'ContactReference') {
                         $details[$groupID][$values['id']]['fields'][$k]['contact_ref_id'] = CRM_Utils_Array::value('data', $values);
                     }
                 }
             } else {
                 $details[$groupID][0]['title'] = CRM_Utils_Array::value('title', $group);
                 $details[$groupID][0]['name'] = CRM_Utils_Array::value('name', $group);
                 $details[$groupID][0]['help_pre'] = CRM_Utils_Array::value('help_pre', $group);
                 $details[$groupID][0]['help_post'] = CRM_Utils_Array::value('help_post', $group);
                 $details[$groupID][0]['collapse_display'] = CRM_Utils_Array::value('collapse_display', $group);
                 $details[$groupID][0]['collapse_adv_display'] = CRM_Utils_Array::value('collapse_adv_display', $group);
                 $details[$groupID][0]['fields'][$k] = array('field_title' => CRM_Utils_Array::value('label', $properties));
             }
         }
     }
     if ($returnCount) {
         //return a single value count if group id is passed to function
         //else return a groupId and count mapped array
         if (!empty($gID)) {
             return count($details[$gID]);
         } else {
             $countValue = array();
             foreach ($details as $key => $value) {
                 $countValue[$key] = count($details[$key]);
             }
             return $countValue;
         }
     } else {
         $form->assign_by_ref("{$prefix}viewCustomData", $details);
         return $details;
     }
 }
 /**
  * generic function to build all the view form elements for a specific group tree
  *
  * @param CRM_Core_Form $page      the page object
  * @param array         $groupTree the group tree object
  * @param string        $viewName  what name should all the values be stored under
  * @param string        $showName  
  * @param string        $hideName
  *
  * @return void
  * @access public
  * @static
  */
 function buildViewHTML(&$page, &$groupTree, $viewName = 'viewForm', $showName = 'showBlocks1', $hideName = 'hideBlocks1')
 {
     //showhide blocks for Custom Fields inline
     $sBlocks = array();
     $hBlocks = array();
     $form = array();
     foreach ($groupTree as $group) {
         $groupId = $group['id'];
         foreach ($group['fields'] as $field) {
             $fieldId = $field['id'];
             $elementName = 'custom_' . $fieldId;
             $form[$elementName] = array();
             $form[$elementName]['name'] = $elementName;
             $form[$elementName]['html'] = null;
             if ($field['data_type'] == 'String' || $field['data_type'] == 'Int' || $field['data_type'] == 'Float' || $field['data_type'] == 'Money') {
                 //added check for Multi-Select in the below if-statement
                 if ($field['html_type'] == 'Radio' || $field['html_type'] == 'CheckBox' || $field['html_type'] == 'Multi-Select') {
                     $freezeString = "";
                     $freezeStringChecked = "";
                     $customData = array();
                     //added check for Multi-Select in the below if-statement
                     if ($field['html_type'] == 'CheckBox' || $field['html_type'] == 'Multi-Select') {
                         $customData = explode(CRM_CORE_BAO_CUSTOMOPTION_VALUE_SEPERATOR, $field['customValue']['data']);
                     } else {
                         $customData[] = $field['customValue']['data'];
                     }
                     $coDAO =& new CRM_Core_DAO_CustomOption();
                     $coDAO->entity_id = $field['id'];
                     $coDAO->entity_table = 'civicrm_custom_field';
                     $coDAO->orderBy('weight ASC, label ASC');
                     $coDAO->find();
                     $counter = 1;
                     while ($coDAO->fetch()) {
                         //to show only values that are checked
                         if (in_array($coDAO->value, $customData)) {
                             $checked = in_array($coDAO->value, $customData) ? $freezeStringChecked : $freezeString;
                             if ($counter != 1) {
                                 $form[$elementName]['html'] .= $checked . ", " . $coDAO->label;
                             } else {
                                 $form[$elementName]['html'] .= $checked . $coDAO->label;
                             }
                             $form[$elementName][$counter]['html'] = $checked . $coDAO->label . "\n";
                             $counter++;
                         }
                     }
                 } else {
                     if ($field['html_type'] == 'Select') {
                         $coDAO =& new CRM_Core_DAO_CustomOption();
                         $coDAO->entity_id = $field['id'];
                         $coDAO->entity_table = 'civicrm_custom_field';
                         $coDAO->orderBy('weight ASC, label ASC');
                         $coDAO->find();
                         while ($coDAO->fetch()) {
                             if ($coDAO->value == $field['customValue']['data']) {
                                 $form[$elementName]['html'] = $coDAO->label;
                             }
                         }
                     } else {
                         $form[$elementName]['html'] = $field['customValue']['data'];
                     }
                 }
             } else {
                 if (isset($field['customValue']['data'])) {
                     switch ($field['data_type']) {
                         case 'Boolean':
                             $freezeString = "";
                             $freezeStringChecked = "";
                             if (isset($field['customValue']['data'])) {
                                 if ($field['customValue']['data'] == '1') {
                                     $form[$elementName]['html'] = $freezeStringChecked . "Yes\n";
                                 } else {
                                     $form[$elementName]['html'] = $freezeStringChecked . "No\n";
                                 }
                             } else {
                                 $form[$elementName]['html'] = "\n";
                             }
                             break;
                         case 'StateProvince':
                             $form[$elementName]['html'] = CRM_Core_PseudoConstant::stateProvince($field['customValue']['data']);
                             break;
                         case 'Country':
                             $form[$elementName]['html'] = CRM_Core_PseudoConstant::country($field['customValue']['data']);
                             break;
                         case 'Date':
                             $format = null;
                             if ($field['date_parts']) {
                                 $parts = explode(CRM_CORE_BAO_CUSTOMOPTION_VALUE_SEPERATOR, $field['date_parts']);
                                 foreach ($parts as $v) {
                                     $format = $format . " %" . $v;
                                 }
                                 $format = str_replace('M', 'B', $format);
                             }
                             $form[$elementName]['html'] = CRM_Utils_Date::customFormat($field['customValue']['data'], $format);
                             break;
                         default:
                             $form[$elementName]['html'] = $field['customValue']['data'];
                     }
                 }
             }
         }
         //showhide group
         if ($group['collapse_display']) {
             $sBlocks[] = "'" . $group['title'] . "[show]'";
             $hBlocks[] = "'" . $group['title'] . "'";
         } else {
             $hBlocks[] = "'" . $group['title'] . "[show]'";
             $sBlocks[] = "'" . $group['title'] . "'";
         }
     }
     $showBlocks = implode(",", $sBlocks);
     $hideBlocks = implode(",", $hBlocks);
     $page->assign($viewName, $form);
     $page->assign($showName, $showBlocks);
     $page->assign($hideName, $hideBlocks);
     $page->assign_by_ref('groupTree', $groupTree);
 }
Beispiel #3
0
 /**
  * Build parent groups form elements.
  *
  * @param CRM_Core_Form $form
  *
  * @return array
  *   parent groups
  */
 public static function buildParentGroups(&$form)
 {
     $groupNames = CRM_Core_PseudoConstant::group();
     $parentGroups = $parentGroupElements = array();
     if (isset($form->_id) && !empty($form->_groupValues['parents'])) {
         $parentGroupIds = explode(',', $form->_groupValues['parents']);
         foreach ($parentGroupIds as $parentGroupId) {
             $parentGroups[$parentGroupId] = $groupNames[$parentGroupId];
             if (array_key_exists($parentGroupId, $groupNames)) {
                 $parentGroupElements[$parentGroupId] = $groupNames[$parentGroupId];
                 $form->addElement('checkbox', "remove_parent_group_{$parentGroupId}", $groupNames[$parentGroupId]);
             }
         }
     }
     $form->assign_by_ref('parent_groups', $parentGroupElements);
     if (isset($form->_id)) {
         $potentialParentGroupIds = CRM_Contact_BAO_GroupNestingCache::getPotentialCandidates($form->_id, $groupNames);
     } else {
         $potentialParentGroupIds = array_keys($groupNames);
     }
     $parentGroupSelectValues = array('' => '- ' . ts('select group') . ' -');
     foreach ($potentialParentGroupIds as $potentialParentGroupId) {
         if (array_key_exists($potentialParentGroupId, $groupNames)) {
             $parentGroupSelectValues[$potentialParentGroupId] = $groupNames[$potentialParentGroupId];
         }
     }
     if (count($parentGroupSelectValues) > 1) {
         if (CRM_Core_Permission::isMultisiteEnabled()) {
             $required = !isset($form->_id) || $form->_id && CRM_Core_BAO_Domain::isDomainGroup($form->_id) ? FALSE : empty($parentGroups);
         } else {
             $required = FALSE;
         }
         $form->add('select', 'parents', ts('Add Parent'), $parentGroupSelectValues, $required, array('class' => 'crm-select2'));
     }
     return $parentGroups;
 }
 /**
  * generic function to build all the form elements for a specific group tree
  *
  * @param CRM_Core_Form $form      the form object
  * @param array         $groupTree the group tree object
  * @param string        $showName  
  * @param string        $hideName
  *
  * @return void
  * @access public
  * @static
  */
 static function buildQuickForm(&$form, &$groupTree, $inactiveNeeded = false, $groupCount = 1, $prefix = '')
 {
     require_once 'CRM/Core/BAO/CustomField.php';
     require_once 'CRM/Core/BAO/CustomOption.php';
     $form->assign_by_ref("{$prefix}groupTree", $groupTree);
     $sBlocks = array();
     $hBlocks = array();
     // this is fix for date field
     $form->assign('currentYear', date('Y'));
     require_once 'CRM/Core/ShowHideBlocks.php';
     foreach ($groupTree as $id => $group) {
         CRM_Core_ShowHideBlocks::links($form, $group['title'], '', '');
         $groupId = CRM_Utils_Array::value('id', $group);
         foreach ($group['fields'] as $field) {
             // skip all view fields
             if (CRM_Utils_Array::value('is_view', $field)) {
                 continue;
             }
             $required = CRM_Utils_Array::value('is_required', $field);
             //fix for CRM-1620
             if ($field['data_type'] == 'File') {
                 if (isset($field['customValue']['data'])) {
                     $required = 0;
                 }
             }
             $fieldId = $field['id'];
             $elementName = $field['element_name'];
             require_once "CRM/Core/BAO/CustomField.php";
             CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, $inactiveNeeded, $required);
         }
     }
 }
 /**
  * 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;
 }