// which (and whether) mailing workflow this template belongs to
protected $_workflow_id = NULL;
- // document ID set during loading default values and later used in formRule
- protected $_document_id = NULL;
+ // Is document file is already loaded as default value?
+ protected $_is_document = FALSE;
public function preProcess() {
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
if (empty($defaults['pdf_format_id'])) {
$defaults['pdf_format_id'] = 'null';
}
+ if (empty($defaults['file_type'])) {
+ $defaults['file_type'] = 0;
+ }
$this->_workflow_id = CRM_Utils_Array::value('workflow_id', $defaults);
$this->assign('workflow_id', $this->_workflow_id);
$documentInfo = CRM_Core_BAO_File::getEntityFile('civicrm_msg_template', $this->_id, TRUE);
if (!empty($documentInfo)) {
- foreach ($documentInfo as &$info) {
- $defaults['file_type'] = array_search($info['mime_type'], CRM_Core_SelectValues::documentApplicationType());
- $info['mime_type'] = $defaults['file_type'];
- $this->_document_id = $info['fileID'];
- }
+ $defaults['file_type'] = 1;
+ $this->_is_document = TRUE;
$this->assign('attachment', $documentInfo);
}
$this->applyFilter('__ALL__', 'trim');
$this->add('text', 'msg_title', ts('Message Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_MessageTemplate', 'msg_title'), TRUE);
- $this->add('select', 'file_type', ts('File Type'), CRM_Core_SelectValues::documentFormat());
+ $options = array(ts('Compose On-screen'), ts('Upload Document'));
+ $this->addRadio('file_type', ts('Source'), $options);
+
$this->addElement('file', "file_id", ts('Upload Document'), 'size=30 maxlength=60');
$this->addUploadElement("file_id");
$errors = array();
//empty file upload validation for odt/docx template
- if (empty($files['file_id']['tmp_name']) && in_array($params['file_type'], array('odt', 'docx'))) {
+ if (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
- if (!empty($self->_document_id)) {
- $fileDAO = new CRM_Core_DAO_File();
- $fileDAO->id = $self->_document_id;
- if ($fileDAO->find(TRUE) &&
- $fileDAO->mime_type != CRM_Utils_Array::value($params['file_type'], CRM_Core_SelectValues::documentApplicationType())
- ) {
- $errors['file_id'] = ts('Please upload document');
- }
- }
- else {
- $errors['file_id'] = ts('Please upload document');
- }
-
+ $errors['file_id'] = ts('Please upload document');
}
return $errors;
$params['id'] = $this->_id;
}
- if (in_array($params['file_type'], array('odt', 'docx'))) {
+ if (!empty($params['file_type'])) {
unset($params['msg_html']);
unset($params['msg_text']);
CRM_Utils_File::formatFile($params, 'file_id');
ALTER TABLE civicrm_pledge_block ADD is_pledge_start_date_visible TINYINT(4) NOT NULL DEFAULT 0 COMMENT 'If true - recurring start date is shown.';
ALTER TABLE civicrm_pledge_block ADD is_pledge_start_date_editable TINYINT(4) NOT NULL DEFAULT 0 COMMENT 'If true - recurring start date is editable.';
ALTER TABLE civicrm_contribution_page ADD adjust_recur_start_date TINYINT(4) NOT NULL DEFAULT 0 COMMENT 'If true - user is able to adjust payment start date.' AFTER is_recur_installments;
+
+-- CRM-17608 Merge to DOCx or ODT template
+SELECT @option_group_id_ext := max(id) from civicrm_option_group where name = 'safe_file_extension';
+SELECT @option_group_id_ext_wt := MAX(weight) FROM civicrm_option_value WHERE option_group_id = @option_group_id_ext;
+SELECT @option_group_id_ext_val := MAX(CAST( `value` AS UNSIGNED )) FROM civicrm_option_value WHERE option_group_id = @option_group_id_ext;
+INSERT INTO
+ `civicrm_option_value` (`option_group_id`, {localize field='label'}label{/localize}, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `is_optgroup`, `is_reserved`, `is_active`)
+VALUES
+ (@option_group_id_ext, {localize}'{ts escape="sql"}odt{/ts}'{/localize}, @option_group_id_ext_val+1, 'odt', NULL, 0, 0, @option_group_id_ext_wt+1, 0, 1, 1);
{localize field="description"}description = '{ts escape="sql"}Export letters and other printable documents.{/ts}'{/localize}
WHERE name = 'Print PDF Letter' AND option_group_id = @option_group_id_act;
--- CRM-17608 Merge to DOCx or ODT template
-SELECT @option_group_id_ext := max(id) from civicrm_option_group where name = 'safe_file_extension';
-SELECT @option_group_id_ext_wt := MAX(weight) FROM civicrm_option_value WHERE option_group_id = @option_group_id_ext;
-SELECT @option_group_id_ext_val := MAX(CAST( `value` AS UNSIGNED )) FROM civicrm_option_value WHERE option_group_id = @option_group_id_ext;
-INSERT INTO
- `civicrm_option_value` (`option_group_id`, {localize field='label'}label{/localize}, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `is_optgroup`, `is_reserved`, `is_active`)
-VALUES
-(@option_group_id_ext, {localize}'{ts escape="sql"}odt{/ts}'{/localize}, @option_group_id_ext_val+1, 'odt', NULL, 0, 0, @option_group_id_ext_wt+1, 0, 1, 1);
-
-- CRM-18699 Fix Wake Island misspelling, was Wake Ialand
UPDATE civicrm_state_province SET name="Wake Island" WHERE name="Wake Ialand";
mimeType = $('a.delete-attachment').data('mimetype');
}
- $('#file_type').on('change', function(){
- toggleByFileType(this.value);
+ showHideUpload($("input[id$='_file_type']:checked").val());
+ $("input[id$='_file_type']").on('click', function(){
+ showHideUpload(this.value);
});
- toggleByFileType($('#file_type').val());
-
- function toggleByFileType(type) {
- var show = (type == 'odt' || type == 'docx') ? false : true;
+ function showHideUpload(type) {
+ var show = (type == 1) ? false : true;
$("#msg_html").toggle(show);
$("#msg_text, #pdf_format").toggle(show);
$("#file_id").parent().parent().toggle(!show);
// auto file type validation
- if (!show) {
- var validType = (type == 'odt') ? 'application/vnd.oasis.opendocument.text' : 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
+ if (type) {
+ var validType = 'application/vnd.oasis.opendocument.text, application/vnd.openxmlformats-officedocument.wordprocessingml.document';
$("#file_id").attr('accept', validType);
}
-
- // when you change file type other than the type of default uploaded document
- if (mimeType) {
- var hide = (mimeType != type) ? true : false;
- $("#file_id").toggle(hide);
- $('.crm-attachment-wrapper').toggle(!hide);
- }
}
});
</script>