added document upload element
authordeb.monish <monish.deb@webaccessglobal.com>
Fri, 3 Jun 2016 14:59:44 +0000 (20:29 +0530)
committerdeb.monish <monish.deb@webaccessglobal.com>
Thu, 14 Jul 2016 18:05:43 +0000 (23:35 +0530)
CRM/Contact/Form/Task/PDFLetterCommon.php
CRM/Utils/PDF/Document.php
templates/CRM/Contact/Form/Task/PDFLetterCommon.tpl
templates/CRM/Mailing/Form/InsertTokens.tpl

index 667b4f3aa3cc33e034920fec4607cafe58f428b6..3811d97543d372263db16d1c6ec00f96305ce228 100644 (file)
@@ -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'])) {
index 3fc6d9c701f9f275f58bec6d6ee8909d9c430de6..51432213d17c2bd58faa358eb32a73cb3e82debb 100644 (file)
@@ -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;
index f7560b2fe5ac2bf27ac22a5fce0dcaec8d2b5b78..47eba656866ea59fd3792b333c6be92896e6ce61 100644 (file)
       <td class="label-left">{$form.template.label}</td>
       <td>{$form.template.html}</td>
     </tr>
+    <tr>
+      <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<sub>OR</sub></td>
+    </tr>
+    <tr>
+      <td class="label-left">{$form.document_file.label}</td>
+      <td>{$form.document_file.html}<br/><br/></td>
+    </tr>
     <tr>
       <td class="label-left">{$form.subject.label}</td>
       <td>{$form.subject.html}</td>
@@ -90,7 +97,7 @@
     {$form.html_message.label}
   </div><!-- /.crm-accordion-header -->
   <div class="crm-accordion-body">
-    <div id='document'></div>
+    <div id='document-preview'></div>
   </div><!-- /.crm-accordion-body -->
 </div><!-- /.crm-accordion-wrapper -->
 
@@ -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}
 
 
index a5252b848026710f6736adee5c022908d881c8a0..bbecb1f6fb69c28c53bc0993a9a8a077017dfe85 100644 (file)
@@ -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='<object type="text/html" data='+ data.document_path +' width="680" height="400" style="background:white;"></object>';
+      document.getElementById("document-preview").innerHTML='<object type="text/html" data='+ data.document_path +' width="680" height="400" style="background:white;"></object>';
       return;
     }