From 8d63890ed73809eccf63a8d3cff3d4e49e07e26f Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Fri, 3 Jun 2016 20:29:44 +0530 Subject: [PATCH] added document upload element --- CRM/Contact/Form/Task/PDFLetterCommon.php | 13 ++++++++++--- CRM/Utils/PDF/Document.php | 3 ++- .../CRM/Contact/Form/Task/PDFLetterCommon.tpl | 17 +++++++++++++++-- templates/CRM/Mailing/Form/InsertTokens.tpl | 7 ++++++- 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/CRM/Contact/Form/Task/PDFLetterCommon.php b/CRM/Contact/Form/Task/PDFLetterCommon.php index 667b4f3aa3..3811d97543 100644 --- a/CRM/Contact/Form/Task/PDFLetterCommon.php +++ b/CRM/Contact/Form/Task/PDFLetterCommon.php @@ -169,12 +169,16 @@ class CRM_Contact_Form_Task_PDFLetterCommon { $form->add('select', 'document_type', ts('Document Type'), CRM_Core_SelectValues::documentFormat()); + $documentTypes = implode(',', CRM_Core_SelectValues::documentApplicationType()); + $form->addElement('file', "document_file", 'Upload Document', 'size=30 maxlength=60 accept="' . $documentTypes . '"'); + $form->addUploadElement("document_file"); + CRM_Mailing_BAO_Mailing::commonCompose($form); $buttons = array(); if ($form->get('action') != CRM_Core_Action::VIEW) { $buttons[] = array( - 'type' => 'submit', + 'type' => 'upload', 'name' => ts('Download Document'), 'isDefault' => TRUE, 'icon' => 'fa-download', @@ -279,6 +283,10 @@ class CRM_Contact_Form_Task_PDFLetterCommon { CRM_Core_BAO_MessageTemplate::add($messageTemplate); } } + // extract the content of uploaded document file + elseif (!empty($formValues['document_file'])) { + $html_message = CRM_Utils_PDF_Document::docReader($formValues['document_file']['name'], $formValues['document_file']['type'], TRUE); + } elseif (CRM_Utils_Array::value('template', $formValues) > 0) { if (!empty($formValues['bind_format']) && $formValues['format_id']) { $query = "UPDATE civicrm_msg_template SET pdf_format_id = {$formValues['format_id']} WHERE id = {$formValues['template']}"; @@ -290,8 +298,7 @@ class CRM_Contact_Form_Task_PDFLetterCommon { $documentInfo = CRM_Core_BAO_File::getEntityFile('civicrm_msg_template', $formValues['template']); foreach ((array) $documentInfo as $info) { - $docType = array_search($info['mime_type'], CRM_Core_SelectValues::documentApplicationType()); - $html_message = CRM_Utils_PDF_Document::docReader($info['fullPath'], $docType, TRUE); + $html_message = CRM_Utils_PDF_Document::docReader($info['fullPath'], $info['mime_type'], TRUE); } } if (!empty($formValues['update_format'])) { diff --git a/CRM/Utils/PDF/Document.php b/CRM/Utils/PDF/Document.php index 3fc6d9c701..51432213d1 100644 --- a/CRM/Utils/PDF/Document.php +++ b/CRM/Utils/PDF/Document.php @@ -129,9 +129,10 @@ class CRM_Utils_PDF_Document { */ public static function doc2Text($filePath, $type) { $content = ''; + $docType = array_search($type, CRM_Core_SelectValues::documentApplicationType()); + $dataFile = ($docType == 'docx') ? "word/document.xml" : "content.xml"; $zip = zip_open($filePath); - $dataFile = ($type == 'docx') ? "word/document.xml" : "content.xml"; if (!$zip || is_numeric($zip)) { return $content; diff --git a/templates/CRM/Contact/Form/Task/PDFLetterCommon.tpl b/templates/CRM/Contact/Form/Task/PDFLetterCommon.tpl index f7560b2fe5..47eba65686 100644 --- a/templates/CRM/Contact/Form/Task/PDFLetterCommon.tpl +++ b/templates/CRM/Contact/Form/Task/PDFLetterCommon.tpl @@ -30,6 +30,13 @@ {$form.template.label} {$form.template.html} + +         OR + + + {$form.document_file.label} + {$form.document_file.html}

+ {$form.subject.label} {$form.subject.html} @@ -90,7 +97,7 @@ {$form.html_message.label}
-
+
@@ -140,7 +147,13 @@ CRM.$(function($) { var $form = $('form.{/literal}{$form.formClass}{literal}'); {/literal}{if $form.formName eq 'PDF'}{literal} - cj('.crm-document-accordion').hide(); + $('.crm-document-accordion').hide(); + $('#document_file').on('change', function() { + if (this.value) { + $('.crm-html_email-accordion, .crm-document-accordion').toggle(false); + $('#template').val(''); + } + }); {/literal}{/if}{literal} diff --git a/templates/CRM/Mailing/Form/InsertTokens.tpl b/templates/CRM/Mailing/Form/InsertTokens.tpl index a5252b8480..bbecb1f6fb 100644 --- a/templates/CRM/Mailing/Form/InsertTokens.tpl +++ b/templates/CRM/Mailing/Form/InsertTokens.tpl @@ -143,10 +143,15 @@ function selectValue( val, prefix) { cj('.crm-html_email-accordion').toggle(hide); cj('.crm-document-accordion').toggle(!hide); + // Unset any uploaded document when any template is chosen + if (cj('#document.file').length) { + cj('#document_file').val(''); + } + if (!hide) { cj("#document_type").val( data.file_type ); cj("#subject").val( data.subject ); - document.getElementById("document").innerHTML=''; + document.getElementById("document-preview").innerHTML=''; return; } -- 2.25.1