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