CRM-17607 - Change PDF activity type label
[civicrm-core.git] / CRM / Contact / Task.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
fa938177 6 | Copyright CiviCRM LLC (c) 2004-2016 |
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 *
30 * @package CRM
fa938177 31 * @copyright CiviCRM LLC (c) 2004-2016
6a488035
TO
32 */
33
34/**
95cdcc0f 35 * Class to represent the actions that can be performed on a group of contacts used by the search forms.
6a488035
TO
36 */
37class CRM_Contact_Task {
7da04cde 38 const
2a6af255
CW
39 GROUP_CONTACTS = 1,
40 REMOVE_CONTACTS = 2,
41 TAG_CONTACTS = 3,
42 REMOVE_TAGS = 4,
43 EXPORT_CONTACTS = 5,
44 EMAIL_CONTACTS = 6,
45 SMS_CONTACTS = 7,
46 DELETE_CONTACTS = 8,
47 HOUSEHOLD_CONTACTS = 9,
48 ORGANIZATION_CONTACTS = 10,
49 RECORD_CONTACTS = 11,
50 MAP_CONTACTS = 12,
51 SAVE_SEARCH = 13,
52 SAVE_SEARCH_UPDATE = 14,
53 PRINT_CONTACTS = 15,
54 LABEL_CONTACTS = 16,
55 BATCH_UPDATE = 17,
56 ADD_EVENT = 18,
57 PRINT_FOR_CONTACTS = 19,
58 CREATE_MAILING = 20,
59 MERGE_CONTACTS = 21,
60 EMAIL_UNHOLD = 22,
61 RESTORE = 23,
62 DELETE_PERMANENTLY = 24,
63 COMMUNICATION_PREFS = 25;
6a488035
TO
64
65 /**
100fef9d 66 * The task array
6a488035
TO
67 *
68 * @var array
6a488035
TO
69 */
70 static $_tasks = NULL;
71
72 /**
100fef9d 73 * The optional task array
6a488035
TO
74 *
75 * @var array
6a488035
TO
76 */
77 static $_optionalTasks = NULL;
78
00be9182 79 public static function initTasks() {
6a488035
TO
80 if (!self::$_tasks) {
81 self::$_tasks = array(
2a6af255 82 self::GROUP_CONTACTS => array(
7f82e636 83 'title' => ts('Group - add contacts'),
6a488035
TO
84 'class' => 'CRM_Contact_Form_Task_AddToGroup',
85 ),
2a6af255 86 self::REMOVE_CONTACTS => array(
7f82e636 87 'title' => ts('Group - remove contacts'),
6a488035
TO
88 'class' => 'CRM_Contact_Form_Task_RemoveFromGroup',
89 ),
2a6af255 90 self::TAG_CONTACTS => array(
79e4c2ad 91 'title' => ts('Tag - add to contacts'),
6a488035
TO
92 'class' => 'CRM_Contact_Form_Task_AddToTag',
93 ),
2a6af255 94 self::REMOVE_TAGS => array(
7f82e636 95 'title' => ts('Tag - remove from contacts'),
6a488035
TO
96 'class' => 'CRM_Contact_Form_Task_RemoveFromTag',
97 ),
2a6af255 98 self::EXPORT_CONTACTS => array(
7f82e636 99 'title' => ts('Export contacts'),
6a488035
TO
100 'class' => array(
101 'CRM_Export_Form_Select',
102 'CRM_Export_Form_Map',
103 ),
104 'result' => FALSE,
105 ),
2a6af255 106 self::EMAIL_CONTACTS => array(
7f82e636 107 'title' => ts('Email - send now (to 50 or less)'),
6a488035
TO
108 'class' => 'CRM_Contact_Form_Task_Email',
109 'result' => TRUE,
110 ),
2a6af255 111 self::DELETE_CONTACTS => array(
7f82e636 112 'title' => ts('Delete contacts'),
6a488035
TO
113 'class' => 'CRM_Contact_Form_Task_Delete',
114 'result' => FALSE,
115 ),
2a6af255 116 self::RECORD_CONTACTS => array(
7f82e636 117 'title' => ts('Add activity'),
6a488035
TO
118 'class' => 'CRM_Activity_Form_Activity',
119 ),
2a6af255 120 self::SAVE_SEARCH => array(
7f12f044 121 'title' => ts('Group - create smart group'),
6a488035
TO
122 'class' => 'CRM_Contact_Form_Task_SaveSearch',
123 'result' => TRUE,
124 ),
2a6af255 125 self::SAVE_SEARCH_UPDATE => array(
7f12f044 126 'title' => ts('Group - update smart group'),
6a488035
TO
127 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update',
128 'result' => TRUE,
129 ),
2a6af255 130 self::PRINT_CONTACTS => array(
7f82e636 131 'title' => ts('Print selected rows'),
6a488035
TO
132 'class' => 'CRM_Contact_Form_Task_Print',
133 'result' => FALSE,
134 ),
2a6af255 135 self::LABEL_CONTACTS => array(
7f82e636 136 'title' => ts('Mailing labels - print'),
6a488035
TO
137 'class' => 'CRM_Contact_Form_Task_Label',
138 'result' => TRUE,
139 ),
2a6af255 140 self::BATCH_UPDATE => array(
b581842f 141 'title' => ts('Update multiple contacts'),
6a488035
TO
142 'class' => array(
143 'CRM_Contact_Form_Task_PickProfile',
144 'CRM_Contact_Form_Task_Batch',
145 ),
146 'result' => TRUE,
147 ),
2a6af255 148 self::PRINT_FOR_CONTACTS => array(
cd095eae 149 'title' => ts('Print/merge document'),
6a488035
TO
150 'class' => 'CRM_Contact_Form_Task_PDF',
151 'result' => TRUE,
152 ),
2a6af255 153 self::EMAIL_UNHOLD => array(
79e4c2ad 154 'title' => ts('Email - unhold addresses'),
6a488035
TO
155 'class' => 'CRM_Contact_Form_Task_Unhold',
156 ),
2a6af255 157 self::COMMUNICATION_PREFS => array(
7f82e636 158 'title' => ts('Communication preferences - alter'),
6a488035
TO
159 'class' => 'CRM_Contact_Form_Task_AlterPreferences',
160 ),
161 self::RESTORE => array(
7f82e636 162 'title' => ts('Restore contacts from trash'),
6a488035
TO
163 'class' => 'CRM_Contact_Form_Task_Delete',
164 'result' => FALSE,
165 ),
166 self::DELETE_PERMANENTLY => array(
7f82e636 167 'title' => ts('Delete permanently'),
6a488035
TO
168 'class' => 'CRM_Contact_Form_Task_Delete',
169 'result' => FALSE,
170 ),
171 );
172
26b0e4d2
SB
173 //CRM-16329, if SMS provider is configured show sms action.
174 $providersCount = CRM_SMS_BAO_Provider::activeProviderCount();
175 if ($providersCount) {
176 self::$_tasks[self::SMS_CONTACTS] = array(
7f82e636 177 'title' => ts('SMS - schedule/send'),
26b0e4d2
SB
178 'class' => 'CRM_Contact_Form_Task_SMS',
179 'result' => TRUE,
180 );
181 }
182
6a488035 183 if (CRM_Contact_BAO_ContactType::isActive('Household')) {
79e4c2ad 184 $label = CRM_Contact_BAO_ContactType::getLabel('household');
2a6af255 185 self::$_tasks[self::HOUSEHOLD_CONTACTS] = array(
79e4c2ad 186 'title' => ts('Add relationship - to %1',
6a488035
TO
187 array(1 => $label)
188 ),
189 'class' => 'CRM_Contact_Form_Task_AddToHousehold',
190 );
191 }
192
193 if (CRM_Contact_BAO_ContactType::isActive('Organization')) {
79e4c2ad 194 $label = CRM_Contact_BAO_ContactType::getLabel('organization');
2a6af255 195 self::$_tasks[self::ORGANIZATION_CONTACTS] = array(
79e4c2ad 196 'title' => ts('Add relationship - to %1',
6a488035
TO
197 array(1 => $label)
198 ),
199 'class' => 'CRM_Contact_Form_Task_AddToOrganization',
200 );
201 }
202
203 if (CRM_Core_Permission::check('merge duplicate contacts')) {
2a6af255 204 self::$_tasks[self::MERGE_CONTACTS] = array(
7f82e636 205 'title' => ts('Merge contacts'),
6a488035
TO
206 'class' => 'CRM_Contact_Form_Task_Merge',
207 'result' => TRUE,
208 );
209 }
210
211 //CRM-4418, check for delete
212 if (!CRM_Core_Permission::check('delete contacts')) {
2a6af255 213 unset(self::$_tasks[self::DELETE_CONTACTS]);
6a488035
TO
214 }
215
216 //show map action only if map provider and geoprovider are set (Google doesn't need geoprovider)
217 // should fix this to be more flexible as providers are added ??
218 $config = CRM_Core_Config::singleton();
219
220 if ($config->mapProvider &&
221 ($config->mapProvider == 'Google' ||
222 ($config->mapProvider == 'OpenStreetMaps' ||
223 $config->geoProvider == 'Google'
224 )
225 )
226 ) {
2a6af255 227 self::$_tasks[self::MAP_CONTACTS] = array(
7f82e636 228 'title' => ts('Map contacts'),
6a488035
TO
229 'class' => 'CRM_Contact_Form_Task_Map',
230 'result' => FALSE,
231 );
232 }
233
234 if (CRM_Core_Permission::access('CiviEvent')) {
2a6af255 235 self::$_tasks[self::ADD_EVENT] = array(
7f82e636 236 'title' => ts('Register participants for event'),
6a488035
TO
237 'class' => 'CRM_Event_Form_Participant',
238 );
239 }
240
0083c73f
TO
241 if (CRM_Core_Permission::access('CiviMail')
242 || (CRM_Mailing_Info::workflowEnabled() && CRM_Core_Permission::check('create mailings'))
243 ) {
244 self::$_tasks[self::CREATE_MAILING] = array(
db2e53c6 245 'title' => ts('Email - schedule/send via CiviMail'),
0083c73f
TO
246 'class' => 'CRM_Mailing_Form_Task_AdhocMailing',
247 'result' => FALSE,
248 );
6a488035
TO
249 }
250
251 self::$_tasks += CRM_Core_Component::taskList();
252
253 CRM_Utils_Hook::searchTasks('contact', self::$_tasks);
254
6a488035
TO
255 }
256 }
257
258 /**
259 * These tasks are the core set of tasks that the user can perform
260 * on a contact / group of contacts
261 *
a6c01b45
CW
262 * @return array
263 * the set of tasks for a group of contacts
6a488035 264 */
00be9182 265 public static function &taskTitles() {
6a488035
TO
266 self::initTasks();
267
268 $titles = array();
269 foreach (self::$_tasks as $id => $value) {
270 $titles[$id] = $value['title'];
271 }
272
62c10c94 273 // hack unset update saved search
2a6af255 274 unset($titles[self::SAVE_SEARCH_UPDATE]);
6a488035
TO
275
276 if (!CRM_Utils_Mail::validOutBoundMail()) {
2a6af255
CW
277 unset($titles[self::EMAIL_CONTACTS]);
278 unset($titles[self::CREATE_MAILING]);
6a488035
TO
279 }
280
6a488035
TO
281 // CRM-6806
282 if (!CRM_Core_Permission::check('access deleted contacts') ||
283 !CRM_Core_Permission::check('delete contacts')
284 ) {
285 unset($titles[self::DELETE_PERMANENTLY]);
286 }
6a488035
TO
287 return $titles;
288 }
289
290 /**
100fef9d 291 * Show tasks selectively based on the permission level
6a488035
TO
292 * of the user
293 *
294 * @param int $permission
77c5b619
TO
295 * @param bool $deletedContacts
296 * Are these tasks for operating on deleted contacts?.
6a488035 297 *
a6c01b45
CW
298 * @return array
299 * set of tasks that are valid for the user
6a488035 300 */
00be9182 301 public static function &permissionedTaskTitles($permission, $deletedContacts = FALSE) {
6a488035
TO
302 self::initTasks();
303 $tasks = array();
304 if ($deletedContacts) {
305 if (CRM_Core_Permission::check('access deleted contacts')) {
306 $tasks[self::RESTORE] = self::$_tasks[self::RESTORE]['title'];
307 if (CRM_Core_Permission::check('delete contacts')) {
308 $tasks[self::DELETE_PERMANENTLY] = self::$_tasks[self::DELETE_PERMANENTLY]['title'];
309 }
310 }
311 }
312 elseif ($permission == CRM_Core_Permission::EDIT) {
313 $tasks = self::taskTitles();
314 }
315 else {
316 $tasks = array(
2a6af255
CW
317 self::EXPORT_CONTACTS => self::$_tasks[self::EXPORT_CONTACTS]['title'],
318 self::EMAIL_CONTACTS => self::$_tasks[self::EMAIL_CONTACTS]['title'],
319 self::LABEL_CONTACTS => self::$_tasks[self::LABEL_CONTACTS]['title'],
6a488035
TO
320 );
321
2a6af255
CW
322 if (isset(self::$_tasks[self::MAP_CONTACTS]) &&
323 !empty(self::$_tasks[self::MAP_CONTACTS]['title'])
6a488035 324 ) {
2a6af255 325 $tasks[self::MAP_CONTACTS] = self::$_tasks[self::MAP_CONTACTS]['title'];
6a488035
TO
326 }
327
2a6af255
CW
328 if (isset(self::$_tasks[self::CREATE_MAILING]) &&
329 !empty(self::$_tasks[self::CREATE_MAILING]['title'])
6a488035 330 ) {
2a6af255 331 $tasks[self::CREATE_MAILING] = self::$_tasks[self::CREATE_MAILING]['title'];
6a488035
TO
332 }
333 }
334 return $tasks;
335 }
336
337 /**
fe482240 338 * These tasks get added based on the context the user is in.
6a488035 339 *
a6c01b45
CW
340 * @return array
341 * the set of optional tasks for a group of contacts
6a488035 342 */
00be9182 343 public static function &optionalTaskTitle() {
6a488035 344 $tasks = array(
2a6af255 345 self::SAVE_SEARCH_UPDATE => self::$_tasks[self::SAVE_SEARCH_UPDATE]['title'],
6a488035
TO
346 );
347 return $tasks;
348 }
349
86538308
EM
350 /**
351 * @param $value
352 *
353 * @return array
354 */
00be9182 355 public static function getTask($value) {
6a488035
TO
356 self::initTasks();
357
358 if (!CRM_Utils_Array::value($value, self::$_tasks)) {
359 // make it the print task by default
2a6af255 360 $value = self::PRINT_CONTACTS;
6a488035 361 }
4154180f 362 return array(
363 CRM_Utils_Array::value('class', self::$_tasks[$value]),
6a488035
TO
364 CRM_Utils_Array::value('result', self::$_tasks[$value]),
365 );
366 }
96025800 367
6a488035 368}