From: deb.monish Date: Thu, 21 Jul 2016 14:06:19 +0000 (+0530) Subject: CRM-17608: add formRule validation for invalid document file X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=100e363e81553bd0b32de3cbdff5088ce00f2bb8;p=civicrm-core.git CRM-17608: add formRule validation for invalid document file --- diff --git a/CRM/Admin/Form/MessageTemplates.php b/CRM/Admin/Form/MessageTemplates.php index 36d845bf99..e269bd6d10 100644 --- a/CRM/Admin/Form/MessageTemplates.php +++ b/CRM/Admin/Form/MessageTemplates.php @@ -245,8 +245,14 @@ class CRM_Admin_Form_MessageTemplates extends CRM_Admin_Form { public static function formRule($params, $files, $self) { $errors = array(); - //empty file upload validation for odt/docx template - if (empty($files['file_id']['tmp_name']) && !empty($params['file_type']) && !$self->_is_document) { + // If user uploads non-document file other than odt/docx + if (!empty($files['file_id']['tmp_name']) && + array_search($files['file_id']['type'], CRM_Core_SelectValues::documentApplicationType()) == NULL + ) { + $error['file_id'] = ts('Invalid document file format'); + } + // If default is not set and no document file is uploaded + elseif (empty($files['file_id']['tmp_name']) && !empty($params['file_type']) && !$self->_is_document) { //On edit page of docx/odt message template if user changes file type but forgot to upload document $errors['file_id'] = ts('Please upload document'); } diff --git a/CRM/Contact/Form/Task/PDFLetterCommon.php b/CRM/Contact/Form/Task/PDFLetterCommon.php index 4a4677f2d6..214afdbad5 100644 --- a/CRM/Contact/Form/Task/PDFLetterCommon.php +++ b/CRM/Contact/Form/Task/PDFLetterCommon.php @@ -214,17 +214,24 @@ class CRM_Contact_Form_Task_PDFLetterCommon { * * @param array $fields * The input form values. - * @param array $dontCare + * @param array $files * @param array $self * Additional values form 'this'. * * @return bool * TRUE if no errors, else array of errors. */ - public static function formRule($fields, $dontCare, $self) { + public static function formRule($fields, $files, $self) { $errors = array(); $template = CRM_Core_Smarty::singleton(); + // If user uploads non-document file other than odt/docx + if (empty($fields['template']) && + !empty($files['document_file']['tmp_name']) && + array_search($files['document_file']['type'], CRM_Core_SelectValues::documentApplicationType()) == NULL + ) { + $errors['document_file'] = ts('Invalid document file format'); + } //Added for CRM-1393 if (!empty($fields['saveTemplate']) && empty($fields['saveTemplateName'])) { $errors['saveTemplateName'] = ts("Enter name to save message template"); diff --git a/templates/CRM/Admin/Form/MessageTemplates.tpl b/templates/CRM/Admin/Form/MessageTemplates.tpl index 69587aacae..c204294327 100644 --- a/templates/CRM/Admin/Form/MessageTemplates.tpl +++ b/templates/CRM/Admin/Form/MessageTemplates.tpl @@ -158,7 +158,8 @@ mimeType = $('a.delete-attachment').data('mimetype'); } - showHideUpload($("input[id$='_file_type']").val()); + var selector = $("input[id$='_file_type']").attr('type') == 'radio' ? "input[id$='_file_type']:checked" : "input[id$='_file_type']"; + showHideUpload($(selector).val()); $("input[id$='_file_type']").on('click', function(){ showHideUpload(this.value); });