commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / CRM / Mailing / Info.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
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 * Get AngularJS modules and their dependencies
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 // load angular files only if valid permissions are granted to the user
69 if (!CRM_Core_Permission::check('access CiviMail')
70 && !CRM_Core_Permission::check('create mailings')
71 && !CRM_Core_Permission::check('schedule mailings')
72 && !CRM_Core_Permission::check('approve mailings')
73 ) {
74 return array();
75 }
76
77 $reportIds = array();
78 $reportTypes = array('detail', 'opened', 'bounce', 'clicks');
79 foreach ($reportTypes as $report) {
80 $result = civicrm_api3('ReportInstance', 'get', array(
81 'sequential' => 1,
82 'report_id' => 'mailing/' . $report));
83 $reportIds[$report] = $result['values'][0]['id'];
84 }
85 $result = array();
86 $result['crmMailing'] = array(
87 'ext' => 'civicrm',
88 'js' => array(
89 'ang/crmMailing.js',
90 'ang/crmMailing/*.js',
91 ),
92 'css' => array('ang/crmMailing.css'),
93 'partials' => array('ang/crmMailing'),
94 );
95 $result['crmMailingAB'] = array(
96 'ext' => 'civicrm',
97 'js' => array(
98 'ang/crmMailingAB.js',
99 'ang/crmMailingAB/*.js',
100 'ang/crmMailingAB/*/*.js',
101 ),
102 'css' => array('ang/crmMailingAB.css'),
103 'partials' => array('ang/crmMailingAB'),
104 );
105 $result['crmD3'] = array(
106 'ext' => 'civicrm',
107 'js' => array(
108 'ang/crmD3.js',
109 'bower_components/d3/d3.min.js',
110 ),
111 );
112
113 $config = CRM_Core_Config::singleton();
114 $session = CRM_Core_Session::singleton();
115 $contactID = $session->get('userID');
116
117 // Get past mailings
118 // CRM-16155 - Limit to a reasonable number
119 $civiMails = civicrm_api3('Mailing', 'get', array(
120 'is_completed' => 1,
121 'mailing_type' => array('IN' => array('standalone', 'winner')),
122 'return' => array('id', 'name', 'scheduled_date'),
123 'sequential' => 1,
124 'options' => array(
125 'limit' => 500,
126 'sort' => 'is_archived asc, scheduled_date desc',
127 ),
128 ));
129 // Generic params
130 $params = array(
131 'options' => array('limit' => 0),
132 'sequential' => 1,
133 );
134
135 $groupNames = civicrm_api3('Group', 'get', $params + array(
136 'is_active' => 1,
137 'check_permissions' => TRUE,
138 'return' => array('title', 'visibility', 'group_type', 'is_hidden'),
139 ));
140 $headerfooterList = civicrm_api3('MailingComponent', 'get', $params + array(
141 'is_active' => 1,
142 'return' => array('name', 'component_type', 'is_default', 'body_html', 'body_text'),
143 ));
144
145 $emailAdd = civicrm_api3('Email', 'get', array(
146 'sequential' => 1,
147 'return' => "email",
148 'contact_id' => $contactID,
149 ));
150
151 $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params + array(
152 'sequential' => 1,
153 'is_active' => 1,
154 'return' => array("id", "msg_title"),
155 'workflow_id' => array('IS NULL' => ""),
156 ));
157 $mailTokens = civicrm_api3('Mailing', 'gettokens', array(
158 'entity' => array('contact', 'mailing'),
159 'sequential' => 1,
160 ));
161 $fromAddress = civicrm_api3('OptionValue', 'get', $params + array(
162 'option_group_id' => "from_email_address",
163 'domain_id' => CRM_Core_Config::domainID(),
164 ));
165 CRM_Core_Resources::singleton()
166 ->addSetting(array(
167 'crmMailing' => array(
168 'templateTypes' => CRM_Mailing_BAO_Mailing::getTemplateTypes(),
169 'civiMails' => $civiMails['values'],
170 'campaignEnabled' => in_array('CiviCampaign', $config->enableComponents),
171 'groupNames' => $groupNames['values'],
172 'headerfooterList' => $headerfooterList['values'],
173 'mesTemplate' => $mesTemplate['values'],
174 'emailAdd' => $emailAdd['values'],
175 'mailTokens' => $mailTokens['values'],
176 'contactid' => $contactID,
177 'requiredTokens' => CRM_Utils_Token::getRequiredTokens(),
178 'enableReplyTo' => (int) CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'replyTo'),
179 'disableMandatoryTokensCheck' => (int) CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'disable_mandatory_tokens_check'),
180 'fromAddress' => $fromAddress['values'],
181 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', array(
182 'id' => 'user_contact_id',
183 'return' => 'email',
184 )),
185 'visibility' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::groupVisibility()),
186 'workflowEnabled' => CRM_Mailing_Info::workflowEnabled(),
187 'reportIds' => $reportIds,
188 ),
189 ))
190 ->addPermissions(array(
191 'view all contacts',
192 'edit all contacts',
193 'access CiviMail',
194 'create mailings',
195 'schedule mailings',
196 'approve mailings',
197 'delete in CiviMail',
198 'edit message templates',
199 ));
200
201 return $result;
202 }
203
204 /**
205 * @return bool
206 */
207 public static function workflowEnabled() {
208 $config = CRM_Core_Config::singleton();
209
210 // early exit, since not true for most
211 if (!$config->userSystem->is_drupal ||
212 !function_exists('module_exists')
213 ) {
214 return FALSE;
215 }
216
217 if (!module_exists('rules')) {
218 return FALSE;
219 }
220
221 $enableWorkflow = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
222 'civimail_workflow',
223 NULL,
224 FALSE
225 );
226
227 return ($enableWorkflow &&
228 $config->userSystem->is_drupal
229 ) ? TRUE : FALSE;
230 }
231
232 /**
233 * @inheritDoc
234 * @param bool $getAllUnconditionally
235 * @param bool $descriptions
236 * Whether to return permission descriptions
237 *
238 * @return array
239 */
240 public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
241 $permissions = array(
242 'access CiviMail' => array(
243 ts('access CiviMail'),
244 ),
245 'access CiviMail subscribe/unsubscribe pages' => array(
246 ts('access CiviMail subscribe/unsubscribe pages'),
247 ts('Subscribe/unsubscribe from mailing list group'),
248 ),
249 'delete in CiviMail' => array(
250 ts('delete in CiviMail'),
251 ts('Delete Mailing'),
252 ),
253 'view public CiviMail content' => array(
254 ts('view public CiviMail content'),
255 ),
256 );
257
258 if (self::workflowEnabled() || $getAllUnconditionally) {
259 $permissions[] = array(
260 'create mailings' => array(
261 ts('create mailings'),
262 ),
263 );
264 $permissions[] = array(
265 'schedule mailings' => array(
266 ts('schedule mailings'),
267 ),
268 );
269 $permissions[] = array(
270 'approve mailings' => array(
271 ts('approve mailings'),
272 ),
273 );
274 }
275
276 if (!$descriptions) {
277 foreach ($permissions as $name => $attr) {
278 $permissions[$name] = array_shift($attr);
279 }
280 }
281
282 return $permissions;
283 }
284
285
286 /**
287 * @inheritDoc
288 * @return null
289 */
290 public function getUserDashboardElement() {
291 // no dashboard element for this component
292 return NULL;
293 }
294
295 /**
296 * @return null
297 */
298 public function getUserDashboardObject() {
299 // no dashboard element for this component
300 return NULL;
301 }
302
303 /**
304 * @inheritDoc
305 * @return array
306 */
307 public function registerTab() {
308 return array(
309 'title' => ts('Mailings'),
310 'id' => 'mailing',
311 'url' => 'mailing',
312 'weight' => 45,
313 );
314 }
315
316 /**
317 * @inheritDoc
318 * @return array
319 */
320 public function registerAdvancedSearchPane() {
321 return array(
322 'title' => ts('Mailings'),
323 'weight' => 20,
324 );
325 }
326
327 /**
328 * @inheritDoc
329 * @return null
330 */
331 public function getActivityTypes() {
332 return NULL;
333 }
334
335 /**
336 * add shortcut to Create New.
337 * @param $shortCuts
338 */
339 public function creatNewShortcut(&$shortCuts) {
340 }
341
342 }