Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
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 | * | |
30 | * @package CRM | |
0f03f337 | 31 | * @copyright CiviCRM LLC (c) 2004-2017 |
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 | */ |
37 | class 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, | |
6b5f37d3 | 63 | COMMUNICATION_PREFS = 25, |
cf0adfdc CR |
64 | INDIVIDUAL_CONTACTS = 26, |
65 | ADD_TO_CASE = 27; | |
6a488035 TO |
66 | |
67 | /** | |
100fef9d | 68 | * The task array |
6a488035 TO |
69 | * |
70 | * @var array | |
6a488035 TO |
71 | */ |
72 | static $_tasks = NULL; | |
73 | ||
74 | /** | |
100fef9d | 75 | * The optional task array |
6a488035 TO |
76 | * |
77 | * @var array | |
6a488035 TO |
78 | */ |
79 | static $_optionalTasks = NULL; | |
80 | ||
78b22ce9 CW |
81 | public static function tasks() { |
82 | self::initTasks(); | |
83 | return self::$_tasks; | |
84 | } | |
85 | ||
00be9182 | 86 | public static function initTasks() { |
6a488035 TO |
87 | if (!self::$_tasks) { |
88 | self::$_tasks = array( | |
2a6af255 | 89 | self::GROUP_CONTACTS => array( |
7f82e636 | 90 | 'title' => ts('Group - add contacts'), |
6a488035 | 91 | 'class' => 'CRM_Contact_Form_Task_AddToGroup', |
061ff68c | 92 | 'url' => 'civicrm/task/add-to-group', |
6a488035 | 93 | ), |
2a6af255 | 94 | self::REMOVE_CONTACTS => array( |
7f82e636 | 95 | 'title' => ts('Group - remove contacts'), |
6a488035 | 96 | 'class' => 'CRM_Contact_Form_Task_RemoveFromGroup', |
061ff68c | 97 | 'url' => 'civicrm/task/remove-from-group', |
6a488035 | 98 | ), |
2a6af255 | 99 | self::TAG_CONTACTS => array( |
79e4c2ad | 100 | 'title' => ts('Tag - add to contacts'), |
6a488035 | 101 | 'class' => 'CRM_Contact_Form_Task_AddToTag', |
061ff68c | 102 | 'url' => 'civicrm/task/add-to-tag', |
6a488035 | 103 | ), |
2a6af255 | 104 | self::REMOVE_TAGS => array( |
7f82e636 | 105 | 'title' => ts('Tag - remove from contacts'), |
6a488035 | 106 | 'class' => 'CRM_Contact_Form_Task_RemoveFromTag', |
061ff68c | 107 | 'url' => 'civicrm/task/remove-from-tag', |
6a488035 | 108 | ), |
2a6af255 | 109 | self::EXPORT_CONTACTS => array( |
7f82e636 | 110 | 'title' => ts('Export contacts'), |
6a488035 TO |
111 | 'class' => array( |
112 | 'CRM_Export_Form_Select', | |
113 | 'CRM_Export_Form_Map', | |
114 | ), | |
115 | 'result' => FALSE, | |
116 | ), | |
2a6af255 | 117 | self::EMAIL_CONTACTS => array( |
eb523ccd | 118 | 'title' => ts('Email - send now (to %1 or less)', array(1 => Civi::settings()->get('simple_mail_limit'))), |
6a488035 TO |
119 | 'class' => 'CRM_Contact_Form_Task_Email', |
120 | 'result' => TRUE, | |
061ff68c | 121 | 'url' => 'civicrm/task/send-email', |
6a488035 | 122 | ), |
2a6af255 | 123 | self::DELETE_CONTACTS => array( |
7f82e636 | 124 | 'title' => ts('Delete contacts'), |
6a488035 TO |
125 | 'class' => 'CRM_Contact_Form_Task_Delete', |
126 | 'result' => FALSE, | |
061ff68c | 127 | 'url' => 'civicrm/task/delete-contact', |
6a488035 | 128 | ), |
2a6af255 | 129 | self::RECORD_CONTACTS => array( |
7f82e636 | 130 | 'title' => ts('Add activity'), |
6a488035 TO |
131 | 'class' => 'CRM_Activity_Form_Activity', |
132 | ), | |
2a6af255 | 133 | self::SAVE_SEARCH => array( |
7f12f044 | 134 | 'title' => ts('Group - create smart group'), |
6a488035 TO |
135 | 'class' => 'CRM_Contact_Form_Task_SaveSearch', |
136 | 'result' => TRUE, | |
137 | ), | |
2a6af255 | 138 | self::SAVE_SEARCH_UPDATE => array( |
7f12f044 | 139 | 'title' => ts('Group - update smart group'), |
6a488035 TO |
140 | 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update', |
141 | 'result' => TRUE, | |
142 | ), | |
2a6af255 | 143 | self::PRINT_CONTACTS => array( |
7f82e636 | 144 | 'title' => ts('Print selected rows'), |
6a488035 TO |
145 | 'class' => 'CRM_Contact_Form_Task_Print', |
146 | 'result' => FALSE, | |
147 | ), | |
2a6af255 | 148 | self::LABEL_CONTACTS => array( |
7f82e636 | 149 | 'title' => ts('Mailing labels - print'), |
6a488035 TO |
150 | 'class' => 'CRM_Contact_Form_Task_Label', |
151 | 'result' => TRUE, | |
061ff68c | 152 | 'url' => 'civicrm/task/make-mailing-label', |
6a488035 | 153 | ), |
2a6af255 | 154 | self::BATCH_UPDATE => array( |
b581842f | 155 | 'title' => ts('Update multiple contacts'), |
6a488035 TO |
156 | 'class' => array( |
157 | 'CRM_Contact_Form_Task_PickProfile', | |
158 | 'CRM_Contact_Form_Task_Batch', | |
159 | ), | |
160 | 'result' => TRUE, | |
061ff68c | 161 | 'url' => 'civicrm/task/pick-profile', |
6a488035 | 162 | ), |
2a6af255 | 163 | self::PRINT_FOR_CONTACTS => array( |
cd095eae | 164 | 'title' => ts('Print/merge document'), |
6a488035 TO |
165 | 'class' => 'CRM_Contact_Form_Task_PDF', |
166 | 'result' => TRUE, | |
061ff68c | 167 | 'url' => 'civicrm/task/print-document', |
6a488035 | 168 | ), |
2a6af255 | 169 | self::EMAIL_UNHOLD => array( |
79e4c2ad | 170 | 'title' => ts('Email - unhold addresses'), |
6a488035 | 171 | 'class' => 'CRM_Contact_Form_Task_Unhold', |
061ff68c | 172 | 'url' => 'civicrm/task/unhold-email', |
6a488035 | 173 | ), |
2a6af255 | 174 | self::COMMUNICATION_PREFS => array( |
7f82e636 | 175 | 'title' => ts('Communication preferences - alter'), |
6a488035 | 176 | 'class' => 'CRM_Contact_Form_Task_AlterPreferences', |
061ff68c | 177 | 'url' => 'civicrm/task/alter-contact-preference', |
6a488035 TO |
178 | ), |
179 | self::RESTORE => array( | |
7f82e636 | 180 | 'title' => ts('Restore contacts from trash'), |
6a488035 TO |
181 | 'class' => 'CRM_Contact_Form_Task_Delete', |
182 | 'result' => FALSE, | |
183 | ), | |
184 | self::DELETE_PERMANENTLY => array( | |
7f82e636 | 185 | 'title' => ts('Delete permanently'), |
6a488035 TO |
186 | 'class' => 'CRM_Contact_Form_Task_Delete', |
187 | 'result' => FALSE, | |
188 | ), | |
189 | ); | |
190 | ||
26b0e4d2 SB |
191 | //CRM-16329, if SMS provider is configured show sms action. |
192 | $providersCount = CRM_SMS_BAO_Provider::activeProviderCount(); | |
193 | if ($providersCount) { | |
194 | self::$_tasks[self::SMS_CONTACTS] = array( | |
7f82e636 | 195 | 'title' => ts('SMS - schedule/send'), |
26b0e4d2 SB |
196 | 'class' => 'CRM_Contact_Form_Task_SMS', |
197 | 'result' => TRUE, | |
198 | ); | |
199 | } | |
200 | ||
6b5f37d3 | 201 | if (CRM_Contact_BAO_ContactType::isActive('Individual')) { |
202 | $label = CRM_Contact_BAO_ContactType::getLabel('individual'); | |
203 | self::$_tasks[self::INDIVIDUAL_CONTACTS] = array( | |
204 | 'title' => ts('Add relationship - to %1', | |
205 | array(1 => $label) | |
206 | ), | |
207 | 'class' => 'CRM_Contact_Form_Task_AddToIndividual', | |
208 | ); | |
209 | } | |
210 | ||
6a488035 | 211 | if (CRM_Contact_BAO_ContactType::isActive('Household')) { |
79e4c2ad | 212 | $label = CRM_Contact_BAO_ContactType::getLabel('household'); |
2a6af255 | 213 | self::$_tasks[self::HOUSEHOLD_CONTACTS] = array( |
79e4c2ad | 214 | 'title' => ts('Add relationship - to %1', |
6a488035 TO |
215 | array(1 => $label) |
216 | ), | |
217 | 'class' => 'CRM_Contact_Form_Task_AddToHousehold', | |
218 | ); | |
219 | } | |
220 | ||
221 | if (CRM_Contact_BAO_ContactType::isActive('Organization')) { | |
79e4c2ad | 222 | $label = CRM_Contact_BAO_ContactType::getLabel('organization'); |
2a6af255 | 223 | self::$_tasks[self::ORGANIZATION_CONTACTS] = array( |
79e4c2ad | 224 | 'title' => ts('Add relationship - to %1', |
6a488035 TO |
225 | array(1 => $label) |
226 | ), | |
227 | 'class' => 'CRM_Contact_Form_Task_AddToOrganization', | |
228 | ); | |
229 | } | |
230 | ||
231 | if (CRM_Core_Permission::check('merge duplicate contacts')) { | |
2a6af255 | 232 | self::$_tasks[self::MERGE_CONTACTS] = array( |
7f82e636 | 233 | 'title' => ts('Merge contacts'), |
6a488035 TO |
234 | 'class' => 'CRM_Contact_Form_Task_Merge', |
235 | 'result' => TRUE, | |
236 | ); | |
237 | } | |
238 | ||
239 | //CRM-4418, check for delete | |
240 | if (!CRM_Core_Permission::check('delete contacts')) { | |
2a6af255 | 241 | unset(self::$_tasks[self::DELETE_CONTACTS]); |
6a488035 TO |
242 | } |
243 | ||
244 | //show map action only if map provider and geoprovider are set (Google doesn't need geoprovider) | |
245 | // should fix this to be more flexible as providers are added ?? | |
246 | $config = CRM_Core_Config::singleton(); | |
247 | ||
248 | if ($config->mapProvider && | |
249 | ($config->mapProvider == 'Google' || | |
250 | ($config->mapProvider == 'OpenStreetMaps' || | |
251 | $config->geoProvider == 'Google' | |
252 | ) | |
253 | ) | |
254 | ) { | |
2a6af255 | 255 | self::$_tasks[self::MAP_CONTACTS] = array( |
7f82e636 | 256 | 'title' => ts('Map contacts'), |
6a488035 TO |
257 | 'class' => 'CRM_Contact_Form_Task_Map', |
258 | 'result' => FALSE, | |
259 | ); | |
260 | } | |
261 | ||
262 | if (CRM_Core_Permission::access('CiviEvent')) { | |
2a6af255 | 263 | self::$_tasks[self::ADD_EVENT] = array( |
7f82e636 | 264 | 'title' => ts('Register participants for event'), |
6a488035 TO |
265 | 'class' => 'CRM_Event_Form_Participant', |
266 | ); | |
267 | } | |
268 | ||
0083c73f TO |
269 | if (CRM_Core_Permission::access('CiviMail') |
270 | || (CRM_Mailing_Info::workflowEnabled() && CRM_Core_Permission::check('create mailings')) | |
271 | ) { | |
272 | self::$_tasks[self::CREATE_MAILING] = array( | |
db2e53c6 | 273 | 'title' => ts('Email - schedule/send via CiviMail'), |
0083c73f TO |
274 | 'class' => 'CRM_Mailing_Form_Task_AdhocMailing', |
275 | 'result' => FALSE, | |
276 | ); | |
6a488035 TO |
277 | } |
278 | ||
cf0adfdc | 279 | if (CRM_Core_Permission::access('CiviCase')) { |
3e240fc3 | 280 | self::$_tasks[self::ADD_TO_CASE] = array( |
cf0adfdc CR |
281 | 'title' => 'Add to case as role', |
282 | 'class' => 'CRM_Case_Form_AddToCaseAsRole', | |
283 | 'result' => FALSE, | |
3e240fc3 | 284 | ); |
cf0adfdc | 285 | } |
f1d7f287 | 286 | |
6a488035 TO |
287 | self::$_tasks += CRM_Core_Component::taskList(); |
288 | ||
289 | CRM_Utils_Hook::searchTasks('contact', self::$_tasks); | |
6a488035 TO |
290 | } |
291 | } | |
292 | ||
293 | /** | |
294 | * These tasks are the core set of tasks that the user can perform | |
295 | * on a contact / group of contacts | |
296 | * | |
a6c01b45 CW |
297 | * @return array |
298 | * the set of tasks for a group of contacts | |
6a488035 | 299 | */ |
00be9182 | 300 | public static function &taskTitles() { |
6a488035 TO |
301 | self::initTasks(); |
302 | ||
303 | $titles = array(); | |
304 | foreach (self::$_tasks as $id => $value) { | |
305 | $titles[$id] = $value['title']; | |
306 | } | |
307 | ||
62c10c94 | 308 | // hack unset update saved search |
2a6af255 | 309 | unset($titles[self::SAVE_SEARCH_UPDATE]); |
6a488035 TO |
310 | |
311 | if (!CRM_Utils_Mail::validOutBoundMail()) { | |
2a6af255 CW |
312 | unset($titles[self::EMAIL_CONTACTS]); |
313 | unset($titles[self::CREATE_MAILING]); | |
6a488035 TO |
314 | } |
315 | ||
6a488035 TO |
316 | // CRM-6806 |
317 | if (!CRM_Core_Permission::check('access deleted contacts') || | |
318 | !CRM_Core_Permission::check('delete contacts') | |
319 | ) { | |
320 | unset($titles[self::DELETE_PERMANENTLY]); | |
321 | } | |
6a488035 TO |
322 | return $titles; |
323 | } | |
324 | ||
325 | /** | |
100fef9d | 326 | * Show tasks selectively based on the permission level |
6a488035 TO |
327 | * of the user |
328 | * | |
329 | * @param int $permission | |
77c5b619 TO |
330 | * @param bool $deletedContacts |
331 | * Are these tasks for operating on deleted contacts?. | |
6a488035 | 332 | * |
a6c01b45 CW |
333 | * @return array |
334 | * set of tasks that are valid for the user | |
6a488035 | 335 | */ |
00be9182 | 336 | public static function &permissionedTaskTitles($permission, $deletedContacts = FALSE) { |
6a488035 TO |
337 | self::initTasks(); |
338 | $tasks = array(); | |
339 | if ($deletedContacts) { | |
340 | if (CRM_Core_Permission::check('access deleted contacts')) { | |
341 | $tasks[self::RESTORE] = self::$_tasks[self::RESTORE]['title']; | |
342 | if (CRM_Core_Permission::check('delete contacts')) { | |
343 | $tasks[self::DELETE_PERMANENTLY] = self::$_tasks[self::DELETE_PERMANENTLY]['title']; | |
344 | } | |
345 | } | |
346 | } | |
347 | elseif ($permission == CRM_Core_Permission::EDIT) { | |
348 | $tasks = self::taskTitles(); | |
349 | } | |
350 | else { | |
351 | $tasks = array( | |
2a6af255 CW |
352 | self::EXPORT_CONTACTS => self::$_tasks[self::EXPORT_CONTACTS]['title'], |
353 | self::EMAIL_CONTACTS => self::$_tasks[self::EMAIL_CONTACTS]['title'], | |
354 | self::LABEL_CONTACTS => self::$_tasks[self::LABEL_CONTACTS]['title'], | |
6a488035 TO |
355 | ); |
356 | ||
2a6af255 CW |
357 | if (isset(self::$_tasks[self::MAP_CONTACTS]) && |
358 | !empty(self::$_tasks[self::MAP_CONTACTS]['title']) | |
6a488035 | 359 | ) { |
2a6af255 | 360 | $tasks[self::MAP_CONTACTS] = self::$_tasks[self::MAP_CONTACTS]['title']; |
6a488035 TO |
361 | } |
362 | ||
2a6af255 CW |
363 | if (isset(self::$_tasks[self::CREATE_MAILING]) && |
364 | !empty(self::$_tasks[self::CREATE_MAILING]['title']) | |
6a488035 | 365 | ) { |
2a6af255 | 366 | $tasks[self::CREATE_MAILING] = self::$_tasks[self::CREATE_MAILING]['title']; |
6a488035 TO |
367 | } |
368 | } | |
369 | return $tasks; | |
370 | } | |
371 | ||
372 | /** | |
fe482240 | 373 | * These tasks get added based on the context the user is in. |
6a488035 | 374 | * |
a6c01b45 CW |
375 | * @return array |
376 | * the set of optional tasks for a group of contacts | |
6a488035 | 377 | */ |
00be9182 | 378 | public static function &optionalTaskTitle() { |
6a488035 | 379 | $tasks = array( |
2a6af255 | 380 | self::SAVE_SEARCH_UPDATE => self::$_tasks[self::SAVE_SEARCH_UPDATE]['title'], |
6a488035 TO |
381 | ); |
382 | return $tasks; | |
383 | } | |
384 | ||
86538308 EM |
385 | /** |
386 | * @param $value | |
387 | * | |
388 | * @return array | |
389 | */ | |
00be9182 | 390 | public static function getTask($value) { |
6a488035 TO |
391 | self::initTasks(); |
392 | ||
393 | if (!CRM_Utils_Array::value($value, self::$_tasks)) { | |
394 | // make it the print task by default | |
2a6af255 | 395 | $value = self::PRINT_CONTACTS; |
6a488035 | 396 | } |
4154180f | 397 | return array( |
398 | CRM_Utils_Array::value('class', self::$_tasks[$value]), | |
6a488035 TO |
399 | CRM_Utils_Array::value('result', self::$_tasks[$value]), |
400 | ); | |
401 | } | |
96025800 | 402 | |
061ff68c | 403 | /** |
404 | * Function to return the task information on basis of provided task's form name | |
405 | * | |
406 | * @param string $className | |
407 | * | |
408 | * @return array | |
409 | */ | |
410 | public static function getTaskAndTitleByClass($className) { | |
411 | self::initTasks(); | |
412 | ||
413 | foreach (self::$_tasks as $task => $value) { | |
78b22ce9 | 414 | if ((!empty($value['url']) || $task == self::EXPORT_CONTACTS) && ( |
061ff68c | 415 | (is_array($value['class']) && in_array($className, $value['class'])) || |
416 | ($value['class'] == $className) | |
417 | ) | |
418 | ) { | |
419 | return array( | |
420 | $task, | |
421 | CRM_Utils_Array::value('title', $value), | |
422 | ); | |
423 | } | |
424 | } | |
425 | } | |
426 | ||
6a488035 | 427 | } |