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