35481af71ea4fb2c263b6b398cda112ae295c150
[civicrm-core.git] / CRM / Mailing / Info.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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 // docs inherited from interface
41 protected $keyword = 'mailing';
42
43
44 // docs inherited from interface
45 /**
46 * @return array
47 */
48 public function getInfo() {
49 return array(
50 'name' => 'CiviMail',
51 'translatedName' => ts('CiviMail'),
52 'title' => 'CiviCRM Mailing Engine',
53 'search' => 1,
54 'showActivitiesInCore' => 1,
55 );
56 }
57
58 public function getAngularModules() {
59 $result = array();
60 $result['crmMailing'] = array(
61 'ext' => 'civicrm',
62 'js' => array(
63 'js/angular-Mailing.js' ,
64 'js/angularsanitize.js' ,
65 'packages/ckeditor/ckeditor.js'
66 ),
67 );
68 $result['crmMailing2'] = array(
69 'ext' => 'civicrm',
70 'js' => array('js/angular-crmMailing2.js', 'js/angular-crmMailing2-directives.js'),
71 'css' => array('css/angular-crmMailing2.css'),
72 );
73 $result['crmMailingAB'] = array(
74 'ext' => 'civicrm',
75 'js' => array(
76 'js/angular-crmMailingAB.js',
77 'js/angular-crmMailingAB-ReportCtrl.js',
78 'js/d3.min.js',
79 'js/angular-sanitize.js',
80 'packages/ckeditor/ckeditor.js',
81 ),
82 'css' => array('css/angular-crmMailingAB.css'),
83 );
84
85 $session = CRM_Core_Session::singleton();
86 $contactID = $session->get('userID');
87 $civiMails = civicrm_api3('Mailing', 'get', array());
88 $campNames = civicrm_api3('Campaign', 'get', array());
89 $mailingabNames = civicrm_api3('MailingAB','get',array());
90 $mailStatus = civicrm_api3('MailingJob', 'get', array());
91 $groupNames = civicrm_api3('Group', 'get', array());
92 $headerfooterList = civicrm_api3('MailingComponent', 'get', array());
93
94 // FIXME: The following two items differ between GSOC CiviMail and ABTest branches
95 if (FALSE) {
96 // AB Test
97 $emailAdd = civicrm_api3('Email', 'get', array());
98 $mesTemplate = civicrm_api3('MessageTemplate', 'get', array(
99 'sequential' => 1,
100 'return' => array("msg_html", "id", "msg_title","msg_subject"),
101 'id' => array('>' => 58),
102 ));
103 } else {
104 // CiviMail UI
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( 'sequential' => 1,
111 'return' => array("msg_html", "id", "msg_title", "msg_subject"),
112 'workflow_id' => array('IS NULL' => ""),
113 ));
114 }
115 $mailGrp = civicrm_api3('MailingGroup','get', array());
116 $mailTokens = civicrm_api3('Mailing', 'get_token', array( 'usage' => 'Mailing'));
117 $fromAddress = civicrm_api3('OptionGroup', 'get', array(
118 'sequential' => 1,
119 'name' => "from_email_address",
120 'api.OptionValue.get' => array(),
121 ));
122 CRM_Core_Resources::singleton()->addSetting(array(
123 'crmMailing' => array(
124 'mailingabNames'=>array_values($mailingabNames['values']),
125 'civiMails' => array_values($civiMails['values']),
126 'campNames' => array_values($campNames['values']),
127 'mailStatus' => array_values($mailStatus['values']),
128 'groupNames' => array_values($groupNames['values']),
129 'headerfooterList' => array_values($headerfooterList['values']),
130 'mesTemplate' => array_values($mesTemplate['values']),
131 'emailAdd' => array_values($emailAdd['values']),
132 'mailGrp' => array_values($mailGrp['values']),
133 'mailTokens' => array_values($mailTokens),
134 'contactid' => $contactID,
135 'fromAddress' => array_values($fromAddress['values'][0]['api.OptionValue.get']['values']),
136 'visibility' => array(
137 array('value' => 'Public Pages', 'label' => ts('Public Pages')),
138 array('value' => 'User and User Admin Only', 'label' => ts('User and User Admin Only')),
139 ),
140 ),
141 ));
142
143 return $result;
144 }
145
146 /**
147 * @return bool
148 */
149 static function workflowEnabled() {
150 $config = CRM_Core_Config::singleton();
151
152 // early exit, since not true for most
153 if (!$config->userSystem->is_drupal ||
154 !function_exists('module_exists')
155 ) {
156 return FALSE;
157 }
158
159 if (!module_exists('rules')) {
160 return FALSE;
161 }
162
163 $enableWorkflow = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
164 'civimail_workflow',
165 NULL,
166 FALSE
167 );
168
169 return ($enableWorkflow &&
170 $config->userSystem->is_drupal
171 ) ? TRUE : FALSE;
172 }
173
174 // docs inherited from interface
175 /**
176 * @param bool $getAllUnconditionally
177 *
178 * @return array
179 */
180 public function getPermissions($getAllUnconditionally = FALSE) {
181 $permissions = array(
182 'access CiviMail',
183 'access CiviMail subscribe/unsubscribe pages',
184 'delete in CiviMail',
185 'view public CiviMail content',
186 );
187
188 if (self::workflowEnabled() || $getAllUnconditionally) {
189 $permissions[] = 'create mailings';
190 $permissions[] = 'schedule mailings';
191 $permissions[] = 'approve mailings';
192 }
193
194 return $permissions;
195 }
196
197
198 // docs inherited from interface
199 /**
200 * @return null
201 */
202 public function getUserDashboardElement() {
203 // no dashboard element for this component
204 return NULL;
205 }
206
207 /**
208 * @return null
209 */
210 public function getUserDashboardObject() {
211 // no dashboard element for this component
212 return NULL;
213 }
214
215 // docs inherited from interface
216 /**
217 * @return array
218 */
219 public function registerTab() {
220 return array(
221 'title' => ts('Mailings'),
222 'id' => 'mailing',
223 'url' => 'mailing',
224 'weight' => 45,
225 );
226 }
227
228 // docs inherited from interface
229 /**
230 * @return array
231 */
232 public function registerAdvancedSearchPane() {
233 return array('title' => ts('Mailings'),
234 'weight' => 20,
235 );
236 }
237
238 // docs inherited from interface
239 /**
240 * @return null
241 */
242 public function getActivityTypes() {
243 return NULL;
244 }
245
246 // add shortcut to Create New
247 /**
248 * @param $shortCuts
249 */
250 public function creatNewShortcut(&$shortCuts) {}
251 }
252