/**
  * Process the form submission.
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Core_BAO_MessageTemplate::del($this->_id);
     } elseif ($this->_action & CRM_Core_Action::VIEW) {
         // currently, the above action is used solely for previewing default workflow templates
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=workflow&reset=1'));
     } else {
         $params = array();
         // store the submitted values in an array
         $params = $this->controller->exportValues($this->_name);
         if ($this->_action & CRM_Core_Action::UPDATE) {
             $params['id'] = $this->_id;
         }
         if (!empty($params['file_type'])) {
             unset($params['msg_html']);
             unset($params['msg_text']);
             CRM_Utils_File::formatFile($params, 'file_id');
         } elseif (!empty($this->_id)) {
             $entityFileDAO = new CRM_Core_DAO_EntityFile();
             $entityFileDAO->entity_id = $this->_id;
             $entityFileDAO->entity_table = 'civicrm_msg_template';
             if ($entityFileDAO->find(TRUE)) {
                 $fileDAO = new CRM_Core_DAO_File();
                 $fileDAO->id = $entityFileDAO->file_id;
                 $fileDAO->find(TRUE);
                 $entityFileDAO->delete();
                 $fileDAO->delete();
             }
         }
         if ($this->_workflow_id) {
             $params['workflow_id'] = $this->_workflow_id;
             $params['is_active'] = TRUE;
         }
         $messageTemplate = CRM_Core_BAO_MessageTemplate::add($params);
         CRM_Core_Session::setStatus(ts('The Message Template \'%1\' has been saved.', array(1 => $messageTemplate->msg_title)), ts('Saved'), 'success');
         if ($this->_workflow_id) {
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=workflow&reset=1'));
         } else {
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=user&reset=1'));
         }
     }
 }
Exemple #2
0
 /**
  * @param $formValues
  * @param array $params
  * @param $entityTable
  * @param int $entityID
  */
 public static function formatAttachment(&$formValues, &$params, $entityTable, $entityID = NULL)
 {
     // delete current attachments if applicable
     if ($entityID && !empty($formValues['is_delete_attachment'])) {
         CRM_Core_BAO_File::deleteEntityFile($entityTable, $entityID);
     }
     $numAttachments = Civi::settings()->get('max_attachments');
     // setup all attachments
     for ($i = 1; $i <= $numAttachments; $i++) {
         $attachName = "attachFile_{$i}";
         $attachDesc = "attachDesc_{$i}";
         $attachTags = "tag_{$i}";
         $attachFreeTags = "file_taglist_{$i}";
         if (isset($formValues[$attachName]) && !empty($formValues[$attachName])) {
             // add static tags if selects
             $tagParams = array();
             if (!empty($formValues[$attachTags])) {
                 foreach ($formValues[$attachTags] as $tag) {
                     $tagParams[$tag] = 1;
                 }
             }
             // we dont care if the file is empty or not
             // CRM-7448
             $extraParams = array('description' => $formValues[$attachDesc], 'tag' => $tagParams, 'attachment_taglist' => CRM_Utils_Array::value($attachFreeTags, $formValues, array()));
             CRM_Utils_File::formatFile($formValues, $attachName, $extraParams);
             // set the formatted attachment attributes to $params, later used by
             // CRM_Activity_BAO_Activity::sendEmail(...) to send mail with desired attachments
             if (!empty($formValues[$attachName])) {
                 $params[$attachName] = $formValues[$attachName];
             }
         }
     }
 }