Пример #1
1
 /**
  * Class constructor.
  *
  * @param null $title
  * @param bool|int $action
  * @param bool $modal
  *
  * @throws \Exception
  */
 public function __construct($title = NULL, $action = CRM_Core_Action::NONE, $modal = TRUE)
 {
     parent::__construct($title, $modal, NULL, FALSE, TRUE);
     // New:            civicrm/mailing/send?reset=1
     // Re-use:         civicrm/mailing/send?reset=1&mid=%%mid%%
     // Continue:       civicrm/mailing/send?reset=1&mid=%%mid%%&continue=true
     $mid = CRM_Utils_Request::retrieve('mid', 'Positive');
     $continue = CRM_Utils_Request::retrieve('continue', 'String');
     if (!$mid) {
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/mailing/new'));
     }
     if ($mid && $continue) {
         //CRM-15979 - check if abtest exist for mailing then redirect accordingly
         $abtest = CRM_Mailing_BAO_MailingAB::getABTest($mid);
         if (!empty($abtest) && !empty($abtest->id)) {
             $redirect = CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/abtest/' . $abtest->id);
         } else {
             $redirect = CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/mailing/' . $mid);
         }
         CRM_Utils_System::redirect($redirect);
     }
     if ($mid && !$continue) {
         $clone = civicrm_api3('Mailing', 'clone', array('id' => $mid));
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/mailing/' . $clone['id']));
     }
 }
Пример #2
0
 /**
  * Class constructor.
  *
  * @param null $title
  * @param bool|int $action
  * @param bool $modal
  *
  * @throws \Exception
  */
 public function __construct($title = NULL, $action = CRM_Core_Action::NONE, $modal = TRUE)
 {
     parent::__construct($title, $modal, NULL, FALSE, TRUE);
     if (!defined('CIVICRM_CIVIMAIL_UI_LEGACY')) {
         // New:            civicrm/mailing/send?reset=1
         // Re-use:         civicrm/mailing/send?reset=1&mid=%%mid%%
         // Continue:       civicrm/mailing/send?reset=1&mid=%%mid%%&continue=true
         $mid = CRM_Utils_Request::retrieve('mid', 'Positive');
         $continue = CRM_Utils_Request::retrieve('continue', 'String');
         if (!$mid) {
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/mailing/new'));
         }
         if ($mid && $continue) {
             //CRM-15979 - check if abtest exist for mailing then redirect accordingly
             $abtest = CRM_Mailing_BAO_MailingAB::getABTest($mid);
             if (!empty($abtest) && !empty($abtest->id)) {
                 $redirect = CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/abtest/' . $abtest->id);
             } else {
                 $redirect = CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/mailing/' . $mid);
             }
             CRM_Utils_System::redirect($redirect);
         }
         if ($mid && !$continue) {
             $clone = civicrm_api3('Mailing', 'clone', array('id' => $mid));
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/mailing/' . $clone['id']));
         }
     }
     $mailingID = CRM_Utils_Request::retrieve('mid', 'String', $this, FALSE, NULL);
     // also get the text and html file
     $txtFile = CRM_Utils_Request::retrieve('txtFile', 'String', CRM_Core_DAO::$_nullObject, FALSE, NULL);
     $htmlFile = CRM_Utils_Request::retrieve('htmlFile', 'String', CRM_Core_DAO::$_nullObject, FALSE, NULL);
     $config = CRM_Core_Config::singleton();
     if ($txtFile && file_exists($config->uploadDir . $txtFile)) {
         $this->set('textFilePath', $config->uploadDir . $txtFile);
     }
     if ($htmlFile && file_exists($config->uploadDir . $htmlFile)) {
         $this->set('htmlFilePath', $config->uploadDir . $htmlFile);
     }
     $this->_stateMachine = new CRM_Mailing_StateMachine_Send($this, $action, $mailingID);
     // create and instantiate the pages
     $this->addPages($this->_stateMachine, $action);
     // add all the actions
     $uploadNames = array_merge(array('textFile', 'htmlFile'), CRM_Core_BAO_File::uploadNames());
     $config = CRM_Core_Config::singleton();
     $this->addActions($config->uploadDir, $uploadNames);
 }
Пример #3
0
/**
 * Send A/B mail to A/B recipients respectively.
 *
 * @param array $params
 *
 * @return array
 * @throws API_Exception
 */
function civicrm_api3_mailing_a_b_submit($params)
{
    civicrm_api3_verify_mandatory($params, 'CRM_Mailing_DAO_MailingAB', array('id', 'status'));
    if (!isset($params['scheduled_date']) && !isset($updateParams['approval_date'])) {
        throw new API_Exception("Missing parameter scheduled_date and/or approval_date");
    }
    $dao = new CRM_Mailing_DAO_MailingAB();
    $dao->id = $params['id'];
    if (!$dao->find(TRUE)) {
        throw new API_Exception("Failed to locate A/B test by ID");
    }
    if (empty($dao->mailing_id_a) || empty($dao->mailing_id_b) || empty($dao->mailing_id_c)) {
        throw new API_Exception("Missing mailing IDs for A/B test");
    }
    $submitParams = CRM_Utils_Array::subset($params, array('scheduled_date', 'approval_date', 'approval_note', 'approval_status_id'));
    switch ($params['status']) {
        case 'Testing':
            if (!empty($dao->status) && $dao->status != 'Draft') {
                throw new API_Exception("Cannot transition to state 'Testing'");
            }
            civicrm_api3('Mailing', 'submit', $submitParams + array('id' => $dao->mailing_id_a, '_skip_evil_bao_auto_recipients_' => 0));
            civicrm_api3('Mailing', 'submit', $submitParams + array('id' => $dao->mailing_id_b, '_skip_evil_bao_auto_recipients_' => 1));
            CRM_Mailing_BAO_MailingAB::distributeRecipients($dao);
            break;
        case 'Final':
            if ($dao->status != 'Testing') {
                throw new API_Exception("Cannot transition to state 'Final'");
            }
            civicrm_api3('Mailing', 'submit', $submitParams + array('id' => $dao->mailing_id_c, '_skip_evil_bao_auto_recipients_' => 1));
            break;
        default:
            throw new API_Exception("Unrecognized submission status");
    }
    return civicrm_api3('MailingAB', 'create', array('id' => $dao->id, 'status' => $params['status'], 'options' => array('reload' => 1)));
}
Пример #4
0
 /**
  * @return string
  */
 public function run()
 {
     $this->_mailing_id = CRM_Utils_Request::retrieve('mid', 'Positive', $this);
     //CRM-15979 - check if abtest exist for mailing then redirect accordingly
     $abtest = CRM_Mailing_BAO_MailingAB::getABTest($this->_mailing_id);
     if (!empty($abtest) && !empty($abtest->id)) {
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/abtest/' . $abtest->id));
     }
     // check that the user has permission to access mailing id
     CRM_Mailing_BAO_Mailing::checkPermission($this->_mailing_id);
     $report = CRM_Mailing_BAO_Mailing::report($this->_mailing_id);
     // get contents of mailing
     CRM_Mailing_BAO_Mailing::getMailingContent($report, $this);
     // assign backurl
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     if ($context == 'activitySelector') {
         $backUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$cid}&selectedChild=activity");
         $backUrlTitle = ts('Back to Activities');
     } elseif ($context == 'activity') {
         $atype = CRM_Utils_Request::retrieve('atype', 'Positive', $this);
         $aid = CRM_Utils_Request::retrieve('aid', 'Positive', $this);
         $backUrl = CRM_Utils_System::url('civicrm/activity/view', "atype={$atype}&action=view&reset=1&id={$aid}&cid={$cid}&context=activity");
         $backUrlTitle = ts('Back to Activity');
     } elseif ($context == 'mailing') {
         $backUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$cid}&selectedChild=mailing");
         $backUrlTitle = ts('Back to Mailing');
     } else {
         $backUrl = CRM_Utils_System::url('civicrm/mailing', 'reset=1');
         $backUrlTitle = ts('Back to CiviMail');
     }
     $this->assign('backUrl', $backUrl);
     $this->assign('backUrlTitle', $backUrlTitle);
     $this->assign('report', $report);
     CRM_Utils_System::setTitle(ts('CiviMail Report: %1', array(1 => $report['mailing']['name'])));
     return CRM_Core_Page::run();
 }