}
}
+ /**
+ * Given this task's list of targets, produce a hidden group.
+ *
+ * @return array
+ * Array(0 => int $groupID, 1 => int|NULL $ssID).
+ * @throws Exception
+ */
+ public function createHiddenGroup() {
+ // Did the user select "All" matches or cherry-pick a few records?
+ $searchParams = $this->controller->exportValues();
+ if ($searchParams['radio_ts'] == 'ts_sel') {
+ // Create a static group.
+
+ $randID = md5(time() . rand(1, 1000)); // groups require a unique name
+ $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
+ return array($grpID, NULL);
+ }
+ else {
+ // Create a smart group.
+
+ $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);
+ return array($smartGroupId, $savedSearchId);
+ }
+
+ }
+
}
);
}
- 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,
- );
+ 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,
+ );
+ }
}
- 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,
+ );
+ }
}
self::$_tasks += CRM_Core_Component::taskList();
--- /dev/null
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.6 |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2014 |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM. |
+ | |
+ | CiviCRM is free software; you can copy, modify, and distribute it |
+ | under the terms of the GNU Affero General Public License |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
+ | |
+ | CiviCRM is distributed in the hope that it will be useful, but |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
+ | See the GNU Affero General Public License for more details. |
+ | |
+ | You should have received a copy of the GNU Affero General Public |
+ | License and the CiviCRM Licensing Exception along |
+ | with this program; if not, contact CiviCRM LLC |
+ | at info[AT]civicrm[DOT]org. If you have questions about the |
+ | GNU Affero General Public License or the licensing of CiviCRM, |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2014
+ * $Id$
+ *
+ */
+
+/**
+ * Given the selected contacts, prepare a mailing with a hidden group.
+ */
+class CRM_Mailing_Form_Task_AdhocMailing extends CRM_Contact_Form_Task {
+
+ public function preProcess() {
+ parent::preProcess();
+ list ($groupId, $ssId) = $this->createHiddenGroup();
+ $mailing = civicrm_api3('Mailing', 'create', array(
+ 'name' => "",
+ 'campaign_id' => NULL,
+ 'replyto_email' => "",
+ 'subject' => "",
+ 'body_html' => "",
+ 'body_text' => "",
+ 'groups' => array(
+ 'include' => array($groupId),
+ 'exclude' => array(),
+ ),
+ 'mailings' => array(
+ 'include' => array(),
+ 'exclude' => array(),
+ ),
+ ));
+
+ CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/mailing/' . $mailing['id']));
+ }
+
+}