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