CRM-15854 - crmMailing, crmMailingAB - Respect 'delete in CiviMail' permission
[civicrm-core.git] / CRM / Mailing / Info.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 * This class introduces component to the system and provides all the
30 * information about it. It needs to extend CRM_Core_Component_Info
31 * abstract class.
32 *
33 * @package CRM
34 * @copyright CiviCRM LLC (c) 2004-2014
35 * $Id$
36 *
37 */
38 class CRM_Mailing_Info extends CRM_Core_Component_Info {
39
40 /**
41 * @inheritDoc
42 */
43 protected $keyword = 'mailing';
44
45
46 /**
47 * @inheritDoc
48 * @return array
49 */
50 public function getInfo() {
51 return array(
52 'name' => 'CiviMail',
53 'translatedName' => ts('CiviMail'),
54 'title' => 'CiviCRM Mailing Engine',
55 'search' => 1,
56 'showActivitiesInCore' => 1,
57 );
58 }
59
60 /**
61 * EXPERIMENTAL: Get a list of AngularJS modules
62 *
63 * @return array
64 * list of modules; same format as CRM_Utils_Hook::angularModules(&$angularModules)
65 * @see CRM_Utils_Hook::angularModules
66 */
67 public function getAngularModules() {
68 $result = array();
69 $result['crmMailing'] = array(
70 'ext' => 'civicrm',
71 'js' => array(
72 'js/angular-crmMailing.js',
73 'js/angular-crmMailing/*.js',
74 ),
75 'css' => array('css/angular-crmMailing.css'),
76 'partials' => array('partials/crmMailing'),
77 );
78 $result['crmMailingAB'] = array(
79 'ext' => 'civicrm',
80 'js' => array(
81 'js/angular-crmMailingAB.js',
82 'js/angular-crmMailingAB/*.js',
83 ),
84 'css' => array('css/angular-crmMailingAB.css'),
85 'partials' => array('partials/crmMailingAB'),
86 );
87 $result['crmD3'] = array(
88 'ext' => 'civicrm',
89 'js' => array(
90 'js/angular-crmD3.js',
91 'bower_components/d3/d3.min.js',
92 ),
93 );
94
95 $config = CRM_Core_Config::singleton();
96 $session = CRM_Core_Session::singleton();
97 $contactID = $session->get('userID');
98 $civiMails = civicrm_api3('Mailing', 'get', array());
99 $campNames = civicrm_api3('Campaign', 'get', array());
100 $mailingabNames = civicrm_api3('MailingAB', 'get', array());
101 $mailStatus = civicrm_api3('MailingJob', 'get', array());
102 $groupNames = civicrm_api3('Group', 'get', array());
103 $headerfooterList = civicrm_api3('MailingComponent', 'get', array());
104
105 $emailAdd = civicrm_api3('Email', 'get', array(
106 'sequential' => 1,
107 'return' => "email",
108 'contact_id' => $contactID,
109 ));
110 $mesTemplate = civicrm_api3('MessageTemplate', 'get', array(
111 'sequential' => 1,
112 'return' => array("msg_html", "id", "msg_title", "msg_subject", "msg_text"),
113 'is_active' => 1,
114 'workflow_id' => array('IS NULL' => ""),
115 ));
116 $mailGrp = civicrm_api3('MailingGroup', 'get', array());
117 $mailTokens = civicrm_api3('Mailing', 'gettokens', array('entity' => array('contact', 'mailing'), 'sequential' => 1));
118 $fromAddress = civicrm_api3('OptionGroup', 'get', array(
119 'sequential' => 1,
120 'name' => "from_email_address",
121 'api.OptionValue.get' => array(),
122 ));
123 CRM_Core_Resources::singleton()->addSetting(array(
124 'crmMailing' => array(
125 'mailingabNames' => array_values($mailingabNames['values']),
126 'civiMails' => array_values($civiMails['values']),
127 'campNames' => array_values($campNames['values']),
128 'mailStatus' => array_values($mailStatus['values']),
129 'groupNames' => array_values($groupNames['values']),
130 'headerfooterList' => array_values($headerfooterList['values']),
131 'mesTemplate' => array_values($mesTemplate['values']),
132 'emailAdd' => array_values($emailAdd['values']),
133 'mailGrp' => array_values($mailGrp['values']),
134 'mailTokens' => $mailTokens['values'],
135 'contactid' => $contactID,
136 'requiredTokens' => CRM_Utils_Token::getRequiredTokens(),
137 'enableReplyTo' => (int) CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'replyTo'),
138 'fromAddress' => array_values($fromAddress['values'][0]['api.OptionValue.get']['values']),
139 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', array(
140 'id' => 'user_contact_id',
141 'return' => 'email',
142 )),
143 'visibility' => array(
144 array('value' => 'Public Pages', 'label' => ts('Public Pages')),
145 array('value' => 'User and User Admin Only', 'label' => ts('User and User Admin Only')),
146 ),
147 'workflowEnabled' => CRM_Mailing_Info::workflowEnabled(),
148 ),
149 ));
150 CRM_Core_Resources::singleton()->addPermissions(array(
151 'view all contacts',
152 'access CiviMail',
153 'create mailings',
154 'schedule mailings',
155 'approve mailings',
156 'delete in CiviMail',
157 ));
158
159 return $result;
160 }
161
162 /**
163 * @return bool
164 */
165 public static function workflowEnabled() {
166 $config = CRM_Core_Config::singleton();
167
168 // early exit, since not true for most
169 if (!$config->userSystem->is_drupal ||
170 !function_exists('module_exists')
171 ) {
172 return FALSE;
173 }
174
175 if (!module_exists('rules')) {
176 return FALSE;
177 }
178
179 $enableWorkflow = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
180 'civimail_workflow',
181 NULL,
182 FALSE
183 );
184
185 return ($enableWorkflow &&
186 $config->userSystem->is_drupal
187 ) ? TRUE : FALSE;
188 }
189
190 /**
191 * @inheritDoc
192 * @param bool $getAllUnconditionally
193 *
194 * @return array
195 */
196 public function getPermissions($getAllUnconditionally = FALSE) {
197 $permissions = array(
198 'access CiviMail',
199 'access CiviMail subscribe/unsubscribe pages',
200 'delete in CiviMail',
201 'view public CiviMail content',
202 );
203
204 if (self::workflowEnabled() || $getAllUnconditionally) {
205 $permissions[] = 'create mailings';
206 $permissions[] = 'schedule mailings';
207 $permissions[] = 'approve mailings';
208 }
209
210 return $permissions;
211 }
212
213
214 /**
215 * @inheritDoc
216 * @return null
217 */
218 public function getUserDashboardElement() {
219 // no dashboard element for this component
220 return NULL;
221 }
222
223 /**
224 * @return null
225 */
226 public function getUserDashboardObject() {
227 // no dashboard element for this component
228 return NULL;
229 }
230
231 /**
232 * @inheritDoc
233 * @return array
234 */
235 public function registerTab() {
236 return array(
237 'title' => ts('Mailings'),
238 'id' => 'mailing',
239 'url' => 'mailing',
240 'weight' => 45,
241 );
242 }
243
244 /**
245 * @inheritDoc
246 * @return array
247 */
248 public function registerAdvancedSearchPane() {
249 return array(
250 'title' => ts('Mailings'),
251 'weight' => 20,
252 );
253 }
254
255 /**
256 * @inheritDoc
257 * @return null
258 */
259 public function getActivityTypes() {
260 return NULL;
261 }
262
263 /**
264 * add shortcut to Create New.
265 * @param $shortCuts
266 */
267 public function creatNewShortcut(&$shortCuts) {
268 }
269
270 }