Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
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 PN |
51 | $financialTypeId = NULL; |
52 | if (CRM_Utils_Array::value('id', $params) && !CRM_Price_BAO_Set::getFor('civicrm_contribution_page', $params['id'], NULL, 1)) { | |
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(); | |
157b21d8 PN |
58 | if ($financialTypeId && CRM_Utils_Array::value('financial_type_id', $params) |
59 | && $financialTypeId != $params['financial_type_id']) { | |
60 | CRM_Price_BAO_FieldValue::updateFinancialType($params['id'], 'civicrm_contribution_page', $params['financial_type_id']); | |
61 | } | |
6a488035 TO |
62 | return $dao; |
63 | } | |
64 | ||
65 | /** | |
66 | * update the is_active flag in the db | |
67 | * | |
68 | * @param int $id id of the database record | |
69 | * @param boolean $is_active value we want to set the is_active field | |
70 | * | |
91bb24a7 | 71 | * @return Object DAO object on success, null otherwise |
6a488035 TO |
72 | * @static |
73 | */ | |
74 | static function setIsActive($id, $is_active) { | |
75 | return CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_ContributionPage', $id, 'is_active', $is_active); | |
76 | } | |
77 | ||
78 | static function setValues($id, &$values) { | |
79 | $params = array( | |
80 | 'id' => $id, | |
81 | ); | |
82 | ||
83 | CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $values); | |
8ef12e64 | 84 | |
6a488035 TO |
85 | // get the profile ids |
86 | $ufJoinParams = array( | |
87 | 'module' => 'CiviContribute', | |
88 | 'entity_table' => 'civicrm_contribution_page', | |
89 | 'entity_id' => $id, | |
90 | ); | |
91 | list($values['custom_pre_id'], $customPostIds) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); | |
92 | ||
93 | if (!empty($customPostIds)) { | |
94 | $values['custom_post_id'] = $customPostIds[0]; | |
95 | } | |
96 | else { | |
97 | $values['custom_post_id'] = ''; | |
98 | } | |
99 | // // add an accounting code also | |
100 | // if ($values ['financial_type_id']) { | |
101 | // $values ['accountingCode'] = CRM_Core_DAO::getFieldValue( 'CRM_Financial_DAO_FinancialType', $values ['financial_type_id'], 'accounting_code' ); | |
102 | // } | |
103 | } | |
104 | ||
105 | /** | |
106 | * Function to send the emails | |
107 | * | |
108 | * @param int $contactID contact id | |
109 | * @param array $values associated array of fields | |
110 | * @param boolean $isTest if in test mode | |
111 | * @param boolean $returnMessageText return the message text instead of sending the mail | |
112 | * | |
113 | * @return void | |
114 | * @access public | |
115 | * @static | |
116 | */ | |
117 | static function sendMail($contactID, &$values, $isTest = FALSE, $returnMessageText = FALSE, $fieldTypes = NULL) { | |
118 | $gIds = $params = array(); | |
119 | $email = NULL; | |
120 | if (isset($values['custom_pre_id'])) { | |
121 | $preProfileType = CRM_Core_BAO_UFField::getProfileType($values['custom_pre_id']); | |
122 | if ($preProfileType == 'Membership' && CRM_Utils_Array::value('membership_id', $values)) { | |
123 | $params['custom_pre_id'] = array( | |
124 | array( | |
125 | 'member_id', | |
126 | '=', | |
127 | $values['membership_id'], | |
128 | 0, | |
129 | 0, | |
130 | ), | |
131 | ); | |
132 | } | |
133 | elseif ($preProfileType == 'Contribution' && CRM_Utils_Array::value('contribution_id', $values)) { | |
134 | $params['custom_pre_id'] = array( | |
135 | array( | |
136 | 'contribution_id', | |
137 | '=', | |
138 | $values['contribution_id'], | |
139 | 0, | |
140 | 0, | |
141 | ), | |
142 | ); | |
143 | } | |
144 | ||
145 | $gIds['custom_pre_id'] = $values['custom_pre_id']; | |
146 | } | |
147 | ||
148 | if (isset($values['custom_post_id'])) { | |
149 | $postProfileType = CRM_Core_BAO_UFField::getProfileType($values['custom_post_id']); | |
150 | if ($postProfileType == 'Membership' && CRM_Utils_Array::value('membership_id', $values)) { | |
151 | $params['custom_post_id'] = array( | |
152 | array( | |
153 | 'member_id', | |
154 | '=', | |
155 | $values['membership_id'], | |
156 | 0, | |
157 | 0, | |
158 | ), | |
159 | ); | |
160 | } | |
161 | elseif ($postProfileType == 'Contribution' && CRM_Utils_Array::value('contribution_id', $values)) { | |
162 | $params['custom_post_id'] = array( | |
163 | array( | |
164 | 'contribution_id', | |
165 | '=', | |
166 | $values['contribution_id'], | |
167 | 0, | |
168 | 0, | |
169 | ), | |
170 | ); | |
171 | } | |
172 | ||
173 | $gIds['custom_post_id'] = $values['custom_post_id']; | |
174 | } | |
175 | ||
176 | if (CRM_Utils_Array::value('is_for_organization', $values)) { | |
177 | if (CRM_Utils_Array::value('membership_id', $values)) { | |
178 | $params['onbehalf_profile'] = array( | |
179 | array( | |
180 | 'member_id', | |
181 | '=', | |
182 | $values['membership_id'], | |
183 | 0, | |
184 | 0, | |
185 | ), | |
186 | ); | |
187 | } | |
188 | elseif (CRM_Utils_Array::value('contribution_id', $values)) { | |
189 | $params['onbehalf_profile'] = array( | |
190 | array( | |
191 | 'contribution_id', | |
192 | '=', | |
193 | $values['contribution_id'], | |
194 | 0, | |
195 | 0, | |
196 | ), | |
197 | ); | |
198 | } | |
199 | } | |
200 | ||
201 | //check whether it is a test drive | |
202 | if ($isTest && !empty($params['custom_pre_id'])) { | |
203 | $params['custom_pre_id'][] = array( | |
204 | 'contribution_test', | |
205 | '=', | |
206 | 1, | |
207 | 0, | |
208 | 0, | |
209 | ); | |
210 | } | |
211 | ||
212 | if ($isTest && !empty($params['custom_post_id'])) { | |
213 | $params['custom_post_id'][] = array( | |
214 | 'contribution_test', | |
215 | '=', | |
216 | 1, | |
217 | 0, | |
218 | 0, | |
219 | ); | |
220 | } | |
8ef12e64 | 221 | |
6a488035 TO |
222 | if (!$returnMessageText && !empty($gIds)) { |
223 | //send notification email if field values are set (CRM-1941) | |
224 | foreach ($gIds as $key => $gId) { | |
225 | if ($gId) { | |
226 | $email = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify'); | |
227 | if ($email) { | |
228 | $val = CRM_Core_BAO_UFGroup::checkFieldsEmptyValues($gId, $contactID, CRM_Utils_Array::value($key, $params), true ); | |
229 | CRM_Core_BAO_UFGroup::commonSendMail($contactID, $val); | |
230 | } | |
231 | } | |
232 | } | |
233 | } | |
234 | ||
235 | if ( CRM_Utils_Array::value('is_email_receipt', $values) || | |
236 | CRM_Utils_Array::value('onbehalf_dupe_alert', $values) || | |
237 | $returnMessageText | |
238 | ) { | |
239 | $template = CRM_Core_Smarty::singleton(); | |
240 | ||
241 | // get the billing location type | |
242 | if (!array_key_exists('related_contact', $values)) { | |
b2b0530a | 243 | $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); |
6a488035 TO |
244 | $billingLocationTypeId = array_search('Billing', $locationTypes); |
245 | } | |
246 | else { | |
247 | // presence of related contact implies onbehalf of org case, | |
248 | // where location type is set to default. | |
249 | $locType = CRM_Core_BAO_LocationType::getDefault(); | |
250 | $billingLocationTypeId = $locType->id; | |
251 | } | |
252 | ||
253 | if (!array_key_exists('related_contact', $values)) { | |
254 | list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID, FALSE, $billingLocationTypeId); | |
255 | } | |
256 | // get primary location email if no email exist( for billing location). | |
257 | if (!$email) { | |
258 | list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID); | |
259 | } | |
260 | if (empty($displayName)) { | |
261 | list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID); | |
262 | } | |
263 | ||
264 | //for display profile need to get individual contact id, | |
265 | //hence get it from related_contact if on behalf of org true CRM-3767 | |
266 | //CRM-5001 Contribution/Membership:: On Behalf of Organization, | |
267 | //If profile GROUP contain the Individual type then consider the | |
268 | //profile is of Individual ( including the custom data of membership/contribution ) | |
269 | //IF Individual type not present in profile then it is consider as Organization data. | |
270 | $userID = $contactID; | |
271 | if ($preID = CRM_Utils_Array::value('custom_pre_id', $values)) { | |
272 | if (CRM_Utils_Array::value('related_contact', $values)) { | |
273 | $preProfileTypes = CRM_Core_BAO_UFGroup::profileGroups($preID); | |
274 | if (in_array('Individual', $preProfileTypes) || in_array('Contact', $postProfileTypes)) { | |
275 | //Take Individual contact ID | |
276 | $userID = CRM_Utils_Array::value('related_contact', $values); | |
277 | } | |
278 | } | |
279 | self::buildCustomDisplay($preID, 'customPre', $userID, $template, $params['custom_pre_id']); | |
280 | } | |
281 | $userID = $contactID; | |
282 | if ($postID = CRM_Utils_Array::value('custom_post_id', $values)) { | |
283 | if (CRM_Utils_Array::value('related_contact', $values)) { | |
284 | $postProfileTypes = CRM_Core_BAO_UFGroup::profileGroups($postID); | |
285 | if (in_array('Individual', $postProfileTypes) || in_array('Contact', $postProfileTypes)) { | |
286 | //Take Individual contact ID | |
287 | $userID = CRM_Utils_Array::value('related_contact', $values); | |
288 | } | |
289 | } | |
290 | self::buildCustomDisplay($postID, 'customPost', $userID, $template, $params['custom_post_id']); | |
291 | } | |
292 | ||
293 | $title = isset($values['title']) ? $values['title'] : CRM_Contribute_PseudoConstant::contributionPage($values['contribution_page_id']); | |
294 | ||
295 | // set email in the template here | |
296 | $tplParams = array( | |
297 | 'email' => $email, | |
298 | 'receiptFromEmail' => CRM_Utils_Array::value('receipt_from_email', $values), | |
299 | 'contactID' => $contactID, | |
300 | 'displayName' => $displayName, | |
301 | 'contributionID' => CRM_Utils_Array::value('contribution_id', $values), | |
302 | 'contributionOtherID' => CRM_Utils_Array::value('contribution_other_id', $values), | |
303 | 'membershipID' => CRM_Utils_Array::value('membership_id', $values), | |
304 | // CRM-5095 | |
305 | 'lineItem' => CRM_Utils_Array::value('lineItem', $values), | |
306 | // CRM-5095 | |
307 | 'priceSetID' => CRM_Utils_Array::value('priceSetID', $values), | |
308 | 'title' => $title, | |
309 | 'isShare' => CRM_Utils_Array::value('is_share', $values), | |
310 | ); | |
311 | ||
91bb24a7 | 312 | if ($contributionTypeId = CRM_Utils_Array::value('financial_type_id', $values)) { |
6a488035 | 313 | $tplParams['contributionTypeId'] = $contributionTypeId; |
91bb24a7 | 314 | $tplParams['contributionTypeName'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', |
315 | $contributionTypeId); | |
6a488035 TO |
316 | } |
317 | ||
318 | if ($contributionPageId = CRM_Utils_Array::value('id', $values)) { | |
319 | $tplParams['contributionPageId'] = $contributionPageId; | |
320 | } | |
321 | ||
322 | // address required during receipt processing (pdf and email receipt) | |
323 | if ($displayAddress = CRM_Utils_Array::value('address', $values)) { | |
324 | $tplParams['address'] = $displayAddress; | |
325 | } | |
326 | ||
327 | // CRM-6976 | |
328 | $originalCCReceipt = CRM_Utils_Array::value('cc_receipt', $values); | |
329 | ||
330 | // cc to related contacts of contributor OR the one who | |
331 | // signs up. Is used for cases like - on behalf of | |
332 | // contribution / signup ..etc | |
333 | if (array_key_exists('related_contact', $values)) { | |
334 | list($ccDisplayName, $ccEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($values['related_contact']); | |
335 | $ccMailId = "{$ccDisplayName} <{$ccEmail}>"; | |
336 | ||
337 | $values['cc_receipt'] = CRM_Utils_Array::value('cc_receipt', $values) ? ($values['cc_receipt'] . ',' . $ccMailId) : $ccMailId; | |
338 | ||
339 | // reset primary-email in the template | |
340 | $tplParams['email'] = $ccEmail; | |
341 | ||
342 | $tplParams['onBehalfName'] = $displayName; | |
343 | $tplParams['onBehalfEmail'] = $email; | |
344 | ||
345 | $ufJoinParams = array( | |
346 | 'module' => 'onBehalf', | |
347 | 'entity_table' => 'civicrm_contribution_page', | |
348 | 'entity_id' => $values['id'], | |
349 | ); | |
350 | $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); | |
91bb24a7 | 351 | $profileId = $OnBehalfProfile[0]; |
352 | $userID = $contactID; | |
6a488035 TO |
353 | self::buildCustomDisplay($profileId, 'onBehalfProfile', $userID, $template, $params['onbehalf_profile'], $fieldTypes); |
354 | } | |
355 | ||
356 | // use either the contribution or membership receipt, based on whether it’s a membership-related contrib or not | |
357 | $sendTemplateParams = array( | |
358 | 'groupName' => $tplParams['membershipID'] ? 'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution', | |
359 | 'valueName' => $tplParams['membershipID'] ? 'membership_online_receipt' : 'contribution_online_receipt', | |
360 | 'contactId' => $contactID, | |
361 | 'tplParams' => $tplParams, | |
362 | 'isTest' => $isTest, | |
363 | 'PDFFilename' => 'receipt.pdf', | |
364 | ); | |
365 | ||
366 | if ($returnMessageText) { | |
367 | list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate($sendTemplateParams); | |
368 | return array( | |
369 | 'subject' => $subject, | |
370 | 'body' => $message, | |
371 | 'to' => $displayName, | |
372 | 'html' => $html, | |
373 | ); | |
374 | } | |
375 | ||
376 | if ($values['is_email_receipt']) { | |
377 | $sendTemplateParams['from'] = CRM_Utils_Array::value('receipt_from_name', $values) . ' <' . $values['receipt_from_email'] . '>'; | |
378 | $sendTemplateParams['toName'] = $displayName; | |
379 | $sendTemplateParams['toEmail'] = $email; | |
380 | $sendTemplateParams['cc'] = CRM_Utils_Array::value('cc_receipt', $values); | |
381 | $sendTemplateParams['bcc'] = CRM_Utils_Array::value('bcc_receipt', $values); | |
382 | list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate($sendTemplateParams); | |
383 | } | |
384 | ||
385 | // send duplicate alert, if dupe match found during on-behalf-of processing. | |
386 | if (CRM_Utils_Array::value('onbehalf_dupe_alert', $values)) { | |
387 | $sendTemplateParams['groupName'] = 'msg_tpl_workflow_contribution'; | |
388 | $sendTemplateParams['valueName'] = 'contribution_dupalert'; | |
389 | $sendTemplateParams['from'] = ts('Automatically Generated') . " <{$values['receipt_from_email']}>"; | |
390 | $sendTemplateParams['toName'] = CRM_Utils_Array::value('receipt_from_name', $values); | |
391 | $sendTemplateParams['toEmail'] = CRM_Utils_Array::value('receipt_from_email', $values); | |
392 | $sendTemplateParams['tplParams']['onBehalfID'] = $contactID; | |
393 | $sendTemplateParams['tplParams']['receiptMessage'] = $message; | |
394 | ||
395 | // fix cc and reset back to original, CRM-6976 | |
396 | $sendTemplateParams['cc'] = $originalCCReceipt; | |
397 | ||
398 | CRM_Core_BAO_MessageTemplates::sendTemplate($sendTemplateParams); | |
399 | } | |
400 | } | |
401 | } | |
8ef12e64 | 402 | |
6a488035 TO |
403 | /* |
404 | * Construct the message to be sent by the send function | |
405 | * | |
406 | */ | |
407 | function composeMessage($tplParams, $contactID, $isTest) { | |
408 | $sendTemplateParams = array( | |
409 | 'groupName' => $tplParams['membershipID'] ? 'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution', | |
410 | 'valueName' => $tplParams['membershipID'] ? 'membership_online_receipt' : 'contribution_online_receipt', | |
411 | 'contactId' => $contactID, | |
412 | 'tplParams' => $tplParams, | |
413 | 'isTest' => $isTest, | |
414 | 'PDFFilename' => 'receipt.pdf', | |
415 | ); | |
416 | if ($returnMessageText) { | |
417 | list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate($sendTemplateParams); | |
418 | return array( | |
419 | 'subject' => $subject, | |
420 | 'body' => $message, | |
421 | 'to' => $displayName, | |
422 | 'html' => $html, | |
423 | ); | |
424 | } | |
425 | } | |
426 | ||
427 | /** | |
428 | * Function to send the emails for Recurring Contribution Notication | |
429 | * | |
430 | * @param string $type txnType | |
431 | * @param int $contactID contact id for contributor | |
432 | * @param int $pageID contribution page id | |
433 | * @param object $recur object of recurring contribution table | |
434 | * @param object $autoRenewMembership is it a auto renew membership. | |
435 | * | |
436 | * @return void | |
437 | * @access public | |
438 | * @static | |
439 | */ | |
440 | static function recurringNotify($type, $contactID, $pageID, $recur, $autoRenewMembership = FALSE) { | |
441 | $value = array(); | |
442 | if ($pageID) { | |
443 | CRM_Core_DAO::commonRetrieveAll('CRM_Contribute_DAO_ContributionPage', 'id', $pageID, $value, array( | |
91bb24a7 | 444 | 'title', |
445 | 'is_email_receipt', | |
446 | 'receipt_from_name', | |
447 | 'receipt_from_email', | |
448 | 'cc_receipt', | |
449 | 'bcc_receipt', | |
450 | )); | |
6a488035 TO |
451 | } |
452 | ||
453 | $isEmailReceipt = CRM_Utils_Array::value('is_email_receipt', $value[$pageID]); | |
454 | $isOfflineRecur = FALSE; | |
455 | if (!$pageID && $recur->id) { | |
456 | $isOfflineRecur = TRUE; | |
457 | } | |
458 | if ($isEmailReceipt || $isOfflineRecur) { | |
459 | if ($pageID) { | |
460 | $receiptFrom = '"' . CRM_Utils_Array::value('receipt_from_name', $value[$pageID]) . '" <' . $value[$pageID]['receipt_from_email'] . '>'; | |
461 | ||
462 | $receiptFromName = $value[$pageID]['receipt_from_name']; | |
463 | $receiptFromEmail = $value[$pageID]['receipt_from_email']; | |
464 | } | |
465 | else { | |
91bb24a7 | 466 | $domainValues = CRM_Core_BAO_Domain::getNameAndEmail(); |
467 | $receiptFrom = "$domainValues[0] <$domainValues[1]>"; | |
468 | $receiptFromName = $domainValues[0]; | |
6a488035 TO |
469 | $receiptFromEmail = $domainValues[1]; |
470 | } | |
471 | ||
472 | list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID, FALSE); | |
473 | $templatesParams = array( | |
474 | 'groupName' => 'msg_tpl_workflow_contribution', | |
475 | 'valueName' => 'contribution_recurring_notify', | |
476 | 'contactId' => $contactID, | |
477 | 'tplParams' => array( | |
478 | 'recur_frequency_interval' => $recur->frequency_interval, | |
479 | 'recur_frequency_unit' => $recur->frequency_unit, | |
480 | 'recur_installments' => $recur->installments, | |
481 | 'recur_start_date' => $recur->start_date, | |
482 | 'recur_end_date' => $recur->end_date, | |
483 | 'recur_amount' => $recur->amount, | |
484 | 'recur_txnType' => $type, | |
485 | 'displayName' => $displayName, | |
486 | 'receipt_from_name' => $receiptFromName, | |
487 | 'receipt_from_email' => $receiptFromEmail, | |
488 | 'auto_renew_membership' => $autoRenewMembership, | |
489 | ), | |
490 | 'from' => $receiptFrom, | |
491 | 'toName' => $displayName, | |
492 | 'toEmail' => $email, | |
493 | ); | |
494 | ||
495 | if ($recur->id) { | |
496 | // in some cases its just recurringNotify() thats called for the first time and these urls don't get set. | |
497 | // like in PaypalPro, & therefore we set it here additionally. | |
91bb24a7 | 498 | $template = CRM_Core_Smarty::singleton(); |
6a488035 | 499 | $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($recur->id, 'recur', 'obj'); |
91bb24a7 | 500 | $url = $paymentProcessor->subscriptionURL($recur->id, 'recur'); |
6a488035 TO |
501 | $template->assign('cancelSubscriptionUrl', $url); |
502 | ||
503 | $url = $paymentProcessor->subscriptionURL($recur->id, 'recur', 'billing'); | |
504 | $template->assign('updateSubscriptionBillingUrl', $url); | |
505 | ||
506 | $url = $paymentProcessor->subscriptionURL($recur->id, 'recur', 'update'); | |
507 | $template->assign('updateSubscriptionUrl', $url); | |
508 | } | |
509 | ||
510 | list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate($templatesParams); | |
511 | ||
512 | if ($sent) { | |
513 | CRM_Core_Error::debug_log_message('Success: mail sent for recurring notification.'); | |
514 | } | |
515 | else { | |
516 | CRM_Core_Error::debug_log_message('Failure: mail not sent for recurring notification.'); | |
517 | } | |
518 | } | |
519 | } | |
520 | ||
521 | /** | |
522 | * Function to add the custom fields for contribution page (ie profile) | |
523 | * | |
524 | * @param int $gid uf group id | |
525 | * @param string $name | |
526 | * @param int $cid contact id | |
527 | * @param array $params params to build component whereclause | |
528 | * | |
529 | * @return void | |
530 | * @access public | |
531 | * @static | |
532 | */ | |
533 | function buildCustomDisplay($gid, $name, $cid, &$template, &$params, $fieldTypes = NULL) { | |
534 | if ($gid) { | |
535 | if (CRM_Core_BAO_UFGroup::filterUFGroups($gid, $cid)) { | |
91bb24a7 | 536 | $values = array(); |
6a488035 | 537 | $groupTitle = NULL; |
91bb24a7 | 538 | $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 |
539 | foreach ($fields as $k => $v) { |
540 | if (!$groupTitle) { | |
541 | $groupTitle = $v["groupTitle"]; | |
542 | } | |
543 | // suppress all file fields from display and formatting fields | |
544 | if ( | |
545 | CRM_Utils_Array::value('data_type', $v, '') == 'File' || | |
546 | CRM_Utils_Array::value('name', $v, '') == 'image_URL' || | |
547 | CRM_Utils_Array::value('field_type', $v) == 'Formatting' | |
548 | ) { | |
549 | unset($fields[$k]); | |
550 | } | |
551 | ||
552 | if (!empty($fieldTypes) && (!in_array($v['field_type'], $fieldTypes))) { | |
553 | unset($fields[$k]); | |
554 | } | |
555 | } | |
556 | ||
557 | if ($groupTitle) { | |
558 | $template->assign($name . "_grouptitle", $groupTitle); | |
559 | } | |
560 | ||
561 | CRM_Core_BAO_UFGroup::getValues($cid, $fields, $values, FALSE, $params); | |
562 | ||
563 | if (count($values)) { | |
564 | $template->assign($name, $values); | |
565 | } | |
566 | } | |
567 | } | |
568 | } | |
569 | ||
570 | /** | |
571 | * This function is to make a copy of a contribution page, including | |
572 | * all the blocks in the page | |
573 | * | |
574 | * @param int $id the contribution page id to copy | |
575 | * | |
576 | * @return the copy object | |
577 | * @access public | |
578 | * @static | |
579 | */ | |
580 | static function copy($id) { | |
581 | $fieldsFix = array( | |
582 | 'prefix' => array( | |
583 | 'title' => ts('Copy of') . ' ', | |
584 | ), | |
585 | ); | |
586 | $copy = &CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_ContributionPage', array( | |
587 | 'id' => $id, | |
588 | ), NULL, $fieldsFix); | |
589 | ||
590 | //copying all the blocks pertaining to the contribution page | |
591 | $copyPledgeBlock = &CRM_Core_DAO::copyGeneric('CRM_Pledge_DAO_PledgeBlock', array( | |
592 | 'entity_id' => $id, | |
593 | 'entity_table' => 'civicrm_contribution_page', | |
594 | ), array( | |
595 | 'entity_id' => $copy->id, | |
596 | )); | |
597 | ||
598 | $copyMembershipBlock = &CRM_Core_DAO::copyGeneric('CRM_Member_DAO_MembershipBlock', array( | |
599 | 'entity_id' => $id, | |
600 | 'entity_table' => 'civicrm_contribution_page', | |
601 | ), array( | |
602 | 'entity_id' => $copy->id, | |
603 | )); | |
604 | ||
605 | $copyUFJoin = &CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array( | |
606 | 'entity_id' => $id, | |
607 | 'entity_table' => 'civicrm_contribution_page', | |
608 | ), array( | |
609 | 'entity_id' => $copy->id, | |
610 | )); | |
611 | ||
612 | $copyWidget = &CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_Widget', array( | |
613 | 'contribution_page_id' => $id, | |
614 | ), array( | |
615 | 'contribution_page_id' => $copy->id, | |
616 | )); | |
617 | ||
c6914066 | 618 | //copy price sets |
9da8dc8c | 619 | CRM_Price_BAO_PriceSet::copyPriceSet('civicrm_contribution_page', $id, $copy->id); |
c6914066 | 620 | |
6a488035 TO |
621 | $copyTellFriend = &CRM_Core_DAO::copyGeneric('CRM_Friend_DAO_Friend', array( |
622 | 'entity_id' => $id, | |
623 | 'entity_table' => 'civicrm_contribution_page', | |
624 | ), array( | |
625 | 'entity_id' => $copy->id, | |
626 | )); | |
627 | ||
628 | $copyPersonalCampaignPages = &CRM_Core_DAO::copyGeneric('CRM_PCP_DAO_PCPBlock', array( | |
629 | 'entity_id' => $id, | |
630 | 'entity_table' => 'civicrm_contribution_page', | |
631 | ), array( | |
632 | 'entity_id' => $copy->id, | |
633 | )); | |
634 | ||
635 | $copyPremium = &CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_Premium', array( | |
636 | 'entity_id' => $id, | |
637 | 'entity_table' => 'civicrm_contribution_page', | |
638 | ), array( | |
639 | 'entity_id' => $copy->id, | |
640 | )); | |
641 | $premiumQuery = " | |
642 | SELECT id | |
643 | FROM civicrm_premiums | |
644 | WHERE entity_table = 'civicrm_contribution_page' | |
645 | AND entity_id ={$id}"; | |
646 | ||
647 | $premiumDao = CRM_Core_DAO::executeQuery($premiumQuery, CRM_Core_DAO::$_nullArray); | |
648 | while ($premiumDao->fetch()) { | |
649 | if ($premiumDao->id) { | |
91bb24a7 | 650 | $copyPremiumProduct = & CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_PremiumsProduct', array( |
651 | 'premiums_id' => $premiumDao->id, | |
652 | ), array( | |
653 | 'premiums_id' => $copyPremium->id, | |
654 | )); | |
6a488035 TO |
655 | } |
656 | } | |
657 | ||
658 | $copy->save(); | |
659 | ||
660 | CRM_Utils_Hook::copy('ContributionPage', $copy); | |
661 | ||
662 | return $copy; | |
663 | } | |
664 | ||
665 | /** | |
666 | * Function to check if contribution page contains payment | |
667 | * processor that supports recurring payment | |
668 | * | |
669 | * @param int $contributionPageId Contribution Page Id | |
670 | * | |
671 | * @return boolean true if payment processor supports recurring | |
672 | * else false | |
673 | * | |
674 | * @access public | |
675 | * @static | |
676 | */ | |
677 | static function checkRecurPaymentProcessor($contributionPageId) { | |
678 | //FIXME | |
679 | $sql = " | |
680 | SELECT pp.is_recur | |
681 | FROM civicrm_contribution_page cp, | |
682 | civicrm_payment_processor pp | |
683 | WHERE cp.payment_processor = pp.id | |
684 | AND cp.id = {$contributionPageId} | |
685 | "; | |
686 | ||
687 | if ($recurring = &CRM_Core_DAO::singleValueQuery($sql, CRM_Core_DAO::$_nullArray)) { | |
688 | return TRUE; | |
689 | } | |
690 | return FALSE; | |
691 | } | |
692 | ||
693 | /** | |
694 | * Function to get info for all sections enable/disable. | |
695 | * | |
696 | * @return array $info info regarding all sections. | |
697 | * @access public | |
698 | * @static | |
699 | */ | |
91bb24a7 | 700 | static function getSectionInfo($contribPageIds = array()) { |
6a488035 TO |
701 | $info = array(); |
702 | $whereClause = NULL; | |
703 | if (is_array($contribPageIds) && !empty($contribPageIds)) { | |
704 | $whereClause = 'WHERE civicrm_contribution_page.id IN ( ' . implode(', ', $contribPageIds) . ' )'; | |
705 | } | |
706 | ||
707 | $sections = array( | |
708 | 'settings', | |
709 | 'amount', | |
710 | 'membership', | |
711 | 'custom', | |
712 | 'thankyou', | |
713 | 'friend', | |
714 | 'pcp', | |
715 | 'widget', | |
716 | 'premium', | |
717 | ); | |
718 | $query = " | |
719 | SELECT civicrm_contribution_page.id as id, | |
8ef12e64 | 720 | civicrm_contribution_page.financial_type_id as settings, |
6a488035 TO |
721 | amount_block_is_active as amount, |
722 | civicrm_membership_block.id as membership, | |
723 | civicrm_uf_join.id as custom, | |
724 | civicrm_contribution_page.thankyou_title as thankyou, | |
725 | civicrm_tell_friend.id as friend, | |
726 | civicrm_pcp_block.id as pcp, | |
727 | civicrm_contribution_widget.id as widget, | |
728 | civicrm_premiums.id as premium | |
729 | FROM civicrm_contribution_page | |
730 | LEFT JOIN civicrm_membership_block ON ( civicrm_membership_block.entity_id = civicrm_contribution_page.id | |
731 | AND civicrm_membership_block.entity_table = 'civicrm_contribution_page' | |
732 | AND civicrm_membership_block.is_active = 1 ) | |
733 | LEFT JOIN civicrm_uf_join ON ( civicrm_uf_join.entity_id = civicrm_contribution_page.id | |
734 | AND civicrm_uf_join.entity_table = 'civicrm_contribution_page' | |
735 | AND module = 'CiviContribute' | |
736 | AND civicrm_uf_join.is_active = 1 ) | |
737 | LEFT JOIN civicrm_tell_friend ON ( civicrm_tell_friend.entity_id = civicrm_contribution_page.id | |
738 | AND civicrm_tell_friend.entity_table = 'civicrm_contribution_page' | |
739 | AND civicrm_tell_friend.is_active = 1) | |
740 | LEFT JOIN civicrm_pcp_block ON ( civicrm_pcp_block.entity_id = civicrm_contribution_page.id | |
741 | AND civicrm_pcp_block.entity_table = 'civicrm_contribution_page' | |
742 | AND civicrm_pcp_block.is_active = 1 ) | |
743 | LEFT JOIN civicrm_contribution_widget ON ( civicrm_contribution_widget.contribution_page_id = civicrm_contribution_page.id | |
744 | AND civicrm_contribution_widget.is_active = 1 ) | |
745 | LEFT JOIN civicrm_premiums ON ( civicrm_premiums.entity_id = civicrm_contribution_page.id | |
746 | AND civicrm_premiums.entity_table = 'civicrm_contribution_page' | |
747 | AND civicrm_premiums.premiums_active = 1 ) | |
748 | $whereClause"; | |
749 | ||
750 | $contributionPage = CRM_Core_DAO::executeQuery($query); | |
751 | while ($contributionPage->fetch()) { | |
752 | if (!isset($info[$contributionPage->id]) || !is_array($info[$contributionPage->id])) { | |
753 | $info[$contributionPage->id] = array_fill_keys(array_values($sections), FALSE); | |
754 | } | |
755 | foreach ($sections as $section) { | |
756 | if ($contributionPage->$section) { | |
757 | $info[$contributionPage->id][$section] = TRUE; | |
758 | } | |
759 | } | |
760 | } | |
761 | ||
762 | return $info; | |
763 | } | |
764 | } | |
765 |