3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
35 class CRM_Contribute_Form_AdditionalInfo
{
38 * Function to build the form for Premium Information.
44 static function buildPremium(&$form) {
46 $form->add('hidden', 'hidden_Premium', 1);
47 $sel1 = $sel2 = array();
49 $dao = new CRM_Contribute_DAO_Product();
52 $min_amount = array();
53 $sel1[0] = '-select product-';
54 while ($dao->fetch()) {
55 $sel1[$dao->id
] = $dao->name
. " ( " . $dao->sku
. " )";
56 $min_amount[$dao->id
] = $dao->min_contribution
;
57 $options = explode(',', $dao->options
);
58 foreach ($options as $k => $v) {
59 $options[$k] = trim($v);
61 if ($options[0] != '') {
62 $sel2[$dao->id
] = $options;
64 $form->assign('premiums', TRUE);
66 $form->_options
= $sel2;
67 $form->assign('mincontribution', $min_amount);
68 $sel = & $form->addElement('hierselect', "product_name", ts('Premium'), 'onclick="showMinContrib();"');
69 $js = "<script type='text/javascript'>\n";
70 $formName = 'document.forms.' . $form->getName();
72 for ($k = 1; $k < 2; $k++
) {
73 if (!isset($defaults['product_name'][$k]) ||
(!$defaults['product_name'][$k])) {
74 $js .= "{$formName}['product_name[$k]'].style.display = 'none';\n";
78 $sel->setOptions(array($sel1, $sel2));
80 $form->assign('initHideBoxes', $js);
82 $form->addDate('fulfilled_date', ts('Fulfilled'), FALSE, array('formatType' => 'activityDate'));
83 $form->addElement('text', 'min_amount', ts('Minimum Contribution Amount'));
87 * Function to build the form for Additional Details.
93 static function buildAdditionalDetail(&$form) {
94 //Additional information section
95 $form->add('hidden', 'hidden_AdditionalDetail', 1);
97 $attributes = CRM_Core_DAO
::getAttribute('CRM_Contribute_DAO_Contribution');
99 $form->addDateTime('thankyou_date', ts('Thank-you Sent'), FALSE, array('formatType' => 'activityDateTime'));
101 // add various amounts
102 $nonDeductAmount = & $form->add('text', 'non_deductible_amount', ts('Non-deductible Amount'),
103 $attributes['non_deductible_amount']
105 $form->addRule('non_deductible_amount', ts('Please enter a valid monetary value for Non-deductible Amount.'), 'money');
107 if ($form->_online
) {
108 $nonDeductAmount->freeze();
110 $feeAmount = & $form->add('text', 'fee_amount', ts('Fee Amount'),
111 $attributes['fee_amount']
113 $form->addRule('fee_amount', ts('Please enter a valid monetary value for Fee Amount.'), 'money');
114 if ($form->_online
) {
115 $feeAmount->freeze();
118 $netAmount = & $form->add('text', 'net_amount', ts('Net Amount'),
119 $attributes['net_amount']
121 $form->addRule('net_amount', ts('Please enter a valid monetary value for Net Amount.'), 'money');
122 if ($form->_online
) {
123 $netAmount->freeze();
125 $element = & $form->add('text', 'invoice_id', ts('Invoice ID'),
126 $attributes['invoice_id']
128 if ($form->_online
) {
132 $form->addRule('invoice_id',
133 ts('This Invoice ID already exists in the database.'),
135 array('CRM_Contribute_DAO_Contribution', $form->_id
, 'invoice_id')
139 $form->add('select', 'contribution_page_id',
140 ts('Online Contribution Page'),
142 '' => ts('- select -')
144 CRM_Contribute_PseudoConstant
::contributionPage()
147 $form->add('textarea', 'note', ts('Notes'), array("rows" => 4, "cols" => 60));
149 $statusName = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
150 if ($form->_id
&& $form->_values
['contribution_status_id'] == array_search('Cancelled', $statusName)) {
151 $netAmount->freeze();
152 $feeAmount->freeze();
158 * Function to build the form for Honoree Information.
164 static function buildHonoree(&$form) {
166 $form->add('hidden', 'hidden_Honoree', 1);
167 $honor = CRM_Core_PseudoConstant
::get('CRM_Contribute_DAO_Contribution', 'honor_type_id');
168 $extraOption = array('onclick' => "return enableHonorType();");
169 foreach ($honor as $key => $var) {
170 $honorTypes[$key] = $form->createElement('radio', NULL, NULL, $var, $key, $extraOption);
172 $form->addGroup($honorTypes, 'honor_type_id', NULL);
173 $form->add('select', 'honor_prefix_id', ts('Prefix'), array('' => ts('- prefix -')) + CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'prefix_id'));
174 $form->add('text', 'honor_first_name', ts('First Name'));
175 $form->add('text', 'honor_last_name', ts('Last Name'));
176 $form->add('text', 'honor_email', ts('Email'));
177 $form->addRule("honor_email", ts('Email is not valid.'), 'email');
181 * This function is used by CRM/Pledge/Form/Pledge.php
183 * Function to build the form for PaymentReminders Information.
190 static function buildPaymentReminders(&$form) {
191 //PaymentReminders section
192 $form->add('hidden', 'hidden_PaymentReminders', 1);
193 $form->add('text', 'initial_reminder_day', ts('Send Initial Reminder'), array('size' => 3));
194 $form->addRule('initial_reminder_day', ts('Please enter a valid reminder day.'), 'positiveInteger');
195 $form->add('text', 'max_reminders', ts('Send up to'), array('size' => 3));
196 $form->addRule('max_reminders', ts('Please enter a valid No. of reminders.'), 'positiveInteger');
197 $form->add('text', 'additional_reminder_day', ts('Send additional reminders'), array('size' => 3));
198 $form->addRule('additional_reminder_day', ts('Please enter a valid additional reminder day.'), 'positiveInteger');
202 * Function to process the Premium Information
208 static function processPremium(&$params, $contributionID, $premiumID = NULL, &$options = NULL) {
209 $dao = new CRM_Contribute_DAO_ContributionProduct();
210 $dao->contribution_id
= $contributionID;
211 $dao->product_id
= $params['product_name'][0];
212 $dao->fulfilled_date
= CRM_Utils_Date
::processDate($params['fulfilled_date'], NULL, TRUE);
215 $premiumParams = array(
216 'id' => $params['product_name'][0],
218 $productDetails = array();
219 CRM_Contribute_BAO_ManagePremiums
::retrieve($premiumParams, $productDetails);
220 $dao->financial_type_id
= CRM_Utils_Array
::value('financial_type_id', $productDetails);
221 if (CRM_Utils_Array
::value($params['product_name'][0], $options)) {
222 $dao->product_option
= $options[$params['product_name'][0]][$params['product_name'][1]];
225 $premoumDAO = new CRM_Contribute_DAO_ContributionProduct();
226 $premoumDAO->id
= $premiumID;
227 $premoumDAO->find(TRUE);
228 if ($premoumDAO->product_id
== $params['product_name'][0]) {
229 $dao->id
= $premiumID;
230 $premium = $dao->save();
233 $premoumDAO->delete();
235 $premium = $dao->save();
239 $premium = $dao->save();
242 if ($premiumID == NULL ||
$isDeleted) {
244 'cost' => CRM_Utils_Array
::value('cost', $productDetails),
245 'currency' => CRM_Utils_Array
::value('currency', $productDetails),
246 'financial_type_id' => CRM_Utils_Array
::value('financial_type_id', $productDetails),
247 'contributionId' => $contributionID
250 $params['oldPremium']['product_id'] = $premoumDAO->product_id
;
251 $params['oldPremium']['contribution_id'] = $premoumDAO->contribution_id
;
253 CRM_Core_BAO_FinancialTrxn
::createPremiumTrxn($params);
258 * Function to process the Note
264 static function processNote(&$params, $contactID, $contributionID, $contributionNoteID = NULL) {
267 'entity_table' => 'civicrm_contribution',
268 'note' => $params['note'],
269 'entity_id' => $contributionID,
270 'contact_id' => $contactID,
273 if ($contributionNoteID) {
274 $noteID = array("id" => $contributionNoteID);
275 $noteParams['note'] = $noteParams['note'] ?
$noteParams['note'] : "null";
277 CRM_Core_BAO_Note
::add($noteParams, $noteID);
281 * Function to process the Common data
287 static function postProcessCommon(&$params, &$formatted, &$form) {
289 'non_deductible_amount',
297 'contribution_page_id',
299 foreach ($fields as $f) {
300 $formatted[$f] = CRM_Utils_Array
::value($f, $params);
303 if (CRM_Utils_Array
::value('thankyou_date', $params) && !CRM_Utils_System
::isNull($params['thankyou_date'])) {
304 $formatted['thankyou_date'] = CRM_Utils_Date
::processDate($params['thankyou_date'], $params['thankyou_date_time']);
307 $formatted['thankyou_date'] = 'null';
310 if (CRM_Utils_Array
::value('is_email_receipt', $params)) {
311 $params['receipt_date'] = $formatted['receipt_date'] = date('YmdHis');
314 if (CRM_Utils_Array
::value('honor_type_id', $params)) {
315 if ($form->_honorID
) {
316 $honorId = CRM_Contribute_BAO_Contribution
::createHonorContact($params, $form->_honorID
);
319 $honorId = CRM_Contribute_BAO_Contribution
::createHonorContact($params);
321 $formatted["honor_contact_id"] = $honorId;
324 $formatted["honor_contact_id"] = 'null';
327 //special case to handle if all checkboxes are unchecked
328 $customFields = CRM_Core_BAO_CustomField
::getFields('Contribution',
331 CRM_Utils_Array
::value('financial_type_id',
335 $formatted['custom'] = CRM_Core_BAO_CustomField
::postProcess($params,
337 CRM_Utils_Array
::value('id', $params, NULL),
343 * Function to send email receipt.
345 * @form object of Contribution form.
347 * @param array $params (reference ) an assoc array of name/value pairs.
348 * @$ccContribution boolen, is it credit card contribution.
353 static function emailReceipt(&$form, &$params, $ccContribution = FALSE) {
354 $form->assign('receiptType', 'contribution');
355 // Retrieve Financial Type Name from financial_type_id
356 $params['contributionType_name'] = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType',
357 $params['financial_type_id']);
358 if (CRM_Utils_Array
::value('payment_instrument_id', $params)) {
359 $paymentInstrument = CRM_Contribute_PseudoConstant
::paymentInstrument();
360 $params['paidBy'] = $paymentInstrument[$params['payment_instrument_id']];
363 // retrieve individual prefix value for honoree
364 if (CRM_Utils_Array
::value('hidden_Honoree', $params)) {
365 $individualPrefix = CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'prefix_id');
366 $honor = CRM_Core_PseudoConstant
::get('CRM_Contribute_DAO_Contribution', 'honor_type_id');
367 $params['honor_prefix'] = CRM_Utils_Array
::value(CRM_Utils_Array
::value('honor_prefix_id',
372 $params["honor_type"] = CRM_Utils_Array
::value(CRM_Utils_Array
::value('honor_type_id',
379 // retrieve premium product name and assigned fulfilled
381 if (CRM_Utils_Array
::value('hidden_Premium', $params)) {
382 if (isset($params['product_name']) &&
383 is_array($params['product_name']) &&
384 !empty($params['product_name'])
386 $productDAO = new CRM_Contribute_DAO_Product();
387 $productDAO->id
= $params['product_name'][0];
388 $productDAO->find(TRUE);
389 $params['product_name'] = $productDAO->name
;
390 $params['product_sku'] = $productDAO->sku
;
392 if (!CRM_Utils_Array
::value('product_option', $params) &&
393 CRM_Utils_Array
::value($params['product_name'][0],
397 $params['product_option'] = $form->_options
[$params['product_name'][0]][$params['product_name'][1]];
401 if (CRM_Utils_Array
::value('fulfilled_date', $params)) {
402 $form->assign('fulfilled_date', CRM_Utils_Date
::processDate($params['fulfilled_date']));
406 $form->assign('ccContribution', $ccContribution);
407 if ($ccContribution) {
409 $name = CRM_Utils_Array
::value('billing_first_name', $params);
410 if (CRM_Utils_Array
::value('billing_middle_name', $params)) {
411 $name .= " {$params['billing_middle_name']}";
413 $name .= ' ' . CRM_Utils_Array
::value('billing_last_name', $params);
415 $form->assign('billingName', $name);
417 //assign the address formatted up for display
418 $addressParts = array(
419 "street_address" => "billing_street_address-{$form->_bltID}",
420 "city" => "billing_city-{$form->_bltID}",
421 "postal_code" => "billing_postal_code-{$form->_bltID}",
422 "state_province" => "state_province-{$form->_bltID}",
423 "country" => "country-{$form->_bltID}",
426 $addressFields = array();
427 foreach ($addressParts as $name => $field) {
428 $addressFields[$name] = CRM_Utils_Array
::value($field, $params);
430 $form->assign('address', CRM_Utils_Address
::format($addressFields));
432 $date = CRM_Utils_Date
::format($params['credit_card_exp_date']);
433 $date = CRM_Utils_Date
::mysqlToIso($date);
434 $form->assign('credit_card_type', CRM_Utils_Array
::value('credit_card_type', $params));
435 $form->assign('credit_card_exp_date', $date);
436 $form->assign('credit_card_number',
437 CRM_Utils_System
::mungeCreditCard($params['credit_card_number'])
441 //offline contribution
442 // assigned various dates to the templates
443 $form->assign('receipt_date', CRM_Utils_Date
::processDate($params['receipt_date']));
445 if (CRM_Utils_Array
::value('cancel_date', $params)) {
446 $form->assign('cancel_date', CRM_Utils_Date
::processDate($params['cancel_date']));
448 if (CRM_Utils_Array
::value('thankyou_date', $params)) {
449 $form->assign('thankyou_date', CRM_Utils_Date
::processDate($params['thankyou_date']));
451 if ($form->_action
& CRM_Core_Action
::UPDATE
) {
452 $form->assign('lineItem', empty($form->_lineItems
) ?
FALSE : $form->_lineItems
);
457 if (CRM_Utils_Array
::value('hidden_custom', $params)) {
458 $contribParams = array(array('contribution_id', '=', $params['contribution_id'], 0, 0));
459 if ($form->_mode
== 'test') {
460 $contribParams[] = array('contribution_test', '=', 1, 0, 0);
463 //retrieve custom data
464 $customGroup = array();
466 foreach ($form->_groupTree
as $groupID => $group) {
467 $customFields = $customValues = array();
468 if ($groupID == 'info') {
471 foreach ($group['fields'] as $k => $field) {
472 $field['title'] = $field['label'];
473 $customFields["custom_{$k}"] = $field;
476 //build the array of customgroup contain customfields.
477 CRM_Core_BAO_UFGroup
::getValues($params['contact_id'], $customFields, $customValues, FALSE, $contribParams);
478 $customGroup[$group['title']] = $customValues;
480 //assign all custom group and corresponding fields to template.
481 $form->assign('customGroup', $customGroup);
484 $form->assign_by_ref('formValues', $params);
485 list($contributorDisplayName,
487 ) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($params['contact_id']);
488 $form->assign('contactID', $params['contact_id']);
489 $form->assign('contributionID', $params['contribution_id']);
491 if (CRM_Utils_Array
::value('currency', $params)) {
492 $form->assign('currency', $params['currency']);
495 if (CRM_Utils_Array
::value('receive_date', $params)) {
496 $form->assign('receive_date', CRM_Utils_Date
::processDate($params['receive_date']));
499 list($sendReceipt, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate(
501 'groupName' => 'msg_tpl_workflow_contribution',
502 'valueName' => 'contribution_offline_receipt',
503 'contactId' => $params['contact_id'],
504 'contributionId' => $params['contribution_id'],
505 'from' => $params['from_email_address'],
506 'toName' => $contributorDisplayName,
507 'toEmail' => $contributorEmail,
508 'isTest' => $form->_mode
== 'test',
509 'PDFFilename' => ts('receipt').'.pdf',