本文整理汇总了PHP中CRM_Utils_PDF_Utils::html2pdf方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_PDF_Utils::html2pdf方法的具体用法?PHP CRM_Utils_PDF_Utils::html2pdf怎么用?PHP CRM_Utils_PDF_Utils::html2pdf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Utils_PDF_Utils
的用法示例。
在下文中一共展示了CRM_Utils_PDF_Utils::html2pdf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postProcessMembers
/**
* process the form after the input has been submitted and validated
* @todo this is horrible copy & paste code because there is so much risk of breakage
* in fixing the existing pdfLetter classes to be suitably generic
* @access public
*
* @param $form
* @param $membershipIDs
* @param $skipOnHold
* @param $skipDeceased
* @param $contactIDs
*
* @return void
*/
static function postProcessMembers(&$form, $membershipIDs, $skipOnHold, $skipDeceased, $contactIDs)
{
list($formValues, $categories, $html_message, $messageToken, $returnProperties) = self::processMessageTemplate($form);
$html = self::generateHTML($membershipIDs, $returnProperties, $skipOnHold, $skipDeceased, $messageToken, $html_message, $categories);
self::createActivities($form, $html_message, $contactIDs);
CRM_Utils_PDF_Utils::html2pdf($html, "CiviLetter.pdf", FALSE, $formValues);
$form->postProcessHook();
CRM_Utils_System::civiExit(1);
}
示例2: postProcess
public function postProcess()
{
// get the acl clauses built before we assemble the query
$this->buildACLClause($this->_aliases['civicrm_contact']);
// get ready with post process params
$this->beginPostProcess();
// build query
$sql = $this->buildQuery();
// build array of result based on column headers. This method also allows
// modifying column headers before using it to build result set i.e $rows.
$rows = array();
$this->buildRows($sql, $rows);
// format result set.
$this->formatDisplay($rows);
//call local post process for only print and pdf.
//we do need special formatted o/p only when we do have grouping
$orderBys = CRM_Utils_Array::value('order_bys', $this->_params, array());
if (in_array($this->_outputMode, array('print', 'pdf'))) {
$outPut = array();
$templateFile = parent::getTemplateFileName();
if (array_key_exists('street_name', $orderBys) || array_key_exists('street_number', $orderBys)) {
$orderByStreetName = CRM_Utils_Array::value('street_name', $orderBys);
$orderByStreetNum = CRM_Utils_Array::value('street_number', $orderBys);
$pageCnt = 0;
$dataPerPage = array();
$lastStreetName = $lastStreetNum = NULL;
foreach ($rows as $row) {
//do we need to take new page.
if ($orderByStreetName && $lastStreetName != CRM_Utils_Array::value('civicrm_address_street_name', $row)) {
$pageCnt++;
} elseif ($orderByStreetNum && $lastStreetNum != CRM_Utils_Array::value('civicrm_address_street_number', $row) % 2) {
$pageCnt++;
}
//get the data per page.
$dataPerPage[$pageCnt][] = $row;
$lastStreetName = CRM_Utils_Array::value('civicrm_address_street_name', $row);
$lastStreetNum = CRM_Utils_Array::value('civicrm_address_street_number', $row) % 2;
}
foreach ($dataPerPage as $page) {
// assign variables to templates
$this->doTemplateAssignment($page);
$outPut[] = CRM_Core_Form::$_template->fetch($templateFile);
}
} else {
$this->doTemplateAssignment($rows);
$outPut[] = CRM_Core_Form::$_template->fetch($templateFile);
}
$header = $this->_formValues['report_header'];
$footer = $this->_formValues['report_footer'];
//get the cover sheet.
$coverSheet = $this->_surveyCoverSheet();
$footerImage = preg_replace('/<\\/html>|<\\/body>|<\\/div>/i', '', $footer);
$outPut = $header . $coverSheet . "<div style=\"page-break-after: always\"></div>" . implode($footerImage . "<div style=\"page-break-after: always\"></div>", $outPut) . $footer;
if ($this->_outputMode == 'print') {
echo $outPut;
} else {
CRM_Utils_PDF_Utils::html2pdf($outPut, "CiviReport.pdf");
}
CRM_Utils_System::civiExit();
} else {
$this->doTemplateAssignment($rows);
$this->endPostProcess($rows);
}
}
示例3: postProcess
/**
* process the form after the input has been submitted and validated
*
* @access public
*
* @return None
*/
static function postProcess(&$form)
{
list($formValues, $categories, $html_message, $messageToken, $returnProperties) = self::processMessageTemplate($form);
$skipOnHold = isset($form->skipOnHold) ? $form->skipOnHold : FALSE;
$skipDeceased = isset($form->skipDeceased) ? $form->skipDeceased : TRUE;
foreach ($form->_contactIds as $item => $contactId) {
$params = array('contact_id' => $contactId);
list($contact) = CRM_Utils_Token::getTokenDetails($params, $returnProperties, $skipOnHold, $skipDeceased, NULL, $messageToken, 'CRM_Contact_Form_Task_PDFLetterCommon');
if (civicrm_error($contact)) {
$notSent[] = $contactId;
continue;
}
$tokenHtml = CRM_Utils_Token::replaceContactTokens($html_message, $contact[$contactId], 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 contact tokens to the template
$smarty->assign_by_ref('contact', $contact);
$tokenHtml = $smarty->fetch("string:{$tokenHtml}");
}
$html[] = $tokenHtml;
}
self::createActivities($form, $html_message, $form->_contactIds);
CRM_Utils_PDF_Utils::html2pdf($html, "CiviLetter.pdf", FALSE, $formValues);
$form->postProcessHook();
CRM_Utils_System::civiExit(1);
}
示例4: generatePDF
//.........这里部分代码省略.........
$html = $this->_template->msg_html;
// --- watermark injection ---
// identify pdf engine
$pdf_engine = $config->wkhtmltopdfPath;
if (!empty($pdf_engine)) {
$wk_is_enabled = TRUE;
$watermark_css = '<style>
{literal}
.watermark {
position: fixed;
z-index: 999;
color: rgba(128, 128, 128, 0.20);
-ms-transform: rotate(-45deg); /* IE 9 */
-webkit-transform: rotate(-45deg); /* Chrome, Safari, Opera */
transform: rotate(-45deg);
font-size: 100pt!important;
}
.watermark-center {
left: 10px;
top: 400px;
}
{/literal}
</style>
';
} else {
$wk_is_enabled = FALSE;
$watermark_css = '<style>
{literal}
.watermark {
position: fixed;
z-index: 999;
opacity: 0.10;
-ms-transform: rotate(-45deg); /* IE 9 */
-webkit-transform: rotate(-45deg); /* Chrome, Safari, Opera */
transform: rotate(-45deg);
font-size: 100pt!important;
}
.watermark-center {
left: 30px;
top: 650px;
}
{/literal}
</style>
';
}
$smarty->assign('wk_enabled', $wk_is_enabled);
// prepare watermark
$watermark_site = '<div class="watermark watermark-center">{if $watermark}{$watermark}{/if}</div>';
// find </style> element
$matches = array();
preg_match('/<\\/style>/', $html, $matches, PREG_OFFSET_CAPTURE);
if (count($matches) == 1) {
$head_offset = $matches[0][1];
$html = substr_replace($html, $watermark_css, $head_offset + strlen($matches[0][0]), 0);
} else {
if (count($matches) < 1) {
CRM_Core_Error::debug_log_message('de.systopia.donrec: watermark css could not be created (</style> not found). falling back to <body>.');
$matches = array();
preg_match('/<body>/', $html, $matches, PREG_OFFSET_CAPTURE);
if (count($matches) == 1) {
$head_offset = $matches[0][1];
$html = substr_replace($html, $watermark_css, $head_offset, 0);
} else {
CRM_Core_Error::debug_log_message('de.systopia.donrec: watermark could not be created. pdf rendering cancelled.');
return FALSE;
}
}
}
// find <body> element
$matches = array();
preg_match('/<body[^>]*>/', $html, $matches, PREG_OFFSET_CAPTURE);
if (count($matches) == 1) {
$body_offset = $matches[0][1];
$html = substr_replace($html, $watermark_site, $body_offset + strlen($matches[0][0]), 0);
} else {
if (count($matches) < 1) {
CRM_Core_Error::debug_log_message('de.systopia.donrec: watermark could not be created for site one (<body> not found). pdf rendering cancelled.');
return FALSE;
}
}
// --- watermark injection end ---
// compile template
$html = $smarty->fetch("string:{$html}");
// reset template variables
$smarty->clearTemplateVars();
// set up file names
$filename_export = CRM_Donrec_Logic_File::makeFileName(ts("donationreceipt-", array('domain' => 'de.systopia.donrec')) . "{$values['contributor']['id']}-" . date('YmdHis'), ".pdf");
// render PDF receipt
$result = file_put_contents($filename_export, CRM_Utils_PDF_Utils::html2pdf($html, null, true, $this->_template->pdf_format_id));
if ($result) {
return $filename_export;
} else {
$parameters['error'] = "Could not write file {$filename_export}";
return FALSE;
}
}
示例5: renderForm
/**
* Render the page using a custom templating system.
*
* @param CRM_Core_Form $page
* The CRM_Core_Form page.
*/
public function renderForm(&$page)
{
$this->_setRenderTemplates($page);
$template = CRM_Core_Smarty::singleton();
$form = $page->toSmarty();
// Deprecated - use snippet=6 instead of json=1
$json = CRM_Utils_Request::retrieve('json', 'Boolean', CRM_Core_DAO::$_nullObject);
if ($json) {
CRM_Utils_JSON::output($form);
}
$template->assign('form', $form);
$template->assign('isForm', 1);
$controller =& $page->controller;
// Stop here if we are in embedded mode. Exception: displaying form errors via ajax
if ($controller->getEmbedded() && !(!empty($form['errors']) && $controller->_QFResponseType == 'json')) {
return;
}
$template->assign('action', $page->getAction());
$pageTemplateFile = $page->getHookedTemplateFileName();
$template->assign('tplFile', $pageTemplateFile);
$content = $template->fetch($controller->getTemplateFile());
if (!defined('CIVICRM_UF_HEAD') && ($region = CRM_Core_Region::instance('html-header', FALSE))) {
CRM_Utils_System::addHTMLHead($region->render(''));
}
CRM_Utils_System::appendTPLFile($pageTemplateFile, $content, $page->overrideExtraTemplateFileName());
//its time to call the hook.
CRM_Utils_Hook::alterContent($content, 'form', $pageTemplateFile, $page);
$print = $controller->getPrint();
if ($print) {
$html =& $content;
} else {
$html = CRM_Utils_System::theme($content, $print);
}
if ($controller->_QFResponseType == 'json') {
$response = array('content' => $html);
if (!empty($page->ajaxResponse)) {
$response += $page->ajaxResponse;
}
if (!empty($form['errors'])) {
$response['status'] = 'form_error';
$response['errors'] = $form['errors'];
}
CRM_Core_Page_AJAX::returnJsonResponse($response);
}
if ($print) {
if ($print == CRM_Core_Smarty::PRINT_PDF) {
CRM_Utils_PDF_Utils::html2pdf($content, "{$page->_name}.pdf", FALSE, array('paper_size' => 'a3', 'orientation' => 'landscape'));
} else {
echo $html;
}
CRM_Utils_System::civiExit();
}
print $html;
}
示例6: postProcess
/**
* process the form after the input has been submitted and validated
*
* @access public
*
* @return void
*/
public function postProcess()
{
// get all the details needed to generate a receipt
$contribIDs = implode(',', $this->_contributionIds);
$details = CRM_Contribute_Form_Task_Status::getDetails($contribIDs);
$baseIPN = new CRM_Core_Payment_BaseIPN();
$message = array();
$template = CRM_Core_Smarty::singleton();
$params = $this->controller->exportValues($this->_name);
$createPdf = FALSE;
if ($params['output'] == "pdf_receipt") {
$createPdf = TRUE;
}
$excludeContactIds = array();
if (!$createPdf) {
$returnProperties = array('email' => 1, 'do_not_email' => 1, 'is_deceased' => 1, 'on_hold' => 1);
list($contactDetails) = CRM_Utils_Token::getTokenDetails($this->_contactIds, $returnProperties, FALSE, FALSE);
$suppressedEmails = 0;
foreach ($contactDetails as $id => $values) {
if (empty($values['email']) || !empty($values['do_not_email']) || CRM_Utils_Array::value('is_deceased', $values) || !empty($values['on_hold'])) {
$suppressedEmails++;
$excludeContactIds[] = $values['contact_id'];
}
}
}
foreach ($details as $contribID => $detail) {
$input = $ids = $objects = array();
if (in_array($detail['contact'], $excludeContactIds)) {
continue;
}
$input['component'] = $detail['component'];
$ids['contact'] = $detail['contact'];
$ids['contribution'] = $contribID;
$ids['contributionRecur'] = NULL;
$ids['contributionPage'] = NULL;
$ids['membership'] = CRM_Utils_Array::value('membership', $detail);
$ids['participant'] = CRM_Utils_Array::value('participant', $detail);
$ids['event'] = CRM_Utils_Array::value('event', $detail);
if (!$baseIPN->validateData($input, $ids, $objects, FALSE)) {
CRM_Core_Error::fatal();
}
$contribution =& $objects['contribution'];
// CRM_Core_Error::debug('o',$objects);
// set some fake input values so we can reuse IPN code
$input['amount'] = $contribution->total_amount;
$input['is_test'] = $contribution->is_test;
$input['fee_amount'] = $contribution->fee_amount;
$input['net_amount'] = $contribution->net_amount;
$input['trxn_id'] = $contribution->trxn_id;
$input['trxn_date'] = isset($contribution->trxn_date) ? $contribution->trxn_date : NULL;
// CRM_Contribute_BAO_Contribution::composeMessageArray expects mysql formatted date
$objects['contribution']->receive_date = CRM_Utils_Date::isoToMysql($objects['contribution']->receive_date);
// CRM_Core_Error::debug('input',$input);
$values = array();
$mail = $baseIPN->sendMail($input, $ids, $objects, $values, FALSE, $createPdf);
if ($mail['html']) {
$message[] = $mail['html'];
} else {
$message[] = nl2br($mail['body']);
}
// reset template values before processing next transactions
$template->clearTemplateVars();
}
if ($createPdf) {
CRM_Utils_PDF_Utils::html2pdf($message, 'civicrmContributionReceipt.pdf', FALSE, $params['pdf_format_id']);
CRM_Utils_System::civiExit();
} else {
if ($suppressedEmails) {
$status = ts('Email was NOT sent to %1 contacts (no email address on file, or communication preferences specify DO NOT EMAIL, or contact is deceased).', array(1 => $suppressedEmails));
$msgTitle = ts('Email Error');
$msgType = 'error';
} else {
$status = ts('Your mail has been sent.');
$msgTitle = ts('Sent');
$msgType = 'success';
}
CRM_Core_Session::setStatus($status, $msgTitle, $msgType);
}
}
示例7: run
/**
* This function takes care of all the things common to all
* pages. This typically involves assigning the appropriate smarty
* variable :)
*
* @return void|string
* The content generated by running this page
*/
public function run()
{
if ($this->_embedded) {
return NULL;
}
self::$_template->assign('mode', $this->_mode);
$pageTemplateFile = $this->getHookedTemplateFileName();
self::$_template->assign('tplFile', $pageTemplateFile);
// invoke the pagRun hook, CRM-3906
CRM_Utils_Hook::pageRun($this);
if ($this->_print) {
if (in_array($this->_print, array(CRM_Core_Smarty::PRINT_SNIPPET, CRM_Core_Smarty::PRINT_PDF, CRM_Core_Smarty::PRINT_NOFORM, CRM_Core_Smarty::PRINT_JSON))) {
$content = self::$_template->fetch('CRM/common/snippet.tpl');
} else {
$content = self::$_template->fetch('CRM/common/print.tpl');
}
CRM_Utils_System::appendTPLFile($pageTemplateFile, $content, $this->overrideExtraTemplateFileName());
//its time to call the hook.
CRM_Utils_Hook::alterContent($content, 'page', $pageTemplateFile, $this);
if ($this->_print == CRM_Core_Smarty::PRINT_PDF) {
CRM_Utils_PDF_Utils::html2pdf($content, "{$this->_name}.pdf", FALSE, array('paper_size' => 'a3', 'orientation' => 'landscape'));
} elseif ($this->_print == CRM_Core_Smarty::PRINT_JSON) {
$this->ajaxResponse['content'] = $content;
CRM_Core_Page_AJAX::returnJsonResponse($this->ajaxResponse);
} else {
echo $content;
}
CRM_Utils_System::civiExit();
}
$config = CRM_Core_Config::singleton();
// Intermittent alert to admins
CRM_Utils_Check::singleton()->showPeriodicAlerts();
if ($this->useLivePageJS && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'ajaxPopupsEnabled', NULL, TRUE)) {
CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js', 1, 'html-header');
}
$content = self::$_template->fetch('CRM/common/' . strtolower($config->userFramework) . '.tpl');
// Render page header
if (!defined('CIVICRM_UF_HEAD') && ($region = CRM_Core_Region::instance('html-header', FALSE))) {
CRM_Utils_System::addHTMLHead($region->render(''));
}
CRM_Utils_System::appendTPLFile($pageTemplateFile, $content);
//its time to call the hook.
CRM_Utils_Hook::alterContent($content, 'page', $pageTemplateFile, $this);
echo CRM_Utils_System::theme($content, $this->_print);
}
示例8: postProcess
/**
* Process the form after the input has been submitted and validated.
*
* @param CRM_Contribute_Form_Task $form
*/
public static function postProcess(&$form)
{
$formValues = $form->controller->exportValues($form->getName());
list($formValues, $categories, $html_message, $messageToken, $returnProperties) = self::processMessageTemplate($formValues);
$isPDF = FALSE;
$emailParams = array();
if (!empty($formValues['email_options'])) {
$returnProperties['email'] = $returnProperties['on_hold'] = $returnProperties['is_deceased'] = $returnProperties['do_not_email'] = 1;
$emailParams = array('subject' => $formValues['subject']);
// We need display_name for emailLetter() so add to returnProperties here
$returnProperties['display_name'] = 1;
if (stristr($formValues['email_options'], 'pdfemail')) {
$isPDF = TRUE;
}
}
// update dates ?
$receipt_update = isset($formValues['receipt_update']) ? $formValues['receipt_update'] : FALSE;
$thankyou_update = isset($formValues['thankyou_update']) ? $formValues['thankyou_update'] : FALSE;
$nowDate = date('YmdHis');
$receipts = $thanks = $emailed = 0;
$updateStatus = '';
$task = 'CRM_Contribution_Form_Task_PDFLetterCommon';
$realSeparator = ', ';
$tableSeparators = array('td' => '</td><td>', 'tr' => '</td></tr><tr><td>');
//the original thinking was mutliple options - but we are going with only 2 (comma & td) for now in case
// there are security (& UI) issues we need to think through
if (isset($formValues['group_by_separator'])) {
if (in_array($formValues['group_by_separator'], array('td', 'tr'))) {
$realSeparator = $tableSeparators[$formValues['group_by_separator']];
} elseif ($formValues['group_by_separator'] == 'br') {
$realSeparator = "<br />";
}
}
$separator = '****~~~~';
// a placeholder in case the separator is common in the string - e.g ', '
$validated = FALSE;
$groupBy = $formValues['group_by'];
// skip some contacts ?
$skipOnHold = isset($form->skipOnHold) ? $form->skipOnHold : FALSE;
$skipDeceased = isset($form->skipDeceased) ? $form->skipDeceased : TRUE;
$contributionIDs = $form->getVar('_contributionIds');
if ($form->_includesSoftCredits) {
//@todo - comment on what is stored there
$contributionIDs = $form->getVar('_contributionContactIds');
}
list($contributions, $contacts) = self::buildContributionArray($groupBy, $contributionIDs, $returnProperties, $skipOnHold, $skipDeceased, $messageToken, $task, $separator, $form->_includesSoftCredits);
$html = array();
foreach ($contributions as $contributionId => $contribution) {
$contact =& $contacts[$contribution['contact_id']];
$grouped = $groupByID = 0;
if ($groupBy) {
$groupByID = empty($contribution[$groupBy]) ? 0 : $contribution[$groupBy];
$contribution = $contact['combined'][$groupBy][$groupByID];
$grouped = TRUE;
}
self::assignCombinedContributionValues($contact, $contributions, $groupBy, $groupByID);
if (empty($groupBy) || empty($contact['is_sent'][$groupBy][$groupByID])) {
if (!$validated && in_array($realSeparator, $tableSeparators) && !self::isValidHTMLWithTableSeparator($messageToken, $html_message)) {
$realSeparator = ', ';
CRM_Core_Session::setStatus(ts('You have selected the table cell separator, but one or more token fields are not placed inside a table cell. This would result in invalid HTML, so comma separators have been used instead.'));
}
$validated = TRUE;
$html[$contributionId] = str_replace($separator, $realSeparator, self::resolveTokens($html_message, $contact, $contribution, $messageToken, $categories, $grouped, $separator));
$contact['is_sent'][$groupBy][$groupByID] = TRUE;
if (!empty($formValues['email_options'])) {
if (self::emailLetter($contact, $html[$contributionId], $isPDF, $formValues, $emailParams)) {
$emailed++;
if (!stristr($formValues['email_options'], 'both')) {
unset($html[$contributionId]);
}
}
}
}
// update dates (do it for each contribution including grouped recurring contribution)
//@todo - the 2 calls below bypass all hooks. Using the api would possibly be slower than one call but not than 2
if ($receipt_update) {
$result = CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'receipt_date', $nowDate);
if ($result) {
$receipts++;
}
}
if ($thankyou_update) {
$result = CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'thankyou_date', $nowDate);
if ($result) {
$thanks++;
}
}
}
//createActivities requires both $form->_contactIds and $contacts -
//@todo - figure out why
$form->_contactIds = array_keys($contacts);
self::createActivities($form, $html_message, $form->_contactIds);
if (!empty($html)) {
CRM_Utils_PDF_Utils::html2pdf($html, "CiviLetter.pdf", FALSE, $formValues);
}
//.........这里部分代码省略.........
示例9: postProcess
/**
* process the form after the input has been submitted and validated
*
* @access public
* @return None
*/
static function postProcess(&$form)
{
$formValues = $form->controller->exportValues($form->getName());
// process message template
require_once 'CRM/Core/BAO/MessageTemplates.php';
if (CRM_Utils_Array::value('saveTemplate', $formValues) || CRM_Utils_Array::value('updateTemplate', $formValues)) {
$messageTemplate = array('msg_text' => NULL, 'msg_html' => $formValues['html_message'], 'msg_subject' => NULL, 'is_active' => true);
if ($formValues['saveTemplate']) {
$messageTemplate['msg_title'] = $formValues['saveTemplateName'];
CRM_Core_BAO_MessageTemplates::add($messageTemplate);
}
if ($formValues['template'] && $formValues['updateTemplate']) {
$messageTemplate['id'] = $formValues['template'];
unset($messageTemplate['msg_title']);
CRM_Core_BAO_MessageTemplates::add($messageTemplate);
}
}
require_once 'dompdf/dompdf_config.inc.php';
$html = '<html><head><style>body { margin: 56px; }</style></head><body>';
require_once 'api/v2/Contact.php';
require_once 'CRM/Utils/Token.php';
$tokens = array();
CRM_Utils_Hook::tokens($tokens);
$categories = array_keys($tokens);
$html_message = $formValues['html_message'];
require_once 'CRM/Activity/BAO/Activity.php';
$messageToken = CRM_Activity_BAO_Activity::getTokens($html_message);
$returnProperties = array();
if (isset($messageToken['contact'])) {
foreach ($messageToken['contact'] as $key => $value) {
$returnProperties[$value] = 1;
}
}
require_once 'CRM/Mailing/BAO/Mailing.php';
$mailing =& new CRM_Mailing_BAO_Mailing();
$first = TRUE;
foreach ($form->_contactIds as $item => $contactId) {
$params = array('contact_id' => $contactId);
list($contact) = $mailing->getDetails($params, $returnProperties, false);
if (civicrm_error($contact)) {
$notSent[] = $contactId;
continue;
}
$tokenHtml = CRM_Utils_Token::replaceContactTokens($html_message, $contact[$contactId], true, $messageToken);
$tokenHtml = CRM_Utils_Token::replaceHookTokens($tokenHtml, $contact[$contactId], $categories, true);
if ($first == TRUE) {
$first = FALSE;
$html .= $tokenHtml;
} else {
$html .= "<div STYLE='page-break-after: always'></div>{$tokenHtml}";
}
}
$html .= '</body></html>';
require_once 'CRM/Utils/PDF/Utils.php';
CRM_Utils_PDF_Utils::html2pdf($html, "CiviLetter.pdf", 'portrait');
exit(1);
}
示例10: endPostProcess
function endPostProcess(&$rows = null)
{
if ($this->_outputMode == 'print' || $this->_outputMode == 'pdf' || $this->_sendmail) {
$templateFile = parent::getTemplateFileName();
$content = $this->_formValues['report_header'] . CRM_Core_Form::$_template->fetch($templateFile) . $this->_formValues['report_footer'];
if ($this->_sendmail) {
if (CRM_Report_Utils_Report::mailReport($content, $this->_id, $this->_outputMode)) {
CRM_Core_Session::setStatus(ts("Report mail has been sent."));
} else {
CRM_Core_Session::setStatus(ts("Report mail could not be sent."));
}
if ($this->get('instanceId')) {
exit;
}
CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1'));
} else {
if ($this->_outputMode == 'print') {
echo $content;
} else {
require_once 'CRM/Utils/PDF/Utils.php';
CRM_Utils_PDF_Utils::html2pdf($content, "CiviReport.pdf");
}
}
exit;
} else {
if ($this->_outputMode == 'csv') {
CRM_Report_Utils_Report::export2csv($this, $rows);
} else {
if ($this->_outputMode == 'group') {
$group = $this->_params['groups'];
CRM_Report_Utils_Report::add2group($this, $group);
} else {
if ($this->_instanceButtonName == $this->controller->getButtonName()) {
require_once 'CRM/Report/Form/Instance.php';
CRM_Report_Form_Instance::postProcess($this);
}
}
}
}
}
示例11: render_beleg_pdf
function render_beleg_pdf($contact_id, $address, $total, $items, $from_date, $to_date, $comment)
{
global $civicrm_root;
$docs = get_docs_table();
$config = CRM_Core_Config::singleton(true, true);
/* If receipts already exist for a date range overlapping the requested range, readjust the from date for the new receipt to follow the lastest date for which receipts were already generated. */
$query = "SELECT GREATEST(MAX(DATE_ADD({$docs['field_to']}, INTERVAL 1 DAY)), '{$from_date}' ) AS from_date\n FROM {$docs['table']}\n WHERE entity_id = {$contact_id}\n AND {$docs['field_from']} < '{$to_date}' -- Ignore existing receipts for a date range beginning after the end of the requested range.\n ";
$from_ts = strtotime($from_date);
$to_ts = strtotime($to_date);
$res = CRM_Core_DAO::executeQuery($query);
$res->fetch();
if ($res->from_date) {
$from_date = $res->from_date;
}
$from_ts = strtotime($from_date);
$to_ts = strtotime($to_date);
$template = CRM_Core_Smarty::singleton();
list($html, $page_format) = get_template();
// select and set up template type
if (count($items) > 1) {
// more than one payment -> "Sammelbescheinigung" with itemized list
$item_table = array();
foreach ($items as $item) {
$item_table[] = array('date' => date("j.n.Y", strtotime($item["date"])), 'art' => $item["art"], 'amount' => number_format($item["amount"], 2, ',', '.'), 'amounttext' => num_to_text($item["amount"]));
}
$template->assign("items", $item_table);
} else {
// one payment only -> "Einzelbescheinigung"
$template->assign("items", null);
/* When generating multiple receipts in a batch (Jahresbescheinigungen), the smarty object is reused between the individual receipts (singleton) -- so need to reset this explicitly! */
$template->assign("date", date("d.m.Y", strtotime($items[0]["date"])));
}
// fill further template fields
if (date("m-d", $from_ts) == "01-01" && date("m-d", $to_ts) == "12-31") {
$daterange = date("Y", $from_ts);
} else {
$daterange = date("j.n.", $from_ts) . " bis " . date("j.n.Y", $to_ts);
}
$template->assign("daterange", $daterange);
$template->assign("donor", $address);
$template->assign("total", number_format($total, 2, ',', '.'));
$template->assign("totaltext", num_to_text($total));
$template->assign("today", date("j.n.Y", time()));
if (date("m-d", $from_ts) == "01-01" && date("m-d", $to_ts) == "12-31") {
$rangespec = date("Y", $from_ts);
} else {
$rangespec = date("Y-m-d", $from_ts) . "_" . date("m-d", $to_ts);
}
$domain = CRM_Core_BAO_Domain::getDomain();
$domain_tokens = array();
foreach (array('name', 'address') as $token) {
$domain_tokens[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain, true, true);
}
$domain_tokens['address'] = str_replace('> <', '> <', $domain_tokens['address']);
/* Hack to work around (yet another) bug in dompdf... */
$template->assign('organisation', $domain_tokens);
$html = $template->fetch("string:{$html}");
// set up file names
$basename = CRM_Utils_File::makeFileName("Zuwendungen_" . $rangespec . "_" . $contact_id . ".pdf");
$outfile = $config->customFileUploadDir;
$outfile .= "/{$basename}";
// render PDF receipt
file_put_contents($outfile, CRM_Utils_PDF_Utils::html2pdf($html, null, true, $page_format));
$file_id = saveDocument($contact_id, $basename, "application/pdf", "Spendenbescheinigung", date("Y-m-d h:i:s"), $from_date, $to_date, $comment);
// return summary data and CiviCRM URL to generated file
return array("contact_id" => $contact_id, "file_id" => $file_id, "from_date" => $from_date, "to_date" => $to_date, "total_amount" => $total, "filename" => "{$basename}", "url" => CRM_Utils_System::url("civicrm/file", "reset=1&id={$file_id}&eid={$contact_id}"));
}
示例12: postProcess
/**
* Process the form after the input has been submitted and validated.
*/
public function postProcess()
{
// get all the details needed to generate a receipt
$message = array();
$template = CRM_Core_Smarty::singleton();
$params = $this->controller->exportValues($this->_name);
$elements = self::getElements($this->_contributionIds, $params, $this->_contactIds);
foreach ($elements['details'] as $contribID => $detail) {
$input = $ids = $objects = array();
if (in_array($detail['contact'], $elements['excludeContactIds'])) {
continue;
}
$input['component'] = $detail['component'];
$ids['contact'] = $detail['contact'];
$ids['contribution'] = $contribID;
$ids['contributionRecur'] = NULL;
$ids['contributionPage'] = NULL;
$ids['membership'] = CRM_Utils_Array::value('membership', $detail);
$ids['participant'] = CRM_Utils_Array::value('participant', $detail);
$ids['event'] = CRM_Utils_Array::value('event', $detail);
if (!$elements['baseIPN']->validateData($input, $ids, $objects, FALSE)) {
CRM_Core_Error::fatal();
}
$contribution =& $objects['contribution'];
// set some fake input values so we can reuse IPN code
$input['amount'] = $contribution->total_amount;
$input['is_test'] = $contribution->is_test;
$input['fee_amount'] = $contribution->fee_amount;
$input['net_amount'] = $contribution->net_amount;
$input['trxn_id'] = $contribution->trxn_id;
$input['trxn_date'] = isset($contribution->trxn_date) ? $contribution->trxn_date : NULL;
$input['receipt_update'] = $params['receipt_update'];
$input['contribution_status_id'] = $contribution->contribution_status_id;
$input['paymentProcessor'] = empty($contribution->trxn_id) ? NULL : CRM_Core_DAO::singleValueQuery("SELECT payment_processor_id\n FROM civicrm_financial_trxn\n WHERE trxn_id = %1\n LIMIT 1", array(1 => array($contribution->trxn_id, 'String')));
// CRM_Contribute_BAO_Contribution::composeMessageArray expects mysql formatted date
$objects['contribution']->receive_date = CRM_Utils_Date::isoToMysql($objects['contribution']->receive_date);
$values = array();
if (isset($params['fromEmailAddress']) && !$elements['createPdf']) {
// CRM-19129 Allow useres the choice of From Email to send the receipt from.
$fromEmail = $params['fromEmailAddress'];
$from = CRM_Utils_Array::value($fromEmail, $this->_emails);
$fromDetails = explode(' <', $from);
$input['receipt_from_email'] = substr(trim($fromDetails[1]), 0, -1);
$input['receipt_from_name'] = str_replace('"', '', $fromDetails[0]);
}
$mail = CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $objects['contribution']->id, $values, FALSE, $elements['createPdf']);
if ($mail['html']) {
$message[] = $mail['html'];
} else {
$message[] = nl2br($mail['body']);
}
// reset template values before processing next transactions
$template->clearTemplateVars();
}
if ($elements['createPdf']) {
CRM_Utils_PDF_Utils::html2pdf($message, 'civicrmContributionReceipt.pdf', FALSE, $elements['params']['pdf_format_id']);
CRM_Utils_System::civiExit();
} else {
if ($elements['suppressedEmails']) {
$status = ts('Email was NOT sent to %1 contacts (no email address on file, or communication preferences specify DO NOT EMAIL, or contact is deceased).', array(1 => $elements['suppressedEmails']));
$msgTitle = ts('Email Error');
$msgType = 'error';
} else {
$status = ts('Your mail has been sent.');
$msgTitle = ts('Sent');
$msgType = 'success';
}
CRM_Core_Session::setStatus($status, $msgTitle, $msgType);
}
}
示例13: sendTemplate
//.........这里部分代码省略.........
$format = $dao->format;
$dao->free();
// add the test banner (if requested)
if ($params['isTest']) {
$query = "SELECT msg_subject subject, msg_text text, msg_html html\n FROM civicrm_msg_template mt\n JOIN civicrm_option_value ov ON workflow_id = ov.id\n JOIN civicrm_option_group og ON ov.option_group_id = og.id\n WHERE og.name = 'msg_tpl_workflow_meta' AND ov.name = 'test_preview' AND mt.is_default = 1";
$testDao = CRM_Core_DAO::executeQuery($query);
$testDao->fetch();
$subject = $testDao->subject . $subject;
$text = $testDao->text . $text;
$html = preg_replace('/<body(.*)$/im', "<body\\1\n{$testDao->html}", $html);
$testDao->free();
}
// replace tokens in the three elements (in subject as if it was the text body)
$domain = CRM_Core_BAO_Domain::getDomain();
$hookTokens = array();
$mailing = new CRM_Mailing_BAO_Mailing();
$mailing->body_text = $text;
$mailing->body_html = $html;
$tokens = $mailing->getTokens();
CRM_Utils_Hook::tokens($hookTokens);
$categories = array_keys($hookTokens);
$contactID = CRM_Utils_Array::value('contactId', $params);
if ($contactID) {
$contactParams = array('contact_id' => $contactID);
$returnProperties = array();
if (isset($tokens['text']['contact'])) {
foreach ($tokens['text']['contact'] as $name) {
$returnProperties[$name] = 1;
}
}
if (isset($tokens['html']['contact'])) {
foreach ($tokens['html']['contact'] as $name) {
$returnProperties[$name] = 1;
}
}
list($contact) = CRM_Utils_Token::getTokenDetails($contactParams, $returnProperties, FALSE, FALSE, NULL, CRM_Utils_Token::flattenTokens($tokens), 'CRM_Core_BAO_MessageTemplate');
$contact = $contact[$contactID];
}
$subject = CRM_Utils_Token::replaceDomainTokens($subject, $domain, TRUE, $tokens['text'], TRUE);
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, TRUE, $tokens['text'], TRUE);
$html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html'], TRUE);
if ($contactID) {
$subject = CRM_Utils_Token::replaceContactTokens($subject, $contact, FALSE, $tokens['text'], FALSE, TRUE);
$text = CRM_Utils_Token::replaceContactTokens($text, $contact, FALSE, $tokens['text'], FALSE, TRUE);
$html = CRM_Utils_Token::replaceContactTokens($html, $contact, FALSE, $tokens['html'], FALSE, TRUE);
$contactArray = array($contactID => $contact);
CRM_Utils_Hook::tokenValues($contactArray, array($contactID), NULL, CRM_Utils_Token::flattenTokens($tokens), 'CRM_Core_BAO_MessageTemplate');
$contact = $contactArray[$contactID];
$subject = CRM_Utils_Token::replaceHookTokens($subject, $contact, $categories, TRUE);
$text = CRM_Utils_Token::replaceHookTokens($text, $contact, $categories, TRUE);
$html = CRM_Utils_Token::replaceHookTokens($html, $contact, $categories, TRUE);
}
// strip whitespace from ends and turn into a single line
$subject = "{strip}{$subject}{/strip}";
// parse the three elements with Smarty
$smarty = CRM_Core_Smarty::singleton();
foreach ($params['tplParams'] as $name => $value) {
$smarty->assign($name, $value);
}
foreach (array('subject', 'text', 'html') as $elem) {
${$elem} = $smarty->fetch("string:{${$elem}}");
}
// send the template, honouring the target user’s preferences (if any)
$sent = FALSE;
// create the params array
$params['subject'] = $subject;
$params['text'] = $text;
$params['html'] = $html;
if ($params['toEmail']) {
$contactParams = array(array('email', 'LIKE', $params['toEmail'], 0, 1));
list($contact, $_) = CRM_Contact_BAO_Query::apiQuery($contactParams);
$prefs = array_pop($contact);
if (isset($prefs['preferred_mail_format']) and $prefs['preferred_mail_format'] == 'HTML') {
$params['text'] = NULL;
}
if (isset($prefs['preferred_mail_format']) and $prefs['preferred_mail_format'] == 'Text') {
$params['html'] = NULL;
}
$config = CRM_Core_Config::singleton();
$pdf_filename = '';
if ($config->doNotAttachPDFReceipt && $params['PDFFilename'] && $params['html']) {
$pdf_filename = $config->templateCompileDir . CRM_Utils_File::makeFileName($params['PDFFilename']);
//FIXME : CRM-7894
//xmlns attribute is required in XHTML but it is invalid in HTML,
//Also the namespace "xmlns=http://www.w3.org/1999/xhtml" is default,
//and will be added to the <html> tag even if you do not include it.
$html = preg_replace('/(<html)(.+?xmlns=["\'].[^\\s]+["\'])(.+)?(>)/', '\\1\\3\\4', $params['html']);
file_put_contents($pdf_filename, CRM_Utils_PDF_Utils::html2pdf($html, $params['PDFFilename'], TRUE, $format));
if (empty($params['attachments'])) {
$params['attachments'] = array();
}
$params['attachments'][] = array('fullPath' => $pdf_filename, 'mime_type' => 'application/pdf', 'cleanName' => $params['PDFFilename']);
}
$sent = CRM_Utils_Mail::send($params);
if ($pdf_filename) {
unlink($pdf_filename);
}
}
return array($sent, $subject, $text, $html);
}
示例14: run
/**
* This function takes care of all the things common to all
* pages. This typically involves assigning the appropriate
* smarty variable :)
*
* @return string The content generated by running this page
*/
function run()
{
if ($this->_embedded) {
return;
}
self::$_template->assign('mode', $this->_mode);
$pageTemplateFile = $this->getTemplateFileName();
self::$_template->assign('tplFile', $pageTemplateFile);
// invoke the pagRun hook, CRM-3906
CRM_Utils_Hook::pageRun($this);
if ($this->_print) {
if (in_array($this->_print, array(CRM_Core_Smarty::PRINT_SNIPPET, CRM_Core_Smarty::PRINT_PDF, CRM_Core_Smarty::PRINT_NOFORM))) {
$content = self::$_template->fetch('CRM/common/snippet.tpl');
} else {
$content = self::$_template->fetch('CRM/common/print.tpl');
}
CRM_Utils_System::appendTPLFile($pageTemplateFile, $content, $this->overrideExtraTemplateFileName());
//its time to call the hook.
CRM_Utils_Hook::alterContent($content, 'page', $pageTemplateFile, $this);
if ($this->_print == CRM_Core_Smarty::PRINT_PDF) {
CRM_Utils_PDF_Utils::html2pdf($content, "{$this->_name}.pdf", FALSE, array('paper_size' => 'a3', 'orientation' => 'landscape'));
} else {
echo $content;
}
CRM_Utils_System::civiExit();
}
$config = CRM_Core_Config::singleton();
$content = self::$_template->fetch('CRM/common/' . strtolower($config->userFramework) . '.tpl');
if ($region = CRM_Core_Region::instance('html-header', FALSE)) {
CRM_Utils_System::addHTMLHead($region->render(''));
}
CRM_Utils_System::appendTPLFile($pageTemplateFile, $content);
//its time to call the hook.
CRM_Utils_Hook::alterContent($content, 'page', $pageTemplateFile, $this);
echo CRM_Utils_System::theme('page', $content, TRUE, $this->_print);
return;
}
示例15: appendPDF
/**
* @param string $fileName
* @param string $html
* @param string $format
*
* @return array
*/
public static function appendPDF($fileName, $html, $format = NULL)
{
$pdf_filename = CRM_Core_Config::singleton()->templateCompileDir . CRM_Utils_File::makeFileName($fileName);
// FIXME : CRM-7894
// xmlns attribute is required in XHTML but it is invalid in HTML,
// Also the namespace "xmlns=http://www.w3.org/1999/xhtml" is default,
// and will be added to the <html> tag even if you do not include it.
$html = preg_replace('/(<html)(.+?xmlns=["\'].[^\\s]+["\'])(.+)?(>)/', '\\1\\3\\4', $html);
file_put_contents($pdf_filename, CRM_Utils_PDF_Utils::html2pdf($html, $fileName, TRUE, $format));
return array('fullPath' => $pdf_filename, 'mime_type' => 'application/pdf', 'cleanName' => $fileName);
}