diff --git a/CRM/Contribute/Form/Task/PDFLatex.php b/CRM/Contribute/Form/Task/PDFLatex.php
new file mode 100644
index 0000000..f353e00
--- /dev/null
+++ b/CRM/Contribute/Form/Task/PDFLatex.php
@@ -0,0 +1,147 @@
+skipOnHold = $this->skipDeceased = FALSE;
+ CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this);
+
+ // store case id if present
+ $this->_caseId = CRM_Utils_Request::retrieve('caseid', 'Positive', $this, FALSE);
+
+ // retrieve contact ID if this is 'single' mode
+ $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE);
+
+ $this->_activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
+
+ if ($cid) {
+ CRM_Contact_Form_Task_PDFLetterCommon::preProcessSingle($this, $cid);
+ $this->_single = TRUE;
+ $this->_cid = $cid;
+ }
+ else {
+ parent::preProcess();
+ }
+ $this->assign('single', $this->_single);
+ }
+
+ function setDefaultValues() {
+ $defaults = array();
+ if (isset($this->_activityId)) {
+ $params = array('id' => $this->_activityId);
+ CRM_Activity_BAO_Activity::retrieve($params, $defaults);
+ $defaults['html_message'] = $defaults['details'];
+ }
+ $defaults = $defaults + CRM_Contact_Form_Task_PDFLetterCommon::setDefaultValues();
+ return $defaults;
+ }
+
+ /**
+ * Build the form
+ *
+ * @access public
+ *
+ * @return void
+ */
+ public function buildQuickForm() {
+ //enable form element
+ $this->assign('suppressForm', FALSE);
+
+ // use contact form as a base
+ CRM_Contact_Form_Task_PDFLetterCommon::buildQuickForm($this);
+
+ // specific need for contributions
+ $this->add('static', 'more_options_header', NULL, ts('Record Update Options'));
+ $this->add('checkbox', 'receipt_update', ts('Update receipt dates for these contributions'), FALSE);
+ $this->add('checkbox', 'thankyou_update', ts('Update thank-you dates for these contributions'), FALSE);
+
+ // Group options for tokens are not yet implemented. dgg
+ $options = array(ts('Contact'), ts('Recurring'));
+ $this->addRadio('is_group_by', ts('Grouping contributions in one letter based on'), $options, array(), " ", FALSE);
+
+ $this->addButtons(array(
+ array(
+ 'type' => 'submit',
+ 'name' => ts('Make Thank-you Letters'),
+ 'isDefault' => TRUE,
+ ),
+ array(
+ 'type' => 'cancel',
+ 'name' => ts('Done'),
+ ),
+ )
+ );
+
+ }
+
+ /**
+ * process the form after the input has been submitted and validated
+ *
+ * @access public
+ *
+ * @return None
+ */
+ public function postProcess() {
+ // TODO: rewrite using contribution token and one letter by contribution
+ $this->setContactIDs();
+
+ CRM_Contribute_Form_Task_PDFLatexCommon::postProcess($this);
+ }
+
+
+}
+
diff --git a/CRM/Contribute/Form/Task/PDFLatexCommon.php b/CRM/Contribute/Form/Task/PDFLatexCommon.php
new file mode 100644
index 0000000..862b03f
--- /dev/null
+++ b/CRM/Contribute/Form/Task/PDFLatexCommon.php
@@ -0,0 +1,116 @@
+skipOnHold) ? $form->skipOnHold : FALSE;
+ $skipDeceased = isset($form->skipDeceased) ? $form->skipDeceased : TRUE;
+
+ foreach ($form->getVar('_contributionIds') as $item => $contributionId) {
+
+ // get contact information
+ $contactId = civicrm_api("Contribution", "getvalue", array('version' => '3', 'id' => $contributionId, 'return' => 'contact_id'));
+ $params = array('contact_id' => $contactId);
+
+ list($contact) = CRM_Utils_Token::getTokenDetails($params,
+ $returnProperties,
+ $skipOnHold,
+ $skipDeceased,
+ NULL,
+ $messageToken,
+ 'CRM_Contribution_Form_Task_PDFLetterCommon'
+ );
+ if (civicrm_error($contact)) {
+ $notSent[] = $contributionId;
+ continue;
+ }
+
+ // get contribution information
+ $params = array('contribution_id' => $contributionId);
+ $contribution = CRM_Utils_Token::getContributionTokenDetails($params,
+ $returnProperties,
+ NULL,
+ $messageToken,
+ 'CRM_Contribution_Form_Task_PDFLetterCommon'
+ );
+ if (civicrm_error($contribution)) {
+ $notSent[] = $contributionId;
+ continue;
+ }
+
+ $tokenHtml = CRM_Utils_Token::replaceContactTokens($html_message, $contact[$contactId], FALSE, $messageToken);
+ $tokenHtml = CRM_Utils_Token::replaceContributionTokens($tokenHtml, $contribution[$contributionId], TRUE, $messageToken);
+ $tokenHtml = CRM_Utils_Token::replaceHookTokens($tokenHtml, $contact[$contactId], $categories, TRUE);
+
+ if (defined('CIVICRM_MAIL_SMARTY') && CIVICRM_MAIL_SMARTY) {
+ $smarty = CRM_Core_Smarty::singleton();
+ // also add the tokens to the template
+ $smarty->assign_by_ref('contact', $contact);
+ $tokenHtml = $smarty->fetch("string:$tokenHtml");
+ }
+
+ $html[] = $tokenHtml;
+
+ // update dates (do it for each contribution including grouped recurring contribution)
+ if ($receipt_update) {
+ $result = CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'receipt_date', $nowDate);
+ // We can't use CRM_Core_Error::fatal here because the api error elevates the exception level. FIXME. dgg
+ if ($result) {
+ $receipts++;
+ }
+ }
+ if ($thankyou_update) {
+ $result = CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'thankyou_date', $nowDate);
+ // We can't use CRM_Core_Error::fatal here because the api error elevates the exception level. FIXME. dgg
+ if ($result) {
+ $thanks++;
+ }
+ }
+ }
+
+ self::createActivities($form, $html_message, $form->_contactIds);
+
+ CRM_Utils_PDF_Utils::latex2pdf($html, "CiviLatex.pdf", FALSE, $formValues);
+
+ $form->postProcessHook();
+
+ if ($receipts) {
+ $updateStatus = ts('Receipt date has been updated for %1 contributions.', array(1 => $receipts));
+ }
+ if ($thanks) {
+ $updateStatus .= ' ' . ts('Thank-you date has been updated for %1 contributions.', array(1 => $thanks));
+ }
+
+ if ($updateStatus) {
+ CRM_Core_Session::setStatus($updateStatus);
+ }
+
+ CRM_Utils_System::civiExit(1);
+ }
+ //end of function
+}
+
diff --git a/CRM/Contribute/Task.php b/CRM/Contribute/Task.php
index 987b280..129cb45 100644
--- a/CRM/Contribute/Task.php
+++ b/CRM/Contribute/Task.php
@@ -39,7 +39,7 @@
*
*/
class CRM_Contribute_Task {
- CONST DELETE_CONTRIBUTIONS = 1, PRINT_CONTRIBUTIONS = 2, EXPORT_CONTRIBUTIONS = 3, BATCH_CONTRIBUTIONS = 4, EMAIL_CONTACTS = 5, UPDATE_STATUS = 6, PDF_RECEIPT = 7;
+ CONST DELETE_CONTRIBUTIONS = 1, PRINT_CONTRIBUTIONS = 2, EXPORT_CONTRIBUTIONS = 3, BATCH_CONTRIBUTIONS = 4, EMAIL_CONTACTS = 5, UPDATE_STATUS = 6, PDF_RECEIPT = 7, LATEX_TEST = 9;
/**
* the task array
@@ -106,6 +106,10 @@ static function &tasks() {
'class' => 'CRM_Contribute_Form_Task_PDFLetter',
'result' => FALSE,
),
+ 9 => array('title' => ts('Latex Letters for Contributions'),
+ 'class' => 'CRM_Contribute_Form_Task_PDFLatex',
+ 'result' => FALSE,
+ ),
);
//CRM-4418, check for delete
diff --git a/CRM/Utils/PDF/Utils.php b/CRM/Utils/PDF/Utils.php
index 72d4880..e9d59b9 100644
--- a/CRM/Utils/PDF/Utils.php
+++ b/CRM/Utils/PDF/Utils.php
@@ -34,6 +34,69 @@
*/
class CRM_Utils_PDF_Utils {
+ static function latex2pdf(&$text, $fileName = 'civicrm.pdf', $output = FALSE, $pdfFormat = NULL) {
+ /* FIXME: get $paper_size, $orientation, $margins */
+
+ if (is_array($text)) {
+ $pages = &$text;
+ }
+ else {
+ $pages = array($text);
+ }
+
+
+ $head='\documentclass[12pt]{letter}
+\oddsidemargin 0in
+\evensidemargin 0in
+\textwidth 6.5in
+
+\topmargin -.25in
+\textheight 8.15in
+
+\address{\vspace{0.354in}}
+
+\begin{document}
+
+';
+ $footer='
+\end{document}';
+
+ $latex = $head;
+ foreach ($pages as $page) {
+ $latex.=$page;
+ }
+ $latex.=$footer;
+
+ $descriptorspec = array(
+ 0 => array("pipe", "r"),
+ 1 => array("pipe", "w")
+ );
+
+
+
+ $process = proc_open("/usr/local/bin/pdflatex_wrapper.sh", $descriptorspec, $pipes);
+
+
+ if (is_resource($process)) {
+ fwrite($pipes[0], $latex);
+ fclose($pipes[0]);
+
+ $pdf = stream_get_contents($pipes[1]);
+ fclose($pipes[1]);
+ } else {
+ CRM_Core_Error::debug_log_message("ERROR creating PDF. Check /tmp/pdflatex_*");
+ }
+
+ if ($output) {
+ return $pdf;
+ }
+ else {
+ header('Content-Type: application/pdf');
+ header('Content-Disposition: attachment; filename="' . $fileName . '"');
+ echo $pdf;
+ }
+ }
+
static function html2pdf(&$text, $fileName = 'civicrm.pdf', $output = FALSE, $pdfFormat = NULL) {
if (is_array($text)) {
$pages = &$text;
diff --git a/CRM/Utils/Token.php b/CRM/Utils/Token.php
index 28ca941..e8df124 100644
--- a/CRM/Utils/Token.php
+++ b/CRM/Utils/Token.php
@@ -619,7 +619,10 @@ function ($matches) use(&$contact, $html, $returnBlankToken, $escapeSmarty) {
$str
);
- $str = preg_replace('/\\\\|\{(\s*)?\}/', ' ', $str);
+ // 2013-08-31 nico@fsf.org this replacement is stripping all the '{' and '}' from the LaTeX files
+ // maybe it got solved at some point. maybe it has undesired collateral effects. I'm bugging the
+ // CiviCRM community to take a look at this pull request.
+ //$str = preg_replace('/\\\\|\{(\s*)?\}/', ' ', $str);
return $str;
}
diff --git a/templates/CRM/Contact/Form/Task/PDFLatexCommon.tpl b/templates/CRM/Contact/Form/Task/PDFLatexCommon.tpl
new file mode 100644
index 0000000..1f75f97
--- /dev/null
+++ b/templates/CRM/Contact/Form/Task/PDFLatexCommon.tpl
@@ -0,0 +1,312 @@
+{*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.4 |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013 |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM. |
+ | |
+ | CiviCRM is free software; you can copy, modify, and distribute it |
+ | under the terms of the GNU Affero General Public License |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
+ | |
+ | CiviCRM is distributed in the hope that it will be useful, but |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
+ | See the GNU Affero General Public License for more details. |
+ | |
+ | You should have received a copy of the GNU Affero General Public |
+ | License and the CiviCRM Licensing Exception along |
+ | with this program; if not, contact CiviCRM LLC |
+ | at info[AT]civicrm[DOT]org. If you have questions about the |
+ | GNU Affero General Public License or the licensing of CiviCRM, |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+*}
+{*common template for compose PDF letters*}
+{if $form.template.html}
+
+{/if}
+
+
+
+
+
+
+ {if $action neq 4}
+
+ {$form.token1.label}
+ {help id="id-token-html" file="CRM/Contact/Form/Task/Email.hlp" tplFile=$tplFile isAdmin=$isAdmin editor=$editor}
+
+
+ {ts}Begin typing to filter list of tokens{/ts}
+ {$form.token1.html}
+
+
+ {/if}
+
+
+ {if $editor EQ 'textarea'}
+
{ts}The content of this page should be LaTeX.{/ts}
+ {/if}
+ {$form.html_message.html}
+
+
+
+
+ {$form.updateTemplate.html} {$form.updateTemplate.label}
+
+
+ {$form.saveTemplate.html} {$form.saveTemplate.label}
+
+
+
+
+
{$form.saveTemplateName.label}
+
{$form.saveTemplateName.html|crmAddClass:huge}
+
+
+
+
+
+{include file="CRM/Mailing/Form/InsertTokens.tpl"}
+
+{literal}
+
+{/literal}
+
diff --git a/templates/CRM/Contribute/Form/Task/PDFLatex.tpl b/templates/CRM/Contribute/Form/Task/PDFLatex.tpl
new file mode 100644
index 0000000..a7fb259
--- /dev/null
+++ b/templates/CRM/Contribute/Form/Task/PDFLatex.tpl
@@ -0,0 +1,48 @@
+{*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.4 |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013 |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM. |
+ | |
+ | CiviCRM is free software; you can copy, modify, and distribute it |
+ | under the terms of the GNU Affero General Public License |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
+ | |
+ | CiviCRM is distributed in the hope that it will be useful, but |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
+ | See the GNU Affero General Public License for more details. |
+ | |
+ | You should have received a copy of the GNU Affero General Public |
+ | License and the CiviCRM Licensing Exception along |
+ | with this program; if not, contact CiviCRM LLC |
+ | at info[AT]civicrm[DOT]org. If you have questions about the |
+ | GNU Affero General Public License or the licensing of CiviCRM, |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+*}
+
--
1.8.4