4 * This class provides the common functionality for creating PDF letter for
5 * one or a group of contact ids.
7 class CRM_Contribute_Form_Task_PDFLatexCommon
extends CRM_Contact_Form_Task_PDFLetterCommon
{
10 * process the form after the input has been submitted and validated
16 static function postProcess(&$form) {
18 list($formValues, $categories, $html_message, $messageToken, $returnProperties) = self
::processMessageTemplate($form);
19 //CRM_Core_Error::debug_log_message(":2 $html_message"); //OK
22 $receipt_update = isset($formValues['receipt_update']) ?
$formValues['receipt_update'] : FALSE;
23 $thankyou_update = isset($formValues['thankyou_update']) ?
$formValues['thankyou_update'] : FALSE;
24 $nowDate = date('YmdHis');
29 // skip some contacts ?
30 $skipOnHold = isset($form->skipOnHold
) ?
$form->skipOnHold
: FALSE;
31 $skipDeceased = isset($form->skipDeceased
) ?
$form->skipDeceased
: TRUE;
33 foreach ($form->getVar('_contributionIds') as $item => $contributionId) {
35 // get contact information
36 $contactId = civicrm_api("Contribution", "getvalue", array('version' => '3', 'id' => $contributionId, 'return' => 'contact_id'));
37 $params = array('contact_id' => $contactId);
39 list($contact) = CRM_Utils_Token
::getTokenDetails($params,
45 'CRM_Contribution_Form_Task_PDFLetterCommon'
47 if (civicrm_error($contact)) {
48 $notSent[] = $contributionId;
52 // get contribution information
53 $params = array('contribution_id' => $contributionId);
54 $contribution = CRM_Utils_Token
::getContributionTokenDetails($params,
58 'CRM_Contribution_Form_Task_PDFLetterCommon'
60 if (civicrm_error($contribution)) {
61 $notSent[] = $contributionId;
65 $tokenHtml = CRM_Utils_Token
::replaceContactTokens($html_message, $contact[$contactId], FALSE, $messageToken);
66 $tokenHtml = CRM_Utils_Token
::replaceContributionTokens($tokenHtml, $contribution[$contributionId], TRUE, $messageToken);
67 $tokenHtml = CRM_Utils_Token
::replaceHookTokens($tokenHtml, $contact[$contactId], $categories, TRUE);
69 if (defined('CIVICRM_MAIL_SMARTY') && CIVICRM_MAIL_SMARTY
) {
70 $smarty = CRM_Core_Smarty
::singleton();
71 // also add the tokens to the template
72 $smarty->assign_by_ref('contact', $contact);
73 $tokenHtml = $smarty->fetch("string:$tokenHtml");
78 // update dates (do it for each contribution including grouped recurring contribution)
79 if ($receipt_update) {
80 $result = CRM_Core_DAO
::setFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'receipt_date', $nowDate);
81 // We can't use CRM_Core_Error::fatal here because the api error elevates the exception level. FIXME. dgg
86 if ($thankyou_update) {
87 $result = CRM_Core_DAO
::setFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'thankyou_date', $nowDate);
88 // We can't use CRM_Core_Error::fatal here because the api error elevates the exception level. FIXME. dgg
95 self
::createActivities($form, $html_message, $form->_contactIds
);
97 CRM_Utils_PDF_Utils
::latex2pdf($html, "CiviLatex.pdf", FALSE, $formValues);
99 $form->postProcessHook();
102 $updateStatus = ts('Receipt date has been updated for %1 contributions.', array(1 => $receipts));
105 $updateStatus .= ' ' . ts('Thank-you date has been updated for %1 contributions.', array(1 => $thanks));
109 CRM_Core_Session
::setStatus($updateStatus);
112 CRM_Utils_System
::civiExit(1);