Example #1
0
 public function postProcess()
 {
     $params = $ids = array();
     $uploadParams = array('header_id', 'footer_id', 'subject', 'from_name', 'from_email');
     $fileType = array('textFile', 'htmlFile');
     $formValues = $this->controller->exportValues($this->_name);
     foreach ($uploadParams as $key) {
         if (!empty($formValues[$key]) || in_array($key, array('header_id', 'footer_id'))) {
             $params[$key] = $formValues[$key];
             $this->set($key, $formValues[$key]);
         }
     }
     if (!$formValues['upload_type']) {
         foreach ($fileType as $key) {
             $contents = NULL;
             if (isset($formValues[$key]) && !empty($formValues[$key])) {
                 $contents = file_get_contents($formValues[$key]['name']);
                 $this->set($key, $formValues[$key]['name']);
             }
             if ($contents) {
                 $params['body_' . substr($key, 0, 4)] = $contents;
             } else {
                 $params['body_' . substr($key, 0, 4)] = 'NULL';
             }
         }
     } else {
         $text_message = $formValues['text_message'];
         $params['body_text'] = $text_message;
         $this->set('textFile', $params['body_text']);
         $this->set('text_message', $params['body_text']);
         $html_message = $formValues['html_message'];
         // dojo editor does some html conversion when tokens are
         // inserted as links. Hence token replacement fails.
         // this is hack to revert html conversion for { to %7B and
         // } to %7D by dojo editor
         $html_message = str_replace('%7B', '{', str_replace('%7D', '}', $html_message));
         $params['body_html'] = $html_message;
         $this->set('htmlFile', $params['body_html']);
         $this->set('html_message', $params['body_html']);
     }
     $params['name'] = $this->get('name');
     $session = CRM_Core_Session::singleton();
     $params['contact_id'] = $session->get('userID');
     $composeFields = array('template', 'saveTemplate', 'updateTemplate', 'saveTemplateName');
     $msgTemplate = NULL;
     //mail template is composed
     if ($formValues['upload_type']) {
         $composeParams = array();
         foreach ($composeFields as $key) {
             if (!empty($formValues[$key])) {
                 $composeParams[$key] = $formValues[$key];
                 $this->set($key, $formValues[$key]);
             }
         }
         if (!empty($composeParams['updateTemplate'])) {
             $templateParams = array('msg_text' => $text_message, 'msg_html' => $html_message, 'msg_subject' => $params['subject'], 'is_active' => TRUE);
             $templateParams['id'] = $formValues['template'];
             $msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams);
         }
         if (!empty($composeParams['saveTemplate'])) {
             $templateParams = array('msg_text' => $text_message, 'msg_html' => $html_message, 'msg_subject' => $params['subject'], 'is_active' => TRUE);
             $templateParams['msg_title'] = $composeParams['saveTemplateName'];
             $msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams);
         }
         if (isset($msgTemplate->id)) {
             $params['msg_template_id'] = $msgTemplate->id;
         } else {
             $params['msg_template_id'] = CRM_Utils_Array::value('template', $formValues);
         }
         $this->set('template', $params['msg_template_id']);
     }
     CRM_Core_BAO_File::formatAttachment($formValues, $params, 'civicrm_mailing', $this->_mailingID);
     $ids['mailing_id'] = $this->_mailingID;
     //handle mailing from name & address.
     $fromEmailAddress = CRM_Utils_Array::value($formValues['from_email_address'], CRM_Core_OptionGroup::values('from_email_address'));
     //get the from email address
     $params['from_email'] = CRM_Utils_Mail::pluckEmailFromHeader($fromEmailAddress);
     //get the from Name
     $params['from_name'] = CRM_Utils_Array::value(1, explode('"', $fromEmailAddress));
     //Add Reply-To to headers
     if (!empty($formValues['reply_to_address'])) {
         $replyToEmail = CRM_Core_OptionGroup::values('from_email_address');
         $params['replyto_email'] = CRM_Utils_Array::value($formValues['reply_to_address'], $replyToEmail);
     }
     /* Build the mailing object */
     CRM_Mailing_BAO_Mailing::create($params, $ids);
     if (isset($this->_submitValues['_qf_Upload_upload_save']) && $this->_submitValues['_qf_Upload_upload_save'] == 'Save & Continue Later') {
         //when user perform mailing from search context
         //redirect it to search result CRM-3711.
         $ssID = $this->get('ssID');
         if ($ssID && $this->_searchBasedMailing) {
             if ($this->_action == CRM_Core_Action::BASIC) {
                 $fragment = 'search';
             } elseif ($this->_action == CRM_Core_Action::PROFILE) {
                 $fragment = 'search/builder';
             } elseif ($this->_action == CRM_Core_Action::ADVANCED) {
                 $fragment = 'search/advanced';
             } else {
                 $fragment = 'search/custom';
             }
             $context = $this->get('context');
             if (!CRM_Contact_Form_Search::isSearchContext($context)) {
                 $context = 'search';
             }
             $urlParams = "force=1&reset=1&ssID={$ssID}&context={$context}";
             $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
             if (CRM_Utils_Rule::qfKey($qfKey)) {
                 $urlParams .= "&qfKey={$qfKey}";
             }
             $session = CRM_Core_Session::singleton();
             $draftURL = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
             $status = ts("You can continue later by clicking the 'Continue' action to resume working on it.<br />From <a href='%1'>Draft and Unscheduled Mailings</a>.", array(1 => $draftURL));
             CRM_Core_Session::setStatus($status, ts('Mailing Saved'), 'success');
             // Redirect user to search.
             $url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $urlParams);
         } else {
             $status = ts("Click the 'Continue' action to resume working on it.");
             $url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
         }
         CRM_Core_Session::setStatus($status, ts('Mailing Saved'), 'success');
         return $this->controller->setDestination($url);
     }
 }
Example #2
0
 function setDefaultValues()
 {
     require_once 'CRM/Core/BAO/Domain.php';
     $defaults = array();
     $params = array();
     $locParams = array();
     if (isset($this->_id)) {
         $params['id'] = $this->_id;
         CRM_Core_BAO_Domain::retrieve($params, $domainDefaults);
         //get the default domain from email address. fix CRM-3552
         require_once 'CRM/Utils/Mail.php';
         require_once 'CRM/Core/OptionValue.php';
         $optionValues = array();
         $grpParams['name'] = 'from_email_address';
         CRM_Core_OptionValue::getValues($grpParams, $optionValues);
         foreach ($optionValues as $Id => $value) {
             if ($value['is_default'] && $value['is_active']) {
                 $this->_fromEmailId = $Id;
                 $domainDefaults['email_name'] = CRM_Utils_Array::value(1, explode('"', $value['label']));
                 $domainDefaults['email_address'] = CRM_Utils_Mail::pluckEmailFromHeader($value['label']);
                 break;
             }
         }
         unset($params['id']);
         $locParams = $params + array('entity_id' => $this->_id, 'entity_table' => 'civicrm_domain');
         require_once 'CRM/Core/BAO/Location.php';
         $defaults = CRM_Core_BAO_Location::getValues($locParams);
         $config = CRM_Core_Config::singleton();
         if (!isset($defaults['address'][1]['country_id'])) {
             $defaults['address'][1]['country_id'] = $config->defaultContactCountry;
         }
         if (!empty($defaults['address'])) {
             foreach ($defaults['address'] as $key => $value) {
                 CRM_Contact_Form_Edit_Address::fixStateSelect($this, "address[{$key}][country_id]", "address[{$key}][state_province_id]", CRM_Utils_Array::value('country_id', $value, $config->defaultContactCountry));
             }
         }
     }
     $defaults = array_merge($defaults, $domainDefaults);
     return $defaults;
 }
Example #3
0
 /**
  * Global form rule.
  *
  * @param array $fields
  *   The input form values.
  * @param array $files
  *   The uploaded files if any.
  * @param array $self
  *   Current form object.
  *
  * @return array
  *   array of errors / empty array.
  */
 public static function formRule($fields, $files, $self)
 {
     $errors = array();
     if ($self->_gName == 'case_status' && empty($fields['grouping'])) {
         $errors['grouping'] = ts('Status class is a required field');
     }
     if (in_array($self->_gName, array('email_greeting', 'postal_greeting', 'addressee')) && empty($self->_defaultValues['is_reserved'])) {
         $label = $fields['label'];
         $condition = " AND v.label = '{$label}' ";
         $values = CRM_Core_OptionGroup::values($self->_gName, FALSE, FALSE, FALSE, $condition, 'filter');
         $checkContactOptions = TRUE;
         if ($self->_id && $self->_defaultValues['contactOptions'] == $fields['contactOptions']) {
             $checkContactOptions = FALSE;
         }
         if ($checkContactOptions && in_array($fields['contactOptions'], $values)) {
             $errors['label'] = ts('This Label already exists in the database for the selected contact type.');
         }
     }
     if ($self->_gName == 'from_email_address') {
         $formEmail = CRM_Utils_Mail::pluckEmailFromHeader($fields['label']);
         if (!CRM_Utils_Rule::email($formEmail)) {
             $errors['label'] = ts('Please enter a valid email address.');
         }
         $formName = explode('"', $fields['label']);
         if (empty($formName[1]) || count($formName) != 3) {
             $errors['label'] = ts('Please follow the proper format for From Email Address');
         }
     }
     $dataType = self::getOptionGroupDataType($self->_gName);
     if ($dataType && $self->_gName !== 'activity_type') {
         $validate = CRM_Utils_Type::validate($fields['value'], $dataType, FALSE);
         if (!$validate) {
             CRM_Core_Session::setStatus(ts('Data Type of the value field for this option value does not match ' . $dataType), ts('Value field Data Type mismatch'));
         }
     }
     return $errors;
 }
 function updateTemplateOptions()
 {
     // Update the templates and upload options
     $params = $ids = array();
     $uploadParams = array('header_id', 'footer_id', 'subject', 'from_name', 'from_email');
     $fileType = array('textFile', 'htmlFile');
     $formValues = $this->controller->exportValues($this->_name);
     foreach ($uploadParams as $key) {
         if (CRM_Utils_Array::value($key, $formValues) || in_array($key, array('header_id', 'footer_id'))) {
             $params[$key] = $formValues[$key];
             $this->set($key, $formValues[$key]);
         }
     }
     $text_message = $formValues['text_message'];
     $params['body_text'] = $text_message;
     $this->set('textFile', $params['body_text']);
     $this->set('text_message', $params['body_text']);
     $html_message = $formValues['html_message'];
     // dojo editor does some html conversion when tokens are
     // inserted as links. Hence token replacement fails.
     // this is hack to revert html conversion for { to %7B and
     // } to %7D by dojo editor
     $html_message = str_replace('%7B', '{', str_replace('%7D', '}', $html_message));
     $params['body_html'] = $html_message;
     $this->set('htmlFile', $params['body_html']);
     $this->set('html_message', $params['body_html']);
     $params['name'] = $this->get('name');
     $session = CRM_Core_Session::singleton();
     $params['contact_id'] = $session->get('userID');
     $composeFields = array('template', 'saveTemplate', 'updateTemplate', 'saveTemplateName');
     CRM_Core_BAO_File::formatAttachment($formValues, $params, 'civicrm_mailing', $this->get('mailing_id'));
     $ids['mailing_id'] = $this->get('mailing_id');
     //set msg_template_id
     $params['msg_template_id'] = CRM_Utils_Array::value('template', $formValues);
     $this->set('template', $params['msg_template_id']);
     //handle mailing from name & address.
     $fromEmailAddress = CRM_Utils_Array::value($formValues['from_email_address'], CRM_Core_OptionGroup::values('from_email_address'));
     //get the from email address
     $params['from_email'] = CRM_Utils_Mail::pluckEmailFromHeader($fromEmailAddress);
     //get the from Name
     $params['from_name'] = CRM_Utils_Array::value(1, explode('"', $fromEmailAddress));
     //Add Reply-To to headers
     if (CRM_Utils_Array::value('reply_to_address', $formValues)) {
         $replyToEmail = CRM_Core_OptionGroup::values('from_email_address');
         $params['replyto_email'] = CRM_Utils_Array::value($formValues['reply_to_address'], $replyToEmail);
     }
     /* Build the mailing object */
     CRM_Mailing_BAO_Mailing::create($params, $ids);
 }
Example #5
0
 static function getNameAndEmail()
 {
     require_once 'CRM/Core/OptionGroup.php';
     $fromEmailAddress = CRM_Core_OptionGroup::values('from_email_address', null, null, null, ' AND is_default = 1');
     if (!empty($fromEmailAddress)) {
         require_once 'CRM/Utils/Mail.php';
         foreach ($fromEmailAddress as $key => $value) {
             $email = CRM_Utils_Mail::pluckEmailFromHeader($value);
             $fromName = CRM_Utils_Array::value(1, explode('"', $value));
             break;
         }
         return array($fromName, $email);
     }
     $url = CRM_Utils_System::url('civicrm/contact/domain', 'action=update&reset=1');
     $status = ts("There is no valid default from email address configured for the domain. You can configure here <a href='%1'>Configure From Email Address.</a>", array(1 => $url));
     CRM_Core_Error::fatal($status);
 }
Example #6
0
 /**
  * This virtual function is used to set the default values of.
  * various form elements
  *
  * @return array
  *   reference to the array of default values
  *
  */
 public function setDefaultValues()
 {
     $defaults = array();
     $params = array();
     if (isset($this->_id)) {
         $params['id'] = $this->_id;
         CRM_Core_BAO_Domain::retrieve($params, $domainDefaults);
         $this->_contactId = $domainDefaults['contact_id'];
         //get the default domain from email address. fix CRM-3552
         $optionValues = array();
         $grpParams['name'] = 'from_email_address';
         CRM_Core_OptionValue::getValues($grpParams, $optionValues);
         foreach ($optionValues as $Id => $value) {
             if ($value['is_default'] && $value['is_active']) {
                 $this->_fromEmailId = $Id;
                 $list = explode('"', $value['label']);
                 $domainDefaults['email_name'] = CRM_Utils_Array::value(1, $list);
                 $domainDefaults['email_address'] = CRM_Utils_Mail::pluckEmailFromHeader($value['label']);
                 break;
             }
         }
         unset($params['id']);
         $locParams = array('contact_id' => $domainDefaults['contact_id']);
         $this->_locationDefaults = $defaults = CRM_Core_BAO_Location::getValues($locParams);
         $config = CRM_Core_Config::singleton();
         if (!isset($defaults['address'][1]['country_id'])) {
             $defaults['address'][1]['country_id'] = $config->defaultContactCountry;
         }
         if (!isset($defaults['address'][1]['state_province_id'])) {
             $defaults['address'][1]['state_province_id'] = $config->defaultContactStateProvince;
         }
     }
     $defaults = array_merge($defaults, $domainDefaults);
     return $defaults;
 }
 static function getNameAndEmail($skipFatal = FALSE)
 {
     $fromEmailAddress = CRM_Core_OptionGroup::values('from_email_address', NULL, NULL, NULL, ' AND is_default = 1');
     if (!empty($fromEmailAddress)) {
         foreach ($fromEmailAddress as $key => $value) {
             $email = CRM_Utils_Mail::pluckEmailFromHeader($value);
             $fromArray = explode('"', $value);
             $fromName = CRM_Utils_Array::value(1, $fromArray);
             break;
         }
         return array($fromName, $email);
     } elseif ($skipFatal) {
         return array('', '');
     }
     $url = CRM_Utils_System::url('civicrm/admin/domain', 'action=update&reset=1');
     $status = ts("There is no valid default from email address configured for the domain. You can configure here <a href='%1'>Configure From Email Address.</a>", array(1 => $url));
     CRM_Core_Error::fatal($status);
 }
Example #8
0
 /**  
  * global form rule  
  *  
  * @param array $fields the input form values  
  * @param array $files  the uploaded files if any  
  * @param array $self   current form object. 
  *  
  * @return array array of errors / empty array.   
  * @access public  
  * @static  
  */
 static function formRule(&$fields, &$files, $self)
 {
     $errors = array();
     if ($self->_gName == 'from_email_address') {
         require_once 'CRM/Utils/Mail.php';
         $formEmail = CRM_Utils_Mail::pluckEmailFromHeader($fields['label']);
         if (!CRM_Utils_Rule::email($formEmail)) {
             $errors['label'] = ts('Please enter the valid email address.');
         }
         $formName = explode('"', $fields['label']);
         if (!CRM_Utils_Array::value(1, $formName) || count($formName) != 3) {
             $errors['label'] = ts('Please follow the proper format for From Email Address');
         }
     }
     return $errors;
 }
Example #9
0
 public function postProcess()
 {
     $params = $ids = array();
     $uploadParams = array('header_id', 'footer_id', 'subject', 'from_name', 'from_email', 'override_verp');
     $fileType = array('textFile', 'htmlFile');
     $formValues = $this->controller->exportValues($this->_name);
     foreach ($uploadParams as $key) {
         if (CRM_Utils_Array::value($key, $formValues) || in_array($key, array('header_id', 'footer_id'))) {
             $params[$key] = $formValues[$key];
             $this->set($key, $formValues[$key]);
         }
     }
     if (!$formValues['upload_type']) {
         foreach ($fileType as $key) {
             $contents = null;
             if (isset($formValues[$key]) && !empty($formValues[$key])) {
                 $contents = file_get_contents($formValues[$key]['name']);
                 $this->set($key, $formValues[$key]['name']);
             }
             if ($contents) {
                 $params['body_' . substr($key, 0, 4)] = $contents;
             } else {
                 $params['body_' . substr($key, 0, 4)] = 'NULL';
             }
         }
     } else {
         $text_message = $formValues['text_message'];
         $params['body_text'] = $text_message;
         $this->set('textFile', $params['body_text']);
         $this->set('text_message', $params['body_text']);
         $html_message = $formValues['html_message'];
         // dojo editor does some html conversion when tokens are
         // inserted as links. Hence token replacement fails.
         // this is hack to revert html conversion for { to %7B and
         // } to %7D by dojo editor
         $html_message = str_replace('%7B', '{', str_replace('%7D', '}', $html_message));
         $params['body_html'] = $html_message;
         $this->set('htmlFile', $params['body_html']);
         $this->set('html_message', $params['body_html']);
     }
     $params['name'] = $this->get('name');
     $session =& CRM_Core_Session::singleton();
     $params['contact_id'] = $session->get('userID');
     $composeFields = array('template', 'saveTemplate', 'updateTemplate', 'saveTemplateName');
     $msgTemplate = null;
     //mail template is composed
     if ($formValues['upload_type']) {
         foreach ($composeFields as $key) {
             if (CRM_Utils_Array::value($key, $formValues)) {
                 $composeParams[$key] = $formValues[$key];
                 $this->set($key, $formValues[$key]);
             }
         }
         if (CRM_Utils_Array::value('updateTemplate', $composeParams)) {
             $templateParams = array('msg_text' => $text_message, 'msg_html' => $html_message, 'msg_subject' => $params['subject'], 'is_active' => true);
             $templateParams['id'] = $formValues['template'];
             $msgTemplate = CRM_Core_BAO_MessageTemplates::add($templateParams);
         }
         if (CRM_Utils_Array::value('saveTemplate', $composeParams)) {
             $templateParams = array('msg_text' => $text_message, 'msg_html' => $html_message, 'msg_subject' => $params['subject'], 'is_active' => true);
             $templateParams['msg_title'] = $composeParams['saveTemplateName'];
             $msgTemplate = CRM_Core_BAO_MessageTemplates::add($templateParams);
         }
         if (isset($msgTemplate->id)) {
             $params['msg_template_id'] = $msgTemplate->id;
         } else {
             $params['msg_template_id'] = CRM_Utils_Array::value('template', $formValues);
         }
         $this->set('template', $params['msg_template_id']);
     }
     CRM_Core_BAO_File::formatAttachment($formValues, $params, 'civicrm_mailing', $this->_mailingID);
     $ids['mailing_id'] = $this->_mailingID;
     //handle mailing from name & address.
     $formEmailAddress = CRM_Utils_Array::value($formValues['from_email_address'], CRM_Core_PseudoConstant::fromEmailAddress("from_email_address"));
     //get the from email address
     require_once 'CRM/Utils/Mail.php';
     $params['from_email'] = CRM_Utils_Mail::pluckEmailFromHeader($formEmailAddress);
     //get the from Name
     $params['from_name'] = CRM_Utils_Array::value(1, explode('"', $formEmailAddress));
     /* Build the mailing object */
     require_once 'CRM/Mailing/BAO/Mailing.php';
     CRM_Mailing_BAO_Mailing::create($params, $ids);
     if ($this->_submitValues['_qf_Upload_upload'] == 'Save & Continue Later') {
         //when user perform mailing from search context
         //redirect it to search result CRM-3711.
         $ssID = $this->get('ssID');
         $context = $this->get('context');
         if ($ssID && $context == 'search') {
             if ($this->_action == CRM_Core_Action::BASIC) {
                 $fragment = 'search';
             } else {
                 if ($this->_action == CRM_Core_Action::PROFILE) {
                     $fragment = 'search/builder';
                 } else {
                     if ($this->_action == CRM_Core_Action::ADVANCED) {
                         $fragment = 'search/advanced';
                     } else {
                         $fragment = 'search/custom';
                     }
                 }
             }
             $session =& CRM_Core_Session::singleton();
             $draftURL = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
             $status = ts("Your mailing has been saved. You can continue later by clicking the 'Continue' action to resume working on it.<br /> From <a href='%1'>Draft and Unscheduled Mailings</a>.", array(1 => $draftURL));
             CRM_Core_Session::setStatus($status);
             //replace user context to search.
             $url = CRM_Utils_System::url('civicrm/contact/' . $fragment, "force=1&reset=1&ssID={$ssID}");
             CRM_Utils_System::redirect($url);
         } else {
             $status = ts("Your mailing has been saved. Click the 'Continue' action to resume working on it.");
             CRM_Core_Session::setStatus($status);
             $url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
             CRM_Utils_System::redirect($url);
         }
     }
 }
 /**
  * global form rule
  *
  * @param array $fields the input form values
  * @param array $files  the uploaded files if any
  * @param array $self   current form object.
  *
  * @return array array of errors / empty array.
  * @access public
  * @static
  */
 static function formRule($fields, $files, $self)
 {
     $errors = array();
     if ($self->_gName == 'case_status' && !CRM_Utils_Array::value('grouping', $fields)) {
         $errors['grouping'] = ts('Status class is a required field');
     }
     if (in_array($self->_gName, array('email_greeting', 'postal_greeting', 'addressee')) && !CRM_Utils_Array::value('is_reserved', $self->_defaultValues)) {
         $label = $fields['label'];
         $condition = " AND v.label = '{$label}' ";
         $values = CRM_Core_OptionGroup::values($self->_gName, FALSE, FALSE, FALSE, $condition, 'filter');
         $checkContactOptions = TRUE;
         if ($self->_id && $self->_defaultValues['contactOptions'] == $fields['contactOptions']) {
             $checkContactOptions = FALSE;
         }
         if ($checkContactOptions && in_array($fields['contactOptions'], $values)) {
             $errors['label'] = ts('This Label already exists in the database for the selected contact type.');
         }
     }
     if ($self->_gName == 'from_email_address') {
         $formEmail = CRM_Utils_Mail::pluckEmailFromHeader($fields['label']);
         if (!CRM_Utils_Rule::email($formEmail)) {
             $errors['label'] = ts('Please enter the valid email address.');
         }
         $formName = explode('"', $fields['label']);
         if (!CRM_Utils_Array::value(1, $formName) || count($formName) != 3) {
             $errors['label'] = ts('Please follow the proper format for From Email Address');
         }
     }
     return $errors;
 }