本文整理汇总了PHP中CRM_Utils_PDF_Utils类的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_PDF_Utils类的具体用法?PHP CRM_Utils_PDF_Utils怎么用?PHP CRM_Utils_PDF_Utils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CRM_Utils_PDF_Utils类的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
/**
* process the form after the input has been submitted and validated
*
* @access public
* @return None
*/
public function postProcess()
{
// get all the details needed to generate a receipt
$contribIDs = implode(',', $this->_contributionIds);
require_once 'CRM/Contribute/Form/Task/Status.php';
$details =& CRM_Contribute_Form_Task_Status::getDetails($contribIDs);
require_once 'CRM/Core/Payment/BaseIPN.php';
$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);
require_once 'CRM/Mailing/BAO/Mailing.php';
list($contactDetails) = CRM_Mailing_BAO_Mailing::getDetails($this->_contactIds, $returnProperties, false, false);
foreach ($contactDetails as $id => $values) {
if (empty($values['email']) || CRM_Utils_Array::value('do_not_email', $values) || CRM_Utils_Array::value('is_deceased', $values) || CRM_Utils_Array::value('on_hold', $values)) {
$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'] = $detail['membership'];
$ids['participant'] = $detail['participant'];
$ids['event'] = $detail['event'];
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_Core_Error::debug('input',$input);
$values = array();
$mail = $baseIPN->sendMail($input, $ids, $objects, $values, false, $createPdf);
if (!$mail['html']) {
$mail = str_replace("\n\n", "<p>", $mail);
$mail = str_replace("\n", "<br/>", $mail);
}
$message[] = $mail;
// reset template values before processing next transactions
$template->clearTemplateVars();
}
if ($createPdf) {
require_once 'CRM/Utils/PDF/Utils.php';
CRM_Utils_PDF_Utils::domlib($message, 'civicrmContributionReceipt.pdf', false, 'portrait', 'letter');
CRM_Utils_System::civiExit();
} else {
if ($suppressedEmails) {
$status = array('', 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)));
} else {
$status = array('', ts('Your mail has been sent.'));
}
CRM_Core_Session::setStatus($status);
}
}
示例3: retrieve
/**
* Retrieve DB object based on input parameters.
*
* It also stores all the retrieved values in the default array.
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
* @param array $values
* (reference ) an assoc array to hold the flattened values.
*
* @return CRM_Core_DAO_OptionValue
*/
public static function retrieve(&$params, &$values)
{
$optionValue = new CRM_Core_DAO_OptionValue();
$optionValue->copyValues($params);
$optionValue->option_group_id = self::_getGid();
if ($optionValue->find(TRUE)) {
// Extract fields that have been serialized in the 'value' column of the Option Value table.
$values = json_decode($optionValue->value, TRUE);
// Add any new fields that don't yet exist in the saved values.
foreach (self::$optionValueFields as $name => $field) {
if (!isset($values[$name])) {
$values[$name] = $field['default'];
if (isset($field['metric']) && $field['metric']) {
$values[$name] = CRM_Utils_PDF_Utils::convertMetric($field['default'], self::$optionValueFields['metric']['default'], $values['metric'], 3);
}
}
}
// Add fields from the OptionValue base class
CRM_Core_DAO::storeValues($optionValue, $values);
return $optionValue;
}
return NULL;
}
示例4: endPostProcess
/**
* End post processing.
*
* @param array|null $rows
*/
public function endPostProcess(&$rows = NULL)
{
if ($this->_storeResultSet) {
$this->_resultSet = $rows;
}
if ($this->_outputMode == 'print' || $this->_outputMode == 'pdf' || $this->_sendmail) {
$content = $this->compileContent();
$url = CRM_Utils_System::url("civicrm/report/instance/{$this->_id}", "reset=1", TRUE);
if ($this->_sendmail) {
$config = CRM_Core_Config::singleton();
$attachments = array();
if ($this->_outputMode == 'csv') {
$content = $this->_formValues['report_header'] . '<p>' . ts('Report URL') . ": {$url}</p>" . '<p>' . ts('The report is attached as a CSV file.') . '</p>' . $this->_formValues['report_footer'];
$csvFullFilename = $config->templateCompileDir . CRM_Utils_File::makeFileName('CiviReport.csv');
$csvContent = CRM_Report_Utils_Report::makeCsv($this, $rows);
file_put_contents($csvFullFilename, $csvContent);
$attachments[] = array('fullPath' => $csvFullFilename, 'mime_type' => 'text/csv', 'cleanName' => 'CiviReport.csv');
}
if ($this->_outputMode == 'pdf') {
// generate PDF content
$pdfFullFilename = $config->templateCompileDir . CRM_Utils_File::makeFileName('CiviReport.pdf');
file_put_contents($pdfFullFilename, CRM_Utils_PDF_Utils::html2pdf($content, "CiviReport.pdf", TRUE, array('orientation' => 'landscape')));
// generate Email Content
$content = $this->_formValues['report_header'] . '<p>' . ts('Report URL') . ": {$url}</p>" . '<p>' . ts('The report is attached as a PDF file.') . '</p>' . $this->_formValues['report_footer'];
$attachments[] = array('fullPath' => $pdfFullFilename, 'mime_type' => 'application/pdf', 'cleanName' => 'CiviReport.pdf');
}
if (CRM_Report_Utils_Report::mailReport($content, $this->_id, $this->_outputMode, $attachments)) {
CRM_Core_Session::setStatus(ts("Report mail has been sent."), ts('Sent'), 'success');
} else {
CRM_Core_Session::setStatus(ts("Report mail could not be sent."), ts('Mail Error'), 'error');
}
return TRUE;
} elseif ($this->_outputMode == 'print') {
echo $content;
} else {
if ($chartType = CRM_Utils_Array::value('charts', $this->_params)) {
$config = CRM_Core_Config::singleton();
//get chart image name
$chartImg = $this->_chartId . '.png';
//get image url path
$uploadUrl = str_replace('/persist/contribute/', '/persist/', $config->imageUploadURL) . 'openFlashChart/';
$uploadUrl .= $chartImg;
//get image doc path to overwrite
$uploadImg = str_replace('/persist/contribute/', '/persist/', $config->imageUploadDir) . 'openFlashChart/' . $chartImg;
//Load the image
$chart = imagecreatefrompng($uploadUrl);
//convert it into formatted png
CRM_Utils_System::setHttpHeader('Content-type', 'image/png');
//overwrite with same image
imagepng($chart, $uploadImg);
//delete the object
imagedestroy($chart);
}
CRM_Utils_PDF_Utils::html2pdf($content, "CiviReport.pdf", FALSE, array('orientation' => 'landscape'));
}
CRM_Utils_System::civiExit();
} elseif ($this->_outputMode == 'csv') {
CRM_Report_Utils_Report::export2csv($this, $rows);
} elseif ($this->_outputMode == 'group') {
$group = $this->_params['groups'];
$this->add2group($group);
}
}
示例5: printPDF
//.........这里部分代码省略.........
} else {
$stateProvinceAbbreviationDomain = '';
}
if (isset($locationDefaults['address'][1]['country_id'])) {
$countryDomain = CRM_Core_PseudoConstant::country($locationDefaults['address'][1]['country_id']);
} else {
$countryDomain = '';
}
// parameters to be assign for template
$tplParams = array('title' => $title, 'component' => $input['component'], 'id' => $contribution->id, 'source' => $source, 'invoice_id' => $invoiceId, 'resourceBase' => $config->userFrameworkResourceURL, 'defaultCurrency' => $config->defaultCurrency, 'amount' => $contribution->total_amount, 'amountDue' => $amountDue, 'invoice_date' => $invoiceDate, 'dueDate' => $dueDate, 'notes' => CRM_Utils_Array::value('notes', $prefixValue), 'display_name' => $contribution->_relatedObjects['contact']->display_name, 'lineItem' => $lineItem, 'dataArray' => $dataArray, 'refundedStatusId' => $refundedStatusId, 'contribution_status_id' => $contribution->contribution_status_id, 'subTotal' => $subTotal, 'street_address' => CRM_Utils_Array::value('street_address', CRM_Utils_Array::value($contribution->contact_id, $billingAddress)), 'supplemental_address_1' => CRM_Utils_Array::value('supplemental_address_1', CRM_Utils_Array::value($contribution->contact_id, $billingAddress)), 'supplemental_address_2' => CRM_Utils_Array::value('supplemental_address_2', CRM_Utils_Array::value($contribution->contact_id, $billingAddress)), 'city' => CRM_Utils_Array::value('city', CRM_Utils_Array::value($contribution->contact_id, $billingAddress)), 'stateProvinceAbbreviation' => $stateProvinceAbbreviation, 'postal_code' => CRM_Utils_Array::value('postal_code', CRM_Utils_Array::value($contribution->contact_id, $billingAddress)), 'is_pay_later' => $contribution->is_pay_later, 'organization_name' => $contribution->_relatedObjects['contact']->organization_name, 'domain_organization' => $domain->name, 'domain_street_address' => CRM_Utils_Array::value('street_address', CRM_Utils_Array::value('1', $locationDefaults['address'])), 'domain_supplemental_address_1' => CRM_Utils_Array::value('supplemental_address_1', CRM_Utils_Array::value('1', $locationDefaults['address'])), 'domain_supplemental_address_2' => CRM_Utils_Array::value('supplemental_address_2', CRM_Utils_Array::value('1', $locationDefaults['address'])), 'domain_city' => CRM_Utils_Array::value('city', CRM_Utils_Array::value('1', $locationDefaults['address'])), 'domain_postal_code' => CRM_Utils_Array::value('postal_code', CRM_Utils_Array::value('1', $locationDefaults['address'])), 'domain_state' => $stateProvinceAbbreviationDomain, 'domain_country' => $countryDomain, 'domain_email' => CRM_Utils_Array::value('email', CRM_Utils_Array::value('1', $locationDefaults['email'])), 'domain_phone' => CRM_Utils_Array::value('phone', CRM_Utils_Array::value('1', $locationDefaults['phone'])));
if (isset($creditNoteId)) {
$tplParams['creditnote_id'] = $creditNoteId;
}
$sendTemplateParams = array('groupName' => 'msg_tpl_workflow_contribution', 'valueName' => 'contribution_invoice_receipt', 'contactId' => $contribution->contact_id, 'tplParams' => $tplParams, 'PDFFilename' => 'Invoice.pdf');
$session = CRM_Core_Session::singleton();
$contactID = $session->get('userID');
//CRM-16319 - we dont store in userID in case the user is doing multiple
//transactions etc
if (empty($contactID)) {
$contactID = $session->get('transaction.userID');
}
$contactEmails = CRM_Core_BAO_Email::allEmails($contactID);
$emails = array();
$fromDisplayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'display_name');
foreach ($contactEmails as $emailId => $item) {
$email = $item['email'];
if ($email) {
$emails[$emailId] = '"' . $fromDisplayName . '" <' . $email . '> ';
}
}
$fromEmail = CRM_Utils_Array::crmArrayMerge($emails, CRM_Core_OptionGroup::values('from_email_address'));
// from email address
if (isset($params['from_email_address'])) {
$fromEmailAddress = CRM_Utils_Array::value($params['from_email_address'], $fromEmail);
}
// condition to check for download PDF Invoice or email Invoice
if ($invoiceElements['createPdf']) {
list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
if (isset($params['forPage'])) {
return $html;
} else {
$mail = array('subject' => $subject, 'body' => $message, 'html' => $html);
if ($mail['html']) {
$messageInvoice[] = $mail['html'];
} else {
$messageInvoice[] = nl2br($mail['body']);
}
}
} elseif ($contribution->_component == 'contribute') {
$email = CRM_Contact_BAO_Contact::getPrimaryEmail($contribution->contact_id);
$sendTemplateParams['tplParams'] = array_merge($tplParams, array('email_comment' => $invoiceElements['params']['email_comment']));
$sendTemplateParams['from'] = $fromEmailAddress;
$sendTemplateParams['toEmail'] = $email;
$sendTemplateParams['cc'] = CRM_Utils_Array::value('cc_receipt', $values);
$sendTemplateParams['bcc'] = CRM_Utils_Array::value('bcc_receipt', $values);
list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
// functions call for adding activity with attachment
$fileName = self::putFile($html);
self::addActivities($subject, $contribution->contact_id, $fileName, $params);
} elseif ($contribution->_component == 'event') {
$email = CRM_Contact_BAO_Contact::getPrimaryEmail($contribution->contact_id);
$sendTemplateParams['tplParams'] = array_merge($tplParams, array('email_comment' => $invoiceElements['params']['email_comment']));
$sendTemplateParams['from'] = $fromEmailAddress;
$sendTemplateParams['toEmail'] = $email;
$sendTemplateParams['cc'] = CRM_Utils_Array::value('cc_confirm', $values);
$sendTemplateParams['bcc'] = CRM_Utils_Array::value('bcc_confirm', $values);
list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
// functions call for adding activity with attachment
$fileName = self::putFile($html);
self::addActivities($subject, $contribution->contact_id, $fileName, $params);
}
CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $contribution->id, 'invoice_id', $invoiceId);
if ($contribution->contribution_status_id == $refundedStatusId) {
CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $contribution->id, 'creditnote_id', $creditNoteId);
}
$invoiceTemplate->clearTemplateVars();
}
if ($invoiceElements['createPdf']) {
if (isset($params['forPage'])) {
return $html;
} else {
CRM_Utils_PDF_Utils::html2pdf($messageInvoice, 'Invoice.pdf', FALSE, array('margin_top' => 10, 'margin_left' => 65, 'metric' => 'px'));
// functions call for adding activity with attachment
$fileName = self::putFile($html);
self::addActivities($subject, $contactIds, $fileName, $params);
CRM_Utils_System::civiExit();
}
} else {
if ($invoiceElements['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 => $invoiceElements['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);
}
}
示例6: renderForm
/**
* render the page using a custom templating
* system
*
* @param object $page the CRM_Core_Form page
* @param boolean $ret should we echo or return output
*
* @return void
* @access public
*/
function renderForm(&$page)
{
$this->_setRenderTemplates($page);
$template = CRM_Core_Smarty::singleton();
$form = $page->toSmarty();
$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;
if ($controller->getEmbedded()) {
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);
// CRM-11831 @see http://www.malsup.com/jquery/form/#file-upload
$xhr = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
if (!$xhr) {
echo '<textarea>';
}
echo json_encode($response);
if (!$xhr) {
echo '</textarea>';
}
CRM_Utils_System::civiExit();
}
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;
}
示例7: LabelSetFormat
/**
* initialize label format settings.
*
* @param $format
* @param $unit
*/
public function LabelSetFormat(&$format, $unit)
{
$this->defaults = CRM_Core_BAO_LabelFormat::getDefaultValues();
$this->format =& $format;
$this->formatName = $this->getFormatValue('name');
$this->paperSize = $this->getFormatValue('paper-size');
$this->orientation = $this->getFormatValue('orientation');
$this->fontName = $this->getFormatValue('font-name');
$this->charSize = $this->getFormatValue('font-size');
$this->fontStyle = $this->getFormatValue('font-style');
$this->xNumber = $this->getFormatValue('NX');
$this->yNumber = $this->getFormatValue('NY');
$this->metricDoc = $unit;
$this->marginLeft = $this->getFormatValue('lMargin', TRUE);
$this->marginTop = $this->getFormatValue('tMargin', TRUE);
$this->xSpace = $this->getFormatValue('SpaceX', TRUE);
$this->ySpace = $this->getFormatValue('SpaceY', TRUE);
$this->width = $this->getFormatValue('width', TRUE);
$this->height = $this->getFormatValue('height', TRUE);
$this->paddingLeft = $this->getFormatValue('lPadding', TRUE);
$this->paddingTop = $this->getFormatValue('tPadding', TRUE);
$paperSize = CRM_Core_BAO_PaperSize::getByName($this->paperSize);
$w = CRM_Utils_PDF_Utils::convertMetric($paperSize['width'], $paperSize['metric'], $this->metricDoc);
$h = CRM_Utils_PDF_Utils::convertMetric($paperSize['height'], $paperSize['metric'], $this->metricDoc);
$this->paper_dimensions = array($w, $h);
}
示例8: 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);
}
}
}
}
}
示例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: postProcess
/**
* process the form after the input has been submitted and validated
*
* @access public
* @return None
*/
public function postProcess()
{
// get all the details needed to generate a receipt
$contribIDs = implode(',', $this->_contributionIds);
require_once 'CRM/Contribute/Form/Task/Status.php';
$details =& CRM_Contribute_Form_Task_Status::getDetails($contribIDs);
require_once 'CRM/Core/Payment/BaseIPN.php';
$baseIPN = new CRM_Core_Payment_BaseIPN();
$message = array();
$template =& CRM_Core_Smarty::singleton();
foreach ($details as $contribID => $detail) {
$input = $ids = $objects = array();
$input['component'] = $detail['component'];
$ids['contact'] = $detail['contact'];
$ids['contribution'] = $contribID;
$ids['contributionRecur'] = null;
$ids['contributionPage'] = null;
$ids['membership'] = $detail['membership'];
$ids['participant'] = $detail['participant'];
$ids['event'] = $detail['event'];
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_Core_Error::debug('input',$input);
$values = array();
$mail = $baseIPN->sendMail($input, $ids, $objects, $values, false, true);
$mail = str_replace("\n\n", "<p>", $mail);
$mail = str_replace("\n", "<br/>", $mail);
$message[] = $mail;
// reset template values before processing next transactions
$template->clearTemplateVars();
}
require_once 'CRM/Utils/PDF/Utils.php';
CRM_Utils_PDF_Utils::domlib($message, "civicrmContributionReceipt.pdf");
exit;
}
示例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: toTwip
/**
* @param $value
* @param $metric
* @return int
*/
public static function toTwip($value, $metric)
{
$point = CRM_Utils_PDF_Utils::convertMetric($value, $metric, 'pt');
return \PhpOffice\PhpWord\Shared\Converter::pointToTwip($point);
}
示例13: 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);
}
}
示例14: 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);
}
示例15: renderForm
/**
* render the page using a custom templating
* system
*
* @param object $page the CRM_Core_Form page
* @param boolean $ret should we echo or return output
*
* @return void
* @access public
*/
function renderForm(&$page, $ret = false)
{
$this->_setRenderTemplates($page);
$template =& CRM_Core_Smarty::singleton();
$template->assign('form', $page->toSmarty());
$template->assign('isForm', 1);
$controller =& $page->controller;
if ($controller->getEmbedded()) {
return;
}
$template->assign('action', $page->getAction());
$template->assign('tplFile', $page->getTemplateFileName());
$content = $template->fetch($controller->getTemplateFile());
$print = $controller->getPrint();
if ($print) {
$html =& $content;
} else {
$html = CRM_Utils_System::theme('page', $content, true, $print, $ret);
}
if ($ret) {
return $html;
}
if ($print) {
if ($print == CRM_Core_Smarty::PRINT_PDF) {
require_once 'CRM/Utils/PDF/Utils.php';
CRM_Utils_PDF_Utils::domlib($content, "{$page->_name}.pdf");
} else {
echo $html;
}
exit;
}
}