$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',
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']}";
$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'])) {
*/
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;
<td class="label-left">{$form.template.label}</td>
<td>{$form.template.html}</td>
</tr>
+ <tr>
+ <td> <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>
{$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 -->
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}
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;
}