From 0083c73f4e19666b6a725dd70825a672a7042777 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 25 Aug 2015 10:34:27 -0700 Subject: [PATCH] CRM-15578 - CiviMail - Remove legacy composition UI --- CRM/Contact/Task.php | 47 +- CRM/Mailing/Controller/Send.php | 78 +--- CRM/Mailing/Form/Group.php | 610 -------------------------- CRM/Mailing/Form/Schedule.php | 361 --------------- CRM/Mailing/Form/Settings.php | 261 ----------- CRM/Mailing/Form/Test.php | 391 ----------------- CRM/Mailing/Form/Upload.php | 704 ------------------------------ CRM/Mailing/StateMachine/Send.php | 76 ---- CRM/Mailing/xml/Menu/Mailing.xml | 7 - CRM/Utils/Token.php | 10 +- 10 files changed, 30 insertions(+), 2515 deletions(-) delete mode 100644 CRM/Mailing/Form/Group.php delete mode 100644 CRM/Mailing/Form/Schedule.php delete mode 100644 CRM/Mailing/Form/Settings.php delete mode 100644 CRM/Mailing/Form/Test.php delete mode 100644 CRM/Mailing/Form/Upload.php delete mode 100644 CRM/Mailing/StateMachine/Send.php diff --git a/CRM/Contact/Task.php b/CRM/Contact/Task.php index 56510a9aba..7b1e47865a 100644 --- a/CRM/Contact/Task.php +++ b/CRM/Contact/Task.php @@ -242,45 +242,14 @@ class CRM_Contact_Task { ); } - if (defined('CIVICRM_CIVIMAIL_UI_LEGACY')) { - if (CRM_Core_Permission::access('CiviMail')) { - self::$_tasks[self::CREATE_MAILING] = array( - 'title' => ts('Schedule/Send a Mass Mailing'), - 'class' => array( - 'CRM_Mailing_Form_Group', - 'CRM_Mailing_Form_Settings', - 'CRM_Mailing_Form_Upload', - 'CRM_Mailing_Form_Test', - 'CRM_Mailing_Form_Schedule', - ), - 'result' => FALSE, - ); - } - elseif (CRM_Mailing_Info::workflowEnabled() && - CRM_Core_Permission::check('create mailings') - ) { - self::$_tasks[self::CREATE_MAILING] = array( - 'title' => ts('Create a Mass Mailing'), - 'class' => array( - 'CRM_Mailing_Form_Group', - 'CRM_Mailing_Form_Settings', - 'CRM_Mailing_Form_Upload', - 'CRM_Mailing_Form_Test', - ), - 'result' => FALSE, - ); - } - } - else { - if (CRM_Core_Permission::access('CiviMail') - || (CRM_Mailing_Info::workflowEnabled() && CRM_Core_Permission::check('create mailings')) - ) { - self::$_tasks[self::CREATE_MAILING] = array( - 'title' => ts('Schedule/Send a Mass Mailing'), - 'class' => 'CRM_Mailing_Form_Task_AdhocMailing', - 'result' => FALSE, - ); - } + if (CRM_Core_Permission::access('CiviMail') + || (CRM_Mailing_Info::workflowEnabled() && CRM_Core_Permission::check('create mailings')) + ) { + self::$_tasks[self::CREATE_MAILING] = array( + 'title' => ts('Schedule/Send a Mass Mailing'), + 'class' => 'CRM_Mailing_Form_Task_AdhocMailing', + 'result' => FALSE, + ); } self::$_tasks += CRM_Core_Component::taskList(); diff --git a/CRM/Mailing/Controller/Send.php b/CRM/Mailing/Controller/Send.php index 7a772096c2..acf3fd2a2b 100644 --- a/CRM/Mailing/Controller/Send.php +++ b/CRM/Mailing/Controller/Send.php @@ -46,69 +46,29 @@ class CRM_Mailing_Controller_Send extends CRM_Core_Controller { 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); + // 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); } - 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'])); + else { + $redirect = CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/mailing/' . $mid); } + CRM_Utils_System::redirect($redirect); } - - $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 ($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'])); } - - 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 - ); } } diff --git a/CRM/Mailing/Form/Group.php b/CRM/Mailing/Form/Group.php deleted file mode 100644 index dcca8afc62..0000000000 --- a/CRM/Mailing/Form/Group.php +++ /dev/null @@ -1,610 +0,0 @@ -default mailbox has not been configured. You will find more info in our online user and administrator guide.', array( - 1 => CRM_Utils_System::url('civicrm/admin/mailSettings', 'reset=1'), - 2 => "http://book.civicrm.org/user/advanced-configuration/email-system-configuration/", - ))); - } - - $this->_mailingID = CRM_Utils_Request::retrieve('mid', 'Integer', $this, FALSE, NULL); - - // when user come from search context. - $this->_searchBasedMailing = CRM_Contact_Form_Search::isSearchContext($this->get('context')); - if ($this->_searchBasedMailing) { - $searchParams = $this->controller->exportValues(); - // number of records that were selected - All or Few. - $this->_resultSelectOption = $searchParams['radio_ts']; - if (CRM_Utils_Array::value('task', $searchParams) == 20) { - parent::preProcess(); - } - } - - $session = CRM_Core_Session::singleton(); - if ($this->_searchBasedMailing) { - $config = CRM_Core_Config::singleton(); - $path = CRM_Utils_Array::value($config->userFrameworkURLVar, $_GET); - $qfKey = CRM_Utils_Array::value('qfKey', $_GET); - if ($qfKey) { - $session->pushUserContext(CRM_Utils_System::url($path, "qfKey=$qfKey")); - } - else { - $session->pushUserContext(CRM_Utils_System::url('civicrm/mailing', 'reset=1')); - } - } - elseif (strpos($session->readUserContext(), 'civicrm/mailing') === FALSE) { - // use previous context unless mailing is not schedule, CRM-4290 - $session->pushUserContext(CRM_Utils_System::url('civicrm/mailing', 'reset=1')); - } - } - - /** - * 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; - } - - /** - * Build the form object. - * - * @return void - */ - public function buildQuickForm() { - - //get the context - $context = $this->get('context'); - if ($this->_searchBasedMailing) { - $context = 'search'; - } - $this->assign('context', $context); - - $this->add('text', 'name', ts('Name Your Mailing'), - CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Mailing', 'name'), - TRUE - ); - - $hiddenMailingGroup = NULL; - $campaignId = NULL; - - //CRM-7362 --add campaigns. - if ($this->_mailingID) { - $campaignId = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingID, 'campaign_id'); - $hiddenMailingGroup = CRM_Mailing_BAO_Mailing::hiddenMailingGroup($this->_mailingID); - } - CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId); - - //dedupe on email option - $this->addElement('checkbox', 'dedupe_email', ts('Remove duplicate emails?')); - - // location types - $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('id' => 'display_name')); - $this->addElement('select', 'location_type_id', ts("Location Type"), array('' => ts('Automatic')) + $locationTypes); - - $methods = CRM_Core_SelectValues::emailSelectMethods(); - $this->addElement('select', 'email_selection_method', ts("Email Selection Method"), $methods); - - //get the mailing groups. - $groups = CRM_Core_PseudoConstant::nestedGroup('Mailing'); - if ($hiddenMailingGroup) { - $groups[$hiddenMailingGroup] - = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $hiddenMailingGroup, 'title'); - } - - $mailings = CRM_Mailing_PseudoConstant::completed(); - if (!$mailings) { - $mailings = array(); - } - - // run the groups through a hook so users can trim it if needed - CRM_Utils_Hook::mailingGroups($this, $groups, $mailings); - - //when the context is search add base group's. - if ($this->_searchBasedMailing) { - //CRM-16600 Include Smart Groups in Unsubscribe list as that matches - //all other practices in CiviMail - $this->add('select', 'baseGroup', - ts('Unsubscription Group'), - array( - '' => ts('- select -'), - ) + $groups, - TRUE, - array('class' => 'crm-select2 huge') - ); - } - - $select2style = array( - 'multiple' => TRUE, - 'style' => 'width: 100%; max-width: 60em;', - 'class' => 'crm-select2', - 'placeholder' => ts('- select -'), - ); - - $this->add('select', 'includeGroups', - ts('Include Group(s)'), - $groups, - !$this->_searchBasedMailing, - $select2style - ); - - $this->add('select', 'excludeGroups', - ts('Exclude Group(s)'), - $groups, - FALSE, - $select2style - ); - - $this->add('select', 'includeMailings', - ts('INCLUDE Recipients of These Mailing(s)') . ' ', - $mailings, - FALSE, - $select2style - ); - $this->add('select', 'excludeMailings', - ts('EXCLUDE Recipients of These Mailing(s)') . ' ', - $mailings, - FALSE, - $select2style - ); - - $this->addFormRule(array('CRM_Mailing_Form_Group', 'formRule')); - - $buttons = array( - array( - 'type' => 'next', - 'name' => ts('Next'), - 'spacing' => '                 ', - 'isDefault' => TRUE, - ), - array( - 'type' => 'submit', - 'name' => ts('Save & Continue Later'), - ), - array( - 'type' => 'cancel', - 'name' => ts('Cancel'), - ), - ); - - $this->addButtons($buttons); - - $this->assign('groupCount', count($groups)); - $this->assign('mailingCount', count($mailings)); - if (count($groups) == 0 && count($mailings) == 0 && !$this->_searchBasedMailing) { - CRM_Core_Error::statusBounce("To send a mailing, you must have a valid group of recipients - either at least one group that's a Mailing List or at least one previous mailing or start from a search"); - } - } - - public function postProcess() { - $values = $this->controller->exportValues($this->_name); - - //build hidden smart group. when user want to send mailing - //through search contact-> more action -> send Mailing. CRM-3711 - $groups = array(); - if ($this->_searchBasedMailing && $this->_contactIds) { - $session = CRM_Core_Session::singleton(); - - if ($this->_resultSelectOption == 'ts_sel') { - // create a static grp if only a subset of result set was selected: - - $randID = md5(time()); - $grpTitle = "Hidden Group {$randID}"; - $grpID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $grpTitle, 'id', 'title'); - - if (!$grpID) { - $groupParams = array( - 'title' => $grpTitle, - 'is_active' => 1, - 'is_hidden' => 1, - 'group_type' => array('2' => 1), - ); - - $group = CRM_Contact_BAO_Group::create($groupParams); - $grpID = $group->id; - - CRM_Contact_BAO_GroupContact::addContactsToGroup($this->_contactIds, $group->id); - - $newGroupTitle = "Hidden Group {$grpID}"; - $groupParams = array( - 'id' => $grpID, - 'name' => CRM_Utils_String::titleToVar($newGroupTitle), - 'title' => $newGroupTitle, - 'group_type' => array('2' => 1), - ); - $group = CRM_Contact_BAO_Group::create($groupParams); - } - - // note at this point its a static group - $smartGroupId = $grpID; - } - else { - //get the hidden smart group id. - $ssId = $this->get('ssID'); - $hiddenSmartParams = array( - 'group_type' => array('2' => 1), - 'form_values' => $this->get('formValues'), - 'saved_search_id' => $ssId, - 'search_custom_id' => $this->get('customSearchID'), - 'search_context' => $this->get('context'), - ); - - list($smartGroupId, $savedSearchId) = CRM_Contact_BAO_Group::createHiddenSmartGroup($hiddenSmartParams); - - //set the saved search id. - if (!$ssId) { - if ($savedSearchId) { - $this->set('ssID', $savedSearchId); - } - else { - CRM_Core_Error::fatal(); - } - } - } - - //get the base group for this mailing, CRM-3711 - $groups['base'] = array($values['baseGroup']); - $values['includeGroups'][] = $smartGroupId; - } - - foreach ( - array( - 'name', - 'group_id', - 'search_id', - 'search_args', - 'campaign_id', - 'dedupe_email', - 'location_type_id', - 'email_selection_method', - ) as $n - ) { - if (!empty($values[$n])) { - $params[$n] = $values[$n]; - } - } - - $qf_Group_submit = $this->controller->exportValue($this->_name, '_qf_Group_submit'); - $this->set('name', $params['name']); - - $inGroups = $values['includeGroups']; - $outGroups = $values['excludeGroups']; - $inMailings = $values['includeMailings']; - $outMailings = $values['excludeMailings']; - - if (is_array($inGroups)) { - foreach ($inGroups as $key => $id) { - if ($id) { - $groups['include'][] = $id; - } - } - } - if (is_array($outGroups)) { - foreach ($outGroups as $key => $id) { - if ($id) { - $groups['exclude'][] = $id; - } - } - } - - $mailings = array(); - if (is_array($inMailings)) { - foreach ($inMailings as $key => $id) { - if ($id) { - $mailings['include'][] = $id; - } - } - } - if (is_array($outMailings)) { - foreach ($outMailings as $key => $id) { - if ($id) { - $mailings['exclude'][] = $id; - } - } - } - - $session = CRM_Core_Session::singleton(); - $params['groups'] = $groups; - $params['mailings'] = $mailings; - $ids = array(); - if ($this->get('mailing_id')) { - - // don't create a new mailing if already exists - $ids['mailing_id'] = $this->get('mailing_id'); - - $groupTableName = CRM_Contact_BAO_Group::getTableName(); - $mailingTableName = CRM_Mailing_BAO_Mailing::getTableName(); - - // delete previous includes/excludes, if mailing already existed - foreach (array('groups', 'mailings') as $entity) { - $mg = new CRM_Mailing_DAO_MailingGroup(); - $mg->mailing_id = $ids['mailing_id']; - $mg->entity_table = ($entity == 'groups') ? $groupTableName : $mailingTableName; - $mg->find(); - while ($mg->fetch()) { - $mg->delete(); - } - } - } - else { - // new mailing, so lets set the created_id - $session = CRM_Core_Session::singleton(); - $params['created_id'] = $session->get('userID'); - $params['created_date'] = date('YmdHis'); - } - $mailing = CRM_Mailing_BAO_Mailing::create($params, $ids); - $this->set('mailing_id', $mailing->id); - - $dedupeEmail = FALSE; - if (isset($params['dedupe_email'])) { - $dedupeEmail = $params['dedupe_email']; - } - - // mailing id should be added to the form object - $this->_mailingID = $mailing->id; - - // also compute the recipients and store them in the mailing recipients table - CRM_Mailing_BAO_Mailing::getRecipients( - $mailing->id, - $mailing->id, - TRUE, - $dedupeEmail - ); - - $count = CRM_Mailing_BAO_Recipients::mailingSize($mailing->id); - $this->set('count', $count); - $this->assign('count', $count); - $this->set('groups', $groups); - $this->set('mailings', $mailings); - - if ($qf_Group_submit) { - //when user perform mailing from search context - //redirect it to search result CRM-3711. - $ssID = $this->get('ssID'); - $context = $this->get('context'); - if ($ssID && $this->_searchBasedMailing) { - if ($this->_action == CRM_Core_Action::BASIC) { - $fragment = 'search'; - } - elseif ($this->_action == CRM_Core_Action::PROFILE) { - $fragment = 'search/builder'; - } - elseif ($this->_action == CRM_Core_Action::ADVANCED) { - $fragment = 'search/advanced'; - } - else { - $fragment = 'search/custom'; - } - - $context = $this->get('context'); - if (!CRM_Contact_Form_Search::isSearchContext($context)) { - $context = 'search'; - } - $urlParams = "force=1&reset=1&ssID={$ssID}&context={$context}"; - - $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); - if (CRM_Utils_Rule::qfKey($qfKey)) { - $urlParams .= "&qfKey=$qfKey"; - } - - $draftURL = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1'); - $status = ts("You can continue later by clicking the 'Continue' action to resume working on it.
From Draft and Unscheduled Mailings.", array(1 => $draftURL)); - - // Redirect user to search. - $url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $urlParams); - } - else { - $status = ts("Click the 'Continue' action to resume working on it."); - $url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1'); - } - CRM_Core_Session::setStatus($status, ts('Mailing Saved'), 'success'); - return $this->controller->setDestination($url); - } - } - - /** - * Display Name of the form. - * - * - * @return string - */ - public function getTitle() { - return ts('Select Recipients'); - } - - /** - * Global validation rules for the form. - * - * @param array $fields - * Posted values of the form. - * - * @return array - * list of errors to be posted back to the form - */ - public static function formRule($fields) { - $errors = array(); - if (isset($fields['includeGroups']) && - is_array($fields['includeGroups']) && - isset($fields['excludeGroups']) && - is_array($fields['excludeGroups']) - ) { - $checkGroups = array(); - $checkGroups = array_intersect($fields['includeGroups'], $fields['excludeGroups']); - if (!empty($checkGroups)) { - $errors['excludeGroups'] = ts('Cannot have same groups in Include Group(s) and Exclude Group(s).'); - } - } - - if (isset($fields['includeMailings']) && - is_array($fields['includeMailings']) && - isset($fields['excludeMailings']) && - is_array($fields['excludeMailings']) - ) { - $checkMailings = array(); - $checkMailings = array_intersect($fields['includeMailings'], $fields['excludeMailings']); - if (!empty($checkMailings)) { - $errors['excludeMailings'] = ts('Cannot have same mail in Include mailing(s) and Exclude mailing(s).'); - } - } - - if (!empty($fields['search_id']) && - empty($fields['group_id']) - ) { - $errors['group_id'] = ts('You must select a group to filter on'); - } - - if (empty($fields['search_id']) && - !empty($fields['group_id']) - ) { - $errors['search_id'] = ts('You must select a search to filter'); - } - - if (!empty($fields['location_type_id'])) { - if ($fields['email_selection_method'] == 'automatic') { - $errors['location_type_id'] = ts("If 'Email Selection Method' is automatic, you are not allowed to choose any 'Location Type'"); - } - } - elseif ($fields['email_selection_method'] != 'automatic') { - $errors['email_selection_method'] = ts("If 'Location Type' is not selected, you must set the 'Email Selection Method' to automatic as well."); - } - - return empty($errors) ? TRUE : $errors; - } - -} diff --git a/CRM/Mailing/Form/Schedule.php b/CRM/Mailing/Form/Schedule.php deleted file mode 100644 index bed7590956..0000000000 --- a/CRM/Mailing/Form/Schedule.php +++ /dev/null @@ -1,361 +0,0 @@ -get('ssID'); - $this->assign('ssid', $ssID); - $this->_searchBasedMailing = CRM_Contact_Form_Search::isSearchContext($this->get('context')); - if (CRM_Contact_Form_Search::isSearchContext($this->get('context')) && !$ssID) { - $params = array(); - $result = CRM_Core_BAO_PrevNextCache::getSelectedContacts(); - $this->assign("value", $result); - } - $this->_mailingID = $this->get('mailing_id'); - $this->_scheduleFormOnly = FALSE; - if (!$this->_mailingID) { - $this->_mailingID = CRM_Utils_Request::retrieve('mid', 'Integer', $this, TRUE); - $this->_scheduleFormOnly = TRUE; - } - } - - /** - * Set default values for the form. - * - * - * @return void - */ - public function setDefaultValues() { - $defaults = array(); - if ($this->_scheduleFormOnly) { - $count = CRM_Mailing_BAO_Recipients::mailingSize($this->_mailingID); - } - else { - $count = $this->get('count'); - } - $this->assign('count', $count); - $defaults['now'] = 1; - return $defaults; - } - - /** - * Build the form object for the last step of the mailing wizard. - * - * @param - * - * @return void - */ - public function buildQuickform() { - $this->addDateTime('start_date', ts('Schedule Mailing'), FALSE, array('formatType' => 'mailing')); - - $this->addElement('checkbox', 'now', ts('Send Immediately')); - - $this->addFormRule(array('CRM_Mailing_Form_Schedule', 'formRule'), $this); - - if ($this->_scheduleFormOnly) { - $title = ts('Schedule Mailing') . ' - ' . CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', - $this->_mailingID, - 'name' - ); - CRM_Utils_System::setTitle($title); - $buttons = array( - array( - 'type' => 'next', - 'name' => ts('Submit Mailing'), - 'spacing' => '                 ', - 'isDefault' => TRUE, - ), - array( - 'type' => 'cancel', - 'name' => ts('Cancel'), - ), - ); - } - else { - //FIXME : currently we are hiding save an continue later when - //search base mailing, we should handle it when we fix CRM-3876 - if ($this->_searchBasedMailing) { - $buttons = array( - array( - 'type' => 'back', - 'name' => ts('Previous'), - ), - array( - 'type' => 'next', - 'name' => ts('Submit Mailing'), - 'spacing' => '                 ', - 'isDefault' => TRUE, - ), - ); - } - else { - $buttons = array( - array( - 'type' => 'back', - 'name' => ts('Previous'), - ), - array( - 'type' => 'next', - 'name' => ts('Submit Mailing'), - 'spacing' => '                 ', - 'isDefault' => TRUE, - 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');"), - ), - array( - 'type' => 'cancel', - 'name' => ts('Continue Later'), - ), - ); - } - } - $this->addButtons($buttons); - - if (CRM_Mailing_Info::workflowEnabled() && - $this->_scheduleFormOnly - ) { - // add the preview elements - $preview = array(); - $preview['type'] = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingID, 'body_html') ? 'html' : 'text'; - $preview['subject'] = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', - $this->_mailingID, - 'subject' - ); - - $mailingKey = $this->_mailingID; - if ($hash = CRM_Mailing_BAO_Mailing::getMailingHash($mailingKey)) { - $mailingKey = $hash; - } - - $preview['viewURL'] = CRM_Utils_System::url('civicrm/mailing/view', "reset=1&id={$mailingKey}"); - - $preview['attachment'] = CRM_Core_BAO_File::attachmentInfo('civicrm_mailing', $this->_mailingID); - - $this->assign_by_ref('preview', $preview); - } - } - - /** - * Form rule to validate the date selector and/or if we should deliver - * immediately. - * - * Warning: if you make changes here, be sure to also make them in - * Retry.php - * - * @param array $params - * The form values. - * - * @param $files - * @param $self - * - * @return bool - * True if either we deliver immediately, or the - * date is properly set. - */ - public static function formRule($params, $files, $self) { - if (!empty($params['_qf_Schedule_submit'])) { - //when user perform mailing from search context - //redirect it to search result CRM-3711. - $ssID = $self->get('ssID'); - if ($ssID && $self->_searchBasedMailing) { - if ($self->_action == CRM_Core_Action::BASIC) { - $fragment = 'search'; - } - elseif ($self->_action == CRM_Core_Action::PROFILE) { - $fragment = 'search/builder'; - } - elseif ($self->_action == CRM_Core_Action::ADVANCED) { - $fragment = 'search/advanced'; - } - else { - $fragment = 'search/custom'; - } - - $draftURL = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1'); - $status = ts("Your mailing has been saved. You can continue later by clicking the 'Continue' action to resume working on it.
From Draft and Unscheduled Mailings.", array(1 => $draftURL)); - CRM_Core_Session::setStatus($status, ts('Mailing Saved'), 'success'); - - //replace user context to search. - $context = $self->get('context'); - if (!CRM_Contact_Form_Search::isSearchContext($context)) { - $context = 'search'; - } - - $urlParams = "force=1&reset=1&ssID={$ssID}&context={$context}"; - $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $self); - if (CRM_Utils_Rule::qfKey($qfKey)) { - $urlParams .= "&qfKey=$qfKey"; - } - $url = CRM_Utils_System::url('civicrm/contact/' . $fragment, "force=1&reset=1&ssID={$ssID}"); - } - else { - $status = ts("Click the 'Continue' action to resume working on it."); - $url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1'); - } - CRM_Core_Session::setStatus($status, ts('Mailing Saved'), 'success'); - CRM_Utils_System::redirect($url); - } - if (isset($params['now']) || CRM_Utils_Array::value('_qf_Schedule_back', $params) == ts('Previous')) { - return TRUE; - } - - if (CRM_Utils_Date::format(CRM_Utils_Date::processDate($params['start_date'], - $params['start_date_time'] - )) < CRM_Utils_Date::format(date('YmdHi00')) - ) { - return array( - 'start_date' => ts('Start date cannot be earlier than the current time.'), - ); - } - return TRUE; - } - - /** - * Process the posted form values. Create and schedule a mailing. - * - * @param - * - * @return void - */ - public function postProcess() { - $params = array(); - - $params['mailing_id'] = $ids['mailing_id'] = $this->_mailingID; - - if (empty($params['mailing_id'])) { - CRM_Core_Error::fatal(ts('Could not find a mailing id')); - } - - foreach (array('now', 'start_date', 'start_date_time') as $parameter) { - $params[$parameter] = $this->controller->exportValue($this->_name, $parameter); - } - - // Previously, we checked if $mailing->is_template, and did *not* - // schedule if it was set. Discussed with Lobo, removed that check - // as it appeared to prevent mails being scheduled if they were - // saved as a template, and this wasn't the documented behaviour. - // $saveTemplate = $this->controller->exportValue('saveTemplate'); - if ($params['now']) { - $params['scheduled_date'] = date('YmdHis'); - } - else { - $params['scheduled_date'] = CRM_Utils_Date::processDate($params['start_date'] . ' ' . $params['start_date_time']); - } - - $session = CRM_Core_Session::singleton(); - - // set the scheduled_id - $params['scheduled_id'] = $session->get('userID'); - - // set approval details if workflow is not enabled - if (!CRM_Mailing_Info::workflowEnabled()) { - $params['approver_id'] = $session->get('userID'); - $params['approval_date'] = date('YmdHis'); - $params['approval_status_id'] = 1; - } - else { - // reset them in case this mailing was rejected - $params['approver_id'] = 'null'; - $params['approval_date'] = 'null'; - $params['approval_status_id'] = 'null'; - } - - /* Build the mailing object */ - CRM_Mailing_BAO_Mailing::create($params, $ids); - - //when user perform mailing from search context - //redirect it to search result CRM-3711. - $ssID = $this->get('ssID'); - if ($ssID && $this->_searchBasedMailing && !CRM_Mailing_Info::workflowEnabled()) { - if ($this->_action == CRM_Core_Action::BASIC) { - $fragment = 'search'; - } - elseif ($this->_action == CRM_Core_Action::PROFILE) { - $fragment = 'search/builder'; - } - elseif ($this->_action == CRM_Core_Action::ADVANCED) { - $fragment = 'search/advanced'; - } - else { - $fragment = 'search/custom'; - } - $context = $this->get('context'); - if (!CRM_Contact_Form_Search::isSearchContext($context)) { - $context = 'search'; - } - $urlParams = "force=1&reset=1&ssID={$ssID}&context={$context}"; - $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); - if (CRM_Utils_Rule::qfKey($qfKey)) { - $urlParams .= "&qfKey=$qfKey"; - } - - $url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $urlParams); - return $this->controller->setDestination($url); - } - - $session = CRM_Core_Session::singleton(); - $session->pushUserContext(CRM_Utils_System::url('civicrm/mailing/browse/scheduled', - 'reset=1&scheduled=true' - )); - } - - /** - * Display Name of the form. - * - * - * @return string - */ - public function getTitle() { - return ts('Schedule or Send'); - } - -} diff --git a/CRM/Mailing/Form/Settings.php b/CRM/Mailing/Form/Settings.php deleted file mode 100644 index 3f485a5616..0000000000 --- a/CRM/Mailing/Form/Settings.php +++ /dev/null @@ -1,261 +0,0 @@ -get('ssID'); - $this->assign('ssid', $ssID); - $this->_searchBasedMailing = CRM_Contact_Form_Search::isSearchContext($this->get('context')); - if (CRM_Contact_Form_Search::isSearchContext($this->get('context')) && !$ssID) { - $params = array(); - $result = CRM_Core_BAO_PrevNextCache::getSelectedContacts(); - $this->assign("value", $result); - } - } - - /** - * 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; - } - - /** - * Build the form object. - * - * @return void - */ - public function buildQuickForm() { - - $this->addElement('checkbox', 'override_verp', ts('Track Replies?')); - - $defaults['override_verp'] = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, - 'track_civimail_replies', NULL, FALSE - ); - - $this->add('checkbox', 'forward_replies', ts('Forward Replies?')); - $defaults['forward_replies'] = FALSE; - - $this->add('checkbox', 'url_tracking', ts('Track Click-throughs?')); - $defaults['url_tracking'] = TRUE; - - $this->add('checkbox', 'open_tracking', ts('Track Opens?')); - $defaults['open_tracking'] = TRUE; - - $this->add('checkbox', 'auto_responder', ts('Auto-respond to Replies?')); - $defaults['auto_responder'] = FALSE; - - $this->add('select', 'visibility', ts('Mailing Visibility'), CRM_Core_SelectValues::groupVisibility(), TRUE); - - $this->add('select', 'reply_id', ts('Auto-responder'), - CRM_Mailing_PseudoConstant::component('Reply'), TRUE - ); - - $this->add('select', 'unsubscribe_id', ts('Unsubscribe Message'), - CRM_Mailing_PseudoConstant::component('Unsubscribe'), TRUE - ); - - $this->add('select', 'resubscribe_id', ts('Resubscribe Message'), - CRM_Mailing_PseudoConstant::component('Resubscribe'), TRUE - ); - - $this->add('select', 'optout_id', ts('Opt-out Message'), - CRM_Mailing_PseudoConstant::component('OptOut'), TRUE - ); - - $buttons = array( - array( - 'type' => 'back', - 'name' => ts('Previous'), - ), - array( - 'type' => 'next', - 'name' => ts('Next'), - 'spacing' => '                 ', - 'isDefault' => TRUE, - ), - array( - 'type' => 'submit', - 'name' => ts('Save & Continue Later'), - ), - array( - 'type' => 'cancel', - 'name' => ts('Cancel'), - ), - ); - - $this->addButtons($buttons); - - $this->setDefaults($defaults); - } - - public function postProcess() { - $params = $ids = array(); - - $session = CRM_Core_Session::singleton(); - $params['created_id'] = $session->get('userID'); - - $uploadParams = array('reply_id', 'unsubscribe_id', 'optout_id', 'resubscribe_id'); - $uploadParamsBoolean = array('override_verp', 'forward_replies', 'url_tracking', 'open_tracking', 'auto_responder'); - - $qf_Settings_submit = $this->controller->exportValue($this->_name, '_qf_Settings_submit'); - - foreach ($uploadParams as $key) { - $params[$key] = $this->controller->exportvalue($this->_name, $key); - $this->set($key, $this->controller->exportvalue($this->_name, $key)); - } - - foreach ($uploadParamsBoolean as $key) { - if ($this->controller->exportvalue($this->_name, $key)) { - $params[$key] = TRUE; - } - else { - $params[$key] = FALSE; - } - $this->set($key, $this->controller->exportvalue($this->_name, $key)); - } - - $params['visibility'] = $this->controller->exportvalue($this->_name, 'visibility'); - - // 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?’ - $params['override_verp'] = !$params['override_verp']; - - $ids['mailing_id'] = $this->get('mailing_id'); - - // update mailing - CRM_Mailing_BAO_Mailing::create($params, $ids); - - if ($qf_Settings_submit) { - //when user perform mailing from search context - //redirect it to search result CRM-3711. - $ssID = $this->get('ssID'); - if ($ssID && $this->_searchBasedMailing) { - if ($this->_action == CRM_Core_Action::BASIC) { - $fragment = 'search'; - } - elseif ($this->_action == CRM_Core_Action::PROFILE) { - $fragment = 'search/builder'; - } - elseif ($this->_action == CRM_Core_Action::ADVANCED) { - $fragment = 'search/advanced'; - } - else { - $fragment = 'search/custom'; - } - - $context = $this->get('context'); - if (!CRM_Contact_Form_Search::isSearchContext($context)) { - $context = 'search'; - } - $urlParams = "force=1&reset=1&ssID={$ssID}&context={$context}"; - $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); - if (CRM_Utils_Rule::qfKey($qfKey)) { - $urlParams .= "&qfKey=$qfKey"; - } - - $draftURL = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1'); - $status = ts("You can continue later by clicking the 'Continue' action to resume working on it.
From Draft and Unscheduled Mailings.", array(1 => $draftURL)); - - // Redirect user to search. - $url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $urlParams); - } - else { - $status = ts("Click the 'Continue' action to resume working on it."); - $url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1'); - } - CRM_Core_Session::setStatus($status, ts('Mailing Saved'), 'success'); - CRM_Utils_System::redirect($url); - } - } - - /** - * Display Name of the form. - * - * - * @return string - */ - public function getTitle() { - return ts('Track and Respond'); - } - -} diff --git a/CRM/Mailing/Form/Test.php b/CRM/Mailing/Form/Test.php deleted file mode 100644 index 4542efe113..0000000000 --- a/CRM/Mailing/Form/Test.php +++ /dev/null @@ -1,391 +0,0 @@ -get('ssID'); - $this->assign('ssid', $ssID); - $this->_searchBasedMailing = CRM_Contact_Form_Search::isSearchContext($this->get('context')); - if (CRM_Contact_Form_Search::isSearchContext($this->get('context')) && !$ssID) { - $params = array(); - $result = CRM_Core_BAO_PrevNextCache::getSelectedContacts(); - $this->assign("value", $result); - } - } - - /** - * Set default values for the form. - * - * - * @return void - */ - public function setDefaultValues() { - $count = $this->get('count'); - $this->assign('count', $count); - } - - public function buildQuickForm() { - $session = CRM_Core_Session::singleton(); - $this->add('text', 'test_email', ts('Send to This Address')); - $defaults['test_email'] = $session->get('ufUniqID'); - $qfKey = $this->get('qfKey'); - - $this->add('select', - 'test_group', - ts('Send to This Group'), - array('' => ts('- none -')) + CRM_Core_PseudoConstant::group('Mailing') - ); - $this->setDefaults($defaults); - - $this->add('submit', 'sendtest', ts('Send a Test Mailing')); - $name = ts('Next'); - if (CRM_Mailing_Info::workflowEnabled()) { - if (!CRM_Core_Permission::check('schedule mailings') && - CRM_Core_Permission::check('create mailings') - ) { - $name = ts('Inform Scheduler'); - } - } - - $buttons = array( - array( - 'type' => 'back', - 'name' => ts('Previous'), - ), - array( - 'type' => 'next', - 'name' => $name, - 'spacing' => '                 ', - 'isDefault' => TRUE, - ), - array( - 'type' => 'submit', - 'name' => ts('Save & Continue Later'), - ), - array( - 'type' => 'cancel', - 'name' => ts('Cancel'), - ), - ); - - $this->addButtons($buttons); - - $mailingID = $this->get('mailing_id'); - $textFile = $this->get('textFile'); - $htmlFile = $this->get('htmlFile'); - - $this->addFormRule(array('CRM_Mailing_Form_Test', 'testMail'), $this); - $preview = array(); - if ($textFile) { - $preview['text_link'] = CRM_Utils_System::url('civicrm/mailing/preview', "type=text&qfKey=$qfKey"); - } - if ($htmlFile) { - $preview['html_link'] = CRM_Utils_System::url('civicrm/mailing/preview', "type=html&qfKey=$qfKey"); - } - - $preview['attachment'] = CRM_Core_BAO_File::attachmentInfo('civicrm_mailing', $mailingID); - $this->assign('preview', $preview); - //Token Replacement of Subject in preview mailing - $options = array(); - $prefix = "CRM_Mailing_Controller_Send_$qfKey"; - if ($this->_searchBasedMailing) { - $prefix = "CRM_Contact_Controller_Search_$qfKey"; - } - $session->getVars($options, $prefix); - - $mailing = new CRM_Mailing_BAO_Mailing(); - $mailing->id = $options['mailing_id']; - $mailing->find(TRUE); - $fromEmail = $mailing->from_email; - $replyToEmail = $mailing->replyto_email; - - $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing', - $mailing->id - ); - - $returnProperties = $mailing->getReturnProperties(); - $userID = $session->get('userID'); - $params = array('contact_id' => $userID); - - $details = CRM_Utils_Token::getTokenDetails($params, - $returnProperties, - TRUE, TRUE, NULL, - $mailing->getFlattenedTokens(), - get_class($this) - ); - - $allDetails = &$mailing->compose(NULL, NULL, NULL, - $userID, - $fromEmail, - $fromEmail, - TRUE, - $details[0][$userID], - $attachments - ); - - $this->assign('subject', $allDetails->_headers['Subject']); - } - - /** - * Form rule to send out a test mailing. - * - * @param aray $testParams - * @param array $files - * Any files posted to the form. - * @param array $self - * An current this object. - * - * @return bool - * true on successful SMTP handoff - */ - public static function testMail($testParams, $files, $self) { - $error = NULL; - - $urlString = 'civicrm/mailing/send'; - $urlParams = "_qf_Test_display=true&qfKey={$testParams['qfKey']}"; - - $ssID = $self->get('ssID'); - if ($ssID && $self->_searchBasedMailing) { - if ($self->_action == CRM_Core_Action::BASIC) { - $fragment = 'search'; - } - elseif ($self->_action == CRM_Core_Action::PROFILE) { - $fragment = 'search/builder'; - } - elseif ($self->_action == CRM_Core_Action::ADVANCED) { - $fragment = 'search/advanced'; - } - else { - $fragment = 'search/custom'; - } - $urlString = 'civicrm/contact/' . $fragment; - } - $emails = NULL; - if (!empty($testParams['sendtest'])) { - if (!($testParams['test_group'] || $testParams['test_email'])) { - CRM_Core_Session::setStatus(ts('You did not provide an email address or select a group.'), ts('Test not sent.'), 'error'); - $error = TRUE; - } - - if ($testParams['test_email']) { - $emailAdd = explode(',', $testParams['test_email']); - foreach ($emailAdd as $key => $value) { - $email = trim($value); - $testParams['emails'][] = $email; - $emails .= ($emails ? ',' : '') . "'" . CRM_Core_DAO::escapeString($email) . "'"; - if (!CRM_Utils_Rule::email($email)) { - CRM_Core_Session::setStatus(ts('Please enter a valid email address.'), ts('Test not sent.'), 'error'); - $error = TRUE; - } - } - } - - if ($error) { - $url = CRM_Utils_System::url($urlString, $urlParams); - CRM_Utils_System::redirect($url); - return $error; - } - } - - if (!empty($testParams['_qf_Test_submit'])) { - //when user perform mailing from search context - //redirect it to search result CRM-3711. - if ($ssID && $self->_searchBasedMailing) { - $draftURL = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1'); - $status = ts("You can continue later by clicking the 'Continue' action to resume working on it.
From Draft and Unscheduled Mailings.", array(1 => $draftURL)); - - //replace user context to search. - $context = $self->get('context'); - if (!CRM_Contact_Form_Search::isSearchContext($context)) { - $context = 'search'; - } - $urlParams = "force=1&reset=1&ssID={$ssID}&context={$context}&qfKey={$testParams['qfKey']}"; - $url = CRM_Utils_System::url($urlString, $urlParams); - } - else { - $status = ts("Click the 'Continue' action to resume working on it."); - $url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1'); - } - CRM_Core_Session::setStatus($status, ts('Mailing Saved'), 'success'); - CRM_Utils_System::redirect($url); - } - - if (CRM_Mailing_Info::workflowEnabled()) { - if (!CRM_Core_Permission::check('schedule mailings') && - CRM_Core_Permission::check('create mailings') - ) { - $url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1'); - CRM_Utils_System::redirect($url); - } - } - - if (!empty($testParams['_qf_Test_next']) && - $self->get('count') <= 0 - ) { - return array( - '_qf_default' => - ts("You can not schedule or send this mailing because there are currently no recipients selected. Click 'Previous' to return to the Select Recipients step, OR click 'Save & Continue Later'."), - ); - } - - if (!empty($_POST['_qf_Import_refresh']) || !empty($testParams['_qf_Test_next']) || empty($testParams['sendtest'])) { - $error = TRUE; - return $error; - } - - $job = new CRM_Mailing_BAO_MailingJob(); - $job->mailing_id = $self->get('mailing_id'); - $job->is_test = TRUE; - $job->save(); - $newEmails = NULL; - $session = CRM_Core_Session::singleton(); - if (!empty($testParams['emails'])) { - $query = " -SELECT e.id, e.contact_id, e.email -FROM civicrm_email e -INNER JOIN civicrm_contact c ON e.contact_id = c.id -WHERE e.email IN ($emails) -AND e.on_hold = 0 -AND c.is_opt_out = 0 -AND c.do_not_email = 0 -AND c.is_deleted = 0 -AND c.is_deceased = 0 -GROUP BY e.id -ORDER BY e.is_bulkmail DESC, e.is_primary DESC -"; - - $dao = CRM_Core_DAO::executeQuery($query); - $emailDetail = array(); - // fetch contact_id and email id for all existing emails - while ($dao->fetch()) { - $emailDetail[$dao->email] = array( - 'contact_id' => $dao->contact_id, - 'email_id' => $dao->id, - ); - } - - $dao->free(); - foreach ($testParams['emails'] as $key => $email) { - // Email addresses are forced to lower case when saved, so ensure - // we have the same case when comparing. - $email = trim(strtolower($email)); - $contactId = $emailId = NULL; - if (array_key_exists($email, $emailDetail)) { - $emailId = $emailDetail[$email]['email_id']; - $contactId = $emailDetail[$email]['contact_id']; - } - - if (!$contactId) { - //create new contact. - $params = array( - 'contact_type' => 'Individual', - 'email' => array( - 1 => array( - 'email' => $email, - 'is_primary' => 1, - 'location_type_id' => 1, - ), - ), - ); - $contact = CRM_Contact_BAO_Contact::create($params); - $emailId = $contact->email[0]->id; - $contactId = $contact->id; - $contact->free(); - } - $params = array( - 'job_id' => $job->id, - 'email_id' => $emailId, - 'contact_id' => $contactId, - ); - CRM_Mailing_Event_BAO_Queue::create($params); - } - } - - $testParams['job_id'] = $job->id; - $isComplete = FALSE; - while (!$isComplete) { - $isComplete = CRM_Mailing_BAO_MailingJob::runJobs($testParams); - } - - if (!empty($testParams['sendtest'])) { - $status = NULL; - if (CRM_Mailing_Info::workflowEnabled()) { - if (( - CRM_Core_Permission::check('schedule mailings') && - CRM_Core_Permission::check('create mailings') - ) || - CRM_Core_Permission::check('access CiviMail') - ) { - $status = ts("Click 'Next' when you are ready to Schedule or Send your live mailing (you will still have a chance to confirm or cancel sending this mailing on the next page)."); - } - } - else { - $status = ts("Click 'Next' when you are ready to Schedule or Send your live mailing (you will still have a chance to confirm or cancel sending this mailing on the next page)."); - } - - if ($status) { - CRM_Core_Session::setStatus($status, ts('Test message sent'), 'success'); - } - $url = CRM_Utils_System::url($urlString, $urlParams); - CRM_Utils_System::redirect($url); - } - $error = TRUE; - return $error; - } - - /** - * Display Name of the form. - * - * - * @return string - */ - public function getTitle() { - return ts('Test'); - } - - public function postProcess() { - } - -} diff --git a/CRM/Mailing/Form/Upload.php b/CRM/Mailing/Form/Upload.php deleted file mode 100644 index 7e1a2e722c..0000000000 --- a/CRM/Mailing/Form/Upload.php +++ /dev/null @@ -1,704 +0,0 @@ -_mailingID = $this->get('mailing_id'); - if (CRM_Core_Permission::check('administer CiviCRM')) { - $this->assign('isAdmin', 1); - } - - //when user come from search context. - $ssID = $this->get('ssID'); - $this->assign('ssid', $ssID); - $this->_searchBasedMailing = CRM_Contact_Form_Search::isSearchContext($this->get('context')); - if (CRM_Contact_Form_Search::isSearchContext($this->get('context')) && !$ssID) { - $params = array(); - $result = CRM_Core_BAO_PrevNextCache::getSelectedContacts(); - $this->assign("value", $result); - } - } - - /** - * 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; - } - - /** - * Build the form object. - * - * @return void - */ - public function buildQuickForm() { - $session = CRM_Core_Session::singleton(); - $config = CRM_Core_Config::singleton(); - $options = array(); - $tempVar = FALSE; - - // this seems so hacky, not sure what we are doing here and why. Need to investigate and fix - $session->getVars($options, - "CRM_Mailing_Controller_Send_{$this->controller->_key}" - ); - - $fromEmailAddress = CRM_Core_OptionGroup::values('from_email_address'); - if (empty($fromEmailAddress)) { - //redirect user to enter from email address. - $url = CRM_Utils_System::url('civicrm/admin/options/from_email_address', 'action=add&reset=1'); - $status = ts("There is no valid from email address present. You can add here Add From Email Address.", array(1 => $url)); - $session->setStatus($status, ts('Notice')); - } - else { - foreach ($fromEmailAddress as $key => $email) { - $fromEmailAddress[$key] = htmlspecialchars($fromEmailAddress[$key]); - } - } - - $this->add('select', 'from_email_address', - ts('From Email Address'), array( - '' => '- select -', - ) + $fromEmailAddress, TRUE - ); - - //Added code to add custom field as Reply-To on form when it is enabled from Mailer settings - if ((int) CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'replyTo') && empty($options['override_verp'])) { - $this->add('select', 'reply_to_address', ts('Reply-To'), - array('' => '- select -') + $fromEmailAddress - ); - } - elseif (!empty($options['override_verp'])) { - $trackReplies = TRUE; - $this->assign('trackReplies', $trackReplies); - } - - $this->add('text', 'subject', ts('Mailing Subject'), - CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Mailing', 'subject'), TRUE - ); - - $attributes = array('onclick' => "showHideUpload();"); - $options = array(ts('Upload Content'), ts('Compose On-screen')); - - $this->addRadio('upload_type', ts('I want to'), $options, $attributes, "  "); - - CRM_Mailing_BAO_Mailing::commonCompose($this); - - $this->addElement('file', 'textFile', ts('Upload TEXT Message'), 'size=30 maxlength=60'); - $this->addUploadElement('textFile'); - $this->setMaxFileSize(1024 * 1024); - $this->addRule('textFile', ts('File size should be less than 1 MByte'), 'maxfilesize', 1024 * 1024); - $this->addRule('textFile', ts('File must be in UTF-8 encoding'), 'utf8File'); - - $this->addElement('file', 'htmlFile', ts('Upload HTML Message'), 'size=30 maxlength=60'); - $this->addUploadElement('htmlFile'); - $this->setMaxFileSize(1024 * 1024); - $this->addRule('htmlFile', - ts('File size should be less than %1 MByte(s)', - array(1 => 1) - ), - 'maxfilesize', - 1024 * 1024 - ); - $this->addRule('htmlFile', ts('File must be in UTF-8 encoding'), 'utf8File'); - - //fix upload files when context is search. CRM-3711 - $ssID = $this->get('ssID'); - if ($this->_searchBasedMailing && $ssID) { - $this->set('uploadNames', array('textFile', 'htmlFile')); - } - - CRM_Core_BAO_File::buildAttachment($this, - 'civicrm_mailing', - $this->_mailingID - ); - - $this->add('select', 'header_id', ts('Mailing Header'), - array('' => ts('- none -')) + CRM_Mailing_PseudoConstant::component('Header') - ); - - $this->add('select', 'footer_id', ts('Mailing Footer'), - array('' => ts('- none -')) + CRM_Mailing_PseudoConstant::component('Footer') - ); - - $this->addFormRule(array('CRM_Mailing_Form_Upload', 'formRule'), $this); - - $buttons = array( - array( - 'type' => 'back', - 'name' => ts('Previous'), - ), - array( - 'type' => 'upload', - 'name' => ts('Next'), - 'spacing' => '                 ', - 'isDefault' => TRUE, - ), - array( - 'type' => 'upload', - 'name' => ts('Save & Continue Later'), - 'subName' => 'save', - ), - array( - 'type' => 'cancel', - 'name' => ts('Cancel'), - ), - ); - $this->addButtons($buttons); - } - - public function postProcess() { - $params = $ids = array(); - $uploadParams = array('header_id', 'footer_id', 'subject', 'from_name', 'from_email'); - $fileType = array('textFile', 'htmlFile'); - - $formValues = $this->controller->exportValues($this->_name); - - foreach ($uploadParams as $key) { - if (!empty($formValues[$key]) || - in_array($key, array('header_id', 'footer_id')) - ) { - $params[$key] = $formValues[$key]; - $this->set($key, $formValues[$key]); - } - } - - if (!$formValues['upload_type']) { - foreach ($fileType as $key) { - $contents = NULL; - if (isset($formValues[$key]) && - !empty($formValues[$key]) - ) { - $contents = file_get_contents($formValues[$key]['name']); - $this->set($key, $formValues[$key]['name']); - } - if ($contents) { - $params['body_' . substr($key, 0, 4)] = $contents; - } - else { - $params['body_' . substr($key, 0, 4)] = 'NULL'; - } - } - } - else { - $text_message = $formValues['text_message']; - $params['body_text'] = $text_message; - $this->set('textFile', $params['body_text']); - $this->set('text_message', $params['body_text']); - $html_message = $formValues['html_message']; - - // dojo editor does some html conversion when tokens are - // inserted as links. Hence token replacement fails. - // this is hack to revert html conversion for { to %7B and - // } to %7D by dojo editor - $html_message = str_replace('%7B', '{', str_replace('%7D', '}', $html_message)); - - $params['body_html'] = $html_message; - $this->set('htmlFile', $params['body_html']); - $this->set('html_message', $params['body_html']); - } - - $params['name'] = $this->get('name'); - - $session = CRM_Core_Session::singleton(); - $params['contact_id'] = $session->get('userID'); - $composeFields = array( - 'template', - 'saveTemplate', - 'updateTemplate', - 'saveTemplateName', - ); - $msgTemplate = NULL; - //mail template is composed - if ($formValues['upload_type']) { - $composeParams = array(); - - foreach ($composeFields as $key) { - if (!empty($formValues[$key])) { - $composeParams[$key] = $formValues[$key]; - $this->set($key, $formValues[$key]); - } - } - - if (!empty($composeParams['updateTemplate'])) { - $templateParams = array( - 'msg_text' => $text_message, - 'msg_html' => $html_message, - 'msg_subject' => $params['subject'], - 'is_active' => TRUE, - ); - - $templateParams['id'] = $formValues['template']; - - $msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams); - } - - if (!empty($composeParams['saveTemplate'])) { - $templateParams = array( - 'msg_text' => $text_message, - 'msg_html' => $html_message, - 'msg_subject' => $params['subject'], - 'is_active' => TRUE, - ); - - $templateParams['msg_title'] = $composeParams['saveTemplateName']; - - $msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams); - } - - if (isset($msgTemplate->id)) { - $params['msg_template_id'] = $msgTemplate->id; - } - else { - $params['msg_template_id'] = CRM_Utils_Array::value('template', $formValues); - } - $this->set('template', $params['msg_template_id']); - } - - CRM_Core_BAO_File::formatAttachment($formValues, - $params, - 'civicrm_mailing', - $this->_mailingID - ); - $ids['mailing_id'] = $this->_mailingID; - - //handle mailing from name & address. - $fromEmailAddress = CRM_Utils_Array::value($formValues['from_email_address'], - CRM_Core_OptionGroup::values('from_email_address') - ); - - //get the from email address - $params['from_email'] = CRM_Utils_Mail::pluckEmailFromHeader($fromEmailAddress); - - //get the from Name - $params['from_name'] = CRM_Utils_Array::value(1, explode('"', $fromEmailAddress)); - - //Add Reply-To to headers - if (!empty($formValues['reply_to_address'])) { - $replyToEmail = CRM_Core_OptionGroup::values('from_email_address'); - $params['replyto_email'] = CRM_Utils_Array::value($formValues['reply_to_address'], $replyToEmail); - } - - /* Build the mailing object */ - - CRM_Mailing_BAO_Mailing::create($params, $ids); - - if (isset($this->_submitValues['_qf_Upload_upload_save']) && - $this->_submitValues['_qf_Upload_upload_save'] == 'Save & Continue Later' - ) { - //when user perform mailing from search context - //redirect it to search result CRM-3711. - $ssID = $this->get('ssID'); - if ($ssID && $this->_searchBasedMailing) { - if ($this->_action == CRM_Core_Action::BASIC) { - $fragment = 'search'; - } - elseif ($this->_action == CRM_Core_Action::PROFILE) { - $fragment = 'search/builder'; - } - elseif ($this->_action == CRM_Core_Action::ADVANCED) { - $fragment = 'search/advanced'; - } - else { - $fragment = 'search/custom'; - } - - $context = $this->get('context'); - if (!CRM_Contact_Form_Search::isSearchContext($context)) { - $context = 'search'; - } - $urlParams = "force=1&reset=1&ssID={$ssID}&context={$context}"; - $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); - if (CRM_Utils_Rule::qfKey($qfKey)) { - $urlParams .= "&qfKey=$qfKey"; - } - - $session = CRM_Core_Session::singleton(); - $draftURL = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1'); - $status = ts("You can continue later by clicking the 'Continue' action to resume working on it.
From Draft and Unscheduled Mailings.", array(1 => $draftURL)); - CRM_Core_Session::setStatus($status, ts('Mailing Saved'), 'success'); - - // Redirect user to search. - $url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $urlParams); - } - else { - $status = ts("Click the 'Continue' action to resume working on it."); - $url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1'); - } - CRM_Core_Session::setStatus($status, ts('Mailing Saved'), 'success'); - return $this->controller->setDestination($url); - } - } - - /** - * Validation. - * - * @param array $params - * (ref.) an assoc array of name/value pairs. - * - * @param $files - * @param $self - * - * @return bool|array - * mixed true or array of errors - */ - public static function formRule($params, $files, $self) { - if (!empty($_POST['_qf_Import_refresh'])) { - return TRUE; - } - $errors = array(); - $template = CRM_Core_Smarty::singleton(); - - if (isset($params['html_message'])) { - $htmlMessage = str_replace(array("\n", "\r"), ' ', $params['html_message']); - $htmlMessage = str_replace("'", "\'", $htmlMessage); - $template->assign('htmlContent', $htmlMessage); - } - - $domain = CRM_Core_BAO_Domain::getDomain(); - - $mailing = new CRM_Mailing_BAO_Mailing(); - $mailing->id = $self->_mailingID; - $mailing->find(TRUE); - - $session = CRM_Core_Session::singleton(); - $values = array( - 'contact_id' => $session->get('userID'), - 'version' => 3, - ); - require_once 'api/api.php'; - $contact = civicrm_api('contact', 'get', $values); - - //CRM-4524 - $contact = reset($contact['values']); - - $verp = array_flip(array('optOut', 'reply', 'unsubscribe', 'resubscribe', 'owner')); - foreach ($verp as $key => $value) { - $verp[$key]++; - } - - $urls = array_flip(array('forward', 'optOutUrl', 'unsubscribeUrl', 'resubscribeUrl')); - foreach ($urls as $key => $value) { - $urls[$key]++; - } - - // set $header and $footer - foreach (array( - 'header', - 'footer', - ) as $part) { - $$part = array(); - if ($params["{$part}_id"]) { - //echo "found

"; - $component = new CRM_Mailing_BAO_Component(); - $component->id = $params["{$part}_id"]; - $component->find(TRUE); - ${$part}['textFile'] = $component->body_text; - ${$part}['htmlFile'] = $component->body_html; - $component->free(); - } - else { - ${$part}['htmlFile'] = ${$part}['textFile'] = ''; - } - } - - $skipTextFile = $self->get('skipTextFile'); - $skipHtmlFile = $self->get('skipHtmlFile'); - - if (!$params['upload_type']) { - if ((!isset($files['textFile']) || !file_exists($files['textFile']['tmp_name'])) && - (!isset($files['htmlFile']) || !file_exists($files['htmlFile']['tmp_name'])) - ) { - if (!($skipTextFile || $skipHtmlFile)) { - $errors['textFile'] = ts('Please provide either a Text or HTML formatted message - or both.'); - } - } - } - else { - if (empty($params['text_message']) && empty($params['html_message'])) { - $errors['html_message'] = ts('Please provide either a Text or HTML formatted message - or both.'); - } - if (!empty($params['saveTemplate']) && empty($params['saveTemplateName'])) { - $errors['saveTemplateName'] = ts('Please provide a Template Name.'); - } - } - - foreach (array( - 'text', - 'html', - ) as $file) { - if (!$params['upload_type'] && !file_exists(CRM_Utils_Array::value('tmp_name', $files[$file . 'File']))) { - continue; - } - if ($params['upload_type'] && !$params[$file . '_message']) { - continue; - } - - if (!$params['upload_type']) { - $str = file_get_contents($files[$file . 'File']['tmp_name']); - $name = $files[$file . 'File']['name']; - } - else { - $str = $params[$file . '_message']; - $str = ($file == 'html') ? str_replace('%7B', '{', str_replace('%7D', '}', $str)) : $str; - $name = $file . ' message'; - } - - /* append header/footer */ - - $str = $header[$file . 'File'] . $str . $footer[$file . 'File']; - - $dataErrors = array(); - - /* First look for missing tokens */ - - if (!CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'disable_mandatory_tokens_check')) { - $err = CRM_Utils_Token::requiredTokens($str); - if ($err !== TRUE) { - foreach ($err as $token => $desc) { - $dataErrors[] = '

  • ' . ts('This message is missing a required token - {%1}: %2', - array(1 => $token, 2 => $desc) - ) . '
  • '; - } - } - } - - /* Do a full token replacement on a dummy verp, the current - * contact and domain, and the first organization. */ - - // here we make a dummy mailing object so that we - // can retrieve the tokens that we need to replace - // so that we do get an invalid token error - // this is qute hacky and I hope that there might - // be a suggestion from someone on how to - // make it a bit more elegant - - $dummy_mail = new CRM_Mailing_BAO_Mailing(); - $mess = "body_{$file}"; - $dummy_mail->$mess = $str; - $tokens = $dummy_mail->getTokens(); - - $str = CRM_Utils_Token::replaceSubscribeInviteTokens($str); - $str = CRM_Utils_Token::replaceDomainTokens($str, $domain, NULL, $tokens[$file]); - $str = CRM_Utils_Token::replaceMailingTokens($str, $mailing, NULL, $tokens[$file]); - $str = CRM_Utils_Token::replaceOrgTokens($str, $org); - $str = CRM_Utils_Token::replaceActionTokens($str, $verp, $urls, NULL, $tokens[$file]); - $str = CRM_Utils_Token::replaceContactTokens($str, $contact, NULL, $tokens[$file]); - - $unmatched = CRM_Utils_Token::unmatchedTokens($str); - - if (!empty($unmatched) && 0) { - foreach ($unmatched as $token) { - $dataErrors[] = '
  • ' . ts('Invalid token code') . ' {' . $token . '}
  • '; - } - } - if (!empty($dataErrors)) { - $errors[$file . 'File'] = ts('The following errors were detected in %1:', array( - 1 => $name, - )) . '
    ' . ts('More information on required tokens...') . ''; - } - } - - $templateName = CRM_Core_BAO_MessageTemplate::getMessageTemplates(); - if (!empty($params['saveTemplate']) && in_array(CRM_Utils_Array::value('saveTemplateName', $params), $templateName) - ) { - $errors['saveTemplate'] = ts('Duplicate Template Name.'); - } - return empty($errors) ? TRUE : $errors; - } - - /** - * Display Name of the form. - * - * - * @return string - */ - public function getTitle() { - return ts('Mailing Content'); - } - - /** - * List available tokens for this form. - * - * @return array - */ - public function listTokens() { - $tokens = CRM_Core_SelectValues::contactTokens(); - $tokens = array_merge(CRM_Core_SelectValues::mailingTokens(), $tokens); - return $tokens; - } - -} diff --git a/CRM/Mailing/StateMachine/Send.php b/CRM/Mailing/StateMachine/Send.php deleted file mode 100644 index 6da3a48f5b..0000000000 --- a/CRM/Mailing/StateMachine/Send.php +++ /dev/null @@ -1,76 +0,0 @@ -_pages = array( - 'CRM_Mailing_Form_Group' => NULL, - 'CRM_Mailing_Form_Settings' => NULL, - 'CRM_Mailing_Form_Upload' => NULL, - 'CRM_Mailing_Form_Test' => NULL, - ); - - if (CRM_Mailing_Info::workflowEnabled()) { - if (CRM_Core_Permission::check('schedule mailings') || CRM_Core_Permission::check('access CiviMail')) { - $this->_pages['CRM_Mailing_Form_Schedule'] = NULL; - } - - if (CRM_Core_Permission::check('approve mailings') || CRM_Core_Permission::check('access CiviMail')) { - $this->_pages['CRM_Mailing_Form_Approve'] = NULL; - } - } - else { - $this->_pages['CRM_Mailing_Form_Schedule'] = NULL; - } - - $this->addSequentialPages($this->_pages, $action); - } - -} diff --git a/CRM/Mailing/xml/Menu/Mailing.xml b/CRM/Mailing/xml/Menu/Mailing.xml index 6b62c7de2f..33b9e501ea 100644 --- a/CRM/Mailing/xml/Menu/Mailing.xml +++ b/CRM/Mailing/xml/Menu/Mailing.xml @@ -182,13 +182,6 @@ CRM_Mailing_Page_AJAX::template access CiviCRM - - civicrm/mailing/schedule - Schedule Mailing - CRM_Mailing_Form_Schedule - access CiviMail;schedule mailings - 700 - civicrm/mailing/view View Mailing diff --git a/CRM/Utils/Token.php b/CRM/Utils/Token.php index 6b2b4da854..cdf314c620 100644 --- a/CRM/Utils/Token.php +++ b/CRM/Utils/Token.php @@ -486,19 +486,15 @@ class CRM_Utils_Token { break; case 'editUrl': + case 'scheduleUrl': + // Note: editUrl and scheduleUrl used to be different, but now there's + // one screen which can adapt based on permissions (in workflow mode). $value = CRM_Utils_System::url('civicrm/mailing/send', "reset=1&mid={$mailing->id}&continue=true", TRUE, NULL, FALSE, TRUE ); break; - case 'scheduleUrl': - $value = CRM_Utils_System::url('civicrm/mailing/schedule', - "reset=1&mid={$mailing->id}", - TRUE, NULL, FALSE, TRUE - ); - break; - case 'html': $page = new CRM_Mailing_Page_View(); $value = $page->run($mailing->id, NULL, FALSE, TRUE); -- 2.25.1