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