/** * Set default values for the form. * the default values are retrieved from the database * * * @return void */ public function setDefaultValues() { $mailingID = CRM_Utils_Request::retrieve('mid', 'Integer', $this, FALSE, NULL); // CRM-14716 - Pick up mailingID from session since most of the time it's not in the URL if (!$mailingID) { $mailingID = $this->get('mailing_id'); } $count = $this->get('count'); $this->assign('count', $count); $defaults = array(); $componentFields = array('reply_id' => 'Reply', 'optout_id' => 'OptOut', 'unsubscribe_id' => 'Unsubscribe', 'resubscribe_id' => 'Resubscribe'); foreach ($componentFields as $componentVar => $componentType) { $defaults[$componentVar] = CRM_Mailing_PseudoConstant::defaultComponent($componentType, ''); } if ($mailingID) { $dao = new CRM_Mailing_DAO_Mailing(); $dao->id = $mailingID; $dao->find(TRUE); // override_verp must be flipped, as in 3.2 we reverted // its meaning to ‘should CiviMail manage replies?’ – i.e., // ‘should it *not* override Reply-To: with VERP-ed address?’ $dao->override_verp = !$dao->override_verp; $dao->storeValues($dao, $defaults); $defaults['visibility'] = $dao->visibility; } return $defaults; }
/** * This function sets the default values for the form. * the default values are retrieved from the database * * @access public * @return None */ function setDefaultValues() { $mailingID = CRM_Utils_Request::retrieve('mid', 'Integer', $this, false, null); $count = $this->get('count'); $this->assign('count', $count); $defaults = array(); $componentFields = array('reply_id' => 'Reply', 'optout_id' => 'OptOut', 'unsubscribe_id' => 'Unsubscribe', 'resubscribe_id' => 'Resubscribe'); foreach ($componentFields as $componentVar => $componentType) { $defaults[$componentVar] = CRM_Mailing_PseudoConstant::defaultComponent($componentType, ''); } if ($mailingID) { require_once "CRM/Mailing/DAO/Mailing.php"; $dao =& new CRM_Mailing_DAO_Mailing(); $dao->id = $mailingID; $dao->find(true); $dao->storeValues($dao, $defaults); } return $defaults; }
/** * This function sets the default values for the form. * the default values are retrieved from the database * * @access public * @return None */ function setDefaultValues() { $mailingID = CRM_Utils_Request::retrieve('mid', 'Integer', $this, false, null); $count = $this->get('count'); $this->assign('count', $count); $defaults = array(); $componentFields = array('reply_id' => 'Reply', 'optout_id' => 'OptOut', 'unsubscribe_id' => 'Unsubscribe', 'resubscribe_id' => 'Resubscribe'); foreach ($componentFields as $componentVar => $componentType) { $defaults[$componentVar] = CRM_Mailing_PseudoConstant::defaultComponent($componentType, ''); } if ($mailingID) { require_once 'CRM/Mailing/DAO/Mailing.php'; $dao =& new CRM_Mailing_DAO_Mailing(); $dao->id = $mailingID; $dao->find(true); // override_verp must be flipped, as in 3.2 we reverted // its meaning to ‘should CiviMail manage replies?’ – i.e., // ‘should it *not* override Reply-To: with VERP-ed address?’ $dao->override_verp = !$dao->override_verp; $dao->storeValues($dao, $defaults); } return $defaults; }
/** * Determine the default mailing component of a given type. * * @param $type * The type of component needed. * @param $undefined * The value to use if no default is defined. * * @return int * The ID of the default mailing component. */ public static function &defaultComponent($type, $undefined = NULL) { if (!self::$defaultComponent) { $queryDefaultComponents = "SELECT id, component_type\n FROM civicrm_mailing_component\n WHERE is_active = 1\n AND is_default = 1\n GROUP BY component_type, id"; $dao = CRM_Core_DAO::executeQuery($queryDefaultComponents); self::$defaultComponent = array(); while ($dao->fetch()) { self::$defaultComponent[$dao->component_type] = $dao->id; } } $value = CRM_Utils_Array::value($type, self::$defaultComponent, $undefined); return $value; }
/** * Set default values for the form. * the default values are retrieved from the database * * * @return void */ public function setDefaultValues() { $mailingID = CRM_Utils_Request::retrieve('mid', 'Integer', $this, FALSE, NULL); //need to differentiate new/reuse mailing, CRM-2873 $reuseMailing = FALSE; if ($mailingID) { $reuseMailing = TRUE; } else { $mailingID = $this->_mailingID; } $count = $this->get('count'); $this->assign('count', $count); $this->set('skipTextFile', FALSE); $this->set('skipHtmlFile', FALSE); $defaults = array(); $htmlMessage = NULL; if ($mailingID) { $dao = new CRM_Mailing_DAO_Mailing(); $dao->id = $mailingID; $dao->find(TRUE); $dao->storeValues($dao, $defaults); //we don't want to retrieve template details once it is //set in session $templateId = $this->get('template'); $this->assign('templateSelected', $templateId ? $templateId : 0); if (isset($defaults['msg_template_id']) && !$templateId) { $defaults['template'] = $defaults['msg_template_id']; $messageTemplate = new CRM_Core_DAO_MessageTemplate(); $messageTemplate->id = $defaults['msg_template_id']; $messageTemplate->selectAdd(); $messageTemplate->selectAdd('msg_text, msg_html'); $messageTemplate->find(TRUE); $defaults['text_message'] = $messageTemplate->msg_text; $htmlMessage = $messageTemplate->msg_html; } if (isset($defaults['body_text'])) { $defaults['text_message'] = $defaults['body_text']; $this->set('textFile', $defaults['body_text']); $this->set('skipTextFile', TRUE); } if (isset($defaults['body_html'])) { $htmlMessage = $defaults['body_html']; $this->set('htmlFile', $defaults['body_html']); $this->set('skipHtmlFile', TRUE); } //set default from email address. if (!empty($defaults['from_name']) && !empty($defaults['from_email'])) { $defaults['from_email_address'] = array_search('"' . $defaults['from_name'] . '" <' . $defaults['from_email'] . '>', CRM_Core_OptionGroup::values('from_email_address')); } else { //get the default from email address. $defaultAddress = CRM_Core_OptionGroup::values('from_email_address', NULL, NULL, NULL, ' AND is_default = 1'); foreach ($defaultAddress as $id => $value) { $defaults['from_email_address'] = $id; } } if (!empty($defaults['replyto_email'])) { $replyToEmail = CRM_Core_OptionGroup::values('from_email_address'); foreach ($replyToEmail as $value) { if (strstr($value, $defaults['replyto_email'])) { $replyToEmailAddress = $value; break; } } $replyToEmailAddress = explode('<', $replyToEmailAddress); if (count($replyToEmailAddress) > 1) { $replyToEmailAddress = $replyToEmailAddress[0] . '<' . $replyToEmailAddress[1]; } $defaults['reply_to_address'] = array_search($replyToEmailAddress, $replyToEmail); } } //fix for CRM-2873 if (!$reuseMailing) { $textFilePath = $this->get('textFilePath'); if ($textFilePath && file_exists($textFilePath)) { $defaults['text_message'] = file_get_contents($textFilePath); if (strlen($defaults['text_message']) > 0) { $this->set('skipTextFile', TRUE); } } $htmlFilePath = $this->get('htmlFilePath'); if ($htmlFilePath && file_exists($htmlFilePath)) { $defaults['html_message'] = file_get_contents($htmlFilePath); if (strlen($defaults['html_message']) > 0) { $htmlMessage = $defaults['html_message']; $this->set('skipHtmlFile', TRUE); } } } if ($this->get('html_message')) { $htmlMessage = $this->get('html_message'); } $htmlMessage = str_replace(array("\n", "\r"), ' ', $htmlMessage); $htmlMessage = str_replace("'", "\\'", $htmlMessage); $this->assign('message_html', $htmlMessage); $defaults['upload_type'] = 1; if (isset($defaults['body_html'])) { $defaults['html_message'] = $defaults['body_html']; } //CRM-4678 setdefault to default component when composing new mailing. if (!$reuseMailing) { $componentFields = array('header_id' => 'Header', 'footer_id' => 'Footer'); foreach ($componentFields as $componentVar => $componentType) { $defaults[$componentVar] = CRM_Mailing_PseudoConstant::defaultComponent($componentType, ''); } } return $defaults; }
/** * Construct a new mailing object, along with job and mailing_group * objects, from the form values of the create mailing wizard. * * This function is a bit evil. It not only merges $params and saves * the mailing -- it also schedules the mailing and chooses the recipients. * Since it merges $params, it's also the only place to correctly trigger * multi-field validation. It should be broken up. * * In the mean time, use-cases which break under the weight of this * evil may find reprieve in these extra evil params: * * - _skip_evil_bao_auto_recipients_: bool * - _skip_evil_bao_auto_schedule_: bool * - _evil_bao_validator_: string|callable * * </twowrongsmakesaright> * * @params array $params * Form values. * * @param array $params * @param array $ids * * @return object * $mailing The new mailing object * @throws \Exception */ public static function create(&$params, $ids = array()) { // WTH $ids if (empty($ids) && isset($params['id'])) { $ids['mailing_id'] = $ids['id'] = $params['id']; } // CRM-12430 // Do the below only for an insert // for an update, we should not set the defaults if (!isset($ids['id']) && !isset($ids['mailing_id'])) { // Retrieve domain email and name for default sender $domain = civicrm_api('Domain', 'getsingle', array('version' => 3, 'current_domain' => 1, 'sequential' => 1)); if (isset($domain['from_email'])) { $domain_email = $domain['from_email']; $domain_name = $domain['from_name']; } else { $domain_email = '*****@*****.**'; $domain_name = 'EXAMPLE.ORG'; } if (!isset($params['created_id'])) { $session =& CRM_Core_Session::singleton(); $params['created_id'] = $session->get('userID'); } $defaults = array('override_verp' => TRUE, 'forward_replies' => FALSE, 'open_tracking' => TRUE, 'url_tracking' => TRUE, 'visibility' => 'Public Pages', 'replyto_email' => $domain_email, 'header_id' => CRM_Mailing_PseudoConstant::defaultComponent('header_id', ''), 'footer_id' => CRM_Mailing_PseudoConstant::defaultComponent('footer_id', ''), 'from_email' => $domain_email, 'from_name' => $domain_name, 'msg_template_id' => NULL, 'created_id' => $params['created_id'], 'approver_id' => NULL, 'auto_responder' => 0, 'created_date' => date('YmdHis'), 'scheduled_date' => NULL, 'approval_date' => NULL); // Get the default from email address, if not provided. if (empty($defaults['from_email'])) { $defaultAddress = CRM_Core_OptionGroup::values('from_email_address', NULL, NULL, NULL, ' AND is_default = 1'); foreach ($defaultAddress as $id => $value) { if (preg_match('/"(.*)" <(.*)>/', $value, $match)) { $defaults['from_email'] = $match[2]; $defaults['from_name'] = $match[1]; } } } $params = array_merge($defaults, $params); } /** * Could check and warn for the following cases: * * - groups OR mailings should be populated. * - body html OR body text should be populated. */ $transaction = new CRM_Core_Transaction(); $mailing = self::add($params, $ids); if (is_a($mailing, 'CRM_Core_Error')) { $transaction->rollback(); return $mailing; } // update mailings with hash values CRM_Contact_BAO_Contact_Utils::generateChecksum($mailing->id, NULL, NULL, NULL, 'mailing', 16); $groupTableName = CRM_Contact_BAO_Group::getTableName(); $mailingTableName = CRM_Mailing_BAO_Mailing::getTableName(); /* Create the mailing group record */ $mg = new CRM_Mailing_DAO_MailingGroup(); $groupTypes = array('include' => 'Include', 'exclude' => 'Exclude', 'base' => 'Base'); foreach (array('groups', 'mailings') as $entity) { foreach (array('include', 'exclude', 'base') as $type) { if (isset($params[$entity][$type])) { self::replaceGroups($mailing->id, $groupTypes[$type], $entity, $params[$entity][$type]); } } } if (!empty($params['search_id']) && !empty($params['group_id'])) { $mg->reset(); $mg->mailing_id = $mailing->id; $mg->entity_table = $groupTableName; $mg->entity_id = $params['group_id']; $mg->search_id = $params['search_id']; $mg->search_args = $params['search_args']; $mg->group_type = 'Include'; $mg->save(); } // check and attach and files as needed CRM_Core_BAO_File::processAttachment($params, 'civicrm_mailing', $mailing->id); // If we're going to autosend, then check validity before saving. if (!empty($params['scheduled_date']) && $params['scheduled_date'] != 'null' && !empty($params['_evil_bao_validator_'])) { $cb = Civi\Core\Resolver::singleton()->get($params['_evil_bao_validator_']); $errors = call_user_func($cb, $mailing); if (!empty($errors)) { $fields = implode(',', array_keys($errors)); throw new CRM_Core_Exception("Mailing cannot be sent. There are missing or invalid fields ({$fields}).", 'cannot-send', $errors); } } $transaction->commit(); // Create parent job if not yet created. // Condition on the existence of a scheduled date. if (!empty($params['scheduled_date']) && $params['scheduled_date'] != 'null' && empty($params['_skip_evil_bao_auto_schedule_'])) { $job = new CRM_Mailing_BAO_MailingJob(); $job->mailing_id = $mailing->id; $job->status = 'Scheduled'; $job->is_test = 0; if (!$job->find(TRUE)) { $job->scheduled_date = $params['scheduled_date']; $job->save(); } // Populate the recipients. if (empty($params['_skip_evil_bao_auto_recipients_'])) { self::getRecipients($job->id, $mailing->id, TRUE, $mailing->dedupe_email); } } return $mailing; }
/** * Adjust Metadata for Create action. * * The metadata is used for setting defaults, documentation & validation. * * @param array $params * Array of parameters determined by getfields. */ function _civicrm_api3_mailing_create_spec(&$params) { $params['created_id']['api.required'] = 1; $params['created_id']['api.default'] = 'user_contact_id'; $params['override_verp']['api.default'] = !CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'track_civimail_replies'); $params['visibility']['api.default'] = 'Public Pages'; $params['dedupe_email']['api.default'] = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'dedupe_email_default'); $params['forward_replies']['api.default'] = FALSE; $params['auto_responder']['api.default'] = FALSE; $params['open_tracking']['api.default'] = TRUE; $params['url_tracking']['api.default'] = TRUE; $params['header_id']['api.default'] = CRM_Mailing_PseudoConstant::defaultComponent('Header', ''); $params['footer_id']['api.default'] = CRM_Mailing_PseudoConstant::defaultComponent('Footer', ''); $params['optout_id']['api.default'] = CRM_Mailing_PseudoConstant::defaultComponent('OptOut', ''); $params['reply_id']['api.default'] = CRM_Mailing_PseudoConstant::defaultComponent('Reply', ''); $params['resubscribe_id']['api.default'] = CRM_Mailing_PseudoConstant::defaultComponent('Resubscribe', ''); $params['unsubscribe_id']['api.default'] = CRM_Mailing_PseudoConstant::defaultComponent('Unsubscribe', ''); $params['mailing_type']['api.default'] = 'standalone'; $defaultAddress = CRM_Core_OptionGroup::values('from_email_address', NULL, NULL, NULL, ' AND is_default = 1'); foreach ($defaultAddress as $id => $value) { if (preg_match('/"(.*)" <(.*)>/', $value, $match)) { $params['from_email']['api.default'] = $match[2]; $params['from_name']['api.default'] = $match[1]; } } }
/** * Construct a new mailing object, along with job and mailing_group * objects, from the form values of the create mailing wizard. * * @params array $params Form values * * @return object $mailing The new mailing object * @access public * @static */ public static function create(&$params, $ids = array()) { // CRM-12430 // Do the below only for an insert // for an update, we should not set the defaults if (!isset($ids['id']) && !isset($ids['mailing_id'])) { // Retrieve domain email and name for default sender $domain = civicrm_api('Domain', 'getsingle', array('version' => 3, 'current_domain' => 1, 'sequential' => 1)); if (isset($domain['from_email'])) { $domain_email = $domain['from_email']; $domain_name = $domain['from_name']; } else { $domain_email = '*****@*****.**'; $domain_name = 'EXAMPLE.ORG'; } if (!isset($params['created_id'])) { $session =& CRM_Core_Session::singleton(); $params['created_id'] = $session->get('userID'); } $defaults = array('override_verp' => TRUE, 'forward_replies' => FALSE, 'open_tracking' => TRUE, 'url_tracking' => TRUE, 'visibility' => 'User and User Admin Only', 'replyto_email' => $domain_email, 'header_id' => CRM_Mailing_PseudoConstant::defaultComponent('header_id', ''), 'footer_id' => CRM_Mailing_PseudoConstant::defaultComponent('footer_id', ''), 'from_email' => $domain_email, 'from_name' => $domain_name, 'msg_template_id' => NULL, 'created_id' => $params['created_id'], 'approver_id' => NULL, 'auto_responder' => 0, 'created_date' => date('YmdHis'), 'scheduled_date' => NULL, 'approval_date' => NULL); // Get the default from email address, if not provided. if (empty($defaults['from_email'])) { $defaultAddress = CRM_Core_OptionGroup::values('from_email_address', NULL, NULL, NULL, ' AND is_default = 1'); foreach ($defaultAddress as $id => $value) { if (preg_match('/"(.*)" <(.*)>/', $value, $match)) { $defaults['from_email'] = $match[2]; $defaults['from_name'] = $match[1]; } } } $params = array_merge($defaults, $params); } /** * Could check and warn for the following cases: * * - groups OR mailings should be populated. * - body html OR body text should be populated. */ $transaction = new CRM_Core_Transaction(); $mailing = self::add($params, $ids); if (is_a($mailing, 'CRM_Core_Error')) { $transaction->rollback(); return $mailing; } $groupTableName = CRM_Contact_BAO_Group::getTableName(); $mailingTableName = CRM_Mailing_BAO_Mailing::getTableName(); /* Create the mailing group record */ $mg = new CRM_Mailing_DAO_MailingGroup(); foreach (array('groups', 'mailings') as $entity) { foreach (array('include', 'exclude', 'base') as $type) { if (isset($params[$entity]) && CRM_Utils_Array::value($type, $params[$entity]) && is_array($params[$entity][$type])) { foreach ($params[$entity][$type] as $entityId) { $mg->reset(); $mg->mailing_id = $mailing->id; $mg->entity_table = $entity == 'groups' ? $groupTableName : $mailingTableName; $mg->entity_id = $entityId; $mg->group_type = $type; $mg->save(); } } } } if (!empty($params['search_id']) && !empty($params['group_id'])) { $mg->reset(); $mg->mailing_id = $mailing->id; $mg->entity_table = $groupTableName; $mg->entity_id = $params['group_id']; $mg->search_id = $params['search_id']; $mg->search_args = $params['search_args']; $mg->group_type = 'Include'; $mg->save(); } // check and attach and files as needed CRM_Core_BAO_File::processAttachment($params, 'civicrm_mailing', $mailing->id); $transaction->commit(); /** * create parent job if not yet created * condition on the existence of a scheduled date */ if (!empty($params['scheduled_date']) && $params['scheduled_date'] != 'null') { $job = new CRM_Mailing_BAO_MailingJob(); $job->mailing_id = $mailing->id; $job->status = 'Scheduled'; $job->is_test = 0; if (!$job->find(TRUE)) { $job->scheduled_date = $params['scheduled_date']; $job->save(); } // Populate the recipients. $mailing->getRecipients($job->id, $mailing->id, NULL, NULL, TRUE, FALSE); } return $mailing; }
/** * This function sets the default values for the form. * the default values are retrieved from the database * * @access public * * @return None */ function setDefaultValues() { // to continue the unscheduled or draft mailing $continue = $this->_continue = CRM_Utils_Request::retrieve('continue', 'String', $this, FALSE, NULL); $mailingID = CRM_Utils_Request::retrieve('mid', 'Integer', $this, FALSE, NULL); $defaults = array(); if ($this->_mailingID) { // check that the user has permission to access mailing id CRM_Mailing_BAO_Mailing::checkPermission($this->_mailingID); $mailing = new CRM_Mailing_DAO_Mailing(); $mailing->id = $this->_mailingID; $mailing->addSelect('name', 'campaign_id'); $mailing->find(TRUE); $defaults['name'] = $mailing->name; if (!$continue) { $defaults['name'] = ts('Copy of %1', array(1 => $mailing->name)); } else { // CRM-7590, reuse same mailing ID if we are continuing $this->set('mailing_id', $this->_mailingID); } $defaults['campaign_id'] = $mailing->campaign_id; $defaults['dedupe_email'] = $mailing->dedupe_email; $dao = new CRM_Mailing_DAO_MailingGroup(); $mailingGroups = array('civicrm_group' => array(), 'civicrm_mailing' => array()); $dao->mailing_id = $this->_mailingID; $dao->find(); while ($dao->fetch()) { // account for multi-lingual // CRM-11431 $entityTable = 'civicrm_group'; if (substr($dao->entity_table, 0, 15) == 'civicrm_mailing') { $entityTable = 'civicrm_mailing'; } $mailingGroups[$entityTable][$dao->group_type][] = $dao->entity_id; } $defaults['includeGroups'] = $mailingGroups['civicrm_group']['include']; $defaults['excludeGroups'] = CRM_Utils_Array::value('exclude', $mailingGroups['civicrm_group']); if (!empty($mailingGroups['civicrm_mailing'])) { $defaults['includeMailings'] = CRM_Utils_Array::value('include', $mailingGroups['civicrm_mailing']); $defaults['excludeMailings'] = CRM_Utils_Array::value('exclude', $mailingGroups['civicrm_mailing']); } } else { $defaults['url_tracking'] = TRUE; $defaults['open_tracking'] = TRUE; } //set default message body $reuseMailing = FALSE; if ($mailingID) { $reuseMailing = TRUE; } else { $mailingID = $this->_mailingID; } $count = $this->get('count'); $this->assign('count', $count); $this->set('skipTextFile', FALSE); $this->set('skipHtmlFile', FALSE); $htmlMessage = NULL; if ($mailingID) { $dao = new CRM_Mailing_DAO_Mailing(); $dao->id = $mailingID; $dao->find(TRUE); $dao->storeValues($dao, $defaults); //we don't want to retrieve template details once it is //set in session $templateId = $this->get('template'); $this->assign('templateSelected', $templateId ? $templateId : 0); if (isset($defaults['msg_template_id']) && !$templateId) { $defaults['template'] = $defaults['msg_template_id']; $messageTemplate = new CRM_Core_DAO_MessageTemplate(); $messageTemplate->id = $defaults['msg_template_id']; $messageTemplate->selectAdd(); $messageTemplate->selectAdd('msg_text, msg_html'); $messageTemplate->find(TRUE); $defaults['text_message'] = $messageTemplate->msg_text; $htmlMessage = $messageTemplate->msg_html; } if (isset($defaults['body_text'])) { $defaults['text_message'] = $defaults['body_text']; $this->set('textFile', $defaults['body_text']); $this->set('skipTextFile', TRUE); } if (isset($defaults['body_html'])) { $htmlMessage = $defaults['body_html']; $this->set('htmlFile', $defaults['body_html']); $this->set('skipHtmlFile', TRUE); } //set default from email address. if (CRM_Utils_Array::value('from_name', $defaults) && CRM_Utils_Array::value('from_email', $defaults)) { $defaults['from_email_address'] = array_search('"' . $defaults['from_name'] . '" <' . $defaults['from_email'] . '>', CRM_Core_OptionGroup::values('from_email_address')); } else { //get the default from email address. $defaultAddress = CRM_Core_OptionGroup::values('from_email_address', NULL, NULL, NULL, ' AND is_default = 1'); foreach ($defaultAddress as $id => $value) { $defaults['from_email_address'] = $id; } } if (CRM_Utils_Array::value('replyto_email', $defaults)) { $replyToEmail = CRM_Core_OptionGroup::values('from_email_address'); foreach ($replyToEmail as $value) { if (strstr($value, $defaults['replyto_email'])) { $replyToEmailAddress = $value; break; } } $replyToEmailAddress = explode('<', $replyToEmailAddress); $replyToEmailAddress = $replyToEmailAddress[0] . '<' . $replyToEmailAddress[1]; $this->replytoAddress = $defaults['reply_to_address'] = array_search($replyToEmailAddress, $replyToEmail); } } /* //set default from email address. if (CRM_Utils_Array::value('from_name', $defaults) && CRM_Utils_Array::value('from_email', $defaults)) { $defaults['from_email_address'] = array_search('"' . $defaults['from_name'] . '" <' . $defaults['from_email'] . '>', CRM_Core_OptionGroup::values('from_email_address') ); } else { //get the default from email address. $defaultAddress = CRM_Core_OptionGroup::values('from_email_address', NULL, NULL, NULL, ' AND is_default = 1'); foreach ($defaultAddress as $id => $value) { $defaults['from_email_address'] = $id; } } if (CRM_Utils_Array::value('replyto_email', $defaults)) { $replyToEmail = CRM_Core_OptionGroup::values('from_email_address'); foreach ($replyToEmail as $value) { if (strstr($value, $defaults['replyto_email'])) { $replyToEmailAddress = $value; break; } } $replyToEmailAddress = explode('<', $replyToEmailAddress); $replyToEmailAddress = $replyToEmailAddress[0] . '<' . $replyToEmailAddress[1]; $this->replytoAddress = $defaults['reply_to_address'] = array_search($replyToEmailAddress, $replyToEmail); } */ //fix for CRM-2873 if (!$reuseMailing) { $textFilePath = $this->get('textFilePath'); if ($textFilePath && file_exists($textFilePath)) { $defaults['text_message'] = file_get_contents($textFilePath); if (strlen($defaults['text_message']) > 0) { $this->set('skipTextFile', TRUE); } } $htmlFilePath = $this->get('htmlFilePath'); if ($htmlFilePath && file_exists($htmlFilePath)) { $defaults['html_message'] = file_get_contents($htmlFilePath); if (strlen($defaults['html_message']) > 0) { $htmlMessage = $defaults['html_message']; $this->set('skipHtmlFile', TRUE); } } } if ($this->get('html_message')) { $htmlMessage = $this->get('html_message'); } $htmlMessage = str_replace(array("\n", "\r"), ' ', $htmlMessage); $htmlMessage = str_replace("'", "\\'", $htmlMessage); $this->assign('message_html', $htmlMessage); $defaults['upload_type'] = 1; if (isset($defaults['body_html'])) { $defaults['html_message'] = $defaults['body_html']; } if (!empty($defaults['html_message'])) { $this->assign('reuse_message_template', $defaults['html_message']); } //CRM-4678 setdefault to default component when composing new mailing. if (!$reuseMailing) { $componentFields = array('header_id' => 'Header', 'footer_id' => 'Footer'); foreach ($componentFields as $componentVar => $componentType) { $defaults[$componentVar] = CRM_Mailing_PseudoConstant::defaultComponent($componentType, ''); } } //end return $defaults; }
/** * This function sets the default values for the form. * the default values are retrieved from the database * * @access public * @return None */ function setDefaultValues() { $mailingID = CRM_Utils_Request::retrieve('mid', 'Integer', $this, false, null); //need to differentiate new/reuse mailing, CRM-2873 $reuseMailing = false; if ($mailingID) { $reuseMailing = true; } else { $mailingID = $this->_mailingID; } $count = $this->get('count'); $this->assign('count', $count); $this->set('skipTextFile', false); $this->set('skipHtmlFile', false); $defaults = array(); $htmlMessage = null; if ($mailingID) { require_once 'CRM/Mailing/DAO/Mailing.php'; $dao = new CRM_Mailing_DAO_Mailing(); $dao->id = $mailingID; $dao->find(true); $dao->storeValues($dao, $defaults); //we don't want to retrieve template details once it is //set in session $templateId = $this->get('template'); $this->assign('templateSelected', $templateId ? $templateId : 0); if (isset($defaults['msg_template_id']) && !$templateId) { $defaults['template'] = $defaults['msg_template_id']; $messageTemplate = new CRM_Core_DAO_MessageTemplates(); $messageTemplate->id = $defaults['msg_template_id']; $messageTemplate->selectAdd(); $messageTemplate->selectAdd('msg_text, msg_html'); $messageTemplate->find(true); $defaults['text_message'] = $messageTemplate->msg_text; $htmlMessage = $messageTemplate->msg_html; } if (isset($defaults['body_text'])) { $defaults['text_message'] = $defaults['body_text']; $this->set('textFile', $defaults['body_text']); $this->set('skipTextFile', true); } if (isset($defaults['body_html'])) { $htmlMessage = $defaults['body_html']; $this->set('htmlFile', $defaults['body_html']); $this->set('skipHtmlFile', true); } //set default from email address. require_once 'CRM/Core/OptionGroup.php'; if (CRM_Utils_Array::value('from_name', $defaults) && CRM_Utils_Array::value('from_email', $defaults)) { $defaults['from_email_address'] = array_search('"' . $defaults['from_name'] . '" <' . $defaults['from_email'] . '>', CRM_Core_OptionGroup::values('from_email_address')); } else { //get the default from email address. $defaultAddress = CRM_Core_OptionGroup::values('from_email_address', null, null, null, ' AND is_default = 1'); foreach ($defaultAddress as $id => $value) { $defaults['from_email_address'] = $id; } } } //fix for CRM-2873 if (!$reuseMailing) { $textFilePath = $this->get('textFilePath'); if ($textFilePath && file_exists($textFilePath)) { $defaults['text_message'] = file_get_contents($textFilePath); if (strlen($defaults['text_message']) > 0) { $this->set('skipTextFile', true); } } $htmlFilePath = $this->get('htmlFilePath'); if ($htmlFilePath && file_exists($htmlFilePath)) { $defaults['html_message'] = file_get_contents($htmlFilePath); if (strlen($defaults['html_message']) > 0) { $htmlMessage = $defaults['html_message']; $this->set('skipHtmlFile', true); } } } if ($this->get('html_message')) { $htmlMessage = $this->get('html_message'); } $htmlMessage = str_replace(array("\n", "\r"), ' ', $htmlMessage); $htmlMessage = str_replace("'", "\\'", $htmlMessage); $this->assign('message_html', $htmlMessage); $defaults['upload_type'] = 1; if (isset($defaults['body_html'])) { $defaults['html_message'] = $defaults['body_html']; } //CRM-4678 setdefault to default component when composing new mailing. if (!$reuseMailing) { $componentFields = array('header_id' => 'Header', 'footer_id' => 'Footer'); foreach ($componentFields as $componentVar => $componentType) { $defaults[$componentVar] = CRM_Mailing_PseudoConstant::defaultComponent($componentType, ''); } } return $defaults; }