/**
  * 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;
 }
示例#2
0
 /**
  * Set default values for the form.
  * The default values are retrieved from the database.
  */
 public function setDefaultValues()
 {
     $mailingID = CRM_Utils_Request::retrieve('mid', 'Integer', $this, FALSE, NULL);
     $continue = CRM_Utils_Request::retrieve('continue', 'String', $this, FALSE, NULL);
     $defaults = array();
     if ($mailingID) {
         $mailing = new CRM_Mailing_DAO_Mailing();
         $mailing->id = $mailingID;
         $mailing->addSelect('name');
         $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', $mailingID);
         }
         $dao = new CRM_Mailing_DAO_MailingGroup();
         $mailingGroups = array();
         $dao->mailing_id = $mailingID;
         $dao->find();
         while ($dao->fetch()) {
             $mailingGroups[$dao->entity_table][$dao->group_type][] = $dao->entity_id;
         }
         $defaults['includeGroups'] = $mailingGroups['civicrm_group']['Include'];
         $defaults['excludeGroups'] = CRM_Utils_Array::value('Exclude', $mailingGroups['civicrm_group']);
         $defaults['includeMailings'] = CRM_Utils_Array::value('Include', CRM_Utils_Array::value('civicrm_mailing', $mailingGroups));
         $defaults['excludeMailings'] = CRM_Utils_Array::value('Exclude', CRM_Utils_Array::value('civicrm_mailing', $mailingGroups));
     }
     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);
     $continue = CRM_Utils_Request::retrieve('continue', 'String', $this, FALSE, NULL);
     // check that the user has permission to access mailing id
     CRM_Mailing_BAO_Mailing::checkPermission($mailingID);
     $defaults = array();
     if ($mailingID) {
         $mailing = new CRM_Mailing_DAO_Mailing();
         $mailing->id = $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', $mailingID);
         }
         $defaults['campaign_id'] = $mailing->campaign_id;
         $defaults['dedupe_email'] = $mailing->dedupe_email;
         $dao = new CRM_Mailing_DAO_Group();
         $mailingGroups = array();
         $dao->mailing_id = $mailingID;
         $dao->find();
         while ($dao->fetch()) {
             $mailingGroups[$dao->entity_table][$dao->group_type][] = $dao->entity_id;
         }
         $defaults['includeGroups'] = $mailingGroups['civicrm_group']['Include'];
         $defaults['excludeGroups'] = CRM_Utils_Array::value('Exclude', $mailingGroups['civicrm_group']);
         $defaults['includeMailings'] = CRM_Utils_Array::value('Include', $mailingGroups['civicrm_mailing']);
         $defaults['excludeMailings'] = $mailingGroups['civicrm_mailing']['Exclude'];
     }
     //when the context is search hide the mailing recipients.
     $showHide = new CRM_Core_ShowHideBlocks();
     $showGroupSelector = TRUE;
     if ($this->_searchBasedMailing) {
         $showGroupSelector = FALSE;
         $formElements = array('includeGroups', 'excludeGroups', 'includeMailings', 'excludeMailings');
         $formValues = $this->controller->exportValues($this->_name);
         foreach ($formElements as $element) {
             if (!empty($formValues[$element])) {
                 $showGroupSelector = TRUE;
                 break;
             }
         }
     }
     if ($showGroupSelector) {
         $showHide->addShow("id-additional");
         $showHide->addHide("id-additional-show");
     } else {
         $showHide->addShow("id-additional-show");
         $showHide->addHide("id-additional");
     }
     $showHide->addToTemplate();
     return $defaults;
 }
示例#4
0
 /**
  * This function sets the default values for the form.
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return void
  */
 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);
     $defaults = array();
     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');
             $messageTemplate->find(TRUE);
             $defaults['text_message'] = $messageTemplate->msg_text;
         }
         if (isset($defaults['body_text'])) {
             $defaults['text_message'] = $defaults['body_text'];
             $this->set('textFile', $defaults['body_text']);
             $this->set('skipTextFile', TRUE);
         }
     }
     //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);
             }
         }
     }
     $defaults['upload_type'] = 1;
     return $defaults;
 }
 /**
  * Delete Mails and all its associated records
  *
  * @param  int  $id id of the mail to delete
  *
  * @return void
  * @access public
  * @static
  */
 public static function del($id)
 {
     if (empty($id)) {
         CRM_Core_Error::fatal();
     }
     // delete all file attachments
     CRM_Core_BAO_File::deleteEntityFile('civicrm_mailing', $id);
     $dao = new CRM_Mailing_DAO_Mailing();
     $dao->id = $id;
     $dao->delete();
     CRM_Core_Session::setStatus(ts('Selected mailing has been deleted.'));
 }
示例#6
0
 /**
  * returns the list of fields that can be exported
  *
  * @access public
  * return array
  */
 function &export($prefix = false)
 {
     if (!$GLOBALS['_CRM_MAILING_DAO_MAILING']['_export']) {
         $GLOBALS['_CRM_MAILING_DAO_MAILING']['_export'] = array();
         $fields =& CRM_Mailing_DAO_Mailing::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     $GLOBALS['_CRM_MAILING_DAO_MAILING']['_export']['mailing'] =& $fields[$name];
                 } else {
                     $GLOBALS['_CRM_MAILING_DAO_MAILING']['_export'][$name] =& $fields[$name];
                 }
             }
         }
     }
     return $GLOBALS['_CRM_MAILING_DAO_MAILING']['_export'];
 }
示例#7
0
 /**
  * Send a response email informing the contact of the groups from which he.
  * has been unsubscribed.
  *
  * @param string $queue_id
  *   The queue event ID.
  * @param array $groups
  *   List of group IDs.
  * @param bool $is_domain
  *   Is this domain-level?.
  * @param int $job
  *   The job ID.
  */
 public static function send_unsub_response($queue_id, $groups, $is_domain = FALSE, $job)
 {
     $config = CRM_Core_Config::singleton();
     $domain = CRM_Core_BAO_Domain::getDomain();
     $jobObject = new CRM_Mailing_BAO_MailingJob();
     $jobTable = $jobObject->getTableName();
     $mailingObject = new CRM_Mailing_DAO_Mailing();
     $mailingTable = $mailingObject->getTableName();
     $contactsObject = new CRM_Contact_DAO_Contact();
     $contacts = $contactsObject->getTableName();
     $emailObject = new CRM_Core_DAO_Email();
     $email = $emailObject->getTableName();
     $queueObject = new CRM_Mailing_Event_BAO_Queue();
     $queue = $queueObject->getTableName();
     //get the default domain email address.
     list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
     $dao = new CRM_Mailing_BAO_Mailing();
     $dao->query("   SELECT * FROM {$mailingTable}\n                        INNER JOIN {$jobTable} ON\n                            {$jobTable}.mailing_id = {$mailingTable}.id\n                        WHERE {$jobTable}.id = {$job}");
     $dao->fetch();
     $component = new CRM_Mailing_BAO_Component();
     if ($is_domain) {
         $component->id = $dao->optout_id;
     } else {
         $component->id = $dao->unsubscribe_id;
     }
     $component->find(TRUE);
     $html = $component->body_html;
     if ($component->body_text) {
         $text = $component->body_text;
     } else {
         $text = CRM_Utils_String::htmlToText($component->body_html);
     }
     $eq = new CRM_Core_DAO();
     $eq->query("SELECT     {$contacts}.preferred_mail_format as format,\n                    {$contacts}.id as contact_id,\n                    {$email}.email as email,\n                    {$queue}.hash as hash\n        FROM        {$contacts}\n        INNER JOIN  {$queue} ON {$queue}.contact_id = {$contacts}.id\n        INNER JOIN  {$email} ON {$queue}.email_id = {$email}.id\n        WHERE       {$queue}.id = " . CRM_Utils_Type::escape($queue_id, 'Integer'));
     $eq->fetch();
     if ($groups) {
         foreach ($groups as $key => $value) {
             if (!$value) {
                 unset($groups[$key]);
             }
         }
     }
     $message = new Mail_mime("\n");
     list($addresses, $urls) = CRM_Mailing_BAO_Mailing::getVerpAndUrls($job, $queue_id, $eq->hash, $eq->email);
     $bao = new CRM_Mailing_BAO_Mailing();
     $bao->body_text = $text;
     $bao->body_html = $html;
     $tokens = $bao->getTokens();
     if ($eq->format == 'HTML' || $eq->format == 'Both') {
         $html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html']);
         $html = CRM_Utils_Token::replaceUnsubscribeTokens($html, $domain, $groups, TRUE, $eq->contact_id, $eq->hash);
         $html = CRM_Utils_Token::replaceActionTokens($html, $addresses, $urls, TRUE, $tokens['html']);
         $html = CRM_Utils_Token::replaceMailingTokens($html, $dao, NULL, $tokens['html']);
         $message->setHTMLBody($html);
     }
     if (!$html || $eq->format == 'Text' || $eq->format == 'Both') {
         $text = CRM_Utils_Token::replaceDomainTokens($text, $domain, FALSE, $tokens['text']);
         $text = CRM_Utils_Token::replaceUnsubscribeTokens($text, $domain, $groups, FALSE, $eq->contact_id, $eq->hash);
         $text = CRM_Utils_Token::replaceActionTokens($text, $addresses, $urls, FALSE, $tokens['text']);
         $text = CRM_Utils_Token::replaceMailingTokens($text, $dao, NULL, $tokens['text']);
         $message->setTxtBody($text);
     }
     $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
     $headers = array('Subject' => $component->subject, 'From' => "\"{$domainEmailName}\" <do-not-reply@{$emailDomain}>", 'To' => $eq->email, 'Reply-To' => "do-not-reply@{$emailDomain}", 'Return-Path' => "do-not-reply@{$emailDomain}");
     CRM_Mailing_BAO_Mailing::addMessageIdHeader($headers, 'u', $job, $queue_id, $eq->hash);
     $b = CRM_Utils_Mail::setMimeParams($message);
     $h = $message->headers($headers);
     $mailer = \Civi::service('pear_mail');
     if (is_object($mailer)) {
         $errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
         $mailer->send($eq->email, $h, $b);
         unset($errorScope);
     }
 }
示例#8
0
 /**
  * class constructor
  */
 function CRM_Mailing_BAO_Mailing()
 {
     parent::CRM_Mailing_DAO_Mailing();
 }
 /**
  * Delete Mails and all its associated records
  *
  * @param  int  $id id of the mail to delete
  *
  * @return void
  * @access public
  * @static
  */
 public static function del($id)
 {
     if (empty($id)) {
         CRM_Core_Error::fatal();
     }
     CRM_Utils_Hook::pre('delete', 'Mailing', $id, CRM_Core_DAO::$_nullArray);
     // delete all file attachments
     CRM_Core_BAO_File::deleteEntityFile('civicrm_mailing', $id);
     $dao = new CRM_Mailing_DAO_Mailing();
     $dao->id = $id;
     $dao->delete();
     CRM_Core_Session::setStatus(ts('Selected mailing has been deleted.'), ts('Deleted'), 'success');
     CRM_Utils_Hook::post('delete', 'Mailing', $id, $dao);
 }
示例#10
0
 /**
  * before we run jobs, we need to split the jobs
  * @param int $offset
  * @param null $mode
  */
 public static function runJobs_pre($offset = 200, $mode = NULL)
 {
     $job = new CRM_Mailing_BAO_MailingJob();
     $jobTable = CRM_Mailing_DAO_MailingJob::getTableName();
     $mailingTable = CRM_Mailing_DAO_Mailing::getTableName();
     $currentTime = date('YmdHis');
     $mailingACL = CRM_Mailing_BAO_Mailing::mailingACL('m');
     $workflowClause = CRM_Mailing_BAO_MailingJob::workflowClause();
     $domainID = CRM_Core_Config::domainID();
     $modeClause = 'AND m.sms_provider_id IS NULL';
     if ($mode == 'sms') {
         $modeClause = 'AND m.sms_provider_id IS NOT NULL';
     }
     // Select all the mailing jobs that are created from
     // when the mailing is submitted or scheduled.
     $query = "\n    SELECT   j.*\n      FROM   {$jobTable}     j,\n         {$mailingTable} m\n     WHERE   m.id = j.mailing_id AND m.domain_id = {$domainID}\n                 {$workflowClause}\n                 {$modeClause}\n       AND   j.is_test = 0\n       AND   ( ( j.start_date IS null\n       AND       j.scheduled_date <= {$currentTime}\n       AND       j.status = 'Scheduled'\n       AND       j.end_date IS null ) )\n       AND ((j.job_type is NULL) OR (j.job_type <> 'child'))\n    ORDER BY j.scheduled_date,\n         j.start_date";
     $job->query($query);
     // For each of the "Parent Jobs" we find, we split them into
     // X Number of child jobs
     while ($job->fetch()) {
         // still use job level lock for each child job
         $lockName = "civimail.job.{$job->id}";
         $lock = new CRM_Core_Lock($lockName);
         if (!$lock->isAcquired()) {
             continue;
         }
         // Re-fetch the job status in case things
         // changed between the first query and now
         // to avoid race conditions
         $job->status = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_MailingJob', $job->id, 'status', 'id', TRUE);
         if ($job->status != 'Scheduled') {
             $lock->release();
             continue;
         }
         $job->split_job($offset);
         // update the status of the parent job
         $transaction = new CRM_Core_Transaction();
         $saveJob = new CRM_Mailing_DAO_MailingJob();
         $saveJob->id = $job->id;
         $saveJob->start_date = date('YmdHis');
         $saveJob->status = 'Running';
         $saveJob->save();
         $transaction->commit();
         // Release the job lock
         $lock->release();
     }
 }
示例#11
0
 /**
  * class constructor
  */
 function __construct()
 {
     parent::__construct();
 }
示例#12
0
/**
 * Adjust metadata for mailing submit api function.
 *
 * @param array $spec
 */
function _civicrm_api3_mailing_submit_spec(&$spec)
{
    $mailingFields = CRM_Mailing_DAO_Mailing::fields();
    $spec['id'] = $mailingFields['id'];
    $spec['scheduled_date'] = $mailingFields['scheduled_date'];
    $spec['approval_date'] = $mailingFields['approval_date'];
    $spec['approval_status_id'] = $mailingFields['approval_status_id'];
    $spec['approval_note'] = $mailingFields['approval_note'];
    // _skip_evil_bao_auto_recipients_: bool
}
示例#13
0
 /**
  * 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;
 }
示例#14
0
文件: Job.php 项目: bhirsch/voipdev
 /**
  * Initiate all pending/ready jobs
  *
  * @return void
  * @access public
  * @static
  */
 public static function runJobs($testParams = null)
 {
     $job =& new CRM_Mailing_BAO_Job();
     $mailing =& new CRM_Mailing_DAO_Mailing();
     $config =& CRM_Core_Config::singleton();
     $jobTable = CRM_Mailing_DAO_Job::getTableName();
     $mailingTable = CRM_Mailing_DAO_Mailing::getTableName();
     if (!empty($testParams)) {
         $query = "\nSELECT *\n  FROM {$jobTable}\n WHERE id = {$testParams['job_id']}";
         $job->query($query);
     } else {
         $currentTime = date('YmdHis');
         /* FIXME: we might want to go to a progress table.. */
         $query = "\nSELECT   j.*\n  FROM   {$jobTable}     j,\n         {$mailingTable} m\n WHERE   m.id = j.mailing_id\n   AND   j.is_test = 0\n   AND   ( ( j.start_date IS null\n   AND       j.scheduled_date <= {$currentTime}\n   AND       j.status = 'Scheduled' )\n    OR     ( j.status = 'Running'\n   AND       j.end_date IS null ) )\nORDER BY j.scheduled_date,\n         j.start_date";
         $job->query($query);
     }
     require_once 'CRM/Core/Lock.php';
     /* TODO We should parallelize or prioritize this */
     while ($job->fetch()) {
         // fix for cancel job at run time which is in queue, CRM-4246
         if (CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Job', $job->id, 'status') == 'Canceled') {
             continue;
         }
         $lockName = "civimail.job.{$job->id}";
         // get a lock on this job id
         $lock = new CRM_Core_Lock($lockName);
         if (!$lock->isAcquired()) {
             continue;
         }
         /* Queue up recipients for all jobs being launched */
         if ($job->status != 'Running') {
             require_once 'CRM/Core/Transaction.php';
             $transaction = new CRM_Core_Transaction();
             $job->queue($testParams);
             /* Start the job */
             // use a seperate DAO object to protect the loop
             // integrity. I think transactions messes it up
             // check CRM-2469
             $saveJob = new CRM_Mailing_DAO_Job();
             $saveJob->id = $job->id;
             $saveJob->start_date = date('YmdHis');
             $saveJob->status = 'Running';
             $saveJob->save();
             $transaction->commit();
         }
         $mailer =& $config->getMailer();
         /* Compose and deliver */
         $isComplete = $job->deliver($mailer, $testParams);
         require_once 'CRM/Utils/Hook.php';
         CRM_Utils_Hook::post('create', 'CRM_Mailing_DAO_Spool', $job->id, $isComplete);
         if ($isComplete) {
             /* Finish the job */
             require_once 'CRM/Core/Transaction.php';
             $transaction = new CRM_Core_Transaction();
             // use a seperate DAO object to protect the loop
             // integrity. I think transactions messes it up
             // check CRM-2469
             $saveJob = new CRM_Mailing_DAO_Job();
             $saveJob->id = $job->id;
             $saveJob->end_date = date('YmdHis');
             $saveJob->status = 'Complete';
             $saveJob->save();
             $mailing->reset();
             $mailing->id = $job->mailing_id;
             $mailing->is_completed = true;
             $mailing->save();
             $transaction->commit();
         }
         $lock->release();
         if ($testParams) {
             return $isComplete;
         }
     }
 }
示例#15
0
文件: Mailing.php 项目: hguru/224Civi
 /**
  * adds $value['foo_display'] for each $value['foo'] enum from civicrm_mailing
  *
  * @param array $values (reference)  the array up for enhancing
  * @return void
  */
 static function addDisplayEnums(&$values)
 {
     $enumFields =& CRM_Mailing_DAO_Mailing::getEnums();
     foreach ($enumFields as $enum) {
         if (isset($values[$enum])) {
             $values[$enum . '_display'] = CRM_Mailing_DAO_Mailing::tsEnum($enum, $values[$enum]);
         }
     }
 }
示例#16
0
function mte_createQueue(&$mandrillHeader, $toEmail)
{
    $mail = new CRM_Mailing_DAO_Mailing();
    $mail->subject = "***All Transactional Emails***";
    $mail->url_tracking = TRUE;
    $mail->forward_replies = FALSE;
    $mail->auto_responder = FALSE;
    $mail->open_tracking = TRUE;
    if ($mail->find(TRUE)) {
        $emails = CRM_Mte_BAO_Mandrill::retrieveEmailContactId($toEmail);
        $jobCLassName = 'CRM_Mailing_DAO_MailingJob';
        if (version_compare('4.4alpha1', CRM_Core_Config::singleton()->civiVersion) > 0) {
            $jobCLassName = 'CRM_Mailing_DAO_Job';
        }
        $params = array('job_id' => CRM_Core_DAO::getFieldValue($jobCLassName, $mail->id, 'id', 'mailing_id'), 'contact_id' => $emails['email']['contact_id'], 'email_id' => $emails['email']['id']);
        $eventQueue = CRM_Mailing_Event_BAO_Queue::create($params);
        $mandrillHeader = implode(CRM_Core_Config::singleton()->verpSeparator, array($mandrillHeader, 'm', $params['job_id'], $eventQueue->id, $eventQueue->hash));
    }
}
示例#17
0
 /**
  * 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;
 }
示例#18
0
 public static function runJobs_pre($offset = 200)
 {
     $job = new CRM_Mailing_BAO_Job();
     $config = CRM_Core_Config::singleton();
     $jobTable = CRM_Mailing_DAO_Job::getTableName();
     $mailingTable = CRM_Mailing_DAO_Mailing::getTableName();
     $currentTime = date('YmdHis');
     $mailingACL = CRM_Mailing_BAO_Mailing::mailingACL('m');
     // add an additional check and only process
     // jobs that are approved
     $workflowClause = null;
     require_once 'CRM/Mailing/Info.php';
     if (CRM_Mailing_Info::workflowEnabled()) {
         require_once 'CRM/Core/OptionGroup.php';
         $approveOptionID = CRM_Core_OptionGroup::getValue('mail_approval_status', 'Approved', 'name');
         if ($approveOptionID) {
             $workflowClause = " AND m.approval_status_id = {$approveOptionID} ";
         }
     }
     // Select all the mailing jobs that are created from
     // when the mailing is submitted or scheduled.
     $query = "\n\t\tSELECT   j.*\n\t\t  FROM   {$jobTable}     j,\n\t\t\t\t {$mailingTable} m\n\t\t WHERE   m.id = j.mailing_id\n                 {$workflowClause}\n\t\t   AND   j.is_test = 0\n\t\t   AND   ( ( j.start_date IS null\n\t\t   AND       j.scheduled_date <= {$currentTime}\n\t\t   AND       j.status = 'Scheduled'\n\t\t   AND       j.end_date IS null ) )\n\t\t   AND ((j.job_type is NULL) OR (j.job_type <> 'child'))\n\t\tORDER BY j.scheduled_date,\n\t\t\t\t j.start_date";
     $job->query($query);
     require_once 'CRM/Core/Lock.php';
     // For reach of the "Parent Jobs" we find, we split them into
     // X Number of child jobs
     while ($job->fetch()) {
         // still use job level lock for each child job
         $lockName = "civimail.job.{$job->id}";
         $lock = new CRM_Core_Lock($lockName);
         if (!$lock->isAcquired()) {
             continue;
         }
         // refetch the job status in case things
         // changed between the first query and now
         // avoid race conditions
         $job->status = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Job', $job->id, 'status');
         if ($job->status != 'Scheduled') {
             $lock->release();
             continue;
         }
         $job->split_job($offset);
         // update the status of the parent job
         require_once 'CRM/Core/Transaction.php';
         $transaction = new CRM_Core_Transaction();
         $saveJob = new CRM_Mailing_DAO_Job();
         $saveJob->id = $job->id;
         $saveJob->start_date = date('YmdHis');
         $saveJob->status = 'Running';
         $saveJob->save();
         $transaction->commit();
         // Release the job lock
         $lock->release();
     }
 }
 /**
  * Get a list of permissions required for CRUD'ing each field
  * (when workflow is enabled).
  *
  * @return array
  *   Array (string $fieldName => string $permName)
  */
 public static function getWorkflowFieldPerms()
 {
     $fieldNames = array_keys(CRM_Mailing_DAO_Mailing::fields());
     $fieldPerms = array();
     foreach ($fieldNames as $fieldName) {
         if ($fieldName == 'id') {
             $fieldPerms[$fieldName] = array(array('access CiviMail', 'schedule mailings', 'approve mailings', 'create mailings'));
         } elseif (in_array($fieldName, array('scheduled_date', 'scheduled_id'))) {
             $fieldPerms[$fieldName] = array(array('access CiviMail', 'schedule mailings'));
         } elseif (in_array($fieldName, array('approval_date', 'approver_id', 'approval_status_id', 'approval_note'))) {
             $fieldPerms[$fieldName] = array(array('access CiviMail', 'approve mailings'));
         } else {
             $fieldPerms[$fieldName] = array(array('access CiviMail', 'create mailings'));
         }
     }
     return $fieldPerms;
 }
示例#20
0
 /**
  * Set default values for the form.
  * the default values are retrieved from the database
  *
  *
  * @return void
  */
 public function setDefaultValues()
 {
     $continue = CRM_Utils_Request::retrieve('continue', 'String', $this, FALSE, NULL);
     $defaults = array();
     $defaults['dedupe_email'] = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'dedupe_email_default', NULL, FALSE);
     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;
         $defaults['location_type_id'] = $mailing->location_type_id;
         $defaults['email_selection_method'] = $mailing->email_selection_method;
         $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'] = CRM_Utils_Array::value('Include', $mailingGroups['civicrm_group']);
         $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']);
         }
     }
     //when the context is search hide the mailing recipients.
     $showHide = new CRM_Core_ShowHideBlocks();
     $showGroupSelector = TRUE;
     if ($this->_searchBasedMailing) {
         $showGroupSelector = FALSE;
         $formElements = array('includeGroups', 'excludeGroups', 'includeMailings', 'excludeMailings');
         $formValues = $this->controller->exportValues($this->_name);
         foreach ($formElements as $element) {
             if (!empty($formValues[$element])) {
                 $showGroupSelector = TRUE;
                 break;
             }
         }
     }
     if ($showGroupSelector) {
         $showHide->addShow("id-additional");
         $showHide->addHide("id-additional-show");
     } else {
         $showHide->addShow("id-additional-show");
         $showHide->addHide("id-additional");
     }
     $showHide->addToTemplate();
     return $defaults;
 }
示例#21
0
 /**
  * Send a reponse email informing the contact of the groups from which he
  * has been unsubscribed.
  *
  * @param string $queue_id      The queue event ID
  * @param array $groups         List of group IDs
  * @param bool $is_domain       Is this domain-level?
  * @param int $job              The job ID
  * @return void
  * @access public
  * @static
  */
 public static function send_unsub_response($queue_id, $groups, $is_domain = false, $job)
 {
     $config =& CRM_Core_Config::singleton();
     $domain =& CRM_Core_BAO_Domain::getDomain();
     $jobTable = CRM_Mailing_BAO_Job::getTableName();
     $mailingTable = CRM_Mailing_DAO_Mailing::getTableName();
     $contacts = CRM_Contact_DAO_Contact::getTableName();
     $email = CRM_Core_DAO_Email::getTableName();
     $queue = CRM_Mailing_Event_BAO_Queue::getTableName();
     //get the default domain email address.
     list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
     $dao =& new CRM_Mailing_BAO_Mailing();
     $dao->query("   SELECT * FROM {$mailingTable} \n                        INNER JOIN {$jobTable} ON\n                            {$jobTable}.mailing_id = {$mailingTable}.id \n                        WHERE {$jobTable}.id = {$job}");
     $dao->fetch();
     $component =& new CRM_Mailing_BAO_Component();
     if ($is_domain) {
         $component->id = $dao->optout_id;
     } else {
         $component->id = $dao->unsubscribe_id;
     }
     $component->find(true);
     $html = $component->body_html;
     if ($component->body_text) {
         $text = $component->body_text;
     } else {
         $text = CRM_Utils_String::htmlToText($component->body_html);
     }
     $eq =& new CRM_Core_DAO();
     $eq->query("SELECT     {$contacts}.preferred_mail_format as format,\n                    {$contacts}.id as contact_id,\n                    {$email}.email as email,\n                    {$queue}.hash as hash\n        FROM        {$contacts}\n        INNER JOIN  {$queue} ON {$queue}.contact_id = {$contacts}.id\n        INNER JOIN  {$email} ON {$queue}.email_id = {$email}.id\n        WHERE       {$queue}.id = " . CRM_Utils_Type::escape($queue_id, 'Integer'));
     $eq->fetch();
     if ($groups) {
         foreach ($groups as $key => $value) {
             if (!$value) {
                 unset($groups[$key]);
             }
         }
     }
     $message =& new Mail_Mime("\n");
     list($addresses, $urls) = CRM_Mailing_BAO_Mailing::getVerpAndUrls($job, $queue_id, $eq->hash, $eq->email);
     $bao =& new CRM_Mailing_BAO_Mailing();
     $bao->body_text = $text;
     $bao->body_html = $html;
     $tokens = $bao->getTokens();
     require_once 'CRM/Utils/Token.php';
     if ($eq->format == 'HTML' || $eq->format == 'Both') {
         $html = CRM_Utils_Token::replaceDomainTokens($html, $domain, true, $tokens['html']);
         $html = CRM_Utils_Token::replaceUnsubscribeTokens($html, $domain, $groups, true, $eq->contact_id, $eq->hash);
         $html = CRM_Utils_Token::replaceActionTokens($html, $addresses, $urls, true, $tokens['html']);
         $html = CRM_Utils_Token::replaceMailingTokens($html, $dao, null, $tokens['html']);
         $message->setHTMLBody($html);
     }
     if (!$html || $eq->format == 'Text' || $eq->format == 'Both') {
         $text = CRM_Utils_Token::replaceDomainTokens($text, $domain, false, $tokens['text']);
         $text = CRM_Utils_Token::replaceUnsubscribeTokens($text, $domain, $groups, false, $eq->contact_id, $eq->hash);
         $text = CRM_Utils_Token::replaceActionTokens($text, $addresses, $urls, false, $tokens['text']);
         $text = CRM_Utils_Token::replaceMailingTokens($text, $dao, null, $tokens['text']);
         $message->setTxtBody($text);
     }
     require_once 'CRM/Core/BAO/MailSettings.php';
     $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
     $headers = array('Subject' => $component->subject, 'From' => "\"{$domainEmailName}\" <do-not-reply@{$emailDomain}>", 'To' => $eq->email, 'Reply-To' => "do-not-reply@{$emailDomain}", 'Return-Path' => "do-not-reply@{$emailDomain}");
     $b =& CRM_Utils_Mail::setMimeParams($message);
     $h =& $message->headers($headers);
     $mailer =& $config->getMailer();
     PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('CRM_Core_Error', 'nullHandler'));
     if (is_object($mailer)) {
         $mailer->send($eq->email, $h, $b);
         CRM_Core_Error::setCallback();
     }
 }
示例#22
0
 /**
  * Send a reponse email informing the contact of the groups from which he
  * has been unsubscribed.
  *
  * @param string $queue_id      The queue event ID
  * @param array $groups         List of group IDs
  * @param bool $is_domain       Is this domain-level?
  * @param int $job              The job ID
  * @return void
  * @access public
  * @static
  */
 function send_unsub_response($queue_id, $groups, $is_domain = false, $job)
 {
     $config =& CRM_Core_Config::singleton();
     $domain =& CRM_Mailing_Event_BAO_Queue::getDomain($queue_id);
     $jobTable = CRM_Mailing_BAO_Job::getTableName();
     $mailingTable = CRM_Mailing_DAO_Mailing::getTableName();
     $contacts = CRM_Contact_DAO_Contact::getTableName();
     $email = CRM_Core_DAO_Email::getTableName();
     $queue = CRM_Mailing_Event_BAO_Queue::getTableName();
     $dao =& new CRM_Mailing_DAO_Mailing();
     $dao->query("   SELECT * FROM {$mailingTable} \n                        INNER JOIN {$jobTable} ON\n                            {$jobTable}.mailing_id = {$mailingTable}.id \n                        WHERE {$jobTable}.id = {$job}");
     $dao->fetch();
     $component =& new CRM_Mailing_BAO_Component();
     if ($is_domain) {
         $component->id = $dao->optout_id;
     } else {
         $component->id = $dao->unsubscribe_id;
     }
     $component->find(true);
     $html = $component->body_html;
     $text = $component->body_text;
     $eq =& new CRM_Core_DAO();
     $eq->query("SELECT     {$contacts}.preferred_mail_format as format,\n                    {$contacts}.id as contact_id,\n                    {$email}.email as email,\n                    {$queue}.hash as hash\n        FROM        {$contacts}\n        INNER JOIN  {$queue} ON {$queue}.contact_id = {$contacts}.id\n        INNER JOIN  {$email} ON {$queue}.email_id = {$email}.id\n        WHERE       {$queue}.id = " . CRM_Utils_Type::escape($queue_id, 'Integer'));
     $eq->fetch();
     $message =& new Mail_Mime("\n");
     require_once 'CRM/Utils/Token.php';
     if ($eq->format == 'HTML' || $eq->format == 'Both') {
         $html = CRM_Utils_Token::replaceDomainTokens($html, $domain, true);
         $html = CRM_Utils_Token::replaceUnsubscribeTokens($html, $domain, $groups, true, $eq->contact_id, $eq->hash);
         $message->setHTMLBody($html);
     }
     if (!$html || $eq->format == 'Text' || $eq->format == 'Both') {
         $text = CRM_Utils_Token::replaceDomainTokens($text, $domain, false);
         $text = CRM_Utils_Token::replaceUnsubscribeTokens($text, $domain, $groups, false, $eq->contact_id, $eq->hash);
         $message->setTxtBody($text);
     }
     $headers = array('Subject' => $component->subject, 'From' => ts('"%1 Administrator" <%2>', array(1 => $domain->name, 2 => "do-not-reply@{$domain->email_domain}")), 'To' => $eq->email, 'Reply-To' => "do-not-reply@{$domain->email_domain}", 'Return-Path' => "do-not-reply@{$domain->email_domain}");
     $b = $message->get();
     $h = $message->headers($headers);
     $mailer =& $config->getMailer();
     PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('CRM_Mailing_BAO_Mailing', 'catchSMTP'));
     $mailer->send($eq->email, $h, $b);
     CRM_Core_Error::setCallback();
 }
示例#23
0
/**
 * Adjust Metadata for submit action.
 *
 * The metadata is used for setting defaults, documentation & validation.
 *
 * @param array $spec
 *   Array of parameters determined by getfields.
 */
function _civicrm_api3_mailing_a_b_submit_spec(&$spec)
{
    $mailingFields = CRM_Mailing_DAO_Mailing::fields();
    $mailingAbFields = CRM_Mailing_DAO_MailingAB::fields();
    $spec['id'] = $mailingAbFields['id'];
    $spec['status'] = $mailingAbFields['status'];
    $spec['scheduled_date'] = $mailingFields['scheduled_date'];
    $spec['approval_date'] = $mailingFields['approval_date'];
    $spec['approval_status_id'] = $mailingFields['approval_status_id'];
    $spec['approval_note'] = $mailingFields['approval_note'];
    // Note: we'll pass through approval_* fields to the underlying mailing, but they may be ignored
    // if the user doesn't have suitable permission. If separate approvals are required, they must be provided
    // outside the A/B Test UI.
}
 /**
  * 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;
 }
示例#25
0
文件: Mailing.php 项目: kidaa30/yes
 /**
  * Returns the list of fields that can be exported
  *
  * @param bool $prefix
  *
  * @return array
  */
 static function &export($prefix = false)
 {
     if (!self::$_export) {
         self::$_export = array();
         $fields = self::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     self::$_export['mailing'] =& $fields[$name];
                 } else {
                     self::$_export[$name] =& $fields[$name];
                 }
             }
         }
     }
     return self::$_export;
 }
 /**
  * Example: Run an external SQL script
  *
  * @return TRUE on success
  * @throws Exception
  */
 public function upgrade_4620()
 {
     $this->ctx->log->info('Applying update for version 2.0');
     $mail = new CRM_Mailing_DAO_Mailing();
     $mail->domain_id = CRM_Core_Config::domainID();
     $mail->subject = "***All Transactional Emails***";
     $mail->url_tracking = TRUE;
     $mail->forward_replies = FALSE;
     $mail->auto_responder = FALSE;
     $mail->open_tracking = TRUE;
     if ($mail->find(TRUE)) {
         $mail->name = ts('Transaction Emails');
         $mail->save();
     }
     $url = CRM_Utils_System::url('civicrm/mte/smtp', 'reset=1', TRUE, NULL, FALSE, TRUE);
     CRM_Core_Session::setStatus(ts("Update the <a href={$url}>Mandrill settings</a> to configure it to use for Transactional Email and/or Civi Bulk Mail."));
     return TRUE;
 }