CRM-21022 - Parameterize variables in SQL query
[civicrm-core.git] / CRM / Mailing / Info.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
0f03f337 6 | Copyright CiviCRM LLC (c) 2004-2017 |
6a488035
TO
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
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
0f03f337 34 * @copyright CiviCRM LLC (c) 2004-2017
6a488035
TO
35 */
36class CRM_Mailing_Info extends CRM_Core_Component_Info {
37
e7c15cb6
CW
38 /**
39 * @inheritDoc
40 */
6a488035
TO
41 protected $keyword = 'mailing';
42
43
e0ef6999 44 /**
e7c15cb6 45 * @inheritDoc
e0ef6999
EM
46 * @return array
47 */
6a488035
TO
48 public function getInfo() {
49 return array(
50 'name' => 'CiviMail',
51 'translatedName' => ts('CiviMail'),
e300cf31 52 'title' => ts('CiviCRM Mailing Engine'),
6a488035
TO
53 'search' => 1,
54 'showActivitiesInCore' => 1,
55 );
56 }
57
ced9bfed 58 /**
25606795 59 * Get AngularJS modules and their dependencies.
ced9bfed
EM
60 *
61 * @return array
62 * list of modules; same format as CRM_Utils_Hook::angularModules(&$angularModules)
63 * @see CRM_Utils_Hook::angularModules
64 */
4aef704e 65 public function getAngularModules() {
56621a6c
KJ
66 // load angular files only if valid permissions are granted to the user
67 if (!CRM_Core_Permission::check('access CiviMail')
011c7136
KJ
68 && !CRM_Core_Permission::check('create mailings')
69 && !CRM_Core_Permission::check('schedule mailings')
70 && !CRM_Core_Permission::check('approve mailings')
56621a6c
KJ
71 ) {
72 return array();
73 }
8456e727 74 global $civicrm_root;
56621a6c 75
78414681
SL
76 $reportIds = array();
77 $reportTypes = array('detail', 'opened', 'bounce', 'clicks');
78 foreach ($reportTypes as $report) {
79 $result = civicrm_api3('ReportInstance', 'get', array(
80 'sequential' => 1,
81 'report_id' => 'mailing/' . $report));
82 $reportIds[$report] = $result['values'][0]['id'];
83 }
4aef704e 84 $result = array();
8456e727
TO
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";
983052fe 88
8099bfee 89 $config = CRM_Core_Config::singleton();
6bea4a47
TO
90 $session = CRM_Core_Session::singleton();
91 $contactID = $session->get('userID');
d979898e 92
25606795 93 // Generic params.
a0f40af4
CW
94 $params = array(
95 'options' => array('limit' => 0),
96 'sequential' => 1,
97 );
31815c2b
SL
98 $groupNames = civicrm_api3('Group', 'get', $params + array(
99 'is_active' => 1,
100 'check_permissions' => TRUE,
101 'return' => array('title', 'visibility', 'group_type', 'is_hidden'),
102 ));
a0f40af4
CW
103 $headerfooterList = civicrm_api3('MailingComponent', 'get', $params + array(
104 'is_active' => 1,
0499685e 105 'return' => array('name', 'component_type', 'is_default', 'body_html', 'body_text'),
72dd949e 106 ));
6bea4a47 107
44a7c67d
TO
108 $emailAdd = civicrm_api3('Email', 'get', array(
109 'sequential' => 1,
110 'return' => "email",
111 'contact_id' => $contactID,
112 ));
a0f40af4 113
d979898e 114 $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params + array(
44a7c67d 115 'sequential' => 1,
a0f40af4 116 'is_active' => 1,
3637550f 117 'return' => array("id", "msg_title"),
44a7c67d
TO
118 'workflow_id' => array('IS NULL' => ""),
119 ));
a0f40af4
CW
120 $mailTokens = civicrm_api3('Mailing', 'gettokens', array(
121 'entity' => array('contact', 'mailing'),
8099bfee 122 'sequential' => 1,
a0f40af4 123 ));
d979898e
CW
124 $fromAddress = civicrm_api3('OptionValue', 'get', $params + array(
125 'option_group_id' => "from_email_address",
84deca8b 126 'domain_id' => CRM_Core_Config::domainID(),
4aef704e 127 ));
c00b95ef
ML
128 $enabledLanguages = CRM_Core_I18n::languages(TRUE);
129 $isMultiLingual = (count($enabledLanguages) > 1);
a0f40af4
CW
130 CRM_Core_Resources::singleton()
131 ->addSetting(array(
132 'crmMailing' => array(
703875d8 133 'templateTypes' => CRM_Mailing_BAO_Mailing::getTemplateTypes(),
836bf6b7 134 'civiMails' => array(),
8099bfee 135 'campaignEnabled' => in_array('CiviCampaign', $config->enableComponents),
836bf6b7 136 'groupNames' => array(),
31815c2b
SL
137 // @todo see if we can remove this by dynamically generating the test group list
138 'testGroupNames' => $groupNames['values'],
a0f40af4
CW
139 'headerfooterList' => $headerfooterList['values'],
140 'mesTemplate' => $mesTemplate['values'],
141 'emailAdd' => $emailAdd['values'],
a0f40af4
CW
142 'mailTokens' => $mailTokens['values'],
143 'contactid' => $contactID,
144 'requiredTokens' => CRM_Utils_Token::getRequiredTokens(),
aaffa79f 145 'enableReplyTo' => (int) Civi::settings()->get('replyTo'),
146 'disableMandatoryTokensCheck' => (int) Civi::settings()->get('disable_mandatory_tokens_check'),
a0f40af4
CW
147 'fromAddress' => $fromAddress['values'],
148 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', array(
149 'id' => 'user_contact_id',
150 'return' => 'email',
151 )),
152 'visibility' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::groupVisibility()),
153 'workflowEnabled' => CRM_Mailing_Info::workflowEnabled(),
78414681 154 'reportIds' => $reportIds,
c00b95ef
ML
155 'enabledLanguages' => $enabledLanguages,
156 'isMultiLingual' => $isMultiLingual,
a0f40af4
CW
157 ),
158 ))
159 ->addPermissions(array(
160 'view all contacts',
84fd40f3 161 'edit all contacts',
a0f40af4
CW
162 'access CiviMail',
163 'create mailings',
164 'schedule mailings',
165 'approve mailings',
166 'delete in CiviMail',
867299da 167 'edit message templates',
a0f40af4 168 ));
983052fe 169
4aef704e 170 return $result;
171 }
983052fe 172
4aef704e 173 /**
e0ef6999
EM
174 * @return bool
175 */
00be9182 176 public static function workflowEnabled() {
6a488035
TO
177 $config = CRM_Core_Config::singleton();
178
179 // early exit, since not true for most
180 if (!$config->userSystem->is_drupal ||
181 !function_exists('module_exists')
182 ) {
183 return FALSE;
184 }
185
186 if (!module_exists('rules')) {
187 return FALSE;
188 }
189
aaffa79f 190 $enableWorkflow = Civi::settings()->get('civimail_workflow');
6a488035
TO
191
192 return ($enableWorkflow &&
193 $config->userSystem->is_drupal
194 ) ? TRUE : FALSE;
195 }
196
e0ef6999 197 /**
e7c15cb6 198 * @inheritDoc
e0ef6999 199 * @param bool $getAllUnconditionally
221b21b4
AH
200 * @param bool $descriptions
201 * Whether to return permission descriptions
e0ef6999
EM
202 *
203 * @return array
204 */
221b21b4 205 public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
6a488035 206 $permissions = array(
221b21b4
AH
207 'access CiviMail' => array(
208 ts('access CiviMail'),
209 ),
210 'access CiviMail subscribe/unsubscribe pages' => array(
211 ts('access CiviMail subscribe/unsubscribe pages'),
212 ts('Subscribe/unsubscribe from mailing list group'),
213 ),
214 'delete in CiviMail' => array(
215 ts('delete in CiviMail'),
216 ts('Delete Mailing'),
217 ),
218 'view public CiviMail content' => array(
219 ts('view public CiviMail content'),
220 ),
6a488035
TO
221 );
222
33777e4a 223 if (self::workflowEnabled() || $getAllUnconditionally) {
de4bf197
TO
224 $permissions['create mailings'] = array(
225 ts('create mailings'),
221b21b4 226 );
de4bf197
TO
227 $permissions['schedule mailings'] = array(
228 ts('schedule mailings'),
221b21b4 229 );
de4bf197
TO
230 $permissions['approve mailings'] = array(
231 ts('approve mailings'),
221b21b4
AH
232 );
233 }
234
235 if (!$descriptions) {
236 foreach ($permissions as $name => $attr) {
237 $permissions[$name] = array_shift($attr);
238 }
6a488035
TO
239 }
240
241 return $permissions;
242 }
243
244
e0ef6999 245 /**
e7c15cb6 246 * @inheritDoc
e0ef6999
EM
247 * @return null
248 */
6a488035
TO
249 public function getUserDashboardElement() {
250 // no dashboard element for this component
251 return NULL;
252 }
253
e0ef6999
EM
254 /**
255 * @return null
256 */
6a488035
TO
257 public function getUserDashboardObject() {
258 // no dashboard element for this component
259 return NULL;
260 }
261
e0ef6999 262 /**
e7c15cb6 263 * @inheritDoc
e0ef6999
EM
264 * @return array
265 */
6a488035 266 public function registerTab() {
2ede60ec
DL
267 return array(
268 'title' => ts('Mailings'),
269 'id' => 'mailing',
270 'url' => 'mailing',
271 'weight' => 45,
272 );
6a488035
TO
273 }
274
e0ef6999 275 /**
e7c15cb6 276 * @inheritDoc
e0ef6999
EM
277 * @return array
278 */
6a488035 279 public function registerAdvancedSearchPane() {
35f7561f 280 return array(
353ffa53 281 'title' => ts('Mailings'),
6a488035
TO
282 'weight' => 20,
283 );
284 }
285
e0ef6999 286 /**
e7c15cb6 287 * @inheritDoc
e0ef6999
EM
288 * @return null
289 */
6a488035
TO
290 public function getActivityTypes() {
291 return NULL;
292 }
293
e0ef6999 294 /**
fe482240 295 * add shortcut to Create New.
e0ef6999
EM
296 * @param $shortCuts
297 */
35f7561f
TO
298 public function creatNewShortcut(&$shortCuts) {
299 }
96025800 300
6a488035 301}