Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
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 | */ |
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, | |
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( |
7f82e636 | 121 | 'title' => ts('Smart group - create'), |
6a488035 TO |
122 | 'class' => 'CRM_Contact_Form_Task_SaveSearch', |
123 | 'result' => TRUE, | |
124 | ), | |
2a6af255 | 125 | self::SAVE_SEARCH_UPDATE => array( |
7f82e636 | 126 | 'title' => ts('Smart group - update'), |
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( |
7f82e636 | 141 | 'title' => ts('Batch update contacts via profile'), |
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( |
7f82e636 | 149 | 'title' => ts('PDF letters - print'), |
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 | ||
255 | asort(self::$_tasks); | |
256 | } | |
257 | } | |
258 | ||
259 | /** | |
260 | * These tasks are the core set of tasks that the user can perform | |
261 | * on a contact / group of contacts | |
262 | * | |
a6c01b45 CW |
263 | * @return array |
264 | * the set of tasks for a group of contacts | |
6a488035 | 265 | */ |
00be9182 | 266 | public static function &taskTitles() { |
6a488035 TO |
267 | self::initTasks(); |
268 | ||
269 | $titles = array(); | |
270 | foreach (self::$_tasks as $id => $value) { | |
271 | $titles[$id] = $value['title']; | |
272 | } | |
273 | ||
62c10c94 | 274 | // hack unset update saved search |
2a6af255 | 275 | unset($titles[self::SAVE_SEARCH_UPDATE]); |
6a488035 TO |
276 | |
277 | if (!CRM_Utils_Mail::validOutBoundMail()) { | |
2a6af255 CW |
278 | unset($titles[self::EMAIL_CONTACTS]); |
279 | unset($titles[self::CREATE_MAILING]); | |
6a488035 TO |
280 | } |
281 | ||
6a488035 TO |
282 | // CRM-6806 |
283 | if (!CRM_Core_Permission::check('access deleted contacts') || | |
284 | !CRM_Core_Permission::check('delete contacts') | |
285 | ) { | |
286 | unset($titles[self::DELETE_PERMANENTLY]); | |
287 | } | |
288 | asort($titles); | |
289 | return $titles; | |
290 | } | |
291 | ||
292 | /** | |
100fef9d | 293 | * Show tasks selectively based on the permission level |
6a488035 TO |
294 | * of the user |
295 | * | |
296 | * @param int $permission | |
77c5b619 TO |
297 | * @param bool $deletedContacts |
298 | * Are these tasks for operating on deleted contacts?. | |
6a488035 | 299 | * |
a6c01b45 CW |
300 | * @return array |
301 | * set of tasks that are valid for the user | |
6a488035 | 302 | */ |
00be9182 | 303 | public static function &permissionedTaskTitles($permission, $deletedContacts = FALSE) { |
6a488035 TO |
304 | self::initTasks(); |
305 | $tasks = array(); | |
306 | if ($deletedContacts) { | |
307 | if (CRM_Core_Permission::check('access deleted contacts')) { | |
308 | $tasks[self::RESTORE] = self::$_tasks[self::RESTORE]['title']; | |
309 | if (CRM_Core_Permission::check('delete contacts')) { | |
310 | $tasks[self::DELETE_PERMANENTLY] = self::$_tasks[self::DELETE_PERMANENTLY]['title']; | |
311 | } | |
312 | } | |
313 | } | |
314 | elseif ($permission == CRM_Core_Permission::EDIT) { | |
315 | $tasks = self::taskTitles(); | |
316 | } | |
317 | else { | |
318 | $tasks = array( | |
2a6af255 CW |
319 | self::EXPORT_CONTACTS => self::$_tasks[self::EXPORT_CONTACTS]['title'], |
320 | self::EMAIL_CONTACTS => self::$_tasks[self::EMAIL_CONTACTS]['title'], | |
321 | self::LABEL_CONTACTS => self::$_tasks[self::LABEL_CONTACTS]['title'], | |
6a488035 TO |
322 | ); |
323 | ||
2a6af255 CW |
324 | if (isset(self::$_tasks[self::MAP_CONTACTS]) && |
325 | !empty(self::$_tasks[self::MAP_CONTACTS]['title']) | |
6a488035 | 326 | ) { |
2a6af255 | 327 | $tasks[self::MAP_CONTACTS] = self::$_tasks[self::MAP_CONTACTS]['title']; |
6a488035 TO |
328 | } |
329 | ||
2a6af255 CW |
330 | if (isset(self::$_tasks[self::CREATE_MAILING]) && |
331 | !empty(self::$_tasks[self::CREATE_MAILING]['title']) | |
6a488035 | 332 | ) { |
2a6af255 | 333 | $tasks[self::CREATE_MAILING] = self::$_tasks[self::CREATE_MAILING]['title']; |
6a488035 TO |
334 | } |
335 | } | |
336 | return $tasks; | |
337 | } | |
338 | ||
339 | /** | |
fe482240 | 340 | * These tasks get added based on the context the user is in. |
6a488035 | 341 | * |
a6c01b45 CW |
342 | * @return array |
343 | * the set of optional tasks for a group of contacts | |
6a488035 | 344 | */ |
00be9182 | 345 | public static function &optionalTaskTitle() { |
6a488035 | 346 | $tasks = array( |
2a6af255 | 347 | self::SAVE_SEARCH_UPDATE => self::$_tasks[self::SAVE_SEARCH_UPDATE]['title'], |
6a488035 TO |
348 | ); |
349 | return $tasks; | |
350 | } | |
351 | ||
86538308 EM |
352 | /** |
353 | * @param $value | |
354 | * | |
355 | * @return array | |
356 | */ | |
00be9182 | 357 | public static function getTask($value) { |
6a488035 TO |
358 | self::initTasks(); |
359 | ||
360 | if (!CRM_Utils_Array::value($value, self::$_tasks)) { | |
361 | // make it the print task by default | |
2a6af255 | 362 | $value = self::PRINT_CONTACTS; |
6a488035 | 363 | } |
4154180f | 364 | return array( |
365 | CRM_Utils_Array::value('class', self::$_tasks[$value]), | |
6a488035 TO |
366 | CRM_Utils_Array::value('result', self::$_tasks[$value]), |
367 | ); | |
368 | } | |
96025800 | 369 | |
6a488035 | 370 | } |