Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
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 | } | |
290 | ||
291 | $title = isset($values['title']) ? $values['title'] : CRM_Contribute_PseudoConstant::contributionPage($values['contribution_page_id']); | |
292 | ||
293 | // set email in the template here | |
294 | $tplParams = array( | |
295 | 'email' => $email, | |
296 | 'receiptFromEmail' => CRM_Utils_Array::value('receipt_from_email', $values), | |
297 | 'contactID' => $contactID, | |
298 | 'displayName' => $displayName, | |
299 | 'contributionID' => CRM_Utils_Array::value('contribution_id', $values), | |
300 | 'contributionOtherID' => CRM_Utils_Array::value('contribution_other_id', $values), | |
301 | 'membershipID' => CRM_Utils_Array::value('membership_id', $values), | |
302 | // CRM-5095 | |
303 | 'lineItem' => CRM_Utils_Array::value('lineItem', $values), | |
304 | // CRM-5095 | |
305 | 'priceSetID' => CRM_Utils_Array::value('priceSetID', $values), | |
306 | 'title' => $title, | |
307 | 'isShare' => CRM_Utils_Array::value('is_share', $values), | |
308 | ); | |
309 | ||
91bb24a7 | 310 | if ($contributionTypeId = CRM_Utils_Array::value('financial_type_id', $values)) { |
6a488035 | 311 | $tplParams['contributionTypeId'] = $contributionTypeId; |
91bb24a7 | 312 | $tplParams['contributionTypeName'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', |
313 | $contributionTypeId); | |
6a488035 TO |
314 | } |
315 | ||
316 | if ($contributionPageId = CRM_Utils_Array::value('id', $values)) { | |
317 | $tplParams['contributionPageId'] = $contributionPageId; | |
318 | } | |
319 | ||
320 | // address required during receipt processing (pdf and email receipt) | |
321 | if ($displayAddress = CRM_Utils_Array::value('address', $values)) { | |
322 | $tplParams['address'] = $displayAddress; | |
323 | } | |
324 | ||
325 | // CRM-6976 | |
326 | $originalCCReceipt = CRM_Utils_Array::value('cc_receipt', $values); | |
327 | ||
328 | // cc to related contacts of contributor OR the one who | |
329 | // signs up. Is used for cases like - on behalf of | |
330 | // contribution / signup ..etc | |
331 | if (array_key_exists('related_contact', $values)) { | |
332 | list($ccDisplayName, $ccEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($values['related_contact']); | |
333 | $ccMailId = "{$ccDisplayName} <{$ccEmail}>"; | |
334 | ||
0d8afee2 | 335 | $values['cc_receipt'] = !empty($values['cc_receipt']) ? ($values['cc_receipt'] . ',' . $ccMailId) : $ccMailId; |
6a488035 TO |
336 | |
337 | // reset primary-email in the template | |
338 | $tplParams['email'] = $ccEmail; | |
339 | ||
340 | $tplParams['onBehalfName'] = $displayName; | |
341 | $tplParams['onBehalfEmail'] = $email; | |
342 | ||
343 | $ufJoinParams = array( | |
344 | 'module' => 'onBehalf', | |
345 | 'entity_table' => 'civicrm_contribution_page', | |
346 | 'entity_id' => $values['id'], | |
347 | ); | |
348 | $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); | |
91bb24a7 | 349 | $profileId = $OnBehalfProfile[0]; |
350 | $userID = $contactID; | |
6a488035 TO |
351 | self::buildCustomDisplay($profileId, 'onBehalfProfile', $userID, $template, $params['onbehalf_profile'], $fieldTypes); |
352 | } | |
353 | ||
354 | // use either the contribution or membership receipt, based on whether it’s a membership-related contrib or not | |
355 | $sendTemplateParams = array( | |
356 | 'groupName' => $tplParams['membershipID'] ? 'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution', | |
357 | 'valueName' => $tplParams['membershipID'] ? 'membership_online_receipt' : 'contribution_online_receipt', | |
358 | 'contactId' => $contactID, | |
359 | 'tplParams' => $tplParams, | |
360 | 'isTest' => $isTest, | |
361 | 'PDFFilename' => 'receipt.pdf', | |
362 | ); | |
363 | ||
364 | if ($returnMessageText) { | |
c6327d7d | 365 | list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); |
6a488035 TO |
366 | return array( |
367 | 'subject' => $subject, | |
368 | 'body' => $message, | |
369 | 'to' => $displayName, | |
370 | 'html' => $html, | |
371 | ); | |
372 | } | |
373 | ||
374 | if ($values['is_email_receipt']) { | |
375 | $sendTemplateParams['from'] = CRM_Utils_Array::value('receipt_from_name', $values) . ' <' . $values['receipt_from_email'] . '>'; | |
376 | $sendTemplateParams['toName'] = $displayName; | |
377 | $sendTemplateParams['toEmail'] = $email; | |
378 | $sendTemplateParams['cc'] = CRM_Utils_Array::value('cc_receipt', $values); | |
379 | $sendTemplateParams['bcc'] = CRM_Utils_Array::value('bcc_receipt', $values); | |
c6327d7d | 380 | list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); |
6a488035 TO |
381 | } |
382 | ||
383 | // send duplicate alert, if dupe match found during on-behalf-of processing. | |
a7488080 | 384 | if (!empty($values['onbehalf_dupe_alert'])) { |
6a488035 TO |
385 | $sendTemplateParams['groupName'] = 'msg_tpl_workflow_contribution'; |
386 | $sendTemplateParams['valueName'] = 'contribution_dupalert'; | |
387 | $sendTemplateParams['from'] = ts('Automatically Generated') . " <{$values['receipt_from_email']}>"; | |
388 | $sendTemplateParams['toName'] = CRM_Utils_Array::value('receipt_from_name', $values); | |
389 | $sendTemplateParams['toEmail'] = CRM_Utils_Array::value('receipt_from_email', $values); | |
390 | $sendTemplateParams['tplParams']['onBehalfID'] = $contactID; | |
391 | $sendTemplateParams['tplParams']['receiptMessage'] = $message; | |
392 | ||
393 | // fix cc and reset back to original, CRM-6976 | |
394 | $sendTemplateParams['cc'] = $originalCCReceipt; | |
395 | ||
c6327d7d | 396 | CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); |
6a488035 TO |
397 | } |
398 | } | |
399 | } | |
8ef12e64 | 400 | |
6a488035 TO |
401 | /* |
402 | * Construct the message to be sent by the send function | |
403 | * | |
404 | */ | |
405 | function composeMessage($tplParams, $contactID, $isTest) { | |
406 | $sendTemplateParams = array( | |
407 | 'groupName' => $tplParams['membershipID'] ? 'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution', | |
408 | 'valueName' => $tplParams['membershipID'] ? 'membership_online_receipt' : 'contribution_online_receipt', | |
409 | 'contactId' => $contactID, | |
410 | 'tplParams' => $tplParams, | |
411 | 'isTest' => $isTest, | |
412 | 'PDFFilename' => 'receipt.pdf', | |
413 | ); | |
414 | if ($returnMessageText) { | |
c6327d7d | 415 | list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); |
6a488035 TO |
416 | return array( |
417 | 'subject' => $subject, | |
418 | 'body' => $message, | |
419 | 'to' => $displayName, | |
420 | 'html' => $html, | |
421 | ); | |
422 | } | |
423 | } | |
424 | ||
425 | /** | |
426 | * Function to send the emails for Recurring Contribution Notication | |
427 | * | |
428 | * @param string $type txnType | |
429 | * @param int $contactID contact id for contributor | |
430 | * @param int $pageID contribution page id | |
431 | * @param object $recur object of recurring contribution table | |
432 | * @param object $autoRenewMembership is it a auto renew membership. | |
433 | * | |
434 | * @return void | |
435 | * @access public | |
436 | * @static | |
437 | */ | |
438 | static function recurringNotify($type, $contactID, $pageID, $recur, $autoRenewMembership = FALSE) { | |
439 | $value = array(); | |
440 | if ($pageID) { | |
441 | CRM_Core_DAO::commonRetrieveAll('CRM_Contribute_DAO_ContributionPage', 'id', $pageID, $value, array( | |
91bb24a7 | 442 | 'title', |
443 | 'is_email_receipt', | |
444 | 'receipt_from_name', | |
445 | 'receipt_from_email', | |
446 | 'cc_receipt', | |
447 | 'bcc_receipt', | |
448 | )); | |
6a488035 TO |
449 | } |
450 | ||
451 | $isEmailReceipt = CRM_Utils_Array::value('is_email_receipt', $value[$pageID]); | |
452 | $isOfflineRecur = FALSE; | |
453 | if (!$pageID && $recur->id) { | |
454 | $isOfflineRecur = TRUE; | |
455 | } | |
456 | if ($isEmailReceipt || $isOfflineRecur) { | |
457 | if ($pageID) { | |
458 | $receiptFrom = '"' . CRM_Utils_Array::value('receipt_from_name', $value[$pageID]) . '" <' . $value[$pageID]['receipt_from_email'] . '>'; | |
459 | ||
460 | $receiptFromName = $value[$pageID]['receipt_from_name']; | |
461 | $receiptFromEmail = $value[$pageID]['receipt_from_email']; | |
462 | } | |
463 | else { | |
91bb24a7 | 464 | $domainValues = CRM_Core_BAO_Domain::getNameAndEmail(); |
465 | $receiptFrom = "$domainValues[0] <$domainValues[1]>"; | |
466 | $receiptFromName = $domainValues[0]; | |
6a488035 TO |
467 | $receiptFromEmail = $domainValues[1]; |
468 | } | |
469 | ||
470 | list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID, FALSE); | |
471 | $templatesParams = array( | |
472 | 'groupName' => 'msg_tpl_workflow_contribution', | |
473 | 'valueName' => 'contribution_recurring_notify', | |
474 | 'contactId' => $contactID, | |
475 | 'tplParams' => array( | |
476 | 'recur_frequency_interval' => $recur->frequency_interval, | |
477 | 'recur_frequency_unit' => $recur->frequency_unit, | |
478 | 'recur_installments' => $recur->installments, | |
479 | 'recur_start_date' => $recur->start_date, | |
480 | 'recur_end_date' => $recur->end_date, | |
481 | 'recur_amount' => $recur->amount, | |
482 | 'recur_txnType' => $type, | |
483 | 'displayName' => $displayName, | |
484 | 'receipt_from_name' => $receiptFromName, | |
485 | 'receipt_from_email' => $receiptFromEmail, | |
486 | 'auto_renew_membership' => $autoRenewMembership, | |
487 | ), | |
488 | 'from' => $receiptFrom, | |
489 | 'toName' => $displayName, | |
490 | 'toEmail' => $email, | |
491 | ); | |
4240a120 | 492 | //CRM-13811 |
039134ba | 493 | if ($pageID) { |
494 | $templatesParams['cc'] = CRM_Utils_Array::value('cc_receipt', $value[$pageID]); | |
495 | $templatesParams['bcc'] = CRM_Utils_Array::value('bcc_receipt', $value[$pageID]); | |
496 | } | |
6a488035 TO |
497 | if ($recur->id) { |
498 | // in some cases its just recurringNotify() thats called for the first time and these urls don't get set. | |
499 | // like in PaypalPro, & therefore we set it here additionally. | |
91bb24a7 | 500 | $template = CRM_Core_Smarty::singleton(); |
6a488035 | 501 | $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($recur->id, 'recur', 'obj'); |
91bb24a7 | 502 | $url = $paymentProcessor->subscriptionURL($recur->id, 'recur'); |
6a488035 TO |
503 | $template->assign('cancelSubscriptionUrl', $url); |
504 | ||
505 | $url = $paymentProcessor->subscriptionURL($recur->id, 'recur', 'billing'); | |
506 | $template->assign('updateSubscriptionBillingUrl', $url); | |
507 | ||
508 | $url = $paymentProcessor->subscriptionURL($recur->id, 'recur', 'update'); | |
509 | $template->assign('updateSubscriptionUrl', $url); | |
510 | } | |
511 | ||
c6327d7d | 512 | list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($templatesParams); |
6a488035 TO |
513 | |
514 | if ($sent) { | |
515 | CRM_Core_Error::debug_log_message('Success: mail sent for recurring notification.'); | |
516 | } | |
517 | else { | |
518 | CRM_Core_Error::debug_log_message('Failure: mail not sent for recurring notification.'); | |
519 | } | |
520 | } | |
521 | } | |
522 | ||
523 | /** | |
524 | * Function to add the custom fields for contribution page (ie profile) | |
525 | * | |
526 | * @param int $gid uf group id | |
527 | * @param string $name | |
528 | * @param int $cid contact id | |
529 | * @param array $params params to build component whereclause | |
530 | * | |
531 | * @return void | |
532 | * @access public | |
533 | * @static | |
534 | */ | |
20222c10 | 535 | public static function buildCustomDisplay($gid, $name, $cid, &$template, &$params, $fieldTypes = NULL) { |
6a488035 TO |
536 | if ($gid) { |
537 | if (CRM_Core_BAO_UFGroup::filterUFGroups($gid, $cid)) { | |
91bb24a7 | 538 | $values = array(); |
6a488035 | 539 | $groupTitle = NULL; |
91bb24a7 | 540 | $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 |
541 | foreach ($fields as $k => $v) { |
542 | if (!$groupTitle) { | |
543 | $groupTitle = $v["groupTitle"]; | |
544 | } | |
545 | // suppress all file fields from display and formatting fields | |
546 | if ( | |
547 | CRM_Utils_Array::value('data_type', $v, '') == 'File' || | |
548 | CRM_Utils_Array::value('name', $v, '') == 'image_URL' || | |
549 | CRM_Utils_Array::value('field_type', $v) == 'Formatting' | |
550 | ) { | |
551 | unset($fields[$k]); | |
552 | } | |
553 | ||
554 | if (!empty($fieldTypes) && (!in_array($v['field_type'], $fieldTypes))) { | |
555 | unset($fields[$k]); | |
556 | } | |
557 | } | |
558 | ||
559 | if ($groupTitle) { | |
560 | $template->assign($name . "_grouptitle", $groupTitle); | |
561 | } | |
562 | ||
563 | CRM_Core_BAO_UFGroup::getValues($cid, $fields, $values, FALSE, $params); | |
564 | ||
565 | if (count($values)) { | |
566 | $template->assign($name, $values); | |
567 | } | |
568 | } | |
569 | } | |
570 | } | |
571 | ||
572 | /** | |
573 | * This function is to make a copy of a contribution page, including | |
574 | * all the blocks in the page | |
575 | * | |
576 | * @param int $id the contribution page id to copy | |
577 | * | |
578 | * @return the copy object | |
579 | * @access public | |
580 | * @static | |
581 | */ | |
582 | static function copy($id) { | |
583 | $fieldsFix = array( | |
584 | 'prefix' => array( | |
585 | 'title' => ts('Copy of') . ' ', | |
586 | ), | |
587 | ); | |
588 | $copy = &CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_ContributionPage', array( | |
589 | 'id' => $id, | |
590 | ), NULL, $fieldsFix); | |
591 | ||
592 | //copying all the blocks pertaining to the contribution page | |
593 | $copyPledgeBlock = &CRM_Core_DAO::copyGeneric('CRM_Pledge_DAO_PledgeBlock', array( | |
594 | 'entity_id' => $id, | |
595 | 'entity_table' => 'civicrm_contribution_page', | |
596 | ), array( | |
597 | 'entity_id' => $copy->id, | |
598 | )); | |
599 | ||
600 | $copyMembershipBlock = &CRM_Core_DAO::copyGeneric('CRM_Member_DAO_MembershipBlock', array( | |
601 | 'entity_id' => $id, | |
602 | 'entity_table' => 'civicrm_contribution_page', | |
603 | ), array( | |
604 | 'entity_id' => $copy->id, | |
605 | )); | |
606 | ||
607 | $copyUFJoin = &CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array( | |
608 | 'entity_id' => $id, | |
609 | 'entity_table' => 'civicrm_contribution_page', | |
610 | ), array( | |
611 | 'entity_id' => $copy->id, | |
612 | )); | |
613 | ||
614 | $copyWidget = &CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_Widget', array( | |
615 | 'contribution_page_id' => $id, | |
616 | ), array( | |
617 | 'contribution_page_id' => $copy->id, | |
618 | )); | |
619 | ||
c6914066 | 620 | //copy price sets |
9da8dc8c | 621 | CRM_Price_BAO_PriceSet::copyPriceSet('civicrm_contribution_page', $id, $copy->id); |
c6914066 | 622 | |
6a488035 TO |
623 | $copyTellFriend = &CRM_Core_DAO::copyGeneric('CRM_Friend_DAO_Friend', array( |
624 | 'entity_id' => $id, | |
625 | 'entity_table' => 'civicrm_contribution_page', | |
626 | ), array( | |
627 | 'entity_id' => $copy->id, | |
628 | )); | |
629 | ||
630 | $copyPersonalCampaignPages = &CRM_Core_DAO::copyGeneric('CRM_PCP_DAO_PCPBlock', array( | |
631 | 'entity_id' => $id, | |
632 | 'entity_table' => 'civicrm_contribution_page', | |
633 | ), array( | |
634 | 'entity_id' => $copy->id, | |
635 | )); | |
636 | ||
637 | $copyPremium = &CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_Premium', array( | |
638 | 'entity_id' => $id, | |
639 | 'entity_table' => 'civicrm_contribution_page', | |
640 | ), array( | |
641 | 'entity_id' => $copy->id, | |
642 | )); | |
643 | $premiumQuery = " | |
644 | SELECT id | |
645 | FROM civicrm_premiums | |
646 | WHERE entity_table = 'civicrm_contribution_page' | |
647 | AND entity_id ={$id}"; | |
648 | ||
649 | $premiumDao = CRM_Core_DAO::executeQuery($premiumQuery, CRM_Core_DAO::$_nullArray); | |
650 | while ($premiumDao->fetch()) { | |
651 | if ($premiumDao->id) { | |
91bb24a7 | 652 | $copyPremiumProduct = & CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_PremiumsProduct', array( |
653 | 'premiums_id' => $premiumDao->id, | |
654 | ), array( | |
655 | 'premiums_id' => $copyPremium->id, | |
656 | )); | |
6a488035 TO |
657 | } |
658 | } | |
659 | ||
660 | $copy->save(); | |
661 | ||
662 | CRM_Utils_Hook::copy('ContributionPage', $copy); | |
663 | ||
664 | return $copy; | |
665 | } | |
666 | ||
667 | /** | |
668 | * Function to check if contribution page contains payment | |
669 | * processor that supports recurring payment | |
670 | * | |
671 | * @param int $contributionPageId Contribution Page Id | |
672 | * | |
673 | * @return boolean true if payment processor supports recurring | |
674 | * else false | |
675 | * | |
676 | * @access public | |
677 | * @static | |
678 | */ | |
679 | static function checkRecurPaymentProcessor($contributionPageId) { | |
680 | //FIXME | |
681 | $sql = " | |
682 | SELECT pp.is_recur | |
683 | FROM civicrm_contribution_page cp, | |
684 | civicrm_payment_processor pp | |
685 | WHERE cp.payment_processor = pp.id | |
686 | AND cp.id = {$contributionPageId} | |
687 | "; | |
688 | ||
689 | if ($recurring = &CRM_Core_DAO::singleValueQuery($sql, CRM_Core_DAO::$_nullArray)) { | |
690 | return TRUE; | |
691 | } | |
692 | return FALSE; | |
693 | } | |
694 | ||
695 | /** | |
696 | * Function to get info for all sections enable/disable. | |
697 | * | |
698 | * @return array $info info regarding all sections. | |
699 | * @access public | |
700 | * @static | |
701 | */ | |
91bb24a7 | 702 | static function getSectionInfo($contribPageIds = array()) { |
6a488035 TO |
703 | $info = array(); |
704 | $whereClause = NULL; | |
705 | if (is_array($contribPageIds) && !empty($contribPageIds)) { | |
706 | $whereClause = 'WHERE civicrm_contribution_page.id IN ( ' . implode(', ', $contribPageIds) . ' )'; | |
707 | } | |
708 | ||
709 | $sections = array( | |
710 | 'settings', | |
711 | 'amount', | |
712 | 'membership', | |
713 | 'custom', | |
714 | 'thankyou', | |
715 | 'friend', | |
716 | 'pcp', | |
717 | 'widget', | |
718 | 'premium', | |
719 | ); | |
720 | $query = " | |
721 | SELECT civicrm_contribution_page.id as id, | |
8ef12e64 | 722 | civicrm_contribution_page.financial_type_id as settings, |
6a488035 TO |
723 | amount_block_is_active as amount, |
724 | civicrm_membership_block.id as membership, | |
725 | civicrm_uf_join.id as custom, | |
726 | civicrm_contribution_page.thankyou_title as thankyou, | |
727 | civicrm_tell_friend.id as friend, | |
728 | civicrm_pcp_block.id as pcp, | |
729 | civicrm_contribution_widget.id as widget, | |
730 | civicrm_premiums.id as premium | |
731 | FROM civicrm_contribution_page | |
732 | LEFT JOIN civicrm_membership_block ON ( civicrm_membership_block.entity_id = civicrm_contribution_page.id | |
733 | AND civicrm_membership_block.entity_table = 'civicrm_contribution_page' | |
734 | AND civicrm_membership_block.is_active = 1 ) | |
735 | LEFT JOIN civicrm_uf_join ON ( civicrm_uf_join.entity_id = civicrm_contribution_page.id | |
736 | AND civicrm_uf_join.entity_table = 'civicrm_contribution_page' | |
737 | AND module = 'CiviContribute' | |
738 | AND civicrm_uf_join.is_active = 1 ) | |
739 | LEFT JOIN civicrm_tell_friend ON ( civicrm_tell_friend.entity_id = civicrm_contribution_page.id | |
740 | AND civicrm_tell_friend.entity_table = 'civicrm_contribution_page' | |
741 | AND civicrm_tell_friend.is_active = 1) | |
742 | LEFT JOIN civicrm_pcp_block ON ( civicrm_pcp_block.entity_id = civicrm_contribution_page.id | |
743 | AND civicrm_pcp_block.entity_table = 'civicrm_contribution_page' | |
744 | AND civicrm_pcp_block.is_active = 1 ) | |
745 | LEFT JOIN civicrm_contribution_widget ON ( civicrm_contribution_widget.contribution_page_id = civicrm_contribution_page.id | |
746 | AND civicrm_contribution_widget.is_active = 1 ) | |
747 | LEFT JOIN civicrm_premiums ON ( civicrm_premiums.entity_id = civicrm_contribution_page.id | |
748 | AND civicrm_premiums.entity_table = 'civicrm_contribution_page' | |
749 | AND civicrm_premiums.premiums_active = 1 ) | |
750 | $whereClause"; | |
751 | ||
752 | $contributionPage = CRM_Core_DAO::executeQuery($query); | |
753 | while ($contributionPage->fetch()) { | |
754 | if (!isset($info[$contributionPage->id]) || !is_array($info[$contributionPage->id])) { | |
755 | $info[$contributionPage->id] = array_fill_keys(array_values($sections), FALSE); | |
756 | } | |
757 | foreach ($sections as $section) { | |
758 | if ($contributionPage->$section) { | |
759 | $info[$contributionPage->id][$section] = TRUE; | |
760 | } | |
761 | } | |
762 | } | |
763 | ||
764 | return $info; | |
765 | } | |
766 | } | |
767 |