3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * This class introduces component to the system and provides all the
30 * information about it. It needs to extend CRM_Core_Component_Info
34 * @copyright CiviCRM LLC (c) 2004-2017
36 class CRM_Mailing_Info
extends CRM_Core_Component_Info
{
41 protected $keyword = 'mailing';
48 public function getInfo() {
51 'translatedName' => ts('CiviMail'),
52 'title' => ts('CiviCRM Mailing Engine'),
54 'showActivitiesInCore' => 1,
59 * Get AngularJS modules and their dependencies.
62 * list of modules; same format as CRM_Utils_Hook::angularModules(&$angularModules)
63 * @see CRM_Utils_Hook::angularModules
65 public function getAngularModules() {
66 // load angular files only if valid permissions are granted to the user
67 if (!CRM_Core_Permission
::check('access CiviMail')
68 && !CRM_Core_Permission
::check('create mailings')
69 && !CRM_Core_Permission
::check('schedule mailings')
70 && !CRM_Core_Permission
::check('approve mailings')
77 $reportTypes = array('detail', 'opened', 'bounce', 'clicks');
78 foreach ($reportTypes as $report) {
79 $result = civicrm_api3('ReportInstance', 'get', array(
81 'report_id' => 'mailing/' . $report));
82 $reportIds[$report] = $result['values'][0]['id'];
85 $result['crmMailing'] = include "$civicrm_root/ang/crmMailing.ang.php";
86 $result['crmMailingAB'] = include "$civicrm_root/ang/crmMailingAB.ang.php";
87 $result['crmD3'] = include "$civicrm_root/ang/crmD3.ang.php";
89 $config = CRM_Core_Config
::singleton();
90 $session = CRM_Core_Session
::singleton();
91 $contactID = $session->get('userID');
94 // CRM-16155 - Limit to a reasonable number.
95 $civiMails = civicrm_api3('Mailing', 'get', array(
97 'mailing_type' => array('IN' => array('standalone', 'winner')),
98 'domain_id' => CRM_Core_Config
::domainID(),
99 'return' => array('id', 'name', 'scheduled_date'),
103 'sort' => 'is_archived asc, scheduled_date desc',
108 'options' => array('limit' => 0),
112 $groupNames = civicrm_api3('Group', 'get', $params +
array(
114 'check_permissions' => TRUE,
115 'return' => array('title', 'visibility', 'group_type', 'is_hidden'),
117 $headerfooterList = civicrm_api3('MailingComponent', 'get', $params +
array(
119 'return' => array('name', 'component_type', 'is_default', 'body_html', 'body_text'),
122 $emailAdd = civicrm_api3('Email', 'get', array(
125 'contact_id' => $contactID,
128 $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params +
array(
131 'return' => array("id", "msg_title"),
132 'workflow_id' => array('IS NULL' => ""),
134 $mailTokens = civicrm_api3('Mailing', 'gettokens', array(
135 'entity' => array('contact', 'mailing'),
138 $fromAddress = civicrm_api3('OptionValue', 'get', $params +
array(
139 'option_group_id' => "from_email_address",
140 'domain_id' => CRM_Core_Config
::domainID(),
142 $enabledLanguages = CRM_Core_I18n
::languages(TRUE);
143 $isMultiLingual = (count($enabledLanguages) > 1);
144 CRM_Core_Resources
::singleton()
146 'crmMailing' => array(
147 'templateTypes' => CRM_Mailing_BAO_Mailing
::getTemplateTypes(),
148 'civiMails' => $civiMails['values'],
149 'campaignEnabled' => in_array('CiviCampaign', $config->enableComponents
),
150 'groupNames' => $groupNames['values'],
151 'headerfooterList' => $headerfooterList['values'],
152 'mesTemplate' => $mesTemplate['values'],
153 'emailAdd' => $emailAdd['values'],
154 'mailTokens' => $mailTokens['values'],
155 'contactid' => $contactID,
156 'requiredTokens' => CRM_Utils_Token
::getRequiredTokens(),
157 'enableReplyTo' => (int) Civi
::settings()->get('replyTo'),
158 'disableMandatoryTokensCheck' => (int) Civi
::settings()->get('disable_mandatory_tokens_check'),
159 'fromAddress' => $fromAddress['values'],
160 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', array(
161 'id' => 'user_contact_id',
164 'visibility' => CRM_Utils_Array
::makeNonAssociative(CRM_Core_SelectValues
::groupVisibility()),
165 'workflowEnabled' => CRM_Mailing_Info
::workflowEnabled(),
166 'reportIds' => $reportIds,
167 'enabledLanguages' => $enabledLanguages,
168 'isMultiLingual' => $isMultiLingual,
171 ->addPermissions(array(
178 'delete in CiviMail',
179 'edit message templates',
188 public static function workflowEnabled() {
189 $config = CRM_Core_Config
::singleton();
191 // early exit, since not true for most
192 if (!$config->userSystem
->is_drupal ||
193 !function_exists('module_exists')
198 if (!module_exists('rules')) {
202 $enableWorkflow = Civi
::settings()->get('civimail_workflow');
204 return ($enableWorkflow &&
205 $config->userSystem
->is_drupal
211 * @param bool $getAllUnconditionally
212 * @param bool $descriptions
213 * Whether to return permission descriptions
217 public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
218 $permissions = array(
219 'access CiviMail' => array(
220 ts('access CiviMail'),
222 'access CiviMail subscribe/unsubscribe pages' => array(
223 ts('access CiviMail subscribe/unsubscribe pages'),
224 ts('Subscribe/unsubscribe from mailing list group'),
226 'delete in CiviMail' => array(
227 ts('delete in CiviMail'),
228 ts('Delete Mailing'),
230 'view public CiviMail content' => array(
231 ts('view public CiviMail content'),
235 if (self
::workflowEnabled() ||
$getAllUnconditionally) {
236 $permissions['create mailings'] = array(
237 ts('create mailings'),
239 $permissions['schedule mailings'] = array(
240 ts('schedule mailings'),
242 $permissions['approve mailings'] = array(
243 ts('approve mailings'),
247 if (!$descriptions) {
248 foreach ($permissions as $name => $attr) {
249 $permissions[$name] = array_shift($attr);
261 public function getUserDashboardElement() {
262 // no dashboard element for this component
269 public function getUserDashboardObject() {
270 // no dashboard element for this component
278 public function registerTab() {
280 'title' => ts('Mailings'),
291 public function registerAdvancedSearchPane() {
293 'title' => ts('Mailings'),
302 public function getActivityTypes() {
307 * add shortcut to Create New.
310 public function creatNewShortcut(&$shortCuts) {