Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
35 | * This class contains Contribution Page related functions. | |
36 | */ | |
37 | class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_ContributionPage { | |
38 | ||
39 | /** | |
7bc789a5 | 40 | * Creates a contribution page. |
6a488035 | 41 | * |
014c4014 | 42 | * @param array $params |
6a488035 | 43 | * |
16b10e64 | 44 | * @return CRM_Contribute_DAO_ContributionPage |
6a488035 | 45 | */ |
7bc789a5 | 46 | public static function create($params) { |
157b21d8 | 47 | $financialTypeId = NULL; |
a7488080 | 48 | if (!empty($params['id']) && !CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $params['id'], NULL, 1)) { |
157b21d8 PN |
49 | $financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $params['id'], 'financial_type_id'); |
50 | } | |
7bc789a5 | 51 | |
52 | if (isset($params['payment_processor']) && is_array($params['payment_processor'])) { | |
53 | $params['payment_processor'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $params['payment_processor']); | |
54 | } | |
d0a0de8d EM |
55 | $hook = empty($params['id']) ? 'create' : 'edit'; |
56 | CRM_Utils_Hook::pre($hook, 'ContributionPage', CRM_Utils_Array::value('id', $params), $params); | |
6a488035 TO |
57 | $dao = new CRM_Contribute_DAO_ContributionPage(); |
58 | $dao->copyValues($params); | |
59 | $dao->save(); | |
8cc574cf | 60 | if ($financialTypeId && !empty($params['financial_type_id']) && $financialTypeId != $params['financial_type_id']) { |
e1c77163 | 61 | CRM_Price_BAO_PriceFieldValue::updateFinancialType($params['id'], 'civicrm_contribution_page', $params['financial_type_id']); |
157b21d8 | 62 | } |
d0a0de8d | 63 | CRM_Utils_Hook::post($hook, 'ContributionPage', $dao->id, $dao); |
6a488035 TO |
64 | return $dao; |
65 | } | |
66 | ||
67 | /** | |
fe482240 | 68 | * Update the is_active flag in the db. |
6a488035 | 69 | * |
2c4442ca | 70 | * @deprecated - this bypasses hooks. |
71 | * | |
014c4014 TO |
72 | * @param int $id |
73 | * Id of the database record. | |
74 | * @param bool $is_active | |
75 | * Value we want to set the is_active field. | |
6a488035 | 76 | * |
a6c01b45 CW |
77 | * @return Object |
78 | * DAO object on success, null otherwise | |
6a488035 | 79 | */ |
00be9182 | 80 | public static function setIsActive($id, $is_active) { |
6a488035 TO |
81 | return CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_ContributionPage', $id, 'is_active', $is_active); |
82 | } | |
83 | ||
186c9c17 | 84 | /** |
2c4442ca | 85 | * Load values for a contribution page. |
86 | * | |
100fef9d | 87 | * @param int $id |
2c4442ca | 88 | * @param array $values |
186c9c17 | 89 | */ |
00be9182 | 90 | public static function setValues($id, &$values) { |
6a488035 TO |
91 | $params = array( |
92 | 'id' => $id, | |
93 | ); | |
94 | ||
95 | CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $values); | |
8ef12e64 | 96 | |
6a488035 TO |
97 | // get the profile ids |
98 | $ufJoinParams = array( | |
99 | 'module' => 'CiviContribute', | |
100 | 'entity_table' => 'civicrm_contribution_page', | |
101 | 'entity_id' => $id, | |
102 | ); | |
103 | list($values['custom_pre_id'], $customPostIds) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); | |
104 | ||
105 | if (!empty($customPostIds)) { | |
106 | $values['custom_post_id'] = $customPostIds[0]; | |
107 | } | |
108 | else { | |
109 | $values['custom_post_id'] = ''; | |
110 | } | |
874c9be7 | 111 | } |
6a488035 TO |
112 | |
113 | /** | |
fe482240 | 114 | * Send the emails. |
6a488035 | 115 | * |
014c4014 TO |
116 | * @param int $contactID |
117 | * Contact id. | |
118 | * @param array $values | |
119 | * Associated array of fields. | |
120 | * @param bool $isTest | |
121 | * If in test mode. | |
122 | * @param bool $returnMessageText | |
123 | * Return the message text instead of sending the mail. | |
6a488035 | 124 | * |
2c4442ca | 125 | * @param array $fieldTypes |
6a488035 | 126 | */ |
00be9182 | 127 | public static function sendMail($contactID, $values, $isTest = FALSE, $returnMessageText = FALSE, $fieldTypes = NULL) { |
6a488035 TO |
128 | $gIds = $params = array(); |
129 | $email = NULL; | |
130 | if (isset($values['custom_pre_id'])) { | |
131 | $preProfileType = CRM_Core_BAO_UFField::getProfileType($values['custom_pre_id']); | |
8cc574cf | 132 | if ($preProfileType == 'Membership' && !empty($values['membership_id'])) { |
6a488035 TO |
133 | $params['custom_pre_id'] = array( |
134 | array( | |
135 | 'member_id', | |
136 | '=', | |
137 | $values['membership_id'], | |
138 | 0, | |
139 | 0, | |
140 | ), | |
141 | ); | |
142 | } | |
8cc574cf | 143 | elseif ($preProfileType == 'Contribution' && !empty($values['contribution_id'])) { |
6a488035 TO |
144 | $params['custom_pre_id'] = array( |
145 | array( | |
146 | 'contribution_id', | |
147 | '=', | |
148 | $values['contribution_id'], | |
149 | 0, | |
150 | 0, | |
151 | ), | |
152 | ); | |
153 | } | |
154 | ||
155 | $gIds['custom_pre_id'] = $values['custom_pre_id']; | |
156 | } | |
157 | ||
158 | if (isset($values['custom_post_id'])) { | |
159 | $postProfileType = CRM_Core_BAO_UFField::getProfileType($values['custom_post_id']); | |
8cc574cf | 160 | if ($postProfileType == 'Membership' && !empty($values['membership_id'])) { |
6a488035 TO |
161 | $params['custom_post_id'] = array( |
162 | array( | |
163 | 'member_id', | |
164 | '=', | |
165 | $values['membership_id'], | |
166 | 0, | |
167 | 0, | |
168 | ), | |
169 | ); | |
170 | } | |
8cc574cf | 171 | elseif ($postProfileType == 'Contribution' && !empty($values['contribution_id'])) { |
6a488035 TO |
172 | $params['custom_post_id'] = array( |
173 | array( | |
174 | 'contribution_id', | |
175 | '=', | |
176 | $values['contribution_id'], | |
177 | 0, | |
178 | 0, | |
179 | ), | |
180 | ); | |
181 | } | |
182 | ||
183 | $gIds['custom_post_id'] = $values['custom_post_id']; | |
184 | } | |
185 | ||
a7488080 CW |
186 | if (!empty($values['is_for_organization'])) { |
187 | if (!empty($values['membership_id'])) { | |
6a488035 TO |
188 | $params['onbehalf_profile'] = array( |
189 | array( | |
190 | 'member_id', | |
191 | '=', | |
192 | $values['membership_id'], | |
193 | 0, | |
194 | 0, | |
195 | ), | |
196 | ); | |
197 | } | |
a7488080 | 198 | elseif (!empty($values['contribution_id'])) { |
6a488035 TO |
199 | $params['onbehalf_profile'] = array( |
200 | array( | |
201 | 'contribution_id', | |
202 | '=', | |
203 | $values['contribution_id'], | |
204 | 0, | |
205 | 0, | |
206 | ), | |
207 | ); | |
208 | } | |
209 | } | |
210 | ||
211 | //check whether it is a test drive | |
212 | if ($isTest && !empty($params['custom_pre_id'])) { | |
213 | $params['custom_pre_id'][] = array( | |
214 | 'contribution_test', | |
215 | '=', | |
216 | 1, | |
217 | 0, | |
218 | 0, | |
219 | ); | |
220 | } | |
221 | ||
222 | if ($isTest && !empty($params['custom_post_id'])) { | |
223 | $params['custom_post_id'][] = array( | |
224 | 'contribution_test', | |
225 | '=', | |
226 | 1, | |
227 | 0, | |
228 | 0, | |
229 | ); | |
230 | } | |
8ef12e64 | 231 | |
6a488035 TO |
232 | if (!$returnMessageText && !empty($gIds)) { |
233 | //send notification email if field values are set (CRM-1941) | |
234 | foreach ($gIds as $key => $gId) { | |
235 | if ($gId) { | |
236 | $email = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify'); | |
237 | if ($email) { | |
481a74f4 | 238 | $val = CRM_Core_BAO_UFGroup::checkFieldsEmptyValues($gId, $contactID, CRM_Utils_Array::value($key, $params), TRUE); |
6a488035 TO |
239 | CRM_Core_BAO_UFGroup::commonSendMail($contactID, $val); |
240 | } | |
241 | } | |
242 | } | |
243 | } | |
244 | ||
8cc574cf | 245 | if (!empty($values['is_email_receipt']) || !empty($values['onbehalf_dupe_alert']) || |
6a488035 TO |
246 | $returnMessageText |
247 | ) { | |
248 | $template = CRM_Core_Smarty::singleton(); | |
249 | ||
250 | // get the billing location type | |
251 | if (!array_key_exists('related_contact', $values)) { | |
180409a4 | 252 | $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate'); |
6a488035 TO |
253 | $billingLocationTypeId = array_search('Billing', $locationTypes); |
254 | } | |
255 | else { | |
256 | // presence of related contact implies onbehalf of org case, | |
257 | // where location type is set to default. | |
258 | $locType = CRM_Core_BAO_LocationType::getDefault(); | |
259 | $billingLocationTypeId = $locType->id; | |
260 | } | |
261 | ||
262 | if (!array_key_exists('related_contact', $values)) { | |
263 | list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID, FALSE, $billingLocationTypeId); | |
264 | } | |
265 | // get primary location email if no email exist( for billing location). | |
266 | if (!$email) { | |
267 | list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID); | |
268 | } | |
269 | if (empty($displayName)) { | |
270 | list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID); | |
271 | } | |
272 | ||
273 | //for display profile need to get individual contact id, | |
274 | //hence get it from related_contact if on behalf of org true CRM-3767 | |
275 | //CRM-5001 Contribution/Membership:: On Behalf of Organization, | |
276 | //If profile GROUP contain the Individual type then consider the | |
277 | //profile is of Individual ( including the custom data of membership/contribution ) | |
278 | //IF Individual type not present in profile then it is consider as Organization data. | |
279 | $userID = $contactID; | |
280 | if ($preID = CRM_Utils_Array::value('custom_pre_id', $values)) { | |
a7488080 | 281 | if (!empty($values['related_contact'])) { |
6a488035 | 282 | $preProfileTypes = CRM_Core_BAO_UFGroup::profileGroups($preID); |
b8950542 | 283 | //@todo - following line should not refer to undefined $postProfileTypes? figure out way to test |
6a488035 TO |
284 | if (in_array('Individual', $preProfileTypes) || in_array('Contact', $postProfileTypes)) { |
285 | //Take Individual contact ID | |
286 | $userID = CRM_Utils_Array::value('related_contact', $values); | |
287 | } | |
288 | } | |
289 | self::buildCustomDisplay($preID, 'customPre', $userID, $template, $params['custom_pre_id']); | |
290 | } | |
291 | $userID = $contactID; | |
292 | if ($postID = CRM_Utils_Array::value('custom_post_id', $values)) { | |
a7488080 | 293 | if (!empty($values['related_contact'])) { |
6a488035 TO |
294 | $postProfileTypes = CRM_Core_BAO_UFGroup::profileGroups($postID); |
295 | if (in_array('Individual', $postProfileTypes) || in_array('Contact', $postProfileTypes)) { | |
296 | //Take Individual contact ID | |
297 | $userID = CRM_Utils_Array::value('related_contact', $values); | |
298 | } | |
299 | } | |
300 | self::buildCustomDisplay($postID, 'customPost', $userID, $template, $params['custom_post_id']); | |
301 | } | |
1421174e | 302 | if (isset($values['honor'])) { |
303 | $honorValues = $values['honor']; | |
304 | CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields( | |
305 | $template, | |
306 | $honorValues['honor_profile_values'], | |
307 | $honorValues['honor_profile_id'], | |
308 | $honorValues['honor_id'] | |
309 | ); | |
310 | } | |
6a488035 TO |
311 | |
312 | $title = isset($values['title']) ? $values['title'] : CRM_Contribute_PseudoConstant::contributionPage($values['contribution_page_id']); | |
313 | ||
314 | // set email in the template here | |
315 | $tplParams = array( | |
316 | 'email' => $email, | |
317 | 'receiptFromEmail' => CRM_Utils_Array::value('receipt_from_email', $values), | |
318 | 'contactID' => $contactID, | |
319 | 'displayName' => $displayName, | |
320 | 'contributionID' => CRM_Utils_Array::value('contribution_id', $values), | |
321 | 'contributionOtherID' => CRM_Utils_Array::value('contribution_other_id', $values), | |
6a488035 TO |
322 | // CRM-5095 |
323 | 'lineItem' => CRM_Utils_Array::value('lineItem', $values), | |
324 | // CRM-5095 | |
325 | 'priceSetID' => CRM_Utils_Array::value('priceSetID', $values), | |
326 | 'title' => $title, | |
327 | 'isShare' => CRM_Utils_Array::value('is_share', $values), | |
8b067691 | 328 | 'thankyou_title' => CRM_Utils_Array::value('thankyou_title', $values), |
6a488035 TO |
329 | ); |
330 | ||
91bb24a7 | 331 | if ($contributionTypeId = CRM_Utils_Array::value('financial_type_id', $values)) { |
6a488035 | 332 | $tplParams['contributionTypeId'] = $contributionTypeId; |
91bb24a7 | 333 | $tplParams['contributionTypeName'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', |
334 | $contributionTypeId); | |
6a488035 TO |
335 | } |
336 | ||
337 | if ($contributionPageId = CRM_Utils_Array::value('id', $values)) { | |
338 | $tplParams['contributionPageId'] = $contributionPageId; | |
339 | } | |
340 | ||
341 | // address required during receipt processing (pdf and email receipt) | |
342 | if ($displayAddress = CRM_Utils_Array::value('address', $values)) { | |
343 | $tplParams['address'] = $displayAddress; | |
344 | } | |
345 | ||
346 | // CRM-6976 | |
347 | $originalCCReceipt = CRM_Utils_Array::value('cc_receipt', $values); | |
348 | ||
349 | // cc to related contacts of contributor OR the one who | |
350 | // signs up. Is used for cases like - on behalf of | |
351 | // contribution / signup ..etc | |
352 | if (array_key_exists('related_contact', $values)) { | |
353 | list($ccDisplayName, $ccEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($values['related_contact']); | |
354 | $ccMailId = "{$ccDisplayName} <{$ccEmail}>"; | |
355 | ||
fdd2a6db | 356 | //@todo - this is the only place in this function where $values is altered - but I can't find any evidence it is used |
0d8afee2 | 357 | $values['cc_receipt'] = !empty($values['cc_receipt']) ? ($values['cc_receipt'] . ',' . $ccMailId) : $ccMailId; |
6a488035 TO |
358 | |
359 | // reset primary-email in the template | |
360 | $tplParams['email'] = $ccEmail; | |
361 | ||
362 | $tplParams['onBehalfName'] = $displayName; | |
363 | $tplParams['onBehalfEmail'] = $email; | |
364 | ||
365 | $ufJoinParams = array( | |
366 | 'module' => 'onBehalf', | |
367 | 'entity_table' => 'civicrm_contribution_page', | |
368 | 'entity_id' => $values['id'], | |
369 | ); | |
370 | $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); | |
91bb24a7 | 371 | $profileId = $OnBehalfProfile[0]; |
372 | $userID = $contactID; | |
6a488035 TO |
373 | self::buildCustomDisplay($profileId, 'onBehalfProfile', $userID, $template, $params['onbehalf_profile'], $fieldTypes); |
374 | } | |
375 | ||
376 | // use either the contribution or membership receipt, based on whether it’s a membership-related contrib or not | |
377 | $sendTemplateParams = array( | |
12dac866 | 378 | 'groupName' => !empty($values['isMembership']) ? 'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution', |
379 | 'valueName' => !empty($values['isMembership']) ? 'membership_online_receipt' : 'contribution_online_receipt', | |
6a488035 TO |
380 | 'contactId' => $contactID, |
381 | 'tplParams' => $tplParams, | |
382 | 'isTest' => $isTest, | |
383 | 'PDFFilename' => 'receipt.pdf', | |
384 | ); | |
385 | ||
386 | if ($returnMessageText) { | |
c6327d7d | 387 | list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); |
6a488035 TO |
388 | return array( |
389 | 'subject' => $subject, | |
390 | 'body' => $message, | |
391 | 'to' => $displayName, | |
392 | 'html' => $html, | |
393 | ); | |
394 | } | |
395 | ||
396 | if ($values['is_email_receipt']) { | |
397 | $sendTemplateParams['from'] = CRM_Utils_Array::value('receipt_from_name', $values) . ' <' . $values['receipt_from_email'] . '>'; | |
398 | $sendTemplateParams['toName'] = $displayName; | |
399 | $sendTemplateParams['toEmail'] = $email; | |
400 | $sendTemplateParams['cc'] = CRM_Utils_Array::value('cc_receipt', $values); | |
401 | $sendTemplateParams['bcc'] = CRM_Utils_Array::value('bcc_receipt', $values); | |
9161952c | 402 | //send email with pdf invoice |
481a74f4 | 403 | $template = CRM_Core_Smarty::singleton(); |
9161952c | 404 | $taxAmt = $template->get_template_vars('dataArray'); |
bb600eae | 405 | $prefixValue = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings'); |
9161952c | 406 | $invoicing = CRM_Utils_Array::value('invoicing', $prefixValue); |
121bf42c | 407 | if (isset($invoicing) && isset($prefixValue['is_email_pdf'])) { |
874c9be7 | 408 | $sendTemplateParams['isEmailPdf'] = TRUE; |
9161952c PD |
409 | $sendTemplateParams['contributionId'] = $values['contribution_id']; |
410 | } | |
c6327d7d | 411 | list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); |
6a488035 TO |
412 | } |
413 | ||
414 | // send duplicate alert, if dupe match found during on-behalf-of processing. | |
a7488080 | 415 | if (!empty($values['onbehalf_dupe_alert'])) { |
6a488035 TO |
416 | $sendTemplateParams['groupName'] = 'msg_tpl_workflow_contribution'; |
417 | $sendTemplateParams['valueName'] = 'contribution_dupalert'; | |
418 | $sendTemplateParams['from'] = ts('Automatically Generated') . " <{$values['receipt_from_email']}>"; | |
419 | $sendTemplateParams['toName'] = CRM_Utils_Array::value('receipt_from_name', $values); | |
420 | $sendTemplateParams['toEmail'] = CRM_Utils_Array::value('receipt_from_email', $values); | |
421 | $sendTemplateParams['tplParams']['onBehalfID'] = $contactID; | |
422 | $sendTemplateParams['tplParams']['receiptMessage'] = $message; | |
423 | ||
424 | // fix cc and reset back to original, CRM-6976 | |
425 | $sendTemplateParams['cc'] = $originalCCReceipt; | |
426 | ||
c6327d7d | 427 | CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); |
6a488035 TO |
428 | } |
429 | } | |
430 | } | |
8ef12e64 | 431 | |
186c9c17 | 432 | /** |
84f0ed41 | 433 | * Send the emails for Recurring Contribution Notification. |
6a488035 | 434 | * |
014c4014 TO |
435 | * @param string $type |
436 | * TxnType. | |
437 | * @param int $contactID | |
438 | * Contact id for contributor. | |
439 | * @param int $pageID | |
440 | * Contribution page id. | |
441 | * @param object $recur | |
442 | * Object of recurring contribution table. | |
2a6da8d7 | 443 | * @param bool|object $autoRenewMembership is it a auto renew membership. |
6a488035 | 444 | */ |
00be9182 | 445 | public static function recurringNotify($type, $contactID, $pageID, $recur, $autoRenewMembership = FALSE) { |
6a488035 | 446 | $value = array(); |
ddf80fb9 | 447 | $isEmailReceipt = FALSE; |
6a488035 TO |
448 | if ($pageID) { |
449 | CRM_Core_DAO::commonRetrieveAll('CRM_Contribute_DAO_ContributionPage', 'id', $pageID, $value, array( | |
91bb24a7 | 450 | 'title', |
451 | 'is_email_receipt', | |
452 | 'receipt_from_name', | |
453 | 'receipt_from_email', | |
454 | 'cc_receipt', | |
455 | 'bcc_receipt', | |
456 | )); | |
ab30e033 | 457 | $isEmailReceipt = CRM_Utils_Array::value('is_email_receipt', $value[$pageID]); |
6a488035 | 458 | } |
ab30e033 EM |
459 | elseif ($recur->id) { |
460 | // This means we are coming from back-office - ie. no page ID, but recurring. | |
461 | // Ideally this information would be passed into the function clearly rather than guessing by convention. | |
462 | $isEmailReceipt = TRUE; | |
6a488035 | 463 | } |
ab30e033 EM |
464 | |
465 | if ($isEmailReceipt) { | |
6a488035 TO |
466 | if ($pageID) { |
467 | $receiptFrom = '"' . CRM_Utils_Array::value('receipt_from_name', $value[$pageID]) . '" <' . $value[$pageID]['receipt_from_email'] . '>'; | |
468 | ||
469 | $receiptFromName = $value[$pageID]['receipt_from_name']; | |
470 | $receiptFromEmail = $value[$pageID]['receipt_from_email']; | |
471 | } | |
472 | else { | |
91bb24a7 | 473 | $domainValues = CRM_Core_BAO_Domain::getNameAndEmail(); |
474 | $receiptFrom = "$domainValues[0] <$domainValues[1]>"; | |
475 | $receiptFromName = $domainValues[0]; | |
6a488035 TO |
476 | $receiptFromEmail = $domainValues[1]; |
477 | } | |
478 | ||
479 | list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID, FALSE); | |
480 | $templatesParams = array( | |
481 | 'groupName' => 'msg_tpl_workflow_contribution', | |
482 | 'valueName' => 'contribution_recurring_notify', | |
483 | 'contactId' => $contactID, | |
484 | 'tplParams' => array( | |
485 | 'recur_frequency_interval' => $recur->frequency_interval, | |
486 | 'recur_frequency_unit' => $recur->frequency_unit, | |
487 | 'recur_installments' => $recur->installments, | |
488 | 'recur_start_date' => $recur->start_date, | |
489 | 'recur_end_date' => $recur->end_date, | |
490 | 'recur_amount' => $recur->amount, | |
491 | 'recur_txnType' => $type, | |
492 | 'displayName' => $displayName, | |
493 | 'receipt_from_name' => $receiptFromName, | |
494 | 'receipt_from_email' => $receiptFromEmail, | |
495 | 'auto_renew_membership' => $autoRenewMembership, | |
496 | ), | |
497 | 'from' => $receiptFrom, | |
498 | 'toName' => $displayName, | |
499 | 'toEmail' => $email, | |
500 | ); | |
1421174e | 501 | //CRM-13811 |
039134ba | 502 | if ($pageID) { |
503 | $templatesParams['cc'] = CRM_Utils_Array::value('cc_receipt', $value[$pageID]); | |
504 | $templatesParams['bcc'] = CRM_Utils_Array::value('bcc_receipt', $value[$pageID]); | |
505 | } | |
6a488035 TO |
506 | if ($recur->id) { |
507 | // in some cases its just recurringNotify() thats called for the first time and these urls don't get set. | |
508 | // like in PaypalPro, & therefore we set it here additionally. | |
91bb24a7 | 509 | $template = CRM_Core_Smarty::singleton(); |
6a488035 | 510 | $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($recur->id, 'recur', 'obj'); |
91bb24a7 | 511 | $url = $paymentProcessor->subscriptionURL($recur->id, 'recur'); |
6a488035 TO |
512 | $template->assign('cancelSubscriptionUrl', $url); |
513 | ||
514 | $url = $paymentProcessor->subscriptionURL($recur->id, 'recur', 'billing'); | |
515 | $template->assign('updateSubscriptionBillingUrl', $url); | |
516 | ||
517 | $url = $paymentProcessor->subscriptionURL($recur->id, 'recur', 'update'); | |
518 | $template->assign('updateSubscriptionUrl', $url); | |
519 | } | |
520 | ||
84f0ed41 | 521 | list($sent) = CRM_Core_BAO_MessageTemplate::sendTemplate($templatesParams); |
6a488035 TO |
522 | |
523 | if ($sent) { | |
524 | CRM_Core_Error::debug_log_message('Success: mail sent for recurring notification.'); | |
525 | } | |
526 | else { | |
527 | CRM_Core_Error::debug_log_message('Failure: mail not sent for recurring notification.'); | |
528 | } | |
529 | } | |
530 | } | |
531 | ||
532 | /** | |
100fef9d | 533 | * Add the custom fields for contribution page (ie profile) |
6a488035 | 534 | * |
014c4014 TO |
535 | * @param int $gid |
536 | * Uf group id. | |
6a488035 | 537 | * @param string $name |
014c4014 TO |
538 | * @param int $cid |
539 | * Contact id. | |
2a6da8d7 | 540 | * @param $template |
014c4014 TO |
541 | * @param array $params |
542 | * Params to build component whereclause. | |
2a6da8d7 | 543 | * |
2c4442ca | 544 | * @param array $fieldTypes |
6a488035 | 545 | */ |
2c4442ca | 546 | public static function buildCustomDisplay($gid, $name, $cid, &$template, &$params, $fieldTypes = array()) { |
6a488035 TO |
547 | if ($gid) { |
548 | if (CRM_Core_BAO_UFGroup::filterUFGroups($gid, $cid)) { | |
91bb24a7 | 549 | $values = array(); |
6a488035 | 550 | $groupTitle = NULL; |
91bb24a7 | 551 | $fields = CRM_Core_BAO_UFGroup::getFields($gid, FALSE, CRM_Core_Action::VIEW, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL); |
6a488035 TO |
552 | foreach ($fields as $k => $v) { |
553 | if (!$groupTitle) { | |
554 | $groupTitle = $v["groupTitle"]; | |
555 | } | |
556 | // suppress all file fields from display and formatting fields | |
557 | if ( | |
558 | CRM_Utils_Array::value('data_type', $v, '') == 'File' || | |
559 | CRM_Utils_Array::value('name', $v, '') == 'image_URL' || | |
560 | CRM_Utils_Array::value('field_type', $v) == 'Formatting' | |
561 | ) { | |
562 | unset($fields[$k]); | |
563 | } | |
564 | ||
565 | if (!empty($fieldTypes) && (!in_array($v['field_type'], $fieldTypes))) { | |
566 | unset($fields[$k]); | |
567 | } | |
568 | } | |
569 | ||
570 | if ($groupTitle) { | |
571 | $template->assign($name . "_grouptitle", $groupTitle); | |
572 | } | |
573 | ||
574 | CRM_Core_BAO_UFGroup::getValues($cid, $fields, $values, FALSE, $params); | |
575 | ||
576 | if (count($values)) { | |
577 | $template->assign($name, $values); | |
578 | } | |
579 | } | |
580 | } | |
581 | } | |
582 | ||
583 | /** | |
2c4442ca | 584 | * Make a copy of a contribution page, including all the blocks in the page. |
6a488035 | 585 | * |
014c4014 TO |
586 | * @param int $id |
587 | * The contribution page id to copy. | |
6a488035 | 588 | * |
72b3a70c | 589 | * @return CRM_Contribute_DAO_ContributionPage |
6a488035 | 590 | */ |
00be9182 | 591 | public static function copy($id) { |
6a488035 TO |
592 | $fieldsFix = array( |
593 | 'prefix' => array( | |
594 | 'title' => ts('Copy of') . ' ', | |
595 | ), | |
596 | ); | |
597 | $copy = &CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_ContributionPage', array( | |
353ffa53 TO |
598 | 'id' => $id, |
599 | ), NULL, $fieldsFix); | |
6a488035 TO |
600 | |
601 | //copying all the blocks pertaining to the contribution page | |
602 | $copyPledgeBlock = &CRM_Core_DAO::copyGeneric('CRM_Pledge_DAO_PledgeBlock', array( | |
353ffa53 TO |
603 | 'entity_id' => $id, |
604 | 'entity_table' => 'civicrm_contribution_page', | |
605 | ), array( | |
606 | 'entity_id' => $copy->id, | |
607 | )); | |
6a488035 TO |
608 | |
609 | $copyMembershipBlock = &CRM_Core_DAO::copyGeneric('CRM_Member_DAO_MembershipBlock', array( | |
353ffa53 TO |
610 | 'entity_id' => $id, |
611 | 'entity_table' => 'civicrm_contribution_page', | |
612 | ), array( | |
613 | 'entity_id' => $copy->id, | |
614 | )); | |
6a488035 TO |
615 | |
616 | $copyUFJoin = &CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array( | |
353ffa53 TO |
617 | 'entity_id' => $id, |
618 | 'entity_table' => 'civicrm_contribution_page', | |
619 | ), array( | |
620 | 'entity_id' => $copy->id, | |
621 | )); | |
6a488035 TO |
622 | |
623 | $copyWidget = &CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_Widget', array( | |
353ffa53 TO |
624 | 'contribution_page_id' => $id, |
625 | ), array( | |
626 | 'contribution_page_id' => $copy->id, | |
627 | )); | |
6a488035 | 628 | |
c6914066 | 629 | //copy price sets |
9da8dc8c | 630 | CRM_Price_BAO_PriceSet::copyPriceSet('civicrm_contribution_page', $id, $copy->id); |
c6914066 | 631 | |
6a488035 | 632 | $copyTellFriend = &CRM_Core_DAO::copyGeneric('CRM_Friend_DAO_Friend', array( |
353ffa53 TO |
633 | 'entity_id' => $id, |
634 | 'entity_table' => 'civicrm_contribution_page', | |
635 | ), array( | |
636 | 'entity_id' => $copy->id, | |
637 | )); | |
6a488035 TO |
638 | |
639 | $copyPersonalCampaignPages = &CRM_Core_DAO::copyGeneric('CRM_PCP_DAO_PCPBlock', array( | |
353ffa53 TO |
640 | 'entity_id' => $id, |
641 | 'entity_table' => 'civicrm_contribution_page', | |
642 | ), array( | |
643 | 'entity_id' => $copy->id, | |
b7ff0a0a | 644 | 'target_entity_id' => $copy->id, |
353ffa53 | 645 | )); |
6a488035 TO |
646 | |
647 | $copyPremium = &CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_Premium', array( | |
353ffa53 TO |
648 | 'entity_id' => $id, |
649 | 'entity_table' => 'civicrm_contribution_page', | |
650 | ), array( | |
651 | 'entity_id' => $copy->id, | |
652 | )); | |
6a488035 TO |
653 | $premiumQuery = " |
654 | SELECT id | |
655 | FROM civicrm_premiums | |
656 | WHERE entity_table = 'civicrm_contribution_page' | |
657 | AND entity_id ={$id}"; | |
658 | ||
659 | $premiumDao = CRM_Core_DAO::executeQuery($premiumQuery, CRM_Core_DAO::$_nullArray); | |
660 | while ($premiumDao->fetch()) { | |
661 | if ($premiumDao->id) { | |
2c4442ca | 662 | CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_PremiumsProduct', array( |
91bb24a7 | 663 | 'premiums_id' => $premiumDao->id, |
664 | ), array( | |
665 | 'premiums_id' => $copyPremium->id, | |
666 | )); | |
6a488035 TO |
667 | } |
668 | } | |
669 | ||
670 | $copy->save(); | |
671 | ||
672 | CRM_Utils_Hook::copy('ContributionPage', $copy); | |
673 | ||
674 | return $copy; | |
675 | } | |
676 | ||
6a488035 | 677 | /** |
100fef9d | 678 | * Get info for all sections enable/disable. |
6a488035 | 679 | * |
2a6da8d7 | 680 | * @param array $contribPageIds |
a6c01b45 CW |
681 | * @return array |
682 | * info regarding all sections. | |
6a488035 | 683 | */ |
00be9182 | 684 | public static function getSectionInfo($contribPageIds = array()) { |
6a488035 TO |
685 | $info = array(); |
686 | $whereClause = NULL; | |
687 | if (is_array($contribPageIds) && !empty($contribPageIds)) { | |
688 | $whereClause = 'WHERE civicrm_contribution_page.id IN ( ' . implode(', ', $contribPageIds) . ' )'; | |
689 | } | |
690 | ||
691 | $sections = array( | |
692 | 'settings', | |
693 | 'amount', | |
694 | 'membership', | |
695 | 'custom', | |
696 | 'thankyou', | |
697 | 'friend', | |
698 | 'pcp', | |
699 | 'widget', | |
700 | 'premium', | |
701 | ); | |
702 | $query = " | |
703 | SELECT civicrm_contribution_page.id as id, | |
8ef12e64 | 704 | civicrm_contribution_page.financial_type_id as settings, |
6a488035 TO |
705 | amount_block_is_active as amount, |
706 | civicrm_membership_block.id as membership, | |
707 | civicrm_uf_join.id as custom, | |
708 | civicrm_contribution_page.thankyou_title as thankyou, | |
709 | civicrm_tell_friend.id as friend, | |
710 | civicrm_pcp_block.id as pcp, | |
711 | civicrm_contribution_widget.id as widget, | |
712 | civicrm_premiums.id as premium | |
713 | FROM civicrm_contribution_page | |
714 | LEFT JOIN civicrm_membership_block ON ( civicrm_membership_block.entity_id = civicrm_contribution_page.id | |
715 | AND civicrm_membership_block.entity_table = 'civicrm_contribution_page' | |
716 | AND civicrm_membership_block.is_active = 1 ) | |
717 | LEFT JOIN civicrm_uf_join ON ( civicrm_uf_join.entity_id = civicrm_contribution_page.id | |
718 | AND civicrm_uf_join.entity_table = 'civicrm_contribution_page' | |
719 | AND module = 'CiviContribute' | |
720 | AND civicrm_uf_join.is_active = 1 ) | |
721 | LEFT JOIN civicrm_tell_friend ON ( civicrm_tell_friend.entity_id = civicrm_contribution_page.id | |
722 | AND civicrm_tell_friend.entity_table = 'civicrm_contribution_page' | |
723 | AND civicrm_tell_friend.is_active = 1) | |
724 | LEFT JOIN civicrm_pcp_block ON ( civicrm_pcp_block.entity_id = civicrm_contribution_page.id | |
725 | AND civicrm_pcp_block.entity_table = 'civicrm_contribution_page' | |
726 | AND civicrm_pcp_block.is_active = 1 ) | |
727 | LEFT JOIN civicrm_contribution_widget ON ( civicrm_contribution_widget.contribution_page_id = civicrm_contribution_page.id | |
728 | AND civicrm_contribution_widget.is_active = 1 ) | |
729 | LEFT JOIN civicrm_premiums ON ( civicrm_premiums.entity_id = civicrm_contribution_page.id | |
730 | AND civicrm_premiums.entity_table = 'civicrm_contribution_page' | |
731 | AND civicrm_premiums.premiums_active = 1 ) | |
732 | $whereClause"; | |
733 | ||
734 | $contributionPage = CRM_Core_DAO::executeQuery($query); | |
735 | while ($contributionPage->fetch()) { | |
736 | if (!isset($info[$contributionPage->id]) || !is_array($info[$contributionPage->id])) { | |
737 | $info[$contributionPage->id] = array_fill_keys(array_values($sections), FALSE); | |
738 | } | |
739 | foreach ($sections as $section) { | |
740 | if ($contributionPage->$section) { | |
741 | $info[$contributionPage->id][$section] = TRUE; | |
742 | } | |
743 | } | |
744 | } | |
745 | ||
746 | return $info; | |
747 | } | |
e1462487 CW |
748 | |
749 | /** | |
750 | * Get options for a given field. | |
751 | * @see CRM_Core_DAO::buildOptions | |
752 | * | |
014c4014 | 753 | * @param string $fieldName |
353ffa53 TO |
754 | * @param string $context : @see CRM_Core_DAO::buildOptionsContext |
755 | * @param array $props : whatever is known about this dao object | |
e1462487 CW |
756 | * |
757 | * @return array|bool | |
758 | */ | |
759 | public static function buildOptions($fieldName, $context = NULL, $props = array()) { | |
760 | $params = array(); | |
761 | // Special logic for fields whose options depend on context or properties | |
762 | switch ($fieldName) { | |
763 | case 'financial_type_id': | |
764 | // Fixme - this is going to ignore context, better to get conditions, add params, and call PseudoConstant::get | |
765 | return CRM_Financial_BAO_FinancialType::getIncomeFinancialType(); | |
874c9be7 | 766 | |
79d7553f | 767 | break; |
e1462487 CW |
768 | } |
769 | return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context); | |
770 | } | |
ba60f73e | 771 | |
772 | /** | |
773 | * Get or Set multilingually affected honor params for processing module_data or setting default values. | |
774 | * | |
353ffa53 TO |
775 | * @param string $params : |
776 | * @param bool $setDefault : If yes then returns array to used for setting default value afterward | |
ba60f73e | 777 | * |
778 | * @return array|string | |
779 | */ | |
780 | public static function formatMultilingualHonorParams($params, $setDefault = FALSE) { | |
781 | $config = CRM_Core_Config::singleton(); | |
782 | $sctJson = $sctJsonDecode = NULL; | |
783 | $domain = new CRM_Core_DAO_Domain(); | |
784 | $domain->find(TRUE); | |
785 | ||
12792976 | 786 | //When we are fetching the honor params respecting both multi and mono lingual state |
ba60f73e | 787 | //and setting it to default param of Contribution Page's Main and Setting form |
788 | if ($setDefault) { | |
789 | $sctJsonDecode = json_decode($params); | |
790 | $sctJsonDecode = (array) $sctJsonDecode->soft_credit; | |
12792976 | 791 | if (!$domain->locales && !empty($sctJsonDecode['default'])) { |
792 | //monolingual state | |
793 | $sctJsonDecode += (array) $sctJsonDecode['default']; | |
794 | } | |
795 | elseif (!empty($sctJsonDecode[$config->lcMessages])) { | |
796 | //multilingual state | |
ba60f73e | 797 | foreach ($sctJsonDecode[$config->lcMessages] as $column => $value) { |
798 | $sctJsonDecode[$column] = $value; | |
799 | } | |
800 | unset($sctJsonDecode[$config->lcMessages]); | |
801 | } | |
802 | return $sctJsonDecode; | |
803 | } | |
804 | ||
805 | //check and handle multilingual honoree params | |
806 | if (!$domain->locales) { | |
807 | //if in singlelingual state simply return the array format | |
808 | $sctJson = json_encode( | |
809 | array( | |
810 | 'soft_credit' => array( | |
811 | 'soft_credit_types' => $params['soft_credit_types'], | |
12792976 | 812 | 'default' => array( |
813 | 'honor_block_title' => $params['honor_block_title'], | |
21dfd5f5 TO |
814 | 'honor_block_text' => $params['honor_block_text'], |
815 | ), | |
816 | ), | |
ba60f73e | 817 | ) |
818 | ); | |
819 | } | |
820 | else { | |
821 | //if in multilingual state then retrieve the module_data against this contribution and | |
822 | //merge with earlier module_data json data to current so not to lose earlier multilingual module_data information | |
874c9be7 | 823 | $sctJson = array( |
ba60f73e | 824 | 'soft_credit' => array( |
825 | 'soft_credit_types' => $params['soft_credit_types'], | |
874c9be7 | 826 | $config->lcMessages => array( |
ba60f73e | 827 | 'honor_block_title' => $params['honor_block_title'], |
21dfd5f5 TO |
828 | 'honor_block_text' => $params['honor_block_text'], |
829 | ), | |
830 | ), | |
ba60f73e | 831 | ); |
832 | ||
833 | $ufJoinDAO = new CRM_Core_DAO_UFJoin(); | |
834 | $ufJoinDAO->module = 'soft_credit'; | |
835 | $ufJoinDAO->entity_id = $params['id']; | |
836 | $ufJoinDAO->find(TRUE); | |
837 | $jsonData = json_decode($ufJoinDAO->module_data); | |
838 | if ($jsonData) { | |
874c9be7 | 839 | $sctJson['soft_credit'] = array_merge((array) $jsonData->soft_credit, $sctJson['soft_credit']); |
ba60f73e | 840 | } |
841 | $sctJson = json_encode($sctJson); | |
842 | } | |
843 | return $sctJson; | |
844 | } | |
9161952c | 845 | |
874c9be7 | 846 | /** |
2c4442ca | 847 | * Generate html for pdf in confirmation receipt email attachment. |
848 | * | |
014c4014 TO |
849 | * @param int $contributionId |
850 | * Contribution Page Id. | |
851 | * @param int $userID | |
852 | * Contact id for contributor. | |
a6c01b45 | 853 | * @return array |
9161952c | 854 | */ |
00be9182 | 855 | public static function addInvoicePdfToEmail($contributionId, $userID) { |
9161952c PD |
856 | $contributionID = array($contributionId); |
857 | $contactId = array($userID); | |
858 | $pdfParams = array( | |
859 | 'output' => 'pdf_invoice', | |
21dfd5f5 | 860 | 'forPage' => 'confirmpage', |
9161952c | 861 | ); |
62179e22 | 862 | $pdfHtml = CRM_Contribute_Form_Task_Invoice::printPDF($contributionID, |
863 | $pdfParams, $contactId, CRM_Core_DAO::$_nullObject); | |
9161952c PD |
864 | return $pdfHtml; |
865 | } | |
f64a217a EM |
866 | |
867 | /** | |
7fe37828 EM |
868 | * Helper to determine if the page supports separate membership payments. |
869 | * | |
79d7553f | 870 | * @param int $id form id |
f64a217a | 871 | * |
a6c01b45 CW |
872 | * @return bool |
873 | * isSeparateMembershipPayment | |
f64a217a | 874 | */ |
00be9182 | 875 | public static function getIsMembershipPayment($id) { |
353ffa53 TO |
876 | $membershipBlocks = civicrm_api3('membership_block', 'get', array( |
877 | 'entity_table' => 'civicrm_contribution_page', | |
878 | 'entity_id' => $id, | |
79d7553f | 879 | 'sequential' => TRUE, |
353ffa53 | 880 | )); |
22e263ad | 881 | if (!$membershipBlocks['count']) { |
f64a217a EM |
882 | return FALSE; |
883 | } | |
884 | return $membershipBlocks['values'][0]['is_separate_payment']; | |
885 | } | |
96025800 | 886 | |
6a488035 | 887 | } |